chombo-discharge
Loading...
Searching...
No Matches
CD_GenericParticleImplem.H
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2021-2026 SINTEF Energy Research
3 *
4 * SPDX-License-Identifier: GPL-3.0-or-later
5 */
6
13#ifndef CD_GENERICPARTICLEIMPLEM_H
14#define CD_GENERICPARTICLEIMPLEM_H
15
16// Our includes
17#include <CD_GenericParticle.H>
18#include <CD_NamespaceHeader.H>
19
20template <size_t M, size_t N>
21inline GenericParticle<M, N>::GenericParticle() : m_particleID(-1), m_rankID(-1), m_position(RealVect::Zero)
22{
23 for (auto& s : m_scalars) {
24 s = 0.0;
25 }
26
27 for (auto& v : m_vectors) {
29 }
30}
31
32template <size_t M, size_t N>
34{
35 this->m_position = a_other.m_position;
36 this->m_scalars = a_other.m_scalars;
37 this->m_vectors = a_other.m_vectors;
38}
39
40template <size_t M, size_t N>
42
43template <size_t M, size_t N>
44inline RealVect&
46{
47 return m_position;
48}
49
50template <size_t M, size_t N>
51inline const RealVect&
53{
54 return m_position;
55}
56
57template <size_t M, size_t N>
58inline const int32_t&
60{
61 return m_particleID;
62}
63
64template <size_t M, size_t N>
65inline int32_t&
67{
68 return m_particleID;
69}
70
71template <size_t M, size_t N>
72inline const int32_t&
74{
75 return m_rankID;
76}
77
78template <size_t M, size_t N>
79inline int32_t&
81{
82 return m_rankID;
83}
84
85template <size_t M, size_t N>
86inline const std::array<Real, M>&
89 return m_scalars;
90}
91
92template <size_t M, size_t N>
95{
96 return m_scalars;
97}
98
99template <size_t M, size_t N>
102{
103 return m_vectors;
104}
105
106template <size_t M, size_t N>
109{
110 return m_vectors;
111}
112
113template <size_t M, size_t N>
114template <size_t K>
115inline Real&
117{
118 return std::get<K>(m_scalars);
119}
120
121template <size_t M, size_t N>
122template <size_t K>
123inline const Real&
125{
126 return std::get<K>(m_scalars);
127}
129template <size_t M, size_t N>
130template <size_t K>
131inline RealVect&
133{
134 return std::get<K>(m_vectors);
136
137template <size_t M, size_t N>
138template <size_t K>
139inline const RealVect&
141{
142 return std::get<K>(m_vectors);
143}
144
145template <size_t M, size_t N>
146inline bool
148{
149 return (this->m_position == a_p.m_position && this->m_scalars == a_p.m_scalars && this->m_vectors == a_p.m_vectors);
150}
151
152template <size_t M, size_t N>
153inline bool
155{
156 return !(*this == a_p);
157}
158
159template <size_t M, size_t N>
160inline bool
162{
163 const RealVect& x = m_position;
164 const RealVect& y = a_other.m_position;
165
166 if (x[0] < y[0]) {
167 return true;
168 }
169#if CH_SPACEDIM > 1
170 if (x[0] > y[0]) {
171 return false;
172 }
173 if (x[1] < y[1]) {
174 return true;
175 }
176#endif
177#if CH_SPACEDIM > 2
178 if (x[1] > y[1]) {
179 return false;
180 }
181 if (x[2] < y[2]) {
182 return true;
184#endif
185
186 return false;
187}
188
189template <size_t M, size_t N>
190inline int
192{
193 // Size is the sum of the particle ID, rank ID, position, plus M Reals and N RealVects
194 int size = 0;
195
196 size += sizeof(int32_t); // Particle ID
197 size += sizeof(int32_t); // Rank ID
198 size += SpaceDim * sizeof(Real); // Position
199 size += M * sizeof(Real); // m_scalars
200 size += N * SpaceDim * sizeof(Real); // m_vectors
201
202 return size;
204
205template <size_t M, size_t N>
206inline void
208{
209 auto* p = static_cast<uint8_t*>(a_buffer);
210
211 detail::pushParticleProperty(p, m_particleID);
212 detail::pushParticleProperty(p, m_rankID);
213
214 detail::pushParticleProperty(p, m_position[0]);
215 detail::pushParticleProperty(p, m_position[1]);
216#if CH_SPACEDIM == 3
217 detail::pushParticleProperty(p, m_position[2]);
218#endif
219
220 for (size_t i = 0; i < M; i++) {
221 detail::pushParticleProperty(p, m_scalars[i]);
222 }
223
224 for (size_t i = 0; i < N; i++) {
225 detail::pushParticleProperty(p, m_vectors[i][0]);
226 detail::pushParticleProperty(p, m_vectors[i][1]);
227#if CH_SPACEDIM == 3
228 detail::pushParticleProperty(p, m_vectors[i][2]);
229#endif
230 }
231}
232
233template <size_t M, size_t N>
234inline void
237 const auto* p = static_cast<const uint8_t*>(a_buffer);
238
239 detail::pullParticleProperty(p, m_particleID);
240 detail::pullParticleProperty(p, m_rankID);
241
242 detail::pullParticleProperty(p, m_position[0]);
243 detail::pullParticleProperty(p, m_position[1]);
244#if CH_SPACEDIM == 3
245 detail::pullParticleProperty(p, m_position[2]);
246#endif
247
248 for (size_t i = 0; i < M; i++) {
249 detail::pullParticleProperty(p, m_scalars[i]);
250 }
252 for (size_t i = 0; i < N; i++) {
253 detail::pullParticleProperty(p, m_vectors[i][0]);
254 detail::pullParticleProperty(p, m_vectors[i][1]);
255#if CH_SPACEDIM == 3
256 detail::pullParticleProperty(p, m_vectors[i][2]);
257#endif
258 }
259}
261template <size_t M, size_t N>
262inline int
264{
265 int size = 0;
266
267 size += SpaceDim * sizeof(Real); // m_position
268 size += M * sizeof(Real); // m_scalars
269 size += N * SpaceDim * sizeof(Real); // m_vectors
270
271 return size;
272}
273
274template <size_t M, size_t N>
275inline void
277{
278 auto* p = static_cast<uint8_t*>(a_buffer);
279
280 detail::pushParticleProperty(p, m_position[0]);
281 detail::pushParticleProperty(p, m_position[1]);
282#if CH_SPACEDIM == 3
283 detail::pushParticleProperty(p, m_position[2]);
284#endif
285
286 for (size_t i = 0; i < M; i++) {
287 detail::pushParticleProperty(p, m_scalars[i]);
288 }
289
290 for (size_t i = 0; i < N; i++) {
291 detail::pushParticleProperty(p, m_vectors[i][0]);
292 detail::pushParticleProperty(p, m_vectors[i][1]);
293#if CH_SPACEDIM == 3
294 detail::pushParticleProperty(p, m_vectors[i][2]);
295#endif
296 }
297}
298
299template <size_t M, size_t N>
300inline void
302{
303 const auto* p = static_cast<const uint8_t*>(a_buffer);
304
305 detail::pullParticleProperty(p, m_position[0]);
306 detail::pullParticleProperty(p, m_position[1]);
307#if CH_SPACEDIM == 3
308 detail::pullParticleProperty(p, m_position[2]);
309#endif
310
311 for (size_t i = 0; i < M; i++) {
312 detail::pullParticleProperty(p, m_scalars[i]);
313 }
314
315 for (size_t i = 0; i < N; i++) {
316 detail::pullParticleProperty(p, m_vectors[i][0]);
317 detail::pullParticleProperty(p, m_vectors[i][1]);
318#if CH_SPACEDIM == 3
319 detail::pullParticleProperty(p, m_vectors[i][2]);
320#endif
321 }
322}
323
324template <size_t M, size_t N>
327{
328 ostr << "GenericParticle : \n";
329
330 // Print position.
331 ostr << "\tPosition = " << p.position() << "\n";
332
333 return ostr;
334}
335
336#include <CD_NamespaceFooter.H>
337
338#endif
std::ostream & operator<<(std::ostream &ostr, const GenericParticle< M, N > &p)
Particle printing function.
Definition CD_GenericParticleImplem.H:326
Declaration of a generic particle class.
virtual void linearOut(void *a_buffer) const
Write a linear binary representation of the internal data. Assumes that sufficient memory for the buf...
Definition CD_GenericParticleImplem.H:207
virtual ~GenericParticle()
Destructor (deallocates runtime memory storage)
const int32_t & particleID() const noexcept
Get the particle ID.
Definition CD_GenericParticleImplem.H:59
virtual int H5size() const
Function that is used when writing particles to HDF5.
Definition CD_GenericParticleImplem.H:263
RealVect & position()
Get the particle position.
Definition CD_GenericParticleImplem.H:45
bool operator!=(const GenericParticle< M, N > &a_p) const
Comparison operator with other particle.
Definition CD_GenericParticleImplem.H:154
Real & real()
Get one of the scalars.
Definition CD_GenericParticleImplem.H:116
const std::array< Real, M > & getReals() const noexcept
Get the M scalars.
Definition CD_GenericParticleImplem.H:87
virtual int size() const
Returns the size, in number of bytes, of a flat representation of the data in this object.
Definition CD_GenericParticleImplem.H:191
virtual void H5linearOut(void *a_buffer) const
Linearize the Real components onto a buffer workable by HDF5.
Definition CD_GenericParticleImplem.H:276
bool operator==(const GenericParticle< M, N > &a_p) const
Comparison operator with other particle.
Definition CD_GenericParticleImplem.H:147
RealVect & vect()
Get one of the RealVects.
Definition CD_GenericParticleImplem.H:132
const int32_t & rankID() const noexcept
Get the MPI rank ID.
Definition CD_GenericParticleImplem.H:73
virtual void linearIn(const void *a_buffer)
Read a linear binary representation of the internal data. Assumes that the buffer has the correct dat...
Definition CD_GenericParticleImplem.H:235
virtual void H5linearIn(const void *a_buffer)
Delinearize the buffer onto the real components in the particle class.
Definition CD_GenericParticleImplem.H:301
bool operator<(const GenericParticle< M, N > &a_other) const noexcept
Particle comparison operator. Returns lexicographical ordering.
Definition CD_GenericParticleImplem.H:161
GenericParticle()
Default constructor – initializes everything to zero.
Definition CD_GenericParticleImplem.H:21
std::array< Real, M > m_scalars
Scalar storage array.
Definition CD_GenericParticle.H:299
std::array< RealVect, N > m_vectors
vector storage array
Definition CD_GenericParticle.H:304
const std::array< RealVect, N > & getVects() const noexcept
Get the N vectors.
Definition CD_GenericParticleImplem.H:101
Base class for a tracer particle solver. This solver can advance particles in a pre-defined velocity ...
Definition CD_TracerParticleSolver.H:38
TracerParticleSolver()
Default constructor.
Definition CD_TracerParticleSolverImplem.H:26