MolSim
Loading...
Searching...
No Matches
Particle.h
Go to the documentation of this file.
1
11#pragma once
12
13#include "utils/OMPWrapper.h"
14#include <array>
15#include <string>
16#include <vector>
17
18#define TYPE_DEFAULT 0
19#define SIGMA_DEFAULT 1
20#define EPSILON_DEFAULT 1
21#define K_DEFAULT 0
22#define R0_DEFAULT 0
23#define FZUP_DEFAULT 0
24#define MASS_ERROR "The mass of a particle must be positive for the currently available simulations!"
25
26// note: because these are macros, they could also be wrapped in such a way that compiles them out if not needed,
27// similarly to what is done below with outflow condition checks; but, since this is not part of any
28// performance evaluation environment (see older commit), these are left on by default...
29#define DO_IF_NOT_WALL(_p, _expr) \
30 if ((_p).getType() != 1) { \
31 _expr; \
32 }
33#define SKIP_IF_WALL(_p) \
34 if ((_p).getType() == 1) \
35 continue;
36
37#ifdef NOUTFLOW
38#define CONTINUE_IF_INACTIVE(p) (void)0
39#else
40#define CONTINUE_IF_INACTIVE(p) \
41 if (!(p).isActive()) \
42 continue;
43#endif
44
46class Particle {
47 private:
49 std::array<double, 3> x;
50
52 std::array<double, 3> v;
53
55 std::array<double, 3> thermal_motion;
56
58 std::array<double, 3> f;
59
61 std::array<double, 3> old_f;
62
64 std::vector<std::reference_wrapper<Particle>> direct_neighbours;
65
67 std::vector<std::reference_wrapper<Particle>> diagonal_neighbours;
68
70 double m;
71
73 int type; // this could probably be made an enum now
74
76 double epsilon;
77
79 double sigma;
80
82 double k;
83
85 double r_0;
86
88 double fzup;
89
92
95
103 bool active{true};
104
106 int id;
107
108 public:
117 explicit Particle(int type = 0);
118
124 Particle(const Particle &other);
125
142 Particle(const std::array<double, 3> &x, const std::array<double, 3> &v, double m, int type = TYPE_DEFAULT,
143 double eps = EPSILON_DEFAULT, double sigma = SIGMA_DEFAULT, double k = K_DEFAULT, double r_0 = R0_DEFAULT,
144 double fzup = FZUP_DEFAULT);
145
164 Particle(const std::array<double, 3> &x, const std::array<double, 3> &v, const std::array<double, 3> &f,
165 const std::array<double, 3> &old_f, double m, int type, double eps, double sigma, double k, double r_0,
166 double fzup, int cellIndex);
167
169 virtual ~Particle();
170
176 inline std::array<double, 3> &getX() { return x; }
177
183 inline std::array<double, 3> &getV() { return v; }
184
190 inline std::array<double, 3> &getF() { return f; }
191
197 inline std::array<double, 3> &getOldF() { return old_f; }
198
204 inline std::vector<std::reference_wrapper<Particle>> &getDirectNeighbours() { return direct_neighbours; }
205
211 inline const std::vector<std::reference_wrapper<Particle>> &getDirectNeighbours() const {
212 return direct_neighbours;
213 }
214
220 inline std::vector<std::reference_wrapper<Particle>> &getDiagonalNeighbours() { return diagonal_neighbours; }
221
227 inline const std::vector<std::reference_wrapper<Particle>> &getDiagonalNeighbours() const {
228 return diagonal_neighbours;
229 }
230
236 inline const std::array<double, 3> &getX() const { return x; }
237
243 inline const std::array<double, 3> &getV() const { return v; }
244
250 inline const std::array<double, 3> &getThermalMotion() const { return thermal_motion; }
251
257 inline const std::array<double, 3> &getF() const { return f; }
258
264 inline const std::array<double, 3> &getOldF() const { return old_f; }
265
271 inline double getM() const { return m; }
272
278 inline int getType() const { return type; }
279
285 inline double getEpsilon() const { return epsilon; }
286
292 inline double getSigma() const { return sigma; }
293
299 inline double getK() const { return k; }
300
306 inline double getR0() const { return r_0; }
307
313 inline double getFZUP() const { return fzup; }
314
322 inline int getCellIndex() const { return cellIndex; }
323
330 inline bool isActive() const { return active; }
331
339 inline int getId() const { return id; }
340
346 inline omp_lock_t &getLock() { return lock; }
347
353 void setX(const std::array<double, 3> &new_x);
354
360 void setV(const std::array<double, 3> &new_v);
361
367 void setDirectNeighbours(const std::vector<std::reference_wrapper<Particle>> &neighbours);
368
374 void setDiagonalNeighbours(const std::vector<std::reference_wrapper<Particle>> &neighbours);
375
381 void setThermalMotion(const std::array<double, 3> &new_thermal_motion);
382
388 void setF(const std::array<double, 3> &new_f);
389
395 void setOldF(const std::array<double, 3> &new_old_f);
396
399
408 void setM(double new_m);
409
415 void setType(double new_type);
416
422 void setEpsilon(double new_eps);
423
429 void setSigma(double new_sigma);
430
436 void setK(double new_k);
437
443 void setFZUP(double new_fzup);
444
450 void setR0(double new_r_0);
451
459 void setCellIndex(int new_index);
460
463
469 std::string toString() const;
470
478 bool operator==(const Particle &other) const;
479
487 bool operator!=(const Particle &other) const;
488};
489
497std::ostream &operator<<(std::ostream &stream, const Particle &p);
Helper class for systems that may not have OpenMP functionality.
int omp_lock_t
Definition OMPWrapper.h:22
#define TYPE_DEFAULT
Definition Particle.h:18
std::ostream & operator<<(std::ostream &stream, const Particle &p)
Overload of the << operator for output streams, used primarily with string streams or console output.
#define K_DEFAULT
Definition Particle.h:21
#define FZUP_DEFAULT
Definition Particle.h:23
#define EPSILON_DEFAULT
Definition Particle.h:20
#define R0_DEFAULT
Definition Particle.h:22
#define SIGMA_DEFAULT
Definition Particle.h:19
Particle class modeling a particle's position, velocity, force, mass and type.
Definition Particle.h:46
std::array< double, 3 > x
Position of the particle.
Definition Particle.h:49
virtual ~Particle()
Destroys the Particle object.
double epsilon
Depth of the potential well. Lennard-Jones parameter.
Definition Particle.h:76
std::array< double, 3 > v
Velocity of the particle.
Definition Particle.h:52
bool operator==(const Particle &other) const
Overload of the equality operator for Particle objects.
void setK(double new_k)
Sets the new stiffness constant to a given value.
double getSigma() const
Gets the Lennard-Jones parameter of the particle.
Definition Particle.h:292
void setR0(double new_r_0)
Sets the new average bond length to a given value.
bool isActive() const
Checks if the particle is currently active.
Definition Particle.h:330
const std::array< double, 3 > & getThermalMotion() const
Gets the thermal motion of this particle (const).
Definition Particle.h:250
void setFZUP(double new_fzup)
Sets the new upward force to a given value.
void setV(const std::array< double, 3 > &new_v)
Sets the new velocity of the particle to a given value.
void setDirectNeighbours(const std::vector< std::reference_wrapper< Particle > > &neighbours)
Sets the direct neighbours of the particle.
double getK() const
Gets the stiffness constant .
Definition Particle.h:299
Particle(const Particle &other)
Construct a new Particle object using another Particle's data.
const std::array< double, 3 > & getOldF() const
Gets the force previously effective on this particle (const).
Definition Particle.h:264
int type
Type of the particle. 1 if wall, 0 otherwise.
Definition Particle.h:73
Particle(const std::array< double, 3 > &x, const std::array< double, 3 > &v, const std::array< double, 3 > &f, const std::array< double, 3 > &old_f, double m, int type, double eps, double sigma, double k, double r_0, double fzup, int cellIndex)
Construct a new Particle object using explicit values for every data field.
std::string toString() const
Returns a string representation of this particle.
int getId() const
Get the ID of this particle.
Definition Particle.h:339
double getFZUP() const
Gets the constant upward force .
Definition Particle.h:313
std::vector< std::reference_wrapper< Particle > > direct_neighbours
Direct (up-down, left-right) neighbours of the particle (for membranes).
Definition Particle.h:64
std::array< double, 3 > & getX()
Gets the position of this particle.
Definition Particle.h:176
int id
A unique ID for this particle. Currently only used for debug purposes.
Definition Particle.h:106
double r_0
The average bond length for membrane simulations.
Definition Particle.h:85
void setX(const std::array< double, 3 > &new_x)
Sets the new position of the particle to a given value.
void markInactive()
Sets the Particle's active status to "inactive".
void setDiagonalNeighbours(const std::vector< std::reference_wrapper< Particle > > &neighbours)
Sets the diagonal neighbours of the particle.
double k
The stiffness constant for membrane simulations.
Definition Particle.h:82
Particle(const std::array< double, 3 > &x, const std::array< double, 3 > &v, double m, int type=TYPE_DEFAULT, double eps=EPSILON_DEFAULT, double sigma=SIGMA_DEFAULT, double k=K_DEFAULT, double r_0=R0_DEFAULT, double fzup=FZUP_DEFAULT)
Construct a new Particle object using explicit values for each new data field.
bool active
The status of the particle.
Definition Particle.h:103
const std::array< double, 3 > & getF() const
Gets the force effective on this particle (const).
Definition Particle.h:257
void setEpsilon(double new_eps)
Sets the new Lennard-Jones parameter of the particle to a given value.
std::array< double, 3 > f
Force effective on this particle.
Definition Particle.h:58
omp_lock_t lock
A mutual exclusion lock, used alongside parallelization.
Definition Particle.h:94
omp_lock_t & getLock()
Get a reference to the Lock object.
Definition Particle.h:346
int getType() const
Gets the type of the particle.
Definition Particle.h:278
Particle(int type=0)
Construct a new Particle object by optionally passing its type. Prevents implicit conversions.
void setOldF(const std::array< double, 3 > &new_old_f)
Sets the new previously effective force on the particle to a given value.
void setType(double new_type)
Sets the new type of the particle to a given value.
std::array< double, 3 > old_f
Force which was effective on this particle.
Definition Particle.h:61
double getR0() const
Gets the average bond length of a molecule pair .
Definition Particle.h:306
void setFToZero()
Resets the force of the particle to 0,0,0.
const std::vector< std::reference_wrapper< Particle > > & getDiagonalNeighbours() const
Gets the diagonal neighbours of this particle (const).
Definition Particle.h:227
void setM(double new_m)
Sets the new mass of the particle to a given value.
const std::vector< std::reference_wrapper< Particle > > & getDirectNeighbours() const
Gets the direct neighbours of this particle (const).
Definition Particle.h:211
void setThermalMotion(const std::array< double, 3 > &new_thermal_motion)
Sets the new thermal motion of the particle to a given value.
double fzup
The constant upward force for membrane simulations.
Definition Particle.h:88
std::array< double, 3 > & getV()
Gets the velocity of this particle.
Definition Particle.h:183
double getM() const
Gets the mass of the particle.
Definition Particle.h:271
double sigma
Distance where the Lennard-Jones potential reaches zero. Lennard-Jones parameter.
Definition Particle.h:79
bool operator!=(const Particle &other) const
Overload of the inequality operator for Particle objects.
std::array< double, 3 > thermal_motion
Thermal motion of the particle.
Definition Particle.h:55
std::vector< std::reference_wrapper< Particle > > diagonal_neighbours
Diagonal neighbours of the particle (for membranes).
Definition Particle.h:67
std::array< double, 3 > & getOldF()
Gets the force previously effective on this particle.
Definition Particle.h:197
void setSigma(double new_sigma)
Sets the new Lennard-Jones parameter of the particle to a given value.
void setCellIndex(int new_index)
Sets the new index in a CellContainer.
double getEpsilon() const
Gets the Lennard-Jones parameter of the particle.
Definition Particle.h:285
int getCellIndex() const
Get the index of the particle in a CellContainer.
Definition Particle.h:322
const std::array< double, 3 > & getX() const
Gets the position of this particle (const).
Definition Particle.h:236
std::vector< std::reference_wrapper< Particle > > & getDiagonalNeighbours()
Gets the diagonal neighbours of this particle.
Definition Particle.h:220
int cellIndex
The cell index of the particle, to be used with the linked cell method.
Definition Particle.h:91
double m
Mass of this particle.
Definition Particle.h:70
std::array< double, 3 > & getF()
Gets the force effective on this particle.
Definition Particle.h:190
void setF(const std::array< double, 3 > &new_f)
Sets the new force effective on the particle to a given value.
std::vector< std::reference_wrapper< Particle > > & getDirectNeighbours()
Gets the direct neighbours of this particle.
Definition Particle.h:204
const std::array< double, 3 > & getV() const
Gets the velocity of this particle (const).
Definition Particle.h:243
Enumeration class corresponding to the type schema type.
Definition vtk-unstructured.h:2125