Lethe Open-Source Library version 1.2.0
Developer Guide
Loading...
Searching...
No Matches
ib_particle.cc
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) 2020-2025 The Lethe Authors
2// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception OR LGPL-2.1-or-later
3
4#include <core/ib_particle.h>
6
7template <int dim>
8void
10{
11 // initialize all the variables associated to an immersed boundary particle.
12 radius = 1.;
13 particle_id = 0.;
14
15 inertia[0][0] = 1.;
16 inertia[0][1] = 0.;
17 inertia[0][2] = 0.;
18 inertia[1][0] = 0.;
19 inertia[1][1] = 1.;
20 inertia[1][2] = 0.;
21 inertia[2][0] = 0.;
22 inertia[2][1] = 0.;
23 inertia[2][2] = 1.;
24
25
26 fluid_forces[0] = 0.;
27 fluid_forces[1] = 0.;
28
29 velocity[0] = 0.;
30 velocity[1] = 0.;
31
32 position[0] = 0.;
33 position[1] = 0.;
34
35 fluid_torque[0] = 0.;
36 fluid_torque[1] = 0.;
37 fluid_torque[2] = 0.;
38
39 orientation[0] = 0.;
40 orientation[1] = 0.;
41 orientation[2] = 0.;
42
43 omega[0] = 0.;
44 omega[1] = 0.;
45 omega[2] = 0.;
46
47 if (dim == 3)
48 {
49 fluid_forces[2] = 0.;
50 velocity[2] = 0.;
51 position[2] = 0.;
52 }
53
54 // Fill the vectors with default value
58
60 omega_impulsion = 0.;
62 impulsion = 0.;
63 impulsion_iter = 0.;
65
66 previous_positions.resize(3);
67 previous_velocity.resize(3);
68 previous_orientation.resize(3);
69 previous_omega.resize(3);
70
71 for (unsigned int i = 0; i < 3; ++i)
72 {
77 }
78
79 f_position = std::make_shared<Functions::ParsedFunction<dim>>(dim);
80 f_velocity = std::make_shared<Functions::ParsedFunction<dim>>(dim);
81 f_omega = std::make_shared<Functions::ParsedFunction<dim>>(3);
82 f_orientation = std::make_shared<Functions::ParsedFunction<dim>>(3);
83
84 rotation_matrix[0][0] = 1.;
85 rotation_matrix[0][1] = 0.;
86 rotation_matrix[0][2] = 0.;
87 rotation_matrix[1][0] = 0.;
88 rotation_matrix[1][1] = 1.;
89 rotation_matrix[1][2] = 0.;
90 rotation_matrix[2][0] = 0.;
91 rotation_matrix[2][1] = 0.;
92 rotation_matrix[2][2] = 1.;
93}
94
95template <int dim>
96void
98{
99 // initialize all the variables associated to an immersed boundary particle
105
106 for (unsigned int i = 0; i < 3; ++i)
107 {
112 }
113}
114
115template <int dim>
116std::vector<std::pair<std::string, int>>
118{
119 std::vector<std::pair<std::string, int>> particle_properties(
121 particle_properties =
124
125 // Rename particle type to id to match IB pattern
126 particle_properties[DEM::CFDDEMProperties::type] = std::make_pair("id", 1);
127
128 return particle_properties;
129}
130
131template <int dim>
132std::vector<double>
134{
135 std::vector<double> properties(get_number_properties());
143 properties
145 fluid_forces[0];
146 properties
148 fluid_forces[1];
150 fluid_torque[0];
152 fluid_torque[1];
154 fluid_torque[2];
156
157 if (dim == 2)
158 {
160 properties
162 0.;
163 }
164 if (dim == 3)
165 {
167 properties
169 fluid_forces[2];
170 }
171
172 return properties;
173}
174
175template <int dim>
176void
178 const Point<dim> &p,
179 Point<dim> &closest_point,
180 const typename DoFHandler<dim>::active_cell_iterator &cell_guess)
181{
182 shape->closest_surface_point(p, closest_point, cell_guess);
183}
184
185template <int dim>
186void
188 Point<dim> &closest_point)
189{
190 shape->closest_surface_point(p, closest_point);
191}
192
193template <int dim>
194bool
196 const Point<dim> &evaluation_point,
197 const double outer_radius,
198 const double inside_radius,
199 const bool absolute_distance,
200 const typename DoFHandler<dim>::active_cell_iterator &cell_guess)
201{
202 const double effective_radius = shape->effective_radius;
203
204 double distance = shape->value_with_cell_guess(evaluation_point, cell_guess);
205 bool is_inside_outer_ring;
206 bool is_outside_inner_ring;
207 if (absolute_distance)
208 {
209 is_inside_outer_ring = distance <= outer_radius;
210 is_outside_inner_ring = distance >= inside_radius;
211 }
212 else
213 {
214 is_inside_outer_ring = distance <= effective_radius * (outer_radius - 1);
215 is_outside_inner_ring =
216 distance >= effective_radius * (inside_radius - 1);
217 }
218
219 return is_inside_outer_ring && is_outside_inner_ring;
220}
221
222template <int dim>
223bool
224IBParticle<dim>::is_inside_crown(const Point<dim> &evaluation_point,
225 const double outer_radius,
226 const double inside_radius,
227 const bool absolute_distance)
228{
229 const double effective_radius = shape->effective_radius;
230
231 double distance = shape->value(evaluation_point);
232 bool is_inside_outer_ring;
233 bool is_outside_inner_ring;
234 if (absolute_distance)
235 {
236 is_inside_outer_ring = distance <= outer_radius;
237 is_outside_inner_ring = distance >= inside_radius;
238 }
239 else
240 {
241 is_inside_outer_ring = distance <= effective_radius * (outer_radius - 1);
242 is_outside_inner_ring =
243 distance >= effective_radius * (inside_radius - 1);
244 }
245
246 return is_inside_outer_ring && is_outside_inner_ring;
247}
248
249template <int dim>
250void
252{
253 this->shape->clear_cache();
254}
255
256template <int dim>
257void
258IBParticle<dim>::initialize_shape(const std::string &type,
259 const std::vector<double> &shape_arguments)
260{
262 shape_arguments,
263 position,
265}
266
267template <int dim>
268void
269IBParticle<dim>::initialize_shape(const std::string &type,
270 const std::string &raw_arguments)
271{
273 raw_arguments,
274 position,
276}
277
278template <int dim>
279void
280IBParticle<dim>::set_orientation(const Tensor<1, 3> &new_orientation)
281{
282 this->orientation = new_orientation;
283 this->shape->set_orientation(new_orientation);
284 this->rotation_matrix = this->shape->get_rotation_matrix();
285}
286
287template <int dim>
288void
289IBParticle<dim>::update_precalculations(DoFHandler<dim> &updated_dof_handler,
290 const bool precalculations)
291{
292 if (integrate_motion || velocity.norm() > 1e-16 || omega.norm() > 1e-16)
293 {
294 this->load_data_from_file();
295 }
296 if (typeid(*shape) == typeid(RBFShape<dim>))
297 {
298 std::static_pointer_cast<RBFShape<dim>>(shape)->update_precalculations(
299 updated_dof_handler, precalculations);
300 }
301 else if (typeid(*shape) == typeid(CompositeShape<dim>))
302 {
303 std::static_pointer_cast<CompositeShape<dim>>(shape)
304 ->update_precalculations(updated_dof_handler, precalculations);
305 }
306}
307
308template <int dim>
309void
310IBParticle<dim>::remove_superfluous_data(DoFHandler<dim> &updated_dof_handler,
311 const bool precalculations)
312{
313 if (typeid(*shape) == typeid(RBFShape<dim>))
314 std::static_pointer_cast<RBFShape<dim>>(shape)->remove_superfluous_data(
315 updated_dof_handler, precalculations);
316 else if (typeid(*shape) == typeid(CompositeShape<dim>))
317 std::static_pointer_cast<CompositeShape<dim>>(shape)
318 ->remove_superfluous_data(updated_dof_handler, precalculations);
319}
320
321template <int dim>
322void
324{
325 if (typeid(*shape) == typeid(RBFShape<dim>))
326 std::static_pointer_cast<RBFShape<dim>>(shape)->load_data_from_file();
327 else if (typeid(*shape) == typeid(CompositeShape<dim>))
328 std::static_pointer_cast<CompositeShape<dim>>(shape)->load_data_from_file();
329}
330
331template class IBParticle<2>;
332template class IBParticle<3>;
This class was designed so that specific composite shapes could be defined through the parameter file...
Definition shape.h:2105
static std::vector< std::pair< std::string, int > > get_properties_name()
Return the names of each DEM property. Used to properly generate output files.
Define the behavior of a specific particle for the sharp interface IB solver.
Definition ib_particle.h:26
std::vector< Tensor< 1, 3 > > previous_orientation
Previous time step's orientation.
Tensor< 1, 3 > orientation
Orientation, with 0 angular position by default on every axis.
std::vector< double > get_properties()
Return the value of the DEM properties, for visualization.
double radius
Effective radius, which is the actual radius for spheres.
Tensor< 1, 3 > omega
Angular velocity.
std::shared_ptr< Functions::ParsedFunction< dim > > f_omega
Function that determines the angular velocity.
Tensor< 1, 3 > fluid_forces
Total fluid force applied on the particle.
std::vector< Point< dim > > previous_positions
Positions at the last n time steps. n depends on the time integration scheme.
bool integrate_motion
Indicate if the particle dynamics are solved.
void set_orientation(const Tensor< 1, 3 > &orientation)
Set the orientation and dependent members to the given orientation.
void load_data_from_file()
Load data from the files (for file-based Shapes).
Tensor< 1, 3 > contact_impulsion
Contact-generated impulsion felt by the particle.
bool is_inside_crown(const Point< dim > &evaluation_point, const double outer_radius, const double inside_radius, const bool absolute_distance, const typename DoFHandler< dim >::active_cell_iterator &cell_guess)
Determine if the given point is inside the crown for which the limits are defined by inner and outer ...
double mass
Particle's mass.
void clear_shape_cache()
Clear the cache used to evaluate the value and vector defining the signed distance function.
unsigned int get_number_properties()
Return the number of DEM properties, for visualization.
Definition ib_particle.h:56
Tensor< 2, 3 > rotation_matrix
Rotation matrix in the global space.
Tensor< 2, 3 > inertia
Inertia matrix in the particle frame of reference.
void update_precalculations(DoFHandler< dim > &updated_dof_handler, const bool mesh_based_precalculations)
Set the proper DOF handler, then compute/update the map of cells and their likely non-null nodes.
void remove_superfluous_data(DoFHandler< dim > &updated_dof_handler, const bool mesh_based_precalculations)
Update precalculations if needed, then compute and remove superfluous data.
Tensor< 1, 3 > velocity
Translational velocity.
Tensor< 1, 3 > previous_fluid_torque
Previous time step's fluid torque applied on the particle.
void closest_surface_point(const Point< dim > &p, Point< dim > &closest_point, const typename DoFHandler< dim >::active_cell_iterator &cell_guess)
Find the closest surface point on the shape.
void initialize_all()
Initialize all particles.
Definition ib_particle.cc:9
Tensor< 1, 3 > impulsion
Total impulsion felt by the particle during the current time step.
void initialize_previous_solution()
Initialize the value of the last state of the particle.
unsigned int particle_id
Unique identification number.
std::vector< std::pair< std::string, int > > get_properties_name()
Return the names of the DEM properties, for visualization.
void initialize_shape(const std::string &type, const std::vector< double > &shape_arguments)
Set up a shape in accordance with the given type and arguments.
std::shared_ptr< Functions::ParsedFunction< dim > > f_velocity
Function that determines the velocity.
Tensor< 1, 3 > omega_iter
Last non-linear iteration's angular velocity for CFD-DEM coupling.
Tensor< 1, 3 > omega_impulsion_iter
Last non-linear iteration's total angular impulsion on the particle.
Tensor< 1, 3 > fluid_torque
Fluid torque applied on the particle.
std::shared_ptr< Functions::ParsedFunction< dim > > f_position
Function that determines the position.
std::shared_ptr< Functions::ParsedFunction< dim > > f_orientation
Function that determines the orientation.
Tensor< 1, 3 > impulsion_iter
Last non-linear iteration's total impulsion on the particle.
Tensor< 1, 3 > velocity_iter
Last non-linear iteration's velocity for CFD-DEM coupling.
std::shared_ptr< Shape< dim > > shape
Geometrical information for IB application.
Tensor< 1, 3 > omega_impulsion
Total angular impulsion felt by the particle during the current time step.
Tensor< 1, 3 > previous_fluid_forces
Previous time step's total fluid force applied on the particle.
std::vector< Tensor< 1, 3 > > previous_omega
Previous time step's angular velocity.
Point< dim > position
Position, which corresponds to the centroid for most implemented shapes.
std::vector< Tensor< 1, 3 > > previous_velocity
Previous time step's translational velocity.
RBF Shapes express the signed distance function as a linear combination of Radial Basis Functions (RB...
Definition shape.h:2624
@ fem_torque_x
FEM torque - x component.
@ n_properties
Number of properties.
@ fem_force_two_way_coupling_y
FEM force which is applied on both fluid and particles - y component.
@ fem_force_two_way_coupling_z
FEM force which is applied on both fluid and particles - z component.
@ v_y
Velocity - y component.
@ fem_torque_z
FEM torque - z component.
@ fem_force_two_way_coupling_x
FEM force which is applied on both fluid and particles - x component.
@ type
Particle type.
@ v_x
Velocity - x component.
@ v_z
Velocity - z component.
@ omega_z
Angular velocity - z component.
@ omega_x
Angular velocity - x component.
@ omega_y
Angular velocity - y component.
@ fem_torque_y
FEM torque - y component.
std::shared_ptr< Shape< dim > > initialize_shape_from_vector(const std::string &type, const std::vector< double > &shape_arguments, const Point< dim > &position, const Tensor< 1, 3 > &orientation)
std::shared_ptr< Shape< dim > > initialize_shape(const std::string &type, const std::string &shape_arguments_str, const Point< dim > &position, const Tensor< 1, 3 > &orientation)