OGS 6.2.1-97-g73d1aeda3
LocalDataInitializer.h
Go to the documentation of this file.
1 
10 #pragma once
11 
12 #include <functional>
13 #include <memory>
14 #include <type_traits>
15 #include <typeindex>
16 #include <typeinfo>
17 #include <unordered_map>
18 
23 
24 #ifndef OGS_MAX_ELEMENT_DIM
25 static_assert(false, "The macro OGS_MAX_ELEMENT_DIM is undefined.");
26 #endif
27 
28 #ifndef OGS_MAX_ELEMENT_ORDER
29 static_assert(false, "The macro OGS_MAX_ELEMENT_ORDER is undefined.");
30 #endif
31 
32 // The following macros decide which element types will be compiled, i.e.
33 // which element types will be available for use in simulations.
34 
35 #ifdef OGS_ENABLE_ELEMENT_SIMPLEX
36 #define ENABLED_ELEMENT_TYPE_SIMPLEX 1u
37 #else
38 #define ENABLED_ELEMENT_TYPE_SIMPLEX 0u
39 #endif
40 
41 #ifdef OGS_ENABLE_ELEMENT_CUBOID
42 #define ENABLED_ELEMENT_TYPE_CUBOID 1u << 1
43 #else
44 #define ENABLED_ELEMENT_TYPE_CUBOID 0u
45 #endif
46 
47 #ifdef OGS_ENABLE_ELEMENT_PRISM
48 #define ENABLED_ELEMENT_TYPE_PRISM 1u << 2
49 #else
50 #define ENABLED_ELEMENT_TYPE_PRISM 0u
51 #endif
52 
53 #ifdef OGS_ENABLE_ELEMENT_PYRAMID
54 #define ENABLED_ELEMENT_TYPE_PYRAMID 1u << 3
55 #else
56 #define ENABLED_ELEMENT_TYPE_PYRAMID 0u
57 #endif
58 
59 // Dependent element types.
60 // Faces of tets, pyramids and prisms are triangles
61 #define ENABLED_ELEMENT_TYPE_TRI \
62  ((ENABLED_ELEMENT_TYPE_SIMPLEX) | (ENABLED_ELEMENT_TYPE_PYRAMID) | \
63  (ENABLED_ELEMENT_TYPE_PRISM))
64 // Faces of hexes, pyramids and prisms are quads
65 #define ENABLED_ELEMENT_TYPE_QUAD \
66  ((ENABLED_ELEMENT_TYPE_CUBOID) | (ENABLED_ELEMENT_TYPE_PYRAMID) | \
67  (ENABLED_ELEMENT_TYPE_PRISM))
68 
69 // All enabled element types
70 #define OGS_ENABLED_ELEMENTS \
71  ((ENABLED_ELEMENT_TYPE_SIMPLEX) | (ENABLED_ELEMENT_TYPE_CUBOID) | \
72  (ENABLED_ELEMENT_TYPE_PYRAMID) | (ENABLED_ELEMENT_TYPE_PRISM))
73 
74 // Include only what is needed (Well, the conditions are not sharp).
75 #if (OGS_ENABLED_ELEMENTS & ENABLED_ELEMENT_TYPE_SIMPLEX) != 0
78 #endif
79 
80 #if (OGS_ENABLED_ELEMENTS & ENABLED_ELEMENT_TYPE_TRI) != 0
83 #endif
84 
85 #if (OGS_ENABLED_ELEMENTS & ENABLED_ELEMENT_TYPE_CUBOID) != 0
88 #endif
89 
90 #if (OGS_ENABLED_ELEMENTS & ENABLED_ELEMENT_TYPE_QUAD) != 0
94 #endif
95 
96 #if (OGS_ENABLED_ELEMENTS & ENABLED_ELEMENT_TYPE_PRISM) != 0
99 #endif
100 
101 #if (OGS_ENABLED_ELEMENTS & ENABLED_ELEMENT_TYPE_PYRAMID) != 0
104 #endif
105 
106 namespace ProcessLib
107 {
108 namespace HydroMechanics
109 {
119 template <typename LocalAssemblerInterface,
120  template <typename, typename, typename, int>
121  class HydroMechanicsLocalAssembler,
122  int GlobalDim, typename... ConstructorArgs>
124 {
125 public:
126  using LADataIntfPtr = std::unique_ptr<LocalAssemblerInterface>;
127 
129  const unsigned shapefunction_order)
130  : _dof_table(dof_table)
131  {
132  if (shapefunction_order != 2)
133  {
134  OGS_FATAL(
135  "The given shape function order %d is not supported.\nOnly "
136  "shape functions of order 2 are supported.",
137  shapefunction_order);
138  }
139 // /// Quads and Hexahedra ///////////////////////////////////
140 
141 #if (OGS_ENABLED_ELEMENTS & ENABLED_ELEMENT_TYPE_QUAD) != 0 && \
142  OGS_MAX_ELEMENT_DIM >= 2 && OGS_MAX_ELEMENT_ORDER >= 2
143  _builder[std::type_index(typeid(MeshLib::Quad8))] =
144  makeLocalAssemblerBuilder<NumLib::ShapeQuad8>();
145  _builder[std::type_index(typeid(MeshLib::Quad9))] =
146  makeLocalAssemblerBuilder<NumLib::ShapeQuad9>();
147 #endif
148 
149 #if (OGS_ENABLED_ELEMENTS & ENABLED_ELEMENT_TYPE_CUBOID) != 0 && \
150  OGS_MAX_ELEMENT_DIM >= 3 && OGS_MAX_ELEMENT_ORDER >= 2
151  _builder[std::type_index(typeid(MeshLib::Hex20))] =
152  makeLocalAssemblerBuilder<NumLib::ShapeHex20>();
153 #endif
154 
155 // /// Simplices ////////////////////////////////////////////////
156 
157 #if (OGS_ENABLED_ELEMENTS & ENABLED_ELEMENT_TYPE_TRI) != 0 && \
158  OGS_MAX_ELEMENT_DIM >= 2 && OGS_MAX_ELEMENT_ORDER >= 2
159  _builder[std::type_index(typeid(MeshLib::Tri6))] =
160  makeLocalAssemblerBuilder<NumLib::ShapeTri6>();
161 #endif
162 
163 #if (OGS_ENABLED_ELEMENTS & ENABLED_ELEMENT_TYPE_SIMPLEX) != 0 && \
164  OGS_MAX_ELEMENT_DIM >= 3 && OGS_MAX_ELEMENT_ORDER >= 2
165  _builder[std::type_index(typeid(MeshLib::Tet10))] =
166  makeLocalAssemblerBuilder<NumLib::ShapeTet10>();
167 #endif
168 
169 // /// Prisms ////////////////////////////////////////////////////
170 
171 #if (OGS_ENABLED_ELEMENTS & ENABLED_ELEMENT_TYPE_PRISM) != 0 && \
172  OGS_MAX_ELEMENT_DIM >= 3 && OGS_MAX_ELEMENT_ORDER >= 2
173  _builder[std::type_index(typeid(MeshLib::Prism15))] =
174  makeLocalAssemblerBuilder<NumLib::ShapePrism15>();
175 #endif
176 
177 // /// Pyramids //////////////////////////////////////////////////
178 
179 #if (OGS_ENABLED_ELEMENTS & ENABLED_ELEMENT_TYPE_PYRAMID) != 0 && \
180  OGS_MAX_ELEMENT_DIM >= 3 && OGS_MAX_ELEMENT_ORDER >= 2
181  _builder[std::type_index(typeid(MeshLib::Pyramid13))] =
182  makeLocalAssemblerBuilder<NumLib::ShapePyra13>();
183 #endif
184  }
185 
191  void operator()(std::size_t const id,
192  MeshLib::Element const& mesh_item,
193  LADataIntfPtr& data_ptr,
194  ConstructorArgs&&... args) const
195  {
196  auto const type_idx = std::type_index(typeid(mesh_item));
197  auto const it = _builder.find(type_idx);
198 
199  if (it != _builder.end())
200  {
201  auto const num_local_dof = _dof_table.getNumberOfElementDOF(id);
202  data_ptr = it->second(mesh_item, num_local_dof,
203  std::forward<ConstructorArgs>(args)...);
204  }
205  else
206  {
207  OGS_FATAL(
208  "You are trying to build a local assembler for an unknown mesh "
209  "element type (%s)."
210  " Maybe you have disabled this mesh element type in your build "
211  "configuration or this process requires higher order elements.",
212  type_idx.name());
213  }
214  }
215 
216 private:
217  using LADataBuilder =
218  std::function<LADataIntfPtr(MeshLib::Element const& e,
219  std::size_t const local_matrix_size,
220  ConstructorArgs&&...)>;
221 
222  template <typename ShapeFunctionDisplacement>
224  typename ShapeFunctionDisplacement::MeshElement>::IntegrationMethod;
225 
226  template <typename ShapeFunctionDisplacement,
227  typename ShapeFunctionPressure>
228  using LAData = HydroMechanicsLocalAssembler<
229  ShapeFunctionDisplacement, ShapeFunctionPressure,
231 
235  template <typename ShapeFunctionDisplacement>
237  {
238  return makeLocalAssemblerBuilder<ShapeFunctionDisplacement>(
239  static_cast<std::integral_constant<
240  bool, (GlobalDim >= ShapeFunctionDisplacement::DIM)>*>(
241  nullptr));
242  }
243 
245  std::unordered_map<std::type_index, LADataBuilder> _builder;
246 
248 
249  // local assembler builder implementations.
250 private:
257  template <typename ShapeFunctionDisplacement>
258  static LADataBuilder makeLocalAssemblerBuilder(std::true_type* /*unused*/)
259  {
260  // (Lower order elements = Order(ShapeFunctionDisplacement) - 1).
261  using ShapeFunctionPressure =
263  return [](MeshLib::Element const& e,
264  std::size_t const local_matrix_size,
265  ConstructorArgs&&... args) {
266  return LADataIntfPtr{
268  e, local_matrix_size,
269  std::forward<ConstructorArgs>(args)...}};
270  };
271  }
272 
275  template <typename ShapeFunctionDisplacement>
276  static LADataBuilder makeLocalAssemblerBuilder(std::false_type* /*unused*/)
277  {
278  return nullptr;
279  }
280 };
281 
282 } // namespace HydroMechanics
283 } // namespace ProcessLib
284 
285 #undef ENABLED_ELEMENT_TYPE_SIMPLEX
286 #undef ENABLED_ELEMENT_TYPE_CUBOID
287 #undef ENABLED_ELEMENT_TYPE_PYRAMID
288 #undef ENABLED_ELEMENT_TYPE_PRISM
289 #undef ENABLED_ELEMENT_TYPE_TRI
290 #undef ENABLED_ELEMENT_TYPE_QUAD
291 #undef OGS_ENABLED_ELEMENTS
std::unordered_map< std::type_index, LADataBuilder > _builder
Mapping of element types to local assembler constructors.
std::function< LADataIntfPtr(MeshLib::Element const &e, std::size_t const local_matrix_size, ConstructorArgs &&...)> LADataBuilder
std::size_t getNumberOfElementDOF(std::size_t const mesh_item_id) const
static LADataBuilder makeLocalAssemblerBuilder(std::false_type *)
std::unique_ptr< LocalAssemblerInterface > LADataIntfPtr
typename NumLib::GaussLegendreIntegrationPolicy< typename ShapeFunctionDisplacement::MeshElement >::IntegrationMethod IntegrationMethod
LocalDataInitializer(NumLib::LocalToGlobalIndexMap const &dof_table, const unsigned shapefunction_order)
static LADataBuilder makeLocalAssemblerBuilder(std::true_type *)
NumLib::LocalToGlobalIndexMap const & _dof_table
void operator()(std::size_t const id, MeshLib::Element const &mesh_item, LADataIntfPtr &data_ptr, ConstructorArgs &&... args) const
#define OGS_FATAL(fmt,...)
Definition: Error.h:63