From 2f3c73217b0a78e23f843a984cbb6f67d02f8993 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 15 Sep 2020 10:50:44 -0400 Subject: [PATCH] detect if dt has been changed from default and print warning if reset by units command --- src/USER-EFF/pair_eff_cut.cpp | 2 +- src/USER-SMD/fix_smd_adjust_dt.cpp | 1 + src/fix_dt_reset.cpp | 1 + src/input.cpp | 1 + src/update.cpp | 31 ++++++++++++++++++++++-------- src/update.h | 1 + 6 files changed, 28 insertions(+), 9 deletions(-) diff --git a/src/USER-EFF/pair_eff_cut.cpp b/src/USER-EFF/pair_eff_cut.cpp index f4e7af6584..72281c4a50 100644 --- a/src/USER-EFF/pair_eff_cut.cpp +++ b/src/USER-EFF/pair_eff_cut.cpp @@ -869,7 +869,7 @@ void PairEffCut::init_style() // make sure to use the appropriate timestep when using real units if (update->whichflag == 1) { - if (force->qqr2e == 332.06371 && update->dt == 1.0) + if (utils::strmatch(update->unit_style,"^real") && update->dt_default) error->all(FLERR,"Must lower the default real units timestep for pEFF "); } diff --git a/src/USER-SMD/fix_smd_adjust_dt.cpp b/src/USER-SMD/fix_smd_adjust_dt.cpp index b5dab3d3a1..2acf6bd3ec 100644 --- a/src/USER-SMD/fix_smd_adjust_dt.cpp +++ b/src/USER-SMD/fix_smd_adjust_dt.cpp @@ -186,6 +186,7 @@ void FixSMDTlsphDtReset::end_of_step() { update->dt = dt; + update->dt_default = 0; if (force->pair) force->pair->reset_dt(); for (int i = 0; i < modify->nfix; i++) diff --git a/src/fix_dt_reset.cpp b/src/fix_dt_reset.cpp index 360f0d2998..4a9465e696 100644 --- a/src/fix_dt_reset.cpp +++ b/src/fix_dt_reset.cpp @@ -190,6 +190,7 @@ void FixDtReset::end_of_step() update->update_time(); update->dt = dt; + update->dt_default = 0; if (respaflag) update->integrate->reset_dt(); if (force->pair) force->pair->reset_dt(); for (int i = 0; i < modify->nfix; i++) modify->fix[i]->reset_dt(); diff --git a/src/input.cpp b/src/input.cpp index 6456f6c229..3a136cd44b 100644 --- a/src/input.cpp +++ b/src/input.cpp @@ -1871,6 +1871,7 @@ void Input::timestep() { if (narg != 1) error->all(FLERR,"Illegal timestep command"); update->dt = utils::numeric(FLERR,arg[0],false,lmp); + update->dt_default = 0; } /* ---------------------------------------------------------------------- */ diff --git a/src/update.cpp b/src/update.cpp index 399584473c..d591e05131 100644 --- a/src/update.cpp +++ b/src/update.cpp @@ -12,18 +12,22 @@ ------------------------------------------------------------------------- */ #include "update.h" -#include -#include "integrate.h" -#include "min.h" + #include "style_integrate.h" // IWYU pragma: keep #include "style_minimize.h" // IWYU pragma: keep -#include "neighbor.h" -#include "force.h" -#include "modify.h" -#include "fix.h" + +#include "comm.h" #include "compute.h" -#include "output.h" +#include "integrate.h" #include "error.h" +#include "fix.h" +#include "force.h" +#include "min.h" +#include "modify.h" +#include "neighbor.h" +#include "output.h" + +#include using namespace LAMMPS_NS; @@ -48,6 +52,7 @@ Update::Update(LAMMPS *lmp) : Pointers(lmp) eflag_global = vflag_global = -1; + dt_default = 1; unit_style = NULL; set_units("lj"); @@ -121,6 +126,8 @@ void Update::set_units(const char *style) // http://physics.nist.gov/cuu/Constants/Table/allascii.txt // using thermochemical calorie = 4.184 J + double dt_old = dt; + if (strcmp(style,"lj") == 0) { force->boltz = 1.0; force->hplanck = 1.0; @@ -295,6 +302,14 @@ void Update::set_units(const char *style) int n = strlen(style) + 1; unit_style = new char[n]; strcpy(unit_style,style); + + // check if timestep was changed from default value + if (!dt_default && (comm->me == 0)) { + error->warning(FLERR,fmt::format("Changing timestep from {:.6} to {:.6} " + "due to changing units to {}", + dt_old, dt, unit_style)); + } + dt_default = 1; } /* ---------------------------------------------------------------------- */ diff --git a/src/update.h b/src/update.h index 558719f4cc..1d1e04b8bd 100644 --- a/src/update.h +++ b/src/update.h @@ -37,6 +37,7 @@ class Update : protected Pointers { int setupflag; // set when setup() is computing forces int post_integrate; // 1 if now at post_integrate() in timestep int multireplica; // 1 if min across replicas, else 0 + int dt_default; // 1 if dt is at default value, else 0 bigint eflag_global,eflag_atom; // timestep global/peratom eng is tallied on bigint vflag_global,vflag_atom; // ditto for virial