From 5f68f3006f1eafaffdb13b3e85220b5d8ac0dd2a Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sat, 8 Feb 2020 15:12:26 -0500 Subject: [PATCH] replace Fix::box_change_xxx variables with Fix::box_change bitmask and add check to Domain::init() This allows a more specific tracking of whether multiple fixes are modifying the same box parameter and error out in that case. --- src/RIGID/fix_rigid_nh.cpp | 4 ++++ src/RIGID/fix_rigid_nh_small.cpp | 4 ++++ src/RIGID/fix_rigid_nph.cpp | 1 - src/RIGID/fix_rigid_nph_small.cpp | 1 - src/RIGID/fix_rigid_npt.cpp | 1 - src/RIGID/fix_rigid_npt_small.cpp | 1 - src/SHOCK/fix_msst.cpp | 15 +++++++++----- src/SRD/fix_srd.cpp | 11 ++++++---- src/USER-BOCS/fix_bocs.cpp | 8 ++++++-- src/USER-MISC/fix_npt_cauchy.cpp | 8 ++++++-- src/USER-OMP/fix_rigid_nph_omp.cpp | 1 - src/USER-OMP/fix_rigid_npt_omp.cpp | 1 - src/USER-QTB/fix_qbmsst.cpp | 12 ++++++----- src/USER-UEF/fix_nh_uef.cpp | 2 +- src/domain.cpp | 33 +++++++++++++++++++++++++++--- src/fix.cpp | 2 +- src/fix.h | 11 +++++++--- src/fix_balance.cpp | 2 +- src/fix_box_relax.cpp | 9 ++++++-- src/fix_deform.cpp | 8 ++++++-- src/fix_nh.cpp | 8 ++++++-- src/fix_press_berendsen.cpp | 6 ++++-- 22 files changed, 108 insertions(+), 41 deletions(-) diff --git a/src/RIGID/fix_rigid_nh.cpp b/src/RIGID/fix_rigid_nh.cpp index 6ffb997ffa..1df7f34532 100644 --- a/src/RIGID/fix_rigid_nh.cpp +++ b/src/RIGID/fix_rigid_nh.cpp @@ -106,6 +106,10 @@ FixRigidNH::FixRigidNH(LAMMPS *lmp, int narg, char **arg) : p_period[0] != p_period[2])) error->all(FLERR,"Invalid fix rigid npt/nph command pressure settings"); + if (p_flag[0]) box_change |= BOX_CHANGE_X; + if (p_flag[1]) box_change |= BOX_CHANGE_Y; + if (p_flag[2]) box_change |= BOX_CHANGE_Z; + if ((tstat_flag && t_period <= 0.0) || (p_flag[0] && p_period[0] <= 0.0) || (p_flag[1] && p_period[1] <= 0.0) || diff --git a/src/RIGID/fix_rigid_nh_small.cpp b/src/RIGID/fix_rigid_nh_small.cpp index 136796ce18..5b75640549 100644 --- a/src/RIGID/fix_rigid_nh_small.cpp +++ b/src/RIGID/fix_rigid_nh_small.cpp @@ -120,6 +120,10 @@ FixRigidNHSmall::FixRigidNHSmall(LAMMPS *lmp, int narg, char **arg) : p_period[0] != p_period[2])) error->all(FLERR,"Invalid fix rigid/small npt/nph command pressure settings"); + if (p_flag[0]) box_change |= BOX_CHANGE_X; + if (p_flag[1]) box_change |= BOX_CHANGE_Y; + if (p_flag[2]) box_change |= BOX_CHANGE_Z; + if ((tstat_flag && t_period <= 0.0) || (p_flag[0] && p_period[0] <= 0.0) || (p_flag[1] && p_period[1] <= 0.0) || diff --git a/src/RIGID/fix_rigid_nph.cpp b/src/RIGID/fix_rigid_nph.cpp index 706e08ec12..5c3b5390aa 100644 --- a/src/RIGID/fix_rigid_nph.cpp +++ b/src/RIGID/fix_rigid_nph.cpp @@ -33,7 +33,6 @@ FixRigidNPH::FixRigidNPH(LAMMPS *lmp, int narg, char **arg) : scalar_flag = 1; restart_global = 1; - box_change_size = 1; extscalar = 1; // error checks diff --git a/src/RIGID/fix_rigid_nph_small.cpp b/src/RIGID/fix_rigid_nph_small.cpp index 32ac58220d..7769ced807 100644 --- a/src/RIGID/fix_rigid_nph_small.cpp +++ b/src/RIGID/fix_rigid_nph_small.cpp @@ -33,7 +33,6 @@ FixRigidNPHSmall::FixRigidNPHSmall(LAMMPS *lmp, int narg, char **arg) : scalar_flag = 1; restart_global = 1; - box_change_size = 1; extscalar = 1; // error checks diff --git a/src/RIGID/fix_rigid_npt.cpp b/src/RIGID/fix_rigid_npt.cpp index 1f19fb4ec7..5f3fde669c 100644 --- a/src/RIGID/fix_rigid_npt.cpp +++ b/src/RIGID/fix_rigid_npt.cpp @@ -33,7 +33,6 @@ FixRigidNPT::FixRigidNPT(LAMMPS *lmp, int narg, char **arg) : scalar_flag = 1; restart_global = 1; - box_change_size = 1; extscalar = 1; // error checks diff --git a/src/RIGID/fix_rigid_npt_small.cpp b/src/RIGID/fix_rigid_npt_small.cpp index e8924be79f..d3bd5b8f57 100644 --- a/src/RIGID/fix_rigid_npt_small.cpp +++ b/src/RIGID/fix_rigid_npt_small.cpp @@ -33,7 +33,6 @@ FixRigidNPTSmall::FixRigidNPTSmall(LAMMPS *lmp, int narg, char **arg) : scalar_flag = 1; restart_global = 1; - box_change_size = 1; extscalar = 1; // error checks diff --git a/src/SHOCK/fix_msst.cpp b/src/SHOCK/fix_msst.cpp index 2e9f751824..67b2a7fb0f 100644 --- a/src/SHOCK/fix_msst.cpp +++ b/src/SHOCK/fix_msst.cpp @@ -46,7 +46,6 @@ FixMSST::FixMSST(LAMMPS *lmp, int narg, char **arg) : if (narg < 4) error->all(FLERR,"Illegal fix msst command"); restart_global = 1; - box_change_size = 1; time_integrate = 1; scalar_flag = 1; vector_flag = 1; @@ -78,10 +77,16 @@ FixMSST::FixMSST(LAMMPS *lmp, int narg, char **arg) : dftb = 0; beta = 0.0; - if (strcmp(arg[3],"x") == 0) direction = 0; - else if (strcmp(arg[3],"y") == 0) direction = 1; - else if (strcmp(arg[3],"z") == 0) direction = 2; - else error->all(FLERR,"Illegal fix msst command"); + if (strcmp(arg[3],"x") == 0) { + direction = 0; + box_change |= BOX_CHANGE_X; + } else if (strcmp(arg[3],"y") == 0) { + direction = 1; + box_change |= BOX_CHANGE_Y; + } else if (strcmp(arg[3],"z") == 0) { + direction = 2; + box_change |= BOX_CHANGE_Z; + } else error->all(FLERR,"Illegal fix msst command"); velocity = force->numeric(FLERR,arg[4]); if (velocity < 0) error->all(FLERR,"Illegal fix msst command"); diff --git a/src/SRD/fix_srd.cpp b/src/SRD/fix_srd.cpp index d5eec91f50..d87851381f 100644 --- a/src/SRD/fix_srd.cpp +++ b/src/SRD/fix_srd.cpp @@ -375,13 +375,16 @@ void FixSRD::init() change_size = change_shape = deformflag = 0; if (domain->nonperiodic == 2) change_size = 1; + + Fix **fixes = modify->fix; for (int i = 0; i < modify->nfix; i++) { - if (modify->fix[i]->box_change_size) change_size = 1; - if (modify->fix[i]->box_change_shape) change_shape = 1; - if (strcmp(modify->fix[i]->style,"deform") == 0) { + if (fixes[i]->box_change & BOX_CHANGE_SIZE) change_size = 1; + if (fixes[i]->box_change & BOX_CHANGE_SHAPE) change_shape = 1; + if (strcmp(fixes[i]->style,"deform") == 0) { deformflag = 1; FixDeform *deform = (FixDeform *) modify->fix[i]; - if (deform->box_change_shape && deform->remapflag != Domain::V_REMAP) + if ((deform->box_change & BOX_CHANGE_SHAPE) + && deform->remapflag != Domain::V_REMAP) error->all(FLERR,"Using fix srd with inconsistent " "fix deform remap option"); } diff --git a/src/USER-BOCS/fix_bocs.cpp b/src/USER-BOCS/fix_bocs.cpp index adce231bf1..3543c2f156 100644 --- a/src/USER-BOCS/fix_bocs.cpp +++ b/src/USER-BOCS/fix_bocs.cpp @@ -292,8 +292,12 @@ FixBocs::FixBocs(LAMMPS *lmp, int narg, char **arg) : if (p_flag[i]) pstat_flag = 1; if (pstat_flag) { - if (p_flag[0] || p_flag[1] || p_flag[2]) box_change_size = 1; - if (p_flag[3] || p_flag[4] || p_flag[5]) box_change_shape = 1; + if (p_flag[0]) box_change |= BOX_CHANGE_X; + if (p_flag[1]) box_change |= BOX_CHANGE_Y; + if (p_flag[2]) box_change |= BOX_CHANGE_Z; + if (p_flag[3]) box_change |= BOX_CHANGE_YZ; + if (p_flag[4]) box_change |= BOX_CHANGE_XZ; + if (p_flag[5]) box_change |= BOX_CHANGE_XY; no_change_box = 1; if (allremap == 0) restart_pbc = 1; diff --git a/src/USER-MISC/fix_npt_cauchy.cpp b/src/USER-MISC/fix_npt_cauchy.cpp index 1b0deb5ae3..7a4a34bd00 100644 --- a/src/USER-MISC/fix_npt_cauchy.cpp +++ b/src/USER-MISC/fix_npt_cauchy.cpp @@ -492,8 +492,12 @@ FixNPTCauchy::FixNPTCauchy(LAMMPS *lmp, int narg, char **arg) : if (p_flag[i]) pstat_flag = 1; if (pstat_flag) { - if (p_flag[0] || p_flag[1] || p_flag[2]) box_change_size = 1; - if (p_flag[3] || p_flag[4] || p_flag[5]) box_change_shape = 1; + if (p_flag[0]) box_change |= BOX_CHANGE_X; + if (p_flag[1]) box_change |= BOX_CHANGE_Y; + if (p_flag[2]) box_change |= BOX_CHANGE_Z; + if (p_flag[3]) box_change |= BOX_CHANGE_YZ; + if (p_flag[4]) box_change |= BOX_CHANGE_XZ; + if (p_flag[5]) box_change |= BOX_CHANGE_XY; no_change_box = 1; if (allremap == 0) restart_pbc = 1; diff --git a/src/USER-OMP/fix_rigid_nph_omp.cpp b/src/USER-OMP/fix_rigid_nph_omp.cpp index 31d53868c8..ff192341e4 100644 --- a/src/USER-OMP/fix_rigid_nph_omp.cpp +++ b/src/USER-OMP/fix_rigid_nph_omp.cpp @@ -33,7 +33,6 @@ FixRigidNPHOMP::FixRigidNPHOMP(LAMMPS *lmp, int narg, char **arg) : scalar_flag = 1; restart_global = 1; - box_change_size = 1; extscalar = 1; // error checks diff --git a/src/USER-OMP/fix_rigid_npt_omp.cpp b/src/USER-OMP/fix_rigid_npt_omp.cpp index 1e7c139d52..6da51e6220 100644 --- a/src/USER-OMP/fix_rigid_npt_omp.cpp +++ b/src/USER-OMP/fix_rigid_npt_omp.cpp @@ -33,7 +33,6 @@ FixRigidNPTOMP::FixRigidNPTOMP(LAMMPS *lmp, int narg, char **arg) : scalar_flag = 1; restart_global = 1; - box_change_size = 1; extscalar = 1; // error checks diff --git a/src/USER-QTB/fix_qbmsst.cpp b/src/USER-QTB/fix_qbmsst.cpp index abbf1701b8..27b1dcd4df 100644 --- a/src/USER-QTB/fix_qbmsst.cpp +++ b/src/USER-QTB/fix_qbmsst.cpp @@ -45,13 +45,16 @@ FixQBMSST::FixQBMSST(LAMMPS *lmp, int narg, char **arg) : { if (narg < 5) error->all(FLERR,"Illegal fix qbmsst command"); - if ( strcmp(arg[3],"x") == 0 ) + if ( strcmp(arg[3],"x") == 0 ) { direction = 0; - else if ( strcmp(arg[3],"y") == 0 ) + box_change |= BOX_CHANGE_X; + } else if ( strcmp(arg[3],"y") == 0 ) { direction = 1; - else if ( strcmp(arg[3],"z") == 0 ) + box_change |= BOX_CHANGE_Y; + } else if ( strcmp(arg[3],"z") == 0 ) { direction = 2; - else { + box_change |= BOX_CHANGE_Z; + } else { error->all(FLERR,"Illegal fix qbmsst command"); } velocity = atof(arg[4]); @@ -64,7 +67,6 @@ FixQBMSST::FixQBMSST(LAMMPS *lmp, int narg, char **arg) : extvector = 0; nevery = 1; restart_global = 1; - box_change_size = 1; time_integrate = 1; scalar_flag = 1; vector_flag = 1; diff --git a/src/USER-UEF/fix_nh_uef.cpp b/src/USER-UEF/fix_nh_uef.cpp index 8873688eb7..5c98a2dc85 100644 --- a/src/USER-UEF/fix_nh_uef.cpp +++ b/src/USER-UEF/fix_nh_uef.cpp @@ -163,7 +163,7 @@ FixNHUef::FixNHUef(LAMMPS *lmp, int narg, char **arg) : // flag that I change the box here (in case of nvt) - box_change_shape = 1; + box_change |= BOX_CHANGE_SHAPE; // initialize the UEFBox class which computes the box at each step diff --git a/src/domain.cpp b/src/domain.cpp index e894682556..efa2ef00cf 100644 --- a/src/domain.cpp +++ b/src/domain.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #include "style_region.h" #include "atom.h" #include "atom_vec.h" @@ -133,13 +134,39 @@ void Domain::init() box_change_size = box_change_shape = box_change_domain = 0; + // flags for detecting, if multiple fixes try to change the + // same box size or shape parameter + + int box_change_x=0, box_change_y=0, box_change_z=0; + int box_change_yz=0, box_change_xz=0, box_change_xy=0; + Fix **fixes = modify->fix; + if (nonperiodic == 2) box_change_size = 1; for (int i = 0; i < modify->nfix; i++) { - if (modify->fix[i]->box_change_size) box_change_size = 1; - if (modify->fix[i]->box_change_shape) box_change_shape = 1; - if (modify->fix[i]->box_change_domain) box_change_domain = 1; + if (fixes[i]->box_change & Fix::BOX_CHANGE_SIZE) box_change_size = 1; + if (fixes[i]->box_change & Fix::BOX_CHANGE_SHAPE) box_change_shape = 1; + if (fixes[i]->box_change & Fix::BOX_CHANGE_DOMAIN) box_change_domain = 1; + if (fixes[i]->box_change & Fix::BOX_CHANGE_X) box_change_x++; + if (fixes[i]->box_change & Fix::BOX_CHANGE_Y) box_change_y++; + if (fixes[i]->box_change & Fix::BOX_CHANGE_Z) box_change_z++; + if (fixes[i]->box_change & Fix::BOX_CHANGE_YZ) box_change_yz++; + if (fixes[i]->box_change & Fix::BOX_CHANGE_XZ) box_change_xz++; + if (fixes[i]->box_change & Fix::BOX_CHANGE_XY) box_change_xy++; } + std::string mesg = "Must not have multiple fixes change box parameter "; + +#define CHECK_BOX_FIX_ERROR(par) \ + if (box_change_ ## par > 1) error->all(FLERR,(mesg + #par).c_str()) + + CHECK_BOX_FIX_ERROR(x); + CHECK_BOX_FIX_ERROR(y); + CHECK_BOX_FIX_ERROR(z); + CHECK_BOX_FIX_ERROR(yz); + CHECK_BOX_FIX_ERROR(xz); + CHECK_BOX_FIX_ERROR(xy); +#undef CHECK_BOX_FIX_ERROR + box_change = 0; if (box_change_size || box_change_shape || box_change_domain) box_change = 1; diff --git a/src/fix.cpp b/src/fix.cpp index d86acf0ae4..9c883a6897 100644 --- a/src/fix.cpp +++ b/src/fix.cpp @@ -58,7 +58,7 @@ Fix::Fix(LAMMPS *lmp, int /*narg*/, char **arg) : restart_global = restart_peratom = restart_file = 0; force_reneighbor = 0; - box_change_size = box_change_shape = box_change_domain = 0; + box_change = NO_BOX_CHANGE; thermo_energy = 0; thermo_virial = 0; rigid_flag = 0; diff --git a/src/fix.h b/src/fix.h index bcab6f289e..921778ae98 100644 --- a/src/fix.h +++ b/src/fix.h @@ -30,9 +30,14 @@ class Fix : protected Pointers { int restart_file; // 1 if Fix writes own restart file, 0 if not int force_reneighbor; // 1 if Fix forces reneighboring, 0 if not - int box_change_size; // 1 if Fix changes box size, 0 if not - int box_change_shape; // 1 if Fix changes box shape, 0 if not - int box_change_domain; // 1 if Fix changes proc sub-domains, 0 if not + int box_change; // >0 if Fix changes box size, shape, or sub-domains, 0 if not + enum { + NO_BOX_CHANGE = 0, BOX_CHANGE_ANY = 1<<0, BOX_CHANGE_DOMAIN = 1<<1, + BOX_CHANGE_X = 1<<2, BOX_CHANGE_Y = 1<<3, BOX_CHANGE_Z = 1<<4, + BOX_CHANGE_YZ = 1<<5, BOX_CHANGE_XZ = 1<<6, BOX_CHANGE_XY = 1<<7, + BOX_CHANGE_SIZE = BOX_CHANGE_X | BOX_CHANGE_Y | BOX_CHANGE_Z, + BOX_CHANGE_SHAPE = BOX_CHANGE_YZ | BOX_CHANGE_XZ | BOX_CHANGE_XY + }; bigint next_reneighbor; // next timestep to force a reneighboring int thermo_energy; // 1 if fix_modify enabled ThEng, 0 if not diff --git a/src/fix_balance.cpp b/src/fix_balance.cpp index 5ca1ec124a..b178cca83b 100644 --- a/src/fix_balance.cpp +++ b/src/fix_balance.cpp @@ -39,7 +39,7 @@ FixBalance::FixBalance(LAMMPS *lmp, int narg, char **arg) : { if (narg < 6) error->all(FLERR,"Illegal fix balance command"); - box_change_domain = 1; + box_change = BOX_CHANGE_DOMAIN; scalar_flag = 1; extscalar = 0; vector_flag = 1; diff --git a/src/fix_box_relax.cpp b/src/fix_box_relax.cpp index c19ea918b4..8d6111c0a0 100644 --- a/src/fix_box_relax.cpp +++ b/src/fix_box_relax.cpp @@ -218,8 +218,13 @@ FixBoxRelax::FixBoxRelax(LAMMPS *lmp, int narg, char **arg) : } else error->all(FLERR,"Illegal fix box/relax command"); } - if (p_flag[0] || p_flag[1] || p_flag[2]) box_change_size = 1; - if (p_flag[3] || p_flag[4] || p_flag[5]) box_change_shape = 1; + if (p_flag[0]) box_change |= BOX_CHANGE_X; + if (p_flag[1]) box_change |= BOX_CHANGE_Y; + if (p_flag[2]) box_change |= BOX_CHANGE_Z; + if (p_flag[3]) box_change |= BOX_CHANGE_YZ; + if (p_flag[4]) box_change |= BOX_CHANGE_XZ; + if (p_flag[5]) box_change |= BOX_CHANGE_XY; + if (allremap == 0) restart_pbc = 1; // error checks diff --git a/src/fix_deform.cpp b/src/fix_deform.cpp index 9d84c4bb62..4ecfa6f433 100644 --- a/src/fix_deform.cpp +++ b/src/fix_deform.cpp @@ -211,8 +211,12 @@ rfix(NULL), irregular(NULL), set(NULL) if (set[i].style == NONE) dimflag[i] = 0; else dimflag[i] = 1; - if (dimflag[0] || dimflag[1] || dimflag[2]) box_change_size = 1; - if (dimflag[3] || dimflag[4] || dimflag[5]) box_change_shape = 1; + if (dimflag[0]) box_change |= BOX_CHANGE_X; + if (dimflag[1]) box_change |= BOX_CHANGE_Y; + if (dimflag[2]) box_change |= BOX_CHANGE_Z; + if (dimflag[3]) box_change |= BOX_CHANGE_YZ; + if (dimflag[4]) box_change |= BOX_CHANGE_XZ; + if (dimflag[5]) box_change |= BOX_CHANGE_XY; // no tensile deformation on shrink-wrapped dims // b/c shrink wrap will change box-length diff --git a/src/fix_nh.cpp b/src/fix_nh.cpp index bb3fe7559c..e397e3367a 100644 --- a/src/fix_nh.cpp +++ b/src/fix_nh.cpp @@ -476,8 +476,12 @@ FixNH::FixNH(LAMMPS *lmp, int narg, char **arg) : if (p_flag[i]) pstat_flag = 1; if (pstat_flag) { - if (p_flag[0] || p_flag[1] || p_flag[2]) box_change_size = 1; - if (p_flag[3] || p_flag[4] || p_flag[5]) box_change_shape = 1; + if (p_flag[0]) box_change |= BOX_CHANGE_X; + if (p_flag[1]) box_change |= BOX_CHANGE_Y; + if (p_flag[2]) box_change |= BOX_CHANGE_Z; + if (p_flag[3]) box_change |= BOX_CHANGE_YZ; + if (p_flag[4]) box_change |= BOX_CHANGE_XZ; + if (p_flag[5]) box_change |= BOX_CHANGE_XY; no_change_box = 1; if (allremap == 0) restart_pbc = 1; diff --git a/src/fix_press_berendsen.cpp b/src/fix_press_berendsen.cpp index c090c554e2..184f02c440 100644 --- a/src/fix_press_berendsen.cpp +++ b/src/fix_press_berendsen.cpp @@ -40,8 +40,6 @@ FixPressBerendsen::FixPressBerendsen(LAMMPS *lmp, int narg, char **arg) : { if (narg < 5) error->all(FLERR,"Illegal fix press/berendsen command"); - box_change_size = 1; - // Berendsen barostat applied every step nevery = 1; @@ -204,6 +202,10 @@ FixPressBerendsen::FixPressBerendsen(LAMMPS *lmp, int narg, char **arg) : (p_flag[2] && p_period[2] <= 0.0)) error->all(FLERR,"Fix press/berendsen damping parameters must be > 0.0"); + if (p_flag[0]) box_change |= BOX_CHANGE_X; + if (p_flag[1]) box_change |= BOX_CHANGE_Y; + if (p_flag[2]) box_change |= BOX_CHANGE_Z; + // pstyle = ISO if XYZ coupling or XY coupling in 2d -> 1 dof // else pstyle = ANISO -> 3 dof