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