11#ifndef DUNE_GRIDGLUE_ADAPTER_INTERSECTION_HH
12#define DUNE_GRIDGLUE_ADAPTER_INTERSECTION_HH
18#include <dune/common/deprecated.hh>
19#include <dune/common/version.hh>
20#include <dune/geometry/affinegeometry.hh>
21#include <dune/geometry/referenceelements.hh>
24#define ONLY_SIMPLEX_INTERSECTIONS
30 template<
typename P0,
typename P1>
31 class IntersectionIndexSet;
36 template<
typename P0,
typename P1>
40 typedef ::Dune::GridGlue::GridGlue<P0, P1>
GridGlue;
50 static constexpr int dim() {
return GridGlue::template GridView<side>::Grid::dimension - GridGlue::template GridPatch<side>::codim; }
54 static constexpr int mydim = dim<0>() < dim<1>() ? dim<0>() : dim<1>();
58 typename GridGlue::template GridView<side>::ctype,
mydim, GridGlue::template GridView<side>::dimension>;
65 typename GridGlue::template GridView<side>::ctype,
mydim, GridGlue::template GridView<side>::dimensionworld>;
71 using GridIndexType =
typename GridGlue::template GridView<side>::IndexSet::IndexType;
77 IntersectionData(
const GridGlue& glue,
unsigned int mergeindex,
unsigned int offset,
bool grid0local,
bool grid1local);
86 {
return *std::get<side>(sideData_).gridlocalgeom[parentId]; }
90 {
return *std::get<side>(sideData_).gridgeom; }
94 {
return std::get<side>(sideData_).gridlocal; }
98 {
return std::get<side>(sideData_).gridindices[parentId]; }
102 {
return std::get<side>(sideData_).gridindices.size(); }
106 void initializeGeometry(
const GridGlue& glue,
unsigned mergeindex);
118 bool gridlocal =
false;
121 std::vector< GridIndexType<side> > gridindices;
124 std::vector< std::optional< GridLocalGeometry<side> > > gridlocalgeom;
133 std::optional< GridGeometry<side> > gridgeom;
136 std::tuple< SideData<0>, SideData<1> > sideData_;
139 template<
typename P0,
typename P1>
141 void IntersectionData<P0, P1>::initializeGeometry(
const GridGlue& glue,
unsigned mergeindex)
143 auto& data = std::get<side>(sideData_);
145 const unsigned n_parents = glue.merger_->template parents<side>(mergeindex);
148 data.gridindices.resize(n_parents);
149 data.gridlocalgeom.resize(n_parents);
152 data.gridindices[0] = 0;
154 static constexpr int nSimplexCorners = mydim + 1;
160 static constexpr int elementdim = GridGlue::template GridView<side>::template Codim<0>::Geometry::mydimension;
163 std::array<Dune::FieldVector< ctype, dim<side>() >, nSimplexCorners> corners_subEntity_local;
165 for (
unsigned int par = 0; par < n_parents; ++par) {
166 for (
int i = 0; i < nSimplexCorners; ++i)
167 corners_subEntity_local[i] = glue.merger_->template parentLocal<side>(mergeindex, i, par);
170 std::array<Dune::FieldVector<ctype, elementdim>, nSimplexCorners> corners_element_local;
172 if (data.gridlocal) {
173 data.gridindices[par] = glue.merger_->template parent<side>(mergeindex,par);
175 typename GridGlue::template GridPatch<side>::LocalGeometry
176 gridLocalGeometry = glue.template patch<side>().geometryLocal(data.gridindices[par]);
177 for (std::size_t i=0; i<corners_subEntity_local.size(); i++) {
178 corners_element_local[i] = gridLocalGeometry.global(corners_subEntity_local[i]);
182#ifdef ONLY_SIMPLEX_INTERSECTIONS
183 const Dune::GeometryType type = Dune::GeometryTypes::simplex(mydim);
185#error Not Implemented
187 data.gridlocalgeom[par].emplace(type, corners_element_local);
191 typename GridGlue::template GridPatch<side>::Geometry
192 gridWorldGeometry = glue.template patch<side>().geometry(data.gridindices[par]);
195 std::array<Dune::FieldVector<ctype, GridGlue::template GridView<side>::dimensionworld>, nSimplexCorners> corners_global;
197 for (std::size_t i=0; i<corners_subEntity_local.size(); i++) {
198 corners_global[i] = gridWorldGeometry.global(corners_subEntity_local[i]);
201 data.gridgeom.emplace(type, corners_global);
208 template<
typename P0,
typename P1>
210 bool grid0local,
bool grid1local)
211 : index_(mergeindex+offset)
215 assert (0 <= mergeindex || mergeindex < glue.index__sz);
217 std::get<0>(sideData_).gridlocal = grid0local;
218 std::get<1>(sideData_).gridlocal = grid1local;
220 initializeGeometry<0>(glue, mergeindex);
221 initializeGeometry<1>(glue, mergeindex);
228 template<
typename P0,
typename P1,
int ins
ide,
int outs
ide>
240 using Geometry =
typename IntersectionData::template GridGeometry<inside>;
255 template<
typename P0,
typename P1,
int I,
int O>
277 typedef typename InsideGridView::Traits::template Codim<0>::Entity
InsideEntity;
278 typedef typename OutsideGridView::Traits::template Codim<0>::Entity
OutsideEntity;
308 glue_(glue), i_(i) {}
318 return glue_->template patch<I>().element(i_->template index<I>(parentId));
327 return glue_->template patch<O>().element(i_->template index<O>(parentId));
333 throw Dune::NotImplemented();
340 return i_->template localGeometry<I>(parentId);
347 return i_->template localGeometry<O>(parentId);
358 return i_->template geometry<I>();
369 return i_->template geometry<O>();
373 Dune::GeometryType
type()
const
375 #ifdef ONLY_SIMPLEX_INTERSECTIONS
376 return Dune::GeometryTypes::simplex(
mydim);
378 #error Not Implemented
386 return i_->template local<I>();
392 if (g == 0 && i_->template local<O>()) {
393 return i_->template parents<O>();
394 }
else if (g == 1 && i_->template local<I>()) {
395 return i_->template parents<I>();
404 return glue_->template patch<I>().indexInInside(i_->template index<I>(parentId));
411 return glue_->template patch<O>().indexInInside(i_->template index<O>(parentId));
422 if (codimensionWorld == 0)
423 DUNE_THROW(Dune::Exception,
"There is no normal vector to a full-dimensional intersection");
424 else if (codimensionWorld == 1) {
426 const auto jacobianTransposed =
geometry().jacobianTransposed(local);
428 normal[0] = - jacobianTransposed[0][1];
429 normal[1] = jacobianTransposed[0][0];
430 }
else if (
mydim==2) {
431 normal[0] = (jacobianTransposed[0][1] * jacobianTransposed[1][2] - jacobianTransposed[0][2] * jacobianTransposed[1][1]);
432 normal[1] = - (jacobianTransposed[0][0] * jacobianTransposed[1][2] - jacobianTransposed[0][2] * jacobianTransposed[1][0]);
433 normal[2] = (jacobianTransposed[0][0] * jacobianTransposed[1][1] - jacobianTransposed[0][1] * jacobianTransposed[1][0]);
435 DUNE_THROW(Dune::NotImplemented,
"Remote intersections don't implement the 'outerNormal' method for " <<
mydim <<
"-dimensional intersections yet");
437 DUNE_THROW(Dune::NotImplemented,
"Remote intersections don't implement the 'outerNormal' method for intersections with codim >= 2 yet");
449 normal /= normal.two_norm();
479#ifdef QUICKHACK_INDEX
482 IndexType index()
const
491 friend class IntersectionIndexSet<P0,P1>;
Central component of the module implementing the coupling of two grids.
Definition gridglue.hh:37
sequential adapter to couple two grids at specified close together boundaries
Definition gridglue.hh:67
unsigned int IndexType
Definition gridglue.hh:147
PromotionTraits< typenameGridView< 0 >::ctype, typenameGridView< 1 >::ctype >::PromotedType ctype
The type used for coordinates.
Definition gridglue.hh:171
static constexpr int dimworld
export the world dimension This is the maximum of the extractors' world dimensions.
Definition gridglue.hh:166
storage class for Dune::GridGlue::Intersection related data
Definition intersection.hh:38
GridGlue::IndexType IndexType
Definition intersection.hh:42
AffineGeometry< typename GridGlue::template GridView< side >::ctype, mydim, GridGlue::template GridView< side >::dimensionworld > GridGeometry
Definition intersection.hh:65
const GridLocalGeometry< side > & localGeometry(unsigned int parentId=0) const
Definition intersection.hh:85
static constexpr int coorddim
Dimension of the world space of the intersection.
Definition intersection.hh:45
GridGeometry< 0 > Grid0Geometry
Definition intersection.hh:67
typename GridGlue::template GridView< side >::IndexSet::IndexType GridIndexType
Definition intersection.hh:71
IndexType index(unsigned int parentId=0) const
Definition intersection.hh:97
IndexType parents() const
Definition intersection.hh:101
GridLocalGeometry< 1 > Grid1LocalGeometry
Definition intersection.hh:61
const GridGeometry< side > & geometry() const
Definition intersection.hh:89
bool local() const
Definition intersection.hh:93
::Dune::GridGlue::GridGlue< P0, P1 > GridGlue
Definition intersection.hh:40
static constexpr int mydim
Dimension of the intersection.
Definition intersection.hh:54
AffineGeometry< typename GridGlue::template GridView< side >::ctype, mydim, GridGlue::template GridView< side >::dimension > GridLocalGeometry
Definition intersection.hh:58
GridLocalGeometry< 0 > Grid0LocalGeometry
Definition intersection.hh:60
IndexType index_
index of this intersection after GridGlue interface
Definition intersection.hh:112
GridIndexType< 1 > Grid1IndexType
Definition intersection.hh:74
GridGeometry< 1 > Grid1Geometry
Definition intersection.hh:68
GridIndexType< 0 > Grid0IndexType
Definition intersection.hh:73
IntersectionData()=default
Default Constructor.
The intersection of two entities of the two patches of a GridGlue.
Definition intersection.hh:257
Traits::OutsideLocalGeometry OutsideLocalGeometry
Definition intersection.hh:271
Intersection< P0, P1, O, I > flip() const
Return a copy of the intersection with inside and outside switched.
Definition intersection.hh:474
bool conforming() const
Return true if intersection is conforming.
Definition intersection.hh:331
InsideGridView::Traits::template Codim< 0 >::Entity InsideEntity
Definition intersection.hh:277
Traits::GridGlue GridGlue
Definition intersection.hh:263
int indexInOutside(unsigned int parentId=0) const
Local number of codim 1 entity in outside() Entity where intersection is contained in.
Definition intersection.hh:408
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:401
bool self() const
For parallel computations: Return true if inside() entity exists locally.
Definition intersection.hh:384
static constexpr auto mydim
dimension of the intersection
Definition intersection.hh:287
static constexpr int outsidePatch
outside patch
Definition intersection.hh:293
Dune::GeometryType type() const
Type of reference element for this intersection.
Definition intersection.hh:373
InsideEntity inside(unsigned int parentId=0) const
Return element on the inside of this intersection.
Definition intersection.hh:315
Traits::LocalCoordinate LocalCoordinate
Definition intersection.hh:280
const OutsideLocalGeometry & geometryInOutside(unsigned int parentId=0) const
Geometric information about this intersection in local coordinates of the outside() element.
Definition intersection.hh:345
GlobalCoordinate unitOuterNormal(const LocalCoordinate &local) const
Return a unit outer normal.
Definition intersection.hh:446
Traits::ctype ctype
Definition intersection.hh:275
IntersectionTraits< P0, P1, I, O > Traits
Definition intersection.hh:261
Traits::IntersectionData IntersectionData
Definition intersection.hh:264
Traits::GlobalCoordinate GlobalCoordinate
Definition intersection.hh:281
Traits::OutsideGeometry OutsideGeometry
Definition intersection.hh:272
size_t neighbor(unsigned int g=0) const
Return number of embeddings into local grid0 (grid1) entities.
Definition intersection.hh:390
Intersection(const GridGlue *glue, const IntersectionData *i)
Constructor for a given Dataset.
Definition intersection.hh:307
static constexpr int insidePatch
inside patch
Definition intersection.hh:290
Traits::Geometry Geometry
Definition intersection.hh:274
OutsideGridView::Traits::template Codim< 0 >::Entity OutsideEntity
Definition intersection.hh:278
OutsideEntity outside(unsigned int parentId=0) const
Return element on the outside of this intersection.
Definition intersection.hh:324
const Geometry & geometry() const
Geometric information about this intersection as part of the inside grid.
Definition intersection.hh:356
Traits::InsideLocalGeometry InsideLocalGeometry
Definition intersection.hh:268
GlobalCoordinate outerNormal(const LocalCoordinate &local) const
Return an outer normal (length not necessarily 1)
Definition intersection.hh:418
const OutsideGeometry & geometryOutside() const
Geometric information about this intersection as part of the outside grid.
Definition intersection.hh:367
Traits::OutsideGridView OutsideGridView
Definition intersection.hh:270
GlobalCoordinate integrationOuterNormal(const LocalCoordinate &local) const
Return an outer normal with the length of the integration element.
Definition intersection.hh:457
Traits::InsideGridView InsideGridView
Definition intersection.hh:267
const InsideLocalGeometry & geometryInInside(unsigned int parentId=0) const
Geometric information about this intersection in local coordinates of the inside() element.
Definition intersection.hh:338
GlobalCoordinate centerUnitOuterNormal() const
Unit outer normal at the center of the intersection.
Definition intersection.hh:466
static constexpr auto coorddim
dimension of the world space of the intersection
Definition intersection.hh:284
Definition intersection.hh:230
static constexpr int insidePatch
Definition intersection.hh:245
Dune::FieldVector< ctype, mydim > LocalCoordinate
Definition intersection.hh:249
static constexpr auto coorddim
Definition intersection.hh:243
typename IntersectionData::template GridGeometry< outside > OutsideGeometry
Definition intersection.hh:241
typename GridGlue::ctype ctype
Definition intersection.hh:248
typename GridGlue::template GridView< outside > OutsideGridView
Definition intersection.hh:235
Dune::FieldVector< ctype, coorddim > GlobalCoordinate
Definition intersection.hh:250
typename IntersectionData::template GridLocalGeometry< outside > OutsideLocalGeometry
Definition intersection.hh:238
typename GridGlue::template GridView< inside > InsideGridView
Definition intersection.hh:234
typename IntersectionData::template GridGeometry< inside > Geometry
Definition intersection.hh:240
typename IntersectionData::template GridLocalGeometry< inside > InsideLocalGeometry
Definition intersection.hh:237
static constexpr int outsidePatch
Definition intersection.hh:246
static constexpr auto mydim
Definition intersection.hh:244