18 #ifndef DUNE_GRIDGLUE_EXTRACTORS_CODIM0EXTRACTOR_HH
19 #define DUNE_GRIDGLUE_EXTRACTORS_CODIM0EXTRACTOR_HH
23 #include <dune/grid/common/mcmgmapper.hh>
45 typedef typename GV::Traits::template Codim<dim>::EntityPointer
VertexPtr;
46 typedef typename GV::Traits::template Codim<dim>::Entity
Vertex;
47 typedef typename GV::Traits::template Codim<0>::EntityPointer
ElementPtr;
48 typedef typename GV::Traits::template Codim<0>::Entity
Element;
50 static const Dune::PartitionIteratorType
PType = Dune::Interior_Partition;
51 typedef typename GV::Traits::template Codim<0>::template Partition<PType>::Iterator
ElementIter;
68 std::cout <<
"This is Codim0Extractor on a <"
69 << GV::dimension <<
"," << GV::dimensionworld <<
"> grid!" << std::endl;
94 size_t element_index = 0;
95 size_t vertex_index = 0;
99 std::deque<SubEntityInfo> temp_faces;
102 for (ElementIter elit = this->gv_.template begin<0, PType>();
103 elit != this->gv_.template end<0, PType>(); ++elit)
105 const auto& elmt = *elit;
106 const auto geometry = elmt.geometry();
107 #if DUNE_VERSION_NEWER(DUNE_GRID, 2, 4)
108 IndexType eindex = this->cellMapper_.index(elmt);
110 IndexType eindex = this->cellMapper_.map(elmt);
118 this->elmtInfo_[eindex] =
new ElementInfo(element_index, elmt, 1);
120 #if DUNE_VERSION_NEWER(DUNE_GRID, 2, 4)
121 unsigned int numCorners = elmt.subEntities(dim);
123 unsigned int numCorners = elmt.template count<dim>();
125 unsigned int vertex_indices[numCorners];
126 unsigned int vertex_numbers[numCorners];
129 for (
unsigned int i = 0; i < numCorners; ++i)
131 vertex_numbers[i] = i;
134 #if DUNE_VERSION_NEWER(DUNE_GRID, 2, 4)
135 const Vertex vertex = elit->template subEntity<dim>(vertex_numbers[i]);
137 const VertexPtr vertexPtr = elit->template subEntity<dim>(vertex_numbers[i]);
138 const Vertex &vertex = *vertexPtr;
140 IndexType vindex = this->gv_.indexSet().template index<dim>(vertex);
144 typename VertexInfoMap::iterator vimit = this->vtxInfo_.find(vindex);
145 if (vimit == this->vtxInfo_.end())
148 this->vtxInfo_[vindex] =
new VertexInfo(vertex_index, vertex);
150 vertex_indices[i] = vertex_index;
157 vertex_indices[i] = vimit->second->idx;
173 bool elementNormalDirection =
174 (geometry.corner(1)[0] < geometry.corner(0)[0]);
175 if ( positiveNormalDirection_ != elementNormalDirection )
177 std::swap(vertex_indices[0], vertex_indices[1]);
178 std::swap(vertex_numbers[0], vertex_numbers[1]);
184 Dune::FieldVector<ctype, dimworld>
185 v0 = geometry.corner(1),
186 v1 = geometry.corner(2);
187 v0 -= geometry.corner(0);
188 v1 -= geometry.corner(0);
189 ctype normal_sign = v0[0]*v1[1] - v0[1]*v1[0];
190 bool elementNormalDirection = (normal_sign < 0);
191 if ( positiveNormalDirection_ != elementNormalDirection )
193 std::cout <<
"swap\n";
194 if (elmt.type().isCube())
196 for (
int i = 0; i < (1<<dim); i+=2)
199 std::swap(vertex_indices[i], vertex_indices[i+1]);
200 std::swap(vertex_numbers[i], vertex_numbers[i+1]);
202 }
else if (elmt.type().isSimplex()) {
203 std::swap(vertex_indices[0], vertex_indices[1]);
204 std::swap(vertex_numbers[0], vertex_numbers[1]);
206 DUNE_THROW(Dune::Exception,
"Unexpected Geometrytype");
215 temp_faces.push_back(SubEntityInfo(eindex,0,elmt.type()));
217 for (
int i=0; i<numCorners; i++) {
218 temp_faces.back().corners[i].idx = vertex_indices[i];
220 temp_faces.back().corners[i].num = vertex_numbers[i];
227 this->subEntities_.resize(element_index);
229 copy(temp_faces.begin(), temp_faces.end(), this->subEntities_.begin());
232 this->coords_.resize(this->vtxInfo_.size());
233 typename VertexInfoMap::const_iterator it1 = this->vtxInfo_.begin();
234 for (; it1 != this->vtxInfo_.end(); ++it1)
237 CoordinateInfo* current = &this->coords_[it1->second->idx];
239 current->index = it1->second->idx;
241 current->vtxindex = it1->first;
244 #if DUNE_VERSION_NEWER(DUNE_GRID, 2, 4)
245 const auto vtx = this->grid().entity(it1->second->p);
247 const auto vtxPtr = this->grid().entityPointer(it1->second->p);
248 const auto& vtx = *vtxPtr;
250 current->coord = vtx.geometry().corner(0);
259 #endif // DUNE_GRIDGLUE_EXTRACTORS_CODIM0EXTRACTOR_HH
GV::Traits::template Codim< dim >::EntityPointer VertexPtr
Definition: codim0extractor.hh:45
static const Dune::PartitionIteratorType PType
Definition: codim0extractor.hh:50
Codim0Extractor(const GV &gv, const ExtractorPredicate< GV, 0 > &descr)
Constructor.
Definition: codim0extractor.hh:65
Extractor< GV, 0 >::VertexInfo VertexInfo
Definition: codim0extractor.hh:56
Definition: codim0extractor.hh:33
const bool & positiveNormalDirection() const
Definition: codim0extractor.hh:74
bool & positiveNormalDirection()
Definition: codim0extractor.hh:73
Extractor< GV, 0 >::CoordinateInfo CoordinateInfo
Definition: codim0extractor.hh:57
Extractor< GV, 0 >::ctype ctype
Definition: codim0extractor.hh:40
virtual bool contains(const Element &element, unsigned int subentity) const =0
Return true if a subentity should be extracted.
Extractor< GV, 0 >::SubEntityInfo SubEntityInfo
Definition: codim0extractor.hh:54
Extractor< GV, 0 >::IndexType IndexType
Definition: codim0extractor.hh:43
Base class for subentity-selecting predicates.
Definition: extractorpredicate.hh:30
Extractor< GV, 0 >::ElementInfo ElementInfo
Definition: codim0extractor.hh:55
GV::Traits::template Codim< 0 >::EntityPointer ElementPtr
Definition: codim0extractor.hh:47
Definition: gridglue.hh:33
GV::Traits::template Codim< 0 >::template Partition< PType >::Iterator ElementIter
Definition: codim0extractor.hh:51
Base class for predicates selecting the part of a grid to be extracted.
GV::Traits::template Codim< 0 >::Entity Element
Definition: codim0extractor.hh:48
Extractor< GV, 0 >::VertexInfoMap VertexInfoMap
Definition: codim0extractor.hh:58
GV::Traits::template Codim< dim >::Entity Vertex
Definition: codim0extractor.hh:46
Provides codimension-independent methods for grid extraction.
Definition: extractor.hh:47
bool positiveNormalDirection_
Definition: codim0extractor.hh:77