diff --git a/src/fix_press_berendsen.cpp b/src/fix_press_berendsen.cpp index bee87f1111..31f200976c 100644 --- a/src/fix_press_berendsen.cpp +++ b/src/fix_press_berendsen.cpp @@ -33,6 +33,7 @@ using namespace LAMMPS_NS; #define MAX(A,B) ((A) > (B)) ? (A) : (B) enum{NOBIAS,BIAS}; +enum{XYZ,XY,YZ,XZ,ANISO}; /* ---------------------------------------------------------------------- */ @@ -50,7 +51,7 @@ FixPressBerendsen::FixPressBerendsen(LAMMPS *lmp, int narg, char **arg) : if (strcmp(arg[3],"xyz") == 0) { if (narg < 7) error->all("Illegal fix press/berendsen command"); - press_couple = 0; + press_couple = XYZ; p_start[0] = p_start[1] = p_start[2] = atof(arg[4]); p_stop[0] = p_stop[1] = p_stop[2] = atof(arg[5]); p_period[0] = p_period[1] = p_period[2] = atof(arg[6]); @@ -61,16 +62,16 @@ FixPressBerendsen::FixPressBerendsen(LAMMPS *lmp, int narg, char **arg) : } } else { - if (strcmp(arg[3],"xy") == 0) press_couple = 1; - else if (strcmp(arg[3],"yz") == 0) press_couple = 2; - else if (strcmp(arg[3],"xz") == 0) press_couple = 3; - else if (strcmp(arg[3],"aniso") == 0) press_couple = 4; + if (strcmp(arg[3],"xy") == 0) press_couple = XY; + else if (strcmp(arg[3],"yz") == 0) press_couple = YZ; + else if (strcmp(arg[3],"xz") == 0) press_couple = XZ; + else if (strcmp(arg[3],"aniso") == 0) press_couple = ANISO; else error->all("Illegal fix press/berendsen command"); if (narg < 8) error->all("Illegal fix press/berendsen command"); if (domain->dimension == 2 && - (press_couple == 1 || press_couple == 2 || press_couple == 3)) + (press_couple == XY || press_couple == YZ || press_couple == XZ)) error->all("Invalid fix press/berendsen command for a 2d simulation"); if (strcmp(arg[4],"NULL") == 0) { @@ -112,7 +113,7 @@ FixPressBerendsen::FixPressBerendsen(LAMMPS *lmp, int narg, char **arg) : allremap = 1; int iarg; - if (press_couple == 0) iarg = 7; + if (press_couple == XYZ) iarg = 7; else iarg = 11; while (iarg < narg) { @@ -133,6 +134,23 @@ FixPressBerendsen::FixPressBerendsen(LAMMPS *lmp, int narg, char **arg) : // error checks + if (press_couple == XY && (p_flag[0] == 0 || p_flag[1] == 0)) + error->all("Invalid fix npt command"); + if (press_couple == YZ && (p_flag[1] == 0 || p_flag[2] == 0)) + error->all("Invalid fix npt command"); + if (press_couple == XZ && (p_flag[0] == 0 || p_flag[2] == 0)) + error->all("Invalid fix npt command"); + + if (press_couple == XY && + (p_start[0] != p_start[1] || p_stop[0] != p_stop[1])) + error->all("Invalid fix npt command"); + if (press_couple == YZ && + (p_start[1] != p_start[2] || p_stop[1] != p_stop[2])) + error->all("Invalid fix npt command"); + if (press_couple == XZ && + (p_start[0] != p_start[2] || p_stop[0] != p_stop[2])) + error->all("Invalid fix npt command"); + if (p_flag[0] && domain->xperiodic == 0) error->all("Cannot use fix press/berendsen on a non-periodic dimension"); if (p_flag[1] && domain->yperiodic == 0) @@ -281,7 +299,7 @@ void FixPressBerendsen::end_of_step() { // compute new T,P - if (press_couple == 0) { + if (press_couple == XYZ) { double tmp = temperature->compute_scalar(); tmp = pressure->compute_scalar(); } else { @@ -319,21 +337,21 @@ void FixPressBerendsen::couple() { double *tensor = pressure->vector; - if (press_couple == 0) + if (press_couple == XYZ) p_current[0] = p_current[1] = p_current[2] = pressure->scalar; - else if (press_couple == 1) { + else if (press_couple == XY) { double ave = 0.5 * (tensor[0] + tensor[1]); p_current[0] = p_current[1] = ave; p_current[2] = tensor[2]; - } else if (press_couple == 2) { + } else if (press_couple == YZ) { double ave = 0.5 * (tensor[1] + tensor[2]); p_current[1] = p_current[2] = ave; p_current[0] = tensor[0]; - } else if (press_couple == 3) { + } else if (press_couple == XZ) { double ave = 0.5 * (tensor[0] + tensor[2]); p_current[0] = p_current[2] = ave; p_current[1] = tensor[1]; - } if (press_couple == 4) { + } if (press_couple == ANISO) { p_current[0] = tensor[0]; p_current[1] = tensor[1]; p_current[2] = tensor[2];