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