Commit c69f3aea authored by athomps's avatar athomps
Browse files

Added tad example

git-svn-id: svn://svn.icms.temple.edu/lammps-ro/trunk@5475 f3b2605a-c512-4ea7-a41b-209d697bcdaa
parent 4e99c502
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -4,32 +4,44 @@ if (test $1 = 1) then

  cp compute_event_displace.cpp ..
  cp fix_event.cpp ..
  cp fix_event_prd.cpp ..
  cp fix_event_tad.cpp ..
  cp fix_neb.cpp ..
  cp neb.cpp ..
  cp prd.cpp ..
  cp tad.cpp ..
  cp temper.cpp ..

  cp compute_event_displace.h ..
  cp fix_event.h ..
  cp fix_event_prd.h ..
  cp fix_event_tad.h ..
  cp fix_neb.h ..
  cp neb.h ..
  cp prd.h ..
  cp tad.h ..
  cp temper.h ..

elif (test $1 = 0) then

  rm ../compute_event_displace.cpp
  rm ../fix_event.cpp
  rm ../fix_event_prd.cpp
  rm ../fix_event_tad.cpp
  rm ../fix_neb.cpp
  rm ../neb.cpp
  rm ../prd.cpp
  rm ../tad.cpp
  rm ../temper.cpp

  rm ../compute_event_displace.h
  rm ../fix_event.h
  rm ../fix_event_prd.h
  rm ../fix_event_tad.h
  rm ../fix_neb.h
  rm ../neb.h
  rm ../prd.h
  rm ../tad.h
  rm ../temper.h

fi
+6 −5
Original line number Diff line number Diff line
@@ -23,7 +23,7 @@
#include "atom.h"
#include "domain.h"
#include "modify.h"
#include "fix.h"
#include "fix_event.h"
#include "memory.h"
#include "error.h"
#include "update.h"
@@ -70,9 +70,10 @@ void ComputeEventDisplace::init()
  if (id_event != NULL) {
    int ifix = modify->find_fix(id_event);
    if (ifix < 0) error->all("Could not find compute event/displace fix ID");
    fix = modify->fix[ifix];
    fix_event = (FixEvent*) modify->fix[ifix];
    
    if (strcmp(fix->style,"EVENT") != 0)
    if (strcmp(fix_event->style,"EVENT/PRD") != 0 &&
	strcmp(fix_event->style,"EVENT/TAD") != 0)
      error->all("Compute event/displace has invalid fix event assigned");
  }

@@ -90,7 +91,7 @@ double ComputeEventDisplace::compute_scalar()
  if (id_event == NULL) return 0.0;

  double event = 0.0;
  double **xevent = fix->array_atom;
  double **xevent = fix_event->array_atom;

  double **x = atom->x;
  int *mask = atom->mask;
@@ -119,7 +120,6 @@ double ComputeEventDisplace::compute_scalar()
          break;
        }
      }

  } else {
    for (int i = 0; i < nlocal; i++)
      if (mask[i] & groupbit) {
@@ -138,6 +138,7 @@ double ComputeEventDisplace::compute_scalar()
  }

  MPI_Allreduce(&event,&scalar,1,MPI_DOUBLE,MPI_SUM,world);

  return scalar;
}

+1 −1
Original line number Diff line number Diff line
@@ -36,7 +36,7 @@ class ComputeEventDisplace : public Compute {
  int triclinic;
  double displace_distsq;
  char *id_event;
  class Fix *fix;
  class FixEvent *fix_event;
};

}
+68 −40
Original line number Diff line number Diff line
@@ -12,7 +12,7 @@
------------------------------------------------------------------------- */

/* ----------------------------------------------------------------------
   Contributing author: Mike Brown (SNL)
   Contributing author: Mike Brown (SNL), Aidan Thompson (SNL)
------------------------------------------------------------------------- */

#include "stdlib.h"
@@ -43,13 +43,10 @@ FixEvent::FixEvent(LAMMPS *lmp, int narg, char **arg) :

  xevent = NULL;
  xold = NULL;
  vold = NULL;
  imageold = NULL;
  grow_arrays(atom->nmax);
  atom->add_callback(0);

  event_number = 0;
  event_timestep = update->ntimestep;
  clock = 0;
}

