8 :
Thermostat(target_temperature, max_temperature_change, third_dimension) {}
13 const double new_temperature = current_temperature + temperature_change * (
target_temperature > current_temperature ? 1 : -1);
15 const double scaling_factor = std::sqrt(new_temperature / current_temperature);
17 for (
auto& particle : *particle_container) {
18 if (particle.isLocked())
continue;
19 particle.setV(scaling_factor * particle.getV());
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;
30 return total_kinetic_energy;
ThirdDimension
Enum class to define the dimension count of the simulation (2D or 3D). Affects primarily the dimensio...
double getCurrentContainerTemperature(const std::unique_ptr< ParticleContainer > &particle_container) const override
Get the current temperature of a particle container.
double getContainerKineticEnergy(const std::unique_ptr< ParticleContainer > &particle_container) const
Get the kinetic energy of all particles in a particle container.
AbsoluteThermostat(double target_temperature, double max_temperature_change=std::numeric_limits< double >::max(), ThirdDimension third_dimension=ThirdDimension::ENABLED)
Construct a new Thermostat object.
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 t...
A thermostat that can be used to control the temperature of a particle container. Allows for gradual ...
const double max_temperature_change
The maximum temperature change allowed per thermostat application.
const double target_temperature
The target temperature for thermostat applications.
const ThirdDimension third_dimension
Defines whether the third dimension is enabled.