OGS
RichardsMechanicsProcess.cpp
Go to the documentation of this file.
1
12
13#include <cassert>
14
23
24namespace ProcessLib
25{
26namespace RichardsMechanics
27{
28template <int DisplacementDim>
30 std::string name,
31 MeshLib::Mesh& mesh,
32 std::unique_ptr<ProcessLib::AbstractJacobianAssembler>&& jacobian_assembler,
33 std::vector<std::unique_ptr<ParameterLib::ParameterBase>> const& parameters,
34 unsigned const integration_order,
35 std::vector<std::vector<std::reference_wrapper<ProcessVariable>>>&&
36 process_variables,
38 SecondaryVariableCollection&& secondary_variables,
39 bool const use_monolithic_scheme)
40 : Process(std::move(name), mesh, std::move(jacobian_assembler), parameters,
41 integration_order, std::move(process_variables),
42 std::move(secondary_variables), use_monolithic_scheme),
43 _process_data(std::move(process_data))
44{
45 _nodal_forces = MeshLib::getOrCreateMeshProperty<double>(
46 mesh, "NodalForces", MeshLib::MeshItemType::Node, DisplacementDim);
47
48 _hydraulic_flow = MeshLib::getOrCreateMeshProperty<double>(
49 mesh, "MassFlowRate", MeshLib::MeshItemType::Node, 1);
50
51 // TODO (naumov) remove ip suffix. Probably needs modification of the mesh
52 // properties, s.t. there is no "overlapping" with cell/point data.
53 // See getOrCreateMeshProperty.
54 _integration_point_writer.emplace_back(
55 std::make_unique<MeshLib::IntegrationPointWriter>(
56 "sigma_ip",
57 static_cast<int>(mesh.getDimension() == 2 ? 4 : 6) /*n components*/,
58 integration_order, _local_assemblers, &LocalAssemblerIF::getSigma));
59
60 _integration_point_writer.emplace_back(
61 std::make_unique<MeshLib::IntegrationPointWriter>(
62 "saturation_ip", 1 /*n components*/, integration_order,
64
65 _integration_point_writer.emplace_back(
66 std::make_unique<MeshLib::IntegrationPointWriter>(
67 "porosity_ip", 1 /*n components*/, integration_order,
69
70 _integration_point_writer.emplace_back(
71 std::make_unique<MeshLib::IntegrationPointWriter>(
72 "transport_porosity_ip", 1 /*n components*/, integration_order,
74
75 _integration_point_writer.emplace_back(
76 std::make_unique<MeshLib::IntegrationPointWriter>(
77 "swelling_stress_ip",
78 static_cast<int>(mesh.getDimension() == 2 ? 4 : 6) /*n components*/,
79 integration_order, _local_assemblers,
81
82 _integration_point_writer.emplace_back(
83 std::make_unique<MeshLib::IntegrationPointWriter>(
84 "epsilon_ip",
85 static_cast<int>(mesh.getDimension() == 2 ? 4 : 6) /*n components*/,
86 integration_order, _local_assemblers,
88}
89
90template <int DisplacementDim>
92{
93 return false;
94}
95
96template <int DisplacementDim>
99 const int process_id) const
100{
101 // For the monolithic scheme or the M process (deformation) in the staggered
102 // scheme.
103 if (_use_monolithic_scheme || process_id == 1)
104 {
105 auto const& l = *_local_to_global_index_map;
106 return {l.dofSizeWithoutGhosts(), l.dofSizeWithoutGhosts(),
107 &l.getGhostIndices(), &this->_sparsity_pattern};
108 }
109
110 // For staggered scheme and H process (pressure).
111 auto const& l = *_local_to_global_index_map_with_base_nodes;
112 return {l.dofSizeWithoutGhosts(), l.dofSizeWithoutGhosts(),
113 &l.getGhostIndices(), &_sparsity_pattern_with_linear_element};
114}
115
116template <int DisplacementDim>
118{
119 // Create single component dof in every of the mesh's nodes.
120 _mesh_subset_all_nodes =
121 std::make_unique<MeshLib::MeshSubset>(_mesh, _mesh.getNodes());
122 // Create single component dof in the mesh's base nodes.
123 _base_nodes = MeshLib::getBaseNodes(_mesh.getElements());
124 _mesh_subset_base_nodes =
125 std::make_unique<MeshLib::MeshSubset>(_mesh, _base_nodes);
126
127 // TODO move the two data members somewhere else.
128 // for extrapolation of secondary variables of stress or strain
129 std::vector<MeshLib::MeshSubset> all_mesh_subsets_single_component{
130 *_mesh_subset_all_nodes};
131 _local_to_global_index_map_single_component =
132 std::make_unique<NumLib::LocalToGlobalIndexMap>(
133 std::move(all_mesh_subsets_single_component),
134 // by location order is needed for output
136
137 if (_use_monolithic_scheme)
138 {
139 // For pressure, which is the first
140 std::vector<MeshLib::MeshSubset> all_mesh_subsets{
141 *_mesh_subset_base_nodes};
142
143 // For displacement.
144 const int monolithic_process_id = 0;
145 std::generate_n(std::back_inserter(all_mesh_subsets),
146 getProcessVariables(monolithic_process_id)[1]
147 .get()
148 .getNumberOfGlobalComponents(),
149 [&]() { return *_mesh_subset_all_nodes; });
150
151 std::vector<int> const vec_n_components{1, DisplacementDim};
152 _local_to_global_index_map =
153 std::make_unique<NumLib::LocalToGlobalIndexMap>(
154 std::move(all_mesh_subsets), vec_n_components,
156 assert(_local_to_global_index_map);
157 }
158 else
159 {
160 // For displacement equation.
161 const int process_id = 1;
162 std::vector<MeshLib::MeshSubset> all_mesh_subsets;
163 std::generate_n(std::back_inserter(all_mesh_subsets),
164 getProcessVariables(process_id)[0]
165 .get()
166 .getNumberOfGlobalComponents(),
167 [&]() { return *_mesh_subset_all_nodes; });
168
169 std::vector<int> const vec_n_components{DisplacementDim};
170 _local_to_global_index_map =
171 std::make_unique<NumLib::LocalToGlobalIndexMap>(
172 std::move(all_mesh_subsets), vec_n_components,
174
175 // For pressure equation.
176 // Collect the mesh subsets with base nodes in a vector.
177 std::vector<MeshLib::MeshSubset> all_mesh_subsets_base_nodes{
178 *_mesh_subset_base_nodes};
179 _local_to_global_index_map_with_base_nodes =
180 std::make_unique<NumLib::LocalToGlobalIndexMap>(
181 std::move(all_mesh_subsets_base_nodes),
182 // by location order is needed for output
184
185 _sparsity_pattern_with_linear_element = NumLib::computeSparsityPattern(
186 *_local_to_global_index_map_with_base_nodes, _mesh);
187
188 assert(_local_to_global_index_map);
189 assert(_local_to_global_index_map_with_base_nodes);
190 }
191}
192
193template <int DisplacementDim>
195 NumLib::LocalToGlobalIndexMap const& dof_table,
196 MeshLib::Mesh const& mesh,
197 unsigned const integration_order)
198{
201 mesh.getElements(), dof_table, _local_assemblers,
202 NumLib::IntegrationOrder{integration_order}, mesh.isAxiallySymmetric(),
203 _process_data);
204
205 auto add_secondary_variable = [&](std::string const& name,
206 int const num_components,
207 auto get_ip_values_function)
208 {
209 _secondary_variables.addSecondaryVariable(
210 name,
211 makeExtrapolator(num_components, getExtrapolator(),
212 _local_assemblers,
213 std::move(get_ip_values_function)));
214 };
215
216 add_secondary_variable("sigma",
218 DisplacementDim>::RowsAtCompileTime,
219 &LocalAssemblerIF::getIntPtSigma);
220
221 add_secondary_variable("swelling_stress",
223 DisplacementDim>::RowsAtCompileTime,
224 &LocalAssemblerIF::getIntPtSwellingStress);
225
226 add_secondary_variable("epsilon",
228 DisplacementDim>::RowsAtCompileTime,
229 &LocalAssemblerIF::getIntPtEpsilon);
230
231 add_secondary_variable("velocity", DisplacementDim,
232 &LocalAssemblerIF::getIntPtDarcyVelocity);
233
234 add_secondary_variable("saturation", 1,
235 &LocalAssemblerIF::getIntPtSaturation);
236
237 add_secondary_variable("micro_saturation", 1,
238 &LocalAssemblerIF::getIntPtMicroSaturation);
239
240 add_secondary_variable("micro_pressure", 1,
241 &LocalAssemblerIF::getIntPtMicroPressure);
242
243 add_secondary_variable("porosity", 1, &LocalAssemblerIF::getIntPtPorosity);
244
245 add_secondary_variable("transport_porosity", 1,
246 &LocalAssemblerIF::getIntPtTransportPorosity);
247
248 add_secondary_variable("dry_density_solid", 1,
249 &LocalAssemblerIF::getIntPtDryDensitySolid);
250
251 //
252 // enable output of internal variables defined by material models
253 //
255 LocalAssemblerIF>(_process_data.solid_materials,
256 add_secondary_variable);
257
260 _process_data.solid_materials, _local_assemblers,
261 _integration_point_writer, integration_order);
262
263 _process_data.element_saturation = MeshLib::getOrCreateMeshProperty<double>(
264 const_cast<MeshLib::Mesh&>(mesh), "saturation_avg",
266
267 _process_data.element_porosity = MeshLib::getOrCreateMeshProperty<double>(
268 const_cast<MeshLib::Mesh&>(mesh), "porosity_avg",
270
271 _process_data.element_stresses = MeshLib::getOrCreateMeshProperty<double>(
272 const_cast<MeshLib::Mesh&>(mesh), "stress_avg",
275 DisplacementDim>::RowsAtCompileTime);
276
277 _process_data.pressure_interpolated =
278 MeshLib::getOrCreateMeshProperty<double>(
279 const_cast<MeshLib::Mesh&>(mesh), "pressure_interpolated",
281
282 setIPDataInitialConditions(_integration_point_writer, mesh.getProperties(),
283 _local_assemblers);
284
285 // Initialize local assemblers after all variables have been set.
286 GlobalExecutor::executeMemberOnDereferenced(&LocalAssemblerIF::initialize,
287 _local_assemblers,
288 *_local_to_global_index_map);
289}
290
291template <int DisplacementDim>
293 std::map<int, std::shared_ptr<MaterialPropertyLib::Medium>> const& media)
294{
295 if (_use_monolithic_scheme)
296 {
297 const int monolithic_process_id = 0;
298 initializeProcessBoundaryConditionsAndSourceTerms(
299 *_local_to_global_index_map, monolithic_process_id, media);
300 return;
301 }
302
303 // Staggered scheme:
304 // for the equations of pressure
305 const int hydraulic_process_id = 0;
306 initializeProcessBoundaryConditionsAndSourceTerms(
307 *_local_to_global_index_map_with_base_nodes, hydraulic_process_id,
308 media);
309
310 // for the equations of deformation.
311 const int mechanical_process_id = 1;
312 initializeProcessBoundaryConditionsAndSourceTerms(
313 *_local_to_global_index_map, mechanical_process_id, media);
314}
315
316template <int DisplacementDim>
318 setInitialConditionsConcreteProcess(std::vector<GlobalVector*>& x,
319 double const t,
320 int const process_id)
321{
322 if (process_id != 0)
323 {
324 return;
325 }
326
327 DBUG("SetInitialConditions RichardsMechanicsProcess.");
328
329 ProcessLib::ProcessVariable const& pv = getProcessVariables(process_id)[0];
330
332 &LocalAssemblerIF::setInitialConditions, _local_assemblers,
333 pv.getActiveElementIDs(), getDOFTables(x.size()), x, t, process_id);
334}
335
336template <int DisplacementDim>
338 const double t, double const dt, std::vector<GlobalVector*> const& x,
339 std::vector<GlobalVector*> const& x_prev, int const process_id,
341{
342 DBUG("Assemble the equations for RichardsMechanics");
343
344 std::vector<NumLib::LocalToGlobalIndexMap const*> dof_table = {
345 _local_to_global_index_map.get()};
346 ProcessLib::ProcessVariable const& pv = getProcessVariables(process_id)[0];
347
348 // Call global assembler for each local assembly item.
350 _global_assembler, &VectorMatrixAssembler::assemble, _local_assemblers,
351 pv.getActiveElementIDs(), dof_table, t, dt, x, x_prev, process_id, M, K,
352 b);
353}
354
355template <int DisplacementDim>
358 const double t, double const dt, std::vector<GlobalVector*> const& x,
359 std::vector<GlobalVector*> const& x_prev, int const process_id,
361{
362 // For the monolithic scheme
363 if (_use_monolithic_scheme)
364 {
365 DBUG(
366 "Assemble the Jacobian of RichardsMechanics for the monolithic"
367 " scheme.");
368 }
369 else
370 {
371 // For the staggered scheme
372 if (process_id == 0)
373 {
374 DBUG(
375 "Assemble the Jacobian equations of liquid fluid process in "
376 "RichardsMechanics for the staggered scheme.");
377 }
378 else
379 {
380 DBUG(
381 "Assemble the Jacobian equations of mechanical process in "
382 "RichardsMechanics for the staggered scheme.");
383 }
384 }
385
386 ProcessLib::ProcessVariable const& pv = getProcessVariables(process_id)[0];
387
388 auto const dof_tables = getDOFTables(x.size());
391 _local_assemblers, pv.getActiveElementIDs(), dof_tables, t, dt, x,
392 x_prev, process_id, M, K, b, Jac);
393
394 auto copyRhs = [&](int const variable_id, auto& output_vector)
395 {
396 if (_use_monolithic_scheme)
397 {
398 transformVariableFromGlobalVector(b, variable_id, *dof_tables[0],
399 output_vector,
400 std::negate<double>());
401 }
402 else
403 {
404 transformVariableFromGlobalVector(b, 0, *dof_tables[process_id],
405 output_vector,
406 std::negate<double>());
407 }
408 };
409 if (_use_monolithic_scheme || process_id == 0)
410 {
411 copyRhs(0, *_hydraulic_flow);
412 }
413 if (_use_monolithic_scheme || process_id == 1)
414 {
415 copyRhs(1, *_nodal_forces);
416 }
417}
418
419template <int DisplacementDim>
421 std::vector<GlobalVector*> const& x,
422 std::vector<GlobalVector*> const& x_prev, double const t, double const dt,
423 const int process_id)
424{
425 if (hasMechanicalProcess(process_id))
426 {
427 DBUG("PostTimestep RichardsMechanicsProcess.");
428
430 getProcessVariables(process_id)[0];
432 &LocalAssemblerIF::postTimestep, _local_assemblers,
433 pv.getActiveElementIDs(), getDOFTables(x.size()), x, x_prev, t, dt,
434 process_id);
435 }
436}
437
438template <int DisplacementDim>
440 computeSecondaryVariableConcrete(const double t, const double dt,
441 std::vector<GlobalVector*> const& x,
442 GlobalVector const& x_prev,
443 int const process_id)
444{
445 if (process_id != 0)
446 {
447 return;
448 }
449
450 DBUG("Compute the secondary variables for RichardsMechanicsProcess.");
451
452 ProcessLib::ProcessVariable const& pv = getProcessVariables(process_id)[0];
454 &LocalAssemblerIF::computeSecondaryVariable, _local_assemblers,
455 pv.getActiveElementIDs(), getDOFTables(x.size()), t, dt, x, x_prev,
456 process_id);
457}
458
459template <int DisplacementDim>
460std::tuple<NumLib::LocalToGlobalIndexMap*, bool> RichardsMechanicsProcess<
461 DisplacementDim>::getDOFTableForExtrapolatorData() const
462{
463 const bool manage_storage = false;
464 return std::make_tuple(_local_to_global_index_map_single_component.get(),
465 manage_storage);
466}
467
468template <int DisplacementDim>
471 const int process_id) const
472{
473 if (hasMechanicalProcess(process_id))
474 {
475 return *_local_to_global_index_map;
476 }
477
478 // For the equation of pressure
479 return *_local_to_global_index_map_with_base_nodes;
480}
481
482template class RichardsMechanicsProcess<2>;
483template class RichardsMechanicsProcess<3>;
484
485} // namespace RichardsMechanics
486} // namespace ProcessLib
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
unsigned getDimension() const
Returns the dimension of the mesh (determined by the maximum dimension over all elements).
Definition Mesh.h:88
Properties & getProperties()
Definition Mesh.h:134
std::vector< std::size_t > const & getActiveElementIDs() const
std::vector< std::unique_ptr< MeshLib::IntegrationPointWriter > > _integration_point_writer
Definition Process.h:380
std::vector< std::unique_ptr< LocalAssemblerIF > > _local_assemblers
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
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().
void computeSecondaryVariableConcrete(double const t, double const dt, std::vector< GlobalVector * > const &x, GlobalVector const &x_prev, int const process_id) 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)
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, GlobalMatrix &M, GlobalMatrix &K, 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
NumLib::LocalToGlobalIndexMap const & getDOFTable(const int process_id) const override
Handles configuration of several secondary variables from the project file.
void assembleWithJacobian(std::size_t const mesh_item_id, LocalAssemblerInterface &local_assembler, std::vector< NumLib::LocalToGlobalIndexMap const * > const &dof_tables, 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, GlobalMatrix &Jac)
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)
Eigen::Matrix< double, kelvin_vector_dimensions(DisplacementDim), 1, Eigen::ColMajor > KelvinVectorType
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::unique_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::unique_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)
virtual std::vector< double > getSaturation() const =0
virtual std::vector< double > getSwellingStress() const =0
virtual std::vector< double > getPorosity() const =0
virtual std::vector< double > getEpsilon() const =0
virtual std::vector< double > getSigma() const =0
virtual std::vector< double > getTransportPorosity() const =0