/* ---------------------------------------------------------------------- */
@@ -64,6 +61,7 @@ FixEvent::~FixEvent()

  memory->destroy_2d_double_array(xevent);
  memory->destroy_2d_double_array(xold);
  memory->destroy_2d_double_array(vold);
  memory->sfree(imageold);
}

@@ -76,12 +74,10 @@ int FixEvent::setmask()

/* ----------------------------------------------------------------------
   save current atom coords as an event
   called when an event occurs in some replica
   set event_timestep = when event occurred in a particular replica
   update clock = elapsed time since last event, across all replicas
   called when an event occurs
------------------------------------------------------------------------- */

void FixEvent::store_event(int timestep, int delta_clock)
void FixEvent::store_event()
{
  double **x = atom->x;
  int *image = atom->image;
@@ -90,9 +86,41 @@ void FixEvent::store_event(int timestep, int delta_clock)
  for (int i = 0; i < nlocal; i++) 
    domain->unmap(x[i],image[i],xevent[i]);

  event_timestep = timestep;
  clock += delta_clock;
  event_number++;
//   printf("store_event %g %d %g %d \n",
// 	 x[8][1],image[8],xevent[8][1],0);

}

/* ----------------------------------------------------------------------
   restore atom coords to quenched initial state
   called prior to NEB calculation
------------------------------------------------------------------------- */

void FixEvent::restore_event()
{
  double **x = atom->x;
  int *image = atom->image;
  int nlocal = atom->nlocal;

//   printf("restore_event1 %g %d %g %d \n",
//   	 x[8][1],image[8],xevent[8][1],0);

  for (int i = 0; i < nlocal; i++) {
    x[i][0] = xevent[i][0];
    x[i][1] = xevent[i][1];
    x[i][2] = xevent[i][2];

    // Since xevent is unwrapped coordinate, need to
    // adjust image flags when remapping

    image[i] = (512 << 20) | (512 << 10) | 512;
    domain->remap(x[i],image[i]);
    //    domain->remap(x[i]);
  }

//   printf("restore_event2 %g %d %g %d \n",
//   	 x[8][1],image[8],xevent[8][1],0);

}

