From cc36947449c2a4059c2257e025421c569c7f67f2 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Wed, 22 Jan 2025 22:15:08 -0500 Subject: [PATCH] make use of new Error class APIs --- src/KSPACE/msm.cpp | 40 +++++++++++++++++++++------------------ src/KSPACE/pppm.cpp | 5 +++-- src/OPENMP/msm_cg_omp.cpp | 8 +++++--- src/OPENMP/msm_omp.cpp | 2 +- src/utils.cpp | 3 ++- 5 files changed, 33 insertions(+), 25 deletions(-) diff --git a/src/KSPACE/msm.cpp b/src/KSPACE/msm.cpp index 80fe145064..72e35ae9f3 100644 --- a/src/KSPACE/msm.cpp +++ b/src/KSPACE/msm.cpp @@ -77,11 +77,12 @@ MSM::MSM(LAMMPS *lmp) void MSM::settings(int narg, char **arg) { - if (narg < 1) error->all(FLERR,"Illegal kspace_style {} command", force->kspace_style); + if (narg < 1) + utils::missing_cmd_args(FLERR, fmt::format("kspace_style {}", force->kspace_style), error); accuracy_relative = fabs(utils::numeric(FLERR,arg[0],false,lmp)); if (accuracy_relative > 1.0) - error->all(FLERR, "Invalid relative accuracy {:g} for kspace_style {}", + error->all(FLERR, 1, "Invalid relative accuracy {:g} for kspace_style {}", accuracy_relative, force->kspace_style); } @@ -124,17 +125,17 @@ void MSM::init() triclinic_check(); if (domain->dimension == 2) - error->all(FLERR,"Cannot (yet) use MSM with 2d simulation"); + error->all(FLERR, Error::NOLASTLINE, "Cannot (yet) use MSM with 2d simulation"); if (comm->style != Comm::BRICK) - error->universe_all(FLERR,"MSM can only currently be used with comm_style brick"); - - if (!atom->q_flag) error->all(FLERR,"Kspace style requires atom attribute q"); + error->all(FLERR, Error::NOLASTLINE, "MSM can only currently be used with comm_style brick"); + if (!atom->q_flag) + error->all(FLERR, Error::NOLASTLINE, "Kspace style requires atom attribute q"); if ((slabflag == 1) && (me == 0)) - error->warning(FLERR,"Slab correction not needed for MSM"); + error->warning(FLERR, "Slab correction not needed for MSM"); if ((order < 4) || (order > 10) || (order%2 != 0)) - error->all(FLERR,"MSM order must be 4, 6, 8, or 10"); + error->all(FLERR, Error::NOLASTLINE, "MSM order must be 4, 6, 8, or 10"); // compute two charge force @@ -148,7 +149,7 @@ void MSM::init() int itmp; auto p_cutoff = (double *) force->pair->extract("cut_coul",itmp); if (p_cutoff == nullptr) - error->all(FLERR,"KSpace style is incompatible with Pair style"); + error->all(FLERR, Error::NOLASTLINE, "KSpace style is incompatible with Pair style"); cutoff = *p_cutoff; // compute qsum & qsqsum and error if not charge-neutral @@ -218,7 +219,7 @@ double MSM::estimate_1d_error(double h, double prd) cprime = 1.0/630.0; error_scaling = 0.013520855; } else { - error->all(FLERR,"MSM order must be 4, 6, 8, or 10"); + error->all(FLERR, Error::NOLASTLINE, "MSM order must be 4, 6, 8, or 10"); } // equation 4.1 from Hardy's thesis @@ -284,7 +285,8 @@ void MSM::setup() // change_box may trigger MSM::setup() before MSM::init() was called // error out and request full initialization. - if (!delxinv) error->all(FLERR, "MSM must be fully initialized for this operation"); + if (!delxinv) + error->all(FLERR, Error::NOLASTLINE, "MSM must be fully initialized for this operation"); double *prd; double a = cutoff; @@ -390,8 +392,8 @@ void MSM::compute(int eflag, int vflag) if (scalar_pressure_flag && vflag_either) { if (vflag_atom) - error->all(FLERR,"Must use 'kspace_modify pressure/scalar no' to obtain " - "per-atom virial with kspace_style MSM"); + error->all(FLERR, Error::NOLASTLINE, "Must use 'kspace_modify pressure/scalar no' to obtain " + "per-atom virial with kspace_style MSM"); // must switch on global energy computation if not already on @@ -942,7 +944,7 @@ void MSM::deallocate_levels() void MSM::set_grid_global() { if (accuracy_relative <= 0.0) - error->all(FLERR,"KSpace accuracy must be > 0"); + error->all(FLERR, Error::NOLASTLINE, "KSpace accuracy must be > 0"); double xprd = domain->xprd; double yprd = domain->yprd; @@ -1092,7 +1094,7 @@ void MSM::set_grid_global() levels = MAX(xlevels,ylevels); levels = MAX(levels,zlevels); - if (levels > MAX_LEVELS) error->all(FLERR,"Too many MSM grid levels"); + if (levels > MAX_LEVELS) error->all(FLERR, Error::NOLASTLINE, "Too many MSM grid levels"); // need at least 2 MSM levels for periodic systems @@ -1130,7 +1132,7 @@ void MSM::set_grid_global() } if (nx_msm[0] >= OFFSET || ny_msm[0] >= OFFSET || nz_msm[0] >= OFFSET) - error->all(FLERR,"MSM grid is too large"); + error->all(FLERR, Error::NOLASTLINE, "MSM grid is too large"); // compute number of extra grid points needed for non-periodic boundary conditions // need to always do this, so we can handle the case of switching from periodic @@ -1440,7 +1442,7 @@ void MSM::particle_map() int flag = 0; if (!std::isfinite(boxlo[0]) || !std::isfinite(boxlo[1]) || !std::isfinite(boxlo[2])) - error->one(FLERR,"Non-numeric box dimensions - simulation unstable"); + error->one(FLERR, Error::NOLASTLINE, "Non-numeric box dimensions - simulation unstable"); for (int i = 0; i < nlocal; i++) { @@ -1463,7 +1465,9 @@ void MSM::particle_map() nz+nlower < nzlo_out[0] || nz+nupper > nzhi_out[0]) flag = 1; } - if (flag) error->one(FLERR,"Out of range atoms - cannot compute MSM{}", utils::errorurl(4)); + if (flag) + error->one(FLERR, Error::NOLASTLINE, "Out of range atoms - cannot compute MSM{}", + utils::errorurl(4)); } /* ---------------------------------------------------------------------- diff --git a/src/KSPACE/pppm.cpp b/src/KSPACE/pppm.cpp index d69af1a82d..3cd743cd0c 100644 --- a/src/KSPACE/pppm.cpp +++ b/src/KSPACE/pppm.cpp @@ -150,11 +150,12 @@ PPPM::PPPM(LAMMPS *lmp) : KSpace(lmp), void PPPM::settings(int narg, char **arg) { - if (narg < 1) error->all(FLERR,"Illegal kspace_style {} command", force->kspace_style); + if (narg < 1) + utils::missing_cmd_args(FLERR,fmt::format("kspace_style {}", force->kspace_style), error); accuracy_relative = fabs(utils::numeric(FLERR,arg[0],false,lmp)); if (accuracy_relative > 1.0) - error->all(FLERR, "Invalid relative accuracy {:g} for kspace_style {}", + error->all(FLERR, 1, "Invalid relative accuracy {:g} for kspace_style {}", accuracy_relative, force->kspace_style); } diff --git a/src/OPENMP/msm_cg_omp.cpp b/src/OPENMP/msm_cg_omp.cpp index ff02b46589..111d2bf4e4 100644 --- a/src/OPENMP/msm_cg_omp.cpp +++ b/src/OPENMP/msm_cg_omp.cpp @@ -80,7 +80,7 @@ MSMCGOMP::~MSMCGOMP() void MSMCGOMP::compute(int eflag, int vflag) { if (scalar_pressure_flag) - error->all(FLERR,"Must use 'kspace_modify pressure/scalar no' " + error->all(FLERR, Error::NOLASTLINE, "Must use 'kspace_modify pressure/scalar no' " "with kspace_style msm/cg/omp"); const double * const q = atom->q; @@ -330,7 +330,7 @@ void MSMCGOMP::particle_map() int i; if (!std::isfinite(boxlo[0]) || !std::isfinite(boxlo[1]) || !std::isfinite(boxlo[2])) - error->one(FLERR,"Non-numeric box dimensions - simulation unstable"); + error->one(FLERR, Error::NOLASTLINE, "Non-numeric box dimensions - simulation unstable"); // XXX: O(N). is it worth to add OpenMP here? for (int j = 0; j < num_charged; j++) { @@ -356,7 +356,9 @@ void MSMCGOMP::particle_map() flag = 1; } - if (flag) error->one(FLERR,"Out of range atoms - cannot compute MSM{}", utils::errorurl(4)); + if (flag) + error->one(FLERR, Error::NOLASTLINE, "Out of range atoms - cannot compute MSM{}", + utils::errorurl(4)); } /* ---------------------------------------------------------------------- diff --git a/src/OPENMP/msm_omp.cpp b/src/OPENMP/msm_omp.cpp index 0a7a08a17a..89a3911db5 100644 --- a/src/OPENMP/msm_omp.cpp +++ b/src/OPENMP/msm_omp.cpp @@ -49,7 +49,7 @@ MSMOMP::MSMOMP(LAMMPS *lmp) : MSM(lmp), ThrOMP(lmp, THR_KSPACE) void MSMOMP::compute(int eflag, int vflag) { if (scalar_pressure_flag) - error->all(FLERR,"Must use 'kspace_modify pressure/scalar no' " + error->all(FLERR, Error::NOLASTLINE, "Must use 'kspace_modify pressure/scalar no' " "with kspace_style msm/omp"); MSM::compute(eflag,vflag); diff --git a/src/utils.cpp b/src/utils.cpp index 52d7e5113a..47e1315304 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -178,7 +178,8 @@ std::string utils::strfind(const std::string &text, const std::string &pattern) void utils::missing_cmd_args(const std::string &file, int line, const std::string &cmd, Error *error) { - if (error) error->all(file, line, "Illegal {} command: missing argument(s)", cmd); + if (error) + error->all(file, line, Error::NOPOINTER, "Illegal {} command: missing argument(s)", cmd); } std::string utils::point_to_error(Input *input, int failed)