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"
20#include "SourceTerm.h"
21#include "SourceTermConfig.h"
22
23namespace ProcessLib
24{
25std::unique_ptr<SourceTerm> createSourceTerm(
26 const SourceTermConfig& config,
27 const NumLib::LocalToGlobalIndexMap& dof_table_bulk,
28 const MeshLib::Mesh& source_term_mesh, const int variable_id,
29 const unsigned integration_order, const unsigned shapefunction_order,
30 std::vector<std::unique_ptr<ParameterLib::ParameterBase>> const& parameters,
31 [[maybe_unused]] std::vector<std::reference_wrapper<ProcessVariable>> const&
32 all_process_variables_for_this_process)
33{
35 auto const type = config.config.peekConfigParameter<std::string>("type");
36
37 // check basic data consistency
38 if (variable_id >=
39 static_cast<int>(dof_table_bulk.getNumberOfVariables()) ||
40 config.component_id >=
41 dof_table_bulk.getNumberOfVariableComponents(variable_id))
42 {
44 "Variable id or component id too high. Actual values: ({:d}, "
45 "{:d}), maximum values: ({:d}, {:d}).",
46 variable_id, config.component_id,
47 dof_table_bulk.getNumberOfVariables(),
48 dof_table_bulk.getNumberOfVariableComponents(variable_id));
49 }
50
51 if (!source_term_mesh.getProperties()
52 .template existsPropertyVector<std::size_t>(
54 {
56 "The required bulk node ids map does not exist in the source term "
57 "mesh '{:s}'.",
58 source_term_mesh.getName());
59 }
60 std::vector<MeshLib::Node*> const& source_term_nodes =
61 source_term_mesh.getNodes();
62 DBUG(
63 "Found {:d} nodes for source term at mesh '{:s}' for the variable {:d} "
64 "and component {:d}",
65 source_term_nodes.size(), source_term_mesh.getName(), variable_id,
66 config.component_id);
67
68 MeshLib::MeshSubset source_term_mesh_subset(source_term_mesh,
69 source_term_nodes);
70
71 if (type == "Nodal")
72 {
73 auto dof_table_source_term =
74 dof_table_bulk.deriveBoundaryConstrainedMap(
75 variable_id, {config.component_id},
76 std::move(source_term_mesh_subset));
78 config.config, config.mesh, std::move(dof_table_source_term),
79 source_term_mesh.getID(), variable_id, config.component_id,
80 parameters);
81 }
82 if (type == "Anchor")
83 {
84 const int number_of_components =
85 dof_table_bulk.getNumberOfVariableComponents(variable_id);
86 std::vector<int> component_ids(number_of_components);
87 std::iota(std::begin(component_ids), std::end(component_ids), 0);
88 auto dof_table_source_term =
89 dof_table_bulk.deriveBoundaryConstrainedMap(
90 variable_id, component_ids, std::move(source_term_mesh_subset));
91 const int bulk_mesh_dimension =
92 dof_table_bulk.getMeshSubset(variable_id, 0)
93 .getMesh()
94 .getDimension();
95 if (bulk_mesh_dimension != number_of_components)
96 {
98 "For the Anchor source term type,"
99 "the bulk mesh dimension needs to be the same "
100 "as the number of process variable components.");
101 }
102 switch (bulk_mesh_dimension)
103 {
104 case 2:
106 config.config, config.mesh,
107 std::move(dof_table_source_term), source_term_mesh.getID(),
108 variable_id, parameters);
109 case 3:
111 config.config, config.mesh,
112 std::move(dof_table_source_term), source_term_mesh.getID(),
113 variable_id, parameters);
114 default:
115 OGS_FATAL(
116 "Anchor can not be instantiated "
117 "for mesh dimensions other than two or three. "
118 "{}-dimensional mesh was given.",
119 bulk_mesh_dimension);
120 }
121 }
122 if (type == "Line" || type == "Volumetric")
123 {
124 auto dof_table_source_term =
125 dof_table_bulk.deriveBoundaryConstrainedMap(
126 variable_id, {config.component_id},
127 std::move(source_term_mesh_subset));
128 auto const& bulk_mesh_dimension =
129 dof_table_bulk.getMeshSubset(variable_id, config.component_id)
130 .getMesh()
131 .getDimension();
133 config.config, bulk_mesh_dimension, config.mesh,
134 std::move(dof_table_source_term), parameters, integration_order,
135 shapefunction_order);
136 }
137 if (type == "Python")
138 {
139 auto dof_table_source_term =
140 dof_table_bulk.deriveBoundaryConstrainedMap(
141 std::move(source_term_mesh_subset));
142
144 config.config, config.mesh, std::move(dof_table_source_term),
145 variable_id, config.component_id, integration_order,
146 shapefunction_order, source_term_mesh.getDimension(),
147 all_process_variables_for_this_process);
148 }
149
150 OGS_FATAL("Unknown source term type: `{:s}'.", type);
151}
152} // 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:106
unsigned getDimension() const
Returns the dimension of the mesh (determined by the maximum dimension over all elements).
Definition Mesh.h:88
std::size_t getID() const
Get id of the mesh.
Definition Mesh.h:121
Properties & getProperties()
Definition Mesh.h:134
const std::string getName() const
Get name of the mesh.
Definition Mesh.h:103
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:188
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< 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 > 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)
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)
MeshLib::Mesh const & mesh