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;
66 p->lambda[1]=ALBE_LAMBDA_C;
68 p->gamma[1]=ALBE_GAMMA_C;
72 /* mixed type: silicon carbide */
77 p->r0_mixed=ALBE_R0_SIC;
78 p->lambda_m=ALBE_LAMBDA_SIC;
80 p->gamma_m=ALBE_GAMMA_SIC;
81 p->c_mixed=ALBE_C_SIC;
82 p->d_mixed=ALBE_D_SIC;
83 p->h_mixed=ALBE_H_SIC;
86 printf("[albe] WARNING: element2\n");
91 printf("[albe] WARNING: element1\n");
95 printf("[albe] parameter completion\n");
96 p->S2[0]=p->S[0]*p->S[0];
97 p->S2[1]=p->S[1]*p->S[1];
98 p->S2mixed=p->Smixed*p->Smixed;
99 p->c2[0]=p->c[0]*p->c[0];
100 p->c2[1]=p->c[1]*p->c[1];
101 p->c2_mixed=p->c_mixed*p->c_mixed;
102 p->d2[0]=p->d[0]*p->d[0];
103 p->d2[1]=p->d[1]*p->d[1];
104 p->d2_mixed=p->d_mixed*p->d_mixed;
105 p->c2d2[0]=p->c2[0]/p->d2[0];
106 p->c2d2[1]=p->c2[1]/p->d2[1];
107 p->c2d2_m=p->c2_mixed/p->d2_mixed;
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\n",p->gamma[0],p->gamma[1]);
118 printf(" c | %f | %f\n",p->c[0],p->c[1]);
119 printf(" d | %f | %f\n",p->d[0],p->d[1]);
120 printf(" h | %f | %f\n",p->h[0],p->h[1]);
125 /* albe 3 body potential function (first ij loop) */
126 int albe_mult_3bp_j1(t_moldyn *moldyn,t_atom *ai,t_atom *aj,u8 bc) {
128 t_albe_mult_params *params;
129 t_albe_exchange *exchange;
135 params=moldyn->pot_params;
136 exchange=&(params->exchange);
139 exchange->zeta_ij=0.0;
142 * set ij depending values
146 if(brand==aj->brand) {
147 S2=params->S2[brand];
154 v3_sub(&dist_ij,&(aj->r),&(ai->r));
155 if(bc) check_per_bound(moldyn,&dist_ij);
156 d_ij2=v3_absolute_square(&dist_ij);
158 /* if d_ij2 > S2 => no force & potential energy contribution */
168 exchange->dist_ij=dist_ij;
169 exchange->d_ij2=d_ij2;
172 /* reset k counter for first k loop */
178 /* albe 3 body potential function (first k loop) */
179 int albe_mult_3bp_k1(t_moldyn *moldyn,
180 t_atom *ai,t_atom *aj,t_atom *ak,u8 bc) {
182 t_albe_mult_params *params;
183 t_albe_exchange *exchange;
186 t_3dvec dist_ij,dist_ik;
187 double d_ik2,d_ik,d_ij;
188 double cos_theta,h_cos,d2_h_cos2,frac,g,dg,s_r,arg;
189 double f_c_ik,df_c_ik;
192 params=moldyn->pot_params;
193 exchange=&(params->exchange);
194 kcount=exchange->kcount;
196 if(kcount>ALBE_MAXN) {
197 printf("FATAL: neighbours = %d\n",kcount);
198 printf(" -> %d %d %d\n",ai->tag,aj->tag,ak->tag);
203 if(brand==ak->brand) {
206 S2=params->S2[brand];
207 /* albe needs i,k depending c,d,h and gamma values */
208 exchange->gamma_i=&(params->gamma[brand]);
209 exchange->c_i=&(params->c[brand]);
210 exchange->d_i=&(params->d[brand]);
211 exchange->h_i=&(params->h[brand]);
217 /* albe needs i,k depending c,d,h and gamma values */
218 exchange->gamma_i=&(params->gamma_m);
219 exchange->c_i=&(params->c_mixed);
220 exchange->d_i=&(params->d_mixed);
221 exchange->h_i=&(params->h_mixed);
223 exchange->ci2=*(exchange->c_i)**(exchange->c_i);
224 exchange->di2=*(exchange->d_i)**(exchange->d_i);
225 exchange->ci2di2=exchange->ci2/exchange->di2;
228 v3_sub(&dist_ik,&(ak->r),&(ai->r));
229 if(bc) check_per_bound(moldyn,&dist_ik);
230 d_ik2=v3_absolute_square(&dist_ik);
232 /* store data for second k loop */
233 exchange->dist_ik[kcount]=dist_ik;
234 exchange->d_ik2[kcount]=d_ik2;
236 /* return if not within cutoff */
246 dist_ij=exchange->dist_ij;
250 cos_theta=v3_scalar_product(&dist_ij,&dist_ik)/(d_ij*d_ik);
253 h_cos=*(exchange->h_i)+cos_theta; // + in albe formalism
254 d2_h_cos2=exchange->di2+(h_cos*h_cos);
255 frac=exchange->ci2/d2_h_cos2;
256 g=*(exchange->gamma_i)*(1.0+exchange->ci2di2-frac);
257 dg=2.0*frac**(exchange->gamma_i)*h_cos/d2_h_cos2; // + in albe f..
259 /* zeta sum += f_c_ik * g_ijk */
261 exchange->zeta_ij+=g;
267 arg=M_PI*(d_ik-R)/s_r;
268 f_c_ik=0.5+0.5*cos(arg);
269 df_c_ik=0.5*sin(arg)*(M_PI/(s_r*d_ik));
270 exchange->zeta_ij+=f_c_ik*g;
274 if(ai==&(moldyn->atom[DATOM]))
275 printf("zeta_ij: %f %f %f %f\n",f_c_ik*g,f_c_ik,g,d_ik);
278 /* store even more data for second k loop */
279 exchange->g[kcount]=g;
280 exchange->dg[kcount]=dg;
281 exchange->d_ik[kcount]=d_ik;
282 exchange->cos_theta[kcount]=cos_theta;
283 exchange->f_c_ik[kcount]=f_c_ik;
284 exchange->df_c_ik[kcount]=df_c_ik;
286 /* increase k counter */
292 int albe_mult_3bp_j2(t_moldyn *moldyn,t_atom *ai,t_atom *aj,u8 bc) {
294 t_albe_mult_params *params;
295 t_albe_exchange *exchange;
297 double f_a,df_a,b,db,f_c,df_c;
307 params=moldyn->pot_params;
308 exchange=&(params->exchange);
311 if(brand==ai->brand) {
316 r0=params->r0[brand];
317 mu=params->mu[brand];
318 lambda=params->lambda[brand];
327 lambda=params->lambda_m;
339 arg=M_PI*(d_ij-R)/s_r;
340 f_c=0.5+0.5*cos(arg);
341 df_c=0.5*sin(arg)*(M_PI/(s_r*d_ij));
345 f_a=-B*exp(-mu*(d_ij-r0));
349 f_r=A*exp(-lambda*(d_ij-r0));
350 df_r=lambda*f_r/d_ij;
353 if(exchange->zeta_ij==0.0) {
358 b=1.0/sqrt(1.0+exchange->zeta_ij);
359 db=-0.5*b/(1.0+exchange->zeta_ij);
362 /* force contribution for atom i */
363 scale=-0.5*(f_c*(df_r-b*df_a)+df_c*(f_r-b*f_a)); // - in albe formalism
364 v3_scale(&force,&(exchange->dist_ij),scale);
365 v3_add(&(ai->f),&(ai->f),&force);
367 /* force contribution for atom j */
368 v3_scale(&force,&force,-1.0); // dri rij = - drj rij
369 v3_add(&(aj->f),&(aj->f),&force);
372 virial_calc(ai,&force,&(exchange->dist_ij));
375 if((ai==&(moldyn->atom[DATOM]))|(aj==&(moldyn->atom[DATOM]))) {
376 printf("force 3bp (j2): [%d %d sum]\n",ai->tag,aj->tag);
377 printf(" adding %f %f %f\n",force.x,force.y,force.z);
378 if(ai==&(moldyn->atom[DATOM]))
379 printf(" total i: %f %f %f\n",ai->f.x,ai->f.y,ai->f.z);
380 if(aj==&(moldyn->atom[DATOM]))
381 printf(" total j: %f %f %f\n",aj->f.x,aj->f.y,aj->f.z);
382 printf(" energy: %f = %f %f %f %f\n",0.5*f_c*(b*f_a+f_r),
384 printf(" %f %f %f\n",exchange->zeta_ij,.0,.0);
388 /* dzeta prefactor = - f_c f_a db, (* -0.5 due to force calc) */
389 exchange->pre_dzeta=0.5*f_a*f_c*db;
391 /* energy contribution */
392 energy=0.5*f_c*(f_r-b*f_a); // - in albe formalism
393 moldyn->energy+=energy;
396 /* reset k counter for second k loop */
402 /* albe 3 body potential function (second k loop) */
403 int albe_mult_3bp_k2(t_moldyn *moldyn,
404 t_atom *ai,t_atom *aj,t_atom *ak,u8 bc) {
406 t_albe_mult_params *params;
407 t_albe_exchange *exchange;
409 t_3dvec dist_ik,dist_ij;
410 double d_ik2,d_ik,d_ij2,d_ij;
413 double g,dg,cos_theta;
415 double f_c_ik,df_c_ik;
416 double dijdik_inv,fcdg,dfcg;
417 t_3dvec dcosdrj,dcosdrk;
420 params=moldyn->pot_params;
421 exchange=&(params->exchange);
422 kcount=exchange->kcount;
425 printf("FATAL: neighbours!\n");
428 d_ik2=exchange->d_ik2[kcount];
432 S2=params->S2[brand];
436 /* return if d_ik > S */
442 /* prefactor dzeta */
443 pre_dzeta=exchange->pre_dzeta;
446 dist_ik=exchange->dist_ik[kcount];
447 d_ik=exchange->d_ik[kcount];
449 /* f_c_ik, df_c_ik */
450 f_c_ik=exchange->f_c_ik[kcount];
451 df_c_ik=exchange->df_c_ik[kcount];
453 /* dist_ij, d_ij2, d_ij */
454 dist_ij=exchange->dist_ij;
455 d_ij2=exchange->d_ij2;
458 /* g, dg, cos_theta */
459 g=exchange->g[kcount];
460 dg=exchange->dg[kcount];
461 cos_theta=exchange->cos_theta[kcount];
463 /* cos_theta derivatives wrt j,k */
464 dijdik_inv=1.0/(d_ij*d_ik);
465 v3_scale(&dcosdrj,&dist_ik,dijdik_inv); // j
466 v3_scale(&tmp,&dist_ij,-cos_theta/d_ij2);
467 v3_add(&dcosdrj,&dcosdrj,&tmp);
468 v3_scale(&dcosdrk,&dist_ij,dijdik_inv); // k
469 v3_scale(&tmp,&dist_ik,-cos_theta/d_ik2);
470 v3_add(&dcosdrk,&dcosdrk,&tmp);
472 /* f_c_ik * dg, df_c_ik * g */
476 /* derivative wrt j */
477 v3_scale(&force,&dcosdrj,fcdg*pre_dzeta);
479 /* force contribution */
480 v3_add(&(aj->f),&(aj->f),&force);
483 if(aj==&(moldyn->atom[DATOM])) {
484 printf("force 3bp (k2): [%d %d %d]\n",ai->tag,aj->tag,ak->tag);
485 printf(" adding %f %f %f\n",force.x,force.y,force.z);
486 printf(" total j: %f %f %f\n",aj->f.x,aj->f.y,aj->f.z);
487 printf(" angle: %f\n",acos(cos_theta)*360.0/(2*M_PI));
488 printf(" d ij ik = %f %f\n",d_ij,d_ik);
493 virial_calc(ai,&force,&dist_ij);
495 /* force contribution to atom i */
496 v3_scale(&force,&force,-1.0);
497 v3_add(&(ai->f),&(ai->f),&force);
499 /* derivative wrt k */
500 v3_scale(&force,&dist_ik,-1.0*dfcg); // dri rik = - drk rik
501 v3_scale(&tmp,&dcosdrk,fcdg);
502 v3_add(&force,&force,&tmp);
503 v3_scale(&force,&force,pre_dzeta);
505 /* force contribution */
506 v3_add(&(ak->f),&(ak->f),&force);
509 if(ak==&(moldyn->atom[DATOM])) {
510 printf("force 3bp (k2): [%d %d %d]\n",ai->tag,aj->tag,ak->tag);
511 printf(" adding %f %f %f\n",force.x,force.y,force.z);
512 printf(" total k: %f %f %f\n",ak->f.x,ak->f.y,ak->f.z);
513 printf(" angle: %f\n",acos(cos_theta)*360.0/(2*M_PI));
514 printf(" d ij ik = %f %f\n",d_ij,d_ik);
519 virial_calc(ai,&force,&dist_ik);
521 /* force contribution to atom i */
522 v3_scale(&force,&force,-1.0);
523 v3_add(&(ai->f),&(ai->f),&force);
525 /* increase k counter */
532 int albe_mult_check_2b_bond(t_moldyn *moldyn,t_atom *itom,t_atom *jtom,u8 bc) {
534 t_albe_mult_params *params;
539 v3_sub(&dist,&(jtom->r),&(itom->r));
540 if(bc) check_per_bound(moldyn,&dist);
541 d=v3_absolute_square(&dist);
543 params=moldyn->pot_params;
546 if(brand==jtom->brand) {
547 if(d<=params->S2[brand])
551 if(d<=params->S2mixed)