Commit 2e8b9cf4 authored by sjplimp's avatar sjplimp
Browse files

git-svn-id: svn://svn.icms.temple.edu/lammps-ro/trunk@1656 f3b2605a-c512-4ea7-a41b-209d697bcdaa
parent a49e234a
Loading
Loading
Loading
Loading
+44 −44
Original line number Diff line number Diff line
@@ -37,7 +37,8 @@ using namespace LAMMPS_NS;
ComputeTempAsphere::ComputeTempAsphere(LAMMPS *lmp, int narg, char **arg) :
  Compute(lmp, narg, arg)
{
  if (narg != 3) error->all("Illegal compute temp command");
  if (narg != 3 || narg != 4)
    error->all("Illegal compute temp/asphere command");

  if (!atom->quat_flag || !atom->angmom_flag)
    error->all("Compute temp/asphere requires atom attributes quat, angmom");
@@ -48,6 +49,15 @@ ComputeTempAsphere::ComputeTempAsphere(LAMMPS *lmp, int narg, char **arg) :
  extvector = 1;
  tempflag = 1;

  tempbias = 0;
  id_bias = NULL;
  if (narg == 4) {
    tempbias = 1;
    int n = strlen(arg[3]) + 1;
    id_bias = new char[n];
    strcpy(id_bias,arg[3]);
  }

  vector = new double[6];
  inertia = 
    memory->create_2d_double_array(atom->ntypes+1,3,"fix_temp_sphere:inertia");
@@ -57,6 +67,7 @@ ComputeTempAsphere::ComputeTempAsphere(LAMMPS *lmp, int narg, char **arg) :

ComputeTempAsphere::~ComputeTempAsphere()
{
  delete [] id_bias;
  delete [] vector;
  memory->destroy_2d_double_array(inertia);
}
@@ -65,20 +76,25 @@ ComputeTempAsphere::~ComputeTempAsphere()

void ComputeTempAsphere::init()
{
  fix_dof = 0;
  for (int i = 0; i < modify->nfix; i++)
    fix_dof += modify->fix[i]->dof(igroup);
  dof_compute();

  tempbias = 0;
  tbias = NULL;
  if (id_bias) {
    tempbias = 1;
  if (tempbias) {
    int i = modify->find_compute(id_bias);
    if (i < 0) error->all("Could not find compute ID for temperature bias");
    tbias = modify->compute[i];
    if (tbias->tempflag == 0)
      error->all("Bias compute does not calculate temperature");
    if (tbias->tempbias == 0)
      error->all("Bias compute does not calculate a velocity bias");
    if (tbias->igroup != igroup)
      error->all("Bias compute group does not match compute group");
    tbias->init();
    if (strcmp(tbias->style,"temp/region") == 0) tempbias = 2;
  }

  fix_dof = 0;
  for (int i = 0; i < modify->nfix; i++)
    fix_dof += modify->fix[i]->dof(igroup);
  dof_compute();

  calculate_inertia();
}

@@ -89,10 +105,10 @@ void ComputeTempAsphere::dof_compute()
  double natoms = group->count(igroup);
  int dimension = domain->dimension;
  dof = dimension * natoms;
  if (tbias) dof -= tbias->dof_remove(natoms);
  dof -= extra_dof + fix_dof;

  // add rotational degrees of freedom
  if (tempbias == 1) dof -= tbias->dof_remove(-1) * natoms;

  // rotational degrees of freedom
  // 0 for sphere, 2 for uniaxial, 3 for biaxial

  double **shape = atom->shape;
@@ -101,27 +117,30 @@ void ComputeTempAsphere::dof_compute()
  int nlocal = atom->nlocal;

  int itype;
  int rot_dof = 0;
  int count = 0;

  for (int i = 0; i < nlocal; i++)
    if (mask[i] & groupbit) {
      if (tempbias == 2 && tbias->dof_remove(i)) continue;
      itype = type[i];
      if (dimension == 2) {
	if (shape[itype][0] == shape[itype][1]) continue;
	else rot_dof += 1;
	else count++;
      } else {
	if (shape[itype][0] == shape[itype][1] && 
	    shape[itype][1] == shape[itype][2]) continue;
	else if (shape[itype][0] == shape[itype][1] || 
		 shape[itype][1] == shape[itype][2] ||
		 shape[itype][0] == shape[itype][2]) rot_dof += 2;
	else rot_dof += 3;
		 shape[itype][0] == shape[itype][2]) count += 2;
	else count += 3;
      }
    }

  int rot_total;
  MPI_Allreduce(&rot_dof,&rot_total,1,MPI_INT,MPI_SUM,world);
  dof += rot_total;
  int count_all;
  MPI_Allreduce(&count,&count_all,1,MPI_INT,MPI_SUM,world);
  dof += count_all;
    
  dof -= extra_dof + fix_dof;
  if (dof > 0) tfactor = force->mvv2e / (dof * force->boltz);
  else tfactor = 0.0;
}
@@ -132,7 +151,7 @@ double ComputeTempAsphere::compute_scalar()
{
  invoked |= INVOKED_SCALAR;

  if (tbias) {
  if (tempbias) {
    if (!(tbias->invoked & INVOKED_SCALAR))
      double tmp = tbias->compute_scalar();
    tbias->remove_bias_all();
@@ -179,10 +198,10 @@ double ComputeTempAsphere::compute_scalar()
      }
    }

  if (tbias) tbias->restore_bias_all();
  if (tempbias) tbias->restore_bias_all();

  MPI_Allreduce(&t,&scalar,1,MPI_DOUBLE,MPI_SUM,world);
  if (dynamic || tbias) dof_compute();
  if (dynamic || tempbias == 2) dof_compute();
  scalar *= tfactor;
  return scalar;
}
@@ -195,7 +214,7 @@ void ComputeTempAsphere::compute_vector()

  invoked |= INVOKED_VECTOR;

  if (tbias) {
  if (tempbias) {
    if (!(tbias->invoked & INVOKED_VECTOR)) tbias->compute_vector();
    tbias->remove_bias_all();
  }
@@ -246,7 +265,7 @@ void ComputeTempAsphere::compute_vector()
      t[5] += inertia[itype][2]*wbody[1]*wbody[2];
    }

  if (tbias) tbias->restore_bias_all();
  if (tempbias) tbias->restore_bias_all();

  MPI_Allreduce(t,vector,6,MPI_DOUBLE,MPI_SUM,world);
  for (i = 0; i < 6; i++) vector[i] *= force->mvv2e;
