git-svn-id: svn://svn.icms.temple.edu/lammps-ro/trunk@14424 f3b2605a-c512-4ea7-a41b-209d697bcdaa

This commit is contained in:
sjplimp 2016-01-12 00:12:15 +00:00
parent 12c8aaf29d
commit 4e199dd5bd
10 changed files with 113 additions and 59 deletions

View File

@ -74,13 +74,14 @@ ComputeTempCS::ComputeTempCS(LAMMPS *lmp, int narg, char **arg) :
strcpy(id_fix,id); strcpy(id_fix,id);
strcat(id_fix,"_COMPUTE_STORE"); strcat(id_fix,"_COMPUTE_STORE");
char **newarg = new char*[5]; char **newarg = new char*[6];
newarg[0] = id_fix; newarg[0] = id_fix;
newarg[1] = group->names[igroup]; newarg[1] = group->names[igroup];
newarg[2] = (char *) "STORE"; newarg[2] = (char *) "STORE";
newarg[3] = (char *) "0"; newarg[3] = (char *) "peratom";
newarg[4] = (char *) "1"; newarg[4] = (char *) "0";
modify->add_fix(5,newarg); newarg[5] = (char *) "1";
modify->add_fix(6,newarg);
fix = (FixStore *) modify->fix[modify->nfix-1]; fix = (FixStore *) modify->fix[modify->nfix-1];
delete [] newarg; delete [] newarg;

View File

@ -154,13 +154,14 @@ void TAD::command(int narg, char **arg)
// create FixStore object to store revert state // create FixStore object to store revert state
narg2 = 5; narg2 = 6;
args = new char*[narg2]; args = new char*[narg2];
args[0] = (char *) "tad_revert"; args[0] = (char *) "tad_revert";
args[1] = (char *) "all"; args[1] = (char *) "all";
args[2] = (char *) "STORE"; args[2] = (char *) "STORE";
args[3] = (char *) "0"; args[3] = (char *) "peratom";
args[4] = (char *) "7"; args[4] = (char *) "0";
args[5] = (char *) "7";
modify->add_fix(narg2,args); modify->add_fix(narg2,args);
fix_revert = (FixStore *) modify->fix[modify->nfix-1]; fix_revert = (FixStore *) modify->fix[modify->nfix-1];
delete [] args; delete [] args;

View File

@ -579,13 +579,14 @@ void ComputeChunkAtom::init()
strcpy(id_fix,id); strcpy(id_fix,id);
strcat(id_fix,"_COMPUTE_STORE"); strcat(id_fix,"_COMPUTE_STORE");
char **newarg = new char*[5]; char **newarg = new char*[6];
newarg[0] = id_fix; newarg[0] = id_fix;
newarg[1] = group->names[igroup]; newarg[1] = group->names[igroup];
newarg[2] = (char *) "STORE"; newarg[2] = (char *) "STORE";
newarg[3] = (char *) "1"; newarg[3] = (char *) "peratom";
newarg[4] = (char *) "1"; newarg[4] = (char *) "1";
modify->add_fix(5,newarg); newarg[5] = (char *) "1";
modify->add_fix(6,newarg);
fixstore = (FixStore *) modify->fix[modify->nfix-1]; fixstore = (FixStore *) modify->fix[modify->nfix-1];
delete [] newarg; delete [] newarg;
} }

View File

@ -45,13 +45,14 @@ ComputeDisplaceAtom::ComputeDisplaceAtom(LAMMPS *lmp, int narg, char **arg) :
strcpy(id_fix,id); strcpy(id_fix,id);
strcat(id_fix,"_COMPUTE_STORE"); strcat(id_fix,"_COMPUTE_STORE");
char **newarg = new char*[5]; char **newarg = new char*[6];
newarg[0] = id_fix; newarg[0] = id_fix;
newarg[1] = group->names[igroup]; newarg[1] = group->names[igroup];
newarg[2] = (char *) "STORE"; newarg[2] = (char *) "STORE";
newarg[3] = (char *) "1"; newarg[3] = (char *) "peratom";
newarg[4] = (char *) "3"; newarg[4] = (char *) "1";
modify->add_fix(5,newarg); newarg[5] = (char *) "3";
modify->add_fix(6,newarg);
fix = (FixStore *) modify->fix[modify->nfix-1]; fix = (FixStore *) modify->fix[modify->nfix-1];
delete [] newarg; delete [] newarg;

