diff --git a/MaterialLib/SolidModels/MFront/CreateMFrontGeneric.cpp b/MaterialLib/SolidModels/MFront/CreateMFrontGeneric.cpp index f447d67d02c79a69f9003b00d9c14330c26b5d06..ef89af2b68cd128e326ec573b1f7c8bc9c7a7d8c 100644 --- a/MaterialLib/SolidModels/MFront/CreateMFrontGeneric.cpp +++ b/MaterialLib/SolidModels/MFront/CreateMFrontGeneric.cpp @@ -94,6 +94,87 @@ void varInfo(std::string const& msg, std::vector<std::string> const& parameters) INFO(" --> with name `{:s}'.", parameter); } } + +std::vector<ParameterLib::Parameter<double> const*> readMaterialProperties( + mgis::behaviour::Behaviour const& behaviour, + mgis::behaviour::Hypothesis const& hypothesis, + std::vector<std::unique_ptr<ParameterLib::ParameterBase>> const& parameters, + BaseLib::ConfigTree const& config) +{ + if (behaviour.mps.empty()) + { + return {}; + } + + std::map<std::string, std::string> map_name_to_param; + + // gather material properties from the prj file + //! \ogs_file_param{material__solid__constitutive_relation__MFront__material_properties} + auto const mps_config = config.getConfigSubtree("material_properties"); + for ( + auto const mp_config : + //! \ogs_file_param{material__solid__constitutive_relation__MFront__material_properties__material_property} + mps_config.getConfigParameterList("material_property")) + { + //! \ogs_file_attr{material__solid__constitutive_relation__MFront__material_properties__material_property__name} + auto name = mp_config.getConfigAttribute<std::string>("name"); + auto const param_name = + //! \ogs_file_attr{material__solid__constitutive_relation__MFront__material_properties__material_property__parameter} + mp_config.getConfigAttribute<std::string>("parameter"); + + map_name_to_param.emplace(std::move(name), std::move(param_name)); + } + + std::vector<ParameterLib::Parameter<double> const*> material_properties; + for (auto& mp : behaviour.mps) + { + auto const it = map_name_to_param.find(mp.name); + if (it == map_name_to_param.end()) + OGS_FATAL( + "Material Property `{:s}' has not been configured in the " + "project file.", + mp.name); + + auto const param_name = it->second; + auto const num_comp = mgis::behaviour::getVariableSize(mp, hypothesis); + auto const* param = &ParameterLib::findParameter<double>( + param_name, parameters, num_comp); + + INFO("Using OGS parameter `{:s}' for material property `{:s}'.", + param_name, mp.name); + + using V = mgis::behaviour::Variable; + if (mp.type == V::STENSOR || mp.type == V::TENSOR) + { + WARN( + "Material property `{:s}' is a tensorial quantity. You, " + "the " + "user, have to make sure that the component order of " + "parameter `{:s}' matches the one required by MFront!", + mp.name, param_name); + } + + material_properties.push_back(param); + map_name_to_param.erase(it); + } + + if (!map_name_to_param.empty()) + { + ERR("Some material parameters that were configured are not used by " + "the material model."); + ERR("These parameters are:"); + + for (auto& e : map_name_to_param) + { + ERR(" name: `{:s}', parameter: `{:s}'.", e.first, e.second); + } + + OGS_FATAL( + "Configuration errors occurred. Please fix the project file."); + } + + return material_properties; +} } // namespace namespace MaterialLib::Solids::MFront @@ -181,77 +262,8 @@ MFrontConfig createMFrontConfig( INFO(" --> ({}, {}).", var1.name, var2.name); } - std::vector<ParameterLib::Parameter<double> const*> material_properties; - - if (!behaviour.mps.empty()) - { - std::map<std::string, std::string> map_name_to_param; - - // gather material properties from the prj file - //! \ogs_file_param{material__solid__constitutive_relation__MFront__material_properties} - auto const mps_config = config.getConfigSubtree("material_properties"); - for ( - auto const mp_config : - //! \ogs_file_param{material__solid__constitutive_relation__MFront__material_properties__material_property} - mps_config.getConfigParameterList("material_property")) - { - //! \ogs_file_attr{material__solid__constitutive_relation__MFront__material_properties__material_property__name} - auto name = mp_config.getConfigAttribute<std::string>("name"); - auto const param_name = - //! \ogs_file_attr{material__solid__constitutive_relation__MFront__material_properties__material_property__parameter} - mp_config.getConfigAttribute<std::string>("parameter"); - - map_name_to_param.emplace(std::move(name), std::move(param_name)); - } - - for (auto& mp : behaviour.mps) - { - auto const it = map_name_to_param.find(mp.name); - if (it == map_name_to_param.end()) - OGS_FATAL( - "Material Property `{:s}' has not been configured in the " - "project file.", - mp.name); - - auto const param_name = it->second; - auto const num_comp = - mgis::behaviour::getVariableSize(mp, hypothesis); - auto const* param = &ParameterLib::findParameter<double>( - param_name, parameters, num_comp); - - INFO("Using OGS parameter `{:s}' for material property `{:s}'.", - param_name, mp.name); - - using V = mgis::behaviour::Variable; - if (mp.type == V::STENSOR || mp.type == V::TENSOR) - { - WARN( - "Material property `{:s}' is a tensorial quantity. You, " - "the " - "user, have to make sure that the component order of " - "parameter `{:s}' matches the one required by MFront!", - mp.name, param_name); - } - - material_properties.push_back(param); - map_name_to_param.erase(it); - } - - if (!map_name_to_param.empty()) - { - ERR("Some material parameters that were configured are not used by " - "the material model."); - ERR("These parameters are:"); - - for (auto& e : map_name_to_param) - { - ERR(" name: `{:s}', parameter: `{:s}'.", e.first, e.second); - } - - OGS_FATAL( - "Configuration errors occurred. Please fix the project file."); - } - } + std::vector<ParameterLib::Parameter<double> const*> material_properties = + readMaterialProperties(behaviour, hypothesis, parameters, config); INFO("### MFRONT END ####################################################");