MolSim
Loading...
Searching...
No Matches
Public Member Functions | Private Attributes | List of all members
Thermostat Class Reference

Class modeling a thermostat which regulates the temperature of a Particle system. More...

#include <Thermostat.h>

Public Member Functions

 Thermostat (ParticleContainer &particles)
 Construct a new Thermostat with default-initialized values.
 
 Thermostat (ParticleContainer &particles, int dimension, double T_init, int n_thermostat, double T_target, double delta_T, bool initBrownianMotion, bool nanoFlow=false)
 Construct a complete Thermostat object with all parameters.
 
 ~Thermostat ()
 Destroys the current Thermostat object.
 
void initialize (int dimension, double T_init, int n_thermostat, double T_target, double delta_T, bool initBrownianMotion, bool nanoFlow=false, bool limitScaling=false)
 Initialize the current Thermostat's parameters.
 
void initializeBrownianMotion ()
 Initialize the Particle velocities with Brownian Motion.
 
void calculateKineticEnergy ()
 Calculates the kinetic energy \( E_{kin} \) for all Particle objects in the system.
 
void calculateTemp ()
 Calculates the current temperature \( T \) of the system.
 
void calculateScalingFactor ()
 Calculates the scaling factor \( \beta \).
 
void calculateThermalMotions ()
 Calculates the thermal motion of each Particle in the system.
 
void updateSystemTemp (int currentStep)
 Updates the system temperature after the number of iterations specified inside the Thermostat object.
 
double getKineticEnergy () const
 Gets the kinetic energy \( E_{kin} \) of the active simulation particles.
 
double getTemp () const
 Gets the current temperature \( T \) of the system.
 
double getInitTemp () const
 Gets the starting temperature \( T_{init} \) of the system.
 
double getTargetTemp () const
 Gets the target temperature \( T_{target} \) of the system.
 
double getDeltaT () const
 Gets the maximum temperature difference \( \Delta T \) in one Thermostat application.
 
double getScalingFactor () const
 Gets the scaling factor \( \beta \) by which to scale the Particle velocities.
 
bool doScalingLimit () const
 Checks if the Thermostat should apply gradual or direct velocity scaling.
 
int getTimestep () const
 Gets the number of simulation iterations after which to apply the Thermostat functionality.
 
bool getNanoflow () const
 Determines whether the thermostat is used for the nano-scale flow simulation.
 
ParticleContainergetParticles () const
 Gets a reference to the Particle system.
 
bool operator== (const Thermostat &other) const
 Overload of the equality operator. Checks if two Thermostat objects have the same values.
 

Private Attributes

int dimension {2}
 The dimensions for which the Thermostat temperature regulation should be applied (default: 2).
 
double kineticEnergy {0.0}
 The kinetic energy \( E_{kin} \) of the active simulation particles (default: 0).
 
double temperature {0.0}
 The Temperature \( T \) of the system (default: 0).
 
double scalingFactor {1.0}
 The scaling factor \( \beta \) by which to scale the Particle velocities (default: 1).
 
double T_init {0.0}
 The starting temperature \( T_{init} \) of the system (default: 0).
 
double T_target {0.0}
 The target temperature \( T_{target} \) of the system (default: \( T_{init} \)).
 
int n_thermostat {1000}
 The number of simulation iterations after which to apply the Thermostat functionality (default: 1000).
 
double delta_T {INFINITY}
 The maximum temperature difference \( \Delta T \) in one Thermostat application (default: \( \infty \)).
 
bool limitScaling {false}
 Determines if the Thermostat should apply gradual velocity scaling or direct velocity scaling (default: direct).
 
bool initBrownianMotion {true}
 Determines whether or not to initialize the velocities with Brownian Motion (default: on).
 
bool nanoFlow {false}
 Determines whether the thermostat is used for the nano-scale flow simulation.
 
std::array< double, 3 > avg_velocity {0, 0, 0}
 Average velocity of the system.
 
ParticleContainerparticles
 A reference to the Particle system.
 

Detailed Description

Class modeling a thermostat which regulates the temperature of a Particle system.

Constructor & Destructor Documentation

◆ Thermostat() [1/2]

Thermostat::Thermostat ( ParticleContainer particles)
explicit

Construct a new Thermostat with default-initialized values.