@@ -280,15 +299,6 @@ void ComputeTempAsphere::remove_bias(int i, double *v)
  if (tbias) tbias->remove_bias(i,v);
}

/* ----------------------------------------------------------------------
   remove velocity bias from all atoms to leave thermal velocity
------------------------------------------------------------------------- */

void ComputeTempAsphere::remove_bias_all()
{
  if (tbias) tbias->remove_bias_all();
}

/* ----------------------------------------------------------------------
   add back in velocity bias to atom I removed by remove_bias()
   assume remove_bias() was previously called
@@ -298,13 +308,3 @@ void ComputeTempAsphere::restore_bias(int i, double *v)
{
  if (tbias) tbias->restore_bias(i,v);
}

/* ----------------------------------------------------------------------
   add back in velocity bias to all atoms removed by remove_bias_all()
   assume remove_bias_all() was previously called
------------------------------------------------------------------------- */

void ComputeTempAsphere::restore_bias_all()
{
  if (tbias) tbias->restore_bias_all();
}
+1 −3
Original line number Diff line number Diff line
@@ -27,15 +27,13 @@ class ComputeTempAsphere : public Compute {
  void compute_vector();

  void remove_bias(int, double *);
  void remove_bias_all();
  void restore_bias(int, double *);
  void restore_bias_all();

 private:
  int fix_dof;
  double tfactor;
  double **inertia;

  char *id_bias;
  Compute *tbias;     // ptr to additional bias compute

  void dof_compute();
+0 −18
Original line number Diff line number Diff line
@@ -62,9 +62,7 @@ Compute::Compute(LAMMPS *lmp, int narg, char **arg) : Pointers(lmp)
  scalar_flag = vector_flag = peratom_flag = 0;
  tempflag = pressflag = peflag = 0;
  pressatomflag = peatomflag = 0;

  tempbias = 0;
  id_bias = NULL;

  id_pre = NULL;
  timeflag = 0;
@@ -90,7 +88,6 @@ Compute::~Compute()
{
  delete [] id;
  delete [] style;
  delete [] id_bias;
  delete [] id_pre;

  memory->sfree(tlist);
@@ -120,21 +117,6 @@ void Compute::modify_params(int narg, char **arg)
      else if (strcmp(arg[iarg+1],"yes") == 0) thermoflag = 1;
      else error->all("Illegal compute_modify command");
      iarg += 2;
    } else if (strcmp(arg[iarg],"bias") == 0) {
      if (iarg+2 > narg) error->all("Illegal compute_modify command");
      delete [] id_bias;
      if (strcmp(arg[iarg+1],"NULL") == 0) id_bias = NULL;
      else {
	int n = strlen(arg[iarg+1]) + 1;
	id_bias = new char[n];
	strcpy(id_bias,arg[iarg+1]);
	int icompute = modify->find_compute(id_bias);
	if (icompute < 0) error->all("Could not find compute_modify bias ID");
	Compute *temperature = modify->compute[icompute];
	if (temperature->igroup != igroup && comm->me == 0)
	  error->warning("Group for compute_modify bias != compute group");
      }
      iarg += 2;
    } else error->all("Illegal compute_modify command");
  }
}
+2 −4
Original line number Diff line number Diff line
@@ -45,9 +45,7 @@ class Compute : protected Pointers {
  int peflag;         // 1 if Compute calculates PE (uses Force energies)
  int peatomflag;     // 1 if Compute calculates per-atom PE

  int tempbias;       // 0/1 if Compute temp includes
                      // self or extra bias via compute_modify
  char *id_bias;      // ID of extra Compute temp that adds bias
  int tempbias;       // 0/1 if Compute temp includes self/extra bias

  char *id_pre;       // ID of pre-compute the Compute may store

@@ -77,7 +75,7 @@ class Compute : protected Pointers {
  virtual int pack_reverse_comm(int, int, double *) {return 0;}
  virtual void unpack_reverse_comm(int, int *, double *) {}

  virtual double dof_remove(double &) {return 0.0;}
  virtual int dof_remove(int) {return 0;}
  virtual void remove_bias(int, double *) {}
  virtual void remove_bias_all() {}
  virtual void restore_bias(int, double *) {}
+2 −64
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@ ComputeTemp::ComputeTemp(LAMMPS *lmp, int narg, char **arg) :
  extscalar = 0;
  extvector = 1;
  tempflag = 1;
  tempbias = 0;

  vector = new double[6];
}
@@ -57,15 +58,6 @@ void ComputeTemp::init()
  for (int i = 0; i < modify->nfix; i++)
    fix_dof += modify->fix[i]->dof(igroup);
  dof_compute();

  tempbias = 0;
  tbias = NULL;
  if (id_bias) {
    tempbias = 1;
    int i = modify->find_compute(id_bias);
    if (i < 0) error->all("Could not find compute ID for temperature bias");
    tbias = modify->compute[i];
  }
}

