From 4e199dd5bdbc49ab5f4e0dba63bb7485cd5c0caa Mon Sep 17 00:00:00 2001 From: sjplimp Date: Tue, 12 Jan 2016 00:12:15 +0000 Subject: [PATCH] git-svn-id: svn://svn.icms.temple.edu/lammps-ro/trunk@14424 f3b2605a-c512-4ea7-a41b-209d697bcdaa --- src/CORESHELL/compute_temp_cs.cpp | 9 +-- src/REPLICA/tad.cpp | 7 ++- src/compute_chunk_atom.cpp | 7 ++- src/compute_displace_atom.cpp | 9 +-- src/compute_msd.cpp | 9 +-- src/compute_vacf.cpp | 9 +-- src/fix_adapt.cpp | 9 +-- src/fix_store.cpp | 94 +++++++++++++++++++++++-------- src/fix_store.h | 10 ++-- src/variable.cpp | 9 +-- 10 files changed, 113 insertions(+), 59 deletions(-) diff --git a/src/CORESHELL/compute_temp_cs.cpp b/src/CORESHELL/compute_temp_cs.cpp index 43bf7b8e5e..b10a9256b8 100644 --- a/src/CORESHELL/compute_temp_cs.cpp +++ b/src/CORESHELL/compute_temp_cs.cpp @@ -74,13 +74,14 @@ ComputeTempCS::ComputeTempCS(LAMMPS *lmp, int narg, char **arg) : strcpy(id_fix,id); strcat(id_fix,"_COMPUTE_STORE"); - char **newarg = new char*[5]; + char **newarg = new char*[6]; newarg[0] = id_fix; newarg[1] = group->names[igroup]; newarg[2] = (char *) "STORE"; - newarg[3] = (char *) "0"; - newarg[4] = (char *) "1"; - modify->add_fix(5,newarg); + newarg[3] = (char *) "peratom"; + newarg[4] = (char *) "0"; + newarg[5] = (char *) "1"; + modify->add_fix(6,newarg); fix = (FixStore *) modify->fix[modify->nfix-1]; delete [] newarg; diff --git a/src/REPLICA/tad.cpp b/src/REPLICA/tad.cpp index 25043a0f8a..8719012935 100644 --- a/src/REPLICA/tad.cpp +++ b/src/REPLICA/tad.cpp @@ -154,13 +154,14 @@ void TAD::command(int narg, char **arg) // create FixStore object to store revert state - narg2 = 5; + narg2 = 6; args = new char*[narg2]; args[0] = (char *) "tad_revert"; args[1] = (char *) "all"; args[2] = (char *) "STORE"; - args[3] = (char *) "0"; - args[4] = (char *) "7"; + args[3] = (char *) "peratom"; + args[4] = (char *) "0"; + args[5] = (char *) "7"; modify->add_fix(narg2,args); fix_revert = (FixStore *) modify->fix[modify->nfix-1]; delete [] args; diff --git a/src/compute_chunk_atom.cpp b/src/compute_chunk_atom.cpp index d4e15ba018..3a9f043ed9 100644 --- a/src/compute_chunk_atom.cpp +++ b/src/compute_chunk_atom.cpp @@ -579,13 +579,14 @@ void ComputeChunkAtom::init() strcpy(id_fix,id); strcat(id_fix,"_COMPUTE_STORE"); - char **newarg = new char*[5]; + char **newarg = new char*[6]; newarg[0] = id_fix; newarg[1] = group->names[igroup]; newarg[2] = (char *) "STORE"; - newarg[3] = (char *) "1"; + newarg[3] = (char *) "peratom"; 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]; delete [] newarg; } diff --git a/src/compute_displace_atom.cpp b/src/compute_displace_atom.cpp index a95a645632..51d8ab22de 100644 --- a/src/compute_displace_atom.cpp +++ b/src/compute_displace_atom.cpp @@ -45,13 +45,14 @@ ComputeDisplaceAtom::ComputeDisplaceAtom(LAMMPS *lmp, int narg, char **arg) : strcpy(id_fix,id); strcat(id_fix,"_COMPUTE_STORE"); - char **newarg = new char*[5]; + char **newarg = new char*[6]; newarg[0] = id_fix; newarg[1] = group->names[igroup]; newarg[2] = (char *) "STORE"; - newarg[3] = (char *) "1"; - newarg[4] = (char *) "3"; - modify->add_fix(5,newarg); + newarg[3] = (char *) "peratom"; + newarg[4] = (char *) "1"; + newarg[5] = (char *) "3"; + modify->add_fix(6,newarg); fix = (FixStore *) modify->fix[modify->nfix-1]; delete [] newarg; diff --git a/src/compute_msd.cpp b/src/compute_msd.cpp index 3634e6817e..32d93f9334 100644 --- a/src/compute_msd.cpp +++ b/src/compute_msd.cpp @@ -65,13 +65,14 @@ ComputeMSD::ComputeMSD(LAMMPS *lmp, int narg, char **arg) : strcpy(id_fix,id); strcat(id_fix,"_COMPUTE_STORE"); - char **newarg = new char*[5]; + char **newarg = new char*[6]; newarg[0] = id_fix; newarg[1] = group->names[igroup]; newarg[2] = (char *) "STORE"; - newarg[3] = (char *) "1"; - newarg[4] = (char *) "3"; - modify->add_fix(5,newarg); + newarg[3] = (char *) "peratom"; + newarg[4] = (char *) "1"; + newarg[5] = (char *) "3"; + modify->add_fix(6,newarg); fix = (FixStore *) modify->fix[modify->nfix-1]; delete [] newarg; diff --git a/src/compute_vacf.cpp b/src/compute_vacf.cpp index bc3ffbd21a..c06113a770 100755 --- a/src/compute_vacf.cpp +++ b/src/compute_vacf.cpp @@ -42,13 +42,14 @@ ComputeVACF::ComputeVACF(LAMMPS *lmp, int narg, char **arg) : strcpy(id_fix,id); strcat(id_fix,"_COMPUTE_STORE"); - char **newarg = new char*[5]; + char **newarg = new char*[6]; newarg[0] = id_fix; newarg[1] = group->names[igroup]; newarg[2] = (char *) "STORE"; - newarg[3] = (char *) "1"; - newarg[4] = (char *) "3"; - modify->add_fix(5,newarg); + newarg[3] = (char *) "peratom"; + newarg[4] = (char *) "1"; + newarg[5] = (char *) "3"; + modify->add_fix(6,newarg); fix = (FixStore *) modify->fix[modify->nfix-1]; delete [] newarg; diff --git a/src/fix_adapt.cpp b/src/fix_adapt.cpp index a9e42ce6dc..904586e949 100644 --- a/src/fix_adapt.cpp +++ b/src/fix_adapt.cpp @@ -210,11 +210,12 @@ void FixAdapt::post_constructor() id_fix_diam = NULL; id_fix_chg = NULL; - char **newarg = new char*[5]; + char **newarg = new char*[6]; newarg[1] = group->names[igroup]; newarg[2] = (char *) "STORE"; - newarg[3] = (char *) "1"; + newarg[3] = (char *) "peratom"; newarg[4] = (char *) "1"; + newarg[5] = (char *) "1"; if (diamflag) { int n = strlen(id) + strlen("_FIX_STORE_DIAM") + 1; @@ -222,7 +223,7 @@ void FixAdapt::post_constructor() strcpy(id_fix_diam,id); strcat(id_fix_diam,"_FIX_STORE_DIAM"); newarg[0] = id_fix_diam; - modify->add_fix(5,newarg); + modify->add_fix(6,newarg); fix_diam = (FixStore *) modify->fix[modify->nfix-1]; if (fix_diam->restart_reset) fix_diam->restart_reset = 0; @@ -245,7 +246,7 @@ void FixAdapt::post_constructor() strcpy(id_fix_chg,id); strcat(id_fix_chg,"_FIX_STORE_CHG"); newarg[0] = id_fix_chg; - modify->add_fix(5,newarg); + modify->add_fix(6,newarg); fix_chg = (FixStore *) modify->fix[modify->nfix-1]; if (fix_chg->restart_reset) fix_chg->restart_reset = 0; diff --git a/src/fix_store.cpp b/src/fix_store.cpp index 1375384f6c..abdbd20774 100644 --- a/src/fix_store.cpp +++ b/src/fix_store.cpp @@ -22,41 +22,82 @@ using namespace LAMMPS_NS; using namespace FixConst; +enum{GLOBAL,PERATOM}; + /* ---------------------------------------------------------------------- */ 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 - // 0/1 flag = not-store or store values in restart file + // 4th arg determines GLOBAL vs PERATOM values + // 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]); - nvalues = force->inumeric(FLERR,arg[4]); + if (strcmp(arg[3],"peratom") == 0) flavor = PERATOM; + else if (strcmp(arg[3],"global") == 0) flavor = GLOBAL; + else error->all(FLERR,"Invalid fix store command"); - vecflag = 0; - if (nvalues == 1) vecflag = 1; + // GLOBAL values are always written to restart file + // PERATOM restart_peratom is set by caller - // perform initial allocation of atom-based array - // register with Atom class + if (flavor == GLOBAL) { + 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; astore = NULL; - grow_arrays(atom->nmax); - atom->add_callback(0); - if (restart_peratom) atom->add_callback(1); + + // allocate vector or array + // 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 - // since may be exchanged before filled by caller + // PERATOM may be exchanged before filled by caller - 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; + if (flavor == GLOBAL) { + if (vecflag) + for (int i = 0; i < nrow; i++) vstore[i] = 0.0; + else + for (int i = 0; i < nrow; i++) + for (int j = 0; j < ncol; j++) + 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 - atom->delete_callback(id,0); - if (restart_peratom) atom->delete_callback(id,1); + if (flavor == PERATOM) { + atom->delete_callback(id,0); + if (restart_peratom) atom->delete_callback(id,1); + } memory->destroy(vstore); memory->destroy(astore); @@ -186,7 +229,8 @@ int FixStore::size_restart(int nlocal) 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; } - diff --git a/src/fix_store.h b/src/fix_store.h index 64b714c3da..459e3f05c1 100644 --- a/src/fix_store.h +++ b/src/fix_store.h @@ -26,8 +26,10 @@ namespace LAMMPS_NS { class FixStore : public Fix { public: - double *vstore; // vector storage if nvalues = 1 - double **astore; // array storage if nvalues > 1 + int nrow,ncol; // size of global data array + 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(); @@ -45,8 +47,8 @@ class FixStore : public Fix { double memory_usage(); private: - int nvalues; // total # of values per atom - int vecflag; // 1 if nvalues = 1 + int flavor; // GLOBAL or PERATOM + int vecflag; // 1 if ncol=1 or nvalues=1 }; } diff --git a/src/variable.cpp b/src/variable.cpp index 5db4ee29c9..d024223beb 100644 --- a/src/variable.cpp +++ b/src/variable.cpp @@ -4480,13 +4480,14 @@ VarReader::VarReader(LAMMPS *lmp, char *name, char *file, int flag) : strcpy(id_fix,name); strcat(id_fix,"_VARIABLE_STORE"); - char **newarg = new char*[5]; + char **newarg = new char*[6]; newarg[0] = id_fix; newarg[1] = (char *) "all"; newarg[2] = (char *) "STORE"; - newarg[3] = (char *) "0"; - newarg[4] = (char *) "1"; - modify->add_fix(5,newarg); + newarg[3] = (char *) "peratom"; + newarg[4] = (char *) "0"; + newarg[5] = (char *) "1"; + modify->add_fix(6,newarg); fixstore = (FixStore *) modify->fix[modify->nfix-1]; delete [] newarg;