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 */>
31 class LocalAssemblerDataSoil,
32 template <typename /* shp fct */, typename /* bhe type */>
33 class LocalAssemblerDataBHE,
34 typename... ConstructorArgs>
36{
37 template <unsigned DIM>
39 {
40 template <typename ElementTraits>
41 constexpr bool operator()(ElementTraits*) const
42 {
43 return ElementTraits::Element::dimension == DIM;
44 }
45 };
46
47public:
48 using LADataIntfPtr = std::unique_ptr<LocalAssemblerInterface>;
49
51 NumLib::LocalToGlobalIndexMap const& dof_table,
52 NumLib::IntegrationOrder const integration_order)
53 : _dof_table(dof_table)
54 {
55 // 3D soil elements
56 using Enabled3DElementTraits =
58 std::declval<IsNDElement<3>>()));
59
61 [this, integration_order]<typename ET>(ET*)
62 {
63 using MeshElement = typename ET::Element;
64 using ShapeFunction = typename ET::ShapeFunction;
65
66 _builder[std::type_index(typeid(MeshElement))] =
68 });
69
70 // 1D BHE elements
71 using Enabled1DElementTraits =
73 std::declval<IsNDElement<1>>()));
74
76 [this, integration_order]<typename ET>(ET*)
77 {
78 using MeshElement = typename ET::Element;
79 using ShapeFunction = typename ET::ShapeFunction;
80
81 _builder[std::type_index(typeid(MeshElement))] =
83 integration_order);
84 });
85 }
86
93 std::size_t const /*id*/,
94 MeshLib::Element const& mesh_item,
95 std::unordered_map<std::size_t, BHE::BHETypes*> const&
96 element_to_bhe_map,
97 ConstructorArgs&&... args) const
98 {
99 auto const type_idx = std::type_index(typeid(mesh_item));
100 auto const it = _builder.find(type_idx);
101
102 if (it == _builder.end())
103 {
104 OGS_FATAL(
105 "You are trying to build a local assembler for an unknown mesh "
106 "element type ({:s})."
107 " Maybe you have disabled this mesh element type in your build "
108 "configuration, or a mesh element order does not match shape "
109 "function order given in the project file.",
110 type_idx.name());
111 }
112
113 return it->second(mesh_item,
114 element_to_bhe_map,
115 std::forward<ConstructorArgs>(args)...);
116 }
117
118private:
119 using LADataBuilder = std::function<LADataIntfPtr(
120 MeshLib::Element const& e,
121 std::unordered_map<std::size_t, BHE::BHETypes*> const&
122 element_to_bhe_map,
123 ConstructorArgs&&...)>;
124
125 template <typename ShapeFunction>
127 NumLib::IntegrationOrder const integration_order)
128 {
129 return [integration_order](
130 MeshLib::Element const& e,
131 std::unordered_map<std::size_t, BHE::BHETypes*> const&
132 /* unused */,
133 ConstructorArgs&&... args) -> LADataIntfPtr
134 {
135 auto const& integration_method = NumLib::IntegrationMethodRegistry::
136 template getIntegrationMethod<
137 typename ShapeFunction::MeshElement>(integration_order);
138
139 if (e.getDimension() == 3) // soil elements
140 {
141 return LADataIntfPtr{new LocalAssemblerDataSoil<ShapeFunction>{
142 e, integration_method,
143 std::forward<ConstructorArgs>(args)...}};
144 }
145
146 return nullptr;
147 };
148 }
149
150 template <typename ShapeFunction>
152 NumLib::IntegrationOrder const integration_order)
153 {
154 return [integration_order](
155 MeshLib::Element const& e,
156 std::unordered_map<std::size_t, BHE::BHETypes*> const&
157 element_to_bhe_map,
158 ConstructorArgs&&... args) -> LADataIntfPtr
159 {
160 auto const& integration_method = NumLib::IntegrationMethodRegistry::
161 template getIntegrationMethod<
162 typename ShapeFunction::MeshElement>(integration_order);
163
164 auto& bhe = *element_to_bhe_map.at(e.getID());
165
166 if (std::holds_alternative<BHE::BHE_1U>(bhe))
167 {
168 return LADataIntfPtr{
169 new LocalAssemblerDataBHE<ShapeFunction, BHE::BHE_1U>{
170 e, integration_method, std::get<BHE::BHE_1U>(bhe),
171 std::forward<ConstructorArgs>(args)...}};
172 }
173
174 if (std::holds_alternative<BHE::BHE_CXA>(bhe))
175 {
176 return LADataIntfPtr{
177 new LocalAssemblerDataBHE<ShapeFunction, BHE::BHE_CXA>{
178 e, integration_method, std::get<BHE::BHE_CXA>(bhe),
179 std::forward<ConstructorArgs>(args)...}};
180 }
181
182 if (std::holds_alternative<BHE::BHE_CXC>(bhe))
183 {
184 return LADataIntfPtr{
185 new LocalAssemblerDataBHE<ShapeFunction, BHE::BHE_CXC>{
186 e, integration_method, std::get<BHE::BHE_CXC>(bhe),
187 std::forward<ConstructorArgs>(args)...}};
188 }
189
190 if (std::holds_alternative<BHE::BHE_2U>(bhe))
191 {
192 return LADataIntfPtr{
193 new LocalAssemblerDataBHE<ShapeFunction, BHE::BHE_2U>{
194 e, integration_method, std::get<BHE::BHE_2U>(bhe),
195 std::forward<ConstructorArgs>(args)...}};
196 }
197
198 if (std::holds_alternative<BHE::BHE_1P>(bhe))
199 {
200 return LADataIntfPtr{
201 new LocalAssemblerDataBHE<ShapeFunction, BHE::BHE_1P>{
202 e, integration_method, std::get<BHE::BHE_1P>(bhe),
203 std::forward<ConstructorArgs>(args)...}};
204 }
205 OGS_FATAL(
206 "Trying to create local assembler for an unknown BHE type.");
207 };
208 }
209
211 std::unordered_map<std::type_index, LADataBuilder> _builder;
212
214};
215} // namespace HeatTransportBHE
216} // 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