Molecular Dynamics Simulation  1.0
Public Member Functions | Static Public Member Functions | Protected Attributes | List of all members
Thermostat Class Referenceabstract

A thermostat that can be used to control the temperature of a particle container. Allows for gradual scaling of the temperature towards a set target. More...

#include <Thermostat.h>

Inheritance diagram for Thermostat:
Inheritance graph
Collaboration diagram for Thermostat:
Collaboration graph

Public Member Functions

 Thermostat (double target_temperature, double max_temperature_change, ThirdDimension third_dimension)
 Construct a new Thermostat object. More...
 
virtual ~Thermostat ()=default
 Destroy the Thermostat object. More...
 
virtual void scaleTemperature (const std::unique_ptr< ParticleContainer > &particle_container) const =0
 Scale the temperature of a particle container towards the target temperature. Capped by the maximum temperature change. More...
 
virtual double getCurrentContainerTemperature (const std::unique_ptr< ParticleContainer > &particle_container) const =0
 Get the current temperature of a particle container. More...
 
void setTemperature (double new_temperature, const std::unique_ptr< ParticleContainer > &particle_container)
 Set the initial temperature of a particle container. This function sets the velocity of all particles in the container to a random value according to the Maxwell-Boltzmann distribution (all previous velocities are discarded). Use this function for systems with no initial velocity. More...
 
double getTargetTemperature () const
 Get the target temperature of the thermostat. More...
 
double getMaxTemperatureChange () const
 Get the maximum temperature change of the thermostat. More...
 
ThirdDimension getThirdDimension () const
 Get if the third dimension is enabled on this thermostat or not. More...
 

Static Public Member Functions

static void setParticleTemperature (double new_temperature, Particle &particle, ThirdDimension third_dimension)
 Set the temperature of a particle. This method adds a random velocity to the particle according to the Maxwell-Boltzmann distribution. This function can be used for particle generators since previous velocities are not discarded. More...
 

Protected Attributes

const double target_temperature
 The target temperature for thermostat applications. More...
 
const double max_temperature_change
 The maximum temperature change allowed per thermostat application. More...
 
const ThirdDimension third_dimension
 Defines whether the third dimension is enabled. More...
 

Detailed Description

A thermostat that can be used to control the temperature of a particle container. Allows for gradual scaling of the temperature towards a set target.

Definition at line 13 of file Thermostat.h.

Constructor & Destructor Documentation

◆ Thermostat()

Thermostat::Thermostat ( double  target_temperature,
double  max_temperature_change,
ThirdDimension  third_dimension 
)
explicit

Construct a new Thermostat object.

Parameters
target_temperatureThe target temperature for thermostat applications.
max_temperature_changeThe maximum temperature change allowed per thermostat application.
third_dimensionWether the third dimension is enabled or not.

Definition at line 7 of file Thermostat.cpp.

9  if (target_temperature < 0) {
10  Logger::logger->error("Target temperature must be positive");
11  throw std::runtime_error("Target temperature must be positive");
12  }
13 
14  if (max_temperature_change < 0) {
15  Logger::logger->error("Max temperature change must be an absolute value (positive)");
16  throw std::runtime_error("Max temperature change must be an absolute value (positive)");
17  }
18 }
static std::shared_ptr< spdlog::logger > logger
Publically accessible shared pointer to the logger.
Definition: Logger.h:35
const double max_temperature_change
The maximum temperature change allowed per thermostat application.
Definition: Thermostat.h:94
const double target_temperature
The target temperature for thermostat applications.
Definition: Thermostat.h:89
const ThirdDimension third_dimension
Defines whether the third dimension is enabled.
Definition: Thermostat.h:99

◆ ~Thermostat()

virtual Thermostat::~Thermostat ( )
virtualdefault

Destroy the Thermostat object.

Member Function Documentation

◆ getCurrentContainerTemperature()

virtual double Thermostat::getCurrentContainerTemperature ( const std::unique_ptr< ParticleContainer > &  particle_container) const
pure virtual

