OGS
HeatTransportBHE/LocalAssemblers/LocalDataInitializer.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) OpenGeoSys Community (opengeosys.org)
2// SPDX-License-Identifier: BSD-3-Clause
3
4#pragma once
5
6#include <functional>
7#include <memory>
8#include <type_traits>
9#include <typeindex>
10#include <typeinfo>
11#include <unordered_map>
12
19
20namespace ProcessLib
21{
22namespace HeatTransportBHE
23{
29template <typename LocalAssemblerInterface,
30 template <typename /* shp fct */> class LocalAssemblerDataSoil,
31 template <typename /* shp fct */,
32 typename /* bhe type */> class LocalAssemblerDataBHE,
33 typename... ConstructorArgs>
35{
36 template <unsigned DIM>
38 {
39 template <typename ElementTraits>
40 constexpr bool operator()(ElementTraits*) const
41 {
42 return ElementTraits::Element::dimension == DIM;
43 }
44 };
45
46public:
47 using LADataIntfPtr = std::unique_ptr<LocalAssemblerInterface>;
48
50 NumLib::LocalToGlobalIndexMap const& dof_table,
51 NumLib::IntegrationOrder const integration_order)
52 : _dof_table(dof_table)
53 {
54 // 3D soil elements
55 using Enabled3DElementTraits =
57 std::declval<IsNDElement<3>>()));
58
60 [this, integration_order]<typename ET>(ET*)
61 {
62 using MeshElement = typename ET::Element;
63 using ShapeFunction = typename ET::ShapeFunction;
64
65 _builder[std::type_index(typeid(MeshElement))] =
67 });
68
69 // 1D BHE elements
70 using Enabled1DElementTraits =
72 std::declval<IsNDElement<1>>()));
73
75 [this, integration_order]<typename ET>(ET*)
76 {
77 using MeshElement = typename ET::Element;
78 using ShapeFunction = typename ET::ShapeFunction;
79
80 _builder[std::type_index(typeid(MeshElement))] =
82 integration_order);
83 });
84 }
85
92 std::size_t const /*id*/,
93 MeshLib::Element const& mesh_item,
94 std::unordered_map<std::size_t, BHE::BHETypes*> const&
95 element_to_bhe_map,
96 ConstructorArgs&&... args) const
97 {
98 auto const type_idx = std::type_index(typeid(mesh_item));
99 auto const it = _builder.find(type_idx);
100
101 if (it == _builder.end())
102 {
103 OGS_FATAL(
104 "You are trying to build a local assembler for an unknown mesh "
105 "element type ({:s})."
106 " Maybe you have disabled this mesh element type in your build "
107 "configuration, or a mesh element order does not match shape "
108 "function order given in the project file.",
109 BaseLib::demangle(type_idx.name()));
110 }
111
112 return it->second(mesh_item,
113 element_to_bhe_map,
114 std::forward<ConstructorArgs>(args)...);
115 }
116
117private:
118 using LADataBuilder = std::function<LADataIntfPtr(
119 MeshLib::Element const& e,
120 std::unordered_map<std::size_t, BHE::BHETypes*> const&
121 element_to_bhe_map,
122 ConstructorArgs&&...)>;
123
124 template <typename ShapeFunction>
126 NumLib::IntegrationOrder const integration_order)
127 {
128 return [integration_order](
129 MeshLib::Element const& e,
130 std::unordered_map<std::size_t, BHE::BHETypes*> const&
131 /* unused */,
132 ConstructorArgs&&... args) -> LADataIntfPtr
133 {
134 auto const& integration_method = NumLib::IntegrationMethodRegistry::
135 template getIntegrationMethod<
136 typename ShapeFunction::MeshElement>(integration_order);
137
138 if (e.getDimension() == 3) // soil elements
139 {
140 return LADataIntfPtr{new LocalAssemblerDataSoil<ShapeFunction>{
141 e, integration_method,
142 std::forward<ConstructorArgs>(args)...}};
143 }
144
145 return nullptr;
146 };
147 }
148
149 template <typename ShapeFunction>
151 NumLib::IntegrationOrder const integration_order)
152 {
153 return [integration_order](
154 MeshLib::Element const& e,
155 std::unordered_map<std::size_t, BHE::BHETypes*> const&
156 element_to_bhe_map,
157 ConstructorArgs&&... args) -> LADataIntfPtr
158 {
159 auto const& integration_method = NumLib::IntegrationMethodRegistry::
160 template getIntegrationMethod<
161 typename ShapeFunction::MeshElement>(integration_order);
162
163 auto& bhe = *element_to_bhe_map.at(e.getID());
164
165 if (std::holds_alternative<BHE::BHE_1U>(bhe))
166 {
167 return LADataIntfPtr{
168 new LocalAssemblerDataBHE<ShapeFunction, BHE::BHE_1U>{
169 e, integration_method, std::get<BHE::BHE_1U>(bhe),
170 std::forward<ConstructorArgs>(args)...}};
171 }
172
173 if (std::holds_alternative<BHE::BHE_CXA>(bhe))
174 {
175 return LADataIntfPtr{
176 new LocalAssemblerDataBHE<ShapeFunction, BHE::BHE_CXA>{
177 e, integration_method, std::get<BHE::BHE_CXA>(bhe),
178 std::forward<ConstructorArgs>(args)...}};
179 }
180
181 if (std::holds_alternative<BHE::BHE_CXC>(bhe))
182 {
183 return LADataIntfPtr{
184 new LocalAssemblerDataBHE<ShapeFunction, BHE::BHE_CXC>{
185 e, integration_method, std::get<BHE::BHE_CXC>(bhe),
186 std::forward<ConstructorArgs>(args)...}};
187 }
188
189 if (std::holds_alternative<BHE::BHE_2U>(bhe))
190 {
191 return LADataIntfPtr{
192 new LocalAssemblerDataBHE<ShapeFunction, BHE::BHE_2U>{
193 e, integration_method, std::get<BHE::BHE_2U>(bhe),
194 std::forward<ConstructorArgs>(args)...}};
195 }
196
197 if (std::holds_alternative<BHE::BHE_1P>(bhe))
198 {
199 return LADataIntfPtr{
200 new LocalAssemblerDataBHE<ShapeFunction, BHE::BHE_1P>{
201 e, integration_method, std::get<BHE::BHE_1P>(bhe),
202 std::forward<ConstructorArgs>(args)...}};
203 }
204 OGS_FATAL(
205 "Trying to create local assembler for an unknown BHE type.");
206 };
207 }
208
210 std::unordered_map<std::type_index, LADataBuilder> _builder;
211
213};
214} // namespace HeatTransportBHE
215} // namespace ProcessLib
#define OGS_FATAL(...)
Definition Error.h:19
virtual constexpr unsigned getDimension() const =0
Get dimension of the mesh element.
std::size_t getID() const
Returns the ID of the element.
Definition Element.h:80
LADataIntfPtr operator()(std::size_t const, MeshLib::Element const &mesh_item, std::unordered_map< std::size_t, BHE::BHETypes * > const &element_to_bhe_map, ConstructorArgs &&... args) const
static LADataBuilder makeLocalAssemblerBuilderBHE(NumLib::IntegrationOrder const integration_order)
std::function< LADataIntfPtr( MeshLib::Element const &e, std::unordered_map< std::size_t, BHE::BHETypes * > const & element_to_bhe_map, ConstructorArgs &&...)> LADataBuilder
static LADataBuilder makeLocalAssemblerBuilder(NumLib::IntegrationOrder const integration_order)
LocalDataInitializer(NumLib::LocalToGlobalIndexMap const &dof_table, NumLib::IntegrationOrder const integration_order)
std::unordered_map< std::type_index, LADataBuilder > _builder
Mapping of element types to local assembler constructors.
void foreach(Function &&f)
Definition TMP.h:150
decltype(auto) filter(Pred pred)
Definition TMP.h:71
std::string demangle(const char *mangled_name)