3 #ifndef DUNE_FOAMGRID_INTERSECTIONS_HH
4 #define DUNE_FOAMGRID_INTERSECTIONS_HH
12 #include <dune/grid/common/intersection.hh>
21 template <
class Gr
idImp>
22 class FoamGridLevelIntersectionIterator;
24 template <
class Gr
idImp>
25 class FoamGridLeafIntersectionIterator;
27 template <
class Gr
idImp>
28 class FoamGridLevelIntersection;
30 template <
class Gr
idImp>
31 class FoamGridLeafIntersection;
37 template<
class Gr
idImp>
40 enum {dimgrid = GridImp::dimension};
41 enum {dimworld = GridImp::dimensionworld};
44 typedef typename GridImp::ctype ctype;
45 typedef typename GridImp::Traits::template Codim<1>::GeometryImpl GeometryImpl;
55 template<
typename,
typename>
56 friend class Dune::Intersection;
78 typedef typename GridImp::template Codim<0>::Entity
Entity;
114 return Dune::GeometryTypes::simplex(dimgrid-1);
120 assert(facetIndex_ < center_->corners());
127 FieldVector<ctype, dimworld>
outerNormal (
const FieldVector<ctype, dimgrid-1>& local)
const
136 const auto refElement = ReferenceElements<ctype, dimgrid>::general(
center_->type());
139 int v0 = refElement.subEntity(
facetIndex_, 1, 0, dimgrid);
143 int v1 = refElement.subEntity(
facetIndex_, 1, 1, dimgrid);
148 assert(v2!=v0 and v2!=v1);
150 FieldVector<ctype, dimworld> facet =
center_->vertex_[v0]->pos_ -
center_->vertex_[v1]->pos_;
151 FieldVector<ctype, dimworld> otherEdge =
center_->vertex_[v2]->pos_ -
center_->vertex_[v1]->pos_;
154 FieldVector<ctype, dimworld> scaledElementNormal;
158 scaledElementNormal[0] = facet[1]*otherEdge[2] - facet[2]*otherEdge[1];
159 scaledElementNormal[1] = facet[2]*otherEdge[0] - facet[0]*otherEdge[2];
160 scaledElementNormal[2] = facet[0]*otherEdge[1] - facet[1]*otherEdge[0];
161 outerNormal_[0] = facet[1]*scaledElementNormal[2] - facet[2]*scaledElementNormal[1];
162 outerNormal_[1] = facet[2]*scaledElementNormal[0] - facet[0]*scaledElementNormal[2];
163 outerNormal_[2] = facet[0]*scaledElementNormal[1] - facet[1]*scaledElementNormal[0];
167 outerNormal_[0] = facet[1];
168 outerNormal_[1] = -facet[0];
172 otherEdge =
center_->vertex_[v0]->pos_ -
center_->vertex_[v2]->pos_;
173 if(otherEdge*outerNormal_ < 0)
174 outerNormal_ *= -1.0;
183 outerNormal_ =
center_->vertex_[v0]->pos_ -
center_->vertex_[v1]->pos_;
187 DUNE_THROW(GridError,
"Non-existing grid dimension requested! Has to be 1 or 2!");
196 const auto refElement = ReferenceElements<ctype, dimgrid>::general(
center_->type());
199 int v0 = refElement.subEntity(
facetIndex_, 1, 0, dimgrid);
200 int v1 = refElement.subEntity(
facetIndex_, 1, 1, dimgrid);
203 ctype facetLength = (
center_->vertex_[v0]->pos_-
center_->vertex_[v1]->pos_).two_norm();
205 FieldVector<ctype, dimworld> integrationOuterNormal_ =
unitOuterNormal(local);
206 integrationOuterNormal_ *= facetLength;
207 return integrationOuterNormal_;
212 return integrationOuterNormal_;
214 DUNE_THROW(GridError,
"Non-existing grid dimension requested! Has to be 1 or 2!");
218 FieldVector<ctype, dimworld>
unitOuterNormal (
const FieldVector<ctype, dimgrid-1>& local)
const
221 unitOuterNormal_ /= unitOuterNormal_.two_norm();
222 return unitOuterNormal_;
233 mutable FieldVector<ctype, dimworld> outerNormal_;
234 mutable FieldVector<ctype, dimworld> unitOuterNormal_;
235 mutable FieldVector<ctype, dimworld> integrationOuterNormal_;
245 typename std::vector<const FoamGridEntityImp<dimgrid, dimgrid, dimworld, ctype>*>::const_iterator
neighbor_;
249 template<
class Gr
idImp>
255 template<
typename,
typename>
256 friend class Dune::Intersection;
260 enum {dimgrid = GridImp::dimension};
261 enum{ dimworld = GridImp::dimensionworld };
264 typedef typename GridImp::template Codim<1>::Geometry Geometry;
265 typedef typename GridImp::template Codim<1>::LocalGeometry LocalGeometry;
267 typedef typename GridImp::Traits::template Codim<1>::GeometryImpl GeometryImpl;
268 typedef typename GridImp::Traits::template Codim<1>::LocalGeometryImpl LocalGeometryImpl;
270 typedef typename GridImp::ctype ctype;
272 FoamGridLevelIntersection(
const FoamGridEntityImp<dimgrid, dimgrid ,dimworld, ctype>* center, std::size_t facet)
273 : FoamGridIntersection<GridImp>(center, facet)
286 return std::find((*this->
neighbor_)->facet_.begin(), (*this->neighbor_)->facet_.end(),
287 this->center_->facet_[this->facetIndex_])
302 std::vector<FieldVector<ctype, dimgrid> > coordinates(dimgrid);
305 const auto refElement = ReferenceElements<ctype, dimgrid>::general(this->
center_->type());
307 for (
int idx = 0; idx < dimgrid; ++idx)
308 coordinates[idx] = refElement.position(refElement.subEntity(this->facetIndex_, 1, idx, dimgrid), dimgrid);
310 geometryInInside_ = std::make_shared<LocalGeometryImpl>(this->
type(), coordinates);
312 return LocalGeometry(*geometryInInside_);
321 const auto refElement = ReferenceElements<ctype, dimgrid>::general(this->
center_->type());
323 std::array<FoamGridEntityImp<0, dimgrid, dimworld, ctype>*, dimgrid> vtx;
325 for (
int idx = 0; idx < dimgrid; ++idx)
326 vtx[idx] = this->
center_->vertex_[refElement.subEntity(this->facetIndex_, 1, idx, dimgrid)];
328 std::vector<FieldVector<ctype, dimgrid> > coordinates(dimgrid);
332 const auto refElementOther = ReferenceElements<ctype, dimgrid>::general((*this->
neighbor_)->
type());
334 for (std::size_t j=0; j<dimgrid; j++)
335 for (
int i=0; i<refElementOther.size(dimgrid); i++)
336 if (vtx[j] == (*this->
neighbor_)->vertex_[refElementOther.subEntity(0, 0, i, dimgrid)])
337 coordinates[j] = refElement.position(refElement.subEntity(0, 0, i, dimgrid), dimgrid);
339 geometryInOutside_ = std::make_shared<LocalGeometryImpl>(this->
type(), coordinates);
341 return LocalGeometry(*geometryInOutside_);
348 std::vector<FieldVector<ctype, dimworld> > coordinates(dimgrid);
351 const auto refElement = ReferenceElements<ctype, dimgrid>::general(this->
center_->type());
353 for (std::size_t idx = 0; idx < dimgrid; ++idx)
354 coordinates[idx] = this->
center_->vertex_[refElement.subEntity(this->facetIndex_, 1, idx, dimgrid)]->pos_;
356 geometry_ = std::make_shared<GeometryImpl>(this->
type(), coordinates);
358 return Geometry(*geometry_);
364 typename std::vector<const FoamGridEntityImp<dimgrid, dimgrid ,dimworld, ctype>*>::const_iterator neighborEnd_;
366 mutable std::shared_ptr<GeometryImpl> geometry_;
367 mutable std::shared_ptr<LocalGeometryImpl> geometryInInside_;
368 mutable std::shared_ptr<LocalGeometryImpl> geometryInOutside_;
383 template<
class Gr
idImp>
390 template<
typename,
typename>
391 friend class Dune::Intersection;
395 enum {dimworld = GridImp::dimensionworld};
396 enum {dimgrid = GridImp::dimension};
398 typedef typename GridImp::ctype ctype;
400 typedef typename GridImp::template Codim<1>::Geometry Geometry;
401 typedef typename GridImp::template Codim<1>::LocalGeometry LocalGeometry;
403 typedef typename GridImp::Traits::template Codim<1>::GeometryImpl GeometryImpl;
404 typedef typename GridImp::Traits::template Codim<1>::LocalGeometryImpl LocalGeometryImpl;
406 FoamGridLeafIntersection(
const FoamGridEntityImp<dimgrid, dimgrid, dimworld, ctype>* center,
408 : FoamGridIntersection<GridImp>(center, facet)
428 while(facet->level() > (*this->neighbor_)->level())
430 assert(facet->father_ !=
nullptr);
431 facet = facet->father_;
434 if (facet->level() == (*this->neighbor_)->level())
436 return std::distance((*this->
neighbor_)->facet_.begin(),
437 std::find((*this->neighbor_)->facet_.begin(),
438 (*this->neighbor_)->facet_.end(),
448 return std::distance((*this->
neighbor_)->facet_.begin(),
449 std::find_if((*this->neighbor_)->facet_.begin(),
450 (*this->neighbor_)->facet_.end(),
451 [
this](
const auto& facet) ->
bool {
452 for (const auto& e : facet->elements_)
453 if (this->center_ == e)
467 std::vector<FieldVector<ctype, dimgrid> > coordinates(dimgrid);
470 const auto refElement = ReferenceElements<ctype, dimgrid>::general(this->
center_->type());
472 for (std::size_t idx = 0; idx < dimgrid; ++idx)
473 coordinates[idx] = refElement.position(refElement.subEntity(this->facetIndex_, 1, idx, dimgrid), dimgrid);
475 geometryInInside_ = std::make_shared<LocalGeometryImpl>(this->
type(), coordinates);
477 return LocalGeometry(*geometryInInside_);
487 const auto refElement = Dune::ReferenceElements<ctype, dimgrid>::general(this->
center_->type());
490 std::vector<FieldVector<ctype, dimgrid> > coordinates(dimgrid);
491 for (std::size_t vIdx = 0; vIdx < dimgrid; ++vIdx)
493 const auto vIdxInElement = refElement.subEntity(this->
facetIndex_, 1, vIdx, dimgrid);
494 coordinates[vIdx] = (*this->
neighbor_)->globalToLocal(this->
center_->vertex_[vIdxInElement]->pos_);
497 geometryInOutside_ = std::make_shared<LocalGeometryImpl>(this->
type(), coordinates);
499 return LocalGeometry(*geometryInOutside_);
506 std::vector<FieldVector<ctype, dimworld> > coordinates(dimgrid);
509 const auto refElement = ReferenceElements<ctype, dimgrid>::general(this->
center_->type());
511 for (std::size_t idx = 0; idx < dimgrid; ++idx)
512 coordinates[idx] = this->
center_->vertex_[refElement.subEntity(this->facetIndex_, 1, idx, dimgrid)]->pos_;
514 geometry_ = std::make_shared<GeometryImpl>(this->
type(), coordinates);
516 return Geometry(*geometry_);
527 mutable std::shared_ptr<GeometryImpl> geometry_;
528 mutable std::shared_ptr<LocalGeometryImpl> geometryInInside_;
529 mutable std::shared_ptr<LocalGeometryImpl> geometryInOutside_;
The FoamGridEntity class.
The FoamGridGeometry class.
The null iterator factory for intersections.
Element specialization of FoamGridEntityImp. Element is a grid entity of topological codimension 0 an...
Definition: foamgridelements.hh:18
The implementation of entities in a FoamGrid.
Definition: foamgridentity.hh:54
Definition: foamgridintersectioniterators.hh:239
Iterator over all element neighborsMesh entities of codimension 0 ("elements") allow to visit all nei...
Definition: foamgridintersectioniterators.hh:28
Definition: foamgridintersections.hh:252
bool conforming() const
Return true if this is a conforming intersection.
Definition: foamgridintersections.hh:279
int indexInOutside(std::size_t neighborIndex=0) const
local number of codim 1 entity in neighbor where intersection is contained
Definition: foamgridintersections.hh:285
LocalGeometry geometryInOutside(std::size_t neighborIndex=0) const
Definition: foamgridintersections.hh:318
bool neighbor() const
return true if across the facet a neighbor on this level exists
Definition: foamgridintersections.hh:292
Geometry geometry() const
Definition: foamgridintersections.hh:346
LocalGeometry geometryInInside() const
Definition: foamgridintersections.hh:300
Iterator over all element neighborsMesh entities of codimension 0 ("elements") allow to visit all nei...
Definition: foamgridintersections.hh:386
int indexInOutside(std::size_t neighborIndex=0) const
local number of codim 1 entity in neighbor where intersection is contained
Definition: foamgridintersections.hh:420
LocalGeometry geometryInInside() const
Definition: foamgridintersections.hh:465
LocalGeometry geometryInOutside(std::size_t neighborIndex=0) const
Definition: foamgridintersections.hh:484
bool conforming() const
Return true if this is a conforming intersection.
Definition: foamgridintersections.hh:414
bool neighbor() const
return true if across the facet a neighbor on this level exists
Definition: foamgridintersections.hh:520
Geometry geometry() const
Definition: foamgridintersections.hh:504
Base class of all intersections within FoamGrid.
Definition: foamgridintersections.hh:39
virtual int indexInOutside(std::size_t neighborIndex=0) const =0
GridImp::template Codim< 0 >::Entity Entity
Definition: foamgridintersections.hh:78
FieldVector< ctype, dimworld > outerNormal(const FieldVector< ctype, dimgrid-1 > &local) const
return outer normal
Definition: foamgridintersections.hh:127
int facetIndex_
Count on which facet we are lookin' at.
Definition: foamgridintersections.hh:242
Entity inside() const
Definition: foamgridintersections.hh:82
std::vector< const FoamGridEntityImp< dimgrid, dimgrid, dimworld, ctype > * >::const_iterator neighbor_
Iterator to the other neighbor of the intersection.
Definition: foamgridintersections.hh:245
const FoamGridEntityImp< dimgrid, dimgrid, dimworld, ctype > * center_
Definition: foamgridintersections.hh:239
FieldVector< ctype, dimworld > integrationOuterNormal(const FieldVector< ctype, dimgrid-1 > &local) const
return outer normal multiplied by the integration element
Definition: foamgridintersections.hh:191
bool boundary() const
return true if intersection is with boundary.
Definition: foamgridintersections.hh:101
int boundarySegmentIndex() const
return information about the Boundary
Definition: foamgridintersections.hh:106
int indexInInside() const
local number of codim 1 entity in self where intersection is contained in
Definition: foamgridintersections.hh:118
Entity outside() const
Definition: foamgridintersections.hh:89
GeometryType type() const
Geometry type of an intersection.
Definition: foamgridintersections.hh:112
FieldVector< ctype, dimworld > centerUnitOuterNormal() const
return unit outer normal at the intersection center
Definition: foamgridintersections.hh:226
bool equals(const FoamGridIntersection< GridImp > &i) const
equality
Definition: foamgridintersections.hh:95
FieldVector< ctype, dimworld > unitOuterNormal(const FieldVector< ctype, dimgrid-1 > &local) const
return unit outer normal
Definition: foamgridintersections.hh:218
Definition: foamgridnulliteratorfactory.hh:16
static std::vector< const FoamGridEntityImp< dimgrid, dimgrid, dimworld, ctype > * >::const_iterator null()
Definition: foamgridnulliteratorfactory.hh:18