Parameters
particlesThe ParticleContainer representing the Particle system.

◆ Thermostat() [2/2]

Thermostat::Thermostat ( ParticleContainer particles,
int  dimension,
double  T_init,
int  n_thermostat,
double  T_target,
double  delta_T,
bool  initBrownianMotion,
bool  nanoFlow = false 
)

Construct a complete Thermostat object with all parameters.

Parameters
particlesThe ParticleContainer representing the Particle system.
dimensionThe dimensions for which the Thermostat temperature regulation should be applied.
T_initThe starting temperature \( T_{init} \) of the system.
n_thermostatThe number of simulation iterations after which to apply the Thermostat functionality.
T_targetThe target temperature \( T_{target} \) of the system.
delta_TThe maximum temperature difference \( \Delta T \) in one Thermostat application.
initBrownianMotionDetermines whether or not to initialize the velocities with Brownian Motion.
nanoFlowDetermines whether the thermostat is used for the nano-scale flow simulation.

◆ ~Thermostat()

Thermostat::~Thermostat ( )

Destroys the current Thermostat object.

Member Function Documentation

◆ calculateKineticEnergy()

void Thermostat::calculateKineticEnergy ( )

Calculates the kinetic energy \( E_{kin} \) for all Particle objects in the system.

The kinetic energy is calculated using the formula

\[ E_{kin} = \sum_{i=1}^N \frac{m_i \langle v_i, v_i \rangle}{2} \]

where \( N \) denotes the total number of active Particle objects.

◆ calculateScalingFactor()

void Thermostat::calculateScalingFactor ( )

Calculates the scaling factor \( \beta \).

The scaling factor is calculated using the formula

\[ \beta = \sqrt{\frac{T_{new}}{T_{current}}} \]

where \( T_{new} \) is either the target temperature if no limit \( \Delta T \) is given or if the target temperature can be reached in the next thermostat application, or \( T_{current} \pm \Delta T \) otherwise (depending if the current temperature is above or below the target temperature).

◆ calculateTemp()

void Thermostat::calculateTemp ( )

Calculates the current temperature \( T \) of the system.

The temperature is calculated after getting the kinetic energy \( E_{kin} \) of all Particle objects in the system by rearranging the equation

\[ E_{kin} = \frac{D \cdot N}{2}k_B T \]

and solving for \( T \), with \( N \) being the total number of active Particle objects, \( D \) being the number of dimensions and \( k_B = 1 \).

◆ calculateThermalMotions()

void Thermostat::calculateThermalMotions ( )

Calculates the thermal motion of each Particle in the system.

First, the average velocity

\[ \tilde v = \frac1N \sum_{i=0}^N v_i \]

is determined using the velocities of each non-wall particle in the system. Then, for each particle, its thermal motion \( \hat v_i \) is calculated as the difference between the velocity and the average velocity.

◆ doScalingLimit()

bool Thermostat::doScalingLimit ( ) const

Checks if the Thermostat should apply gradual or direct velocity scaling.

◆ getDeltaT()

double Thermostat::getDeltaT ( ) const

Gets the maximum temperature difference \( \Delta T \) in one Thermostat application.

◆ getInitTemp()

double Thermostat::getInitTemp ( ) const

Gets the starting temperature \( T_{init} \) of the system.

◆ getKineticEnergy()

double Thermostat::getKineticEnergy ( ) const

Gets the kinetic energy \( E_{kin} \) of the active simulation particles.

◆ getNanoflow()

bool Thermostat::getNanoflow ( ) const

Determines whether the thermostat is used for the nano-scale flow simulation.

◆ getParticles()

ParticleContainer & Thermostat::getParticles ( ) const

Gets a reference to the Particle system.

◆ getScalingFactor()

double Thermostat::getScalingFactor ( ) const

Gets the scaling factor \( \beta \) by which to scale the Particle velocities.

◆ getTargetTemp()

double Thermostat::getTargetTemp ( ) const

Gets the target temperature \( T_{target} \) of the system.

◆ getTemp()

double Thermostat::getTemp ( ) const

Gets the current temperature \( T \) of the system.

◆ getTimestep()

int Thermostat::getTimestep ( ) const

Gets the number of simulation iterations after which to apply the Thermostat functionality.

◆ initialize()

