diff --git a/src/USER-MEAMC/meam.h b/src/USER-MEAMC/meam.h index 0590d2fe0..9932bfd9c 100644 --- a/src/USER-MEAMC/meam.h +++ b/src/USER-MEAMC/meam.h @@ -1,195 +1,189 @@ #ifndef LMP_MEAM_H #define LMP_MEAM_H #include #include "memory.h" #define maxelt 5 namespace LAMMPS_NS { typedef enum { FCC, BCC, HCP, DIM, DIA, B1, C11, L12, B2 } lattice_t; class MEAM { public: MEAM(Memory *mem) : memory(mem) {}; ~MEAM() { meam_cleanup(); } private: Memory *&memory; // cutforce = force cutoff // cutforcesq = force cutoff squared double cutforce, cutforcesq; // Ec_meam = cohesive energy // re_meam = nearest-neighbor distance // Omega_meam = atomic volume // B_meam = bulk modulus // Z_meam = number of first neighbors for reference structure // ielt_meam = atomic number of element // A_meam = adjustable parameter // alpha_meam = sqrt(9*Omega*B/Ec) // rho0_meam = density scaling parameter // delta_meam = heat of formation for alloys // beta[0-3]_meam = electron density constants // t[0-3]_meam = coefficients on densities in Gamma computation // rho_ref_meam = background density for reference structure // ibar_meam(i) = selection parameter for Gamma function for elt i, // lattce_meam(i,j) = lattce configuration for elt i or alloy (i,j) // neltypes = maximum number of element type defined // eltind = index number of pair (similar to Voigt notation; ij = ji) // phir = pair potential function array // phirar[1-6] = spline coeffs // attrac_meam = attraction parameter in Rose energy // repuls_meam = repulsion parameter in Rose energy // nn2_meam = 1 if second nearest neighbors are to be computed, else 0 // zbl_meam = 1 if zbl potential for small r to be use, else 0 // emb_lin_neg = 1 if linear embedding function for rhob to be used, else 0 // bkgd_dyn = 1 if reference densities follows Dynamo, else 0 // Cmin_meam, Cmax_meam = min and max values in screening cutoff // rc_meam = cutoff distance for meam // delr_meam = cutoff region for meam // ebound_meam = factor giving maximum boundary of sceen fcn ellipse // augt1 = flag for whether t1 coefficient should be augmented // ialloy = flag for newer alloy formulation (as in dynamo code) // mix_ref_t = flag to recover "old" way of computing t in reference config // erose_form = selection parameter for form of E_rose function // gsmooth_factor = factor determining length of G smoothing region // vind[23]D = Voight notation index maps for 2 and 3D // v2D,v3D = array of factors to apply for Voight notation // nr,dr = pair function discretization parameters // nrar,rdrar = spline coeff array parameters double Ec_meam[maxelt + 1][maxelt + 1], re_meam[maxelt + 1][maxelt + 1]; double Omega_meam[maxelt + 1], Z_meam[maxelt + 1]; double A_meam[maxelt + 1], alpha_meam[maxelt + 1][maxelt + 1], rho0_meam[maxelt + 1]; double delta_meam[maxelt + 1][maxelt + 1]; double beta0_meam[maxelt + 1], beta1_meam[maxelt + 1]; double beta2_meam[maxelt + 1], beta3_meam[maxelt + 1]; double t0_meam[maxelt + 1], t1_meam[maxelt + 1]; double t2_meam[maxelt + 1], t3_meam[maxelt + 1]; double rho_ref_meam[maxelt + 1]; int ibar_meam[maxelt + 1], ielt_meam[maxelt + 1]; lattice_t lattce_meam[maxelt + 1][maxelt + 1]; int nn2_meam[maxelt + 1][maxelt + 1]; int zbl_meam[maxelt + 1][maxelt + 1]; int eltind[maxelt + 1][maxelt + 1]; int neltypes; double **phir; double **phirar, **phirar1, **phirar2, **phirar3, **phirar4, **phirar5, **phirar6; double attrac_meam[maxelt + 1][maxelt + 1], repuls_meam[maxelt + 1][maxelt + 1]; double Cmin_meam[maxelt + 1][maxelt + 1][maxelt + 1]; double Cmax_meam[maxelt + 1][maxelt + 1][maxelt + 1]; double rc_meam, delr_meam, ebound_meam[maxelt + 1][maxelt + 1]; int augt1, ialloy, mix_ref_t, erose_form; int emb_lin_neg, bkgd_dyn; double gsmooth_factor; int vind2D[3 + 1][3 + 1], vind3D[3 + 1][3 + 1][3 + 1]; int v2D[6 + 1], v3D[10 + 1]; int nr, nrar; double dr, rdrar; protected: void meam_checkindex(int, int, int, int*, int*); void G_gam(double, int, double, double*, int*); void dG_gam(double, int, double, double*, double*); void getscreen(int, int, double*, double*, double*, double*, int, int*, int, int*, int, int*, int*); void screen(int, int, int, double*, double, double*, int, int*, int, int*, int*); void calc_rho1(int, int, int, int*, int*, double*, int, int*, double*, double*, double*, double*, double*, double*, double*, double*, double*, double*); void dsij(int, int, int, int, int, int, double, double*, double*, int, int*, int*, double*, double*, double*); void fcut(double, double*); void dfcut(double, double*, double*); void dCfunc(double, double, double, double*); void dCfunc2(double, double, double, double*, double*); void alloyparams(); void compute_pair_meam(); double phi_meam(double, int, int); void compute_reference_density(); void get_shpfcn(double*, lattice_t); void get_tavref(double*, double*, double*, double*, double*, double*, double, double, double, double, double, double, double, int, int, lattice_t); void get_Zij(int*, lattice_t); void get_Zij2(int*, double*, double*, lattice_t, double, double); void get_sijk(double, int, int, int, double*); void get_densref(double, int, int, double*, double*, double*, double*, double*, double*, double*, double*); double zbl(double, int, int); double erose(double, double, double, double, double, double, int); void interpolate_meam(int); double compute_phi(double, int, int); public: void meam_setup_global(int*, int*, double*, int*, double*, double*, double*, double*, double*, double*, double*, double*, double*, double*, double*, double*, double*, double*, int*); void meam_setup_param(int*, double*, int*, int*, int*); void meam_setup_done(double*); void meam_dens_init(int*, int*, int*, int*, int*, double*, int*, int*, int*, int*, double*, double*, double*, double*, double*, double*, double*, double*, double*, double*, double*, int*); void meam_dens_final(int*, int*, int*, int*, int*, double*, double*, int*, int*, int*, double*, double*, double*, double*, double*, double*, double*, double*, double*, double*, double*, double*, double*, double*, double*, double*, double*, int*); void meam_force(int*, int*, int*, int*, int*, int*, double*, double*, int*, int*, int*, double*, int*, int*, int*, int*, double*, double*, double*, double*, double*, double*, double*, double*, double*, double*, double*, double*, double*, double*, double*, double*, double*, double*, double*, double*, int*); void meam_cleanup(); }; // Functions we need for compat #define iszero(f) (fabs(f) < 1e-20) #define setall2d(arr, v) \ { \ for (int __i = 1; __i <= maxelt; __i++) \ for (int __j = 1; __j <= maxelt; __j++) \ arr[__i][__j] = v; \ } #define setall3d(arr, v) \ { \ for (int __i = 1; __i <= maxelt; __i++) \ for (int __j = 1; __j <= maxelt; __j++) \ for (int __k = 1; __k <= maxelt; __k++) \ arr[__i][__j][__k] = v; \ } /* Fortran Array Semantics in C. - Stack-Allocated and global arrays are 1-based, declared as foo[N+1] and simply ignoring the first element - Multi-Dimensional MUST be declared in reverse, so that the order when accessing is the same as in Fortran - arrays that are passed externally via the meam_* functions must use the arr*v() functions below (or be used with 0-based indexing) - - allocatable arrays must be accessed with arr2() */ // we receive a pointer to the first element, and F dimensions is ptr(a,b,c) // we know c data structure is ptr[c][b][a] #define arrdim2v(ptr, a, b) \ const int DIM1__##ptr = a; \ const int DIM2__##ptr = b; \ (void)(DIM1__##ptr); \ (void)(DIM2__##ptr); #define arrdim3v(ptr, a, b, c) \ const int DIM1__##ptr = a; \ const int DIM2__##ptr = b; \ const int DIM3__##ptr = c; \ (void)(DIM1__##ptr); (void)(DIM2__##ptr; (void)(DIM3__##ptr); // access data with same index as used in fortran (1-based) #define arr1v(ptr, i) ptr[i - 1] #define arr2v(ptr, i, j) ptr[(DIM1__##ptr) * (j - 1) + (i - 1)] #define arr3v(ptr, i, j, k) \ ptr[(i - 1) + (j - 1) * (DIM1__##ptr) + \ (k - 1) * (DIM1__##ptr) * (DIM2__##ptr)] - -// allocatable arrays -// access data with same index as used in fortran (1-based) -#define arr2(arr, i, j) arr[j-1][i-1] - }; #endif diff --git a/src/USER-MEAMC/meam_force.cpp b/src/USER-MEAMC/meam_force.cpp index 3b2d0d8b8..c5fd4b819 100644 --- a/src/USER-MEAMC/meam_force.cpp +++ b/src/USER-MEAMC/meam_force.cpp @@ -1,598 +1,598 @@ #include "meam.h" #include #include #include "math_special.h" using namespace LAMMPS_NS; // Extern "C" declaration has the form: // // void meam_force_(int *, int *, int *, double *, int *, int *, int *, double // *, // int *, int *, int *, int *, double *, double *, // double *, double *, double *, double *, double *, double *, // double *, double *, double *, double *, double *, double *, // double *, double *, double *, double *, double *, double *, int //*); // // Call from pair_meam.cpp has the form: // // meam_force_(&i,&nmax,&eflag_either,&eflag_global,&eflag_atom,&vflag_atom, // &eng_vdwl,eatom,&ntype,type,fmap,&x[0][0], // &numneigh[i],firstneigh[i],&numneigh_full[i],firstneigh_full[i], // &scrfcn[offset],&dscrfcn[offset],&fcpair[offset], // dgamma1,dgamma2,dgamma3,rho0,rho1,rho2,rho3,frhop, // &arho1[0][0],&arho2[0][0],arho2b,&arho3[0][0],&arho3b[0][0], // &t_ave[0][0],&tsq_ave[0][0],&f[0][0],&vatom[0][0],&errorflag); // void MEAM::meam_force(int* iptr, int* nmax, int* eflag_either, int* eflag_global, int* eflag_atom, int* vflag_atom, double* eng_vdwl, double* eatom, int* ntype, int* type, int* fmap, double* x, int* numneigh, int* firstneigh, int* numneigh_full, int* firstneigh_full, double* scrfcn, double* dscrfcn, double* fcpair, double* dGamma1, double* dGamma2, double* dGamma3, double* rho0, double* rho1, double* rho2, double* rho3, double* fp, double* Arho1, double* Arho2, double* Arho2b, double* Arho3, double* Arho3b, double* t_ave, double* tsq_ave, double* f, double* vatom, int* errorflag) { arrdim2v(x, 3, *nmax); arrdim2v(Arho1, 3, *nmax); arrdim2v(Arho2, 6, *nmax); arrdim2v(Arho3, 10, *nmax); arrdim2v(Arho3b, 3, *nmax); arrdim2v(t_ave, 3, *nmax); arrdim2v(tsq_ave, 3, *nmax); arrdim2v(f, 3, *nmax); arrdim2v(vatom, 6, *nmax); int i, j, jn, k, kn, kk, m, n, p, q; int nv2, nv3, elti, eltj, eltk, ind; double xitmp, yitmp, zitmp, delij[3 + 1], rij2, rij, rij3; double delik[3 + 1], deljk[3 + 1], v[6 + 1], fi[3 + 1], fj[3 + 1]; double third, sixth; double pp, dUdrij, dUdsij, dUdrijm[3 + 1], force, forcem; double r, recip, phi, phip; double sij; double a1, a1i, a1j, a2, a2i, a2j; double a3i, a3j; double shpi[3 + 1], shpj[3 + 1]; double ai, aj, ro0i, ro0j, invrei, invrej; double rhoa0j, drhoa0j, rhoa0i, drhoa0i; double rhoa1j, drhoa1j, rhoa1i, drhoa1i; double rhoa2j, drhoa2j, rhoa2i, drhoa2i; double a3, a3a, rhoa3j, drhoa3j, rhoa3i, drhoa3i; double drho0dr1, drho0dr2, drho0ds1, drho0ds2; double drho1dr1, drho1dr2, drho1ds1, drho1ds2; double drho1drm1[3 + 1], drho1drm2[3 + 1]; double drho2dr1, drho2dr2, drho2ds1, drho2ds2; double drho2drm1[3 + 1], drho2drm2[3 + 1]; double drho3dr1, drho3dr2, drho3ds1, drho3ds2; double drho3drm1[3 + 1], drho3drm2[3 + 1]; double dt1dr1, dt1dr2, dt1ds1, dt1ds2; double dt2dr1, dt2dr2, dt2ds1, dt2ds2; double dt3dr1, dt3dr2, dt3ds1, dt3ds2; double drhodr1, drhodr2, drhods1, drhods2, drhodrm1[3 + 1], drhodrm2[3 + 1]; double arg; double arg1i1, arg1j1, arg1i2, arg1j2, arg1i3, arg1j3, arg3i3, arg3j3; double dsij1, dsij2, force1, force2; double t1i, t2i, t3i, t1j, t2j, t3j; *errorflag = 0; third = 1.0 / 3.0; sixth = 1.0 / 6.0; //: aliased i = *iptr; // Compute forces atom i elti = arr1v(fmap, arr1v(type, i)); if (elti > 0) { xitmp = arr2v(x, 1, i); yitmp = arr2v(x, 2, i); zitmp = arr2v(x, 3, i); // Treat each pair for (jn = 1; jn <= *numneigh; jn++) { j = arr1v(firstneigh, jn); eltj = arr1v(fmap, arr1v(type, j)); if (!iszero(arr1v(scrfcn, jn)) && eltj > 0) { sij = arr1v(scrfcn, jn) * arr1v(fcpair, jn); delij[1] = arr2v(x, 1, j) - xitmp; delij[2] = arr2v(x, 2, j) - yitmp; delij[3] = arr2v(x, 3, j) - zitmp; rij2 = delij[1] * delij[1] + delij[2] * delij[2] + delij[3] * delij[3]; if (rij2 < this->cutforcesq) { rij = sqrt(rij2); r = rij; // Compute phi and phip - ind = this->eltind[elti][eltj]; - pp = rij * this->rdrar + 1.0; + ind = this->eltind[elti][eltj] - 1; //: TODO Remove -1 when reindexing eltind + pp = rij * this->rdrar; kk = (int)pp; - kk = std::min(kk, this->nrar - 1); + kk = std::min(kk, this->nrar - 2); pp = pp - kk; pp = std::min(pp, 1.0); - phi = ((arr2(this->phirar3, kk, ind) * pp + - arr2(this->phirar2, kk, ind)) * + phi = ((this->phirar3[ind][kk] * pp + + this->phirar2[ind][kk]) * pp + - arr2(this->phirar1, kk, ind)) * + this->phirar1[ind][kk]) * pp + - arr2(this->phirar, kk, ind); - phip = (arr2(this->phirar6, kk, ind) * pp + - arr2(this->phirar5, kk, ind)) * + this->phirar[ind][kk]; + phip = (this->phirar6[ind][kk] * pp + + this->phirar5[ind][kk]) * pp + - arr2(this->phirar4, kk, ind); + this->phirar4[ind][kk]; recip = 1.0 / r; if (*eflag_either != 0) { if (*eflag_global != 0) *eng_vdwl = *eng_vdwl + phi * sij; if (*eflag_atom != 0) { arr1v(eatom, i) = arr1v(eatom, i) + 0.5 * phi * sij; arr1v(eatom, j) = arr1v(eatom, j) + 0.5 * phi * sij; } } // write(1,*) "force_meamf: phi: ",phi // write(1,*) "force_meamf: phip: ",phip // Compute pair densities and derivatives invrei = 1.0 / this->re_meam[elti][elti]; ai = rij * invrei - 1.0; ro0i = this->rho0_meam[elti]; rhoa0i = ro0i * MathSpecial::fm_exp(-this->beta0_meam[elti] * ai); drhoa0i = -this->beta0_meam[elti] * invrei * rhoa0i; rhoa1i = ro0i * MathSpecial::fm_exp(-this->beta1_meam[elti] * ai); drhoa1i = -this->beta1_meam[elti] * invrei * rhoa1i; rhoa2i = ro0i * MathSpecial::fm_exp(-this->beta2_meam[elti] * ai); drhoa2i = -this->beta2_meam[elti] * invrei * rhoa2i; rhoa3i = ro0i * MathSpecial::fm_exp(-this->beta3_meam[elti] * ai); drhoa3i = -this->beta3_meam[elti] * invrei * rhoa3i; if (elti != eltj) { invrej = 1.0 / this->re_meam[eltj][eltj]; aj = rij * invrej - 1.0; ro0j = this->rho0_meam[eltj]; rhoa0j = ro0j * MathSpecial::fm_exp(-this->beta0_meam[eltj] * aj); drhoa0j = -this->beta0_meam[eltj] * invrej * rhoa0j; rhoa1j = ro0j * MathSpecial::fm_exp(-this->beta1_meam[eltj] * aj); drhoa1j = -this->beta1_meam[eltj] * invrej * rhoa1j; rhoa2j = ro0j * MathSpecial::fm_exp(-this->beta2_meam[eltj] * aj); drhoa2j = -this->beta2_meam[eltj] * invrej * rhoa2j; rhoa3j = ro0j * MathSpecial::fm_exp(-this->beta3_meam[eltj] * aj); drhoa3j = -this->beta3_meam[eltj] * invrej * rhoa3j; } else { rhoa0j = rhoa0i; drhoa0j = drhoa0i; rhoa1j = rhoa1i; drhoa1j = drhoa1i; rhoa2j = rhoa2i; drhoa2j = drhoa2i; rhoa3j = rhoa3i; drhoa3j = drhoa3i; } if (this->ialloy == 1) { rhoa1j = rhoa1j * this->t1_meam[eltj]; rhoa2j = rhoa2j * this->t2_meam[eltj]; rhoa3j = rhoa3j * this->t3_meam[eltj]; rhoa1i = rhoa1i * this->t1_meam[elti]; rhoa2i = rhoa2i * this->t2_meam[elti]; rhoa3i = rhoa3i * this->t3_meam[elti]; drhoa1j = drhoa1j * this->t1_meam[eltj]; drhoa2j = drhoa2j * this->t2_meam[eltj]; drhoa3j = drhoa3j * this->t3_meam[eltj]; drhoa1i = drhoa1i * this->t1_meam[elti]; drhoa2i = drhoa2i * this->t2_meam[elti]; drhoa3i = drhoa3i * this->t3_meam[elti]; } nv2 = 1; nv3 = 1; arg1i1 = 0.0; arg1j1 = 0.0; arg1i2 = 0.0; arg1j2 = 0.0; arg1i3 = 0.0; arg1j3 = 0.0; arg3i3 = 0.0; arg3j3 = 0.0; for (n = 1; n <= 3; n++) { for (p = n; p <= 3; p++) { for (q = p; q <= 3; q++) { arg = delij[n] * delij[p] * delij[q] * this->v3D[nv3]; arg1i3 = arg1i3 + arr2v(Arho3, nv3, i) * arg; arg1j3 = arg1j3 - arr2v(Arho3, nv3, j) * arg; nv3 = nv3 + 1; } arg = delij[n] * delij[p] * this->v2D[nv2]; arg1i2 = arg1i2 + arr2v(Arho2, nv2, i) * arg; arg1j2 = arg1j2 + arr2v(Arho2, nv2, j) * arg; nv2 = nv2 + 1; } arg1i1 = arg1i1 + arr2v(Arho1, n, i) * delij[n]; arg1j1 = arg1j1 - arr2v(Arho1, n, j) * delij[n]; arg3i3 = arg3i3 + arr2v(Arho3b, n, i) * delij[n]; arg3j3 = arg3j3 - arr2v(Arho3b, n, j) * delij[n]; } // rho0 terms drho0dr1 = drhoa0j * sij; drho0dr2 = drhoa0i * sij; // rho1 terms a1 = 2 * sij / rij; drho1dr1 = a1 * (drhoa1j - rhoa1j / rij) * arg1i1; drho1dr2 = a1 * (drhoa1i - rhoa1i / rij) * arg1j1; a1 = 2.0 * sij / rij; for (m = 1; m <= 3; m++) { drho1drm1[m] = a1 * rhoa1j * arr2v(Arho1, m, i); drho1drm2[m] = -a1 * rhoa1i * arr2v(Arho1, m, j); } // rho2 terms a2 = 2 * sij / rij2; drho2dr1 = a2 * (drhoa2j - 2 * rhoa2j / rij) * arg1i2 - 2.0 / 3.0 * arr1v(Arho2b, i) * drhoa2j * sij; drho2dr2 = a2 * (drhoa2i - 2 * rhoa2i / rij) * arg1j2 - 2.0 / 3.0 * arr1v(Arho2b, j) * drhoa2i * sij; a2 = 4 * sij / rij2; for (m = 1; m <= 3; m++) { drho2drm1[m] = 0.0; drho2drm2[m] = 0.0; for (n = 1; n <= 3; n++) { drho2drm1[m] = drho2drm1[m] + arr2v(Arho2, this->vind2D[m][n], i) * delij[n]; drho2drm2[m] = drho2drm2[m] - arr2v(Arho2, this->vind2D[m][n], j) * delij[n]; } drho2drm1[m] = a2 * rhoa2j * drho2drm1[m]; drho2drm2[m] = -a2 * rhoa2i * drho2drm2[m]; } // rho3 terms rij3 = rij * rij2; a3 = 2 * sij / rij3; a3a = 6.0 / 5.0 * sij / rij; drho3dr1 = a3 * (drhoa3j - 3 * rhoa3j / rij) * arg1i3 - a3a * (drhoa3j - rhoa3j / rij) * arg3i3; drho3dr2 = a3 * (drhoa3i - 3 * rhoa3i / rij) * arg1j3 - a3a * (drhoa3i - rhoa3i / rij) * arg3j3; a3 = 6 * sij / rij3; a3a = 6 * sij / (5 * rij); for (m = 1; m <= 3; m++) { drho3drm1[m] = 0.0; drho3drm2[m] = 0.0; nv2 = 1; for (n = 1; n <= 3; n++) { for (p = n; p <= 3; p++) { arg = delij[n] * delij[p] * this->v2D[nv2]; drho3drm1[m] = drho3drm1[m] + arr2v(Arho3, this->vind3D[m][n][p], i) * arg; drho3drm2[m] = drho3drm2[m] + arr2v(Arho3, this->vind3D[m][n][p], j) * arg; nv2 = nv2 + 1; } } drho3drm1[m] = (a3 * drho3drm1[m] - a3a * arr2v(Arho3b, m, i)) * rhoa3j; drho3drm2[m] = (-a3 * drho3drm2[m] + a3a * arr2v(Arho3b, m, j)) * rhoa3i; } // Compute derivatives of weighting functions t wrt rij t1i = arr2v(t_ave, 1, i); t2i = arr2v(t_ave, 2, i); t3i = arr2v(t_ave, 3, i); t1j = arr2v(t_ave, 1, j); t2j = arr2v(t_ave, 2, j); t3j = arr2v(t_ave, 3, j); if (this->ialloy == 1) { a1i = 0.0; a1j = 0.0; a2i = 0.0; a2j = 0.0; a3i = 0.0; a3j = 0.0; if (!iszero(arr2v(tsq_ave, 1, i))) a1i = drhoa0j * sij / arr2v(tsq_ave, 1, i); if (!iszero(arr2v(tsq_ave, 1, j))) a1j = drhoa0i * sij / arr2v(tsq_ave, 1, j); if (!iszero(arr2v(tsq_ave, 2, i))) a2i = drhoa0j * sij / arr2v(tsq_ave, 2, i); if (!iszero(arr2v(tsq_ave, 2, j))) a2j = drhoa0i * sij / arr2v(tsq_ave, 2, j); if (!iszero(arr2v(tsq_ave, 3, i))) a3i = drhoa0j * sij / arr2v(tsq_ave, 3, i); if (!iszero(arr2v(tsq_ave, 3, j))) a3j = drhoa0i * sij / arr2v(tsq_ave, 3, j); dt1dr1 = a1i * (this->t1_meam[eltj] - t1i * pow(this->t1_meam[eltj], 2)); dt1dr2 = a1j * (this->t1_meam[elti] - t1j * pow(this->t1_meam[elti], 2)); dt2dr1 = a2i * (this->t2_meam[eltj] - t2i * pow(this->t2_meam[eltj], 2)); dt2dr2 = a2j * (this->t2_meam[elti] - t2j * pow(this->t2_meam[elti], 2)); dt3dr1 = a3i * (this->t3_meam[eltj] - t3i * pow(this->t3_meam[eltj], 2)); dt3dr2 = a3j * (this->t3_meam[elti] - t3j * pow(this->t3_meam[elti], 2)); } else if (this->ialloy == 2) { dt1dr1 = 0.0; dt1dr2 = 0.0; dt2dr1 = 0.0; dt2dr2 = 0.0; dt3dr1 = 0.0; dt3dr2 = 0.0; } else { ai = 0.0; if (!iszero(arr1v(rho0, i))) ai = drhoa0j * sij / arr1v(rho0, i); aj = 0.0; if (!iszero(arr1v(rho0, j))) aj = drhoa0i * sij / arr1v(rho0, j); dt1dr1 = ai * (this->t1_meam[elti] - t1i); dt1dr2 = aj * (this->t1_meam[elti] - t1j); dt2dr1 = ai * (this->t2_meam[elti] - t2i); dt2dr2 = aj * (this->t2_meam[elti] - t2j); dt3dr1 = ai * (this->t3_meam[elti] - t3i); dt3dr2 = aj * (this->t3_meam[elti] - t3j); } // Compute derivatives of total density wrt rij, sij and rij(3) get_shpfcn(shpi, this->lattce_meam[elti][elti]); get_shpfcn(shpj, this->lattce_meam[eltj][eltj]); drhodr1 = arr1v(dGamma1, i) * drho0dr1 + arr1v(dGamma2, i) * (dt1dr1 * arr1v(rho1, i) + t1i * drho1dr1 + dt2dr1 * arr1v(rho2, i) + t2i * drho2dr1 + dt3dr1 * arr1v(rho3, i) + t3i * drho3dr1) - arr1v(dGamma3, i) * (shpi[1] * dt1dr1 + shpi[2] * dt2dr1 + shpi[3] * dt3dr1); drhodr2 = arr1v(dGamma1, j) * drho0dr2 + arr1v(dGamma2, j) * (dt1dr2 * arr1v(rho1, j) + t1j * drho1dr2 + dt2dr2 * arr1v(rho2, j) + t2j * drho2dr2 + dt3dr2 * arr1v(rho3, j) + t3j * drho3dr2) - arr1v(dGamma3, j) * (shpj[1] * dt1dr2 + shpj[2] * dt2dr2 + shpj[3] * dt3dr2); for (m = 1; m <= 3; m++) { drhodrm1[m] = 0.0; drhodrm2[m] = 0.0; drhodrm1[m] = arr1v(dGamma2, i) * (t1i * drho1drm1[m] + t2i * drho2drm1[m] + t3i * drho3drm1[m]); drhodrm2[m] = arr1v(dGamma2, j) * (t1j * drho1drm2[m] + t2j * drho2drm2[m] + t3j * drho3drm2[m]); } // Compute derivatives wrt sij, but only if necessary if (!iszero(arr1v(dscrfcn, jn))) { drho0ds1 = rhoa0j; drho0ds2 = rhoa0i; a1 = 2.0 / rij; drho1ds1 = a1 * rhoa1j * arg1i1; drho1ds2 = a1 * rhoa1i * arg1j1; a2 = 2.0 / rij2; drho2ds1 = a2 * rhoa2j * arg1i2 - 2.0 / 3.0 * arr1v(Arho2b, i) * rhoa2j; drho2ds2 = a2 * rhoa2i * arg1j2 - 2.0 / 3.0 * arr1v(Arho2b, j) * rhoa2i; a3 = 2.0 / rij3; a3a = 6.0 / (5.0 * rij); drho3ds1 = a3 * rhoa3j * arg1i3 - a3a * rhoa3j * arg3i3; drho3ds2 = a3 * rhoa3i * arg1j3 - a3a * rhoa3i * arg3j3; if (this->ialloy == 1) { a1i = 0.0; a1j = 0.0; a2i = 0.0; a2j = 0.0; a3i = 0.0; a3j = 0.0; if (!iszero(arr2v(tsq_ave, 1, i))) a1i = rhoa0j / arr2v(tsq_ave, 1, i); if (!iszero(arr2v(tsq_ave, 1, j))) a1j = rhoa0i / arr2v(tsq_ave, 1, j); if (!iszero(arr2v(tsq_ave, 2, i))) a2i = rhoa0j / arr2v(tsq_ave, 2, i); if (!iszero(arr2v(tsq_ave, 2, j))) a2j = rhoa0i / arr2v(tsq_ave, 2, j); if (!iszero(arr2v(tsq_ave, 3, i))) a3i = rhoa0j / arr2v(tsq_ave, 3, i); if (!iszero(arr2v(tsq_ave, 3, j))) a3j = rhoa0i / arr2v(tsq_ave, 3, j); dt1ds1 = a1i * (this->t1_meam[eltj] - t1i * pow(this->t1_meam[eltj], 2)); dt1ds2 = a1j * (this->t1_meam[elti] - t1j * pow(this->t1_meam[elti], 2)); dt2ds1 = a2i * (this->t2_meam[eltj] - t2i * pow(this->t2_meam[eltj], 2)); dt2ds2 = a2j * (this->t2_meam[elti] - t2j * pow(this->t2_meam[elti], 2)); dt3ds1 = a3i * (this->t3_meam[eltj] - t3i * pow(this->t3_meam[eltj], 2)); dt3ds2 = a3j * (this->t3_meam[elti] - t3j * pow(this->t3_meam[elti], 2)); } else if (this->ialloy == 2) { dt1ds1 = 0.0; dt1ds2 = 0.0; dt2ds1 = 0.0; dt2ds2 = 0.0; dt3ds1 = 0.0; dt3ds2 = 0.0; } else { ai = 0.0; if (!iszero(arr1v(rho0, i))) ai = rhoa0j / arr1v(rho0, i); aj = 0.0; if (!iszero(arr1v(rho0, j))) aj = rhoa0i / arr1v(rho0, j); dt1ds1 = ai * (this->t1_meam[eltj] - t1i); dt1ds2 = aj * (this->t1_meam[elti] - t1j); dt2ds1 = ai * (this->t2_meam[eltj] - t2i); dt2ds2 = aj * (this->t2_meam[elti] - t2j); dt3ds1 = ai * (this->t3_meam[eltj] - t3i); dt3ds2 = aj * (this->t3_meam[elti] - t3j); } drhods1 = arr1v(dGamma1, i) * drho0ds1 + arr1v(dGamma2, i) * (dt1ds1 * arr1v(rho1, i) + t1i * drho1ds1 + dt2ds1 * arr1v(rho2, i) + t2i * drho2ds1 + dt3ds1 * arr1v(rho3, i) + t3i * drho3ds1) - arr1v(dGamma3, i) * (shpi[1] * dt1ds1 + shpi[2] * dt2ds1 + shpi[3] * dt3ds1); drhods2 = arr1v(dGamma1, j) * drho0ds2 + arr1v(dGamma2, j) * (dt1ds2 * arr1v(rho1, j) + t1j * drho1ds2 + dt2ds2 * arr1v(rho2, j) + t2j * drho2ds2 + dt3ds2 * arr1v(rho3, j) + t3j * drho3ds2) - arr1v(dGamma3, j) * (shpj[1] * dt1ds2 + shpj[2] * dt2ds2 + shpj[3] * dt3ds2); } // Compute derivatives of energy wrt rij, sij and rij[3] dUdrij = phip * sij + arr1v(fp, i) * drhodr1 + arr1v(fp, j) * drhodr2; dUdsij = 0.0; if (!iszero(arr1v(dscrfcn, jn))) { dUdsij = phi + arr1v(fp, i) * drhods1 + arr1v(fp, j) * drhods2; } for (m = 1; m <= 3; m++) { dUdrijm[m] = arr1v(fp, i) * drhodrm1[m] + arr1v(fp, j) * drhodrm2[m]; } // Add the part of the force due to dUdrij and dUdsij force = dUdrij * recip + dUdsij * arr1v(dscrfcn, jn); for (m = 1; m <= 3; m++) { forcem = delij[m] * force + dUdrijm[m]; arr2v(f, m, i) = arr2v(f, m, i) + forcem; arr2v(f, m, j) = arr2v(f, m, j) - forcem; } // Tabulate per-atom virial as symmetrized stress tensor if (*vflag_atom != 0) { fi[1] = delij[1] * force + dUdrijm[1]; fi[2] = delij[2] * force + dUdrijm[2]; fi[3] = delij[3] * force + dUdrijm[3]; v[1] = -0.5 * (delij[1] * fi[1]); v[2] = -0.5 * (delij[2] * fi[2]); v[3] = -0.5 * (delij[3] * fi[3]); v[4] = -0.25 * (delij[1] * fi[2] + delij[2] * fi[1]); v[5] = -0.25 * (delij[1] * fi[3] + delij[3] * fi[1]); v[6] = -0.25 * (delij[2] * fi[3] + delij[3] * fi[2]); arr2v(vatom, 1, i) = arr2v(vatom, 1, i) + v[1]; arr2v(vatom, 2, i) = arr2v(vatom, 2, i) + v[2]; arr2v(vatom, 3, i) = arr2v(vatom, 3, i) + v[3]; arr2v(vatom, 4, i) = arr2v(vatom, 4, i) + v[4]; arr2v(vatom, 5, i) = arr2v(vatom, 5, i) + v[5]; arr2v(vatom, 6, i) = arr2v(vatom, 6, i) + v[6]; arr2v(vatom, 1, j) = arr2v(vatom, 1, j) + v[1]; arr2v(vatom, 2, j) = arr2v(vatom, 2, j) + v[2]; arr2v(vatom, 3, j) = arr2v(vatom, 3, j) + v[3]; arr2v(vatom, 4, j) = arr2v(vatom, 4, j) + v[4]; arr2v(vatom, 5, j) = arr2v(vatom, 5, j) + v[5]; arr2v(vatom, 6, j) = arr2v(vatom, 6, j) + v[6]; } // Now compute forces on other atoms k due to change in sij if (iszero(sij) || iszero(sij - 1.0)) continue; //: cont jn loop for (kn = 1; kn <= *numneigh_full; kn++) { k = arr1v(firstneigh_full, kn); eltk = arr1v(fmap, arr1v(type, k)); if (k != j && eltk > 0) { dsij(i, j, k, jn, *nmax, *numneigh, rij2, &dsij1, &dsij2, *ntype, type, fmap, x, scrfcn, fcpair); if (!iszero(dsij1) || !iszero(dsij2)) { force1 = dUdsij * dsij1; force2 = dUdsij * dsij2; for (m = 1; m <= 3; m++) { delik[m] = arr2v(x, m, k) - arr2v(x, m, i); deljk[m] = arr2v(x, m, k) - arr2v(x, m, j); } for (m = 1; m <= 3; m++) { arr2v(f, m, i) = arr2v(f, m, i) + force1 * delik[m]; arr2v(f, m, j) = arr2v(f, m, j) + force2 * deljk[m]; arr2v(f, m, k) = arr2v(f, m, k) - force1 * delik[m] - force2 * deljk[m]; } // Tabulate per-atom virial as symmetrized stress tensor if (*vflag_atom != 0) { fi[1] = force1 * delik[1]; fi[2] = force1 * delik[2]; fi[3] = force1 * delik[3]; fj[1] = force2 * deljk[1]; fj[2] = force2 * deljk[2]; fj[3] = force2 * deljk[3]; v[1] = -third * (delik[1] * fi[1] + deljk[1] * fj[1]); v[2] = -third * (delik[2] * fi[2] + deljk[2] * fj[2]); v[3] = -third * (delik[3] * fi[3] + deljk[3] * fj[3]); v[4] = -sixth * (delik[1] * fi[2] + deljk[1] * fj[2] + delik[2] * fi[1] + deljk[2] * fj[1]); v[5] = -sixth * (delik[1] * fi[3] + deljk[1] * fj[3] + delik[3] * fi[1] + deljk[3] * fj[1]); v[6] = -sixth * (delik[2] * fi[3] + deljk[2] * fj[3] + delik[3] * fi[2] + deljk[3] * fj[2]); arr2v(vatom, 1, i) = arr2v(vatom, 1, i) + v[1]; arr2v(vatom, 2, i) = arr2v(vatom, 2, i) + v[2]; arr2v(vatom, 3, i) = arr2v(vatom, 3, i) + v[3]; arr2v(vatom, 4, i) = arr2v(vatom, 4, i) + v[4]; arr2v(vatom, 5, i) = arr2v(vatom, 5, i) + v[5]; arr2v(vatom, 6, i) = arr2v(vatom, 6, i) + v[6]; arr2v(vatom, 1, j) = arr2v(vatom, 1, j) + v[1]; arr2v(vatom, 2, j) = arr2v(vatom, 2, j) + v[2]; arr2v(vatom, 3, j) = arr2v(vatom, 3, j) + v[3]; arr2v(vatom, 4, j) = arr2v(vatom, 4, j) + v[4]; arr2v(vatom, 5, j) = arr2v(vatom, 5, j) + v[5]; arr2v(vatom, 6, j) = arr2v(vatom, 6, j) + v[6]; arr2v(vatom, 1, k) = arr2v(vatom, 1, k) + v[1]; arr2v(vatom, 2, k) = arr2v(vatom, 2, k) + v[2]; arr2v(vatom, 3, k) = arr2v(vatom, 3, k) + v[3]; arr2v(vatom, 4, k) = arr2v(vatom, 4, k) + v[4]; arr2v(vatom, 5, k) = arr2v(vatom, 5, k) + v[5]; arr2v(vatom, 6, k) = arr2v(vatom, 6, k) + v[6]; } } } // end of k loop } } } // end of j loop } // else if elti=0, this is not a meam atom } } diff --git a/src/USER-MEAMC/meam_setup_done.cpp b/src/USER-MEAMC/meam_setup_done.cpp index 5e1ad1f4d..1f701061a 100644 --- a/src/USER-MEAMC/meam_setup_done.cpp +++ b/src/USER-MEAMC/meam_setup_done.cpp @@ -1,1066 +1,1070 @@ #include "meam.h" #include #include #include "math_special.h" using namespace LAMMPS_NS; // Declaration in pair_meam.h: // // void meam_setup_done(double *) // // Call from pair_meam.cpp: // // meam_setup_done(&cutmax) // void MEAM::meam_setup_done(double* cutmax) { int nv2, nv3, m, n, p; // Force cutoff this->cutforce = this->rc_meam; this->cutforcesq = this->cutforce * this->cutforce; // Pass cutoff back to calling program *cutmax = this->cutforce; // Augment t1 term for (int i = 1; i <= maxelt; i++) this->t1_meam[i] = this->t1_meam[i] + this->augt1 * 3.0 / 5.0 * this->t3_meam[i]; // Compute off-diagonal alloy parameters alloyparams(); // indices and factors for Voight notation nv2 = 1; nv3 = 1; for (m = 1; m <= 3; m++) { for (n = m; n <= 3; n++) { this->vind2D[m][n] = nv2; this->vind2D[n][m] = nv2; nv2 = nv2 + 1; for (p = n; p <= 3; p++) { this->vind3D[m][n][p] = nv3; this->vind3D[m][p][n] = nv3; this->vind3D[n][m][p] = nv3; this->vind3D[n][p][m] = nv3; this->vind3D[p][m][n] = nv3; this->vind3D[p][n][m] = nv3; nv3 = nv3 + 1; } } } this->v2D[1] = 1; this->v2D[2] = 2; this->v2D[3] = 2; this->v2D[4] = 1; this->v2D[5] = 2; this->v2D[6] = 1; this->v3D[1] = 1; this->v3D[2] = 3; this->v3D[3] = 3; this->v3D[4] = 3; this->v3D[5] = 6; this->v3D[6] = 3; this->v3D[7] = 1; this->v3D[8] = 3; this->v3D[9] = 3; this->v3D[10] = 1; nv2 = 1; for (m = 1; m <= this->neltypes; m++) { for (n = m; n <= this->neltypes; n++) { this->eltind[m][n] = nv2; this->eltind[n][m] = nv2; nv2 = nv2 + 1; } } // Compute background densities for reference structure compute_reference_density(); // Compute pair potentials and setup arrays for interpolation this->nr = 1000; this->dr = 1.1 * this->rc_meam / this->nr; compute_pair_meam(); } // ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc // Fill off-diagonal alloy parameters void MEAM::alloyparams(void) { int i, j, k; double eb; // Loop over pairs for (i = 1; i <= this->neltypes; i++) { for (j = 1; i <= this->neltypes; i++) { // Treat off-diagonal pairs // If i>j, set all equal to i j) { this->re_meam[i][j] = this->re_meam[j][i]; this->Ec_meam[i][j] = this->Ec_meam[j][i]; this->alpha_meam[i][j] = this->alpha_meam[j][i]; this->lattce_meam[i][j] = this->lattce_meam[j][i]; this->nn2_meam[i][j] = this->nn2_meam[j][i]; // If i i) { if (iszero(this->Ec_meam[i][j])) { if (this->lattce_meam[i][j] == L12) this->Ec_meam[i][j] = (3 * this->Ec_meam[i][i] + this->Ec_meam[j][j]) / 4.0 - this->delta_meam[i][j]; else if (this->lattce_meam[i][j] == C11) { if (this->lattce_meam[i][i] == DIA) this->Ec_meam[i][j] = (2 * this->Ec_meam[i][i] + this->Ec_meam[j][j]) / 3.0 - this->delta_meam[i][j]; else this->Ec_meam[i][j] = (this->Ec_meam[i][i] + 2 * this->Ec_meam[j][j]) / 3.0 - this->delta_meam[i][j]; } else this->Ec_meam[i][j] = (this->Ec_meam[i][i] + this->Ec_meam[j][j]) / 2.0 - this->delta_meam[i][j]; } if (iszero(this->alpha_meam[i][j])) this->alpha_meam[i][j] = (this->alpha_meam[i][i] + this->alpha_meam[j][j]) / 2.0; if (iszero(this->re_meam[i][j])) this->re_meam[i][j] = (this->re_meam[i][i] + this->re_meam[j][j]) / 2.0; } } } // Cmin[i][k][j] is symmetric in i-j, but not k. For all triplets // where i>j, set equal to the ineltypes; i++) { for (j = 1; j <= i - 1; j++) { for (k = 1; k <= this->neltypes; k++) { this->Cmin_meam[i][j][k] = this->Cmin_meam[j][i][k]; this->Cmax_meam[i][j][k] = this->Cmax_meam[j][i][k]; } } } // ebound gives the squared distance such that, for rik2 or rjk2>ebound, // atom k definitely lies outside the screening function ellipse (so // there is no need to calculate its effects). Here, compute it for all // triplets [i][j][k] so that ebound[i][j] is the maximized over k for (i = 2; i <= this->neltypes; i++) { for (j = 1; j <= this->neltypes; j++) { for (k = 1; k <= this->neltypes; k++) { eb = (this->Cmax_meam[i][j][k] * this->Cmax_meam[i][j][k]) / (4.0 * (this->Cmax_meam[i][j][k] - 1.0)); this->ebound_meam[i][j] = std::max(this->ebound_meam[i][j], eb); } } } } //----------------------------------------------------------------------- // compute MEAM pair potential for each pair of element types // void MEAM::compute_pair_meam(void) { double r /*ununsed:, temp*/; int j, a, b, nv2; double astar, frac, phizbl; int n, nmax, Z1, Z2; double arat, rarat, scrn, scrn2; double phiaa, phibb /*unused:,phitmp*/; double C, s111, s112, s221, S11, S22; // check for previously allocated arrays and free them if (this->phir != NULL) memory->destroy(this->phir); if (this->phirar != NULL) memory->destroy(this->phirar); if (this->phirar1 != NULL) memory->destroy(this->phirar1); if (this->phirar2 != NULL) memory->destroy(this->phirar2); if (this->phirar3 != NULL) memory->destroy(this->phirar3); if (this->phirar4 != NULL) memory->destroy(this->phirar4); if (this->phirar5 != NULL) memory->destroy(this->phirar5); if (this->phirar6 != NULL) memory->destroy(this->phirar6); // allocate memory for array that defines the potential - memory->create(this->phir, this->nr, + memory->create(this->phir, (this->neltypes * (this->neltypes + 1)) / 2, + this->nr, "pair:phir"); // allocate coeff memory - memory->create(this->phirar, this->nr, + memory->create(this->phirar, (this->neltypes * (this->neltypes + 1)) / 2, + this->nr, "pair:phirar"); - memory->create(this->phirar1, this->nr, + memory->create(this->phirar1, (this->neltypes * (this->neltypes + 1)) / 2, + this->nr, "pair:phirar1"); - memory->create(this->phirar2, this->nr, + memory->create(this->phirar2, (this->neltypes * (this->neltypes + 1)) / 2, + this->nr, "pair:phirar2"); - memory->create(this->phirar3, this->nr, + memory->create(this->phirar3, (this->neltypes * (this->neltypes + 1)) / 2, + this->nr, "pair:phirar3"); - memory->create(this->phirar4, this->nr, + memory->create(this->phirar4, (this->neltypes * (this->neltypes + 1)) / 2, + this->nr, "pair:phirar4"); - memory->create(this->phirar5, this->nr, + memory->create(this->phirar5, (this->neltypes * (this->neltypes + 1)) / 2, + this->nr, "pair:phirar5"); - memory->create(this->phirar6, this->nr, + memory->create(this->phirar6, (this->neltypes * (this->neltypes + 1)) / 2, + this->nr, "pair:phirar6"); // loop over pairs of element types nv2 = 0; for (a = 1; a <= this->neltypes; a++) { for (b = a; b <= this->neltypes; b++) { - nv2 = nv2 + 1; - // loop over r values and compute - for (j = 1; j <= this->nr; j++) { - r = (j - 1) * this->dr; + for (j = 0; j < this->nr; j++) { + r = j * this->dr; - arr2(this->phir, j, nv2) = phi_meam(r, a, b); + this->phir[nv2][j] = phi_meam(r, a, b); // if using second-nearest neighbor, solve recursive problem // (see Lee and Baskes, PRB 62(13):8564 eqn.(21)) if (this->nn2_meam[a][b] == 1) { get_Zij(&Z1, this->lattce_meam[a][b]); get_Zij2(&Z2, &arat, &scrn, this->lattce_meam[a][b], this->Cmin_meam[a][a][b], this->Cmax_meam[a][a][b]); // The B1, B2, and L12 cases with NN2 have a trick to them; we // need to // compute the contributions from second nearest neighbors, like // a-a // pairs, but need to include NN2 contributions to those pairs as // well. if (this->lattce_meam[a][b] == B1 || this->lattce_meam[a][b] == B2 || this->lattce_meam[a][b] == L12) { rarat = r * arat; // phi_aa phiaa = phi_meam(rarat, a, a); get_Zij(&Z1, this->lattce_meam[a][a]); get_Zij2(&Z2, &arat, &scrn, this->lattce_meam[a][a], this->Cmin_meam[a][a][a], this->Cmax_meam[a][a][a]); nmax = 10; if (scrn > 0.0) { for (n = 1; n <= nmax; n++) { phiaa = phiaa + pow((-Z2 * scrn / Z1), n) * phi_meam(rarat * pow(arat, n), a, a); } } // phi_bb phibb = phi_meam(rarat, b, b); get_Zij(&Z1, this->lattce_meam[b][b]); get_Zij2(&Z2, &arat, &scrn, this->lattce_meam[b][b], this->Cmin_meam[b][b][b], this->Cmax_meam[b][b][b]); nmax = 10; if (scrn > 0.0) { for (n = 1; n <= nmax; n++) { phibb = phibb + pow((-Z2 * scrn / Z1), n) * phi_meam(rarat * pow(arat, n), b, b); } } if (this->lattce_meam[a][b] == B1 || this->lattce_meam[a][b] == B2) { // Add contributions to the B1 or B2 potential get_Zij(&Z1, this->lattce_meam[a][b]); get_Zij2(&Z2, &arat, &scrn, this->lattce_meam[a][b], this->Cmin_meam[a][a][b], this->Cmax_meam[a][a][b]); - arr2(this->phir, j, nv2) = - arr2(this->phir, j, nv2) - Z2 * scrn / (2 * Z1) * phiaa; + this->phir[nv2][j] = + this->phir[nv2][j] - Z2 * scrn / (2 * Z1) * phiaa; get_Zij2(&Z2, &arat, &scrn2, this->lattce_meam[a][b], this->Cmin_meam[b][b][a], this->Cmax_meam[b][b][a]); - arr2(this->phir, j, nv2) = - arr2(this->phir, j, nv2) - Z2 * scrn2 / (2 * Z1) * phibb; + this->phir[nv2][j] = + this->phir[nv2][j] - Z2 * scrn2 / (2 * Z1) * phibb; } else if (this->lattce_meam[a][b] == L12) { // The L12 case has one last trick; we have to be careful to // compute // the correct screening between 2nd-neighbor pairs. 1-1 // second-neighbor pairs are screened by 2 type 1 atoms and // two type // 2 atoms. 2-2 second-neighbor pairs are screened by 4 type // 1 // atoms. C = 1.0; get_sijk(C, a, a, a, &s111); get_sijk(C, a, a, b, &s112); get_sijk(C, b, b, a, &s221); S11 = s111 * s111 * s112 * s112; S22 = pow(s221, 4); - arr2(this->phir, j, nv2) = arr2(this->phir, j, nv2) - + this->phir[nv2][j] = this->phir[nv2][j] - 0.75 * S11 * phiaa - 0.25 * S22 * phibb; } } else { nmax = 10; for (n = 1; n <= nmax; n++) { - arr2(this->phir, j, nv2) = - arr2(this->phir, j, nv2) + + this->phir[nv2][j] = + this->phir[nv2][j] + pow((-Z2 * scrn / Z1), n) * phi_meam(r * pow(arat, n), a, b); } } } // For Zbl potential: // if astar <= -3 // potential is zbl potential // else if -3 < astar < -1 // potential is linear combination with zbl potential // endif if (this->zbl_meam[a][b] == 1) { astar = this->alpha_meam[a][b] * (r / this->re_meam[a][b] - 1.0); if (astar <= -3.0) - arr2(this->phir, j, nv2) = + this->phir[nv2][j] = zbl(r, this->ielt_meam[a], this->ielt_meam[b]); else if (astar > -3.0 && astar < -1.0) { fcut(1 - (astar + 1.0) / (-3.0 + 1.0), &frac); phizbl = zbl(r, this->ielt_meam[a], this->ielt_meam[b]); - arr2(this->phir, j, nv2) = - frac * arr2(this->phir, j, nv2) + (1 - frac) * phizbl; + this->phir[nv2][j] = + frac * this->phir[nv2][j] + (1 - frac) * phizbl; } } } // call interpolation interpolate_meam(nv2); + + nv2 = nv2 + 1; } } } //----------------------------------------------------------------------c // Compute MEAM pair potential for distance r, element types a and b // double MEAM::phi_meam(double r, int a, int b) { /*unused:double a1,a2,a12;*/ double t11av, t21av, t31av, t12av, t22av, t32av; double G1, G2, s1[3 + 1], s2[3 + 1] /*,s12[3+1]*/, rho0_1, rho0_2; double Gam1, Gam2, Z1, Z2; double rhobar1, rhobar2, F1, F2; double rho01, rho11, rho21, rho31; double rho02, rho12, rho22, rho32; double scalfac, phiaa, phibb; double Eu; double arat, scrn /*unused:,scrn2*/; int Z12, errorflag; int n, nmax, Z1nn, Z2nn; lattice_t latta /*unused:,lattb*/; double rho_bkgd1, rho_bkgd2; double phi_m = 0.0; // Equation numbers below refer to: // I. Huang et.al., Modelling simul. Mater. Sci. Eng. 3:615 // get number of neighbors in the reference structure // Nref[i][j] = # of i's neighbors of type j get_Zij(&Z12, this->lattce_meam[a][b]); get_densref(r, a, b, &rho01, &rho11, &rho21, &rho31, &rho02, &rho12, &rho22, &rho32); // if densities are too small, numerical problems may result; just return zero if (rho01 <= 1e-14 && rho02 <= 1e-14) return 0.0; // calculate average weighting factors for the reference structure if (this->lattce_meam[a][b] == C11) { if (this->ialloy == 2) { t11av = this->t1_meam[a]; t12av = this->t1_meam[b]; t21av = this->t2_meam[a]; t22av = this->t2_meam[b]; t31av = this->t3_meam[a]; t32av = this->t3_meam[b]; } else { scalfac = 1.0 / (rho01 + rho02); t11av = scalfac * (this->t1_meam[a] * rho01 + this->t1_meam[b] * rho02); t12av = t11av; t21av = scalfac * (this->t2_meam[a] * rho01 + this->t2_meam[b] * rho02); t22av = t21av; t31av = scalfac * (this->t3_meam[a] * rho01 + this->t3_meam[b] * rho02); t32av = t31av; } } else { // average weighting factors for the reference structure, eqn. I.8 get_tavref(&t11av, &t21av, &t31av, &t12av, &t22av, &t32av, this->t1_meam[a], this->t2_meam[a], this->t3_meam[a], this->t1_meam[b], this->t2_meam[b], this->t3_meam[b], r, a, b, this->lattce_meam[a][b]); } // for c11b structure, calculate background electron densities if (this->lattce_meam[a][b] == C11) { latta = this->lattce_meam[a][a]; if (latta == DIA) { rhobar1 = pow(((Z12 / 2) * (rho02 + rho01)), 2) + t11av * pow((rho12 - rho11), 2) + t21av / 6.0 * pow(rho22 + rho21, 2) + 121.0 / 40.0 * t31av * pow((rho32 - rho31), 2); rhobar1 = sqrt(rhobar1); rhobar2 = pow(Z12 * rho01, 2) + 2.0 / 3.0 * t21av * pow(rho21, 2); rhobar2 = sqrt(rhobar2); } else { rhobar2 = pow(((Z12 / 2) * (rho01 + rho02)), 2) + t12av * pow((rho11 - rho12), 2) + t22av / 6.0 * pow(rho21 + rho22, 2) + 121.0 / 40.0 * t32av * pow((rho31 - rho32), 2); rhobar2 = sqrt(rhobar2); rhobar1 = pow(Z12 * rho02, 2) + 2.0 / 3.0 * t22av * pow(rho22, 2); rhobar1 = sqrt(rhobar1); } } else { // for other structures, use formalism developed in Huang's paper // // composition-dependent scaling, equation I.7 // If using mixing rule for t, apply to reference structure; else // use precomputed values if (this->mix_ref_t == 1) { Z1 = this->Z_meam[a]; Z2 = this->Z_meam[b]; if (this->ibar_meam[a] <= 0) G1 = 1.0; else { get_shpfcn(s1, this->lattce_meam[a][a]); Gam1 = (s1[1] * t11av + s1[2] * t21av + s1[3] * t31av) / (Z1 * Z1); G_gam(Gam1, this->ibar_meam[a], this->gsmooth_factor, &G1, &errorflag); } if (this->ibar_meam[b] <= 0) G2 = 1.0; else { get_shpfcn(s2, this->lattce_meam[b][b]); Gam2 = (s2[1] * t12av + s2[2] * t22av + s2[3] * t32av) / (Z2 * Z2); G_gam(Gam2, this->ibar_meam[b], this->gsmooth_factor, &G2, &errorflag); } rho0_1 = this->rho0_meam[a] * Z1 * G1; rho0_2 = this->rho0_meam[b] * Z2 * G2; } Gam1 = (t11av * rho11 + t21av * rho21 + t31av * rho31); if (rho01 < 1.0e-14) Gam1 = 0.0; else Gam1 = Gam1 / (rho01 * rho01); Gam2 = (t12av * rho12 + t22av * rho22 + t32av * rho32); if (rho02 < 1.0e-14) Gam2 = 0.0; else Gam2 = Gam2 / (rho02 * rho02); G_gam(Gam1, this->ibar_meam[a], this->gsmooth_factor, &G1, &errorflag); G_gam(Gam2, this->ibar_meam[b], this->gsmooth_factor, &G2, &errorflag); if (this->mix_ref_t == 1) { rho_bkgd1 = rho0_1; rho_bkgd2 = rho0_2; } else { if (this->bkgd_dyn == 1) { rho_bkgd1 = this->rho0_meam[a] * this->Z_meam[a]; rho_bkgd2 = this->rho0_meam[b] * this->Z_meam[b]; } else { rho_bkgd1 = this->rho_ref_meam[a]; rho_bkgd2 = this->rho_ref_meam[b]; } } rhobar1 = rho01 / rho_bkgd1 * G1; rhobar2 = rho02 / rho_bkgd2 * G2; } // compute embedding functions, eqn I.5 if (iszero(rhobar1)) F1 = 0.0; else { if (this->emb_lin_neg == 1 && rhobar1 <= 0) F1 = -this->A_meam[a] * this->Ec_meam[a][a] * rhobar1; else F1 = this->A_meam[a] * this->Ec_meam[a][a] * rhobar1 * log(rhobar1); } if (iszero(rhobar2)) F2 = 0.0; else { if (this->emb_lin_neg == 1 && rhobar2 <= 0) F2 = -this->A_meam[b] * this->Ec_meam[b][b] * rhobar2; else F2 = this->A_meam[b] * this->Ec_meam[b][b] * rhobar2 * log(rhobar2); } // compute Rose function, I.16 Eu = erose(r, this->re_meam[a][b], this->alpha_meam[a][b], this->Ec_meam[a][b], this->repuls_meam[a][b], this->attrac_meam[a][b], this->erose_form); // calculate the pair energy if (this->lattce_meam[a][b] == C11) { latta = this->lattce_meam[a][a]; if (latta == DIA) { phiaa = phi_meam(r, a, a); phi_m = (3 * Eu - F2 - 2 * F1 - 5 * phiaa) / Z12; } else { phibb = phi_meam(r, b, b); phi_m = (3 * Eu - F1 - 2 * F2 - 5 * phibb) / Z12; } } else if (this->lattce_meam[a][b] == L12) { phiaa = phi_meam(r, a, a); // account for second neighbor a-a potential here... get_Zij(&Z1nn, this->lattce_meam[a][a]); get_Zij2(&Z2nn, &arat, &scrn, this->lattce_meam[a][a], this->Cmin_meam[a][a][a], this->Cmax_meam[a][a][a]); nmax = 10; if (scrn > 0.0) { for (n = 1; n <= nmax; n++) { phiaa = phiaa + pow((-Z2nn * scrn / Z1nn), n) * phi_meam(r * pow(arat, n), a, a); } } phi_m = Eu / 3.0 - F1 / 4.0 - F2 / 12.0 - phiaa; } else { // // potential is computed from Rose function and embedding energy phi_m = (2 * Eu - F1 - F2) / Z12; // } // if r = 0, just return 0 if (iszero(r)) { phi_m = 0.0; } return phi_m; } //----------------------------------------------------------------------c // Compute background density for reference structure of each element void MEAM::compute_reference_density(void) { int a, Z, Z2, errorflag; double gam, Gbar, shp[3 + 1]; double rho0, rho0_2nn, arat, scrn; // loop over element types for (a = 1; a <= this->neltypes; a++) { Z = (int)this->Z_meam[a]; if (this->ibar_meam[a] <= 0) Gbar = 1.0; else { get_shpfcn(shp, this->lattce_meam[a][a]); gam = (this->t1_meam[a] * shp[1] + this->t2_meam[a] * shp[2] + this->t3_meam[a] * shp[3]) / (Z * Z); G_gam(gam, this->ibar_meam[a], this->gsmooth_factor, &Gbar, &errorflag); } // The zeroth order density in the reference structure, with // equilibrium spacing, is just the number of first neighbors times // the rho0_meam coefficient... rho0 = this->rho0_meam[a] * Z; // ...unless we have unscreened second neighbors, in which case we // add on the contribution from those (accounting for partial // screening) if (this->nn2_meam[a][a] == 1) { get_Zij2(&Z2, &arat, &scrn, this->lattce_meam[a][a], this->Cmin_meam[a][a][a], this->Cmax_meam[a][a][a]); rho0_2nn = this->rho0_meam[a] * MathSpecial::fm_exp(-this->beta0_meam[a] * (arat - 1)); rho0 = rho0 + Z2 * rho0_2nn * scrn; } this->rho_ref_meam[a] = rho0 * Gbar; } } //----------------------------------------------------------------------c // Shape factors for various configurations void MEAM::get_shpfcn(double* s /* s(3) */, lattice_t latt) { if (latt == FCC || latt == BCC || latt == B1 || latt == B2) { s[1] = 0.0; s[2] = 0.0; s[3] = 0.0; } else if (latt == HCP) { s[1] = 0.0; s[2] = 0.0; s[3] = 1.0 / 3.0; } else if (latt == DIA) { s[1] = 0.0; s[2] = 0.0; s[3] = 32.0 / 9.0; } else if (latt == DIM) { s[1] = 1.0; s[2] = 2.0 / 3.0; // s(3) = 1.d0 s[3] = 0.40; } else { s[1] = 0.0; // call error('Lattice not defined in get_shpfcn.') } } //------------------------------------------------------------------------------c // Average weighting factors for the reference structure void MEAM::get_tavref(double* t11av, double* t21av, double* t31av, double* t12av, double* t22av, double* t32av, double t11, double t21, double t31, double t12, double t22, double t32, double r, int a, int b, lattice_t latt) { double rhoa01, rhoa02, a1, a2, rho01 /*,rho02*/; // For ialloy = 2, no averaging is done if (this->ialloy == 2) { *t11av = t11; *t21av = t21; *t31av = t31; *t12av = t12; *t22av = t22; *t32av = t32; } else { if (latt == FCC || latt == BCC || latt == DIA || latt == HCP || latt == B1 || latt == DIM || latt == B2) { // all neighbors are of the opposite type *t11av = t12; *t21av = t22; *t31av = t32; *t12av = t11; *t22av = t21; *t32av = t31; } else { a1 = r / this->re_meam[a][a] - 1.0; a2 = r / this->re_meam[b][b] - 1.0; rhoa01 = this->rho0_meam[a] * MathSpecial::fm_exp(-this->beta0_meam[a] * a1); rhoa02 = this->rho0_meam[b] * MathSpecial::fm_exp(-this->beta0_meam[b] * a2); if (latt == L12) { rho01 = 8 * rhoa01 + 4 * rhoa02; *t11av = (8 * t11 * rhoa01 + 4 * t12 * rhoa02) / rho01; *t12av = t11; *t21av = (8 * t21 * rhoa01 + 4 * t22 * rhoa02) / rho01; *t22av = t21; *t31av = (8 * t31 * rhoa01 + 4 * t32 * rhoa02) / rho01; *t32av = t31; } else { // call error('Lattice not defined in get_tavref.') } } } } //------------------------------------------------------------------------------c // Number of neighbors for the reference structure void MEAM::get_Zij(int* Zij, lattice_t latt) { if (latt == FCC) *Zij = 12; else if (latt == BCC) *Zij = 8; else if (latt == HCP) *Zij = 12; else if (latt == B1) *Zij = 6; else if (latt == DIA) *Zij = 4; else if (latt == DIM) *Zij = 1; else if (latt == C11) *Zij = 10; else if (latt == L12) *Zij = 12; else if (latt == B2) *Zij = 8; else { // call error('Lattice not defined in get_Zij.') } } //------------------------------------------------------------------------------c // Zij2 = number of second neighbors, a = distance ratio R1/R2, and S = second // neighbor screening function for lattice type "latt" void MEAM::get_Zij2(int* Zij2, double* a, double* S, lattice_t latt, double cmin, double cmax) { double /*rratio,*/ C, x, sijk; int numscr = 0; if (latt == BCC) { *Zij2 = 6; *a = 2.0 / sqrt(3.0); numscr = 4; } else if (latt == FCC) { *Zij2 = 6; *a = sqrt(2.0); numscr = 4; } else if (latt == DIA) { *Zij2 = 0; *a = sqrt(8.0 / 3.0); numscr = 4; if (cmin < 0.500001) { // call error('can not do 2NN MEAM for dia') } } else if (latt == HCP) { *Zij2 = 6; *a = sqrt(2.0); numscr = 4; } else if (latt == B1) { *Zij2 = 12; *a = sqrt(2.0); numscr = 2; } else if (latt == L12) { *Zij2 = 6; *a = sqrt(2.0); numscr = 4; } else if (latt == B2) { *Zij2 = 6; *a = 2.0 / sqrt(3.0); numscr = 4; } else if (latt == DIM) { // this really shouldn't be allowed; make sure screening is zero *Zij2 = 0; *a = 1; *S = 0; return; } else { // call error('Lattice not defined in get_Zij2.') } // Compute screening for each first neighbor C = 4.0 / (*a * *a) - 1.0; x = (C - cmin) / (cmax - cmin); fcut(x, &sijk); // There are numscr first neighbors screening the second neighbors *S = pow(sijk, numscr); } //------------------------------------------------------------------------------c void MEAM::get_sijk(double C, int i, int j, int k, double* sijk) { double x; x = (C - this->Cmin_meam[i][j][k]) / (this->Cmax_meam[i][j][k] - this->Cmin_meam[i][j][k]); fcut(x, sijk); } //------------------------------------------------------------------------------c // Calculate density functions, assuming reference configuration void MEAM::get_densref(double r, int a, int b, double* rho01, double* rho11, double* rho21, double* rho31, double* rho02, double* rho12, double* rho22, double* rho32) { double a1, a2; double s[3 + 1]; lattice_t lat; int Zij1nn, Zij2nn; double rhoa01nn, rhoa02nn; double rhoa01, rhoa11, rhoa21, rhoa31; double rhoa02, rhoa12, rhoa22, rhoa32; double arat, scrn, denom; double C, s111, s112, s221, S11, S22; a1 = r / this->re_meam[a][a] - 1.0; a2 = r / this->re_meam[b][b] - 1.0; rhoa01 = this->rho0_meam[a] * MathSpecial::fm_exp(-this->beta0_meam[a] * a1); rhoa11 = this->rho0_meam[a] * MathSpecial::fm_exp(-this->beta1_meam[a] * a1); rhoa21 = this->rho0_meam[a] * MathSpecial::fm_exp(-this->beta2_meam[a] * a1); rhoa31 = this->rho0_meam[a] * MathSpecial::fm_exp(-this->beta3_meam[a] * a1); rhoa02 = this->rho0_meam[b] * MathSpecial::fm_exp(-this->beta0_meam[b] * a2); rhoa12 = this->rho0_meam[b] * MathSpecial::fm_exp(-this->beta1_meam[b] * a2); rhoa22 = this->rho0_meam[b] * MathSpecial::fm_exp(-this->beta2_meam[b] * a2); rhoa32 = this->rho0_meam[b] * MathSpecial::fm_exp(-this->beta3_meam[b] * a2); lat = this->lattce_meam[a][b]; *rho11 = 0.0; *rho21 = 0.0; *rho31 = 0.0; *rho12 = 0.0; *rho22 = 0.0; *rho32 = 0.0; get_Zij(&Zij1nn, lat); if (lat == FCC) { *rho01 = 12.0 * rhoa02; *rho02 = 12.0 * rhoa01; } else if (lat == BCC) { *rho01 = 8.0 * rhoa02; *rho02 = 8.0 * rhoa01; } else if (lat == B1) { *rho01 = 6.0 * rhoa02; *rho02 = 6.0 * rhoa01; } else if (lat == DIA) { *rho01 = 4.0 * rhoa02; *rho02 = 4.0 * rhoa01; *rho31 = 32.0 / 9.0 * rhoa32 * rhoa32; *rho32 = 32.0 / 9.0 * rhoa31 * rhoa31; } else if (lat == HCP) { *rho01 = 12 * rhoa02; *rho02 = 12 * rhoa01; *rho31 = 1.0 / 3.0 * rhoa32 * rhoa32; *rho32 = 1.0 / 3.0 * rhoa31 * rhoa31; } else if (lat == DIM) { get_shpfcn(s, DIM); *rho01 = rhoa02; *rho02 = rhoa01; *rho11 = s[1] * rhoa12 * rhoa12; *rho12 = s[1] * rhoa11 * rhoa11; *rho21 = s[2] * rhoa22 * rhoa22; *rho22 = s[2] * rhoa21 * rhoa21; *rho31 = s[3] * rhoa32 * rhoa32; *rho32 = s[3] * rhoa31 * rhoa31; } else if (lat == C11) { *rho01 = rhoa01; *rho02 = rhoa02; *rho11 = rhoa11; *rho12 = rhoa12; *rho21 = rhoa21; *rho22 = rhoa22; *rho31 = rhoa31; *rho32 = rhoa32; } else if (lat == L12) { *rho01 = 8 * rhoa01 + 4 * rhoa02; *rho02 = 12 * rhoa01; if (this->ialloy == 1) { *rho21 = 8. / 3. * pow(rhoa21 * this->t2_meam[a] - rhoa22 * this->t2_meam[b], 2); denom = 8 * rhoa01 * pow(this->t2_meam[a], 2) + 4 * rhoa02 * pow(this->t2_meam[b], 2); if (denom > 0.) *rho21 = *rho21 / denom * *rho01; } else *rho21 = 8. / 3. * (rhoa21 - rhoa22) * (rhoa21 - rhoa22); } else if (lat == B2) { *rho01 = 8.0 * rhoa02; *rho02 = 8.0 * rhoa01; } else { // call error('Lattice not defined in get_densref.') } if (this->nn2_meam[a][b] == 1) { get_Zij2(&Zij2nn, &arat, &scrn, lat, this->Cmin_meam[a][a][b], this->Cmax_meam[a][a][b]); a1 = arat * r / this->re_meam[a][a] - 1.0; a2 = arat * r / this->re_meam[b][b] - 1.0; rhoa01nn = this->rho0_meam[a] * MathSpecial::fm_exp(-this->beta0_meam[a] * a1); rhoa02nn = this->rho0_meam[b] * MathSpecial::fm_exp(-this->beta0_meam[b] * a2); if (lat == L12) { // As usual, L12 thinks it's special; we need to be careful computing // the screening functions C = 1.0; get_sijk(C, a, a, a, &s111); get_sijk(C, a, a, b, &s112); get_sijk(C, b, b, a, &s221); S11 = s111 * s111 * s112 * s112; S22 = pow(s221, 4); *rho01 = *rho01 + 6 * S11 * rhoa01nn; *rho02 = *rho02 + 6 * S22 * rhoa02nn; } else { // For other cases, assume that second neighbor is of same type, // first neighbor may be of different type *rho01 = *rho01 + Zij2nn * scrn * rhoa01nn; // Assume Zij2nn and arat don't depend on order, but scrn might get_Zij2(&Zij2nn, &arat, &scrn, lat, this->Cmin_meam[b][b][a], this->Cmax_meam[b][b][a]); *rho02 = *rho02 + Zij2nn * scrn * rhoa02nn; } } } //--------------------------------------------------------------------- // Compute ZBL potential // double MEAM::zbl(double r, int z1, int z2) { int i; const double c[] = { 0.028171, 0.28022, 0.50986, 0.18175 }; const double d[] = { 0.20162, 0.40290, 0.94229, 3.1998 }; const double azero = 0.4685; const double cc = 14.3997; double a, x; // azero = (9pi^2/128)^1/3 (0.529) Angstroms a = azero / (pow(z1, 0.23) + pow(z2, 0.23)); double result = 0.0; x = r / a; for (i = 0; i <= 3; i++) { result = result + c[i] * MathSpecial::fm_exp(-d[i] * x); } if (r > 0.0) result = result * z1 * z2 / r * cc; return result; } //--------------------------------------------------------------------- // Compute Rose energy function, I.16 // double MEAM::erose(double r, double re, double alpha, double Ec, double repuls, double attrac, int form) { double astar, a3; double result = 0.0; if (r > 0.0) { astar = alpha * (r / re - 1.0); a3 = 0.0; if (astar >= 0) a3 = attrac; else if (astar < 0) a3 = repuls; if (form == 1) result = -Ec * (1 + astar + (-attrac + repuls / r) * pow(astar, 3)) * MathSpecial::fm_exp(-astar); else if (form == 2) result = -Ec * (1 + astar + a3 * pow(astar, 3)) * MathSpecial::fm_exp(-astar); else result = -Ec * (1 + astar + a3 * pow(astar, 3) / (r / re)) * MathSpecial::fm_exp(-astar); } return result; } // ----------------------------------------------------------------------- void MEAM::interpolate_meam(int ind) { int j; double drar; // map to coefficient space this->nrar = this->nr; drar = this->dr; this->rdrar = 1.0 / drar; // phir interp - for (j = 1; j <= this->nrar; j++) { - arr2(this->phirar, j, ind) = arr2(this->phir, j, ind); + for (j = 0; j < this->nrar; j++) { + this->phirar[ind][j] = this->phir[ind][j]; } - arr2(this->phirar1, 1, ind) = - arr2(this->phirar, 2, ind) - arr2(this->phirar, 1, ind); - arr2(this->phirar1, 2, ind) = - 0.5 * (arr2(this->phirar, 3, ind) - arr2(this->phirar, 1, ind)); - arr2(this->phirar1, this->nrar - 1, ind) = - 0.5 * (arr2(this->phirar, this->nrar, ind) - - arr2(this->phirar, this->nrar - 2, ind)); - arr2(this->phirar1, this->nrar, ind) = 0.0; - for (j = 3; j <= this->nrar - 2; j++) { - arr2(this->phirar1, j, ind) = - ((arr2(this->phirar, j - 2, ind) - - arr2(this->phirar, j + 2, ind)) + - 8.0 * (arr2(this->phirar, j + 1, ind) - - arr2(this->phirar, j - 1, ind))) / + this->phirar1[ind][0] = this->phirar[ind][1] - this->phirar[ind][0]; + this->phirar1[ind][1] = 0.5 * (this->phirar[ind][2] - this->phirar[ind][0]); + this->phirar1[ind][this->nrar - 2] = 0.5 * (this->phirar[ind][this->nrar - 1] - this->phirar[ind][this->nrar - 3]); + this->phirar1[ind][this->nrar - 1] = 0.0; + for (j = 2; j < this->nrar - 2; j++) { + this->phirar1[ind][j] = + ((this->phirar[ind][j - 2] - + this->phirar[ind][j + 2]) + + 8.0 * (this->phirar[ind][j + 1] - + this->phirar[ind][j - 1])) / 12.; } - for (j = 1; j <= this->nrar - 1; j++) { - arr2(this->phirar2, j, ind) = + for (j = 0; j < this->nrar - 1; j++) { + this->phirar2[ind][j] = 3.0 * - (arr2(this->phirar, j + 1, ind) - arr2(this->phirar, j, ind)) - - 2.0 * arr2(this->phirar1, j, ind) - - arr2(this->phirar1, j + 1, ind); - arr2(this->phirar3, j, ind) = - arr2(this->phirar1, j, ind) + arr2(this->phirar1, j + 1, ind) - + (this->phirar[ind][j + 1] - this->phirar[ind][j]) - + 2.0 * this->phirar1[ind][j] - + this->phirar1[ind][j + 1]; + this->phirar3[ind][j] = + this->phirar1[ind][j] + this->phirar1[ind][j + 1] - 2.0 * - (arr2(this->phirar, j + 1, ind) - arr2(this->phirar, j, ind)); + (this->phirar[ind][j + 1] - this->phirar[ind][j]); } - arr2(this->phirar2, this->nrar, ind) = 0.0; - arr2(this->phirar3, this->nrar, ind) = 0.0; - - for (j = 1; j <= this->nrar; j++) { - arr2(this->phirar4, j, ind) = arr2(this->phirar1, j, ind) / drar; - arr2(this->phirar5, j, ind) = - 2.0 * arr2(this->phirar2, j, ind) / drar; - arr2(this->phirar6, j, ind) = - 3.0 * arr2(this->phirar3, j, ind) / drar; + this->phirar2[ind][this->nrar - 1] = 0.0; + this->phirar3[ind][this->nrar - 1] = 0.0; + + for (j = 0; j < this->nrar; j++) { + this->phirar4[ind][j] = this->phirar1[ind][j] / drar; + this->phirar5[ind][j] = + 2.0 * this->phirar2[ind][j] / drar; + this->phirar6[ind][j] = + 3.0 * this->phirar3[ind][j] / drar; } } //--------------------------------------------------------------------- // Compute Rose energy function, I.16 // double MEAM::compute_phi(double rij, int elti, int eltj) { double pp; int ind, kk; ind = this->eltind[elti][eltj]; - pp = rij * this->rdrar + 1.0; + pp = rij * this->rdrar; kk = (int)pp; - kk = std::min(kk, this->nrar - 1); + kk = std::min(kk, this->nrar - 2); pp = pp - kk; pp = std::min(pp, 1.0); - double result = ((arr2(this->phirar3, kk, ind) * pp + - arr2(this->phirar2, kk, ind)) * + double result = ((this->phirar3[ind][kk] * pp + + this->phirar2[ind][kk]) * pp + - arr2(this->phirar1, kk, ind)) * + this->phirar1[ind][kk]) * pp + - arr2(this->phirar, kk, ind); + this->phirar[ind][kk]; return result; }