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

Production run for a full-atomistic Lennard-Jones fluid as reference to an AdResS simulation. The trajectory is stored in an H5MD file.

Configuration for the full-atomistic Lennard-Jones production simulation in NVT ensemble.

struct Config
{
// time parameters
idx_t nsteps = 200000001;
real_t dt = 0.002_r;
// input file parameters
std::string fileRestoreH5MD =
"equilibrateLangevin_final.h5md";
// interaction parameters
static constexpr real_t sigma =
1_r;
static constexpr real_t epsilon = 1_r;
static constexpr real_t mass = 1_r;
static constexpr real_t r_cut = 2.5_r * sigma;
real_t r_cap = 0_r;
// neighbor list parameters
static constexpr real_t skin = 0.3_r * sigma;
static constexpr real_t neighborCutoff = r_cut + skin;
static constexpr real_t cell_ratio =
1_r;
static constexpr idx_t estimatedMaxNeighbors =
60;
// thermostat parameters
real_t temperature =
1.5_r;
real_t friction = 0.04_r / dt;
// output parameters
bool bOutput = true;
idx_t outputInterval = -1;
const std::string resName = "Argon";
const std::vector<std::string> typeNames = {"Ar"};
std::string fileOut = "productionAtomistic";
std::string fileOutH5MD;
std::string fileOutFinalGRO;
std::string fileOutFinalH5MD;
};
int64_t idx_t
Definition datatypes.hpp:91
double real_t
Definition datatypes.hpp:99

Simulation logic goes here

