103 #define MAX(A,B) ((A) > (B) ? (A) : (B))
161 static void fileNotFound(
const char* callSite,
const char* filename);
192 if (strcmp(type,
"setfl" ) == 0)
194 else if (strcmp(type,
"funcfl") == 0)
248 for (
int jTmp=0; jTmp<nNbrBoxes; jTmp++)
250 int jBox = nbrBoxes[jTmp];
251 if (jBox < iBox )
continue;
255 for (
int iOff=
MAXATOMS*iBox,ii=0; ii<nIBox; ii++,iOff++)
258 for (
int jOff=
MAXATOMS*jBox,ij=0; ij<nJBox; ij++,jOff++)
260 if ( (iBox==jBox) &&(ij <= ii) )
continue;
264 for (
int k=0; k<3; k++)
269 if(r2>rCut2)
continue;
273 real_t phiTmp, dPhi, rhoTmp, dRho;
277 for (
int k=0; k<3; k++)
279 s->
atoms->
f[iOff][k] -= dPhi*dr[k]/r;
280 s->
atoms->
f[jOff][k] += dPhi*dr[k]/r;
286 if (jBox < s->boxes->nLocalBoxes)
291 s->
atoms->
U[iOff] += 0.5*phiTmp;
292 s->
atoms->
U[jOff] += 0.5*phiTmp;
295 pot->
rhobar[iOff] += rhoTmp;
296 pot->
rhobar[jOff] += rhoTmp;
311 for (
int iOff=
MAXATOMS*iBox,ii=0; ii<nIBox; ii++,iOff++)
317 s->
atoms->
U[iOff] += fEmbed;
333 for (
int jTmp=0; jTmp<nNbrBoxes; jTmp++)
335 int jBox = nbrBoxes[jTmp];
336 if(jBox < iBox)
continue;
340 for (
int iOff=
MAXATOMS*iBox,ii=0; ii<nIBox; ii++,iOff++)
343 for (
int jOff=
MAXATOMS*jBox,ij=0; ij<nJBox; ij++,jOff++)
345 if ((iBox==jBox) && (ij <= ii))
continue;
349 for (
int k=0; k<3; k++)
354 if(r2>=rCut2)
continue;
361 for (
int k=0; k<3; k++)
380 fprintf(file,
" Potential type : EAM\n");
381 fprintf(file,
" Species name : %s\n", eamPot->
name);
382 fprintf(file,
" Atomic number : %d\n", eamPot->
atomicNo);
384 fprintf(file,
" Lattice type : %s\n", eamPot->
latticeType);
385 fprintf(file,
" Lattice spacing : "FMT1" Angstroms\n", eamPot->
lat);
386 fprintf(file,
" Cutoff : "FMT1" Angstroms\n", eamPot->
cutoff);
391 if ( ! pPot )
return;
421 buf.mass = pot->
mass;
425 strcpy(buf.name, pot->
name);
429 pot->
mass = buf.mass;
433 strcpy(pot->
name, buf.name);
464 table->
invDx = 1.0/dx;
467 for (
int ii=0; ii<n; ++ii)
468 table->
values[ii] = data[ii];
516 if ( r < table->x0 ) r = table->
x0;
518 r = (r-table->
x0)*(table->
invDx) ;
519 int ii = (int)floor(r);
523 r = table->
n / table->
invDx;
528 real_t g1 = tt[ii+1] - tt[ii-1];
529 real_t g2 = tt[ii+2] - tt[ii];
531 *f = tt[ii] + 0.5*r*(g1 + r*(tt[ii+1] + tt[ii-1] - 2.0*tt[ii]) );
533 *df = 0.5*(g1 + r*(g2-g1))*table->
invDx;
555 buf.x0 = (*table)->x0;
556 buf.invDx = (*table)->invDx;
562 assert(*table == NULL);
565 (*table)->x0 = buf.x0;
566 (*table)->invDx = buf.invDx;
571 int valuesSize =
sizeof(
real_t) * ((*table)->n+3);
580 potData = fopen(fileName,
"w");
582 for (
int i = 0; i<table->
n; i++)
585 fprintf(potData,
"%d %e %e\n", i, r, table->
values[i]);
637 sprintf(tmp,
"%s/%s", dir, potName);
639 FILE* potFile = fopen(tmp,
"r");
644 fgets(tmp,
sizeof(tmp), potFile);
645 fgets(tmp,
sizeof(tmp), potFile);
646 fgets(tmp,
sizeof(tmp), potFile);
649 fgets(tmp,
sizeof(tmp), potFile);
651 sscanf(tmp,
"%d", &nElems);
657 double dRho, dR, cutoff;
659 fgets(tmp,
sizeof(tmp), potFile);
660 sscanf(tmp,
"%d %le %d %le %le", &nRho, &dRho, &nR, &dR, &cutoff);
665 fgets(tmp,
sizeof(tmp), potFile);
669 sscanf(tmp,
"%d %le %le %s", &nAtomic, &mass, &lat, latticeType);
676 int bufSize =
MAX(nRho, nR);
681 for (
int ii=0; ii<nRho; ++ii)
682 fscanf(potFile,
FMT1, buf+ii);
686 for (
int ii=0; ii<nR; ++ii)
687 fscanf(potFile,
FMT1, buf+ii);
691 for (
int ii=0; ii<nR; ++ii)
692 fscanf(potFile,
FMT1, buf+ii);
693 for (
int ii=1; ii<nR; ++ii)
698 buf[0] = buf[1] + (buf[1] - buf[2]);
756 sprintf(tmp,
"%s/%s", dir, potName);
757 FILE* potFile = fopen(tmp,
"r");
762 fgets(tmp,
sizeof(tmp), potFile);
764 sscanf(tmp,
"%s", name);
765 strcpy(pot->
name, name);
771 fgets(tmp,
sizeof(tmp),potFile);
772 sscanf(tmp,
"%d %le %le %s", &nAtomic, &mass, &lat, latticeType);
780 double dRho, dR, cutoff;
781 fgets(tmp,
sizeof(tmp),potFile);
782 sscanf(tmp,
"%d %le %d %le %le", &nRho, &dRho, &nR, &dR, &cutoff);
787 int bufSize =
MAX(nRho, nR);
791 for (
int ii=0; ii<nRho; ++ii)
792 fscanf(potFile,
FMT1, buf+ii);
796 for (
int ii=0; ii<nR; ++ii)
797 fscanf(potFile,
FMT1, buf+ii);
798 for (
int ii=1; ii<nR; ++ii)
801 buf[ii] *= buf[ii] / r;
804 buf[0] = buf[1] + (buf[1] - buf[2]);
808 for (
int ii=0; ii<nR; ++ii)
809 fscanf(potFile,
FMT1, buf+ii);
822 "%s: Can't open file %s. Fatal Error.\n", callSite, filename);
829 "%s: CoMD 1.1 does not support alloys and cannot\n"
830 " read setfl files with multiple species. Fatal Error.\n", callSite);
837 "%s: Potential type %s not supported. Fatal Error.\n", callSite, type);