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