forked from lijiext/lammps
git-svn-id: svn://svn.icms.temple.edu/lammps-ro/trunk@10350 f3b2605a-c512-4ea7-a41b-209d697bcdaa
This commit is contained in:
parent
856f78e50a
commit
48510d047b
99
src/atom.cpp
99
src/atom.cpp
|
@ -106,6 +106,13 @@ Atom::Atom(LAMMPS *lmp) : Pointers(lmp)
|
|||
improper_type = improper_atom1 = improper_atom2 = NULL;
|
||||
improper_atom3 = improper_atom4 = NULL;
|
||||
|
||||
// custom atom arrays
|
||||
|
||||
nivector = ndvector = 0;
|
||||
ivector = NULL;
|
||||
dvector = NULL;
|
||||
iname = dname = NULL;
|
||||
|
||||
// initialize atom style and array existence flags
|
||||
// customize by adding new flag
|
||||
|
||||
|
@ -223,6 +230,17 @@ Atom::~Atom()
|
|||
memory->destroy(improper_atom3);
|
||||
memory->destroy(improper_atom4);
|
||||
|
||||
// delete custom atom arrays
|
||||
|
||||
for (int i = 0; i < nivector; i++) {
|
||||
memory->destroy(ivector[i]);
|
||||
delete [] iname[i];
|
||||
}
|
||||
for (int i = 0; i < ndvector; i++) {
|
||||
memory->destroy(dvector[i]);
|
||||
delete [] dname[i];
|
||||
}
|
||||
|
||||
// delete per-type arrays
|
||||
|
||||
delete [] mass;
|
||||
|
@ -1439,6 +1457,87 @@ void Atom::update_callback(int ifix)
|
|||
if (extra_border[i] > ifix) extra_border[i]--;
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
find custom per-atom vector with name
|
||||
return index if found, and flag = 0/1 for int/double
|
||||
return -1 if not found
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
int Atom::find_custom(char *name, int &flag)
|
||||
{
|
||||
for (int i = 0; i < nivector; i++)
|
||||
if (iname[i] && strcmp(iname[i],name) == 0) {
|
||||
flag = 0;
|
||||
return i;
|
||||
}
|
||||
|
||||
for (int i = 0; i < ndvector; i++)
|
||||
if (dname[i] && strcmp(dname[i],name) == 0) {
|
||||
flag = 1;
|
||||
return i;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
add a custom variable with name of type flag = 0/1 for int/double
|
||||
assumes name does not already exist
|
||||
return index in ivector or dvector of its location
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
int Atom::add_custom(char *name, int flag)
|
||||
{
|
||||
int index;
|
||||
|
||||
if (flag == 0) {
|
||||
index = nivector;
|
||||
nivector++;
|
||||
iname = (char **) memory->srealloc(iname,nivector*sizeof(char *),
|
||||
"atom:iname");
|
||||
int n = strlen(name) + 1;
|
||||
iname[index] = new char[n];
|
||||
strcpy(iname[index],name);
|
||||
ivector = (int **) memory->srealloc(ivector,nivector*sizeof(int *),
|
||||
"atom:ivector");
|
||||
memory->create(ivector[index],nmax,"atom:ivector");
|
||||
} else {
|
||||
index = ndvector;
|
||||
ndvector++;
|
||||
dname = (char **) memory->srealloc(dname,ndvector*sizeof(char *),
|
||||
"atom:dname");
|
||||
int n = strlen(name) + 1;
|
||||
dname[index] = new char[n];
|
||||
strcpy(dname[index],name);
|
||||
dvector = (double **) memory->srealloc(dvector,ndvector*sizeof(double *),
|
||||
"atom:dvector");
|
||||
memory->create(dvector[index],nmax,"atom:dvector");
|
||||
}
|
||||
|
||||
return index;
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
remove a custom variable of type flag = 0/1 for int/double at index
|
||||
free memory for vector and name and set ptrs to NULL
|
||||
ivector/dvector and iname/dname lists never shrink
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
void Atom::remove_custom(int flag, int index)
|
||||
{
|
||||
if (flag == 0) {
|
||||
memory->destroy(ivector[index]);
|
||||
ivector[index] = NULL;
|
||||
delete [] iname[index];
|
||||
iname[index] = NULL;
|
||||
} else {
|
||||
memory->destroy(dvector[index]);
|
||||
dvector[index] = NULL;
|
||||
delete [] dname[index];
|
||||
dname[index] = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
return a pointer to a named internal variable
|
||||
if don't recognize name, return NULL
|
||||
|
|
13
src/atom.h
13
src/atom.h
|
@ -83,6 +83,15 @@ class Atom : protected Pointers {
|
|||
int **improper_type;
|
||||
int **improper_atom1,**improper_atom2,**improper_atom3,**improper_atom4;
|
||||
|
||||
// custom arrays used by fix property/atom
|
||||
|
||||
int **ivector;
|
||||
double **dvector;
|
||||
char **iname,**dname;
|
||||
int nivector,ndvector;
|
||||
|
||||
// used by USER-CUDA to flag used per-atom arrays
|
||||
|
||||
unsigned int datamask;
|
||||
unsigned int datamask_ext;
|
||||
|
||||
|
@ -176,6 +185,10 @@ class Atom : protected Pointers {
|
|||
void delete_callback(const char *, int);
|
||||
void update_callback(int);
|
||||
|
||||
int find_custom(char *, int &);
|
||||
int add_custom(char *, int);
|
||||
void remove_custom(int, int);
|
||||
|
||||
void *extract(char *);
|
||||
|
||||
inline int* get_map_array() {return map_array;};
|
||||
|
|
|
@ -25,11 +25,6 @@ using namespace FixConst;
|
|||
|
||||
enum{MOLECULE,INTEGER,DOUBLE};
|
||||
|
||||
// NOTE: how to prevent atom style being changed after this fix defined?
|
||||
// e.g. what if replicate happens, will it wipe out molecule_flag
|
||||
// will it copy ivectors in atom.h ??
|
||||
// maybe setting of atom->mol_flag should happen in fix init
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
FixPropertyAtom::FixPropertyAtom(LAMMPS *lmp, int narg, char **arg) :
|
||||
|
@ -42,6 +37,7 @@ FixPropertyAtom::FixPropertyAtom(LAMMPS *lmp, int narg, char **arg) :
|
|||
int iarg = 3;
|
||||
nvalue = narg-iarg;
|
||||
style = new int[nvalue];
|
||||
index = new int[nvalue];
|
||||
|
||||
molecule_flag = 0;
|
||||
|
||||
|
@ -58,9 +54,19 @@ FixPropertyAtom::FixPropertyAtom(LAMMPS *lmp, int narg, char **arg) :
|
|||
nvalue++;
|
||||
} else if (strstr(arg[iarg],"i_") == arg[iarg]) {
|
||||
style[nvalue] = INTEGER;
|
||||
int tmp;
|
||||
index[nvalue] = atom->find_custom(&arg[iarg][2],tmp);
|
||||
if (index[nvalue] >= 0)
|
||||
error->all(FLERR,"Fix property/atom vector name already exists");
|
||||
index[nvalue] = atom->add_custom(&arg[iarg][2],0);
|
||||
nvalue++;
|
||||
} else if (strstr(arg[iarg],"d_") == arg[iarg]) {
|
||||
style[nvalue] = DOUBLE;
|
||||
int tmp;
|
||||
index[nvalue] = atom->find_custom(&arg[iarg][2],tmp);
|
||||
if (index[nvalue] >= 0)
|
||||
error->all(FLERR,"Fix property/atom vector name already exists");
|
||||
index[nvalue] = atom->add_custom(&arg[iarg][2],1);
|
||||
nvalue++;
|
||||
} else break;
|
||||
|
||||
|
@ -111,11 +117,14 @@ FixPropertyAtom::~FixPropertyAtom()
|
|||
memory->destroy(atom->molecule);
|
||||
atom->molecule = NULL;
|
||||
} else if (style[m] == INTEGER) {
|
||||
atom->remove_custom(0,index[m]);
|
||||
} else if (style[m] == DOUBLE) {
|
||||
atom->remove_custom(1,index[m]);
|
||||
}
|
||||
}
|
||||
|
||||
delete [] style;
|
||||
delete [] index;
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
@ -187,8 +196,10 @@ void FixPropertyAtom::read_data_section(char *keyword, int n, char *buf)
|
|||
if ((m = atom->map(tagdata)) >= 0) {
|
||||
for (j = 0; j < nvalue; j++) {
|
||||
if (style[j] == MOLECULE) atom->molecule[m] = atoi(values[j+1]);
|
||||
else if (style[j] == INTEGER) atom->molecule[m] = atoi(values[j+1]);
|
||||
else if (style[j] == DOUBLE) atom->molecule[m] = atof(values[j+1]);
|
||||
else if (style[j] == INTEGER)
|
||||
atom->ivector[index[j]][m] = atoi(values[j+1]);
|
||||
else if (style[j] == DOUBLE)
|
||||
atom->dvector[index[j]][m] = atof(values[j+1]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -235,13 +246,13 @@ void FixPropertyAtom::grow_arrays(int nmax)
|
|||
size_t nbytes = (nmax-nmax_old) * sizeof(int);
|
||||
memset(&atom->molecule[nmax_old],0,nbytes);
|
||||
} else if (style[m] == INTEGER) {
|
||||
memory->grow(atom->molecule,nmax,"atom:molecule");
|
||||
memory->grow(atom->ivector[index[m]],nmax,"atom:ivector");
|
||||
size_t nbytes = (nmax-nmax_old) * sizeof(int);
|
||||
memset(&atom->molecule[nmax_old],0,nbytes);
|
||||
memset(&atom->ivector[index[m]][nmax_old],0,nbytes);
|
||||
} else if (style[m] == DOUBLE) {
|
||||
memory->grow(atom->molecule,nmax,"atom:molecule");
|
||||
memory->grow(atom->dvector[index[m]],nmax,"atom:dvector");
|
||||
size_t nbytes = (nmax-nmax_old) * sizeof(double);
|
||||
memset(&atom->molecule[nmax_old],0,nbytes);
|
||||
memset(&atom->dvector[index[m]][nmax_old],0,nbytes);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -258,9 +269,9 @@ void FixPropertyAtom::copy_arrays(int i, int j, int delflag)
|
|||
if (style[m] == MOLECULE)
|
||||
atom->molecule[j] = atom->molecule[i];
|
||||
else if (style[m] == INTEGER)
|
||||
atom->molecule[j] = atom->molecule[i];
|
||||
atom->ivector[index[m]][j] = atom->ivector[index[m]][i];
|
||||
else if (style[m] == DOUBLE)
|
||||
atom->molecule[j] = atom->molecule[i];
|
||||
atom->dvector[index[m]][j] = atom->dvector[index[m]][i];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -281,11 +292,20 @@ int FixPropertyAtom::pack_border(int n, int *list, double *buf)
|
|||
buf[m++] = molecule[j];
|
||||
}
|
||||
} else if (style[j] == INTEGER) {
|
||||
int *ivector = atom->ivector[index[k]];
|
||||
for (i = 0; i < n; i++) {
|
||||
j = list[i];
|
||||
buf[m++] = ivector[j];
|
||||
}
|
||||
} else if (style[j] == DOUBLE) {
|
||||
double *dvector = atom->dvector[index[k]];
|
||||
for (i = 0; i < n; i++) {
|
||||
j = list[i];
|
||||
buf[m++] = dvector[j];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
printf("PBORDER %ld %d\n",update->ntimestep,m);
|
||||
return m;
|
||||
}
|
||||
|
||||
|
@ -304,9 +324,17 @@ int FixPropertyAtom::unpack_border(int n, int first, double *buf)
|
|||
last = first + n;
|
||||
for (i = first; i < last; i++)
|
||||
molecule[i] = static_cast<int> (buf[m++]);
|
||||
} else if (style[k] == INTEGER) {
|
||||
} else if (style[k] == DOUBLE) {
|
||||
}
|
||||
} else if (style[k] == INTEGER) {
|
||||
int *ivector = atom->ivector[index[k]];
|
||||
last = first + n;
|
||||
for (i = first; i < last; i++)
|
||||
ivector[i] = static_cast<int> (buf[m++]);
|
||||
} else if (style[k] == DOUBLE) {
|
||||
double *dvector = atom->dvector[index[k]];
|
||||
last = first + n;
|
||||
for (i = first; i < last; i++)
|
||||
dvector[i] = buf[m++];
|
||||
}
|
||||
}
|
||||
|
||||
return m;
|
||||
|
@ -320,8 +348,8 @@ int FixPropertyAtom::pack_exchange(int i, double *buf)
|
|||
{
|
||||
for (int m = 0; m < nvalue; m++) {
|
||||
if (style[m] == MOLECULE) buf[m] = atom->molecule[i];
|
||||
else if (style[m] == INTEGER) buf[m] = atom->molecule[i];
|
||||
else if (style[m] == DOUBLE) buf[m] = atom->molecule[i];
|
||||
else if (style[m] == INTEGER) buf[m] = atom->ivector[index[m]][i];
|
||||
else if (style[m] == DOUBLE) buf[m] = atom->dvector[index[m]][i];
|
||||
}
|
||||
return nvalue;
|
||||
}
|
||||
|
@ -336,9 +364,9 @@ int FixPropertyAtom::unpack_exchange(int nlocal, double *buf)
|
|||
if (style[m] == MOLECULE)
|
||||
atom->molecule[nlocal] = static_cast<int> (buf[m]);
|
||||
else if (style[m] == INTEGER)
|
||||
atom->molecule[nlocal] = static_cast<int> (buf[m]);
|
||||
atom->ivector[index[m]][nlocal] = static_cast<int> (buf[m]);
|
||||
else if (style[m] == DOUBLE)
|
||||
atom->molecule[nlocal] = buf[m];
|
||||
atom->dvector[index[m]][nlocal] = buf[m];
|
||||
}
|
||||
return nvalue;
|
||||
}
|
||||
|
@ -352,8 +380,8 @@ int FixPropertyAtom::pack_restart(int i, double *buf)
|
|||
buf[0] = nvalue+1;
|
||||
for (int m = 1; m <= nvalue; m++) {
|
||||
if (style[m] == MOLECULE) buf[m] = atom->molecule[i];
|
||||
else if (style[m] == INTEGER) buf[m] = atom->molecule[i];
|
||||
else if (style[m] == DOUBLE) buf[m] = atom->molecule[i];
|
||||
else if (style[m] == INTEGER) buf[m] = atom->ivector[index[m]][i];
|
||||
else if (style[m] == DOUBLE) buf[m] = atom->dvector[index[m]][i];
|
||||
}
|
||||
return nvalue+1;
|
||||
}
|
||||
|
@ -376,9 +404,9 @@ void FixPropertyAtom::unpack_restart(int nlocal, int nth)
|
|||
if (style[i] == MOLECULE)
|
||||
atom->molecule[nlocal] = static_cast<int> (extra[nlocal][m++]);
|
||||
else if (style[m] == INTEGER)
|
||||
atom->molecule[nlocal] = static_cast<int> (extra[nlocal][m++]);
|
||||
atom->ivector[index[m]][nlocal] = static_cast<int> (extra[nlocal][m++]);
|
||||
else if (style[m] == DOUBLE)
|
||||
atom->molecule[nlocal] = extra[nlocal][m++];
|
||||
atom->dvector[index[m]][nlocal] = extra[nlocal][m++];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -48,7 +48,7 @@ class FixPropertyAtom : public Fix {
|
|||
|
||||
private:
|
||||
int nvalue,border,molecule_flag;
|
||||
int *style;
|
||||
int *style,*index;
|
||||
int nmax_old; // length of peratom arrays the last time they grew
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue