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_complete_params(t_albe_mult_params *p) {
25 printf("[moldyn] albe parameter completion\n");
26 p->S2[0]=p->S[0]*p->S[0];
27 p->S2[1]=p->S[1]*p->S[1];
28 p->S2mixed=p->Smixed*p->Smixed;
30 printf("[moldyn] albe mult parameter info:\n");
31 printf(" S (A) | %f | %f | %f\n",p->S[0],p->S[1],p->Smixed);
32 printf(" R (A) | %f | %f | %f\n",p->R[0],p->R[1],p->Rmixed);
33 printf(" A (eV) | %f | %f | %f\n",p->A[0]/EV,p->A[1]/EV,p->Amixed/EV);
34 printf(" B (eV) | %f | %f | %f\n",p->B[0]/EV,p->B[1]/EV,p->Bmixed/EV);
35 printf(" lambda | %f | %f | %f\n",p->lambda[0],p->lambda[1],
37 printf(" mu | %f | %f | %f\n",p->mu[0],p->mu[1],p->mu_m);
38 printf(" gamma | %f | %f\n",p->gamma[0],p->gamma[1]);
39 printf(" c | %f | %f\n",p->c[0],p->c[1]);
40 printf(" d | %f | %f\n",p->d[0],p->d[1]);
41 printf(" h | %f | %f\n",p->h[0],p->h[1]);
46 /* albe 3 body potential function (first ij loop) */
47 int albe_mult_3bp_j1(t_moldyn *moldyn,t_atom *ai,t_atom *aj,u8 bc) {
49 t_albe_mult_params *params;
50 t_albe_exchange *exchange;
56 params=moldyn->pot_params;
57 exchange=&(params->exchange);
60 exchange->zeta_ij=0.0;
63 * set ij depending values
67 if(brand==aj->brand) {
75 v3_sub(&dist_ij,&(aj->r),&(ai->r));
76 if(bc) check_per_bound(moldyn,&dist_ij);
77 d_ij2=v3_absolute_square(&dist_ij);
79 /* if d_ij2 > S2 => no force & potential energy contribution */
89 exchange->dist_ij=dist_ij;
90 exchange->d_ij2=d_ij2;
93 /* reset k counter for first k loop */
99 /* albe 3 body potential function (first k loop) */
100 int albe_mult_3bp_k1(t_moldyn *moldyn,
101 t_atom *ai,t_atom *aj,t_atom *ak,u8 bc) {
103 t_albe_mult_params *params;
104 t_albe_exchange *exchange;
107 t_3dvec dist_ij,dist_ik;
108 double d_ik2,d_ik,d_ij;
109 double cos_theta,h_cos,d2_h_cos2,frac,g,dg,s_r,arg;
110 double f_c_ik,df_c_ik;
113 params=moldyn->pot_params;
114 exchange=&(params->exchange);
115 kcount=exchange->kcount;
117 if(kcount>ALBE_MAXN) {
118 printf("FATAL: neighbours = %d\n",kcount);
119 printf(" -> %d %d %d\n",ai->tag,aj->tag,ak->tag);
124 if(brand==ak->brand) {
127 S2=params->S2[brand];
128 /* albe needs i,k depending c,d,h and gamma values */
129 exchange->gamma_i=&(params->gamma[brand]);
130 exchange->c_i=&(params->c[brand]);
131 exchange->d_i=&(params->d[brand]);
132 exchange->h_i=&(params->h[brand]);
138 /* albe needs i,k depending c,d,h and gamma values */
139 exchange->gamma_i=&(params->gamma_m);
140 exchange->c_i=&(params->c_mixed);
141 exchange->d_i=&(params->d_mixed);
142 exchange->h_i=&(params->h_mixed);
144 exchange->ci2=*(exchange->c_i)**(exchange->c_i);
145 exchange->di2=*(exchange->d_i)**(exchange->d_i);
146 exchange->ci2di2=exchange->ci2/exchange->di2;
149 v3_sub(&dist_ik,&(ak->r),&(ai->r));
150 if(bc) check_per_bound(moldyn,&dist_ik);
151 d_ik2=v3_absolute_square(&dist_ik);
153 /* store data for second k loop */
154 exchange->dist_ik[kcount]=dist_ik;
155 exchange->d_ik2[kcount]=d_ik2;
157 /* return if not within cutoff */
167 dist_ij=exchange->dist_ij;
171 cos_theta=v3_scalar_product(&dist_ij,&dist_ik)/(d_ij*d_ik);
174 h_cos=*(exchange->h_i)+cos_theta; // + in albe formalism
175 d2_h_cos2=exchange->di2+(h_cos*h_cos);
176 frac=exchange->ci2/d2_h_cos2;
177 g=*(exchange->gamma_i)*(1.0+exchange->ci2di2-frac);
178 dg=2.0*frac**(exchange->gamma_i)*h_cos/d2_h_cos2; // + in albe f..
180 /* zeta sum += f_c_ik * g_ijk */
182 exchange->zeta_ij+=g;
188 arg=M_PI*(d_ik-R)/s_r;
189 f_c_ik=0.5+0.5*cos(arg);
190 df_c_ik=0.5*sin(arg)*(M_PI/(s_r*d_ik));
191 exchange->zeta_ij+=f_c_ik*g;
195 if((ai==&(moldyn->atom[0]))|
196 (aj==&(moldyn->atom[864]))|
197 (ak==&(moldyn->atom[1003]))) {
198 printf(" -> %f %f %f\n",exchange->ci2di2,frac,h_cos);
202 /* store even more data for second k loop */
203 exchange->g[kcount]=g;
204 exchange->dg[kcount]=dg;
205 exchange->d_ik[kcount]=d_ik;
206 exchange->cos_theta[kcount]=cos_theta;
207 exchange->f_c_ik[kcount]=f_c_ik;
208 exchange->df_c_ik[kcount]=df_c_ik;
210 /* increase k counter */
216 int albe_mult_3bp_j2(t_moldyn *moldyn,t_atom *ai,t_atom *aj,u8 bc) {
218 t_albe_mult_params *params;
219 t_albe_exchange *exchange;
221 double f_a,df_a,b,db,f_c,df_c;
231 params=moldyn->pot_params;
232 exchange=&(params->exchange);
235 if(brand==ai->brand) {
240 r0=params->r0[brand];
241 mu=params->mu[brand];
242 lambda=params->lambda[brand];
251 lambda=params->lambda_m;
263 arg=M_PI*(d_ij-R)/s_r;
264 f_c=0.5+0.5*cos(arg);
265 df_c=0.5*sin(arg)*(M_PI/(s_r*d_ij));
269 f_a=-B*exp(-mu*(d_ij-r0));
273 f_r=A*exp(-lambda*(d_ij-r0));
274 df_r=lambda*f_r/d_ij;
277 if(exchange->zeta_ij==0.0) {
282 b=1.0/sqrt(1.0+exchange->zeta_ij);
283 db=-0.5*b/(1.0+exchange->zeta_ij);
286 /* force contribution */
287 scale=-0.5*(f_c*(df_r+b*df_a)+df_c*(f_r+b*f_a));
288 v3_scale(&force,&(exchange->dist_ij),scale);
289 v3_add(&(ai->f),&(ai->f),&force);
290 v3_sub(&(aj->f),&(aj->f),&force); // dri rij = - drj rij
293 if((ai==&(moldyn->atom[0]))|(aj==&(moldyn->atom[0]))) {
294 printf("force 3bp (j2): [%d %d sum]\n",ai->tag,aj->tag);
295 printf("adding %f %f %f\n",force.x,force.y,force.z);
296 if(ai==&(moldyn->atom[0]))
297 printf("total i: %f %f %f\n",ai->f.x,ai->f.y,ai->f.z);
298 if(aj==&(moldyn->atom[0]))
299 printf("total j: %f %f %f\n",aj->f.x,aj->f.y,aj->f.z);
300 printf("energy: %f = %f %f %f %f\n",0.5*f_c*(b*f_a+f_r),
302 printf(" %f %f %f\n",exchange->zeta_ij,.0,.0);
307 virial_calc(ai,&force,&(exchange->dist_ij));
309 /* dzeta prefactor = - 0.5 f_c f_a db */
310 exchange->pre_dzeta=-0.5*f_a*f_c*db;
312 /* energy contribution */
313 energy=0.5*f_c*(f_r+b*f_a);
314 moldyn->energy+=energy;
317 /* reset k counter for second k loop */
323 /* albe 3 body potential function (second k loop) */
324 int albe_mult_3bp_k2(t_moldyn *moldyn,
325 t_atom *ai,t_atom *aj,t_atom *ak,u8 bc) {
327 t_albe_mult_params *params;
328 t_albe_exchange *exchange;
330 t_3dvec dist_ik,dist_ij;
331 double d_ik2,d_ik,d_ij2,d_ij;
334 double g,dg,cos_theta;
336 double f_c_ik,df_c_ik;
337 double dijdik_inv,fcdg,dfcg;
338 t_3dvec dcosdri,dcosdrj,dcosdrk;
341 params=moldyn->pot_params;
342 exchange=&(params->exchange);
343 kcount=exchange->kcount;
346 printf("FATAL: neighbours!\n");
349 d_ik2=exchange->d_ik2[kcount];
353 S2=params->S2[brand];
357 /* return if d_ik > S */
363 /* prefactor dzeta */
364 pre_dzeta=exchange->pre_dzeta;
367 dist_ik=exchange->dist_ik[kcount];
368 d_ik=exchange->d_ik[kcount];
370 /* f_c_ik, df_c_ik */
371 f_c_ik=exchange->f_c_ik[kcount];
372 df_c_ik=exchange->df_c_ik[kcount];
374 /* dist_ij, d_ij2, d_ij */
375 dist_ij=exchange->dist_ij;
376 d_ij2=exchange->d_ij2;
379 /* g, dg, cos_theta */
380 g=exchange->g[kcount];
381 dg=exchange->dg[kcount];
382 cos_theta=exchange->cos_theta[kcount];
384 /* cos_theta derivatives wrt i,j,k */
385 dijdik_inv=1.0/(d_ij*d_ik);
386 v3_scale(&dcosdrj,&dist_ik,dijdik_inv); // j
387 v3_scale(&tmp,&dist_ij,-cos_theta/d_ij2);
388 v3_add(&dcosdrj,&dcosdrj,&tmp);
389 v3_scale(&dcosdrk,&dist_ij,dijdik_inv); // k
390 v3_scale(&tmp,&dist_ik,-cos_theta/d_ik2);
391 v3_add(&dcosdrk,&dcosdrk,&tmp);
392 v3_add(&dcosdri,&dcosdrj,&dcosdrk); // i
393 v3_scale(&dcosdri,&dcosdri,-1.0);
395 /* f_c_ik * dg, df_c_ik * g */
399 /* derivative wrt i */
400 v3_scale(&force,&dist_ik,dfcg);
401 v3_scale(&tmp,&dcosdri,fcdg);
402 v3_add(&force,&force,&tmp);
403 v3_scale(&force,&force,pre_dzeta);
405 /* force contribution */
406 v3_add(&(ai->f),&(ai->f),&force);
409 if(ai==&(moldyn->atom[0])) {
410 printf("force 3bp (k2): [%d %d %d]\n",ai->tag,aj->tag,ak->tag);
411 printf("adding %f %f %f\n",force.x,force.y,force.z);
412 printf("total i: %f %f %f\n",ai->f.x,ai->f.y,ai->f.z);
417 //virial_calc(ai,&force,&dist_ij);
419 /* derivative wrt j */
420 v3_scale(&force,&dcosdrj,fcdg*pre_dzeta);
422 /* force contribution */
423 v3_add(&(aj->f),&(aj->f),&force);
426 if(aj==&(moldyn->atom[0])) {
427 printf("force 3bp (k2): [%d %d %d]\n",ai->tag,aj->tag,ak->tag);
428 printf("adding %f %f %f\n",force.x,force.y,force.z);
429 printf("total j: %f %f %f\n",aj->f.x,aj->f.y,aj->f.z);
434 v3_scale(&force,&force,-1.0);
435 virial_calc(ai,&force,&dist_ij);
437 /* derivative wrt k */
438 v3_scale(&force,&dist_ik,-1.0*dfcg); // dri rik = - drk rik
439 v3_scale(&tmp,&dcosdrk,fcdg);
440 v3_add(&force,&force,&tmp);
441 v3_scale(&force,&force,pre_dzeta);
443 /* force contribution */
444 v3_add(&(ak->f),&(ak->f),&force);
447 if(ak==&(moldyn->atom[0])) {
448 printf("force 3bp (k2): [%d %d %d]\n",ai->tag,aj->tag,ak->tag);
449 printf("adding %f %f %f\n",force.x,force.y,force.z);
450 printf("total k: %f %f %f\n",ak->f.x,ak->f.y,ak->f.z);
455 v3_scale(&force,&force,-1.0);
456 virial_calc(ai,&force,&dist_ik);
458 /* increase k counter */