Unverified Commit 6913e3a6 authored by Axel Kohlmeyer's avatar Axel Kohlmeyer Committed by GitHub
Browse files

Merge pull request #1760 from lammps/fix-dummy

added internal fix dummy command to enable more control of fix ordering
parents 6b8f26e8 eba1a156
Loading
Loading
Loading
Loading
+25 −7
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@
#include "update.h"
#include "modify.h"
#include "fix.h"
#include "fix_dummy.h"
#include "fix_neigh_history.h"
#include "comm.h"
#include "neighbor.h"
@@ -43,7 +44,6 @@ PairGranHookeHistory::PairGranHookeHistory(LAMMPS *lmp) : Pair(lmp)
  no_virial_fdotr_compute = 1;
  history = 1;
  size_history = 3;
  fix_history = NULL;

  single_extra = 10;
  svector = new double[10];
@@ -60,6 +60,19 @@ PairGranHookeHistory::PairGranHookeHistory(LAMMPS *lmp) : Pair(lmp)
  // keep default behavior of history[i][j] = -history[j][i]

  nondefault_history_transfer = 0;

  // create dummy fix as placeholder for FixNeighHistory
  // this is so final order of Modify:fix will conform to input script

  fix_history = NULL;

  char **fixarg = new char*[3];
  fixarg[0] = (char *) "NEIGH_HISTORY_HH_DUMMY";
  fixarg[1] = (char *) "all";
  fixarg[2] = (char *) "DUMMY";
  modify->add_fix(3,fixarg,1);
  delete [] fixarg;
  fix_dummy = (FixDummy *) modify->fix[modify->nfix-1];
}

