From c2f6e483b4841cfdeaee98a28753bebe9f3cecfe Mon Sep 17 00:00:00 2001 From: Florian Zill Date: Tue, 1 Oct 2024 14:08:10 +0200 Subject: [PATCH 1/6] Enable list input for id of constitutive relations --- .../CreateConstitutiveRelation.cpp | 6 +- .../SolidModels/CreateConstitutiveRelation.h | 6 +- .../CreateConstitutiveRelationsGeneric.h | 58 +++++++++++++------ ...olidMaterialInternalToSecondaryVariables.h | 8 +-- .../HydroMechanicsProcessData.h | 2 +- .../HydroMechanicsProcessData.h | 2 +- .../SmallDeformationProcessData.h | 5 +- .../CreateConstitutiveSetting.cpp | 2 +- .../CreateConstitutiveSetting.h | 2 +- .../LargeDeformationProcessData.h | 2 +- ProcessLib/PhaseField/PhaseFieldProcessData.h | 2 +- .../CreateConstitutiveSetting.cpp | 2 +- .../CreateConstitutiveSetting.h | 2 +- .../RichardsMechanicsProcessData.h | 2 +- .../CreateConstitutiveSetting.cpp | 2 +- .../CreateConstitutiveSetting.h | 2 +- .../SmallDeformationProcessData.h | 2 +- .../SmallDeformationNonlocalProcessData.h | 2 +- ProcessLib/TH2M/TH2MProcessData.h | 2 +- .../ThermoHydroMechanicsProcessData.h | 4 +- .../ThermoMechanicalPhaseFieldProcessData.h | 2 +- .../ThermoMechanicsProcessData.h | 2 +- .../CreateConstitutiveSetting.cpp | 2 +- .../CreateConstitutiveSetting.h | 2 +- .../CreateConstitutiveSetting.cpp | 2 +- .../CreateConstitutiveSetting.h | 2 +- .../ThermoRichardsMechanicsProcessData.h | 2 +- 27 files changed, 76 insertions(+), 53 deletions(-) diff --git a/MaterialLib/SolidModels/CreateConstitutiveRelation.cpp b/MaterialLib/SolidModels/CreateConstitutiveRelation.cpp index 8e9d6c8f8af..5f1e32f610f 100644 --- a/MaterialLib/SolidModels/CreateConstitutiveRelation.cpp +++ b/MaterialLib/SolidModels/CreateConstitutiveRelation.cpp @@ -106,7 +106,7 @@ createConstitutiveRelation( template std::map>> + std::shared_ptr>> createConstitutiveRelations( std::vector> const& parameters, std::optional const& @@ -121,14 +121,14 @@ createConstitutiveRelations( createConstitutiveRelation); } -template std::map>> +template std::map>> createConstitutiveRelations<2>( std::vector> const& parameters, std::optional const& local_coordinate_system, BaseLib::ConfigTree const& config); -template std::map>> +template std::map>> createConstitutiveRelations<3>( std::vector> const& parameters, std::optional const& diff --git a/MaterialLib/SolidModels/CreateConstitutiveRelation.h b/MaterialLib/SolidModels/CreateConstitutiveRelation.h index 7ebf6bead0c..4bb1a10ff4b 100644 --- a/MaterialLib/SolidModels/CreateConstitutiveRelation.h +++ b/MaterialLib/SolidModels/CreateConstitutiveRelation.h @@ -58,7 +58,7 @@ createConstitutiveRelation( template std::map>> + std::shared_ptr>> createConstitutiveRelations( std::vector> const& parameters, std::optional const& @@ -66,7 +66,7 @@ createConstitutiveRelations( BaseLib::ConfigTree const& config); extern template std::map>> + std::shared_ptr>> createConstitutiveRelations<2>( std::vector> const& parameters, std::optional const& @@ -74,7 +74,7 @@ createConstitutiveRelations<2>( BaseLib::ConfigTree const& config); extern template std::map>> + std::shared_ptr>> createConstitutiveRelations<3>( std::vector> const& parameters, std::optional const& diff --git a/MaterialLib/SolidModels/CreateConstitutiveRelationsGeneric.h b/MaterialLib/SolidModels/CreateConstitutiveRelationsGeneric.h index 2db9552ed71..9b6e7c72207 100644 --- a/MaterialLib/SolidModels/CreateConstitutiveRelationsGeneric.h +++ b/MaterialLib/SolidModels/CreateConstitutiveRelationsGeneric.h @@ -11,12 +11,13 @@ #pragma once #include "BaseLib/ConfigTree.h" +#include "BaseLib/StringTools.h" #include "ParameterLib/Parameter.h" namespace MaterialLib::Solids { template -std::map> +std::map> createConstitutiveRelationsGeneric( std::vector> const& parameters, std::optional const& @@ -31,31 +32,54 @@ createConstitutiveRelationsGeneric( //! \ogs_file_param{material__solid__constitutive_relation} config.getConfigSubtreeList("constitutive_relation"); - std::map> + std::map> constitutive_relations; for (auto const& constitutive_relation_config : constitutive_relation_configs) { - int const material_id = + auto const material_id_string = //! \ogs_file_attr{material__solid__constitutive_relation__id} - constitutive_relation_config.getConfigAttribute("id", 0); + constitutive_relation_config.getConfigAttribute("id", + "0"); - if (constitutive_relations.find(material_id) != - constitutive_relations.end()) + auto const material_ids_of_this_constitutive_relation = + BaseLib::splitMaterialIdString(material_id_string); + + auto first_relation_for_material_id = constitutive_relations.end(); + for (auto const& material_id : + material_ids_of_this_constitutive_relation) { - 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 (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); + } } - - constitutive_relations.emplace( - material_id, - create_constitutive_relation(parameters, - local_coordinate_system, - constitutive_relation_config)); } DBUG("Found {:d} constitutive relations.", constitutive_relations.size()); diff --git a/ProcessLib/Deformation/SolidMaterialInternalToSecondaryVariables.h b/ProcessLib/Deformation/SolidMaterialInternalToSecondaryVariables.h index 7429d7f8c8f..f09e609f89d 100644 --- a/ProcessLib/Deformation/SolidMaterialInternalToSecondaryVariables.h +++ b/ProcessLib/Deformation/SolidMaterialInternalToSecondaryVariables.h @@ -25,7 +25,7 @@ template std::map>> collectInternalVariables( - std::map> const& solid_materials) + std::map> const& solid_materials) { assert(!solid_materials.empty()); @@ -107,7 +107,7 @@ InternalVariablesCollection(std::vector&&, int, bool) template void forEachSolidMaterialInternalVariable( - std::map> const& solid_materials, + std::map> const& solid_materials, auto const& function) { auto internal_variables_by_name = collectInternalVariables(solid_materials); @@ -202,7 +202,7 @@ class CollectIntegrationPointDataForExtrapolation final template void solidMaterialInternalToSecondaryVariables( - std::map> const& solid_materials, + std::map> const& solid_materials, AddSecondaryVariableCallback const& add_secondary_variable) { auto register_secondary_variable = @@ -261,7 +261,7 @@ class CollectIntegrationPointDataForIpWriter final template void solidMaterialInternalVariablesToIntegrationPointWriter( - std::map> const& solid_materials, + std::map> const& solid_materials, std::vector> const& local_assemblers, std::vector>& diff --git a/ProcessLib/HydroMechanics/HydroMechanicsProcessData.h b/ProcessLib/HydroMechanics/HydroMechanicsProcessData.h index 961a971b233..5b530e0162c 100644 --- a/ProcessLib/HydroMechanics/HydroMechanicsProcessData.h +++ b/ProcessLib/HydroMechanics/HydroMechanicsProcessData.h @@ -66,7 +66,7 @@ struct HydroMechanicsProcessData MaterialPropertyLib::MaterialSpatialDistributionMap media_map; /// The constitutive relation for the mechanical part. - std::map>> solid_materials; diff --git a/ProcessLib/LIE/HydroMechanics/HydroMechanicsProcessData.h b/ProcessLib/LIE/HydroMechanics/HydroMechanicsProcessData.h index 253170eef48..09d0e506b27 100644 --- a/ProcessLib/LIE/HydroMechanics/HydroMechanicsProcessData.h +++ b/ProcessLib/LIE/HydroMechanics/HydroMechanicsProcessData.h @@ -36,7 +36,7 @@ struct HydroMechanicsProcessData { MeshLib::PropertyVector const* const material_ids; std::map>> + std::shared_ptr>> solid_materials; ParameterLib::Parameter const& intrinsic_permeability; ParameterLib::Parameter const& specific_storage; diff --git a/ProcessLib/LIE/SmallDeformation/SmallDeformationProcessData.h b/ProcessLib/LIE/SmallDeformation/SmallDeformationProcessData.h index 34a2cd3f2c8..361e732fbe5 100644 --- a/ProcessLib/LIE/SmallDeformation/SmallDeformationProcessData.h +++ b/ProcessLib/LIE/SmallDeformation/SmallDeformationProcessData.h @@ -35,9 +35,8 @@ struct SmallDeformationProcessData MeshLib::PropertyVector const* const material_ids; /// The constitutive relation for the mechanical part. - std::map< - int, - std::unique_ptr>> + std::map>> solid_materials; std::unique_ptr> diff --git a/ProcessLib/LargeDeformation/ConstitutiveRelations/CreateConstitutiveSetting.cpp b/ProcessLib/LargeDeformation/ConstitutiveRelations/CreateConstitutiveSetting.cpp index a594500d2ae..321506ff96e 100644 --- a/ProcessLib/LargeDeformation/ConstitutiveRelations/CreateConstitutiveSetting.cpp +++ b/ProcessLib/LargeDeformation/ConstitutiveRelations/CreateConstitutiveSetting.cpp @@ -33,7 +33,7 @@ std::unique_ptr> createMFrontGeneric( } template -std::map>> +std::map>> CreateConstitutiveSetting::createSolidConstitutiveRelations( std::vector> const& parameters, std::optional const& diff --git a/ProcessLib/LargeDeformation/ConstitutiveRelations/CreateConstitutiveSetting.h b/ProcessLib/LargeDeformation/ConstitutiveRelations/CreateConstitutiveSetting.h index 3f294623a18..c7f0b2247f1 100644 --- a/ProcessLib/LargeDeformation/ConstitutiveRelations/CreateConstitutiveSetting.h +++ b/ProcessLib/LargeDeformation/ConstitutiveRelations/CreateConstitutiveSetting.h @@ -19,7 +19,7 @@ template struct CreateConstitutiveSetting { static std::map>> + std::shared_ptr>> createSolidConstitutiveRelations( std::vector> const& parameters, diff --git a/ProcessLib/LargeDeformation/LargeDeformationProcessData.h b/ProcessLib/LargeDeformation/LargeDeformationProcessData.h index 5c989e98e88..c9757b19264 100644 --- a/ProcessLib/LargeDeformation/LargeDeformationProcessData.h +++ b/ProcessLib/LargeDeformation/LargeDeformationProcessData.h @@ -38,7 +38,7 @@ struct LargeDeformationProcessData MaterialPropertyLib::MaterialSpatialDistributionMap media_map; std::map>> solid_materials; diff --git a/ProcessLib/PhaseField/PhaseFieldProcessData.h b/ProcessLib/PhaseField/PhaseFieldProcessData.h index 21cc7e38a9c..f8123a02e82 100644 --- a/ProcessLib/PhaseField/PhaseFieldProcessData.h +++ b/ProcessLib/PhaseField/PhaseFieldProcessData.h @@ -204,7 +204,7 @@ struct PhaseFieldProcessData std::map< int, - std::unique_ptr>> + std::shared_ptr>> solid_materials; ParameterLib::Parameter const& residual_stiffness; ParameterLib::Parameter const& crack_resistance; diff --git a/ProcessLib/RichardsMechanics/ConstitutiveRelations/CreateConstitutiveSetting.cpp b/ProcessLib/RichardsMechanics/ConstitutiveRelations/CreateConstitutiveSetting.cpp index 5ed1a9226ea..8accb9ef08e 100644 --- a/ProcessLib/RichardsMechanics/ConstitutiveRelations/CreateConstitutiveSetting.cpp +++ b/ProcessLib/RichardsMechanics/ConstitutiveRelations/CreateConstitutiveSetting.cpp @@ -16,7 +16,7 @@ namespace ProcessLib::RichardsMechanics { template std::map>> + std::shared_ptr>> CreateConstitutiveSetting::createSolidConstitutiveRelations( std::vector> const& parameters, std::optional const& diff --git a/ProcessLib/RichardsMechanics/ConstitutiveRelations/CreateConstitutiveSetting.h b/ProcessLib/RichardsMechanics/ConstitutiveRelations/CreateConstitutiveSetting.h index 3a1d56fb416..d81b1d01206 100644 --- a/ProcessLib/RichardsMechanics/ConstitutiveRelations/CreateConstitutiveSetting.h +++ b/ProcessLib/RichardsMechanics/ConstitutiveRelations/CreateConstitutiveSetting.h @@ -22,7 +22,7 @@ struct CreateConstitutiveSetting { static std::map< int, - std::unique_ptr>> + std::shared_ptr>> createSolidConstitutiveRelations( std::vector> const& parameters, diff --git a/ProcessLib/RichardsMechanics/RichardsMechanicsProcessData.h b/ProcessLib/RichardsMechanics/RichardsMechanicsProcessData.h index d237ed6c01c..f4e5b8a5a7f 100644 --- a/ProcessLib/RichardsMechanics/RichardsMechanicsProcessData.h +++ b/ProcessLib/RichardsMechanics/RichardsMechanicsProcessData.h @@ -39,7 +39,7 @@ struct RichardsMechanicsProcessData MaterialPropertyLib::MaterialSpatialDistributionMap media_map; /// The constitutive relation for the mechanical part. - std::map>> solid_materials; diff --git a/ProcessLib/SmallDeformation/ConstitutiveRelations/CreateConstitutiveSetting.cpp b/ProcessLib/SmallDeformation/ConstitutiveRelations/CreateConstitutiveSetting.cpp index ddbd3aa06d0..d80e2be64ed 100644 --- a/ProcessLib/SmallDeformation/ConstitutiveRelations/CreateConstitutiveSetting.cpp +++ b/ProcessLib/SmallDeformation/ConstitutiveRelations/CreateConstitutiveSetting.cpp @@ -16,7 +16,7 @@ namespace ProcessLib::SmallDeformation namespace ConstitutiveRelations { template -std::map>> +std::map>> CreateConstitutiveSetting::createSolidConstitutiveRelations( std::vector> const& parameters, std::optional const& diff --git a/ProcessLib/SmallDeformation/ConstitutiveRelations/CreateConstitutiveSetting.h b/ProcessLib/SmallDeformation/ConstitutiveRelations/CreateConstitutiveSetting.h index a8d8f8567b1..0f434a3d9f6 100644 --- a/ProcessLib/SmallDeformation/ConstitutiveRelations/CreateConstitutiveSetting.h +++ b/ProcessLib/SmallDeformation/ConstitutiveRelations/CreateConstitutiveSetting.h @@ -34,7 +34,7 @@ template struct CreateConstitutiveSetting { static std::map>> + std::shared_ptr>> createSolidConstitutiveRelations( std::vector> const& parameters, diff --git a/ProcessLib/SmallDeformation/SmallDeformationProcessData.h b/ProcessLib/SmallDeformation/SmallDeformationProcessData.h index 0a87a472e4e..3a26b17f482 100644 --- a/ProcessLib/SmallDeformation/SmallDeformationProcessData.h +++ b/ProcessLib/SmallDeformation/SmallDeformationProcessData.h @@ -36,7 +36,7 @@ struct SmallDeformationProcessData MaterialPropertyLib::MaterialSpatialDistributionMap media_map; - std::map>> solid_materials; diff --git a/ProcessLib/SmallDeformationNonlocal/SmallDeformationNonlocalProcessData.h b/ProcessLib/SmallDeformationNonlocal/SmallDeformationNonlocalProcessData.h index 3347db71201..e3b443105b7 100644 --- a/ProcessLib/SmallDeformationNonlocal/SmallDeformationNonlocalProcessData.h +++ b/ProcessLib/SmallDeformationNonlocal/SmallDeformationNonlocalProcessData.h @@ -31,7 +31,7 @@ struct SmallDeformationNonlocalProcessData { MeshLib::PropertyVector const* const material_ids = nullptr; - std::map>> solid_materials; /// Solid's density. A scalar quantity, ParameterLib::Parameter. diff --git a/ProcessLib/TH2M/TH2MProcessData.h b/ProcessLib/TH2M/TH2MProcessData.h index e23f42d8cff..5a40e269bfd 100644 --- a/ProcessLib/TH2M/TH2MProcessData.h +++ b/ProcessLib/TH2M/TH2MProcessData.h @@ -32,7 +32,7 @@ struct TH2MProcessData MaterialPropertyLib::MaterialSpatialDistributionMap media_map; /// The constitutive relation for the mechanical part. - std::map>> solid_materials; diff --git a/ProcessLib/ThermoHydroMechanics/ThermoHydroMechanicsProcessData.h b/ProcessLib/ThermoHydroMechanics/ThermoHydroMechanicsProcessData.h index 66f22c3c422..31fdff5416a 100644 --- a/ProcessLib/ThermoHydroMechanics/ThermoHydroMechanicsProcessData.h +++ b/ProcessLib/ThermoHydroMechanics/ThermoHydroMechanicsProcessData.h @@ -39,13 +39,13 @@ struct ThermoHydroMechanicsProcessData MaterialPropertyLib::MaterialSpatialDistributionMap media_map; /// The constitutive relation for the mechanical part. - std::map>> solid_materials; /// The constitutive relation for the mechanical part of ice. When no /// freezing is configured, this is a nullptr. - std::unique_ptr> + std::shared_ptr> ice_constitutive_relation; InitialStress const initial_stress; diff --git a/ProcessLib/ThermoMechanicalPhaseField/ThermoMechanicalPhaseFieldProcessData.h b/ProcessLib/ThermoMechanicalPhaseField/ThermoMechanicalPhaseFieldProcessData.h index 699295eef65..c8e3b652443 100644 --- a/ProcessLib/ThermoMechanicalPhaseField/ThermoMechanicalPhaseFieldProcessData.h +++ b/ProcessLib/ThermoMechanicalPhaseField/ThermoMechanicalPhaseFieldProcessData.h @@ -34,7 +34,7 @@ struct ThermoMechanicalPhaseFieldProcessData { MeshLib::PropertyVector const* const material_ids = nullptr; - std::map>> solid_materials; ParameterLib::Parameter const& residual_stiffness; diff --git a/ProcessLib/ThermoMechanics/ThermoMechanicsProcessData.h b/ProcessLib/ThermoMechanics/ThermoMechanicsProcessData.h index 743ea017a92..9117f393c01 100644 --- a/ProcessLib/ThermoMechanics/ThermoMechanicsProcessData.h +++ b/ProcessLib/ThermoMechanics/ThermoMechanicsProcessData.h @@ -37,7 +37,7 @@ struct ThermoMechanicsProcessData MaterialPropertyLib::MaterialSpatialDistributionMap media_map; /// The constitutive relation for the mechanical part. - std::map>> solid_materials; diff --git a/ProcessLib/ThermoRichardsMechanics/ConstitutiveStressSaturation_StrainPressureTemperature/CreateConstitutiveSetting.cpp b/ProcessLib/ThermoRichardsMechanics/ConstitutiveStressSaturation_StrainPressureTemperature/CreateConstitutiveSetting.cpp index 208056cb771..a465e1af4bc 100644 --- a/ProcessLib/ThermoRichardsMechanics/ConstitutiveStressSaturation_StrainPressureTemperature/CreateConstitutiveSetting.cpp +++ b/ProcessLib/ThermoRichardsMechanics/ConstitutiveStressSaturation_StrainPressureTemperature/CreateConstitutiveSetting.cpp @@ -34,7 +34,7 @@ std::unique_ptr> createMFrontGeneric( } template -std::map>> +std::map>> CreateConstitutiveSetting::createSolidConstitutiveRelations( std::vector> const& parameters, std::optional const& diff --git a/ProcessLib/ThermoRichardsMechanics/ConstitutiveStressSaturation_StrainPressureTemperature/CreateConstitutiveSetting.h b/ProcessLib/ThermoRichardsMechanics/ConstitutiveStressSaturation_StrainPressureTemperature/CreateConstitutiveSetting.h index 4d244186f85..ff7a701aa7f 100644 --- a/ProcessLib/ThermoRichardsMechanics/ConstitutiveStressSaturation_StrainPressureTemperature/CreateConstitutiveSetting.h +++ b/ProcessLib/ThermoRichardsMechanics/ConstitutiveStressSaturation_StrainPressureTemperature/CreateConstitutiveSetting.h @@ -20,7 +20,7 @@ template struct CreateConstitutiveSetting { static std::map>> + std::shared_ptr>> createSolidConstitutiveRelations( std::vector> const& parameters, diff --git a/ProcessLib/ThermoRichardsMechanics/ConstitutiveStress_StrainTemperature/CreateConstitutiveSetting.cpp b/ProcessLib/ThermoRichardsMechanics/ConstitutiveStress_StrainTemperature/CreateConstitutiveSetting.cpp index 12071380b88..fc33267844b 100644 --- a/ProcessLib/ThermoRichardsMechanics/ConstitutiveStress_StrainTemperature/CreateConstitutiveSetting.cpp +++ b/ProcessLib/ThermoRichardsMechanics/ConstitutiveStress_StrainTemperature/CreateConstitutiveSetting.cpp @@ -17,7 +17,7 @@ namespace ProcessLib::ThermoRichardsMechanics namespace ConstitutiveStress_StrainTemperature { template -std::map>> +std::map>> CreateConstitutiveSetting::createSolidConstitutiveRelations( std::vector> const& parameters, std::optional const& diff --git a/ProcessLib/ThermoRichardsMechanics/ConstitutiveStress_StrainTemperature/CreateConstitutiveSetting.h b/ProcessLib/ThermoRichardsMechanics/ConstitutiveStress_StrainTemperature/CreateConstitutiveSetting.h index f366d01efc5..0cd6c05a903 100644 --- a/ProcessLib/ThermoRichardsMechanics/ConstitutiveStress_StrainTemperature/CreateConstitutiveSetting.h +++ b/ProcessLib/ThermoRichardsMechanics/ConstitutiveStress_StrainTemperature/CreateConstitutiveSetting.h @@ -23,7 +23,7 @@ template struct CreateConstitutiveSetting { static std::map>> + std::shared_ptr>> createSolidConstitutiveRelations( std::vector> const& parameters, diff --git a/ProcessLib/ThermoRichardsMechanics/ThermoRichardsMechanicsProcessData.h b/ProcessLib/ThermoRichardsMechanics/ThermoRichardsMechanicsProcessData.h index b01f9d61280..2974b474585 100644 --- a/ProcessLib/ThermoRichardsMechanics/ThermoRichardsMechanicsProcessData.h +++ b/ProcessLib/ThermoRichardsMechanics/ThermoRichardsMechanicsProcessData.h @@ -35,7 +35,7 @@ struct ThermoRichardsMechanicsProcessData MaterialPropertyLib::MaterialSpatialDistributionMap media_map; /// The constitutive relation for the mechanical part. - std::map> solid_materials; From 057008cfee2b3802533db038942f9fa0b4c6f35d Mon Sep 17 00:00:00 2001 From: Florian Zill Date: Tue, 1 Oct 2024 14:08:10 +0200 Subject: [PATCH 2/6] [Tests] use id list for equal constitutive relations --- ProcessLib/SmallDeformation/Tests.cmake | 27 +++++++++++++++++++ .../Excavation/time_linear_excavation.prj | 7 +---- .../element_deactivation_M_3D.prj | 7 +---- .../failcase_duplicate_id_0.xml | 10 +++++++ .../failcase_duplicate_id_1.xml | 10 +++++++ .../failcase_duplicate_id_list.xml | 12 +++++++++ .../Linear/square_with_deactivated_hole.prj | 7 +---- Tests/Data/RichardsMechanics/A2.prj | 7 +---- .../TH2M/TH2M/Ansicht_Simple_1e2/A2_THM.prj | 7 +---- .../TH2M/TH2M/Ansicht_Simple_1e2/A2_TRM.prj | 7 +---- Tests/Data/ThermoHydroMechanics/A2/A2.prj | 7 +---- .../ThermoHydroMechanics/A2/A2_heating.prj | 7 +---- Tests/Data/ThermoRichardsMechanics/A2/A2.prj | 7 +---- .../ThermoRichardsMechanics/MFront/A2/A2.xml | 21 ++------------- .../MFront/A2/A2_effective_stress0.xml | 21 ++------------- 15 files changed, 72 insertions(+), 92 deletions(-) create mode 100644 Tests/Data/Mechanics/Linear/ElementDeactivation3D/failcase_duplicate_id_0.xml create mode 100644 Tests/Data/Mechanics/Linear/ElementDeactivation3D/failcase_duplicate_id_1.xml create mode 100644 Tests/Data/Mechanics/Linear/ElementDeactivation3D/failcase_duplicate_id_list.xml diff --git a/ProcessLib/SmallDeformation/Tests.cmake b/ProcessLib/SmallDeformation/Tests.cmake index ad89a65b992..9fcf1d903f0 100644 --- a/ProcessLib/SmallDeformation/Tests.cmake +++ b/ProcessLib/SmallDeformation/Tests.cmake @@ -16,6 +16,33 @@ if (NOT OGS_USE_MPI) OgsTest(PROJECTFILE Mechanics/Linear/disc_with_hole.prj) if(NOT ENABLE_ASAN) OgsTest(PROJECTFILE Mechanics/Linear/ElementDeactivation3D/element_deactivation_M_3D.prj RUNTIME 2) + AddTest( + NAME Mechanics_ElementDeactivation3D_failcase_duplicate_id_list + PATH Mechanics/Linear/ElementDeactivation3D + RUNTIME 1 + 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." + ) + AddTest( + NAME Mechanics_ElementDeactivation3D_failcase_duplicate_id_0 + PATH Mechanics/Linear/ElementDeactivation3D + RUNTIME 1 + 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." + ) + AddTest( + NAME Mechanics_ElementDeactivation3D_failcase_duplicate_id_1 + PATH Mechanics/Linear/ElementDeactivation3D + RUNTIME 1 + 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." + ) endif() OgsTest(PROJECTFILE Mechanics/Linear/square_1e5.prj RUNTIME 200) OgsTest(PROJECTFILE Mechanics/Linear/square_1e2_quad8_traction_top.prj) diff --git a/Tests/Data/Mechanics/Excavation/time_linear_excavation.prj b/Tests/Data/Mechanics/Excavation/time_linear_excavation.prj index 48ae58ab1f5..ecc651b3b02 100644 --- a/Tests/Data/Mechanics/Excavation/time_linear_excavation.prj +++ b/Tests/Data/Mechanics/Excavation/time_linear_excavation.prj @@ -16,12 +16,7 @@ SD SMALL_DEFORMATION 2 - - LinearElasticIsotropic - E - nu - - + LinearElasticIsotropic E nu diff --git a/Tests/Data/Mechanics/Linear/ElementDeactivation3D/element_deactivation_M_3D.prj b/Tests/Data/Mechanics/Linear/ElementDeactivation3D/element_deactivation_M_3D.prj index 7d2403d6c07..6fbed6d760d 100644 --- a/Tests/Data/Mechanics/Linear/ElementDeactivation3D/element_deactivation_M_3D.prj +++ b/Tests/Data/Mechanics/Linear/ElementDeactivation3D/element_deactivation_M_3D.prj @@ -13,12 +13,7 @@ SD SMALL_DEFORMATION 2 - - LinearElasticIsotropic - E - nu - - + LinearElasticIsotropic E nu diff --git a/Tests/Data/Mechanics/Linear/ElementDeactivation3D/failcase_duplicate_id_0.xml b/Tests/Data/Mechanics/Linear/ElementDeactivation3D/failcase_duplicate_id_0.xml new file mode 100644 index 00000000000..007c32b513b --- /dev/null +++ b/Tests/Data/Mechanics/Linear/ElementDeactivation3D/failcase_duplicate_id_0.xml @@ -0,0 +1,10 @@ + + + + + LinearElasticIsotropic + E + nu + + + diff --git a/Tests/Data/Mechanics/Linear/ElementDeactivation3D/failcase_duplicate_id_1.xml b/Tests/Data/Mechanics/Linear/ElementDeactivation3D/failcase_duplicate_id_1.xml new file mode 100644 index 00000000000..101eec94165 --- /dev/null +++ b/Tests/Data/Mechanics/Linear/ElementDeactivation3D/failcase_duplicate_id_1.xml @@ -0,0 +1,10 @@ + + + + + LinearElasticIsotropic + E + nu + + + diff --git a/Tests/Data/Mechanics/Linear/ElementDeactivation3D/failcase_duplicate_id_list.xml b/Tests/Data/Mechanics/Linear/ElementDeactivation3D/failcase_duplicate_id_list.xml new file mode 100644 index 00000000000..a362af71c84 --- /dev/null +++ b/Tests/Data/Mechanics/Linear/ElementDeactivation3D/failcase_duplicate_id_list.xml @@ -0,0 +1,12 @@ + + + + + + + LinearElasticIsotropic + E + nu + + + diff --git a/Tests/Data/Mechanics/Linear/square_with_deactivated_hole.prj b/Tests/Data/Mechanics/Linear/square_with_deactivated_hole.prj index 11ab2d28704..af89a5eca7b 100644 --- a/Tests/Data/Mechanics/Linear/square_with_deactivated_hole.prj +++ b/Tests/Data/Mechanics/Linear/square_with_deactivated_hole.prj @@ -7,12 +7,7 @@ SD SMALL_DEFORMATION 2 - - LinearElasticIsotropic - E - nu - - + LinearElasticIsotropic E nu diff --git a/Tests/Data/RichardsMechanics/A2.prj b/Tests/Data/RichardsMechanics/A2.prj index b9940195372..731ef01b1ff 100644 --- a/Tests/Data/RichardsMechanics/A2.prj +++ b/Tests/Data/RichardsMechanics/A2.prj @@ -14,12 +14,7 @@ RM RICHARDS_MECHANICS 3 - - LinearElasticIsotropic - E - nu - - + LinearElasticIsotropic E nu diff --git a/Tests/Data/TH2M/TH2M/Ansicht_Simple_1e2/A2_THM.prj b/Tests/Data/TH2M/TH2M/Ansicht_Simple_1e2/A2_THM.prj index a251f4d979b..8e101842584 100644 --- a/Tests/Data/TH2M/TH2M/Ansicht_Simple_1e2/A2_THM.prj +++ b/Tests/Data/TH2M/TH2M/Ansicht_Simple_1e2/A2_THM.prj @@ -14,12 +14,7 @@ THM THERMO_HYDRO_MECHANICS 3 - - LinearElasticIsotropic - E - nu - - + LinearElasticIsotropic E nu diff --git a/Tests/Data/TH2M/TH2M/Ansicht_Simple_1e2/A2_TRM.prj b/Tests/Data/TH2M/TH2M/Ansicht_Simple_1e2/A2_TRM.prj index fa9c2df8021..bf659d74207 100644 --- a/Tests/Data/TH2M/TH2M/Ansicht_Simple_1e2/A2_TRM.prj +++ b/Tests/Data/TH2M/TH2M/Ansicht_Simple_1e2/A2_TRM.prj @@ -14,12 +14,7 @@ TRM THERMO_RICHARDS_MECHANICS 3 - - LinearElasticIsotropic - E - nu - - + LinearElasticIsotropic E nu diff --git a/Tests/Data/ThermoHydroMechanics/A2/A2.prj b/Tests/Data/ThermoHydroMechanics/A2/A2.prj index 771c45df5e3..831f991c55f 100644 --- a/Tests/Data/ThermoHydroMechanics/A2/A2.prj +++ b/Tests/Data/ThermoHydroMechanics/A2/A2.prj @@ -14,12 +14,7 @@ THM THERMO_HYDRO_MECHANICS 3 - - LinearElasticIsotropic - E - nu - - + LinearElasticIsotropic E nu diff --git a/Tests/Data/ThermoHydroMechanics/A2/A2_heating.prj b/Tests/Data/ThermoHydroMechanics/A2/A2_heating.prj index 36ebc67b06c..925ce86bd42 100644 --- a/Tests/Data/ThermoHydroMechanics/A2/A2_heating.prj +++ b/Tests/Data/ThermoHydroMechanics/A2/A2_heating.prj @@ -15,12 +15,7 @@ THM THERMO_HYDRO_MECHANICS 3 - - LinearElasticIsotropic - E - nu - - + LinearElasticIsotropic E nu diff --git a/Tests/Data/ThermoRichardsMechanics/A2/A2.prj b/Tests/Data/ThermoRichardsMechanics/A2/A2.prj index bf0a90623f5..4e89b451388 100644 --- a/Tests/Data/ThermoRichardsMechanics/A2/A2.prj +++ b/Tests/Data/ThermoRichardsMechanics/A2/A2.prj @@ -14,12 +14,7 @@ TRM THERMO_RICHARDS_MECHANICS 3 - - LinearElasticIsotropic - E - nu - - + LinearElasticIsotropic E nu diff --git a/Tests/Data/ThermoRichardsMechanics/MFront/A2/A2.xml b/Tests/Data/ThermoRichardsMechanics/MFront/A2/A2.xml index 6da706b769b..58b6702e91e 100644 --- a/Tests/Data/ThermoRichardsMechanics/MFront/A2/A2.xml +++ b/Tests/Data/ThermoRichardsMechanics/MFront/A2/A2.xml @@ -7,27 +7,10 @@ sigma0 - - - + - - MFront - ThermoPoroElasticity - - - - - - - - - - - - - + MFront ThermoPoroElasticity diff --git a/Tests/Data/ThermoRichardsMechanics/MFront/A2/A2_effective_stress0.xml b/Tests/Data/ThermoRichardsMechanics/MFront/A2/A2_effective_stress0.xml index a50b12c4231..f1ab85ce3a2 100644 --- a/Tests/Data/ThermoRichardsMechanics/MFront/A2/A2_effective_stress0.xml +++ b/Tests/Data/ThermoRichardsMechanics/MFront/A2/A2_effective_stress0.xml @@ -7,27 +7,10 @@ sigma0 - - - + - - MFront - ThermoPoroElasticity - - - - - - - - - - - - - + MFront ThermoPoroElasticity From 6555bafe54751458ff735c520d4a2ae655574200 Mon Sep 17 00:00:00 2001 From: Dmitri Naumov Date: Mon, 7 Oct 2024 13:52:09 +0200 Subject: [PATCH 3/6] Move media creation related fcts to MaterialLib --- Applications/ApplicationsLib/ProjectData.cpp | 64 +----------- BaseLib/StringTools.cpp | 52 ---------- BaseLib/StringTools.h | 5 - MaterialLib/CMakeLists.txt | 3 +- .../CreateConstitutiveRelationsGeneric.h | 4 +- MaterialLib/Utils/CMakeLists.txt | 4 + MaterialLib/Utils/MediaCreation.cpp | 98 +++++++++++++++++++ MaterialLib/Utils/MediaCreation.h | 70 +++++++++++++ ProcessLib/Output/CreateOutputConfig.cpp | 4 +- .../TestSplitMaterialIdString.cpp | 24 ++--- 10 files changed, 195 insertions(+), 133 deletions(-) create mode 100644 MaterialLib/Utils/CMakeLists.txt create mode 100644 MaterialLib/Utils/MediaCreation.cpp create mode 100644 MaterialLib/Utils/MediaCreation.h rename Tests/{BaseLib => MaterialLib}/TestSplitMaterialIdString.cpp (77%) diff --git a/Applications/ApplicationsLib/ProjectData.cpp b/Applications/ApplicationsLib/ProjectData.cpp index 4c32723f64a..9fe6549e7d8 100644 --- a/Applications/ApplicationsLib/ProjectData.cpp +++ b/Applications/ApplicationsLib/ProjectData.cpp @@ -37,6 +37,7 @@ #include "GeoLib/Raster.h" #include "InfoLib/CMakeInfo.h" #include "MaterialLib/MPL/CreateMedium.h" +#include "MaterialLib/Utils/MediaCreation.h" #include "MathLib/Curve/CreatePiecewiseLinearCurve.h" #if defined(USE_LIS) #include "MathLib/LinAlg/EigenLis/LinearSolverOptionsParser.h" @@ -356,61 +357,6 @@ std::vector readRasters( // } //} -std::vector parseMaterialIdString( - std::string const& material_id_string, - MeshLib::PropertyVector const* const material_ids) -{ - if (material_id_string == "*") - { - if (material_ids == nullptr) - { - OGS_FATAL( - "MaterialIDs property is not defined in the mesh but it is " - "required to parse '*' definition."); - } - - std::vector material_ids_of_this_medium = - *material_ids | - ranges::views::adjacent_remove_if(std::equal_to<>()) | - ranges::to_vector; - BaseLib::makeVectorUnique(material_ids_of_this_medium); - DBUG("Catch all medium definition for material ids {}.", - fmt::join(material_ids_of_this_medium, ", ")); - return material_ids_of_this_medium; - } - - // Usual case of ids separated by comma. - return BaseLib::splitMaterialIdString(material_id_string); -} - -template -requires std::convertible_to()( - std::declval())), - std::shared_ptr> -void createMediumForId(int const id, - std::map>& _media, - std::vector const& material_ids_of_this_medium, - CreateMedium&& create_medium) -{ - if (_media.find(id) != end(_media)) - { - OGS_FATAL( - "Multiple media 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.", - id); - } - - if (id == material_ids_of_this_medium[0]) - { - _media[id] = create_medium(id); - } - else - { - _media[id] = _media[material_ids_of_this_medium[0]]; - } -} - } // namespace ProjectData::ProjectData() = default; @@ -630,13 +576,13 @@ void ProjectData::parseMedia( medium_config.getConfigAttribute("id", "0"); std::vector const material_ids_of_this_medium = - parseMaterialIdString(material_id_string, - materialIDs(*_mesh_vec[0])); + MaterialLib::parseMaterialIdString(material_id_string, + materialIDs(*_mesh_vec[0])); for (auto const& id : material_ids_of_this_medium) { - createMediumForId(id, _media, material_ids_of_this_medium, - create_medium); + MaterialLib::createMediumForId( + id, _media, material_ids_of_this_medium, create_medium); } } diff --git a/BaseLib/StringTools.cpp b/BaseLib/StringTools.cpp index ce5e22ffd5d..ee4c15d233f 100644 --- a/BaseLib/StringTools.cpp +++ b/BaseLib/StringTools.cpp @@ -132,56 +132,4 @@ std::string getUniqueName(std::vector const& existing_names, } return result_name; } - -std::vector splitMaterialIdString(std::string const& material_id_string) -{ - auto const material_ids_strings = - BaseLib::splitString(material_id_string, ','); - - std::vector material_ids; - for (auto& mid_str : material_ids_strings) - { - std::size_t num_chars_processed = 0; - int material_id; - try - { - material_id = std::stoi(mid_str, &num_chars_processed); - } - catch (std::invalid_argument&) - { - OGS_FATAL( - "Could not parse material ID from '{}' to a valid " - "integer.", - mid_str); - } - catch (std::out_of_range&) - { - OGS_FATAL( - "Could not parse material ID from '{}'. The integer value " - "of the given string exceeds the permitted range.", - mid_str); - } - - if (num_chars_processed != mid_str.size()) - { - // Not the whole string has been parsed. Check the rest. - if (auto const it = std::find_if_not( - begin(mid_str) + num_chars_processed, end(mid_str), - [](unsigned char const c) { return std::isspace(c); }); - it != end(mid_str)) - { - OGS_FATAL( - "Could not parse material ID from '{}'. Please " - "separate multiple material IDs by comma only. " - "Invalid character: '{}' at position {}.", - mid_str, *it, distance(begin(mid_str), it)); - } - } - - material_ids.push_back(material_id); - }; - - return material_ids; -} - } // end namespace BaseLib diff --git a/BaseLib/StringTools.h b/BaseLib/StringTools.h index f8c7542fb61..056aaf1a87d 100644 --- a/BaseLib/StringTools.h +++ b/BaseLib/StringTools.h @@ -83,9 +83,4 @@ std::string randomString(std::size_t length); //! Append '-' and a number such that the name is unique. std::string getUniqueName(std::vector const& existing_names, std::string const& input_name); - -/// Parses a comma separated list of integers. -/// Such lists occur in the medium definition in the OGS prj file. -/// Error messages in this function refer to this specific purpose. -std::vector splitMaterialIdString(std::string const& material_id_string); } // end namespace BaseLib diff --git a/MaterialLib/CMakeLists.txt b/MaterialLib/CMakeLists.txt index a056c6aebc9..cfb389619c1 100644 --- a/MaterialLib/CMakeLists.txt +++ b/MaterialLib/CMakeLists.txt @@ -1,5 +1,6 @@ add_subdirectory(SolidModels) add_subdirectory(FractureModels) +add_subdirectory(Utils) # Source files get_source_files(SOURCES) @@ -42,7 +43,7 @@ ogs_add_library( target_link_libraries( MaterialLib PUBLIC BaseLib Eigen3::Eigen MaterialLib_SolidModels - MaterialLib_FractureModels + MaterialLib_FractureModels MaterialLib_Utils PRIVATE MathLib MeshLib ParameterLib exprtk Boost::math ) diff --git a/MaterialLib/SolidModels/CreateConstitutiveRelationsGeneric.h b/MaterialLib/SolidModels/CreateConstitutiveRelationsGeneric.h index 9b6e7c72207..b3b67cc979c 100644 --- a/MaterialLib/SolidModels/CreateConstitutiveRelationsGeneric.h +++ b/MaterialLib/SolidModels/CreateConstitutiveRelationsGeneric.h @@ -11,7 +11,7 @@ #pragma once #include "BaseLib/ConfigTree.h" -#include "BaseLib/StringTools.h" +#include "MaterialLib/Utils/MediaCreation.h" #include "ParameterLib/Parameter.h" namespace MaterialLib::Solids @@ -44,7 +44,7 @@ createConstitutiveRelationsGeneric( "0"); auto const material_ids_of_this_constitutive_relation = - BaseLib::splitMaterialIdString(material_id_string); + MaterialLib::splitMaterialIdString(material_id_string); auto first_relation_for_material_id = constitutive_relations.end(); for (auto const& material_id : diff --git a/MaterialLib/Utils/CMakeLists.txt b/MaterialLib/Utils/CMakeLists.txt new file mode 100644 index 00000000000..b9d58f96f80 --- /dev/null +++ b/MaterialLib/Utils/CMakeLists.txt @@ -0,0 +1,4 @@ +get_source_files(SOURCES) + +ogs_add_library(MaterialLib_Utils ${SOURCES}) +target_link_libraries(MaterialLib_Utils PRIVATE BaseLib MeshLib) diff --git a/MaterialLib/Utils/MediaCreation.cpp b/MaterialLib/Utils/MediaCreation.cpp new file mode 100644 index 00000000000..7be7a916115 --- /dev/null +++ b/MaterialLib/Utils/MediaCreation.cpp @@ -0,0 +1,98 @@ +/** + * \file + * \copyright + * Copyright (c) 2012-2024, OpenGeoSys Community (http://www.opengeosys.org) + * Distributed under a Modified BSD License. + * See accompanying file LICENSE.txt or + * http://www.opengeosys.org/project/license + */ + +#include +#include + +#include "BaseLib/Algorithm.h" +#include "BaseLib/Logging.h" +#include "BaseLib/StringTools.h" +#include "MeshLib/PropertyVector.h" + +namespace MaterialLib +{ + +std::vector splitMaterialIdString(std::string const& material_id_string) +{ + auto const material_ids_strings = + BaseLib::splitString(material_id_string, ','); + + std::vector material_ids; + for (auto& mid_str : material_ids_strings) + { + std::size_t num_chars_processed = 0; + int material_id; + try + { + material_id = std::stoi(mid_str, &num_chars_processed); + } + catch (std::invalid_argument&) + { + OGS_FATAL( + "Could not parse material ID from '{}' to a valid integer.", + mid_str); + } + catch (std::out_of_range&) + { + OGS_FATAL( + "Could not parse material ID from '{}'. The integer value of " + "the given string exceeds the permitted range.", + mid_str); + } + + if (num_chars_processed != mid_str.size()) + { + // Not the whole string has been parsed. Check the rest. + if (auto const it = std::find_if_not( + begin(mid_str) + num_chars_processed, end(mid_str), + [](unsigned char const c) { return std::isspace(c); }); + it != end(mid_str)) + { + OGS_FATAL( + "Could not parse material ID from '{}'. Please separate " + "multiple material IDs by comma only. Invalid character: " + "'{}' at position {}.", + mid_str, *it, distance(begin(mid_str), it)); + } + } + + material_ids.push_back(material_id); + }; + + return material_ids; +} + +std::vector parseMaterialIdString( + std::string const& material_id_string, + MeshLib::PropertyVector const* const material_ids) +{ + if (material_id_string == "*") + { + if (material_ids == nullptr) + { + OGS_FATAL( + "MaterialIDs property is not defined in the mesh but it is " + "required to parse '*' definition."); + } + + std::vector material_ids_of_this_medium = + *material_ids | + ranges::views::adjacent_remove_if(std::equal_to<>()) | + ranges::to_vector; + BaseLib::makeVectorUnique(material_ids_of_this_medium); + DBUG("Catch all medium definition for material ids {}.", + fmt::join(material_ids_of_this_medium, ", ")); + return material_ids_of_this_medium; + } + + // Usual case of ids separated by comma. + return splitMaterialIdString(material_id_string); +} + +} // namespace MaterialLib diff --git a/MaterialLib/Utils/MediaCreation.h b/MaterialLib/Utils/MediaCreation.h new file mode 100644 index 00000000000..c66e091fda3 --- /dev/null +++ b/MaterialLib/Utils/MediaCreation.h @@ -0,0 +1,70 @@ +/** + * \file + * \copyright + * Copyright (c) 2012-2024, OpenGeoSys Community (http://www.opengeosys.org) + * Distributed under a Modified BSD License. + * See accompanying file LICENSE.txt or + * http://www.opengeosys.org/project/license + */ + +#include +#include +#include +#include + +#include "BaseLib/Error.h" + +namespace MeshLib +{ +template +class PropertyVector; +} // namespace MeshLib + +namespace MaterialLib +{ + +/// Parses a comma separated list of integers. +/// Such lists occur in the medium definition in the OGS prj file. +/// Error messages in this function refer to this specific purpose. +std::vector splitMaterialIdString(std::string const& material_id_string); + +/// Parses a comma separated list of integers or "*" string. +/// Such lists occur in the medium definition in the OGS prj file. +/// For the "*" input a vector of all (unique) material ids is returned. +/// Error messages in this function refer to this specific purpose. +std::vector parseMaterialIdString( + std::string const& material_id_string, + MeshLib::PropertyVector const* const material_ids); + +/// Creates a new entry for the material id in the media map by either calling +/// the create_medium function and creating a new shared pointer, or by reusing +/// the existing shared pointer. +template + requires std::convertible_to< + decltype(std::declval()(std::declval())), + std::shared_ptr> +void createMediumForId(int const id, + std::map>& media, + std::vector const& material_ids_of_this_medium, + CreateMedium&& create_medium) +{ + if (media.find(id) != end(media)) + { + OGS_FATAL( + "Multiple media 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.", + id); + } + + if (id == material_ids_of_this_medium[0]) + { + media[id] = create_medium(id); + } + else + { + media[id] = media[material_ids_of_this_medium[0]]; + } +} + +} // namespace MaterialLib diff --git a/ProcessLib/Output/CreateOutputConfig.cpp b/ProcessLib/Output/CreateOutputConfig.cpp index 6465bd9f134..1366c99599a 100644 --- a/ProcessLib/Output/CreateOutputConfig.cpp +++ b/ProcessLib/Output/CreateOutputConfig.cpp @@ -14,7 +14,7 @@ #include "BaseLib/Algorithm.h" #include "BaseLib/ConfigTree.h" -#include "BaseLib/StringTools.h" // required for splitMaterialIDString +#include "MaterialLib/Utils/MediaCreation.h" // required for splitMaterialIDString #include "MeshLib/Mesh.h" #include "MeshLib/Utils/createMaterialIDsBasedSubMesh.h" #include "MeshLib/Utils/transformMeshToNodePartitionedMesh.h" @@ -50,7 +50,7 @@ std::string parseOutputMeshConfig( } auto const material_ids_for_output = - BaseLib::splitMaterialIdString(*material_id_string); + MaterialLib::splitMaterialIdString(*material_id_string); #ifdef USE_PETSC // this mesh isn't yet a NodePartitionedMesh auto subdomain_mesh = MeshLib::createMaterialIDsBasedSubMesh( diff --git a/Tests/BaseLib/TestSplitMaterialIdString.cpp b/Tests/MaterialLib/TestSplitMaterialIdString.cpp similarity index 77% rename from Tests/BaseLib/TestSplitMaterialIdString.cpp rename to Tests/MaterialLib/TestSplitMaterialIdString.cpp index 4f540ce7488..83cf2d40399 100644 --- a/Tests/BaseLib/TestSplitMaterialIdString.cpp +++ b/Tests/MaterialLib/TestSplitMaterialIdString.cpp @@ -13,16 +13,16 @@ #include -#include "BaseLib/StringTools.h" +#include "MaterialLib/Utils/MediaCreation.h" -using namespace BaseLib; +using namespace MaterialLib; -TEST(BaseLib_SplitIntegerList, EmptyList) +TEST(MaterialLib_SplitIntegerList, EmptyList) { ASSERT_TRUE(splitMaterialIdString("").empty()); } -TEST(BaseLib_SplitIntegerList, SingleInt) +TEST(MaterialLib_SplitIntegerList, SingleInt) { using namespace testing; @@ -41,7 +41,7 @@ TEST(BaseLib_SplitIntegerList, SingleInt) ContainerEq(std::vector{-20})); } -TEST(BaseLib_SplitIntegerList, SingleIntFail) +TEST(MaterialLib_SplitIntegerList, SingleIntFail) { // wrong character prefix/suffix EXPECT_THROW(splitMaterialIdString("x"), std::runtime_error); @@ -62,7 +62,7 @@ TEST(BaseLib_SplitIntegerList, SingleIntFail) std::runtime_error); } -TEST(BaseLib_SplitIntegerList, IntList) +TEST(MaterialLib_SplitIntegerList, IntList) { using namespace testing; @@ -78,20 +78,20 @@ TEST(BaseLib_SplitIntegerList, IntList) ContainerEq(std::vector{20, 22, 24})); } -TEST(BaseLib_SplitIntegerList, IntListFail) +TEST(MaterialLib_SplitIntegerList, IntListFail) { // only delimiter - EXPECT_THROW(BaseLib::splitMaterialIdString(","), std::runtime_error); + EXPECT_THROW(splitMaterialIdString(","), std::runtime_error); // empty element - EXPECT_THROW(BaseLib::splitMaterialIdString("5,,6"), std::runtime_error); + EXPECT_THROW(splitMaterialIdString("5,,6"), std::runtime_error); // leading comma - EXPECT_THROW(BaseLib::splitMaterialIdString(",40"), std::runtime_error); + EXPECT_THROW(splitMaterialIdString(",40"), std::runtime_error); // missing comma - EXPECT_THROW(BaseLib::splitMaterialIdString("12 20"), std::runtime_error); + EXPECT_THROW(splitMaterialIdString("12 20"), std::runtime_error); // wrong number in the list - EXPECT_THROW(BaseLib::splitMaterialIdString("1,2,x,5"), std::runtime_error); + EXPECT_THROW(splitMaterialIdString("1,2,x,5"), std::runtime_error); } From c4dcca12b703606a421ca1d585998a82c8660498 Mon Sep 17 00:00:00 2001 From: Dmitri Naumov Date: Mon, 7 Oct 2024 15:08:34 +0200 Subject: [PATCH 4/6] [PL] Pass material ids to solid const.rel. create Needed for the implementation of id="*" in solid constitutive relations. --- MaterialLib/SolidModels/CreateConstitutiveRelation.cpp | 4 ++++ MaterialLib/SolidModels/CreateConstitutiveRelation.h | 8 ++++++++ .../SolidModels/CreateConstitutiveRelationsGeneric.h | 2 ++ .../HydroMechanics/CreateHydroMechanicsProcess.cpp | 2 +- .../LIE/HydroMechanics/CreateHydroMechanicsProcess.cpp | 2 +- .../SmallDeformation/CreateSmallDeformationProcess.cpp | 2 +- .../ConstitutiveRelations/CreateConstitutiveSetting.cpp | 3 ++- .../ConstitutiveRelations/CreateConstitutiveSetting.h | 7 +++++++ .../LargeDeformation/CreateLargeDeformationProcess.cpp | 4 ++-- ProcessLib/PhaseField/CreatePhaseFieldProcess.cpp | 2 +- .../ConstitutiveRelations/CreateConstitutiveSetting.cpp | 3 ++- .../ConstitutiveRelations/CreateConstitutiveSetting.h | 1 + .../RichardsMechanics/CreateRichardsMechanicsProcess.cpp | 2 +- .../ConstitutiveRelations/CreateConstitutiveSetting.cpp | 3 ++- .../ConstitutiveRelations/CreateConstitutiveSetting.h | 6 ++++++ .../SmallDeformation/CreateSmallDeformationProcess.cpp | 2 +- .../CreateSmallDeformationNonlocalProcess.cpp | 2 +- ProcessLib/TH2M/CreateTH2MProcess.cpp | 2 +- .../CreateThermoHydroMechanicsProcess.cpp | 2 +- .../CreateThermoMechanicalPhaseFieldProcess.cpp | 2 +- .../ThermoMechanics/CreateThermoMechanicsProcess.cpp | 2 +- .../CreateConstitutiveSetting.cpp | 3 ++- .../CreateConstitutiveSetting.h | 6 ++++++ .../CreateConstitutiveSetting.cpp | 9 ++++++++- .../CreateConstitutiveSetting.h | 6 ++++++ .../CreateThermoRichardsMechanicsProcess.cpp | 2 +- 26 files changed, 70 insertions(+), 19 deletions(-) diff --git a/MaterialLib/SolidModels/CreateConstitutiveRelation.cpp b/MaterialLib/SolidModels/CreateConstitutiveRelation.cpp index 5f1e32f610f..fdcd91c7a1b 100644 --- a/MaterialLib/SolidModels/CreateConstitutiveRelation.cpp +++ b/MaterialLib/SolidModels/CreateConstitutiveRelation.cpp @@ -111,12 +111,14 @@ createConstitutiveRelations( std::vector> const& parameters, std::optional const& local_coordinate_system, + MeshLib::PropertyVector const* const material_ids, BaseLib::ConfigTree const& config) { return createConstitutiveRelationsGeneric< MaterialLib::Solids::MechanicsBase>( parameters, local_coordinate_system, + material_ids, config, createConstitutiveRelation); } @@ -126,6 +128,7 @@ createConstitutiveRelations<2>( std::vector> const& parameters, std::optional const& local_coordinate_system, + MeshLib::PropertyVector const* const material_ids, BaseLib::ConfigTree const& config); template std::map>> @@ -133,6 +136,7 @@ createConstitutiveRelations<3>( std::vector> const& parameters, std::optional const& local_coordinate_system, + MeshLib::PropertyVector const* const material_ids, BaseLib::ConfigTree const& config); } // namespace Solids } // namespace MaterialLib diff --git a/MaterialLib/SolidModels/CreateConstitutiveRelation.h b/MaterialLib/SolidModels/CreateConstitutiveRelation.h index 4bb1a10ff4b..4a384775f94 100644 --- a/MaterialLib/SolidModels/CreateConstitutiveRelation.h +++ b/MaterialLib/SolidModels/CreateConstitutiveRelation.h @@ -20,6 +20,11 @@ namespace BaseLib { class ConfigTree; } +namespace MeshLib +{ +template +class PropertyVector; +} namespace ParameterLib { @@ -63,6 +68,7 @@ createConstitutiveRelations( std::vector> const& parameters, std::optional const& local_coordinate_system, + MeshLib::PropertyVector const* const material_ids, BaseLib::ConfigTree const& config); extern template std::map( std::vector> const& parameters, std::optional const& local_coordinate_system, + MeshLib::PropertyVector const* const material_ids, BaseLib::ConfigTree const& config); extern template std::map( std::vector> const& parameters, std::optional const& local_coordinate_system, + MeshLib::PropertyVector const* const material_ids, BaseLib::ConfigTree const& config); } // namespace Solids } // namespace MaterialLib diff --git a/MaterialLib/SolidModels/CreateConstitutiveRelationsGeneric.h b/MaterialLib/SolidModels/CreateConstitutiveRelationsGeneric.h index b3b67cc979c..6c41c40c378 100644 --- a/MaterialLib/SolidModels/CreateConstitutiveRelationsGeneric.h +++ b/MaterialLib/SolidModels/CreateConstitutiveRelationsGeneric.h @@ -12,6 +12,7 @@ #include "BaseLib/ConfigTree.h" #include "MaterialLib/Utils/MediaCreation.h" +#include "MeshLib/PropertyVector.h" #include "ParameterLib/Parameter.h" namespace MaterialLib::Solids @@ -22,6 +23,7 @@ createConstitutiveRelationsGeneric( std::vector> const& parameters, std::optional const& local_coordinate_system, + MeshLib::PropertyVector const* const material_ids, BaseLib::ConfigTree const& config, std::unique_ptr (*create_constitutive_relation)( std::vector> const&, diff --git a/ProcessLib/HydroMechanics/CreateHydroMechanicsProcess.cpp b/ProcessLib/HydroMechanics/CreateHydroMechanicsProcess.cpp index aef2e32482d..5e55893938a 100644 --- a/ProcessLib/HydroMechanics/CreateHydroMechanicsProcess.cpp +++ b/ProcessLib/HydroMechanics/CreateHydroMechanicsProcess.cpp @@ -179,7 +179,7 @@ std::unique_ptr createHydroMechanicsProcess( auto solid_constitutive_relations = MaterialLib::Solids::createConstitutiveRelations( - parameters, local_coordinate_system, config); + parameters, local_coordinate_system, materialIDs(mesh), config); /// \section parametershm Process Parameters // Specific body force diff --git a/ProcessLib/LIE/HydroMechanics/CreateHydroMechanicsProcess.cpp b/ProcessLib/LIE/HydroMechanics/CreateHydroMechanicsProcess.cpp index 3554dcc013e..ba887104e63 100644 --- a/ProcessLib/LIE/HydroMechanics/CreateHydroMechanicsProcess.cpp +++ b/ProcessLib/LIE/HydroMechanics/CreateHydroMechanicsProcess.cpp @@ -135,7 +135,7 @@ std::unique_ptr createHydroMechanicsProcess( /// \section parametersliehm Process Parameters auto solid_constitutive_relations = MaterialLib::Solids::createConstitutiveRelations( - parameters, local_coordinate_system, config); + parameters, local_coordinate_system, materialIDs(mesh), config); // Intrinsic permeability auto& intrinsic_permeability = ParameterLib::findParameter( diff --git a/ProcessLib/LIE/SmallDeformation/CreateSmallDeformationProcess.cpp b/ProcessLib/LIE/SmallDeformation/CreateSmallDeformationProcess.cpp index 899d1bd95fc..c65bf8eea99 100644 --- a/ProcessLib/LIE/SmallDeformation/CreateSmallDeformationProcess.cpp +++ b/ProcessLib/LIE/SmallDeformation/CreateSmallDeformationProcess.cpp @@ -113,7 +113,7 @@ std::unique_ptr createSmallDeformationProcess( /// \section parametersliesd Process Parameters auto solid_constitutive_relations = MaterialLib::Solids::createConstitutiveRelations( - parameters, local_coordinate_system, config); + parameters, local_coordinate_system, materialIDs(mesh), config); // Fracture constitutive relation. // read type; diff --git a/ProcessLib/LargeDeformation/ConstitutiveRelations/CreateConstitutiveSetting.cpp b/ProcessLib/LargeDeformation/ConstitutiveRelations/CreateConstitutiveSetting.cpp index 321506ff96e..9691321cd7a 100644 --- a/ProcessLib/LargeDeformation/ConstitutiveRelations/CreateConstitutiveSetting.cpp +++ b/ProcessLib/LargeDeformation/ConstitutiveRelations/CreateConstitutiveSetting.cpp @@ -38,10 +38,11 @@ CreateConstitutiveSetting::createSolidConstitutiveRelations( std::vector> const& parameters, std::optional const& local_coordinate_system, + MeshLib::PropertyVector const* const material_ids, BaseLib::ConfigTree const& config) { return MaterialLib::Solids::createConstitutiveRelationsGeneric( - parameters, local_coordinate_system, config, + parameters, local_coordinate_system, material_ids, config, createMFrontGeneric); } diff --git a/ProcessLib/LargeDeformation/ConstitutiveRelations/CreateConstitutiveSetting.h b/ProcessLib/LargeDeformation/ConstitutiveRelations/CreateConstitutiveSetting.h index c7f0b2247f1..ab1e5276705 100644 --- a/ProcessLib/LargeDeformation/ConstitutiveRelations/CreateConstitutiveSetting.h +++ b/ProcessLib/LargeDeformation/ConstitutiveRelations/CreateConstitutiveSetting.h @@ -11,6 +11,12 @@ #include "SolidMechanics.h" +namespace MeshLib +{ +template +class PropertyVector; +} + namespace ProcessLib::LargeDeformation { namespace ConstitutiveRelations @@ -25,6 +31,7 @@ struct CreateConstitutiveSetting parameters, std::optional const& local_coordinate_system, + MeshLib::PropertyVector const* const material_ids, BaseLib::ConfigTree const& config); }; } // namespace ConstitutiveRelations diff --git a/ProcessLib/LargeDeformation/CreateLargeDeformationProcess.cpp b/ProcessLib/LargeDeformation/CreateLargeDeformationProcess.cpp index 53d008fe2ee..f9868dd360e 100644 --- a/ProcessLib/LargeDeformation/CreateLargeDeformationProcess.cpp +++ b/ProcessLib/LargeDeformation/CreateLargeDeformationProcess.cpp @@ -72,8 +72,8 @@ std::unique_ptr createLargeDeformationProcess( /// \section parametersld Process Parameters auto solid_constitutive_relations = ConstitutiveRelations::CreateConstitutiveSetting:: - createSolidConstitutiveRelations(parameters, - local_coordinate_system, config); + createSolidConstitutiveRelations( + parameters, local_coordinate_system, materialIDs(mesh), config); // Specific body force Eigen::Matrix specific_body_force; diff --git a/ProcessLib/PhaseField/CreatePhaseFieldProcess.cpp b/ProcessLib/PhaseField/CreatePhaseFieldProcess.cpp index a9d8f3fb07c..dc906e9aa9c 100644 --- a/ProcessLib/PhaseField/CreatePhaseFieldProcess.cpp +++ b/ProcessLib/PhaseField/CreatePhaseFieldProcess.cpp @@ -106,7 +106,7 @@ std::unique_ptr createPhaseFieldProcess( /// \section parameterspf Process Parameters auto solid_constitutive_relations = MaterialLib::Solids::createConstitutiveRelations( - parameters, local_coordinate_system, config); + parameters, local_coordinate_system, materialIDs(mesh), config); auto const phasefield_parameters_config = //! \ogs_file_param{prj__processes__process__PHASE_FIELD__phasefield_parameters} diff --git a/ProcessLib/RichardsMechanics/ConstitutiveRelations/CreateConstitutiveSetting.cpp b/ProcessLib/RichardsMechanics/ConstitutiveRelations/CreateConstitutiveSetting.cpp index 8accb9ef08e..e7458337c31 100644 --- a/ProcessLib/RichardsMechanics/ConstitutiveRelations/CreateConstitutiveSetting.cpp +++ b/ProcessLib/RichardsMechanics/ConstitutiveRelations/CreateConstitutiveSetting.cpp @@ -21,10 +21,11 @@ CreateConstitutiveSetting::createSolidConstitutiveRelations( std::vector> const& parameters, std::optional const& local_coordinate_system, + MeshLib::PropertyVector const* const material_ids, BaseLib::ConfigTree const& config) { return MaterialLib::Solids::createConstitutiveRelations( - parameters, local_coordinate_system, config); + parameters, local_coordinate_system, material_ids, config); } template struct CreateConstitutiveSetting<2>; diff --git a/ProcessLib/RichardsMechanics/ConstitutiveRelations/CreateConstitutiveSetting.h b/ProcessLib/RichardsMechanics/ConstitutiveRelations/CreateConstitutiveSetting.h index d81b1d01206..e5d75993887 100644 --- a/ProcessLib/RichardsMechanics/ConstitutiveRelations/CreateConstitutiveSetting.h +++ b/ProcessLib/RichardsMechanics/ConstitutiveRelations/CreateConstitutiveSetting.h @@ -28,6 +28,7 @@ struct CreateConstitutiveSetting parameters, std::optional const& local_coordinate_system, + MeshLib::PropertyVector const* const material_ids, BaseLib::ConfigTree const& config); }; } // namespace ProcessLib::RichardsMechanics diff --git a/ProcessLib/RichardsMechanics/CreateRichardsMechanicsProcess.cpp b/ProcessLib/RichardsMechanics/CreateRichardsMechanicsProcess.cpp index e41f4ca124d..c34dcb63237 100644 --- a/ProcessLib/RichardsMechanics/CreateRichardsMechanicsProcess.cpp +++ b/ProcessLib/RichardsMechanics/CreateRichardsMechanicsProcess.cpp @@ -138,7 +138,7 @@ std::unique_ptr createRichardsMechanicsProcess( auto solid_constitutive_relations = MaterialLib::Solids::createConstitutiveRelations( - parameters, local_coordinate_system, config); + parameters, local_coordinate_system, materialIDs(mesh), config); /// \section parametersrm Process Parameters // Specific body force diff --git a/ProcessLib/SmallDeformation/ConstitutiveRelations/CreateConstitutiveSetting.cpp b/ProcessLib/SmallDeformation/ConstitutiveRelations/CreateConstitutiveSetting.cpp index d80e2be64ed..8c13a9e33e2 100644 --- a/ProcessLib/SmallDeformation/ConstitutiveRelations/CreateConstitutiveSetting.cpp +++ b/ProcessLib/SmallDeformation/ConstitutiveRelations/CreateConstitutiveSetting.cpp @@ -21,10 +21,11 @@ CreateConstitutiveSetting::createSolidConstitutiveRelations( std::vector> const& parameters, std::optional const& local_coordinate_system, + MeshLib::PropertyVector const* const material_ids, BaseLib::ConfigTree const& config) { return MaterialLib::Solids::createConstitutiveRelations( - parameters, local_coordinate_system, config); + parameters, local_coordinate_system, material_ids, config); } template struct CreateConstitutiveSetting<2>; diff --git a/ProcessLib/SmallDeformation/ConstitutiveRelations/CreateConstitutiveSetting.h b/ProcessLib/SmallDeformation/ConstitutiveRelations/CreateConstitutiveSetting.h index 0f434a3d9f6..cca822e5a37 100644 --- a/ProcessLib/SmallDeformation/ConstitutiveRelations/CreateConstitutiveSetting.h +++ b/ProcessLib/SmallDeformation/ConstitutiveRelations/CreateConstitutiveSetting.h @@ -20,6 +20,11 @@ namespace BaseLib { class ConfigTree; } +namespace MeshLib +{ +template +class PropertyVector; +} namespace ParameterLib { struct ParameterBase; @@ -40,6 +45,7 @@ struct CreateConstitutiveSetting parameters, std::optional const& local_coordinate_system, + MeshLib::PropertyVector const* const material_ids, BaseLib::ConfigTree const& config); }; } // namespace ConstitutiveRelations diff --git a/ProcessLib/SmallDeformation/CreateSmallDeformationProcess.cpp b/ProcessLib/SmallDeformation/CreateSmallDeformationProcess.cpp index 4b367bf3a0f..e54a3f4dae0 100644 --- a/ProcessLib/SmallDeformation/CreateSmallDeformationProcess.cpp +++ b/ProcessLib/SmallDeformation/CreateSmallDeformationProcess.cpp @@ -82,7 +82,7 @@ std::unique_ptr createSmallDeformationProcess( /// \section parameterssd Process Parameters auto solid_constitutive_relations = MaterialLib::Solids::createConstitutiveRelations( - parameters, local_coordinate_system, config); + parameters, local_coordinate_system, materialIDs(mesh), config); //! \ogs_file_param{prj__processes__process__SMALL_DEFORMATION__solid_density} if (config.getConfigParameterOptional("solid_density")) diff --git a/ProcessLib/SmallDeformationNonlocal/CreateSmallDeformationNonlocalProcess.cpp b/ProcessLib/SmallDeformationNonlocal/CreateSmallDeformationNonlocalProcess.cpp index 8ac1e89eddb..52300a776ed 100644 --- a/ProcessLib/SmallDeformationNonlocal/CreateSmallDeformationNonlocalProcess.cpp +++ b/ProcessLib/SmallDeformationNonlocal/CreateSmallDeformationNonlocalProcess.cpp @@ -70,7 +70,7 @@ std::unique_ptr createSmallDeformationNonlocalProcess( /// \section parameterssdnl Process Parameters auto solid_constitutive_relations = MaterialLib::Solids::createConstitutiveRelations( - parameters, local_coordinate_system, config); + parameters, local_coordinate_system, materialIDs(mesh), config); // Solid density auto const& solid_density = ParameterLib::findParameter( diff --git a/ProcessLib/TH2M/CreateTH2MProcess.cpp b/ProcessLib/TH2M/CreateTH2MProcess.cpp index f303597a8c8..27f12c9259c 100644 --- a/ProcessLib/TH2M/CreateTH2MProcess.cpp +++ b/ProcessLib/TH2M/CreateTH2MProcess.cpp @@ -176,7 +176,7 @@ std::unique_ptr createTH2MProcess( /// \section parametersth2m Process Parameters auto solid_constitutive_relations = MaterialLib::Solids::createConstitutiveRelations( - parameters, local_coordinate_system, config); + parameters, local_coordinate_system, materialIDs(mesh), config); // reference temperature const auto& reference_temperature = ParameterLib::findParameter( diff --git a/ProcessLib/ThermoHydroMechanics/CreateThermoHydroMechanicsProcess.cpp b/ProcessLib/ThermoHydroMechanics/CreateThermoHydroMechanicsProcess.cpp index 70c3e2fe2e0..2dd9a0c3de1 100644 --- a/ProcessLib/ThermoHydroMechanics/CreateThermoHydroMechanicsProcess.cpp +++ b/ProcessLib/ThermoHydroMechanics/CreateThermoHydroMechanicsProcess.cpp @@ -145,7 +145,7 @@ std::unique_ptr createThermoHydroMechanicsProcess( /// \section parametersthm Process Parameters auto solid_constitutive_relations = MaterialLib::Solids::createConstitutiveRelations( - parameters, local_coordinate_system, config); + parameters, local_coordinate_system, materialIDs(mesh), config); auto ice_constitutive_relation = MaterialLib::Solids::createConstitutiveRelationIce( diff --git a/ProcessLib/ThermoMechanicalPhaseField/CreateThermoMechanicalPhaseFieldProcess.cpp b/ProcessLib/ThermoMechanicalPhaseField/CreateThermoMechanicalPhaseFieldProcess.cpp index 057329b5431..259f4b60732 100644 --- a/ProcessLib/ThermoMechanicalPhaseField/CreateThermoMechanicalPhaseFieldProcess.cpp +++ b/ProcessLib/ThermoMechanicalPhaseField/CreateThermoMechanicalPhaseFieldProcess.cpp @@ -116,7 +116,7 @@ std::unique_ptr createThermoMechanicalPhaseFieldProcess( /// \section parameterstmpf Process Parameters auto solid_constitutive_relations = MaterialLib::Solids::createConstitutiveRelations( - parameters, local_coordinate_system, config); + parameters, local_coordinate_system, materialIDs(mesh), config); auto const phasefield_parameters_config = //! \ogs_file_param{prj__processes__process__THERMO_MECHANICAL_PHASE_FIELD__phasefield_parameters} diff --git a/ProcessLib/ThermoMechanics/CreateThermoMechanicsProcess.cpp b/ProcessLib/ThermoMechanics/CreateThermoMechanicsProcess.cpp index e8df39bc1c5..34db6aeef81 100644 --- a/ProcessLib/ThermoMechanics/CreateThermoMechanicsProcess.cpp +++ b/ProcessLib/ThermoMechanics/CreateThermoMechanicsProcess.cpp @@ -135,7 +135,7 @@ std::unique_ptr createThermoMechanicsProcess( config.peekConfigParameter("constitutive_relation"); auto solid_constitutive_relations = MaterialLib::Solids::createConstitutiveRelations( - parameters, local_coordinate_system, config); + parameters, local_coordinate_system, materialIDs(mesh), config); // Specific body force Eigen::Matrix specific_body_force; diff --git a/ProcessLib/ThermoRichardsMechanics/ConstitutiveStressSaturation_StrainPressureTemperature/CreateConstitutiveSetting.cpp b/ProcessLib/ThermoRichardsMechanics/ConstitutiveStressSaturation_StrainPressureTemperature/CreateConstitutiveSetting.cpp index a465e1af4bc..797ea88ce3d 100644 --- a/ProcessLib/ThermoRichardsMechanics/ConstitutiveStressSaturation_StrainPressureTemperature/CreateConstitutiveSetting.cpp +++ b/ProcessLib/ThermoRichardsMechanics/ConstitutiveStressSaturation_StrainPressureTemperature/CreateConstitutiveSetting.cpp @@ -39,10 +39,11 @@ CreateConstitutiveSetting::createSolidConstitutiveRelations( std::vector> const& parameters, std::optional const& local_coordinate_system, + MeshLib::PropertyVector const* const material_ids, BaseLib::ConfigTree const& config) { return MaterialLib::Solids::createConstitutiveRelationsGeneric( - parameters, local_coordinate_system, config, + parameters, local_coordinate_system, material_ids, config, createMFrontGeneric); } diff --git a/ProcessLib/ThermoRichardsMechanics/ConstitutiveStressSaturation_StrainPressureTemperature/CreateConstitutiveSetting.h b/ProcessLib/ThermoRichardsMechanics/ConstitutiveStressSaturation_StrainPressureTemperature/CreateConstitutiveSetting.h index ff7a701aa7f..bdea724476a 100644 --- a/ProcessLib/ThermoRichardsMechanics/ConstitutiveStressSaturation_StrainPressureTemperature/CreateConstitutiveSetting.h +++ b/ProcessLib/ThermoRichardsMechanics/ConstitutiveStressSaturation_StrainPressureTemperature/CreateConstitutiveSetting.h @@ -12,6 +12,11 @@ #include "TraitsBase.h" +namespace MeshLib +{ +template +class PropertyVector; +} namespace ProcessLib::ThermoRichardsMechanics { namespace ConstitutiveStressSaturation_StrainPressureTemperature @@ -26,6 +31,7 @@ struct CreateConstitutiveSetting parameters, std::optional const& local_coordinate_system, + MeshLib::PropertyVector const* const material_ids, BaseLib::ConfigTree const& config); }; } // namespace ConstitutiveStressSaturation_StrainPressureTemperature diff --git a/ProcessLib/ThermoRichardsMechanics/ConstitutiveStress_StrainTemperature/CreateConstitutiveSetting.cpp b/ProcessLib/ThermoRichardsMechanics/ConstitutiveStress_StrainTemperature/CreateConstitutiveSetting.cpp index fc33267844b..76a87d77e31 100644 --- a/ProcessLib/ThermoRichardsMechanics/ConstitutiveStress_StrainTemperature/CreateConstitutiveSetting.cpp +++ b/ProcessLib/ThermoRichardsMechanics/ConstitutiveStress_StrainTemperature/CreateConstitutiveSetting.cpp @@ -12,6 +12,12 @@ #include "MaterialLib/SolidModels/CreateConstitutiveRelation.h" +namespace MeshLib +{ +template +class PropertyVector; +} + namespace ProcessLib::ThermoRichardsMechanics { namespace ConstitutiveStress_StrainTemperature @@ -22,10 +28,11 @@ CreateConstitutiveSetting::createSolidConstitutiveRelations( std::vector> const& parameters, std::optional const& local_coordinate_system, + MeshLib::PropertyVector const* const material_ids, BaseLib::ConfigTree const& config) { return MaterialLib::Solids::createConstitutiveRelations( - parameters, local_coordinate_system, config); + parameters, local_coordinate_system, material_ids, config); } template struct CreateConstitutiveSetting<2>; diff --git a/ProcessLib/ThermoRichardsMechanics/ConstitutiveStress_StrainTemperature/CreateConstitutiveSetting.h b/ProcessLib/ThermoRichardsMechanics/ConstitutiveStress_StrainTemperature/CreateConstitutiveSetting.h index 0cd6c05a903..6d0045e98f7 100644 --- a/ProcessLib/ThermoRichardsMechanics/ConstitutiveStress_StrainTemperature/CreateConstitutiveSetting.h +++ b/ProcessLib/ThermoRichardsMechanics/ConstitutiveStress_StrainTemperature/CreateConstitutiveSetting.h @@ -15,6 +15,11 @@ #include "ParameterLib/Parameter.h" #include "TraitsBase.h" +namespace MeshLib +{ +template +class PropertyVector; +} namespace ProcessLib::ThermoRichardsMechanics { namespace ConstitutiveStress_StrainTemperature @@ -29,6 +34,7 @@ struct CreateConstitutiveSetting parameters, std::optional const& local_coordinate_system, + MeshLib::PropertyVector const* const material_ids, BaseLib::ConfigTree const& config); }; } // namespace ConstitutiveStress_StrainTemperature diff --git a/ProcessLib/ThermoRichardsMechanics/CreateThermoRichardsMechanicsProcess.cpp b/ProcessLib/ThermoRichardsMechanics/CreateThermoRichardsMechanicsProcess.cpp index 55b676f60f8..8bff9076ec9 100644 --- a/ProcessLib/ThermoRichardsMechanics/CreateThermoRichardsMechanicsProcess.cpp +++ b/ProcessLib/ThermoRichardsMechanics/CreateThermoRichardsMechanicsProcess.cpp @@ -136,7 +136,7 @@ std::unique_ptr createThermoRichardsMechanicsProcessStage2( auto solid_constitutive_relations = CreateConstitutiveSetting::createSolidConstitutiveRelations( - parameters, local_coordinate_system, config); + parameters, local_coordinate_system, materialIDs(mesh), config); // Specific body force Eigen::Matrix specific_body_force; From b8407a806eee0f0472473f6342b950e81c4bcbfe Mon Sep 17 00:00:00 2001 From: Dmitri Naumov Date: Mon, 7 Oct 2024 15:18:57 +0200 Subject: [PATCH 5/6] [MatL/S] Reuse media creation function; id='*' Reuse previously generalised and extracted functions for media map creation. This enables also to write ... in the project file. The error output has slightly changed. --- MaterialLib/SolidModels/CMakeLists.txt | 4 +- .../CreateConstitutiveRelationsGeneric.h | 48 +++++++------------ ProcessLib/SmallDeformation/Tests.cmake | 6 +-- 3 files changed, 22 insertions(+), 36 deletions(-) diff --git a/MaterialLib/SolidModels/CMakeLists.txt b/MaterialLib/SolidModels/CMakeLists.txt index c68895b48a1..251862463bd 100644 --- a/MaterialLib/SolidModels/CMakeLists.txt +++ b/MaterialLib/SolidModels/CMakeLists.txt @@ -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) diff --git a/MaterialLib/SolidModels/CreateConstitutiveRelationsGeneric.h b/MaterialLib/SolidModels/CreateConstitutiveRelationsGeneric.h index 6c41c40c378..1157316892b 100644 --- a/MaterialLib/SolidModels/CreateConstitutiveRelationsGeneric.h +++ b/MaterialLib/SolidModels/CreateConstitutiveRelationsGeneric.h @@ -40,47 +40,33 @@ createConstitutiveRelationsGeneric( for (auto const& constitutive_relation_config : constitutive_relation_configs) { + auto create = [&create_constitutive_relation, + ¶meters, + &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("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); } } diff --git a/ProcessLib/SmallDeformation/Tests.cmake b/ProcessLib/SmallDeformation/Tests.cmake index 9fcf1d903f0..0632e3c28bc 100644 --- a/ProcessLib/SmallDeformation/Tests.cmake +++ b/ProcessLib/SmallDeformation/Tests.cmake @@ -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 @@ -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 @@ -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) From b8f614177857b225f4f8579e0ab52c7406bade98 Mon Sep 17 00:00:00 2001 From: Dmitri Naumov Date: Mon, 7 Oct 2024 15:53:08 +0200 Subject: [PATCH 6/6] [T/M] Use constitutive_relation id="*" --- .../Linear/ElementDeactivation3D/element_deactivation_M_3D.prj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/Data/Mechanics/Linear/ElementDeactivation3D/element_deactivation_M_3D.prj b/Tests/Data/Mechanics/Linear/ElementDeactivation3D/element_deactivation_M_3D.prj index 6fbed6d760d..1e0c1b04e51 100644 --- a/Tests/Data/Mechanics/Linear/ElementDeactivation3D/element_deactivation_M_3D.prj +++ b/Tests/Data/Mechanics/Linear/ElementDeactivation3D/element_deactivation_M_3D.prj @@ -13,7 +13,7 @@ SD SMALL_DEFORMATION 2 - + LinearElasticIsotropic E nu