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>
49 typedef typename GV::Traits::template Codim<dim>::Entity
Vertex;
50 typedef typename GV::Traits::template Codim<0>::Entity
Element;
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 (
const auto& elmt : elements(this->gv_, Partitions::interior))
104 const auto geometry = elmt.geometry();
105 IndexType eindex = this->cellMapper_.index(elmt);
109 if (predicate(elmt,0))
112 this->elmtInfo_.emplace(eindex, ElementInfo(element_index, elmt, 1));
114 unsigned int numCorners = elmt.subEntities(dim);
115 unsigned int vertex_indices[numCorners];
116 unsigned int vertex_numbers[numCorners];
119 for (
unsigned int i = 0; i < numCorners; ++i)
121 vertex_numbers[i] = i;
124 const Vertex vertex = elmt.template subEntity<dim>(vertex_numbers[i]);
125 IndexType vindex = this->gv_.indexSet().template index<dim>(vertex);
129 typename VertexInfoMap::iterator vimit = this->vtxInfo_.find(vindex);
130 if (vimit == this->vtxInfo_.end())
133 this->vtxInfo_.emplace(vindex, VertexInfo(vertex_index, vertex));
135 vertex_indices[i] = vertex_index;
142 vertex_indices[i] = vimit->second.idx;
158 bool elementNormalDirection =
159 (geometry.corner(1)[0] < geometry.corner(0)[0]);
160 if ( positiveNormalDirection_ != elementNormalDirection )
162 std::swap(vertex_indices[0], vertex_indices[1]);
163 std::swap(vertex_numbers[0], vertex_numbers[1]);
169 Dune::FieldVector<ctype, dimworld>
170 v0 = geometry.corner(1),
171 v1 = geometry.corner(2);
172 v0 -= geometry.corner(0);
173 v1 -= geometry.corner(0);
174 ctype normal_sign = v0[0]*v1[1] - v0[1]*v1[0];
175 bool elementNormalDirection = (normal_sign < 0);
176 if ( positiveNormalDirection_ != elementNormalDirection )
178 std::cout <<
"swap\n";
179 if (elmt.type().isCube())
181 for (
int i = 0; i < (1<<dim); i+=2)
184 std::swap(vertex_indices[i], vertex_indices[i+1]);
185 std::swap(vertex_numbers[i], vertex_numbers[i+1]);
187 }
else if (elmt.type().isSimplex()) {
188 std::swap(vertex_indices[0], vertex_indices[1]);
189 std::swap(vertex_numbers[0], vertex_numbers[1]);
191 DUNE_THROW(Dune::Exception,
"Unexpected Geometrytype");
200 temp_faces.emplace_back(eindex, 0, elmt.type());
202 for (
unsigned int i=0; i<numCorners; i++) {
203 temp_faces.back().corners[i].idx = vertex_indices[i];
205 temp_faces.back().corners[i].num = vertex_numbers[i];
212 this->subEntities_.resize(element_index);
214 copy(temp_faces.begin(), temp_faces.end(), this->subEntities_.begin());
217 this->coords_.resize(this->vtxInfo_.size());
218 for (
const auto& vinfo : this->vtxInfo_)
221 CoordinateInfo* current = &this->coords_[vinfo.second.idx];
223 current->index = vinfo.second.idx;
225 current->vtxindex = vinfo.first;
228 const auto vtx = this->grid().entity(vinfo.second.p);
229 current->coord = vtx.geometry().corner(0);
Definition: gridglue.hh:35
Definition: codim0extractor.hh:38
bool & positiveNormalDirection()
Definition: codim0extractor.hh:73
Extractor< GV, 0 >::IndexType IndexType
Definition: codim0extractor.hh:47
const bool & positiveNormalDirection() const
Definition: codim0extractor.hh:74
GV::Traits::template Codim< dim >::Entity Vertex
Definition: codim0extractor.hh:49
Extractor< GV, 0 >::CoordinateInfo CoordinateInfo
Definition: codim0extractor.hh:57
Extractor< GV, 0 >::VertexInfo VertexInfo
Definition: codim0extractor.hh:56
Extractor< GV, 0 >::ctype ctype
Definition: codim0extractor.hh:44
bool positiveNormalDirection_
Definition: codim0extractor.hh:77
Extractor< GV, 0 >::VertexInfoMap VertexInfoMap
Definition: codim0extractor.hh:58
std::function< bool(const Element &, unsigned int subentity)> Predicate
Definition: codim0extractor.hh:51
Codim0Extractor(const GV &gv, const Predicate &predicate)
Constructor.
Definition: codim0extractor.hh:65
Extractor< GV, 0 >::ElementInfo ElementInfo
Definition: codim0extractor.hh:55
GV::Traits::template Codim< 0 >::Entity Element
Definition: codim0extractor.hh:50
Extractor< GV, 0 >::SubEntityInfo SubEntityInfo
Definition: codim0extractor.hh:54
Provides codimension-independent methods for grid extraction.
Definition: extractor.hh:44