AMDiS  2.10
The Adaptive Multi-Dimensional Simulation Toolbox
ContextGeometry.hpp
1 #pragma once
2 
3 #include <optional>
4 #include <type_traits>
5 
6 #include <dune/common/typetraits.hh>
7 #include <dune/geometry/referenceelement.hh>
8 #include <dune/geometry/type.hh>
9 
10 namespace AMDiS
11 {
12  namespace Impl
13  {
14  template <class E, class = std::void_t<>>
15  struct ContextTypes
16  {
17  using Entity = E;
18  };
19 
20  // specialization for intersections
21  template <class I>
22  struct ContextTypes<I, std::void_t<decltype(std::declval<I>().inside())>>
23  {
24  using Entity = typename I::Entity;
25  };
26 
27  template <class Tag>
28  struct ContextTagType
29  {
30  using type = typename Tag::type;
31  };
32 
33  } // end namespace Impl
34 
35 
37 
47  template <class ContextType>
49  {
50  template <class I>
51  using IsIntersection = std::void_t<typename I::Entity, typename I::Geometry, typename I::LocalGeometry>;
52 
53  template <class E>
54  using IsElement = std::void_t<typename E::Geometry, typename E::EntitySeed, typename E::LocalGeometry, typename E::HierarchicIterator>;
55 
56  public:
57  using Context = ContextType;
58  using Geometry = typename Context::Geometry;
59  using LocalCoordinate = typename Geometry::LocalCoordinate;
60 
61  using Element = typename Impl::ContextTypes<Context>::Entity;
62  using ElementGeometry = typename Element::Geometry;
63  using ElementCoordinate = typename ElementGeometry::LocalCoordinate;
64 
65  template <class C>
66  static constexpr bool isEntity = Dune::Std::is_detected_v<IsElement,C>;
67 
68  enum {
69  dim = ElementGeometry::mydimension, //< the dimension of the grid element
70  dow = ElementGeometry::coorddimension //< the dimension of the world
71  };
72 
74  ContextGeometry(Context const& context, Element const& element, ElementGeometry const& elementGeo)
75  : context_(&context)
76  , element_(&element)
77  , elementGeometry_(&elementGeo)
78  {}
79 
80  // Prevent from storing pointer to rvalue-reference
81  ContextGeometry(Context const& context, Element const& element, ElementGeometry&& elementGeo) = delete;
82 
83  public:
85  Context const& context() const
86  {
87  return *context_;
88  }
89 
91  Element const& element() const
92  {
93  return *element_;
94  }
95 
97  ElementGeometry const& elementGeometry() const
98  {
99  return *elementGeometry_;
100  }
101 
103  template <class C = Context>
104  decltype(auto) geometry() const
105  {
106  if constexpr(isEntity<C>)
107  return *elementGeometry_;
108  else
109  return context_->geometry();
110  }
111 
113  template <class C = Context>
114  auto geometryInElement() const
115  {
116  if constexpr(isEntity<C>)
117  return Dune::referenceElement(*element_).geometry();
118  else
119  return context_->geometryInInside();
120  }
121 
124  template <class C = Context>
125  auto coordinateInElement(LocalCoordinate const& p) const
126  {
127  if constexpr(isEntity<C>)
128  return p;
129  else
130  return context_->geometryInInside().global(p);
131  }
132 
134  template <class C = Context>
135  auto global(LocalCoordinate const& p) const
136  {
137  return geometry().global(p);
138  }
139 
141  Dune::GeometryType type() const
142  {
143  return context().type();
144  }
145 
147  template <class C = Context>
148  auto integrationElement(LocalCoordinate const& p) const
149  {
150  return geometry().integrationElement(p);
151  }
152 
153  private:
154  Context const* context_;
155  Element const* element_;
156  ElementGeometry const* elementGeometry_;
157  };
158 
159 
160  template <class GV>
162  {
163  public:
164  using GridView = GV;
165  using Element = typename GV::template Codim<0>::Entity;
166  using Geometry = typename Element::Geometry;
167 
168  enum {
169  dim = GridView::dimension, //< the dimension of the grid element
170  dow = GridView::dimensionworld //< the dimension of the world
171  };
172 
174  template <class E, class G>
175  GlobalContext(GV const& gridView, E&& element, G&& geometry)
176  : gridView_(gridView)
177  , element_(Dune::wrap_or_move(FWD(element)))
178  , geometry_(Dune::wrap_or_move(FWD(geometry)))
179  {}
180 
181  public:
183  GridView const& gridView() const
184  {
185  return gridView_;
186  }
187 
189  Element const& element() const
190  {
191  return *element_;
192  }
193 
195  Geometry const& geometry() const
196  {
197  return *geometry_;
198  }
199 
200  private:
201  GridView gridView_;
202  std::shared_ptr<Element const> element_;
203  std::shared_ptr<Geometry const> geometry_;
204  };
205 
206 } // end namespace AMDiS
GridView const & gridView() const
Return the GridView this context is bound to.
Definition: ContextGeometry.hpp:183
Definition: ContextGeometry.hpp:161
Definition: AdaptiveGrid.hpp:393
Element const & element() const
Return the bound element (entity of codim 0)
Definition: ContextGeometry.hpp:91
Definition: FieldMatVec.hpp:12
Definition: AdaptBase.hpp:6
GlobalContext(GV const &gridView, E &&element, G &&geometry)
Constructor. Stores a copy of gridView and a pointer to element and geometry.
Definition: ContextGeometry.hpp:175
Geometry const & geometry() const
Return the geometry of the Element.
Definition: ContextGeometry.hpp:195
auto geometryInElement() const
Return the geometry relative to the element geometry. This can be either an identity, or geometryInInside of the intersection.
Definition: ContextGeometry.hpp:114
ContextGeometry(Context const &context, Element const &element, ElementGeometry const &elementGeo)
Constructor. Stores pointer to localContext, element, and geometry.
Definition: ContextGeometry.hpp:74
Context const & context() const
Return the LocalContext, either the element or an intersection.
Definition: ContextGeometry.hpp:85
auto global(LocalCoordinate const &p) const
Coordinate p given in coordinates inside the context, transformed to coordinate in world space...
Definition: ContextGeometry.hpp:135
Wrapper class for element and geometry.
Definition: ContextGeometry.hpp:48
ElementGeometry const & elementGeometry() const
Return the geometry of the Element.
Definition: ContextGeometry.hpp:97
auto coordinateInElement(LocalCoordinate const &p) const
Definition: ContextGeometry.hpp:125
Dune::GeometryType type() const
Return the geometry-type of the local context.
Definition: ContextGeometry.hpp:141
auto integrationElement(LocalCoordinate const &p) const
The integration element of the context geometry.
Definition: ContextGeometry.hpp:148
Element const & element() const
Return the bound element (entity of codim 0)
Definition: ContextGeometry.hpp:189