Add a Thermostat
This tutorial shows how to add a thermostat to the system. This tutorial builds on the topics in Minimal Simulation OOP and also those from Initialize System Lattice and Initialize System Random, so please read these first.
The following code pertains to a single component Lennard-Jones, NVT molecular dynamics simulation.
- Created 5-29-07; code revision 203
Thermostat
We will start from the final code used in Initialize System Random, where we have a single component Lennard-Jones NVE system. Glotzilla has two different ways to add a thermostat, depending on the thermostating routing; these two methods are either by adding a SimulationComponent? to the standard NVE integration schemes, or changing the integration scheme.
Adding a SimulationComponent?
Algorithms such as the Berendsen Thermostat and the Brownian Dynamics Thermostat can be added as fixes to the standard NVE integration scheme. To add a thermostat as a SimulationComponent? (sometimes referred to as a fix), we need only modify our custom constructor class:
LennardJonesSimulationRandom()
{
IntializeParticles();
SetInteraction(new LennardJones);
SetForceRoutine(new BruteForce);
SetBoundaryConditions(new PeriodicBoundary(10));
SetIntegrationScheme(new VelocityVerletIntegrator);
BerendsenThermostat *thermostat = new BerendsenThermostat;
thermostat->SetTemperature(1.0);
AddSimulationComponent(thermostat);
}Here we create an instance of the BerendsenThermostat class, call it thermostat. To se the temperature, we call the "SetTemperature?" routine, in this case, setting it to a value of 1.0 (in LJ units). The final step to implement this is to pass thermostat to the AddSimulationComponent?, which is inherited from MdSimulation.
Changing the Integration Scheme
An additional way to add a thermostat is to change the integration scheme. For instance, algorithms such as the Nose-Hoover Thermostat? are best implemented into the integration scheme and are not added as an additional SimulationComponent? to the standard NVE integrator. This is because the Nose-Hoover equations of motion are build directly into the integration scheme.
The following example adds a constant temperature integrator, which uses Nose-Hoover chains in the formulation of Martyna et al.
MartynaNvtIntegrator *nvt = new MartynaNvtIntegrator;
nvt -> SetTemperature(0.55);
SetIntegrationScheme(nvt);Attachments
- MDSimulationComponentNVT.cpp (1.6 kB) - added by cri 15 months ago.