void productionAtomistic(Config& config)
{
// initialize
data::Subdomain subdomain;
auto atoms = data::Atoms(0);
// load data from file
auto io = io::RestoreH5MD();
io.restore(config.fileRestoreH5MD, subdomain, atoms);
// calculate volume of the simulation domain
const auto volume = subdomain.getVolume();
// calculate and print initial density
auto rho = real_c(atoms.numLocalAtoms) / volume;
std::cout << "rho: " << rho << std::endl;
// set up ghost layer for periodic boundary conditions
// set up neighbor list
HalfVerletList verletList;
real_t maxAtomDisplacement = std::numeric_limits<real_t>::max();
idx_t rebuildCounter = 0;
// set up interaction potential and force calculation and application
action::LennardJones lennardJones(config.r_cut, config.sigma, config.epsilon, config.r_cap);
// calculate and print box center coordinates
const auto boxCenter = subdomain.getCenter();
std::cout << "x center: " << boxCenter[0] << std::endl;
std::cout << "y center: " << boxCenter[1] << std::endl;
std::cout << "z center: " << boxCenter[2] << std::endl;
// set up thermostat for temperature control
action::VelocityVerletLangevinThermostat langevinIntegrator(config.friction,
config.temperature);
// set up timer for runtime measurement
Kokkos::Timer timer;
// set up mean square displacement analysis
analysis::MeanSquareDisplacement meanSquareDisplacement;
meanSquareDisplacement.reset(atoms);
auto msd = 0_r;
// set up variables for counting particle flux across the domain
analysis::CountingPlane countingPlane(
{boxCenter[0] + 10_r * config.sigma, boxCenter[1], boxCenter[2]}, {1_r, 0_r, 0_r});
int64_t flux = 0;
// output management
auto dumpH5MD = io::DumpH5MD("J-Hizzle");
std::ofstream fStat("statistics.txt");
if (config.bOutput)
{
// print table header for simulation statistics
"step", "time", "T", "Ek", "E0", "E", "p", "msd", "flux", "Nlocal", "Nghost");
"step", "time", "T", "Ek", "E0", "E", "p", "msd", "flux", "Nlocal", "Nghost");
// phase point output setup
dumpH5MD.open(config.fileOutH5MD, subdomain, atoms);
}
// main simulation loop
for (auto step = 0; step < config.nsteps; ++step)
{
// start counting particle flux across the plane
countingPlane.startCounting(atoms);
// integrate equations of motion with local Langevin thermostat during production phase
maxAtomDisplacement += langevinIntegrator.preForceIntegrate(atoms, config.dt);
// stop counting particle flux across the plane and calculate flux
flux += countingPlane.stopCounting(atoms);
if (maxAtomDisplacement >= config.skin * 0.5_r)
{
// reset displacement
maxAtomDisplacement = 0_r;
ghostLayer.exchangeRealAtoms(atoms, subdomain);
ghostLayer.createGhostAtoms(atoms, subdomain);
verletList.build(atoms.getPos(),
0,
atoms.numLocalAtoms,
config.neighborCutoff,
config.cell_ratio,
subdomain.minGhostCorner.data(),
subdomain.maxGhostCorner.data(),
config.estimatedMaxNeighbors);
++rebuildCounter;
}
else
{
ghostLayer.updateGhostAtoms(atoms, subdomain);
}
// reset forces to zero
auto force = atoms.getForce();
Cabana::deep_copy(force, 0_r);
// compute and apply forces
lennardJones.apply(atoms, verletList);
// contribute forces calculated on ghost atoms back to real atoms
ghostLayer.contributeBackGhostToReal(atoms);
// integrate equations of motion after force calculation
langevinIntegrator.postForceIntegrate(atoms, config.dt);
// handle output and statistics
if (config.bOutput && (step % config.outputInterval == 0))
{
// calculate statistics
auto E0 = (lennardJones.getEnergy()) / real_c(atoms.numLocalAtoms);
auto systemMomentum = analysis::getSystemMomentum(atoms);
auto T = (2_r / 3_r) * Ek;
auto p = analysis::getPressure(atoms, subdomain);
msd = meanSquareDisplacement.calc(atoms, subdomain) /
(real_c(config.outputInterval) * config.dt);
meanSquareDisplacement.reset(atoms);
// print statistics to console
timer.seconds(),
T,
Ek,
E0,
E0 + Ek,
p,
msd,
flux,
atoms.numLocalAtoms,
atoms.numGhostAtoms);
// dump statistics to file
fStat << step << " " << timer.seconds() << " " << T << " " << Ek << " " << E0 << " "
<< E0 + Ek << " " << p << " " << msd << " " << flux << " " << atoms.numLocalAtoms
<< " " << atoms.numGhostAtoms << " " << std::endl;
// reset flux counter
flux = 0;
// phase point output
dumpH5MD.dumpStep(subdomain, atoms, step, config.dt);
}
}
if (config.bOutput)
{
dumpH5MD.close();
// final phase point output
dumpH5MD.dump(config.fileOutFinalH5MD, subdomain, atoms);
// close statistics file
fStat.close();
io::dumpGRO(config.fileOutFinalGRO,
atoms,
subdomain,
0,
config.resName,
config.resName,
config.typeNames,
false,
true);
}
// write performance data to file
auto time = timer.seconds();
std::cout << time << std::endl;
auto cores = util::getEnvironmentVariable("OMP_NUM_THREADS");
std::ofstream fout("ecab.perf", std::ofstream::app);
fout << cores << ", " << time << ", " << atoms.numLocalAtoms << ", " << config.nsteps
<< std::endl;
fout.close();
}
High-level interface for the application of the Lennard-Jones potential to given atoms.
Definition LennardJones.hpp:118
Integrator that updates the positions and velocities of atoms using the BAOAB Langevin dynamics algor...
Definition VelocityVerletLangevinThermostat.hpp:36
Counts particles that cross a defined plane between two time steps.
Definition CountingPlane.hpp:29
Calculates the mean square displacement of particles over time.
Definition MeanSquareDisplacement.hpp:31
void reset(data::Atoms &atoms)
Store current positions as a starting point.
Definition MeanSquareDisplacement.cpp:24
real_t calc(data::Atoms &atoms, const data::Subdomain &subdomain)
Compare current positions against the starting point.
Definition MeanSquareDisplacement.cpp:60
High-level interface for managing ghost atoms at the periodic boundaries.
Definition GhostLayer.hpp:33
void createGhostAtoms(data::Atoms &atoms, const data::Subdomain &subdomain)
Definition GhostLayer.hpp:44
void updateGhostAtoms(data::Atoms &atoms, const data::Subdomain &subdomain)
Definition GhostLayer.hpp:49
void exchangeRealAtoms(data::Atoms &atoms, const data::Subdomain &subdomain)
Definition GhostLayer.hpp:39
void contributeBackGhostToReal(data::Atoms &atoms)
Definition GhostLayer.hpp:56
Handles dumping trajectory data in H5MD format.
Definition DumpH5MD.hpp:41
Handles restoring trajectory data from H5MD format.
Definition RestoreH5MD.hpp:33
real_t getMeanKineticEnergy(data::Atoms &atoms)
Definition KineticEnergy.hpp:44
Vector3D getSystemMomentum(data::Atoms &atoms)
Definition SystemMomentum.cpp:21
real_t getPressure(data::Atoms &atoms, const data::Subdomain &subdomain)
Definition Pressure.cpp:23
DeviceAtoms Atoms
Definition Atoms.hpp:177
Save and load simulation data.
void dumpGRO(const std::string &filename, data::Atoms &atoms, const data::Subdomain &subdomain, const real_t &timestamp, const std::string &title, const std::string &resName, const std::vector< std::string > &typeNames, bool dumpGhosts, bool dumpVelocities)
format specification https://manual.gromacs.org/current/reference-manual/file-formats....
Definition DumpGRO.cpp:26
void printTableSep(HEAD)
Definition PrintTable.hpp:40
std::string getEnvironmentVariable(const std::string &variable)
Definition EnvironmentVariables.hpp:23
void printTable(HEAD head)
Definition PrintTable.hpp:27
Cabana::VerletList< Kokkos::DefaultExecutionSpace::memory_space, Cabana::HalfNeighborTag, Cabana::VerletLayout2D, Cabana::TeamOpTag > HalfVerletList
Definition datatypes.hpp:184
KOKKOS_INLINE_FUNCTION constexpr real_t real_c(T t)
Definition datatypes.hpp:114
Axis-aligned simulation box with a surrounding ghost layer.
Definition Subdomain.hpp:46
Point3D getCenter() const
Definition Subdomain.cpp:59
Point3D minGhostCorner
Definition Subdomain.hpp:97
Point3D maxGhostCorner
Definition Subdomain.hpp:100
real_t getVolume() const
Definition Subdomain.cpp:57

