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;
61 typedef std::function<bool(const Element&, unsigned int subentity)>
Predicate;
82 std::cout <<
"This is Codim1Extractor on a <" <<
dim 103 void update(
const Predicate& predicate);
108 template<
typename GV>
120 int simplex_index = 0;
121 int vertex_index = 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())
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)
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);
192 temp_faces.back().corners[i].num = vertex_number;
196 typename VertexInfoMap::iterator vimit = this->
vtxInfo_.find(vindex);
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]);
243 std::array<unsigned int, 4> vertex_indices;
244 std::array<unsigned int, 4> vertex_numbers;
249 std::array<FieldVector<ctype,dimworld>, 4> cornerCoords;
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);
266 typename VertexInfoMap::iterator vimit = this->
vtxInfo_.find(vindex);
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";
362 copy(temp_faces.begin(), temp_faces.end(), this->
subEntities_.begin());
368 for (
const auto& vinfo : this->
vtxInfo_)
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);
388 #endif // DUNE_GRIDGLUE_EXTRACTORS_CODIM1EXTRACTOR_HH static constexpr auto dim
Definition: extractor.hh:49
GV::Traits::template Codim< 0 >::Entity Element
Definition: codim1extractor.hh:60
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
static constexpr int simplex_corners
compile time number of corners of surface simplices
Definition: codim1extractor.hh:52
std::function< bool(const Element &, unsigned int subentity)> Predicate
Definition: codim1extractor.hh:61
static constexpr auto codim
Definition: extractor.hh:50
static constexpr int cube_corners
Definition: extractor.hh:52
Definition: codim1extractor.hh:39
Extractor< GV, 1 >::ElementInfo ElementInfo
Definition: codim1extractor.hh:65
Extractor< GV, 1 >::SubEntityInfo SubEntityInfo
Definition: codim1extractor.hh:64
Vertex vertex(unsigned int index) const
gets the vertex for a given coordinate index throws an exception if index not valid ...
Definition: extractor.hh:394
IteratorRange<... > intersections(const GridGlue<... > &glue, const Reverse<... > &reverse=!reversed)
Iterate over all intersections of a GridGlue.
const GridView gv_
the grid object to extract the surface from
Definition: extractor.hh:199
static constexpr auto dimworld
Definition: extractor.hh:48
const Grid & grid() const
Definition: extractor.hh:366
Extractor< GV, 1 >::CoordinateInfo CoordinateInfo
Definition: codim1extractor.hh:67
VertexInfoMap vtxInfo_
a map enabling faster access to vertices and coordinates
Definition: extractor.hh:214
GV::Grid::ctype ctype
Definition: codim1extractor.hh:56
Codim1Extractor(const GV &gv, const Predicate &predicate)
Constructor.
Definition: codim1extractor.hh:79
Extractor< GV, 1 >::VertexInfo VertexInfo
Definition: codim1extractor.hh:66
Dune::FieldVector< ctype, dimworld > Coords
Definition: codim1extractor.hh:57
ElementInfoMap elmtInfo_
a map enabling faster access to elements and faces
Definition: extractor.hh:221
GV GridView
Definition: codim1extractor.hh:54
std::vector< SubEntityInfo > subEntities_
all information about the extracted subEntities
Definition: extractor.hh:207
CellMapper cellMapper_
Definition: extractor.hh:223
GV::Traits::template Codim< dim >::Entity Vertex
Definition: codim1extractor.hh:59
Extractor< GV, 1 >::VertexInfoMap VertexInfoMap
Definition: codim1extractor.hh:68
Definition: gridglue.hh:35
Extractor< GV, 1 >::IndexType IndexType
Definition: codim1extractor.hh:49
std::vector< CoordinateInfo > coords_
all information about the corner vertices of the extracted
Definition: extractor.hh:204
Provides codimension-independent methods for grid extraction.
Definition: extractor.hh:43
void clear()
delete everything build up so far and free the memory
Definition: extractor.hh:247