Molecular Dynamics  v0.4
Project for the Practical hosted by the Scientific Computing Chair
Model.h
Go to the documentation of this file.
1 //
2 // Created by daniel on 22.05.24.
3 //
4 
5 #pragma once
9 
17 class Model {
18  //Thermostats need direct access to the model to meassure and regulate the temperature of the particles.
19  friend class DefaultThermostat;
20  friend class Thermostat;
21  friend class FlowThermostat;
22 
23 private:
26 
27 protected:
30  double deltaT;
31  bool gravityOn;
32  std::array<double, 3> g;
33 
46  bool gravityOn, std::array<double, 3> g = {});
47 
54  void updatePositions() const;
55 
62  void updateVelocities() const;
63 
67  void applyGravity();
68 
69 public:
73  virtual ~Model() = default;
74 
81  void plot(int iteration, std::string &baseName);
82 
99  void addCuboid(const std::array<double, 3> &position, unsigned N1, unsigned N2, unsigned N3, double h, double mass,
100  const std::array<double, 3> &initVelocity, int dimensions, double brownianMotionAverageVelocity,
101  double epsilon = 5, double sigma = 1, bool fixed = false);
102 
117  void addDisc(const std::array<double, 3> &center,
118  const std::array<double, 3> &initVelocity, int N, double h, double mass, int dimensions,
119  double brownianMotionAverageVelocity, double epsilon = 5, double sigma = 1, bool fixed = false);
120 
135  void addSphere(const std::array<double, 3> &center, const std::array<double, 3> &initVelocity, int N, double h,
136  double mass, int dimensions, double brownianMotionAverageVelocity, double epsilon = 5, double sigma = 1,
137  bool fixed = false);
138 
145  void addParticle(Particle &p);
146 
153  void addViaFile(std::string &filepath, FileHandler::inputFormat inputFormat);
154 
159  void saveState();
160 
169  void updateForces() const;
170 
180  virtual void step(int iteration) = 0;
181 
189  [[nodiscard]] ParticleContainer &getParticles() const {
190  return particles;
191  }
192 
196  virtual void initializeForces() = 0;
197 };
Class for controling the temperature of the simulated system.
Definition: DefaultThermostat.h:11
Wrapper class for file handling.
Definition: FileHandler.h:19
outputFormat
Supported output formats.
Definition: FileHandler.h:31
inputFormat
Supported input formats.
Definition: FileHandler.h:38
Class for controling the temperature of a flow.
Definition: FlowThermostat.h:12
Interface representing the force that the source exerts on the target.
Definition: Force.h:14
Abstract base class for any model for molecule simulation.
Definition: Model.h:17
void updatePositions() const
Helper method to calculate the position of all particles.
Definition: Model.cpp:33
ParticleContainer & particles
Definition: Model.h:28
FileHandler::outputFormat outputFormat
Definition: Model.h:25
void updateForces() const
Helper method to calculate the force between all particles.
Definition: Model.cpp:14
virtual ~Model()=default
Virtual default constructor to guarantee appropriate memory clean up.
void updateVelocities() const
Helper method to calculate the velocity of all particles.
Definition: Model.cpp:41
void plot(int iteration, std::string &baseName)
Write current state of the model to a file.
Definition: Model.cpp:57
void addDisc(const std::array< double, 3 > &center, const std::array< double, 3 > &initVelocity, int N, double h, double mass, int dimensions, double brownianMotionAverageVelocity, double epsilon=5, double sigma=1, bool fixed=false)
Add a 2D disc structure to this model.
Definition: Model.cpp:68
void applyGravity()
Add a gravitational force of g * m along the y-axis to each particle inside the simulation domain.
Definition: Model.cpp:49
std::array< double, 3 > g
Definition: Model.h:32
virtual void step(int iteration)=0
Perform one single step in the simulation.
virtual void initializeForces()=0
Calculate forces at the beginning of the simulation that the old force is not 0.
void addViaFile(std::string &filepath, FileHandler::inputFormat inputFormat)
Add new particles / particle structures to the model via a file.
Definition: Model.cpp:86
bool gravityOn
Definition: Model.h:31
double deltaT
Definition: Model.h:30
void addCuboid(const std::array< double, 3 > &position, unsigned N1, unsigned N2, unsigned N3, double h, double mass, const std::array< double, 3 > &initVelocity, int dimensions, double brownianMotionAverageVelocity, double epsilon=5, double sigma=1, bool fixed=false)
Add a cuboid structure to this model.
Definition: Model.cpp:61
ParticleContainer & getParticles() const
Get the Particles of this model.
Definition: Model.h:189
void addSphere(const std::array< double, 3 > &center, const std::array< double, 3 > &initVelocity, int N, double h, double mass, int dimensions, double brownianMotionAverageVelocity, double epsilon=5, double sigma=1, bool fixed=false)
Add a 3D sphere structure to this model.
Definition: Model.cpp:75
void saveState()
Export the current state of all molecules to a txt file for using them in a new simulation.
Definition: Model.cpp:90
Model(ParticleContainer &particles, Force &force, double deltaT, FileHandler::outputFormat outputFormat, bool gravityOn, std::array< double, 3 > g={})
Constructor for this model. Cannot be called from any other class but classes that extend this class,...
Definition: Model.cpp:8
void addParticle(Particle &p)
Add a single particle to this model.
Definition: Model.cpp:82
Force & force
Definition: Model.h:29
FileHandler fileHandler
Definition: Model.h:24
Class corresponding to the N1 schema type.
Definition: ConfigurationFile.h:10343
Class corresponding to the N2 schema type.
Definition: ConfigurationFile.h:10437
Class corresponding to the N3 schema type.
Definition: ConfigurationFile.h:11829
Definition: ParticleContainer.h:11
Definition: Particle.h:16
Base class for controling the temperature of the simulated system.
Definition: Thermostat.h:13
int dimensions
Definition: Thermostat.h:29
Enumeration class corresponding to the force schema type.
Definition: ConfigurationFile.h:6026
::xsd::cxx::tree::string< char, simple_type > string
C++ type corresponding to the string XML Schema built-in type.
Definition: vtk-unstructured.h:270