18 #ifndef DUNE_GRIDGLUE_EXTRACTORS_CODIM1EXTRACTOR_HH
19 #define DUNE_GRIDGLUE_EXTRACTORS_CODIM1EXTRACTOR_HH
27 #include <dune/common/deprecated.hh>
28 #include <dune/common/version.hh>
56 typedef typename GV::Grid::ctype
ctype;
57 typedef Dune::FieldVector<ctype, dimworld>
Coords;
59 typedef typename GV::Traits::template Codim<dim>::Entity
Vertex;
60 typedef typename GV::Traits::template Codim<0>::Entity
Element;
82 std::cout <<
"This is Codim1Extractor on a <" <<
dim
108 template<
typename GV>
109 void Codim1Extractor<GV>::update(
const Predicate& predicate)
120 int simplex_index = 0;
121 int vertex_index = 0;
122 IndexType eindex = 0;
129 std::deque<SubEntityInfo> temp_faces;
132 for (
const auto& elmt : elements(this->gv_, Partitions::interior))
134 Dune::GeometryType gt = elmt.type();
137 if (elmt.hasBoundaryIntersections())
141 eindex = this->cellMapper_.index(elmt);
142 this->elmtInfo_.emplace(eindex, ElementInfo(simplex_index, elmt, 0));
149 if (!in.boundary() or !predicate(elmt, in.indexInInside()))
152 const auto& refElement = Dune::ReferenceElements<ctype, dim>::general(gt);
154 const int face_corners = refElement.size(in.indexInInside(), 1, dim);
158 switch (face_corners)
166 this->elmtInfo_.at(eindex).faces++;
169 temp_faces.emplace_back(eindex, in.indexInInside(),
170 #
if DUNE_VERSION_NEWER(DUNE_GEOMETRY, 2, 6)
171 Dune::GeometryTypes::simplex(dim-codim)
173 Dune::GeometryType(Dune::GeometryType::simplex,dim-codim)
177 std::vector<FieldVector<ctype,dimworld> > cornerCoords(face_corners);
180 for (
int i = 0; i < face_corners; ++i)
183 int vertex_number = refElement.subEntity(in.indexInInside(), 1, i, dim);
186 const Vertex vertex = elmt.template subEntity<dim>(vertex_number);
187 cornerCoords[i] = vertex.geometry().corner(0);
189 IndexType vindex = this->gv_.indexSet().template index<dim>(vertex);
192 temp_faces.back().corners[i].num = vertex_number;
196 typename VertexInfoMap::iterator vimit = this->vtxInfo_.find(vindex);
197 if (vimit == this->vtxInfo_.end())
200 this->vtxInfo_.emplace(vindex, VertexInfo(vertex_index, vertex));
202 temp_faces.back().corners[i].idx = vertex_index;
209 temp_faces.back().corners[i].idx = vimit->second.idx;
217 FieldVector<ctype,dimworld> realNormal = in.centerUnitOuterNormal();
220 FieldVector<ctype,dimworld> reconstructedNormal;
223 reconstructedNormal[0] = cornerCoords[1][1] - cornerCoords[0][1];
224 reconstructedNormal[1] = cornerCoords[0][0] - cornerCoords[1][0];
226 FieldVector<ctype,dimworld> segment1 = cornerCoords[1] - cornerCoords[0];
227 FieldVector<ctype,dimworld> segment2 = cornerCoords[2] - cornerCoords[0];
230 reconstructedNormal /= reconstructedNormal.two_norm();
232 if (realNormal * reconstructedNormal < 0.0)
233 std::swap(temp_faces.back().corners[0], temp_faces.back().corners[1]);
241 assert(dim == 3 && cube_corners == 4);
243 std::array<unsigned int, 4> vertex_indices;
244 std::array<unsigned int, 4> vertex_numbers;
247 this->elmtInfo_.at(eindex).faces += 2;
249 std::array<FieldVector<ctype,dimworld>, 4> cornerCoords;
253 for (
int i = 0; i < cube_corners; ++i)
256 vertex_numbers[i] = refElement.subEntity(in.indexInInside(), 1, i, dim);
259 const Vertex vertex = elmt.template subEntity<dim>(vertex_numbers[i]);
260 cornerCoords[i] = vertex.geometry().corner(0);
262 IndexType vindex = this->gv_.indexSet().template index<dim>(vertex);
266 typename VertexInfoMap::iterator vimit = this->vtxInfo_.find(vindex);
267 if (vimit == this->vtxInfo_.end())
270 this->vtxInfo_.emplace(vindex, VertexInfo(vertex_index, vertex));
272 vertex_indices[i] = vertex_index;
279 vertex_indices[i] = vimit->second.idx;
288 temp_faces.emplace_back(eindex, in.indexInInside(),
289 #
if DUNE_VERSION_NEWER(DUNE_GEOMETRY, 2, 6)
290 Dune::GeometryTypes::simplex(dim-codim)
292 Dune::GeometryType(Dune::GeometryType::simplex,dim-codim)
295 temp_faces.back().corners[0].idx = vertex_indices[0];
296 temp_faces.back().corners[1].idx = vertex_indices[1];
297 temp_faces.back().corners[2].idx = vertex_indices[2];
299 temp_faces.back().corners[0].num = vertex_numbers[0];
300 temp_faces.back().corners[1].num = vertex_numbers[1];
301 temp_faces.back().corners[2].num = vertex_numbers[2];
307 FieldVector<ctype,dimworld> realNormal = in.centerUnitOuterNormal();
310 FieldVector<ctype,dimworld> reconstructedNormal =
crossProduct(cornerCoords[1] - cornerCoords[0],
311 cornerCoords[2] - cornerCoords[0]);
312 reconstructedNormal /= reconstructedNormal.two_norm();
314 if (realNormal * reconstructedNormal < 0.0)
315 std::swap(temp_faces.back().corners[0], temp_faces.back().corners[1]);
319 temp_faces.emplace_back(eindex, in.indexInInside(),
320 #
if DUNE_VERSION_NEWER(DUNE_GEOMETRY, 2, 6)
321 Dune::GeometryTypes::simplex(dim-codim)
323 Dune::GeometryType(Dune::GeometryType::simplex,dim-codim)
326 temp_faces.back().corners[0].idx = vertex_indices[3];
327 temp_faces.back().corners[1].idx = vertex_indices[2];
328 temp_faces.back().corners[2].idx = vertex_indices[1];
330 temp_faces.back().corners[0].num = vertex_numbers[3];
331 temp_faces.back().corners[1].num = vertex_numbers[2];
332 temp_faces.back().corners[2].num = vertex_numbers[1];
339 reconstructedNormal =
crossProduct(cornerCoords[2] - cornerCoords[3],
340 cornerCoords[1] - cornerCoords[3]);
341 reconstructedNormal /= reconstructedNormal.two_norm();
343 if (realNormal * reconstructedNormal < 0.0)
344 std::swap(temp_faces.back().corners[0], temp_faces.back().corners[1]);
350 DUNE_THROW(Dune::NotImplemented,
"the extractor does only work for triangle and quadrilateral faces (" << face_corners <<
" corners)");
357 std::cout <<
"added " << simplex_index <<
" subfaces\n";
360 this->subEntities_.resize(simplex_index);
362 copy(temp_faces.begin(), temp_faces.end(), this->subEntities_.begin());
367 this->coords_.resize(this->vtxInfo_.size());
368 for (
const auto& vinfo : this->vtxInfo_)
371 CoordinateInfo* current = &this->coords_[vinfo.second.idx];
373 current->index = vinfo.second.idx;
375 current->vtxindex = vinfo.first;
378 const auto vtx = this->grid().entity(vinfo.second.p);
379 current->coord = vtx.geometry().corner(0);
Definition: gridglue.hh:35
static Dune::FieldVector< T, dim > crossProduct(const Dune::FieldVector< T, dim > &a, const Dune::FieldVector< T, dim > &b)
compute cross product
Definition: crossproduct.hh:13
IteratorRange<... > intersections(const GridGlue<... > &glue, const Reverse<... > &reverse=!reversed)
Iterate over all intersections of a GridGlue.
Definition: codim1extractor.hh:40
Extractor< GV, 1 >::IndexType IndexType
Definition: codim1extractor.hh:49
GV GridView
Definition: codim1extractor.hh:54
GV::Traits::template Codim< 0 >::Entity Element
Definition: codim1extractor.hh:60
Dune::FieldVector< ctype, dimworld > Coords
Definition: codim1extractor.hh:57
GV::Grid::ctype ctype
Definition: codim1extractor.hh:56
Codim1Extractor(const GV &gv, const Predicate &predicate)
Constructor.
Definition: codim1extractor.hh:79
static constexpr int simplex_corners
compile time number of corners of surface simplices
Definition: codim1extractor.hh:52
Extractor< GV, 1 >::VertexInfo VertexInfo
Definition: codim1extractor.hh:66
Extractor< GV, 1 >::CoordinateInfo CoordinateInfo
Definition: codim1extractor.hh:67
Extractor< GV, 1 >::ElementInfo ElementInfo
Definition: codim1extractor.hh:65
Extractor< GV, 1 >::SubEntityInfo SubEntityInfo
Definition: codim1extractor.hh:64
Extractor< GV, 1 >::VertexInfoMap VertexInfoMap
Definition: codim1extractor.hh:68
std::function< bool(const Element &, unsigned int subentity)> Predicate
Definition: codim1extractor.hh:61
GV::Traits::template Codim< dim >::Entity Vertex
Definition: codim1extractor.hh:59
Provides codimension-independent methods for grid extraction.
Definition: extractor.hh:44
static constexpr auto dimworld
Definition: extractor.hh:48
static constexpr auto dim
Definition: extractor.hh:49