View File

@ -65,13 +65,14 @@ ComputeMSD::ComputeMSD(LAMMPS *lmp, int narg, char **arg) :
strcpy(id_fix,id); strcpy(id_fix,id);
strcat(id_fix,"_COMPUTE_STORE"); strcat(id_fix,"_COMPUTE_STORE");
char **newarg = new char*[5]; char **newarg = new char*[6];
newarg[0] = id_fix; newarg[0] = id_fix;
newarg[1] = group->names[igroup]; newarg[1] = group->names[igroup];
newarg[2] = (char *) "STORE"; newarg[2] = (char *) "STORE";
newarg[3] = (char *) "1"; newarg[3] = (char *) "peratom";
newarg[4] = (char *) "3"; newarg[4] = (char *) "1";
modify->add_fix(5,newarg); newarg[5] = (char *) "3";
modify->add_fix(6,newarg);
fix = (FixStore *) modify->fix[modify->nfix-1]; fix = (FixStore *) modify->fix[modify->nfix-1];
delete [] newarg; delete [] newarg;

View File

@ -42,13 +42,14 @@ ComputeVACF::ComputeVACF(LAMMPS *lmp, int narg, char **arg) :
strcpy(id_fix,id); strcpy(id_fix,id);
strcat(id_fix,"_COMPUTE_STORE"); strcat(id_fix,"_COMPUTE_STORE");
char **newarg = new char*[5]; char **newarg = new char*[6];
newarg[0] = id_fix; newarg[0] = id_fix;
newarg[1] = group->names[igroup]; newarg[1] = group->names[igroup];
newarg[2] = (char *) "STORE"; newarg[2] = (char *) "STORE";
newarg[3] = (char *) "1"; newarg[3] = (char *) "peratom";
newarg[4] = (char *) "3"; newarg[4] = (char *) "1";
modify->add_fix(5,newarg); newarg[5] = (char *) "3";
modify->add_fix(6,newarg);
fix = (FixStore *) modify->fix[modify->nfix-1]; fix = (FixStore *) modify->fix[modify->nfix-1];
delete [] newarg; delete [] newarg;

View File

