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>
35 class IntersectionData
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);
80 std::get<0>(sideData_).gridlocal =
false;
81 std::get<1>(sideData_).gridlocal =
false;
88 {
return *std::get<side>(sideData_).gridlocalgeom[parentId]; }
92 {
return *std::get<side>(sideData_).gridgeom; }
96 {
return std::get<side>(sideData_).gridlocal; }
99 IndexType
index(
unsigned int parentId = 0)
const 100 {
return std::get<side>(sideData_).gridindices[parentId]; }
104 {
return std::get<side>(sideData_).gridindices.size(); }
108 void initializeGeometry(
const GridGlue& glue,
unsigned mergeindex);
123 std::vector< GridIndexType<side> > gridindices;
127 std::vector< std::unique_ptr< GridLocalGeometry<side> > > gridlocalgeom;
137 std::unique_ptr< GridGeometry<side> > gridgeom;
140 std::tuple< SideData<0>, SideData<1> > sideData_;
143 template<
typename P0,
typename P1>
147 auto& data = std::get<side>(sideData_);
149 const unsigned n_parents = glue.merger_->template parents<side>(mergeindex);
152 data.gridindices.resize(n_parents);
153 data.gridlocalgeom.resize(n_parents);
156 data.gridindices[0] = 0;
158 static constexpr
int nSimplexCorners =
mydim + 1;
164 static constexpr
int elementdim = GridGlue::template GridView<side>::template Codim<0>::Geometry::mydimension;
167 std::array<Dune::FieldVector< ctype, dim<side>() >, nSimplexCorners> corners_subEntity_local;
169 for (
unsigned int par = 0; par < n_parents; ++par) {
170 for (
int i = 0; i < nSimplexCorners; ++i)
171 corners_subEntity_local[i] = glue.merger_->template parentLocal<side>(mergeindex, i, par);
174 std::array<Dune::FieldVector<ctype, elementdim>, nSimplexCorners> corners_element_local;
176 if (data.gridlocal) {
177 data.gridindices[par] = glue.merger_->template parent<side>(mergeindex,par);
179 typename GridGlue::template GridPatch<side>::LocalGeometry
180 gridLocalGeometry = glue.template patch<side>().geometryLocal(data.gridindices[par]);
181 for (std::size_t i=0; i<corners_subEntity_local.size(); i++) {
182 corners_element_local[i] = gridLocalGeometry.global(corners_subEntity_local[i]);
186 #ifdef ONLY_SIMPLEX_INTERSECTIONS 187 # if DUNE_VERSION_NEWER(DUNE_GEOMETRY, 2, 6) 188 const Dune::GeometryType type = Dune::GeometryTypes::simplex(
mydim);
190 const Dune::GeometryType type(Dune::GeometryType::simplex,
mydim);
193 #error Not Implemented 195 data.gridlocalgeom[par] = std::make_unique< GridLocalGeometry<side> >(type, corners_element_local);
199 typename GridGlue::template GridPatch<side>::Geometry
200 gridWorldGeometry = glue.template patch<side>().
geometry(data.gridindices[par]);
203 std::array<Dune::FieldVector<ctype, GridGlue::template GridView<side>::dimensionworld>, nSimplexCorners> corners_global;
205 for (std::size_t i=0; i<corners_subEntity_local.size(); i++) {
206 corners_global[i] = gridWorldGeometry.global(corners_subEntity_local[i]);
209 data.gridgeom = std::make_unique< GridGeometry<side> >(type, corners_global);
216 template<
typename P0,
typename P1>
218 bool grid0local,
bool grid1local)
219 :
index_(mergeindex+offset)
223 assert (0 <= mergeindex || mergeindex < glue.index__sz);
225 std::get<0>(sideData_).gridlocal = grid0local;
226 std::get<1>(sideData_).gridlocal = grid1local;
228 initializeGeometry<0>(glue, mergeindex);
229 initializeGeometry<1>(glue, mergeindex);
236 template<
typename P0,
typename P1,
int ins
ide,
int outs
ide>
248 using Geometry =
typename IntersectionData::template GridGeometry<inside>;
253 static constexpr
int insidePatch =
inside;
254 static constexpr
int outsidePatch = outside;
263 template<
typename P0,
typename P1,
int I,
int O>
285 typedef typename InsideGridView::Traits::template Codim<0>::Entity
InsideEntity;
286 typedef typename OutsideGridView::Traits::template Codim<0>::Entity
OutsideEntity;
295 static constexpr
auto mydim = Traits::mydim;
298 static constexpr
int insidePatch = Traits::insidePatch;
301 static constexpr
int outsidePatch = Traits::outsidePatch;
309 static constexpr
int codimensionWorld = coorddim -
mydim;
316 glue_(glue), i_(i) {}
326 return glue_->template patch<I>().element(i_->template index<I>(parentId));
335 return glue_->template patch<O>().element(i_->template index<O>(parentId));
341 throw Dune::NotImplemented();
348 return i_->template localGeometry<I>(parentId);
355 return i_->template localGeometry<O>(parentId);
366 return i_->template geometry<I>();
377 return i_->template geometry<O>();
381 Dune::GeometryType
type()
const 383 #ifdef ONLY_SIMPLEX_INTERSECTIONS 384 # if DUNE_VERSION_NEWER(DUNE_GEOMETRY, 2, 6) 385 return Dune::GeometryTypes::simplex(mydim);
387 static const Dune::GeometryType type(Dune::GeometryType::simplex, mydim);
391 #error Not Implemented 399 return i_->template local<I>();
405 if (g == 0 && i_->template local<O>()) {
406 return i_->template parents<O>();
407 }
else if (g == 1 && i_->template local<I>()) {
408 return i_->template parents<I>();
417 return glue_->template patch<I>().indexInInside(i_->template index<I>(parentId));
424 return glue_->template patch<O>().indexInInside(i_->template index<O>(parentId));
433 GlobalCoordinate normal;
435 if (codimensionWorld == 0)
436 DUNE_THROW(Dune::Exception,
"There is no normal vector to a full-dimensional intersection");
437 else if (codimensionWorld == 1) {
439 const auto jacobianTransposed =
geometry().jacobianTransposed(local);
441 normal[0] = - jacobianTransposed[0][1];
442 normal[1] = jacobianTransposed[0][0];
443 }
else if (mydim==2) {
444 normal[0] = (jacobianTransposed[0][1] * jacobianTransposed[1][2] - jacobianTransposed[0][2] * jacobianTransposed[1][1]);
445 normal[1] = - (jacobianTransposed[0][0] * jacobianTransposed[1][2] - jacobianTransposed[0][2] * jacobianTransposed[1][0]);
446 normal[2] = (jacobianTransposed[0][0] * jacobianTransposed[1][1] - jacobianTransposed[0][1] * jacobianTransposed[1][0]);
448 DUNE_THROW(Dune::NotImplemented,
"Remote intersections don't implement the 'outerNormal' method for " << mydim <<
"-dimensional intersections yet");
450 DUNE_THROW(Dune::NotImplemented,
"Remote intersections don't implement the 'outerNormal' method for intersections with codim >= 2 yet");
461 GlobalCoordinate normal = outerNormal(local);
462 normal /= normal.two_norm();
472 return (unitOuterNormal(local) *=
geometry().integrationElement(local));
481 return unitOuterNormal(ReferenceElements<ctype,mydim>::general(type()).position(0,0));
492 #ifdef QUICKHACK_INDEX 495 IndexType
index()
const 509 const GridGlue* glue_;
512 const IntersectionData* i_;
519 #endif // DUNE_GRIDGLUE_ADAPTER_INTERSECTION_HH GridGeometry< 0 > Grid0Geometry
Definition: intersection.hh:65
GridLocalGeometry< 0 > Grid0LocalGeometry
Definition: intersection.hh:58
Dune::FieldVector< ctype, coorddim > GlobalCoordinate
Definition: intersection.hh:258
const GridGeometry< side > & geometry() const
Definition: intersection.hh:91
IntersectionTraits< P0, P1, I, O > Traits
Definition: intersection.hh:269
GridGeometry< 1 > Grid1Geometry
Definition: intersection.hh:66
PromotionTraits< typename GridView< 0 >::ctype, typename GridView< 1 >::ctype >::PromotedType ctype
The type used for coordinates.
Definition: gridglue.hh:169
size_t neighbor(unsigned int g=0) const
Return number of embeddings into local grid0 (grid1) entities.
Definition: intersection.hh:403
Definition: intersection.hh:237
static constexpr int dimworld
export the world dimension This is the maximum of the extractors' world dimensions.
Definition: gridglue.hh:164
Traits::OutsideLocalGeometry OutsideLocalGeometry
Definition: intersection.hh:279
const OutsideGeometry & geometryOutside() const
Geometric information about this intersection as part of the outside grid.
Definition: intersection.hh:375
typename GridGlue::template GridView< inside > InsideGridView
Definition: intersection.hh:242
Traits::InsideGridView InsideGridView
Definition: intersection.hh:275
OutsideEntity outside(unsigned int parentId=0) const
Return element on the outside of this intersection.
Definition: intersection.hh:332
GridGlue::IndexType IndexType
Definition: intersection.hh:40
Traits::GlobalCoordinate GlobalCoordinate
Definition: intersection.hh:289
sequential adapter to couple two grids at specified close together boundaries
Definition: gridglue.hh:40
typename GridGlue::ctype ctype
Definition: intersection.hh:256
::Dune::GridGlue::GridGlue< P0, P1 > GridGlue
Definition: intersection.hh:38
int indexInOutside(unsigned int parentId=0) const
Local number of codim 1 entity in outside() Entity where intersection is contained in...
Definition: intersection.hh:421
typename IntersectionData::template GridGeometry< outside > OutsideGeometry
Definition: intersection.hh:249
IndexType index(unsigned int parentId=0) const
Definition: intersection.hh:99
The intersection of two entities of the two patches of a GridGlue.
Definition: gridglue.hh:46
IntersectionData()
Default Constructor.
Definition: intersection.hh:78
IndexType index_
index of this intersection after GridGlue interface
Definition: intersection.hh:114
IndexType parents() const
Definition: intersection.hh:103
GridIndexType< 0 > Grid0IndexType
Definition: intersection.hh:71
GlobalCoordinate centerUnitOuterNormal() const
Unit outer normal at the center of the intersection.
Definition: intersection.hh:479
typename GridGlue::template GridView< outside > OutsideGridView
Definition: intersection.hh:243
const OutsideLocalGeometry & geometryInOutside(unsigned int parentId=0) const
Geometric information about this intersection in local coordinates of the outside() element...
Definition: intersection.hh:353
InsideEntity inside(unsigned int parentId=0) const
Return element on the inside of this intersection.
Definition: intersection.hh:323
Definition: gridglue.hh:52
Traits::ctype ctype
Definition: intersection.hh:283
typename IntersectionData::template GridLocalGeometry< outside > OutsideLocalGeometry
Definition: intersection.hh:246
Traits::OutsideGridView OutsideGridView
Definition: intersection.hh:278
const GridLocalGeometry< side > & localGeometry(unsigned int parentId=0) const
Definition: intersection.hh:87
storage class for Dune::GridGlue::Intersection related data
Definition: gridglue.hh:43
GlobalCoordinate integrationOuterNormal(const LocalCoordinate &local) const
Return an outer normal with the length of the integration element.
Definition: intersection.hh:470
Traits::OutsideGeometry OutsideGeometry
Definition: intersection.hh:280
typename GridGlue::template GridView< side >::IndexSet::IndexType GridIndexType
Definition: intersection.hh:69
typename IntersectionData::template GridLocalGeometry< inside > InsideLocalGeometry
Definition: intersection.hh:245
static constexpr int coorddim
Dimension of the world space of the intersection.
Definition: intersection.hh:43
Traits::LocalCoordinate LocalCoordinate
Definition: intersection.hh:288
GlobalCoordinate outerNormal(const LocalCoordinate &local) const
Return an outer normal (length not necessarily 1)
Definition: intersection.hh:431
OutsideGridView::Traits::template Codim< 0 >::Entity OutsideEntity
Definition: intersection.hh:286
InsideGridView::Traits::template Codim< 0 >::Entity InsideEntity
Definition: intersection.hh:285
AffineGeometry< typename GridGlue::template GridView< side >::ctype, mydim, GridGlue::template GridView< side >::dimension > GridLocalGeometry
Definition: intersection.hh:56
Intersection< P0, P1, O, I > flip() const
Return a copy of the intersection with inside and outside switched.
Definition: intersection.hh:487
unsigned int IndexType
Definition: gridglue.hh:145
bool conforming() const
Return true if intersection is conforming.
Definition: intersection.hh:339
Traits::InsideLocalGeometry InsideLocalGeometry
Definition: intersection.hh:276
GridLocalGeometry< 1 > Grid1LocalGeometry
Definition: intersection.hh:59
static constexpr int mydim
Dimension of the intersection.
Definition: intersection.hh:52
Dune::GeometryType type() const
Type of reference element for this intersection.
Definition: intersection.hh:381
Intersection(const GridGlue *glue, const IntersectionData *i)
Constructor for a given Dataset.
Definition: intersection.hh:315
bool local() const
Definition: intersection.hh:95
Traits::Geometry Geometry
Definition: intersection.hh:282
GridIndexType< 1 > Grid1IndexType
Definition: intersection.hh:72
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:414
typename IntersectionData::template GridGeometry< inside > Geometry
Definition: intersection.hh:248
bool inside(const Coordinate &x, const Field &epsilon)
Definition: projection_impl.hh:109
Dune::FieldVector< ctype, mydim > LocalCoordinate
Definition: intersection.hh:257
AffineGeometry< typename GridGlue::template GridView< side >::ctype, mydim, GridGlue::template GridView< side >::dimensionworld > GridGeometry
Definition: intersection.hh:63
GlobalCoordinate unitOuterNormal(const LocalCoordinate &local) const
Return a unit outer normal.
Definition: intersection.hh:459
Definition: gridglue.hh:35
Traits::GridGlue GridGlue
Definition: intersection.hh:271
Central component of the module implementing the coupling of two grids.
Traits::IntersectionData IntersectionData
Definition: intersection.hh:272
const InsideLocalGeometry & geometryInInside(unsigned int parentId=0) const
Geometric information about this intersection in local coordinates of the inside() element...
Definition: intersection.hh:346
const Geometry & geometry() const
Geometric information about this intersection as part of the inside grid.
Definition: intersection.hh:364