OGS
HydroMechanicsProcess.cpp
Go to the documentation of this file.
1
12
13#include <cassert>
14
15#include "HydroMechanicsFEM.h"
21#include "ProcessLib/Process.h"
24
25namespace ProcessLib
26{
27namespace HydroMechanics
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),
44 AssemblyMixin<HydroMechanicsProcess<DisplacementDim>>{
46 process_data_(std::move(process_data))
47{
48 _integration_point_writer.emplace_back(
49 std::make_unique<MeshLib::IntegrationPointWriter>(
50 "sigma_ip",
51 static_cast<int>(mesh.getDimension() == 2 ? 4 : 6) /*n components*/,
52 integration_order, local_assemblers_, &LocalAssemblerIF::getSigma));
53
54 _integration_point_writer.emplace_back(
55 std::make_unique<MeshLib::IntegrationPointWriter>(
56 "epsilon_ip",
57 static_cast<int>(mesh.getDimension() == 2 ? 4 : 6) /*n components*/,
58 integration_order, local_assemblers_,
59 &LocalAssemblerIF::getEpsilon));
60
61 if (!_use_monolithic_scheme)
62 {
63 _integration_point_writer.emplace_back(
64 std::make_unique<MeshLib::IntegrationPointWriter>(
65 "strain_rate_variable_ip", 1, integration_order,
66 local_assemblers_, &LocalAssemblerIF::getStrainRateVariable));
67 }
68}
69
70template <int DisplacementDim>
72{
73 return false;
74}
75
76template <int DisplacementDim>
79 const int process_id) const
80{
81 // For the monolithic scheme or the M process (deformation) in the staggered
82 // scheme.
83 if (process_id == process_data_.mechanics_related_process_id)
84 {
85 auto const& l = *_local_to_global_index_map;
86 return {l.dofSizeWithoutGhosts(), l.dofSizeWithoutGhosts(),
87 &l.getGhostIndices(), &this->_sparsity_pattern};
88 }
89
90 // For staggered scheme and H process (pressure).
91 auto const& l = *local_to_global_index_map_with_base_nodes_;
92 return {l.dofSizeWithoutGhosts(), l.dofSizeWithoutGhosts(),
93 &l.getGhostIndices(), &sparsity_pattern_with_linear_element_};
94}
95
96template <int DisplacementDim>
98{
99 // Create single component dof in every of the mesh's nodes.
100 _mesh_subset_all_nodes = std::make_unique<MeshLib::MeshSubset>(
101 _mesh, _mesh.getNodes(), process_data_.use_taylor_hood_elements);
102
103 // Create single component dof in the mesh's base nodes.
104 base_nodes_ = MeshLib::getBaseNodes(_mesh.getElements());
105 mesh_subset_base_nodes_ = std::make_unique<MeshLib::MeshSubset>(
106 _mesh, base_nodes_, process_data_.use_taylor_hood_elements);
107
108 // TODO move the two data members somewhere else.
109 // for extrapolation of secondary variables of stress or strain
110 std::vector<MeshLib::MeshSubset> all_mesh_subsets_single_component{
111 *_mesh_subset_all_nodes};
112 local_to_global_index_map_single_component_ =
113 std::make_unique<NumLib::LocalToGlobalIndexMap>(
114 std::move(all_mesh_subsets_single_component),
115 // by location order is needed for output
117
118 if (process_data_.isMonolithicSchemeUsed())
119 {
120 // For pressure, which is the first
121 std::vector<MeshLib::MeshSubset> all_mesh_subsets{
122 *mesh_subset_base_nodes_};
123
124 // For displacement.
125 const int monolithic_process_id = 0;
126 std::generate_n(std::back_inserter(all_mesh_subsets),
127 getProcessVariables(monolithic_process_id)[1]
128 .get()
129 .getNumberOfGlobalComponents(),
130 [&]() { return *_mesh_subset_all_nodes; });
131
132 std::vector<int> const vec_n_components{1, DisplacementDim};
133 _local_to_global_index_map =
134 std::make_unique<NumLib::LocalToGlobalIndexMap>(
135 std::move(all_mesh_subsets), vec_n_components,
137 assert(_local_to_global_index_map);
138 }
139 else
140 {
141 // For displacement equation.
142 const int process_id = 1;
143 std::vector<MeshLib::MeshSubset> all_mesh_subsets;
144 std::generate_n(std::back_inserter(all_mesh_subsets),
145 getProcessVariables(process_id)[0]
146 .get()
147 .getNumberOfGlobalComponents(),
148 [&]() { return *_mesh_subset_all_nodes; });
149
150 std::vector<int> const vec_n_components{DisplacementDim};
151 _local_to_global_index_map =
152 std::make_unique<NumLib::LocalToGlobalIndexMap>(
153 std::move(all_mesh_subsets), vec_n_components,
155
156 // For pressure equation.
157 // Collect the mesh subsets with base nodes in a vector.
158 std::vector<MeshLib::MeshSubset> all_mesh_subsets_base_nodes{
159 *mesh_subset_base_nodes_};
160 local_to_global_index_map_with_base_nodes_ =
161 std::make_unique<NumLib::LocalToGlobalIndexMap>(
162 std::move(all_mesh_subsets_base_nodes),
163 // by location order is needed for output
165
166 sparsity_pattern_with_linear_element_ = NumLib::computeSparsityPattern(
167 *local_to_global_index_map_with_base_nodes_, _mesh);
168
169 assert(_local_to_global_index_map);
170 assert(local_to_global_index_map_with_base_nodes_);
171 }
172}
173
174template <int DisplacementDim>
176 NumLib::LocalToGlobalIndexMap const& dof_table,
177 MeshLib::Mesh const& mesh,
178 unsigned const integration_order)
179{
182 mesh.getElements(), dof_table, local_assemblers_,
183 NumLib::IntegrationOrder{integration_order}, mesh.isAxiallySymmetric(),
184 process_data_);
185
186 auto add_secondary_variable = [&](std::string const& name,
187 int const num_components,
188 auto get_ip_values_function)
189 {
190 _secondary_variables.addSecondaryVariable(
191 name,
192 makeExtrapolator(num_components, getExtrapolator(),
193 local_assemblers_,
194 std::move(get_ip_values_function)));
195 };
196
197 add_secondary_variable("sigma",
199 DisplacementDim>::RowsAtCompileTime,
200 &LocalAssemblerIF::getIntPtSigma);
201
202 add_secondary_variable("epsilon",
204 DisplacementDim>::RowsAtCompileTime,
205 &LocalAssemblerIF::getIntPtEpsilon);
206
207 add_secondary_variable("velocity", DisplacementDim,
208 &LocalAssemblerIF::getIntPtDarcyVelocity);
209
210 //
211 // enable output of internal variables defined by material models
212 //
214 LocalAssemblerIF>(process_data_.solid_materials,
215 add_secondary_variable);
216
217 process_data_.pressure_interpolated =
219 const_cast<MeshLib::Mesh&>(mesh), "pressure_interpolated",
221
222 process_data_.principal_stress_vector[0] =
224 const_cast<MeshLib::Mesh&>(mesh), "principal_stress_vector_1",
226
227 process_data_.principal_stress_vector[1] =
229 const_cast<MeshLib::Mesh&>(mesh), "principal_stress_vector_2",
231
232 process_data_.principal_stress_vector[2] =
234 const_cast<MeshLib::Mesh&>(mesh), "principal_stress_vector_3",
236
237 process_data_.principal_stress_values =
239 const_cast<MeshLib::Mesh&>(mesh), "principal_stress_values",
241
242 process_data_.permeability = MeshLib::getOrCreateMeshProperty<double>(
243 const_cast<MeshLib::Mesh&>(mesh), "permeability",
246
247 setIPDataInitialConditions(_integration_point_writer, mesh.getProperties(),
248 local_assemblers_);
249
250 // Initialize local assemblers after all variables have been set.
251 GlobalExecutor::executeMemberOnDereferenced(&LocalAssemblerIF::initialize,
252 local_assemblers_,
253 *_local_to_global_index_map);
254}
255
256template <int DisplacementDim>
258 std::map<int, std::shared_ptr<MaterialPropertyLib::Medium>> const& media)
259{
260 if (process_data_.isMonolithicSchemeUsed())
261 {
262 const int process_id_of_hydromechanics = 0;
263 initializeProcessBoundaryConditionsAndSourceTerms(
264 *_local_to_global_index_map, process_id_of_hydromechanics, media);
265 return;
266 }
267
268 // Staggered scheme:
269 // for the equations of pressure
270 const int hydraulic_process_id = 0;
271 initializeProcessBoundaryConditionsAndSourceTerms(
272 *local_to_global_index_map_with_base_nodes_, hydraulic_process_id,
273 media);
274
275 // for the equations of deformation.
276 const int mechanical_process_id = 1;
277 initializeProcessBoundaryConditionsAndSourceTerms(
278 *_local_to_global_index_map, mechanical_process_id, media);
279}
280
281template <int DisplacementDim>
283 const double t, double const dt, std::vector<GlobalVector*> const& x,
284 std::vector<GlobalVector*> const& x_prev, int const process_id,
286{
287 DBUG("Assemble the equations for HydroMechanics");
288
289 // Note: This assembly function is for the Picard nonlinear solver. Since
290 // only the Newton-Raphson method is employed to simulate coupled HM
291 // processes in this class, this function is actually not used so far.
292
293 std::vector<NumLib::LocalToGlobalIndexMap const*> dof_table = {
294 _local_to_global_index_map.get()};
295
297 _global_assembler, &VectorMatrixAssembler::assemble, local_assemblers_,
298 getActiveElementIDs(), dof_table, t, dt, x, x_prev, process_id, &M, &K,
299 &b);
300}
301
302template <int DisplacementDim>
305 const double t, double const dt, std::vector<GlobalVector*> const& x,
306 std::vector<GlobalVector*> const& x_prev, int const process_id,
307 GlobalVector& b, GlobalMatrix& Jac)
308{
309 // For the monolithic scheme
310 bool const use_monolithic_scheme = process_data_.isMonolithicSchemeUsed();
311 if (use_monolithic_scheme)
312 {
313 DBUG(
314 "Assemble the Jacobian of HydroMechanics for the monolithic "
315 "scheme.");
316 }
317 else
318 {
319 // For the staggered scheme
320 if (process_id == process_data_.hydraulic_process_id)
321 {
322 DBUG(
323 "Assemble the Jacobian equations of liquid fluid process in "
324 "HydroMechanics for the staggered scheme.");
325 }
326 else
327 {
328 DBUG(
329 "Assemble the Jacobian equations of mechanical process in "
330 "HydroMechanics for the staggered scheme.");
331 }
332 }
333
335 t, dt, x, x_prev, process_id, b, Jac);
336}
337
338template <int DisplacementDim>
340 std::vector<GlobalVector*> const& x, double const t, double const dt,
341 const int process_id)
342{
343 DBUG("PreTimestep HydroMechanicsProcess.");
344
345 if (hasMechanicalProcess(process_id))
346 {
348 &LocalAssemblerIF::preTimestep, local_assemblers_,
349 getActiveElementIDs(), *_local_to_global_index_map, *x[process_id],
350 t, dt);
351 }
352}
353
354template <int DisplacementDim>
355std::vector<std::vector<std::string>>
357 std::vector<std::reference_wrapper<MeshLib::Mesh>> const& meshes)
358{
359 INFO("HydroMechanicsProcess initializeSubmeshOutput().");
360 std::vector<std::vector<std::string>> per_process_residuum_names;
361 if (_process_variables.size() == 1) // monolithic
362 {
363 per_process_residuum_names = {{"MassFlowRate", "NodalForces"}};
364 }
365 else // staggered
366 {
367 per_process_residuum_names = {{"MassFlowRate"}, {"NodalForces"}};
368 }
369
371 initializeAssemblyOnSubmeshes(meshes, per_process_residuum_names);
372
373 return per_process_residuum_names;
374}
375
376template <int DisplacementDim>
378 std::vector<GlobalVector*> const& x,
379 std::vector<GlobalVector*> const& x_prev, double const t, double const dt,
380 const int process_id)
381{
382 if (process_id != process_data_.hydraulic_process_id)
383 {
384 return;
385 }
386
387 DBUG("PostTimestep HydroMechanicsProcess.");
388
390 &LocalAssemblerIF::postTimestep, local_assemblers_,
391 getActiveElementIDs(), getDOFTables(x.size()), x, x_prev, t, dt,
392 process_id);
393}
394
395template <int DisplacementDim>
397 std::vector<GlobalVector*> const& x,
398 std::vector<GlobalVector*> const& x_prev, const double t, double const dt,
399 const int process_id)
400{
401 DBUG("PostNonLinearSolver HydroMechanicsProcess.");
402
403 // Calculate strain, stress or other internal variables of mechanics.
405 &LocalAssemblerIF::postNonLinearSolver, local_assemblers_,
406 getActiveElementIDs(), getDOFTables(x.size()), x, x_prev, t, dt,
407 process_id);
408}
409
410template <int DisplacementDim>
412 setInitialConditionsConcreteProcess(std::vector<GlobalVector*>& x,
413 double const t,
414 int const process_id)
415{
416 // So far, this function only sets the initial stress using the input data.
417 if (process_id != process_data_.mechanics_related_process_id)
418 {
419 return;
420 }
421
422 DBUG("Set initial conditions of HydroMechanicsProcess.");
423
425 &LocalAssemblerIF::setInitialConditions, local_assemblers_,
426 getActiveElementIDs(), getDOFTables(x.size()), x, t, process_id);
427}
428
429template <int DisplacementDim>
431 double const t, double const dt, std::vector<GlobalVector*> const& x,
432 GlobalVector const& x_prev, const int process_id)
433{
434 if (process_id != process_data_.hydraulic_process_id)
435 {
436 return;
437 }
438
439 DBUG("Compute the secondary variables for HydroMechanicsProcess.");
440
442 &LocalAssemblerIF::computeSecondaryVariable, local_assemblers_,
443 getActiveElementIDs(), getDOFTables(x.size()), t, dt, x, x_prev,
444 process_id);
445}
446
447template <int DisplacementDim>
448std::tuple<NumLib::LocalToGlobalIndexMap*, bool>
450{
451 const bool manage_storage = false;
452 return std::make_tuple(local_to_global_index_map_single_component_.get(),
453 manage_storage);
454}
455
456template <int DisplacementDim>
459{
460 if (hasMechanicalProcess(process_id))
461 {
462 return *_local_to_global_index_map;
463 }
464
465 // For the equation of pressure
466 return *local_to_global_index_map_with_base_nodes_;
467}
468
469template class HydroMechanicsProcess<2>;
470template class HydroMechanicsProcess<3>;
471
472} // namespace HydroMechanics
473} // 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:137
std::vector< Element * > const & getElements() const
Get the element-vector for the mesh.
Definition Mesh.h:109
Properties & getProperties()
Definition Mesh.h:134
void assembleConcreteProcess(const double t, double const, std::vector< GlobalVector * > const &x, std::vector< GlobalVector * > const &x_prev, int const process_id, GlobalMatrix &M, GlobalMatrix &K, GlobalVector &b) override
std::vector< std::vector< std::string > > initializeAssemblyOnSubmeshes(std::vector< std::reference_wrapper< MeshLib::Mesh > > const &meshes) override
HydroMechanicsProcess(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, HydroMechanicsProcessData< DisplacementDim > &&process_data, SecondaryVariableCollection &&secondary_variables, bool const use_monolithic_scheme)
void computeSecondaryVariableConcrete(double const t, double const dt, std::vector< GlobalVector * > const &x, GlobalVector const &x_prev, const int process_id) override
void preTimestepConcreteProcess(std::vector< GlobalVector * > const &x, double const t, double const dt, const int process_id) override
void initializeBoundaryConditions(std::map< int, std::shared_ptr< MaterialPropertyLib::Medium > > const &media) override
NumLib::LocalToGlobalIndexMap const & getDOFTable(const int process_id) const override
void assembleWithJacobianConcreteProcess(const double t, double const, std::vector< GlobalVector * > const &x, std::vector< GlobalVector * > const &x_prev, int const process_id, GlobalVector &b, GlobalMatrix &Jac) override
void postNonLinearSolverConcreteProcess(std::vector< GlobalVector * > const &x, std::vector< GlobalVector * > const &x_prev, const double t, double const dt, int const process_id) override
void setInitialConditionsConcreteProcess(std::vector< GlobalVector * > &x, double const t, int const process_id) override
MathLib::MatrixSpecifications getMatrixSpecifications(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().
std::tuple< NumLib::LocalToGlobalIndexMap *, bool > getDOFTableForExtrapolatorData() const 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
std::unique_ptr< ProcessLib::AbstractJacobianAssembler > _jacobian_assembler
Definition Process.h:376
Handles configuration of several secondary variables from the project file.
void assemble(std::size_t const mesh_item_id, LocalAssemblerInterface &local_assembler, std::vector< NumLib::LocalToGlobalIndexMap const * > const &dof_tables, double const 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)
constexpr int kelvin_vector_dimensions(int const displacement_dim)
Kelvin vector dimensions for given displacement dimension.
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 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 executeSelectedMemberDereferenced(Object &object, 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)