diff --git a/src/compute_displace_atom.cpp b/src/compute_displace_atom.cpp index bf5848ebf2..c7c1e89c8a 100644 --- a/src/compute_displace_atom.cpp +++ b/src/compute_displace_atom.cpp @@ -35,19 +35,23 @@ ComputeDisplaceAtom::ComputeDisplaceAtom(LAMMPS *lmp, int narg, char **arg) : peratom_flag = 1; size_peratom_cols = 4; - // create a new fix store/coord style - // id = compute-ID + store_coord, fix group = compute group + // create a new fix store style + // id = compute-ID + store, fix group = compute group - int n = strlen(id) + strlen("_store_coord") + 1; + int n = strlen(id) + strlen("_store") + 1; id_fix = new char[n]; strcpy(id_fix,id); - strcat(id_fix,"_store_coord"); + strcat(id_fix,"_store"); - char **newarg = new char*[3]; + char **newarg = new char*[7]; newarg[0] = id_fix; newarg[1] = group->names[igroup]; - newarg[2] = (char *) "store/coord"; - modify->add_fix(3,newarg); + newarg[2] = (char *) "store"; + newarg[3] = (char *) "0"; + newarg[4] = (char *) "xu"; + newarg[5] = (char *) "yu"; + newarg[6] = (char *) "zu"; + modify->add_fix(7,newarg); delete [] newarg; nmax = 0; diff --git a/src/compute_msd.cpp b/src/compute_msd.cpp index c769891c0d..4d7f6639ad 100644 --- a/src/compute_msd.cpp +++ b/src/compute_msd.cpp @@ -49,22 +49,26 @@ ComputeMSD::ComputeMSD(LAMMPS *lmp, int narg, char **arg) : } else error->all("Illegal compute msd command"); } - // create a new fix store/coord style with or without com keyword - // id = compute-ID + store_coord, fix group = compute group + // create a new fix store style with or without com keyword + // id = compute-ID + store, fix group = compute group - int n = strlen(id) + strlen("_store_coord") + 1; + int n = strlen(id) + strlen("_store") + 1; id_fix = new char[n]; strcpy(id_fix,id); - strcat(id_fix,"_store_coord"); + strcat(id_fix,"_store"); - char **newarg = new char*[5]; + char **newarg = new char*[9]; newarg[0] = id_fix; newarg[1] = group->names[igroup]; - newarg[2] = (char *) "store/coord"; - newarg[3] = (char *) "com"; - newarg[4] = (char *) "yes"; - if (comflag) modify->add_fix(5,newarg); - else modify->add_fix(3,newarg); + newarg[2] = (char *) "store"; + newarg[3] = (char *) "0"; + newarg[4] = (char *) "xu"; + newarg[5] = (char *) "yu"; + newarg[6] = (char *) "zu"; + newarg[7] = (char *) "com"; + newarg[8] = (char *) "yes"; + if (comflag) modify->add_fix(9,newarg); + else modify->add_fix(7,newarg); delete [] newarg; vector = new double[4]; diff --git a/src/compute_property_atom.cpp b/src/compute_property_atom.cpp index a8d44fd3a6..659057fc35 100644 --- a/src/compute_property_atom.cpp +++ b/src/compute_property_atom.cpp @@ -21,15 +21,6 @@ using namespace LAMMPS_NS; -// customize by adding keyword -// same as in dump_custom.cpp - -enum{ID,MOL,TYPE,MASS, - X,Y,Z,XS,YS,ZS,XSTRI,YSTRI,ZSTRI,XU,YU,ZU,XUTRI,YUTRI,ZUTRI,IX,IY,IZ, - VX,VY,VZ,FX,FY,FZ, - Q,MUX,MUY,MUZ,RADIUS,OMEGAX,OMEGAY,OMEGAZ,ANGMOMX,ANGMOMY,ANGMOMZ, - QUATW,QUATI,QUATJ,QUATK,TQX,TQY,TQZ}; - /* ---------------------------------------------------------------------- */ ComputePropertyAtom::ComputePropertyAtom(LAMMPS *lmp, int narg, char **arg) : @@ -42,6 +33,9 @@ ComputePropertyAtom::ComputePropertyAtom(LAMMPS *lmp, int narg, char **arg) : if (nvalues == 1) size_peratom_cols = 0; else size_peratom_cols = nvalues; + // parse input values + // customize a new keyword by adding to if statement + pack_choice = new FnPtrPack[nvalues]; int i; @@ -249,7 +243,7 @@ void ComputePropertyAtom::compute_peratom() buf = vector; (this->*pack_choice[0])(0); } else { - if (array) buf = &array[0][0]; + buf = &array[0][0]; for (int n = 0; n < nvalues; n++) (this->*pack_choice[n])(n); } diff --git a/src/fix_store.cpp b/src/fix_store.cpp new file mode 100644 index 0000000000..2c675bf0fe --- /dev/null +++ b/src/fix_store.cpp @@ -0,0 +1,1330 @@ +/* ---------------------------------------------------------------------- + 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 + certain rights in this software. This software is distributed under + the GNU General Public License. + + See the README file in the top-level LAMMPS directory. +------------------------------------------------------------------------- */ + +#include "stdlib.h" +#include "string.h" +#include "fix_store.h" +#include "atom.h" +#include "domain.h" +#include "update.h" +#include "group.h" +#include "modify.h" +#include "compute.h" +#include "fix.h" +#include "input.h" +#include "variable.h" +#include "memory.h" +#include "error.h" + +using namespace LAMMPS_NS; + +enum{KEYWORD,COMPUTE,FIX,VARIABLE}; + +#define INVOKED_PERATOM 8 + +/* ---------------------------------------------------------------------- */ + +FixStore::FixStore(LAMMPS *lmp, int narg, char **arg) : + Fix(lmp, narg, arg) +{ + if (narg < 5) error->all("Illegal fix store command"); + + restart_peratom = 1; + peratom_freq = 1; + + nevery = atoi(arg[3]); + if (nevery < 0) error->all("Illegal fix store command"); + + // parse values until one isn't recognized + // customize a new keyword by adding to if statement + + pack_choice = new FnPtrPack[narg-4]; + which = new int[narg-4]; + argindex = new int[narg-4]; + ids = new char*[narg-4]; + value2index = new int[narg-4]; + nvalues = 0; + cfv_any = 0; + + int iarg = 4; + while (iarg < narg) { + which[nvalues] = KEYWORD; + ids[nvalues] = NULL; + + if (strcmp(arg[iarg],"id") == 0) { + pack_choice[nvalues++] = &FixStore::pack_id; + } else if (strcmp(arg[iarg],"mol") == 0) { + if (!atom->molecule_flag) + error->all("Fix store for atom property that isn't allocated"); + pack_choice[nvalues++] = &FixStore::pack_molecule; + } else if (strcmp(arg[iarg],"type") == 0) { + pack_choice[nvalues++] = &FixStore::pack_type; + } else if (strcmp(arg[iarg],"mass") == 0) { + pack_choice[nvalues++] = &FixStore::pack_mass; + + } else if (strcmp(arg[iarg],"x") == 0) { + pack_choice[nvalues++] = &FixStore::pack_x; + } else if (strcmp(arg[iarg],"y") == 0) { + pack_choice[nvalues++] = &FixStore::pack_y; + } else if (strcmp(arg[iarg],"z") == 0) { + pack_choice[nvalues++] = &FixStore::pack_z; + } else if (strcmp(arg[iarg],"xs") == 0) { + if (domain->triclinic) + pack_choice[nvalues++] = &FixStore::pack_xs_triclinic; + else pack_choice[nvalues++] = &FixStore::pack_xs; + } else if (strcmp(arg[iarg],"ys") == 0) { + if (domain->triclinic) + pack_choice[nvalues++] = &FixStore::pack_ys_triclinic; + else pack_choice[nvalues++] = &FixStore::pack_ys; + } else if (strcmp(arg[iarg],"zs") == 0) { + if (domain->triclinic) + pack_choice[nvalues++] = &FixStore::pack_zs_triclinic; + else pack_choice[nvalues++] = &FixStore::pack_zs; + } else if (strcmp(arg[iarg],"xu") == 0) { + if (domain->triclinic) + pack_choice[nvalues++] = &FixStore::pack_xu_triclinic; + else pack_choice[nvalues++] = &FixStore::pack_xu; + } else if (strcmp(arg[iarg],"yu") == 0) { + if (domain->triclinic) + pack_choice[nvalues++] = &FixStore::pack_yu_triclinic; + else pack_choice[nvalues++] = &FixStore::pack_yu; + } else if (strcmp(arg[iarg],"zu") == 0) { + if (domain->triclinic) + pack_choice[nvalues++] = &FixStore::pack_zu_triclinic; + else pack_choice[nvalues++] = &FixStore::pack_zu; + } else if (strcmp(arg[iarg],"ix") == 0) { + pack_choice[nvalues++] = &FixStore::pack_ix; + } else if (strcmp(arg[iarg],"iy") == 0) { + pack_choice[nvalues++] = &FixStore::pack_iy; + } else if (strcmp(arg[iarg],"iz") == 0) { + pack_choice[nvalues++] = &FixStore::pack_iz; + + } else if (strcmp(arg[iarg],"vx") == 0) { + pack_choice[nvalues++] = &FixStore::pack_vx; + } else if (strcmp(arg[iarg],"vy") == 0) { + pack_choice[nvalues++] = &FixStore::pack_vy; + } else if (strcmp(arg[iarg],"vz") == 0) { + pack_choice[nvalues++] = &FixStore::pack_vz; + } else if (strcmp(arg[iarg],"fx") == 0) { + pack_choice[nvalues++] = &FixStore::pack_fx; + } else if (strcmp(arg[iarg],"fy") == 0) { + pack_choice[nvalues++] = &FixStore::pack_fy; + } else if (strcmp(arg[iarg],"fz") == 0) { + pack_choice[nvalues++] = &FixStore::pack_fz; + + } else if (strcmp(arg[iarg],"q") == 0) { + if (!atom->q_flag) + error->all("Fix store for atom property that isn't allocated"); + pack_choice[nvalues++] = &FixStore::pack_q; + } else if (strcmp(arg[iarg],"mux") == 0) { + if (!atom->mu_flag) + error->all("Fix store for atom property that isn't allocated"); + pack_choice[nvalues++] = &FixStore::pack_mux; + } else if (strcmp(arg[iarg],"muy") == 0) { + if (!atom->mu_flag) + error->all("Fix store for atom property that isn't allocated"); + pack_choice[nvalues++] = &FixStore::pack_muy; + } else if (strcmp(arg[iarg],"muz") == 0) { + if (!atom->mu_flag) + error->all("Fix store for atom property that isn't allocated"); + pack_choice[nvalues++] = &FixStore::pack_muz; + + } else if (strcmp(arg[iarg],"radius") == 0) { + if (!atom->radius_flag) + error->all("Fix store for atom property that isn't allocated"); + pack_choice[nvalues++] = &FixStore::pack_radius; + } else if (strcmp(arg[iarg],"omegax") == 0) { + if (!atom->omega_flag) + error->all("Fix store for atom property that isn't allocated"); + pack_choice[nvalues++] = &FixStore::pack_omegax; + } else if (strcmp(arg[iarg],"omegay") == 0) { + if (!atom->omega_flag) + error->all("Fix store for atom property that isn't allocated"); + pack_choice[nvalues++] = &FixStore::pack_omegay; + } else if (strcmp(arg[iarg],"omegaz") == 0) { + if (!atom->omega_flag) + error->all("Fix store for atom property that isn't allocated"); + pack_choice[nvalues++] = &FixStore::pack_omegaz; + } else if (strcmp(arg[iarg],"angmomx") == 0) { + if (!atom->angmom_flag) + error->all("Fix store for atom property that isn't allocated"); + pack_choice[nvalues++] = &FixStore::pack_angmomx; + } else if (strcmp(arg[iarg],"angmomy") == 0) { + if (!atom->angmom_flag) + error->all("Fix store for atom property that isn't allocated"); + pack_choice[nvalues++] = &FixStore::pack_angmomy; + } else if (strcmp(arg[iarg],"angmomz") == 0) { + if (!atom->angmom_flag) + error->all("Fix store for atom property that isn't allocated"); + pack_choice[nvalues++] = &FixStore::pack_angmomz; + + } else if (strcmp(arg[iarg],"quatw") == 0) { + if (!atom->quat_flag) + error->all("Fix store for atom property that isn't allocated"); + pack_choice[nvalues++] = &FixStore::pack_quatw; + } else if (strcmp(arg[iarg],"quati") == 0) { + if (!atom->quat_flag) + error->all("Fix store for atom property that isn't allocated"); + pack_choice[nvalues++] = &FixStore::pack_quati; + } else if (strcmp(arg[iarg],"quatj") == 0) { + if (!atom->quat_flag) + error->all("Fix store for atom property that isn't allocated"); + pack_choice[nvalues++] = &FixStore::pack_quatj; + } else if (strcmp(arg[iarg],"quatk") == 0) { + if (!atom->quat_flag) + error->all("Fix store for atom property that isn't allocated"); + pack_choice[nvalues++] = &FixStore::pack_quatk; + } else if (strcmp(arg[iarg],"tqx") == 0) { + if (!atom->torque_flag) + error->all("Fix store for atom property that isn't allocated"); + pack_choice[nvalues++] = &FixStore::pack_tqx; + } else if (strcmp(arg[iarg],"tqy") == 0) { + if (!atom->torque_flag) + error->all("Fix store for atom property that isn't allocated"); + pack_choice[nvalues++] = &FixStore::pack_tqy; + } else if (strcmp(arg[iarg],"tqz") == 0) { + if (!atom->torque_flag) + error->all("Fix store for atom property that isn't allocated"); + pack_choice[nvalues++] = &FixStore::pack_tqz; + + } else if (strncmp(arg[iarg],"c_",2) == 0 || + strncmp(arg[iarg],"f_",2) == 0 || + strncmp(arg[iarg],"v_",2) == 0) { + cfv_any = 1; + if (arg[iarg][0] == 'c') which[nvalues] = COMPUTE; + else if (arg[iarg][0] == 'f') which[nvalues] = FIX; + else if (arg[iarg][0] == 'v') which[nvalues] = VARIABLE; + + int n = strlen(arg[iarg]); + char *suffix = new char[n]; + strcpy(suffix,&arg[iarg][2]); + + char *ptr = strchr(suffix,'['); + if (ptr) { + if (suffix[strlen(suffix)-1] != ']') + error->all("Illegal fix store command"); + argindex[nvalues] = atoi(ptr+1); + *ptr = '\0'; + } else argindex[nvalues] = 0; + + n = strlen(suffix) + 1; + ids[nvalues] = new char[n]; + strcpy(ids[nvalues],suffix); + nvalues++; + delete [] suffix; + + } else break; + + iarg++; + } + + // optional args + + int comflag = 0; + + while (iarg < narg) { + if (strcmp(arg[iarg],"com") == 0) { + if (iarg+2 > narg) error->all("Illegal fix store command"); + if (strcmp(arg[iarg+1],"no") == 0) comflag = 0; + else if (strcmp(arg[iarg+1],"yes") == 0) comflag = 1; + else error->all("Illegal fix store command"); + iarg += 2; + } else error->all("Illegal fix store command"); + } + + // error check + + for (int i = 0; i < nvalues; i++) { + if (which[i] == COMPUTE) { + int icompute = modify->find_compute(ids[i]); + if (icompute < 0) + error->all("Compute ID for fix store does not exist"); + if (modify->compute[icompute]->peratom_flag == 0) + error->all("Fix store compute does not calculate per-atom values"); + if (argindex[i] == 0 && + modify->compute[icompute]->size_peratom_cols != 0) + error->all("Fix store compute does not " + "calculate a per-atom vector"); + if (argindex[i] && modify->compute[icompute]->size_peratom_cols == 0) + error->all("Fix store compute does not " + "calculate a per-atom array"); + if (argindex[i] && + argindex[i] > modify->compute[icompute]->size_peratom_cols) + error->all("Fix store compute array is accessed out-of-range"); + + } else if (which[i] == FIX) { + int ifix = modify->find_fix(ids[i]); + if (ifix < 0) + error->all("Fix ID for fix store does not exist"); + if (modify->fix[ifix]->peratom_flag == 0) + error->all("Fix store fix does not calculate per-atom values"); + if (argindex[i] == 0 && modify->fix[ifix]->size_peratom_cols != 0) + error->all("Fix store fix does not calculate a per-atom vector"); + if (argindex[i] && modify->fix[ifix]->size_peratom_cols == 0) + error->all("Fix store fix does not calculate a per-atom array"); + if (argindex[i] && argindex[i] > modify->fix[ifix]->size_peratom_cols) + error->all("Fix store fix array is accessed out-of-range"); + if (nevery % modify->fix[ifix]->peratom_freq) + error->all("Fix for fix store not computed at compatible time"); + + } else if (which[i] == VARIABLE) { + int ivariable = input->variable->find(ids[i]); + if (ivariable < 0) + error->all("Variable name for fix store does not exist"); + if (input->variable->atomstyle(ivariable) == 0) + error->all("Fix store variable is not atom-style variable"); + } + } + + // this fix produces either a per-atom vector or array + + peratom_flag = 1; + if (nvalues == 1) size_peratom_cols = 0; + else size_peratom_cols = nvalues; + + // perform initial allocation of atom-based array + // register with Atom class + + values = NULL; + grow_arrays(atom->nmax); + atom->add_callback(0); + atom->add_callback(1); + + // zero the array since dump may access it on timestep 0 + // zero the array since a variable may access it before first run + + int nlocal = atom->nlocal; + for (int i = 0; i < nlocal; i++) + for (int m = 0; m < nvalues; m++) + values[i][m] = 0.0; + + // store current values for keywords but not for compute, fix, variable + + kflag = 1; + cfv_flag = 0; + end_of_step(); + firstflag = 1; +} + +/* ---------------------------------------------------------------------- */ + +FixStore::~FixStore() +{ + // unregister callbacks to this fix from Atom class + + atom->delete_callback(id,0); + atom->delete_callback(id,1); + + delete [] which; + delete [] argindex; + for (int m = 0; m < nvalues; m++) delete [] ids[m]; + delete [] ids; + delete [] value2index; + delete [] pack_choice; + + memory->destroy_2d_double_array(values); +} + +/* ---------------------------------------------------------------------- */ + +int FixStore::setmask() +{ + int mask = 0; + if (nevery) mask |= END_OF_STEP; + return mask; +} + +/* ---------------------------------------------------------------------- */ + +void FixStore::init() +{ + // set indices and check validity of all computes,fixes,variables + + for (int m = 0; m < nvalues; m++) { + if (which[m] == COMPUTE) { + int icompute = modify->find_compute(ids[m]); + if (icompute < 0) + error->all("Compute ID for fix ave/atom does not exist"); + value2index[m] = icompute; + + } else if (which[m] == FIX) { + int ifix = modify->find_fix(ids[m]); + if (ifix < 0) + error->all("Fix ID for fix ave/atom does not exist"); + value2index[m] = ifix; + + } else if (which[m] == VARIABLE) { + int ivariable = input->variable->find(ids[m]); + if (ivariable < 0) + error->all("Variable name for fix ave/atom does not exist"); + value2index[m] = ivariable; + } + } +} + +/* ---------------------------------------------------------------------- */ + +void FixStore::setup(int vflag) +{ + // if first invocation, store current values for compute, fix, variable + + if (firstflag) { + kflag = 0; + cfv_flag = 1; + end_of_step(); + firstflag = 0; + kflag = cfv_flag = 1; + } +} + +/* ---------------------------------------------------------------------- */ + +void FixStore::end_of_step() +{ + int i,j,n; + + // compute com if comflag set + + if (comflag) { + double masstotal = group->mass(igroup); + group->xcm(igroup,masstotal,cm); + } + + // if any compute/fix/variable and nevery, wrap with clear/add + + if (cfv_any && nevery) modify->clearstep_compute(); + + // fill vector or array with per-atom values + + buf = &values[0][0]; + for (int m = 0; m < nvalues; m++) { + if (which[m] == KEYWORD && kflag) (this->*pack_choice[m])(m); + + else if (cfv_flag) { + n = value2index[m]; + j = argindex[m]; + + int *mask = atom->mask; + int nlocal = atom->nlocal; + + // invoke compute if not previously invoked + + if (which[m] == COMPUTE) { + Compute *compute = modify->compute[n]; + if (!(compute->invoked_flag & INVOKED_PERATOM)) { + compute->compute_peratom(); + compute->invoked_flag |= INVOKED_PERATOM; + } + + if (j == 0) { + double *compute_vector = compute->vector_atom; + for (i = 0; i < nlocal; i++) + if (mask[i] & groupbit) values[i][m] += compute_vector[i]; + } else { + int jm1 = j - 1; + double **compute_array = compute->array_atom; + for (i = 0; i < nlocal; i++) + if (mask[i] & groupbit) values[i][m] += compute_array[i][jm1]; + } + + // access fix fields, guaranteed to be ready + + } else if (which[m] == FIX) { + if (j == 0) { + double *fix_vector = modify->fix[n]->vector_atom; + for (i = 0; i < nlocal; i++) + if (mask[i] & groupbit) values[i][m] += fix_vector[i]; + } else { + int jm1 = j - 1; + double **fix_array = modify->fix[n]->array_atom; + for (i = 0; i < nlocal; i++) + if (mask[i] & groupbit) values[i][m] += fix_array[i][jm1]; + } + + // evaluate atom-style variable + + } else if (which[m] == VARIABLE) + input->variable->compute_atom(n,igroup,&values[0][m],nvalues,1); + } + } + + // if any compute/fix/variable and nevery, wrap with clear/add + + if (cfv_any && nevery) { + int nextstep = (update->ntimestep/nevery)*nevery + nevery; + modify->addstep_compute(nextstep); + } +} + +/* ---------------------------------------------------------------------- + memory usage of local atom-based array +------------------------------------------------------------------------- */ + +double FixStore::memory_usage() +{ + double bytes = atom->nmax*nvalues * sizeof(double); + return bytes; +} + +/* ---------------------------------------------------------------------- + allocate atom-based array +------------------------------------------------------------------------- */ + +void FixStore::grow_arrays(int nmax) +{ + values = memory->grow_2d_double_array(values,nmax,3,"fix_store:values"); + if (nvalues == 0) vector_atom = &values[0][0]; + else array_atom = values; +} + +/* ---------------------------------------------------------------------- + copy values within local atom-based array +------------------------------------------------------------------------- */ + +void FixStore::copy_arrays(int i, int j) +{ + for (int m = 0; m < nvalues; m++) values[j][m] = values[i][m]; +} + +/* ---------------------------------------------------------------------- + pack values in local atom-based array for exchange with another proc +------------------------------------------------------------------------- */ + +int FixStore::pack_exchange(int i, double *buf) +{ + for (int m = 0; m < nvalues; m++) buf[m] = values[i][m]; + return nvalues; +} + +/* ---------------------------------------------------------------------- + unpack values in local atom-based array from exchange with another proc +------------------------------------------------------------------------- */ + +int FixStore::unpack_exchange(int nlocal, double *buf) +{ + for (int m = 0; m < nvalues; m++) values[nlocal][m] = buf[m]; + return nvalues; +} + +/* ---------------------------------------------------------------------- + pack values in local atom-based arrays for restart file +------------------------------------------------------------------------- */ + +int FixStore::pack_restart(int i, double *buf) +{ + buf[0] = nvalues+1; + for (int m = 0; m < nvalues; m++) buf[m+1] = values[i][m]; + return nvalues+1; +} + +/* ---------------------------------------------------------------------- + unpack values from atom->extra array to restart the fix +------------------------------------------------------------------------- */ + +void FixStore::unpack_restart(int nlocal, int nth) +{ + double **extra = atom->extra; + + // skip to Nth set of extra values + + int m = 0; + for (int i = 0; i < nth; i++) m += static_cast (extra[nlocal][m]); + m++; + + for (int i = 0; i < nvalues; i++) values[nlocal][i] = extra[nlocal][m++]; +} + +/* ---------------------------------------------------------------------- + maxsize of any atom's restart data +------------------------------------------------------------------------- */ + +int FixStore::maxsize_restart() +{ + return nvalues+1; +} + +/* ---------------------------------------------------------------------- + size of atom nlocal's restart data +------------------------------------------------------------------------- */ + +int FixStore::size_restart(int nlocal) +{ + return nvalues+1; +} + +/* ---------------------------------------------------------------------- + one method for every keyword fix store can archive + the atom property is packed into buf starting at n with stride nvalues + customize a new keyword by adding a method +------------------------------------------------------------------------- */ + +/* ---------------------------------------------------------------------- */ + +void FixStore::pack_id(int n) +{ + int *tag = atom->tag; + int *mask = atom->mask; + int nlocal = atom->nlocal; + + for (int i = 0; i < nlocal; i++) { + if (mask[i] & groupbit) buf[n] = tag[i]; + else buf[n] = 0.0; + n += nvalues; + } +} + +/* ---------------------------------------------------------------------- */ + +void FixStore::pack_molecule(int n) +{ + int *molecule = atom->molecule; + int *mask = atom->mask; + int nlocal = atom->nlocal; + + for (int i = 0; i < nlocal; i++) { + if (mask[i] & groupbit) buf[n] = molecule[i]; + else buf[n] = 0.0; + n += nvalues; + } +} + +/* ---------------------------------------------------------------------- */ + +void FixStore::pack_type(int n) +{ + int *type = atom->type; + int *mask = atom->mask; + int nlocal = atom->nlocal; + + for (int i = 0; i < nlocal; i++) { + if (mask[i] & groupbit) buf[n] = type[i]; + else buf[n] = 0.0; + n += nvalues; + } +} + +/* ---------------------------------------------------------------------- */ + +void FixStore::pack_mass(int n) +{ + int *type = atom->type; + double *mass = atom->mass; + double *rmass = atom->rmass; + int *mask = atom->mask; + int nlocal = atom->nlocal; + + if (rmass) { + for (int i = 0; i < nlocal; i++) { + if (mask[i] & groupbit) buf[n] = rmass[i]; + else buf[n] = 0.0; + n += nvalues; + } + } else { + for (int i = 0; i < nlocal; i++) { + if (mask[i] & groupbit) buf[n] = mass[type[i]]; + else buf[n] = 0.0; + n += nvalues; + } + } +} + +/* ---------------------------------------------------------------------- */ + +void FixStore::pack_x(int n) +{ + double **x = atom->x; + int *mask = atom->mask; + int nlocal = atom->nlocal; + + for (int i = 0; i < nlocal; i++) { + if (mask[i] & groupbit) buf[n] = x[i][0]; + else buf[n] = 0.0; + n += nvalues; + } +} + +/* ---------------------------------------------------------------------- */ + +void FixStore::pack_y(int n) +{ + double **x = atom->x; + int *mask = atom->mask; + int nlocal = atom->nlocal; + + for (int i = 0; i < nlocal; i++) { + if (mask[i] & groupbit) buf[n] = x[i][1]; + else buf[n] = 0.0; + n += nvalues; + } +} + +/* ---------------------------------------------------------------------- */ + +void FixStore::pack_z(int n) +{ + double **x = atom->x; + int *mask = atom->mask; + int nlocal = atom->nlocal; + + for (int i = 0; i < nlocal; i++) { + if (mask[i] & groupbit) buf[n] = x[i][2]; + else buf[n] = 0.0; + n += nvalues; + } +} + +/* ---------------------------------------------------------------------- */ + +void FixStore::pack_xs(int n) +{ + double **x = atom->x; + int *mask = atom->mask; + int nlocal = atom->nlocal; + + double boxxlo = domain->boxlo[0]; + double invxprd = 1.0/domain->xprd; + + for (int i = 0; i < nlocal; i++) { + if (mask[i] & groupbit) buf[n] = (x[i][0] - boxxlo) * invxprd; + else buf[n] = 0.0; + n += nvalues; + } +} + +/* ---------------------------------------------------------------------- */ + +void FixStore::pack_ys(int n) +{ + double **x = atom->x; + int *mask = atom->mask; + int nlocal = atom->nlocal; + + double boxylo = domain->boxlo[1]; + double invyprd = 1.0/domain->yprd; + + for (int i = 0; i < nlocal; i++) { + if (mask[i] & groupbit) buf[n] = (x[i][1] - boxylo) * invyprd; + else buf[n] = 0.0; + n += nvalues; + } +} + +/* ---------------------------------------------------------------------- */ + +void FixStore::pack_zs(int n) +{ + double **x = atom->x; + int *mask = atom->mask; + int nlocal = atom->nlocal; + + double boxzlo = domain->boxlo[2]; + double invzprd = 1.0/domain->zprd; + + for (int i = 0; i < nlocal; i++) { + if (mask[i] & groupbit) buf[n] = (x[i][2] - boxzlo) * invzprd; + else buf[n] = 0.0; + n += nvalues; + } +} + +/* ---------------------------------------------------------------------- */ + +void FixStore::pack_xs_triclinic(int n) +{ + double **x = atom->x; + int *mask = atom->mask; + int nlocal = atom->nlocal; + + double *boxlo = domain->boxlo; + double *h_inv = domain->h_inv; + + for (int i = 0; i < nlocal; i++) { + if (mask[i] & groupbit) + buf[n] = h_inv[0]*(x[i][0]-boxlo[0]) + + h_inv[5]*(x[i][1]-boxlo[1]) + h_inv[4]*(x[i][2]-boxlo[2]); + else buf[n] = 0.0; + n += nvalues; + } +} + +/* ---------------------------------------------------------------------- */ + +void FixStore::pack_ys_triclinic(int n) +{ + double **x = atom->x; + int *mask = atom->mask; + int nlocal = atom->nlocal; + + double *boxlo = domain->boxlo; + double *h_inv = domain->h_inv; + + for (int i = 0; i < nlocal; i++) { + if (mask[i] & groupbit) + buf[n] = h_inv[1]*(x[i][1]-boxlo[1]) + h_inv[3]*(x[i][2]-boxlo[2]); + else buf[n] = 0.0; + n += nvalues; + } +} + +/* ---------------------------------------------------------------------- */ + +void FixStore::pack_zs_triclinic(int n) +{ + double **x = atom->x; + int *mask = atom->mask; + int nlocal = atom->nlocal; + + double *boxlo = domain->boxlo; + double *h_inv = domain->h_inv; + + for (int i = 0; i < nlocal; i++) { + if (mask[i] & groupbit) + buf[n] = h_inv[2]*(x[i][2]-boxlo[2]); + else buf[n] = 0.0; + n += nvalues; + } +} + +/* ---------------------------------------------------------------------- */ + +void FixStore::pack_xu(int n) +{ + double **x = atom->x; + int *image = atom->image; + int *mask = atom->mask; + int nlocal = atom->nlocal; + + double xprd = domain->xprd; + + for (int i = 0; i < nlocal; i++) { + if (mask[i] & groupbit) { + buf[n] = x[i][0] + ((image[i] & 1023) - 512) * xprd; + if (comflag) buf[n] -= cm[0]; + } else buf[n] = 0.0; + n += nvalues; + } +} + +/* ---------------------------------------------------------------------- */ + +void FixStore::pack_yu(int n) +{ + double **x = atom->x; + int *image = atom->image; + int *mask = atom->mask; + int nlocal = atom->nlocal; + + double yprd = domain->yprd; + + for (int i = 0; i < nlocal; i++) { + if (mask[i] & groupbit) { + buf[n] = x[i][1] + ((image[i] >> 10 & 1023) - 512) * yprd; + if (comflag) buf[n] -= cm[1]; + } else buf[n] = 0.0; + n += nvalues; + } +} + +/* ---------------------------------------------------------------------- */ + +void FixStore::pack_zu(int n) +{ + double **x = atom->x; + int *image = atom->image; + int *mask = atom->mask; + int nlocal = atom->nlocal; + + double zprd = domain->zprd; + + for (int i = 0; i < nlocal; i++) { + if (mask[i] & groupbit) { + buf[n] = x[i][2] + ((image[i] >> 20) - 512) * zprd; + if (comflag) buf[n] -= cm[2]; + } else buf[n] = 0.0; + n += nvalues; + } +} + +/* ---------------------------------------------------------------------- */ + +void FixStore::pack_xu_triclinic(int n) +{ + double **x = atom->x; + int *image = atom->image; + int *mask = atom->mask; + int nlocal = atom->nlocal; + + double *h = domain->h; + int xbox,ybox,zbox; + + for (int i = 0; i < nlocal; i++) { + if (mask[i] & groupbit) { + xbox = (image[i] & 1023) - 512; + ybox = (image[i] >> 10 & 1023) - 512; + zbox = (image[i] >> 20) - 512; + buf[n] = x[i][0] + h[0]*xbox + h[5]*ybox + h[4]*zbox; + if (comflag) buf[n] -= cm[0]; + } else buf[n] = 0.0; + n += nvalues; + } +} + +/* ---------------------------------------------------------------------- */ + +void FixStore::pack_yu_triclinic(int n) +{ + double **x = atom->x; + int *image = atom->image; + int *mask = atom->mask; + int nlocal = atom->nlocal; + + double *h = domain->h; + int ybox,zbox; + + for (int i = 0; i < nlocal; i++) { + if (mask[i] & groupbit) { + ybox = (image[i] >> 10 & 1023) - 512; + zbox = (image[i] >> 20) - 512; + buf[n] = x[i][1] + h[1]*ybox + h[3]*zbox; + if (comflag) buf[n] -= cm[1]; + } else buf[n] = 0.0; + n += nvalues; + } +} + +/* ---------------------------------------------------------------------- */ + +void FixStore::pack_zu_triclinic(int n) +{ + double **x = atom->x; + int *image = atom->image; + int *mask = atom->mask; + int nlocal = atom->nlocal; + + double *h = domain->h; + int zbox; + + for (int i = 0; i < nlocal; i++) { + if (mask[i] & groupbit) { + zbox = (image[i] >> 20) - 512; + buf[n] = x[i][2] + h[2]*zbox; + if (comflag) buf[n] -= cm[2]; + } else buf[n] = 0.0; + n += nvalues; + } +} + +/* ---------------------------------------------------------------------- */ + +void FixStore::pack_ix(int n) +{ + int *image = atom->image; + int *mask = atom->mask; + int nlocal = atom->nlocal; + + for (int i = 0; i < nlocal; i++) { + if (mask[i] & groupbit) buf[n] = (image[i] & 1023) - 512; + else buf[n] = 0.0; + n += nvalues; + } +} + +/* ---------------------------------------------------------------------- */ + +void FixStore::pack_iy(int n) +{ + int *image = atom->image; + int *mask = atom->mask; + int nlocal = atom->nlocal; + + for (int i = 0; i < nlocal; i++) { + if (mask[i] & groupbit) buf[n] = (image[i] >> 10 & 1023) - 512; + else buf[n] = 0.0; + n += nvalues; + } +} + +/* ---------------------------------------------------------------------- */ + +void FixStore::pack_iz(int n) +{ + int *image = atom->image; + int *mask = atom->mask; + int nlocal = atom->nlocal; + + for (int i = 0; i < nlocal; i++) { + if (mask[i] & groupbit) buf[n] = (image[i] >> 20) - 512; + else buf[n] = 0.0; + n += nvalues; + } +} + +/* ---------------------------------------------------------------------- */ + +void FixStore::pack_vx(int n) +{ + double **v = atom->v; + int *mask = atom->mask; + int nlocal = atom->nlocal; + + for (int i = 0; i < nlocal; i++) { + if (mask[i] & groupbit) buf[n] = v[i][0]; + else buf[n] = 0.0; + n += nvalues; + } +} + +/* ---------------------------------------------------------------------- */ + +void FixStore::pack_vy(int n) +{ + double **v = atom->v; + int *mask = atom->mask; + int nlocal = atom->nlocal; + + for (int i = 0; i < nlocal; i++) { + if (mask[i] & groupbit) buf[n] = v[i][1]; + else buf[n] = 0.0; + n += nvalues; + } +} + +/* ---------------------------------------------------------------------- */ + +void FixStore::pack_vz(int n) +{ + double **v = atom->v; + int *mask = atom->mask; + int nlocal = atom->nlocal; + + for (int i = 0; i < nlocal; i++) { + if (mask[i] & groupbit) buf[n] = v[i][2]; + else buf[n] = 0.0; + n += nvalues; + } +} + +/* ---------------------------------------------------------------------- */ + +void FixStore::pack_fx(int n) +{ + double **f = atom->f; + int *mask = atom->mask; + int nlocal = atom->nlocal; + + for (int i = 0; i < nlocal; i++) { + if (mask[i] & groupbit) buf[n] = f[i][0]; + else buf[n] = 0.0; + n += nvalues; + } +} + +/* ---------------------------------------------------------------------- */ + +void FixStore::pack_fy(int n) +{ + double **f = atom->f; + int *mask = atom->mask; + int nlocal = atom->nlocal; + + for (int i = 0; i < nlocal; i++) { + if (mask[i] & groupbit) buf[n] = f[i][1]; + else buf[n] = 0.0; + n += nvalues; + } +} + +/* ---------------------------------------------------------------------- */ + +void FixStore::pack_fz(int n) +{ + double **f = atom->f; + int *mask = atom->mask; + int nlocal = atom->nlocal; + + for (int i = 0; i < nlocal; i++) { + if (mask[i] & groupbit) buf[n] = f[i][2]; + else buf[n] = 0.0; + n += nvalues; + } +} + +/* ---------------------------------------------------------------------- */ + +void FixStore::pack_q(int n) +{ + double *q = atom->q; + int *mask = atom->mask; + int nlocal = atom->nlocal; + + for (int i = 0; i < nlocal; i++) { + if (mask[i] & groupbit) buf[n] = q[i]; + else buf[n] = 0.0; + n += nvalues; + } +} + +/* ---------------------------------------------------------------------- */ + +void FixStore::pack_mux(int n) +{ + double **mu = atom->mu; + int *mask = atom->mask; + int nlocal = atom->nlocal; + + for (int i = 0; i < nlocal; i++) { + if (mask[i] & groupbit) buf[n] = mu[i][0]; + else buf[n] = 0.0; + n += nvalues; + } +} + +/* ---------------------------------------------------------------------- */ + +void FixStore::pack_muy(int n) +{ + double **mu = atom->mu; + int *mask = atom->mask; + int nlocal = atom->nlocal; + + for (int i = 0; i < nlocal; i++) { + if (mask[i] & groupbit) buf[n] = mu[i][1]; + else buf[n] = 0.0; + n += nvalues; + } +} + +/* ---------------------------------------------------------------------- */ + +void FixStore::pack_muz(int n) +{ + double **mu = atom->mu; + int *mask = atom->mask; + int nlocal = atom->nlocal; + + for (int i = 0; i < nlocal; i++) { + if (mask[i] & groupbit) buf[n] = mu[i][2]; + else buf[n] = 0.0; + n += nvalues; + } +} + +/* ---------------------------------------------------------------------- */ + +void FixStore::pack_radius(int n) +{ + double *radius = atom->radius; + int *mask = atom->mask; + int nlocal = atom->nlocal; + + for (int i = 0; i < nlocal; i++) { + if (mask[i] & groupbit) buf[n] = radius[i]; + else buf[n] = 0.0; + n += nvalues; + } +} + +/* ---------------------------------------------------------------------- */ + +void FixStore::pack_omegax(int n) +{ + double **omega = atom->omega; + int *mask = atom->mask; + int nlocal = atom->nlocal; + + for (int i = 0; i < nlocal; i++) { + if (mask[i] & groupbit) buf[n] = omega[i][0]; + else buf[n] = 0.0; + n += nvalues; + } +} + +/* ---------------------------------------------------------------------- */ + +void FixStore::pack_omegay(int n) +{ + double **omega = atom->omega; + int *mask = atom->mask; + int nlocal = atom->nlocal; + + for (int i = 0; i < nlocal; i++) { + if (mask[i] & groupbit) buf[n] = omega[i][1]; + else buf[n] = 0.0; + n += nvalues; + } +} + +/* ---------------------------------------------------------------------- */ + +void FixStore::pack_omegaz(int n) +{ + double **omega = atom->omega; + int *mask = atom->mask; + int nlocal = atom->nlocal; + + for (int i = 0; i < nlocal; i++) { + if (mask[i] & groupbit) buf[n] = omega[i][2]; + else buf[n] = 0.0; + n += nvalues; + } +} + +/* ---------------------------------------------------------------------- */ + +void FixStore::pack_angmomx(int n) +{ + double **angmom = atom->angmom; + int *mask = atom->mask; + int nlocal = atom->nlocal; + + for (int i = 0; i < nlocal; i++) { + if (mask[i] & groupbit) buf[n] = angmom[i][0]; + else buf[n] = 0.0; + n += nvalues; + } +} + +/* ---------------------------------------------------------------------- */ + +void FixStore::pack_angmomy(int n) +{ + double **angmom = atom->angmom; + int *mask = atom->mask; + int nlocal = atom->nlocal; + + for (int i = 0; i < nlocal; i++) { + if (mask[i] & groupbit) buf[n] = angmom[i][1]; + else buf[n] = 0.0; + n += nvalues; + } +} + +/* ---------------------------------------------------------------------- */ + +void FixStore::pack_angmomz(int n) +{ + double **angmom = atom->angmom; + int *mask = atom->mask; + int nlocal = atom->nlocal; + + for (int i = 0; i < nlocal; i++) { + if (mask[i] & groupbit) buf[n] = angmom[i][2]; + else buf[n] = 0.0; + n += nvalues; + } +} + +/* ---------------------------------------------------------------------- */ + +void FixStore::pack_quatw(int n) +{ + double **quat = atom->quat; + int *mask = atom->mask; + int nlocal = atom->nlocal; + + for (int i = 0; i < nlocal; i++) { + if (mask[i] & groupbit) buf[n] = quat[i][0]; + else buf[n] = 0.0; + n += nvalues; + } +} + +/* ---------------------------------------------------------------------- */ + +void FixStore::pack_quati(int n) +{ + double **quat = atom->quat; + int *mask = atom->mask; + int nlocal = atom->nlocal; + + for (int i = 0; i < nlocal; i++) { + if (mask[i] & groupbit) buf[n] = quat[i][1]; + else buf[n] = 0.0; + n += nvalues; + } +} + +/* ---------------------------------------------------------------------- */ + +void FixStore::pack_quatj(int n) +{ + double **quat = atom->quat; + int *mask = atom->mask; + int nlocal = atom->nlocal; + + for (int i = 0; i < nlocal; i++) { + if (mask[i] & groupbit) buf[n] = quat[i][2]; + else buf[n] = 0.0; + n += nvalues; + } +} + +/* ---------------------------------------------------------------------- */ + +void FixStore::pack_quatk(int n) +{ + double **quat = atom->quat; + int *mask = atom->mask; + int nlocal = atom->nlocal; + + for (int i = 0; i < nlocal; i++) { + if (mask[i] & groupbit) buf[n] = quat[i][3]; + else buf[n] = 0.0; + n += nvalues; + } +} + +/* ---------------------------------------------------------------------- */ + +void FixStore::pack_tqx(int n) +{ + double **torque = atom->torque; + int *mask = atom->mask; + int nlocal = atom->nlocal; + + for (int i = 0; i < nlocal; i++) { + if (mask[i] & groupbit) buf[n] = torque[i][0]; + else buf[n] = 0.0; + n += nvalues; + } +} + +/* ---------------------------------------------------------------------- */ + +void FixStore::pack_tqy(int n) +{ + double **torque = atom->torque; + int *mask = atom->mask; + int nlocal = atom->nlocal; + + for (int i = 0; i < nlocal; i++) { + if (mask[i] & groupbit) buf[n] = torque[i][1]; + else buf[n] = 0.0; + n += nvalues; + } +} + +/* ---------------------------------------------------------------------- */ + +void FixStore::pack_tqz(int n) +{ + double **torque = atom->torque; + int *mask = atom->mask; + int nlocal = atom->nlocal; + + for (int i = 0; i < nlocal; i++) { + if (mask[i] & groupbit) buf[n] = torque[i][2]; + else buf[n] = 0.0; + n += nvalues; + } +} diff --git a/src/fix_store.h b/src/fix_store.h new file mode 100644 index 0000000000..0719ab834f --- /dev/null +++ b/src/fix_store.h @@ -0,0 +1,115 @@ +/* ---------------------------------------------------------------------- + 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 + certain rights in this software. This software is distributed under + the GNU General Public License. + + See the README file in the top-level LAMMPS directory. +------------------------------------------------------------------------- */ + +#ifdef FIX_CLASS + +FixStyle(store,FixStore) + +#else + +#ifndef LMP_FIX_STORE_H +#define LMP_FIX_STORE_H + +#include "fix.h" + +namespace LAMMPS_NS { + +class FixStore : public Fix { + public: + FixStore(class LAMMPS *, int, char **); + ~FixStore(); + int setmask(); + void init(); + void setup(int); + void end_of_step(); + + double memory_usage(); + void grow_arrays(int); + void copy_arrays(int, int); + int pack_exchange(int, double *); + int unpack_exchange(int, double *); + int pack_restart(int, double *); + void unpack_restart(int, int); + int size_restart(int); + int maxsize_restart(); + + private: + int nvalues; + int *which,*argindex,*value2index; + char **ids; + double **values; // archived atom properties + double *buf; // 1d ptr to values + + int comflag; + double cm[3]; // center of mass + + int kflag,cfv_flag,firstflag; + int cfv_any; // 1 if any compute/fix/variable specified + + typedef void (FixStore::*FnPtrPack)(int); + FnPtrPack *pack_choice; // ptrs to pack functions + + void pack_id(int); + void pack_molecule(int); + void pack_type(int); + void pack_mass(int); + + void pack_x(int); + void pack_y(int); + void pack_z(int); + void pack_xs(int); + void pack_ys(int); + void pack_zs(int); + void pack_xs_triclinic(int); + void pack_ys_triclinic(int); + void pack_zs_triclinic(int); + void pack_xu(int); + void pack_yu(int); + void pack_zu(int); + void pack_xu_triclinic(int); + void pack_yu_triclinic(int); + void pack_zu_triclinic(int); + void pack_ix(int); + void pack_iy(int); + void pack_iz(int); + + void pack_vx(int); + void pack_vy(int); + void pack_vz(int); + void pack_fx(int); + void pack_fy(int); + void pack_fz(int); + void pack_q(int); + void pack_mux(int); + void pack_muy(int); + void pack_muz(int); + void pack_radius(int); + void pack_omegax(int); + void pack_omegay(int); + void pack_omegaz(int); + void pack_angmomx(int); + void pack_angmomy(int); + void pack_angmomz(int); + void pack_quatw(int); + void pack_quati(int); + void pack_quatj(int); + void pack_quatk(int); + void pack_tqx(int); + void pack_tqy(int); + void pack_tqz(int); +}; + +} + +#endif +#endif diff --git a/src/fix_store_coord.cpp b/src/fix_store_coord.cpp deleted file mode 100644 index 8a25140804..0000000000 --- a/src/fix_store_coord.cpp +++ /dev/null @@ -1,212 +0,0 @@ -/* ---------------------------------------------------------------------- - 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 - certain rights in this software. This software is distributed under - the GNU General Public License. - - See the README file in the top-level LAMMPS directory. -------------------------------------------------------------------------- */ - -#include "stdlib.h" -#include "string.h" -#include "fix_store_coord.h" -#include "atom.h" -#include "domain.h" -#include "group.h" -#include "memory.h" -#include "error.h" - -using namespace LAMMPS_NS; - -/* ---------------------------------------------------------------------- */ - -FixStoreCoord::FixStoreCoord(LAMMPS *lmp, int narg, char **arg) : - Fix(lmp, narg, arg) -{ - if (narg < 3) error->all("Illegal fix store/coord command"); - - restart_peratom = 1; - peratom_flag = 1; - size_peratom_cols = 3; - peratom_freq = 1; - - // optional args - - int comflag = 0; - - int iarg = 3; - while (iarg < narg) { - if (strcmp(arg[iarg],"com") == 0) { - if (iarg+2 > narg) error->all("Illegal fix store/coord command"); - if (strcmp(arg[iarg+1],"no") == 0) comflag = 0; - else if (strcmp(arg[iarg+1],"yes") == 0) comflag = 1; - else error->all("Illegal fix store/coord command"); - iarg += 2; - } else error->all("Illegal fix store/coord command"); - } - - // perform initial allocation of atom-based array - // register with Atom class - - xoriginal = NULL; - grow_arrays(atom->nmax); - atom->add_callback(0); - atom->add_callback(1); - - // cm = original center of mass - - double cm[3]; - if (comflag) { - double masstotal = group->mass(igroup); - group->xcm(igroup,masstotal,cm); - } - - // xoriginal = initial unwrapped positions of atoms - // relative to center of mass if comflag is set - - double **x = atom->x; - int *mask = atom->mask; - int *image = atom->image; - int nlocal = atom->nlocal; - - for (int i = 0; i < nlocal; i++) { - if (mask[i] & groupbit) { - domain->unmap(x[i],image[i],xoriginal[i]); - if (comflag) { - xoriginal[i][0] -= cm[0]; - xoriginal[i][1] -= cm[1]; - xoriginal[i][2] -= cm[2]; - } - } else xoriginal[i][0] = xoriginal[i][1] = xoriginal[i][2] = 0.0; - } -} - -/* ---------------------------------------------------------------------- */ - -FixStoreCoord::~FixStoreCoord() -{ - // unregister callbacks to this fix from Atom class - - atom->delete_callback(id,0); - atom->delete_callback(id,1); - - memory->destroy_2d_double_array(xoriginal); -} - -/* ---------------------------------------------------------------------- */ - -int FixStoreCoord::setmask() -{ - int mask = 0; - return mask; -} - -/* ---------------------------------------------------------------------- - memory usage of local atom-based array -------------------------------------------------------------------------- */ - -double FixStoreCoord::memory_usage() -{ - double bytes = atom->nmax*3 * sizeof(double); - return bytes; -} - -/* ---------------------------------------------------------------------- - allocate atom-based array -------------------------------------------------------------------------- */ - -void FixStoreCoord::grow_arrays(int nmax) -{ - xoriginal = - memory->grow_2d_double_array(xoriginal,nmax,3,"fix_msd:xoriginal"); - array_atom = xoriginal; -} - -/* ---------------------------------------------------------------------- - copy values within local atom-based array -------------------------------------------------------------------------- */ - -void FixStoreCoord::copy_arrays(int i, int j) -{ - xoriginal[j][0] = xoriginal[i][0]; - xoriginal[j][1] = xoriginal[i][1]; - xoriginal[j][2] = xoriginal[i][2]; -} - -/* ---------------------------------------------------------------------- - pack values in local atom-based array for exchange with another proc -------------------------------------------------------------------------- */ - -int FixStoreCoord::pack_exchange(int i, double *buf) -{ - buf[0] = xoriginal[i][0]; - buf[1] = xoriginal[i][1]; - buf[2] = xoriginal[i][2]; - return 3; -} - -/* ---------------------------------------------------------------------- - unpack values in local atom-based array from exchange with another proc -------------------------------------------------------------------------- */ - -int FixStoreCoord::unpack_exchange(int nlocal, double *buf) -{ - xoriginal[nlocal][0] = buf[0]; - xoriginal[nlocal][1] = buf[1]; - xoriginal[nlocal][2] = buf[2]; - return 3; -} - -/* ---------------------------------------------------------------------- - pack values in local atom-based arrays for restart file -------------------------------------------------------------------------- */ - -int FixStoreCoord::pack_restart(int i, double *buf) -{ - buf[0] = 4; - buf[1] = xoriginal[i][0]; - buf[2] = xoriginal[i][1]; - buf[3] = xoriginal[i][2]; - return 4; -} - -/* ---------------------------------------------------------------------- - unpack values from atom->extra array to restart the fix -------------------------------------------------------------------------- */ - -void FixStoreCoord::unpack_restart(int nlocal, int nth) -{ - double **extra = atom->extra; - - // skip to Nth set of extra values - - int m = 0; - for (int i = 0; i < nth; i++) m += static_cast (extra[nlocal][m]); - m++; - - xoriginal[nlocal][0] = extra[nlocal][m++]; - xoriginal[nlocal][1] = extra[nlocal][m++]; - xoriginal[nlocal][2] = extra[nlocal][m++]; -} - -/* ---------------------------------------------------------------------- - maxsize of any atom's restart data -------------------------------------------------------------------------- */ - -int FixStoreCoord::maxsize_restart() -{ - return 4; -} - -/* ---------------------------------------------------------------------- - size of atom nlocal's restart data -------------------------------------------------------------------------- */ - -int FixStoreCoord::size_restart(int nlocal) -{ - return 4; -} diff --git a/src/fix_store_coord.h b/src/fix_store_coord.h deleted file mode 100644 index 536bade429..0000000000 --- a/src/fix_store_coord.h +++ /dev/null @@ -1,50 +0,0 @@ -/* ---------------------------------------------------------------------- - 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 - certain rights in this software. This software is distributed under - the GNU General Public License. - - See the README file in the top-level LAMMPS directory. -------------------------------------------------------------------------- */ - -#ifdef FIX_CLASS - -FixStyle(store/coord,FixStoreCoord) - -#else - -#ifndef LMP_FIX_STORE_COORD_H -#define LMP_FIX_STORE_COORD_H - -#include "fix.h" - -namespace LAMMPS_NS { - -class FixStoreCoord : public Fix { - public: - FixStoreCoord(class LAMMPS *, int, char **); - ~FixStoreCoord(); - int setmask(); - - double memory_usage(); - void grow_arrays(int); - void copy_arrays(int, int); - int pack_exchange(int, double *); - int unpack_exchange(int, double *); - int pack_restart(int, double *); - void unpack_restart(int, int); - int size_restart(int); - int maxsize_restart(); - - private: - double **xoriginal; // original coords of atoms -}; - -} - -#endif -#endif