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;
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) 135 if (predicate(elmt,0))
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;
164 typename VertexInfoMap::iterator vimit = this->
vtxInfo_.find(vindex);
170 vertex_indices[i] = vertex_index;
177 vertex_indices[i] = vimit->second->idx;
193 bool elementNormalDirection =
197 std::swap(vertex_indices[0], vertex_indices[1]);
198 std::swap(vertex_numbers[0], vertex_numbers[1]);
204 Dune::FieldVector<ctype, dimworld>
209 ctype normal_sign = v0[0]*v1[1] - v0[1]*v1[0];
210 bool elementNormalDirection = (normal_sign < 0);
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");
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];
249 copy(temp_faces.begin(), temp_faces.end(), this->
subEntities_.begin());
253 typename VertexInfoMap::const_iterator it1 = this->
vtxInfo_.begin();
254 for (; it1 != this->
vtxInfo_.end(); ++it1)
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< 0 >::Entity Element
Definition: codim0extractor.hh:50
const GridView gv_
the grid object to extract the surface from
Definition: extractor.hh:206
Extractor< GV, 0 >::ElementInfo ElementInfo
Definition: codim0extractor.hh:58
void clear()
delete everything build up so far and free the memory
Definition: extractor.hh:252
Definition: codim0extractor.hh:35
std::vector< CoordinateInfo > coords_
all information about the corner vertices of the extracted
Definition: extractor.hh:211
std::vector< SubEntityInfo > subEntities_
all information about the extracted subEntities
Definition: extractor.hh:214
Definition: gridglue.hh:33
GV::Traits::template Codim< 0 >::template Partition< PType >::Iterator ElementIter
Definition: codim0extractor.hh:54
const bool & positiveNormalDirection() const
Definition: codim0extractor.hh:94
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
static const Dune::PartitionIteratorType PType
Definition: codim0extractor.hh:53
const Grid & grid() const
Definition: extractor.hh:380
GV::Traits::template Codim< dim >::Entity Vertex
Definition: codim0extractor.hh:48
Extractor< GV, 0 >::SubEntityInfo SubEntityInfo
Definition: codim0extractor.hh:57
GV::Traits::template Codim< 0 >::EntityPointer ElementPtr
Definition: codim0extractor.hh:49
Extractor< GV, 0 >::ctype ctype
Definition: codim0extractor.hh:42
Extractor< GV, 0 >::IndexType IndexType
Definition: codim0extractor.hh:45
Definition: extractor.hh:53
std::function< bool(const Element &, unsigned int subentity)> Predicate
Definition: codim0extractor.hh:51
Base class for subentity-selecting predicates.
Definition: extractorpredicate.hh:30
Extractor< GV, 0 >::CoordinateInfo CoordinateInfo
Definition: codim0extractor.hh:60
Codim0Extractor(const GV &gv, const Predicate &predicate)
Constructor.
Definition: codim0extractor.hh:85
VertexInfoMap vtxInfo_
a map enabling faster access to vertices and coordinates
Definition: extractor.hh:221
bool positiveNormalDirection_
Definition: codim0extractor.hh:97
Geometry geometry(unsigned int index) const
Get world geometry of the extracted face.
Base class for predicates selecting the part of a grid to be extracted.
CellMapper cellMapper_
Definition: extractor.hh:230
Extractor< GV, 0 >::VertexInfo VertexInfo
Definition: codim0extractor.hh:59
Vertex vertex(unsigned int index) const
gets the vertex for a given coordinate index throws an exception if index not valid ...
Definition: extractor.hh:420
GV::Traits::template Codim< dim >::EntityPointer VertexPtr
Definition: codim0extractor.hh:47
Provides codimension-independent methods for grid extraction.
Definition: extractor.hh:47
bool & positiveNormalDirection()
Definition: codim0extractor.hh:93
ElementInfoMap elmtInfo_
a map enabling faster access to elements and faces
Definition: extractor.hh:228
Extractor< GV, 0 >::VertexInfoMap VertexInfoMap
Definition: codim0extractor.hh:61