Molecular Dynamics  v0.4
Project for the Practical hosted by the Scientific Computing Chair
Public Member Functions | Protected Member Functions | Protected Attributes | Private Attributes | Friends | List of all members
Model Class Referenceabstract

Abstract base class for any model for molecule simulation. More...

#include <Model.h>

Inheritance diagram for Model:
Inheritance graph
Collaboration diagram for Model:
Collaboration graph

Public Member Functions

virtual ~Model ()=default
 Virtual default constructor to guarantee appropriate memory clean up. More...
 
void plot (int iteration, std::string &baseName)
 Write current state of the model to a file. More...
 
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. More...
 
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. More...
 
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. More...
 
void addParticle (Particle &p)
 Add a single particle to this model. More...
 
void addViaFile (std::string &filepath, FileHandler::inputFormat inputFormat)
 Add new particles / particle structures to the model via a file. More...
 
void saveState ()
 Export the current state of all molecules to a txt file for using them in a new simulation. More...
 
void updateForces () const
 Helper method to calculate the force between all particles. More...
 
virtual void step (int iteration)=0
 Perform one single step in the simulation. More...
 
ParticleContainergetParticles () const
 Get the Particles of this model. More...
 
virtual void initializeForces ()=0
 Calculate forces at the beginning of the simulation that the old force is not 0. More...
 

Protected Member Functions

 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, because this class is a base class and should not be instantiated. More...
 
void updatePositions () const
 Helper method to calculate the position of all particles. More...
 
void updateVelocities () const
 Helper method to calculate the velocity of all particles. More...
 
void applyGravity ()
 Add a gravitational force of g * m along the y-axis to each particle inside the simulation domain. More...
 

Protected Attributes

ParticleContainerparticles
 
Forceforce
 
double deltaT
 
bool gravityOn
 
std::array< double, 3 > g
 

Private Attributes

FileHandler fileHandler
 
FileHandler::outputFormat outputFormat
 

Friends

class DefaultThermostat
 
class Thermostat
 
class FlowThermostat
 

Detailed Description

Abstract base class for any model for molecule simulation.

Each specific model should extend this class. At the moment there are two different models: -Direct Sum -Linked Cells

Constructor & Destructor Documentation

◆ Model()

Model::Model ( ParticleContainer particles,
Force force,
double  deltaT,
FileHandler::outputFormat  outputFormat,
bool  gravityOn,
std::array< double, 3 >  g = {} 
)
protected

Constructor for this model. Cannot be called from any other class but classes that extend this class, because this class is a base class and should not be instantiated.

Parameters
particlesParticle container of the model. This parameter is instantiated with the appropriated container by the derived models.
forceForce to use in the simulation.
deltaTDuration of one time step. Small time step will result in a better simulation, but will demand more computational resources.
outputFormatFormat of the output file. Supported formats are vtk and xyz.
gravityOnToggle gravtiy on or of
gGravity factor

◆ ~Model()

virtual Model::~Model ( )
virtualdefault

Virtual default constructor to guarantee appropriate memory clean up.

Member Function Documentation

◆ addCuboid()

void Model::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.

Parameters
positionThe coordinates of the lower left front-side corner.
N1Number of particles in dimension N1.
N2Number of particles in dimension N2.
N3Number of particles in dimension N3.
hDistance of the particles (mesh width of the grid).
massMass of one particle.
initVelocityInitial velocity of the of the particles.
dimensionsNumber of dimensions to which the Brownian Motion will be added. Valid values are 0, 1, 2 and 3.
brownianMotionAverageVelocity
epsilonLeonard Jones parameter epsilon
sigmaLeonard Jones parameter sigma
fixedFix particles.
Here is the call graph for this function:

◆ addDisc()

void Model::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.

