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

This commit is contained in:
sjplimp
2013-01-31 16:31:03 +00:00
parent 21590469d0
commit 0c6b84987c
55 changed files with 498 additions and 170 deletions

View File

@ -44,9 +44,10 @@ using namespace LAMMPS_NS;
#define LB_FACTOR 1.1
#define CHUNK 1024
#define DELTA 4 // must be 2 or larger
#define MAXBODY 20 // max # of lines in one body, also in Atom class
// customize for new sections
#define NSECTIONS 23 // change when add to header::section_keywords
#define NSECTIONS 24 // change when add to header::section_keywords
/* ---------------------------------------------------------------------- */
@ -68,6 +69,8 @@ ReadData::ReadData(LAMMPS *lmp) : Pointers(lmp)
avec_line = (AtomVecLine *) atom->style_match("line");
ntris = 0;
avec_tri = (AtomVecTri *) atom->style_match("tri");
nbodies = 0;
avec_body = (AtomVecBody *) atom->style_match("body");
}
/* ---------------------------------------------------------------------- */
@ -219,6 +222,11 @@ void ReadData::command(int narg, char **arg)
error->all(FLERR,"Invalid data file section: Triangles");
if (atomflag == 0) error->all(FLERR,"Must read Atoms before Triangles");
bonus(ntris,(AtomVec *) avec_tri,"triangles");
} else if (strcmp(keyword,"Bodies") == 0) {
if (!avec_body)
error->all(FLERR,"Invalid data file section: Bodies");
if (atomflag == 0) error->all(FLERR,"Must read Atoms before Bodies");
bodies();
} else if (strcmp(keyword,"Bonds") == 0) {
if (atom->avec->bonds_allow == 0)
@ -377,7 +385,7 @@ void ReadData::header(int flag)
// customize for new sections
const char *section_keywords[NSECTIONS] =
{"Atoms","Velocities","Ellipsoids","Lines","Triangles",
{"Atoms","Velocities","Ellipsoids","Lines","Triangles","Bodies",
"Bonds","Angles","Dihedrals","Impropers",
"Masses","Pair Coeffs","Bond Coeffs","Angle Coeffs",
"Dihedral Coeffs","Improper Coeffs",
@ -452,6 +460,10 @@ void ReadData::header(int flag)
if (!avec_tri && me == 0)
error->one(FLERR,"No triangles allowed with this atom style");
sscanf(line,BIGINT_FORMAT,&ntris);
} else if (strstr(line,"bodies")) {
if (!avec_body && me == 0)
error->one(FLERR,"No bodies allowed with this atom style");
sscanf(line,BIGINT_FORMAT,&nbodies);
}
else if (strstr(line,"bonds")) sscanf(line,BIGINT_FORMAT,&atom->nbonds);
@ -718,6 +730,86 @@ void ReadData::bonus(bigint nbonus, AtomVec *ptr, const char *type)
}
}
/* ----------------------------------------------------------------------
read all body data
variable amount of info per body, described by ninteger and ndouble
to find atoms, must build atom map if not a molecular system
------------------------------------------------------------------------- */
void ReadData::bodies()
{
int i,m,nchunk,nmax,ninteger,ndouble,tmp,onebody;
char *eof;
int mapflag = 0;
if (atom->map_style == 0) {
mapflag = 1;
atom->map_style = 1;
atom->map_init();
atom->map_set();
}
// nmax = max # of bodies to read in this chunk
// nchunk = actual # readr
bigint nread = 0;
bigint natoms = nbodies;
while (nread < natoms) {
if (natoms-nread > CHUNK) nmax = CHUNK;
else nmax = natoms-nread;
if (me == 0) {
nchunk = 0;
nlines = 0;
m = 0;
while (nchunk < nmax && nlines <= CHUNK-MAXBODY) {
eof = fgets(&buffer[m],MAXLINE,fp);
if (eof == NULL) error->one(FLERR,"Unexpected end of data file");
sscanf(&buffer[m],"%d %d %d",&tmp,&ninteger,&ndouble);
m += strlen(&buffer[m]);
onebody = 0;
if (ninteger) onebody += (ninteger-1)/10 + 1;
if (ndouble) onebody += (ndouble-1)/10 + 1;
if (onebody+1 > MAXBODY)
error->one(FLERR,
"Too many lines in one body in data file - boost MAXBODY");
for (i = 0; i < onebody; i++) {
eof = fgets(&buffer[m],MAXLINE,fp);
if (eof == NULL) error->one(FLERR,"Unexpected end of data file");
m += strlen(&buffer[m]);
}
nchunk++;
nlines += onebody+1;
}
if (buffer[m-1] != '\n') strcpy(&buffer[m++],"\n");
m++;
}
MPI_Bcast(&nchunk,1,MPI_INT,0,world);
MPI_Bcast(&m,1,MPI_INT,0,world);
MPI_Bcast(buffer,m,MPI_CHAR,0,world);
atom->data_bodies(nchunk,buffer,avec_body);
nread += nchunk;
}
if (mapflag) {
atom->map_delete();
atom->map_style = 0;
}
if (me == 0) {
if (screen) fprintf(screen," " BIGINT_FORMAT " bodies\n",natoms);
if (logfile) fprintf(logfile," " BIGINT_FORMAT " bodies\n",natoms);
}
}
/* ---------------------------------------------------------------------- */
void ReadData::bonds()
@ -1157,6 +1249,7 @@ void ReadData::scan(int &bond_per_atom, int &angle_per_atom,
int ellipsoid_flag = 0;
int line_flag = 0;
int tri_flag = 0;
int body_flag = 0;
// customize for new sections
// allocate topology counting vector
@ -1203,6 +1296,10 @@ void ReadData::scan(int &bond_per_atom, int &angle_per_atom,
if (!avec_tri) error->one(FLERR,"Invalid data file section: Triangles");
tri_flag = 1;
skip_lines(ntris);
} else if (strcmp(keyword,"Bodies") == 0) {
if (!avec_body) error->one(FLERR,"Invalid data file section: Bodies");
body_flag = 1;
skip_lines(nbodies);
} else if (strcmp(keyword,"Pair Coeffs") == 0) {
if (force->pair == NULL)
@ -1434,6 +1531,8 @@ void ReadData::scan(int &bond_per_atom, int &angle_per_atom,
error->one(FLERR,"Needed bonus data not in data file");
if (ntris && !tri_flag)
error->one(FLERR,"Needed bonus data not in data file");
if (nbodies && !body_flag)
error->one(FLERR,"Needed bonus data not in data file");
}
/* ----------------------------------------------------------------------