Equilibration simulation of a Lennard-Jones system using the Berendsen thermostat as a first step towards running an AdResS simulation. The particles are initialized with random positions and velocities inside a rectangular simulation box with user-defined dimensions and number of particles. The final phase position is dumped into both GRO and H5MD output files.
Configuration for the Lennard-Jones equilibration simulation using the Berendsen thermostat.
void equilibrateBerendsen(Config& config)
{
auto subdomain =
data::Subdomain({0_r, 0_r, 0_r}, {config.Lx, config.Ly, config.Lz}, config.neighborCutoff);
auto atoms =
auto rho =
real_c(atoms.numLocalAtoms) / volume;
std::cout << "rho: " << rho << std::endl;
Kokkos::Timer timer;
real_t maxAtomDisplacement = std::numeric_limits<real_t>::max();
idx_t rebuildCounter = 0;
if (config.bOutput)
{
"step", "wall time", "T", "p", "V", "E_kin", "E_LJ", "E_total", "Nlocal", "Nghost");
"step", "wall time", "T", "p", "V", "E_kin", "E_LJ", "E_total", "Nlocal", "Nghost");
}
for (auto step = 0; step < config.nsteps; ++step)
{
atoms, currentTemperature, config.temperature, config.friction);
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);
LJ.apply(atoms, verletList);
currentPressure << 2_r * (Ek - LJ.getVirial()) / (3_r * volume);
Ek /=
real_c(atoms.numLocalAtoms);
currentTemperature << (2_r / 3_r) * Ek;
if (config.bOutput && (step % config.outputInterval == 0))
{
timer.seconds(),
currentTemperature,
currentPressure,
volume,
Ek,
LJ.getEnergy() /
real_c(atoms.numLocalAtoms),
Ek + LJ.getEnergy() /
real_c(atoms.numLocalAtoms),
atoms.numLocalAtoms,
atoms.numGhostAtoms);
}
}
if (config.bOutput)
{
dumpH5MD.dump(config.fileOutFinalH5MD, subdomain, atoms);
atoms,
subdomain,
0,
config.resName,
config.resName,
config.typeNames,
false,
true);
}
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
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
Calculates the exponential moving average (EMA) for values added with append.
Definition ExponentialMovingAverage.hpp:32
void apply(data::Atoms &atoms, const real_t ¤tTemperature, const real_t &targetTemperature, const real_t &gamma)
Berendsen thermostat.
Definition BerendsenThermostat.cpp:27
real_t getKineticEnergy(data::Atoms &atoms)
Definition KineticEnergy.hpp:26
real_t getMeanKineticEnergy(data::Atoms &atoms)
Definition KineticEnergy.hpp:44
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
real_t getVolume() const
Definition Subdomain.cpp:57
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{"preliminary NVT equilibration of Lennard-Jones fluid with Berendsen thermostat"};
app.add_option("-n,--nsteps", config.nsteps, "number of simulation steps");
app.add_option("-x,--xlength", config.Lx, "x length of the box");
app.add_option("-y,--ylength", config.Ly, "y length of the box");
app.add_option("-z,--zlength", config.Lz, "z length of the box");
app.add_option("-N,--numAtoms", config.numAtoms, "number of atoms");
app.add_option("-T,--temperature", config.temperature, "thermostat target temperature");
app.add_option("-o,--outint", config.outputInterval, "output interval");
app.add_option("-f,--outfile", config.fileOut, "output file name");
CLI11_PARSE(app, argc, argv);
config.fileOutFinalGRO = format("{0}_final.gro", config.fileOut);
config.fileOutFinalH5MD = format("{0}_final.h5md", config.fileOut);
if (config.outputInterval < 0) config.bOutput = false;
equilibrateBerendsen(config);
return EXIT_SUCCESS;
}