2007-01-30 08:31:11 +08:00
|
|
|
/* ----------------------------------------------------------------------
|
|
|
|
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
|
2012-06-07 06:47:51 +08:00
|
|
|
certain rights in this software. This software is distributed under
|
2007-01-30 08:31:11 +08:00
|
|
|
the GNU General Public License.
|
|
|
|
|
2010-01-13 00:32:06 +08:00
|
|
|
See the README file in the top-level LAMMPS directory.
|
2007-01-30 08:31:11 +08:00
|
|
|
------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
#include "mpi.h"
|
|
|
|
#include "stdlib.h"
|
|
|
|
#include "string.h"
|
2008-01-03 03:24:46 +08:00
|
|
|
#include "ctype.h"
|
2007-01-30 08:31:11 +08:00
|
|
|
#include "compute.h"
|
2009-12-22 01:24:04 +08:00
|
|
|
#include "atom.h"
|
2008-03-21 01:35:20 +08:00
|
|
|
#include "domain.h"
|
2009-12-22 01:24:04 +08:00
|
|
|
#include "comm.h"
|
2007-01-30 08:31:11 +08:00
|
|
|
#include "group.h"
|
2014-05-07 22:30:27 +08:00
|
|
|
#include "modify.h"
|
|
|
|
#include "fix.h"
|
2012-08-28 22:21:55 +08:00
|
|
|
#include "atom_masks.h"
|
2007-11-03 04:25:11 +08:00
|
|
|
#include "memory.h"
|
2007-01-30 08:31:11 +08:00
|
|
|
#include "error.h"
|
2013-06-29 03:00:58 +08:00
|
|
|
#include "force.h"
|
2007-01-30 08:31:11 +08:00
|
|
|
|
|
|
|
using namespace LAMMPS_NS;
|
|
|
|
|
2007-11-03 04:25:11 +08:00
|
|
|
#define DELTA 4
|
2014-01-23 01:44:32 +08:00
|
|
|
#define BIG MAXTAGINT
|
2009-12-22 01:24:04 +08:00
|
|
|
|
2015-01-20 07:38:26 +08:00
|
|
|
// allocate space for static class instance variable and initialize it
|
|
|
|
|
|
|
|
int Compute::instance_total = 0;
|
|
|
|
|
2007-01-30 08:31:11 +08:00
|
|
|
/* ---------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
Compute::Compute(LAMMPS *lmp, int narg, char **arg) : Pointers(lmp)
|
|
|
|
{
|
2015-01-20 07:38:26 +08:00
|
|
|
instance_me = instance_total++;
|
|
|
|
|
2011-09-24 02:06:55 +08:00
|
|
|
if (narg < 3) error->all(FLERR,"Illegal compute command");
|
2007-01-30 08:31:11 +08:00
|
|
|
|
|
|
|
// compute ID, group, and style
|
2008-01-03 03:24:46 +08:00
|
|
|
// ID must be all alphanumeric chars or underscores
|
2007-01-30 08:31:11 +08:00
|
|
|
|
|
|
|
int n = strlen(arg[0]) + 1;
|
|
|
|
id = new char[n];
|
|
|
|
strcpy(id,arg[0]);
|
|
|
|
|
2008-01-03 03:24:46 +08:00
|
|
|
for (int i = 0; i < n-1; i++)
|
|
|
|
if (!isalnum(id[i]) && id[i] != '_')
|
2011-12-17 05:15:49 +08:00
|
|
|
error->all(FLERR,
|
2012-06-07 06:47:51 +08:00
|
|
|
"Compute ID must be alphanumeric or underscore characters");
|
2008-01-03 03:24:46 +08:00
|
|
|
|
2007-01-30 08:31:11 +08:00
|
|
|
igroup = group->find(arg[1]);
|
2011-09-24 02:06:55 +08:00
|
|
|
if (igroup == -1) error->all(FLERR,"Could not find compute group ID");
|
2007-01-30 08:31:11 +08:00
|
|
|
groupbit = group->bitmask[igroup];
|
|
|
|
|
|
|
|
n = strlen(arg[2]) + 1;
|
|
|
|
style = new char[n];
|
|
|
|
strcpy(style,arg[2]);
|
|
|
|
|
|
|
|
// set child class defaults
|
|
|
|
|
2009-12-05 05:03:54 +08:00
|
|
|
scalar_flag = vector_flag = array_flag = 0;
|
|
|
|
peratom_flag = local_flag = 0;
|
|
|
|
|
2007-11-03 04:25:11 +08:00
|
|
|
tempflag = pressflag = peflag = 0;
|
2007-12-01 05:54:30 +08:00
|
|
|
pressatomflag = peatomflag = 0;
|
2015-01-28 23:55:56 +08:00
|
|
|
create_attribute = 0;
|
2008-03-12 01:15:30 +08:00
|
|
|
tempbias = 0;
|
2008-03-20 22:53:21 +08:00
|
|
|
|
2007-11-03 04:25:11 +08:00
|
|
|
timeflag = 0;
|
2007-01-30 08:31:11 +08:00
|
|
|
comm_forward = comm_reverse = 0;
|
2014-11-18 02:11:29 +08:00
|
|
|
dynamic = 0;
|
2014-05-02 23:49:01 +08:00
|
|
|
dynamic_group_allow = 1;
|
2011-05-20 23:28:28 +08:00
|
|
|
cudable = 0;
|
2007-01-30 08:31:11 +08:00
|
|
|
|
2009-12-05 05:03:54 +08:00
|
|
|
invoked_scalar = invoked_vector = invoked_array = -1;
|
|
|
|
invoked_peratom = invoked_local = -1;
|
2014-10-01 06:55:05 +08:00
|
|
|
invoked_flag = 0;
|
2009-01-06 06:26:08 +08:00
|
|
|
|
2007-01-30 08:31:11 +08:00
|
|
|
// set modify defaults
|
|
|
|
|
2008-05-17 04:40:00 +08:00
|
|
|
extra_dof = domain->dimension;
|
2014-11-18 02:11:29 +08:00
|
|
|
dynamic_user = 0;
|
2007-11-03 04:25:11 +08:00
|
|
|
|
|
|
|
// setup list of timesteps
|
2012-06-07 06:47:51 +08:00
|
|
|
|
2007-11-03 04:25:11 +08:00
|
|
|
ntime = maxtime = 0;
|
|
|
|
tlist = NULL;
|
2009-12-22 01:24:04 +08:00
|
|
|
|
|
|
|
// setup map for molecule IDs
|
|
|
|
|
|
|
|
molmap = NULL;
|
2012-08-28 22:21:55 +08:00
|
|
|
|
|
|
|
datamask = ALL_MASK;
|
|
|
|
datamask_ext = ALL_MASK;
|
2014-12-10 03:37:05 +08:00
|
|
|
|
|
|
|
// force init to zero in case these are used as logicals
|
|
|
|
|
|
|
|
vector = vector_atom = vector_local = NULL;
|
|
|
|
array = array_atom = array_local = NULL;
|
2007-01-30 08:31:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ---------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
Compute::~Compute()
|
|
|
|
{
|
|
|
|
delete [] id;
|
|
|
|
delete [] style;
|
2007-11-03 04:25:11 +08:00
|
|
|
|
2011-03-26 08:50:29 +08:00
|
|
|
memory->destroy(tlist);
|
|
|
|
memory->destroy(molmap);
|
2007-01-30 08:31:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ---------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
void Compute::modify_params(int narg, char **arg)
|
|
|
|
{
|
2011-09-24 02:06:55 +08:00
|
|
|
if (narg == 0) error->all(FLERR,"Illegal compute_modify command");
|
2007-01-30 08:31:11 +08:00
|
|
|
|
2007-11-03 04:25:11 +08:00
|
|
|
int iarg = 0;
|
|
|
|
while (iarg < narg) {
|
2007-01-30 08:31:11 +08:00
|
|
|
if (strcmp(arg[iarg],"extra") == 0) {
|
2011-09-24 02:06:55 +08:00
|
|
|
if (iarg+2 > narg) error->all(FLERR,"Illegal compute_modify command");
|
2013-06-29 03:00:58 +08:00
|
|
|
extra_dof = force->inumeric(FLERR,arg[iarg+1]);
|
2007-01-30 08:31:11 +08:00
|
|
|
iarg += 2;
|
|
|
|
} else if (strcmp(arg[iarg],"dynamic") == 0) {
|
2011-09-24 02:06:55 +08:00
|
|
|
if (iarg+2 > narg) error->all(FLERR,"Illegal compute_modify command");
|
2014-11-18 02:11:29 +08:00
|
|
|
if (strcmp(arg[iarg+1],"no") == 0) dynamic_user = 0;
|
|
|
|
else if (strcmp(arg[iarg+1],"yes") == 0) dynamic_user = 1;
|
2011-09-24 02:06:55 +08:00
|
|
|
else error->all(FLERR,"Illegal compute_modify command");
|
2007-01-30 08:31:11 +08:00
|
|
|
iarg += 2;
|
2007-11-03 04:25:11 +08:00
|
|
|
} else if (strcmp(arg[iarg],"thermo") == 0) {
|
2011-09-24 02:06:55 +08:00
|
|
|
if (iarg+2 > narg) error->all(FLERR,"Illegal compute_modify command");
|
2007-11-03 04:25:11 +08:00
|
|
|
if (strcmp(arg[iarg+1],"no") == 0) thermoflag = 0;
|
|
|
|
else if (strcmp(arg[iarg+1],"yes") == 0) thermoflag = 1;
|
2011-09-24 02:06:55 +08:00
|
|
|
else error->all(FLERR,"Illegal compute_modify command");
|
2007-11-03 04:25:11 +08:00
|
|
|
iarg += 2;
|
2011-09-24 02:06:55 +08:00
|
|
|
} else error->all(FLERR,"Illegal compute_modify command");
|
2007-01-30 08:31:11 +08:00
|
|
|
}
|
|
|
|
}
|
2007-11-03 04:25:11 +08:00
|
|
|
|
2014-05-07 22:30:27 +08:00
|
|
|
/* ----------------------------------------------------------------------
|
|
|
|
calculate adjustment in DOF due to fixes
|
|
|
|
------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
void Compute::adjust_dof_fix()
|
|
|
|
{
|
|
|
|
fix_dof = 0;
|
|
|
|
for (int i = 0; i < modify->nfix; i++)
|
|
|
|
fix_dof += modify->fix[i]->dof(igroup);
|
|
|
|
}
|
|
|
|
|
2008-05-17 05:58:06 +08:00
|
|
|
/* ----------------------------------------------------------------------
|
|
|
|
reset extra_dof to its default value
|
|
|
|
------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
void Compute::reset_extra_dof()
|
|
|
|
{
|
|
|
|
extra_dof = domain->dimension;
|
|
|
|
}
|
|
|
|
|
2009-07-02 04:28:37 +08:00
|
|
|
/* ---------------------------------------------------------------------- */
|
|
|
|
|
2011-12-17 05:15:49 +08:00
|
|
|
void Compute::reset_extra_compute_fix(const char *)
|
2009-07-02 04:28:37 +08:00
|
|
|
{
|
2011-12-17 05:15:49 +08:00
|
|
|
error->all(FLERR,
|
2012-06-07 06:47:51 +08:00
|
|
|
"Compute does not allow an extra compute or fix to be reset");
|
2009-07-02 04:28:37 +08:00
|
|
|
}
|
|
|
|
|
2007-11-03 04:25:11 +08:00
|
|
|
/* ----------------------------------------------------------------------
|
|
|
|
add ntimestep to list of timesteps the compute will be called on
|
|
|
|
do not add if already in list
|
|
|
|
search from top downward, since list of times is in decreasing order
|
|
|
|
------------------------------------------------------------------------- */
|
|
|
|
|
2011-01-11 08:41:00 +08:00
|
|
|
void Compute::addstep(bigint ntimestep)
|
2007-11-03 04:25:11 +08:00
|
|
|
{
|
|
|
|
// i = location in list to insert ntimestep
|
|
|
|
|
|
|
|
int i;
|
|
|
|
for (i = ntime-1; i >= 0; i--) {
|
|
|
|
if (ntimestep == tlist[i]) return;
|
|
|
|
if (ntimestep < tlist[i]) break;
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
|
|
|
|
// extend list as needed
|
|
|
|
|
|
|
|
if (ntime == maxtime) {
|
|
|
|
maxtime += DELTA;
|
2011-03-26 08:50:29 +08:00
|
|
|
memory->grow(tlist,maxtime,"compute:tlist");
|
2007-11-03 04:25:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// move remainder of list upward and insert ntimestep
|
|
|
|
|
|
|
|
for (int j = ntime-1; j >= i; j--) tlist[j+1] = tlist[j];
|
|
|
|
tlist[i] = ntimestep;
|
|
|
|
ntime++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ----------------------------------------------------------------------
|
|
|
|
return 1/0 if ntimestep is or is not in list of calling timesteps
|
|
|
|
if value(s) on top of list are less than ntimestep, delete them
|
|
|
|
search from top downward, since list of times is in decreasing order
|
|
|
|
------------------------------------------------------------------------- */
|
|
|
|
|
2011-01-11 08:41:00 +08:00
|
|
|
int Compute::matchstep(bigint ntimestep)
|
2007-11-03 04:25:11 +08:00
|
|
|
{
|
|
|
|
for (int i = ntime-1; i >= 0; i--) {
|
|
|
|
if (ntimestep < tlist[i]) return 0;
|
|
|
|
if (ntimestep == tlist[i]) return 1;
|
|
|
|
if (ntimestep > tlist[i]) ntime--;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2009-01-06 06:26:08 +08:00
|
|
|
|
|
|
|
/* ----------------------------------------------------------------------
|
|
|
|
clean out list of timesteps to call the compute on
|
|
|
|
------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
void Compute::clearstep()
|
|
|
|
{
|
|
|
|
ntime = 0;
|
|
|
|
}
|
2009-12-22 01:24:04 +08:00
|
|
|
|
|
|
|
/* ----------------------------------------------------------------------
|
|
|
|
identify molecule IDs with atoms in group
|
|
|
|
warn if any atom in group has molecule ID = 0
|
|
|
|
warn if any molecule has only some atoms in group
|
|
|
|
return Ncount = # of molecules with atoms in group
|
|
|
|
set molmap to NULL if molecule IDs include all in range from 1 to Ncount
|
|
|
|
else: molecule IDs range from idlo to idhi
|
|
|
|
set molmap to vector of length idhi-idlo+1
|
2012-06-07 06:47:51 +08:00
|
|
|
molmap[id-idlo] = index from 0 to Ncount-1
|
2009-12-22 01:24:04 +08:00
|
|
|
return idlo and idhi
|
|
|
|
------------------------------------------------------------------------- */
|
|
|
|
|
2014-01-23 01:44:32 +08:00
|
|
|
int Compute::molecules_in_group(tagint &idlo, tagint &idhi)
|
2009-12-22 01:24:04 +08:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2011-03-26 08:50:29 +08:00
|
|
|
memory->destroy(molmap);
|
2009-12-22 01:24:04 +08:00
|
|
|
molmap = NULL;
|
|
|
|
|
|
|
|
// find lo/hi molecule ID for any atom in group
|
|
|
|
// warn if atom in group has ID = 0
|
|
|
|
|
2014-01-23 01:44:32 +08:00
|
|
|
tagint *molecule = atom->molecule;
|
2009-12-22 01:24:04 +08:00
|
|
|
int *mask = atom->mask;
|
|
|
|
int nlocal = atom->nlocal;
|
|
|
|
|
2014-01-23 01:44:32 +08:00
|
|
|
tagint lo = BIG;
|
|
|
|
tagint hi = -BIG;
|
2009-12-22 01:24:04 +08:00
|
|
|
int flag = 0;
|
|
|
|
for (i = 0; i < nlocal; i++)
|
|
|
|
if (mask[i] & groupbit) {
|
2011-03-30 22:48:45 +08:00
|
|
|
if (molecule[i] == 0) flag = 1;
|
2009-12-22 01:24:04 +08:00
|
|
|
lo = MIN(lo,molecule[i]);
|
|
|
|
hi = MAX(hi,molecule[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
int flagall;
|
|
|
|
MPI_Allreduce(&flag,&flagall,1,MPI_INT,MPI_SUM,world);
|
|
|
|
if (flagall && comm->me == 0)
|
2011-09-24 02:06:55 +08:00
|
|
|
error->warning(FLERR,"Atom with molecule ID = 0 included in "
|
2012-06-07 06:47:51 +08:00
|
|
|
"compute molecule group");
|
2009-12-22 01:24:04 +08:00
|
|
|
|
2014-01-23 01:44:32 +08:00
|
|
|
MPI_Allreduce(&lo,&idlo,1,MPI_LMP_TAGINT,MPI_MIN,world);
|
|
|
|
MPI_Allreduce(&hi,&idhi,1,MPI_LMP_TAGINT,MPI_MAX,world);
|
2009-12-22 01:24:04 +08:00
|
|
|
if (idlo == BIG) return 0;
|
|
|
|
|
|
|
|
// molmap = vector of length nlen
|
|
|
|
// set to 1 for IDs that appear in group across all procs, else 0
|
|
|
|
|
2014-01-23 01:44:32 +08:00
|
|
|
tagint nlen_tag = idhi-idlo+1;
|
|
|
|
if (nlen_tag > MAXSMALLINT)
|
|
|
|
error->all(FLERR,"Too many molecules for compute");
|
|
|
|
int nlen = (int) nlen_tag;
|
|
|
|
|
2011-03-26 08:50:29 +08:00
|
|
|
memory->create(molmap,nlen,"compute:molmap");
|
2009-12-22 01:24:04 +08:00
|
|
|
for (i = 0; i < nlen; i++) molmap[i] = 0;
|
|
|
|
|
|
|
|
for (i = 0; i < nlocal; i++)
|
|
|
|
if (mask[i] & groupbit)
|
|
|
|
molmap[molecule[i]-idlo] = 1;
|
|
|
|
|
2011-03-26 08:50:29 +08:00
|
|
|
int *molmapall;
|
|
|
|
memory->create(molmapall,nlen,"compute:molmapall");
|
2009-12-22 01:24:04 +08:00
|
|
|
MPI_Allreduce(molmap,molmapall,nlen,MPI_INT,MPI_MAX,world);
|
|
|
|
|
|
|
|
// nmolecules = # of non-zero IDs in molmap
|
|
|
|
// molmap[i] = index of molecule, skipping molecules not in group with -1
|
|
|
|
|
|
|
|
int nmolecules = 0;
|
|
|
|
for (i = 0; i < nlen; i++)
|
|
|
|
if (molmapall[i]) molmap[i] = nmolecules++;
|
|
|
|
else molmap[i] = -1;
|
2011-03-26 08:50:29 +08:00
|
|
|
memory->destroy(molmapall);
|
2009-12-22 01:24:04 +08:00
|
|
|
|
|
|
|
// warn if any molecule has some atoms in group and some not in group
|
|
|
|
|
|
|
|
flag = 0;
|
|
|
|
for (i = 0; i < nlocal; i++) {
|
|
|
|
if (mask[i] & groupbit) continue;
|
|
|
|
if (molecule[i] < idlo || molecule[i] > idhi) continue;
|
|
|
|
if (molmap[molecule[i]-idlo] >= 0) flag = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
MPI_Allreduce(&flag,&flagall,1,MPI_INT,MPI_SUM,world);
|
|
|
|
if (flagall && comm->me == 0)
|
2012-08-01 07:47:56 +08:00
|
|
|
error->warning(FLERR,
|
|
|
|
"One or more compute molecules has atoms not in group");
|
2009-12-22 01:24:04 +08:00
|
|
|
|
|
|
|
// if molmap simply stores 1 to Nmolecules, then free it
|
|
|
|
|
2011-03-30 22:48:45 +08:00
|
|
|
if (idlo == 1 && idhi == nmolecules && nlen == nmolecules) {
|
|
|
|
memory->destroy(molmap);
|
|
|
|
molmap = NULL;
|
|
|
|
}
|
2009-12-22 01:24:04 +08:00
|
|
|
return nmolecules;
|
|
|
|
}
|