/* ----------------------------------------------------------------------
@@ -104,14 +132,20 @@ void FixEvent::store_event(int timestep, int delta_clock)
void FixEvent::store_state()
{
  double **x = atom->x;
  double **f = atom->f;
  double **v = atom->v;
  int *image = atom->image;
  int nlocal = atom->nlocal;

//   printf("store_state %g %d %g %d \n",
// 	 xold[8][1],imageold[8],x[8][1],image[8]);

  for (int i = 0; i < nlocal; i++) {
    xold[i][0] = x[i][0];
    xold[i][1] = x[i][1];
    xold[i][2] = x[i][2];
    vold[i][0] = v[i][0];
    vold[i][1] = v[i][1];
    vold[i][2] = v[i][2];
    imageold[i] = image[i];
  }
}
@@ -124,13 +158,20 @@ void FixEvent::store_state()
void FixEvent::restore_state()
{
  double **x = atom->x;
  double **v = atom->v;
  int *image = atom->image;
  int nlocal = atom->nlocal;

//   printf("restore_state %g %d %g %d \n",
// 	 xold[8][1],imageold[8],x[8][1],image[8]);

  for (int i = 0; i < nlocal; i++) {
    x[i][0] = xold[i][0];
    x[i][1] = xold[i][1];
    x[i][2] = xold[i][2];
    v[i][0] = vold[i][0];
    v[i][1] = vold[i][1];
    v[i][2] = vold[i][2];
    image[i] = imageold[i];
  }
}
@@ -154,6 +195,7 @@ void FixEvent::grow_arrays(int nmax)
{
  xevent = memory->grow_2d_double_array(xevent,nmax,3,"event:xevent");
  xold = memory->grow_2d_double_array(xold,nmax,3,"event:xold");
  vold = memory->grow_2d_double_array(vold,nmax,3,"event:vold");
  imageold = (int *) 
    memory->srealloc(imageold,nmax*sizeof(int),"event:imageold");

@@ -174,6 +216,9 @@ void FixEvent::copy_arrays(int i, int j)
  xold[j][0] = xold[i][0];
  xold[j][1] = xold[i][1];
  xold[j][2] = xold[i][2];
  vold[j][0] = vold[i][0];
  vold[j][1] = vold[i][1];
  vold[j][2] = vold[i][2];
  imageold[j] = imageold[i];
}

@@ -189,9 +234,12 @@ int FixEvent::pack_exchange(int i, double *buf)
  buf[3] = xold[i][0];
  buf[4] = xold[i][1];
  buf[5] = xold[i][2];
  buf[6] = imageold[i];
  buf[6] = vold[i][0];
  buf[7] = vold[i][1];
  buf[8] = vold[i][2];
  buf[9] = imageold[i];

  return 7;
  return 10;
}

/* ----------------------------------------------------------------------
@@ -206,9 +254,12 @@ int FixEvent::unpack_exchange(int nlocal, double *buf)
  xold[nlocal][0] = buf[3];
  xold[nlocal][1] = buf[4];
  xold[nlocal][2] = buf[5];
  imageold[nlocal] = static_cast<int>(buf[6]);
  vold[nlocal][0] = buf[6];
  vold[nlocal][1] = buf[7];
  vold[nlocal][2] = buf[8];
  imageold[nlocal] = static_cast<int>(buf[9]);

  return 7;
  return 10;
}

/* ----------------------------------------------------------------------
@@ -217,20 +268,6 @@ int FixEvent::unpack_exchange(int nlocal, double *buf)

void FixEvent::write_restart(FILE *fp)
{
  int n = 0;
  double list[5];
  list[n++] = event_number;
  list[n++] = event_timestep;
  list[n++] = clock;
  list[n++] = replica_number;
  list[n++] = correlated_event;
  list[n++] = ncoincident;

  if (comm->me == 0) {
    int size = n * sizeof(double);
    fwrite(&size,sizeof(int),1,fp);
    fwrite(list,sizeof(double),n,fp);
  }
}

/* ----------------------------------------------------------------------
@@ -239,13 +276,4 @@ void FixEvent::write_restart(FILE *fp)

void FixEvent::restart(char *buf)
{
  int n = 0;
  double *list = (double *) buf;

  event_number = static_cast<int> (list[n++]);
  event_timestep = static_cast<int> (list[n++]);
  clock = static_cast<int> (list[n++]);
  replica_number = static_cast<int> (list[n++]);
  correlated_event = static_cast<int> (list[n++]);
  ncoincident = static_cast<int> (list[n++]);
}
+7 −18
Original line number Diff line number Diff line
@@ -11,12 +11,6 @@
   See the README file in the top-level LAMMPS directory.
------------------------------------------------------------------------- */

#ifdef FIX_CLASS

FixStyle(EVENT,FixEvent)

#else

#ifndef LMP_FIX_EVENT_H
#define LMP_FIX_EVENT_H

@@ -26,15 +20,9 @@ namespace LAMMPS_NS {

class FixEvent : public Fix {
 public:
  int event_number;      // event counter
  int event_timestep;    // timestep of last event on any replica
  int clock;             // total elapsed timesteps across all replicas
  int replica_number;    // replica where last event occured
  int correlated_event;  // 1 if last event was correlated, 0 otherwise
  int ncoincident;       // # of simultaneous events on different replicas

  FixEvent(class LAMMPS *, int, char **);
  ~FixEvent();
  virtual ~FixEvent()=0;    // Use destructor to make base class virtual
  int setmask();

  double memory_usage();
@@ -42,22 +30,23 @@ class FixEvent : public Fix {
  void copy_arrays(int, int);
  int pack_exchange(int, double *);
  int unpack_exchange(int, double *);
  void write_restart(FILE *);
  void restart(char *);
  virtual void write_restart(FILE *);
  virtual void restart(char *);

  // methods specific to FixEvent, invoked by PRD
  // methods specific to FixEvent

  void store_event(int, int);
  virtual void store_event(); // base class stores quenched atoms
  void restore_event();       // restore quenched atoms
  void store_state();
  void restore_state();

 private:
  double **xevent;       // atom coords at last event
  double **xold;         // atom coords for reset/restore
  double **vold;         // atom vels for reset/restore
  int *imageold;         // image flags for reset/restore
};

}

#endif
#endif
Loading