generalize some checks in fix rigid and rigid/small

This commit is contained in:
Axel Kohlmeyer
2021-03-31 15:55:31 -04:00
parent c53f2d4629
commit 7699fb3708
3 changed files with 25 additions and 28 deletions

View File

@ -720,17 +720,14 @@ void FixRigid::init()
}
}
// error if npt,nph fix comes before rigid fix
for (i = 0; i < modify->nfix; i++) {
if (strcmp(modify->fix[i]->style,"npt") == 0) break;
if (strcmp(modify->fix[i]->style,"nph") == 0) break;
}
// error if a fix changing the box comes before rigid fix
for (i = 0; i < modify->nfix; i++)
if (modify->fix[i]->box_change) break;
if (i < modify->nfix) {
for (int j = i; j < modify->nfix; j++)
if (strcmp(modify->fix[j]->style,"rigid") == 0)
error->all(FLERR,"Rigid fix must come before NPT/NPH fix");
if (utils::strmatch(modify->fix[j]->style,"^rigid"))
error->all(FLERR,"Rigid fixes must come before any box changing fix");
}
// add gravity forces based on gravity vector from fix
@ -738,7 +735,7 @@ void FixRigid::init()
if (id_gravity) {
int ifix = modify->find_fix(id_gravity);
if (ifix < 0) error->all(FLERR,"Fix rigid cannot find fix gravity ID");
if (strcmp(modify->fix[ifix]->style,"gravity") != 0)
if (!utils::strmatch(modify->fix[ifix]->style,"^gravity"))
error->all(FLERR,"Fix rigid gravity fix is invalid");
int tmp;
gvec = (double *) modify->fix[ifix]->extract("gvec",tmp);

View File

@ -19,22 +19,24 @@
#include "fix_rigid_nh_small.h"
#include <cmath>
#include <cstring>
#include "math_extra.h"
#include "atom.h"
#include "comm.h"
#include "compute.h"
#include "domain.h"
#include "update.h"
#include "modify.h"
#include "fix_deform.h"
#include "group.h"
#include "comm.h"
#include "force.h"
#include "kspace.h"
#include "memory.h"
#include "error.h"
#include "fix_deform.h"
#include "force.h"
#include "group.h"
#include "kspace.h"
#include "math_extra.h"
#include "memory.h"
#include "modify.h"
#include "molecule.h"
#include "rigid_const.h"
#include "update.h"
#include <cmath>
#include <cstring>
using namespace LAMMPS_NS;
using namespace FixConst;

View File

@ -571,16 +571,14 @@ void FixRigidSmall::init()
}
}
// error if npt,nph fix comes before rigid fix
// error if a fix changing the box comes before rigid fix
for (i = 0; i < modify->nfix; i++) {
if (strcmp(modify->fix[i]->style,"npt") == 0) break;
if (strcmp(modify->fix[i]->style,"nph") == 0) break;
}
for (i = 0; i < modify->nfix; i++)
if (modify->fix[i]->box_change) break;
if (i < modify->nfix) {
for (int j = i; j < modify->nfix; j++)
if (strcmp(modify->fix[j]->style,"rigid") == 0)
error->all(FLERR,"Rigid fix must come before NPT/NPH fix");
if (utils::strmatch(modify->fix[j]->style,"^rigid"))
error->all(FLERR,"Rigid fixes must come before any box changing fix");
}
// add gravity forces based on gravity vector from fix
@ -588,7 +586,7 @@ void FixRigidSmall::init()
if (id_gravity) {
int ifix = modify->find_fix(id_gravity);
if (ifix < 0) error->all(FLERR,"Fix rigid/small cannot find fix gravity ID");
if (strcmp(modify->fix[ifix]->style,"gravity") != 0)
if (!utils::strmatch(modify->fix[ifix]->style,"^gravity"))
error->all(FLERR,"Fix rigid/small gravity fix is invalid");
int tmp;
gvec = (double *) modify->fix[ifix]->extract("gvec",tmp);