Lethe Open-Source Library version 1.2.0
Developer Guide
Loading...
Searching...
No Matches
ray_tracing.cc
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) 2025-2026 The Lethe Authors
2// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception OR LGPL-2.1-or-later
3
4#include <core/grids.h>
6
10#include <dem/ray_tracing.h>
11#include <dem/visualization.h>
12
13#include <deal.II/particles/data_out.h>
14
15#include <sys/stat.h>
16
17template <int dim>
21 : mpi_communicator(MPI_COMM_WORLD)
24 , pcout(std::cout, Utilities::MPI::this_mpi_process(MPI_COMM_WORLD) == 0)
28 Triangulation<dim>::limit_level_difference_at_vertices)
29 , mapping(1)
31 mapping,
32 DEMProperties::PropertiesIndex::n_properties)
35 this->pcout,
36 TimerOutput::never,
37 TimerOutput::wall_times)
40{
41 AssertThrow(!(parameters.model_parameters.load_balance_method ==
43 dim>::LoadBalanceMethod::dynamic_with_sparse_contacts ||
44 parameters.model_parameters.load_balance_method ==
46 dim>::LoadBalanceMethod::dynamic),
47 dealii::ExcMessage(
48 "The \"dynamic\" and \"dynamic_with_sparse_contacts\""
49 "load balancing methods are not supported"));
50}
51
52template <int dim>
53void
55{
56 // Ray tracing relies on a parallel::distributed::Triangulation throughout,
57 // whereas simplex meshes need a parallel::fullydistributed::Triangulation.
58 // Reject them explicitly rather than letting the grid reading reach an
59 // unimplemented deal.II code path.
60 AssertThrow(
61 !parameters.mesh.simplex,
62 ExcMessage(
63 "Simplex meshes are not supported by ray tracing simulations. Set 'simplex = false' in the mesh subsection."));
64
65 // Print simulation starting information
66 pcout << std::endl;
67 std::string msg =
68 "Running on " + std::to_string(n_mpi_processes) + " rank(s)";
69 announce_string(pcout, msg, '*');
70
71 // Get the pointer of the only instance of the action manager
73
74 // Set the simulation control as SimulationControlRayTracing
76 std::make_shared<SimulationControlRayTracing>(parameters.simulation_control,
78
79 // Setup load balancing parameters and attach the correct functions to the
80 // signals inside the triangulation
81 load_balancing.set_parameters(parameters.model_parameters);
82
84 dummy_sparse_contacts_object;
85 load_balancing.copy_references(simulation_control,
88 dummy_sparse_contacts_object);
89 load_balancing.connect_weight_signals();
90}
91
92template <int dim>
93std::shared_ptr<Insertion<dim, DEMProperties::PropertiesIndex>>
95{
96 using namespace Parameters::Lagrangian;
97 typename InsertionInfo<dim>::InsertionMethod insertion_method =
98 parameters.particle_insertion_info.insertion_method;
99
100 std::vector<std::shared_ptr<Distribution>>
101 dummy_size_distribution_object_container;
102
103 switch (insertion_method)
104 {
106 return std::make_shared<
108 dummy_size_distribution_object_container,
112 return std::make_shared<
114 dummy_size_distribution_object_container,
117 default:
118 AssertThrow(
119 false,
120 dealii::ExcMessage(
121 "For lethe-particles-ray-tracing simulation, only the list"
122 " and file insertion are supported."));
123 return nullptr;
124 }
125}
126
127
128template <int dim>
129void
131{
132 FE_Q<dim> background_fe(1);
133 background_dh.distribute_dofs(background_fe);
134}
135
136template <int dim>
137void
139{
140 load_balancing.check_load_balance_iteration();
141
142 if (!action_manager->check_load_balance())
143 return;
144
145 TimerOutput::Scope t(this->computing_timer, "Load balancing");
146 // Prepare particle handler for the adaptation of the triangulation to the
147 // load
148 photon_handler.prepare_for_coarsening_and_refinement();
149 particle_handler.prepare_for_coarsening_and_refinement();
150
151 pcout << "-->Repartitioning triangulation" << std::endl;
152 triangulation.repartition();
153
154 // Unpack the photon handler after the mesh has been repartitioned
155 photon_handler.unpack_after_coarsening_and_refinement();
156 particle_handler.unpack_after_coarsening_and_refinement();
157
158 const auto average_minimum_maximum_cells =
159 Utilities::MPI::min_max_avg(triangulation.n_active_cells(),
161
162 const auto average_minimum_maximum_photons =
163 Utilities::MPI::min_max_avg(photon_handler.n_locally_owned_particles(),
165
166 pcout << "Load balance finished " << std::endl;
167 pcout
168 << "Average, minimum and maximum number of photons on the processors are "
169 << average_minimum_maximum_photons.avg << " , "
170 << average_minimum_maximum_photons.min << " and "
171 << average_minimum_maximum_photons.max << std::endl;
172 pcout << "Minimum and maximum number of cells owned by the processors are "
173 << average_minimum_maximum_cells.min << " and "
174 << average_minimum_maximum_cells.max << std::endl;
175
177
178 // Particles don't move, thus we sort them at the end of a load balance.
179 // Photons are being sorted every pseudo time step, thus no need to sort them
180 // here.
181 particle_handler.sort_particles_into_subdomains_and_cells();
182
183 // Exchange ghost particles
184 particle_handler.exchange_ghost_particles(true);
185
188
189 // Update cell neighbors
193}
194
195template <int dim>
196void
197RayTracingSolver<dim>::print_insertion_info(const unsigned int &inserted_photon,
198 const ConditionalOStream &pcout)
199{
200 std::stringstream ss;
201
202 ss << inserted_photon << " photons "
203 << " were inserted.";
204
205 announce_string(pcout, ss.str(), '*');
206}
207
208template <int dim>
209void
211{
212 // Insert particles using the insertion object.
216
217 // A vector of points where the insertion location of every photon will be
218 // stored.
219 std::vector<Point<3>> insertion_points_on_proc;
220
221 // For each photon, we store its insertion/initial location as a property.
222 // This initial location is used to identify the right intersection
223 // point when multiple intersections are found. The logic used therein is that
224 // the intersection point which is closest to the initial location is the
225 // correct one. We also store the displacement direction unit vector in this
226 // vector since each photon has its own slightly offset from the reference
227 // displacement direction.
228 std::vector<std::vector<double>> photon_properties;
229
230 // Create variables for readability
231 const std::vector<unsigned int> &n_photons_each_directions =
232 parameters.ray_tracing_info.n_photons_each_directions;
233
234 // Starting point
235 const Point<dim> starting_insertion_point =
236 parameters.ray_tracing_info.starting_point;
237
238 // Insertion directions
239 const Tensor<1, dim> first_dir =
240 parameters.ray_tracing_info.insertion_directions_units_vector.at(0);
241 const Tensor<1, dim> second_dir =
242 parameters.ray_tracing_info.insertion_directions_units_vector.at(1);
243 const Tensor<1, dim> third_dir =
244 parameters.ray_tracing_info.insertion_directions_units_vector.at(2);
245
246 // Steps
247 const double step_first_dir =
248 parameters.ray_tracing_info.step_between_photons_each_directions.at(0);
249 const double step_second_dir =
250 parameters.ray_tracing_info.step_between_photons_each_directions.at(1);
251 const double step_third_dir =
252 parameters.ray_tracing_info.step_between_photons_each_directions.at(2);
253
254 // Reference displacement direction
255 const Tensor<1, 3> ref_displacement_dir =
256 parameters.ray_tracing_info.ref_displacement_tensor_unit;
257
258 // Total number of photons to insert
259 const unsigned int n_total_photons_to_insert =
260 n_photons_each_directions.at(0) * n_photons_each_directions.at(1) *
261 n_photons_each_directions.at(2);
262
263 // Distributing photons between processors
264 const unsigned int base_photons_per_proc =
265 n_total_photons_to_insert / n_mpi_processes;
266 const unsigned int remainder = n_total_photons_to_insert % n_mpi_processes;
267
268 // We add one photon to the first processors so that the total number of
269 // photon inserted match the requested number written in the prm file.
270 const unsigned int n_photons_to_insert_this_proc =
271 base_photons_per_proc + (this_mpi_process < remainder ? 1 : 0);
272
273 // First and last photon id on this processor. This will be used to find the
274 // insertion location on this proc.
275 const unsigned int first_id =
276 this_mpi_process * base_photons_per_proc +
277 (this_mpi_process < remainder ? this_mpi_process : remainder);
278 const unsigned int last_id = first_id + n_photons_to_insert_this_proc - 1;
279
280 // Generate the random offsets for the insertion position and the displacement
281 // direction. For the position, the offset uses the same logic as other
282 // insertion mechanism in Lethe. For the displacement direction of each
283 // photon, we need to generate one random angular offset (theta) relative to
284 // the reference displacement vector. We then need to decide in which
285 // direction (phi) around this reference displacement direction vector the
286 // offset will be applied.
287 std::vector<double> random_number_angular_1; // From 0 to 2*pi
288 std::vector<double> random_number_angular_2; // From 0 to max_angular_offset
289 std::vector<double> random_number_position; // From 0 to max_insertion_offset
290
291 // Reserve the size of the vectors
292 random_number_angular_1.reserve(n_photons_to_insert_this_proc);
293 random_number_angular_2.reserve(n_photons_to_insert_this_proc);
294 random_number_position.reserve(3 * n_photons_to_insert_this_proc);
295
297 random_number_angular_1,
298 n_photons_to_insert_this_proc,
299 2.0 * M_PI,
300 parameters.ray_tracing_info.prn_seed_photon_displacement);
301
303 random_number_angular_2,
304 n_photons_to_insert_this_proc,
305 parameters.ray_tracing_info.max_angular_offset,
306 parameters.ray_tracing_info.prn_seed_photon_displacement);
307
309 random_number_position,
310 3 * n_photons_to_insert_this_proc,
311 parameters.ray_tracing_info.max_insertion_offset,
312 parameters.ray_tracing_info.prn_seed_photon_insertion);
313
314 // For the displacement direction randomness, we need to find two vectors
315 // normal to ref_displacement_dir.
316 // We make sure that our first vector is not parallel to the
317 // ref_displacement_dir
318 const Tensor<1, 3> temp_normal_vector =
319 (std::fabs(ref_displacement_dir[0]) < 0.9) ? Tensor<1, 3>({1, 0, 0}) :
320 Tensor<1, 3>({0, 1, 0});
321
322 Tensor<1, 3> u = temp_normal_vector -
323 temp_normal_vector *
324 scalar_product(temp_normal_vector, ref_displacement_dir);
325 u = u / u.norm();
326
327 // We find the second one using the cross product
328 const Tensor<1, 3> v = cross_product_3d(ref_displacement_dir, u);
329
330 // Create the insertion location of every photon from their IDs.
331 // Temporary variable
332 Point<3> temp_point;
333 Tensor<1, 3> temp_dir;
334 std::vector<double> properties_of_one_photon(6);
335
336 // Prepare the containers.
337 insertion_points_on_proc.reserve(n_photons_to_insert_this_proc);
338
339 // Fill the photon properties container with vectors of size 6.
340 photon_properties.resize(n_photons_to_insert_this_proc,
341 std::vector<double>(6));
342 // This loop is equivalent of having three nested loops over the three
343 // directions. However, this way we can easily distribute the photons over
344 // the processors using the first and last ID.
345 for (unsigned int id = first_id; id <= last_id; ++id)
346 {
347 // nth position in the z direction
348 const unsigned int iz = id / (n_photons_each_directions.at(0) *
349 n_photons_each_directions.at(1));
350
351 const unsigned int rem = id % (n_photons_each_directions.at(0) *
352 n_photons_each_directions.at(1));
353 // nth position in the y direction
354 const unsigned int iy = rem / n_photons_each_directions.at(0);
355
356 // nth position in the x direction
357 const unsigned int ix = rem % n_photons_each_directions.at(0);
358
359 // ID relative to this processor. This is used to write at the right
360 // location in each container.
361 const unsigned int id_on_proc = id - first_id;
362 temp_point =
363 starting_insertion_point +
364 (ix * step_first_dir + random_number_position.at(3 * id_on_proc)) *
365 first_dir +
366 (iy * step_second_dir + random_number_position.at(3 * id_on_proc + 1)) *
367 second_dir +
368 (iz * step_third_dir + random_number_position.at(3 * id_on_proc + 2)) *
369 third_dir;
370 insertion_points_on_proc.push_back(temp_point);
371
372 temp_dir = ref_displacement_dir +
373 std::sin(random_number_angular_2.at(id_on_proc)) *
374 (std::cos(random_number_angular_1.at(id_on_proc)) * u +
375 std::sin(random_number_angular_1.at(id_on_proc)) * v);
376
377 for (unsigned int d = 0; d < 3; ++d)
378 {
379 properties_of_one_photon[d] = temp_point[d];
380 properties_of_one_photon[d + 3] = temp_dir[d];
381 }
382 photon_properties[id_on_proc] = properties_of_one_photon;
383 }
384 MPI_Comm communicator = triangulation.get_mpi_communicator();
385 // Obtain global bounding boxes
386 const auto my_bounding_box = GridTools::compute_mesh_predicate_bounding_box(
387 triangulation, IteratorFilters::LocallyOwnedCell());
388 const auto global_bounding_boxes =
389 Utilities::MPI::all_gather(communicator, my_bounding_box);
390
391 // Insert the photons using the points and the assigned properties.
392 photon_handler.insert_global_particles(insertion_points_on_proc,
393 global_bounding_boxes,
394 photon_properties);
395
396 ConditionalOStream pcout(std::cout,
397 Utilities::MPI::this_mpi_process(MPI_COMM_WORLD) ==
398 0);
399 print_insertion_info(n_total_photons_to_insert, pcout);
400}
401
402template <int dim>
403void
405 const std::vector<Point<dim>> &points)
406{
407 TimerOutput::Scope t(this->computing_timer, "Output VTU");
408
409 // Check if the output directory exists
410 std::string output_dir_name = parameters.simulation_control.output_folder;
411 struct stat buffer;
412
413 // If output directory does not exist, create it
414 if (this_mpi_process == 0)
415 {
416 if (stat(output_dir_name.c_str(), &buffer) != 0)
417 {
418 create_output_folder(output_dir_name);
419 }
420 }
421
422 // Create a temporary particle handler on the existing triangulation
423 Particles::ParticleHandler<dim> temp_handler(triangulation, mapping, 0);
424
425 MPI_Comm communicator = triangulation.get_mpi_communicator();
426 // Obtain global bounding boxes
427 const auto my_bounding_box = GridTools::compute_mesh_predicate_bounding_box(
428 triangulation, IteratorFilters::LocallyOwnedCell());
429 const auto global_bounding_boxes =
430 Utilities::MPI::all_gather(communicator, my_bounding_box);
431
432 std::vector<std::vector<double>> photon_properties(points.size());
433
434 // Insert the photons using the points and the assigned properties.
435 temp_handler.insert_global_particles(points,
436 global_bounding_boxes,
437 photon_properties);
438
439 // Write particles to a VTU file
440 Particles::DataOut<dim> data_out;
441 data_out.build_patches(temp_handler);
442
443 const std::string filename = parameters.simulation_control.output_folder +
444 "/" + parameters.simulation_control.output_name +
445 ".vtu";
446
447 data_out.write_vtu_in_parallel(filename, this->mpi_communicator);
448}
449template <int dim>
450void
452 const std::vector<Point<3>> &intersection_points)
453{
454 // Timer output
456 {
457 this->pcout << std::defaultfloat;
458 this->computing_timer.print_summary();
459 this->pcout << std::scientific;
460 }
461
462 // Testing
463 if (parameters.test.enabled)
464 {
465 // Proc 0 gathers all intersection points
466 std::vector<std::vector<Point<3>>> all_intersection_points =
467 Utilities::MPI::gather(mpi_communicator, intersection_points, 0);
468
469 pcout << "x, y, z" << std::endl;
470 // Loop over all intersection points
471 for (const std::vector<Point<3>> &sub_vector : all_intersection_points)
472 {
473 for (const Point<3> &p : sub_vector)
474 pcout << p << std::endl;
475 }
476 }
477}
478
479template <int dim>
480template <typename NeighborListType>
481void
483 NeighborListType &cell_list,
484 ankerl::unordered_dense::map<
485 types::particle_index,
486 std::tuple<double, Point<dim>, Particles::ParticleIterator<dim>>>
487 &photon_intersection_points_map)
488{
489 // Loop over each local cell in the triangulation. To do this, we loop
490 // over each cell neighbor list. Each local cell has a list and the first
491 // iterator is the main cell itself.
492 for (auto cell_neighbor_list_iterator = cell_list.begin();
493 cell_neighbor_list_iterator != cell_list.end();
494 ++cell_neighbor_list_iterator)
495 {
496 // The main cell
497 const auto main_cell = cell_neighbor_list_iterator->begin();
498
499 // Photons in main cell
500 typename Particles::ParticleHandler<dim>::particle_iterator_range
501 photons_in_main_cell = photon_handler.particles_in_cell(*main_cell);
502
503 // Loop on each photon in the main cell
504 for (auto current_photon = photons_in_main_cell.begin();
505 current_photon != photons_in_main_cell.end();
506 ++current_photon)
507 {
508 // Get the photon properties. We need the properties to find the
509 // insertion position of the current photon. This will be used to
510 // differentiate between intersection points when there's more
511 // than one.
512 auto photon_properties = current_photon->get_properties();
513
514 // Current photon insertion point.
515 const Point<3> photon_insertion_point(
516 {photon_properties[0], photon_properties[1], photon_properties[2]});
517
518 // Displacement vector of the current photon
519 Tensor<1, 3> photon_displacement_vector(
520 {photon_properties[3], photon_properties[4], photon_properties[5]});
521
522 const Point<dim> current_photon_location =
523 current_photon->get_location();
524
525 // Loop over the neighboring cells of the main cell. This includes
526 // the main cell itself.
527 auto &cell_neighbor_list = *cell_neighbor_list_iterator;
528
529 auto starting_iterator = cell_neighbor_list.begin();
530
531 // The intersection between the photon and the particles in the main
532 // cell is checked when we are looping on the local cells, thus we
533 // skip the main cell when we are looping on the ghost cells.
534 if constexpr (std::is_same_v<NeighborListType, ghost_neighbor_list>)
535 ++starting_iterator;
536 for (auto current_neighboring_cell = starting_iterator;
537 current_neighboring_cell != cell_neighbor_list.end();
538 ++current_neighboring_cell)
539 {
540 // Particle iterators in the current neighboring cell
541 typename Particles::ParticleHandler<dim>::particle_iterator_range
542 particle_in_neighboring_cell =
543 particle_handler.particles_in_cell(*current_neighboring_cell);
544
545 // This vector will be reused for every line-sphere
546 // intersection search. There is maximum 2 intersection points
547 // between a line and a sphere.
548 std::vector<Point<dim>> current_intersection_points;
549 current_intersection_points.reserve(2);
550
551 // Loop of the particles in the current neighboring cells
552 for (auto current_particle = particle_in_neighboring_cell.begin();
553 current_particle != particle_in_neighboring_cell.end();
554 ++current_particle)
555 {
556 // Check if the current photon intersects the current
557 // particle
558 const Point<dim> particle_position =
559 current_particle->get_location();
560 const double particle_diameter =
561 current_particle
562 ->get_properties()[DEMProperties::PropertiesIndex::dp];
563
564 current_intersection_points =
566 photon_insertion_point,
567 photon_displacement_vector,
568 particle_position,
569 particle_diameter);
570
571 // If the size of the vector is 0, there's no intersection
572 // point, thus we go to the next particle.
573 if (current_intersection_points.size() == 0)
574 continue;
575
576 // Otherwise, there is at least one intersection point.
577 // Initializing the needed variables.
578 double new_distance;
579 Point<dim> new_closest_point;
580
581 // If the size of the vector is 1, we have one
582 // intersection point.
583 if (current_intersection_points.size() == 1)
584 {
585 new_distance = (photon_insertion_point -
586 current_intersection_points[0])
587 .norm();
588 new_closest_point = current_intersection_points[0];
589 }
590 // If the size is equal to 2, we need to find which one
591 // between the two new intersection points is the closest
592 // to the photon insertion point.
593 else
594 {
595 const double distance_0 = (photon_insertion_point -
596 current_intersection_points[0])
597 .norm();
598 const double distance_1 = (photon_insertion_point -
599 current_intersection_points[1])
600 .norm();
601
602 if (distance_0 < distance_1)
603 {
604 new_distance = distance_0;
605 new_closest_point = current_intersection_points[0];
606 }
607 else
608 {
609 new_distance = distance_1;
610 new_closest_point = current_intersection_points[1];
611 }
612 }
613 // We need to add the intersection point in the
614 // photon_insertion_point map. We first need to check
615 // if an intersection point already exist in the map
616 // for that given photon.
617 if (photon_intersection_points_map.find(
618 current_photon->get_id()) ==
619 photon_intersection_points_map.end())
620 {
621 // If it doesn't exist, we just add the new one.
622 photon_intersection_points_map[current_photon->get_id()] =
623 {new_distance, new_closest_point, current_photon};
624 }
625 else
626 {
627 // If it does exist, we need to check which
628 // intersection point is the closest to the
629 // current photon insertion point. We replace the
630 // value only if the new one is closer.
631 const double old_distance = std::get<0>(
632 photon_intersection_points_map[current_photon
633 ->get_id()]);
634
635 if (new_distance < old_distance)
636 {
637 // if the new distance is smaller, we replace the
638 // old one in the map. Otherwise, we do nothing.
639 photon_intersection_points_map[current_photon
640 ->get_id()] = {
641 new_distance, new_closest_point, current_photon};
642 }
643 }
644 }
645 }
646 // Even if we are removing photon at the end on this pseudo-time
647 // step, we move the photons here since we are looping on each of
648 // them in this loop. This way, we don't need to loop on each of
649 // them at the end.
650 if constexpr (std::is_same_v<NeighborListType, local_neighbor_list>)
651 {
652 const Point<dim> new_photon_location =
653 current_photon_location +
654 photon_displacement_vector * displacement_distance;
655 current_photon->set_location(new_photon_location);
656 }
657 }
658 }
659}
660
661
662template <int dim>
663void
665{
666 // Set up the parameters
668
669 // Reading mesh
670 pcout << "Reading triangulation" << std::endl;
671
674 parameters.mesh,
675 parameters.manifolds_parameters,
676 action_manager->check_restart_simulation(),
677 dem_parameters.boundary_conditions.periodic_boundaries);
678
679 pcout << std::endl << "Finished reading triangulation" << std::endl;
680
681 displacement_distance = 0.5 * GridTools::minimal_cell_diameter(triangulation);
682
683 // Set particle insertion object
685
686 // Insert photon and particles
688
689 // Particles won't move, thus we can sort them.
690 particle_handler.sort_particles_into_subdomains_and_cells();
691 // Exchange ghost particles
692 particle_handler.exchange_ghost_particles(true);
693
694 // Every intersection point from the beginning of the simulation.
695 std::vector<Point<dim>> total_intersection_points;
696 total_intersection_points.reserve(photon_handler.n_global_particles());
697
698 // Map :
699 // <photon_iterator, (distance, intersection point<dim>, iterator to remove)>
700 ankerl::unordered_dense::map<
701 types::particle_index,
702 std::tuple<double, Point<dim>, Particles::ParticleIterator<dim>>>
703 photon_intersection_points_map;
704
705 photon_intersection_points_map.reserve(
706 photon_handler.n_locally_owned_particles());
707
708 // Update cell neighbors
712
713 // Particle don't move, thus we sort them at the end of a load balance.
714 // Photons are being sorted every pseudo time step, thus no need to sort them
715 // here.
716 particle_handler.sort_particles_into_subdomains_and_cells();
717
718 // Exchange ghost particles
719 particle_handler.exchange_ghost_particles(true);
720
721 while (simulation_control->integrate())
722 {
723 simulation_control->print_progression(pcout);
724
725 // Load balancing (if needed)
726 load_balance();
727 // Since last pseudo time step, there is a high chance that the photons
728 // have changed cell considering the size of their displacement relative
729 // to the cell size. Thus, we sort them.
730
731 photon_handler.sort_particles_into_subdomains_and_cells();
732
734 photon_intersection_points_map);
735
737 photon_intersection_points_map);
738
739 // Remove all the photon that have found their intersection. In other
740 // words, every photon that is present in the map. We also store the
741 // intersection points in the appropriate vector.
742 std::vector<Particles::ParticleIterator<dim>> photon_iterators_to_remove;
743 photon_iterators_to_remove.reserve(photon_intersection_points_map.size());
744
745 for (auto it = photon_intersection_points_map.begin();
746 it != photon_intersection_points_map.end();
747 ++it)
748 {
749 auto photon_tuple = it->second;
750 total_intersection_points.push_back(std::get<1>(photon_tuple));
751 photon_iterators_to_remove.push_back(std::get<2>(photon_tuple));
752 }
753
754 // Removes the photon and clear the containers.
755 photon_handler.remove_particles(photon_iterators_to_remove);
756 photon_iterators_to_remove.clear();
757 photon_intersection_points_map.clear();
758
759 action_manager->reset_triggers();
760 }
761
762 // We don't want to write an output file if we are in test mode.
763 if (!parameters.test.enabled)
764 write_output_results(total_intersection_points);
765
766 finish_simulation(total_intersection_points);
767}
768template class RayTracingSolver<3>;
Mechanism that disables contacts computation through mobility status of cells based on granular tempe...
static DEMActionManager * get_action_manager()
Getter of the unique instance of the DEMActionManager.
Handles all the parameters declared in the parameter handler file.
Parameters controlling particle insertion in DEM simulations.
InsertionMethod
Method used to insert particles.
Numerical model parameters for DEM simulations.
Handles all the parameters declared in the parameter handler file.
Solver that uses ray tracing to find intersection points between photons and particles.
Definition ray_tracing.h:25
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.
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.
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.
void create_random_number_container(std::vector< double > &random_container, const unsigned int number_of_elements, const double maximum_range, const unsigned int prn_seed)
Creates a vector of random doubles between 0 and a maximum value using a pseudo random seed.
Definition utilities.h:1302
void create_output_folder(const std::string &dirname)
Creates the simulation output folder.
Definition utilities.cc:401
void announce_string(const ConditionalOStream &pcout, const std::string &expression, const char delimiter='-')
Prints a string and then adds a line above and below made with dashes containing as many dashes as th...
Definition utilities.h:500
void find_cell_neighbors(const parallel::distributed::Triangulation< dim > &triangulation, typename DEM::dem_data_structures< dim >::cells_neighbor_list &cells_local_neighbor_list, typename DEM::dem_data_structures< dim >::cells_neighbor_list &cells_ghost_neighbor_list)
Finds the neighbor list (without repetition) of all the active cells in the triangulation....
void read_mesh_and_manifolds(parallel::DistributedTriangulationBase< dim, spacedim > &triangulation, const Parameters::Mesh< dim, spacedim > &mesh_parameters, const Parameters::Manifolds &manifolds_parameters, bool restart, const Parameters::PeriodicBoundaries &periodic_boundaries)
Completely sets up a mesh and its manifolds.
Definition grids.cc:447
std::vector< Point< dim > > find_line_sphere_intersection(const Point< dim > &line_start, const Tensor< 1, dim > &line_direction, const Point< dim > &sphere_center, const double &sphere_diameter)
Calculates the intersection points between a line and a sphere. The full calculation is taken from Ge...