Lethe Open-Source Library version 1.2.0
Developer Guide
Loading...
Searching...
No Matches
insertion.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) 2020-2026 The Lethe Authors
2// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception OR LGPL-2.1-or-later
3
4#ifndef lethe_insertion_h
5#define lethe_insertion_h
6
8#include <dem/distributions.h>
9
10#include <deal.II/base/data_out_base.h>
11
12#include <deal.II/distributed/tria.h>
13
14#include <deal.II/grid/filtered_iterator.h>
15#include <deal.II/grid/grid_tools.h>
16
17#include <deal.II/particles/particle_handler.h>
18#include <deal.II/particles/particle_iterator.h>
19
20#include <boost/archive/text_iarchive.hpp>
21#include <boost/archive/text_oarchive.hpp>
22
23using namespace dealii;
24
25/**
26 * @brief Base interface for classes that carry out the insertion of particles
27 * in the system.
28 * @tparam dim An integer that denotes the number of spatial dimensions.
29 * @tparam PropertiesIndex Index of the properties used within the ParticleHandler.
30 */
31template <int dim, typename PropertiesIndex>
33{
34public:
35 /**
36 * @brief Carries out the insertion of particles. This is the base class of
37 * volume_insertion, plane_insertion, list_insertion and file_insertion
38 * classes.
39 *
40 * @param size_distribution_object_container Contains all distribution for each
41 * particle type
42 * @param triangulation Triangulation to access the cells in which the
43 * particles are inserted
44 * @param dem_parameters DEM parameters declared in the .prm file
45 */
46 Insertion(const std::vector<std::shared_ptr<Distribution>>
47 &size_distribution_object_container,
48 const parallel::distributed::Triangulation<dim> &triangulation,
49 const DEMSolverParameters<dim> &dem_parameters);
50 /**
51 * @brief Carries out the destruction of the insertion class.
52 *
53 */
54 virtual ~Insertion()
55 {
56 // This boost signal needs to be disconnected before being destroyed,
57 // otherwise a segfault could occur when the triangulation will be
58 // destroyed.
59 this->change_to_triangulation.disconnect();
60 };
61
62 /**
63 * @brief This function is overridden by the volume_insertion, plane_insertion,
64 * list_insertion and file_insertion classes.
65 *
66 * @param particle_handler The particle handler of particles which are being
67 * inserted
68 * @param triangulation Triangulation to access the cells in which the
69 * particles are inserted
70 * @param dem_parameters DEM parameters declared in the .prm file
71 */
72 virtual void
73 insert(Particles::ParticleHandler<dim> &particle_handler,
74 const parallel::distributed::Triangulation<dim> &triangulation,
75 const DEMSolverParameters<dim> &dem_parameters) = 0;
76
77 /**
78 * @brief Serialize the insertion object to an output archive. Is being used
79 * when checkpointing a simulation. This function is overridden by
80 * volume_insertion, plane_insertion, list_insertion and file_insertion
81 * classes.
82 *
83 * @param ar Output archive where the attributes are stored.
84 *
85 */
86 virtual void
87 serialize(boost::archive::text_oarchive &ar) = 0;
88
89
90 /**
91 * @brief Deserialize an input archive to the insertion object. Is being used
92 * when restarting a simulation. This function is overridden by
93 * volume_insertion, plane_insertion, list_insertion and from_file_insertion
94 * classes.
95 *
96 * @param ar Input archive where the attributes are stored.
97 *
98 */
99 virtual void
100 deserialize(boost::archive::text_iarchive &ar) = 0;
101
102protected:
103 /**
104 * @brief Print information about the particles that have been inserted during an
105 * insertion time step.
106 *
107 * @param inserted_this_step Number of particles that are inserted
108 * at each insertion step.
109 * @param remained_particles Number of remained particles going to be inserted
110 * in future insertions
111 * @param particle_type Inserted particle type
112 * @param pcout Printing in parallel
113 */
114 void
115 print_insertion_info(const unsigned int &inserted_this_step,
116 const unsigned int &remained_particles,
117 const unsigned int &particle_type,
118 const ConditionalOStream &pcout);
119
120 /**
121 * @brief Carries out assigning the properties of inserted particles.
122 *
123 * @param dem_parameters DEM parameters declared in the prm file.
124 * @param inserted_this_step_this_proc Number of particles that are inserted
125 * at each insertion step on each processor. This value can change in the last
126 * insertion step to reach the desired number of particles.
127 * @param current_inserting_particle_type Type of inserting particles.
128 * @param insertion_points Insertion points of all inserted particles at this
129 * insertion step.
130 * @param particle_properties Properties of all inserted particles at this
131 * insertion step.
132 */
133 void
135 const DEMSolverParameters<dim> &dem_parameters,
136 const unsigned int &inserted_this_step_this_proc,
137 const unsigned int &current_inserting_particle_type,
138 const std::vector<Point<dim>> &insertion_points,
139 std::vector<std::vector<double>> &particle_properties);
140
141 /**
142 * @brief Find all cells that are completely and partially inside de the
143 * clearing box. For the cell completely inside the box, all the particles
144 * will be deleted. For those partially inside, fine verification is
145 * required.
146 *
147 * @param triangulation Triangulation to access the cells in which the
148 * particles deleted.
149 */
150 void
152 const parallel::distributed::Triangulation<dim> &triangulation);
153
154 /**
155 * @brief Remove every particle located inside a predefined zone. Currently,
156 * the zone is defined by a box.
157 *
158 * @param particle_handler The particle handler of particles which are being
159 * removed.
160 */
161 void
162 remove_particles_in_box(Particles::ParticleHandler<dim> &particle_handler);
163
164
165 // A distribution object that carries out the attribution of diameter to every
166 // particle during an insertion time step
167 std::vector<std::shared_ptr<Distribution>> distributions_objects;
168
169 // Clearing bool
171
172 // Clearing box coordinates
173 Point<dim> p_min, p_max;
174
175 // Cell iterator containers for clearing
176 std::set<typename Triangulation<dim>::active_cell_iterator> in_removal_box;
177 std::set<typename Triangulation<dim>::active_cell_iterator>
179
180 // For when the triangulation has changed (i.e. when load balancing)
182 boost::signals2::connection change_to_triangulation;
183};
184
185#endif /*lethe_insertion_h*/
Handles all the parameters declared in the parameter handler file.
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
virtual ~Insertion()
Carries out the destruction of the insertion class.
Definition insertion.h:54
boost::signals2::connection change_to_triangulation
Definition insertion.h:182
std::vector< std::shared_ptr< Distribution > > distributions_objects
Definition insertion.h:167
std::set< typename Triangulation< dim >::active_cell_iterator > in_removal_box
Definition insertion.h:176
Point< dim > p_min
Definition insertion.h:173
void assign_particle_properties(const DEMSolverParameters< dim > &dem_parameters, const unsigned int &inserted_this_step_this_proc, const unsigned int &current_inserting_particle_type, const std::vector< Point< dim > > &insertion_points, std::vector< std::vector< double > > &particle_properties)
Carries out assigning the properties of inserted particles.
Definition insertion.cc:63
const bool removing_particles_in_region
Definition insertion.h:170
virtual void insert(Particles::ParticleHandler< dim > &particle_handler, const parallel::distributed::Triangulation< dim > &triangulation, const DEMSolverParameters< dim > &dem_parameters)=0
This function is overridden by the volume_insertion, plane_insertion, list_insertion and file_inserti...
virtual void serialize(boost::archive::text_oarchive &ar)=0
Serialize the insertion object to an output archive. Is being used when checkpointing a simulation....
virtual void deserialize(boost::archive::text_iarchive &ar)=0
Deserialize an input archive to the insertion object. Is being used when restarting a simulation....
std::set< typename Triangulation< dim >::active_cell_iterator > edge_of_removal_box
Definition insertion.h:178
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
Point< dim > p_max
Definition insertion.h:173