Molecular Dynamics Simulation  1.0
Public Member Functions | Private Attributes | List of all members
Particle Class Reference

Class to represent a particle. More...

#include <Particle.h>

Collaboration diagram for Particle:
Collaboration graph

Public Member Functions

 Particle (const Particle &other)
 
 Particle (std::array< double, 3 > x_arg, std::array< double, 3 > v_arg, double m_arg, int type=0, double epsilon_arg=1.0, double sigma_arg=1.2, LockState lock_state=LockState::UNLOCKED)
 
 Particle (std::array< double, 3 > x_arg, std::array< double, 3 > v_arg, std::array< double, 3 > f_arg, std::array< double, 3 > old_f_arg, double m_arg, int type=0, double epsilon_arg=1.0, double sigma_arg=1.2, LockState lock_state=LockState::UNLOCKED)
 
virtual ~Particle ()
 
Particleoperator= (const Particle &other)
 
void setX (const std::array< double, 3 > &x)
 Sets the position of the particle. More...
 
void setV (const std::array< double, 3 > &v)
 Sets the velocity of the particle. More...
 
void setF (const std::array< double, 3 > &f)
 Sets the force of the particle. More...
 
void addF (const std::array< double, 3 > &force)
 Adds a force to the particle. More...
 
void subF (const std::array< double, 3 > &force)
 Subtracts a force from the particle. More...
 
void setOldF (const std::array< double, 3 > &oldF)
 Sets the old force of the particle. More...
 
const std::array< double, 3 > & getX () const
 Gets the position of the particle. More...
 
const std::array< double, 3 > & getV () const
 Gets the velocity of the particle. More...
 
const std::array< double, 3 > & getF () const
 Gets the total force of the particle. More...
 
const std::array< double, 3 > & getOldF () const
 Gets the old total force of the particle. More...
 
double getM () const
 Gets the mass of the particle. More...
 
int getType () const
 Gets the type of the particle. More...
 
double getEpsilon () const
 Gets the Lennard-Jones potential parameter epsilon. More...
 
double getSigma () const
 Gets the Lennard-Jones potential parameter sigma. More...
 
void setLocked (LockState new_lock_state)
 Set wheter the particle is locked in space. More...
 
bool isLocked () const
 Gets whether the particle is locked in space. More...
 
const std::vector< std::tuple< long, double, double > > & getConnectedParticles () const
 Gets the list of connected particles. More...
 
void addConnectedParticle (long ptr_diff, double l_0, double k)
 Adds a connected particle. More...
 
bool operator== (Particle &other)
 
bool operator== (const Particle &other) const
 
std::string toString () const
 

Private Attributes

std::array< double, 3 > x {}
 Position of the particle. More...
 
std::array< double, 3 > v {}
 Velocity of the particle. More...
 
std::array< double, 3 > f {}
 Force effective on this particle. More...
 
std::array< double, 3 > old_f {}
 Force which was effective on this particle. More...
 
double m
 Mass of this particle. More...
 
int type
 Type of the particle. Use it for whatever you want (e.g. to separate molecules belonging to different bodies, matters, and so on) More...
 
double epsilon
 Lennard-Jones potential parameter epsilon. More...
 
double sigma
 Lennard-Jones potential parameter sigma. More...
 
LockState lock_state
 Wheter the particle is loccked in space. More...
 
std::vector< std::tuple< long, double, double > > connected_particles
 List of connected particles. More...
 

Detailed Description

Class to represent a particle.

Particle.h

Created on: 23.02.2010 Author: eckhardw

Class to represent a particle. A particle has a position, a velocity, a mass and a type. Additionally, the current and previous force exerted on the particle is stored.

Definition at line 26 of file Particle.h.

Constructor & Destructor Documentation

◆ Particle() [1/3]

Particle::Particle ( const Particle other)

Particle.cpp

Created on: 23.02.2010 Author: eckhardw

Definition at line 15 of file Particle.cpp.

