From 8594d7388029fa28c9a5c074a99189942f648e74 Mon Sep 17 00:00:00 2001 From: Dmitri Naumov <dmitri.naumov@ufz.de> Date: Wed, 28 Aug 2019 12:20:42 +0200 Subject: [PATCH] [PL] Extract parsing of initial stress. Adding a new function for parameter lookup of optional tags. --- ParameterLib/Utils.h | 34 +++++++++++++++++++ .../CreateSmallDeformationProcess.cpp | 25 ++++---------- .../CreateThermoMechanicsProcess.cpp | 24 ++++--------- 3 files changed, 46 insertions(+), 37 deletions(-) diff --git a/ParameterLib/Utils.h b/ParameterLib/Utils.h index a2a4dcebadd..a65f7469d47 100644 --- a/ParameterLib/Utils.h +++ b/ParameterLib/Utils.h @@ -142,4 +142,38 @@ Parameter<ParameterDataType>& findParameter( return findParameter<ParameterDataType>(name, parameters, num_components, mesh); } + +/// Find a parameter of specific type for a name given in the process +/// configuration under the optional tag. +/// If the tag is not present, a nullptr will be returned. +/// The parameter must have the specified number of components. +/// In the process config a parameter is referenced by a name. For example it +/// will be looking for a parameter named "K" in the list of parameters +/// when the tag is "hydraulic_conductivity": +/// \code +/// <process> +/// ... +/// <hydraulic_conductivity>K</hydraulic_conductivity> +/// </process> +/// \endcode +/// and return a pointer to that parameter. Additionally it checks for the +/// type of the found parameter. +template <typename ParameterDataType> +Parameter<ParameterDataType>* findOptionalTagParameter( + BaseLib::ConfigTree const& process_config, std::string const& tag, + std::vector<std::unique_ptr<ParameterBase>> const& parameters, + int const num_components, MeshLib::Mesh const* const mesh = nullptr) +{ + // Find parameter name in process config. + auto const name = + //! \ogs_file_special + process_config.getConfigParameterOptional<std::string>(tag); + + if (!name) + { + return nullptr; + } + return &findParameter<ParameterDataType>(*name, parameters, num_components, + mesh); +} } // namespace ParameterLib diff --git a/ProcessLib/SmallDeformation/CreateSmallDeformationProcess.cpp b/ProcessLib/SmallDeformation/CreateSmallDeformationProcess.cpp index 24d6e9a4083..21a03970930 100644 --- a/ProcessLib/SmallDeformation/CreateSmallDeformationProcess.cpp +++ b/ProcessLib/SmallDeformation/CreateSmallDeformationProcess.cpp @@ -12,7 +12,6 @@ #include <cassert> #include "MaterialLib/SolidModels/CreateConstitutiveRelation.h" -#include "MathLib/KelvinVector.h" #include "ParameterLib/Utils.h" #include "ProcessLib/Output/CreateSecondaryVariables.h" #include "ProcessLib/Utils/ProcessUtils.h" @@ -104,24 +103,12 @@ std::unique_ptr<Process> createSmallDeformationProcess( "reference_temperature", std::numeric_limits<double>::quiet_NaN()); // Initial stress conditions - ParameterLib::Parameter<double> const* initial_stress = nullptr; - auto const initial_stress_parameter_name = - //! \ogs_file_param{prj__processes__process__SMALL_DEFORMATION__initial_stress} - config.getConfigParameterOptional<std::string>("initial_stress"); - if (initial_stress_parameter_name) - { - initial_stress = ParameterLib::findParameterOptional<double>( - *initial_stress_parameter_name, parameters, - // Symmetric tensor size, 4 or 6, not a Kelvin vector. - MathLib::KelvinVector::KelvinVectorDimensions< - DisplacementDim>::value, - &mesh); - } - if (initial_stress != nullptr) - { - DBUG("Use '%s' as initial stress parameter.", - initial_stress->name.c_str()); - } + auto const initial_stress = ParameterLib::findOptionalTagParameter<double>( + //! \ogs_file_param_special{prj__processes__process__SMALL_DEFORMATION__initial_stress} + config, "initial_stress", parameters, + // Symmetric tensor size, 4 or 6, not a Kelvin vector. + MathLib::KelvinVector::KelvinVectorDimensions<DisplacementDim>::value, + &mesh); SmallDeformationProcessData<DisplacementDim> process_data{ materialIDs(mesh), std::move(solid_constitutive_relations), diff --git a/ProcessLib/ThermoMechanics/CreateThermoMechanicsProcess.cpp b/ProcessLib/ThermoMechanics/CreateThermoMechanicsProcess.cpp index deaf6f9c047..383570020b0 100644 --- a/ProcessLib/ThermoMechanics/CreateThermoMechanicsProcess.cpp +++ b/ProcessLib/ThermoMechanics/CreateThermoMechanicsProcess.cpp @@ -168,24 +168,12 @@ std::unique_ptr<Process> createThermoMechanicsProcess( } // Initial stress conditions - ParameterLib::Parameter<double> const* initial_stress = nullptr; - auto const initial_stress_parameter_name = - //! \ogs_file_param{prj__processes__process__THERMO_MECHANICS__initial_stress} - config.getConfigParameterOptional<std::string>("initial_stress"); - if (initial_stress_parameter_name) - { - initial_stress = ParameterLib::findParameterOptional<double>( - *initial_stress_parameter_name, parameters, - // Symmetric tensor size, 4 or 6, not a Kelvin vector. - MathLib::KelvinVector::KelvinVectorDimensions< - DisplacementDim>::value, - &mesh); - } - if (initial_stress != nullptr) - { - DBUG("Use '%s' as initial stress parameter.", - initial_stress->name.c_str()); - } + auto const initial_stress = ParameterLib::findOptionalTagParameter<double>( + //! \ogs_file_param_special{prj__processes__process__THERMO_MECHANICS__initial_stress} + config, "initial_stress", parameters, + // Symmetric tensor size, 4 or 6, not a Kelvin vector. + MathLib::KelvinVector::KelvinVectorDimensions<DisplacementDim>::value, + &mesh); ThermoMechanicsProcessData<DisplacementDim> process_data{ materialIDs(mesh), -- GitLab