/* ---------------------------------------------------------------------- */
@@ -74,7 +66,6 @@ void ComputeTemp::dof_compute()
{
  double natoms = group->count(igroup);
  dof = domain->dimension * natoms;
  if (tbias) dof -= tbias->dof_remove(natoms);
  dof -= extra_dof + fix_dof;
  if (dof > 0.0) tfactor = force->mvv2e / (dof * force->boltz);
  else tfactor = 0.0;
@@ -86,12 +77,6 @@ double ComputeTemp::compute_scalar()
{
  invoked |= INVOKED_SCALAR;

  if (tbias) {
    if (!(tbias->invoked & INVOKED_SCALAR))
      double tmp = tbias->compute_scalar();
    tbias->remove_bias_all();
  }

  double **v = atom->v;
  double *mass = atom->mass;
  double *rmass = atom->rmass;
@@ -112,10 +97,8 @@ double ComputeTemp::compute_scalar()
	t += (v[i][0]*v[i][0] + v[i][1]*v[i][1] + v[i][2]*v[i][2]) * rmass[i];
  }

  if (tbias) tbias->restore_bias_all();

  MPI_Allreduce(&t,&scalar,1,MPI_DOUBLE,MPI_SUM,world);
  if (dynamic || tbias) dof_compute();
  if (dynamic) dof_compute();
  scalar *= tfactor;
  return scalar;
}
@@ -128,11 +111,6 @@ void ComputeTemp::compute_vector()

  invoked |= INVOKED_VECTOR;

  if (tbias) {
    if (!(tbias->invoked & INVOKED_VECTOR)) tbias->compute_vector();
    tbias->remove_bias_all();
  }

  double **v = atom->v;
  double *mass = atom->mass;
  double *rmass = atom->rmass;
@@ -155,46 +133,6 @@ void ComputeTemp::compute_vector()
      t[5] += massone * v[i][1]*v[i][2];
    }

  if (tbias) tbias->restore_bias_all();

  MPI_Allreduce(t,vector,6,MPI_DOUBLE,MPI_SUM,world);
  for (i = 0; i < 6; i++) vector[i] *= force->mvv2e;
}

/* ----------------------------------------------------------------------
   remove velocity bias from atom I to leave thermal velocity
------------------------------------------------------------------------- */

void ComputeTemp::remove_bias(int i, double *v)
{
  if (tbias) tbias->remove_bias(i,v);
}

/* ----------------------------------------------------------------------
   remove velocity bias from all atoms to leave thermal velocity
------------------------------------------------------------------------- */

void ComputeTemp::remove_bias_all()
{
  if (tbias) tbias->remove_bias_all();
}

/* ----------------------------------------------------------------------
   add back in velocity bias to atom I removed by remove_bias()
   assume remove_bias() was previously called
------------------------------------------------------------------------- */

void ComputeTemp::restore_bias(int i, double *v)
{
  if (tbias) tbias->restore_bias(i,v);
}

/* ----------------------------------------------------------------------
   add back in velocity bias to all atoms removed by remove_bias_all()
   assume remove_bias_all() was previously called
------------------------------------------------------------------------- */

void ComputeTemp::restore_bias_all()
{
  if (tbias) tbias->restore_bias_all();
}
Loading