OGS
CreateTH2MProcess.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
4#include "CreateTH2MProcess.h"
5
6#include <cassert>
7
12#include "ParameterLib/Utils.h"
18#include "TH2MProcess.h"
19#include "TH2MProcessData.h"
20
21namespace ProcessLib
22{
23namespace TH2M
24{
25std::unique_ptr<ConstitutiveRelations::PhaseTransitionModel>
27 std::map<int, std::shared_ptr<MaterialPropertyLib::Medium>> const& media)
28{
29 // the approach here is that the number of phase components determines the
30 // nature of the phase transition: If the gas phase consists of two or more
31 // components, evaporation is involved; if the water phase consists of at
32 // least two components, gas can be dissolved in water.
33
34 // Fluid phases are always defined in the first medium of the media vector,
35 // thus media.begin() points to the right medium.
36 const bool phase_transition =
37 (media.begin()->second->phase("Gas").numberOfComponents() > 1) &&
38 (media.begin()->second->phase("AqueousLiquid").numberOfComponents() >
39 1);
40 // Only if both fluids consist of more than one component, the model
41 // phase_transition is returned.
42 if (phase_transition)
43 {
44 return std::make_unique<ConstitutiveRelations::PhaseTransition>(media);
45 }
46 return std::make_unique<ConstitutiveRelations::NoPhaseTransition>(media);
47}
48
49template <int DisplacementDim>
50std::unique_ptr<Process> createTH2MProcess(
51 std::string const& name, MeshLib::Mesh& mesh,
52 std::unique_ptr<ProcessLib::AbstractJacobianAssembler>&& jacobian_assembler,
53 std::vector<ProcessVariable> const& variables,
54 std::vector<std::unique_ptr<ParameterLib::ParameterBase>> const& parameters,
55 std::optional<ParameterLib::CoordinateSystem> const&
56 local_coordinate_system,
57 unsigned const integration_order, BaseLib::ConfigTree const& config,
58 std::map<int, std::shared_ptr<MaterialPropertyLib::Medium>> const& media)
59{
61 config.checkConfigParameter("type", "TH2M");
62 DBUG("Create TH2M Process.");
63 DBUG(" ");
64
65 auto const coupling_scheme =
67 config.getConfigParameterOptional<std::string>("coupling_scheme");
68 const bool use_monolithic_scheme =
69 !(coupling_scheme && (*coupling_scheme == "staggered"));
70
72
74 auto const pv_config = config.getConfigSubtree("process_variables");
75
76 ProcessVariable* variable_pGR;
77 ProcessVariable* variable_pCap;
78 ProcessVariable* variable_T;
79 ProcessVariable* variable_u;
80 std::vector<std::vector<std::reference_wrapper<ProcessVariable>>>
81 process_variables;
82 if (use_monolithic_scheme) // monolithic scheme.
83 {
86 auto per_process_variables = findProcessVariables(
87 variables, pv_config,
88 {
89 "gas_pressure",
91 "capillary_pressure",
93 "temperature",
95 "displacement"});
96 variable_pGR = &per_process_variables[0].get();
97 variable_pCap = &per_process_variables[1].get();
98 variable_T = &per_process_variables[2].get();
99 variable_u = &per_process_variables[3].get();
100 process_variables.push_back(std::move(per_process_variables));
101 }
102 else // staggered scheme.
103 {
104 OGS_FATAL("A Staggered version of TH2M is not implemented.");
105
106 using namespace std::string_literals;
107 for (auto const& variable_name :
108 {"gas_pressure"s, "capillary_pressure"s, "temperature"s,
109 "displacement"s})
110 {
111 auto per_process_variables =
112 findProcessVariables(variables, pv_config, {variable_name});
113 process_variables.push_back(std::move(per_process_variables));
114 }
115 variable_pGR = &process_variables[0][0].get();
116 variable_pCap = &process_variables[1][0].get();
117 variable_T = &process_variables[2][0].get();
118 variable_u = &process_variables[3][0].get();
119 }
120
121 DBUG("Associate displacement with process variable '{:s}'.",
122 variable_u->getName());
123
124 if (variable_u->getNumberOfGlobalComponents() != DisplacementDim)
125 {
126 OGS_FATAL(
127 "Number of components of the process variable '{:s}' is different "
128 "from the displacement dimension: got {:d}, expected {:d}",
129 variable_u->getName(),
130 variable_u->getNumberOfGlobalComponents(),
131 DisplacementDim);
132 }
133
134 DBUG("Associate gas pressure with process variable '{:s}'.",
135 variable_pGR->getName());
136 if (variable_pGR->getNumberOfGlobalComponents() != 1)
137 {
138 OGS_FATAL(
139 "Gas pressure process variable '{:s}' is not a scalar variable but "
140 "has "
141 "{:d} components.",
142 variable_pGR->getName(),
143 variable_pGR->getNumberOfGlobalComponents());
144 }
145
146 DBUG("Associate capillary pressure with process variable '{:s}'.",
147 variable_pCap->getName());
148 if (variable_pCap->getNumberOfGlobalComponents() != 1)
149 {
150 OGS_FATAL(
151 "Capillary pressure process variable '{:s}' is not a scalar "
152 "variable but has "
153 "{:d} components.",
154 variable_pCap->getName(),
155 variable_pCap->getNumberOfGlobalComponents());
156 }
157
158 DBUG("Associate temperature with process variable '{:s}'.",
159 variable_T->getName());
160 if (variable_T->getNumberOfGlobalComponents() != 1)
161 {
162 OGS_FATAL(
163 "temperature process variable '{:s}' is not a scalar variable but "
164 "has {:d} components.",
165 variable_T->getName(),
166 variable_T->getNumberOfGlobalComponents());
167 }
168
170 auto solid_constitutive_relations =
172 parameters, local_coordinate_system, materialIDs(mesh), config);
173
174 // reference temperature
175 const auto& reference_temperature = ParameterLib::findParameter<double>(
176 config,
178 "reference_temperature", parameters, 1, &mesh);
179 DBUG("Use '{:s}' as reference temperature parameter.",
180 reference_temperature.name);
181
182 // Specific body force
183 Eigen::Matrix<double, DisplacementDim, 1> specific_body_force;
184 {
185 std::vector<double> const b =
187 config.getConfigParameter<std::vector<double>>(
188 "specific_body_force");
189 if (b.size() != DisplacementDim)
190 {
191 OGS_FATAL(
192 "The size of the specific body force vector does not match the "
193 "displacement dimension. Vector size is {:d}, displacement "
194 "dimension is {:d}",
195 b.size(), DisplacementDim);
196 }
197
198 std::copy_n(b.data(), b.size(), specific_body_force.data());
199 }
200
201 // Initial stress conditions
203 config, parameters, mesh);
204
205 auto const mass_lumping =
207 config.getConfigParameter<bool>("mass_lumping", false);
208 auto const is_linear =
210 config.getConfigParameter("linear", false);
211
212 auto media_map =
214
215 auto phase_transition_model = createPhaseTransitionModel(media);
216
217 const bool use_TaylorHood_elements =
218 variable_pCap->getShapeFunctionOrder() !=
219 variable_u->getShapeFunctionOrder()
220 ? true
221 : false;
222 bool const initialize_porosity_from_medium_property =
224 config.getConfigParameter("initialize_porosity_from_medium_property",
225 true);
226
228 materialIDs(mesh),
229 std::move(media_map),
230 std::move(solid_constitutive_relations),
231 std::move(phase_transition_model),
232 reference_temperature,
233 std::move(initial_stress),
234 specific_body_force,
235 mass_lumping,
236 use_TaylorHood_elements,
238 initialize_porosity_from_medium_property}};
239
240 SecondaryVariableCollection secondary_variables;
241
242 ProcessLib::createSecondaryVariables(config, secondary_variables);
243
244 return std::make_unique<TH2MProcess<DisplacementDim>>(
245 std::move(name), mesh, std::move(jacobian_assembler), parameters,
246 integration_order, std::move(process_variables),
247 std::move(process_data), std::move(secondary_variables),
248 use_monolithic_scheme, is_linear);
249}
250
251template std::unique_ptr<Process> createTH2MProcess<2>(
252 std::string const& name,
253 MeshLib::Mesh& mesh,
254 std::unique_ptr<ProcessLib::AbstractJacobianAssembler>&& jacobian_assembler,
255 std::vector<ProcessVariable> const& variables,
256 std::vector<std::unique_ptr<ParameterLib::ParameterBase>> const& parameters,
257 std::optional<ParameterLib::CoordinateSystem> const&
258 local_coordinate_system,
259 unsigned const integration_order,
260 BaseLib::ConfigTree const& config,
261 std::map<int, std::shared_ptr<MaterialPropertyLib::Medium>> const& media);
262
263template std::unique_ptr<Process> createTH2MProcess<3>(
264 std::string const& name,
265 MeshLib::Mesh& mesh,
266 std::unique_ptr<ProcessLib::AbstractJacobianAssembler>&& jacobian_assembler,
267 std::vector<ProcessVariable> const& variables,
268 std::vector<std::unique_ptr<ParameterLib::ParameterBase>> const& parameters,
269 std::optional<ParameterLib::CoordinateSystem> const&
270 local_coordinate_system,
271 unsigned const integration_order,
272 BaseLib::ConfigTree const& config,
273 std::map<int, std::shared_ptr<MaterialPropertyLib::Medium>> const& media);
274} // namespace TH2M
275} // namespace ProcessLib
#define OGS_FATAL(...)
Definition Error.h:19
void DBUG(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:22
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
unsigned getShapeFunctionOrder() 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)
OGS_NO_DANGLING Parameter< ParameterDataType > & findParameter(std::string const &parameter_name, std::vector< std::unique_ptr< ParameterBase > > const &parameters, int const num_components, MeshLib::Mesh const *const mesh=nullptr)
template std::unique_ptr< Process > createTH2MProcess< 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)
template std::unique_ptr< Process > createTH2MProcess< 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::unique_ptr< ConstitutiveRelations::PhaseTransitionModel > createPhaseTransitionModel(std::map< int, std::shared_ptr< MaterialPropertyLib::Medium > > const &media)
BaseLib::StrongType< bool, struct InitializePorosityFromMediumPropertyTag > InitializePorosityFromMediumProperty
A type helping to avoid confusion of different boolean values.
std::unique_ptr< Process > createTH2MProcess(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)
InitialStress createInitialStress(BaseLib::ConfigTree const &config, std::vector< std::unique_ptr< ParameterLib::ParameterBase > > const &parameters, MeshLib::Mesh const &mesh, bool const mandatory_stress_type)
void createSecondaryVariables(BaseLib::ConfigTree const &config, SecondaryVariableCollection &secondary_variables)