chombo-discharge
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 
19 template <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) {
31  v = RealVect::Zero;
32  }
33 }
34 
35 template <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 
45 template <size_t M, size_t N>
47 {}
48 
49 template <size_t M, size_t N>
50 inline Real&
52 {
53  return m_weight;
54 }
55 
56 template <size_t M, size_t N>
57 inline const Real&
59 {
60  return m_weight;
61 }
62 
63 template <size_t M, size_t N>
64 inline RealVect&
66 {
67  return m_velocity;
68 }
69 
70 template <size_t M, size_t N>
71 inline const RealVect&
73 {
74  return m_velocity;
75 }
76 
77 template <size_t M, size_t N>
78 inline int
80 {
81  return (GenericParticle<M, N>::size() + sizeof(Real) + SpaceDim * sizeof(Real));
82 }
83 
84 template <size_t M, size_t N>
85 inline void
87 {
88  // clang-format off
89  Real* buffer = (Real*) buf;
90 
91  // Linearize m_position onto buffer.
92  D_TERM(*buffer++ = this->m_position[0];,
93  *buffer++ = this->m_position[1];,
94  *buffer++ = this->m_position[2];);
95 
96  // Linearize m_scalars onto the buffer
97  for (size_t i = 0; i < M; i++) {
98  *buffer++ = this->m_scalars[i];
99  }
100 
101  // Linearize vectors onto the buffer
102  for (size_t i = 0; i < N; i++) {
103  const RealVect& v = this->m_vectors[i];
104 
105  D_TERM(*buffer++ = v[0];, *buffer++ = v[1];, *buffer++ = v[2];);
106  }
107 
108  // Linearize m_velocity onto buffer
109  D_TERM(*buffer++ = m_velocity[0];,
110  *buffer++ = m_velocity[1];,
111  *buffer++ = m_velocity[2];);
112 
113  // // Linearize weight onto buffer
114  *buffer = m_weight;
115 
116  // clang-format on
117 }
118 
119 template <size_t M, size_t N>
120 inline void
122 {
123  // clang-format off
124 
125  Real* buffer = (Real*)buf;
126 
127  D_TERM(this->m_position[0] = *buffer++;,
128  this->m_position[1] = *buffer++;,
129  this->m_position[2] = *buffer++;);
130 
131  // Linearize buffer onto scalars
132  for (size_t i = 0; i < M; i++) {
133  this->m_scalars[i] = *buffer++;
134  }
135 
136  // Linearize buffer onto vectors
137  for (size_t i = 0; i < N; i++) {
138  RealVect& v = this->m_vectors[i];
139 
140  D_TERM(v[0] = *buffer++;,
141  v[1] = *buffer++;,
142  v[2] = *buffer++;);
143  }
144 
145  // Put velocity onto buffer.
146  D_TERM(m_velocity[0] = *buffer++;,
147  m_velocity[1] = *buffer++;,
148  m_velocity[2] = *buffer++;);
149 
150  // Put weight onto buffer
151  m_weight = *buffer;
152 
153  // clang-format on
154 }
155 
156 template <size_t M, size_t N>
157 inline std::ostream&
158 operator<<(std::ostream& ostr, const TracerParticle<M, N>& p)
159 {
160  ostr << "TracerParticle : \n";
161 
162  // Print position.
163  ostr << "\tPosition = " << p.position() << "\n";
164  ostr << "\tWeight = " << p.weight() << "\n";
165  ostr << "\tVelocity = " << p.velocity() << "\n";
166 
167  return ostr;
168 }
169 
170 #include <CD_NamespaceFooter.H>
171 
172 #endif
std::ostream & operator<<(std::ostream &ostr, const TracerParticle< M, N > &p)
Particle printing function.
Definition: CD_TracerParticleImplem.H:158
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:33
RealVect & position()
Get the particle position.
Definition: CD_GenericParticleImplem.H:47
RealVect m_position
Particle position.
Definition: CD_GenericParticle.H:180
std::array< Real, M > m_scalars
Scalar storage array.
Definition: CD_GenericParticle.H:185
std::array< RealVect, N > m_vectors
vector storage array
Definition: CD_GenericParticle.H:190
A tracer particle class. This is templated for holding extra storage (useful for kernels).
Definition: CD_TracerParticle.H:33
TracerParticle()
Default constructor – initializes everything to zero.
Definition: CD_TracerParticleImplem.H:20
RealVect m_velocity
Particle velocity.
Definition: CD_TracerParticle.H:109
RealVect & velocity()
Get the particle velocity.
Definition: CD_TracerParticleImplem.H:65
virtual void linearOut(void *a_buffer) const override
Write a linear binary representation of the internal data. Assumes that sufficient memory for the buf...
Definition: CD_TracerParticleImplem.H:86
virtual ~TracerParticle()
Destructor (deallocates runtime memory storage)
Definition: CD_TracerParticleImplem.H:46
Real m_weight
Particle "weight".
Definition: CD_TracerParticle.H:104
virtual void linearIn(void *a_buffer) override
Read a linear binary representation of the internal data. Assumes that the buffer has the correct dat...
Definition: CD_TracerParticleImplem.H:121
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 & weight()
Get the particle "weight".
Definition: CD_TracerParticleImplem.H:51