Lethe Open-Source Library version 1.2.0
Developer Guide
Loading...
Searching...
No Matches
particle_handler_conversion.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 particle_handler_conversion_h
5#define particle_handler_conversion_h
6
8
9#include <deal.II/grid/filtered_iterator.h>
10#include <deal.II/grid/grid_tools.h>
11
12#include <deal.II/particles/particle_handler.h>
13#include <deal.II/particles/particle_iterator.h>
14
15using namespace dealii;
16
17/** @brief Converts an input particle handler with a given set of input properties
18 * into an output particle handler with a different set of output properties.
19 * This is used, notably, to convert DEM simulation particle_handlers into
20 * CFD-DEM particle_handlers.
21 *
22 * @tparam dim the number of dimensions
23 * @tparam input the properties index used for the ph_in
24 * @tparam output the properties index used for the ph_out
25 *
26 * @param[in] triangulation The triangulation on which the ph_out is stored
27 * @param[in] ph_in The input particle_handler that has properties identified by
28 * the input.
29 * @param[out] ph_out The output particle_handler that has properties identified
30 *by the output.
31 */
32template <int dim, typename input, typename output>
33void
35 const parallel::distributed::Triangulation<dim> &triangulation,
36 const Particles::ParticleHandler<dim> &ph_in,
37 Particles::ParticleHandler<dim> &ph_out)
38{
39 // Pre-allocate the vector of particle properties and location of ph_out
40 std::vector<std::vector<double>> ph_out_properties;
41 std::vector<Point<dim>> ph_out_points;
42 ph_out_properties.reserve(ph_in.n_locally_owned_particles());
43 ph_out_points.reserve(ph_in.n_locally_owned_particles());
44
45 // We loop through all particles of the input particle handler and gather the
46 // properties and locations
47 for (auto particle = ph_in.begin(); particle != ph_in.end(); ++particle)
48 {
49 // Get and store particle location
50 auto particle_location = particle->get_location();
51 ph_out_points.emplace_back(particle_location);
52
53 // Get the particle properties
54 auto particle_properties = particle->get_properties();
55 // Give a default value of zero to all properties. This will account for
56 // increasing number of properties
57 std::vector<double> ph_out_particle_properties(output::n_properties, 0.);
58 ph_out_particle_properties[output::type] =
59 particle_properties[input::type];
60 ph_out_particle_properties[output::dp] = particle_properties[input::dp];
61
62 ph_out_particle_properties[output::v_x] = particle_properties[input::v_x];
63 ph_out_particle_properties[output::v_y] = particle_properties[input::v_y];
64 ph_out_particle_properties[output::v_z] = particle_properties[input::v_z];
65
66 ph_out_particle_properties[output::omega_x] =
67 particle_properties[input::omega_x];
68 ph_out_particle_properties[output::omega_y] =
69 particle_properties[input::omega_y];
70 ph_out_particle_properties[output::omega_z] =
71 particle_properties[input::omega_z];
72
73 ph_out_particle_properties[output::mass] =
74 particle_properties[input::mass];
75
76 // The thermal properties are only carried over when both particle
77 // handlers are those of a multiphysics solver. Going from a multiphysics
78 // to a non-multiphysics solver drops them, and the opposite leaves them
79 // at their default value of zero.
82 {
83 ph_out_particle_properties[output::T] = particle_properties[input::T];
84 ph_out_particle_properties[output::specific_heat] =
85 particle_properties[input::specific_heat];
86 }
87
88 ph_out_properties.emplace_back(ph_out_particle_properties);
89 }
90
91
92 // We use the insert global functionalities to insert the particles in the
93 // output particle handler. This is not optimal since it will recalculate the
94 // reference location of every particle, but since this operation is only done
95 // once per simulation, this cost should be negligible.
96
97 // Calculate global bounding box for global insertion
98 const auto my_bounding_box = GridTools::compute_mesh_predicate_bounding_box(
99 triangulation, IteratorFilters::LocallyOwnedCell());
100 const auto global_bounding_boxes =
101 Utilities::MPI::all_gather(triangulation.get_mpi_communicator(),
102 my_bounding_box);
103
104 // Do the global insertion
105 ph_out.insert_global_particles(ph_out_points,
106 global_bounding_boxes,
107 ph_out_properties);
108}
109
110
111#endif
DEM particle property definitions and output name management.
constexpr bool has_thermal_properties
Whether a properties index set carries thermal properties.
void convert_particle_handler(const parallel::distributed::Triangulation< dim > &triangulation, const Particles::ParticleHandler< dim > &ph_in, Particles::ParticleHandler< dim > &ph_out)
Converts an input particle handler with a given set of input properties into an output particle handl...