more accurate checking for styles using utils::strmatch() instead of strcmp() or strncmp()

This commit is contained in:
Axel Kohlmeyer 2019-06-07 07:14:57 -04:00
parent b53df3dd63
commit 61e9dc4c8d
No known key found for this signature in database
GPG Key ID: D9B44E93BF0C375A
7 changed files with 30 additions and 33 deletions

View File

@ -33,6 +33,7 @@
#include "compute.h"
#include "modify.h"
#include "pair.h"
#include "utils.h"
#include "plumed/wrapper/Plumed.h"
@ -250,15 +251,15 @@ FixPlumed::FixPlumed(LAMMPS *lmp, int narg, char **arg) :
// Avoid conflict with fixes that define internal pressure computes.
// See comment in the setup method
if ((strncmp(check_style,"nph",3) == 0) ||
(strncmp(check_style,"npt",3) == 0) ||
(strncmp(check_style,"rigid/nph",9) == 0) ||
(strncmp(check_style,"rigid/npt",9) == 0) ||
(strncmp(check_style,"msst",4) == 0) ||
(strncmp(check_style,"nphug",5) == 0) ||
(strncmp(check_style,"ipi",3) == 0) ||
(strncmp(check_style,"press/berendsen",15) == 0) ||
(strncmp(check_style,"qbmsst",6) == 0))
if (utils::strmatch(check_style,"^nph") ||
utils::strmatch(check_style,"^npt") ||
utils::strmatch(check_style,"^rigid/nph") ||
utils::strmatch(check_style,"^rigid/npt") ||
utils::strmatch(check_style,"^msst") ||
utils::strmatch(check_style,"^nphug") ||
utils::strmatch(check_style,"^ipi") ||
utils::strmatch(check_style,"^press/berendsen") ||
utils::strmatch(check_style,"^qbmsst"))
error->all(FLERR,"Fix plumed must be defined before any other fixes, "
"that compute pressure internally");
}
@ -289,7 +290,7 @@ int FixPlumed::setmask()
void FixPlumed::init()
{
if (strcmp(update->integrate_style,"respa") == 0)
if (utils::strmatch(update->integrate_style,"^respa"))
nlevels_respa = ((Respa *) update->integrate)->nlevels;
// This avoids nan pressure if compute_pressure is called
@ -309,12 +310,12 @@ void FixPlumed::setup(int vflag)
// has to be executed first. This creates a race condition with the
// setup method of fix_nh. This is why in the constructor I check if
// nh fixes have already been called.
if (strcmp(update->integrate_style,"verlet") == 0)
post_force(vflag);
else {
if (utils::strmatch(update->integrate_style,"^respa")) {
((Respa *) update->integrate)->copy_flevel_f(nlevels_respa-1);
post_force_respa(vflag,nlevels_respa-1,0);
((Respa *) update->integrate)->copy_f_flevel(nlevels_respa-1);
} else {
post_force(vflag);
}
}

View File

@ -41,6 +41,7 @@
#include "group.h"
#include "kspace.h"
#include "thermo.h"
#include "utils.h"
using namespace LAMMPS_NS;
using namespace FixConst;
@ -410,14 +411,14 @@ void FixQBMSST::init()
// rfix[] = indices to each fix rigid
nrigid = 0;
for (int i = 0; i < modify->nfix; i++)
if (strcmp(modify->fix[i]->style,"rigid") == 0 ||
strcmp(modify->fix[i]->style,"poems") == 0) nrigid++;
if (nrigid) {
if (utils::strmatch(modify->fix[i]->style,"^rigid") ||
(strcmp(modify->fix[i]->style,"poems") == 0)) nrigid++;
if (nrigid > 0) {
rfix = new int[nrigid];
nrigid = 0;
for (int i = 0; i < modify->nfix; i++)
if (strcmp(modify->fix[i]->style,"rigid") == 0 ||
strcmp(modify->fix[i]->style,"poems") == 0) rfix[nrigid++] = i;
if (utils::strmatch(modify->fix[i]->style,"^rigid") ||
(strcmp(modify->fix[i]->style,"poems") == 0)) rfix[nrigid++] = i;
}
}

View File

@ -31,6 +31,7 @@
#include "math_const.h"
#include "memory.h"
#include "error.h"
#include "utils.h"
using namespace LAMMPS_NS;
using namespace FixConst;
@ -375,8 +376,7 @@ void FixAdapt::init()
// if pair hybrid, test that ilo,ihi,jlo,jhi are valid for sub-style
if (strcmp(force->pair_style,"hybrid") == 0 ||
strcmp(force->pair_style,"hybrid/overlay") == 0) {
if (utils::strmatch(force->pair_style,"^hybrid")) {
PairHybrid *pair = (PairHybrid *) force->pair;
for (i = ad->ilo; i <= ad->ihi; i++)
for (j = MAX(ad->jlo,i); j <= ad->jhi; j++)
@ -416,8 +416,7 @@ void FixAdapt::init()
if (ad->bdim == 1) ad->vector = (double *) ptr;
if (strcmp(force->bond_style,"hybrid") == 0 ||
strcmp(force->bond_style,"hybrid_overlay") == 0)
if (utils::strmatch(force->bond_style,"^hybrid"))
error->all(FLERR,"Fix adapt does not support bond_style hybrid");
delete [] bstyle;

View File

@ -23,6 +23,7 @@
#include "modify.h"
#include "comm.h"
#include "error.h"
#include "utils.h"
using namespace LAMMPS_NS;
using namespace FixConst;
@ -72,8 +73,8 @@ void FixNVELimit::init()
// warn if using fix shake, which will lead to invalid constraint forces
for (int i = 0; i < modify->nfix; i++)
if ((strcmp(modify->fix[i]->style,"shake") == 0)
|| (strcmp(modify->fix[i]->style,"rattle") == 0)) {
if (utils::strmatch(modify->fix[i]->style,"^shake")
|| utils::strmatch(modify->fix[i]->style,"^rattle")) {
if (comm->me == 0)
error->warning(FLERR,"Should not use fix nve/limit with fix shake or fix rattle");
}

View File

@ -46,6 +46,7 @@
#include "citeme.h"
#include "memory.h"
#include "error.h"
#include "utils.h"
#include <map>
@ -1282,8 +1283,8 @@ void Neighbor::init_topology()
int bond_off = 0;
int angle_off = 0;
for (i = 0; i < modify->nfix; i++)
if ((strcmp(modify->fix[i]->style,"shake") == 0)
|| (strcmp(modify->fix[i]->style,"rattle") == 0))
if (utils::strmatch(modify->fix[i]->style,"^shake")
|| utils::strmatch(modify->fix[i]->style,"^rattle"))
bond_off = angle_off = 1;
if (force->bond && force->bond_match("quartic")) bond_off = 1;

View File

@ -219,12 +219,6 @@ void PairCoulStreitz::init_style()
error->all(FLERR,"Pair style requires a KSpace style");
g_ewald = force->kspace->g_ewald;
}
// ptr to QEQ fix
//for (i = 0; i < modify->nfix; i++)
// if (strcmp(modify->fix[i]->style,"qeq") == 0) break;
//if (i < modify->nfix) fixqeq = (FixQEQ *) modify->fix[i];
//else fixqeq = NULL;
}
/* ----------------------------------------------------------------------

View File

@ -112,7 +112,7 @@ void Velocity::command(int narg, char **arg)
int initcomm = 0;
if (style == ZERO && rfix >= 0 &&
strcmp(modify->fix[rfix]->style,"rigid/small") == 0) initcomm = 1;
utils::strmatch(modify->fix[rfix]->style,"^rigid/small")) initcomm = 1;
if ((style == CREATE || style == SET) && temperature &&
strcmp(temperature->style,"temp/cs") == 0) initcomm = 1;