+ /* zeta_ij/dzeta_ij contribution only for d_ik < S */
+ if(d_ik<S) {
+
+ /* get constants_i from exchange data */
+ n=*(exchange->n_i);
+ c=*(exchange->c_i);
+ d=*(exchange->d_i);
+ h=*(exchange->h_i);
+ c2=exchange->ci2;
+ d2=exchange->di2;
+ c2d2=exchange->ci2di2;
+
+ /* cosine of theta_ijk by scalaproduct */
+ rr=v3_scalar_product(&dist_ij,&dist_ik);
+ dd=d_ij*d_ik;
+ cos_theta=rr/dd;
+
+ /* d_costheta */
+ tmp=1.0/dd;
+ d_costheta1=cos_theta/(d_ij*d_ij)-tmp;
+ d_costheta2=cos_theta/(d_ik*d_ik)-tmp;
+
+ /* 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_ij and dg(cos_theta) - needed in any case! */
+ v3_scale(&temp1,&dist_ij,d_costheta1);
+ v3_scale(&temp2,&dist_ik,d_costheta2);
+ v3_add(&temp1,&temp1,&temp2);
+ v3_scale(&temp1,&temp1,-2.0*frac*h_cos/d2_h_cos2); /* dg */
+
+ /* f_c_ik & df_c_ik + {d,}zeta contribution */
+ dzeta=&(exchange->dzeta_ij);
+ if(d_ik<R) {
+ /* {d,}f_c_ik */
+ // => f_c_ik=1.0;
+ // => df_c_ik=0.0; of course we do not set this!
+
+ /* zeta_ij */
+ exchange->zeta_ij+=g;
+
+ /* dzeta_ij */
+ v3_add(dzeta,dzeta,&temp1);
+ }
+ else {
+ /* {d,}f_c_ik */
+ s_r=S-R;
+ arg=M_PI*(d_ik-R)/s_r;
+ f_c_ik=0.5+0.5*cos(arg);
+ //df_c_ik=-0.5*sin(arg)*(M_PI/(s_r*d_ik)); /* MARK */
+ df_c_ik=0.5*sin(arg)*(M_PI/(s_r*d_ik));
+
+ /* zeta_ij */
+ exchange->zeta_ij+=f_c_ik*g;
+
+ /* dzeta_ij */
+ v3_scale(&temp1,&temp1,f_c_ik);
+ v3_scale(&temp2,&dist_ik,g*df_c_ik);
+ v3_add(&temp1,&temp1,&temp2);
+ v3_add(dzeta,dzeta,&temp1);
+ }