Get the current temperature of a particle container.

Parameters
particle_containerThe particle container to get the temperature of.
Returns
double The current temperature of the particle container.

Implemented in RelativeThermostat, and AbsoluteThermostat.

◆ getMaxTemperatureChange()

double Thermostat::getMaxTemperatureChange ( ) const

Get the maximum temperature change of the thermostat.

Returns
double The maximum temperature change of the thermostat.

Definition at line 36 of file Thermostat.cpp.

36 { return max_temperature_change; }

◆ getTargetTemperature()

double Thermostat::getTargetTemperature ( ) const

Get the target temperature of the thermostat.

Returns
double The target temperature of the thermostat.

Definition at line 34 of file Thermostat.cpp.

34 { return target_temperature; }

◆ getThirdDimension()

ThirdDimension Thermostat::getThirdDimension ( ) const

Get if the third dimension is enabled on this thermostat or not.

Returns
ThirdDimension

Definition at line 38 of file Thermostat.cpp.

38 { return third_dimension; }

◆ scaleTemperature()

virtual void Thermostat::scaleTemperature ( const std::unique_ptr< ParticleContainer > &  particle_container) const
pure virtual

Scale the temperature of a particle container towards the target temperature. Capped by the maximum temperature change.

Parameters
particle_containerThe particle container to scale the temperature of.

Implemented in RelativeThermostat, and AbsoluteThermostat.

◆ setParticleTemperature()

void Thermostat::setParticleTemperature ( double  new_temperature,
Particle particle,
ThirdDimension  third_dimension 
)
static

Set the temperature of a particle. This method adds a random velocity to the particle according to the Maxwell-Boltzmann distribution. This function can be used for particle generators since previous velocities are not discarded.

Parameters
new_temperatureThe new temperature of the particle.
particleThe particle to set the initial temperature of.
third_dimensionWether the third dimension is enabled or not.

Definition at line 20 of file Thermostat.cpp.

20  {
21  size_t dimension_count = third_dimension == ThirdDimension::ENABLED ? 3 : 2;
22 
23  particle.setV(particle.getV() + maxwellBoltzmannDistributedVelocity(std::sqrt(new_temperature / particle.getM()), dimension_count));
24 }
std::array< double, 3 > maxwellBoltzmannDistributedVelocity(double averageVelocity, size_t dimensions)
const std::array< double, 3 > & getV() const
Gets the velocity of the particle.
Definition: Particle.h:162
double getM() const
Gets the mass of the particle.
Definition: Particle.h:177
void setV(const std::array< double, 3 > &v)
Sets the velocity of the particle.
Definition: Particle.h:116

◆ setTemperature()

void Thermostat::setTemperature ( double  new_temperature,
const std::unique_ptr< ParticleContainer > &  particle_container 
)

Set the initial temperature of a particle container. This function sets the velocity of all particles in the container to a random value according to the Maxwell-Boltzmann distribution (all previous velocities are discarded). Use this function for systems with no initial velocity.

Parameters
new_temperatureThe new temperature of the particle container.
particle_containerThe particle container to set the initial temperature of.

Definition at line 26 of file Thermostat.cpp.

26  {
27  size_t dimension_count = third_dimension == ThirdDimension::ENABLED ? 3 : 2;
28 
29  for (auto& particle : *particle_container) {
30  particle.setV(maxwellBoltzmannDistributedVelocity(std::sqrt(new_temperature / particle.getM()), dimension_count));
31  }
32 }

Member Data Documentation

◆ max_temperature_change

const double Thermostat::max_temperature_change
protected

The maximum temperature change allowed per thermostat application.

Definition at line 94 of file Thermostat.h.

◆ target_temperature

const double Thermostat::target_temperature
protected

The target temperature for thermostat applications.

Definition at line 89 of file Thermostat.h.

◆ third_dimension

const ThirdDimension Thermostat::third_dimension
protected

Defines whether the third dimension is enabled.

Definition at line 99 of file Thermostat.h.


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