- /* zeta_ji/dzeta_ji contribution only for d_jk < S_jk */
- if(d_jk2<S2) {
-
- /* now we need d_ik */
- d_jk=sqrt(d_jk2);
-
- /* constants_j from exchange data */
- n=*(exchange->n_j);
- c=*(exchange->c_j);
- d=*(exchange->d_j);
- h=*(exchange->h_j);
- c2=exchange->cj2;
- d2=exchange->dj2;
- c2d2=exchange->cj2dj2;
-
- /* cosine of theta_jik by scalaproduct */
- rr=-v3_scalar_product(&dist_ij,&dist_jk); /* -1, as ij -> ji */
- dd=d_ij*d_jk;
- cos_theta=rr/dd;
-
- /* d_costheta */
- d_costheta1=1.0/dd;
- d_costheta2=cos_theta/d_ij2;
-
- /* some usefull values */
- h_cos=(h-cos_theta);
- d2_h_cos2=d2+(h_cos*h_cos);
- frac=c2/(d2_h_cos2);
-
- /* g(cos_theta) */
- g=1.0+c2d2-frac;
-
- /* d_costheta_jik and dg(cos_theta) - needed in any case! */
- v3_scale(&temp1,&dist_jk,d_costheta1);
- v3_scale(&temp2,&dist_ij,-d_costheta2); /* ji -> ij => -1 */
- //v3_add(&temp1,&temp1,&temp2);
- v3_sub(&temp1,&temp1,&temp2); /* there is a minus! */
- v3_scale(&temp1,&temp1,-2.0*frac*h_cos/d2_h_cos2); /* dg */
-
- /* store dg in temp2 and use it for dVjk later */
- v3_copy(&temp2,&temp1);
-
- /* f_c_jk + {d,}zeta contribution (df_c_jk = 0) */
- dzeta=&(exchange->dzeta_ji);
- if(d_jk<R) {
- /* f_c_jk */
- f_c_jk=1.0;
-
- /* zeta_ji */
- exchange->zeta_ji+=g;
-
- /* dzeta_ji */
- v3_add(dzeta,dzeta,&temp1);
- }
- else {
- /* f_c_jk */
- s_r=S-R;
- arg=M_PI*(d_jk-R)/s_r;
- f_c_jk=0.5+0.5*cos(arg);
-
- /* zeta_ji */
- exchange->zeta_ji+=f_c_jk*g;
-
- /* dzeta_ji */
- v3_scale(&temp1,&temp1,f_c_jk);
- v3_add(dzeta,dzeta,&temp1);
- }
-
- /* dV_jk stuff | add force contribution on atom i immediately */
- if(exchange->d_ij_between_rs) {
- zeta=f_c*g;
- v3_scale(&temp1,&temp2,f_c);
- v3_scale(&temp2,&dist_ij,df_c*g);
- v3_add(&temp2,&temp2,&temp1); /* -> dzeta_jk in temp2 */
- }
- else {
- zeta=g;
- // dzeta_jk is simply dg, which is stored in temp2
- }
- /* betajnj * zeta_jk ^ nj-1 */
- tmp=exchange->betajnj*pow(zeta,(n-1.0));
- tmp=-chi/2.0*pow((1+tmp*zeta),(-1.0/(2.0*n)-1))*tmp;
- v3_scale(&temp2,&temp2,tmp*B*exp(-mu*d_jk)*f_c_jk*0.5);
- v3_add(&(ai->f),&(ai->f),&temp2); /* -1 skipped in f_a calc ^ */
- /* scaled with 0.5 ^ */
-
- /* virial */
- ai->virial.xx-=temp2.x*dist_jk.x;
- ai->virial.yy-=temp2.y*dist_jk.y;
- ai->virial.zz-=temp2.z*dist_jk.z;
- ai->virial.xy-=temp2.x*dist_jk.y;
- ai->virial.xz-=temp2.x*dist_jk.z;
- ai->virial.yz-=temp2.y*dist_jk.z;