From 609226f8d0ea4b74599a007b3730adc052d80987 Mon Sep 17 00:00:00 2001 From: sjplimp Date: Wed, 3 Apr 2013 17:59:23 +0000 Subject: [PATCH] git-svn-id: svn://svn.icms.temple.edu/lammps-ro/trunk@9743 f3b2605a-c512-4ea7-a41b-209d697bcdaa --- src/atom_vec.cpp | 58 +++++++++++++++++++++++++++++-------------- src/atom_vec.h | 4 +-- src/write_data.cpp | 61 +++++++++++++--------------------------------- src/write_data.h | 3 ++- 4 files changed, 61 insertions(+), 65 deletions(-) diff --git a/src/atom_vec.cpp b/src/atom_vec.cpp index b9e14355a9..692b9141c1 100644 --- a/src/atom_vec.cpp +++ b/src/atom_vec.cpp @@ -96,10 +96,13 @@ void AtomVec::write_vel(FILE *fp, int n, double **buf) } /* ---------------------------------------------------------------------- - pack bond info for data file + pack bond info for data file into buf if non-NULL + return count of bonds from this proc + do not count/pack bonds with bondtype = 0 + if bondtype is negative, flip back to positive ------------------------------------------------------------------------- */ -void AtomVec::pack_bond(int **buf) +int AtomVec::pack_bond(int **buf) { int *tag = atom->tag; int *num_bond = atom->num_bond; @@ -113,21 +116,29 @@ void AtomVec::pack_bond(int **buf) if (newton_bond) { for (i = 0; i < nlocal; i++) for (j = 0; j < num_bond[i]; j++) { - buf[m][0] = bond_type[i][j]; - buf[m][1] = tag[i]; - buf[m][2] = bond_atom[i][j]; + if (bond_type[i][j] == 0) continue; + if (buf) { + buf[m][0] = MAX(bond_type[i][j],-bond_type[i][j]); + buf[m][1] = tag[i]; + buf[m][2] = bond_atom[i][j]; + } m++; } } else { for (i = 0; i < nlocal; i++) for (j = 0; j < num_bond[i]; j++) if (tag[i] < bond_atom[i][j]) { - buf[m][0] = bond_type[i][j]; - buf[m][1] = tag[i]; - buf[m][2] = bond_atom[i][j]; + if (bond_type[i][j] == 0) continue; + if (buf) { + buf[m][0] = MAX(bond_type[i][j],-bond_type[i][j]); + buf[m][1] = tag[i]; + buf[m][2] = bond_atom[i][j]; + } m++; } } + + return m; } /* ---------------------------------------------------------------------- @@ -143,10 +154,13 @@ void AtomVec::write_bond(FILE *fp, int n, int **buf, int index) } /* ---------------------------------------------------------------------- - pack angle info for data file + pack angle info for data file into buf if non-NULL + return count of angles from this proc + do not count/pack angles with angletype = 0 + if angletype is negative, flip back to positive ------------------------------------------------------------------------- */ -void AtomVec::pack_angle(int **buf) +int AtomVec::pack_angle(int **buf) { int *tag = atom->tag; int *num_angle = atom->num_angle; @@ -162,23 +176,31 @@ void AtomVec::pack_angle(int **buf) if (newton_bond) { for (i = 0; i < nlocal; i++) for (j = 0; j < num_angle[i]; j++) { - buf[m][0] = angle_type[i][j]; - buf[m][1] = angle_atom1[i][j]; - buf[m][2] = angle_atom2[i][j]; - buf[m][3] = angle_atom3[i][j]; + if (angle_type[i][j] == 0) continue; + if (buf) { + buf[m][0] = MAX(angle_type[i][j],-angle_type[i][j]); + buf[m][1] = angle_atom1[i][j]; + buf[m][2] = angle_atom2[i][j]; + buf[m][3] = angle_atom3[i][j]; + } m++; } } else { for (i = 0; i < nlocal; i++) for (j = 0; j < num_angle[i]; j++) if (tag[i] == angle_atom2[i][j]) { - buf[m][0] = angle_type[i][j]; - buf[m][1] = angle_atom1[i][j]; - buf[m][2] = angle_atom2[i][j]; - buf[m][3] = angle_atom3[i][j]; + if (angle_type[i][j] == 0) continue; + if (buf) { + buf[m][0] = MAX(angle_type[i][j],-angle_type[i][j]); + buf[m][1] = angle_atom1[i][j]; + buf[m][2] = angle_atom2[i][j]; + buf[m][3] = angle_atom3[i][j]; + } m++; } } + + return m; } /* ---------------------------------------------------------------------- diff --git a/src/atom_vec.h b/src/atom_vec.h index 6f1bb7bde9..934bc59ff5 100644 --- a/src/atom_vec.h +++ b/src/atom_vec.h @@ -98,9 +98,9 @@ class AtomVec : protected Pointers { virtual void write_vel(FILE *, int, double **); virtual int write_vel_hybrid(FILE *, double *) {return 0;} - void pack_bond(int **); + int pack_bond(int **); void write_bond(FILE *, int, int **, int); - void pack_angle(int **); + int pack_angle(int **); void write_angle(FILE *, int, int **, int); void pack_dihedral(int **); void write_dihedral(FILE *, int, int **, int); diff --git a/src/write_data.cpp b/src/write_data.cpp index e3c98bc672..7fa149f84f 100644 --- a/src/write_data.cpp +++ b/src/write_data.cpp @@ -112,6 +112,7 @@ void WriteData::write(char *file) // if unequal and thermo lostflag is "error", don't write data file bigint nblocal = atom->nlocal; + bigint natoms; MPI_Allreduce(&nblocal,&natoms,1,MPI_LMP_BIGINT,MPI_SUM,world); if (natoms != atom->natoms && output->thermo->lostflag == ERROR) error->all(FLERR,"Atom count is inconsistent, cannot write data file"); @@ -165,11 +166,17 @@ void WriteData::header() fprintf(fp,"%d atom types\n",atom->ntypes); if (atom->nbonds || atom->nbondtypes) { - fprintf(fp,BIGINT_FORMAT " bonds\n",atom->nbonds); + nbonds_local = atom->avec->pack_bond(NULL); + bigint nbonds; + MPI_Allreduce(&nbonds_local,&nbonds,1,MPI_LMP_BIGINT,MPI_SUM,world); + fprintf(fp,BIGINT_FORMAT " bonds\n",nbonds); fprintf(fp,"%d bond types\n",atom->nbondtypes); } if (atom->nangles || atom->nangletypes) { - fprintf(fp,BIGINT_FORMAT " angles\n",atom->nangles); + nangles_local = atom->avec->pack_angle(NULL); + bigint nangles; + MPI_Allreduce(&nangles_local,&nangles,1,MPI_LMP_BIGINT,MPI_SUM,world); + fprintf(fp,BIGINT_FORMAT " angles\n",nangles); fprintf(fp,"%d angle types\n",atom->nangletypes); } if (atom->ndihedrals || atom->ndihedraltypes) { @@ -214,19 +221,21 @@ void WriteData::force_fields() fprintf(fp,"\nPair Coeffs\n\n"); force->pair->write_data(fp); } - if (atom->avec->bonds_allow && force->bond) { + if (atom->avec->bonds_allow && force->bond && force->bond->writedata) { fprintf(fp,"\nBond Coeffs\n\n"); force->bond->write_data(fp); } - if (atom->avec->angles_allow && force->angle) { + if (atom->avec->angles_allow && force->angle && force->angle->writedata) { fprintf(fp,"\nAngle Coeffs\n\n"); force->angle->write_data(fp); } - if (atom->avec->dihedrals_allow && force->dihedral) { + if (atom->avec->dihedrals_allow && force->dihedral && + force->dihedral->writedata) { fprintf(fp,"\nDihedral Coeffs\n\n"); force->dihedral->write_data(fp); } - if (atom->avec->impropers_allow && force->improper) { + if (atom->avec->impropers_allow && force->improper && + force->improper->writedata) { fprintf(fp,"\nImproper Coeffs\n\n"); force->improper->write_data(fp); } @@ -343,27 +352,9 @@ void WriteData::velocities() void WriteData::bonds() { // communication buffer for all my Bond info - // max_size = largest buffer needed by any proc int ncol = 3; - - int *tag = atom->tag; - int *num_bond = atom->num_bond; - int **bond_atom = atom->bond_atom; - int nlocal = atom->nlocal; - int newton_bond = force->newton_bond; - - int i,j; - int sendrow = 0; - if (newton_bond) { - for (i = 0; i < nlocal; i++) - sendrow += num_bond[i]; - } else { - for (i = 0; i < nlocal; i++) - for (j = 0; j < num_bond[i]; j++) - if (tag[i] < bond_atom[i][j]) sendrow++; - } - + int sendrow = static_cast (nbonds_local); int maxrow; MPI_Allreduce(&sendrow,&maxrow,1,MPI_INT,MPI_MAX,world); @@ -413,27 +404,9 @@ void WriteData::bonds() void WriteData::angles() { // communication buffer for all my Angle info - // max_size = largest buffer needed by any proc int ncol = 4; - - int *tag = atom->tag; - int *num_angle = atom->num_angle; - int **angle_atom2 = atom->angle_atom2; - int nlocal = atom->nlocal; - int newton_bond = force->newton_bond; - - int i,j; - int sendrow = 0; - if (newton_bond) { - for (i = 0; i < nlocal; i++) - sendrow += num_angle[i]; - } else { - for (i = 0; i < nlocal; i++) - for (j = 0; j < num_angle[i]; j++) - if (tag[i] == angle_atom2[i][j]) sendrow++; - } - + int sendrow = static_cast (nangles_local); int maxrow; MPI_Allreduce(&sendrow,&maxrow,1,MPI_INT,MPI_MAX,world); diff --git a/src/write_data.h b/src/write_data.h index 971de1cc84..4fab5243bb 100644 --- a/src/write_data.h +++ b/src/write_data.h @@ -34,7 +34,8 @@ class WriteData : protected Pointers { private: int me,nprocs; FILE *fp; - bigint natoms; // natoms (sum of nlocal) to write into file + bigint nbonds_local; + bigint nangles_local; void header(); void type_arrays();