OpenLB 1.7
Loading...
Searching...
No Matches
particle3D.hh
Go to the documentation of this file.
1/* This file is part of the OpenLB library
2 *
3 * Copyright (C) 2016 Thomas Henn, Davide Dapelo
4 * E-mail contact: info@openlb.net
5 * The most recent release of OpenLB can be downloaded at
6 * <http://www.openlb.net/>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public
19 * License along with this program; if not, write to the Free
20 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301, USA.
22 */
23
24#ifndef PARTICLE_3D_HH
25#define PARTICLE_3D_HH
26
27#include <string>
28#include <iostream>
29#include <set>
30#include <vector>
31#include <list>
32#include <deque>
33
34#include "particle3D.h"
35
36namespace olb {
37
38
40
41 template<typename T>
43 : _pos(3, 0.),
44 _vel(3, 0.),
45 _force(3, 0.),
46 _effectiveMas(1.),
47 _mas(1.),
48 _masAdd(0.),
49 _rad(0),
50 _cuboid(0),
51 _id(0),
52 _active(false),
53 _storeForce(3, 0.)
54 { }
55
56 /*
57 template<typename T>
58 Particle3D<T>::Particle3D(std::vector<T> pos, T mas, T rad, int id)
59 : _pos(pos),
60 _vel(3, 0.),
61 _force(3, 0.),
62 _rad(rad),
63 _cuboid(0),
64 _id(id),
65 _active(true),
66 _storeForce(3, 0.)
67 {
68 setMass(mas);
69 setAddedMass(mas);
70 // RK4
71 // _positions = std::vector<std::vector<T> > (4, std::vector<T> (3, T() ));
72 // _velocities = std::vector<std::vector<T> > (4, std::vector<T> (3, T() ));
73 // _forces = std::vector<std::vector<T> > (4, std::vector<T> (3, T() ));
74 }
75 */
76
77 template<typename T>
78 Particle3D<T>::Particle3D(std::vector<T> pos, T mas, T rad, int id, T masAdd)
79 : _pos(pos),
80 _vel(3, 0.),
81 _force(3, 0.),
82 _rad(rad),
83 _cuboid(0),
84 _id(id),
85 _active(true),
86 _storeForce(3, 0.)
87 {
88 setMass(mas);
89 setAddedMass(masAdd);
90 // RK4
91 // _positions = std::vector<std::vector<T> > (4, std::vector<T> (3, T() ));
92 // _velocities = std::vector<std::vector<T> > (4, std::vector<T> (3, T() ));
93 // _forces = std::vector<std::vector<T> > (4, std::vector<T> (3, T() ));
94 }
95
96 template<typename T>
98 : _pos(p._pos),
99 _vel(p._vel),
100 _force(p._force),
101 _rad(p._rad),
102 _cuboid(p._cuboid),
103 _id(p._id),
104 _active(p._active),
105 _storeForce(p._storeForce)
106 {
107 setMass(p._mas);
109 // RK4
110 // _positions = std::vector<std::vector<T> > (4, std::vector<T> (3, T() ));
111 // _velocities = std::vector<std::vector<T> > (4, std::vector<T> (3, T() ));
112 // _forces = std::vector<std::vector<T> > (4, std::vector<T> (3, T() ));
113 }
114
115 /*
116 template<typename T>
117 Particle3D<T>::Particle3D(std::vector<T> pos, std::vector<T> vel, T mas, T rad, int id)
118 : _pos(pos),
119 _vel(vel),
120 _force(12, 0.),
121 _rad(rad),
122 _cuboid(0),
123 _id(id),
124 _active(true),
125 _storeForce(3, 0.)
126 {
127 setMass(mas);
128 setAddedMass(mas);
129 _vel.resize(12, 0.);
130 // RK4
131 // _positions = std::vector<std::vector<T> > (4, std::vector<T> (3, T() ));
132 // _velocities = std::vector<std::vector<T> > (4, std::vector<T> (3, T() ));
133 // _forces = std::vector<std::vector<T> > (4, std::vector<T> (3, T() ));
134 }
135 */
136
137 template<typename T>
138 Particle3D<T>::Particle3D(std::vector<T> pos, std::vector<T> vel, T mas, T rad, int id, T masAdd)
139 : _pos(pos),
140 _vel(vel),
141 _force(12, 0.),
142 _rad(rad),
143 _cuboid(0),
144 _id(id),
145 _active(true),
146 _storeForce(3, 0.)
148 setMass(mas);
149 setAddedMass(masAdd);
150 _vel.resize(12, 0.);
151 // RK4
152 // _positions = std::vector<std::vector<T> > (4, std::vector<T> (3, T() ));
153 // _velocities = std::vector<std::vector<T> > (4, std::vector<T> (3, T() ));
154 // _forces = std::vector<std::vector<T> > (4, std::vector<T> (3, T() ));
155 }
156
157 template<typename T>
158 inline void Particle3D<T>::setPos(std::vector<T> pos)
159 {
160 _pos = pos;
161 }
162
163 template<typename T>
164 inline void Particle3D<T>::setStoredPos(std::vector<T> pos)
165 {
166 _storePos = pos;
167 }
168
169 template<typename T>
170 inline std::vector<T>& Particle3D<T>::getStoredPos()
171 {
172 return _storePos;
173 }
174
175 template<typename T>
176 inline std::vector<T>& Particle3D<T>::getPos()
177 {
178 return _pos;
179 }
180
181 template<typename T>
182 inline const std::vector<T>& Particle3D<T>::getPos() const
183 {
184 return _pos;
185 }
186
187 template<typename T>
188 inline void Particle3D<T>::setVel(std::vector<T> vel)
189 {
190 _vel = vel;
191 }
192
193 template<typename T>
194 inline void Particle3D<T>::setStoredVel(std::vector<T> vel)
195 {
196 _storeVel = vel;
197 }
198
199 template<typename T>
200 inline std::vector<T>& Particle3D<T>::getStoredVel()
201 {
202 return _storeVel;
203 }
204
205 template<typename T>
207 {
208 return _id;
209 }
210
211 template<typename T>
212 inline void Particle3D<T>::setID(int id)
213 {
214 _id = id;
215 }
216
217 template<typename T>
218 inline std::vector<T>& Particle3D<T>::getVel()
219 {
220 return _vel;
221 }
222
223 template<typename T>
224 inline const std::vector<T>& Particle3D<T>::getVel() const
225 {
226 return _vel;
227 }
228
229 template<typename T>
230 inline void Particle3D<T>::addForce(std::vector<T>& force)
231 {
232 for (int i = 0; i < 3; i++) {
233 _force[i] += force[i];
234 }
235 }
236 // set and get force
237 template<typename T>
238 inline void Particle3D<T>::setForce(std::vector<T>& force)
239 {
240 _force = force;
241 }
242 template<typename T>
244 {
245 for (int i = 0; i < 3; i++) {
246 _force[i] = 0.;
247 }
248 }
249
250 // set and get storedForce
251 template<typename T>
252 inline void Particle3D<T>::setStoreForce(std::vector<T>& storeForce)
253 {
254 for (int i = 0; i < 3; i++) {
255 _storeForce[i] = storeForce[i];
256 }
257 }
258
259 template<typename T>
261 {
262 for (int i = 0; i < 3; i++) {
263 _storeForce[i] = T(0);
264 }
265 }
266
267 template<typename T>
268 inline std::vector<T>& Particle3D<T>::getForce()
269 {
270 return _force;
271 }
272
273 template<typename T>
274 inline const std::vector<T>& Particle3D<T>::getForce() const
275 {
276 return _force;
277 }
278
279 template<typename T>
280 inline std::vector<T>& Particle3D<T>::getStoreForce()
281 {
282 return _storeForce;
283 }
284
285 template<typename T>
286 inline const std::vector<T>& Particle3D<T>::getStoreForce() const
287 {
288 return _storeForce;
289 }
290
291 // RK4
292 //template<typename T>
293 //inline void Particle3D<T>::setPos(std::vector<T> pos, int i)
294 //{
295 // _positions[i] = pos;
296 //}
297
298 //template<typename T>
299 //inline std::vector<T>& Particle3D<T>::getPos(int i)
300 //{
301 // return _positions[i];
302 //}
303
304 //template<typename T>
305 //inline const std::vector<T>& Particle3D<T>::getPos(int i) const
306 //{
307 // return _positions[i];
308 //}
309
310 //template<typename T>
311 //inline void Particle3D<T>::setVel(std::vector<T> vel, int i)
312 //{
313 // _velocities[i] = vel;
314 //}
315
316 //template<typename T>
317 //inline std::vector<T>& Particle3D<T>::getVel(int i)
318 //{
319 // return _velocities[i];
320 //}
321
322 //template<typename T>
323 //inline const std::vector<T>& Particle3D<T>::getVel(int i) const
324 //{
325 // return _velocities[i];
326 //}
327
328 //template<typename T>
329 //inline void Particle3D<T>::setForce(std::vector<T> force, int i)
330 //{
331 // _forces[i] = force;
332 //}
333
334 //template<typename T>
335 //inline std::vector<T>& Particle3D<T>::getForce(int i)
336 //{
337 // return _forces[i];
338 //}
339
340 //template<typename T>
341 //inline const std::vector<T>& Particle3D<T>::getForce(int i) const
342 //{
343 // return _forces[i];
344 //}
345
346 template<typename T>
348 {
349 for (int i = 0; i < 3; i++) {
350 serial[i] = _pos[i];
351 serial[i + 3] = _vel[i];
352 serial[i + 6] = _force[i];
353 }
354 serial[9] = _mas;
355 serial[10] = _masAdd;
356 serial[11] = _effectiveMas;
357 serial[12] = _rad;
358 serial[13] = _cuboid;
359 serial[14] = _active;
360 serial[15] = _id;
361
362 for (int i = 0; i < 3; i++) {
363 serial[i + 16] = _storeForce[i];
364 }
365
366 //for (int i = 0; i < 18; i++) {
367 //cout << "serialize " << i << ": " << serial[i] << " tn: " << typeid(serial[i]).name() << std::endl;
368 //}
369 }
370
371 template<typename T>
373 {
374 for (int i = 0; i < 3; i++) {
375 _pos[i] = data[i];
376 _vel[i] = data[i + 3];
377 _force[i] = data[i + 6];
378 }
379 _mas = data[9];
380 _masAdd = data[10];
381 _effectiveMas = data[11];
382 _rad = data[12];
383 _cuboid = int(data[13]);
384 _active = data[14];
385 _invMas = 1. / _mas;
386 _invMasAdd = 1. / _masAdd;
387 _invEffectiveMas = 1. / _effectiveMas;
388 _id = data[15];
389
390 for (int i = 0; i < 3; i++) {
391 _storeForce[i] = data[i + 16];
392 }
393 }
394
395 template<typename T>
397 {
398 std::cout << "Pos=(" << _pos[0] << ", " << _pos[1] << ", " << _pos[2] << ") "
399 << "Vel=(" << _vel[0] << ", " << _vel[1] << ", " << _vel[2] << ") "
400 << "Cub=" << _cuboid
401 << std::endl;
402 }
403
404 template<typename T>
405 void Particle3D<T>::printDeep(std::string message)
406 {
407 std::cout << message
408 << " ID=" << this->getID()
409// << " rad=" << this->getRad()
410// << " mass=" << this->getMass()
411// << " invMass=" << this->getInvMass()
412// << " addedMass=" << this->getAddedMass()
413// << " force=(" << this->getForce()[0] << ", " << this->getForce()[1] << ", " << this->getForce()[2] << ")"
414// << " storeForce=(" << this->getStoreForce()[0] << " " << this->getStoreForce()[1] << ", " << this->getStoreForce()[2] << ")"
415// << " active=" << this->getActive()
416// << std::endl;
417 << " ";
418 this->print();
419// std::cout << std::endl;
420 }
421
422 template<typename T>
423 inline const T& Particle3D<T>::getMass()
424 {
425 return _mas;
426 }
427
428 template<typename T>
430 {
431 return _masAdd;
432 }
433
434 template<typename T>
436 {
437 return _invMas;
438 }
439
440 template<typename T>
442 {
443 return _invEffectiveMas;
444 }
445
446 template<typename T>
448 {
449 return _effectiveMas;
450 }
451
452 template<typename T>
453 inline const T& Particle3D<T>::getMass() const
454 {
455 return _mas;
456 }
457
458 template<typename T>
459 inline const T& Particle3D<T>::getAddedMass() const
460 {
461 return _masAdd;
462 }
463
464 template<typename T>
465 inline const T& Particle3D<T>::getEffectiveMass() const
466 {
467 return _effectiveMas;
468 }
469
470 template<typename T>
471 inline void Particle3D<T>::setMass(T m)
472 {
473 if (m <= T()) {
474 throw std::invalid_argument("Exception called in particle3D::setMass(T). Input value must be > 0, but instead was " + std::to_string(m));
475 }
476 _mas = m;
477 _invMas = 1. / _mas;
478 _effectiveMas = _mas + _masAdd;
479 _invEffectiveMas = 1. / _effectiveMas;
480 }
481
482 template<typename T>
484 {
485 if (m < T()) {
486 throw std::invalid_argument("Exception called in particle3D::setAddedMass(T). Input value must be >= 0, but instead was " + std::to_string(m));
487 }
488 _masAdd = m;
489 _effectiveMas = _mas + _masAdd;
490 _invEffectiveMas = 1. / _effectiveMas;
491 }
492
493 template<typename T>
494 inline const T& Particle3D<T>::getRad()
495 {
496 return _rad;
497 }
498
499 template<typename T>
500 inline const T& Particle3D<T>::getRad() const
501 {
502 return _rad;
503 }
504
505 template<typename T>
506 inline void Particle3D<T>::setRad(T r)
507 {
508 _rad = r;
509 }
510
511 template<typename T>
512 inline const int& Particle3D<T>::getCuboid()
513 {
514 return _cuboid;
515 }
516
517 template<typename T>
518 inline void Particle3D<T>::setCuboid(int c)
519 {
520 _cuboid = c;
521 }
522
523 template<typename T>
524 inline const bool& Particle3D<T>::getActive()
525 {
526 return _active;
527 }
528
529 template<typename T>
530 inline const bool& Particle3D<T>::getActive() const
531 {
532 return _active;
533 }
534
535 template<typename T>
536 inline void Particle3D<T>::setActive(bool act)
537 {
538 _active = act;
539 if (!act) {
540 _vel[0] = 0;
541 _vel[1] = 0;
542 _vel[2] = 0;
543 }
544 }
545
546
548
549 template<typename T, template<typename U> class PARTICLETYPE>
553
554 template<typename T, template<typename U> class PARTICLETYPE>
556 {
557 _pSys->computeForce();
558 _pSys->explicitEuler(dT, scale);
559 //_pSys->rungeKutta4(dT);
560 }
561
562 template<typename T, template<typename U> class PARTICLETYPE>
563 inline void SimulateParticles<T,PARTICLETYPE>::simulate(T dT, std::set<int> sActivityOfParticle, bool scale)
564 {
565 simulate(dT, scale);
566 }
567
568 template<typename T, template<typename U> class PARTICLETYPE>
572 int material, int subSteps, bool scale )
573 {
574 for (int iSubStep=1; iSubStep<=subSteps; iSubStep++) {
575 if (! _pSys->executeForwardCoupling(forwardCoupling) ) {
576 std::cout << " on substep " << iSubStep << std::endl;
578 }
579 _pSys->computeForce();
580 _pSys->explicitEuler(dT/(T)(subSteps), scale);
581 //_pSys->rungeKutta4(dT/(T)(subSteps));
582 }
583 _pSys->executeBackwardCoupling(backCoupling, material);
584 }
585
586 template<typename T, template<typename U> class PARTICLETYPE>
590 int material, int subSteps, bool scale )
591 {
592 for (int iSubStep=1; iSubStep<=subSteps; iSubStep++) {
593 if (! _pSys->executeForwardCoupling(forwardCoupling) ) {
594 std::cout << " on substep " << iSubStep << std::endl;
596 }
597 _pSys->executeBackwardCoupling(backCoupling, material, subSteps);
598 _pSys->computeForce();
599 _pSys->explicitEuler(dT/(T)(subSteps), scale);
600 //_pSys->rungeKutta4(dT/(T)(subSteps));
601 }
602 }
603
604
605}
606
607#endif /* PARTICLE_3D_HH */
Abstact base class for BaseBackCouplingModel.
Abstact base class for all the forward-coupling models Its raison d'etre consists of not being temple...
std::vector< T > & getVel()
const T & getInvEffectiveMass()
void unserialize(T *)
void setStoreForce(std::vector< T > &storeForce)
std::vector< T > & getForce()
void addForce(std::vector< T > &frc)
std::vector< T > & getPos()
std::vector< T > & getStoredPos()
void setMass(T m)
const int & getCuboid()
std::vector< T > & getStoreForce()
const T & getMass()
void setStoredVel(std::vector< T > vel)
void setVel(std::vector< T > vel)
void setCuboid(int c)
void printDeep(std::string message)
void serialize(T serial[])
void setActive(bool act)
void setID(int id)
void setPos(std::vector< T > pos)
void setRad(T r)
const bool & getActive()
std::vector< T > & getStoredVel()
const T & getAddedMass()
const T & getInvMass()
const T & getRad()
void setStoredPos(std::vector< T > pos)
void setForce(std::vector< T > &frc)
void setAddedMass(T m)
void resetStoreForce()
const T & getEffectiveMass()
void simulateWithTwoWayCoupling_Mathias(T dT, ForwardCouplingModel< T, PARTICLETYPE > &forwardCoupling, BackCouplingModel< T, PARTICLETYPE > &backCoupling, int material, int subSteps=1, bool scale=false)
SimulateParticles(ParticleSystem3D< T, PARTICLETYPE > *ps)
void simulateWithTwoWayCoupling_Davide(T dT, ForwardCouplingModel< T, PARTICLETYPE > &forwardCoupling, BackCouplingModel< T, PARTICLETYPE > &backCoupling, int material, int subSteps=1, bool scale=false)
void simulate(T dT, bool scale=false)
void exit(int exitcode)
Definition singleton.h:165
Top level namespace for all of OpenLB.