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 /* alloc mem for potential parameters */
28 moldyn->pot_params=malloc(sizeof(t_albe_mult_params));
29 if(moldyn->pot_params==NULL) {
30 perror("[albe] pot params alloc");
34 /* these are now albe parameters */
37 // only 1 combination by now :p
46 p->lambda[0]=ALBE_LAMBDA_SI;
48 p->gamma[0]=ALBE_GAMMA_SI;
60 p->lambda[1]=ALBE_LAMBDA_C;
62 p->gamma[1]=ALBE_GAMMA_C;
66 /* mixed type: silicon carbide */
71 p->r0_mixed=ALBE_R0_SIC;
72 p->lambda_m=ALBE_LAMBDA_SIC;
74 p->gamma_m=ALBE_GAMMA_SIC;
75 p->c_mixed=ALBE_C_SIC;
76 p->d_mixed=ALBE_D_SIC;
77 p->h_mixed=ALBE_H_SIC;
80 printf("[albe] WARNING: element2\n");
85 printf("[albe] WARNING: element1\n");
89 printf("[albe] parameter completion\n");
90 p->S2[0]=p->S[0]*p->S[0];
91 p->S2[1]=p->S[1]*p->S[1];
92 p->S2mixed=p->Smixed*p->Smixed;
94 printf("[albe] mult parameter info:\n");
95 printf(" S (A) | %f | %f | %f\n",p->S[0],p->S[1],p->Smixed);
96 printf(" R (A) | %f | %f | %f\n",p->R[0],p->R[1],p->Rmixed);
97 printf(" A (eV) | %f | %f | %f\n",p->A[0]/EV,p->A[1]/EV,p->Amixed/EV);
98 printf(" B (eV) | %f | %f | %f\n",p->B[0]/EV,p->B[1]/EV,p->Bmixed/EV);
99 printf(" lambda | %f | %f | %f\n",p->lambda[0],p->lambda[1],
101 printf(" mu | %f | %f | %f\n",p->mu[0],p->mu[1],p->mu_m);
102 printf(" gamma | %f | %f\n",p->gamma[0],p->gamma[1]);
103 printf(" c | %f | %f\n",p->c[0],p->c[1]);
104 printf(" d | %f | %f\n",p->d[0],p->d[1]);
105 printf(" h | %f | %f\n",p->h[0],p->h[1]);
110 /* albe 3 body potential function (first ij loop) */
111 int albe_mult_3bp_j1(t_moldyn *moldyn,t_atom *ai,t_atom *aj,u8 bc) {
113 t_albe_mult_params *params;
114 t_albe_exchange *exchange;
120 params=moldyn->pot_params;
121 exchange=&(params->exchange);
124 exchange->zeta_ij=0.0;
127 * set ij depending values
131 if(brand==aj->brand) {
132 S2=params->S2[brand];
139 v3_sub(&dist_ij,&(aj->r),&(ai->r));
140 if(bc) check_per_bound(moldyn,&dist_ij);
141 d_ij2=v3_absolute_square(&dist_ij);
143 /* if d_ij2 > S2 => no force & potential energy contribution */
153 exchange->dist_ij=dist_ij;
154 exchange->d_ij2=d_ij2;
157 /* reset k counter for first k loop */
163 /* albe 3 body potential function (first k loop) */
164 int albe_mult_3bp_k1(t_moldyn *moldyn,
165 t_atom *ai,t_atom *aj,t_atom *ak,u8 bc) {
167 t_albe_mult_params *params;
168 t_albe_exchange *exchange;
171 t_3dvec dist_ij,dist_ik;
172 double d_ik2,d_ik,d_ij;
173 double cos_theta,h_cos,d2_h_cos2,frac,g,dg,s_r,arg;
174 double f_c_ik,df_c_ik;
177 params=moldyn->pot_params;
178 exchange=&(params->exchange);
179 kcount=exchange->kcount;
181 if(kcount>ALBE_MAXN) {
182 printf("FATAL: neighbours = %d\n",kcount);
183 printf(" -> %d %d %d\n",ai->tag,aj->tag,ak->tag);
188 if(brand==ak->brand) {
191 S2=params->S2[brand];
192 /* albe needs i,k depending c,d,h and gamma values */
193 exchange->gamma_i=&(params->gamma[brand]);
194 exchange->c_i=&(params->c[brand]);
195 exchange->d_i=&(params->d[brand]);
196 exchange->h_i=&(params->h[brand]);
202 /* albe needs i,k depending c,d,h and gamma values */
203 exchange->gamma_i=&(params->gamma_m);
204 exchange->c_i=&(params->c_mixed);
205 exchange->d_i=&(params->d_mixed);
206 exchange->h_i=&(params->h_mixed);
208 exchange->ci2=*(exchange->c_i)**(exchange->c_i);
209 exchange->di2=*(exchange->d_i)**(exchange->d_i);
210 exchange->ci2di2=exchange->ci2/exchange->di2;
213 v3_sub(&dist_ik,&(ak->r),&(ai->r));
214 if(bc) check_per_bound(moldyn,&dist_ik);
215 d_ik2=v3_absolute_square(&dist_ik);
217 /* store data for second k loop */
218 exchange->dist_ik[kcount]=dist_ik;
219 exchange->d_ik2[kcount]=d_ik2;
221 /* return if not within cutoff */
231 dist_ij=exchange->dist_ij;
235 cos_theta=v3_scalar_product(&dist_ij,&dist_ik)/(d_ij*d_ik);
238 h_cos=*(exchange->h_i)+cos_theta; // + in albe formalism
239 d2_h_cos2=exchange->di2+(h_cos*h_cos);
240 frac=exchange->ci2/d2_h_cos2;
241 g=*(exchange->gamma_i)*(1.0+exchange->ci2di2-frac);
242 dg=2.0*frac**(exchange->gamma_i)*h_cos/d2_h_cos2; // + in albe f..
244 /* zeta sum += f_c_ik * g_ijk */
246 exchange->zeta_ij+=g;
252 arg=M_PI*(d_ik-R)/s_r;
253 f_c_ik=0.5+0.5*cos(arg);
254 df_c_ik=0.5*sin(arg)*(M_PI/(s_r*d_ik));
255 exchange->zeta_ij+=f_c_ik*g;
258 /* store even more data for second k loop */
259 exchange->g[kcount]=g;
260 exchange->dg[kcount]=dg;
261 exchange->d_ik[kcount]=d_ik;
262 exchange->cos_theta[kcount]=cos_theta;
263 exchange->f_c_ik[kcount]=f_c_ik;
264 exchange->df_c_ik[kcount]=df_c_ik;
266 /* increase k counter */
272 int albe_mult_3bp_j2(t_moldyn *moldyn,t_atom *ai,t_atom *aj,u8 bc) {
274 t_albe_mult_params *params;
275 t_albe_exchange *exchange;
277 double f_a,df_a,b,db,f_c,df_c;
287 params=moldyn->pot_params;
288 exchange=&(params->exchange);
291 if(brand==ai->brand) {
296 r0=params->r0[brand];
297 mu=params->mu[brand];
298 lambda=params->lambda[brand];
307 lambda=params->lambda_m;
319 arg=M_PI*(d_ij-R)/s_r;
320 f_c=0.5+0.5*cos(arg);
321 df_c=0.5*sin(arg)*(M_PI/(s_r*d_ij));
325 f_a=-B*exp(-mu*(d_ij-r0));
329 f_r=A*exp(-lambda*(d_ij-r0));
330 df_r=lambda*f_r/d_ij;
333 if(exchange->zeta_ij==0.0) {
338 b=1.0/sqrt(1.0+exchange->zeta_ij);
339 db=-0.5*b/(1.0+exchange->zeta_ij);
342 /* force contribution for atom i */
343 scale=-0.5*(f_c*(df_r-b*df_a)+df_c*(f_r-b*f_a)); // - in albe formalism
344 v3_scale(&force,&(exchange->dist_ij),scale);
345 v3_add(&(ai->f),&(ai->f),&force);
347 /* force contribution for atom j */
348 v3_scale(&force,&force,-1.0); // dri rij = - drj rij
349 v3_add(&(aj->f),&(aj->f),&force);
352 virial_calc(aj,&force,&(exchange->dist_ij));
355 if(moldyn->time>DSTART&&moldyn->time<DEND) {
356 if((ai==&(moldyn->atom[DATOM]))|(aj==&(moldyn->atom[DATOM]))) {
357 printf("force 3bp (j2): [%d %d sum]\n",ai->tag,aj->tag);
358 printf(" adding %f %f %f\n",force.x,force.y,force.z);
359 if(ai==&(moldyn->atom[0]))
360 printf(" total i: %f %f %f\n",ai->f.x,ai->f.y,ai->f.z);
361 if(aj==&(moldyn->atom[0]))
362 printf(" total j: %f %f %f\n",aj->f.x,aj->f.y,aj->f.z);
363 printf(" energy: %f = %f %f %f %f\n",0.5*f_c*(b*f_a+f_r),
365 printf(" %f %f %f\n",exchange->zeta_ij,.0,.0);
370 /* dzeta prefactor = - f_c f_a db, (* -0.5 due to force calc) */
371 exchange->pre_dzeta=0.5*f_a*f_c*db;
373 /* energy contribution */
374 energy=0.5*f_c*(f_r-b*f_a); // - in albe formalism
375 moldyn->energy+=energy;
378 /* reset k counter for second k loop */
384 /* albe 3 body potential function (second k loop) */
385 int albe_mult_3bp_k2(t_moldyn *moldyn,
386 t_atom *ai,t_atom *aj,t_atom *ak,u8 bc) {
388 t_albe_mult_params *params;
389 t_albe_exchange *exchange;
391 t_3dvec dist_ik,dist_ij;
392 double d_ik2,d_ik,d_ij2,d_ij;
395 double g,dg,cos_theta;
397 double f_c_ik,df_c_ik;
398 double dijdik_inv,fcdg,dfcg;
399 t_3dvec dcosdrj,dcosdrk;
402 params=moldyn->pot_params;
403 exchange=&(params->exchange);
404 kcount=exchange->kcount;
407 printf("FATAL: neighbours!\n");
410 d_ik2=exchange->d_ik2[kcount];
414 S2=params->S2[brand];
418 /* return if d_ik > S */
424 /* prefactor dzeta */
425 pre_dzeta=exchange->pre_dzeta;
428 dist_ik=exchange->dist_ik[kcount];
429 d_ik=exchange->d_ik[kcount];
431 /* f_c_ik, df_c_ik */
432 f_c_ik=exchange->f_c_ik[kcount];
433 df_c_ik=exchange->df_c_ik[kcount];
435 /* dist_ij, d_ij2, d_ij */
436 dist_ij=exchange->dist_ij;
437 d_ij2=exchange->d_ij2;
440 /* g, dg, cos_theta */
441 g=exchange->g[kcount];
442 dg=exchange->dg[kcount];
443 cos_theta=exchange->cos_theta[kcount];
445 /* cos_theta derivatives wrt j,k */
446 dijdik_inv=1.0/(d_ij*d_ik);
447 v3_scale(&dcosdrj,&dist_ik,dijdik_inv); // j
448 v3_scale(&tmp,&dist_ij,-cos_theta/d_ij2);
449 v3_add(&dcosdrj,&dcosdrj,&tmp);
450 v3_scale(&dcosdrk,&dist_ij,dijdik_inv); // k
451 v3_scale(&tmp,&dist_ik,-cos_theta/d_ik2);
452 v3_add(&dcosdrk,&dcosdrk,&tmp);
454 /* f_c_ik * dg, df_c_ik * g */
458 /* derivative wrt j */
459 v3_scale(&force,&dcosdrj,fcdg*pre_dzeta);
461 /* force contribution */
462 v3_add(&(aj->f),&(aj->f),&force);
465 if(moldyn->time>DSTART&&moldyn->time<DEND) {
466 if(aj==&(moldyn->atom[DATOM])) {
467 printf("force 3bp (k2): [%d %d %d]\n",ai->tag,aj->tag,ak->tag);
468 printf(" adding %f %f %f\n",force.x,force.y,force.z);
469 printf(" total j: %f %f %f\n",aj->f.x,aj->f.y,aj->f.z);
470 printf(" angle: %f\n",acos(cos_theta)*360.0/(2*M_PI));
471 printf(" d ij ik = %f %f\n",d_ij,d_ik);
476 /* force contribution to atom i */
477 v3_scale(&force,&force,-1.0);
478 v3_add(&(ai->f),&(ai->f),&force);
481 virial_calc(ai,&force,&dist_ij);
483 /* derivative wrt k */
484 v3_scale(&force,&dist_ik,-1.0*dfcg); // dri rik = - drk rik
485 v3_scale(&tmp,&dcosdrk,fcdg);
486 v3_add(&force,&force,&tmp);
487 v3_scale(&force,&force,pre_dzeta);
489 /* force contribution */
490 v3_add(&(ak->f),&(ak->f),&force);
493 if(moldyn->time>DSTART&&moldyn->time<DEND) {
494 if(ak==&(moldyn->atom[DATOM])) {
495 printf("force 3bp (k2): [%d %d %d]\n",ai->tag,aj->tag,ak->tag);
496 printf(" adding %f %f %f\n",force.x,force.y,force.z);
497 printf(" total k: %f %f %f\n",ak->f.x,ak->f.y,ak->f.z);
498 printf(" angle: %f\n",acos(cos_theta)*360.0/(2*M_PI));
499 printf(" d ij ik = %f %f\n",d_ij,d_ik);
504 /* force contribution to atom i */
505 v3_scale(&force,&force,-1.0);
506 v3_add(&(ai->f),&(ai->f),&force);
509 virial_calc(ai,&force,&dist_ik);
511 /* increase k counter */
518 int albe_mult_check_2b_bond(t_moldyn *moldyn,t_atom *itom,t_atom *jtom,u8 bc) {
520 t_albe_mult_params *params;
525 v3_sub(&dist,&(jtom->r),&(itom->r));
526 if(bc) check_per_bound(moldyn,&dist);
527 d=v3_absolute_square(&dist);
529 params=moldyn->pot_params;
532 if(brand==jtom->brand) {
533 if(d<=params->S2[brand])
537 if(d<=params->S2mixed)