9 #ifndef DUNE_GRIDGLUE_ADAPTER_INTERSECTION_HH
10 #define DUNE_GRIDGLUE_ADAPTER_INTERSECTION_HH
16 #include <dune/common/deprecated.hh>
17 #include <dune/common/version.hh>
18 #include <dune/geometry/affinegeometry.hh>
19 #include <dune/geometry/referenceelements.hh>
22 #define ONLY_SIMPLEX_INTERSECTIONS
28 template<
typename P0,
typename P1>
29 class IntersectionIndexSet;
34 template<
typename P0,
typename P1>
38 typedef ::Dune::GridGlue::GridGlue<P0, P1>
GridGlue;
48 static constexpr
int dim() {
return GridGlue::template GridView<side>::Grid::dimension - GridGlue::template GridPatch<side>::codim; }
52 static constexpr
int mydim = dim<0>() < dim<1>() ? dim<0>() : dim<1>();
56 typename GridGlue::template GridView<side>::ctype,
mydim, GridGlue::template GridView<side>::dimension>;
63 typename GridGlue::template GridView<side>::ctype,
mydim, GridGlue::template GridView<side>::dimensionworld>;
69 using GridIndexType =
typename GridGlue::template GridView<side>::IndexSet::IndexType;
75 IntersectionData(
const GridGlue& glue,
unsigned int mergeindex,
unsigned int offset,
bool grid0local,
bool grid1local);
84 {
return *std::get<side>(sideData_).gridlocalgeom[parentId]; }
88 {
return *std::get<side>(sideData_).gridgeom; }
92 {
return std::get<side>(sideData_).gridlocal; }
96 {
return std::get<side>(sideData_).gridindices[parentId]; }
100 {
return std::get<side>(sideData_).gridindices.size(); }
104 void initializeGeometry(
const GridGlue& glue,
unsigned mergeindex);
116 bool gridlocal =
false;
119 std::vector< GridIndexType<side> > gridindices;
122 std::vector< std::optional< GridLocalGeometry<side> > > gridlocalgeom;
131 std::optional< GridGeometry<side> > gridgeom;
134 std::tuple< SideData<0>, SideData<1> > sideData_;
137 template<
typename P0,
typename P1>
139 void IntersectionData<P0, P1>::initializeGeometry(
const GridGlue& glue,
unsigned mergeindex)
141 auto& data = std::get<side>(sideData_);
143 const unsigned n_parents = glue.merger_->template parents<side>(mergeindex);
146 data.gridindices.resize(n_parents);
147 data.gridlocalgeom.resize(n_parents);
150 data.gridindices[0] = 0;
152 static constexpr
int nSimplexCorners = mydim + 1;
153 using ctype =
typename GridGlue::ctype;
158 static constexpr
int elementdim = GridGlue::template GridView<side>::template Codim<0>::Geometry::mydimension;
161 std::array<Dune::FieldVector< ctype, dim<side>() >, nSimplexCorners> corners_subEntity_local;
163 for (
unsigned int par = 0; par < n_parents; ++par) {
164 for (
int i = 0; i < nSimplexCorners; ++i)
165 corners_subEntity_local[i] = glue.merger_->template parentLocal<side>(mergeindex, i, par);
168 std::array<Dune::FieldVector<ctype, elementdim>, nSimplexCorners> corners_element_local;
170 if (data.gridlocal) {
171 data.gridindices[par] = glue.merger_->template parent<side>(mergeindex,par);
173 typename GridGlue::template GridPatch<side>::LocalGeometry
174 gridLocalGeometry = glue.template patch<side>().geometryLocal(data.gridindices[par]);
175 for (std::size_t i=0; i<corners_subEntity_local.size(); i++) {
176 corners_element_local[i] = gridLocalGeometry.global(corners_subEntity_local[i]);
180 #ifdef ONLY_SIMPLEX_INTERSECTIONS
181 # if DUNE_VERSION_NEWER(DUNE_GEOMETRY, 2, 6)
182 const Dune::GeometryType type = Dune::GeometryTypes::simplex(mydim);
184 const Dune::GeometryType type(Dune::GeometryType::simplex, mydim);
187 #error Not Implemented
189 data.gridlocalgeom[par].emplace(type, corners_element_local);
193 typename GridGlue::template GridPatch<side>::Geometry
194 gridWorldGeometry = glue.template patch<side>().geometry(data.gridindices[par]);
197 std::array<Dune::FieldVector<ctype, GridGlue::template GridView<side>::dimensionworld>, nSimplexCorners> corners_global;
199 for (std::size_t i=0; i<corners_subEntity_local.size(); i++) {
200 corners_global[i] = gridWorldGeometry.global(corners_subEntity_local[i]);
203 data.gridgeom.emplace(type, corners_global);
210 template<
typename P0,
typename P1>
212 bool grid0local,
bool grid1local)
213 : index_(mergeindex+offset)
217 assert (0 <= mergeindex || mergeindex < glue.index__sz);
219 std::get<0>(sideData_).gridlocal = grid0local;
220 std::get<1>(sideData_).gridlocal = grid1local;
222 initializeGeometry<0>(glue, mergeindex);
223 initializeGeometry<1>(glue, mergeindex);
230 template<
typename P0,
typename P1,
int ins
ide,
int outs
ide>
242 using Geometry =
typename IntersectionData::template GridGeometry<inside>;
257 template<
typename P0,
typename P1,
int I,
int O>
279 typedef typename InsideGridView::Traits::template Codim<0>::Entity
InsideEntity;
280 typedef typename OutsideGridView::Traits::template Codim<0>::Entity
OutsideEntity;
310 glue_(glue), i_(i) {}
320 return glue_->template patch<I>().element(i_->template index<I>(parentId));
329 return glue_->template patch<O>().element(i_->template index<O>(parentId));
335 throw Dune::NotImplemented();
342 return i_->template localGeometry<I>(parentId);
349 return i_->template localGeometry<O>(parentId);
360 return i_->template geometry<I>();
371 return i_->template geometry<O>();
375 Dune::GeometryType
type()
const
377 #ifdef ONLY_SIMPLEX_INTERSECTIONS
378 # if DUNE_VERSION_NEWER(DUNE_GEOMETRY, 2, 6)
379 return Dune::GeometryTypes::simplex(
mydim);
381 static const Dune::GeometryType
type(Dune::GeometryType::simplex,
mydim);
385 #error Not Implemented
393 return i_->template local<I>();
399 if (g == 0 && i_->template local<O>()) {
400 return i_->template parents<O>();
401 }
else if (g == 1 && i_->template local<I>()) {
402 return i_->template parents<I>();
411 return glue_->template patch<I>().indexInInside(i_->template index<I>(parentId));
418 return glue_->template patch<O>().indexInInside(i_->template index<O>(parentId));
429 if (codimensionWorld == 0)
430 DUNE_THROW(Dune::Exception,
"There is no normal vector to a full-dimensional intersection");
431 else if (codimensionWorld == 1) {
433 const auto jacobianTransposed =
geometry().jacobianTransposed(local);
435 normal[0] = - jacobianTransposed[0][1];
436 normal[1] = jacobianTransposed[0][0];
437 }
else if (
mydim==2) {
438 normal[0] = (jacobianTransposed[0][1] * jacobianTransposed[1][2] - jacobianTransposed[0][2] * jacobianTransposed[1][1]);
439 normal[1] = - (jacobianTransposed[0][0] * jacobianTransposed[1][2] - jacobianTransposed[0][2] * jacobianTransposed[1][0]);
440 normal[2] = (jacobianTransposed[0][0] * jacobianTransposed[1][1] - jacobianTransposed[0][1] * jacobianTransposed[1][0]);
442 DUNE_THROW(Dune::NotImplemented,
"Remote intersections don't implement the 'outerNormal' method for " <<
mydim <<
"-dimensional intersections yet");
444 DUNE_THROW(Dune::NotImplemented,
"Remote intersections don't implement the 'outerNormal' method for intersections with codim >= 2 yet");
456 normal /= normal.two_norm();
486 #ifdef QUICKHACK_INDEX
489 IndexType index()
const
498 friend class IntersectionIndexSet<P0,P1>;
Central component of the module implementing the coupling of two grids.
Definition: gridglue.hh:35
bool inside(const Coordinate &x, const Field &epsilon)
Definition: projection_impl.hh:109
sequential adapter to couple two grids at specified close together boundaries
Definition: gridglue.hh:52
unsigned int IndexType
Definition: gridglue.hh:145
static constexpr int dimworld
export the world dimension This is the maximum of the extractors' world dimensions.
Definition: gridglue.hh:164
PromotionTraits< typename GridView< 0 >::ctype, typename GridView< 1 >::ctype >::PromotedType ctype
The type used for coordinates.
Definition: gridglue.hh:169
storage class for Dune::GridGlue::Intersection related data
Definition: intersection.hh:36
GridGlue::IndexType IndexType
Definition: intersection.hh:40
AffineGeometry< typename GridGlue::template GridView< side >::ctype, mydim, GridGlue::template GridView< side >::dimensionworld > GridGeometry
Definition: intersection.hh:63
static constexpr int coorddim
Dimension of the world space of the intersection.
Definition: intersection.hh:43
GridGeometry< 0 > Grid0Geometry
Definition: intersection.hh:65
typename GridGlue::template GridView< side >::IndexSet::IndexType GridIndexType
Definition: intersection.hh:69
IndexType index(unsigned int parentId=0) const
Definition: intersection.hh:95
IndexType parents() const
Definition: intersection.hh:99
GridLocalGeometry< 1 > Grid1LocalGeometry
Definition: intersection.hh:59
const GridGeometry< side > & geometry() const
Definition: intersection.hh:87
const GridLocalGeometry< side > & localGeometry(unsigned int parentId=0) const
Definition: intersection.hh:83
bool local() const
Definition: intersection.hh:91
::Dune::GridGlue::GridGlue< P0, P1 > GridGlue
Definition: intersection.hh:38
static constexpr int mydim
Dimension of the intersection.
Definition: intersection.hh:52
AffineGeometry< typename GridGlue::template GridView< side >::ctype, mydim, GridGlue::template GridView< side >::dimension > GridLocalGeometry
Definition: intersection.hh:56
GridLocalGeometry< 0 > Grid0LocalGeometry
Definition: intersection.hh:58
IndexType index_
index of this intersection after GridGlue interface
Definition: intersection.hh:110
GridIndexType< 1 > Grid1IndexType
Definition: intersection.hh:72
GridGeometry< 1 > Grid1Geometry
Definition: intersection.hh:66
GridIndexType< 0 > Grid0IndexType
Definition: intersection.hh:71
IntersectionData()=default
Default Constructor.
The intersection of two entities of the two patches of a GridGlue.
Definition: intersection.hh:259
Traits::OutsideLocalGeometry OutsideLocalGeometry
Definition: intersection.hh:273
bool conforming() const
Return true if intersection is conforming.
Definition: intersection.hh:333
InsideGridView::Traits::template Codim< 0 >::Entity InsideEntity
Definition: intersection.hh:279
Intersection< P0, P1, O, I > flip() const
Return a copy of the intersection with inside and outside switched.
Definition: intersection.hh:481
Traits::GridGlue GridGlue
Definition: intersection.hh:265
int indexInOutside(unsigned int parentId=0) const
Local number of codim 1 entity in outside() Entity where intersection is contained in.
Definition: intersection.hh:415
int indexInInside(unsigned int parentId=0) const
Local number of codim 1 entity in the inside() Entity where intersection is contained in.
Definition: intersection.hh:408
const OutsideGeometry & geometryOutside() const
Geometric information about this intersection as part of the outside grid.
Definition: intersection.hh:369
static constexpr auto mydim
dimension of the intersection
Definition: intersection.hh:289
static constexpr int outsidePatch
outside patch
Definition: intersection.hh:295
const InsideLocalGeometry & geometryInInside(unsigned int parentId=0) const
Geometric information about this intersection in local coordinates of the inside() element.
Definition: intersection.hh:340
Dune::GeometryType type() const
Type of reference element for this intersection.
Definition: intersection.hh:375
InsideEntity inside(unsigned int parentId=0) const
Return element on the inside of this intersection.
Definition: intersection.hh:317
Traits::LocalCoordinate LocalCoordinate
Definition: intersection.hh:282
GlobalCoordinate unitOuterNormal(const LocalCoordinate &local) const
Return a unit outer normal.
Definition: intersection.hh:453
const OutsideLocalGeometry & geometryInOutside(unsigned int parentId=0) const
Geometric information about this intersection in local coordinates of the outside() element.
Definition: intersection.hh:347
Traits::ctype ctype
Definition: intersection.hh:277
IntersectionTraits< P0, P1, I, O > Traits
Definition: intersection.hh:263
Traits::IntersectionData IntersectionData
Definition: intersection.hh:266
Traits::GlobalCoordinate GlobalCoordinate
Definition: intersection.hh:283
Traits::OutsideGeometry OutsideGeometry
Definition: intersection.hh:274
size_t neighbor(unsigned int g=0) const
Return number of embeddings into local grid0 (grid1) entities.
Definition: intersection.hh:397
Intersection(const GridGlue *glue, const IntersectionData *i)
Constructor for a given Dataset.
Definition: intersection.hh:309
static constexpr int insidePatch
inside patch
Definition: intersection.hh:292
const Geometry & geometry() const
Geometric information about this intersection as part of the inside grid.
Definition: intersection.hh:358
Traits::Geometry Geometry
Definition: intersection.hh:276
OutsideGridView::Traits::template Codim< 0 >::Entity OutsideEntity
Definition: intersection.hh:280
OutsideEntity outside(unsigned int parentId=0) const
Return element on the outside of this intersection.
Definition: intersection.hh:326
Traits::InsideLocalGeometry InsideLocalGeometry
Definition: intersection.hh:270
GlobalCoordinate outerNormal(const LocalCoordinate &local) const
Return an outer normal (length not necessarily 1)
Definition: intersection.hh:425
Traits::OutsideGridView OutsideGridView
Definition: intersection.hh:272
GlobalCoordinate integrationOuterNormal(const LocalCoordinate &local) const
Return an outer normal with the length of the integration element.
Definition: intersection.hh:464
Traits::InsideGridView InsideGridView
Definition: intersection.hh:269
GlobalCoordinate centerUnitOuterNormal() const
Unit outer normal at the center of the intersection.
Definition: intersection.hh:473
static constexpr auto coorddim
dimension of the world space of the intersection
Definition: intersection.hh:286
Definition: intersection.hh:232
static constexpr int insidePatch
Definition: intersection.hh:247
Dune::FieldVector< ctype, mydim > LocalCoordinate
Definition: intersection.hh:251
static constexpr auto coorddim
Definition: intersection.hh:245
typename IntersectionData::template GridGeometry< outside > OutsideGeometry
Definition: intersection.hh:243
typename GridGlue::ctype ctype
Definition: intersection.hh:250
typename GridGlue::template GridView< outside > OutsideGridView
Definition: intersection.hh:237
Dune::FieldVector< ctype, coorddim > GlobalCoordinate
Definition: intersection.hh:252
typename IntersectionData::template GridLocalGeometry< outside > OutsideLocalGeometry
Definition: intersection.hh:240
typename GridGlue::template GridView< inside > InsideGridView
Definition: intersection.hh:236
typename IntersectionData::template GridGeometry< inside > Geometry
Definition: intersection.hh:242
typename IntersectionData::template GridLocalGeometry< inside > InsideLocalGeometry
Definition: intersection.hh:239
static constexpr int outsidePatch
Definition: intersection.hh:248
static constexpr auto mydim
Definition: intersection.hh:246