Skip to content

Commit

Permalink
[PL/ST] Make component id mandatory for source terms
Browse files Browse the repository at this point in the history
  • Loading branch information
chleh committed Nov 21, 2023
1 parent 27546c0 commit 363608c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 14 deletions.
16 changes: 8 additions & 8 deletions ProcessLib/BoundaryConditionAndSourceTerm/CreateSourceTerm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ std::unique_ptr<SourceTerm> createSourceTerm(
// check basic data consistency
if (variable_id >=
static_cast<int>(dof_table_bulk.getNumberOfVariables()) ||
*config.component_id >=
config.component_id >=
dof_table_bulk.getNumberOfVariableComponents(variable_id))
{
OGS_FATAL(
"Variable id or component id too high. Actual values: ({:d}, "
"{:d}), maximum values: ({:d}, {:d}).",
variable_id, *config.component_id,
variable_id, config.component_id,
dof_table_bulk.getNumberOfVariables(),
dof_table_bulk.getNumberOfVariableComponents(variable_id));
}
Expand All @@ -59,7 +59,7 @@ std::unique_ptr<SourceTerm> createSourceTerm(
"Found {:d} nodes for source term at mesh '{:s}' for the variable {:d} "
"and component {:d}",
source_term_nodes.size(), source_term_mesh.getName(), variable_id,
*config.component_id);
config.component_id);

MeshLib::MeshSubset source_term_mesh_subset(source_term_mesh,
source_term_nodes);
Expand All @@ -68,22 +68,22 @@ std::unique_ptr<SourceTerm> createSourceTerm(
{
auto dof_table_source_term =
dof_table_bulk.deriveBoundaryConstrainedMap(
variable_id, {*config.component_id},
variable_id, {config.component_id},
std::move(source_term_mesh_subset));
return ProcessLib::createNodalSourceTerm(
config.config, config.mesh, std::move(dof_table_source_term),
source_term_mesh.getID(), variable_id, *config.component_id,
source_term_mesh.getID(), variable_id, config.component_id,
parameters);
}

if (type == "Line" || type == "Volumetric")
{
auto dof_table_source_term =
dof_table_bulk.deriveBoundaryConstrainedMap(
variable_id, {*config.component_id},
variable_id, {config.component_id},
std::move(source_term_mesh_subset));
auto const& bulk_mesh_dimension =
dof_table_bulk.getMeshSubset(variable_id, *config.component_id)
dof_table_bulk.getMeshSubset(variable_id, config.component_id)
.getMesh()
.getDimension();
return ProcessLib::createVolumetricSourceTerm(
Expand All @@ -100,7 +100,7 @@ std::unique_ptr<SourceTerm> createSourceTerm(

return ProcessLib::createPythonSourceTerm(
config.config, config.mesh, std::move(dof_table_source_term),
variable_id, *config.component_id, integration_order,
variable_id, config.component_id, integration_order,
shapefunction_order, source_term_mesh.getDimension(),
all_process_variables_for_this_process);
}
Expand Down
4 changes: 2 additions & 2 deletions ProcessLib/BoundaryConditionAndSourceTerm/SourceTermConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ struct SourceTermConfig final
{
SourceTermConfig(BaseLib::ConfigTree&& config_,
MeshLib::Mesh const& mesh_,
std::optional<int> const component_id_)
int component_id_)
: config(std::move(config_)), mesh(mesh_), component_id(component_id_)
{
}
Expand All @@ -33,7 +33,7 @@ struct SourceTermConfig final

BaseLib::ConfigTree config;
MeshLib::Mesh const& mesh;
std::optional<int> const component_id;
int component_id;
};

} // namespace ProcessLib
18 changes: 14 additions & 4 deletions ProcessLib/ProcessVariable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,14 +172,24 @@ ProcessVariable::ProcessVariable(
//! \ogs_file_param{prj__process_variables__process_variable__source_terms__source_term__component}
st_config.getConfigParameterOptional<int>("component");

if (!component_id && _n_components == 1)
if (!component_id)
{
// default value for single component vars.
component_id = 0;
if (_n_components == 1)
{
// default value for single component vars.
component_id = 0;
}
else
{
OGS_FATAL(
"Specifying the component id (<component>) for a "
"source term for a non-scalar process variable is "
"mandatory.");
}
}

_source_term_configs.emplace_back(std::move(st_config), st_mesh,
component_id);
*component_id);
}
}
else
Expand Down

0 comments on commit 363608c

Please sign in to comment.