forked from lijiext/lammps
reformat
This commit is contained in:
parent
cc7538e7b9
commit
f5f5721cfb
|
@ -1,4 +1,3 @@
|
||||||
// clang-format off
|
|
||||||
/* ----------------------------------------------------------------------
|
/* ----------------------------------------------------------------------
|
||||||
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
|
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
|
||||||
https://www.lammps.org/, Sandia National Laboratories
|
https://www.lammps.org/, Sandia National Laboratories
|
||||||
|
@ -14,21 +13,22 @@
|
||||||
|
|
||||||
#include "fix_dt_reset.h"
|
#include "fix_dt_reset.h"
|
||||||
|
|
||||||
|
#include "atom.h"
|
||||||
|
#include "comm.h"
|
||||||
|
#include "domain.h"
|
||||||
|
#include "dump.h"
|
||||||
|
#include "error.h"
|
||||||
|
#include "fix.h"
|
||||||
|
#include "force.h"
|
||||||
|
#include "integrate.h"
|
||||||
|
#include "lattice.h"
|
||||||
|
#include "modify.h"
|
||||||
|
#include "output.h"
|
||||||
|
#include "pair.h"
|
||||||
|
#include "update.h"
|
||||||
|
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include "atom.h"
|
|
||||||
#include "update.h"
|
|
||||||
#include "integrate.h"
|
|
||||||
#include "domain.h"
|
|
||||||
#include "lattice.h"
|
|
||||||
#include "force.h"
|
|
||||||
#include "pair.h"
|
|
||||||
#include "modify.h"
|
|
||||||
#include "fix.h"
|
|
||||||
#include "output.h"
|
|
||||||
#include "dump.h"
|
|
||||||
#include "comm.h"
|
|
||||||
#include "error.h"
|
|
||||||
|
|
||||||
using namespace LAMMPS_NS;
|
using namespace LAMMPS_NS;
|
||||||
using namespace FixConst;
|
using namespace FixConst;
|
||||||
|
@ -37,10 +37,9 @@ using namespace FixConst;
|
||||||
|
|
||||||
/* ---------------------------------------------------------------------- */
|
/* ---------------------------------------------------------------------- */
|
||||||
|
|
||||||
FixDtReset::FixDtReset(LAMMPS *lmp, int narg, char **arg) :
|
FixDtReset::FixDtReset(LAMMPS *lmp, int narg, char **arg) : Fix(lmp, narg, arg)
|
||||||
Fix(lmp, narg, arg)
|
|
||||||
{
|
{
|
||||||
if (narg < 7) error->all(FLERR,"Illegal fix dt/reset command");
|
if (narg < 7) error->all(FLERR, "Illegal fix dt/reset command");
|
||||||
|
|
||||||
// set time_depend, else elapsed time accumulation can be messed up
|
// set time_depend, else elapsed time accumulation can be messed up
|
||||||
|
|
||||||
|
@ -51,40 +50,47 @@ FixDtReset::FixDtReset(LAMMPS *lmp, int narg, char **arg) :
|
||||||
extvector = 0;
|
extvector = 0;
|
||||||
dynamic_group_allow = 1;
|
dynamic_group_allow = 1;
|
||||||
|
|
||||||
nevery = utils::inumeric(FLERR,arg[3],false,lmp);
|
nevery = utils::inumeric(FLERR, arg[3], false, lmp);
|
||||||
if (nevery <= 0) error->all(FLERR,"Illegal fix dt/reset command");
|
if (nevery <= 0) error->all(FLERR, "Illegal fix dt/reset command");
|
||||||
|
|
||||||
minbound = maxbound = 1;
|
minbound = maxbound = 1;
|
||||||
tmin = tmax = 0.0;
|
tmin = tmax = 0.0;
|
||||||
if (strcmp(arg[4],"NULL") == 0) minbound = 0;
|
if (strcmp(arg[4], "NULL") == 0)
|
||||||
else tmin = utils::numeric(FLERR,arg[4],false,lmp);
|
minbound = 0;
|
||||||
if (strcmp(arg[5],"NULL") == 0) maxbound = 0;
|
else
|
||||||
else tmax = utils::numeric(FLERR,arg[5],false,lmp);
|
tmin = utils::numeric(FLERR, arg[4], false, lmp);
|
||||||
xmax = utils::numeric(FLERR,arg[6],false,lmp);
|
if (strcmp(arg[5], "NULL") == 0)
|
||||||
|
maxbound = 0;
|
||||||
|
else
|
||||||
|
tmax = utils::numeric(FLERR, arg[5], false, lmp);
|
||||||
|
xmax = utils::numeric(FLERR, arg[6], false, lmp);
|
||||||
|
|
||||||
if (minbound && tmin < 0.0) error->all(FLERR,"Illegal fix dt/reset command");
|
if (minbound && tmin < 0.0) error->all(FLERR, "Illegal fix dt/reset command");
|
||||||
if (maxbound && tmax < 0.0) error->all(FLERR,"Illegal fix dt/reset command");
|
if (maxbound && tmax < 0.0) error->all(FLERR, "Illegal fix dt/reset command");
|
||||||
if (minbound && maxbound && tmin >= tmax)
|
if (minbound && maxbound && tmin >= tmax) error->all(FLERR, "Illegal fix dt/reset command");
|
||||||
error->all(FLERR,"Illegal fix dt/reset command");
|
if (xmax <= 0.0) error->all(FLERR, "Illegal fix dt/reset command");
|
||||||
if (xmax <= 0.0) error->all(FLERR,"Illegal fix dt/reset command");
|
|
||||||
|
|
||||||
int scaleflag = 1;
|
int scaleflag = 1;
|
||||||
|
|
||||||
emax = -1.0;
|
emax = -1.0;
|
||||||
int iarg = 7;
|
int iarg = 7;
|
||||||
while (iarg < narg) {
|
while (iarg < narg) {
|
||||||
if (strcmp(arg[iarg],"units") == 0) {
|
if (strcmp(arg[iarg], "units") == 0) {
|
||||||
if (iarg+2 > narg) error->all(FLERR,"Illegal fix dt/reset command");
|
if (iarg + 2 > narg) error->all(FLERR, "Illegal fix dt/reset command");
|
||||||
if (strcmp(arg[iarg+1],"box") == 0) scaleflag = 0;
|
if (strcmp(arg[iarg + 1], "box") == 0)
|
||||||
else if (strcmp(arg[iarg+1],"lattice") == 0) scaleflag = 1;
|
scaleflag = 0;
|
||||||
else error->all(FLERR,"Illegal fix dt/reset command");
|
else if (strcmp(arg[iarg + 1], "lattice") == 0)
|
||||||
|
scaleflag = 1;
|
||||||
|
else
|
||||||
|
error->all(FLERR, "Illegal fix dt/reset command");
|
||||||
iarg += 2;
|
iarg += 2;
|
||||||
} else if (strcmp(arg[iarg],"emax") == 0) {
|
} else if (strcmp(arg[iarg], "emax") == 0) {
|
||||||
if (iarg+2 > narg) error->all(FLERR,"Illegal fix dt/reset command");
|
if (iarg + 2 > narg) error->all(FLERR, "Illegal fix dt/reset command");
|
||||||
emax = utils::numeric(FLERR,arg[iarg+1],false,lmp);
|
emax = utils::numeric(FLERR, arg[iarg + 1], false, lmp);
|
||||||
if (emax <= 0.0) error->all(FLERR,"Illegal fix dt/reset command");
|
if (emax <= 0.0) error->all(FLERR, "Illegal fix dt/reset command");
|
||||||
iarg += 2;
|
iarg += 2;
|
||||||
} else error->all(FLERR,"Illegal fix dt/reset command");
|
} else
|
||||||
|
error->all(FLERR, "Illegal fix dt/reset command");
|
||||||
}
|
}
|
||||||
|
|
||||||
// setup scaling, based on xlattice parameter
|
// setup scaling, based on xlattice parameter
|
||||||
|
@ -113,15 +119,15 @@ void FixDtReset::init()
|
||||||
// set rRESPA flag
|
// set rRESPA flag
|
||||||
|
|
||||||
respaflag = 0;
|
respaflag = 0;
|
||||||
if (utils::strmatch(update->integrate_style,"^respa")) respaflag = 1;
|
if (utils::strmatch(update->integrate_style, "^respa")) respaflag = 1;
|
||||||
|
|
||||||
// check for DCD or XTC dumps
|
// check for DCD or XTC dumps
|
||||||
|
|
||||||
for (int i = 0; i < output->ndump; i++)
|
for (int i = 0; i < output->ndump; i++)
|
||||||
if ((strcmp(output->dump[i]->style,"dcd") == 0 ||
|
if ((strcmp(output->dump[i]->style, "dcd") == 0 ||
|
||||||
strcmp(output->dump[i]->style,"xtc") == 0) && comm->me == 0)
|
strcmp(output->dump[i]->style, "xtc") == 0) &&
|
||||||
error->warning(FLERR,
|
comm->me == 0)
|
||||||
"Dump dcd/xtc timestamp may be wrong with fix dt/reset");
|
error->warning(FLERR, "Dump dcd/xtc timestamp may be wrong with fix dt/reset");
|
||||||
|
|
||||||
ftm2v = force->ftm2v;
|
ftm2v = force->ftm2v;
|
||||||
mvv2e = force->mvv2e;
|
mvv2e = force->mvv2e;
|
||||||
|
@ -139,9 +145,9 @@ void FixDtReset::setup(int /*vflag*/)
|
||||||
|
|
||||||
void FixDtReset::end_of_step()
|
void FixDtReset::end_of_step()
|
||||||
{
|
{
|
||||||
double dtv,dtf,dte,dtsq;
|
double dtv, dtf, dte, dtsq;
|
||||||
double vsq,fsq,massinv;
|
double vsq, fsq, massinv;
|
||||||
double delx,dely,delz,delr;
|
double delx, dely, delz, delr;
|
||||||
|
|
||||||
double **v = atom->v;
|
double **v = atom->v;
|
||||||
double **f = atom->f;
|
double **f = atom->f;
|
||||||
|
@ -155,31 +161,33 @@ void FixDtReset::end_of_step()
|
||||||
|
|
||||||
for (int i = 0; i < nlocal; i++)
|
for (int i = 0; i < nlocal; i++)
|
||||||
if (mask[i] & groupbit) {
|
if (mask[i] & groupbit) {
|
||||||
if (rmass) massinv = 1.0/rmass[i];
|
if (rmass)
|
||||||
else massinv = 1.0/mass[type[i]];
|
massinv = 1.0 / rmass[i];
|
||||||
vsq = v[i][0]*v[i][0] + v[i][1]*v[i][1] + v[i][2]*v[i][2];
|
else
|
||||||
fsq = f[i][0]*f[i][0] + f[i][1]*f[i][1] + f[i][2]*f[i][2];
|
massinv = 1.0 / mass[type[i]];
|
||||||
|
vsq = v[i][0] * v[i][0] + v[i][1] * v[i][1] + v[i][2] * v[i][2];
|
||||||
|
fsq = f[i][0] * f[i][0] + f[i][1] * f[i][1] + f[i][2] * f[i][2];
|
||||||
dtv = dtf = dte = BIG;
|
dtv = dtf = dte = BIG;
|
||||||
if (vsq > 0.0) dtv = xmax/sqrt(vsq);
|
if (vsq > 0.0) dtv = xmax / sqrt(vsq);
|
||||||
if (fsq > 0.0) dtf = sqrt(2.0*xmax/(ftm2v*sqrt(fsq)*massinv));
|
if (fsq > 0.0) dtf = sqrt(2.0 * xmax / (ftm2v * sqrt(fsq) * massinv));
|
||||||
dt = MIN(dtv,dtf);
|
dt = MIN(dtv, dtf);
|
||||||
if (emax > 0.0 && vsq > 0.0 && fsq > 0.0) {
|
if (emax > 0.0 && vsq > 0.0 && fsq > 0.0) {
|
||||||
dte = emax/sqrt(fsq*vsq)/sqrt(ftm2v*mvv2e);
|
dte = emax / sqrt(fsq * vsq) / sqrt(ftm2v * mvv2e);
|
||||||
dt = MIN(dt, dte);
|
dt = MIN(dt, dte);
|
||||||
}
|
}
|
||||||
dtsq = dt*dt;
|
dtsq = dt * dt;
|
||||||
delx = dt*v[i][0] + 0.5*dtsq*massinv*f[i][0] * ftm2v;
|
delx = dt * v[i][0] + 0.5 * dtsq * massinv * f[i][0] * ftm2v;
|
||||||
dely = dt*v[i][1] + 0.5*dtsq*massinv*f[i][1] * ftm2v;
|
dely = dt * v[i][1] + 0.5 * dtsq * massinv * f[i][1] * ftm2v;
|
||||||
delz = dt*v[i][2] + 0.5*dtsq*massinv*f[i][2] * ftm2v;
|
delz = dt * v[i][2] + 0.5 * dtsq * massinv * f[i][2] * ftm2v;
|
||||||
delr = sqrt(delx*delx + dely*dely + delz*delz);
|
delr = sqrt(delx * delx + dely * dely + delz * delz);
|
||||||
if (delr > xmax) dt *= xmax/delr;
|
if (delr > xmax) dt *= xmax / delr;
|
||||||
dtmin = MIN(dtmin,dt);
|
dtmin = MIN(dtmin, dt);
|
||||||
}
|
}
|
||||||
|
|
||||||
MPI_Allreduce(&dtmin,&dt,1,MPI_DOUBLE,MPI_MIN,world);
|
MPI_Allreduce(&dtmin, &dt, 1, MPI_DOUBLE, MPI_MIN, world);
|
||||||
|
|
||||||
if (minbound) dt = MAX(dt,tmin);
|
if (minbound) dt = MAX(dt, tmin);
|
||||||
if (maxbound) dt = MIN(dt,tmax);
|
if (maxbound) dt = MIN(dt, tmax);
|
||||||
|
|
||||||
// if timestep didn't change, just return
|
// if timestep didn't change, just return
|
||||||
// else reset update->dt and other classes that depend on it
|
// else reset update->dt and other classes that depend on it
|
||||||
|
|
Loading…
Reference in New Issue