20#ifndef DUNE_GRIDGLUE_EXTRACTORS_CODIM0EXTRACTOR_HH
21#define DUNE_GRIDGLUE_EXTRACTORS_CODIM0EXTRACTOR_HH
26#include <dune/common/deprecated.hh>
27#include <dune/grid/common/mcmgmapper.hh>
51 typedef typename GV::Traits::template Codim<dim>::Entity Vertex;
52 typedef typename GV::Traits::template Codim<0>::Entity Element;
53 typedef std::function<bool(
const Element&,
unsigned int subentity)> Predicate;
68 :
Extractor<GV,0>(gv), positiveNormalDirection_(false)
70 std::cout <<
"This is Codim0Extractor on a <"
71 << GV::dimension <<
"," << GV::dimensionworld <<
"> grid!" << std::endl;
75 bool & positiveNormalDirection() {
return positiveNormalDirection_; }
76 const bool & positiveNormalDirection()
const {
return positiveNormalDirection_; }
79 bool positiveNormalDirection_;
81 void update(
const Predicate& predicate);
86void Codim0Extractor<GV>::update(
const Predicate& predicate)
96 size_t element_index = 0;
97 size_t vertex_index = 0;
101 std::deque<SubEntityInfo> temp_faces;
104 for (
const auto& elmt : elements(this->gv_, Partitions::interior))
106 const auto geometry = elmt.geometry();
107 IndexType eindex = this->cellMapper_.index(elmt);
111 if (predicate(elmt,0))
114 this->elmtInfo_.emplace(eindex, ElementInfo(element_index, elmt, 1));
116 unsigned int numCorners = elmt.subEntities(dim);
117 unsigned int vertex_indices[numCorners];
118 unsigned int vertex_numbers[numCorners];
121 for (
unsigned int i = 0; i < numCorners; ++i)
123 vertex_numbers[i] = i;
126 const Vertex vertex = elmt.template subEntity<dim>(vertex_numbers[i]);
127 IndexType vindex = this->gv_.indexSet().template index<dim>(vertex);
131 typename VertexInfoMap::iterator vimit = this->vtxInfo_.find(vindex);
132 if (vimit == this->vtxInfo_.end())
135 this->vtxInfo_.emplace(vindex, VertexInfo(vertex_index, vertex));
137 vertex_indices[i] = vertex_index;
144 vertex_indices[i] = vimit->second.idx;
160 bool elementNormalDirection =
161 (geometry.corner(1)[0] < geometry.corner(0)[0]);
162 if ( positiveNormalDirection_ != elementNormalDirection )
164 std::swap(vertex_indices[0], vertex_indices[1]);
165 std::swap(vertex_numbers[0], vertex_numbers[1]);
171 Dune::FieldVector<ctype, dimworld>
172 v0 = geometry.corner(1),
173 v1 = geometry.corner(2);
174 v0 -= geometry.corner(0);
175 v1 -= geometry.corner(0);
176 ctype normal_sign = v0[0]*v1[1] - v0[1]*v1[0];
177 bool elementNormalDirection = (normal_sign < 0);
178 if ( positiveNormalDirection_ != elementNormalDirection )
180 std::cout <<
"swap\n";
181 if (elmt.type().isCube())
183 for (
int i = 0; i < (1<<dim); i+=2)
186 std::swap(vertex_indices[i], vertex_indices[i+1]);
187 std::swap(vertex_numbers[i], vertex_numbers[i+1]);
189 }
else if (elmt.type().isSimplex()) {
190 std::swap(vertex_indices[0], vertex_indices[1]);
191 std::swap(vertex_numbers[0], vertex_numbers[1]);
193 DUNE_THROW(Dune::Exception,
"Unexpected Geometrytype");
202 temp_faces.emplace_back(eindex, 0, elmt.type());
204 for (
unsigned int i=0; i<numCorners; i++) {
205 temp_faces.back().corners[i].idx = vertex_indices[i];
207 temp_faces.back().corners[i].num = vertex_numbers[i];
214 this->subEntities_.resize(element_index);
216 copy(temp_faces.begin(), temp_faces.end(), this->subEntities_.begin());
219 this->coords_.resize(this->vtxInfo_.size());
220 for (
const auto& vinfo : this->vtxInfo_)
223 CoordinateInfo* current = &this->coords_[vinfo.second.idx];
225 current->index = vinfo.second.idx;
227 current->vtxindex = vinfo.first;
230 const auto vtx = this->grid().entity(vinfo.second.p);
231 current->coord = vtx.geometry().corner(0);