Lethe Open-Source Library version 1.2.0
Developer Guide
Loading...
Searching...
No Matches
continuum_solid_dynamics.cc
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) 2026 The Lethe Authors
2// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception OR LGPL-2.1-or-later
3
4#include <core/bdf.h>
5#include <core/utilities.h>
6
8
9#include <deal.II/base/exceptions.h>
10#include <deal.II/base/quadrature_lib.h>
11
12#include <deal.II/dofs/dof_renumbering.h>
13#include <deal.II/dofs/dof_tools.h>
14
15#include <deal.II/fe/fe_q.h>
16#include <deal.II/fe/fe_system.h>
17#include <deal.II/fe/mapping_q.h>
18
19#include <deal.II/grid/grid_tools.h>
20
21#include <deal.II/lac/dynamic_sparsity_pattern.h>
22#include <deal.II/lac/sparsity_tools.h>
23
24#include <deal.II/numerics/data_component_interpretation.h>
25
26#include <algorithm>
27#include <cmath>
28#include <iomanip>
29#include <string>
30#include <utility>
31
32template <int dim>
34 MultiphysicsInterface<dim> *multiphysics_interface,
35 const SimulationParameters<dim> &p_simulation_parameters,
36 const std::shared_ptr<parallel::DistributedTriangulationBase<dim>>
37 &p_triangulation,
38 const std::shared_ptr<SimulationControl> &p_simulation_control)
40 p_simulation_parameters.physics_solving_strategy.at(
42 , multiphysics(multiphysics_interface)
43 , computing_timer(p_triangulation->get_mpi_communicator(),
44 this->pcout,
45 TimerOutput::never,
46 TimerOutput::wall_times)
47 , simulation_parameters(p_simulation_parameters)
48 , triangulation(p_triangulation)
49 , simulation_control(p_simulation_control)
50 , dof_handler(std::make_shared<DoFHandler<dim>>(*triangulation))
53{
54 AssertThrow(!simulation_parameters.mesh.simplex,
55 ExcMessage("The solid phase physics does not support simplex "
56 "meshes yet."));
57
58 this->pcout << std::setprecision(simulation_control->get_log_precision())
59 << std::scientific;
60
61 const unsigned int velocity_degree =
62 simulation_parameters.fem_parameters.solid_velocity_degree;
63 const unsigned int volume_fraction_degree =
64 simulation_parameters.fem_parameters.solid_volume_fraction_degree;
65
66 // Solid velocity (dim components) followed by the solid volume fraction
67 fe = std::make_shared<FESystem<dim>>(FE_Q<dim>(velocity_degree),
68 dim,
69 FE_Q<dim>(volume_fraction_degree),
70 1);
71 // fe->degree is the highest degree of the two fields
72 mapping = std::make_shared<MappingQ<dim>>(fe->degree);
73 cell_quadrature = std::make_shared<QGauss<dim>>(fe->degree + 1);
74 face_quadrature = std::make_shared<QGauss<dim - 1>>(fe->degree + 1);
75
76 present_solution = std::make_shared<GlobalVectorType>();
78 std::make_shared<SolutionTransfer<dim, GlobalVectorType>>(*dof_handler);
79
80 previous_solutions = std::make_shared<std::vector<GlobalVectorType>>(
83 for (unsigned int i = 0; i < previous_solutions->size(); ++i)
84 previous_solutions_transfer.emplace_back(
85 SolutionTransfer<dim, GlobalVectorType>(*dof_handler));
86}
87
88template <int dim>
89std::vector<OutputStruct<dim, GlobalVectorType>>
91{
92 std::vector<OutputStruct<dim, GlobalVectorType>> solution_output_structs;
93
94 std::vector<std::string> solution_names(dim, "solid_velocity");
95 solution_names.emplace_back("solid_volume_fraction");
96
97 std::vector<DataComponentInterpretation::DataComponentInterpretation>
98 component_interpretation(
99 dim, DataComponentInterpretation::component_is_part_of_vector);
100 component_interpretation.push_back(
101 DataComponentInterpretation::component_is_scalar);
102
103 solution_output_structs.emplace_back(
107 solution_names,
108 component_interpretation);
109 return solution_output_structs;
110}
111
112template <int dim>
113void
115{
117 {
118 announce_string(this->pcout, "Continuum Solid Dynamics");
119 this->pcout << std::defaultfloat;
120 computing_timer.print_summary();
121 this->pcout << std::scientific;
122 }
123}
124
125template <int dim>
126void
128{
129 for (unsigned int i = previous_solutions->size() - 1; i > 0; --i)
130 (*previous_solutions)[i] = (*previous_solutions)[i - 1];
131 (*previous_solutions)[0] = *present_solution;
132}
133
134template <int dim>
135void
136ContinuumSolidDynamics<dim>::postprocess([[maybe_unused]] bool first_iteration)
137{}
138
139template <int dim>
140void
142{
143 announce_string(this->pcout, "Continuum Solid Dynamics");
144 this->pcout << std::defaultfloat;
145 computing_timer.print_summary();
146 this->pcout << std::scientific;
147 computing_timer.reset();
148}
149
150template <int dim>
151void
153{
154 solution_transfer->prepare_for_coarsening_and_refinement(*present_solution);
155 for (unsigned int i = 0; i < previous_solutions->size(); ++i)
156 previous_solutions_transfer[i].prepare_for_coarsening_and_refinement(
157 (*previous_solutions)[i]);
158}
159
160template <int dim>
161void
163{
164 const auto mpi_communicator = triangulation->get_mpi_communicator();
165
166 GlobalVectorType tmp(locally_owned_dofs, mpi_communicator);
167 solution_transfer->interpolate(tmp);
168 nonzero_constraints.distribute(tmp);
169 *present_solution = tmp;
170
171 for (unsigned int i = 0; i < previous_solutions->size(); ++i)
172 {
173 GlobalVectorType tmp_previous_solution(locally_owned_dofs,
174 mpi_communicator);
175 previous_solutions_transfer[i].interpolate(tmp_previous_solution);
176 nonzero_constraints.distribute(tmp_previous_solution);
177 (*previous_solutions)[i] = tmp_previous_solution;
178 }
179}
180
181template <int dim>
182void
184 [[maybe_unused]] const std::pair<const Variable,
186 &ivar,
187 [[maybe_unused]] dealii::Vector<float> &estimated_error_per_cell)
188{
189 AssertThrow(false,
190 ExcMessage("Mesh adaptation based on solid phase variables is "
191 "not implemented yet."));
192}
193
194template <int dim>
195void
197{
198 std::vector<const GlobalVectorType *> sol_set_transfer;
199
201 std::make_shared<SolutionTransfer<dim, GlobalVectorType>>(*dof_handler);
202
203 sol_set_transfer.emplace_back(&(*present_solution));
204 for (const auto &previous_solution : *previous_solutions)
205 sol_set_transfer.emplace_back(&previous_solution);
206
207 solution_transfer->prepare_for_serialization(sol_set_transfer);
208}
209
210template <int dim>
211void
213{
214 const auto mpi_communicator = triangulation->get_mpi_communicator();
215 this->pcout << "Reading solid phase checkpoint" << std::endl;
216
217 std::vector<GlobalVectorType *> input_vectors(1 + previous_solutions->size());
218 GlobalVectorType distributed_system(locally_owned_dofs, mpi_communicator);
219 input_vectors[0] = &distributed_system;
220
221 std::vector<GlobalVectorType> distributed_previous_solutions;
222 distributed_previous_solutions.reserve(previous_solutions->size());
223 for (unsigned int i = 0; i < previous_solutions->size(); ++i)
224 {
225 distributed_previous_solutions.emplace_back(
226 GlobalVectorType(locally_owned_dofs, mpi_communicator));
227 input_vectors[i + 1] = &distributed_previous_solutions[i];
228 }
229
230 solution_transfer->deserialize(input_vectors);
231
232 *present_solution = distributed_system;
233 for (unsigned int i = 0; i < previous_solutions->size(); ++i)
234 (*previous_solutions)[i] = distributed_previous_solutions[i];
235}
236
237template <int dim>
238std::vector<OutputStructTableHandler>
240{
241 return std::vector<OutputStructTableHandler>();
242}
243
244template <int dim>
245void
247{
248 nonzero_constraints.clear();
250 DoFTools::make_hanging_node_constraints(*dof_handler, nonzero_constraints);
251 nonzero_constraints.close();
252
253 zero_constraints.clear();
255 DoFTools::make_hanging_node_constraints(*dof_handler, zero_constraints);
256 zero_constraints.close();
257}
258
259template <int dim>
260void
262{
263 dof_handler->distribute_dofs(*fe);
264 DoFRenumbering::Cuthill_McKee(*dof_handler);
265
266 const auto mpi_communicator = triangulation->get_mpi_communicator();
267
268 locally_owned_dofs = dof_handler->locally_owned_dofs();
269 locally_relevant_dofs = DoFTools::extract_locally_relevant_dofs(*dof_handler);
270
273 mpi_communicator);
274 for (auto &solution : *previous_solutions)
275 solution.reinit(locally_owned_dofs,
277 mpi_communicator);
278
281 mpi_communicator);
282 system_rhs.reinit(locally_owned_dofs, mpi_communicator);
283 newton_update.reinit(locally_owned_dofs, mpi_communicator);
284 local_evaluation_point.reinit(locally_owned_dofs, mpi_communicator);
285
287
288 DynamicSparsityPattern dsp(locally_relevant_dofs);
289 DoFTools::make_sparsity_pattern(*dof_handler,
290 dsp,
292 /*keep_constrained_dofs = */ true);
293 SparsityTools::distribute_sparsity_pattern(dsp,
295 mpi_communicator,
299 dsp,
300 mpi_communicator);
301
302 this->pcout << " Number of solid phase degrees of freedom: "
303 << dof_handler->n_dofs() << std::endl;
304
305 // Share the solid phase fields with the other physics (e.g. VANS)
313}
314
315template <int dim>
316void
318{
319 // Zero until solid phase initial conditions are added to the parameters
320 *present_solution = 0.;
322}
323
324template <int dim>
325void
327{
328 AssertThrow(false,
329 ExcMessage("The solid phase linear solver is not implemented "
330 "yet."));
331}
332
333template <int dim>
334void
336{
337 AssertThrow(false,
338 ExcMessage("The solid phase system matrix assembly is not "
339 "implemented yet."));
340}
341
342template <int dim>
343void
345{
346 AssertThrow(false,
347 ExcMessage("The solid phase right-hand side assembly is not "
348 "implemented yet."));
349}
350
351template <int dim>
352void
354{
355 this->pcout << "\t ||dx||_L2 = " << std::setw(6) << newton_update.l2_norm()
356 << std::setw(6)
357 << "\t ||dx||_Linfty = " << newton_update.linfty_norm()
358 << std::endl;
359}
360
361template <int dim>
362double
364{
365 return simulation_parameters.linear_solver
367 .rescale_residual_by_volume ?
368 std::sqrt(GridTools::volume(*triangulation, *mapping)) :
369 1.;
370}
371
372template class ContinuumSolidDynamics<2>;
373template class ContinuumSolidDynamics<3>;
unsigned int maximum_number_of_previous_solutions()
Get the maximum number of previous time steps supposed by the BDF schemes implemented in Lethe.
Definition bdf.h:84
AuxiliaryPhysics(const Parameters::NonLinearSolver non_linear_solver_parameters)
Solid phase of the Euler-Euler model, solved as an auxiliary physics coupled to the VANS fluid dynami...
std::shared_ptr< SimulationControl > simulation_control
Simulation control.
std::shared_ptr< SolutionTransfer< dim, GlobalVectorType > > solution_transfer
Solution transfer for mesh adaptation and checkpointing.
std::shared_ptr< DoFHandler< dim > > dof_handler
DoFHandler of the solid phase.
std::vector< SolutionTransfer< dim, GlobalVectorType > > previous_solutions_transfer
void compute_error_estimate(const std::pair< const Variable, Parameters::MultipleAdaptationParameters > &ivar, dealii::Vector< float > &estimated_error_per_cell) override
Compute the error estimate used for mesh adaptation. Not supported yet for the solid phase.
TimerOutput computing_timer
Timer of the solid phase physics.
void solve_linear_system() override
Solve the linear system. Not implemented yet.
void assemble_system_rhs() override
Assemble the system right-hand side. Not implemented yet.
const SimulationParameters< dim > & simulation_parameters
Simulation parameters.
std::shared_ptr< FiniteElement< dim > > fe
FESystem: dim velocity components + 1 volume fraction component.
TrilinosWrappers::SparseMatrix system_matrix
std::vector< OutputStructTableHandler > gather_tables() override
Gather the post-processing tables to serialize. None yet.
void pre_mesh_adaptation() override
Prepare the solution vectors for mesh refinement/coarsening.
std::vector< OutputStruct< dim, GlobalVectorType > > gather_output_hook() override
Gather the solid velocity and solid volume fraction for output.
ContinuumSolidDynamics(MultiphysicsInterface< dim > *multiphysics_interface, const SimulationParameters< dim > &p_simulation_parameters, const std::shared_ptr< parallel::DistributedTriangulationBase< dim > > &p_triangulation, const std::shared_ptr< SimulationControl > &p_simulation_control)
Constructor of the solid phase physics.
std::shared_ptr< parallel::DistributedTriangulationBase< dim > > triangulation
Triangulation shared by all physics.
void set_initial_conditions() override
Set the initial conditions. Fields are set to zero for now.
std::shared_ptr< std::vector< GlobalVectorType > > previous_solutions
Previous solutions for the BDF time-stepping schemes.
double get_residual_rescale_metric() const override
Get the metric used to rescale the residual.
void write_checkpoint() override
Serialize the present and previous solutions for restart.
void percolate_time_vectors() override
Shift the solution history for the BDF time-stepping schemes.
std::shared_ptr< Quadrature< dim - 1 > > face_quadrature
AffineConstraints< double > zero_constraints
void setup_dofs() override
Distribute the DoFs, allocate the vectors and matrix, and register the solid phase fields in the mult...
const FEValuesExtractors::Scalar solid_volume_fraction_extractor
void post_mesh_adaptation() override
Interpolate the solution vectors onto the adapted mesh.
std::shared_ptr< GlobalVectorType > present_solution
void read_checkpoint() override
Deserialize the present and previous solutions for restart.
IndexSet locally_owned_dofs
Locally owned and locally relevant DoFs.
std::shared_ptr< Quadrature< dim > > cell_quadrature
void finish_simulation() override
Finish the simulation (print timers).
const FEValuesExtractors::Vector solid_velocity_extractor
Extractors of the solid velocity and solid volume fraction.
GlobalVectorType evaluation_point
Solution and solver vectors.
AffineConstraints< double > nonzero_constraints
void define_constraints()
Define the constraints (hanging nodes only for now).
std::shared_ptr< Mapping< dim > > mapping
Mapping, cell and face quadratures.
void postprocess(bool first_iteration) override
Post-process the solid phase solution. Nothing is computed yet.
void output_per_iteration_timer() override
Print the timer summary at each iteration.
void output_newton_update_norms() override
Print the norms of the Newton update.
MultiphysicsInterface< dim > * multiphysics
Multiphysics interface used to exchange fields with other physics.
void assemble_system_matrix() override
Assemble the system matrix. Not implemented yet.
PhysicsSolverStrategy< GlobalVectorType > * physics_solving_strategy
Auxiliary physics for the solid phase of the Euler-Euler (two-fluid) model.
void announce_string(const ConditionalOStream &pcout, const std::string &expression, const char delimiter='-')
Prints a string and then adds a line above and below made with dashes containing as many dashes as th...
Definition utilities.h:500
Variable
Solution fields of the different physics that are used as an indicator for multiple purposes (e....
PhysicsID
Unique identifiers for each physics module in Lethe.
@ continuum_solid_dynamics
Euler-Euler solid phase (solid velocity, solid volume fraction).
Struct containing information about the solution output. It is used to pass all the information requi...
Mesh Adaptation Parameters that can differ for each refinement variable.
dealii::TrilinosWrappers::MPI::Vector GlobalVectorType
Definition vector.h:17