Multi Resolution Molecular Dynamics 0.4.0
Multi Resolution Molecular Dynamics
Loading...
Searching...
No Matches
01_IdealGas_NVT
Note
This page is generated from examples/01_IdealGas_NVT/01_IdealGas_NVT.cpp. Build and run it with cmake --build mrmd-build --target 01_IdealGas_NVT followed by ./mrmd-build/examples/01_IdealGas_NVT/01_IdealGas_NVT. Pass --help to see the available command line options.

Minimal ideal gas simulation in the NVT (canonical) ensemble.

#include <CLI/App.hpp>
#include <CLI/Config.hpp>
#include <CLI/Formatter.hpp>
#include "data/Atoms.hpp"
#include "datatypes.hpp"
#include "io/DumpCSV.hpp"
using namespace mrmd;
Top-level namespace of MRMD.

Configuration for the ideal gas example simulation in NVT ensemble.

struct Config
{
idx_t nsteps = 2001;
static constexpr real_t dt = 0.005;
// thermostat parameters
static constexpr real_t temperature =
1.5_r;
static constexpr real_t friction =
0.04_r / dt;
};
int64_t idx_t
Definition datatypes.hpp:91
double real_t
Definition datatypes.hpp:99

Simulation logic goes here

void runIdealGas(const Config& config)
{
// initialize simulation domain
auto subdomain = data::Subdomain({0_r, 0_r, 0_r}, {100_r, 100_r, 100_r}, 1_r);
// initialize atoms randomly in the domain
auto atoms = util::fillDomainWithAtoms(subdomain, 100000, 1_r, 1_r);
// set up ghost layer for periodic boundary conditions
// set up thermostat for temperature control
action::VelocityVerletLangevinThermostat integrator(config.friction, config.temperature);
// set up timer for runtime measurement
Kokkos::Timer timer;
// main simulation loop
for (auto i = 0; i < config.nsteps; ++i)
{
// integrate equations of motion before (potentially) calculating forces
integrator.preForceIntegrate(atoms, config.dt);
// reinsert atoms that left the domain according to periodic boundary conditions
ghostLayer.exchangeRealAtoms(atoms, subdomain);
// finish integrating equations of motion
integrator.postForceIntegrate(atoms, config.dt);
// handle output
if (i % 100 == 0)
{
io::dumpCSV("atoms_" + std::to_string(i) + ".csv", atoms);
}
}
// print performance data
auto time = timer.seconds();
std::cout << time << std::endl;
}
Integrator that updates the positions and velocities of atoms using the BAOAB Langevin dynamics algor...
Definition VelocityVerletLangevinThermostat.hpp:36
High-level interface for managing ghost atoms at the periodic boundaries.
Definition GhostLayer.hpp:33
void exchangeRealAtoms(data::Atoms &atoms, const data::Subdomain &subdomain)
Definition GhostLayer.hpp:39
void dumpCSV(const std::string &filename, data::Atoms &atoms, bool dumpGhosts)
Definition DumpCSV.cpp:26
data::Atoms fillDomainWithAtoms(const data::Subdomain &subdomain, const idx_t &numAtoms, const real_t &maxVelocity, const real_t &inputMass)
Helper function to provide an initial atoms ensamble.
Definition simulationSetup.cpp:22
Axis-aligned simulation box with a surrounding ghost layer.
Definition Subdomain.hpp:46

Main function for the simulation

int main(int argc, char* argv[])
{
// initialize Kokkos environment
Kokkos::ScopeGuard scope_guard(argc, argv);
// print Kokkos execution space
std::cout << "execution space: " << typeid(Kokkos::DefaultExecutionSpace).name() << std::endl;
// initialize simulation configuration with command line interface
Config config;
CLI::App app{"ideal gas benchmark application"};
app.add_option("-n,--nsteps", config.nsteps, "number of simulation steps");
CLI11_PARSE(app, argc, argv);
// run simulation of the ideal gas
runIdealGas(config);
return EXIT_SUCCESS;
}