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;
100 printf("[albe] mult parameter info:\n");
101 printf(" S (A) | %f | %f | %f\n",p->S[0],p->S[1],p->Smixed);
102 printf(" R (A) | %f | %f | %f\n",p->R[0],p->R[1],p->Rmixed);
103 printf(" A (eV) | %f | %f | %f\n",p->A[0]/EV,p->A[1]/EV,p->Amixed/EV);
104 printf(" B (eV) | %f | %f | %f\n",p->B[0]/EV,p->B[1]/EV,p->Bmixed/EV);
105 printf(" lambda | %f | %f | %f\n",p->lambda[0],p->lambda[1],
107 printf(" mu | %f | %f | %f\n",p->mu[0],p->mu[1],p->mu_m);
108 printf(" gamma | %f | %f\n",p->gamma[0],p->gamma[1]);
109 printf(" c | %f | %f\n",p->c[0],p->c[1]);
110 printf(" d | %f | %f\n",p->d[0],p->d[1]);
111 printf(" h | %f | %f\n",p->h[0],p->h[1]);
116 /* albe 3 body potential function (first ij loop) */
117 int albe_mult_3bp_j1(t_moldyn *moldyn,t_atom *ai,t_atom *aj,u8 bc) {
119 t_albe_mult_params *params;
120 t_albe_exchange *exchange;
126 params=moldyn->pot_params;
127 exchange=&(params->exchange);
130 exchange->zeta_ij=0.0;
133 * set ij depending values
137 if(brand==aj->brand) {
138 S2=params->S2[brand];
145 v3_sub(&dist_ij,&(aj->r),&(ai->r));
146 if(bc) check_per_bound(moldyn,&dist_ij);
147 d_ij2=v3_absolute_square(&dist_ij);
149 /* if d_ij2 > S2 => no force & potential energy contribution */
159 exchange->dist_ij=dist_ij;
160 exchange->d_ij2=d_ij2;
163 /* reset k counter for first k loop */
169 /* albe 3 body potential function (first k loop) */
170 int albe_mult_3bp_k1(t_moldyn *moldyn,
171 t_atom *ai,t_atom *aj,t_atom *ak,u8 bc) {
173 t_albe_mult_params *params;
174 t_albe_exchange *exchange;
177 t_3dvec dist_ij,dist_ik;
178 double d_ik2,d_ik,d_ij;
179 double cos_theta,h_cos,d2_h_cos2,frac,g,dg,s_r,arg;
180 double f_c_ik,df_c_ik;
183 params=moldyn->pot_params;
184 exchange=&(params->exchange);
185 kcount=exchange->kcount;
187 if(kcount>ALBE_MAXN) {
188 printf("FATAL: neighbours = %d\n",kcount);
189 printf(" -> %d %d %d\n",ai->tag,aj->tag,ak->tag);
194 if(brand==ak->brand) {
197 S2=params->S2[brand];
198 /* albe needs i,k depending c,d,h and gamma values */
199 exchange->gamma_i=&(params->gamma[brand]);
200 exchange->c_i=&(params->c[brand]);
201 exchange->d_i=&(params->d[brand]);
202 exchange->h_i=&(params->h[brand]);
208 /* albe needs i,k depending c,d,h and gamma values */
209 exchange->gamma_i=&(params->gamma_m);
210 exchange->c_i=&(params->c_mixed);
211 exchange->d_i=&(params->d_mixed);
212 exchange->h_i=&(params->h_mixed);
214 exchange->ci2=*(exchange->c_i)**(exchange->c_i);
215 exchange->di2=*(exchange->d_i)**(exchange->d_i);
216 exchange->ci2di2=exchange->ci2/exchange->di2;
219 v3_sub(&dist_ik,&(ak->r),&(ai->r));
220 if(bc) check_per_bound(moldyn,&dist_ik);
221 d_ik2=v3_absolute_square(&dist_ik);
223 /* store data for second k loop */
224 exchange->dist_ik[kcount]=dist_ik;
225 exchange->d_ik2[kcount]=d_ik2;
227 /* return if not within cutoff */
237 dist_ij=exchange->dist_ij;
241 cos_theta=v3_scalar_product(&dist_ij,&dist_ik)/(d_ij*d_ik);
244 h_cos=*(exchange->h_i)+cos_theta; // + in albe formalism
245 d2_h_cos2=exchange->di2+(h_cos*h_cos);
246 frac=exchange->ci2/d2_h_cos2;
247 g=*(exchange->gamma_i)*(1.0+exchange->ci2di2-frac);
248 dg=2.0*frac**(exchange->gamma_i)*h_cos/d2_h_cos2; // + in albe f..
250 /* zeta sum += f_c_ik * g_ijk */
252 exchange->zeta_ij+=g;
258 arg=M_PI*(d_ik-R)/s_r;
259 f_c_ik=0.5+0.5*cos(arg);
260 df_c_ik=0.5*sin(arg)*(M_PI/(s_r*d_ik));
261 exchange->zeta_ij+=f_c_ik*g;
264 /* store even more data for second k loop */
265 exchange->g[kcount]=g;
266 exchange->dg[kcount]=dg;
267 exchange->d_ik[kcount]=d_ik;
268 exchange->cos_theta[kcount]=cos_theta;
269 exchange->f_c_ik[kcount]=f_c_ik;
270 exchange->df_c_ik[kcount]=df_c_ik;
272 /* increase k counter */
278 int albe_mult_3bp_j2(t_moldyn *moldyn,t_atom *ai,t_atom *aj,u8 bc) {
280 t_albe_mult_params *params;
281 t_albe_exchange *exchange;
283 double f_a,df_a,b,db,f_c,df_c;
293 params=moldyn->pot_params;
294 exchange=&(params->exchange);
297 if(brand==ai->brand) {
302 r0=params->r0[brand];
303 mu=params->mu[brand];
304 lambda=params->lambda[brand];
313 lambda=params->lambda_m;
325 arg=M_PI*(d_ij-R)/s_r;
326 f_c=0.5+0.5*cos(arg);
327 df_c=0.5*sin(arg)*(M_PI/(s_r*d_ij));
331 f_a=-B*exp(-mu*(d_ij-r0));
335 f_r=A*exp(-lambda*(d_ij-r0));
336 df_r=lambda*f_r/d_ij;
339 if(exchange->zeta_ij==0.0) {
344 b=1.0/sqrt(1.0+exchange->zeta_ij);
345 db=-0.5*b/(1.0+exchange->zeta_ij);
348 /* force contribution for atom i */
349 scale=-0.5*(f_c*(df_r-b*df_a)+df_c*(f_r-b*f_a)); // - in albe formalism
350 v3_scale(&force,&(exchange->dist_ij),scale);
351 v3_add(&(ai->f),&(ai->f),&force);
353 /* force contribution for atom j */
354 v3_scale(&force,&force,-1.0); // dri rij = - drj rij
355 v3_add(&(aj->f),&(aj->f),&force);
358 virial_calc(aj,&force,&(exchange->dist_ij));
361 if(moldyn->time>DSTART&&moldyn->time<DEND) {
362 if((ai==&(moldyn->atom[DATOM]))|(aj==&(moldyn->atom[DATOM]))) {
363 printf("force 3bp (j2): [%d %d sum]\n",ai->tag,aj->tag);
364 printf(" adding %f %f %f\n",force.x,force.y,force.z);
365 if(ai==&(moldyn->atom[0]))
366 printf(" total i: %f %f %f\n",ai->f.x,ai->f.y,ai->f.z);
367 if(aj==&(moldyn->atom[0]))
368 printf(" total j: %f %f %f\n",aj->f.x,aj->f.y,aj->f.z);
369 printf(" energy: %f = %f %f %f %f\n",0.5*f_c*(b*f_a+f_r),
371 printf(" %f %f %f\n",exchange->zeta_ij,.0,.0);
376 /* dzeta prefactor = - f_c f_a db, (* -0.5 due to force calc) */
377 exchange->pre_dzeta=0.5*f_a*f_c*db;
379 /* energy contribution */
380 energy=0.5*f_c*(f_r-b*f_a); // - in albe formalism
381 moldyn->energy+=energy;
384 /* reset k counter for second k loop */
390 /* albe 3 body potential function (second k loop) */
391 int albe_mult_3bp_k2(t_moldyn *moldyn,
392 t_atom *ai,t_atom *aj,t_atom *ak,u8 bc) {
394 t_albe_mult_params *params;
395 t_albe_exchange *exchange;
397 t_3dvec dist_ik,dist_ij;
398 double d_ik2,d_ik,d_ij2,d_ij;
401 double g,dg,cos_theta;
403 double f_c_ik,df_c_ik;
404 double dijdik_inv,fcdg,dfcg;
405 t_3dvec dcosdrj,dcosdrk;
408 params=moldyn->pot_params;
409 exchange=&(params->exchange);
410 kcount=exchange->kcount;
413 printf("FATAL: neighbours!\n");
416 d_ik2=exchange->d_ik2[kcount];
420 S2=params->S2[brand];
424 /* return if d_ik > S */
430 /* prefactor dzeta */
431 pre_dzeta=exchange->pre_dzeta;
434 dist_ik=exchange->dist_ik[kcount];
435 d_ik=exchange->d_ik[kcount];
437 /* f_c_ik, df_c_ik */
438 f_c_ik=exchange->f_c_ik[kcount];
439 df_c_ik=exchange->df_c_ik[kcount];
441 /* dist_ij, d_ij2, d_ij */
442 dist_ij=exchange->dist_ij;
443 d_ij2=exchange->d_ij2;
446 /* g, dg, cos_theta */
447 g=exchange->g[kcount];
448 dg=exchange->dg[kcount];
449 cos_theta=exchange->cos_theta[kcount];
451 /* cos_theta derivatives wrt j,k */
452 dijdik_inv=1.0/(d_ij*d_ik);
453 v3_scale(&dcosdrj,&dist_ik,dijdik_inv); // j
454 v3_scale(&tmp,&dist_ij,-cos_theta/d_ij2);
455 v3_add(&dcosdrj,&dcosdrj,&tmp);
456 v3_scale(&dcosdrk,&dist_ij,dijdik_inv); // k
457 v3_scale(&tmp,&dist_ik,-cos_theta/d_ik2);
458 v3_add(&dcosdrk,&dcosdrk,&tmp);
460 /* f_c_ik * dg, df_c_ik * g */
464 /* derivative wrt j */
465 v3_scale(&force,&dcosdrj,fcdg*pre_dzeta);
467 /* force contribution */
468 v3_add(&(aj->f),&(aj->f),&force);
471 if(moldyn->time>DSTART&&moldyn->time<DEND) {
472 if(aj==&(moldyn->atom[DATOM])) {
473 printf("force 3bp (k2): [%d %d %d]\n",ai->tag,aj->tag,ak->tag);
474 printf(" adding %f %f %f\n",force.x,force.y,force.z);
475 printf(" total j: %f %f %f\n",aj->f.x,aj->f.y,aj->f.z);
476 printf(" angle: %f\n",acos(cos_theta)*360.0/(2*M_PI));
477 printf(" d ij ik = %f %f\n",d_ij,d_ik);
482 /* force contribution to atom i */
483 v3_scale(&force,&force,-1.0);
484 v3_add(&(ai->f),&(ai->f),&force);
487 virial_calc(ai,&force,&dist_ij);
489 /* derivative wrt k */
490 v3_scale(&force,&dist_ik,-1.0*dfcg); // dri rik = - drk rik
491 v3_scale(&tmp,&dcosdrk,fcdg);
492 v3_add(&force,&force,&tmp);
493 v3_scale(&force,&force,pre_dzeta);
495 /* force contribution */
496 v3_add(&(ak->f),&(ak->f),&force);
499 if(moldyn->time>DSTART&&moldyn->time<DEND) {
500 if(ak==&(moldyn->atom[DATOM])) {
501 printf("force 3bp (k2): [%d %d %d]\n",ai->tag,aj->tag,ak->tag);
502 printf(" adding %f %f %f\n",force.x,force.y,force.z);
503 printf(" total k: %f %f %f\n",ak->f.x,ak->f.y,ak->f.z);
504 printf(" angle: %f\n",acos(cos_theta)*360.0/(2*M_PI));
505 printf(" d ij ik = %f %f\n",d_ij,d_ik);
510 /* force contribution to atom i */
511 v3_scale(&force,&force,-1.0);
512 v3_add(&(ai->f),&(ai->f),&force);
515 virial_calc(ai,&force,&dist_ik);
517 /* increase k counter */
524 int albe_mult_check_2b_bond(t_moldyn *moldyn,t_atom *itom,t_atom *jtom,u8 bc) {
526 t_albe_mult_params *params;
531 v3_sub(&dist,&(jtom->r),&(itom->r));
532 if(bc) check_per_bound(moldyn,&dist);
533 d=v3_absolute_square(&dist);
535 params=moldyn->pot_params;
538 if(brand==jtom->brand) {
539 if(d<=params->S2[brand])
543 if(d<=params->S2mixed)