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