Molecular Dynamics Simulation  1.0
Public Member Functions | List of all members
AbsoluteThermostat Class Reference

A basic 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 <AbsoluteThermostat.h>

Inheritance diagram for AbsoluteThermostat:
Inheritance graph
Collaboration diagram for AbsoluteThermostat:
Collaboration graph

Public Member Functions

 AbsoluteThermostat (double target_temperature, double max_temperature_change=std::numeric_limits< double >::max(), ThirdDimension third_dimension=ThirdDimension::ENABLED)
 Construct a new Thermostat object. More...
 
void scaleTemperature (const std::unique_ptr< ParticleContainer > &particle_container) const override
 Scale the temperature of a particle container towards the target temperature. Capped by the maximum temperature change. More...
 
double getContainerKineticEnergy (const std::unique_ptr< ParticleContainer > &particle_container) const
 Get the kinetic energy of all particles in a particle container. More...
 
double getCurrentContainerTemperature (const std::unique_ptr< ParticleContainer > &particle_container) const override
 Get the current temperature of a particle container. More...
 
- Public Member Functions inherited from Thermostat
 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...
 
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...
 

Additional Inherited Members

- Static Public Member Functions inherited from Thermostat
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 inherited from Thermostat
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 basic thermostat that can be used to control the temperature of a particle container. Allows for gradual scaling of the temperature towards a set target.

This thermostat is a basic implementation of the Thermostat interface.

This Thermostats is "absolute" in the sense that it does not take the actual velocity of the particles into account when scaling the temperature. It simply freezes the particles until they are no longer moving, even if they have an initial velocity.

Definition at line 18 of file AbsoluteThermostat.h.

Constructor & Destructor Documentation

◆ AbsoluteThermostat()

AbsoluteThermostat::AbsoluteThermostat ( double  target_temperature,
double  max_temperature_change = std::numeric_limits<double>::max(),
ThirdDimension  third_dimension = ThirdDimension::ENABLED 
)

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 thermostat applies to a 3-dimensional domain or 2 dimensions.

Definition at line 7 of file AbsoluteThermostat.cpp.

Thermostat(double target_temperature, double max_temperature_change, ThirdDimension third_dimension)
Construct a new Thermostat object.
Definition: Thermostat.cpp:7
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

Member Function Documentation

◆ getContainerKineticEnergy()

double AbsoluteThermostat::getContainerKineticEnergy ( const std::unique_ptr< ParticleContainer > &  particle_container) const

Get the kinetic energy of all particles in a particle container.

Parameters
particle_containerThe particle container to get the kinetic energy of.
Returns
double The total kinetic energy of all particles in the container.

Definition at line 23 of file AbsoluteThermostat.cpp.

23  {
24  double total_kinetic_energy = 0;
25  for (auto& particle : *particle_container) {
26  if (particle.isLocked()) continue;
27  std::array<double, 3> v = particle.getV();
28  total_kinetic_energy += particle.getM() * (v[0] * v[0] + v[1] * v[1] + v[2] * v[2]) * 0.5;
29  }
30  return total_kinetic_energy;
31 }

◆ getCurrentContainerTemperature()

double AbsoluteThermostat::getCurrentContainerTemperature ( const std::unique_ptr< ParticleContainer > &  particle_container) const
overridevirtual

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.

Implements Thermostat.

Definition at line 33 of file AbsoluteThermostat.cpp.

33  {
34  double dimension_count = third_dimension == ThirdDimension::ENABLED ? 3 : 2;
35  return 2 * getContainerKineticEnergy(particle_container) / (dimension_count * particle_container->size());
36 }
double getContainerKineticEnergy(const std::unique_ptr< ParticleContainer > &particle_container) const
Get the kinetic energy of all particles in a particle container.

◆ scaleTemperature()

void AbsoluteThermostat::scaleTemperature ( const std::unique_ptr< ParticleContainer > &  particle_container) const
overridevirtual

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.

Implements Thermostat.

Definition at line 10 of file AbsoluteThermostat.cpp.

10  {
11  const double current_temperature = getCurrentContainerTemperature(particle_container);
12  const double temperature_change = std::min(std::abs(target_temperature - current_temperature), max_temperature_change);
13  const double new_temperature = current_temperature + temperature_change * (target_temperature > current_temperature ? 1 : -1);
14 
15  const double scaling_factor = std::sqrt(new_temperature / current_temperature);
16 
17  for (auto& particle : *particle_container) {
18  if (particle.isLocked()) continue;
19  particle.setV(scaling_factor * particle.getV());
20  }
21 }
double getCurrentContainerTemperature(const std::unique_ptr< ParticleContainer > &particle_container) const override
Get the current temperature of a particle container.

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