summaryrefslogtreecommitdiff
path: root/src/particles/particle3D.h
blob: a9af64a489250b91fd12dd0f8ed37b3418fee789 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
/*  This file is part of the OpenLB library
 *
 *  Copyright (C) 2016 Thomas Henn, Mathias J. Krause
 *  E-mail contact: info@openlb.net
 *  The most recent release of OpenLB can be downloaded at
 *  <http://www.openlb.net/>
 *
 *  This program is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU General Public License
 *  as published by the Free Software Foundation; either version 2
 *  of the License, or (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public
 *  License along with this program; if not, write to the Free
 *  Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 *  Boston, MA  02110-1301, USA.
 */

#ifndef PARTICLE_3D_H
#define PARTICLE_3D_H

#include <set>
#include <vector>
#include <list>
#include <deque>
#include <string>
#include <iostream>

namespace olb {

template<typename T>
class Particle3D {
public:
  Particle3D();
  Particle3D(std::vector<T> pos, T mas = 1., T rad = 1., int id = 0);
  Particle3D(std::vector<T> pos, std::vector<T> vel,
             T mas = 1., T rad = 1., int id = 0);
  Particle3D(const Particle3D<T>& p);

  inline void setPos(std::vector<T> pos) {
    _pos = pos;
  }
  inline void setStoredPos(std::vector<T> pos) {
    _storePos = pos;
  }
  inline std::vector<T>& getStoredPos() {
    return _storePos;
  }
  inline std::vector<T>& getPos() {
    return _pos;
  }
  inline const std::vector<T>& getPos() const {
    return _pos;
  }
  inline void setVel(std::vector<T> vel) {
    _vel = vel;
  }
  inline void setStoredVel(std::vector<T> vel) {
    _storeVel = vel;
  }
  inline std::vector<T>& getStoredVel() {
    return _storeVel;
  }
  inline int getID() {
    return _id;
  }
  inline void setID(int id) {
    _id = id;
  }
  inline std::vector<T>& getVel() {
    return _vel;
  }
  inline const std::vector<T>& getVel() const {
    return _vel;
  }

  inline void addForce(std::vector<T>& frc);

  inline void setForce(std::vector<T>& frc);
  inline void resetForce();
  inline std::vector<T>& getForce() {
    return _force;
  }
  inline const std::vector<T>& getForce() const {
    return _force;
  }

  inline void setStoreForce(std::vector<T>& storeForce);
  inline void resetStoreForce();
  inline std::vector<T>& getStoreForce()
  {
    return _storeForce;
  }
  inline const std::vector<T>& getStoreForce() const {
    return _storeForce;
  }

  // RK4
//  inline void setPos(std::vector<T> pos, int i) {
//    _positions[i] = pos;
//  }
//  inline std::vector<T>& getPos(int i) {
//    return _positions[i];
//  }
//  inline const std::vector<T>& getPos(int i) const {
//    return _positions[i];
//  }
//  inline void setVel(std::vector<T> vel, int i) {
//    _velocities[i] = vel;
//  }
//  inline std::vector<T>& getVel(int i) {
//    return _velocities[i];
//  }
//  inline const std::vector<T>& getVel(int i) const {
//    return _velocities[i];
//  }
//  inline void setForce(std::vector<T> force, int i) {
//    _forces[i] = force;
//  }
//  inline std::vector<T>& getForce(int i) {
//    return _forces[i];
//  }
//  inline const std::vector<T>& getForce(int i) const {
//    return _forces[i];
//  }

// write particle properties into serial
  void serialize(T serial[]);
  // write data into particle properties
  void unserialize(T*);
  void print();
  void printDeep(std::string message);

  inline const T& getMass() {
    return _mas;
  }

  inline const T& getInvMass() {
    return _invMas;
  }

  inline const T& getMass() const {
    return _mas;
  }
  inline void setMass(T m) {
    _mas = m;
    _invMas = 1. / _mas;
  }
  inline const T& getRad() {
    return _rad;
  }
  inline const T& getRad() const {
    return _rad;
  }
  inline void setRad(T r) {
    _rad = r;
  }
  inline const int& getCuboid() {
    return _cuboid;
  }
  inline void setCuboid(int c) {
    _cuboid = c;
  }
  inline const bool& getActive() {
    return _active;
  }
  inline const bool& getActive() const {
    return _active;
  }
  inline void setActive(bool act) {
    _active = act;
    if (!act) {
      _vel[0] = 0;
      _vel[1] = 0;
      _vel[2] = 0;
    }
  }

  // static const int serialPartSize = 14; // pos, vel, force, mas, rad, cuboid, id, active
  static const int serialPartSize = 17; // pos, vel, force, mas, rad, cuboid, id, active, storeForce
  // static const int serialPartSize = 23; // pos, vel, force, mas, rad, cuboid, id, active, storeForce, storePos, storeVel

  std::vector<std::pair<size_t, T> > _verletList;

protected:
  std::vector<T> _pos;
  std::vector<T> _vel;
  std::vector<T> _force;
  T _invMas;
  T _mas;
  T _rad;
  ///globIC
  int _cuboid;
  int _id;
  bool _active;
  std::vector<T> _storePos;
  std::vector<T> _storeVel;
  std::vector<T> _storeForce;
  // RK4
//  std::vector<std::vector<T> > _positions;
//  std::vector<std::vector<T> > _velocities;
//  std::vector<std::vector<T> > _forces;

};

/*
 * Electric Particles
 */
template<typename T>
class ElParticle3D: public Particle3D<T> {
public:
  ElParticle3D();
  ElParticle3D(std::vector<T> pos, T mas = 1., T rad = 1., T charge = 1.);
  ElParticle3D(std::vector<T> pos, std::vector<T> vel,
               T mas = 1., T rad = 1., T charge = 1.);
  ElParticle3D(const ElParticle3D<T>& p);
  virtual ~ElParticle3D() {
  }
  ;
  virtual void serialize(T serial[]);
  virtual void unserialize(T*);
  static const int serialPartSize = 10;
  T _charge;
};

/*
 * Particles for Agglomeration
 */

template<typename T>
class AggParticle3D: public Particle3D<T> {
public:
  AggParticle3D();
  AggParticle3D(std::vector<T> pos, T mas = 1., T rad = 1.);
  AggParticle3D(std::vector<T> pos, std::vector<T> vel, T mas = 1., T rad = 1.);
  AggParticle3D(const Particle3D<T>& p);

  inline void setMass(T mas) {
    this->_mas = mas;
  }
  inline void setRad(T rad) {
    this->_rad = rad;
  }
  inline const bool& getAggl() {
    return _aggl;
  }
  inline const bool& getAggl() const {
    return _aggl;
  }
  inline void setAggl(bool aggl) {
    _aggl = aggl;
    if (aggl) {
      this->setActive(false);
    }
  }

  static const int serialPartSize = 14;
  void serialize(T serial[]);
  void unserialize(T*);

private:
  bool _aggl;
};

/*
 * Rotating Particles
 */
template<typename T>
class RotatingParticle3D: public