/* ---------------------------------------------------------------------- */
@@ -69,7 +82,9 @@ PairGranHookeHistory::~PairGranHookeHistory()
  if (copymode) return;

  delete [] svector;
  if (fix_history) modify->delete_fix("NEIGH_HISTORY");

  if (!fix_history) modify->delete_fix("NEIGH_HISTORY_HH_DUMMY");
  else modify->delete_fix("NEIGH_HISTORY_HH");

  if (allocated) {
    memory->destroy(setflag);
@@ -412,19 +427,22 @@ void PairGranHookeHistory::init_style()

  dt = update->dt;

  // if first init, create Fix needed for storing shear history
  // if history is stored and first init, create Fix to store history
  // it replaces FixDummy, created in the constructor
  // this is so its order in the fix list is preserved

  if (history && fix_history == NULL) {
    char dnumstr[16];
    sprintf(dnumstr,"%d",size_history);
    char **fixarg = new char*[4];
    fixarg[0] = (char *) "NEIGH_HISTORY";
    fixarg[0] = (char *) "NEIGH_HISTORY_HH";
    fixarg[1] = (char *) "all";
    fixarg[2] = (char *) "NEIGH_HISTORY";
    fixarg[3] = dnumstr;
    modify->add_fix(4,fixarg,1);
    modify->replace_fix("NEIGH_HISTORY_HH_DUMMY",4,fixarg,1);
    delete [] fixarg;
    fix_history = (FixNeighHistory *) modify->fix[modify->nfix-1];
    int ifix = modify->find_fix("NEIGH_HISTORY_HH");
    fix_history = (FixNeighHistory *) modify->fix[ifix];
    fix_history->pair = this;
  }

@@ -491,7 +509,7 @@ void PairGranHookeHistory::init_style()
  // set fix which stores history info

  if (history) {
    int ifix = modify->find_fix("NEIGH_HISTORY");
    int ifix = modify->find_fix("NEIGH_HISTORY_HH");
    if (ifix < 0) error->all(FLERR,"Could not find pair fix neigh history ID");
    fix_history = (FixNeighHistory *) modify->fix[ifix];
  }
+1 −0
Original line number Diff line number Diff line
@@ -56,6 +56,7 @@ class PairGranHookeHistory : public Pair {

  int size_history;

  class FixDummy *fix_dummy;
  class FixNeighHistory *fix_history;

  // storage of rigid body masses for use in granular interactions
+33 −15
Original line number Diff line number Diff line
/* ----------------------------------------------------------------------
   LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
   http://lammps.sandia.gov, Sandia National Laboratories
   Steve Plimpton, sjplimp@sandia.gov

@@ -25,6 +26,7 @@ See the README file in the top-level LAMMPS directory.
#include "update.h"
#include "modify.h"
#include "fix.h"
#include "fix_dummy.h"
#include "fix_neigh_history.h"
#include "comm.h"
#include "neighbor.h"
@@ -62,7 +64,6 @@ PairGranular::PairGranular(LAMMPS *lmp) : Pair(lmp)
{
  single_enable = 1;
  no_virial_fdotr_compute = 1;
  fix_history = NULL;

  single_extra = 12;
  svector = new double[single_extra];
@@ -90,6 +91,19 @@ PairGranular::PairGranular(LAMMPS *lmp) : Pair(lmp)
  nondefault_history_transfer = 0;
  tangential_history_index = 0;
  roll_history_index = twist_history_index = 0;

  // create dummy fix as placeholder for FixNeighHistory
  // this is so final order of Modify:fix will conform to input script

  fix_history = NULL;

  char **fixarg = new char*[3];
  fixarg[0] = (char *) "NEIGH_HISTORY_GRANULAR_DUMMY";
  fixarg[1] = (char *) "all";
  fixarg[2] = (char *) "DUMMY";
  modify->add_fix(3,fixarg,1);
  delete [] fixarg;
  fix_dummy = (FixDummy *) modify->fix[modify->nfix-1];
}

/* ---------------------------------------------------------------------- */
@@ -97,7 +111,9 @@ PairGranular::PairGranular(LAMMPS *lmp) : Pair(lmp)
PairGranular::~PairGranular()
{
  delete [] svector;
  if (fix_history) modify->delete_fix("NEIGH_HISTORY");

  if (!fix_history) modify->delete_fix("NEIGH_HISTORY_GRANULAR_DUMMY");
  else modify->delete_fix("NEIGH_HISTORY_GRANULAR");

  if (allocated) {
    memory->destroy(setflag);
@@ -1021,20 +1037,22 @@ void PairGranular::init_style()

  dt = update->dt;

  // if history is stored:
  // if first init, create Fix needed for storing history
  // if history is stored and first init, create Fix to store history
  // it replaces FixDummy, created in the constructor
  // this is so its order in the fix list is preserved

  if (use_history && fix_history == NULL) {
    char dnumstr[16];
    sprintf(dnumstr,"%d",size_history);
    char **fixarg = new char*[4];
    fixarg[0] = (char *) "NEIGH_HISTORY";
    fixarg[0] = (char *) "NEIGH_HISTORY_GRANULAR";
    fixarg[1] = (char *) "all";
    fixarg[2] = (char *) "NEIGH_HISTORY";
    fixarg[3] = dnumstr;
    modify->add_fix(4,fixarg,1);
    modify->replace_fix("NEIGH_HISTORY_GRANULAR_DUMMY",4,fixarg,1);
    delete [] fixarg;
    fix_history = (FixNeighHistory *) modify->fix[modify->nfix-1];
    int ifix = modify->find_fix("NEIGH_HISTORY_GRANULAR");
    fix_history = (FixNeighHistory *) modify->fix[ifix];
    fix_history->pair = this;
  }

@@ -1104,7 +1122,7 @@ void PairGranular::init_style()
  // set fix which stores history info

  if (size_history > 0) {
    int ifix = modify->find_fix("NEIGH_HISTORY");
    int ifix = modify->find_fix("NEIGH_HISTORY_GRANULAR");
    if (ifix < 0) error->all(FLERR,"Could not find pair fix neigh history ID");
    fix_history = (FixNeighHistory *) modify->fix[ifix];
  }
+2 −1
Original line number Diff line number Diff line
@@ -51,6 +51,7 @@ class PairGranular : public Pair {
  double *maxrad_dynamic,*maxrad_frozen;
  double **cut;

  class FixDummy *fix_dummy;
  class FixNeighHistory *fix_history;

  // storage of rigid body masses for use in granular interactions
+12 −0
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@
#include "neigh_list_kokkos.h"
#include "pair_kokkos.h"
#include "comm.h"
#include "modify.h"

using namespace LAMMPS_NS;

@@ -69,6 +70,17 @@ void FixNeighHistoryKokkos<DeviceType>::init()
{
  if (atomKK->tag_enable == 0)
    error->all(FLERR,"Neighbor history requires atoms have IDs");

  // this fix must come before any fix which migrates atoms in its pre_exchange()
  // b/c this fix's pre_exchange() creates per-atom data structure
  // that data must be current for atom migration to carry it along

  for (int i = 0; i < modify->nfix; i++) {
    if (modify->fix[i] == this) break;
    if (modify->fix[i]->pre_exchange_migrate)
      error->all(FLERR,"Fix neigh_history comes after a fix which "
                 "migrates atoms in pre_exchange");
  }
}

/* ---------------------------------------------------------------------- */
Loading