Minimal Lennard-Jones simulation in the NVE (microcanonical) ensemble starting from a phase position restored from a GRO file, with output of observables and the final phase position in H5MD format.
Configuration for the Argon NVE example simulation.
void runLennardJonesNVE(Config& config)
{
auto subdomain =
data::Subdomain({0_r, 0_r, 0_r}, {0_r, 0_r, 0_r}, config.neighborCutoff);
const auto volume = subdomain.diameter[0] * subdomain.diameter[1] * subdomain.diameter[2];
auto rho =
real_c(atoms.numLocalAtoms) / volume;
std::cout << "rho: " << rho << std::endl;
real_t maxAtomDisplacement = std::numeric_limits<real_t>::max();
idx_t rebuildCounter = 0;
Kokkos::Timer timer;
meanSquareDisplacement.
reset(atoms);
auto msd = 0_r;
util::printTable(
"step",
"time",
"T",
"Ek",
"E0",
"E",
"p",
"msd",
"Nlocal",
"Nghost");
std::ofstream fStat("statistics.txt");
for (auto step = 0; step < config.nsteps; ++step)
{
if (maxAtomDisplacement >=
config.skin *
0.5_r)
{
maxAtomDisplacement = 0_r;
verletList.build(atoms.getPos(),
0,
atoms.numLocalAtoms,
config.neighborCutoff,
config.cell_ratio,
subdomain.minGhostCorner.data(),
subdomain.maxGhostCorner.data(),
config.estimatedMaxNeighbors);
++rebuildCounter;
}
else
{
}
auto force = atoms.getForce();
Cabana::deep_copy(force, 0_r);
lennardJones.apply(atoms, verletList);
if (config.bOutput && (step % config.outputInterval == 0))
{
auto E0 = lennardJones.getEnergy() /
real_c(atoms.numLocalAtoms);
auto T = (2_r / 3_r) * Ek;
msd = meanSquareDisplacement.
calc(atoms, subdomain) /
(
real_c(config.outputInterval) * config.dt);
meanSquareDisplacement.
reset(atoms);
timer.seconds(),
T,
Ek,
E0,
E0 + Ek,
p,
msd,
atoms.numLocalAtoms,
atoms.numGhostAtoms);
fStat << step << " " << timer.seconds() << " " << T << " " << Ek << " " << E0 << " "
<< E0 + Ek << " " << p << " " << msd << " " << atoms.numLocalAtoms << " "
<< atoms.numGhostAtoms << " " << std::endl;
}
}
if (config.bOutput)
{
dumpH5MD.dump(config.fileOutFinalH5MD, subdomain, atoms);
}
fStat.close();
auto time = timer.seconds();
std::cout << time << std::endl;
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
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
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
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
void restoreGRO(const std::string &filename, data::Subdomain &subdomain, data::Atoms &atoms, bool containsGhostAtoms)
Definition RestoreGRO.cpp:24
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
int main(int argc, char* argv[])
{
Kokkos::ScopeGuard scope_guard(argc, argv);
std::cout << "execution space: " << typeid(Kokkos::DefaultExecutionSpace).name() << std::endl;
Config config;
CLI::App app{"Lennard Jones Fluid NVE benchmark application"};
app.add_option("-n,--nsteps", config.nsteps, "total number of simulation steps");
app.add_option("-o,--output", config.outputInterval, "output interval");
app.add_option("-i,--inpfile", config.fileRestoreGRO, "input file name");
CLI11_PARSE(app, argc, argv);
if (config.outputInterval < 0) config.bOutput = false;
runLennardJonesNVE(config);
return EXIT_SUCCESS;
}