Commit fcbd40eb authored by sjplimp's avatar sjplimp
Browse files

git-svn-id: svn://svn.icms.temple.edu/lammps-ro/trunk@5176 f3b2605a-c512-4ea7-a41b-209d697bcdaa
parent 3ab35d60
Loading
Loading
Loading
Loading
+4 −0
Original line number Original line Diff line number Diff line
@@ -3,13 +3,17 @@
if (test $1 == 1) then
if (test $1 == 1) then


  cp fix_srd.cpp ..
  cp fix_srd.cpp ..
  cp fix_wall_srd.cpp ..


  cp fix_srd.h ..
  cp fix_srd.h ..
  cp fix_wall_srd.h ..


elif (test $1 == 0) then
elif (test $1 == 0) then


  rm ../fix_srd.cpp
  rm ../fix_srd.cpp
  rm ../fix_wall_srd.cpp


  rm ../fix_srd.h
  rm ../fix_srd.h
  rm ../fix_wall_srd.h


fi
fi
+704 −262

File changed.

Preview size limit exceeded, changes collapsed.

+31 −10
Original line number Original line Diff line number Diff line
@@ -54,7 +54,14 @@ class FixSRD : public Fix {
  double srd_per_cell;
  double srd_per_cell;
  double dmax,vmax,vmaxsq;
  double dmax,vmax,vmaxsq;
  double maxbigdiam,minbigdiam;
  double maxbigdiam,minbigdiam;
  double dist_bigghost;
  double dist_ghost,dist_srd,dist_srd_reneigh;   // explained in code

  int wallexist,nwall,wallvarflag;
  class FixWallSRD *wallfix;
  int *wallwhich;
  double *xwall,*xwallhold,*vwall;
  double **fwall;
  double walltrigger;


  // for orthogonal box, these are in box units
  // for orthogonal box, these are in box units
  // for triclinic box, these are in lamda units
  // for triclinic box, these are in lamda units
@@ -79,11 +86,11 @@ class FixSRD : public Fix {
  double **flocal;       // local ptrs to atom force and torque
  double **flocal;       // local ptrs to atom force and torque
  double **tlocal;
  double **tlocal;


  // info to store for each owned and ghost big particle
  // info to store for each owned and ghost big particle and wall


  struct Big {
  struct Big {
    int index;                 // local index or particle in atom arrays
    int index;                 // local index of particle/wall
    int type;                  // SPHERE or ELLIPSOID
    int type;                  // SPHERE or ELLIPSOID or WALL
    int typesphere;            // SPHERE_SHAPE or SPHERE_RADIUS
    int typesphere;            // SPHERE_SHAPE or SPHERE_RADIUS
    int typeangular;           // ANGULAR_OMEGA or ANGULAR_ANGMOM
    int typeangular;           // ANGULAR_OMEGA or ANGULAR_ANGMOM
    double radius,radsq;       // radius of sphere
    double radius,radsq;       // radius of sphere
@@ -95,15 +102,15 @@ class FixSRD : public Fix {
    double ex[3],ey[3],ez[3];  // current orientation vecs for ellipsoid
    double ex[3],ey[3],ez[3];  // current orientation vecs for ellipsoid
  };
  };


  Big *biglist;           // list of info for each owned & ghost big particle
  Big *biglist;           // list of info for each owned & ghost big and wall
  int any_ellipsoids;     // 1 if any big particles are ellipsoids
  int any_ellipsoids;     // 1 if any big particles are ellipsoids
  int torqueflag;         // 1 if any big particle is torqued
  int torqueflag;         // 1 if any big particle is torqued


  // current size of particle-based arrays
  // current size of particle-based arrays


  int nbig;               // # of big particles, owned + ghost
  int nbig;               // # of owned/ghost big particles and walls
  int nmax;
  int maxbig;             // max number of owned/ghost big particles and walls
  int maxbig;             // max number of big particles, owned + ghost
  int nmax;               // max number of SRD particles


  // bins for SRD velocity remap, shifting and communication
  // bins for SRD velocity remap, shifting and communication
  // binsize and inv are in lamda units for triclinic
  // binsize and inv are in lamda units for triclinic
@@ -170,6 +177,8 @@ class FixSRD : public Fix {


  int inside_sphere(double *, double *, Big *);
  int inside_sphere(double *, double *, Big *);
  int inside_ellipsoid(double *, double *, Big *);
  int inside_ellipsoid(double *, double *, Big *);
  int inside_wall(double *, int);

  double collision_sphere_exact(double *, double *, double *, double *,
  double collision_sphere_exact(double *, double *, double *, double *,
				Big *, double *, double *, double *);
				Big *, double *, double *, double *);
  void collision_sphere_inexact(double *, double *,
  void collision_sphere_inexact(double *, double *,
@@ -178,22 +187,34 @@ class FixSRD : public Fix {
				   Big *, double *, double *, double *);
				   Big *, double *, double *, double *);
  void collision_ellipsoid_inexact(double *, double *,
  void collision_ellipsoid_inexact(double *, double *,
				   Big *, double *, double *, double *);
				   Big *, double *, double *, double *);
  double collision_wall_exact(double *, int, double *,
			      double *, double *, double *);
  void collision_wall_inexact(double *, int, double *, double *, double *);

  void slip_sphere(double *, double *, double *, double *);
  void slip_sphere(double *, double *, double *, double *);
  void slip_ellipsoid(double *, double *, double *, Big *,
  void slip_ellipsoid(double *, double *, double *, Big *,
		      double *, double *,  double *);
		      double *, double *,  double *);
  void slip_wall(double *, int, double *, double *);

  void noslip(double *, double *, double *, Big *,
  void noslip(double *, double *, double *, Big *,
	      double *, double *,  double *);
	      double *, double *,  double *);
  void noslip_wall(double *, int, double *, double *, double *);

  void force_torque(double *, double *, double *,
  void force_torque(double *, double *, double *,
		    double *, double *,  double *);
		    double *, double *,  double *);
  void force_wall(double *, double *, int);

  int update_srd(int, double, double *, double *, double *, double *);
  int update_srd(int, double, double *, double *, double *, double *);


  void parameterize();
  void parameterize();
  void setup_bounds();
  void setup_velocity_bins();
  void setup_velocity_bins();
  void setup_velocity_shift(int, int);
  void setup_velocity_shift(int, int);
  void setup_search_bins();
  void setup_search_bins();
  void setup_search_stencil();
  void setup_search_stencil();
  void big_static();
  void big_static();
  void big_dynamic();
  void big_dynamic();

  double point_bin_distance(double *, int, int, int);
  double point_bin_distance(double *, int, int, int);
  double bin_bin_distance(int, int, int);
  double bin_bin_distance(int, int, int);
  void exyz_from_q(double *, double *, double *, double *);
  void exyz_from_q(double *, double *, double *, double *);
@@ -203,7 +224,7 @@ class FixSRD : public Fix {


  double distance(int, int);
  double distance(int, int);
  void print_collision(int, int, int, double, double,
  void print_collision(int, int, int, double, double,
		       double *, double *, double *);
		       double *, double *, double *, int);
};
};


}
}
+252 −0
Original line number Original line 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

   Copyright (2003) Sandia Corporation.  Under the terms of Contract
   DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
   certain rights in this software.  This software is distributed under 
   the GNU General Public License.

   See the README file in the top-level LAMMPS directory.
------------------------------------------------------------------------- */

#include "stdlib.h"
#include "string.h"
#include "fix_wall_srd.h"
#include "atom.h"
#include "modify.h"
#include "fix.h"
#include "domain.h"
#include "lattice.h"
#include "input.h"
#include "modify.h"
#include "update.h"
#include "variable.h"
#include "memory.h"
#include "error.h"

using namespace LAMMPS_NS;

enum{XLO,XHI,YLO,YHI,ZLO,ZHI};
enum{NONE,EDGE,CONSTANT,VARIABLE};

/* ---------------------------------------------------------------------- */

FixWallSRD::FixWallSRD(LAMMPS *lmp, int narg, char **arg) :
  Fix(lmp, narg, arg)
{
  if (narg < 4) error->all("Illegal fix wall/srd command");

  // parse args

  nwall = 0;
  int scaleflag = 1;

  int iarg = 3;
  while (iarg < narg) {
    if ((strcmp(arg[iarg],"xlo") == 0) || (strcmp(arg[iarg],"xhi") == 0) ||
	(strcmp(arg[iarg],"ylo") == 0) || (strcmp(arg[iarg],"yhi") == 0) ||
	(strcmp(arg[iarg],"zlo") == 0) || (strcmp(arg[iarg],"zhi") == 0)) {
      if (iarg+2 > narg) error->all("Illegal fix wall/srd command");

      int newwall;
      if (strcmp(arg[iarg],"xlo") == 0) newwall = XLO;
      else if (strcmp(arg[iarg],"xhi") == 0) newwall = XHI;
      else if (strcmp(arg[iarg],"ylo") == 0) newwall = YLO;
      else if (strcmp(arg[iarg],"yhi") == 0) newwall = YHI;
      else if (strcmp(arg[iarg],"zlo") == 0) newwall = ZLO;
      else if (strcmp(arg[iarg],"zhi") == 0) newwall = ZHI;

      for (int m = 0; m < nwall; m++)
	if (newwall == wallwhich[m])
	  error->all("Wall defined twice in fix wall/srd command");

      wallwhich[nwall] = newwall;
      if (strcmp(arg[iarg+1],"EDGE") == 0) {
	wallstyle[nwall] = EDGE;
	int dim = wallwhich[nwall] / 2;
	int side = wallwhich[nwall] % 2;
	if (side == 0) coord0[nwall] = domain->boxlo[dim];
	else coord0[nwall] = domain->boxhi[dim];
      } else if (strstr(arg[iarg+1],"v_") == arg[iarg+1]) {
	wallstyle[nwall] = VARIABLE;
	int n = strlen(&arg[iarg+1][2]) + 1;
	varstr[nwall] = new char[n];
	strcpy(varstr[nwall],&arg[iarg+1][2]);
      } else {
	wallstyle[nwall] = CONSTANT;
	coord0[nwall] = atof(arg[iarg+1]);
      }

      nwall++;
      iarg += 2;

    } else if (strcmp(arg[iarg],"units") == 0) {
      if (iarg+2 > narg) error->all("Illegal wall/srd command");
      if (strcmp(arg[iarg+1],"box") == 0) scaleflag = 0;
      else if (strcmp(arg[iarg+1],"lattice") == 0) scaleflag = 1;
      else error->all("Illegal fix wall/srd command");
      iarg += 2;
    } else error->all("Illegal fix wall/srd command");
  }

  // error check

  if (nwall == 0) error->all("Illegal fix wall command");

  for (int m = 0; m < nwall; m++) {
    if ((wallwhich[m] == XLO || wallwhich[m] == XHI) && domain->xperiodic)
      error->all("Cannot use fix wall/srd in periodic dimension");
    if ((wallwhich[m] == YLO || wallwhich[m] == YHI) && domain->yperiodic)
      error->all("Cannot use fix wall/srd in periodic dimension");
    if ((wallwhich[m] == ZLO || wallwhich[m] == ZHI) && domain->zperiodic)
      error->all("Cannot use fix wall/srd in periodic dimension");
  }

  for (int m = 0; m < nwall; m++)
    if ((wallwhich[m] == ZLO || wallwhich[m] == ZHI) && domain->dimension == 2)
      error->all("Cannot use fix wall/srd zlo/zhi for a 2d simulation");

  // setup wall force array

  array_flag = 1;
  size_array_rows = nwall;
  size_array_cols = 3;
  global_freq = 1;
  extarray = 1;

  fwall = memory->create_2d_double_array(nwall,3,"wall/srd:fwall");
  fwall_all = memory->create_2d_double_array(nwall,3,"wall/srd:fwall_all");

  // scale coord for CONSTANT walls

  int flag = 0;
  for (int m = 0; m < nwall; m++)
    if (wallstyle[m] == CONSTANT) flag = 1;

  if (flag) {
    if (scaleflag && domain->lattice == NULL)
      error->all("Use of fix wall with undefined lattice");

    double xscale,yscale,zscale;
    if (scaleflag) {
      xscale = domain->lattice->xlattice;
      yscale = domain->lattice->ylattice;
      zscale = domain->lattice->zlattice;
    }
    else xscale = yscale = zscale = 1.0;

    double scale;
    for (int m = 0; m < nwall; m++) {
      if (wallwhich[m] < YLO) scale = xscale;
      else if (wallwhich[m] < ZLO) scale = yscale;
      else scale = zscale;
      if (wallstyle[m] == CONSTANT) coord0[m] *= scale;
    }
  }

  // set time_depend and varflag if any wall positions are variable

  varflag = 0;
  for (int m = 0; m < nwall; m++)
    if (wallstyle[m] == VARIABLE) time_depend = varflag = 1;
  laststep = -1;
}

/* ---------------------------------------------------------------------- */

FixWallSRD::~FixWallSRD()
{
  for (int m = 0; m < nwall; m++)
    if (wallstyle[m] == VARIABLE) delete [] varstr[m];
  memory->destroy_2d_double_array(fwall);
  memory->destroy_2d_double_array(fwall_all);
}

/* ---------------------------------------------------------------------- */

int FixWallSRD::setmask()
{
  int mask = 0;
  return mask;
}

/* ---------------------------------------------------------------------- */

void FixWallSRD::init()
{
  int flag = 0;
  for (int m = 0; m < modify->nfix; m++)
    if (strcmp(modify->fix[m]->style,"srd2") == 0) flag = 1;
  if (!flag) error->all("Cannot use fix wall/srd without fix srd");

  for (int m = 0; m < nwall; m++) {
    if (wallstyle[m] != VARIABLE) continue;
    varindex[m] = input->variable->find(varstr[m]);
    if (varindex[m] < 0)
      error->all("Variable name for fix wall/srd does not exist");
    if (!input->variable->equalstyle(varindex[m]))
      error->all("Variable for fix wall/srd is invalid style");
  }

  dt = update->dt;
}

/* ----------------------------------------------------------------------
   return force component on a wall
------------------------------------------------------------------------- */

double FixWallSRD::compute_array(int i, int j)
{
  // only sum across procs one time

  if (force_flag == 0) {
    MPI_Allreduce(&fwall[0][0],&fwall_all[0][0],3*nwall,
		  MPI_DOUBLE,MPI_SUM,world);
    force_flag = 1;
  }
  return fwall_all[i][j];
}

/* ----------------------------------------------------------------------
   set wall position and velocity, zero forces on walls
   evaluate variable if necessary, wrap with clear/add
   if flag, then being called on reneighbor, so archive wall positions
------------------------------------------------------------------------- */

void FixWallSRD::wall_params(int flag)
{
  double xnew;

  if (varflag) modify->clearstep_compute();

  int ntimestep = update->ntimestep;

  for (int m = 0; m < nwall; m++) {
    if (wallstyle[m] == VARIABLE)
      xnew = input->variable->compute_equal(varindex[m]);
    else xnew = coord0[m];

    if (laststep < 0) {
      xwall[m] = xwalllast[m] = xnew;
      vwall[m] = 0.0;
    } else if (laststep < ntimestep) {
      xwalllast[m] = xwall[m];
      xwall[m] = xnew;
      vwall[m] = (xwall[m] - xwalllast[m]) / dt;
    } 

    fwall[m][0] = fwall[m][1] = fwall[m][2] = 0.0;
  }

  laststep = ntimestep;

  if (varflag) modify->addstep_compute(update->ntimestep + 1);

  if (flag)
    for (int m = 0; m < nwall; m++)
      xwallhold[m] = xwall[m];

  force_flag = 0;
}

src/SRD/fix_wall_srd.h

0 → 100644
+59 −0
Original line number Original line 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

   Copyright (2003) Sandia Corporation.  Under the terms of Contract
   DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
   certain rights in this software.  This software is distributed under 
   the GNU General Public License.

   See the README file in the top-level LAMMPS directory.
------------------------------------------------------------------------- */

#ifdef FIX_CLASS

FixStyle(wall/srd,FixWallSRD)

#else

#ifndef LMP_FIX_WALL_SRD_H
#define LMP_FIX_WALL_SRD_H

#include "fix.h"

namespace LAMMPS_NS {

class FixWallSRD : public Fix {
 public:
  int nwall,varflag;
  int wallwhich[6];
  double xwall[6],xwallhold[6],vwall[6];
  double **fwall;

  FixWallSRD(class LAMMPS *, int, char **);
  ~FixWallSRD();
  int setmask();
  void init();
  double compute_array(int, int);

  void wall_params(int);

 private:
  int wallstyle[6];
  double coord0[6];
  char *varstr[6];
  int varindex[6];

  double dt;
  double xwalllast[6];
  int laststep;
  
  double **fwall_all;
  int force_flag;
};

}

#endif
#endif
Baidu
map