Skip to content

Commit

Permalink
[MatL/S] Reuse media creation function; id='*'
Browse files Browse the repository at this point in the history
Reuse previously generalised and extracted functions for media map
creation. This enables also to write <constitutive_relation id='*'>...
in the project file.

The error output has slightly changed.
  • Loading branch information
endJunction committed Oct 14, 2024
1 parent c4dcca1 commit b8407a8
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 36 deletions.
4 changes: 2 additions & 2 deletions MaterialLib/SolidModels/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ get_source_files(SOURCES)

ogs_add_library(MaterialLib_SolidModels ${SOURCES})
target_link_libraries(
MaterialLib_SolidModels PUBLIC MathLib Boost::math PRIVATE ParameterLib
NumLib
MaterialLib_SolidModels PUBLIC MathLib Boost::math
PRIVATE ParameterLib MaterialLib_Utils NumLib
)

if(OGS_USE_MFRONT)
Expand Down
48 changes: 17 additions & 31 deletions MaterialLib/SolidModels/CreateConstitutiveRelationsGeneric.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,47 +40,33 @@ createConstitutiveRelationsGeneric(
for (auto const& constitutive_relation_config :
constitutive_relation_configs)
{
auto create = [&create_constitutive_relation,
&parameters,
&local_coordinate_system,
&constitutive_relation_config](int const /*id*/)
{
return create_constitutive_relation(parameters,
local_coordinate_system,
constitutive_relation_config);
};

auto const material_id_string =
//! \ogs_file_attr{material__solid__constitutive_relation__id}
constitutive_relation_config.getConfigAttribute<std::string>("id",
"0");

auto const material_ids_of_this_constitutive_relation =
MaterialLib::splitMaterialIdString(material_id_string);
MaterialLib::parseMaterialIdString(material_id_string,
material_ids);

auto first_relation_for_material_id = constitutive_relations.end();
for (auto const& material_id :
material_ids_of_this_constitutive_relation)
{
if (constitutive_relations.find(material_id) !=
constitutive_relations.end())
{
OGS_FATAL(
"Multiple constitutive relations were specified for the "
"same material id {:d}. Keep in mind, that if no material "
"id is specified, it is assumed to be 0 by default.",
material_id);
}
if (material_id == material_ids_of_this_constitutive_relation[0])
{
auto [it, insertion_succeeded] = constitutive_relations.emplace(
material_id,
create_constitutive_relation(parameters,
local_coordinate_system,
constitutive_relation_config));
assert(insertion_succeeded);
first_relation_for_material_id = it;
}
else
{
// This constitutive relation has multiple material IDs assigned
// and this is not the first material ID. Therefore we can reuse
// the constitutive relation we created before.
assert(first_relation_for_material_id !=
constitutive_relations.end());
constitutive_relations.emplace(
material_id, first_relation_for_material_id->second);
}
MaterialLib::createMediumForId(
material_id,
constitutive_relations,
material_ids_of_this_constitutive_relation,
create);
}
}

Expand Down
6 changes: 3 additions & 3 deletions ProcessLib/SmallDeformation/Tests.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ if (NOT OGS_USE_MPI)
EXECUTABLE ogs
EXECUTABLE_ARGS -p failcase_duplicate_id_list.xml element_deactivation_M_3D.prj
PROPERTIES
PASS_REGULAR_EXPRESSION "Multiple constitutive relations were specified for the same material id 1."
PASS_REGULAR_EXPRESSION "Multiple media were specified for the same material id '1'."
)
AddTest(
NAME Mechanics_ElementDeactivation3D_failcase_duplicate_id_0
Expand All @@ -32,7 +32,7 @@ if (NOT OGS_USE_MPI)
EXECUTABLE ogs
EXECUTABLE_ARGS -p failcase_duplicate_id_0.xml element_deactivation_M_3D.prj
PROPERTIES
PASS_REGULAR_EXPRESSION "Multiple constitutive relations were specified for the same material id 0."
PASS_REGULAR_EXPRESSION "Multiple media were specified for the same material id '0'."
)
AddTest(
NAME Mechanics_ElementDeactivation3D_failcase_duplicate_id_1
Expand All @@ -41,7 +41,7 @@ if (NOT OGS_USE_MPI)
EXECUTABLE ogs
EXECUTABLE_ARGS -p failcase_duplicate_id_1.xml element_deactivation_M_3D.prj
PROPERTIES
PASS_REGULAR_EXPRESSION "Multiple constitutive relations were specified for the same material id 1."
PASS_REGULAR_EXPRESSION "Multiple media were specified for the same material id '1'."
)
endif()
OgsTest(PROJECTFILE Mechanics/Linear/square_1e5.prj RUNTIME 200)
Expand Down

0 comments on commit b8407a8

Please sign in to comment.