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

Minimal ideal gas (non-interacting particles) simulation in the NVE (microcanonical) ensemble. Introduces the simulation domain, ghost layer, and the velocity-Verlet integrator.

#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 NVE ensemble.

struct Config
{
idx_t nsteps = 2001;
real_t dt = 0.005;
};
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 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
// reinsert atoms that left the domain according to periodic boundary conditions
ghostLayer.exchangeRealAtoms(atoms, subdomain);
// finish integrating equations of motion
// 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;
}
static void postForceIntegrate(data::Atoms &atoms, const real_t dt)
Definition VelocityVerlet.cpp:69
static real_t preForceIntegrate(data::Atoms &atoms, const real_t dt)
Definition VelocityVerlet.cpp:26
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;
}