From 1e3938835bdca943c5226bd96d0efee5fe8b2390 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 5 Sep 2019 11:32:13 -0400 Subject: [PATCH 1/2] consolidate rigid fix constants and enumerators into a single header and namespace --- src/RIGID/fix_rigid.cpp | 40 ++++----------------- src/RIGID/fix_rigid.h | 4 --- src/RIGID/fix_rigid_nh.cpp | 7 ++-- src/RIGID/fix_rigid_nh_small.cpp | 9 ++--- src/RIGID/fix_rigid_small.cpp | 44 ++++------------------- src/RIGID/fix_rigid_small.h | 1 - src/RIGID/rigid_const.h | 54 ++++++++++++++++++++++++++++ src/USER-OMP/fix_rigid_nh_omp.cpp | 11 +++--- src/USER-OMP/fix_rigid_omp.cpp | 10 +++--- src/USER-OMP/fix_rigid_small_omp.cpp | 10 +++--- 10 files changed, 82 insertions(+), 108 deletions(-) create mode 100644 src/RIGID/rigid_const.h diff --git a/src/RIGID/fix_rigid.cpp b/src/RIGID/fix_rigid.cpp index 912f529403..3e6130ac7c 100644 --- a/src/RIGID/fix_rigid.cpp +++ b/src/RIGID/fix_rigid.cpp @@ -34,25 +34,12 @@ #include "math_const.h" #include "memory.h" #include "error.h" +#include "rigid_const.h" using namespace LAMMPS_NS; using namespace FixConst; using namespace MathConst; - -enum{SINGLE,MOLECULE,GROUP}; -enum{NONE,XYZ,XY,YZ,XZ}; -enum{ISO,ANISO,TRICLINIC}; - -#define MAXLINE 1024 -#define CHUNK 1024 -#define ATTRIBUTE_PERBODY 20 - -#define TOLERANCE 1.0e-6 -#define EPSILON 1.0e-7 - -#define SINERTIA 0.4 // moment of inertia prefactor for sphere -#define EINERTIA 0.2 // moment of inertia prefactor for ellipsoid -#define LINERTIA (1.0/12.0) // moment of inertia prefactor for line segment +using namespace RigidConst; /* ---------------------------------------------------------------------- */ @@ -605,21 +592,6 @@ FixRigid::FixRigid(LAMMPS *lmp, int narg, char **arg) : for (ibody = 0; ibody < nbody; ibody++) if (nrigid[ibody] <= 1) error->all(FLERR,"One or zero atoms in rigid body"); - // bitmasks for properties of extended particles - - POINT = 1; - SPHERE = 2; - ELLIPSOID = 4; - LINE = 8; - TRIANGLE = 16; - DIPOLE = 32; - OMEGA = 64; - ANGMOM = 128; - TORQUE = 256; - - MINUSPI = -MY_PI; - TWOPI = 2.0*MY_PI; - // wait to setup bodies until first init() using current atom properties setupflag = 0; @@ -1472,8 +1444,8 @@ void FixRigid::set_xv() if (quat[ibody][3] >= 0.0) theta_body = 2.0*acos(quat[ibody][0]); else theta_body = -2.0*acos(quat[ibody][0]); theta = orient[i][0] + theta_body; - while (theta <= MINUSPI) theta += TWOPI; - while (theta > MY_PI) theta -= TWOPI; + while (theta <= -MY_PI) theta += MY_2PI; + while (theta > MY_PI) theta -= MY_2PI; lbonus[line[i]].theta = theta; omega_one[i][0] = omega[ibody][0]; omega_one[i][1] = omega[ibody][1]; @@ -2018,8 +1990,8 @@ void FixRigid::setup_bodies_static() if (quat[ibody][3] >= 0.0) theta_body = 2.0*acos(quat[ibody][0]); else theta_body = -2.0*acos(quat[ibody][0]); orient[i][0] = lbonus[line[i]].theta - theta_body; - while (orient[i][0] <= MINUSPI) orient[i][0] += TWOPI; - while (orient[i][0] > MY_PI) orient[i][0] -= TWOPI; + while (orient[i][0] <= -MY_PI) orient[i][0] += MY_2PI; + while (orient[i][0] > MY_PI) orient[i][0] -= MY_2PI; if (orientflag == 4) orient[i][1] = orient[i][2] = orient[i][3] = 0.0; } else if (eflags[i] & TRIANGLE) { quatatom = tbonus[tri[i]].quat; diff --git a/src/RIGID/fix_rigid.h b/src/RIGID/fix_rigid.h index d9d7b07ce8..8c4ab9ed49 100644 --- a/src/RIGID/fix_rigid.h +++ b/src/RIGID/fix_rigid.h @@ -65,7 +65,6 @@ class FixRigid : public Fix { double dtv,dtf,dtq; double *step_respa; int triclinic; - double MINUSPI,TWOPI; char *inpfile; // file to read rigid body attributes from int rstyle; // SINGLE,MOLECULE,GROUP @@ -137,9 +136,6 @@ class FixRigid : public Fix { class AtomVecLine *avec_line; class AtomVecTri *avec_tri; - int POINT,SPHERE,ELLIPSOID,LINE,TRIANGLE,DIPOLE; // bitmasks for eflags - int OMEGA,ANGMOM,TORQUE; - void image_shift(); void set_xv(); void set_v(); diff --git a/src/RIGID/fix_rigid_nh.cpp b/src/RIGID/fix_rigid_nh.cpp index 4738e253f6..6ffb997ffa 100644 --- a/src/RIGID/fix_rigid_nh.cpp +++ b/src/RIGID/fix_rigid_nh.cpp @@ -33,14 +33,11 @@ #include "kspace.h" #include "memory.h" #include "error.h" +#include "rigid_const.h" using namespace LAMMPS_NS; using namespace FixConst; - -enum{NONE,XYZ,XY,YZ,XZ}; // same as in FixRigid -enum{ISO,ANISO,TRICLINIC}; // same as in FixRigid - -#define EPSILON 1.0e-7 +using namespace RigidConst; /* ---------------------------------------------------------------------- */ diff --git a/src/RIGID/fix_rigid_nh_small.cpp b/src/RIGID/fix_rigid_nh_small.cpp index 1545e913c0..136796ce18 100644 --- a/src/RIGID/fix_rigid_nh_small.cpp +++ b/src/RIGID/fix_rigid_nh_small.cpp @@ -34,17 +34,12 @@ #include "kspace.h" #include "memory.h" #include "error.h" +#include "rigid_const.h" using namespace LAMMPS_NS; using namespace FixConst; using namespace MathExtra; - -enum{NONE,XYZ,XY,YZ,XZ}; // same as in FixRigid -enum{ISO,ANISO,TRICLINIC}; // same as in FixRigid - -#define EPSILON 1.0e-7 - -enum{FULL_BODY,INITIAL,FINAL,FORCE_TORQUE,VCM_ANGMOM,XCM_MASS,ITENSOR,DOF}; +using namespace RigidConst; /* ---------------------------------------------------------------------- */ diff --git a/src/RIGID/fix_rigid_small.cpp b/src/RIGID/fix_rigid_small.cpp index 14e230ab9c..ba570d5840 100644 --- a/src/RIGID/fix_rigid_small.cpp +++ b/src/RIGID/fix_rigid_small.cpp @@ -38,34 +38,17 @@ #include "hashlittle.h" #include "memory.h" #include "error.h" +#include "rigid_const.h" #include using namespace LAMMPS_NS; using namespace FixConst; using namespace MathConst; +using namespace RigidConst; #define RVOUS 1 // 0 for irregular, 1 for all2all -#define MAXLINE 1024 -#define CHUNK 1024 -#define ATTRIBUTE_PERBODY 20 - -#define TOLERANCE 1.0e-6 -#define EPSILON 1.0e-7 -#define BIG 1.0e20 - -#define SINERTIA 0.4 // moment of inertia prefactor for sphere -#define EINERTIA 0.2 // moment of inertia prefactor for ellipsoid -#define LINERTIA (1.0/12.0) // moment of inertia prefactor for line segment - -#define DELTA_BODY 10000 - -enum{NONE,XYZ,XY,YZ,XZ}; // same as in FixRigid -enum{ISO,ANISO,TRICLINIC}; // same as in FixRigid - -enum{FULL_BODY,INITIAL,FINAL,FORCE_TORQUE,VCM_ANGMOM,XCM_MASS,ITENSOR,DOF}; - /* ---------------------------------------------------------------------- */ FixRigidSmall::FixRigidSmall(LAMMPS *lmp, int narg, char **arg) : @@ -455,21 +438,6 @@ FixRigidSmall::FixRigidSmall(LAMMPS *lmp, int narg, char **arg) : comm_forward = 1 + bodysize; comm_reverse = 6; - // bitmasks for properties of extended particles - - POINT = 1; - SPHERE = 2; - ELLIPSOID = 4; - LINE = 8; - TRIANGLE = 16; - DIPOLE = 32; - OMEGA = 64; - ANGMOM = 128; - TORQUE = 256; - - MINUSPI = -MY_PI; - TWOPI = 2.0*MY_PI; - // atom style pointers to particles that store extra info avec_ellipsoid = (AtomVecEllipsoid *) atom->style_match("ellipsoid"); @@ -1384,8 +1352,8 @@ void FixRigidSmall::set_xv() if (b->quat[3] >= 0.0) theta_body = 2.0*acos(b->quat[0]); else theta_body = -2.0*acos(b->quat[0]); theta = orient[i][0] + theta_body; - while (theta <= MINUSPI) theta += TWOPI; - while (theta > MY_PI) theta -= TWOPI; + while (theta <= -MY_PI) theta += MY_2PI; + while (theta > MY_PI) theta -= MY_2PI; lbonus[line[i]].theta = theta; omega[i][0] = b->omega[0]; omega[i][1] = b->omega[1]; @@ -2155,8 +2123,8 @@ void FixRigidSmall::setup_bodies_static() if (b->quat[3] >= 0.0) theta_body = 2.0*acos(b->quat[0]); else theta_body = -2.0*acos(b->quat[0]); orient[i][0] = lbonus[line[i]].theta - theta_body; - while (orient[i][0] <= MINUSPI) orient[i][0] += TWOPI; - while (orient[i][0] > MY_PI) orient[i][0] -= TWOPI; + while (orient[i][0] <= -MY_PI) orient[i][0] += MY_2PI; + while (orient[i][0] > MY_PI) orient[i][0] -= MY_2PI; if (orientflag == 4) orient[i][1] = orient[i][2] = orient[i][3] = 0.0; } else if (eflags[i] & TRIANGLE) { quatatom = tbonus[tri[i]].quat; diff --git a/src/RIGID/fix_rigid_small.h b/src/RIGID/fix_rigid_small.h index 6dae443d1c..469616439c 100644 --- a/src/RIGID/fix_rigid_small.h +++ b/src/RIGID/fix_rigid_small.h @@ -72,7 +72,6 @@ class FixRigidSmall : public Fix { double dtv,dtf,dtq; double *step_respa; int triclinic; - double MINUSPI,TWOPI; char *inpfile; // file to read rigid body attributes from int setupflag; // 1 if body properties are setup, else 0 diff --git a/src/RIGID/rigid_const.h b/src/RIGID/rigid_const.h new file mode 100644 index 0000000000..804cd9260a --- /dev/null +++ b/src/RIGID/rigid_const.h @@ -0,0 +1,54 @@ +/* -*- c++ -*- ---------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + http://lammps.sandia.gov, Sandia National Laboratories + Steve Plimpton, sjplimp@sandia.gov + + Copyright (2003) Sandia Corporation. Under the terms of Contract + DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains + certain rights in this software. This software is distributed under + the GNU General Public License. + + See the README file in the top-level LAMMPS directory. +------------------------------------------------------------------------- */ + +#ifndef LMP_RIGID_CONST_H +#define LMP_RIGID_CONST_H + +namespace LAMMPS_NS { + namespace RigidConst { + + enum{SINGLE,MOLECULE,GROUP}; + enum{NONE,XYZ,XY,YZ,XZ}; + enum{ISO,ANISO,TRICLINIC}; + enum{FULL_BODY,INITIAL,FINAL,FORCE_TORQUE,VCM_ANGMOM,XCM_MASS,ITENSOR,DOF}; + + enum {POINT = 1<<0, + SPHERE = 1<<1, + ELLIPSOID = 1<<2, + LINE = 1<<3, + TRIANGLE = 1<<4, + DIPOLE = 1<<5, + OMEGA = 1<<6, + ANGMOM = 1<<7, + TORQUE = 1<<8 + }; + + static const double TOLERANCE = 1.0e-6; + static const double EPSILON = 1.0e-7; + static const double BIG = 1.0e20; + + // moment of inertia prefactor for sphere + static const double SINERTIA = 0.4; + // moment of inertia prefactor for ellipsoid + static const double EINERTIA = 0.2; + // moment of inertia prefactor for line segment + static const double LINERTIA = 1.0/12.0; + + static const int MAXLINE = 1024; + static const int CHUNK = 1024; + static const int DELTA_BODY = 10000; + static const int ATTRIBUTE_PERBODY = 20; + } +} + +#endif diff --git a/src/USER-OMP/fix_rigid_nh_omp.cpp b/src/USER-OMP/fix_rigid_nh_omp.cpp index 74b2a92775..866021b3f4 100644 --- a/src/USER-OMP/fix_rigid_nh_omp.cpp +++ b/src/USER-OMP/fix_rigid_nh_omp.cpp @@ -38,15 +38,12 @@ #include "math_extra.h" #include "math_const.h" +#include "rigid_const.h" using namespace LAMMPS_NS; using namespace FixConst; using namespace MathConst; - -enum{SINGLE,MOLECULE,GROUP}; // same as in FixRigid -enum{ISO,ANISO,TRICLINIC}; // same as in FixRigid - -#define EINERTIA 0.4 // moment of inertia prefactor for ellipsoid +using namespace RigidConst; typedef struct { double x,y,z; } dbl3_t; @@ -770,8 +767,8 @@ void FixRigidNHOMP::set_xv_thr() if (quat[ibody][3] >= 0.0) theta_body = 2.0*acos(quat[ibody][0]); else theta_body = -2.0*acos(quat[ibody][0]); theta = orient[i][0] + theta_body; - while (theta <= MINUSPI) theta += TWOPI; - while (theta > MY_PI) theta -= TWOPI; + while (theta <= -MY_PI) theta += MY_2PI; + while (theta > MY_PI) theta -= MY_2PI; lbonus[line[i]].theta = theta; omega_one[i][0] = omega[ibody][0]; omega_one[i][1] = omega[ibody][1]; diff --git a/src/USER-OMP/fix_rigid_omp.cpp b/src/USER-OMP/fix_rigid_omp.cpp index b807ddba7c..3baa9de20a 100644 --- a/src/USER-OMP/fix_rigid_omp.cpp +++ b/src/USER-OMP/fix_rigid_omp.cpp @@ -33,14 +33,12 @@ #include "math_extra.h" #include "math_const.h" +#include "rigid_const.h" using namespace LAMMPS_NS; using namespace FixConst; using namespace MathConst; - -enum{SINGLE,MOLECULE,GROUP}; // same as in FixRigid - -#define EINERTIA 0.2 // moment of inertia prefactor for ellipsoid +using namespace RigidConst; typedef struct { double x,y,z; } dbl3_t; @@ -488,8 +486,8 @@ void FixRigidOMP::set_xv_thr() if (quat[ibody][3] >= 0.0) theta_body = 2.0*acos(quat[ibody][0]); else theta_body = -2.0*acos(quat[ibody][0]); theta = orient[i][0] + theta_body; - while (theta <= MINUSPI) theta += TWOPI; - while (theta > MY_PI) theta -= TWOPI; + while (theta <= -MY_PI) theta += MY_2PI; + while (theta > MY_PI) theta -= MY_2PI; lbonus[line[i]].theta = theta; omega_one[i][0] = omega[ibody][0]; omega_one[i][1] = omega[ibody][1]; diff --git a/src/USER-OMP/fix_rigid_small_omp.cpp b/src/USER-OMP/fix_rigid_small_omp.cpp index 41f6c53e40..523bd4df07 100644 --- a/src/USER-OMP/fix_rigid_small_omp.cpp +++ b/src/USER-OMP/fix_rigid_small_omp.cpp @@ -31,14 +31,12 @@ #include "math_extra.h" #include "math_const.h" +#include "rigid_const.h" using namespace LAMMPS_NS; using namespace FixConst; using namespace MathConst; - -#define EINERTIA 0.2 // moment of inertia prefactor for ellipsoid - -enum{FULL_BODY,INITIAL,FINAL,FORCE_TORQUE,VCM_ANGMOM,XCM_MASS,ITENSOR,DOF}; +using namespace RigidConst; typedef struct { double x,y,z; } dbl3_t; @@ -427,8 +425,8 @@ void FixRigidSmallOMP::set_xv_thr() if (b.quat[3] >= 0.0) theta_body = 2.0*acos(b.quat[0]); else theta_body = -2.0*acos(b.quat[0]); theta = orient[i][0] + theta_body; - while (theta <= MINUSPI) theta += TWOPI; - while (theta > MY_PI) theta -= TWOPI; + while (theta <= -MY_PI) theta += MY_2PI; + while (theta > MY_PI) theta -= MY_2PI; lbonus[line[i]].theta = theta; omega[i][0] = b.omega[0]; omega[i][1] = b.omega[1]; From 493f1cf65b3ea87c5b05d3a2c06af53bc2a4c228 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 9 Sep 2019 15:33:56 -0400 Subject: [PATCH 2/2] correct overlapping definitions of bitmask flags --- src/RIGID/fix_rigid_small.h | 3 --- src/RIGID/rigid_const.h | 2 +- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/src/RIGID/fix_rigid_small.h b/src/RIGID/fix_rigid_small.h index 469616439c..0d1cdb5963 100644 --- a/src/RIGID/fix_rigid_small.h +++ b/src/RIGID/fix_rigid_small.h @@ -128,9 +128,6 @@ class FixRigidSmall : public Fix { int dorientflag; // 1 if particles store dipole orientation int reinitflag; // 1 if re-initialize rigid bodies between runs - int POINT,SPHERE,ELLIPSOID,LINE,TRIANGLE,DIPOLE; // bitmasks for eflags - int OMEGA,ANGMOM,TORQUE; - class AtomVecEllipsoid *avec_ellipsoid; class AtomVecLine *avec_line; class AtomVecTri *avec_tri; diff --git a/src/RIGID/rigid_const.h b/src/RIGID/rigid_const.h index 804cd9260a..14db517fcd 100644 --- a/src/RIGID/rigid_const.h +++ b/src/RIGID/rigid_const.h @@ -16,7 +16,7 @@ namespace LAMMPS_NS { namespace RigidConst { - + enum{SINGLE,MOLECULE,GROUP}; enum{NONE,XYZ,XY,YZ,XZ}; enum{ISO,ANISO,TRICLINIC};