Thermodynamic force iteration run for the Lennard-Jones fluid coupled to a tracer gas of non-interacting particles and starting from an initial guess for the force. The final thermodynamic force is dumped into a TXT file.
Configuration for the thermodynamic force iteration simulation.
void thermodynamicForce_initialGuess(Config& config)
{
io.restore(config.fileRestoreH5MD, initialSubdomain, atoms);
{
},
{
},
auto rho =
real_c(atoms.numLocalAtoms) / volume;
std::cout << "rho: " << rho << std::endl;
std::cout << "restoring thermodynamic force from file" << std::endl;
subdomain,
{rho},
{config.thermodynamicForceModulation},
config.enforceSymmetry,
false,
1);
real_t maxAtomDisplacement = std::numeric_limits<real_t>::max();
idx_t rebuildCounter = 0;
config.r_cut, config.sigma, config.epsilon, config.r_cap);
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;
{boxCenter[0], boxCenter[1], boxCenter[2]}, config.intRegionMin, config.intRegionMax);
config.thermoForceRegionMin,
config.thermoForceRegionMax,
-std::numeric_limits<real_t>::epsilon());
config.temperature);
Kokkos::Timer timer;
meanSquareDisplacement.
reset(atoms);
auto msd = 0_r;
subdomain.diameter[1] * subdomain.diameter[2] * config.densityBinWidth;
std::ofstream fStat("statistics.txt");
if (config.bOutput)
{
util::printTable(
"step",
"time",
"T",
"Ek",
"E0",
"E",
"p",
"msd",
"Nlocal",
"Nghost");
dumpDens.
open(config.fileOutDens);
Kokkos::HostSpace(),
data::createGrid(thermodynamicForce.getDensityProfile())));
dumpH5MD.open(config.fileOutH5MD, subdomain, atoms);
}
for (auto step = 0; step < config.nsteps; ++step)
{
maxAtomDisplacement += langevinIntegrator.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;
}
else
{
}
if (step % config.densitySamplingInterval == 0)
{
thermodynamicForce.sample(atoms);
}
if (config.bOutput && (step % config.outputInterval == 0))
{
auto numberOfDensityProfileSamples =
thermodynamicForce.getNumberOfDensityProfileSamples();
real_t normalizationFactor = 1_r / densityBinVolume;
if (numberOfDensityProfileSamples > 0)
{
normalizationFactor =
1_r / (densityBinVolume *
real_c(numberOfDensityProfileSamples));
}
auto densityProfile = Kokkos::create_mirror_view_and_copy(
Kokkos::HostSpace(), thermodynamicForce.getDensityProfile(0));
}
if (step % config.densityUpdateInterval == 0 && step > 0)
{
thermodynamicForce.update_if(
config.smoothingInverseDamping, config.smoothingRange, isInThermoForceRegion);
}
auto force = atoms.getForce();
Cabana::deep_copy(force, 0_r);
thermodynamicForce.applyInterpolated_if(atoms, isInThermoForceRegion);
lennardJonesInner.apply_if(
atoms,
verletList,
KOKKOS_LAMBDA(
const real_t x1,
return (isInIntRegion(x1, y1, z1) && isInIntRegion(x2, y2, z2));
});
langevinIntegrator.postForceIntegrate(atoms, config.dt);
if (config.bOutput && (step % config.outputInterval == 0))
{
auto E0 = (lennardJonesInner.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;
auto thermoForce = Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace(),
thermodynamicForce.getForce(0));
config.fileOut,
idx_c(std::floor(step / config.densityUpdateInterval))),
thermodynamicForce,
0);
dumpH5MD.dumpStep(subdomain, atoms, step, config.dt);
}
}
if (config.bOutput)
{
dumpH5MD.close();
dumpH5MD.dump(config.fileOutFinalH5MD, subdomain, atoms);
fStat.close();
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
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 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 dumping profile data to a file.
Definition DumpProfile.hpp:30
void close()
Definition DumpProfile.cpp:24
void open(const std::string &filename)
Definition DumpProfile.cpp:22
void dumpScalarView(const ScalarView::HostMirror &dataProfile, const real_t &normalizationFactor=1_r)
Definition DumpProfile.cpp:26
Handles restoring trajectory data from H5MD format.
Definition RestoreH5MD.hpp:33
Predicate to check if a point is within an axis-aligned slab.
Definition IsInSymmetricSlab.hpp:26
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
ScalarView createGrid(const MultiHistogram &input)
Definition MultiHistogram.cpp:214
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 ×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
action::ThermodynamicForce restoreThermoForce(const std::string &filename, const data::Subdomain &subdomain, const std::vector< real_t > &targetDensities, const std::vector< real_t > &thermodynamicForceModulations, const bool enforceSymmetry, const bool usePeriodicity, const idx_t maxNumForces)
Definition RestoreThermoForce.cpp:24
void dumpThermoForce(const std::string &filename, const action::ThermodynamicForce &thermodynamicForce, const idx_t &typeId)
Definition DumpThermoForce.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 idx_t idx_c(const T &val)
Definition datatypes.hpp:93
@ X
index of the x coordinate in vector views
Definition datatypes.hpp:142
Axis-aligned simulation box with a surrounding ghost layer.
Definition Subdomain.hpp:46
Point3D minCorner
Definition Subdomain.hpp:86
Point3D maxCorner
Definition Subdomain.hpp:89
Point3D ghostLayerThickness
Definition Subdomain.hpp:93
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{"Lennard-Jones Thermodynamic Force Simulation with initial guess"};
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(
"--forceguess", config.fileRestoreTF, "initial guess for the thermodynamics force");
app.add_option("--sampling", config.densitySamplingInterval, "density sampling interval");
app.add_option("--update", config.densityUpdateInterval, "density update interval");
app.add_option("--densbinwidth", config.densityBinWidth, "density bin width");
app.add_option("--damping", config.smoothingDamping, "density smoothing damping factor");
app.add_option("--neighbors", config.smoothingNeighbors, "density smoothing neighbors");
app.add_option(
"--forcemod", config.thermodynamicForceModulation, "thermodynamic force modulation");
app.add_option("--rcap", config.r_cap, "capping radius for inner Lennard-Jones potential");
app.add_option("--innermin", config.intRegionMin, "interacting region minimum coordinate");
app.add_option("--innermax", config.intRegionMax, "interacting region maximum coordinate");
app.add_option("--thermoforcemin",
config.thermoForceRegionMin,
"thermodynamic force region minimum coordinate");
app.add_option("--thermoforcemax",
config.thermoForceRegionMax,
"thermodynamic force region maximum coordinate");
CLI11_PARSE(app, argc, argv);
config.fileOutH5MD = format("{0}.h5md", config.fileOut);
config.fileOutTF = format("{0}_tf.txt", config.fileOut);
config.fileOutDens = format("{0}_dens.txt", config.fileOut);
config.fileOutFinalGRO = format("{0}_final.gro", config.fileOut);
config.fileOutFinalH5MD = format("{0}_final.h5md", config.fileOut);
config.fileOutFinalTF = format("{0}_final_tf.txt", config.fileOut);
config.smoothingRange =
real_c(config.smoothingNeighbors) * config.densityBinWidth * config.smoothingDamping;
if (config.outputInterval < 0) config.bOutput = false;
thermodynamicForce_initialGuess(config);
return EXIT_SUCCESS;
}