OGS
RichardsMechanicsProcess.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
5
6#include <cassert>
7
18
19namespace ProcessLib
20{
21namespace RichardsMechanics
22{
23template <int DisplacementDim>
25 std::string name, MeshLib::Mesh& mesh,
26 std::unique_ptr<ProcessLib::AbstractJacobianAssembler>&& jacobian_assembler,
27 std::vector<std::unique_ptr<ParameterLib::ParameterBase>> const& parameters,
28 unsigned const integration_order,
29 std::vector<std::vector<std::reference_wrapper<ProcessVariable>>>&&
30 process_variables,
32 SecondaryVariableCollection&& secondary_variables,
33 bool const use_monolithic_scheme, bool const is_linear)
34 : Process(std::move(name), mesh, std::move(jacobian_assembler), parameters,
35 integration_order, std::move(process_variables),
36 std::move(secondary_variables), use_monolithic_scheme),
38 *_jacobian_assembler, is_linear, use_monolithic_scheme},
39 process_data_(std::move(process_data))
40{
41 // For numerical Jacobian assembler
42 this->_jacobian_assembler->setNonDeformationComponentIDs(
43 {0} /* pressure variable */);
44
46 DisplacementDim>(LocalAssemblerIF::getReflectionDataForOutput(),
47 _integration_point_writer, integration_order,
48 local_assemblers_);
49}
50
51template <int DisplacementDim>
56
57template <int DisplacementDim>
60 const int process_id) const
61{
62 // For the monolithic scheme or the M process (deformation) in the staggered
63 // scheme.
64 if (_use_monolithic_scheme || process_id == 1)
65 {
66 auto const& l = *_local_to_global_index_map;
67 return {l.dofSizeWithoutGhosts(), l.dofSizeWithoutGhosts(),
68 &l.getGhostIndices(), &this->_sparsity_pattern};
69 }
70
71 // For staggered scheme and H process (pressure).
73 return {l.dofSizeWithoutGhosts(), l.dofSizeWithoutGhosts(),
74 &l.getGhostIndices(), &sparsity_pattern_with_linear_element_};
75}
76
77template <int DisplacementDim>
79{
80 // Create single component dof in every of the mesh's nodes.
82 std::make_unique<MeshLib::MeshSubset>(_mesh, _mesh.getNodes());
83 // Create single component dof in the mesh's base nodes.
86 std::make_unique<MeshLib::MeshSubset>(_mesh, base_nodes_);
87
88 // TODO move the two data members somewhere else.
89 // for extrapolation of secondary variables of stress or strain
90 std::vector<MeshLib::MeshSubset> all_mesh_subsets_single_component{
93 std::make_unique<NumLib::LocalToGlobalIndexMap>(
94 std::move(all_mesh_subsets_single_component),
95 // by location order is needed for output
97
99 {
100 // For pressure, which is the first
101 std::vector<MeshLib::MeshSubset> all_mesh_subsets{
103
104 // For displacement.
105 const int monolithic_process_id = 0;
106 std::generate_n(std::back_inserter(all_mesh_subsets),
107 getProcessVariables(monolithic_process_id)[1]
108 .get()
109 .getNumberOfGlobalComponents(),
110 [&]() { return *_mesh_subset_all_nodes; });
111
112 std::vector<int> const vec_n_components{1, DisplacementDim};
114 std::make_unique<NumLib::LocalToGlobalIndexMap>(
115 std::move(all_mesh_subsets), vec_n_components,
118 }
119 else
120 {
121 // For displacement equation.
122 const int process_id = 1;
123 std::vector<MeshLib::MeshSubset> all_mesh_subsets;
124 std::generate_n(std::back_inserter(all_mesh_subsets),
125 getProcessVariables(process_id)[0]
126 .get()
127 .getNumberOfGlobalComponents(),
128 [&]() { return *_mesh_subset_all_nodes; });
129
130 std::vector<int> const vec_n_components{DisplacementDim};
132 std::make_unique<NumLib::LocalToGlobalIndexMap>(
133 std::move(all_mesh_subsets), vec_n_components,
135
136 // For pressure equation.
137 // Collect the mesh subsets with base nodes in a vector.
138 std::vector<MeshLib::MeshSubset> all_mesh_subsets_base_nodes{
141 std::make_unique<NumLib::LocalToGlobalIndexMap>(
142 std::move(all_mesh_subsets_base_nodes),
143 // by location order is needed for output
145
148
151 }
152}
153
154template <int DisplacementDim>
156 NumLib::LocalToGlobalIndexMap const& dof_table,
157 MeshLib::Mesh const& mesh,
158 unsigned const integration_order)
159{
162 mesh.getElements(), dof_table, local_assemblers_,
163 NumLib::IntegrationOrder{integration_order}, mesh.isAxiallySymmetric(),
165
169
170 auto add_secondary_variable = [&](std::string const& name,
171 int const num_components,
172 auto get_ip_values_function)
173 {
174 _secondary_variables.addSecondaryVariable(
175 name,
176 makeExtrapolator(num_components, getExtrapolator(),
178 std::move(get_ip_values_function)));
179 };
180
181 //
182 // enable output of internal variables defined by material models
183 //
185 LocalAssemblerIF>(process_data_.solid_materials,
186 add_secondary_variable);
187
190 process_data_.solid_materials, local_assemblers_,
191 _integration_point_writer, integration_order);
192
194 const_cast<MeshLib::Mesh&>(mesh), "saturation_avg",
196
198 const_cast<MeshLib::Mesh&>(mesh), "porosity_avg",
200
202 const_cast<MeshLib::Mesh&>(mesh), "stress_avg",
205 DisplacementDim>::RowsAtCompileTime);
206
207 process_data_.pressure_interpolated =
209 const_cast<MeshLib::Mesh&>(mesh), "pressure_interpolated",
211
214
215 // Initialize local assemblers after all variables have been set.
219}
220
221template <int DisplacementDim>
223 std::map<int, std::shared_ptr<MaterialPropertyLib::Medium>> const& media)
224{
226 {
227 const int monolithic_process_id = 0;
229 *_local_to_global_index_map, monolithic_process_id, media);
230 return;
231 }
232
233 // Staggered scheme:
234 // for the equations of pressure
235 const int hydraulic_process_id = 0;
237 *local_to_global_index_map_with_base_nodes_, hydraulic_process_id,
238 media);
239
240 // for the equations of deformation.
241 const int mechanical_process_id = 1;
243 *_local_to_global_index_map, mechanical_process_id, media);
244}
245
246template <int DisplacementDim>
248 setInitialConditionsConcreteProcess(std::vector<GlobalVector*>& x,
249 double const t,
250 int const process_id)
251{
252 if (process_id != 0)
253 {
254 return;
255 }
256
257 DBUG("SetInitialConditions RichardsMechanicsProcess.");
258
261 getActiveElementIDs(), getDOFTables(x.size()), x, t, process_id);
262}
263
264template <int DisplacementDim>
266 const double t, double const dt, std::vector<GlobalVector*> const& x,
267 std::vector<GlobalVector*> const& x_prev, int const process_id,
269{
270 DBUG("Assemble the equations for RichardsMechanics");
271
273 t, dt, x, x_prev, process_id, M, K, b);
274}
275
276template <int DisplacementDim>
279 const double t, double const dt, std::vector<GlobalVector*> const& x,
280 std::vector<GlobalVector*> const& x_prev, int const process_id,
281 GlobalVector& b, GlobalMatrix& Jac)
282{
283 // For the monolithic scheme
285 {
286 DBUG(
287 "Assemble the Jacobian of RichardsMechanics for the monolithic"
288 " scheme.");
289 }
290 else
291 {
292 // For the staggered scheme
293 if (process_id == 0)
294 {
295 DBUG(
296 "Assemble the Jacobian equations of liquid fluid process in "
297 "RichardsMechanics for the staggered scheme.");
298 }
299 else
300 {
301 DBUG(
302 "Assemble the Jacobian equations of mechanical process in "
303 "RichardsMechanics for the staggered scheme.");
304 }
305 }
306
308 assembleWithJacobian(t, dt, x, x_prev, process_id, b, Jac);
309}
310
311template <int DisplacementDim>
313 std::vector<GlobalVector*> const& x, double const t, double const dt,
314 const int process_id)
315{
316 DBUG("PreTimestep RichardsMechanicsProcess.");
317
320 getActiveElementIDs(), *_local_to_global_index_map, *x[process_id], t,
321 dt);
322
325}
326
327template <int DisplacementDim>
329 std::vector<GlobalVector*> const& x,
330 std::vector<GlobalVector*> const& x_prev, double const t, double const dt,
331 const int process_id)
332{
333 if (hasMechanicalProcess(process_id))
334 {
335 DBUG("PostTimestep RichardsMechanicsProcess.");
336
339 getActiveElementIDs(), getDOFTables(x.size()), x, x_prev, t, dt,
340 process_id);
341 }
342}
343
344template <int DisplacementDim>
345std::vector<std::vector<std::string>>
347 std::vector<std::reference_wrapper<MeshLib::Mesh>> const& meshes)
348{
349 INFO("RichardsMechanics process initializeSubmeshOutput().");
350 std::vector<std::vector<std::string>> residuum_names{
351 {"MassFlowRate", "NodalForces"}};
352
354 initializeAssemblyOnSubmeshes(meshes, residuum_names);
355
356 return residuum_names;
357}
358
359template <int DisplacementDim>
361 computeSecondaryVariableConcrete(const double t, const double dt,
362 std::vector<GlobalVector*> const& x,
363 GlobalVector const& x_prev,
364 int const process_id)
365{
366 if (process_id != 0)
367 {
368 return;
369 }
370
371 DBUG("Compute the secondary variables for RichardsMechanicsProcess.");
372
375 getActiveElementIDs(), getDOFTables(x.size()), t, dt, x, x_prev,
376 process_id);
377}
378
379template <int DisplacementDim>
380std::tuple<NumLib::LocalToGlobalIndexMap*, bool> RichardsMechanicsProcess<
381 DisplacementDim>::getDOFTableForExtrapolatorData() const
382{
383 const bool manage_storage = false;
384 return std::make_tuple(local_to_global_index_map_single_component_.get(),
385 manage_storage);
386}
387
388template <int DisplacementDim>
391 const int process_id) const
392{
393 if (hasMechanicalProcess(process_id))
394 {
396 }
397
398 // For the equation of pressure
400}
401
402template class RichardsMechanicsProcess<2>;
403template class RichardsMechanicsProcess<3>;
404
405} // namespace RichardsMechanics
406} // namespace ProcessLib
MathLib::EigenMatrix GlobalMatrix
MathLib::EigenVector GlobalVector
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:28
void DBUG(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:22
bool isAxiallySymmetric() const
Definition Mesh.h:128
std::vector< Element * > const & getElements() const
Get the element-vector for the mesh.
Definition Mesh.h:100
Properties & getProperties()
Definition Mesh.h:125
virtual void postTimestep(std::size_t const mesh_item_id, std::vector< NumLib::LocalToGlobalIndexMap const * > const &dof_tables, std::vector< GlobalVector * > const &x, std::vector< GlobalVector * > const &x_prev, double const t, double const dt, int const process_id)
virtual void computeSecondaryVariable(std::size_t const mesh_item_id, std::vector< NumLib::LocalToGlobalIndexMap const * > const &dof_tables, double const t, double const dt, std::vector< GlobalVector * > const &x, GlobalVector const &x_prev, int const process_id)
virtual void preTimestep(std::size_t const mesh_item_id, NumLib::LocalToGlobalIndexMap const &dof_table, GlobalVector const &x, double const t, double const delta_t)
virtual void initialize(std::size_t const mesh_item_id, NumLib::LocalToGlobalIndexMap const &dof_table)
virtual void setInitialConditions(std::size_t const mesh_item_id, std::vector< NumLib::LocalToGlobalIndexMap const * > const &dof_tables, std::vector< GlobalVector * > const &x, double const t, int const process_id)
std::string const name
Definition Process.h:361
std::vector< NumLib::LocalToGlobalIndexMap const * > getDOFTables(int const number_of_processes) const
Definition Process.cpp:376
std::vector< std::unique_ptr< MeshLib::IntegrationPointWriter > > _integration_point_writer
Definition Process.h:389
void initializeProcessBoundaryConditionsAndSourceTerms(const NumLib::LocalToGlobalIndexMap &dof_table, const int process_id, std::map< int, std::shared_ptr< MaterialPropertyLib::Medium > > const &media)
Definition Process.cpp:83
void assemble(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) final
Definition Process.cpp:258
Process(std::string name_, MeshLib::Mesh &mesh, std::unique_ptr< 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, SecondaryVariableCollection &&secondary_variables, const bool use_monolithic_scheme=true)
Definition Process.cpp:37
std::unique_ptr< MeshLib::MeshSubset const > _mesh_subset_all_nodes
Definition Process.h:365
MeshLib::Mesh & _mesh
Definition Process.h:364
std::vector< std::size_t > const & getActiveElementIDs() const
Definition Process.h:160
SecondaryVariableCollection _secondary_variables
Definition Process.h:369
std::unique_ptr< NumLib::LocalToGlobalIndexMap > _local_to_global_index_map
Definition Process.h:367
std::unique_ptr< ProcessLib::AbstractJacobianAssembler > _jacobian_assembler
Definition Process.h:375
std::vector< std::vector< std::reference_wrapper< ProcessVariable > > > const & getProcessVariables() const
Definition Process.h:149
NumLib::Extrapolator & getExtrapolator() const
Definition Process.h:201
GlobalSparsityPattern _sparsity_pattern
Definition Process.h:391
const bool _use_monolithic_scheme
Definition Process.h:378
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 preTimestepConcreteProcess(std::vector< GlobalVector * > const &x, double const t, double const dt, const int process_id) override
MathLib::MatrixSpecifications getMatrixSpecifications(const int process_id) const override
RichardsMechanicsProcessData< DisplacementDim > process_data_
void initializeConcreteProcess(NumLib::LocalToGlobalIndexMap const &dof_table, MeshLib::Mesh const &mesh, unsigned const integration_order) override
Process specific initialization called by initialize().
std::unique_ptr< NumLib::LocalToGlobalIndexMap > local_to_global_index_map_with_base_nodes_
void computeSecondaryVariableConcrete(double const t, double const dt, std::vector< GlobalVector * > const &x, GlobalVector const &x_prev, int const process_id) override
std::unique_ptr< NumLib::LocalToGlobalIndexMap > local_to_global_index_map_single_component_
void setInitialConditionsConcreteProcess(std::vector< GlobalVector * > &x, double const t, int const process_id) override
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
void initializeBoundaryConditions(std::map< int, std::shared_ptr< MaterialPropertyLib::Medium > > const &media) override
void postTimestepConcreteProcess(std::vector< GlobalVector * > const &x, std::vector< GlobalVector * > const &x_prev, double const t, double const dt, const int process_id) override
std::vector< std::vector< std::string > > initializeAssemblyOnSubmeshes(std::vector< std::reference_wrapper< MeshLib::Mesh > > const &meshes) override
LocalAssemblerInterface< DisplacementDim > LocalAssemblerIF
std::vector< std::unique_ptr< LocalAssemblerIF > > local_assemblers_
NumLib::LocalToGlobalIndexMap const & getDOFTable(const int process_id) const override
std::tuple< NumLib::LocalToGlobalIndexMap *, bool > getDOFTableForExtrapolatorData() const override
RichardsMechanicsProcess(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, RichardsMechanicsProcessData< DisplacementDim > &&process_data, SecondaryVariableCollection &&secondary_variables, bool const use_monolithic_scheme, bool const is_linear)
std::unique_ptr< MeshLib::MeshSubset const > mesh_subset_base_nodes_
Handles configuration of several secondary variables from the project file.
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)
@ 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)
void addReflectedSecondaryVariables(ReflData const &reflection_data, SecondaryVariableCollection &secondary_variables, NumLib::Extrapolator &extrapolator, std::vector< std::unique_ptr< LocAsmIF > > const &local_assemblers)
void addReflectedIntegrationPointWriters(ReflData const &reflection_data, std::vector< std::unique_ptr< MeshLib::IntegrationPointWriter > > &integration_point_writers, unsigned const integration_order, std::vector< std::unique_ptr< LocAsmIF > > const &local_assemblers)
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)