AMDiS  0.3
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/type.hh>
8 
9 namespace AMDiS
10 {
11  namespace Impl
12  {
13  template <class E, class = std::void_t<>>
14  struct ContextTypes
15  {
16  using Entity = E;
17  using LocalGeometry = typename E::Geometry;
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  using LocalGeometry = typename I::LocalGeometry;
26  };
27 
28  } // end namespace Impl
29 
30 
32 
42  template <class LC>
44  {
45  using ContextType = Impl::ContextTypes<LC>;
46 
47  public:
48  using LocalContext = LC;
49  using Element = typename ContextType::Entity;
50  using Geometry = typename Element::Geometry;
51  using LocalGeometry = typename ContextType::LocalGeometry;
52 
53  using IsEntity = std::is_same<Element, LocalContext>;
54 
55  enum {
56  dim = Geometry::mydimension, //< the dimension of the grid element
57  dow = Geometry::coorddimension //< the dimension of the world
58  };
59 
61  ContextGeometry(LocalContext const& localContext, Element const& element, Geometry const& geometry)
62  : localContext_(&localContext)
63  , element_(&element)
64  , geometry_(&geometry)
65  {}
66 
67  public:
69  Element const& element() const
70  {
71  return *element_;
72  }
73 
75  LocalContext const& localContext() const
76  {
77  return *localContext_;
78  }
79 
81  Geometry const& geometry() const
82  {
83  return *geometry_;
84  }
85 
87  LocalGeometry const& localGeometry() const
88  {
89  return localGeometry_impl(IsEntity{});
90  }
91 
92 
93  public:
94 
96  template <class Coordinate>
97  decltype(auto) local(Coordinate const& p) const
98  {
99  return local_impl(p, IsEntity{});
100  }
101 
103  template <class Coordinate>
104  decltype(auto) global(Coordinate const& p) const
105  {
106  return geometry_->global(p);
107  }
108 
110  Dune::GeometryType type() const
111  {
112  return localContext_->type();
113  }
114 
117  template <class Coordinate>
118  auto integrationElement(Coordinate const& p) const
119  {
120  return localGeometry().integrationElement(p);
121  }
122 
123  private: // implementation detail
124 
125  // position for elements
126  template <class Coordinate>
127  Coordinate const& local_impl(Coordinate const& p, std::true_type) const
128  {
129  return p;
130  }
131 
132  // position for intersection
133  template <class Coordinate>
134  auto local_impl(Coordinate const& p, std::false_type) const
135  {
136  return localGeometry().global(p);
137  }
138 
139  // local-geometry is the same as geometry
140  Geometry const& localGeometry_impl(std::true_type) const
141  {
142  return *geometry_;
143  }
144 
145  // local-geometry of intersection in inside element
146  LocalGeometry const& localGeometry_impl(std::false_type) const
147  {
148  if (!localGeometry_)
149  localGeometry_.emplace(localContext_->geometryInInside());
150 
151  return *localGeometry_;
152  }
153 
154  private:
155  LocalContext const* localContext_;
156  Element const* element_;
157  Geometry const* geometry_;
158 
159  // The localGeometry may be constructed only if needed
160  mutable std::optional<LocalGeometry> localGeometry_;
161  };
162 
163 } // end namespace AMDiS
LocalGeometry const & localGeometry() const
Return the geometry of the element, or geometryInInside of the intersection.
Definition: ContextGeometry.hpp:87
Element const & element() const
Return the bound element (entity of codim 0)
Definition: ContextGeometry.hpp:69
Definition: FieldMatVec.hpp:12
Contains all classes needed for solving linear and non linear equation systems.
Definition: AdaptBase.hpp:6
auto integrationElement(Coordinate const &p) const
Definition: ContextGeometry.hpp:118
ContextGeometry(LocalContext const &localContext, Element const &element, Geometry const &geometry)
Constructor. Stores pointer to localContext, element, and geometry.
Definition: ContextGeometry.hpp:61
Geometry const & geometry() const
Return the geometry of the Element.
Definition: ContextGeometry.hpp:81
Wrapper class for element and geometry.
Definition: ContextGeometry.hpp:43
LocalContext const & localContext() const
Return the LocalContext, either the element or an intersection.
Definition: ContextGeometry.hpp:75
Dune::GeometryType type() const
Return the geometry-type of the localContext.
Definition: ContextGeometry.hpp:110