add sanity checks to EAM potential file reader subroutine
This commit is contained in:
@ -465,16 +465,17 @@ void PairEAM::read_file(char *filename)
|
||||
}
|
||||
}
|
||||
|
||||
int tmp;
|
||||
int tmp,nwords;
|
||||
if (me == 0) {
|
||||
fgets(line,MAXLINE,fptr);
|
||||
fgets(line,MAXLINE,fptr);
|
||||
sscanf(line,"%d %lg",&tmp,&file->mass);
|
||||
fgets(line,MAXLINE,fptr);
|
||||
sscanf(line,"%d %lg %d %lg %lg",
|
||||
nwords = sscanf(line,"%d %lg %d %lg %lg",
|
||||
&file->nrho,&file->drho,&file->nr,&file->dr,&file->cut);
|
||||
}
|
||||
|
||||
MPI_Bcast(&nwords,1,MPI_INT,0,world);
|
||||
MPI_Bcast(&file->mass,1,MPI_DOUBLE,0,world);
|
||||
MPI_Bcast(&file->nrho,1,MPI_INT,0,world);
|
||||
MPI_Bcast(&file->drho,1,MPI_DOUBLE,0,world);
|
||||
@ -482,6 +483,9 @@ void PairEAM::read_file(char *filename)
|
||||
MPI_Bcast(&file->dr,1,MPI_DOUBLE,0,world);
|
||||
MPI_Bcast(&file->cut,1,MPI_DOUBLE,0,world);
|
||||
|
||||
if ((nwords != 5) || (file->nrho <= 0) || (file->nr <= 0) || (file->dr <= 0.0))
|
||||
error->all(FLERR,"Invalid EAM potential file");
|
||||
|
||||
memory->create(file->frho,(file->nrho+1),"pair:frho");
|
||||
memory->create(file->rhor,(file->nr+1),"pair:rhor");
|
||||
memory->create(file->zr,(file->nr+1),"pair:zr");
|
||||
|
||||
@ -166,16 +166,20 @@ void PairEAMAlloy::read_file(char *filename)
|
||||
|
||||
if (me == 0) {
|
||||
fgets(line,MAXLINE,fptr);
|
||||
sscanf(line,"%d %lg %d %lg %lg",
|
||||
nwords = sscanf(line,"%d %lg %d %lg %lg",
|
||||
&file->nrho,&file->drho,&file->nr,&file->dr,&file->cut);
|
||||
}
|
||||
|
||||
MPI_Bcast(&nwords,1,MPI_INT,0,world);
|
||||
MPI_Bcast(&file->nrho,1,MPI_INT,0,world);
|
||||
MPI_Bcast(&file->drho,1,MPI_DOUBLE,0,world);
|
||||
MPI_Bcast(&file->nr,1,MPI_INT,0,world);
|
||||
MPI_Bcast(&file->dr,1,MPI_DOUBLE,0,world);
|
||||
MPI_Bcast(&file->cut,1,MPI_DOUBLE,0,world);
|
||||
|
||||
if ((nwords != 5) || (file->nrho <= 0) || (file->nr <= 0) || (file->dr <= 0.0))
|
||||
error->all(FLERR,"Invalid EAM potential file");
|
||||
|
||||
file->mass = new double[file->nelements];
|
||||
memory->create(file->frho,file->nelements,file->nrho+1,"pair:frho");
|
||||
memory->create(file->rhor,file->nelements,file->nr+1,"pair:rhor");
|
||||
|
||||
@ -166,16 +166,20 @@ void PairEAMFS::read_file(char *filename)
|
||||
|
||||
if (me == 0) {
|
||||
fgets(line,MAXLINE,fptr);
|
||||
sscanf(line,"%d %lg %d %lg %lg",
|
||||
nwords = sscanf(line,"%d %lg %d %lg %lg",
|
||||
&file->nrho,&file->drho,&file->nr,&file->dr,&file->cut);
|
||||
}
|
||||
|
||||
MPI_Bcast(&nwords,1,MPI_INT,0,world);
|
||||
MPI_Bcast(&file->nrho,1,MPI_INT,0,world);
|
||||
MPI_Bcast(&file->drho,1,MPI_DOUBLE,0,world);
|
||||
MPI_Bcast(&file->nr,1,MPI_INT,0,world);
|
||||
MPI_Bcast(&file->dr,1,MPI_DOUBLE,0,world);
|
||||
MPI_Bcast(&file->cut,1,MPI_DOUBLE,0,world);
|
||||
|
||||
if ((nwords != 5) || (file->nrho <= 0) || (file->nr <= 0) || (file->dr <= 0.0))
|
||||
error->all(FLERR,"Invalid EAM potential file");
|
||||
|
||||
file->mass = new double[file->nelements];
|
||||
memory->create(file->frho,file->nelements,file->nrho+1,
|
||||
"pair:frho");
|
||||
|
||||
Reference in New Issue
Block a user