Lethe Open-Source Library version 1.2.0
Developer Guide
Loading...
Searching...
No Matches
insertion_list.cc
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) 2021, 2023-2025 The Lethe Authors
2// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception OR LGPL-2.1-or-later
3
5
6using namespace DEM;
7
8DeclException2(DiameterSizeCoherence,
9 int,
10 int,
11 << "Incoherent particle diameter lists: list x has " << arg1
12 << " element(s) and list d has " << arg2 << " element(s).");
13
14/* @brief The constructor checks if the position lists are of a coherent size
15 * relative to each-other and creates the insertion_points member
16 */
17template <int dim, typename PropertiesIndex>
19 const std::vector<std::shared_ptr<Distribution>>
20 &size_distribution_object_container,
21 const parallel::distributed::Triangulation<dim> &triangulation,
22 const DEMSolverParameters<dim> &dem_parameters)
23 : Insertion<dim, PropertiesIndex>(size_distribution_object_container,
24 triangulation,
25 dem_parameters)
27 dem_parameters.lagrangian_physical_properties.number.at(0))
28{
29 // Initializing the current inserting particle type
31
32 const std::vector<double> &list_x = dem_parameters.insertion_info.list_x;
33 const std::vector<double> &list_y = dem_parameters.insertion_info.list_y;
34 const std::vector<double> &list_z = dem_parameters.insertion_info.list_z;
35 const std::vector<double> &list_vx = dem_parameters.insertion_info.list_vx;
36 const std::vector<double> &list_vy = dem_parameters.insertion_info.list_vy;
37 const std::vector<double> &list_vz = dem_parameters.insertion_info.list_vz;
38 const std::vector<double> &list_wx = dem_parameters.insertion_info.list_wx;
39 const std::vector<double> &list_wy = dem_parameters.insertion_info.list_wy;
40 const std::vector<double> &list_wz = dem_parameters.insertion_info.list_wz;
41 std::vector<double> list_d = dem_parameters.insertion_info.list_d;
42 std::vector<double> list_T = dem_parameters.insertion_info.list_T;
43
44 // If the default diameter is negative, the diameter list is resized to the
45 // number of particles and assigned the average particle diameter to all
46 // particles
47 if (list_d[0] < 0)
48 {
49 const double particle_average_diameter =
52 list_d.assign(list_x.size(), particle_average_diameter);
53 }
54
55 // Throw an error if the number diameter provided is not coherent with the
56 // number of particles.
57 AssertThrow(list_x.size() == list_d.size(),
58 DiameterSizeCoherence(list_x.size(), list_d.size()));
59
60 // Generate vector of insertion position
61 for (unsigned int i = 0; i < list_x.size(); ++i)
62 {
63 if constexpr (dim == 2)
64 {
65 insertion_points.emplace_back(Point<dim>({list_x[i], list_y[i]}));
66 velocities.emplace_back(Tensor<1, 3>({list_vx[i], list_vy[i], 0.}));
67 angular_velocities.emplace_back(Tensor<1, 3>({0., 0., list_wz[i]}));
68 }
69 if constexpr (dim == 3)
70 {
71 insertion_points.emplace_back(
72 Point<dim>({list_x[i], list_y[i], list_z[i]}));
73 velocities.emplace_back(
74 Tensor<1, 3>({list_vx[i], list_vy[i], list_vz[i]}));
75 angular_velocities.emplace_back(
76 Tensor<1, 3>({list_wx[i], list_wy[i], list_wz[i]}));
77 }
78 }
79 diameters = list_d;
80 temperatures = list_T;
81}
82
83// The main insertion function. Insert_global_function is used to insert the
84// particles
85template <int dim, typename PropertiesIndex>
86void
88 Particles::ParticleHandler<dim> &particle_handler,
89 const parallel::distributed::Triangulation<dim> &triangulation,
90 const DEMSolverParameters<dim> &dem_parameters)
91{
92 // TODO refactor into a function call
96 {
98 dem_parameters.lagrangian_physical_properties.number.at(
100 }
101
103 {
105 {
106 if (this->mark_for_update)
107 {
108 this->find_cells_in_removing_box(triangulation);
109 this->mark_for_update = false;
110 }
111 this->remove_particles_in_box(particle_handler);
112 }
113
114 unsigned int n_total_particles_to_insert = insertion_points.size();
115 n_total_particles_to_insert =
116 std::min(remaining_particles_of_each_type, n_total_particles_to_insert);
117
118 // All processors except 0 will not insert particles
119 MPI_Comm communicator = triangulation.get_mpi_communicator();
120 auto this_mpi_process = Utilities::MPI::this_mpi_process(communicator);
121 const unsigned int n_particles_to_insert_this_proc =
122 this_mpi_process == 0 ? n_total_particles_to_insert : 0;
123
124 std::vector<Point<dim>> insertion_points_on_proc_this_step;
125 insertion_points_on_proc_this_step.reserve(
126 n_particles_to_insert_this_proc);
127
128 // Because the list insertion is made to insert only a few particles,
129 // only processor 0 manages the insertion of these particles
130 if (this_mpi_process == 0)
131 {
132 for (unsigned int p = 0; p < n_particles_to_insert_this_proc; ++p)
133 {
134 insertion_points_on_proc_this_step.emplace_back(
136 }
137 }
138
139 // Get global bounding boxes
140 const auto my_bounding_box =
141 GridTools::compute_mesh_predicate_bounding_box(
142 triangulation, IteratorFilters::LocallyOwnedCell());
143 const auto global_bounding_boxes =
144 Utilities::MPI::all_gather(communicator, my_bounding_box);
145
146 // A vector of vectors, which contains all the properties of all inserted
147 // particles at each insertion step
148 std::vector<std::vector<double>> particle_properties;
149
150 // Assign inserted particles properties
152 dem_parameters, n_particles_to_insert_this_proc, particle_properties);
153
154 // Insert the particles using the points and assigned properties
155 particle_handler.insert_global_particles(
156 insertion_points_on_proc_this_step,
157 global_bounding_boxes,
158 particle_properties);
159
160 // Updated number of particles remaining to be inserted
161 remaining_particles_of_each_type -= n_total_particles_to_insert;
162
163
164 ConditionalOStream pcout(
165 std::cout, Utilities::MPI::this_mpi_process(MPI_COMM_WORLD) == 0);
166 this->print_insertion_info(n_total_particles_to_insert,
169 pcout);
170 }
171}
172
173template <int dim, typename PropertiesIndex>
174void
177 const DEMSolverParameters<dim> &dem_parameters,
178 const unsigned int &inserted_this_step_this_proc,
179 std::vector<std::vector<double>> &particle_properties)
180{
181 // Clearing and resizing particle_properties
182 particle_properties.reserve(inserted_this_step_this_proc);
183
184 // Getting properties as local parameters
185 // TODO: MAYBE CHANGE THE INPUT TO PHYSICAL PROPERTIES DIRECTLY
186 auto physical_properties = dem_parameters.lagrangian_physical_properties;
187
188 // A loop is defined over the number of particles which are going to be
189 // inserted at this step
190 for (unsigned int particle_counter = 0;
191 particle_counter < inserted_this_step_this_proc;
192 ++particle_counter)
193 {
194 const double type = current_inserting_particle_type;
195 const double diameter = this->diameters[particle_counter];
196 const double density =
197 physical_properties.density_particle[current_inserting_particle_type];
198 const double vel_x = this->velocities[particle_counter][0];
199 const double vel_y = this->velocities[particle_counter][1];
200 const double vel_z = this->velocities[particle_counter][2];
201 const double omega_x = this->angular_velocities[particle_counter][0];
202 const double omega_y = this->angular_velocities[particle_counter][1];
203 const double omega_z = this->angular_velocities[particle_counter][2];
204 const double mass = density * 4. / 3. * M_PI *
205 Utilities::fixed_power<3, double>(diameter * 0.5);
206
207 // Every property which is not set explicitly below, such as the CFD-DEM
208 // coupling properties, is left to zero.
209 std::vector<double> properties_of_one_particle(
210 PropertiesIndex::n_properties, 0.);
211
212 properties_of_one_particle[PropertiesIndex::type] = type;
213 properties_of_one_particle[PropertiesIndex::dp] = diameter;
214 properties_of_one_particle[PropertiesIndex::mass] = mass;
215 properties_of_one_particle[PropertiesIndex::v_x] = vel_x;
216 properties_of_one_particle[PropertiesIndex::v_y] = vel_y;
217 properties_of_one_particle[PropertiesIndex::v_z] = vel_z;
218 properties_of_one_particle[PropertiesIndex::omega_x] = omega_x;
219 properties_of_one_particle[PropertiesIndex::omega_y] = omega_y;
220 properties_of_one_particle[PropertiesIndex::omega_z] = omega_z;
221
223 {
224 properties_of_one_particle[PropertiesIndex::T] =
225 this->temperatures[particle_counter];
226 properties_of_one_particle[PropertiesIndex::specific_heat] =
227 physical_properties
228 .specific_heat_particle[current_inserting_particle_type];
229 }
230
231 particle_properties.push_back(properties_of_one_particle);
232 properties_of_one_particle.clear();
233 }
234}
235
Handles all the parameters declared in the parameter handler file.
Parameters::Lagrangian::LagrangianPhysicalProperties lagrangian_physical_properties
Parameters::Lagrangian::InsertionInfo< dim > insertion_info
std::vector< Tensor< 1, 3 > > velocities
std::vector< Tensor< 1, 3 > > angular_velocities
unsigned int remaining_particles_of_each_type
std::vector< double > diameters
virtual void insert(Particles::ParticleHandler< dim > &particle_handler, const parallel::distributed::Triangulation< dim > &triangulation, const DEMSolverParameters< dim > &dem_parameters) override
The InsertionList class inserts particles using a list of specific position. This allows the insertio...
InsertionList(const std::vector< std::shared_ptr< Distribution > > &size_distribution_object_container, const parallel::distributed::Triangulation< dim > &triangulation, const DEMSolverParameters< dim > &dem_parameters)
Insert particles using a list of specific positions. This allows the insertion of a low number of par...
unsigned int current_inserting_particle_type
std::vector< double > temperatures
void assign_particle_properties_for_list_insertion(const DEMSolverParameters< dim > &dem_parameters, const unsigned int &inserted_this_step_this_proc, std::vector< std::vector< double > > &particle_properties)
Carries out assigning the properties of inserted particles specifically for the list insertion method...
std::vector< Point< dim > > insertion_points
void remove_particles_in_box(Particles::ParticleHandler< dim > &particle_handler)
Remove every particle located inside a predefined zone. Currently, the zone is defined by a box.
Definition insertion.cc:186
bool mark_for_update
Definition insertion.h:181
void find_cells_in_removing_box(const parallel::distributed::Triangulation< dim > &triangulation)
Find all cells that are completely and partially inside de the clearing box. For the cell completely ...
Definition insertion.cc:134
const bool removing_particles_in_region
Definition insertion.h:170
Insertion(const std::vector< std::shared_ptr< Distribution > > &size_distribution_object_container, const parallel::distributed::Triangulation< dim > &triangulation, const DEMSolverParameters< dim > &dem_parameters)
Carries out the insertion of particles. This is the base class of volume_insertion,...
Definition insertion.cc:10
void print_insertion_info(const unsigned int &inserted_this_step, const unsigned int &remained_particles, const unsigned int &particle_type, const ConditionalOStream &pcout)
Print information about the particles that have been inserted during an insertion time step.
Definition insertion.cc:44
DeclException2(DiameterSizeCoherence, int, int,<< "Incoherent particle diameter lists: list x has "<< arg1<< " element(s) and list d has "<< arg2<< " element(s).")
This namespace defines all the data containers and required operations on these containers for the DE...
constexpr bool has_thermal_properties
Whether a properties index set carries thermal properties.
std::vector< double > particle_average_diameter
Average diameter of each particle type.
unsigned int particle_type_number
Number of particle types.
std::vector< int > number
Number particles of each particle type.