Lethe Open-Source Library version 1.2.0
Developer Guide
Loading...
Searching...
No Matches
log_collision_data.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_collision_log_data_h
5#define lethe_collision_log_data_h
6
8
10
11#include <deal.II/base/tensor.h>
12#include <deal.II/base/types.h>
13
14using namespace dealii;
15
16/**
17 * @brief Struct to store information about a particle-wall collision moment.
18 */
19template <int dim>
21{
22 unsigned int particle_id;
23 double dp;
24 double mass;
25 Tensor<1, dim> velocity;
26 Tensor<1, dim> omega;
27 double time;
28 types::boundary_id boundary_id;
29};
30
31/**
32 * @brief Struct storing a full collision event (start and end).
33 */
34template <int dim>
41
42/**
43 * @brief Class managing the ongoing collisions.
44 */
45template <int dim>
47{
48public:
49 /**
50 * @brief Start logging a collision for a particle. If the particle is already present in the log, it does nothing.
51 *
52 * @param[in] log The collision log to be added for the particle.
53 */
54 void
56 {
57 ongoing_collisions[std::make_pair(log.particle_id, log.boundary_id)] = log;
58 }
59
60 /**
61 * @brief End a collision for a particle. Retrieve the start log and remove the particle from the ongoing collisions.
62 *
63 * @param[in] particle_id The id of the particle that ended the collision.
64 * @param[out] start_log The log of the collision start to be filled.
65 */
66 void
67 end_collision(const unsigned int particle_id,
68 const types::boundary_id boundary_id,
69 collision_log<dim> &start_log)
70 {
71 auto it = ongoing_collisions.find(std::make_pair(particle_id, boundary_id));
72 start_log = it->second;
73 ongoing_collisions.erase(it);
74 }
75
76 /**
77 * @brief Check whether the particle is currently in a collision.
78 *
79 * @param[in] particle_id The id of the particle to check.
80 * @return True if the particle is in a collision, false otherwise.
81 */
82 bool
83 is_in_collision(const unsigned int particle_id,
84 const types::boundary_id boundary_id) const
85 {
86 return ongoing_collisions.find(std::make_pair(particle_id, boundary_id)) !=
88 }
89
90private:
91 // Map to store ongoing collisions with particle id as key and collision log
92 // as value
93 std::map<std::pair<unsigned int, types::boundary_id>, collision_log<dim>>
95};
96
97/**
98 * @brief Class that stores all the completed collision events.
99 */
100template <int dim>
102{
103public:
104 /**
105 * @brief Add a completed event to the log.
106 *
107 * @param[in] event Collision event to be added.
108 */
109 void
111 {
112 events.push_back(event);
113 }
114
115 /**
116 * @brief Retrieve the list of all completed collision events.
117 *
118 * @return List of completed collision events.
119 */
120 const std::list<collision_event<dim>> &
122 {
123 return events;
124 }
125
126private:
127 // List to store completed collision events
128 std::list<collision_event<dim>> events;
129};
130
131/**
132 * @brief Get the 3d location of the particle.
133 *
134 * @param[in] particle The particle to get the location from.
135 * @return 3d location of particle.
136 */
137template <int dim>
138inline Point<3>
139get_location(const Particles::ParticleIterator<dim> &particle)
140{
141 if constexpr (dim == 3)
142 return particle->get_location();
143
144 if constexpr (dim == 2)
145 return point_nd_to_3d(particle->get_location());
146}
147
148/**
149 * @brief This function is used to find the projection of vector_a on
150 * vector_b
151 * @param[in] vector_a A vector which is going to be projected on vector_b
152 * @param[in] vector_b The projection vector of vector_a
153 * @return The projection of vector_a on vector_b
154 */
155inline Tensor<1, 3>
156find_projection(const Tensor<1, 3> &vector_a, const Tensor<1, 3> &vector_b)
157{
158 Tensor<1, 3> vector_c;
159 vector_c = ((vector_a * vector_b) / (vector_b.norm_square())) * vector_b;
160
161 return vector_c;
162}
163
164/**
165 * @brief Logs the particle-wall contact statistics.
166 *
167 * @param[in] parameters Parameters
168 * @param[in] particle_wall_pairs_in_contact Required information for the
169 * calculation of the particle-wall contact.
170 * @param[in] current_time Current simulation time.
171 * @param[out] ongoing_collision_log Ongoing collision log.
172 * @param[out] collision_event_log Collision event log.
173 */
174template <int dim, typename PropertiesIndex>
175void
177 const DEMSolverParameters<dim> &parameters,
179 &particle_wall_pairs_in_contact,
180 const double current_time,
181 OngoingCollisionLog<dim> &ongoing_collision_log,
182 CompletedCollisionLog<dim> &collision_event_log);
183
184/**
185 * @brief Writes the collision statistics to a file.
186 * @param[in] collision_event_log Completed collision event log.
187 * @param[in] parameters Parameters
188 * @param[in] mpi_communicator MPI communicator
189 */
190template <int dim>
191void
193 const CompletedCollisionLog<dim> &collision_event_log,
194 const MPI_Comm &mpi_communicator);
195
196#endif // lethe_collision_log_data_h
Class that stores all the completed collision events.
void add_event(const collision_event< dim > &event)
Add a completed event to the log.
std::list< collision_event< dim > > events
const std::list< collision_event< dim > > & get_events() const
Retrieve the list of all completed collision events.
Handles all the parameters declared in the parameter handler file.
Class managing the ongoing collisions.
bool is_in_collision(const unsigned int particle_id, const types::boundary_id boundary_id) const
Check whether the particle is currently in a collision.
std::map< std::pair< unsigned int, types::boundary_id >, collision_log< dim > > ongoing_collisions
void end_collision(const unsigned int particle_id, const types::boundary_id boundary_id, collision_log< dim > &start_log)
End a collision for a particle. Retrieve the start log and remove the particle from the ongoing colli...
void start_collision(const collision_log< dim > &log)
Start logging a collision for a particle. If the particle is already present in the log,...
void log_collision_data(const DEMSolverParameters< dim > &parameters, typename DEM::dem_data_structures< dim >::particle_wall_in_contact &particle_wall_pairs_in_contact, const double current_time, OngoingCollisionLog< dim > &ongoing_collision_log, CompletedCollisionLog< dim > &collision_event_log)
Logs the particle-wall contact statistics.
void write_collision_stats(const DEMSolverParameters< dim > &parameters, const CompletedCollisionLog< dim > &collision_event_log, const MPI_Comm &mpi_communicator)
Writes the collision statistics to a file.
Tensor< 1, 3 > find_projection(const Tensor< 1, 3 > &vector_a, const Tensor< 1, 3 > &vector_b)
This function is used to find the projection of vector_a on vector_b.
Point< 3 > get_location(const Particles::ParticleIterator< dim > &particle)
Get the 3d location of the particle.
ankerl::unordered_dense::map< types::particle_index, ankerl::unordered_dense::map< global_face_id, particle_wall_contact_info< dim > > > particle_wall_in_contact
Struct storing a full collision event (start and end).
unsigned int particle_id
collision_log< dim > start_log
collision_log< dim > end_log
Struct to store information about a particle-wall collision moment.
types::boundary_id boundary_id
Tensor< 1, dim > omega
unsigned int particle_id
Tensor< 1, dim > velocity
Point< 3 > point_nd_to_3d(const Point< dim > &point)