void Thermostat::initialize ( int  dimension,
double  T_init,
int  n_thermostat,
double  T_target,
double  delta_T,
bool  initBrownianMotion,
bool  nanoFlow = false,
bool  limitScaling = false 
)

Initialize the current Thermostat's parameters.

Parameters
dimensionThe dimensions for which the Thermostat temperature regulation should be applied.
T_initThe starting temperature \( T_{init} \) of the system.
n_thermostatThe number of simulation iterations after which to apply the Thermostat functionality.
T_targetThe target temperature \( T_{target} \) of the system.
delta_TThe maximum temperature difference \( \Delta T \) in one Thermostat application.
initBrownianMotionDetermines whether or not to initialize the velocities with Brownian Motion.
nanoFlowDetermines whether the thermostat is used for the nano-scale flow simulation.
limitScalingDetermines if the Thermostat should apply gradual or direct velocity scaling.

◆ initializeBrownianMotion()

void Thermostat::initializeBrownianMotion ( )

Initialize the Particle velocities with Brownian Motion.

Assuming a Particle does not have an initial velocity, in order for the system to have a non-zero temperature, the velocity for any given Particle \( i \) is calculated using a Maxwell-Boltzmann distribution with the factor

\[ f_i = \sqrt{\frac{T_{init}}{m_i}}. \]

◆ operator==()

bool Thermostat::operator== ( const Thermostat other) const

Overload of the equality operator. Checks if two Thermostat objects have the same values.

Does not check if both objects reference the same ParticleContainer.

Parameters
otherThe other Thermostat to check the values against.
Returns
true if both Thermostat objects contain the same values.
false if both Thermostat objects do not contain the same values.

◆ updateSystemTemp()

void Thermostat::updateSystemTemp ( int  currentStep)

Updates the system temperature after the number of iterations specified inside the Thermostat object.

For nanoscale simulations, the thermal motion of the particles inside the system are taken into account.

Parameters
currentStepThe current iteration of the simulation, used to determine whether or not to apply the thermostat. In the first iteration, if initBrownianMotion is set, the Particle velocities will be initialized with Brownian Motion. Otherwise, nothing is done in the first iteration.

Member Data Documentation

◆ avg_velocity

std::array<double, 3> Thermostat::avg_velocity {0, 0, 0}
private

Average velocity of the system.

◆ delta_T

double Thermostat::delta_T {INFINITY}
private

The maximum temperature difference \( \Delta T \) in one Thermostat application (default: \( \infty \)).

If no temperature difference is specified (i.e. if the value is defaulted to INFINITY), the temperature is set directly in one Thermostat application.

◆ dimension

int Thermostat::dimension {2}
private

The dimensions for which the Thermostat temperature regulation should be applied (default: 2).

◆ initBrownianMotion

bool Thermostat::initBrownianMotion {true}
private

Determines whether or not to initialize the velocities with Brownian Motion (default: on).

◆ kineticEnergy

double Thermostat::kineticEnergy {0.0}
private

The kinetic energy \( E_{kin} \) of the active simulation particles (default: 0).

◆ limitScaling

bool Thermostat::limitScaling {false}
private

Determines if the Thermostat should apply gradual velocity scaling or direct velocity scaling (default: direct).

◆ n_thermostat

int Thermostat::n_thermostat {1000}
private

The number of simulation iterations after which to apply the Thermostat functionality (default: 1000).

Must be specified when initializing a Thermostat.

◆ nanoFlow

bool Thermostat::nanoFlow {false}
private

Determines whether the thermostat is used for the nano-scale flow simulation.

◆ particles

ParticleContainer& Thermostat::particles
private

A reference to the Particle system.

◆ scalingFactor

double Thermostat::scalingFactor {1.0}
private

The scaling factor \( \beta \) by which to scale the Particle velocities (default: 1).

◆ T_init

double Thermostat::T_init {0.0}
private

The starting temperature \( T_{init} \) of the system (default: 0).

Must be specified when initializing a Thermostat.

◆ T_target

double Thermostat::T_target {0.0}
private

The target temperature \( T_{target} \) of the system (default: \( T_{init} \)).

If no target temperature is given in the input, the target temperature is set to \( T_{init} \).

◆ temperature

double Thermostat::temperature {0.0}
private

The Temperature \( T \) of the system (default: 0).


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