8 :
Thermostat(target_temperature, max_temperature_change, third_dimension) {}
10 std::array<double, 3>
averageVelocity(
const std::unique_ptr<ParticleContainer>& particle_container) {
11 std::array<double, 3> average_velocity = {0, 0, 0};
13 for (
auto& particle : *particle_container) {
14 if (particle.isLocked())
continue;
15 average_velocity = average_velocity + particle.getV();
18 average_velocity = (1.0 / count) * average_velocity;
19 return average_velocity;
22 const std::array<double, 3> average_velocity =
averageVelocity(particle_container);
26 const double new_temperature = current_temperature + temperature_change * (
target_temperature > current_temperature ? 1 : -1);
28 const double scaling_factor = std::sqrt(new_temperature / current_temperature);
30 for (
auto& particle : *particle_container) {
31 if (particle.isLocked())
continue;
32 particle.setV(average_velocity + scaling_factor * (particle.getV() - average_velocity));
37 std::array<double, 3> average_velocity)
const {
38 double total_kinetic_energy = 0;
39 for (
auto& particle : *particle_container) {
40 if (particle.isLocked())
continue;
41 std::array<double, 3> v = particle.getV() - average_velocity;
42 total_kinetic_energy += particle.getM() * (v[0] * v[0] + v[1] * v[1] + v[2] * v[2]) * 0.5;
44 return total_kinetic_energy;
48 std::array<double, 3> average_velocity)
const {
50 return 2 *
getContainerKineticEnergy(particle_container, average_velocity) / (dimension_count * particle_container->size());
ThirdDimension
Enum class to define the dimension count of the simulation (2D or 3D). Affects primarily the dimensio...
std::array< double, 3 > averageVelocity(const std::unique_ptr< ParticleContainer > &particle_container)
double getCurrentContainerTemperature(const std::unique_ptr< ParticleContainer > &particle_container, std::array< double, 3 > average_velocity) const
Get the current temperature of a particle.
double getContainerKineticEnergy(const std::unique_ptr< ParticleContainer > &particle_container, std::array< double, 3 > average_velocity) const
Get the kinetic energy of a particle.
RelativeThermostat(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.