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{
25template <typename LocalAssemblerInterface, typename... ConstructorArgs>
27{
28 using LocAsmIntfPtr = std::unique_ptr<LocalAssemblerInterface>;
30 std::function<LocAsmIntfPtr(MeshLib::Element const& e,
31 std::size_t const local_matrix_size,
32 ConstructorArgs&&...)>;
33
34protected: // only allow instances of subclasses
36 NumLib::LocalToGlobalIndexMap const& dof_table)
37 : _dof_table(dof_table)
38 {
39 }
40
41public:
47 LocAsmIntfPtr operator()(std::size_t const id,
48 MeshLib::Element const& mesh_item,
49 ConstructorArgs&&... args) const
50 {
51 auto const type_idx = std::type_index(typeid(mesh_item));
52 auto const it = _builders.find(type_idx);
53
54 if (it != _builders.end())
55 {
56 auto const num_local_dof = _dof_table.getNumberOfElementDOF(id);
57 return it->second(mesh_item, num_local_dof,
58 std::forward<ConstructorArgs>(args)...);
59 }
61 "You are trying to build a local assembler for an unknown mesh "
62 "element type ({:s})."
63 " Maybe you have disabled this mesh element type in your build "
64 "configuration, or a mesh element order does not match shape "
65 "function order given in the project file.",
66 type_idx.name());
67 }
68
69private:
71
72protected:
74 std::unordered_map<std::type_index, LocAsmBuilder> _builders;
75};
76
77template <typename ShapeFunction, typename LocalAssemblerInterface,
78 template <typename /* shp fct */, typename /* int meth */,
79 int /* global dim */>
80 class LocalAssemblerImplementation,
81 int GlobalDim, typename... ConstructorArgs>
83{
85 ConstructorArgs...>;
88
90 typename ShapeFunction::MeshElement>::IntegrationMethod;
91
92 using LocAsmImpl =
93 LocalAssemblerImplementation<ShapeFunction, IntegrationMethod,
94 GlobalDim>;
95
97
98public:
102 {
103 return [](MeshLib::Element const& e,
104 std::size_t const local_matrix_size,
105 ConstructorArgs&&... args)
106 {
107 return std::make_unique<LocAsmImpl>(
108 e, local_matrix_size, std::forward<ConstructorArgs>(args)...);
109 };
110 }
111};
112
113} // namespace ProcessLib
#define OGS_FATAL(...)
Definition: Error.h:26
std::size_t getNumberOfElementDOF(std::size_t const mesh_item_id) const
LocalAssemblerImplementation< ShapeFunction, IntegrationMethod, GlobalDim > LocAsmImpl
typename NumLib::GaussLegendreIntegrationPolicy< typename ShapeFunction::MeshElement >::IntegrationMethod IntegrationMethod
LocAsmIntfPtr operator()(std::size_t const id, MeshLib::Element const &mesh_item, ConstructorArgs &&... args) const
NumLib::LocalToGlobalIndexMap const & _dof_table
GenericLocalAssemblerFactory(NumLib::LocalToGlobalIndexMap const &dof_table)
std::unordered_map< std::type_index, LocAsmBuilder > _builders
Mapping of element types to local assembler builders.
std::unique_ptr< LocalAssemblerInterface > LocAsmIntfPtr
std::function< LocAsmIntfPtr(MeshLib::Element const &e, std::size_t const local_matrix_size, ConstructorArgs &&...)> LocAsmBuilder