15  {
16  x = other.x;
17  v = other.v;
18  f = other.f;
19  old_f = other.old_f;
20  m = other.m;
21  type = other.type;
22  epsilon = other.epsilon;
23  sigma = other.sigma;
24  lock_state = other.lock_state;
26  Logger::logger->debug("Particle created");
27 }
static std::shared_ptr< spdlog::logger > logger
Publically accessible shared pointer to the logger.
Definition: Logger.h:35
std::array< double, 3 > x
Position of the particle.
Definition: Particle.h:31
double epsilon
Lennard-Jones potential parameter epsilon.
Definition: Particle.h:62
std::array< double, 3 > v
Velocity of the particle.
Definition: Particle.h:36
int type
Type of the particle. Use it for whatever you want (e.g. to separate molecules belonging to different...
Definition: Particle.h:57
std::array< double, 3 > f
Force effective on this particle.
Definition: Particle.h:41
std::array< double, 3 > old_f
Force which was effective on this particle.
Definition: Particle.h:46
double sigma
Lennard-Jones potential parameter sigma.
Definition: Particle.h:67
LockState lock_state
Wheter the particle is loccked in space.
Definition: Particle.h:72
double m
Mass of this particle.
Definition: Particle.h:51
std::vector< std::tuple< long, double, double > > connected_particles
List of connected particles.
Definition: Particle.h:89

◆ Particle() [2/3]

Particle::Particle ( std::array< double, 3 >  x_arg,
std::array< double, 3 >  v_arg,
double  m_arg,
int  type = 0,
double  epsilon_arg = 1.0,
double  sigma_arg = 1.2,
LockState  lock_state = LockState::UNLOCKED 
)

Definition at line 29 of file Particle.cpp.

30  {
31  x = x_arg;
32  v = v_arg;
33  m = m_arg;
34  type = type_arg;
35  f = {0., 0., 0.};
36  epsilon = epsilon_arg;
37  sigma = sigma_arg;
38  lock_state = lock_state_arg;
39  old_f = {0., 0., 0.};
40  Logger::logger->debug("Particle created");
41 }

◆ Particle() [3/3]

Particle::Particle ( std::array< double, 3 >  x_arg,
std::array< double, 3 >  v_arg,
std::array< double, 3 >  f_arg,
std::array< double, 3 >  old_f_arg,
double  m_arg,
int  type = 0,
double  epsilon_arg = 1.0,
double  sigma_arg = 1.2,
LockState  lock_state = LockState::UNLOCKED 
)

Definition at line 43 of file Particle.cpp.

44  {
45  x = x_arg;
46  v = v_arg;
47  f = f_arg;
48  old_f = old_f_arg;
49  m = m_arg;
50  type = type_arg;
51  epsilon = epsilon_arg;
52  sigma = sigma_arg;
53  lock_state = lock_state_arg;
54  Logger::logger->debug("Particle created");
55 }

◆ ~Particle()

Particle::~Particle ( )
virtual

Definition at line 57 of file Particle.cpp.

57 { Logger::logger->debug("Particle destroyed"); }

Member Function Documentation

◆ addConnectedParticle()

void Particle::addConnectedParticle ( long  ptr_diff,
double  l_0,
double  k 
)

Adds a connected particle.

Parameters
ptr_diff
l_0Prefered distance between the particles
kSpring constant

Definition at line 74 of file Particle.cpp.

74 { connected_particles.push_back({ptr_diff, l_0, k}); }

◆ addF()

void Particle::addF ( const std::array< double, 3 > &  force)
inline

Adds a force to the particle.

Parameters
forceForce to be added

Definition at line 129 of file Particle.h.

129  {
130 #if PARALLEL_V2
131  std::lock_guard lock(mutex_f);
132 #endif
133  f = f + force;
134  }

◆ getConnectedParticles()

const std::vector<std::tuple<long, double, double> >& Particle::getConnectedParticles ( ) const
inline

Gets the list of connected particles.

Definition at line 207 of file Particle.h.

207 { return connected_particles; }

◆ getEpsilon()

double Particle::getEpsilon ( ) const
inline

Gets the Lennard-Jones potential parameter epsilon.

Definition at line 187 of file Particle.h.

187 { return epsilon; }

◆ getF()

const std::array<double, 3>& Particle::getF ( ) const
inline

Gets the total force of the particle.

Definition at line 167 of file Particle.h.

167 { return f; }

◆ getM()

double Particle::getM ( ) const
inline

Gets the mass of the particle.

Definition at line 177 of file Particle.h.

177 { return m; }

◆ getOldF()

const std::array<double, 3>& Particle::getOldF ( ) const
inline

Gets the old total force of the particle.

Definition at line 172 of file Particle.h.

172 { return old_f; }

◆ getSigma()

double Particle::getSigma ( ) const
inline

Gets the Lennard-Jones potential parameter sigma.

Definition at line 192 of file Particle.h.

192 { return sigma; }

◆ getType()

int Particle::getType ( ) const
inline

Gets the type of the particle.

Definition at line 182 of file Particle.h.

182 { return type; }

◆ getV()

const std::array<double, 3>& Particle::getV ( ) const
inline

Gets the velocity of the particle.

Definition at line 162 of file Particle.h.

162 { return v; }

◆ getX()

const std::array<double, 3>& Particle::getX ( ) const
inline

Gets the position of the particle.

Definition at line 157 of file Particle.h.

157 { return x; }

◆ isLocked()

bool Particle::isLocked ( ) const
inline

Gets whether the particle is locked in space.

Definition at line 202 of file Particle.h.

202 { return lock_state == LockState::LOCKED; }

◆ operator=()

Particle & Particle::operator= ( const Particle other)

Definition at line 59 of file Particle.cpp.

59  {
60  x = other.x;
61  v = other.v;
62  f = other.f;
63  old_f = other.old_f;
64  m = other.m;
65  type = other.type;
66  epsilon = other.epsilon;
67  sigma = other.sigma;
68  lock_state = other.lock_state;
70  Logger::logger->debug("Particle created");
71  return *this;
72 }

◆ operator==() [1/2]

bool Particle::operator== ( const Particle other) const

Definition at line 86 of file Particle.cpp.

86  {
87  return (x == other.x) and (v == other.v) and (f == other.f) and (type == other.type) and (m == other.m) and (old_f == other.old_f);
88 }

◆ operator==() [2/2]

bool Particle::operator== ( Particle other)

Definition at line 82 of file Particle.cpp.

82  {
83  return (x == other.x) and (v == other.v) and (f == other.f) and (type == other.type) and (m == other.m) and (old_f == other.old_f);
84 }

◆ setF()

void Particle::setF ( const std::array< double, 3 > &  f)
inline

Sets the force of the particle.

Parameters
fNew force

Definition at line 123 of file Particle.h.

123 { this->f = f; }

◆ setLocked()

void Particle::setLocked ( LockState  new_lock_state)
inline

Set wheter the particle is locked in space.

Definition at line 197 of file Particle.h.

197 { lock_state = new_lock_state; }

◆ setOldF()

void Particle::setOldF ( const std::array< double, 3 > &  oldF)
inline

Sets the old force of the particle.

Parameters
oldFNew old force

Definition at line 152 of file Particle.h.

152 { old_f = oldF; }

◆ setV()

void Particle::setV ( const std::array< double, 3 > &  v)
inline

Sets the velocity of the particle.

Parameters
vNew velocity

Definition at line 116 of file Particle.h.

116 { this->v = v; }

◆ setX()

void Particle::setX ( const std::array< double, 3 > &  x)
inline

Sets the position of the particle.

Parameters
xNew position

Definition at line 109 of file Particle.h.

109 { this->x = x; }

◆ subF()

void Particle::subF ( const std::array< double, 3 > &  force)
inline

Subtracts a force from the particle.

Parameters
forceForce to be subtracted

Definition at line 140 of file Particle.h.

140  {
141 #if PARALLEL_V2
142  std::lock_guard lock(mutex_f);
143 #endif
144  f = f - force;
145  }

◆ toString()

std::string Particle::toString ( ) const

Definition at line 76 of file Particle.cpp.

76  {
77  std::stringstream stream;
78  stream << "Particle: X:" << x << " v: " << v << " f: " << f << " old_f: " << old_f << " type: " << type;
79  return stream.str();
80 }

Member Data Documentation

◆ connected_particles

std::vector<std::tuple<long, double, double> > Particle::connected_particles
private

List of connected particles.

List of connected particles. Each entry is a tuple of a weak pointer to the connected particle, and the prefered distance between the the particles and the spring constant. The prefered distance is the distance at which the spring force is zero.

entry = (ptr_diff, l_0, k)

Definition at line 89 of file Particle.h.

◆ epsilon

double Particle::epsilon
private

Lennard-Jones potential parameter epsilon.

Definition at line 62 of file Particle.h.

◆ f

std::array<double, 3> Particle::f {}
private

Force effective on this particle.

Definition at line 41 of file Particle.h.

◆ lock_state

LockState Particle::lock_state
private

Wheter the particle is loccked in space.

Definition at line 72 of file Particle.h.

◆ m

double Particle::m
private

Mass of this particle.

Definition at line 51 of file Particle.h.

◆ old_f

std::array<double, 3> Particle::old_f {}
private

Force which was effective on this particle.

Definition at line 46 of file Particle.h.

◆ sigma

double Particle::sigma
private

Lennard-Jones potential parameter sigma.

Definition at line 67 of file Particle.h.

◆ type

int Particle::type
private

Type of the particle. Use it for whatever you want (e.g. to separate molecules belonging to different bodies, matters, and so on)

Definition at line 57 of file Particle.h.

◆ v

std::array<double, 3> Particle::v {}
private

Velocity of the particle.

Definition at line 36 of file Particle.h.

◆ x

std::array<double, 3> Particle::x {}
private

Position of the particle.

Definition at line 31 of file Particle.h.


The documentation for this class was generated from the following files: