chombo-discharge
Loading...
Searching...
No Matches
CD_GenericParticleImplem.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_GenericParticleImplem_H
13#define CD_GenericParticleImplem_H
14
15// Our includes
16#include <CD_GenericParticle.H>
17#include <CD_NamespaceHeader.H>
18
19template <size_t M, size_t N>
21{
22 m_particleID = -1;
23 m_rankID = -1;
24 m_position = RealVect::Zero;
25
26 for (auto& s : m_scalars) {
27 s = 0.0;
28 }
29
30 for (auto& v : m_vectors) {
32 }
33}
34
35template <size_t M, size_t N>
37{
38 this->m_position = a_other.m_position;
39 this->m_scalars = a_other.m_scalars;
40 this->m_vectors = a_other.m_vectors;
41}
42
43template <size_t M, size_t N>
46
47template <size_t M, size_t N>
48inline RealVect&
50{
51 return m_position;
52}
53
54template <size_t M, size_t N>
55inline const RealVect&
57{
58 return m_position;
59}
60
61template <size_t M, size_t N>
62inline const int32_t&
64{
65 return m_particleID;
66}
67
68template <size_t M, size_t N>
69inline int32_t&
71{
72 return m_particleID;
73}
74
75template <size_t M, size_t N>
76inline const int32_t&
78{
79 return m_rankID;
80}
82template <size_t M, size_t N>
83inline int32_t&
85{
86 return m_rankID;
88
89template <size_t M, size_t N>
90inline const std::array<Real, M>&
93 return m_scalars;
94}
95
96template <size_t M, size_t N>
99{
100 return m_scalars;
101}
102
103template <size_t M, size_t N>
106{
107 return m_vectors;
108}
109
110template <size_t M, size_t N>
113{
114 return m_vectors;
115}
117template <size_t M, size_t N>
118template <size_t K>
119inline Real&
121{
122 return std::get<K>(m_scalars);
124
125template <size_t M, size_t N>
126template <size_t K>
127inline const Real&
129{
130 return std::get<K>(m_scalars);
131}
132
133template <size_t M, size_t N>
134template <size_t K>
135inline RealVect&
138 return std::get<K>(m_vectors);
139}
140
141template <size_t M, size_t N>
142template <size_t K>
143inline const RealVect&
145{
146 return std::get<K>(m_vectors);
147}
148
149template <size_t M, size_t N>
150inline bool
152{
153 return (this->m_position == a_p.m_position && this->m_scalars == a_p.m_scalars && this->m_vectors == a_p.m_vectors);
154}
155
156template <size_t M, size_t N>
157inline bool
159{
160 return !(*this == a_p);
161}
162
163template <size_t M, size_t N>
164inline bool
166{
167 const RealVect& x = m_position;
168 const RealVect& y = a_other.m_position;
169
170 if (x[0] < y[0]) {
171 return true;
172 }
173#if CH_SPACEDIM > 1
174 if (x[0] > y[0]) {
175 return false;
176 }
177 if (x[1] < y[1]) {
178 return true;
179 }
180#endif
181#if CH_SPACEDIM > 2
182 if (x[1] > y[1]) {
183 return false;
184 }
185 if (x[2] < y[2]) {
186 return true;
187 }
188#endif
189
190 return false;
191}
192
193template <size_t M, size_t N>
194inline int
196{
197 // Size is the sum of the particle ID, rank ID, position, plus M Reals and N RealVects
198 int size = 0;
199
200 size += sizeof(int32_t); // Particle ID
201 size += sizeof(int32_t); // Rank ID
202 size += SpaceDim * sizeof(Real); // Position
203 size += M * sizeof(Real); // m_scalars
204 size += N * SpaceDim * sizeof(Real); // m_vectors
205
206 return size;
207}
208
209template <size_t M, size_t N>
210inline void
212{
213 uint8_t* p = static_cast<uint8_t*>(a_buffer);
215 detail::pushParticleProperty(p, m_particleID);
216 detail::pushParticleProperty(p, m_rankID);
217
218 detail::pushParticleProperty(p, m_position[0]);
219 detail::pushParticleProperty(p, m_position[1]);
220#if CH_SPACEDIM == 3
221 detail::pushParticleProperty(p, m_position[2]);
222#endif
223
224 for (size_t i = 0; i < M; i++) {
225 detail::pushParticleProperty(p, m_scalars[i]);
227
228 for (size_t i = 0; i < N; i++) {
229 detail::pushParticleProperty(p, m_vectors[i][0]);
230 detail::pushParticleProperty(p, m_vectors[i][1]);
231#if CH_SPACEDIM == 3
232 detail::pushParticleProperty(p, m_vectors[i][2]);
233#endif
235}
236
237template <size_t M, size_t N>
238inline void
240{
241 const uint8_t* p = static_cast<const uint8_t*>(a_buffer);
242
243 detail::pullParticleProperty(p, m_particleID);
244 detail::pullParticleProperty(p, m_rankID);
245
246 detail::pullParticleProperty(p, m_position[0]);
247 detail::pullParticleProperty(p, m_position[1]);
248#if CH_SPACEDIM == 3
249 detail::pullParticleProperty(p, m_position[2]);
250#endif
251
252 for (size_t i = 0; i < M; i++) {
253 detail::pullParticleProperty(p, m_scalars[i]);
254 }
255
256 for (size_t i = 0; i < N; i++) {
257 detail::pullParticleProperty(p, m_vectors[i][0]);
258 detail::pullParticleProperty(p, m_vectors[i][1]);
259#if CH_SPACEDIM == 3
260 detail::pullParticleProperty(p, m_vectors[i][2]);
261#endif
262 }
263}
264
265template <size_t M, size_t N>
266inline int
268{
269 int size = 0;
270
271 size += SpaceDim * sizeof(Real); // m_position
272 size += M * sizeof(Real); // m_scalars
273 size += N * SpaceDim * sizeof(Real); // m_vectors
274
275 return size;
276}
277
278template <size_t M, size_t N>
279inline void
281{
282 uint8_t* p = static_cast<uint8_t*>(a_buffer);
283
284 detail::pushParticleProperty(p, m_position[0]);
285 detail::pushParticleProperty(p, m_position[1]);
286#if CH_SPACEDIM == 3
287 detail::pushParticleProperty(p, m_position[2]);
288#endif
289
290 for (size_t i = 0; i < M; i++) {
291 detail::pushParticleProperty(p, m_scalars[i]);
292 }
293
294 for (size_t i = 0; i < N; i++) {
295 detail::pushParticleProperty(p, m_vectors[i][0]);
296 detail::pushParticleProperty(p, m_vectors[i][1]);
297#if CH_SPACEDIM == 3
298 detail::pushParticleProperty(p, m_vectors[i][2]);
299#endif
300 }
301}
302
303template <size_t M, size_t N>
304inline void
306{
307 const uint8_t* p = static_cast<const uint8_t*>(a_buffer);
308
309 detail::pullParticleProperty(p, m_position[0]);
310 detail::pullParticleProperty(p, m_position[1]);
311#if CH_SPACEDIM == 3
312 detail::pullParticleProperty(p, m_position[2]);
313#endif
314
315 for (size_t i = 0; i < M; i++) {
316 detail::pullParticleProperty(p, m_scalars[i]);
317 }
318
319 for (size_t i = 0; i < N; i++) {
320 detail::pullParticleProperty(p, m_vectors[i][0]);
321 detail::pullParticleProperty(p, m_vectors[i][1]);
322#if CH_SPACEDIM == 3
323 detail::pullParticleProperty(p, m_vectors[i][2]);
324#endif
325 }
326}
327
328template <size_t M, size_t N>
331{
332 ostr << "GenericParticle : \n";
333
334 // Print position.
335 ostr << "\tPosition = " << p.position() << "\n";
336
337 return ostr;
338}
339
340#include <CD_NamespaceFooter.H>
341
342#endif
std::ostream & operator<<(std::ostream &ostr, const GenericParticle< M, N > &p)
Particle printing function.
Definition CD_GenericParticleImplem.H:330
Declaration of a generic particle class.
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
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
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
GenericParticle()
Default constructor – initializes everything to zero.
Definition CD_GenericParticleImplem.H:20
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