From 27546c0f4ca687993024d30ed078d60c3d361557 Mon Sep 17 00:00:00 2001 From: Christoph Lehmann Date: Tue, 21 Nov 2023 14:28:48 +0100 Subject: [PATCH 1/2] [PL/BC] Added a check for the presence of the component --- .../CreateBoundaryCondition.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/ProcessLib/BoundaryConditionAndSourceTerm/CreateBoundaryCondition.cpp b/ProcessLib/BoundaryConditionAndSourceTerm/CreateBoundaryCondition.cpp index 4191dba25f2..2f25857fe25 100644 --- a/ProcessLib/BoundaryConditionAndSourceTerm/CreateBoundaryCondition.cpp +++ b/ProcessLib/BoundaryConditionAndSourceTerm/CreateBoundaryCondition.cpp @@ -54,6 +54,15 @@ std::unique_ptr createBoundaryCondition( //! \ogs_file_param{prj__process_variables__process_variable__boundary_conditions__boundary_condition__type} auto const type = config.config.peekConfigParameter("type"); + if (bool const component_id_required = type != "NormalTraction"; + component_id_required && !config.component_id.has_value()) + { + OGS_FATAL( + "Specifying the component id () for a boundary " + "condition of type {} is mandatory.", + type); + } + if (type == "Dirichlet") { return ProcessLib::createDirichletBoundaryCondition( From 363608c79db28c62e2c5dd708cc9b509037eb340 Mon Sep 17 00:00:00 2001 From: Christoph Lehmann Date: Tue, 21 Nov 2023 14:50:55 +0100 Subject: [PATCH 2/2] [PL/ST] Make component id mandatory for source terms --- .../CreateSourceTerm.cpp | 16 ++++++++-------- .../SourceTermConfig.h | 4 ++-- ProcessLib/ProcessVariable.cpp | 18 ++++++++++++++---- 3 files changed, 24 insertions(+), 14 deletions(-) diff --git a/ProcessLib/BoundaryConditionAndSourceTerm/CreateSourceTerm.cpp b/ProcessLib/BoundaryConditionAndSourceTerm/CreateSourceTerm.cpp index 7850fa9e4cb..2ae9b5628f3 100644 --- a/ProcessLib/BoundaryConditionAndSourceTerm/CreateSourceTerm.cpp +++ b/ProcessLib/BoundaryConditionAndSourceTerm/CreateSourceTerm.cpp @@ -33,13 +33,13 @@ std::unique_ptr createSourceTerm( // check basic data consistency if (variable_id >= static_cast(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)); } @@ -59,7 +59,7 @@ std::unique_ptr 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); @@ -68,11 +68,11 @@ std::unique_ptr 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); } @@ -80,10 +80,10 @@ std::unique_ptr 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)); 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( @@ -100,7 +100,7 @@ std::unique_ptr 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); } diff --git a/ProcessLib/BoundaryConditionAndSourceTerm/SourceTermConfig.h b/ProcessLib/BoundaryConditionAndSourceTerm/SourceTermConfig.h index 60f7cb28549..170ee89a602 100644 --- a/ProcessLib/BoundaryConditionAndSourceTerm/SourceTermConfig.h +++ b/ProcessLib/BoundaryConditionAndSourceTerm/SourceTermConfig.h @@ -19,7 +19,7 @@ struct SourceTermConfig final { SourceTermConfig(BaseLib::ConfigTree&& config_, MeshLib::Mesh const& mesh_, - std::optional const component_id_) + int component_id_) : config(std::move(config_)), mesh(mesh_), component_id(component_id_) { } @@ -33,7 +33,7 @@ struct SourceTermConfig final BaseLib::ConfigTree config; MeshLib::Mesh const& mesh; - std::optional const component_id; + int component_id; }; } // namespace ProcessLib diff --git a/ProcessLib/ProcessVariable.cpp b/ProcessLib/ProcessVariable.cpp index b7d0d58c9c5..2ae57236f49 100644 --- a/ProcessLib/ProcessVariable.cpp +++ b/ProcessLib/ProcessVariable.cpp @@ -172,14 +172,24 @@ ProcessVariable::ProcessVariable( //! \ogs_file_param{prj__process_variables__process_variable__source_terms__source_term__component} st_config.getConfigParameterOptional("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 () 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