Lethe Open-Source Library version 1.2.0
Developer Guide
Loading...
Searching...
No Matches
ray_tracing.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) 2025 The Lethe Authors
2// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception OR LGPL-2.1-or-later
3
4#ifndef lethe_ray_tracing_h
5#define lethe_ray_tracing_h
6
8
11#include <dem/insertion.h>
12#include <dem/load_balancing.h>
14
15#include <deal.II/base/timer.h>
16
17
18/**
19 * @brief Solver that uses ray tracing to find intersection points between photons
20 * and particles.
21 * @tparam dim An integer that denotes the number of spatial dimensions.
22 */
23template <int dim>
25{
26public:
29
30 /**
31 * @brief Calls all the necessary functions to set parameters, solve the intersection
32 * points between the photons and the particles, and finish the simulation.
33 */
34 void
35 solve();
36
37private:
38 /**
39 * @brief Set the parameters for the ray tracing.
40 */
41 void
43
44 /**
45 * @brief Set the insertion method. Supported insertion method are list and file.
46 *
47 * @return The pointer to the particle insertion object.
48 */
49 std::shared_ptr<Insertion<dim, DEMProperties::PropertiesIndex>>
51
52 /**
53 * @brief Set up the background degree of freedom used for parallel grid
54 * output or mapping of periodic dofs when using periodic boundaries.
55 */
56 void
58
59 /**
60 * @brief Check if a load balancing is required according to the load
61 * balancing method and perform it if necessary.
62 */
63 void
65
66 /**
67 * @brief Print information about the photons that have been inserted during an
68 * insertion time step.
69 *
70 * @param[in] inserted_photon Number of inserted photon at the start of the
71 * simulation.
72 * @param[in] pcout Printing in parallel
73 */
74 static void
75 print_insertion_info(const unsigned int &inserted_photon,
76 const ConditionalOStream &pcout);
77
78 /**
79 * @brief Insert particles and photons at the beginning of a ray tracing
80 * simulation.
81 */
82 void
84
85 /**
86 * @brief Generate the output file of the particle ray tracing in parallel.
87 *
88 * @param[in] points Vector of points containing every intersection points
89 * between photons and particles.
90 */
91 void
92 write_output_results(const std::vector<Point<dim>> &points);
93
94 /**
95 * @brief Execute the last post-processing at the end of the simulation and
96 * output test results if necessary.
97 *
98 * @param[in] intersection_points Vector of points containing every
99 * intersection between photons and particles.
100 */
101 void
102 finish_simulation(const std::vector<Point<3>> &intersection_points);
103
104 /**
105 * @brief Execute the ray tracing algorithm to find intersection points between
106 * photons and particles.
107 *
108 * @tparam NeighborListType Type of the data structure containing the neighboring
109 * cells.
110 *
111 * @param[in] cell_list Data structure containing the local or ghost
112 * neighboring cell to each local cell in the triangulation.
113 * @param[in,out] photon_intersection_points_map A map containing information
114 * about each intersection point found during the ray tracing. The key of the
115 * map is the particle index of the photon. The value is a tuple containing
116 * the distance between the initial location of the photon and the
117 * intersection point, the intersection point and an iterator to the photon
118 * that needs to be removed.
119 */
120 template <typename NeighborListType>
121 void
123 NeighborListType &cell_list,
124 ankerl::unordered_dense::map<
125 types::particle_index,
126 std::tuple<double, Point<dim>, Particles::ParticleIterator<dim>>>
127 &photon_intersection_points_map);
128
129 /**
130 * @brief The MPI communicator used for the parallel simulation.
131 */
133
134 /**
135 * @brief The number of MPI processes used for the parallel simulation.
136 */
137 const unsigned int n_mpi_processes;
138
139 /**
140 * @brief The rank of the current MPI process.
141 */
142 const unsigned int this_mpi_process;
143
144 /**
145 * @brief The output stream used for the parallel simulation, only used by
146 * the process 0.
147 */
148 ConditionalOStream pcout;
149
150 /**
151 * @brief The parameters of the Ray Tracing simulation.
152 */
154
155 /**
156 * @brief DEM parameters needed for some functions related to the DEM particles.
157 */
159 /**
160 * @brief The distributed triangulation used for the DEM simulation.
161 */
162 parallel::distributed::Triangulation<dim> triangulation;
163
164 /**
165 * @brief The polynomial mapping. The mapping is first order in DEM
166 * simulations.
167 */
168 MappingQGeneric<dim> mapping;
169
170 /**
171 * @brief The particle handler that manages the particles.
172 */
173 Particles::ParticleHandler<dim, dim> particle_handler;
174
175 /**
176 * @brief The photon handler that manages the photons.
177 */
178 Particles::ParticleHandler<dim, dim> photon_handler;
179
180 /**
181 * @brief The timer that keeps track of the time spent in some functions.
182 * Currently, the only function for which timing is monitored is load
183 * balancing.
184 */
185 TimerOutput computing_timer;
186
187 /**
188 * @brief The action manager that manages the actions triggered by events.
189 */
191
192 /**
193 * @brief The load balancing handler.
194 */
196
197 /**
198 * @brief The background degree of freedom handler uses for parallel grid
199 * processing.
200 */
201 DoFHandler<dim> background_dh;
202
203 /**
204 * @brief The simulation control (DEM Transient).
205 */
206 std::shared_ptr<SimulationControl> simulation_control;
207
208 /**
209 * @brief The particle insertion object.
210 */
211 std::shared_ptr<Insertion<dim, DEMProperties::PropertiesIndex>>
213
214 /**
215 * @brief The reference displacement distance used to move the photons
216 * during each pseudo time step.
217 */
219
220 /**
221 * @brief Container that shows the local/ghost neighbor cells of all local
222 * cells in the triangulation. Note that they are reciprocal.
223 */
225 {
226 // Base type, shared by both
228
229 // Distinct tagged typedefs
231 {};
233 {};
234 };
235
238
239 /// Local neighbor list
241
242 /// Ghost neighbor list
244};
245#endif // lethe_ray_tracing_h
Manage the actions to be performed in the DEM solver and on the DEM part of the coupling CFD-DEM solv...
Handles all the parameters declared in the parameter handler file.
Manages the load balancing (repartitioning), of the domain according to the computational load of the...
Handles all the parameters declared in the parameter handler file.
void load_balance()
Check if a load balancing is required according to the load balancing method and perform it if necess...
DEMActionManager * action_manager
The action manager that manages the actions triggered by events.
const DEMSolverParameters< dim > dem_parameters
DEM parameters needed for some functions related to the DEM particles.
typename neighbor_list_types::ghost ghost_neighbor_list
const unsigned int this_mpi_process
The rank of the current MPI process.
ghost_neighbor_list cells_ghost_neighbor_list
Ghost neighbor list.
parallel::distributed::Triangulation< dim > triangulation
The distributed triangulation used for the DEM simulation.
void finish_simulation(const std::vector< Point< 3 > > &intersection_points)
Execute the last post-processing at the end of the simulation and output test results if necessary.
const unsigned int n_mpi_processes
The number of MPI processes used for the parallel simulation.
Particles::ParticleHandler< dim, dim > photon_handler
The photon handler that manages the photons.
TimerOutput computing_timer
The timer that keeps track of the time spent in some functions. Currently, the only function for whic...
LagrangianLoadBalancing< dim, DEMProperties::PropertiesIndex > load_balancing
The load balancing handler.
void setup_parameters()
Set the parameters for the ray tracing.
MPI_Comm mpi_communicator
The MPI communicator used for the parallel simulation.
void setup_background_dofs()
Set up the background degree of freedom used for parallel grid output or mapping of periodic dofs whe...
std::shared_ptr< Insertion< dim, DEMProperties::PropertiesIndex > > set_particle_insertion_type()
Set the insertion method. Supported insertion method are list and file.
ConditionalOStream pcout
The output stream used for the parallel simulation, only used by the process 0.
DoFHandler< dim > background_dh
The background degree of freedom handler uses for parallel grid processing.
MappingQGeneric< dim > mapping
The polynomial mapping. The mapping is first order in DEM simulations.
Particles::ParticleHandler< dim, dim > particle_handler
The particle handler that manages the particles.
void write_output_results(const std::vector< Point< dim > > &points)
Generate the output file of the particle ray tracing in parallel.
RayTracingSolver(RayTracingSolverParameters< dim > &parameters, DEMSolverParameters< dim > &dem_parameters)
std::shared_ptr< Insertion< dim, DEMProperties::PropertiesIndex > > particle_insertion_object
The particle insertion object.
std::shared_ptr< SimulationControl > simulation_control
The simulation control (DEM Transient).
local_neighbor_list cells_local_neighbor_list
Local neighbor list.
void find_intersection(NeighborListType &cell_list, ankerl::unordered_dense::map< types::particle_index, std::tuple< double, Point< dim >, Particles::ParticleIterator< dim > > > &photon_intersection_points_map)
Execute the ray tracing algorithm to find intersection points between photons and particles.
double displacement_distance
The reference displacement distance used to move the photons during each pseudo time step.
typename neighbor_list_types::local local_neighbor_list
void insert_particles_and_photons()
Insert particles and photons at the beginning of a ray tracing simulation.
void solve()
Calls all the necessary functions to set parameters, solve the intersection points between the photon...
const RayTracingSolverParameters< dim > parameters
The parameters of the Ray Tracing simulation.
static void print_insertion_info(const unsigned int &inserted_photon, const ConditionalOStream &pcout)
Print information about the photons that have been inserted during an insertion time step.
DEM particle property definitions and output name management.
std::vector< std::vector< typename Triangulation< dim >::active_cell_iterator > > cells_neighbor_list
Container that shows the local/ghost neighbor cells of all local cells in the triangulation....
typename dem_data_structures< dim >::cells_neighbor_list base_type