use symbolic constants and fix out of bound accesses

This commit is contained in:
Axel Kohlmeyer
2022-02-18 05:07:18 -05:00
parent 9151a2e820
commit 4e03589cee
4 changed files with 16 additions and 18 deletions

View File

@ -91,7 +91,6 @@ FixOrientBCC::FixOrientBCC(LAMMPS *lmp, int narg, char **arg) :
// initializations
half_bcc_nn = 4;
use_xismooth = false;
double xicutoff = 1.57;
xicutoffsq = xicutoff * xicutoff;
@ -107,7 +106,7 @@ FixOrientBCC::FixOrientBCC(LAMMPS *lmp, int narg, char **arg) :
FILE *inpfile = fopen(xifilename,"r");
if (inpfile == nullptr) error->one(FLERR,"Fix orient/bcc file open failed");
for (int i = 0; i < 4; i++) {
for (int i = 0; i < half_bcc_nn; i++) {
result = fgets(line,IMGMAX,inpfile);
if (!result) error->one(FLERR,"Fix orient/bcc file read failed");
count = sscanf(line,"%lg %lg %lg",&Rxi[i][0],&Rxi[i][1],&Rxi[i][2]);
@ -117,7 +116,7 @@ FixOrientBCC::FixOrientBCC(LAMMPS *lmp, int narg, char **arg) :
inpfile = fopen(chifilename,"r");
if (inpfile == nullptr) error->one(FLERR,"Fix orient/bcc file open failed");
for (int i = 0; i < 4; i++) {
for (int i = 0; i < half_bcc_nn; i++) {
result = fgets(line,IMGMAX,inpfile);
if (!result) error->one(FLERR,"Fix orient/bcc file read failed");
count = sscanf(line,"%lg %lg %lg",&Rchi[i][0],&Rchi[i][1],&Rchi[i][2]);
@ -126,12 +125,12 @@ FixOrientBCC::FixOrientBCC(LAMMPS *lmp, int narg, char **arg) :
fclose(inpfile);
}
MPI_Bcast(&Rxi[0][0],18,MPI_DOUBLE,0,world);
MPI_Bcast(&Rchi[0][0],18,MPI_DOUBLE,0,world);
MPI_Bcast(&Rxi[0][0],half_bcc_nn*3,MPI_DOUBLE,0,world);
MPI_Bcast(&Rchi[0][0],half_bcc_nn*3,MPI_DOUBLE,0,world);
// make copy of the reference vectors
for (int i = 0; i < 4; i++)
for (int i = 0; i < half_bcc_nn; i++)
for (int j = 0; j < 3; j++) {
half_xi_chi_vec[0][i][j] = Rxi[i][j];
half_xi_chi_vec[1][i][j] = Rchi[i][j];
@ -144,7 +143,7 @@ FixOrientBCC::FixOrientBCC(LAMMPS *lmp, int narg, char **arg) :
double xi_sq,dxi[3],rchi[3];
xiid = 0.0;
for (int i = 0; i < 4; i++) {
for (int i = 0; i < half_bcc_nn; i++) {
rchi[0] = Rchi[i][0];
rchi[1] = Rchi[i][1];
rchi[2] = Rchi[i][2];

View File

@ -69,9 +69,9 @@ class FixOrientBCC : public Fix {
char *xifilename, *chifilename; // file names for 2 crystal orientations
bool use_xismooth;
double Rxi[8][3] = {0}, Rchi[8][3] = {0}, half_xi_chi_vec[2][4][3] = {0};
static constexpr int half_bcc_nn = 4;
double Rxi[half_bcc_nn][3] = {}, Rchi[half_bcc_nn][3] = {}, half_xi_chi_vec[2][half_bcc_nn][3] = {};
double xiid, xi0, xi1, xicutoffsq, cutsq, added_energy;
int half_bcc_nn;
int nmax; // expose 2 per-atom quantities
double **order; // order param and normalized order param

View File

@ -89,7 +89,6 @@ FixOrientFCC::FixOrientFCC(LAMMPS *lmp, int narg, char **arg) :
// initializations
half_fcc_nn = 6;
use_xismooth = false;
double xicutoff = 1.57;
xicutoffsq = xicutoff * xicutoff;
@ -105,7 +104,7 @@ FixOrientFCC::FixOrientFCC(LAMMPS *lmp, int narg, char **arg) :
FILE *inpfile = fopen(xifilename,"r");
if (inpfile == nullptr) error->one(FLERR,"Fix orient/fcc file open failed");
for (int i = 0; i < 6; i++) {
for (int i = 0; i < half_fcc_nn; i++) {
result = fgets(line,IMGMAX,inpfile);
if (!result) error->one(FLERR,"Fix orient/fcc file read failed");
count = sscanf(line,"%lg %lg %lg",&Rxi[i][0],&Rxi[i][1],&Rxi[i][2]);
@ -115,7 +114,7 @@ FixOrientFCC::FixOrientFCC(LAMMPS *lmp, int narg, char **arg) :
inpfile = fopen(chifilename,"r");
if (inpfile == nullptr) error->one(FLERR,"Fix orient/fcc file open failed");
for (int i = 0; i < 6; i++) {
for (int i = 0; i < half_fcc_nn; i++) {
result = fgets(line,IMGMAX,inpfile);
if (!result) error->one(FLERR,"Fix orient/fcc file read failed");
count = sscanf(line,"%lg %lg %lg",&Rchi[i][0],&Rchi[i][1],&Rchi[i][2]);
@ -124,12 +123,12 @@ FixOrientFCC::FixOrientFCC(LAMMPS *lmp, int narg, char **arg) :
fclose(inpfile);
}
MPI_Bcast(&Rxi[0][0],18,MPI_DOUBLE,0,world);
MPI_Bcast(&Rchi[0][0],18,MPI_DOUBLE,0,world);
MPI_Bcast(&Rxi[0][0],half_fcc_nn*3,MPI_DOUBLE,0,world);
MPI_Bcast(&Rchi[0][0],half_fcc_nn*3,MPI_DOUBLE,0,world);
// make copy of the reference vectors
for (int i = 0; i < 6; i++)
for (int i = 0; i < half_fcc_nn; i++)
for (int j = 0; j < 3; j++) {
half_xi_chi_vec[0][i][j] = Rxi[i][j];
half_xi_chi_vec[1][i][j] = Rchi[i][j];
@ -142,7 +141,7 @@ FixOrientFCC::FixOrientFCC(LAMMPS *lmp, int narg, char **arg) :
double xi_sq,dxi[3],rchi[3];
xiid = 0.0;
for (int i = 0; i < 6; i++) {
for (int i = 0; i < half_fcc_nn; i++) {
rchi[0] = Rchi[i][0];
rchi[1] = Rchi[i][1];
rchi[2] = Rchi[i][2];

View File

@ -69,9 +69,9 @@ class FixOrientFCC : public Fix {
char *xifilename, *chifilename; // file names for 2 crystal orientations
bool use_xismooth;
double Rxi[8][3] = {0}, Rchi[8][3] = {0}, half_xi_chi_vec[2][4][3] = {0};
static constexpr int half_fcc_nn = 6;
double Rxi[half_fcc_nn][3] = {}, Rchi[half_fcc_nn][3] = {}, half_xi_chi_vec[2][half_fcc_nn][3] = {};
double xiid, xi0, xi1, xicutoffsq, cutsq, added_energy;
int half_fcc_nn;
int nmax; // expose 2 per-atom quantities
double **order; // order param and normalized order param