Lethe Open-Source Library version 1.2.0
Developer Guide
Loading...
Searching...
No Matches
insertion_file.cc
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) 2024-2026 The Lethe Authors
2// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception OR LGPL-2.1-or-later
3
4#include <core/utilities.h>
5
7
8using namespace DEM;
9
10template <int dim, typename PropertiesIndex>
12 const std::vector<std::shared_ptr<Distribution>>
13 &size_distribution_object_container,
14 const parallel::distributed::Triangulation<dim> &triangulation,
15 const DEMSolverParameters<dim> &dem_parameters)
16 : Insertion<dim, PropertiesIndex>(size_distribution_object_container,
17 triangulation,
18 dem_parameters)
20 dem_parameters.lagrangian_physical_properties.number.at(0))
21 , number_of_files(dem_parameters.insertion_info.list_of_input_files.size())
22 , insertion_files(dem_parameters.insertion_info.list_of_input_files)
23{
24 // Initializing current inserting particle type and file id
26 this->current_file_id = 0;
27}
28template <int dim, typename PropertiesIndex>
29void
31 Particles::ParticleHandler<dim> &particle_handler,
32 const parallel::distributed::Triangulation<dim> &triangulation,
33 const DEMSolverParameters<dim> &dem_parameters)
34{
38 {
40 dem_parameters.lagrangian_physical_properties.number.at(
42 }
43
45 {
47 {
48 if (this->mark_for_update)
49 {
50 this->find_cells_in_removing_box(triangulation);
51 this->mark_for_update = false;
52 }
53 this->remove_particles_in_box(particle_handler);
54 }
55
56 // Read the input file
57 std::map<std::string, std::vector<double>> particles_data;
58 fill_vectors_from_file(particles_data,
60 ";");
63
64 // Number of particles in the file
65 unsigned int n_total_particles_to_insert = particles_data["p_x"].size();
66
67 // Adjusting the value in case we exceed the maximum number of particle in
68 // the simulation.
69 n_total_particles_to_insert =
70 std::min(remaining_particles_of_each_type, n_total_particles_to_insert);
71
72 // Processor 0 will be the only one inserting particles
73 MPI_Comm communicator = triangulation.get_mpi_communicator();
74 auto this_mpi_process = Utilities::MPI::this_mpi_process(communicator);
75 const unsigned int n_particles_to_insert_this_proc =
76 this_mpi_process == 0 ? n_total_particles_to_insert : 0;
77
78 std::vector<Point<dim>> insertion_points_on_proc_this_step;
79 insertion_points_on_proc_this_step.reserve(
80 n_particles_to_insert_this_proc);
81
82 if (this_mpi_process == 0)
83 {
84 for (unsigned int p = 0; p < n_particles_to_insert_this_proc; ++p)
85 {
86 if constexpr (dim == 2)
87 {
88 insertion_points_on_proc_this_step.emplace_back(Point<dim>(
89 {particles_data["p_x"][p], particles_data["p_y"][p]}));
90 }
91
92 if constexpr (dim == 3)
93 {
94 insertion_points_on_proc_this_step.emplace_back(
95 Point<dim>({particles_data["p_x"][p],
96 particles_data["p_y"][p],
97 particles_data["p_z"][p]}));
98 }
99 }
100 }
101
102 // Obtain global bounding boxes
103 const auto my_bounding_box =
104 GridTools::compute_mesh_predicate_bounding_box(
105 triangulation, IteratorFilters::LocallyOwnedCell());
106 const auto global_bounding_boxes =
107 Utilities::MPI::all_gather(communicator, my_bounding_box);
108
109 // A vector of vectors, which contains all the properties of all particles
110 // about to get inserted
111 std::vector<std::vector<double>> particle_properties;
112
113 // Assign inserted particles properties
115 dem_parameters,
116 n_particles_to_insert_this_proc,
117 particles_data,
118 particle_properties);
119
120 // Insert the particles using the points and assigned properties
121 particle_handler.insert_global_particles(
122 insertion_points_on_proc_this_step,
123 global_bounding_boxes,
124 particle_properties);
125
126 // Update number of particle remaining to be inserted
127 remaining_particles_of_each_type -= n_total_particles_to_insert;
128
129
130 ConditionalOStream pcout(
131 std::cout, Utilities::MPI::this_mpi_process(MPI_COMM_WORLD) == 0);
132 this->print_insertion_info(n_total_particles_to_insert,
135 pcout);
136 }
137}
138
139template <int dim, typename PropertiesIndex>
140void
143 const DEMSolverParameters<dim> &dem_parameters,
144 const unsigned int &inserted_this_step_this_proc,
145 std::map<std::string, std::vector<double>> &particles_data,
146 std::vector<std::vector<double>> &particle_properties)
147{
148 // Clearing and resizing particle_properties
149 particle_properties.reserve(inserted_this_step_this_proc);
150
151 // Getting properties as local parameters
152 auto physical_properties = dem_parameters.lagrangian_physical_properties;
153
154 // A loop is defined over the number of particles which are going to be
155 // inserted at this step
156 for (unsigned int particle_counter = 0;
157 particle_counter < inserted_this_step_this_proc;
158 ++particle_counter)
159 {
160 double type = this->current_inserting_particle_type;
161 double diameter = particles_data["diameters"][particle_counter];
162 double density =
163 physical_properties
164 .density_particle[this->current_inserting_particle_type];
165 double vel_x = particles_data["v_x"][particle_counter];
166 double vel_y = particles_data["v_y"][particle_counter];
167 double vel_z = particles_data["v_z"][particle_counter];
168 double omega_x = particles_data["w_x"][particle_counter];
169 double omega_y = particles_data["w_y"][particle_counter];
170 double omega_z = particles_data["w_z"][particle_counter];
171 double mass = density * 4. / 3. * M_PI *
172 Utilities::fixed_power<3, double>(diameter * 0.5);
173
174 // Every property which is not set explicitly below, such as the CFD-DEM
175 // coupling properties, is left to zero.
176 std::vector<double> properties_of_one_particle(
177 PropertiesIndex::n_properties, 0.);
178
179 properties_of_one_particle[PropertiesIndex::type] = type;
180 properties_of_one_particle[PropertiesIndex::dp] = diameter;
181 properties_of_one_particle[PropertiesIndex::mass] = mass;
182 properties_of_one_particle[PropertiesIndex::v_x] = vel_x;
183 properties_of_one_particle[PropertiesIndex::v_y] = vel_y;
184 properties_of_one_particle[PropertiesIndex::v_z] = vel_z;
185 properties_of_one_particle[PropertiesIndex::omega_x] = omega_x;
186 properties_of_one_particle[PropertiesIndex::omega_y] = omega_y;
187 properties_of_one_particle[PropertiesIndex::omega_z] = omega_z;
188
190 {
191 properties_of_one_particle[PropertiesIndex::T] =
192 particles_data["T"][particle_counter];
193 properties_of_one_particle[PropertiesIndex::specific_heat] =
194 physical_properties
195 .specific_heat_particle[this->current_inserting_particle_type];
196 }
197
198 particle_properties.push_back(properties_of_one_particle);
199 properties_of_one_particle.clear();
200 }
201}
202
Handles all the parameters declared in the parameter handler file.
Parameters::Lagrangian::LagrangianPhysicalProperties lagrangian_physical_properties
unsigned int current_inserting_particle_type
void assign_particle_properties_for_file_insertion(const DEMSolverParameters< dim > &dem_parameters, const unsigned int &inserted_this_step_this_proc, std::map< std::string, std::vector< double > > &particles_data, std::vector< std::vector< double > > &particle_properties)
Carries out assigning the properties of inserted particles specifically for the file insertion method...
unsigned int current_file_id
virtual void insert(Particles::ParticleHandler< dim > &particle_handler, const parallel::distributed::Triangulation< dim > &triangulation, const DEMSolverParameters< dim > &dem_parameters) override
The InsertionFile class inserts particles using data stored in a file. This allows the insertion of a...
InsertionFile(const std::vector< std::shared_ptr< Distribution > > &size_distribution_object_container, const parallel::distributed::Triangulation< dim > &triangulation, const DEMSolverParameters< dim > &dem_parameters)
The InsertionFile class inserts particles using data stored in a file. This allows the insertion of a...
const unsigned int number_of_files
const std::vector< std::string > insertion_files
unsigned int remaining_particles_of_each_type
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
void fill_vectors_from_file(std::map< std::string, std::vector< double > > &map, const std::string &file_name, const std::string &delimiter=" ")
function that read a file that was build from a dealii table and fill 2 vectors. The first vector con...
Definition utilities.cc:299
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.
unsigned int particle_type_number
Number of particle types.
std::vector< int > number
Number particles of each particle type.