diff --git a/src/ML-RANN/rann_fingerprint_bond.cpp b/src/ML-RANN/rann_fingerprint_bond.cpp index acc3318ba0..536859dc8f 100644 --- a/src/ML-RANN/rann_fingerprint_bond.cpp +++ b/src/ML-RANN/rann_fingerprint_bond.cpp @@ -36,6 +36,8 @@ DISTRIBUTION A. Approved for public release; distribution unlimited. OPSEC#4918 using namespace LAMMPS_NS::RANN; +static constexpr double SMALL = 1.0e-12; + Fingerprint_bond::Fingerprint_bond(PairRANN *_pair) : Fingerprint(_pair) { n_body_type = 3; @@ -317,7 +319,8 @@ void Fingerprint_bond::do3bodyfeatureset_singleneighborloop(double * features,do i = ilist[ii]; itype = pair->map[type[i]]; int f = pair->net[itype].dimensions[0]; - double expr[jnum][kmax+12]; + std::vector row(kmax+12, 0.0); + std::vector> expr(jnum, row); int p = kmax; int countmb=((mlength)*(mlength+1))>>1; // calculate interpolation expr, rinvs and dfc, for each neighbor @@ -354,13 +357,13 @@ void Fingerprint_bond::do3bodyfeatureset_singleneighborloop(double * features,do expr[jj][p+1]=dely*rinvs; expr[jj][p+2]=delz*rinvs; //Hack to avoid nan when x y or z component of radial vector is exactly 0. Shouldn't affect accuracy. - if (expr[jj][p]*expr[jj][p]<0.000000000001) { + if (expr[jj][p]*expr[jj][p] < SMALL) { expr[jj][p] = 0.000001; } - if (expr[jj][p+1]*expr[jj][p+1]<0.000000000001) { + if (expr[jj][p+1]*expr[jj][p+1] < SMALL) { expr[jj][p+1] = 0.000001; } - if (expr[jj][p+2]*expr[jj][p+2]<0.000000000001) { + if (expr[jj][p+2]*expr[jj][p+2] < SMALL) { expr[jj][p+2] = 0.000001; } expr[jj][p+3] = -dfc*expr[jj][p]; @@ -377,7 +380,7 @@ void Fingerprint_bond::do3bodyfeatureset_singleneighborloop(double * features,do int kb = kmax; int mb = mlength; count = startingneuron; - double Bb[mb]; + std::vector Bb(mb, 0.0); double dBbx; double dBby; double dBbz; @@ -397,7 +400,7 @@ void Fingerprint_bond::do3bodyfeatureset_singleneighborloop(double * features,do } for (n=0;n Bg(mb, 0.0); ai = n; double y1 = alpha_k[ai]/re; //loop over ktype to get Bg @@ -433,7 +433,7 @@ void Fingerprint_bond::do3bodyfeatureset_singleneighborloop(double * features,do continue; } double yprod = expr[jj][ai]; - double *y4 = &expr[jj][p]; + double *y4 = expr[jj].data() + p; for (a2=0;a2map[type[i]]; int f = pair->net[itype].dimensions[0]; - double expr[jnum][kmax]; - double y[jnum][3]; - double ri[jnum]; - double dfc[jnum]; + std::vector row(kmax, 0.0); + std::vector> expr(jnum, row); + std::vector yrow(3, 0.0); + std::vector> y(jnum, yrow); + std::vector ri(jnum, 0.0); + std::vector dfc(jnum, 0.0); int kb = kmax; int mb = mlength; - double c41[kmax]; - double c51[kmax]; - double c61[kmax]; - double ct[kmax]; + std::vector c41(kmax, 0.0); + std::vector c51(kmax, 0.0); + std::vector c61(kmax, 0.0); + std::vector ct(kmax, 0.0); for (jj = 0; jj < jnum; jj++) { jtype = tn[jj]; if (jtypes != nelements && jtypes != jtype && ktypes != nelements && ktypes != jtype) { diff --git a/src/ML-RANN/rann_fingerprint_bondscreened.cpp b/src/ML-RANN/rann_fingerprint_bondscreened.cpp index 8dcc2e4389..018bbc6df1 100644 --- a/src/ML-RANN/rann_fingerprint_bondscreened.cpp +++ b/src/ML-RANN/rann_fingerprint_bondscreened.cpp @@ -36,6 +36,8 @@ DISTRIBUTION A. Approved for public release; distribution unlimited. OPSEC#4918 using namespace LAMMPS_NS::RANN; +static constexpr double SMALL = 1.0e-12; + Fingerprint_bondscreened::Fingerprint_bondscreened(PairRANN *_pair) : Fingerprint(_pair) { n_body_type = 3; @@ -319,7 +321,8 @@ void Fingerprint_bondscreened::do3bodyfeatureset_singleneighborloop(double * fea i = ilist[ii]; itype = pair->map[type[i]]; int f = pair->net[itype].dimensions[0]; - double expr[jnum][kmax+12]; + std::vector row(kmax+12, 0.0); + std::vector> expr(jnum, row); int p = kmax; int countmb=((mlength)*(mlength+1))>>1; // calculate interpolation expr, rinvs and dfc, for each neighbor @@ -358,13 +361,13 @@ void Fingerprint_bondscreened::do3bodyfeatureset_singleneighborloop(double * fea expr[jj][p+1]=dely*rinvs; expr[jj][p+2]=delz*rinvs; //Hack to avoid nan when x y or z component of radial vector is exactly 0. Shouldn't affect accuracy. - if (expr[jj][p]*expr[jj][p]<0.000000000001) { + if (expr[jj][p]*expr[jj][p] < SMALL) { expr[jj][p] = 0.000001; } - if (expr[jj][p+1]*expr[jj][p+1]<0.000000000001) { + if (expr[jj][p+1]*expr[jj][p+1] < SMALL) { expr[jj][p+1] = 0.000001; } - if (expr[jj][p+2]*expr[jj][p+2]<0.000000000001) { + if (expr[jj][p+2]*expr[jj][p+2] < SMALL) { expr[jj][p+2] = 0.000001; } expr[jj][p+3] = -dfc*expr[jj][p]-dSikx[jj]; @@ -381,20 +384,20 @@ void Fingerprint_bondscreened::do3bodyfeatureset_singleneighborloop(double * fea int kb = kmax; int mb = mlength; count = startingneuron; - double Bb[mb]; + std::vector Bb(mb, 0.0); double dBbx; double dBby; double dBbz; - double dBbx1[mb]; - double dBby1[mb]; - double dBbz1[mb]; + std::vector dBbx1(mb, 0.0); + std::vector dBby1(mb, 0.0); + std::vector dBbz1(mb, 0.0); double yprod; for (mcount=0;mcount Bg(mb, 0.0); ai = n; double y1 = alpha_k[ai]/re; //loop over ktype to get Bg @@ -445,7 +445,7 @@ void Fingerprint_bondscreened::do3bodyfeatureset_singleneighborloop(double * fea continue; } double yprod = expr[jj][ai]; - double *y4 = &expr[jj][p]; + double *y4 = expr[jj].data() + p; for (a2=0;a2map[type[i]]; int f = pair->net[itype].dimensions[0]; - double expr[jnum][kmax]; - double y[jnum][3]; - double ri[jnum]; - double dfc[jnum]; + std::vector row(kmax, 0.0); + std::vector> expr(jnum, row); + std::vector yrow(3, 0.0); + std::vector> y(jnum, yrow); + std::vector ri(jnum, 0.0); + std::vector dfc(jnum, 0.0); int kb = kmax; int mb = mlength; - double Bijk[kb][mb]; - double c41[kmax]; - double c51[kmax]; - double c61[kmax]; - double ct[kmax]; + std::vector brow(mb, 0.0); + std::vector> Bijk(kb, brow); + std::vector c41(kmax, 0.0); + std::vector c51(kmax, 0.0); + std::vector c61(kmax, 0.0); + std::vector ct(kmax, 0.0); for (jj = 0; jj < jnum; jj++) { if (Bij[jj]==false) {continue;} jtype = tn[jj]; diff --git a/src/ML-RANN/rann_fingerprint_bondscreenedspin.cpp b/src/ML-RANN/rann_fingerprint_bondscreenedspin.cpp index cbd3b2a6dc..26fa46b4eb 100644 --- a/src/ML-RANN/rann_fingerprint_bondscreenedspin.cpp +++ b/src/ML-RANN/rann_fingerprint_bondscreenedspin.cpp @@ -35,6 +35,8 @@ DISTRIBUTION A. Approved for public release; distribution unlimited. OPSEC#4918 using namespace LAMMPS_NS::RANN; +static constexpr double SMALL = 1.0e-12; + Fingerprint_bondscreenedspin::Fingerprint_bondscreenedspin(PairRANN *_pair) : Fingerprint(_pair) { n_body_type = 3; @@ -320,7 +322,8 @@ void Fingerprint_bondscreenedspin::do3bodyfeatureset_singleneighborloop(double * i = ilist[ii]; itype = pair->map[type[i]]; int f = pair->net[itype].dimensions[0]; - double expr[jnum][kmax+12]; + std::vector row(kmax+12, 0.0); + std::vector> expr(jnum, row); int p = kmax; int countmb=((mlength)*(mlength+1))>>1; double *si = sim->s[i]; @@ -360,13 +363,13 @@ void Fingerprint_bondscreenedspin::do3bodyfeatureset_singleneighborloop(double * expr[jj][p+1]=dely*rinvs; expr[jj][p+2]=delz*rinvs; //Hack to avoid nan when x y or z component of radial vector is exactly 0. Shouldn't affect accuracy. - if (expr[jj][p]*expr[jj][p]<0.000000000001) { + if (expr[jj][p]*expr[jj][p] < SMALL) { expr[jj][p] = 0.000001; } - if (expr[jj][p+1]*expr[jj][p+1]<0.000000000001) { + if (expr[jj][p+1]*expr[jj][p+1] < SMALL) { expr[jj][p+1] = 0.000001; } - if (expr[jj][p+2]*expr[jj][p+2]<0.000000000001) { + if (expr[jj][p+2]*expr[jj][p+2] < SMALL) { expr[jj][p+2] = 0.000001; } expr[jj][p+3] = -dfc*expr[jj][p]-dSikx[jj]; @@ -383,8 +386,8 @@ void Fingerprint_bondscreenedspin::do3bodyfeatureset_singleneighborloop(double * int kb = kmax; int mb = mlength; count = startingneuron; - double Bb[mb]; - double Bbs[mb]; + std::vector Bb(mb, 0.0); + std::vector Bbs(mb, 0.0); double dBbx; double dBby; double dBbz; @@ -421,7 +424,7 @@ void Fingerprint_bondscreenedspin::do3bodyfeatureset_singleneighborloop(double * double *sj = sim->s[j]; double sp = si[0]*sj[0]+si[1]*sj[1]+si[2]*sj[2]; double yprod = expr[jj][ai]; - double *y4 = &expr[jj][p]; + double *y4 = expr[jj].data() + p; for (a2=0;a2 Bg(mb, 0.0); + std::vector Bgs(mb, 0.0); ai = n; double y1 = alpha_k[ai]/re; //loop over ktype to get Bg @@ -452,7 +451,7 @@ void Fingerprint_bondscreenedspin::do3bodyfeatureset_singleneighborloop(double * double *sj = sim->s[j]; double sp = si[0]*sj[0]+si[1]*sj[1]+si[2]*sj[2]; double yprod = expr[jj][ai]; - double *y4 = &expr[jj][p]; + double *y4 = expr[jj].data() + p; for (a2=0;a2s[j]; double sp = si[0]*sj[0]+si[1]*sj[1]+si[2]*sj[2]; - double *y3 = &expr[jj][p+3]; - double *y4 = &expr[jj][p]; + double *y3 = expr[jj].data() + p + 3; + double *y4 = expr[jj].data() + p; ai = n; yprod = expr[jj][ai]; for (a2=0;a2s[j]; double sp = si[0]*sj[0]+si[1]*sj[1]+si[2]*sj[2]; - double *y3 = &expr[jj][p+3]; - double *y4 = &expr[jj][p]; + double *y3 = expr[jj].data() + p + 3; + double *y4 = expr[jj].data() + p; ai = n; yprod = expr[jj][ai]; for (a2=0;a2s[j]; double sp = si[0]*sj[0]+si[1]*sj[1]+si[2]*sj[2]; - double *y3 = &expr[jj][p+3]; - double *y4 = &expr[jj][p]; + double *y3 = expr[jj].data() + p + 3; + double *y4 = expr[jj].data() + p; ai = n; yprod = expr[jj][ai]; for (a2=0;a2map[type[i]]; int f = pair->net[itype].dimensions[0]; - double expr[jnum][kmax]; - double y[jnum][3]; - double ri[jnum]; - double dfc[jnum]; + std::vector row(kmax, 0.0); + std::vector> expr(jnum, row); + std::vector yrow(3, 0.0); + std::vector> y(jnum, yrow); + std::vector ri(jnum, 0.0); + std::vector dfc(jnum, 0.0); int kb = kmax; int mb = mlength; - double Bijk[kb][mb]; - double c41[kmax]; - double c51[kmax]; - double c61[kmax]; - double ct[kmax]; double *si = sim->s[i]; + std::vector brow(mb, 0.0); + std::vector> Bijk(kb, brow); + std::vector c41(kmax, 0.0); + std::vector c51(kmax, 0.0); + std::vector c61(kmax, 0.0); + std::vector ct(kmax, 0.0); for (jj = 0; jj < jnum; jj++) { if (Bij[jj]==false) {continue;} jtype = tn[jj]; diff --git a/src/ML-RANN/rann_fingerprint_bondspin.cpp b/src/ML-RANN/rann_fingerprint_bondspin.cpp index 1ccdf8ff62..5ecd37b89c 100644 --- a/src/ML-RANN/rann_fingerprint_bondspin.cpp +++ b/src/ML-RANN/rann_fingerprint_bondspin.cpp @@ -35,6 +35,8 @@ DISTRIBUTION A. Approved for public release; distribution unlimited. OPSEC#4918 using namespace LAMMPS_NS::RANN; +static constexpr double SMALL = 1.0e-12; + Fingerprint_bondspin::Fingerprint_bondspin(PairRANN *_pair) : Fingerprint(_pair) { n_body_type = 3; @@ -317,7 +319,8 @@ void Fingerprint_bondspin::do3bodyfeatureset_singleneighborloop(double * feature i = ilist[ii]; itype = pair->map[type[i]]; int f = pair->net[itype].dimensions[0]; - double expr[jnum][kmax+12]; + std::vector row(kmax+12, 0.0); + std::vector> expr(jnum, row); int p = kmax; int countmb=((mlength)*(mlength+1))>>1; double *si = sim->s[i]; @@ -355,13 +358,13 @@ void Fingerprint_bondspin::do3bodyfeatureset_singleneighborloop(double * feature expr[jj][p+1]=dely*rinvs; expr[jj][p+2]=delz*rinvs; //Hack to avoid nan when x y or z component of radial vector is exactly 0. Shouldn't affect accuracy. - if (expr[jj][p]*expr[jj][p]<0.000000000001) { + if (expr[jj][p]*expr[jj][p] < SMALL) { expr[jj][p] = 0.000001; } - if (expr[jj][p+1]*expr[jj][p+1]<0.000000000001) { + if (expr[jj][p+1]*expr[jj][p+1] < SMALL) { expr[jj][p+1] = 0.000001; } - if (expr[jj][p+2]*expr[jj][p+2]<0.000000000001) { + if (expr[jj][p+2]*expr[jj][p+2] < SMALL) { expr[jj][p+2] = 0.000001; } expr[jj][p+3] = -dfc*expr[jj][p]; @@ -378,8 +381,8 @@ void Fingerprint_bondspin::do3bodyfeatureset_singleneighborloop(double * feature int kb = kmax; int mb = mlength; count = startingneuron; - double Bb[mb]; - double Bbs[mb]; + std::vector Bb(mb, 0.0); + std::vector Bbs(mb, 0.0); double dBbx; double dBby; double dBbz; @@ -415,7 +418,7 @@ void Fingerprint_bondspin::do3bodyfeatureset_singleneighborloop(double * feature double *sj = sim->s[j]; double sp = si[0]*sj[0]+si[1]*sj[1]+si[2]*sj[2]; double yprod = expr[jj][ai]; - double *y4 = &expr[jj][p]; + double *y4 = expr[jj].data() + p; for (a2=0;a2 Bg(mb, 0.0); + std::vector Bgs(mb, 0.0); ai = n; double y1 = alpha_k[ai]/re; //loop over ktype to get Bg @@ -445,7 +444,7 @@ void Fingerprint_bondspin::do3bodyfeatureset_singleneighborloop(double * feature double *sj = sim->s[j]; double sp = si[0]*sj[0]+si[1]*sj[1]+si[2]*sj[2]; double yprod = expr[jj][ai]; - double *y4 = &expr[jj][p]; + double *y4 = expr[jj].data() + p; for (a2=0;a2s[j]; double sp = si[0]*sj[0]+si[1]*sj[1]+si[2]*sj[2]; - double *y3 = &expr[jj][p+3]; - double *y4 = &expr[jj][p]; + double *y3 = expr[jj].data() + p + 3; + double *y4 = expr[jj].data() + p; ai = n; yprod = expr[jj][ai]; for (a2=0;a2s[j]; double sp = si[0]*sj[0]+si[1]*sj[1]+si[2]*sj[2]; - double *y3 = &expr[jj][p+3]; - double *y4 = &expr[jj][p]; + double *y3 = expr[jj].data() + p + 3; + double *y4 = expr[jj].data() + p; ai = n; yprod = expr[jj][ai]; for (a2=0;a2s[j]; double sp = si[0]*sj[0]+si[1]*sj[1]+si[2]*sj[2]; - double *y3 = &expr[jj][p+3]; - double *y4 = &expr[jj][p]; + double *y3 = expr[jj].data() + p + 3; + double *y4 = expr[jj].data() + p; ai = n; yprod = expr[jj][ai]; for (a2=0;a2map[type[i]]; int f = pair->net[itype].dimensions[0]; - double expr[jnum][kmax]; - double y[jnum][3]; - double ri[jnum]; - double dfc[jnum]; + std::vector row(kmax, 0.0); + std::vector> expr(jnum, row); + std::vector yrow(3, 0.0); + std::vector> y(jnum, yrow); + std::vector ri(jnum, 0.0); + std::vector dfc(jnum, 0.0); int kb = kmax; int mb = mlength; - double c41[kmax]; - double c51[kmax]; - double c61[kmax]; - double ct[kmax]; + std::vector c41(kmax, 0.0); + std::vector c51(kmax, 0.0); + std::vector c61(kmax, 0.0); + std::vector ct(kmax, 0.0); double *si = sim->s[i]; for (jj = 0; jj < jnum; jj++) { jtype = tn[jj];