Lethe Open-Source Library version 1.2.0
Developer Guide
Loading...
Searching...
No Matches
serial_solid.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) 2022-2026 The Lethe Authors
2// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception OR LGPL-2.1-or-later
3
4#ifndef lethe_serial_solid_h
5#define lethe_serial_solid_h
6
7#include <core/pvd_handler.h>
11#include <core/utilities.h>
12
13#include <deal.II/base/function.h>
14
15#include <deal.II/dofs/dof_handler.h>
16
17#include <deal.II/fe/mapping_fe.h>
18
19#include <deal.II/particles/particle_handler.h>
20
21#include <unordered_map>
22
23using namespace dealii;
24
25/**
26 * A class that generates an object to manage a serial triangulation that
27 * represents a solid object. This class can represent solid objects for which
28 * the dimension do not match the spatial dimension. For example, a 2D surface
29 * defined in 3D or a line defined in 2D.
30 *
31 * @tparam dim An integer that denotes the dimensionality of the geometry
32 * @tparam spacedim An integer that denotes the dimension of the space occupied
33 * by the embedded solid
34 *
35 */
36
37template <int dim, int spacedim = dim>
39{
40public:
43 unsigned int id);
44
45 /**
46 * @brief Maps the solid object in the background triangulation
47 */
48 std::vector<
49 std::pair<typename Triangulation<spacedim>::active_cell_iterator,
50 typename Triangulation<dim, spacedim>::active_cell_iterator>>
52 const parallel::TriangulationBase<spacedim> &background_tr);
53
54 /**
55 * @brief Manages solid triangulation setup
56 */
57 void
59
60 /**
61 * @brief Generates a solid triangulation from a dealii or gmsh mesh
62 *
63 * @param restart Boolean variable that indicates if the simulation is being restarted
64 */
65 void
66 setup_triangulation(const bool restart);
67
68 /**
69 * @brief Set-ups the displacement vector to store the motion of the triangulation
70 */
71 void
73
74 /**
75 * @brief Builds the neighboring cells information for each cell of the solid
76 * object. These containers store for each of these cells which neighboring
77 * cells are sharing a vertex or an edge (two vertex). Also stores which of
78 * these neighboring cells are coplanar or non-coplanar.
79 */
80 void
82
83 /**
84 * @brief Returns the shared pointer to the solid object triangulation.
85 *
86 * @return shared_ptr of the solid triangulation
87 */
88 std::shared_ptr<Triangulation<dim, spacedim>>
90
91 /**
92 * @brief Returns the dof_handler associated with the displacement of the solid object
93 *
94 * @return the reference to the displacement dof handler
95 */
96 DoFHandler<dim, spacedim> &
98
99 /**
100 * @brief Returns the displacement vector of all the vertices of the solid object
101 *
102 * @return the reference to the displacement vector
103 */
104 Vector<double> &
106
107 /**
108 * @brief Calculates the max displacement of the solid object. The max
109 * displacement is defined as the L^\infty norm of the displacement
110 * components. This is a measure of the maximal displacement in any direction.
111 *
112 * @return The reference to the vector of the displacement since the mapping
113 */
114 double
116
117 /**
118 * @brief Returns translational velocity of the center of mass of the solid object
119 *
120 * @return The translational velocity of the solid object
121 */
122 inline Tensor<1, 3>
127
128 /**
129 * @brief Returns the angular velocity of the center of mass of the solid object
130 *
131 * @return The angular velocity of the solid object
132 */
133 inline Tensor<1, 3>
135 {
136 return this->current_angular_velocity;
137 }
138
139 /**
140 * @brief Returns the center of rotation of the center of mass of the solid object
141 *
142 * @return The center of rotation of the solid object
143 */
144 inline Point<3>
146 {
147 if constexpr (spacedim == 3)
148 return this->center_of_rotation;
149
150 else
152 }
153
154 /**
155 * @brief Returns the temperature of the solid object
156 *
157 * @return The temperature of the solid object
158 */
159 inline double
161 {
162 return this->current_solid_temperature;
163 }
164
165 /**
166 * @brief Returns the thermal boundary type of the solid object
167 *
168 * @return The thermal boundary type of the solid object
169 */
172 {
173 return this->thermal_boundary_type;
174 }
175
176 /**
177 * @brief Returns the solid id of the solid object.
178 * This ID is an unsigned integer which is given to the solid object at
179 * compile time and is mostly used when writing files.
180 *
181 * @return id of the solid
182 */
183 inline unsigned int
185 {
186 return id;
187 }
188
189 using triangulation_cell_neighbors_map = std::unordered_map<
190 typename Triangulation<dim, spacedim>::active_cell_iterator,
191 std::vector<typename Triangulation<dim, spacedim>::active_cell_iterator>,
193
194 /**
195 * @brief Returns the neighboring cells maps of the solid object triangulation.
196 * These maps store for each cell of the solid object which neighboring cells
197 * are sharing a vertex or an edge (two vertex). 1. edge-sharing and 2.
198 * vertex-sharing.
199 *
200 * @return A tuple of references to the edge-sharing and vertex-sharing
201 * neighboring cells maps.
202 */
203 inline std::tuple<const triangulation_cell_neighbors_map &,
206 {
207 return std::tie(es_neighbors, vs_neighbors);
208 }
209
210 /**
211 * @brief Update the temperature of the solid object, which is a function of time.
212 *
213 * @param initial_time The initial time (time t) of the timestep. This is used to
214 * set the time of the temperature function.
215 */
216 void
217 update_solid_temperature(const double initial_time);
218
219 /**
220 * @brief Moves the vertices of the solid triangulation. This function
221 * uses explicitEuler scheme time integrator to displace the vertices
222 * of the solid triangulation and stores the displacement in an array
223 * in order to allow correct checkpointing of the triangulation.
224 *
225 * @param time_step The time_step value for this iteration
226 * @param initial_time The initial time (time t) of the timestep. This is used to
227 * set the time of the velocity function.
228 */
229 void
230 move_solid_triangulation(double time_step, double initial_time);
231
232 /**
233 * @brief Write the output file of the solid object triangulation
234 *
235 * @param simulation_control The simulation control object
236 */
237 void
239 const std::shared_ptr<SimulationControl> &simulation_control);
240
241 /**
242 * @brief read solid base triangulation checkpoint and replaces the
243 * triangulation at the location where it was when it was checkpointed
244 *
245 * @param prefix_name The prefix of the checkpoint of the simulation
246 *
247 */
248 void
249 read_checkpoint(const std::string &prefix_name);
250
251 /**
252 * @brief write solid base triangulation checkpoint
253 *
254 * @param prefix_name The prefix of the checkpoint of the simulation
255 */
256 void
257 write_checkpoint(const std::string &prefix_name);
258
259
260private:
261 /**
262 * @brief Moves the dofs of the solid_triangulation by using the displacement vector.
263 * This is only used to move the solid triangulation at the correct location
264 * when the simulation is restarted.
265 */
266 void
268
269 /**
270 * @brief Reset displacements since intersection for contact detection
271 */
272 void
277
278 /**
279 * @brief Moves the vertices of the solid triangulation using the displacement
280 * vector. This is mostly used when restarting simulations which contain
281 * a serial solid in order to replace it at the position it was when the
282 * simulation finished.
283 */
284 void
286
287 /**
288 * @brief Rotates the grid by a given angle around an axis
289 *
290 * @param angle The angle (in rad) with which the solid is rotated
291 * @param axis The axis over which the solid is rotated.
292 *
293 */
294 void
295 rotate_grid(const double angle,
296 [[maybe_unused]] const Tensor<1, spacedim> &axis);
297
298 /**
299 * @brief Translate the grid. In spacedim=2, the third component is ignored
300 *
301 * @param translate The vector with which the solid is translated.
302 */
303 void
304 translate_grid(const Tensor<1, spacedim> &translate);
305
306 // Member variables
307
308 // MPI
310 const unsigned int n_mpi_processes;
311 const unsigned int this_mpi_process;
312
313 // Parameters
314 std::shared_ptr<Parameters::RigidSolidObject<dim, spacedim>> &param;
315
316 // Identifier of the solid
317 unsigned int id;
318
319 // Triangulation and DOFs management
320 std::shared_ptr<Triangulation<dim, spacedim>> solid_tria;
321 std::shared_ptr<FiniteElement<dim, spacedim>> fe;
322 std::shared_ptr<Mapping<dim, spacedim>> solid_mapping;
323 DoFHandler<dim, spacedim> displacement_dh;
324 std::shared_ptr<FESystem<dim, spacedim>> displacement_fe;
325 Vector<double> displacement;
327
328 // Output management
330 const bool output_bool;
331
332 // Elements used to store the velocity of the solid object
333 std::shared_ptr<Function<spacedim>> translational_velocity;
334 std::shared_ptr<Function<spacedim>> angular_velocity;
335 Point<spacedim> center_of_rotation;
338 std::shared_ptr<Function<spacedim>> solid_temperature;
341
342 // Neighboring cells maps
343 // ES : edge-sharing
344 // VS : vertex-sharing
346};
347
348#endif
The PVDHandler class manages the storage of the information required to write pvd file....
Definition pvd_handler.h:17
Parameters for a single rigid solid object used in DEM simulations.
std::shared_ptr< Function< spacedim > > angular_velocity
void setup_containers()
Builds the neighboring cells information for each cell of the solid object. These containers store fo...
const unsigned int n_mpi_processes
unsigned int id
PVDHandler pvdhandler
Tensor< 1, 3 > current_angular_velocity
std::shared_ptr< Triangulation< dim, spacedim > > solid_tria
void setup_dof_handler()
Set-ups the displacement vector to store the motion of the triangulation.
MPI_Comm mpi_communicator
void write_output_results(const std::shared_ptr< SimulationControl > &simulation_control)
Write the output file of the solid object triangulation.
std::shared_ptr< FiniteElement< dim, spacedim > > fe
std::shared_ptr< Parameters::RigidSolidObject< dim, spacedim > > & param
double current_solid_temperature
Tensor< 1, 3 > get_translational_velocity() const
Returns translational velocity of the center of mass of the solid object.
std::shared_ptr< FESystem< dim, spacedim > > displacement_fe
triangulation_cell_neighbors_map vs_neighbors
Vector< double > displacement_since_mapped
std::shared_ptr< Triangulation< dim, spacedim > > get_triangulation()
Returns the shared pointer to the solid object triangulation.
Tensor< 1, spacedim > current_translational_velocity
triangulation_cell_neighbors_map es_neighbors
void move_solid_triangulation(double time_step, double initial_time)
Moves the vertices of the solid triangulation. This function uses explicitEuler scheme time integrato...
void initial_setup()
Manages solid triangulation setup.
void reset_displacement_monitoring()
Reset displacements since intersection for contact detection.
void read_checkpoint(const std::string &prefix_name)
read solid base triangulation checkpoint and replaces the triangulation at the location where it was ...
DoFHandler< dim, spacedim > displacement_dh
void rotate_grid(const double angle, const Tensor< 1, spacedim > &axis)
Rotates the grid by a given angle around an axis.
void write_checkpoint(const std::string &prefix_name)
write solid base triangulation checkpoint
Tensor< 1, 3 > get_angular_velocity() const
Returns the angular velocity of the center of mass of the solid object.
const bool output_bool
std::shared_ptr< Function< spacedim > > translational_velocity
double get_temperature() const
Returns the temperature of the solid object.
Parameters::SolidObjectThermalBoundaryType get_thermal_boundary_type() const
Returns the thermal boundary type of the solid object.
Vector< double > displacement
DoFHandler< dim, spacedim > & get_dof_handler()
Returns the dof_handler associated with the displacement of the solid object.
Point< 3 > get_center_of_rotation() const
Returns the center of rotation of the center of mass of the solid object.
void update_solid_temperature(const double initial_time)
Update the temperature of the solid object, which is a function of time.
double get_max_displacement_since_mapped() const
Calculates the max displacement of the solid object. The max displacement is defined as the L^\infty ...
Parameters::SolidObjectThermalBoundaryType thermal_boundary_type
std::vector< std::pair< typename Triangulation< spacedim >::active_cell_iterator, typename Triangulation< dim, spacedim >::active_cell_iterator > > map_solid_in_background_triangulation(const parallel::TriangulationBase< spacedim > &background_tr)
Maps the solid object in the background triangulation.
void translate_grid(const Tensor< 1, spacedim > &translate)
Translate the grid. In spacedim=2, the third component is ignored.
std::shared_ptr< Function< spacedim > > solid_temperature
std::tuple< const triangulation_cell_neighbors_map &, const triangulation_cell_neighbors_map & > get_neighbors_maps() const
Returns the neighboring cells maps of the solid object triangulation. These maps store for each cell ...
unsigned int get_solid_id() const
Returns the solid id of the solid object. This ID is an unsigned integer which is given to the solid ...
std::unordered_map< typename Triangulation< dim, spacedim >::active_cell_iterator, std::vector< typename Triangulation< dim, spacedim >::active_cell_iterator >, cut_cell_hash< spacedim > > triangulation_cell_neighbors_map
const unsigned int this_mpi_process
void move_solid_triangulation_with_displacement()
Moves the vertices of the solid triangulation using the displacement vector. This is mostly used when...
Point< spacedim > center_of_rotation
void displace_solid_triangulation()
Moves the dofs of the solid_triangulation by using the displacement vector. This is only used to move...
std::shared_ptr< Mapping< dim, spacedim > > solid_mapping
void setup_triangulation(const bool restart)
Generates a solid triangulation from a dealii or gmsh mesh.
SerialSolid(std::shared_ptr< Parameters::RigidSolidObject< dim, spacedim > > &param, unsigned int id)
Vector< double > & get_displacement_vector()
Returns the displacement vector of all the vertices of the solid object.
SolidObjectThermalBoundaryType
Thermal boundary condition type applied on a solid object surface.
Simulation control classes for managing time-stepping and iteration control in Lethe.
Parameter classes for solid objects used in Nitsche immersed boundary and DEM simulations.
Hash functor to enable using cut-cell (embedded triangulation) active cell iterators as keys of an un...
Definition utilities.h:1431
Tensor< 1, 3 > tensor_nd_to_3d(const Tensor< 1, dim > &tensor)
Point< 3 > point_nd_to_3d(const Point< dim > &point)