Loading [MathJax]/extensions/MathZoom.js
OGS
ThermoHydroMechanicsProcess.cpp
Go to the documentation of this file.
1
12
13#include <cassert>
14
19#include "ProcessLib/Process.h"
24
25namespace ProcessLib
26{
27namespace ThermoHydroMechanics
28{
29template <int DisplacementDim>
31 std::string name,
32 MeshLib::Mesh& mesh,
33 std::unique_ptr<ProcessLib::AbstractJacobianAssembler>&& jacobian_assembler,
34 std::vector<std::unique_ptr<ParameterLib::ParameterBase>> const& parameters,
35 unsigned const integration_order,
36 std::vector<std::vector<std::reference_wrapper<ProcessVariable>>>&&
37 process_variables,
39 SecondaryVariableCollection&& secondary_variables,
40 bool const use_monolithic_scheme)
41 : Process(std::move(name), mesh, std::move(jacobian_assembler), parameters,
42 integration_order, std::move(process_variables),
43 std::move(secondary_variables), use_monolithic_scheme),
46 _process_data(std::move(process_data))
47
48{
50 mesh, "NodalForces", MeshLib::MeshItemType::Node, DisplacementDim);
51
53 mesh, "MassFlowRate", MeshLib::MeshItemType::Node, 1);
54
56 mesh, "HeatFlowRate", MeshLib::MeshItemType::Node, 1);
57
58 _integration_point_writer.emplace_back(
59 std::make_unique<MeshLib::IntegrationPointWriter>(
60 "sigma_ip",
61 static_cast<int>(mesh.getDimension() == 2 ? 4 : 6) /*n components*/,
62 integration_order, local_assemblers_,
64
65 _integration_point_writer.emplace_back(
66 std::make_unique<MeshLib::IntegrationPointWriter>(
67 "epsilon_m_ip",
68 static_cast<int>(mesh.getDimension() == 2 ? 4 : 6) /*n components*/,
69 integration_order, local_assemblers_,
71
72 _integration_point_writer.emplace_back(
73 std::make_unique<MeshLib::IntegrationPointWriter>(
74 "epsilon_ip",
75 static_cast<int>(mesh.getDimension() == 2 ? 4 : 6) /*n components*/,
76 integration_order, local_assemblers_,
78}
79
80template <int DisplacementDim>
82{
83 return false;
84}
85
86template <int DisplacementDim>
89 const int process_id) const
90{
91 // For the monolithic scheme or the M process (deformation) in the staggered
92 // scheme.
93 if (_use_monolithic_scheme || process_id == 2)
94 {
95 auto const& l = *_local_to_global_index_map;
96 return {l.dofSizeWithoutGhosts(), l.dofSizeWithoutGhosts(),
97 &l.getGhostIndices(), &this->_sparsity_pattern};
98 }
99
100 // For staggered scheme and T or H process (pressure).
101 auto const& l = *_local_to_global_index_map_with_base_nodes;
102 return {l.dofSizeWithoutGhosts(), l.dofSizeWithoutGhosts(),
103 &l.getGhostIndices(), &_sparsity_pattern_with_linear_element};
104}
105
106template <int DisplacementDim>
108{
109 // Create single component dof in every of the mesh's nodes.
110 _mesh_subset_all_nodes =
111 std::make_unique<MeshLib::MeshSubset>(_mesh, _mesh.getNodes());
112 // Create single component dof in the mesh's base nodes.
113 _base_nodes = MeshLib::getBaseNodes(_mesh.getElements());
114 _mesh_subset_base_nodes =
115 std::make_unique<MeshLib::MeshSubset>(_mesh, _base_nodes);
116
117 // TODO move the two data members somewhere else.
118 // for extrapolation of secondary variables of stress or strain
119 std::vector<MeshLib::MeshSubset> all_mesh_subsets_single_component{
120 *_mesh_subset_all_nodes};
121 _local_to_global_index_map_single_component =
122 std::make_unique<NumLib::LocalToGlobalIndexMap>(
123 std::move(all_mesh_subsets_single_component),
124 // by location order is needed for output
126
127 if (_use_monolithic_scheme)
128 {
129 // For temperature, which is the first
130 std::vector<MeshLib::MeshSubset> all_mesh_subsets{
131 *_mesh_subset_base_nodes};
132
133 // For pressure, which is the second
134 all_mesh_subsets.push_back(*_mesh_subset_base_nodes);
135
136 // For displacement.
137 const int monolithic_process_id = 0;
138 std::generate_n(std::back_inserter(all_mesh_subsets),
139 getProcessVariables(monolithic_process_id)[2]
140 .get()
141 .getNumberOfGlobalComponents(),
142 [&]() { return *_mesh_subset_all_nodes; });
143
144 std::vector<int> const vec_n_components{1, 1, DisplacementDim};
145 _local_to_global_index_map =
146 std::make_unique<NumLib::LocalToGlobalIndexMap>(
147 std::move(all_mesh_subsets), vec_n_components,
149 assert(_local_to_global_index_map);
150 }
151 else
152 {
153 // For displacement equation.
154 const int process_id = 2;
155 std::vector<MeshLib::MeshSubset> all_mesh_subsets;
156 std::generate_n(std::back_inserter(all_mesh_subsets),
157 getProcessVariables(process_id)[0]
158 .get()
159 .getNumberOfGlobalComponents(),
160 [&]() { return *_mesh_subset_all_nodes; });
161
162 std::vector<int> const vec_n_components{DisplacementDim};
163 _local_to_global_index_map =
164 std::make_unique<NumLib::LocalToGlobalIndexMap>(
165 std::move(all_mesh_subsets), vec_n_components,
167
168 // For pressure equation or temperature equation.
169 // Collect the mesh subsets with base nodes in a vector.
170 std::vector<MeshLib::MeshSubset> all_mesh_subsets_base_nodes{
171 *_mesh_subset_base_nodes};
172 _local_to_global_index_map_with_base_nodes =
173 std::make_unique<NumLib::LocalToGlobalIndexMap>(
174 std::move(all_mesh_subsets_base_nodes),
175 // by location order is needed for output
177
178 _sparsity_pattern_with_linear_element = NumLib::computeSparsityPattern(
179 *_local_to_global_index_map_with_base_nodes, _mesh);
180
181 assert(_local_to_global_index_map);
182 assert(_local_to_global_index_map_with_base_nodes);
183 }
184}
185
186template <int DisplacementDim>
188 NumLib::LocalToGlobalIndexMap const& dof_table,
189 MeshLib::Mesh const& mesh,
190 unsigned const integration_order)
191{
194 mesh.getElements(), dof_table, local_assemblers_,
195 NumLib::IntegrationOrder{integration_order}, mesh.isAxiallySymmetric(),
196 _process_data);
197
198 auto add_secondary_variable = [&](std::string const& name,
199 int const num_components,
200 auto get_ip_values_function)
201 {
202 _secondary_variables.addSecondaryVariable(
203 name,
204 makeExtrapolator(num_components, getExtrapolator(),
205 local_assemblers_,
206 std::move(get_ip_values_function)));
207 };
208
209 add_secondary_variable(
210 "sigma",
212 DisplacementDim>::RowsAtCompileTime,
214
215 add_secondary_variable(
216 "sigma_ice",
218 DisplacementDim>::RowsAtCompileTime,
220
221 add_secondary_variable(
222 "epsilon_m",
224 DisplacementDim>::RowsAtCompileTime,
226
227 add_secondary_variable(
228 "epsilon",
230 DisplacementDim>::RowsAtCompileTime,
232
233 add_secondary_variable(
234 "ice_volume_fraction", 1,
236
237 add_secondary_variable(
238 "velocity", mesh.getDimension(),
240
241 add_secondary_variable(
242 "fluid_density", 1,
244
245 add_secondary_variable(
246 "viscosity", 1,
248
249 _process_data.element_fluid_density =
251 const_cast<MeshLib::Mesh&>(mesh), "fluid_density_avg",
253
254 _process_data.element_viscosity = MeshLib::getOrCreateMeshProperty<double>(
255 const_cast<MeshLib::Mesh&>(mesh), "viscosity_avg",
257
258 _process_data.element_stresses = MeshLib::getOrCreateMeshProperty<double>(
259 const_cast<MeshLib::Mesh&>(mesh), "stress_avg",
262 DisplacementDim>::RowsAtCompileTime);
263
264 _process_data.pressure_interpolated =
266 const_cast<MeshLib::Mesh&>(mesh), "pressure_interpolated",
268
269 _process_data.temperature_interpolated =
271 const_cast<MeshLib::Mesh&>(mesh), "temperature_interpolated",
273
274 //
275 // enable output of internal variables defined by material models
276 //
278 LocalAssemblerInterface<DisplacementDim>>(_process_data.solid_materials,
279 add_secondary_variable);
280
283 _process_data.solid_materials, local_assemblers_,
284 _integration_point_writer, integration_order);
285
286 setIPDataInitialConditions(_integration_point_writer, mesh.getProperties(),
287 local_assemblers_);
288
289 // Initialize local assemblers after all variables have been set.
292 local_assemblers_, *_local_to_global_index_map);
293}
294
295template <int DisplacementDim>
297 std::map<int, std::shared_ptr<MaterialPropertyLib::Medium>> const& media)
298{
299 if (_use_monolithic_scheme)
300 {
301 const int process_id_of_thermohydromechancs = 0;
302 initializeProcessBoundaryConditionsAndSourceTerms(
303 *_local_to_global_index_map, process_id_of_thermohydromechancs,
304 media);
305 return;
306 }
307
308 // Staggered scheme:
309 // for the equations of heat transport
310 const int thermal_process_id = 0;
311 initializeProcessBoundaryConditionsAndSourceTerms(
312 *_local_to_global_index_map_with_base_nodes, thermal_process_id, media);
313
314 // for the equations of mass balance
315 const int hydraulic_process_id = 1;
316 initializeProcessBoundaryConditionsAndSourceTerms(
317 *_local_to_global_index_map_with_base_nodes, hydraulic_process_id,
318 media);
319
320 // for the equations of deformation.
321 const int mechanical_process_id = 2;
322 initializeProcessBoundaryConditionsAndSourceTerms(
323 *_local_to_global_index_map, mechanical_process_id, media);
324}
325
326template <int DisplacementDim>
328 setInitialConditionsConcreteProcess(std::vector<GlobalVector*>& x,
329 double const t,
330 int const process_id)
331{
332 DBUG("SetInitialConditions ThermoHydroMechanicsProcess.");
333
336 local_assemblers_, getDOFTables(x.size()), x, t, process_id);
337}
338
339template <int DisplacementDim>
341 const double t, double const dt, std::vector<GlobalVector*> const& x,
342 std::vector<GlobalVector*> const& x_prev, int const process_id,
344{
345 DBUG("Assemble the equations for ThermoHydroMechanics");
346
348 t, dt, x, x_prev, process_id, M, K, b);
349}
350
351template <int DisplacementDim>
354 const double t, double const dt, std::vector<GlobalVector*> const& x,
355 std::vector<GlobalVector*> const& x_prev, int const process_id,
356 GlobalVector& b, GlobalMatrix& Jac)
357{
358 // For the monolithic scheme
359 if (_use_monolithic_scheme)
360 {
361 DBUG(
362 "Assemble the Jacobian of ThermoHydroMechanics for the monolithic "
363 "scheme.");
364 }
365 else
366 {
367 // For the staggered scheme
368 if (process_id == 0)
369 {
370 DBUG(
371 "Assemble the Jacobian equations of heat transport process in "
372 "ThermoHydroMechanics for the staggered scheme.");
373 }
374 else if (process_id == 1)
375 {
376 DBUG(
377 "Assemble the Jacobian equations of liquid fluid process in "
378 "ThermoHydroMechanics for the staggered scheme.");
379 }
380 else
381 {
382 DBUG(
383 "Assemble the Jacobian equations of mechanical process in "
384 "ThermoHydroMechanics for the staggered scheme.");
385 }
386 }
387
388 auto const dof_tables = getDOFTables(x.size());
389
391 assembleWithJacobian(t, dt, x, x_prev, process_id, b, Jac);
392
393 auto copyRhs = [&](int const variable_id, auto& output_vector)
394 {
395 if (_use_monolithic_scheme)
396 {
397 transformVariableFromGlobalVector(b, variable_id, *dof_tables[0],
398 output_vector,
399 std::negate<double>());
400 }
401 else
402 {
403 transformVariableFromGlobalVector(b, 0, *dof_tables[process_id],
404 output_vector,
405 std::negate<double>());
406 }
407 };
408 if (_use_monolithic_scheme || process_id == 0)
409 {
410 copyRhs(0, *_heat_flux);
411 }
412 if (_use_monolithic_scheme || process_id == 1)
413 {
414 copyRhs(1, *_hydraulic_flow);
415 }
416 if (_use_monolithic_scheme || process_id == 2)
417 {
418 copyRhs(2, *_nodal_forces);
419 }
420}
421
422template <int DisplacementDim>
424 std::vector<GlobalVector*> const& x, double const t, double const dt,
425 const int process_id)
426{
427 DBUG("PreTimestep ThermoHydroMechanicsProcess.");
428
429 if (hasMechanicalProcess(process_id))
430 {
433 local_assemblers_, *_local_to_global_index_map, *x[process_id], t,
434 dt);
435
437 updateActiveElements();
438 }
439}
440
441template <int DisplacementDim>
443 std::vector<GlobalVector*> const& x,
444 std::vector<GlobalVector*> const& x_prev, double const t, double const dt,
445 const int process_id)
446{
447 if (process_id != 0)
448 {
449 return;
450 }
451
452 DBUG("PostTimestep ThermoHydroMechanicsProcess.");
453
456 local_assemblers_, getActiveElementIDs(), getDOFTables(x.size()), x,
457 x_prev, t, dt, process_id);
458}
459
460template <int DisplacementDim>
461std::vector<std::vector<std::string>>
463 std::vector<std::reference_wrapper<MeshLib::Mesh>> const& meshes)
464{
465 INFO("ThermoHydroMechanicsProcess process initializeSubmeshOutput().");
466 std::vector<std::vector<std::string>> per_process_residuum_names;
467 if (_process_variables.size() == 1) // monolithic
468 {
469 per_process_residuum_names = {
470 {"HeatFlowRate", "MassFlowRate", "NodalForces"}};
471 }
472 else // staggered
473 {
474 per_process_residuum_names = {
475 {"HeatFlowRate"}, {"MassFlowRate"}, {"NodalForces"}};
476 }
477
479 initializeAssemblyOnSubmeshes(meshes, per_process_residuum_names);
480
481 return per_process_residuum_names;
482}
483
484template <int DisplacementDim>
486 computeSecondaryVariableConcrete(double const t, double const dt,
487 std::vector<GlobalVector*> const& x,
488 GlobalVector const& x_prev,
489 const int process_id)
490{
491 if (process_id != 0)
492 {
493 return;
494 }
495
496 DBUG("Compute the secondary variables for ThermoHydroMechanicsProcess.");
497
500 local_assemblers_, getActiveElementIDs(), getDOFTables(x.size()), t, dt,
501 x, x_prev, process_id);
502}
503
504template <int DisplacementDim>
505std::tuple<NumLib::LocalToGlobalIndexMap*, bool> ThermoHydroMechanicsProcess<
506 DisplacementDim>::getDOFTableForExtrapolatorData() const
507{
508 const bool manage_storage = false;
509 return std::make_tuple(_local_to_global_index_map_single_component.get(),
510 manage_storage);
511}
512
513template <int DisplacementDim>
516 const int process_id) const
517{
518 if (hasMechanicalProcess(process_id))
519 {
520 return *_local_to_global_index_map;
521 }
522
523 // For the equation of pressure
524 return *_local_to_global_index_map_with_base_nodes;
525}
526
527template class ThermoHydroMechanicsProcess<2>;
528template class ThermoHydroMechanicsProcess<3>;
529
530} // namespace ThermoHydroMechanics
531} // namespace ProcessLib
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:35
void DBUG(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:30
Global vector based on Eigen vector.
Definition EigenVector.h:25
bool isAxiallySymmetric() const
Definition Mesh.h:139
std::vector< Element * > const & getElements() const
Get the element-vector for the mesh.
Definition Mesh.h:111
unsigned getDimension() const
Returns the dimension of the mesh (determined by the maximum dimension over all elements).
Definition Mesh.h:90
Properties & getProperties()
Definition Mesh.h:136
std::unique_ptr< ProcessLib::AbstractJacobianAssembler > _jacobian_assembler
Definition Process.h:376
Handles configuration of several secondary variables from the project file.
void assembleWithJacobianConcreteProcess(const double t, double const dt, std::vector< GlobalVector * > const &x, std::vector< GlobalVector * > const &x_prev, int const process_id, GlobalVector &b, GlobalMatrix &Jac) override
NumLib::LocalToGlobalIndexMap const & getDOFTable(const int process_id) const override
void initializeConcreteProcess(NumLib::LocalToGlobalIndexMap const &dof_table, MeshLib::Mesh const &mesh, unsigned const integration_order) override
Process specific initialization called by initialize().
void preTimestepConcreteProcess(std::vector< GlobalVector * > const &x, double const t, double const dt, const int process_id) override
ThermoHydroMechanicsProcess(std::string name, MeshLib::Mesh &mesh, std::unique_ptr< ProcessLib::AbstractJacobianAssembler > &&jacobian_assembler, std::vector< std::unique_ptr< ParameterLib::ParameterBase > > const &parameters, unsigned const integration_order, std::vector< std::vector< std::reference_wrapper< ProcessVariable > > > &&process_variables, ThermoHydroMechanicsProcessData< DisplacementDim > &&process_data, SecondaryVariableCollection &&secondary_variables, bool const use_monolithic_scheme)
void initializeBoundaryConditions(std::map< int, std::shared_ptr< MaterialPropertyLib::Medium > > const &media) override
void computeSecondaryVariableConcrete(double const t, double const dt, std::vector< GlobalVector * > const &x, GlobalVector const &x_prev, const int process_id) override
void assembleConcreteProcess(const double t, double const dt, std::vector< GlobalVector * > const &x, std::vector< GlobalVector * > const &x_prev, int const process_id, GlobalMatrix &M, GlobalMatrix &K, GlobalVector &b) override
void postTimestepConcreteProcess(std::vector< GlobalVector * > const &x, std::vector< GlobalVector * > const &x_prev, const double t, const double dt, int const process_id) override
MathLib::MatrixSpecifications getMatrixSpecifications(const int process_id) const override
void setInitialConditionsConcreteProcess(std::vector< GlobalVector * > &x, double const t, int const process_id) override
std::vector< std::vector< std::string > > initializeAssemblyOnSubmeshes(std::vector< std::reference_wrapper< MeshLib::Mesh > > const &meshes) override
Eigen::Matrix< double, kelvin_vector_dimensions(DisplacementDim), 1, Eigen::ColMajor > KelvinVectorType
PropertyVector< T > * getOrCreateMeshProperty(Mesh &mesh, std::string const &property_name, MeshItemType const item_type, int const number_of_components)
std::vector< Node * > getBaseNodes(std::vector< Element * > const &elements)
Definition Utils.h:26
@ BY_LOCATION
Ordering data by spatial location.
GlobalSparsityPattern computeSparsityPattern(LocalToGlobalIndexMap const &dof_table, MeshLib::Mesh const &mesh)
Computes a sparsity pattern for the given inputs.
void solidMaterialInternalVariablesToIntegrationPointWriter(std::map< int, std::shared_ptr< SolidMaterial > > const &solid_materials, std::vector< std::unique_ptr< LocalAssemblerInterface > > const &local_assemblers, std::vector< std::unique_ptr< MeshLib::IntegrationPointWriter > > &integration_point_writer, int const integration_order)
void solidMaterialInternalToSecondaryVariables(std::map< int, std::shared_ptr< SolidMaterial > > const &solid_materials, AddSecondaryVariableCallback const &add_secondary_variable)
SecondaryVariableFunctions makeExtrapolator(const unsigned num_components, NumLib::Extrapolator &extrapolator, LocalAssemblerCollection const &local_assemblers, typename NumLib::ExtrapolatableLocalAssemblerCollection< LocalAssemblerCollection >::IntegrationPointValuesMethod integration_point_values_method)
void setIPDataInitialConditions(std::vector< std::unique_ptr< MeshLib::IntegrationPointWriter > > const &_integration_point_writer, MeshLib::Properties const &mesh_properties, LocalAssemblersVector &local_assemblers)
void createLocalAssemblersHM(std::vector< MeshLib::Element * > const &mesh_elements, NumLib::LocalToGlobalIndexMap const &dof_table, std::vector< std::unique_ptr< LocalAssemblerInterface > > &local_assemblers, ProviderOrOrder const &provider_or_order, ExtraCtorArgs &&... extra_ctor_args)
static void executeSelectedMemberOnDereferenced(Method method, Container const &container, std::vector< std::size_t > const &active_container_ids, Args &&... args)
static void executeMemberOnDereferenced(Method method, Container const &container, Args &&... args)