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(
35 required_solid_properties);
36 }
37}
38
39template <int DisplacementDim>
40std::unique_ptr<Process> createThermoMechanicsProcess(
41 std::string const& name, MeshLib::Mesh& mesh,
42 std::unique_ptr<ProcessLib::AbstractJacobianAssembler>&& jacobian_assembler,
43 std::vector<ProcessVariable> const& variables,
44 std::vector<std::unique_ptr<ParameterLib::ParameterBase>> const& parameters,
45 std::optional<ParameterLib::CoordinateSystem> const&
46 local_coordinate_system,
47 unsigned const integration_order, BaseLib::ConfigTree const& config,
48 std::map<int, std::shared_ptr<MaterialPropertyLib::Medium>> const& media)
49{
51 config.checkConfigParameter("type", "THERMO_MECHANICS");
52 DBUG("Create ThermoMechanicsProcess.");
53
54 auto const coupling_scheme =
56 config.getConfigParameterOptional<std::string>("coupling_scheme");
57 const bool use_monolithic_scheme =
58 !(coupling_scheme && (*coupling_scheme == "staggered"));
59
61
63 auto const pv_config = config.getConfigSubtree("process_variables");
64
65 // Process IDs, which are set according to the appearance order of the
66 int heat_conduction_process_id = 0;
67 int mechanics_process_id = 0;
68
69 ProcessVariable* variable_T;
70 ProcessVariable* variable_u;
71 std::vector<std::vector<std::reference_wrapper<ProcessVariable>>>
72 process_variables;
73 if (use_monolithic_scheme) // monolithic scheme.
74 {
77 auto per_process_variables = findProcessVariables(
78 variables, pv_config,
79 {
80 "temperature",
82 "displacement"});
83 variable_T = &per_process_variables[0].get();
84 variable_u = &per_process_variables[1].get();
85 process_variables.push_back(std::move(per_process_variables));
86 }
87 else // staggered scheme.
88 {
89 using namespace std::string_literals;
90 for (auto const& variable_name : {"temperature"s, "displacement"s})
91 {
92 auto per_process_variables =
93 findProcessVariables(variables, pv_config, {variable_name});
94 process_variables.push_back(std::move(per_process_variables));
95 }
96 variable_T = &process_variables[0][0].get();
97 variable_u = &process_variables[1][0].get();
98 // process variables. Up to now, the ordering is fixed as:
99 heat_conduction_process_id = 0;
100 mechanics_process_id = 1;
101 }
102
103 DBUG("Associate displacement with process variable '{:s}'.",
104 variable_u->getName());
105
106 if (variable_u->getNumberOfGlobalComponents() != DisplacementDim)
107 {
108 OGS_FATAL(
109 "Number of components of the process variable '{:s}' is different "
110 "from the displacement dimension: got {:d}, expected {:d}",
111 variable_u->getName(),
112 variable_u->getNumberOfGlobalComponents(),
113 DisplacementDim);
114 }
115
116 DBUG("Associate temperature with process variable '{:s}'.",
117 variable_T->getName());
118 if (variable_T->getNumberOfGlobalComponents() != 1)
119 {
120 OGS_FATAL(
121 "Pressure process variable '{:s}' is not a scalar variable but has "
122 "{:d} components.",
123 variable_T->getName(),
124 variable_T->getNumberOfGlobalComponents());
125 }
126
129 config.peekConfigParameter<std::string>("constitutive_relation");
130 auto solid_constitutive_relations =
132 parameters, local_coordinate_system, materialIDs(mesh), config);
133
134 // Specific body force
135 Eigen::Matrix<double, DisplacementDim, 1> specific_body_force;
136 {
137 std::vector<double> const b =
139 config.getConfigParameter<std::vector<double>>(
140 "specific_body_force");
141 if (b.size() != DisplacementDim)
142 {
143 OGS_FATAL(
144 "The size of the specific body force vector does not match the "
145 "displacement dimension. Vector size is {:d}, displacement "
146 "dimension is {:d}",
147 b.size(), DisplacementDim);
148 }
149
150 std::copy_n(b.data(), b.size(), specific_body_force.data());
151 }
152
153 // Initial stress conditions
154 auto const initial_stress = ParameterLib::findOptionalTagParameter<double>(
156 config, "initial_stress", parameters,
157 // Symmetric tensor size, 4 or 6, not a Kelvin vector.
159 &mesh);
160
161 auto media_map =
163 DBUG("Check the solid properties of ThermoMechanics process ...");
164 checkMPLProperties(media);
165 DBUG("Solid properties verified.");
166
168 materialIDs(mesh),
169 std::move(media_map),
170 std::move(solid_constitutive_relations),
171 initial_stress,
172 specific_body_force,
173 mechanics_process_id,
174 heat_conduction_process_id};
175
176 SecondaryVariableCollection secondary_variables;
177
178 ProcessLib::createSecondaryVariables(config, secondary_variables);
179
180 return std::make_unique<ThermoMechanicsProcess<DisplacementDim>>(
181 std::move(name), mesh, std::move(jacobian_assembler), parameters,
182 integration_order, std::move(process_variables),
183 std::move(process_data), std::move(secondary_variables),
184 use_monolithic_scheme);
185}
186
187template std::unique_ptr<Process> createThermoMechanicsProcess<2>(
188 std::string const& name,
189 MeshLib::Mesh& mesh,
190 std::unique_ptr<ProcessLib::AbstractJacobianAssembler>&& jacobian_assembler,
191 std::vector<ProcessVariable> const& variables,
192 std::vector<std::unique_ptr<ParameterLib::ParameterBase>> const& parameters,
193 std::optional<ParameterLib::CoordinateSystem> const&
194 local_coordinate_system,
195 unsigned const integration_order,
196 BaseLib::ConfigTree const& config,
197 std::map<int, std::shared_ptr<MaterialPropertyLib::Medium>> const& media);
198
199template std::unique_ptr<Process> createThermoMechanicsProcess<3>(
200 std::string const& name,
201 MeshLib::Mesh& mesh,
202 std::unique_ptr<ProcessLib::AbstractJacobianAssembler>&& jacobian_assembler,
203 std::vector<ProcessVariable> const& variables,
204 std::vector<std::unique_ptr<ParameterLib::ParameterBase>> const& parameters,
205 std::optional<ParameterLib::CoordinateSystem> const&
206 local_coordinate_system,
207 unsigned const integration_order,
208 BaseLib::ConfigTree const& config,
209 std::map<int, std::shared_ptr<MaterialPropertyLib::Medium>> const& media);
210
211} // namespace ThermoMechanics
212} // 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)