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>::Entity
Vertex;
48 typedef typename GV::Traits::template Codim<0>::Entity
Element;
51 static const Dune::PartitionIteratorType
PType = Dune::Interior_Partition;
52 typedef typename GV::Traits::template Codim<0>::template Partition<PType>::Iterator
ElementIter;
66 DUNE_DEPRECATED_MSG(
"Please use a std::function<bool(const Element&, unsigned int)> in favor of the ExtractorPredicate.")
70 std::cout <<
"This is Codim0Extractor on a <"
71 << GV::dimension <<
"," << GV::dimensionworld <<
"> grid!" << std::endl;
72 const auto predicate = [&](
const Element&
element,
unsigned int subentity) ->
bool {
73 return descr.contains(
element, subentity);
86 std::cout <<
"This is Codim0Extractor on a <"
87 << GV::dimension <<
"," << GV::dimensionworld <<
"> grid!" << std::endl;
112 size_t element_index = 0;
113 size_t vertex_index = 0;
117 std::deque<SubEntityInfo> temp_faces;
120 for (ElementIter elit = this->gv_.template begin<0, PType>();
121 elit != this->gv_.template end<0, PType>(); ++elit)
123 const auto& elmt = *elit;
124 const auto geometry = elmt.geometry();
125 IndexType eindex = this->cellMapper_.index(elmt);
129 if (predicate(elmt,0))
132 this->elmtInfo_[eindex] =
new ElementInfo(element_index, elmt, 1);
134 unsigned int numCorners = elmt.subEntities(dim);
135 unsigned int vertex_indices[numCorners];
136 unsigned int vertex_numbers[numCorners];
139 for (
unsigned int i = 0; i < numCorners; ++i)
141 vertex_numbers[i] = i;
144 const Vertex vertex = elit->template subEntity<dim>(vertex_numbers[i]);
145 IndexType vindex = this->gv_.indexSet().template index<dim>(vertex);
149 typename VertexInfoMap::iterator vimit = this->vtxInfo_.find(vindex);
150 if (vimit == this->vtxInfo_.end())
153 this->vtxInfo_[vindex] =
new VertexInfo(vertex_index, vertex);
155 vertex_indices[i] = vertex_index;
162 vertex_indices[i] = vimit->second->idx;
178 bool elementNormalDirection =
179 (geometry.corner(1)[0] < geometry.corner(0)[0]);
180 if ( positiveNormalDirection_ != elementNormalDirection )
182 std::swap(vertex_indices[0], vertex_indices[1]);
183 std::swap(vertex_numbers[0], vertex_numbers[1]);
189 Dune::FieldVector<ctype, dimworld>
190 v0 = geometry.corner(1),
191 v1 = geometry.corner(2);
192 v0 -= geometry.corner(0);
193 v1 -= geometry.corner(0);
194 ctype normal_sign = v0[0]*v1[1] - v0[1]*v1[0];
195 bool elementNormalDirection = (normal_sign < 0);
196 if ( positiveNormalDirection_ != elementNormalDirection )
198 std::cout <<
"swap\n";
199 if (elmt.type().isCube())
201 for (
int i = 0; i < (1<<dim); i+=2)
204 std::swap(vertex_indices[i], vertex_indices[i+1]);
205 std::swap(vertex_numbers[i], vertex_numbers[i+1]);
207 }
else if (elmt.type().isSimplex()) {
208 std::swap(vertex_indices[0], vertex_indices[1]);
209 std::swap(vertex_numbers[0], vertex_numbers[1]);
211 DUNE_THROW(Dune::Exception,
"Unexpected Geometrytype");
220 temp_faces.push_back(SubEntityInfo(eindex,0,elmt.type()));
222 for (
unsigned int i=0; i<numCorners; i++) {
223 temp_faces.back().corners[i].idx = vertex_indices[i];
225 temp_faces.back().corners[i].num = vertex_numbers[i];
232 this->subEntities_.resize(element_index);
234 copy(temp_faces.begin(), temp_faces.end(), this->subEntities_.begin());
237 this->coords_.resize(this->vtxInfo_.size());
238 typename VertexInfoMap::const_iterator it1 = this->vtxInfo_.begin();
239 for (; it1 != this->vtxInfo_.end(); ++it1)
242 CoordinateInfo* current = &this->coords_[it1->second->idx];
244 current->index = it1->second->idx;
246 current->vtxindex = it1->first;
249 const auto vtx = this->grid().entity(it1->second->p);
250 current->coord = vtx.geometry().corner(0);
Base class for predicates selecting the part of a grid to be extracted.
Definition gridglue.hh:30
Definition codim0extractor.hh:36
bool & positiveNormalDirection()
Definition codim0extractor.hh:91
Extractor< GV, 0 >::IndexType IndexType
Definition codim0extractor.hh:45
const bool & positiveNormalDirection() const
Definition codim0extractor.hh:92
GV::Traits::template Codim< dim >::Entity Vertex
Definition codim0extractor.hh:47
Extractor< GV, 0 >::CoordinateInfo CoordinateInfo
Definition codim0extractor.hh:58
static const Dune::PartitionIteratorType PType
Definition codim0extractor.hh:51
Extractor< GV, 0 >::VertexInfo VertexInfo
Definition codim0extractor.hh:57
Extractor< GV, 0 >::ctype ctype
Definition codim0extractor.hh:42
GV::Traits::template Codim< 0 >::template Partition< PType >::Iterator ElementIter
Definition codim0extractor.hh:52
bool positiveNormalDirection_
Definition codim0extractor.hh:95
Extractor< GV, 0 >::VertexInfoMap VertexInfoMap
Definition codim0extractor.hh:59
std::function< bool(const Element &, unsigned int subentity)> Predicate
Definition codim0extractor.hh:49
Codim0Extractor(const GV &gv, const Predicate &predicate)
Constructor.
Definition codim0extractor.hh:83
Extractor< GV, 0 >::ElementInfo ElementInfo
Definition codim0extractor.hh:56
GV::Traits::template Codim< 0 >::Entity Element
Definition codim0extractor.hh:48
Extractor< GV, 0 >::SubEntityInfo SubEntityInfo
Definition codim0extractor.hh:55
Provides codimension-independent methods for grid extraction.
Definition extractor.hh:43
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:375
@ dim
Definition extractor.hh:48
int IndexType
Definition extractor.hh:74
@ dimworld
Definition extractor.hh:47
GV::Grid::ctype ctype
Definition extractor.hh:59
std::map< IndexType, VertexInfo * > VertexInfoMap
Definition extractor.hh:184
@ codim
Definition extractor.hh:49
Definition extractor.hh:95
simple struct holding a vertex pointer and an index
Definition extractor.hh:117
simple struct holding an element seed and an index
Definition extractor.hh:129
Holds some information about an element's subentity involved in a coupling.
Definition extractor.hh:148
Base class for subentity-selecting predicates.
Definition extractorpredicate.hh:31