computational_cell_2d.cpp
1 #include "computational_cell_2d.hpp"
2 #include "../../misc/utils.hpp"
3 
4 using namespace std;
5 
7  density(0), pressure(0), velocity(Vector2D()), tracers(),
8  stickers(){}
9 
11  density(other.density), pressure(other.pressure), velocity(other.velocity), tracers(other.tracers),
12  stickers(other.stickers){}
13 
15 {
16  density = other.density;
17  pressure = other.pressure;
18  velocity = other.velocity;
19  tracers = other.tracers;
20  stickers = other.stickers;
21  return *this;
22 }
23 
25 {
26  this->density += other.density;
27  this->pressure += other.pressure;
28  this->velocity += other.velocity;
29  assert(this->tracers.size() == other.tracers.size());
30  size_t N = this->tracers.size();
31  for (size_t j = 0; j < N; ++j)
32  this->tracers[j] += other.tracers[j];
33  return *this;
34 }
35 
37 {
38  this->density -= other.density;
39  this->pressure -= other.pressure;
40  this->velocity -= other.velocity;
41  assert(this->tracers.size() == other.tracers.size());
42  size_t N = this->tracers.size();
43  for (size_t j = 0; j < N; ++j)
44  this->tracers[j] -= other.tracers[j];
45  return *this;
46 }
47 
49 {
50  this->density *= s;
51  this->pressure *= s;
52  this->velocity *= s;
53  size_t N = this->tracers.size();
54  for (size_t j = 0; j < N; ++j)
55  this->tracers[j] *= s;
56  return *this;
57 }
58 
59 void ComputationalCellAddMult(ComputationalCell &res, ComputationalCell const& other, double scalar)
60 {
61  res.density += other.density*scalar;
62  res.pressure += other.pressure*scalar;
63  res.velocity += other.velocity*scalar;
64  assert(res.tracers.size() == other.tracers.size());
65  size_t N = res.tracers.size();
66  for (size_t j = 0; j < N; ++j)
67  res.tracers[j] += other.tracers[j]*scalar;
68 }
69 
71 {
72  ComputationalCell res(p1);
73  res += p2;
74  return res;
75 }
76 
78 {
79  ComputationalCell res(p1);
80  res -= p2;
81  return res;
82 }
83 
85 {
86  ComputationalCell res(p);
87  res.density /= s;
88  res.pressure /= s;
89  size_t N = res.tracers.size();
90  for (size_t j = 0; j < N; ++j)
91  res.tracers[j] /= s;
92  res.velocity = res.velocity / s;
93  return res;
94 }
95 
97 {
98  ComputationalCell res(p);
99  res.density *= s;
100  res.pressure *= s;
101  size_t N = res.tracers.size();
102  for (size_t j = 0; j < N; ++j)
103  res.tracers[j] *= s;
104  res.velocity = res.velocity * s;
105  return res;
106 }
107 
109 {
110  return p*s;
111 }
112 
113 void ReplaceComputationalCell(ComputationalCell & cell, ComputationalCell const& other)
114 {
115  cell.density = other.density;
116  cell.pressure = other.pressure;
117  cell.velocity = other.velocity;
118  size_t N = other.tracers.size();
119  cell.tracers.resize(N);
120  for (size_t j = 0; j < N; ++j)
121  cell.tracers[j] = other.tracers[j];
122  N = other.stickers.size();
123  cell.stickers.resize(N);
124  for (size_t i = 0; i < N; ++i)
125  cell.stickers[i] = other.stickers[i];
126 }
127 
128 void ReplaceComputationalCellDiff(ComputationalCell &cell, ComputationalCell const& first, ComputationalCell const& second)
129 {
130  cell.density = first.density-second.density;
131  cell.pressure = first.pressure-second.pressure;
132  cell.velocity = first.velocity-second.velocity;
133  assert(first.tracers.size() == second.tracers.size());
134  size_t N = first.tracers.size();
135  cell.tracers.resize(N);
136  for (size_t j = 0; j < N; ++j)
137  cell.tracers[j] = first.tracers[j]-second.tracers[j];
138  assert(first.stickers.size() == second.stickers.size());
139  N = first.stickers.size();
140  cell.stickers.resize(N);
141  for (size_t i = 0; i < N; ++i)
142  cell.stickers[i] = first.stickers[i];
143 }
144 
145 Slope::Slope(void) :xderivative(ComputationalCell()), yderivative(ComputationalCell()) {}
146 
148 {}
149 
150 TracerStickerNames& TracerStickerNames::operator=
151 (const TracerStickerNames& other)
152 {
153  tracer_names = other.tracer_names;
154  sticker_names = other.sticker_names;
155  return *this;
156 }
157 
159  : tracer_names(vector<string>()), sticker_names(vector<string>()) {}
160 
162 
164 
166 (const std::vector<std::string>& tracers,
167  const std::vector<std::string>& stickers):
168  tracer_names(tracers),sticker_names(stickers){}
169 
170 #ifdef RICH_MPI
172 {
173  return 4 + tracers.size() + stickers.size();
174 }
175 
176 vector<double> ComputationalCell::serialize(void) const
177 {
178  vector<double> res (getChunkSize());
179  res.at(0) = density;
180  res.at(1) = pressure;
181  res.at(2) = velocity.x;
182  res.at(3) = velocity.y;
183  size_t counter = 4;
184  size_t N = tracers.size();
185  for (size_t j = 0; j < N ; ++j)
186  res[j+counter] = tracers[j];
187  size_t N2 = stickers.size();
188  for (size_t j = 0; j < N2; ++j)
189  res[j + counter + N] = stickers[j] ? 1 : 0;
190  return res;
191 }
192 
194 (const vector<double>& data)
195 {
196  assert(data.size()==getChunkSize());
197  density = data.at(0);
198  pressure = data.at(1);
199  velocity.x = data.at(2);
200  velocity.y = data.at(3);
201  size_t counter = 4;
202  size_t N = tracers.size();
203  for (size_t j = 0; j < N; ++j)
204  tracers[j] = data.at(counter + j);
205  size_t N2 = stickers.size();
206  for (size_t i = 0; i < N2; ++i)
207  stickers[i] = data.at(counter + N + i)>0.5;
208 }
209 
210 size_t Slope::getChunkSize(void) const
211 {
212  return xderivative.getChunkSize() * 2;
213 }
214 
215 vector<double> Slope::serialize(void) const
216 {
217  vector<double> res(getChunkSize());
218  vector<double> temp(xderivative.serialize());
219  std::copy(temp.begin(), temp.end(), res.begin());
220  temp = yderivative.serialize();
221  std::copy(temp.begin(), temp.end(), res.begin() + xderivative.getChunkSize());
222  return res;
223 }
224 
225 void Slope::unserialize(const vector<double>& data)
226 {
227  size_t size = xderivative.getChunkSize();
228  xderivative.unserialize(vector<double>(data.begin(), data.begin() + size));
229  yderivative.unserialize(vector<double>(data.begin() + size, data.end()));
230 }
231 
232 #endif // RICH_MPI
ComputationalCell & operator*=(double s)
Self multiplication operator.
std::vector< std::string > sticker_names
The names of the stickers.
void unserialize(const vector< double > &data)
Convert an array of numbers to an object.
vector< double > serialize(void) const
Convert an object to an array of numbers.
size_t getChunkSize(void) const
Returns the size of array needed to store all data.
size_t getChunkSize(void) const
Returns the size of array needed to store all data.
~TracerStickerNames(void)
Class destructor.
tvector tracers
Tracers (can transfer from one cell to another)
double pressure
Pressure.
Vector3D operator*(double d, Vector3D const &v)
Scalar product.
Definition: Vector3D.cpp:162
ComputationalCell xderivative
Slope in the x direction.
vector< double > serialize(void) const
Convert an object to an array of numbers.
ComputationalCell & operator=(ComputationalCell const &other)
Self decrement operator.
Vector3D operator/(Vector3D const &v, double d)
Scalar division.
Definition: Vector3D.cpp:176
ComputationalCell & operator+=(ComputationalCell const &other)
Self increment operator.
std::vector< std::string > tracer_names
The names of the tracers.
svector stickers
Stickers (stick to the same cell)
Class for keeping the names of the tracers and stickers.
ComputationalCell(void)
Default constructor.
Vector3D operator+(Vector3D const &v1, Vector3D const &v2)
Term by term addition.
Definition: Vector3D.cpp:143
void unserialize(const vector< double > &data)
Convert an array of numbers to an object.
Slope(void)
Default constructor.
ComputationalCell & operator-=(ComputationalCell const &other)
Self reduction operator.
Vector2D velocity
Velocity.
TracerStickerNames(void)
Default constructor.
2D Mathematical vector
Definition: geometry.hpp:15
Vector3D operator-(Vector3D const &v1, Vector3D const &v2)
Term by term subtraction.
Definition: Vector3D.cpp:152
Computational cell.
ComputationalCell yderivative
Slope in the y direction.