chombo-discharge
Loading...
Searching...
No Matches
CD_TracerParticleImplem.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_TracerParticleImplem_H
13#define CD_TracerParticleImplem_H
14
15// Our includes
16#include <CD_TracerParticle.H>
17#include <CD_NamespaceHeader.H>
18
19template <size_t M, size_t N>
21{
22 this->m_position = RealVect::Zero;
23 this->m_weight = 0.0;
24 this->m_velocity = RealVect::Zero;
25
26 for (auto& s : this->m_scalars) {
27 s = 0.0;
28 }
29
30 for (auto& v : this->m_vectors) {
32 }
33}
34
35template <size_t M, size_t N>
37{
38 this->m_position = a_other.m_position;
39 this->m_weight = a_other.m_weight;
40 this->m_velocity = a_other.m_velocity;
41 this->m_scalars = a_other.m_scalars;
42 this->m_vectors = a_other.m_vectors;
43}
44
45template <size_t M, size_t N>
48
49template <size_t M, size_t N>
50inline Real&
52{
53 return m_weight;
54}
55
56template <size_t M, size_t N>
57inline const Real&
59{
60 return m_weight;
61}
62
63template <size_t M, size_t N>
64inline RealVect&
66{
67 return m_velocity;
68}
69
70template <size_t M, size_t N>
71inline const RealVect&
73{
74 return m_velocity;
75}
76
77template <size_t M, size_t N>
78inline int
80{
81 int size = 0;
82
84 size += SpaceDim * sizeof(Real);
85 size += sizeof(Real);
86
87 return size;
88}
89
90template <size_t M, size_t N>
91inline void
93{
94 uint8_t* p = static_cast<uint8_t*>(a_buffer);
95
96 detail::pushParticleProperty(p, this->m_particleID);
97 detail::pushParticleProperty(p, this->m_rankID);
98
99 detail::pushParticleProperty(p, this->m_position[0]);
100 detail::pushParticleProperty(p, this->m_position[1]);
101#if CH_SPACEDIM == 3
102 detail::pushParticleProperty(p, this->m_position[2]);
103#endif
104
105 for (size_t i = 0; i < M; i++) {
106 detail::pushParticleProperty(p, this->m_scalars[i]);
107 }
108
109 for (size_t i = 0; i < M; i++) {
110 detail::pushParticleProperty(p, this->m_vectors[i][0]);
111 detail::pushParticleProperty(p, this->m_vectors[i][1]);
112#if CH_SPACEDIM == 3
113 detail::pushParticleProperty(p, this->m_vectors[i][2]);
114#endif
115 }
116
117 detail::pushParticleProperty(p, m_weight);
118
119 detail::pushParticleProperty(p, m_velocity[0]);
120 detail::pushParticleProperty(p, m_velocity[1]);
121#if CH_SPACEDIM == 3
122 detail::pushParticleProperty(p, m_velocity[2]);
123#endif
124}
125
126template <size_t M, size_t N>
127inline void
129{
130 const uint8_t* p = static_cast<const uint8_t*>(a_buffer);
131
132 detail::pullParticleProperty(p, this->m_particleID);
133 detail::pullParticleProperty(p, this->m_rankID);
134
135 detail::pullParticleProperty(p, this->m_position[0]);
136 detail::pullParticleProperty(p, this->m_position[1]);
137#if CH_SPACEDIM == 3
138 detail::pullParticleProperty(p, this->m_position[2]);
139#endif
140
141 for (size_t i = 0; i < M; i++) {
142 detail::pullParticleProperty(p, this->m_scalars[i]);
143 }
144
145 for (size_t i = 0; i < M; i++) {
146 detail::pullParticleProperty(p, this->m_vectors[i][0]);
147 detail::pullParticleProperty(p, this->m_vectors[i][1]);
148#if CH_SPACEDIM == 3
149 detail::pullParticleProperty(p, this->m_vectors[i][2]);
150#endif
151 }
152
153 detail::pullParticleProperty(p, m_weight);
154
155 detail::pullParticleProperty(p, m_velocity[0]);
156 detail::pullParticleProperty(p, m_velocity[1]);
157#if CH_SPACEDIM == 3
158 detail::pullParticleProperty(p, m_velocity[2]);
159#endif
160}
161
162template <size_t M, size_t N>
163inline int
165{
166 int size = 0;
167
168 size += SpaceDim * sizeof(Real); // Position.
169 size += M * sizeof(Real); // m_scalars
170 size += N * SpaceDim * sizeof(Real); // m_vectors
171 size += sizeof(Real); // m_weight
172 size += SpaceDim * sizeof(Real); // m_velocity
173
174 return size;
175}
176
177template <size_t M, size_t N>
178inline void
180{
181 uint8_t* p = static_cast<uint8_t*>(a_buffer);
182
183 detail::pushParticleProperty(p, this->m_position[0]);
184 detail::pushParticleProperty(p, this->m_position[1]);
185#if CH_SPACEDIM == 3
186 detail::pushParticleProperty(p, this->m_position[2]);
187#endif
188
189 for (size_t i = 0; i < M; i++) {
190 detail::pushParticleProperty(p, this->m_scalars[i]);
191 }
192
193 for (size_t i = 0; i < M; i++) {
194 detail::pushParticleProperty(p, this->m_vectors[i][0]);
195 detail::pushParticleProperty(p, this->m_vectors[i][1]);
196#if CH_SPACEDIM == 3
197 detail::pushParticleProperty(p, this->m_vectors[i][2]);
198#endif
199 }
200
201 detail::pushParticleProperty(p, m_weight);
202
203 detail::pushParticleProperty(p, m_velocity[0]);
204 detail::pushParticleProperty(p, m_velocity[1]);
205#if CH_SPACEDIM == 3
206 detail::pushParticleProperty(p, m_velocity[2]);
207#endif
208}
209
210template <size_t M, size_t N>
211inline void
213{
214 const uint8_t* p = static_cast<const uint8_t*>(a_buffer);
215
216 detail::pullParticleProperty(p, this->m_position[0]);
217 detail::pullParticleProperty(p, this->m_position[1]);
218#if CH_SPACEDIM == 3
219 detail::pullParticleProperty(p, this->m_position[2]);
220#endif
221
222 for (size_t i = 0; i < M; i++) {
223 detail::pullParticleProperty(p, this->m_scalars[i]);
224 }
225
226 for (size_t i = 0; i < M; i++) {
227 detail::pullParticleProperty(p, this->m_vectors[i][0]);
228 detail::pullParticleProperty(p, this->m_vectors[i][1]);
229#if CH_SPACEDIM == 3
230 detail::pullParticleProperty(p, this->m_vectors[i][2]);
231#endif
232 }
233
234 detail::pullParticleProperty(p, m_weight);
235
236 detail::pullParticleProperty(p, m_velocity[0]);
237 detail::pullParticleProperty(p, m_velocity[1]);
238#if CH_SPACEDIM == 3
239 detail::pullParticleProperty(p, m_velocity[2]);
240#endif
241}
242
243template <size_t M, size_t N>
244template <size_t K>
245inline Real&
250
251template <size_t M, size_t N>
252template <size_t K>
253inline const Real&
258
259template <size_t M, size_t N>
260template <size_t K>
261inline RealVect&
266
267template <size_t M, size_t N>
268template <size_t K>
269inline const RealVect&
274
275template <size_t M, size_t N>
278{
279 ostr << "TracerParticle : \n";
280
281 // Print position.
282 ostr << "\tPosition = " << p.position() << "\n";
283 ostr << "\tWeight = " << p.weight() << "\n";
284 ostr << "\tVelocity = " << p.velocity() << "\n";
285
286 return ostr;
287}
288
289#include <CD_NamespaceFooter.H>
290
291#endif
std::ostream & operator<<(std::ostream &ostr, const TracerParticle< M, N > &p)
Particle printing function.
Definition CD_TracerParticleImplem.H:277
Declaration of a tracer particle class.
A generic particle class, holding the position and a specified number of real and vector values.
Definition CD_GenericParticle.H:76
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
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
TracerParticle()
Default constructor – initializes everything to zero.
Definition CD_TracerParticleImplem.H:20
virtual void linearIn(const void *const a_buffer) override
Read a linear binary representation of the internal data. Assumes that the buffer has the correct dat...
Definition CD_TracerParticleImplem.H:128
virtual void H5linearOut(void *const a_buffer) const
Linearize the Real components onto a buffer workable by HDF5.
Definition CD_TracerParticleImplem.H:179
RealVect & vect()
Get one of the RealVects.
Definition CD_TracerParticleImplem.H:262
RealVect & velocity()
Get the particle velocity.
Definition CD_TracerParticleImplem.H:65
virtual int H5size() const
Function that is used when writing particles to HDF5.
Definition CD_TracerParticleImplem.H:164
virtual ~TracerParticle()
Destructor (deallocates runtime memory storage)
Definition CD_TracerParticleImplem.H:46
virtual void linearOut(void *const a_buffer) const override
Write a linear binary representation of the internal data. Assumes that sufficient memory for the buf...
Definition CD_TracerParticleImplem.H:92
virtual void H5linearIn(const void *const a_buffer)
Delinearize the buffer onto the real components in the particle class.
Definition CD_TracerParticleImplem.H:212
virtual int size() const override
Returns the size, in number of bytes, of a flat representation of the data in this object.
Definition CD_TracerParticleImplem.H:79
Real & real()
Get one of the scalars.
Definition CD_TracerParticleImplem.H:246
Real & weight()
Get the particle "weight".
Definition CD_TracerParticleImplem.H:51