use enumerators for symbolic constants to flag integrator and linesearch styles
also a small update to error, warning, and info output
This commit is contained in:
@ -87,9 +87,9 @@ void MinKokkos::setup(int flag)
|
||||
nextra_global = modify->min_dof();
|
||||
if (nextra_global) {
|
||||
fextra = new double[nextra_global];
|
||||
if (comm->me == 0 && screen)
|
||||
fprintf(screen,"WARNING: Energy due to %d extra global DOFs will"
|
||||
" be included in minimizer energies\n",nextra_global);
|
||||
if (comm->me == 0)
|
||||
error->warning(FLERR, "Energy due to {} extra global DOFs will"
|
||||
" be included in minimizer energies\n", nextra_global);
|
||||
}
|
||||
|
||||
// compute for potential energy
|
||||
|
||||
@ -69,7 +69,7 @@ void MinLineSearchKokkos::init()
|
||||
{
|
||||
MinKokkos::init();
|
||||
|
||||
if (linestyle == 1) linemin = &MinLineSearchKokkos::linemin_quadratic;
|
||||
if (linestyle == QUADRATIC) linemin = &MinLineSearchKokkos::linemin_quadratic;
|
||||
else error->all(FLERR,"Kokkos minimize only supports the 'min_modify line "
|
||||
"quadratic' option");
|
||||
}
|
||||
|
||||
@ -99,12 +99,12 @@ void MinSpinCG::init()
|
||||
|
||||
// warning if line_search combined to gneb
|
||||
|
||||
if ((nreplica >= 1) && (linestyle != 4) && (comm->me == 0))
|
||||
error->warning(FLERR,"Line search incompatible gneb");
|
||||
if ((nreplica >= 1) && (linestyle != SPIN_NONE) && (comm->me == 0))
|
||||
error->warning(FLERR,"Line search incompatible with gneb");
|
||||
|
||||
// set back use_line_search to 0 if more than one replica
|
||||
|
||||
if (linestyle == 3 && nreplica == 1) {
|
||||
if (linestyle == SPIN_CUBIC && nreplica == 1) {
|
||||
use_line_search = 1;
|
||||
}
|
||||
else{
|
||||
|
||||
@ -104,12 +104,12 @@ void MinSpinLBFGS::init()
|
||||
|
||||
// warning if line_search combined to gneb
|
||||
|
||||
if ((nreplica >= 1) && (linestyle != 4) && (comm->me == 0))
|
||||
error->warning(FLERR,"Line search incompatible gneb");
|
||||
if ((nreplica >= 1) && (linestyle != SPIN_NONE) && (comm->me == 0))
|
||||
error->warning(FLERR,"Line search incompatible with gneb");
|
||||
|
||||
// set back use_line_search to 0 if more than one replica
|
||||
|
||||
if (linestyle == 3 && nreplica == 1) {
|
||||
if (linestyle == SPIN_CUBIC && nreplica == 1) {
|
||||
use_line_search = 1;
|
||||
}
|
||||
else{
|
||||
|
||||
17
src/min.cpp
17
src/min.cpp
@ -205,8 +205,7 @@ void Min::init()
|
||||
void Min::setup(int flag)
|
||||
{
|
||||
if (comm->me == 0 && screen) {
|
||||
fmt::print(screen,"Setting up {} style minimization ...\n",
|
||||
update->minimize_style);
|
||||
fmt::print(screen,"Setting up {} style minimization ...\n", update->minimize_style);
|
||||
if (flag) {
|
||||
fmt::print(screen," Unit style : {}\n", update->unit_style);
|
||||
fmt::print(screen," Current step : {}\n", update->ntimestep);
|
||||
@ -221,9 +220,9 @@ void Min::setup(int flag)
|
||||
nextra_global = modify->min_dof();
|
||||
if (nextra_global) {
|
||||
fextra = new double[nextra_global];
|
||||
if (comm->me == 0 && screen)
|
||||
fprintf(screen,"WARNING: Energy due to %d extra global DOFs will"
|
||||
" be included in minimizer energies\n",nextra_global);
|
||||
if (comm->me == 0)
|
||||
error->warning(FLERR, "Energy due to {} extra global DOFs will"
|
||||
" be included in minimizer energies\n",nextra_global);
|
||||
}
|
||||
|
||||
// compute for potential energy
|
||||
@ -714,10 +713,10 @@ void Min::modify_params(int narg, char **arg)
|
||||
iarg += 2;
|
||||
} else if (strcmp(arg[iarg],"integrator") == 0) {
|
||||
if (iarg+2 > narg) error->all(FLERR,"Illegal min_modify command");
|
||||
if (strcmp(arg[iarg+1],"eulerimplicit") == 0) integrator = 0;
|
||||
else if (strcmp(arg[iarg+1],"verlet") == 0) integrator = 1;
|
||||
else if (strcmp(arg[iarg+1],"leapfrog") == 0) integrator = 2;
|
||||
else if (strcmp(arg[iarg+1],"eulerexplicit") == 0) integrator = 3;
|
||||
if (strcmp(arg[iarg+1],"eulerimplicit") == 0) integrator = EULERIMPLICIT;
|
||||
else if (strcmp(arg[iarg+1],"verlet") == 0) integrator = VERLET;
|
||||
else if (strcmp(arg[iarg+1],"leapfrog") == 0) integrator = LEAPFROG;
|
||||
else if (strcmp(arg[iarg+1],"eulerexplicit") == 0) integrator = EULEREXPLICIT;
|
||||
else error->all(FLERR,"Illegal min_modify command");
|
||||
iarg += 2;
|
||||
} else if (strcmp(arg[iarg],"line") == 0) {
|
||||
|
||||
@ -72,6 +72,12 @@ class Min : protected Pointers {
|
||||
MAXVDOTF
|
||||
};
|
||||
|
||||
// integrator styles
|
||||
enum { EULERIMPLICIT, VERLET, LEAPFROG, EULEREXPLICIT };
|
||||
|
||||
// line search styles
|
||||
enum { BACKTRACK, QUADRATIC, FORCEZERO, SPIN_CUBIC, SPIN_NONE };
|
||||
|
||||
protected:
|
||||
int eflag, vflag; // flags for energy/virial computation
|
||||
int virial_style; // compute virial explicitly or implicitly
|
||||
|
||||
@ -1,4 +1,3 @@
|
||||
// clang-format off
|
||||
/* ----------------------------------------------------------------------
|
||||
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
|
||||
https://www.lammps.org/, Sandia National Laboratories
|
||||
@ -48,9 +47,9 @@ void MinFire::init()
|
||||
|
||||
// simple parameters validation
|
||||
|
||||
if (tmax < tmin) error->all(FLERR,"tmax has to be larger than tmin");
|
||||
if (dtgrow < 1.0) error->all(FLERR,"dtgrow has to be larger than 1.0");
|
||||
if (dtshrink > 1.0) error->all(FLERR,"dtshrink has to be smaller than 1.0");
|
||||
if (tmax < tmin) error->all(FLERR, "tmax has to be larger than tmin");
|
||||
if (dtgrow < 1.0) error->all(FLERR, "dtgrow has to be larger than 1.0");
|
||||
if (dtshrink > 1.0) error->all(FLERR, "dtshrink has to be smaller than 1.0");
|
||||
|
||||
dt = update->dt;
|
||||
dtmax = tmax * dt;
|
||||
@ -69,22 +68,22 @@ void MinFire::setup_style()
|
||||
|
||||
// print the parameters used within fire into the log
|
||||
|
||||
const char *s1[] = {"eulerimplicit","verlet","leapfrog","eulerexplicit"};
|
||||
const char *s2[] = {"no","yes"};
|
||||
const char *integrator_names[] = {"eulerimplicit", "verlet", "leapfrog", "eulerexplicit"};
|
||||
const char *yesno[] = {"yes", "no"};
|
||||
|
||||
if (comm->me == 0 && logfile) {
|
||||
fprintf(logfile," Parameters for fire: \n"
|
||||
" dmax delaystep dtgrow dtshrink alpha0 alphashrink tmax tmin "
|
||||
" integrator halfstepback \n"
|
||||
" %4g %9i %6g %8g %6g %11g %4g %4g %13s %12s \n",
|
||||
dmax, delaystep, dtgrow, dtshrink, alpha0, alphashrink, tmax, tmin,
|
||||
s1[integrator], s2[halfstepback_flag]);
|
||||
}
|
||||
if (comm->me == 0)
|
||||
utils::logmesg(lmp,
|
||||
" Parameters for {}:\n"
|
||||
" {:^5} {:^9} {:^6} {:^8} {:^6} {:^11} {:^4} {:^4} {:^14} {:^12} \n"
|
||||
" {:^5} {:^9} {:^6} {:^8} {:^6} {:^11} {:^4} {:^4} {:^14} {:^12} \n",
|
||||
update->minimize_style, "dmax", "delaystep", "dtgrow", "dtshrink", "alpha0",
|
||||
"alphashrink", "tmax", "tmin", "integrator", "halfstepback", dmax, delaystep,
|
||||
dtgrow, dtshrink, alpha0, alphashrink, tmax, tmin, integrator_names[integrator],
|
||||
yesno[halfstepback_flag]);
|
||||
|
||||
// initialize the velocities
|
||||
|
||||
for (int i = 0; i < nlocal; i++)
|
||||
v[i][0] = v[i][1] = v[i][2] = 0.0;
|
||||
for (int i = 0; i < nlocal; i++) v[i][0] = v[i][1] = v[i][2] = 0.0;
|
||||
flagv0 = 1;
|
||||
}
|
||||
|
||||
@ -102,6 +101,7 @@ void MinFire::reset_vectors()
|
||||
if (nvec) fvec = atom->f[0];
|
||||
}
|
||||
|
||||
// clang-format off
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
int MinFire::iterate(int maxiter)
|
||||
@ -116,7 +116,7 @@ int MinFire::iterate(int maxiter)
|
||||
|
||||
// Leap Frog integration initialization
|
||||
|
||||
if (integrator == 2) {
|
||||
if (integrator == LEAPFROG) {
|
||||
|
||||
double **f = atom->f;
|
||||
double **v = atom->v;
|
||||
@ -321,15 +321,9 @@ int MinFire::iterate(int maxiter)
|
||||
MPI_Allreduce(&dtvone,&dtv,1,MPI_DOUBLE,MPI_MIN,universe->uworld);
|
||||
}
|
||||
|
||||
// Dynamic integration scheme:
|
||||
// 0: semi-implicit Euler
|
||||
// 1: velocity Verlet
|
||||
// 2: leapfrog (initial half step before the iteration loop)
|
||||
// 3: explicit Euler
|
||||
// Adapt to requested integration style for dynamics
|
||||
|
||||
// Semi-implicit Euler OR Leap Frog integration
|
||||
|
||||
if (integrator == 0 || integrator == 2) {
|
||||
if (integrator == EULERIMPLICIT || integrator == LEAPFROG) {
|
||||
|
||||
dtf = dtv * force->ftm2v;
|
||||
|
||||
@ -371,7 +365,7 @@ int MinFire::iterate(int maxiter)
|
||||
|
||||
// Velocity Verlet integration
|
||||
|
||||
} else if (integrator == 1) {
|
||||
} else if (integrator == VERLET) {
|
||||
|
||||
dtf = 0.5 * dtv * force->ftm2v;
|
||||
|
||||
@ -429,7 +423,7 @@ int MinFire::iterate(int maxiter)
|
||||
|
||||
// Standard Euler integration
|
||||
|
||||
} else if (integrator == 3) {
|
||||
} else if (integrator == EULEREXPLICIT) {
|
||||
|
||||
dtf = dtv * force->ftm2v;
|
||||
|
||||
|
||||
@ -63,11 +63,11 @@ MinLineSearch::MinLineSearch(LAMMPS *lmp) : Min(lmp)
|
||||
|
||||
MinLineSearch::~MinLineSearch()
|
||||
{
|
||||
delete [] gextra;
|
||||
delete [] hextra;
|
||||
delete [] x0extra_atom;
|
||||
delete [] gextra_atom;
|
||||
delete [] hextra_atom;
|
||||
delete[] gextra;
|
||||
delete[] hextra;
|
||||
delete[] x0extra_atom;
|
||||
delete[] gextra_atom;
|
||||
delete[] hextra_atom;
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
@ -76,17 +76,17 @@ void MinLineSearch::init()
|
||||
{
|
||||
Min::init();
|
||||
|
||||
if (linestyle == 0) linemin = &MinLineSearch::linemin_backtrack;
|
||||
else if (linestyle == 1) linemin = &MinLineSearch::linemin_quadratic;
|
||||
else if (linestyle == 2) linemin = &MinLineSearch::linemin_forcezero;
|
||||
if (linestyle == BACKTRACK) linemin = &MinLineSearch::linemin_backtrack;
|
||||
else if (linestyle == QUADRATIC) linemin = &MinLineSearch::linemin_quadratic;
|
||||
else if (linestyle == FORCEZERO) linemin = &MinLineSearch::linemin_forcezero;
|
||||
|
||||
delete [] gextra;
|
||||
delete [] hextra;
|
||||
delete[] gextra;
|
||||
delete[] hextra;
|
||||
gextra = hextra = nullptr;
|
||||
|
||||
delete [] x0extra_atom;
|
||||
delete [] gextra_atom;
|
||||
delete [] hextra_atom;
|
||||
delete[] x0extra_atom;
|
||||
delete[] gextra_atom;
|
||||
delete[] hextra_atom;
|
||||
x0extra_atom = gextra_atom = hextra_atom = nullptr;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user