chombo-discharge
Loading...
Searching...
No Matches
CD_GenericParticle.H
Go to the documentation of this file.
1/* chombo-discharge
2 * Copyright © 2022 SINTEF Energy Research.
3 * Please refer to Copyright.txt and LICENSE in the chombo-discharge root directory.
4 */
5
12#ifndef CD_GenericParticle_H
13#define CD_GenericParticle_H
14
15// Std includes
16#include <string>
17#include <typeinfo>
18#include <cstdio>
19#include <cmath>
20#include <array>
21#include <cstdint>
22
23// Chombo includes
24#include <RealVect.H>
25
26// Our includes
27#include <CD_NamespaceHeader.H>
28
29namespace detail {
36 template <class T>
37 inline void
39 {
40 static_assert(std::is_trivially_copyable<T>::value,
41 "detail::pushParticleProperty expects trivially-copyable fields");
42
43 std::memcpy(p, &a_x, sizeof(T));
44
45 p += sizeof(T);
46 };
47
54 template <class T>
55 inline void
57 {
58 static_assert(std::is_trivially_copyable<T>::value,
59 "detail::pushParticleProperty expects trivially-copyable fields");
60
61 std::memcpy(&a_x, p, sizeof(T));
62
63 p += sizeof(T);
64 };
65} // namespace detail
66
74template <size_t M, size_t N>
76{
77public:
81 inline GenericParticle();
82
88
92 inline virtual ~GenericParticle();
93
97 inline const int32_t&
98 particleID() const noexcept;
99
103 inline int32_t&
104 particleID() noexcept;
105
109 inline const int32_t&
110 rankID() const noexcept;
111
115 inline int32_t&
116 rankID() noexcept;
117
122 inline RealVect&
123 position();
124
129 inline const RealVect&
130 position() const;
131
136 inline const std::array<Real, M>&
137 getReals() const noexcept;
138
143 inline std::array<Real, M>&
144 getReals() noexcept;
145
150 inline const std::array<RealVect, N>&
151 getVects() const noexcept;
152
158 getVects() noexcept;
159
166 template <size_t K>
167 inline Real&
168 real();
169
176 template <size_t K>
177 inline const Real&
178 real() const;
179
186 template <size_t K>
187 inline RealVect&
188 vect();
189
196 template <size_t K>
197 inline const RealVect&
198 vect() const;
199
205 inline bool
207
213 inline bool
215
219 inline bool
220 operator<(const GenericParticle<M, N>& a_other) const noexcept;
221
225 inline virtual int
226 size() const;
227
233 inline virtual void
234 linearOut(void* const a_buffer) const;
235
240 inline virtual void
241 linearIn(const void* const a_buffer);
242
248 inline virtual int
249 H5size() const;
250
257 inline virtual void
258 H5linearOut(void* const a_buffer) const;
259
266 inline virtual void
267 H5linearIn(const void* const a_buffer);
268
269protected:
274
279
284
289
294};
295
301template <size_t M, size_t N>
302inline std::ostream&
304
305#include <CD_NamespaceFooter.H>
306
308
309#endif
Implementation of CD_GenericParticle.H.
void pullParticleProperty(const uint8_t *&p, T &a_x)
Helper function for linearizing a buffer onto a particle property. @detail This copies from the buffe...
Definition CD_GenericParticle.H:56
std::ostream & operator<<(std::ostream &ostr, const GenericParticle< M, N > &p)
Particle printing function.
Definition CD_GenericParticleImplem.H:330
void pushParticleProperty(uint8_t *&p, const T &a_x)
Helper function for linearizing a particle onto a buffer. @detail This copies T into the buffer p and...
Definition CD_GenericParticle.H:38
A generic particle class, holding the position and a specified number of real and vector values.
Definition CD_GenericParticle.H:76
virtual ~GenericParticle()
Destructor (deallocates runtime memory storage)
Definition CD_GenericParticleImplem.H:44
virtual void linearOut(void *const a_buffer) const
Write a linear binary representation of the internal data. Assumes that sufficient memory for the buf...
Definition CD_GenericParticleImplem.H:211
const int32_t & particleID() const noexcept
Get the particle ID.
Definition CD_GenericParticleImplem.H:63
virtual int H5size() const
Function that is used when writing particles to HDF5.
Definition CD_GenericParticleImplem.H:267
int32_t m_rankID
MPI rank owning this particle.
Definition CD_GenericParticle.H:278
RealVect & position()
Get the particle position.
Definition CD_GenericParticleImplem.H:49
Real & real()
Get one of the scalars.
Definition CD_GenericParticleImplem.H:120
virtual void linearIn(const void *const a_buffer)
Read a linear binary representation of the internal data. Assumes that the buffer has the correct dat...
Definition CD_GenericParticleImplem.H:239
const std::array< Real, M > & getReals() const noexcept
Get the M scalars.
Definition CD_GenericParticleImplem.H:91
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:195
RealVect & vect()
Get one of the RealVects.
Definition CD_GenericParticleImplem.H:136
virtual void H5linearOut(void *const a_buffer) const
Linearize the Real components onto a buffer workable by HDF5.
Definition CD_GenericParticleImplem.H:280
const int32_t & rankID() const noexcept
Get the MPI rank ID.
Definition CD_GenericParticleImplem.H:77
int32_t m_particleID
Particle ID.
Definition CD_GenericParticle.H:273
virtual void H5linearIn(const void *const a_buffer)
Delinearize the buffer onto the real components in the particle class.
Definition CD_GenericParticleImplem.H:305
bool operator==(const GenericParticle< M, N > &a_other) const
Comparison operator with other particle.
Definition CD_GenericParticleImplem.H:151
bool operator!=(const GenericParticle< M, N > &a_other) const
Comparison operator with other particle.
Definition CD_GenericParticleImplem.H:158
bool operator<(const GenericParticle< M, N > &a_other) const noexcept
Particle comparison operator. Returns lexicographical ordering.
Definition CD_GenericParticleImplem.H:165
RealVect m_position
Particle position.
Definition CD_GenericParticle.H:283
GenericParticle()
Default constructor – initializes everything to zero.
Definition CD_GenericParticleImplem.H:20
std::array< Real, M > m_scalars
Scalar storage array.
Definition CD_GenericParticle.H:288
std::array< RealVect, N > m_vectors
vector storage array
Definition CD_GenericParticle.H:293
const std::array< RealVect, N > & getVects() const noexcept
Get the N vectors.
Definition CD_GenericParticleImplem.H:105
Base class for a tracer particle solver. This solver can advance particles in a pre-defined velocity ...
Definition CD_TracerParticleSolver.H:37
TracerParticleSolver()
Default constructor.
Definition CD_TracerParticleSolverImplem.H:25