2 * albe.c - albe potential
4 * author: Frank Zirkelbach <frank.zirkelbach@physik.uni-augsburg.de>
12 #include <sys/types.h>
18 #include "../moldyn.h"
19 #include "../math/math.h"
22 /* create mixed terms from parameters and set them */
23 int albe_mult_set_params(t_moldyn *moldyn,int element1,int element2) {
25 t_albe_mult_params *p;
27 // set cutoff before parameters (actually only necessary for some pots)
28 if(moldyn->cutoff==0.0) {
29 printf("[albe] WARNING: no cutoff!\n");
33 /* alloc mem for potential parameters */
34 moldyn->pot_params=malloc(sizeof(t_albe_mult_params));
35 if(moldyn->pot_params==NULL) {
36 perror("[albe] pot params alloc");
40 /* these are now albe parameters */
43 // only 1 combination by now :p
52 p->lambda[0]=ALBE_LAMBDA_SI;
54 p->gamma[0]=ALBE_GAMMA_SI;
56 p->c2[0]=p->c[0]*p->c[0];
58 p->d2[0]=p->d[0]*p->d[0];
59 p->c2d2[0]=p->c2[0]/p->d2[0];
69 p->lambda[1]=ALBE_LAMBDA_C;
71 p->gamma[1]=ALBE_GAMMA_C;
73 p->c2[1]=p->c[1]*p->c[1];
75 p->d2[1]=p->d[1]*p->d[1];
76 p->c2d2[1]=p->c2[1]/p->d2[1];
78 /* mixed type: silicon carbide */
83 p->r0_mixed=ALBE_R0_SIC;
84 p->lambda_m=ALBE_LAMBDA_SIC;
86 p->gamma_m=ALBE_GAMMA_SIC;
87 p->c_mixed=ALBE_C_SIC;
88 p->c2_mixed=p->c_mixed*p->c_mixed;
89 p->d_mixed=ALBE_D_SIC;
90 p->d2_mixed=p->d_mixed*p->d_mixed;
91 p->c2d2_m=p->c2_mixed/p->d2_mixed;
92 p->h_mixed=ALBE_H_SIC;
95 printf("[albe] WARNING: element2\n");
100 printf("[albe] WARNING: element1\n");
104 printf("[albe] parameter completion\n");
105 p->S2[0]=p->S[0]*p->S[0];
106 p->S2[1]=p->S[1]*p->S[1];
107 p->S2mixed=p->Smixed*p->Smixed;
109 printf("[albe] mult parameter info:\n");
110 printf(" S (A) | %f | %f | %f\n",p->S[0],p->S[1],p->Smixed);
111 printf(" R (A) | %f | %f | %f\n",p->R[0],p->R[1],p->Rmixed);
112 printf(" A (eV) | %f | %f | %f\n",p->A[0]/EV,p->A[1]/EV,p->Amixed/EV);
113 printf(" B (eV) | %f | %f | %f\n",p->B[0]/EV,p->B[1]/EV,p->Bmixed/EV);
114 printf(" lambda | %f | %f | %f\n",p->lambda[0],p->lambda[1],
116 printf(" mu | %f | %f | %f\n",p->mu[0],p->mu[1],p->mu_m);
117 printf(" gamma | %f | %f | %f\n",p->gamma[0],p->gamma[1],p->gamma_m);
118 printf(" c | %f | %f | %f\n",p->c[0],p->c[1],p->c_mixed);
119 printf(" d | %f | %f | %f\n",p->d[0],p->d[1],p->d_mixed);
120 printf(" c2 | %f | %f | %f\n",p->c2[0],p->c2[1],p->c2_mixed);
121 printf(" d2 | %f | %f | %f\n",p->d2[0],p->d2[1],p->d2_mixed);
122 printf(" c2d2 | %f | %f | %f\n",p->c2d2[0],p->c2d2[1],p->c2d2_m);
123 printf(" h | %f | %f | %f\n",p->h[0],p->h[1],p->h_mixed);
129 int albe_mult_i0(t_moldyn *moldyn,t_atom *ai) {
131 t_albe_mult_params *params;
132 t_albe_exchange *exchange;
136 params=moldyn->pot_params;
137 exchange=&(params->exchange);
139 /* zero exchange values */
140 memset(exchange->zeta,0,ALBE_MAXN*sizeof(double));
141 for(i=0;i<ALBE_MAXN;i++)
142 memset(exchange->dzeta[i],0,ALBE_MAXN*sizeof(t_3dvec));
149 /* first j loop within first i loop */
150 int albe_mult_i0_j0(t_moldyn *moldyn,t_atom *ai,t_atom *aj,u8 bc) {
152 t_albe_mult_params *params;
153 t_albe_exchange *exchange;
155 double S2,S,R,d2,d,s_r,arg;
160 params=moldyn->pot_params;
161 exchange=&(params->exchange);
166 /* set ij depending values */
168 if(brand==aj->brand) {
169 S2=params->S2[brand];
176 v3_sub(&dist,&(aj->r),&(ai->r));
177 if(bc) check_per_bound(moldyn,&dist);
178 exchange->dist[j]=dist;
179 d2=v3_absolute_square(&dist);
182 /* if d_ij2 > S2 => no force & potential energy contribution */
191 /* more ij depending values */
192 if(brand==aj->brand) {
195 /* albe needs i,(j/k) depending c,d,h and gamma values */
196 exchange->gamma_[j]=&(params->gamma[brand]);
197 exchange->c_[j]=&(params->c[brand]);
198 exchange->d_[j]=&(params->d[brand]);
199 exchange->h_[j]=&(params->h[brand]);
200 exchange->c2_[j]=&(params->c2[brand]);
201 exchange->d2_[j]=&(params->d2[brand]);
202 exchange->c2d2_[j]=&(params->c2d2[brand]);
207 /* albe needs i,(j/k) depending c,d,h and gamma values */
208 exchange->gamma_[j]=&(params->gamma_m);
209 exchange->c_[j]=&(params->c_mixed);
210 exchange->d_[j]=&(params->d_mixed);
211 exchange->h_[j]=&(params->h_mixed);
212 exchange->c2_[j]=&(params->c2_mixed);
213 exchange->d2_[j]=&(params->d2_mixed);
214 exchange->c2d2_[j]=&(params->c2d2_m);
223 exchange->f_c[j]=1.0;
224 exchange->df_c[j]=0.0;
229 exchange->f_c[j]=0.5+0.5*cos(arg);
230 exchange->df_c[j]=0.5*sin(arg)*(M_PI/(s_r*d));
233 /* reset k counter */
239 /* first k loop within first j loop within first i loop */
240 int albe_mult_i0_j0_k0(t_moldyn *moldyn,
241 t_atom *ai,t_atom *aj,t_atom *ak,u8 bc) {
243 t_albe_mult_params *params;
244 t_albe_exchange *exchange;
248 double dj,dk,djdk_inv,cos_theta;
249 double gj,dgj,h_cos_j,d2_h_cos2_j,frac_j;
250 double gk,dgk,h_cos_k,d2_h_cos2_k,frac_k;
251 t_3dvec dcosdrj,dcosdrk,tmp;
252 t_3dvec *dzjj,*dzkk,*dzjk,*dzkj;
254 params=moldyn->pot_params;
255 exchange=&(params->exchange);
262 /* k<j & check whether to run k */
266 printf("FATAL: too many neighbours! (%d)\n",k);
267 printf(" atom i:%d | j:%d | k:%d\n",ai->tag,aj->tag,ak->tag);
269 if((k>=j)|(exchange->skip[k])) {
275 distj=exchange->dist[j];
276 distk=exchange->dist[k];
279 djdk_inv=1.0/(dj*dk);
282 cos_theta=v3_scalar_product(&distj,&distk)*djdk_inv;
284 /* g(cos(theta)) ij and ik values */
285 h_cos_j=*(exchange->h_[j])+cos_theta; // + in albe formalism
286 d2_h_cos2_j=*exchange->d2_[j]+(h_cos_j*h_cos_j);
287 frac_j=*exchange->c2_[j]/d2_h_cos2_j;
288 gj=1.0+*exchange->c2d2_[j]-frac_j;
289 gj*=*(exchange->gamma_[j]);
290 dgj=*(exchange->gamma_[j])*2.0*frac_j*h_cos_j/d2_h_cos2_j; // + in albe
291 if(ak->brand==aj->brand) {
296 h_cos_k=*(exchange->h_[k])+cos_theta;
297 d2_h_cos2_k=*exchange->d2_[k]+(h_cos_k*h_cos_k);
298 frac_k=*exchange->c2_[k]/d2_h_cos2_k;
299 gk=1.0+*exchange->c2d2_[k]-frac_k;
300 gk*=*(exchange->gamma_[k]);
301 dgk=*(exchange->gamma_[k])*2.0*frac_k*h_cos_k/d2_h_cos2_k;
304 /* zeta - for albe: ik depending g function */
306 // printf("------> %.15f %.15f\n",dj,dk);
307 // printf("------> %.15f %.15f\n",dj,dk);
310 exchange->zeta[j]+=(exchange->f_c[k]*gk);
311 exchange->zeta[k]+=(exchange->f_c[j]*gj);
313 /* cos theta derivatives */
314 v3_scale(&dcosdrj,&distk,djdk_inv); // j
315 v3_scale(&tmp,&distj,-cos_theta/exchange->d2[j]);
316 v3_add(&dcosdrj,&dcosdrj,&tmp);
317 v3_scale(&dcosdrk,&distj,djdk_inv); // k
318 v3_scale(&tmp,&distk,-cos_theta/exchange->d2[k]);
319 v3_add(&dcosdrk,&dcosdrk,&tmp);
321 /* zeta derivatives */
322 dzjj=&(exchange->dzeta[j][j]);
323 dzkk=&(exchange->dzeta[k][k]);
324 dzjk=&(exchange->dzeta[j][k]);
325 dzkj=&(exchange->dzeta[k][j]);
326 v3_scale(&tmp,&dcosdrj,exchange->f_c[k]*dgk);
327 v3_add(dzjj,dzjj,&tmp); // j j
328 v3_scale(&tmp,&dcosdrk,exchange->f_c[j]*dgj);
329 v3_add(dzkk,dzkk,&tmp); // k k
330 v3_scale(&tmp,&distk,-exchange->df_c[k]*gk); // dk rik = - di rik
331 v3_add(dzjk,dzjk,&tmp);
332 v3_scale(&tmp,&dcosdrk,exchange->f_c[k]*dgk);
333 v3_add(dzjk,dzjk,&tmp); // j k
334 v3_scale(&tmp,&distj,-exchange->df_c[j]*gj); // dj rij = - di rij
335 v3_add(dzkj,dzkj,&tmp);
336 v3_scale(&tmp,&dcosdrj,exchange->f_c[j]*dgj);
337 v3_add(dzkj,dzkj,&tmp); // k j
339 /* increase k counter */
345 /* first j loop within first i loop */
346 int albe_mult_i0_j1(t_moldyn *moldyn,t_atom *ai,t_atom *aj,u8 bc) {
348 t_albe_mult_params *params;
349 t_albe_exchange *exchange;
351 params=moldyn->pot_params;
352 exchange=&(params->exchange);
354 /* increase j counter */
360 /* second j loop within first i loop */
361 int albe_mult_i0_j2(t_moldyn *moldyn,t_atom *ai,t_atom *aj,u8 bc) {
363 t_albe_mult_params *params;
364 t_albe_exchange *exchange;
367 double d,f_a,df_a,f_r,df_r,f_c,df_c,b,db;
368 double A,B,mu,lambda,r0;
374 params=moldyn->pot_params;
375 exchange=&(params->exchange);
380 /* skip if j not within cutoff */
381 if(exchange->skip[j]) {
389 dist=&(exchange->dist[j]);
390 f_c=exchange->f_c[j];
391 df_c=exchange->df_c[j];
393 /* determine parameters to calculate fa, dfa, fr, dfr */
395 if(brand==ai->brand) {
398 r0=params->r0[brand];
399 mu=params->mu[brand];
400 lambda=params->lambda[brand];
407 lambda=params->lambda_m;
411 f_a=-B*exp(-mu*(d-r0));
415 f_r=A*exp(-lambda*(d-r0));
419 b=1.0/sqrt(1.0+exchange->zeta[j]);
420 db=-0.5*b/(1.0+exchange->zeta[j]);
422 /* energy contribution */
423 energy=0.5*f_c*(f_r-b*f_a); // - in albe formalism
424 moldyn->energy+=energy;
427 /* force contribution for atom i due to ij bond */
428 scale=-0.5*(f_c*(df_r-b*df_a)+df_c*(f_r-b*f_a)); // - in albe formalism
429 v3_scale(&force,dist,scale);
430 v3_add(&(ai->f),&(ai->f),&force);
434 printf("force: %.15f %.15f %.15f | %d %d (ij) %.15f\n",force.x,force.y,force.z,ai->tag,aj->tag,exchange->zeta[j]);
435 printf(" t: %.15f %.15f %.15f\n",ai->f.x,ai->f.y,ai->f.z);
439 /* force contribution for atom j due to ij bond */
440 v3_scale(&force,&force,-1.0); // dri rij = - drj rij
441 v3_add(&(aj->f),&(aj->f),&force);
445 printf("force: %.15f %.15f %.15f | %d %d (ji) %.15f\n",force.x,force.y,force.z,aj->tag,ai->tag,exchange->zeta[j]);
446 printf(" t: %.15f %.15f %.15f\n",aj->f.x,aj->f.y,aj->f.z);
451 virial_calc(ai,&force,dist);
453 /* dzeta prefactor = - f_c f_a db, (* -0.5 due to force calc) */
454 exchange->pre_dzeta=0.5*f_a*f_c*db;
456 /* force contribution (drj derivative) */
457 v3_scale(&force,&(exchange->dzeta[j][j]),exchange->pre_dzeta);
458 v3_add(&(aj->f),&(aj->f),&force);
462 printf("force: %.15f %.15f %.15f | %d %d (j der)\n",force.x,force.y,force.z,aj->tag,ai->tag);
463 printf(" t: %.15f %.15f %.15f\n",aj->f.x,aj->f.y,aj->f.z);
468 virial_calc(ai,&force,dist);
470 v3_scale(&force,&force,-1.0);
471 v3_add(&(ai->f),&(ai->f),&force);
475 printf("force: %.15f %.15f %.15f | %d %d (i contr j der)\n",force.x,force.y,force.z,ai->tag,aj->tag);
476 printf(" t: %.15f %.15f %.15f\n",ai->f.x,ai->f.y,ai->f.z);
480 /* reset k counter for second k loop */
486 /* second k loop within second j loop within first i loop */
487 int albe_mult_i0_j2_k0(t_moldyn *moldyn,
488 t_atom *ai,t_atom *aj,t_atom *ak,u8 bc) {
490 t_albe_mult_params *params;
491 t_albe_exchange *exchange;
496 params=moldyn->pot_params;
497 exchange=&(params->exchange);
504 /* k!=j & check whether to run k */
507 if((k==j)|(exchange->skip[k])) {
512 /* force contribution (drk derivative) */
513 v3_scale(&force,&(exchange->dzeta[j][k]),exchange->pre_dzeta);
514 v3_add(&(ak->f),&(ak->f),&force);
518 printf("force: %.15f %.15f %.15f | %d %d %d (k der)\n",force.x,force.y,force.z,ai->tag,aj->tag,ak->tag);
519 printf(" t: %.15f %.15f %.15f\n",ak->f.x,ak->f.y,ak->f.z);
524 virial_calc(ai,&force,&(exchange->dist[k]));
526 v3_scale(&force,&force,-1.0);
527 v3_add(&(ai->f),&(ai->f),&force);
531 printf("force: %.15f %.15f %.15f | %d %d %d -- %d(i contr k der)\n",force.x,force.y,force.z,ai->tag,aj->tag,ak->tag,k);
532 printf(" t: %.15f %.15f %.15f\n",ai->f.x,ai->f.y,ai->f.z);
533 printf(" ## %f\n",exchange->d[k]);
537 /* increase k counter */
543 int albe_mult_i0_j3(t_moldyn *moldyn,t_atom *ai,t_atom *aj,u8 bc) {
545 t_albe_mult_params *params;
546 t_albe_exchange *exchange;
548 params=moldyn->pot_params;
549 exchange=&(params->exchange);
551 /* increase j counter */
557 int albe_mult_check_2b_bond(t_moldyn *moldyn,t_atom *itom,t_atom *jtom,u8 bc) {
559 t_albe_mult_params *params;
564 v3_sub(&dist,&(jtom->r),&(itom->r));
565 if(bc) check_per_bound(moldyn,&dist);
566 d=v3_absolute_square(&dist);
568 params=moldyn->pot_params;
571 if(brand==jtom->brand) {
572 if(d<=params->S2[brand])
576 if(d<=params->S2mixed)