18 #ifndef DUNE_GRIDGLUE_EXTRACTORS_CODIM0EXTRACTOR_HH
19 #define DUNE_GRIDGLUE_EXTRACTORS_CODIM0EXTRACTOR_HH
24 #include <dune/common/deprecated.hh>
25 #include <dune/grid/common/mcmgmapper.hh>
47 typedef typename GV::Traits::template Codim<dim>::EntityPointer
VertexPtr;
48 typedef typename GV::Traits::template Codim<dim>::Entity
Vertex;
49 typedef typename GV::Traits::template Codim<0>::EntityPointer
ElementPtr;
50 typedef typename GV::Traits::template Codim<0>::Entity
Element;
51 typedef std::function<bool(const Element&, unsigned int subentity)>
Predicate;
53 static const Dune::PartitionIteratorType
PType = Dune::Interior_Partition;
54 typedef typename GV::Traits::template Codim<0>::template Partition<PType>::Iterator
ElementIter;
68 DUNE_DEPRECATED_MSG(
"Please use a std::function<bool(const Element&, unsigned int)> in favor of the ExtractorPredicate.")
72 std::cout <<
"This is Codim0Extractor on a <"
73 << GV::dimension <<
"," << GV::dimensionworld <<
"> grid!" << std::endl;
74 const auto predicate = [&](
const Element&
element,
unsigned int subentity) ->
bool {
75 return descr.contains(element, subentity);
88 std::cout <<
"This is Codim0Extractor on a <"
89 << GV::dimension <<
"," << GV::dimensionworld <<
"> grid!" << std::endl;
99 void update(
const Predicate& predicate);
103 template<
typename GV>
114 size_t element_index = 0;
115 size_t vertex_index = 0;
119 std::deque<SubEntityInfo> temp_faces;
122 for (ElementIter elit = this->gv_.template begin<0, PType>();
123 elit != this->gv_.template end<0, PType>(); ++elit)
125 const auto& elmt = *elit;
126 const auto geometry = elmt.geometry();
127 #if DUNE_VERSION_NEWER(DUNE_GRID, 2, 4)
128 IndexType eindex = this->cellMapper_.index(elmt);
130 IndexType eindex = this->cellMapper_.map(elmt);
135 if (predicate(elmt,0))
138 this->elmtInfo_[eindex] =
new ElementInfo(element_index, elmt, 1);
140 #if DUNE_VERSION_NEWER(DUNE_GRID, 2, 4)
141 unsigned int numCorners = elmt.subEntities(dim);
143 unsigned int numCorners = elmt.template count<dim>();
145 unsigned int vertex_indices[numCorners];
146 unsigned int vertex_numbers[numCorners];
149 for (
unsigned int i = 0; i < numCorners; ++i)
151 vertex_numbers[i] = i;
154 #if DUNE_VERSION_NEWER(DUNE_GRID, 2, 4)
155 const Vertex vertex = elit->template subEntity<dim>(vertex_numbers[i]);
157 const VertexPtr vertexPtr = elit->template subEntity<dim>(vertex_numbers[i]);
158 const Vertex &vertex = *vertexPtr;
160 IndexType vindex = this->gv_.indexSet().template index<dim>(vertex);
164 typename VertexInfoMap::iterator vimit = this->vtxInfo_.find(vindex);
165 if (vimit == this->vtxInfo_.end())
168 this->vtxInfo_[vindex] =
new VertexInfo(vertex_index, vertex);
170 vertex_indices[i] = vertex_index;
177 vertex_indices[i] = vimit->second->idx;
193 bool elementNormalDirection =
194 (geometry.corner(1)[0] < geometry.corner(0)[0]);
195 if ( positiveNormalDirection_ != elementNormalDirection )
197 std::swap(vertex_indices[0], vertex_indices[1]);
198 std::swap(vertex_numbers[0], vertex_numbers[1]);
204 Dune::FieldVector<ctype, dimworld>
205 v0 = geometry.corner(1),
206 v1 = geometry.corner(2);
207 v0 -= geometry.corner(0);
208 v1 -= geometry.corner(0);
209 ctype normal_sign = v0[0]*v1[1] - v0[1]*v1[0];
210 bool elementNormalDirection = (normal_sign < 0);
211 if ( positiveNormalDirection_ != elementNormalDirection )
213 std::cout <<
"swap\n";
214 if (elmt.type().isCube())
216 for (
int i = 0; i < (1<<dim); i+=2)
219 std::swap(vertex_indices[i], vertex_indices[i+1]);
220 std::swap(vertex_numbers[i], vertex_numbers[i+1]);
222 }
else if (elmt.type().isSimplex()) {
223 std::swap(vertex_indices[0], vertex_indices[1]);
224 std::swap(vertex_numbers[0], vertex_numbers[1]);
226 DUNE_THROW(Dune::Exception,
"Unexpected Geometrytype");
235 temp_faces.push_back(SubEntityInfo(eindex,0,elmt.type()));
237 for (
unsigned int i=0; i<numCorners; i++) {
238 temp_faces.back().corners[i].idx = vertex_indices[i];
240 temp_faces.back().corners[i].num = vertex_numbers[i];
247 this->subEntities_.resize(element_index);
249 copy(temp_faces.begin(), temp_faces.end(), this->subEntities_.begin());
252 this->coords_.resize(this->vtxInfo_.size());
253 typename VertexInfoMap::const_iterator it1 = this->vtxInfo_.begin();
254 for (; it1 != this->vtxInfo_.end(); ++it1)
257 CoordinateInfo* current = &this->coords_[it1->second->idx];
259 current->index = it1->second->idx;
261 current->vtxindex = it1->first;
264 #if DUNE_VERSION_NEWER(DUNE_GRID, 2, 4)
265 const auto vtx = this->grid().entity(it1->second->p);
267 const auto vtxPtr = this->grid().entityPointer(it1->second->p);
268 const auto& vtx = *vtxPtr;
270 current->coord = vtx.geometry().corner(0);
279 #endif // DUNE_GRIDGLUE_EXTRACTORS_CODIM0EXTRACTOR_HH
GV::Traits::template Codim< dim >::EntityPointer VertexPtr
Definition: codim0extractor.hh:47
static const Dune::PartitionIteratorType PType
Definition: codim0extractor.hh:53
Base class for subentity-selecting predicates.
Definition: extractorpredicate.hh:30
Extractor< GV, 0 >::VertexInfo VertexInfo
Definition: codim0extractor.hh:59
Definition: codim0extractor.hh:35
Definition: gridglue.hh:33
Codim0Extractor(const GV &gv, const Predicate &predicate)
Constructor.
Definition: codim0extractor.hh:85
const bool & positiveNormalDirection() const
Definition: codim0extractor.hh:94
bool & positiveNormalDirection()
Definition: codim0extractor.hh:93
Extractor< GV, 0 >::CoordinateInfo CoordinateInfo
Definition: codim0extractor.hh:60
std::function< bool(const Element &, unsigned int subentity)> Predicate
Definition: codim0extractor.hh:51
Extractor< GV, 0 >::ctype ctype
Definition: codim0extractor.hh:42
Base class for predicates selecting the part of a grid to be extracted.
Extractor< GV, 0 >::SubEntityInfo SubEntityInfo
Definition: codim0extractor.hh:57
Provides codimension-independent methods for grid extraction.
Definition: extractor.hh:47
Extractor< GV, 0 >::IndexType IndexType
Definition: codim0extractor.hh:45
Extractor< GV, 0 >::ElementInfo ElementInfo
Definition: codim0extractor.hh:58
GV::Traits::template Codim< 0 >::EntityPointer ElementPtr
Definition: codim0extractor.hh:49
GV::Traits::template Codim< 0 >::template Partition< PType >::Iterator ElementIter
Definition: codim0extractor.hh:54
Element element(unsigned int index) const
gets the parent element for a given face index, throws an exception if index not valid ...
Definition: extractor.hh:396
GV::Traits::template Codim< 0 >::Entity Element
Definition: codim0extractor.hh:50
Extractor< GV, 0 >::VertexInfoMap VertexInfoMap
Definition: codim0extractor.hh:61
GV::Traits::template Codim< dim >::Entity Vertex
Definition: codim0extractor.hh:48
bool positiveNormalDirection_
Definition: codim0extractor.hh:97