Minimal Lennard-Jones simulation in the NVT (canonical) ensemble with output of observables and final phase position in GRO format.
Configuration for the Argon NVT example simulation.
void runLennardJonesNVT(Config& config)
{
auto subdomain =
data::Subdomain({0_r, 0_r, 0_r}, {config.Lx, config.Lx, config.Lx}, config.neighborCutoff);
const auto volume = subdomain.
diameter[0] * subdomain.diameter[1] * subdomain.diameter[2];
auto atoms =
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)
{
maxAtomDisplacement += integrator.preForceIntegrate(atoms, config.dt);
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;
}
auto force = atoms.getForce();
Cabana::deep_copy(force, 0_r);
lennardJones.apply(atoms, verletList);
integrator.postForceIntegrate(atoms, config.dt);
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)
{
atoms,
subdomain,
real_c(config.nsteps) * config.dt,
config.fileOutFinalGRO,
config.resName,
config.typeNames,
false,
true);
}
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
Integrator that updates the positions and velocities of atoms using the BAOAB Langevin dynamics algor...
Definition VelocityVerletLangevinThermostat.hpp:36
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 exchangeRealAtoms(data::Atoms &atoms, const data::Subdomain &subdomain)
Definition GhostLayer.hpp:39
void contributeBackGhostToReal(data::Atoms &atoms)
Definition GhostLayer.hpp:56
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
void dumpGRO(const std::string &filename, data::Atoms &atoms, const data::Subdomain &subdomain, const real_t ×tamp, 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
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
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
Vector3D diameter
Definition Subdomain.hpp:111
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 NVT benchmark application"};
app.add_option("-n,--nsteps", config.nsteps, "total number of simulation steps");
app.add_option("-L,--length", config.Lx, "simulation box diameter");
app.add_option("-T,--temperature", config.temperature, "thermostat target temperature");
app.add_option("-o,--outint", config.outputInterval, "output interval");
CLI11_PARSE(app, argc, argv);
if (config.outputInterval < 0) config.bOutput = false;
runLennardJonesNVT(config);
return EXIT_SUCCESS;
}