From 187a35d7b21086f872ae5107d743a16e520488de Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 5 Feb 2024 23:57:41 -0500 Subject: [PATCH] convert a few more defines to static constexpr --- src/CG-SPICA/pair_lj_spica_coul_long.cpp | 10 ++-------- src/CORESHELL/pair_born_coul_long_cs.cpp | 24 +++++++++++++----------- src/CORESHELL/pair_buck_coul_long_cs.cpp | 20 ++++++++++---------- src/EXTRA-PAIR/pair_coul_slater_long.cpp | 10 ++-------- src/EXTRA-PAIR/pair_lj_cut_coul_dsf.cpp | 13 ++++++------- src/comm_tiled.cpp | 3 +-- src/fix_box_relax.cpp | 6 ++---- src/fix_box_relax.h | 11 ++++++----- src/math_special.cpp | 2 +- src/min_cg.cpp | 2 +- src/min_fire.cpp | 2 +- src/min_linesearch.cpp | 11 +++++------ src/min_quickmin.cpp | 3 +-- src/min_sd.cpp | 2 +- src/nbin_multi.cpp | 2 +- src/nbin_standard.cpp | 2 +- src/pair_coul_dsf.cpp | 13 ++++++------- 17 files changed, 60 insertions(+), 76 deletions(-) diff --git a/src/CG-SPICA/pair_lj_spica_coul_long.cpp b/src/CG-SPICA/pair_lj_spica_coul_long.cpp index 8b655ea911..9e0d4dc276 100644 --- a/src/CG-SPICA/pair_lj_spica_coul_long.cpp +++ b/src/CG-SPICA/pair_lj_spica_coul_long.cpp @@ -21,6 +21,7 @@ #include "atom.h" #include "comm.h" #include "error.h" +#include "ewald_const.h" #include "force.h" #include "kspace.h" #include "memory.h" @@ -35,14 +36,7 @@ using namespace LAMMPS_NS; using namespace LJSPICAParms; - -#define EWALD_F 1.12837917 -#define EWALD_P 0.3275911 -#define A1 0.254829592 -#define A2 -0.284496736 -#define A3 1.421413741 -#define A4 -1.453152027 -#define A5 1.061405429 +using namespace EwaldConst; /* ---------------------------------------------------------------------- */ diff --git a/src/CORESHELL/pair_born_coul_long_cs.cpp b/src/CORESHELL/pair_born_coul_long_cs.cpp index c29bd5c31d..3e13577879 100644 --- a/src/CORESHELL/pair_born_coul_long_cs.cpp +++ b/src/CORESHELL/pair_born_coul_long_cs.cpp @@ -17,25 +17,27 @@ ------------------------------------------------------------------------- */ #include "pair_born_coul_long_cs.h" -#include + #include "atom.h" #include "force.h" #include "neigh_list.h" +#include + using namespace LAMMPS_NS; -#define EWALD_F 1.12837917 -#define EWALD_P 9.95473818e-1 -#define B0 -0.1335096380159268 -#define B1 -2.57839507e-1 -#define B2 -1.37203639e-1 -#define B3 -8.88822059e-3 -#define B4 -5.80844129e-3 -#define B5 1.14652755e-1 +static constexpr double EWALD_F = 1.12837917; +static constexpr double EWALD_P = 9.95473818e-1; +static constexpr double B0 = -0.1335096380159268; +static constexpr double B1 = -2.57839507e-1; +static constexpr double B2 = -1.37203639e-1; +static constexpr double B3 = -8.88822059e-3; +static constexpr double B4 = -5.80844129e-3; +static constexpr double B5 = 1.14652755e-1; static constexpr double EPSILON = 1.0e-20; -#define EPS_EWALD 1.0e-6 -#define EPS_EWALD_SQR 1.0e-12 +static constexpr double EPS_EWALD = 1.0e-6; +static constexpr double EPS_EWALD_SQR = 1.0e-12; /* ---------------------------------------------------------------------- */ diff --git a/src/CORESHELL/pair_buck_coul_long_cs.cpp b/src/CORESHELL/pair_buck_coul_long_cs.cpp index 96203deae1..f885b412d8 100644 --- a/src/CORESHELL/pair_buck_coul_long_cs.cpp +++ b/src/CORESHELL/pair_buck_coul_long_cs.cpp @@ -24,18 +24,18 @@ using namespace LAMMPS_NS; -#define EWALD_F 1.12837917 -#define EWALD_P 9.95473818e-1 -#define B0 -0.1335096380159268 -#define B1 -2.57839507e-1 -#define B2 -1.37203639e-1 -#define B3 -8.88822059e-3 -#define B4 -5.80844129e-3 -#define B5 1.14652755e-1 +static constexpr double EWALD_F = 1.12837917; +static constexpr double EWALD_P = 9.95473818e-1; +static constexpr double B0 = -0.1335096380159268; +static constexpr double B1 = -2.57839507e-1; +static constexpr double B2 = -1.37203639e-1; +static constexpr double B3 = -8.88822059e-3; +static constexpr double B4 = -5.80844129e-3; +static constexpr double B5 = 1.14652755e-1; static constexpr double EPSILON = 1.0e-20; -#define EPS_EWALD 1.0e-6 -#define EPS_EWALD_SQR 1.0e-12 +static constexpr double EPS_EWALD = 1.0e-6; +static constexpr double EPS_EWALD_SQR = 1.0e-12; /* ---------------------------------------------------------------------- */ diff --git a/src/EXTRA-PAIR/pair_coul_slater_long.cpp b/src/EXTRA-PAIR/pair_coul_slater_long.cpp index 3f5803af8e..65906f73b5 100644 --- a/src/EXTRA-PAIR/pair_coul_slater_long.cpp +++ b/src/EXTRA-PAIR/pair_coul_slater_long.cpp @@ -21,6 +21,7 @@ #include "atom.h" #include "comm.h" #include "error.h" +#include "ewald_const.h" #include "force.h" #include "kspace.h" #include "memory.h" @@ -31,14 +32,7 @@ #include using namespace LAMMPS_NS; - -#define EWALD_F 1.12837917 -#define EWALD_P 0.3275911 -#define A1 0.254829592 -#define A2 -0.284496736 -#define A3 1.421413741 -#define A4 -1.453152027 -#define A5 1.061405429 +using namespace EwaldConst; /* ---------------------------------------------------------------------- */ diff --git a/src/EXTRA-PAIR/pair_lj_cut_coul_dsf.cpp b/src/EXTRA-PAIR/pair_lj_cut_coul_dsf.cpp index 49e1468af1..9356062914 100644 --- a/src/EXTRA-PAIR/pair_lj_cut_coul_dsf.cpp +++ b/src/EXTRA-PAIR/pair_lj_cut_coul_dsf.cpp @@ -34,13 +34,12 @@ using namespace LAMMPS_NS; using namespace MathConst; -#define EWALD_F 1.12837917 -#define EWALD_P 0.3275911 -#define A1 0.254829592 -#define A2 -0.284496736 -#define A3 1.421413741 -#define A4 -1.453152027 -#define A5 1.061405429 +static constexpr double EWALD_P = 0.3275911; +static constexpr double A1 = 0.254829592; +static constexpr double A2 = -0.284496736; +static constexpr double A3 = 1.421413741; +static constexpr double A4 = -1.453152027; +static constexpr double A5 = 1.061405429; /* ---------------------------------------------------------------------- */ diff --git a/src/comm_tiled.cpp b/src/comm_tiled.cpp index 6c44af686f..65cbfad0b5 100644 --- a/src/comm_tiled.cpp +++ b/src/comm_tiled.cpp @@ -39,8 +39,7 @@ using namespace LAMMPS_NS; static constexpr double BUFFACTOR = 1.5; static constexpr int BUFMIN = 1024; static constexpr double EPSILON = 1.0e-6; - -#define DELTA_PROCS 16 +static constexpr int DELTA_PROCS = 16; /* ---------------------------------------------------------------------- */ diff --git a/src/fix_box_relax.cpp b/src/fix_box_relax.cpp index 1f715a1dd4..cf8df7cd02 100644 --- a/src/fix_box_relax.cpp +++ b/src/fix_box_relax.cpp @@ -35,10 +35,8 @@ using namespace LAMMPS_NS; using namespace FixConst; -enum{NONE,XYZ,XY,YZ,XZ}; -enum{ISO,ANISO,TRICLINIC}; - -#define MAX_LIFO_DEPTH 2 // 3 box0 arrays in *.h dimensioned to this +enum { NONE, XYZ, XY, YZ, XZ }; +enum { ISO, ANISO, TRICLINIC }; /* ---------------------------------------------------------------------- */ diff --git a/src/fix_box_relax.h b/src/fix_box_relax.h index 0870ed522d..bf9379ceac 100644 --- a/src/fix_box_relax.h +++ b/src/fix_box_relax.h @@ -52,11 +52,12 @@ class FixBoxRelax : public Fix { double vmax, pv2e, pflagsum; int kspace_flag; - int current_lifo; // LIFO stack pointer - double boxlo0[2][3]; // box bounds at start of line search - double boxhi0[2][3]; - double boxtilt0[2][3]; // xy,xz,yz tilts at start of line search - double ds[6]; // increment in scale matrix + static constexpr int MAX_LIFO_DEPTH = 2; + int current_lifo; // LIFO stack pointer + double boxlo0[MAX_LIFO_DEPTH][3]; // low box bounds at start of line search + double boxhi0[MAX_LIFO_DEPTH][3]; // high box bounds at start of line search + double boxtilt0[MAX_LIFO_DEPTH][3]; // xy,xz,yz tilts at start of line search + double ds[6]; // increment in scale matrix int scaleyz; // 1 if yz scaled with lz int scalexz; // 1 if xz scaled with lz diff --git a/src/math_special.cpp b/src/math_special.cpp index fd47aec9e9..2bc0cc3deb 100644 --- a/src/math_special.cpp +++ b/src/math_special.cpp @@ -702,7 +702,7 @@ static const double fm_exp2_p[] = { }; /* double precision constants */ -#define FM_DOUBLE_LOG2OFE 1.4426950408889634074 +static constexpr double FM_DOUBLE_LOG2OFE = 1.4426950408889634074; double MathSpecial::exp2_x86(double x) { diff --git a/src/min_cg.cpp b/src/min_cg.cpp index 782ab04c44..aa4d036b6c 100644 --- a/src/min_cg.cpp +++ b/src/min_cg.cpp @@ -25,7 +25,7 @@ using namespace LAMMPS_NS; // EPS_ENERGY = minimum normalization for energy tolerance -#define EPS_ENERGY 1.0e-8 +static constexpr double EPS_ENERGY = 1.0e-8; /* ---------------------------------------------------------------------- */ diff --git a/src/min_fire.cpp b/src/min_fire.cpp index 1f24ea5a15..b227c1cc3a 100644 --- a/src/min_fire.cpp +++ b/src/min_fire.cpp @@ -38,7 +38,7 @@ using namespace LAMMPS_NS; // EPS_ENERGY = minimum normalization for energy tolerance -#define EPS_ENERGY 1.0e-8 +static constexpr double EPS_ENERGY = 1.0e-8; /* ---------------------------------------------------------------------- */ diff --git a/src/min_linesearch.cpp b/src/min_linesearch.cpp index 97dcca9d8a..d33b7579b9 100644 --- a/src/min_linesearch.cpp +++ b/src/min_linesearch.cpp @@ -42,13 +42,12 @@ using namespace LAMMPS_NS; // EMACH = machine accuracy limit of energy changes (1.0e-8) // EPS_QUAD = tolerance for quadratic projection -#define ALPHA_MAX 1.0 -#define ALPHA_REDUCE 0.5 -#define BACKTRACK_SLOPE 0.4 -#define QUADRATIC_TOL 0.1 -//#define EMACH 1.0e-8 +static constexpr double ALPHA_MAX = 1.0; +static constexpr double ALPHA_REDUCE = 0.5; +static constexpr double BACKTRACK_SLOPE = 0.4; +static constexpr double QUADRATIC_TOL = 0.1; static constexpr double EMACH = 1.0e-8; -#define EPS_QUAD 1.0e-28 +static constexpr double EPS_QUAD = 1.0e-28; /* ---------------------------------------------------------------------- */ diff --git a/src/min_quickmin.cpp b/src/min_quickmin.cpp index c3730f2cd7..6e314cc67b 100644 --- a/src/min_quickmin.cpp +++ b/src/min_quickmin.cpp @@ -28,8 +28,7 @@ using namespace LAMMPS_NS; // EPS_ENERGY = minimum normalization for energy tolerance -#define EPS_ENERGY 1.0e-8 - +static constexpr double EPS_ENERGY = 1.0e-8; static constexpr int DELAYSTEP = 5; /* ---------------------------------------------------------------------- */ diff --git a/src/min_sd.cpp b/src/min_sd.cpp index b190c78575..122b92ae8e 100644 --- a/src/min_sd.cpp +++ b/src/min_sd.cpp @@ -24,7 +24,7 @@ using namespace LAMMPS_NS; // EPS_ENERGY = minimum normalization for energy tolerance -#define EPS_ENERGY 1.0e-8 +static constexpr double EPS_ENERGY = 1.0e-8; /* ---------------------------------------------------------------------- */ diff --git a/src/nbin_multi.cpp b/src/nbin_multi.cpp index 15c089bee7..86cefbfa23 100644 --- a/src/nbin_multi.cpp +++ b/src/nbin_multi.cpp @@ -27,7 +27,7 @@ using namespace LAMMPS_NS; static constexpr double SMALL = 1.0e-6; -#define CUT2BIN_RATIO 100 +static constexpr double CUT2BIN_RATIO = 100.0; /* ---------------------------------------------------------------------- */ diff --git a/src/nbin_standard.cpp b/src/nbin_standard.cpp index 08ff537d71..1c611080cf 100644 --- a/src/nbin_standard.cpp +++ b/src/nbin_standard.cpp @@ -25,7 +25,7 @@ using namespace LAMMPS_NS; static constexpr double SMALL = 1.0e-6; -#define CUT2BIN_RATIO 100 +static constexpr double CUT2BIN_RATIO = 100.0; /* ---------------------------------------------------------------------- */ diff --git a/src/pair_coul_dsf.cpp b/src/pair_coul_dsf.cpp index 8e42cdadee..b384946e86 100644 --- a/src/pair_coul_dsf.cpp +++ b/src/pair_coul_dsf.cpp @@ -33,13 +33,12 @@ using namespace LAMMPS_NS; using namespace MathConst; -#define EWALD_F 1.12837917 -#define EWALD_P 0.3275911 -#define A1 0.254829592 -#define A2 -0.284496736 -#define A3 1.421413741 -#define A4 -1.453152027 -#define A5 1.061405429 +static constexpr double EWALD_P = 0.3275911; +static constexpr double A1 = 0.254829592; +static constexpr double A2 = -0.284496736; +static constexpr double A3 = 1.421413741; +static constexpr double A4 = -1.453152027; +static constexpr double A5 = 1.061405429; /* ---------------------------------------------------------------------- */