@ -210,11 +210,12 @@ void FixAdapt::post_constructor()
id_fix_diam = NULL; id_fix_diam = NULL;
id_fix_chg = NULL; id_fix_chg = NULL;
char **newarg = new char*[5]; char **newarg = new char*[6];
newarg[1] = group->names[igroup]; newarg[1] = group->names[igroup];
newarg[2] = (char *) "STORE"; newarg[2] = (char *) "STORE";
newarg[3] = (char *) "1"; newarg[3] = (char *) "peratom";
newarg[4] = (char *) "1"; newarg[4] = (char *) "1";
newarg[5] = (char *) "1";
if (diamflag) { if (diamflag) {
int n = strlen(id) + strlen("_FIX_STORE_DIAM") + 1; int n = strlen(id) + strlen("_FIX_STORE_DIAM") + 1;
@ -222,7 +223,7 @@ void FixAdapt::post_constructor()
strcpy(id_fix_diam,id); strcpy(id_fix_diam,id);
strcat(id_fix_diam,"_FIX_STORE_DIAM"); strcat(id_fix_diam,"_FIX_STORE_DIAM");
newarg[0] = id_fix_diam; newarg[0] = id_fix_diam;
modify->add_fix(5,newarg); modify->add_fix(6,newarg);
fix_diam = (FixStore *) modify->fix[modify->nfix-1]; fix_diam = (FixStore *) modify->fix[modify->nfix-1];
if (fix_diam->restart_reset) fix_diam->restart_reset = 0; if (fix_diam->restart_reset) fix_diam->restart_reset = 0;
@ -245,7 +246,7 @@ void FixAdapt::post_constructor()
strcpy(id_fix_chg,id); strcpy(id_fix_chg,id);
strcat(id_fix_chg,"_FIX_STORE_CHG"); strcat(id_fix_chg,"_FIX_STORE_CHG");
newarg[0] = id_fix_chg; newarg[0] = id_fix_chg;
modify->add_fix(5,newarg); modify->add_fix(6,newarg);
fix_chg = (FixStore *) modify->fix[modify->nfix-1]; fix_chg = (FixStore *) modify->fix[modify->nfix-1];
if (fix_chg->restart_reset) fix_chg->restart_reset = 0; if (fix_chg->restart_reset) fix_chg->restart_reset = 0;

View File

@ -22,41 +22,82 @@
using namespace LAMMPS_NS; using namespace LAMMPS_NS;
using namespace FixConst; using namespace FixConst;
enum{GLOBAL,PERATOM};
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
FixStore::FixStore(LAMMPS *lmp, int narg, char **arg) : Fix(lmp, narg, arg) FixStore::FixStore(LAMMPS *lmp, int narg, char **arg) : Fix(lmp, narg, arg)
{ {
if (narg != 5) error->all(FLERR,"Illegal fix store command"); if (narg != 6) error->all(FLERR,"Illegal fix store command");
// syntax: id group style 0/1 nvalue // 4th arg determines GLOBAL vs PERATOM values
// 0/1 flag = not-store or store values in restart file // syntax: id group style peratom 0/1 nvalue
// 0/1 flag = not-store or store peratom values in restart file
// nvalue = # of peratom values, N=1 is vector, N>1 is array
// syntax: id group style global nrow ncol
// Nrow by Ncol array of global values
// Ncol=1 is vector, Nrow>1 is array
restart_peratom = force->inumeric(FLERR,arg[3]); if (strcmp(arg[3],"peratom") == 0) flavor = PERATOM;
nvalues = force->inumeric(FLERR,arg[4]); else if (strcmp(arg[3],"global") == 0) flavor = GLOBAL;
else error->all(FLERR,"Invalid fix store command");
vecflag = 0; // GLOBAL values are always written to restart file
if (nvalues == 1) vecflag = 1; // PERATOM restart_peratom is set by caller
// perform initial allocation of atom-based array if (flavor == GLOBAL) {
// register with Atom class restart_global = 1;
nrow = force->inumeric(FLERR,arg[4]);
ncol = force->inumeric(FLERR,arg[5]);
if (nrow <= 0 || ncol <= 0)
error->all(FLERR,"Invalid fix store command");
vecflag = 0;
if (ncol == 1) vecflag = 1;
} else {
restart_peratom = force->inumeric(FLERR,arg[4]);
nvalues = force->inumeric(FLERR,arg[5]);
if (restart_peratom < 0 or restart_peratom > 1 || nvalues <= 0)
error->all(FLERR,"Invalid fix store command");
vecflag = 0;
if (nvalues == 1) vecflag = 1;
}
vstore = NULL; vstore = NULL;
astore = NULL; astore = NULL;
grow_arrays(atom->nmax);
atom->add_callback(0); // allocate vector or array
if (restart_peratom) atom->add_callback(1); // for PERATOM, register with Atom class
if (flavor == GLOBAL) {
if (vecflag) memory->create(vstore,nrow,"fix/store:vstore");
else memory->create(astore,nrow,ncol,"fix/store:astore");
}
if (flavor == PERATOM) {
grow_arrays(atom->nmax);
atom->add_callback(0);
if (restart_peratom) atom->add_callback(1);
}
// zero the storage // zero the storage
// since may be exchanged before filled by caller // PERATOM may be exchanged before filled by caller
int nlocal = atom->nlocal; if (flavor == GLOBAL) {
if (vecflag) if (vecflag)
for (int i = 0; i < nlocal; i++) for (int i = 0; i < nrow; i++) vstore[i] = 0.0;
vstore[i] = 0.0; else
else for (int i = 0; i < nrow; i++)
for (int i = 0; i < nlocal; i++) for (int j = 0; j < ncol; j++)
for (int j = 0; j < nvalues; j++) astore[i][j] = 0.0;
astore[i][j] = 0.0; }
if (flavor == PERATOM) {
int nlocal = atom->nlocal;
if (vecflag)
for (int i = 0; i < nlocal; i++) vstore[i] = 0.0;
else
for (int i = 0; i < nlocal; i++)
for (int j = 0; j < nvalues; j++)
astore[i][j] = 0.0;
}
} }
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
@ -65,8 +106,10 @@ FixStore::~FixStore()
{ {
// unregister callbacks to this fix from Atom class // unregister callbacks to this fix from Atom class
atom->delete_callback(id,0); if (flavor == PERATOM) {
if (restart_peratom) atom->delete_callback(id,1); atom->delete_callback(id,0);
if (restart_peratom) atom->delete_callback(id,1);
}
memory->destroy(vstore); memory->destroy(vstore);
memory->destroy(astore); memory->destroy(astore);
@ -186,7 +229,8 @@ int FixStore::size_restart(int nlocal)
double FixStore::memory_usage() double FixStore::memory_usage()
{ {
double bytes = atom->nmax*nvalues * sizeof(double); double bytes;
if (flavor == GLOBAL) bytes += nrow*ncol * sizeof(double);
if (flavor == PERATOM) bytes += atom->nmax*nvalues * sizeof(double);
return bytes; return bytes;
} }

View File

@ -26,8 +26,10 @@ namespace LAMMPS_NS {
class FixStore : public Fix { class FixStore : public Fix {
public: public:
double *vstore; // vector storage if nvalues = 1 int nrow,ncol; // size of global data array
double **astore; // array storage if nvalues > 1 int nvalues; // number of per-atom values
double *vstore; // vector storage for GLOBAL or PERATOM
double **astore; // array storage for GLOBAL or PERATOM
FixStore(class LAMMPS *, int, char **); FixStore(class LAMMPS *, int, char **);
~FixStore(); ~FixStore();
@ -45,8 +47,8 @@ class FixStore : public Fix {
double memory_usage(); double memory_usage();
private: private:
int nvalues; // total # of values per atom int flavor; // GLOBAL or PERATOM
int vecflag; // 1 if nvalues = 1 int vecflag; // 1 if ncol=1 or nvalues=1
}; };
} }

View File

@ -4480,13 +4480,14 @@ VarReader::VarReader(LAMMPS *lmp, char *name, char *file, int flag) :
strcpy(id_fix,name); strcpy(id_fix,name);
strcat(id_fix,"_VARIABLE_STORE"); strcat(id_fix,"_VARIABLE_STORE");
char **newarg = new char*[5]; char **newarg = new char*[6];
newarg[0] = id_fix; newarg[0] = id_fix;
newarg[1] = (char *) "all"; newarg[1] = (char *) "all";
newarg[2] = (char *) "STORE"; newarg[2] = (char *) "STORE";
newarg[3] = (char *) "0"; newarg[3] = (char *) "peratom";
newarg[4] = (char *) "1"; newarg[4] = (char *) "0";
modify->add_fix(5,newarg); newarg[5] = (char *) "1";
modify->add_fix(6,newarg);
fixstore = (FixStore *) modify->fix[modify->nfix-1]; fixstore = (FixStore *) modify->fix[modify->nfix-1];
delete [] newarg; delete [] newarg;