OGS
CreateSourceTerm.cpp
Go to the documentation of this file.
1 
11 #include "CreateSourceTerm.h"
12 
13 #include "CreateNodalSourceTerm.h"
15 #ifdef OGS_USE_PYTHON
17 #endif
18 #include "SourceTerm.h"
19 #include "SourceTermConfig.h"
20 
21 namespace ProcessLib
22 {
23 std::unique_ptr<SourceTerm> createSourceTerm(
24  const SourceTermConfig& config,
25  const NumLib::LocalToGlobalIndexMap& dof_table_bulk,
26  const MeshLib::Mesh& source_term_mesh, const int variable_id,
27  const unsigned integration_order, const unsigned shapefunction_order,
28  std::vector<std::unique_ptr<ParameterLib::ParameterBase>> const& parameters)
29 {
31  auto const type = config.config.peekConfigParameter<std::string>("type");
32 
33  // check basic data consistency
34  if (variable_id >=
35  static_cast<int>(dof_table_bulk.getNumberOfVariables()) ||
36  *config.component_id >=
37  dof_table_bulk.getNumberOfVariableComponents(variable_id))
38  {
39  OGS_FATAL(
40  "Variable id or component id too high. Actual values: ({:d}, "
41  "{:d}), maximum values: ({:d}, {:d}).",
42  variable_id, *config.component_id,
43  dof_table_bulk.getNumberOfVariables(),
44  dof_table_bulk.getNumberOfVariableComponents(variable_id));
45  }
46 
47  if (!source_term_mesh.getProperties()
48  .template existsPropertyVector<std::size_t>("bulk_node_ids"))
49  {
50  OGS_FATAL(
51  "The required bulk node ids map does not exist in the source term "
52  "mesh '{:s}'.",
53  source_term_mesh.getName());
54  }
55  std::vector<MeshLib::Node*> const& source_term_nodes =
56  source_term_mesh.getNodes();
57  DBUG(
58  "Found {:d} nodes for source term at mesh '{:s}' for the variable {:d} "
59  "and component {:d}",
60  source_term_nodes.size(), source_term_mesh.getName(), variable_id,
61  *config.component_id);
62 
63  MeshLib::MeshSubset source_term_mesh_subset(source_term_mesh,
64  source_term_nodes);
65 
66  if (type == "Nodal")
67  {
68  std::unique_ptr<NumLib::LocalToGlobalIndexMap> dof_table_source_term(
69  dof_table_bulk.deriveBoundaryConstrainedMap(
70  variable_id, {*config.component_id},
71  std::move(source_term_mesh_subset)));
73  config.config, config.mesh, std::move(dof_table_source_term),
74  source_term_mesh.getID(), variable_id, *config.component_id,
75  parameters);
76  }
77 
78  if (type == "Line" || type == "Volumetric")
79  {
80  std::unique_ptr<NumLib::LocalToGlobalIndexMap> dof_table_source_term(
81  dof_table_bulk.deriveBoundaryConstrainedMap(
82  variable_id, {*config.component_id},
83  std::move(source_term_mesh_subset)));
84  auto const& bulk_mesh_dimension =
85  dof_table_bulk.getMeshSubset(variable_id, *config.component_id)
86  .getMesh()
87  .getDimension();
89  config.config, bulk_mesh_dimension, config.mesh,
90  std::move(dof_table_source_term), parameters, integration_order,
91  shapefunction_order);
92  }
93 
94  if (type == "Python")
95  {
96 #ifdef OGS_USE_PYTHON
97  std::unique_ptr<NumLib::LocalToGlobalIndexMap> dof_table_source_term(
98  dof_table_bulk.deriveBoundaryConstrainedMap(
99  std::move(source_term_mesh_subset)));
100 
102  config.config, config.mesh, std::move(dof_table_source_term),
103  variable_id, *config.component_id, integration_order,
104  shapefunction_order, source_term_mesh.getDimension());
105 #else
106  OGS_FATAL("OpenGeoSys has not been built with Python support.");
107 #endif
108  }
109 
110  OGS_FATAL("Unknown source term type: `{:s}'.", type);
111 }
112 } // namespace ProcessLib
#define OGS_FATAL(...)
Definition: Error.h:26
void DBUG(char const *fmt, Args const &... args)
Definition: Logging.h:27
T peekConfigParameter(std::string const &param) const
A subset of nodes on a single mesh.
Definition: MeshSubset.h:27
Mesh const & getMesh() const
Definition: MeshSubset.h:106
std::vector< Node * > const & getNodes() const
Get the nodes-vector for the mesh.
Definition: Mesh.h:95
unsigned getDimension() const
Returns the dimension of the mesh (determined by the maximum dimension over all elements).
Definition: Mesh.h:71
std::size_t getID() const
Get id of the mesh.
Definition: Mesh.h:110
const std::string getName() const
Get name of the mesh.
Definition: Mesh.h:92
Properties & getProperties()
Definition: Mesh.h:123
int getNumberOfVariableComponents(int variable_id) const
MeshLib::MeshSubset const & getMeshSubset(int const variable_id, int const component_id) const
LocalToGlobalIndexMap * deriveBoundaryConstrainedMap(int const variable_id, std::vector< int > const &component_ids, MeshLib::MeshSubset &&new_mesh_subset) const
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::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< 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 > 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)
BaseLib::ConfigTree config
MeshLib::Mesh const & mesh
std::optional< int > const component_id