00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112 #include "meam.h"
00113
00114
00115
00116 int MEAMFrame::readMEAM()
00117 {
00118 FILE *fp;
00119 char string[500], *p, *q;
00120
00121 LFile::SubHomeDir(potfile,potfile);
00122
00123 fp=fopen(potfile,"r");
00124 if(fp==NULL)
00125 {
00126 FATAL("MEAMFrame::readmeam file ("<<potfile<<") not found!");
00127 return -1;
00128 }
00129 fgets(string,500,fp);
00130 sscanf(string,"%lf",&zsmeam);
00131 INFO_Printf("zsmeam\t = %g\n",zsmeam);
00132
00133 fgets(string,500,fp);
00134 sscanf(string,"%lf",&alphas);
00135 INFO_Printf("alphas\t = %g\n",alphas);
00136
00137 fgets(string,500,fp);
00138 sscanf(string,"%lf %lf %lf %lf",betas,betas+1,betas+2,betas+3);
00139 INFO_Printf("betas\t = %g %g %g %g\n",betas[0],betas[1],betas[2],betas[3]);
00140
00141 fgets(string,500,fp);
00142 sscanf(string,"%lf %lf",&esubs,&asubs);
00143 INFO_Printf("esubs\t = %g asubs = %g\n",esubs,asubs);
00144
00145 fgets(string,500,fp);
00146 sscanf(string,"%lf %lf %lf %lf",ts,ts+1,ts+2,ts+3);
00147 INFO_Printf("ts\t = %g %g %g %g\n",ts[0],ts[1],ts[2],ts[3]);
00148
00149 fgets(string,500,fp);
00150 sscanf(string,"%lf",&rozros);
00151 INFO_Printf("rozros\t = %g\n",rozros);
00152
00153 fgets(string,500,fp);
00154 sscanf(string,"%d",&ibarr);
00155 INFO_Printf("ibarr\t = %d\n",ibarr);
00156
00157 fgets(string,500,fp);
00158 sscanf(string,"%lf",&rcutmeam);
00159 INFO_Printf("rcut\t = %g\n",rcutmeam);
00160
00161 fgets(string,500,fp);
00162 sscanf(string,"%lf %lf",&cmin,&cmax);
00163 INFO_Printf("cmin\t = %g cmax = %g\n",cmin,cmax);
00164
00165 fgets(string,500,fp);
00166 sscanf(string,"%lf %lf",&repuls,&attrac);
00167 INFO_Printf("repuls\t = %g attrac = %g\n",repuls,attrac);
00168
00169 fgets(string,500,fp);
00170 sscanf(string,"%lf",&legend);
00171 INFO_Printf("legend\t = %g (Legendre correction)\n",legend);
00172
00173 fgets(string,500,fp);
00174 sscanf(string,"%d",&noscr);
00175 INFO_Printf("noscr\t = %d\n",noscr);
00176
00177 fgets(string,500,fp);
00178 sscanf(string,"%lf",&alat);
00179 INFO_Printf("alat\t = %g\n",alat);
00180
00181 fgets(string,500,fp);
00182 sscanf(string,"%lf",&ielement);
00183 INFO_Printf("ielement\t = %g\n",ielement);
00184
00185 fgets(string,500,fp);
00186 p = strchr(string,'\'');
00187 if(p!=NULL)
00188 {
00189 q = strchr(p+1,'\'');
00190 if(q!=NULL)
00191 {
00192 q[0]=0;
00193 strcpy(lat,p+1);
00194 }
00195 }
00196 INFO_Printf("lat\t = %s\n",lat);
00197
00198 fgets(string,500,fp);
00199 p = strchr(string,'\'');
00200 if(p!=NULL)
00201 {
00202 q = strchr(p+1,'\'');
00203 if(q!=NULL)
00204 {
00205 q[0]=0;
00206 strcpy(elt,p+1);
00207 }
00208 }
00209 INFO_Printf("elt\t = %s\n",elt);
00210
00211 _RLIST = 1.1*rcutmeam;
00212 _SKIN = _RLIST - rcutmeam;
00213 rcutmeam2 = SQR(rcutmeam);
00214
00215 if(strcmp(lat,"dia")==0)
00216 {
00217 res = alat*sqrt(3.0)/4.0;
00218 INFO_Printf("diamond-cubic: res = %f\n",res);
00219 }
00220 else if (strcmp(lat,"fcc")==0)
00221 {
00222 res = alat/sqrt(2.0);
00223 INFO_Printf("FCC: res = %f\n",res);
00224 }
00225 else if (strcmp(lat,"bcc")==0)
00226 {
00227 res = alat*sqrt(3.0)/2.0;
00228 INFO_Printf("BCC: res = %f\n",res);
00229 }
00230 else
00231 {
00232 res = 0;
00233 FATAL("unknown lat ("<<lat<<"), res not set!");
00234 }
00235
00236 return 0;
00237 }
00238
00239 #ifdef _TORSION_OR_BENDING
00240 #include "../cookies/src/meam_torsion_bending.cpp"
00241 #else
00242 void MEAMFrame::rhoMEAM()
00243 {
00244
00245
00246
00247 int i, j, jpt, idx, jdx, itmp, jtmp, ktmp, ibar;
00248 Vector3 sij, rij, rcosv;
00249 double r2ij, rmagg, screenij, phifs, rej, rzj, drh;
00250 double betaj0, betaj1, betaj2, betaj3, rhj;
00251 double rogj1, rogj2, rogj3, rinve, rhocon;
00252 double t1, t2, t3, asub, esub, rozeroi, zmeam, z0meam;
00253 double rho0, rho1, rho2, rho3, rhobr, rhobar;
00254
00255
00256 rhocon = 1e-10;
00257
00258 for(i=0;i<_NP;i++)
00259 {
00260 atpe2b[i]=0;
00261 atpe3b[i]=0;
00262 _EPOT_IND[i]=0;
00263 rhotot[i]=0;
00264 embf [i]=0;
00265 c8a [i]=0;
00266 cg8c [i]=0;
00267
00268
00269 tav[i].clear();
00270 ag[i].clear();
00271 a8b[i].clear();
00272
00273
00274 b8c[i].clear();
00275
00276
00277 d8d[i].clear();
00278
00279 _F[i].clear();
00280 _VIRIAL_IND[i].clear();
00281 }
00282 _EPOT=0;
00283 _VIRIAL.clear();
00284
00285
00286
00287
00288
00289
00290 for(i=0;i<_NP;i++)
00291 {
00292 if(fixed[i]==-1) continue;
00293
00294 idx = species[i];
00295
00296 for(j=0;j<nn[i];j++)
00297 {
00298
00299 jpt=nindex[i][j];
00300 if(fixed[jpt]==-1) continue;
00301 jdx = species[jpt];
00302
00303 if(i==jpt) continue;
00304
00305 sij=_SR[jpt]-_SR[i];
00306 sij.subint();
00307 rij=_H*sij;
00308 r2ij=rij.norm2();
00309 rmagg=sqrt(r2ij);
00310
00311 #ifdef _EXTRACUTOFF
00312 if(rmagg>rcutmeam) continue;
00313 #endif
00314
00315 screenij = scrnab[i][j];
00316
00317 if(screenij<scnres) continue;
00318
00319
00320 phifs = phiid(rmagg,idx);
00321
00322
00323
00324
00325 atpe2b[i] += 0.5*phifs*screenij;
00326
00327
00328 rej = res;
00329 rzj = rozros;
00330 betaj0 = betas[0];
00331 betaj1 = betas[1];
00332 betaj2 = betas[2];
00333 betaj3 = betas[3];
00334
00335
00336 rhj = rhof(rmagg,betaj0,rej,rzj);
00337 rogj1 = rhof(rmagg,betaj1,rej,rzj);
00338 rogj2 = rhof(rmagg,betaj2,rej,rzj);
00339 rogj3 = rhof(rmagg,betaj3,rej,rzj);
00340
00341 rinve = 1./rmagg;
00342
00343
00344 rcosv = rij * rinve;
00345
00346 c8a[i] += rhj*screenij;
00347 for(itmp=0;itmp<3;itmp++)
00348 {
00349 t1 = screenij*rcosv[itmp];
00350 a8b[i][itmp] += rogj1*t1;
00351 ag [i][itmp] += rogj3*t1;
00352
00353 for(jtmp=0;jtmp<3;jtmp++)
00354 {
00355 t2 = t1*rcosv[jtmp];
00356 b8c[i][itmp][jtmp] += rogj2*t2;
00357
00358
00359 for(ktmp=0;ktmp<3;ktmp++)
00360 {
00361
00362 d8d[i].element[itmp][jtmp][ktmp] += rogj3*t2*rcosv[ktmp];
00363 }
00364 }
00365 }
00366
00367 tav[i][0] += ts[1]*rhj*screenij;
00368 tav[i][1] += ts[2]*rhj*screenij;
00369 tav[i][2] += ts[3]*rhj*screenij;
00370
00371 cg8c[i] += rogj2*screenij;
00372
00373 }
00374 }
00375
00376
00377 for(i=0;i<_NP;i++)
00378 {
00379 if(fixed[i]==-1) continue;
00380 rho0 = c8a[i];
00381
00382 if(rho0<=0)
00383 {
00384 embf[i] = 0;
00385 rhotot[i] = rhocon;
00386 rhsq[i].clear();
00387 }
00388 else
00389 {
00390 t1 = tav[i][0]/rho0;
00391 t2 = tav[i][1]/rho0;
00392 t3 = tav[i][2]/rho0;
00393 ibar = ibarr;
00394 asub = asubs;
00395 esub = esubs;
00396 rozeroi = rozros;
00397 zmeam = zsmeam;
00398
00399
00400 z0meam = zmeam;
00401
00402
00403
00404
00405 rho2 = -(cg8c[i]*cg8c[i])/3.0;
00406
00407 rho1 = rho3 = 0.0;
00408
00409
00410 for(itmp=0;itmp<3;itmp++)
00411 rho3 -= legend*SQR(ag[i][itmp]);
00412
00413 for(itmp=0;itmp<3;itmp++)
00414 {
00415 rho1 += SQR(a8b[i][itmp]);
00416 for(jtmp=0;jtmp<3;jtmp++)
00417 {
00418 rho2 += SQR(b8c[i][itmp][jtmp]);
00419 for(ktmp=0;ktmp<3;ktmp++)
00420 {
00421 rho3 += SQR(d8d[i].element[itmp][jtmp][ktmp]);
00422 }
00423 }
00424 }
00425
00426
00427 rhsq[i].set(rho1,rho2,rho3);
00428
00429
00430 drh = t1*rho1 + t2*rho2 + t3*rho3;
00431 rhobr = bar(rho0,drh,ibar,zmeam*rozeroi,dang1+i,dang2+i);
00432 rhobar= rhobr / (z0meam*rozeroi);
00433
00434 if(rhobr<0)
00435 {
00436 ERROR("rhobr("<<i<<") = "<<rhobr);
00437 }
00438 rhotot[i] = rhobr;
00439
00440 embf[i] = frhoi(rhobar,asub,esub);
00441
00442 atpe3b[i] = embf[i];
00443 }
00444 }
00445
00446 for(i=0;i<_NP;i++)
00447 {
00448 _EPOT_IND[i] = atpe2b[i] + atpe3b[i];
00449 _EPOT += _EPOT_IND[i];
00450 }
00451 }
00452
00453 void MEAMFrame::dscrfor()
00454 {
00455 int i, j, k, jpt, kpt, idx, jdx, kdx, ibar, ib, itmp, jtmp, ktmp;
00456 Vector3 sij, rij, sik, rik, rjk, rkm, r2ij_p, r2ij_m, r2ik_p, r2ik_m, r2jk_p, r2jk_m;
00457 double r2ij, r2jk, r2ik, screenij;
00458 double hhmeam, h2meam;
00459 Vector3 rcosv, scrpk, scrmk, dscrnabk, df;
00460 double t1, t2, t3, s1, s2, s3, asub, esub, rozeroi, zmeam, z0meam, re, roz;
00461 double rho0, dfrho, drbd0, drbdAA, tmp0, rmagg, rinve;
00462 double rozero, beta0, beta1, beta2, beta3, rhs1, rhs2, rhs3, rhs4;
00463 double factor, ddd, phiij, scr1, drho0s, drho1s, drho1sg, drho2s, drho3s;
00464 double tmp1, tmp2, tmp3, tmp1g, term2, rml, rmln;
00465
00466
00467
00468
00469
00470
00471
00472
00473 if(noscr)
00474 {
00475 INFO("no need to call dscrfor");
00476 return;
00477 }
00478
00479 hhmeam = SQR(hmeam);
00480 h2meam = 2.0 * hmeam;
00481
00482 for(i=0;i<_NP;i++)
00483 {
00484 if(fixed[i]==-1) continue;
00485
00486 idx = species[i];
00487
00488 if(c8a[i]<=0)
00489 continue;
00490
00491
00492 t1 = tav[i][0]/c8a[i];
00493 t2 = tav[i][1]/c8a[i];
00494 t3 = tav[i][2]/c8a[i];
00495 ibar = ibarr;
00496 ib = abs(ibar);
00497 asub = asubs;
00498 esub = esubs;
00499 rozeroi = rozros;
00500 zmeam = zsmeam;
00501 z0meam = zmeam;
00502 s1 = 0.0;
00503 s2 = 0.0;
00504 s3 = 0.0;
00505
00506
00507 roz = rhotot[i] / (z0meam*rozeroi);
00508 rho0 = c8a[i];
00509 if(roz<0)
00510 {
00511 ERROR("roz["<<i<<"] = "<<roz);
00512 }
00513 dfrho = dfrhoi(roz,asub,esub)/(z0meam*rozeroi);
00514
00515
00516 drbd0 = rhotot[i]/rho0 + rho0*dang1[i];
00517
00518
00519 drbdAA = rho0*dang2[i];
00520
00521 tmp0 = (2.0/3.0) * cg8c[i];
00522
00523
00524
00525 for(j=0;j<nn[i];j++)
00526 {
00527
00528 jpt=nindex[i][j];
00529 if(fixed[jpt]==-1) continue;
00530 jdx = species[jpt];
00531
00532 if(i==jpt) continue;
00533
00534
00535 screenij=scrnab[i][j];
00536 if((screenij<=scnres)||(screenij>=1.0-scnres)) continue;
00537
00538 sij=_SR[jpt]-_SR[i];
00539 sij.subint();
00540 rij=_H*sij;
00541 r2ij=rij.norm2();
00542 rmagg=sqrt(r2ij);
00543
00544 #ifdef _EXTRACUTOFF
00545 if(rmagg>rcutmeam) continue;
00546 #endif
00547 rinve = 1./rmagg;
00548
00549
00550 rcosv = rij * rinve;
00551
00552 re = res;
00553 rozero = rozros;
00554 beta0 = betas[0];
00555 beta1 = betas[1];
00556 beta2 = betas[2];
00557 beta3 = betas[3];
00558
00559 rhs1 = rhof(rmagg,beta0,re,rozero);
00560 rhs2 = rhof(rmagg,beta1,re,rozero);
00561 rhs3 = rhof(rmagg,beta2,re,rozero);
00562 rhs4 = rhof(rmagg,beta3,re,rozero);
00563
00564 if(ibar<=0)
00565 {
00566 factor = 0.0;
00567 }
00568 else
00569 {
00570 factor = SQR(rho0/zmeam);
00571 }
00572
00573 s1 = s2 = s3 = 0.0;
00574
00575 ddd = (ts[1]-t1)*(rhsq[i][0]-s1*factor) +
00576 (ts[2]-t2)*(rhsq[i][1]-s2*factor) +
00577 (ts[3]-t3)*(rhsq[i][2]-s3*factor);
00578
00579 phiij = phiid(rmagg,idx);
00580
00581
00582
00583 for(k=0;k<nn[i];k++)
00584 {
00585 kpt = nindex[i][k];
00586 if(fixed[kpt]==-1) continue;
00587 kdx = species[kpt];
00588
00589 if(kpt==i) continue;
00590 if(kpt==jpt) continue;
00591
00592 sik=_SR[kpt]-_SR[i];
00593 sik.subint();
00594 rik=_H*sik;
00595 r2ik=rik.norm2();
00596
00597 #ifdef _EXTRACUTOFF
00598 if(r2ik>rcutmeam2) continue;
00599 #endif
00600 rjk = rik - rij;
00601 r2jk=rjk.norm2();
00602
00603 #ifdef _EXTRACUTOFF
00604 if(r2jk>rcutmeam2) continue;
00605 #endif
00606
00607 rkm = rik*2.0 - rij;
00608
00609
00610 scr1 = dscrn(r2ij,r2ik,r2jk,cmin,cmax);
00611
00612
00613 if((scr1<scnres)||(scr1>1.0-scnres)) continue;
00614
00615
00616 r2ik_p = rik*( h2meam); r2ik_p += r2ik + hhmeam;
00617 r2ik_m = rik*(-h2meam); r2ik_m += r2ik + hhmeam;
00618
00619 r2jk_p = rjk*( h2meam); r2jk_p += r2jk + hhmeam;
00620 r2jk_m = rjk*(-h2meam); r2jk_m += r2jk + hhmeam;
00621
00622 scrpk.x = dscrn(r2ij,r2ik_p.x,r2jk_p.x,cmin,cmax);
00623 scrpk.y = dscrn(r2ij,r2ik_p.y,r2jk_p.y,cmin,cmax);
00624 scrpk.z = dscrn(r2ij,r2ik_p.z,r2jk_p.z,cmin,cmax);
00625
00626 scrmk.x = dscrn(r2ij,r2ik_m.x,r2jk_m.x,cmin,cmax);
00627 scrmk.y = dscrn(r2ij,r2ik_m.y,r2jk_m.y,cmin,cmax);
00628 scrmk.z = dscrn(r2ij,r2ik_m.z,r2jk_m.z,cmin,cmax);
00629
00630
00631
00632 dscrnabk = scrpk - scrmk;
00633 dscrnabk *= (screenij/(scr1*hmeam*2));
00634
00635
00636 drho0s = rhs1;
00637 drho1s = 0.0;
00638 drho1sg = 0.0;
00639 drho2s = -rhs3 * tmp0;
00640 drho3s = 0.0;
00641
00642 for(itmp=0;itmp<3;itmp++)
00643 {
00644 tmp1 = 2.0 * a8b[i][itmp];
00645 tmp1g = 2.0 * ag[i][itmp];
00646 drho1s += tmp1*rhs2*rcosv[itmp];
00647 drho1sg += tmp1g*rhs4*rcosv[itmp];
00648
00649 for(jtmp=0;jtmp<3;jtmp++)
00650 {
00651 rml = rcosv[itmp]*rcosv[jtmp];
00652 tmp2 = 2.0 * b8c[i][itmp][jtmp];
00653 drho2s += tmp2 * rhs3 * rml;
00654
00655 for(ktmp=0;ktmp<3;ktmp++)
00656 {
00657 rmln = rml * rcosv[ktmp];
00658 tmp3 = 2.0 * d8d[i].element[itmp][jtmp][ktmp];
00659 drho3s += tmp3 * rhs4 * rmln;;
00660 }
00661 }
00662 }
00663
00664 term2 = t1*drho1s + t2*drho2s
00665 + t3*(drho3s-legend*drho1sg) + ddd*drho0s/rho0;
00666
00667
00668 df = dscrnabk * (0.5*phiij + dfrho * (drbd0*drho0s + drbdAA*term2));
00669
00670 _F[kpt] -= df;
00671
00672 _VIRIAL.addnvv(-0.5,df,rkm);
00673 _VIRIAL_IND[kpt].addnvv(-0.5,df,rkm);
00674 }
00675 }
00676 }
00677
00678 }
00679
00680
00681 void MEAMFrame::kraMEAM()
00682 {
00683 int i, j, ia, jpt, idx, jdx, ibar, ib, kk, itmp, jtmp, ktmp;
00684 double t1, t2, t3, asub, esub, rozeroi, zmeam, z0meam, s1, s2, s3, roz, rho0;
00685 double dfrho, drbd0, drbdAA, screenij, r2ij, rmagg, rinve;
00686 double beta0, beta1, beta2, beta3, re, rozero, rhs1, rhs2, rhs3, rhs4, drhs1, drhs2, drhs3, drhs4;
00687 double factor, ddd, tmp0;
00688 double drho0, drho1, drho1g, drho1sg, drho2, drho3;
00689 double drho0s, drho1s, drho2s, drho3s, tmp1, tmp2, tmp3, tmp4, tmp1g, term1, term2;
00690 double t1j, t2j, t3j, rozj, rho0j, dfrhoj, drbd0j, drbdAAj;
00691 double drho0j, drho1j, drho1gj, drho1sgj, drho2j, drho3j, dddj, tmp0j;
00692 double drho0sj, drho1sj, drho2sj, drho3sj, tmp1j, tmp2j, tmp3j, tmp4j, tmp1gj, term1j, term2j;
00693 double rml, rmln, drmllm, df, phip, phim, dphif, phiij;
00694 Vector3 sij, rij, rcosv, dfi, dfj, dfip, dfjp;
00695 Matrix33 drcos;
00696
00697
00698
00699
00700 for(i=0;i<_NP;i++)
00701 _F[i].clear();
00702
00703 for(i=0;i<_NP;i++)
00704 {
00705 if(fixed[i]==-1) continue;
00706
00707 idx = species[i];
00708
00709
00710 t1 = tav[i][0]/c8a[i];
00711 t2 = tav[i][1]/c8a[i];
00712 t3 = tav[i][2]/c8a[i];
00713 ibar = ibarr;
00714 ib = abs(ibar);
00715 asub = asubs;
00716 esub = esubs;
00717 rozeroi = rozros;
00718 zmeam = zsmeam;
00719 z0meam = zmeam;
00720 s1 = 0.0;
00721 s2 = 0.0;
00722 s3 = 0.0;
00723
00724
00725 roz = rhotot[i] / (z0meam*rozeroi);
00726 rho0 = c8a[i];
00727 if(roz<0)
00728 {
00729 ERROR("roz["<<i<<"] = "<<roz);
00730 }
00731 dfrho = dfrhoi(roz,asub,esub)/(z0meam*rozeroi);
00732
00733
00734 drbd0 = rhotot[i]/rho0 + rho0*dang1[i];
00735
00736
00737 drbdAA = rho0*dang2[i];
00738
00739
00740 for(j=0;j<nn[i];j++)
00741 {
00742
00743 jpt=nindex[i][j];
00744 if(fixed[jpt]==-1) continue;
00745 jdx = species[jpt];
00746
00747
00748 if(i>=jpt) continue;
00749
00750 screenij = scrnab[i][j];
00751 if(screenij<=scnres) continue;
00752
00753 sij=_SR[jpt]-_SR[i];
00754 sij.subint();
00755 rij=_H*sij;
00756
00757 r2ij=rij.norm2();
00758 rmagg=sqrt(r2ij);
00759
00760 #ifdef _EXTRACUTOFF
00761 if(rmagg>rcutmeam) continue;
00762 #endif
00763
00764 rinve = 1./rmagg;
00765
00766
00767 rcosv = rij * rinve;
00768
00769
00770 drcos = dcmij(rij,rmagg);
00771
00772
00773
00774 t1j = tav[jpt][0]/c8a[jpt];
00775 t2j = tav[jpt][1]/c8a[jpt];
00776 t3j = tav[jpt][2]/c8a[jpt];
00777
00778
00779 rozj = rhotot[jpt] / (z0meam*rozeroi);
00780 rho0j = c8a[jpt];
00781 if(rozj<0)
00782 {
00783 ERROR("roz["<<jpt<<"] = "<<rozj);
00784 }
00785 dfrhoj = dfrhoi(rozj,asub,esub)/(z0meam*rozeroi);
00786
00787
00788 drbd0j = rhotot[jpt]/rho0j + rho0j*dang1[jpt];
00789
00790
00791 drbdAAj = rho0j*dang2[jpt];
00792
00793 re = res;
00794 rozero = rozros;
00795 beta0 = betas[0];
00796 beta1 = betas[1];
00797 beta2 = betas[2];
00798 beta3 = betas[3];
00799
00800 rhs1 = rhof(rmagg,beta0,re,rozero);
00801 rhs2 = rhof(rmagg,beta1,re,rozero);
00802 rhs3 = rhof(rmagg,beta2,re,rozero);
00803 rhs4 = rhof(rmagg,beta3,re,rozero);
00804
00805 drhs1 = drhof(beta0,re,rhs1);
00806 drhs2 = drhof(beta1,re,rhs2);
00807 drhs3 = drhof(beta2,re,rhs3);
00808 drhs4 = drhof(beta3,re,rhs4);
00809
00810 if(ibar<=0)
00811 factor = 0.0;
00812 else
00813 factor = SQR(rho0/zmeam);
00814
00815 ddd = (ts[1]-t1)*(rhsq[i][0]-s1*factor) +
00816 (ts[2]-t2)*(rhsq[i][1]-s2*factor) +
00817 (ts[3]-t3)*(rhsq[i][2]-s3*factor);
00818
00819 tmp0 = (2.0/3.0) * cg8c[i];
00820
00821 dddj = (ts[1]-t1j)*(rhsq[jpt][0]-s1*factor) +
00822 (ts[2]-t2j)*(rhsq[jpt][1]-s2*factor) +
00823 (ts[3]-t3j)*(rhsq[jpt][2]-s3*factor);
00824
00825 tmp0j = (2.0/3.0) * cg8c[jpt];
00826
00827 for(kk=0;kk<3;kk++)
00828 {
00829 drho0 = drhs1*screenij*rcosv[kk];
00830 drho1 = 0.0;
00831 drho1g = 0.0;
00832 drho1sg = 0.0;
00833 drho2 = -tmp0*drhs3*screenij*rcosv[kk];
00834 drho3 = 0.0;
00835 drho0s = rhs1;
00836 drho1s = 0.0;
00837 drho2s = -rhs3*tmp0;
00838 drho3s = 0.0;
00839
00840 drho0j = drhs1*screenij*rcosv[kk];
00841 drho1j = 0.0;
00842 drho1gj = 0.0;
00843 drho1sgj = 0.0;
00844 drho2j = -tmp0j*drhs3*screenij*rcosv[kk];
00845 drho3j = 0.0;
00846 drho0sj = rhs1;
00847 drho1sj = 0.0;
00848 drho2sj = -rhs3*tmp0j;
00849 drho3sj = 0.0;
00850
00851 for(itmp=0;itmp<3;itmp++)
00852 {
00853 tmp1 = 2.0*a8b[i][itmp];
00854 tmp1g = 2.0*ag[i][itmp];
00855
00856 drho1 += tmp1*(drhs2*rcosv[kk]*rcosv[itmp] +
00857 rhs2*drcos[kk][itmp])*screenij;
00858 drho1g += tmp1g*(drhs4*rcosv[kk]*rcosv[itmp] +
00859 rhs4*drcos[kk][itmp])*screenij;
00860 drho1s += tmp1*rhs2*rcosv[itmp];
00861 drho1sg += tmp1g*rhs4*rcosv[itmp];
00862
00863 tmp1j = 2.0*a8b[jpt][itmp];
00864 tmp1gj = 2.0*ag[jpt][itmp];
00865
00866 drho1j += tmp1j*(drhs2*rcosv[kk]*rcosv[itmp] +
00867 rhs2*drcos[kk][itmp])*screenij;
00868 drho1gj += tmp1gj*(drhs4*rcosv[kk]*rcosv[itmp] +
00869 rhs4*drcos[kk][itmp])*screenij;
00870 drho1sj += tmp1j*rhs2*rcosv[itmp];
00871 drho1sgj += tmp1gj*rhs4*rcosv[itmp];
00872
00873 for(jtmp=0;jtmp<3;jtmp++)
00874 {
00875 rml = rcosv[itmp]*rcosv[jtmp];
00876 drmllm = drcos[kk][itmp]*rcosv[jtmp]+
00877 rcosv[itmp]*drcos[kk][jtmp];
00878 tmp2 = 2.0*b8c[i][itmp][jtmp];
00879 drho2 += tmp2*(drhs3*rcosv[kk]*rml + rhs3*drmllm)*screenij;
00880 drho2s += tmp2*rhs3*rml;
00881
00882 tmp2j = 2.0*b8c[jpt][itmp][jtmp];
00883 drho2j += tmp2j*(drhs3*rcosv[kk]*rml + rhs3*drmllm)*screenij;
00884 drho2sj += tmp2j*rhs3*rml;
00885
00886 for(ktmp=0;ktmp<3;ktmp++)
00887 {
00888 rmln = rml*rcosv[ktmp];
00889 tmp3 = 2.0*d8d[i].element[itmp][jtmp][ktmp];
00890 drho3 += tmp3*(drhs4*rcosv[kk]*rmln
00891 + rhs4*(drmllm*rcosv[ktmp] + rml*drcos[kk][ktmp]))
00892 * screenij;
00893 drho3s += tmp3*rhs4*rmln;
00894
00895 tmp3j = 2.0*d8d[jpt].element[itmp][jtmp][ktmp];
00896 drho3j += tmp3j*(drhs4*rcosv[kk]*rmln
00897 + rhs4*(drmllm*rcosv[ktmp] + rml*drcos[kk][ktmp]))
00898 * screenij;
00899 drho3sj += tmp3j*rhs4*rmln;
00900 }
00901 }
00902 }
00903
00904 term1 = t1*drho1 + t2*drho2 + t3*(drho3-legend*drho1g) + ddd*drho0/rho0;
00905
00906 term2 = t1*drho1s + t2*drho2s + t3*(drho3s-legend*drho1sg) + ddd*drho0s/rho0;
00907
00908 term1j = t1*drho1j - t2*drho2j + t3*(drho3j-legend*drho1gj) + dddj*drho0j/rho0j;
00909
00910 term2j = t1*drho1sj - t2*drho2sj + t3*(drho3sj-legend*drho1sgj) + dddj*drho0sj/rho0j;
00911
00912
00913 for(ia=0;ia<nn[jpt];ia++)
00914 if(nindex[jpt][ia]==i) break;
00915 if(ia==nn[jpt])
00916 FATAL(jpt<<"in neighbor list of "<<i<<" but the reverse it not true");
00917
00918 tmp4 = dscrnab[i][3*j+kk];
00919 df = dfrho*((drho0-drho0s*tmp4)*drbd0 + (term1-term2*tmp4)*drbdAA);
00920 dfi[kk]=df;
00921
00922 tmp4 = dscrnab[jpt][3*ia+kk];
00923 df = dfrho*((drho0+drho0s*tmp4)*drbd0 + (term1+term2*tmp4)*drbdAA);
00924 dfj[kk]=df;
00925
00926 tmp4j = dscrnab[jpt][3*ia+kk];
00927 df = dfrhoj*((-drho0j-drho0sj*tmp4j)*drbd0j + (term1j+term2j*tmp4j)*drbdAAj);
00928 dfip[kk]=df;
00929
00930 tmp4j = dscrnab[i][3*j+kk];
00931 df = dfrhoj*((-drho0j+drho0sj*tmp4j)*drbd0j + (term1j-term2j*tmp4j)*drbdAAj);
00932 dfjp[kk]=df;
00933 }
00934
00935
00936
00937
00938
00939
00940
00941
00942
00943
00944
00945 _F[i] += dfi; _F[jpt] -= dfj;
00946 _F[i] -= dfjp; _F[jpt] += dfip;
00947
00948 _VIRIAL.addnvv(-0.5,dfi,rij);
00949 _VIRIAL_IND[i].addnvv(-0.5,dfi,rij);
00950
00951 _VIRIAL.addnvv(-0.5,dfj,rij);
00952 _VIRIAL_IND[jpt].addnvv(-0.5,dfj,rij);
00953
00954 _VIRIAL.addnvv( 0.5,dfjp,rij);
00955 _VIRIAL_IND[i].addnvv( 0.5,dfjp,rij);
00956
00957 _VIRIAL.addnvv( 0.5,dfip,rij);
00958 _VIRIAL_IND[jpt].addnvv( 0.5,dfip,rij);
00959
00960
00961 phip = phiid(rmagg+hmeam,idx);
00962 phim = phiid(rmagg-hmeam,idx);
00963
00964 dphif=(phip-phim)/(2.*hmeam);
00965
00966 phiij=phiid(rmagg,idx);
00967
00968 dfi = rcosv*(dphif*screenij);
00969 dfi[0] -= phiij*dscrnab[i][3*j+0];
00970 dfi[1] -= phiij*dscrnab[i][3*j+1];
00971 dfi[2] -= phiij*dscrnab[i][3*j+2];
00972
00973
00974 _F[i] += dfi;
00975 _VIRIAL.addnvv(-0.5,dfi,rij);
00976 _VIRIAL_IND[i].addnvv(-0.5,dfi,rij);
00977
00978
00979
00980
00981 dfi = rcosv*(dphif*screenij*(-1.0));
00982 dfi[0] -= phiij*dscrnab[jpt][3*ia+0];
00983 dfi[1] -= phiij*dscrnab[jpt][3*ia+1];
00984 dfi[2] -= phiij*dscrnab[jpt][3*ia+2];
00985 _F[jpt] += dfi;
00986 _VIRIAL.addnvv( 0.5,dfi,rij);
00987 _VIRIAL_IND[jpt].addnvv( 0.5,dfi,rij);
00988 }
00989 }
00990 }
00991 #endif
00992
00993 void MEAMFrame::screen()
00994 {
00995 int i, j, k, jpt, kpt, idx, jdx, kdx, iid;
00996 Vector3 sij, rij, sik, rik, rjk;
00997 double r2ij, r2jk, r2ik, screenij;
00998 Vector3 *rij_table; double *r2ij_table;
00999
01000
01001
01002
01003
01004
01005
01006
01007
01008
01009 rij_table = (Vector3 *) malloc(sizeof(Vector3)*_NNM);
01010 r2ij_table = (double *) malloc(sizeof(double )*_NNM);
01011
01012 for(i=0;i<_NP;i++)
01013 {
01014 if(fixed[i]==-1) continue;
01015
01016 idx = species[i];
01017
01018
01019 for(j=0;j<nn[i];j++)
01020 {
01021 jpt=nindex[i][j];
01022 jdx = species[jpt];
01023 if(i==jpt) continue;
01024
01025 sij=_SR[jpt]-_SR[i];
01026 sij.subint();
01027 rij=_H*sij;
01028 r2ij=rij.norm2();
01029 rij_table[j] = rij;
01030 r2ij_table[j] = r2ij;
01031 }
01032
01033
01034
01035 for(j=0;j<nn[i];j++)
01036 {
01037
01038 jpt=nindex[i][j];
01039 if(fixed[jpt]==-1) continue;
01040 jdx = species[jpt];
01041
01042
01043 if(i>=jpt) continue;
01044
01045 iid=-1;
01046 for(k=0;k<nn[jpt];k++)
01047 {
01048 if(nindex[jpt][k]==i)
01049 {
01050 iid = k;
01051 break;
01052 }
01053 }
01054 if(iid==-1)
01055 FATAL("screen: i="<<i<<" j="<<j<<" jpt="<<jpt<<" iid="<<iid);
01056
01057
01058 scrnab[i][j] = 0;
01059 scrnab[jpt][iid] = 0;
01060
01061 rij = rij_table[j];
01062 r2ij = r2ij_table[j];
01063
01064 #ifdef _EXTRACUTOFF
01065
01066 if(r2ij>rcutmeam2) continue;
01067 #endif
01068
01069 screenij = rscrn(r2ij);
01070
01071
01072 if((noscr==1)||(screenij<=scnres)) continue;
01073 for(k=0;k<nn[i];k++)
01074 {
01075 if(k==j) continue;
01076 kpt = nindex[i][k];
01077 if(fixed[kpt]==-1) continue;
01078 kdx = species[kpt];
01079
01080 if(kpt==i) continue;
01081 if(kpt==jpt) continue;
01082
01083 rik = rij_table[k];
01084 r2ik = r2ij_table[k];
01085
01086 #ifdef _EXTRACUTOFF
01087
01088 if(r2ik>rcutmeam2) continue;
01089 #endif
01090
01091 rjk = rik - rij;
01092 r2jk=rjk.norm2();
01093
01094 #ifdef _EXTRACUTOFF
01095
01096 if(r2jk>rcutmeam2) continue;
01097 #endif
01098
01099
01100 screenij *= dscrn(r2ij,r2ik,r2jk,cmin,cmax);
01101
01102
01103
01104
01105
01106
01107 if(screenij<=scnres) break;
01108 }
01109 scrnab[i][j] = screenij;
01110 scrnab[jpt][iid] = screenij;
01111 }
01112 }
01113
01114 free(rij_table);
01115 free(r2ij_table);
01116 }
01117
01118 void MEAMFrame::dscreen()
01119 {
01120 int i, j, k, jpt, kpt, idx, jdx, kdx;
01121 Vector3 sij, rij, sik, rik, rjk, r2ij_p, r2ij_m, r2ik_p, r2ik_m;
01122 double r2ij, r2jk, r2ik, screenij;
01123 double hhmeam, h2meam, scrpx, scrpy, scrpz, scrmx, scrmy, scrmz;
01124
01125
01126
01127
01128
01129 if(noscr)
01130 {
01131 INFO("no need to call dscreen");
01132 return;
01133 }
01134
01135 hhmeam = SQR(hmeam);
01136 h2meam = 2.0 * hmeam;
01137
01138
01139 for(i=0;i<_NP;i++)
01140 {
01141 if(fixed[i]==-1) continue;
01142
01143 idx = species[i];
01144
01145 for(j=0;j<nn[i];j++)
01146 {
01147
01148 jpt=nindex[i][j];
01149 if(fixed[jpt]==-1) continue;
01150 jdx = species[jpt];
01151
01152 if(i==jpt) continue;
01153
01154 sij=_SR[jpt]-_SR[i];
01155 sij.subint();
01156 rij=_H*sij;
01157 r2ij=rij.norm2();
01158
01159 #ifdef _EXTRACUTOFF
01160
01161 if(r2ij>rcutmeam2) continue;
01162 #endif
01163
01164 screenij=scrnab[i][j];
01165
01166
01167
01168 if((screenij>1-scnres)||(screenij<scnres))
01169 {
01170 dscrnab[i][j*3] = dscrnab[i][j*3+1] = dscrnab[i][j*3+2] = 0;
01171 continue;
01172 }
01173
01174
01175 r2ij_p = rij*(-h2meam); r2ij_p += hhmeam + r2ij;
01176 r2ij_m = rij*( h2meam); r2ij_m += hhmeam + r2ij;
01177
01178 scrpx = rscrn(r2ij_p.x);
01179 scrpy = rscrn(r2ij_p.y);
01180 scrpz = rscrn(r2ij_p.z);
01181
01182 scrmx = rscrn(r2ij_m.x);
01183 scrmy = rscrn(r2ij_m.y);
01184 scrmz = rscrn(r2ij_m.z);
01185
01186
01187
01188
01189 for(k=0;k<nn[i];k++)
01190 {
01191 kpt = nindex[i][k];
01192 if(fixed[kpt]==-1) continue;
01193 kdx = species[kpt];
01194
01195 if(kpt==i) continue;
01196 if(kpt==jpt) continue;
01197
01198 sik=_SR[kpt]-_SR[i];
01199 sik.subint();
01200 rik=_H*sik;
01201 r2ik=rik.norm2();
01202
01203 #ifdef _EXTRACUTOFF
01204 if(r2ik>rcutmeam2) continue;
01205 #endif
01206 rjk = rik - rij;
01207 r2jk=rjk.norm2();
01208
01209 #ifdef _EXTRACUTOFF
01210 if(r2jk>rcutmeam2) continue;
01211 #endif
01212
01213
01214
01215 r2ik_p = rik*(-h2meam); r2ik_p += hhmeam + r2ik;
01216 r2ik_m = rik*( h2meam); r2ik_m += hhmeam + r2ik;
01217
01218 scrpx *= dscrn(r2ij_p.x,r2ik_p.x,r2jk,cmin,cmax);
01219 scrpy *= dscrn(r2ij_p.y,r2ik_p.y,r2jk,cmin,cmax);
01220 scrpz *= dscrn(r2ij_p.z,r2ik_p.z,r2jk,cmin,cmax);
01221
01222 scrmx *= dscrn(r2ij_m.x,r2ik_m.x,r2jk,cmin,cmax);
01223 scrmy *= dscrn(r2ij_m.y,r2ik_m.y,r2jk,cmin,cmax);
01224 scrmz *= dscrn(r2ij_m.z,r2ik_m.z,r2jk,cmin,cmax);
01225
01226
01227 }
01228 dscrnab[i][j*3+0] = (scrpx-scrmx)/(2*hmeam);
01229 dscrnab[i][j*3+1] = (scrpy-scrmy)/(2*hmeam);
01230 dscrnab[i][j*3+2] = (scrpz-scrmz)/(2*hmeam);
01231 }
01232 }
01233
01234 }
01235
01236
01237 double MEAMFrame::phiid(double r, int it)
01238 {
01239 double charge, re, alpha, xmjc, phizbl, frac, fdimer;
01240 double rozero, esub, repul, attra;
01241 double asub, ztmp, t1, t2, t3, z0meam, rh0, roz, zdimer;
01242 double beta0, beta1, beta2, beta3, rh1, rh2, rh3, arg, dum1, dum2;
01243 double phi;
01244 int ibar;
01245
01246
01247
01248 charge = ielement;
01249 re = res;
01250 alpha = alphas;
01251
01252 beta0=betas[0];
01253 beta1=betas[1];
01254 beta2=betas[2];
01255 beta3=betas[3];
01256 t1 =ts[1];
01257 t2 =ts[2];
01258 t3 =ts[3];
01259
01260 rozero=rozros;
01261 esub =esubs;
01262 repul =repuls;
01263 attra =attrac;
01264 asub =asubs;
01265 ibar =ibarr;
01266 ztmp =zsmeam;
01267
01268 z0meam=zbar(ibar,ztmp,lat,t1,t2,t3);
01269
01270
01271 xmjc=alpha*(r/re-1.0);
01272
01273
01274
01275
01276
01277
01278
01279
01280
01281
01282
01283
01284
01285
01286
01287
01288
01289
01290
01291
01292
01293
01294 rh0=rhof(r,beta0,re,1.0);
01295 rh1=rhof(r,beta1,re,1.0);
01296 rh2=rhof(r,beta2,re,1.0);
01297 rh3=rhof(r,beta3,re,1.0);
01298 if(xmjc<=xzbl0)
01299 {
01300 arg=t1*SQR(rh1)+(2.0/3.0)*t2*SQR(rh2)+t3*(1-legend)*SQR(rh3);
01301 zdimer=1;
01302 roz=bar(zdimer*rh0,arg,ibar,zdimer,&dum1,&dum2)/z0meam;
01303 fdimer=frhoi(roz,asub,esub);
01304
01305 phizbl=zbl(r,charge,charge);
01306
01307 if(xmjc<xzbl)
01308 frac=0.0;
01309 else
01310 frac=xcut((xmjc-xzbl0)/(xzbl-xzbl0));
01311 }
01312 else
01313 {
01314 frac=1;
01315 phizbl=0;
01316 fdimer=0;
01317 }
01318
01319
01320
01321
01322
01323
01324
01325
01326
01327
01328
01329
01330
01331
01332
01333
01334
01335
01336
01337
01338
01339 rh0=rhof(r,beta0,re,1.0);
01340
01341
01342 if(strcmp(lat,"dia")==0)
01343 {
01344 rh3=rhof(r,beta3,re,1.0);
01345
01346 arg=(32.0/9.0)*t3*SQR(rh3);
01347 rh0=bar(z0meam*rh0,arg,ibar,z0meam,&dum1,&dum2);
01348 roz=rh0/z0meam;
01349
01350 }
01351 else if(strcmp(lat,"hcp")==0)
01352 {
01353 rh3=rhof(r,beta3,re,1.0);
01354 arg=(1.0/3.0)*ts[3]*SQR(rh3);
01355 rh0=bar(z0meam*rh0,arg,ibar,z0meam,&dum1,&dum2);
01356 roz=rh0/z0meam;
01357 }
01358 else if(strcmp(lat,"dim")==0)
01359 {
01360 rh1=rhof(r,beta1,re,1.0);
01361 rh2=rhof(r,beta2,re,1.0);
01362 rh3=rhof(r,beta3,re,1.0);
01363
01364 arg=t1*SQR(rh1)+(2.0/3.0)*t2*SQR(rh2)+t3*(1-legend)*SQR(rh3);
01365 rh0=bar(z0meam*rh0,arg,ibar,z0meam,&dum1,&dum2);
01366 roz=rh0/z0meam;
01367 }
01368 else
01369 {
01370 FATAL("lat = "<<lat<<" not recognized");
01371 }
01372
01373
01374 phi=(2.0/ztmp)*( erose(r,re,alpha,esub,repul,attra)
01375 - frhoi(roz,asub,esub) );
01376
01377
01378
01379
01380
01381
01382
01383
01384
01385
01386 if(!enable_zbl_fdimer) fdimer=0.0;
01387
01388
01389
01390 phi=frac*phi+(1.0-frac)*(phizbl-2*fdimer);
01391
01392
01393
01394
01395
01396
01397
01398
01399
01400 return phi;
01401 }
01402
01403 double MEAMFrame::zbl(double r,double z1val,double z2val)
01404 {
01405 int i; double z1, z2;
01406 double c[4]={0.028171,0.28022,0.50986,0.18175};
01407 double d[4]={0.20162,0.40290,0.94229,3.1998};
01408 double azero = 0.4685;
01409 double cc = 14.3997;
01410 double x, a, ret;
01411
01412
01413
01414 z1 = round(z1val);
01415 z2 = round(z2val);
01416
01417 a=azero/(pow(z1,0.23)+pow(z2,0.23));
01418 ret=0.0;
01419
01420 x = r/a;
01421 for(i=0;i<4;i++)
01422 ret += c[i]*exp(-d[i]*x);
01423
01424 ret *= (z1*z2/r*cc);
01425
01426 return ret;
01427 }
01428
01429 double MEAMFrame::bar(double rho0,double A,int ibar,double z,double *dang1,double *dang2)
01430 {
01431 int ib;
01432 double ang, ex, x;
01433 double x0=-0.99; int n=99;
01434
01435 if(rho0<=0) return 1e-20;
01436
01437 ib = abs(ibar);
01438 if((ib==0)||(ib==4))
01439 {
01440 ang = 1+A/SQR(rho0);
01441
01442
01443
01444
01445
01446
01447
01448 if(ang<1+x0)
01449 {
01450 x=ang-1;
01451 ang=sqrt((1+x0)*pow(x0/x,n));
01452 *dang1=ang*n/rho0;
01453 *dang2=-ang*n/(2*A);
01454 }
01455 else
01456 {
01457 ang=sqrt(ang);
01458 *dang1 = -A/(rho0*rho0*rho0*ang);
01459 *dang2 = 1/(2*rho0*rho0*ang);
01460 }
01461 }
01462 else if(ib==1)
01463 {
01464 ang = exp(0.5*A/SQR(rho0));
01465 *dang1 = -ang*A/(rho0*rho0*rho0);
01466 *dang2 = ang/(2*rho0*rho0);
01467 }
01468 else if(ib==2)
01469 {
01470 ang = exp(0.5*A/SQR(z));
01471 *dang1 = 0;
01472 *dang2 = ang/(2.0*SQR(z));
01473 }
01474 else if(ib==3)
01475 {
01476 ex = exp(-A/SQR(rho0));
01477 ang = 2.0/(1.0 + ex);
01478 *dang1 = -SQR(ang)*ex*A/(rho0*rho0*rho0);
01479 *dang2 = SQR(ang)/2.0*ex/SQR(rho0);
01480 }
01481 return rho0*ang;
01482 }
01483
01484 inline double MEAMFrame::erose(double r,double re,double alpha,double esub,double repuls,double attrac)
01485 {
01486 double x, an3, E;
01487
01488
01489
01490
01491 x=alpha*(r/re-1.0);
01492 if(x>=0)
01493 an3=attrac;
01494 else
01495 an3=repuls;
01496
01497 E=-esub*(1.+x+an3*x*x*x/(r/re))*exp(-x);
01498
01499
01500
01501
01502
01503
01504
01505
01506
01507
01508
01509
01510
01511
01512
01513 return E;
01514 }
01515
01516
01517
01518
01519
01520
01521 Matrix33 MEAMFrame::dcmij(Vector3 rr,double rs)
01522 {
01523 int i, j; double r1, r13, tmp1;
01524 Matrix33 drcos;
01525
01526 r1 = 1.0 / rs;
01527 r13 = r1 * r1 * r1;
01528 for(i=0;i<3;i++)
01529 {
01530 tmp1 = r13 * rr[i];
01531 for(j=0;j<3;j++)
01532 {
01533 drcos[j][i] = -tmp1 * rr[j];
01534 }
01535 drcos[i][i] += r1;
01536 }
01537 return drcos;
01538 }
01539
01540 inline double MEAMFrame::zbar(int ibar,double z,char *lattice,double t1,double t2,double t3)
01541 {
01542 if(ibar<=0)
01543 return z;
01544 else
01545 {
01546 FATAL("ibar = "<<ibar<<" not implemented!");
01547 return 0;
01548 }
01549 }
01550
01551 inline double MEAMFrame::rhof(double r,double abc,double re,double rozero)
01552 {
01553
01554
01555
01556 return rozero*exp(-abc*(r/re-1.0));
01557 }
01558
01559 inline double MEAMFrame::frhoi(double rhotp,double asub,double esub)
01560 {
01561 if(rhotp>0)
01562 return asub*esub*rhotp*log(rhotp);
01563 else
01564 return asub*esub*rhotp*(-100.0);
01565 }
01566
01567 inline double MEAMFrame::dfrhoi(double rho,double asub,double esub)
01568 {
01569 if(rho>0)
01570 return asub*esub*(log(rho)+1.0);
01571 else
01572 return asub*esub*(-100.0);
01573 }
01574
01575 inline double MEAMFrame::rscrn(double r2ij)
01576 {
01577 double fac, rij, frcut=0.9;
01578
01579 if(enable_square_rscrn)
01580 {
01581
01582 fac=(r2ij-frcut*rcutmeam2)/((1.0-frcut)*rcutmeam2);
01583 }
01584 else
01585 {
01586
01587 rij = sqrt(r2ij);
01588 fac = 1.0-(rcutmeam-rij)/(1.0-frcut);
01589 }
01590 if(fac <= 0.0)
01591 return 1.0;
01592 else if(fac >= 1.0)
01593 return 0.0;
01594 else
01595 return xcut(fac);
01596 }
01597
01598 double MEAMFrame::dscrn(double rij, double rik, double rjk, double cmin, double cmax)
01599 {
01600 double dotil, dotjl, fac;
01601 double argb, argt, arg;
01602
01603 if((rik>sconst*rij)||(rjk>sconst*rij)) return 1.0;
01604
01605
01606 dotil = rik+rij-rjk;
01607 if(dotil<=2.0e-3) return 1.0;
01608 dotjl = rij+rjk-rik;
01609 if(dotjl<=2.0e-3) return 1.0;
01610 argb=SQR(rij)-SQR(rik-rjk);
01611 argt=4.0*(rik*rij)-SQR(rik-rjk+rij);
01612 arg=argt/argb;
01613
01614 if(arg>=cmax) return 1.0;
01615 else if(arg<=cmin) return 0.0;
01616 else
01617 {
01618 fac = (cmax-arg)/(cmax-cmin);
01619
01620 return xcut(fac);
01621 }
01622
01623 #if 0
01624 argb = 1.0 - SQR((rik-rjk)/rij);
01625 if(argb==0) return 1.0;
01626
01627 argt = 4.0*(rik/rij)-SQR((rik-rjk+rij)/rij);
01628 arg=argt/argb;
01629
01630
01631
01632
01633
01634
01635
01636
01637
01638
01639
01640
01641
01642
01643
01644
01645
01646
01647 if((arg>cmax)||(arg<0.0))
01648 return 1.0;
01649 else if(arg<cmin)
01650 return 0.0;
01651 else
01652 return xcut( (cmax-arg)/(cmax-cmin) );
01653 #endif
01654 }
01655
01656
01657
01658
01659
01660 void MEAMFrame::Alloc()
01661 {
01662 MDPARALLELFrame::Alloc();
01663 int i, size;
01664 size=_NP*allocmultiple;
01665
01666
01667 Realloc(atpe2b,double,size);
01668 Realloc(atpe3b,double,size);
01669 Realloc(rhotot,double,size);
01670 Realloc(embf,double,size);
01671 Realloc(c8a,double,size);
01672 Realloc(dang1,double,size);
01673 Realloc(dang2,double,size);
01674 Realloc(cg8c,double,size);
01675 Realloc(tav,Vector3,size);
01676 Realloc(rhsq,Vector3,size);
01677 Realloc(a8b,Vector3,size);
01678 Realloc(ag,Vector3,size);
01679 Realloc(b8c,Matrix33,size);
01680 Realloc(d8d,Matrix333,size);
01681
01682
01683 Realloc(scrnab_mem,char,size*_NNM*sizeof(double)+size*sizeof(double *));
01684 scrnab=(double **)(scrnab_mem+size*_NNM*sizeof(double));
01685 for(i=0;i<size;i++) scrnab[i]=(double *)(scrnab_mem+i*_NNM*sizeof(double));
01686
01687 Realloc(dscrnab_mem,char,size*_NNM*3*sizeof(double)+size*sizeof(double *));
01688 dscrnab=(double **)(dscrnab_mem+size*_NNM*3*sizeof(double));
01689 for(i=0;i<size;i++) dscrnab[i]=(double *)(dscrnab_mem+i*_NNM*3*sizeof(double));
01690
01691
01692 bindvar("atpe2b",atpe2b,DOUBLE);
01693 bindvar("atpe3b",atpe3b,DOUBLE);
01694 bindvar("rhotot",rhotot,DOUBLE);
01695 bindvar("embf",embf,DOUBLE);
01696 bindvar("c8a",c8a,DOUBLE);
01697 bindvar("dang1",dang1,DOUBLE);
01698 bindvar("dang2",dang2,DOUBLE);
01699 bindvar("cg8c",cg8c,DOUBLE);
01700 bindvar("tav",tav,DOUBLE);
01701 bindvar("rhsq",rhsq,DOUBLE);
01702 bindvar("a8b",a8b,DOUBLE);
01703 bindvar("ag",ag,DOUBLE);
01704 bindvar("b8c",b8c,DOUBLE);
01705 bindvar("d8d",d8d,DOUBLE);
01706
01707 }
01708
01709 void MEAMFrame::potential()
01710 {
01711 refreshneighborlist();
01712 screen();
01713 dscreen();
01714 rhoMEAM();
01715 kraMEAM();
01716 if(noscr==0) dscrfor();
01717 }
01718
01719 void MEAMFrame::initvars()
01720 {
01721 MDPARALLELFrame::initvars();
01722
01723 betas[0]=betas[1]=betas[2]=betas[3]=0;
01724 ts[0]=ts[1]=ts[2]=ts[3]=0;
01725 strcpy(potfile,"meamdata");
01726
01727 strcpy(lat,"unknown");
01728 strcpy(elt,"unknown");
01729 }
01730 void MEAMFrame::initparser()
01731 {
01732 MDPARALLELFrame::initparser();
01733
01734 bindvar("xzbl",&xzbl,DOUBLE);
01735 bindvar("xzbl0",&xzbl0,DOUBLE);
01736 bindvar("enable_zbl_fdimer",&enable_zbl_fdimer,INT);
01737 bindvar("enable_square_rscrn",&enable_square_rscrn,INT);
01738 }
01739
01740 int MEAMFrame::exec(char *name)
01741 {
01742 if(MDPARALLELFrame::exec(name)==0) return 0;
01743 bindcommand(name,"readMEAM",readMEAM());
01744 bindcommand(name,"printpairpot",printpairpot());
01745
01746 #ifdef _PARALLEL
01747 bindcommand(name,"Broadcast_MEAM_Param",Broadcast_MEAM_Param());
01748 #endif
01749 return -1;
01750 }
01751
01752
01753 void MEAMFrame::printpairpot()
01754 {
01755 int elti, eltj;
01756 double rmin, dr, rmax, r, phi, phip;
01757 char pairfile[200];
01758 FILE *fp;
01759
01760 elti = (int) input[0];
01761 eltj = (int) input[1];
01762 rmin = input[2];
01763 dr = input[3];
01764 rmax = input[4];
01765
01766 strcpy(pairfile,"pairpot_baskes.dat");
01767 fp=fopen(pairfile,"w");
01768 if(fp==NULL)
01769 {
01770 FATAL("printpairpot: file "<<pairfile<<" open failure.");
01771 }
01772 if(elti!=eltj)
01773 {
01774 FATAL("elti ("<<elti<<") != eltj("<<eltj<<") not implemented");
01775 }
01776 if((rmax<rmin)||(dr<=0))
01777 FATAL("rmax cannot be smaller than rmin, dr must be positive");
01778
01779 phip = 0;
01780 for(r=rmin;r<=rmax;r+=dr)
01781 {
01782 phi = phiid(r,elti);
01783 fprintf(fp,"%21.14e %21.14e %21.14e\n",r,phi,phip);
01784 }
01785 fclose(fp);
01786 INFO("results written to "<<pairfile);
01787 }
01788
01789
01790 #ifdef _PARALLEL
01791 void MEAMFrame::Broadcast_MEAM_Param()
01792 {
01793 double *buf_double;
01794 int nparam;
01795
01796
01797 if(myDomain==0) Master_to_Slave("Broadcast_MEAM_Param");
01798
01799
01800 nparam = 36;
01801 buf_double = (double *) malloc(nparam*sizeof(double));
01802 if(myDomain==0)
01803 {
01804 buf_double[0] = zsmeam;
01805 buf_double[1] = alphas;
01806 buf_double[2] = betas[0];
01807 buf_double[3] = betas[1];
01808 buf_double[4] = betas[2];
01809 buf_double[5] = betas[3];
01810 buf_double[6] = esubs;
01811 buf_double[7] = asubs;
01812 buf_double[8] = ts[0];
01813 buf_double[9] = ts[1];
01814 buf_double[10] = ts[2];
01815 buf_double[11] = ts[3];
01816 buf_double[12] = rozros;
01817 buf_double[13] = rcutmeam;
01818 buf_double[14] = cmin;
01819 buf_double[15] = cmax;
01820 buf_double[16] = repuls;
01821 buf_double[17] = attrac;
01822 buf_double[18] = legend;
01823 buf_double[19] = (double) ibarr;
01824 buf_double[20] = (double) noscr;
01825 buf_double[21] = res;
01826 buf_double[22] = alat;
01827 buf_double[23] = ielement;
01828 buf_double[24] = rcutmeam2;
01829 buf_double[25] = sconst;
01830 buf_double[26] = scnres;
01831 buf_double[27] = xzbl;
01832 buf_double[28] = xzbl0;
01833 buf_double[29] = hmeam;
01834 buf_double[30] = _RLIST;
01835 buf_double[31] = _SKIN;
01836 buf_double[32] = rcutmeam2;
01837 buf_double[33] = res;
01838 buf_double[34] = _NNM;
01839 buf_double[35] = _NIC;
01840 }
01841
01842 MPI_Bcast(buf_double,nparam,MPI_DOUBLE,0,MPI_COMM_WORLD);
01843
01844 if(myDomain!=0)
01845 {
01846
01847
01848
01849
01850
01851
01852 zsmeam = buf_double[0];
01853 alphas = buf_double[1];
01854 betas[0] = buf_double[2];
01855 betas[1] = buf_double[3];
01856 betas[2] = buf_double[4];
01857 betas[3] = buf_double[5];
01858 esubs = buf_double[6];
01859 asubs = buf_double[7];
01860 ts[0] = buf_double[8];
01861 ts[1] = buf_double[9];
01862 ts[2] = buf_double[10];
01863 ts[3] = buf_double[11];
01864 rozros = buf_double[12];
01865 rcutmeam = buf_double[13];
01866 cmin = buf_double[14];
01867 cmax = buf_double[15];
01868 repuls = buf_double[16];
01869 attrac = buf_double[17];
01870 legend = buf_double[18];
01871 ibarr = (int) buf_double[19];
01872 noscr = (int) buf_double[20];
01873 res = buf_double[21];
01874 alat = buf_double[22];
01875 ielement = buf_double[23];
01876 rcutmeam2 = buf_double[24];
01877 sconst = buf_double[25];
01878 scnres = buf_double[26];
01879 xzbl = buf_double[27];
01880 xzbl0 = buf_double[28];
01881 hmeam = buf_double[29];
01882 _RLIST = buf_double[30];
01883 _SKIN = buf_double[31];
01884 rcutmeam2 = buf_double[32];
01885 res = buf_double[33];
01886 _NNM = (int) buf_double[34];
01887 _NIC = (int) buf_double[35];
01888 }
01889
01890 free(buf_double);
01891
01892
01893 MPI_Bcast(elt,10,MPI_CHAR,0,MPI_COMM_WORLD);
01894 MPI_Bcast(lat,10,MPI_CHAR,0,MPI_COMM_WORLD);
01895 }
01896 #endif//_PARALLEL
01897
01898 #ifdef _TEST
01899
01900
01901 class MEAMFrame sim;
01902
01903
01904 #include "main.cpp"
01905
01906 #endif//_TEST
01907
01908
01909
01910
01911
01912
01913
01914
01915
01916
01917
01918
01919
01920
01921
01922
01923
01924
01925
01926
01927
01928
01929
01930
01931
01932
01933
01934
01935
01936
01937
01938
01939
01940
01941
01942
01943
01944
01945
01946
01947
01948
01949
01950
01951
01952
01953
01954
01955
01956
01957
01958
01959
01960
01961
01962
01963