Main function for the simulation

int main(int argc, char* argv[])
{
// initialize Kokkos environment
Kokkos::ScopeGuard scope_guard(argc, argv);
std::cout << "execution space: " << typeid(Kokkos::DefaultExecutionSpace).name() << std::endl;
Config config;
CLI::App app{"Lennard-Jones atomistic production simulation"};
app.add_option("-n,--nsteps", config.nsteps, "number of simulation steps");
app.add_option("-d,--tstep", config.dt, "time step");
app.add_option("-o,--outint", config.outputInterval, "output interval");
app.add_option("-i,--inpfile", config.fileRestoreH5MD, "input file name");
app.add_option("-f,--outfile", config.fileOut, "output file name");
app.add_option("-T,--temperature", config.temperature, "thermostat target temperature");
app.add_option("--friction", config.friction, "friction coefficient for thermostat");
app.add_option("--rcap", config.r_cap, "capping radius for Lennard-Jones potential");
CLI11_PARSE(app, argc, argv);
config.fileOutH5MD = format("{0}.h5md", config.fileOut);
config.fileOutFinalGRO = format("{0}_final.gro", config.fileOut);
config.fileOutFinalH5MD = format("{0}_final.h5md", config.fileOut);
if (config.outputInterval < 0) config.bOutput = false;
productionAtomistic(config);
return EXIT_SUCCESS;
}