OGS
CreateThermoMechanicsProcess.cpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) OpenGeoSys Community (opengeosys.org)
2// SPDX-License-Identifier: BSD-3-Clause
3
5
6#include <cassert>
7
13#include "ParameterLib/Utils.h"
18
19namespace ProcessLib
20{
22{
24 std::map<int, std::shared_ptr<MaterialPropertyLib::Medium>> const& media)
25{
26 std::array const required_solid_properties = {
30
31 for (auto const& m : media)
32 {
33 checkRequiredProperties(m.second->phase("Solid"),
34 required_solid_properties);
35 }
36}
37
38template <int DisplacementDim>
39std::unique_ptr<Process> createThermoMechanicsProcess(
40 std::string const& name, MeshLib::Mesh& mesh,
41 std::unique_ptr<ProcessLib::AbstractJacobianAssembler>&& jacobian_assembler,
42 std::vector<ProcessVariable> const& variables,
43 std::vector<std::unique_ptr<ParameterLib::ParameterBase>> const& parameters,
44 std::optional<ParameterLib::CoordinateSystem> const&
45 local_coordinate_system,
46 unsigned const integration_order, BaseLib::ConfigTree const& config,
47 std::map<int, std::shared_ptr<MaterialPropertyLib::Medium>> const& media)
48{
50 config.checkConfigParameter("type", "THERMO_MECHANICS");
51 DBUG("Create ThermoMechanicsProcess.");
52
53 auto const coupling_scheme =
55 config.getConfigParameterOptional<std::string>("coupling_scheme");
56 const bool use_monolithic_scheme =
57 !(coupling_scheme && (*coupling_scheme == "staggered"));
58
60
62 auto const pv_config = config.getConfigSubtree("process_variables");
63
64 // Process IDs, which are set according to the appearance order of the
65 int heat_conduction_process_id = 0;
66 int mechanics_process_id = 0;
67
68 ProcessVariable* variable_T;
69 ProcessVariable* variable_u;
70 std::vector<std::vector<std::reference_wrapper<ProcessVariable>>>
71 process_variables;
72 if (use_monolithic_scheme) // monolithic scheme.
73 {
76 auto per_process_variables = findProcessVariables(
77 variables, pv_config,
78 {
79 "temperature",
81 "displacement"});
82 variable_T = &per_process_variables[0].get();
83 variable_u = &per_process_variables[1].get();
84 process_variables.push_back(std::move(per_process_variables));
85 }
86 else // staggered scheme.
87 {
88 using namespace std::string_literals;
89 for (auto const& variable_name : {"temperature"s, "displacement"s})
90 {
91 auto per_process_variables =
92 findProcessVariables(variables, pv_config, {variable_name});
93 process_variables.push_back(std::move(per_process_variables));
94 }
95 variable_T = &process_variables[0][0].get();
96 variable_u = &process_variables[1][0].get();
97 // process variables. Up to now, the ordering is fixed as:
98 heat_conduction_process_id = 0;
99 mechanics_process_id = 1;
100 }
101
102 DBUG("Associate displacement with process variable '{:s}'.",
103 variable_u->getName());
104
105 if (variable_u->getNumberOfGlobalComponents() != DisplacementDim)
106 {
107 OGS_FATAL(
108 "Number of components of the process variable '{:s}' is different "
109 "from the displacement dimension: got {:d}, expected {:d}",
110 variable_u->getName(),
111 variable_u->getNumberOfGlobalComponents(),
112 DisplacementDim);
113 }
114
115 DBUG("Associate temperature with process variable '{:s}'.",
116 variable_T->getName());
117 if (variable_T->getNumberOfGlobalComponents() != 1)
118 {
119 OGS_FATAL(
120 "Pressure process variable '{:s}' is not a scalar variable but has "
121 "{:d} components.",
122 variable_T->getName(),
123 variable_T->getNumberOfGlobalComponents());
124 }
125
128 config.peekConfigParameter<std::string>("constitutive_relation");
129 auto solid_constitutive_relations =
131 parameters, local_coordinate_system, materialIDs(mesh), config);
132
133 // Specific body force
134 Eigen::Matrix<double, DisplacementDim, 1> specific_body_force;
135 {
136 std::vector<double> const b =
138 config.getConfigParameter<std::vector<double>>(
139 "specific_body_force");
140 if (b.size() != DisplacementDim)
141 {
142 OGS_FATAL(
143 "The size of the specific body force vector does not match the "
144 "displacement dimension. Vector size is {:d}, displacement "
145 "dimension is {:d}",
146 b.size(), DisplacementDim);
147 }
148
149 std::copy_n(b.data(), b.size(), specific_body_force.data());
150 }
151
152 // Initial stress conditions
153 auto const initial_stress = ParameterLib::findOptionalTagParameter<double>(
155 config, "initial_stress", parameters,
156 // Symmetric tensor size, 4 or 6, not a Kelvin vector.
158 &mesh);
159
160 auto media_map =
162 DBUG("Check the solid properties of ThermoMechanics process ...");
163 checkMPLProperties(media);
164 DBUG("Solid properties verified.");
165
167 materialIDs(mesh),
168 std::move(media_map),
169 std::move(solid_constitutive_relations),
170 initial_stress,
171 specific_body_force,
172 mechanics_process_id,
173 heat_conduction_process_id};
174
175 SecondaryVariableCollection secondary_variables;
176
177 ProcessLib::createSecondaryVariables(config, secondary_variables);
178
179 return std::make_unique<ThermoMechanicsProcess<DisplacementDim>>(
180 std::move(name), mesh, std::move(jacobian_assembler), parameters,
181 integration_order, std::move(process_variables),
182 std::move(process_data), std::move(secondary_variables),
183 use_monolithic_scheme);
184}
185
186template std::unique_ptr<Process> createThermoMechanicsProcess<2>(
187 std::string const& name,
188 MeshLib::Mesh& mesh,
189 std::unique_ptr<ProcessLib::AbstractJacobianAssembler>&& jacobian_assembler,
190 std::vector<ProcessVariable> const& variables,
191 std::vector<std::unique_ptr<ParameterLib::ParameterBase>> const& parameters,
192 std::optional<ParameterLib::CoordinateSystem> const&
193 local_coordinate_system,
194 unsigned const integration_order,
195 BaseLib::ConfigTree const& config,
196 std::map<int, std::shared_ptr<MaterialPropertyLib::Medium>> const& media);
197
198template std::unique_ptr<Process> createThermoMechanicsProcess<3>(
199 std::string const& name,
200 MeshLib::Mesh& mesh,
201 std::unique_ptr<ProcessLib::AbstractJacobianAssembler>&& jacobian_assembler,
202 std::vector<ProcessVariable> const& variables,
203 std::vector<std::unique_ptr<ParameterLib::ParameterBase>> const& parameters,
204 std::optional<ParameterLib::CoordinateSystem> const&
205 local_coordinate_system,
206 unsigned const integration_order,
207 BaseLib::ConfigTree const& config,
208 std::map<int, std::shared_ptr<MaterialPropertyLib::Medium>> const& media);
209
210} // namespace ThermoMechanics
211} // namespace ProcessLib
#define OGS_FATAL(...)
Definition Error.h:19
void DBUG(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:22
T peekConfigParameter(std::string const &param) const
std::optional< T > getConfigParameterOptional(std::string const &param) const
T getConfigParameter(std::string const &param) const
ConfigTree getConfigSubtree(std::string const &root) const
void checkConfigParameter(std::string const &param, std::string_view const value) const
std::string const & getName() const
int getNumberOfGlobalComponents() const
Returns the number of components of the process variable.
Handles configuration of several secondary variables from the project file.
std::map< int, std::shared_ptr< MaterialLib::Solids::MechanicsBase< DisplacementDim > > > createConstitutiveRelations(std::vector< std::unique_ptr< ParameterLib::ParameterBase > > const &parameters, std::optional< ParameterLib::CoordinateSystem > const &local_coordinate_system, MeshLib::PropertyVector< int > const *const material_ids, BaseLib::ConfigTree const &config)
MaterialSpatialDistributionMap createMaterialSpatialDistributionMap(std::map< int, std::shared_ptr< Medium > > const &media, MeshLib::Mesh const &mesh)
constexpr int kelvin_vector_dimensions(int const displacement_dim)
Kelvin vector dimensions for given displacement dimension.
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)
template std::unique_ptr< Process > createThermoMechanicsProcess< 3 >(std::string const &name, MeshLib::Mesh &mesh, std::unique_ptr< ProcessLib::AbstractJacobianAssembler > &&jacobian_assembler, std::vector< ProcessVariable > const &variables, std::vector< std::unique_ptr< ParameterLib::ParameterBase > > const &parameters, std::optional< ParameterLib::CoordinateSystem > const &local_coordinate_system, unsigned const integration_order, BaseLib::ConfigTree const &config, std::map< int, std::shared_ptr< MaterialPropertyLib::Medium > > const &media)
std::unique_ptr< Process > createThermoMechanicsProcess(std::string const &name, MeshLib::Mesh &mesh, std::unique_ptr< ProcessLib::AbstractJacobianAssembler > &&jacobian_assembler, std::vector< ProcessVariable > const &variables, std::vector< std::unique_ptr< ParameterLib::ParameterBase > > const &parameters, std::optional< ParameterLib::CoordinateSystem > const &local_coordinate_system, unsigned const integration_order, BaseLib::ConfigTree const &config, std::map< int, std::shared_ptr< MaterialPropertyLib::Medium > > const &media)
void checkMPLProperties(std::map< int, std::shared_ptr< MaterialPropertyLib::Medium > > const &media)
template std::unique_ptr< Process > createThermoMechanicsProcess< 2 >(std::string const &name, MeshLib::Mesh &mesh, std::unique_ptr< ProcessLib::AbstractJacobianAssembler > &&jacobian_assembler, std::vector< ProcessVariable > const &variables, std::vector< std::unique_ptr< ParameterLib::ParameterBase > > const &parameters, std::optional< ParameterLib::CoordinateSystem > const &local_coordinate_system, unsigned const integration_order, BaseLib::ConfigTree const &config, std::map< int, std::shared_ptr< MaterialPropertyLib::Medium > > const &media)
std::vector< std::reference_wrapper< ProcessVariable > > findProcessVariables(std::vector< ProcessVariable > const &variables, BaseLib::ConfigTree const &pv_config, std::initializer_list< std::string > tags)
void createSecondaryVariables(BaseLib::ConfigTree const &config, SecondaryVariableCollection &secondary_variables)