Hi,
I wrote the function below to scatter dihedrals back to lammps. Because the number of dihedrals changes, I increase the length of the lists for dihedrals. However, the code crashed or gave me the errors dihedral atoms missing on processers. Could you give me some advices? Thank you very much.
Best,
Yumeng
void lammps_scatter_dihedrals(void *ptr, int **data,int nn,int maxd,FILE* fp)
{
LAMMPS *lmp = (LAMMPS *) ptr;
int natoms = static_cast<int> (lmp->atom->natoms);
int ndihedrals = static_cast<int> (lmp->atom->ndihedrals);
int ndihedraltypes = static_cast<int> (lmp->atom->ndihedraltypes);
int i,j,m,atom1,atom2,atom3,atom4,itype;
int *numptr= lmp->atom->num_dihedral;
int **dptr = (int **) data;
for(i=0;i<natoms;i++) {
if ((m = lmp->atom->map(i+1)) >= 0)
numptr[m]=0;
}
if(nn>ndihedrals)
{
lmp->atom->ndihedrals=nn;
lmp->memory->grow(lmp->atom->dihedral_atom1,nn,maxd,"atom:dihedral_atom1");
lmp->memory->grow(lmp->atom->dihedral_atom2,nn,maxd,"atom:dihedral_atom2");
lmp->memory->grow(lmp->atom->dihedral_atom3,nn,maxd,"atom:dihedral_atom3");
lmp->memory->grow(lmp->atom->dihedral_atom4,nn,maxd,"atom:dihedral_atom4");
lmp->memory->grow(lmp->atom->dihedral_type,nn,maxd,"atom:dihedral_type");
}
int **vptr1 = lmp->atom->dihedral_atom1;
int **vptr2 = lmp->atom->dihedral_atom2;
int **vptr3 = lmp->atom->dihedral_atom3;
int **vptr4 = lmp->atom->dihedral_atom4;
int **vvptr = lmp->atom->dihedral_type;
for (i = 0; i < nn; i++){
atom1=dptr[i][0];
atom2=dptr[i][1];
atom3=dptr[i][2];
atom4=dptr[i][3];
itype=dptr[i][4];
if (itype <= 0 || itype > ndihedraltypes)
lmp->error->one(FLERR,"Invalid dihedral type in Dihedrals section of data file");
if ((m = lmp->atom->map(atom2)) >= 0) {
vvptr[m][numptr[m]] = itype;
vptr1[m][numptr[m]] = atom1;
vptr2[m][numptr[m]] = atom2;
vptr3[m][numptr[m]] = atom3;
vptr4[m][numptr[m]] = atom4;
numptr[m]++;
}
}
}