From 21f3f51ea2a719c9e57bdaf31c34b385c0c4efd4 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 2 Aug 2019 10:13:52 -0400 Subject: [PATCH 1/4] better error messages on accessing invalid IDs in variable expressions --- src/variable.cpp | 65 +++++++++++++++++++++++++++++++++--------------- 1 file changed, 45 insertions(+), 20 deletions(-) diff --git a/src/variable.cpp b/src/variable.cpp index 3fffa11d5e..1093ce9066 100644 --- a/src/variable.cpp +++ b/src/variable.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #include "universe.h" #include "atom.h" #include "update.h" @@ -1302,8 +1303,12 @@ double Variable::evaluate(char *str, Tree **tree, int ivar) if (word[0] == 'C') lowercase = 0; int icompute = modify->find_compute(word+2); - if (icompute < 0) - print_var_error(FLERR,"Invalid compute ID in variable formula",ivar); + if (icompute < 0) { + std::string mesg = "Invalid compute ID '"; + mesg += (word+2); + mesg += "' in variable formula"; + print_var_error(FLERR,mesg.c_str(),ivar); + } Compute *compute = modify->compute[icompute]; // parse zero or one or two trailing brackets @@ -1604,9 +1609,10 @@ double Variable::evaluate(char *str, Tree **tree, int ivar) int ifix = modify->find_fix(word+2); if (ifix < 0) { - char msg[128]; - snprintf(msg,128,"Invalid fix ID '%s' in variable formula",word+2); - print_var_error(FLERR,msg,ivar); + std::string mesg = "Invalid fix ID '"; + mesg += (word+2); + mesg += "' in variable formula"; + print_var_error(FLERR,mesg.c_str(),ivar); } Fix *fix = modify->fix[ifix]; @@ -3792,8 +3798,12 @@ int Variable::group_function(char *word, char *contents, Tree **tree, // group to operate on int igroup = group->find(args[0]); - if (igroup == -1) - print_var_error(FLERR,"Group ID in variable formula does not exist",ivar); + if (igroup == -1) { + std::string mesg = "Group ID '"; + mesg += args[0]; + mesg += "' in variable formula does not exist"; + print_var_error(FLERR,mesg.c_str(),ivar); + } // match word to group function @@ -4001,8 +4011,12 @@ int Variable::group_function(char *word, char *contents, Tree **tree, int Variable::region_function(char *id, int ivar) { int iregion = domain->find_region(id); - if (iregion == -1) - print_var_error(FLERR,"Region ID in variable formula does not exist",ivar); + if (iregion == -1) { + std::string mesg = "Region ID '"; + mesg += id; + mesg += "' in variable formula does not exist"; + print_var_error(FLERR,mesg.c_str(),ivar); + } // init region in case sub-regions have been deleted @@ -4080,9 +4094,10 @@ int Variable::special_function(char *word, char *contents, Tree **tree, int icompute = modify->find_compute(&args[0][2]); if (icompute < 0) { - char msg[128]; - snprintf(msg,128,"Invalid compute ID '%s' in variable formula",word+2); - print_var_error(FLERR,msg,ivar); + std::string mesg = "Invalid compute ID '"; + mesg += (args[0]+2); + mesg += "' in variable formula"; + print_var_error(FLERR,mesg.c_str(),ivar); } compute = modify->compute[icompute]; if (index == 0 && compute->vector_flag) { @@ -4123,13 +4138,20 @@ int Variable::special_function(char *word, char *contents, Tree **tree, } else index = 0; int ifix = modify->find_fix(&args[0][2]); - if (ifix < 0) - print_var_error(FLERR,"Invalid fix ID in variable formula",ivar); + if (ifix < 0) { + std::string mesg = "Invalid fix ID '"; + mesg += (args[0]+2); + mesg += "' in variable formula"; + print_var_error(FLERR,mesg.c_str(),ivar); + } fix = modify->fix[ifix]; if (index == 0 && fix->vector_flag) { - if (update->whichflag > 0 && update->ntimestep % fix->global_freq) - print_var_error(FLERR,"Fix in variable not computed at " - "compatible time",ivar); + if (update->whichflag > 0 && update->ntimestep % fix->global_freq) { + std::string mesg = "Fix with ID '"; + mesg += (args[0]+2); + mesg += "' in variable formula not computed at compatible time"; + print_var_error(FLERR,mesg.c_str(),ivar); + } nvec = fix->size_vector; nstride = 1; } else if (index && fix->array_flag) { @@ -4336,9 +4358,12 @@ int Variable::special_function(char *word, char *contents, Tree **tree, print_var_error(FLERR,"Invalid special function in variable formula",ivar); int ivar = find(args[0]); - if (ivar < 0) - print_var_error(FLERR,"Variable ID in " - "variable formula does not exist",ivar); + if (ivar < 0) { + std::string mesg = "Variable ID '"; + mesg += args[0]; + mesg += "' in variable formula does not exist"; + print_var_error(FLERR,mesg.c_str(),ivar); + } // SCALARFILE has single current value, read next one // save value in tree or on argstack From 71ce1c20274d373b4312171d8f4ef95921a16a7c Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 5 Aug 2019 23:25:06 -0400 Subject: [PATCH 2/4] use cube() and square() from math_special.h instead of pow(x,3.0) and pow(x,2.0) --- src/MANYBODY/pair_tersoff.cpp | 8 +++++--- src/MANYBODY/pair_tersoff_mod.cpp | 8 +++++--- src/MANYBODY/pair_tersoff_zbl.cpp | 6 ++++-- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/MANYBODY/pair_tersoff.cpp b/src/MANYBODY/pair_tersoff.cpp index 62c74576e0..5f53760e71 100644 --- a/src/MANYBODY/pair_tersoff.cpp +++ b/src/MANYBODY/pair_tersoff.cpp @@ -30,9 +30,11 @@ #include "error.h" #include "math_const.h" +#include "math_special.h" using namespace LAMMPS_NS; using namespace MathConst; +using namespace MathSpecial; #define MAXLINE 1024 #define DELTA 4 @@ -604,7 +606,7 @@ double PairTersoff::zeta(Param *param, double rsqij, double rsqik, costheta = (delrij[0]*delrik[0] + delrij[1]*delrik[1] + delrij[2]*delrik[2]) / (rij*rik); - if (param->powermint == 3) arg = pow(param->lam3 * (rij-rik),3.0); + if (param->powermint == 3) arg = cube(param->lam3 * (rij-rik)); else arg = param->lam3 * (rij-rik); if (arg > 69.0776) ex_delr = 1.e30; @@ -744,7 +746,7 @@ void PairTersoff::ters_zetaterm_d(double prefactor, fc = ters_fc(rik,param); dfc = ters_fc_d(rik,param); - if (param->powermint == 3) tmp = pow(param->lam3 * (rij-rik),3.0); + if (param->powermint == 3) tmp = cube(param->lam3 * (rij-rik)); else tmp = param->lam3 * (rij-rik); if (tmp > 69.0776) ex_delr = 1.e30; @@ -752,7 +754,7 @@ void PairTersoff::ters_zetaterm_d(double prefactor, else ex_delr = exp(tmp); if (param->powermint == 3) - ex_delr_d = 3.0*pow(param->lam3,3.0) * pow(rij-rik,2.0)*ex_delr; + ex_delr_d = 3.0*cube(param->lam3) * square(rij-rik)*ex_delr; else ex_delr_d = param->lam3 * ex_delr; cos_theta = vec3_dot(rij_hat,rik_hat); diff --git a/src/MANYBODY/pair_tersoff_mod.cpp b/src/MANYBODY/pair_tersoff_mod.cpp index 698dd8fa03..9d4bdb7fd0 100644 --- a/src/MANYBODY/pair_tersoff_mod.cpp +++ b/src/MANYBODY/pair_tersoff_mod.cpp @@ -25,11 +25,13 @@ #include "force.h" #include "comm.h" #include "math_const.h" +#include "math_special.h" #include "memory.h" #include "error.h" using namespace LAMMPS_NS; using namespace MathConst; +using namespace MathSpecial; #define MAXLINE 1024 #define DELTA 4 @@ -241,7 +243,7 @@ double PairTersoffMOD::zeta(Param *param, double rsqij, double rsqik, costheta = (delrij[0]*delrik[0] + delrij[1]*delrik[1] + delrij[2]*delrik[2]) / (rij*rik); - if (param->powermint == 3) arg = pow(param->lam3 * (rij-rik),3.0); + if (param->powermint == 3) arg = cube(param->lam3 * (rij-rik)); else arg = param->lam3 * (rij-rik); if (arg > 69.0776) ex_delr = 1.e30; @@ -314,7 +316,7 @@ void PairTersoffMOD::ters_zetaterm_d(double prefactor, fc = ters_fc(rik,param); dfc = ters_fc_d(rik,param); - if (param->powermint == 3) tmp = pow(param->lam3 * (rij-rik),3.0); + if (param->powermint == 3) tmp = cube(param->lam3 * (rij-rik)); else tmp = param->lam3 * (rij-rik); if (tmp > 69.0776) ex_delr = 1.e30; @@ -322,7 +324,7 @@ void PairTersoffMOD::ters_zetaterm_d(double prefactor, else ex_delr = exp(tmp); if (param->powermint == 3) - ex_delr_d = 3.0*pow(param->lam3,3.0) * pow(rij-rik,2.0)*ex_delr; + ex_delr_d = 3.0*cube(param->lam3) * square(rij-rik)*ex_delr; else ex_delr_d = param->lam3 * ex_delr; cos_theta = vec3_dot(rij_hat,rik_hat); diff --git a/src/MANYBODY/pair_tersoff_zbl.cpp b/src/MANYBODY/pair_tersoff_zbl.cpp index ab06e6ec31..d5e3fb1b0f 100644 --- a/src/MANYBODY/pair_tersoff_zbl.cpp +++ b/src/MANYBODY/pair_tersoff_zbl.cpp @@ -28,9 +28,11 @@ #include "memory.h" #include "error.h" #include "math_const.h" +#include "math_special.h" using namespace LAMMPS_NS; using namespace MathConst; +using namespace MathSpecial; #define MAXLINE 1024 #define DELTA 4 @@ -226,7 +228,7 @@ void PairTersoffZBL::repulsive(Param *param, double rsq, double &fforce, // ZBL repulsive portion - double esq = pow(global_e,2.0); + double esq = square(global_e); double a_ij = (0.8854*global_a_0) / (pow(param->Z_i,0.23) + pow(param->Z_j,0.23)); double premult = (param->Z_i * param->Z_j * esq)/(4.0*MY_PI*global_epsilon_0); @@ -286,5 +288,5 @@ double PairTersoffZBL::F_fermi(double r, Param *param) double PairTersoffZBL::F_fermi_d(double r, Param *param) { return param->ZBLexpscale*exp(-param->ZBLexpscale*(r-param->ZBLcut)) / - pow(1.0 + exp(-param->ZBLexpscale*(r-param->ZBLcut)),2.0); + square(1.0 + exp(-param->ZBLexpscale*(r-param->ZBLcut))); } From e4e2342641a42dea2eec7c941f8f3d45c4fff525 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 13 Aug 2019 11:01:14 -0400 Subject: [PATCH 3/4] no need to include mpi.h in headers that include pointers.h (directly or indirectly) --- src/comm_tiled.h | 1 - src/irregular.h | 1 - src/rcb.h | 1 - src/read_dump.h | 1 - 4 files changed, 4 deletions(-) diff --git a/src/comm_tiled.h b/src/comm_tiled.h index 4ceba44d4c..679be195aa 100644 --- a/src/comm_tiled.h +++ b/src/comm_tiled.h @@ -14,7 +14,6 @@ #ifndef LMP_COMM_TILED_H #define LMP_COMM_TILED_H -#include #include "comm.h" namespace LAMMPS_NS { diff --git a/src/irregular.h b/src/irregular.h index 7a3613b4e1..01fe40c46b 100644 --- a/src/irregular.h +++ b/src/irregular.h @@ -14,7 +14,6 @@ #ifndef LMP_IRREGULAR_H #define LMP_IRREGULAR_H -#include #include "pointers.h" namespace LAMMPS_NS { diff --git a/src/rcb.h b/src/rcb.h index f65ee2388a..555c4142b5 100644 --- a/src/rcb.h +++ b/src/rcb.h @@ -14,7 +14,6 @@ #ifndef LAMMPS_RCB_H #define LAMMPS_RCB_H -#include #include "pointers.h" namespace LAMMPS_NS { diff --git a/src/read_dump.h b/src/read_dump.h index 6fb4f11ed1..66c05cc445 100644 --- a/src/read_dump.h +++ b/src/read_dump.h @@ -22,7 +22,6 @@ CommandStyle(read_dump,ReadDump) #ifndef LMP_READ_DUMP_H #define LMP_READ_DUMP_H -#include #include "pointers.h" namespace LAMMPS_NS { From 88ff8ce2d7942ce9e01d934fbaed9f4ef4905548 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 20 Aug 2019 12:05:14 -0400 Subject: [PATCH 4/4] fix spelling issues in docs --- doc/src/fix.txt | 2 +- doc/utils/sphinx-config/false_positives.txt | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/doc/src/fix.txt b/doc/src/fix.txt index 409fde3503..e5036d5a73 100644 --- a/doc/src/fix.txt +++ b/doc/src/fix.txt @@ -244,7 +244,7 @@ accelerated styles exist. "mscg"_fix_mscg.html - apply MSCG method for force-matching to generate coarse grain models "msst"_fix_msst.html - multi-scale shock technique (MSST) integration "mvv/dpd"_fix_mvv_dpd.html - DPD using the modified velocity-Verlet integration algorithm -"mvv/edpd"_fix_mvv_dpd.html - constant energy DPD using the modified velocity-Verlet algrithm +"mvv/edpd"_fix_mvv_dpd.html - constant energy DPD using the modified velocity-Verlet algorithm "mvv/tdpd"_fix_mvv_dpd.html - constant temperature DPD using the modified velocity-Verlet algorithm "neb"_fix_neb.html - nudged elastic band (NEB) spring forces "nph"_fix_nh.html - constant NPH time integration via Nose/Hoover diff --git a/doc/utils/sphinx-config/false_positives.txt b/doc/utils/sphinx-config/false_positives.txt index 67252659bb..012c377ba5 100644 --- a/doc/utils/sphinx-config/false_positives.txt +++ b/doc/utils/sphinx-config/false_positives.txt @@ -421,6 +421,7 @@ coreshell cornflowerblue cornsilk corotate +corotation corotational correlator cosineshifted