Parameters
centerThe coordinates of the center of the disc.
initVelocityInitial velocity of the of the particles.
NNumber of particles along the radius, including the particle in the center.
hDistance of the particles (mesh width of the grid).
massMass of one particle.
dimensionsNumber of dimensions to which the Brownian Motion will be added. Valid values are 0, 1, 2 and 3.
brownianMotionAverageVelocityConstant, specifying the average velocity of the Brownian Motion.
epsilonLeonard Jones parameter epsilon
sigmaLeonard Jones parameter sigma
fixedFix particles.
Here is the call graph for this function:

◆ addParticle()

void Model::addParticle ( Particle p)

Add a single particle to this model.

Parameters
pParticle to add to this model.
Here is the call graph for this function:

◆ addSphere()

void Model::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.

Parameters
centerThe coordinates of the center of the disc.
initVelocityInitial velocity of the of the particles.
NNumber of particles along the radius, including the particle in the center.
hDistance of the particles (mesh width of the grid).
massMass of one particle.
dimensionsNumber of dimensions to which the Brownian Motion will be added. Valid values are 0, 1, 2 and 3.
brownianMotionAverageVelocityConstant, specifying the average velocity of the Brownian Motion.
epsilonLeonard Jones parameter epsilon
sigmaLeonard Jones parameter sigma
fixedFix particles.
Here is the call graph for this function:

◆ addViaFile()

void Model::addViaFile ( std::string &  filepath,
FileHandler::inputFormat  inputFormat 
)

Add new particles / particle structures to the model via a file.

Parameters
filepathPath to the file. Example: ../input/eingabe-sonne.txt
inputFormatFormat of the input file (txt, xml)
Here is the call graph for this function:

◆ applyGravity()

void Model::applyGravity ( )
protected

Add a gravitational force of g * m along the y-axis to each particle inside the simulation domain.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getParticles()

ParticleContainer& Model::getParticles ( ) const
inline

Get the Particles of this model.

Returns
Particles stored in this model.

Should be only used for testing purposes.

◆ initializeForces()

virtual void Model::initializeForces ( )
pure virtual

Calculate forces at the beginning of the simulation that the old force is not 0.

Implemented in LinkedCells, and DirectSum.

◆ plot()

void Model::plot ( int  iteration,
std::string &  baseName 
)

Write current state of the model to a file.

Parameters
iterationCurrent iteration.
baseNameBase name of the output file.
Here is the call graph for this function:

◆ saveState()

void Model::saveState ( )

Export the current state of all molecules to a txt file for using them in a new simulation.

Here is the call graph for this function:

◆ step()

virtual void Model::step ( int  iteration)
pure virtual

Perform one single step in the simulation.

@parameter Current iteration the simulator is in.

Each step consists of force, velocity and position updates. For each concrete model the exact implementation might differ.

Implemented in LinkedCells, and DirectSum.

◆ updateForces()

void Model::updateForces ( ) const

Helper method to calculate the force between all particles.

After each time step the forces acting between the particles have changed due to their new positions, so they have to be recalculated. This method uses Newtons third law of motion to simplify calculations and make them more efficient.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ updatePositions()

void Model::updatePositions ( ) const
protected

Helper method to calculate the position of all particles.

After each time step positions of all particles with velocities unequal to zero have to be updated.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ updateVelocities()

void Model::updateVelocities ( ) const
protected

Helper method to calculate the velocity of all particles.

After each time step the velocity of each particle may have changed due to forces that act between the particles.

Here is the call graph for this function:
Here is the caller graph for this function:

Friends And Related Function Documentation

◆ DefaultThermostat

friend class DefaultThermostat
friend

◆ FlowThermostat

friend class FlowThermostat
friend

◆ Thermostat

friend class Thermostat
friend

Member Data Documentation

◆ deltaT

double Model::deltaT
protected

◆ fileHandler

FileHandler Model::fileHandler
private

◆ force

Force& Model::force
protected

◆ g

std::array<double, 3> Model::g
protected

◆ gravityOn

bool Model::gravityOn
protected

◆ outputFormat

FileHandler::outputFormat Model::outputFormat
private

◆ particles

ParticleContainer& Model::particles
protected

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