From bb6a1180067e6de2639120ff5742ff9dfb492f96 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 3 Oct 2022 16:31:23 -0400 Subject: [PATCH] refactor for simpler flow of control. apply clang-format. --- src/pair_zero.cpp | 33 ++++++++++++++++----------------- src/pair_zero.h | 4 +--- 2 files changed, 17 insertions(+), 20 deletions(-) diff --git a/src/pair_zero.cpp b/src/pair_zero.cpp index e4d98ad66e..b554f78b7f 100644 --- a/src/pair_zero.cpp +++ b/src/pair_zero.cpp @@ -88,25 +88,24 @@ void PairZero::allocate() void PairZero::settings(int narg, char **arg) { - if ((narg != 1) && (narg != 2) && (narg != 3)) error->all(FLERR, "Illegal pair_style command"); + if (narg < 1) utils::missing_cmd_args(FLERR, "pair_style zero", error); cut_global = utils::numeric(FLERR, arg[0], false, lmp); - if (narg == 2){ - if (strcmp("nocoeff", arg[1]) == 0) + // reset to defaults + coeffflag = 1; + fullneighflag = 0; + + int iarg = 1; + while (iarg < narg) { + if (strcmp("nocoeff", arg[iarg]) == 0) { coeffflag = 0; - else if(strcmp("full", arg[1]) == 0) + ++iarg; + } else if (strcmp("full", arg[iarg]) == 0) { fullneighflag = 1; - else - error->all(FLERR, "Illegal pair_style command"); - } - else if (narg == 3) { - if (strcmp("nocoeff", arg[1]) == 0 || strcmp("nocoeff", arg[2]) == 0) - coeffflag = 0; - else if(strcmp("full", arg[1]) == 0 || strcmp("full", arg[2]) == 0) - fullneighflag = 1; - else - error->all(FLERR, "Illegal pair_style command"); + ++iarg; + } else + error->all(FLERR, "Unknown pair style zero option {}", arg[iarg]); } // reset cutoffs that have been explicitly set @@ -154,10 +153,10 @@ void PairZero::coeff(int narg, char **arg) void PairZero::init_style() { - if (fullneighflag == 0) - neighbor->add_request(this, NeighConst::REQ_DEFAULT); - else + if (fullneighflag) neighbor->add_request(this, NeighConst::REQ_FULL); + else + neighbor->add_request(this, NeighConst::REQ_DEFAULT); } /* ---------------------------------------------------------------------- diff --git a/src/pair_zero.h b/src/pair_zero.h index 10102f1cad..06d7b2ab72 100644 --- a/src/pair_zero.h +++ b/src/pair_zero.h @@ -56,12 +56,10 @@ class PairZero : public Pair { double cut_global; double **cut; int coeffflag; - int fullneighflag; // 0 for half list, 1 for full list + int fullneighflag; // 0 for half list, 1 for full list virtual void allocate(); }; - } // namespace LAMMPS_NS - #endif #endif