Commit bb36e6e3 authored by Axel Kohlmeyer's avatar Axel Kohlmeyer
Browse files

implement some examples for using the utils::strmatch() function and use it...

implement some examples for using the utils::strmatch() function and use it for inexact Force::pair_match()
parent 7fcc76f0
Loading
Loading
Loading
Loading
+7 −12
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@
#include "neighbor.h"
#include "citeme.h"
#include "error.h"
#include "utils.h"

using namespace LAMMPS_NS;
using namespace FixConst;
@@ -221,12 +222,11 @@ void FixGPU::init()
  // hybrid cannot be used with force/neigh option

  if (_gpu_mode == GPU_NEIGH || _gpu_mode == GPU_HYB_NEIGH)
    if (force->pair_match("hybrid",1) != NULL ||
        force->pair_match("hybrid/overlay",1) != NULL)
    if (force->pair_match("^hybrid",0) != NULL)
      error->all(FLERR,"Cannot use pair hybrid with GPU neighbor list builds");

  if (_particle_split < 0)
    if (force->pair_match("hybrid",1) != NULL ||
        force->pair_match("hybrid/overlay",1) != NULL)
    if (force->pair_match("^hybrid",0) != NULL)
      error->all(FLERR,"GPU split param must be positive "
                 "for hybrid pair styles");

@@ -243,21 +243,16 @@ void FixGPU::init()

  // make sure fdotr virial is not accumulated multiple times

  if (force->pair_match("hybrid",1) != NULL) {
  if (force->pair_match("^hybrid",0) != NULL) {
    PairHybrid *hybrid = (PairHybrid *) force->pair;
    for (int i = 0; i < hybrid->nstyles; i++)
      if (strstr(hybrid->keywords[i],"/gpu")==NULL)
        force->pair->no_virial_fdotr_compute = 1;
  } else if (force->pair_match("hybrid/overlay",1) != NULL) {
    PairHybridOverlay *hybrid = (PairHybridOverlay *) force->pair;
    for (int i = 0; i < hybrid->nstyles; i++)
      if (strstr(hybrid->keywords[i],"/gpu")==NULL)
      if (utils::strmatch(hybrid->keywords[i],"/gpu$") == NULL)
        force->pair->no_virial_fdotr_compute = 1;
  }

  // rRESPA support

  if (strstr(update->integrate_style,"respa"))
  if (utils::strmatch(update->integrate_style,"^respa"))
    _nlevels_respa = ((Respa *) update->integrate)->nlevels;
}

+5 −3
Original line number Diff line number Diff line
@@ -33,6 +33,8 @@
#include "update.h"
#include "memory.h"
#include "error.h"
#include "utils.h"

using namespace LAMMPS_NS;
using namespace FixConst;

@@ -121,12 +123,12 @@ void FixQEQComb::init()
  if (!atom->q_flag)
    error->all(FLERR,"Fix qeq/comb requires atom attribute q");

  comb = (PairComb *) force->pair_match("comb",1);
  comb3 = (PairComb3 *) force->pair_match("comb3",1);
  comb = (PairComb *) force->pair_match("^comb",0);
  comb3 = (PairComb3 *) force->pair_match("^comb3",0);
  if (comb == NULL && comb3 == NULL)
    error->all(FLERR,"Must use pair_style comb or comb3 with fix qeq/comb");

  if (strstr(update->integrate_style,"respa")) {
  if (utils::strmatch(update->integrate_style,"^respa")) {
    ilevel_respa = ((Respa *) update->integrate)->nlevels-1;
    if (respa_level >= 0) ilevel_respa = MIN(respa_level,ilevel_respa);
  }
+3 −4
Original line number Diff line number Diff line
@@ -46,9 +46,8 @@
#include "thermo.h"
#include "output.h"
#include "neighbor.h"
#include <iostream>
#include "utils.h"

using namespace std;
using namespace LAMMPS_NS;
using namespace FixConst;
using namespace MathConst;
@@ -478,8 +477,8 @@ void FixGCMC::init()
    if ((force->kspace) ||
        (force->pair == NULL) ||
        (force->pair->single_enable == 0) ||
        (force->pair_match("hybrid",0)) ||
        (force->pair_match("eam",0)) ||
        (force->pair_match("^hybrid",0)) ||
        (force->pair_match("^eam",0)) ||
        (force->pair->tail_flag)
        ) {
      full_flag = true;
+3 −1
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@
#include "comm.h"
#include "domain.h"
#include "math_const.h"
#include "utils.h"

using namespace LAMMPS_NS;
using namespace MathConst;
@@ -124,7 +125,8 @@ void ComputeGroupGroup::init()

  if (pairflag && force->pair == NULL)
    error->all(FLERR,"No pair style defined for compute group/group");
  if (force->pair_match("hybrid",0) == NULL && force->pair->single_enable == 0)
  if (force->pair_match("^hybrid",0) == NULL
      && force->pair->single_enable == 0)
    error->all(FLERR,"Pair style does not support compute group/group");

  // error if Kspace style does not compute group/group interactions
+6 −18
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@
#include "group.h"
#include "memory.h"
#include "error.h"
#include "utils.h"

using namespace LAMMPS_NS;

@@ -287,26 +288,13 @@ Pair *Force::pair_match(const char *word, int exact, int nsub)
  int iwhich,count;

  if (exact && strcmp(pair_style,word) == 0) return pair;
  else if (!exact && strstr(pair_style,word)) return pair;

  else if (strstr(pair_style,"hybrid/overlay")) {
    PairHybridOverlay *hybrid = (PairHybridOverlay *) pair;
    count = 0;
    for (int i = 0; i < hybrid->nstyles; i++)
      if ((exact && strcmp(hybrid->keywords[i],word) == 0) ||
          (!exact && strstr(hybrid->keywords[i],word))) {
        iwhich = i;
        count++;
        if (nsub == count) return hybrid->styles[iwhich];
      }
    if (count == 1) return hybrid->styles[iwhich];

  } else if (strstr(pair_style,"hybrid")) {
  else if (!exact && utils::strmatch(pair_style,word)) return pair;
  else if (utils::strmatch(pair_style,"^hybrid")) {
    PairHybrid *hybrid = (PairHybrid *) pair;
    count = 0;
    for (int i = 0; i < hybrid->nstyles; i++)
      if ((exact && strcmp(hybrid->keywords[i],word) == 0) ||
          (!exact && strstr(hybrid->keywords[i],word))) {
          (!exact && utils::strmatch(hybrid->keywords[i],word))) {
        iwhich = i;
        count++;
        if (nsub == count) return hybrid->styles[iwhich];
@@ -327,7 +315,7 @@ char *Force::pair_match_ptr(Pair *ptr)
{
  if (ptr == pair) return pair_style;

  if (strstr(pair_style,"hybrid")) {
  if (utils::strmatch(pair_style,"^hybrid")) {
    PairHybrid *hybrid = (PairHybrid *) pair;
    for (int i = 0; i < hybrid->nstyles; i++)
      if (ptr == hybrid->styles[i]) return hybrid->keywords[i];
@@ -741,7 +729,7 @@ KSpace *Force::kspace_creator(LAMMPS *lmp)
KSpace *Force::kspace_match(const char *word, int exact)
{
  if (exact && strcmp(kspace_style,word) == 0) return kspace;
  else if (!exact && strstr(kspace_style,word)) return kspace;
  else if (!exact && utils::strmatch(kspace_style,word)) return kspace;
  return NULL;
}

Loading