Loading [MathJax]/extensions/tex2jax.js
OGS
CreateSourceTerm.cpp
Go to the documentation of this file.
1
11#include "CreateSourceTerm.h"
12
13#include <cassert>
14#include <numeric>
15
16#include "CreateAnchorTerm.h"
21#include "SourceTerm.h"
22#include "SourceTermConfig.h"
23
24namespace ProcessLib
25{
26std::unique_ptr<SourceTermBase> createSourceTerm(
27 const SourceTermConfig& config,
28 const NumLib::LocalToGlobalIndexMap& dof_table_bulk,
29 const MeshLib::Mesh& source_term_mesh, const int variable_id,
30 const unsigned integration_order, const unsigned shapefunction_order,
31 std::vector<std::unique_ptr<ParameterLib::ParameterBase>> const& parameters,
32 [[maybe_unused]] std::vector<std::reference_wrapper<ProcessVariable>> const&
33 all_process_variables_for_this_process,
34 const MeshLib::Mesh& bulk_mesh)
35{
37 auto const type = config.config.peekConfigParameter<std::string>("type");
38
39 // check basic data consistency
40 if (variable_id >=
41 static_cast<int>(dof_table_bulk.getNumberOfVariables()) ||
42 config.component_id >=
43 dof_table_bulk.getNumberOfVariableComponents(variable_id))
44 {
46 "Variable id or component id too high. Actual values: ({:d}, "
47 "{:d}), maximum values: ({:d}, {:d}).",
48 variable_id, config.component_id,
49 dof_table_bulk.getNumberOfVariables(),
50 dof_table_bulk.getNumberOfVariableComponents(variable_id));
51 }
52
53 if (!source_term_mesh.getProperties()
54 .template existsPropertyVector<std::size_t>(
56 (type != "EmbeddedAnchor"))
57 {
59 "The required bulk node ids map does not exist in the source term "
60 "mesh '{:s}'.",
61 source_term_mesh.getName());
62 }
63 std::vector<MeshLib::Node*> const& source_term_nodes =
64 source_term_mesh.getNodes();
65 DBUG(
66 "Found {:d} nodes for source term at mesh '{:s}' for the variable {:d} "
67 "and component {:d}",
68 source_term_nodes.size(), source_term_mesh.getName(), variable_id,
69 config.component_id);
70
71 MeshLib::MeshSubset source_term_mesh_subset(source_term_mesh,
72 source_term_nodes);
73
74 if (type == "Nodal")
75 {
76 auto dof_table_source_term =
77 dof_table_bulk.deriveBoundaryConstrainedMap(
78 variable_id, {config.component_id},
79 std::move(source_term_mesh_subset));
81 config.config, config.mesh, std::move(dof_table_source_term),
82 source_term_mesh.getID(), variable_id, config.component_id,
83 parameters);
84 }
85 if (type == "Anchor")
86 {
87 const int number_of_components =
88 dof_table_bulk.getNumberOfVariableComponents(variable_id);
89 std::vector<int> component_ids(number_of_components);
90 std::iota(std::begin(component_ids), std::end(component_ids), 0);
91 auto dof_table_source_term =
92 dof_table_bulk.deriveBoundaryConstrainedMap(
93 variable_id, component_ids, std::move(source_term_mesh_subset));
94 const int bulk_mesh_dimension =
95 dof_table_bulk.getMeshSubset(variable_id, 0)
96 .getMesh()
97 .getDimension();
98 if (bulk_mesh_dimension != number_of_components)
99 {
100 OGS_FATAL(
101 "For the Anchor source term type,"
102 "the bulk mesh dimension needs to be the same "
103 "as the number of process variable components.");
104 }
105 switch (bulk_mesh_dimension)
106 {
107 case 2:
109 config.config, config.mesh,
110 std::move(dof_table_source_term), source_term_mesh.getID(),
111 variable_id, parameters);
112 case 3:
114 config.config, config.mesh,
115 std::move(dof_table_source_term), source_term_mesh.getID(),
116 variable_id, parameters);
117 default:
118 OGS_FATAL(
119 "Anchor can not be instantiated "
120 "for mesh dimensions other than two or three. "
121 "{}-dimensional mesh was given.",
122 bulk_mesh_dimension);
123 }
124 }
125 if (type == "EmbeddedAnchor")
126 {
127 const int number_of_components =
128 dof_table_bulk.getNumberOfVariableComponents(variable_id);
129
130 const int bulk_mesh_dimension = bulk_mesh.getDimension();
131 if (bulk_mesh_dimension != number_of_components)
132 {
133 OGS_FATAL(
134 "For the EmbeddedAnchor source term type,"
135 "the bulk mesh dimension needs to be the same "
136 "as the number of process variable components.");
137 }
138 switch (bulk_mesh_dimension)
139 {
140 case 2:
142 config.config, config.mesh, bulk_mesh, dof_table_bulk,
143 source_term_mesh.getID(), variable_id, parameters);
144 case 3:
146 config.config, config.mesh, bulk_mesh, dof_table_bulk,
147 source_term_mesh.getID(), variable_id, parameters);
148 default:
149 OGS_FATAL(
150 "Anchor can not be instantiated "
151 "for mesh dimensions other than two or three. "
152 "{}-dimensional mesh was given.",
153 bulk_mesh_dimension);
154 }
155 }
156 if (type == "Line" || type == "Volumetric")
157 {
158 auto dof_table_source_term =
159 dof_table_bulk.deriveBoundaryConstrainedMap(
160 variable_id, {config.component_id},
161 std::move(source_term_mesh_subset));
162 auto const& bulk_mesh_dimension =
163 dof_table_bulk.getMeshSubset(variable_id, config.component_id)
164 .getMesh()
165 .getDimension();
167 config.config, bulk_mesh_dimension, config.mesh,
168 std::move(dof_table_source_term), parameters, integration_order,
169 shapefunction_order);
170 }
171 if (type == "Python")
172 {
173 auto dof_table_source_term =
174 dof_table_bulk.deriveBoundaryConstrainedMap(
175 std::move(source_term_mesh_subset));
176
178 config.config, config.mesh, std::move(dof_table_source_term),
179 variable_id, config.component_id, integration_order,
180 shapefunction_order, source_term_mesh.getDimension(),
181 all_process_variables_for_this_process);
182 }
183
184 OGS_FATAL("Unknown source term type: `{:s}'.", type);
185}
186} // namespace ProcessLib
#define OGS_FATAL(...)
Definition Error.h:26
void DBUG(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:30
T peekConfigParameter(std::string const &param) const
A subset of nodes on a single mesh.
Definition MeshSubset.h:26
Mesh const & getMesh() const
Definition MeshSubset.h:92
std::vector< Node * > const & getNodes() const
Get the nodes-vector for the mesh.
Definition Mesh.h:108
unsigned getDimension() const
Returns the dimension of the mesh (determined by the maximum dimension over all elements).
Definition Mesh.h:90
std::size_t getID() const
Get id of the mesh.
Definition Mesh.h:123
Properties & getProperties()
Definition Mesh.h:136
const std::string getName() const
Get name of the mesh.
Definition Mesh.h:105
int getNumberOfVariableComponents(int variable_id) const
std::unique_ptr< LocalToGlobalIndexMap > deriveBoundaryConstrainedMap(int const variable_id, std::vector< int > const &component_ids, MeshLib::MeshSubset &&new_mesh_subset) const
MeshLib::MeshSubset const & getMeshSubset(int const variable_id, int const component_id) const
constexpr std::string_view getBulkIDString(MeshItemType mesh_item_type)
Definition Properties.h:185
std::unique_ptr< SourceTerm > createPythonSourceTerm(BaseLib::ConfigTree const &config, MeshLib::Mesh const &source_term_mesh, std::unique_ptr< NumLib::LocalToGlobalIndexMap > dof_table, int const variable_id, int const component_id, unsigned const integration_order, unsigned const shapefunction_order, unsigned const global_dim, std::vector< std::reference_wrapper< ProcessVariable > > const &all_process_variables_for_this_process)
template std::unique_ptr< SourceTermBase > createEmbeddedAnchor< 2 >(BaseLib::ConfigTree const &config, MeshLib::Mesh const &st_mesh, MeshLib::Mesh const &bulk_mesh, NumLib::LocalToGlobalIndexMap const &dof_table_bulk, std::size_t const source_term_mesh_id, const int variable_id, std::vector< std::unique_ptr< ParameterLib::ParameterBase > > const &parameters)
template std::unique_ptr< SourceTerm > createAnchorTerm< 3 >(BaseLib::ConfigTree const &config, MeshLib::Mesh const &st_mesh, std::unique_ptr< NumLib::LocalToGlobalIndexMap > dof_table, std::size_t const source_term_mesh_id, const int variable_id, std::vector< std::unique_ptr< ParameterLib::ParameterBase > > const &parameters)
template std::unique_ptr< SourceTermBase > createEmbeddedAnchor< 3 >(BaseLib::ConfigTree const &config, MeshLib::Mesh const &st_mesh, MeshLib::Mesh const &bulk_mesh, NumLib::LocalToGlobalIndexMap const &dof_table_bulk, std::size_t const source_term_mesh_id, const int variable_id, std::vector< std::unique_ptr< ParameterLib::ParameterBase > > const &parameters)
template std::unique_ptr< SourceTerm > createAnchorTerm< 2 >(BaseLib::ConfigTree const &config, MeshLib::Mesh const &st_mesh, std::unique_ptr< NumLib::LocalToGlobalIndexMap > dof_table, std::size_t const source_term_mesh_id, const int variable_id, std::vector< std::unique_ptr< ParameterLib::ParameterBase > > const &parameters)
std::unique_ptr< SourceTerm > createNodalSourceTerm(BaseLib::ConfigTree const &config, MeshLib::Mesh const &st_mesh, std::unique_ptr< NumLib::LocalToGlobalIndexMap > dof_table, std::size_t const source_term_mesh_id, const int variable_id, const int component_id, std::vector< std::unique_ptr< ParameterLib::ParameterBase > > const &parameters)
std::unique_ptr< SourceTerm > createVolumetricSourceTerm(BaseLib::ConfigTree const &config, unsigned const bulk_mesh_dimension, MeshLib::Mesh const &source_term_mesh, std::unique_ptr< NumLib::LocalToGlobalIndexMap > source_term_dof_table, std::vector< std::unique_ptr< ParameterLib::ParameterBase > > const &parameters, unsigned const integration_order, unsigned const shapefunction_order)
std::unique_ptr< SourceTermBase > createSourceTerm(const SourceTermConfig &config, const NumLib::LocalToGlobalIndexMap &dof_table_bulk, const MeshLib::Mesh &source_term_mesh, const int variable_id, const unsigned integration_order, const unsigned shapefunction_order, std::vector< std::unique_ptr< ParameterLib::ParameterBase > > const &parameters, std::vector< std::reference_wrapper< ProcessVariable > > const &all_process_variables_for_this_process, const MeshLib::Mesh &bulk_mesh)
MeshLib::Mesh const & mesh