diff --git a/MaterialLib/SolidModels/CreateConstitutiveRelation.cpp b/MaterialLib/SolidModels/CreateConstitutiveRelation.cpp index 41a0002acdbd0eb18a813955d03381eb91587770..1f8ac0c61d0c0189ecd38d12ff4e2d9304c4e537 100644 --- a/MaterialLib/SolidModels/CreateConstitutiveRelation.cpp +++ b/MaterialLib/SolidModels/CreateConstitutiveRelation.cpp @@ -33,47 +33,83 @@ createConstitutiveRelation( std::vector<std::unique_ptr<ProcessLib::ParameterBase>> const& parameters, BaseLib::ConfigTree const& config) { - auto const constitutive_relation_config = - //! \ogs_file_param{material__solid__constitutive_relation} - config.getConfigSubtree("constitutive_relation"); - auto const type = //! \ogs_file_param{material__solid__constitutive_relation__type} - constitutive_relation_config.peekConfigParameter<std::string>("type"); + config.peekConfigParameter<std::string>("type"); if (type == "Ehlers") { return MaterialLib::Solids::Ehlers::createEhlers<DisplacementDim>( - parameters, constitutive_relation_config); + parameters, config); } if (type == "LinearElasticIsotropic") { const bool skip_type_checking = false; return MaterialLib::Solids::createLinearElasticIsotropic< - DisplacementDim>( - parameters, constitutive_relation_config, skip_type_checking); + DisplacementDim>(parameters, config, skip_type_checking); } if (type == "Lubby2") { return MaterialLib::Solids::Lubby2::createLubby2<DisplacementDim>( - parameters, constitutive_relation_config); + parameters, config); } if (type == "CreepBGRa") { return MaterialLib::Solids::Creep::createCreepBGRa<DisplacementDim>( - parameters, constitutive_relation_config); + parameters, config); } OGS_FATAL("Cannot construct constitutive relation of given type \'%s\'.", type.c_str()); } -template std::unique_ptr<MaterialLib::Solids::MechanicsBase<2>> -createConstitutiveRelation<2>( +template <int DisplacementDim> +std::map<int, + std::unique_ptr<MaterialLib::Solids::MechanicsBase<DisplacementDim>>> +createConstitutiveRelations( + std::vector<std::unique_ptr<ProcessLib::ParameterBase>> const& parameters, + BaseLib::ConfigTree const& config) +{ + auto const constitutive_relation_configs = + //! \ogs_file_param{material__solid__constitutive_relation} + config.getConfigSubtreeList("constitutive_relation"); + + std::map<int, std::unique_ptr<MechanicsBase<DisplacementDim>>> + constitutive_relations; + + for (auto const& constitutive_relation_config : + constitutive_relation_configs) + { + int const material_id = + constitutive_relation_config.getConfigAttribute<int>("id", 0); + + 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); + } + + constitutive_relations.emplace( + material_id, + createConstitutiveRelation<DisplacementDim>( + parameters, constitutive_relation_config)); + } + + DBUG("Found %d constitutive relations.", constitutive_relations.size()); + + return constitutive_relations; +} + +template std::map<int, std::unique_ptr<MaterialLib::Solids::MechanicsBase<2>>> +createConstitutiveRelations<2>( std::vector<std::unique_ptr<ProcessLib::ParameterBase>> const& parameters, BaseLib::ConfigTree const& config); -template std::unique_ptr<MaterialLib::Solids::MechanicsBase<3>> -createConstitutiveRelation<3>( +template std::map<int, std::unique_ptr<MaterialLib::Solids::MechanicsBase<3>>> +createConstitutiveRelations<3>( std::vector<std::unique_ptr<ProcessLib::ParameterBase>> const& parameters, BaseLib::ConfigTree const& config); } diff --git a/MaterialLib/SolidModels/CreateConstitutiveRelation.h b/MaterialLib/SolidModels/CreateConstitutiveRelation.h index 15c43ebf81a20513d59894b0c8be6b0a036049b6..e1e4bba9421f49941a6d9e2bc41c1cfda87a96ea 100644 --- a/MaterialLib/SolidModels/CreateConstitutiveRelation.h +++ b/MaterialLib/SolidModels/CreateConstitutiveRelation.h @@ -11,6 +11,7 @@ #pragma once +#include <map> #include <memory> #include <vector> @@ -32,18 +33,21 @@ template <int DisplacementDim> struct MechanicsBase; template <int DisplacementDim> -std::unique_ptr<MaterialLib::Solids::MechanicsBase<DisplacementDim>> -createConstitutiveRelation( +std::map<int, + std::unique_ptr<MaterialLib::Solids::MechanicsBase<DisplacementDim>>> +createConstitutiveRelations( std::vector<std::unique_ptr<ProcessLib::ParameterBase>> const& parameters, BaseLib::ConfigTree const& config); -extern template std::unique_ptr<MaterialLib::Solids::MechanicsBase<2>> -createConstitutiveRelation<2>( +extern template std::map<int, + std::unique_ptr<MaterialLib::Solids::MechanicsBase<2>>> +createConstitutiveRelations<2>( std::vector<std::unique_ptr<ProcessLib::ParameterBase>> const& parameters, BaseLib::ConfigTree const& config); -extern template std::unique_ptr<MaterialLib::Solids::MechanicsBase<3>> -createConstitutiveRelation<3>( +extern template std::map<int, + std::unique_ptr<MaterialLib::Solids::MechanicsBase<3>>> +createConstitutiveRelations<3>( std::vector<std::unique_ptr<ProcessLib::ParameterBase>> const& parameters, BaseLib::ConfigTree const& config); }