Skip to content
Snippets Groups Projects
Commit 6a7e53cd authored by Dmitri Naumov's avatar Dmitri Naumov
Browse files

[PL] PV: Extract findMeshInConfig().

Removing most of the code duplication in the BCs/STs creation.
parent 7fb10158
No related branches found
No related tags found
No related merge requests found
......@@ -19,6 +19,59 @@
#include "ProcessLib/SourceTerms/NodalSourceTerm.h"
#include "ProcessLib/Utils/ProcessUtils.h"
namespace
{
MeshLib::Mesh const& findMeshInConfig(
BaseLib::ConfigTree const& config,
std::vector<std::unique_ptr<MeshLib::Mesh>> const& meshes)
{
//
// Get the mesh name from the config.
//
std::string mesh_name; // Either given directly in <mesh> or constructed
// from <geometrical_set>_<geometry>.
auto optional_mesh_name =
//! \ogs_file_param{prj__process_variables__process_variable__boundary_conditions__boundary_condition__mesh}
config.getConfigParameterOptional<std::string>("mesh");
if (optional_mesh_name)
{
mesh_name = *optional_mesh_name;
}
else
{
// Looking for the mesh created before for the given geometry.
auto const geometrical_set_name =
//! \ogs_file_param{prj__process_variables__process_variable__boundary_conditions__boundary_condition__geometrical_set}
config.getConfigParameter<std::string>("geometrical_set");
auto const geometry_name =
//! \ogs_file_param{prj__process_variables__process_variable__boundary_conditions__boundary_condition__geometry}
config.getConfigParameter<std::string>("geometry");
mesh_name = geometrical_set_name + "_" + geometry_name;
}
//
// Find and extract mesh from the list of meshes.
//
auto const mesh_it = std::find_if(
begin(meshes), end(meshes), [&mesh_name](auto const& mesh) {
assert(mesh != nullptr);
return mesh->getName() == mesh_name;
});
if (mesh_it == end(meshes))
{
OGS_FATAL("Required mesh with name '%s' not found.",
mesh_name.c_str());
}
auto const& mesh = **mesh_it;
DBUG("Found mesh '%s' with id %d.", mesh.getName().c_str(), mesh.getID());
return mesh;
}
} // namespace
namespace ProcessLib
{
ProcessVariable::ProcessVariable(
......@@ -51,43 +104,7 @@ ProcessVariable::ProcessVariable(
//! \ogs_file_param{prj__process_variables__process_variable__boundary_conditions__boundary_condition}
bcs_config->getConfigSubtreeList("boundary_condition"))
{
std::string
bc_mesh_name; // Either given directly in <mesh> or constructed
// from <geometrical_set>_<geometry>.
auto optional_bc_mesh_name =
bc_config.getConfigParameterOptional<std::string>("mesh");
if (optional_bc_mesh_name)
{
bc_mesh_name = *optional_bc_mesh_name;
}
else
{
// Looking for the mesh created before for the given geometry.
auto const geometrical_set_name =
//! \ogs_file_param{prj__process_variables__process_variable__boundary_conditions__boundary_condition__geometrical_set}
bc_config.getConfigParameter<std::string>(
"geometrical_set");
auto const geometry_name =
//! \ogs_file_param{prj__process_variables__process_variable__boundary_conditions__boundary_condition__geometry}
bc_config.getConfigParameter<std::string>("geometry");
bc_mesh_name = geometrical_set_name + "_" + geometry_name;
}
auto const mesh_it = std::find_if(
begin(meshes), end(meshes), [&bc_mesh_name](auto const& mesh) {
assert(mesh != nullptr);
return mesh->getName() == bc_mesh_name;
});
if (mesh_it == end(meshes))
{
OGS_FATAL("Required mesh with name '%s' not found.",
bc_mesh_name.c_str());
}
MeshLib::Mesh const& bc_mesh = **mesh_it;
DBUG("Found mesh '%s' with id %d.", bc_mesh.getName().c_str(),
bc_mesh.getID());
auto const& mesh = findMeshInConfig(bc_config, meshes);
auto component_id =
//! \ogs_file_param{prj__process_variables__process_variable__boundary_conditions__boundary_condition__component}
bc_config.getConfigParameterOptional<int>("component");
......@@ -96,8 +113,7 @@ ProcessVariable::ProcessVariable(
// default value for single component vars.
component_id = 0;
_bc_configs.emplace_back(std::move(bc_config), bc_mesh,
component_id);
_bc_configs.emplace_back(std::move(bc_config), mesh, component_id);
}
} else {
INFO("No boundary conditions found.");
......@@ -111,32 +127,7 @@ ProcessVariable::ProcessVariable(
//! \ogs_file_param{prj__process_variables__process_variable__source_terms__source_term}
sts_config->getConfigSubtreeList("source_term"))
{
// TODO (naumov) Remove code duplication with the bc_config parsing.
auto const geometrical_set_name =
//! \ogs_file_param{prj__process_variables__process_variable__source_terms__source_term__geometrical_set}
st_config.getConfigParameter<std::string>("geometrical_set");
auto const geometry_name =
//! \ogs_file_param{prj__process_variables__process_variable__source_terms__source_term__geometry}
st_config.getConfigParameter<std::string>("geometry");
auto const full_geometry_name =
geometrical_set_name + "_" + geometry_name;
auto const mesh_it =
std::find_if(begin(meshes), end(meshes),
[&full_geometry_name](auto const& mesh) {
assert(mesh != nullptr);
return mesh->getName() == full_geometry_name;
});
if (mesh_it == end(meshes))
{
OGS_FATAL("Required mesh with name '%s' not found.",
full_geometry_name.c_str());
}
MeshLib::Mesh const& bc_mesh = **mesh_it;
DBUG("Found mesh '%s' with id %d.", bc_mesh.getName().c_str(),
bc_mesh.getID());
MeshLib::Mesh const& mesh = findMeshInConfig(st_config, meshes);
auto component_id =
//! \ogs_file_param{prj__process_variables__process_variable__source_terms__source_term__component}
st_config.getConfigParameterOptional<int>("component");
......@@ -145,7 +136,7 @@ ProcessVariable::ProcessVariable(
// default value for single component vars.
component_id = 0;
_source_term_configs.emplace_back(std::move(st_config), bc_mesh,
_source_term_configs.emplace_back(std::move(st_config), mesh,
component_id);
}
} else {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment