Molecular Dynamics Simulation  1.0
Particle.cpp
Go to the documentation of this file.
1 
8 #include "Particle.h"
9 
10 #include <iostream>
11 
12 #include "io/logger/Logger.h"
13 #include "utils/ArrayUtils.h"
14 
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 }
28 
29 Particle::Particle(std::array<double, 3> x_arg, std::array<double, 3> v_arg, double m_arg, int type_arg, double epsilon_arg,
30  double sigma_arg, LockState lock_state_arg) {
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 }
42 
43 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,
44  double m_arg, int type_arg, double epsilon_arg, double sigma_arg, LockState lock_state_arg) {
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 }
56 
57 Particle::~Particle() { Logger::logger->debug("Particle destroyed"); }
58 
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 }
73 
74 void Particle::addConnectedParticle(long ptr_diff, double l_0, double k) { connected_particles.push_back({ptr_diff, l_0, k}); }
75 
76 std::string Particle::toString() const {
77  std::stringstream stream;
78  stream << "Particle: X:" << x << " v: " << v << " f: " << f << " old_f: " << old_f << " type: " << type;
79  return stream.str();
80 }
81 
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 }
85 
86 bool Particle::operator==(const Particle& other) const {
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 }
89 
90 std::ostream& operator<<(std::ostream& stream, Particle& p) {
91  stream << p.toString();
92  return stream;
93 }
LockState
Enum class to define the lockstate of particles. Locked particles are not allowed to move.
Definition: Enums.h:12
std::ostream & operator<<(std::ostream &stream, Particle &p)
Definition: Particle.cpp:90
static std::shared_ptr< spdlog::logger > logger
Publically accessible shared pointer to the logger.
Definition: Logger.h:35
Class to represent a particle.
Definition: Particle.h:26
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
Particle(const Particle &other)
Definition: Particle.cpp:15
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::string toString() const
Definition: Particle.cpp:76
bool operator==(Particle &other)
Definition: Particle.cpp:82
Particle & operator=(const Particle &other)
Definition: Particle.cpp:59
void addConnectedParticle(long ptr_diff, double l_0, double k)
Adds a connected particle.
Definition: Particle.cpp:74
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
virtual ~Particle()
Definition: Particle.cpp:57
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