OGS
GenericLocalAssemblerFactory.h
Go to the documentation of this file.
1
11#pragma once
12
13#include <functional>
14#include <memory>
15#include <typeindex>
16#include <unordered_map>
17
20
21namespace ProcessLib
22{
29template <typename T>
32 std::same_as<T, NumLib::IntegrationOrder>;
33
36template <typename LocalAssemblerInterface,
37 NumLib::IntegrationMethodProvider IntegrationMethodProvider,
38 typename... ConstructorArgs>
40{
41 using LocAsmIntfPtr = std::unique_ptr<LocalAssemblerInterface>;
42 using LocAsmBuilder = std::function<LocAsmIntfPtr(
43 MeshLib::Element const& e,
44 std::size_t const local_matrix_size,
45 IntegrationMethodProvider const& integration_method_provider,
46 ConstructorArgs&&...)>;
47
48protected: // only allow instances of subclasses
50 NumLib::LocalToGlobalIndexMap const& dof_table,
51 IntegrationMethodProvider const& integration_method_provider)
52 : _dof_table{dof_table},
53 _integration_method_provider{integration_method_provider}
54 {
55 }
56
57public:
63 LocAsmIntfPtr operator()(std::size_t const id,
64 MeshLib::Element const& mesh_item,
65 ConstructorArgs&&... args) const
66 {
67 auto const type_idx = std::type_index(typeid(mesh_item));
68 auto const it = _builders.find(type_idx);
69
70 if (it != _builders.end())
71 {
72 auto const num_local_dof = _dof_table.getNumberOfElementDOF(id);
73 return it->second(mesh_item, num_local_dof,
75 std::forward<ConstructorArgs>(args)...);
76 }
78 "You are trying to build a local assembler for an unknown mesh "
79 "element type ({:s})."
80 " Maybe you have disabled this mesh element type in your build "
81 "configuration, or a mesh element order does not match shape "
82 "function order given in the project file.",
83 type_idx.name());
84 }
85
86private:
88 IntegrationMethodProvider const& _integration_method_provider;
89
90protected:
92 std::unordered_map<std::type_index, LocAsmBuilder> _builders;
93};
94
95template <typename ShapeFunction, typename LocalAssemblerInterface,
96 template <typename /* shp fct */, int /* global dim */>
97 class LocalAssemblerImplementation,
98 NumLib::IntegrationMethodProvider IntegrationMethodProvider,
99 int GlobalDim, typename... ConstructorArgs>
101{
103 LocalAssemblerInterface, IntegrationMethodProvider, ConstructorArgs...>;
106
107 using LocAsmImpl = LocalAssemblerImplementation<ShapeFunction, GlobalDim>;
108
110
111public:
114 template <typename MeshElement>
116 {
117 return [](MeshLib::Element const& e,
118 std::size_t const local_matrix_size,
119 IntegrationMethodProvider const& integration_method_provider,
120 ConstructorArgs&&... args)
121 {
122 auto const& integration_method =
123 integration_method_provider
124 .template getIntegrationMethod<MeshElement>(e);
125
126 static_assert(!std::is_abstract_v<LocAsmImpl>,
127 "The given local assembler implementation is an "
128 "abstract class, which cannot be instantiated. Make "
129 "sure to implement all virtual methods!");
130
131 static_assert(
132 std::is_constructible_v<
133 LocAsmImpl, MeshLib::Element const&, std::size_t,
134 decltype(integration_method), ConstructorArgs&&...>,
135 "The given local assembler implementation is not "
136 "constructible from the provided arguments.");
137
138 return std::make_unique<LocAsmImpl>(
139 e, local_matrix_size, integration_method,
140 std::forward<ConstructorArgs>(args)...);
141 };
142 }
143};
144
145} // namespace ProcessLib
#define OGS_FATAL(...)
Definition Error.h:26
std::size_t getNumberOfElementDOF(std::size_t const mesh_item_id) const
LocalAssemblerImplementation< ShapeFunction, GlobalDim > LocAsmImpl
std::unordered_map< std::type_index, LocAsmBuilder > _builders
Mapping of element types to local assembler builders.
IntegrationMethodProvider const & _integration_method_provider
GenericLocalAssemblerFactory(NumLib::LocalToGlobalIndexMap const &dof_table, IntegrationMethodProvider const &integration_method_provider)
std::function< LocAsmIntfPtr( MeshLib::Element const &e, std::size_t const local_matrix_size, IntegrationMethodProvider const &integration_method_provider, ConstructorArgs &&...)> LocAsmBuilder
NumLib::LocalToGlobalIndexMap const & _dof_table
std::unique_ptr< LocalAssemblerInterface > LocAsmIntfPtr
LocAsmIntfPtr operator()(std::size_t const id, MeshLib::Element const &mesh_item, ConstructorArgs &&... args) const