small mods to support site energies and kinetic energies per atom
[physik/posic.git] / potentials / tersoff.c
index b6533e1..953b839 100644 (file)
@@ -93,6 +93,10 @@ int tersoff_mult_2bp(t_moldyn *moldyn,t_atom *ai,t_atom *aj,u8 bc) {
        int brand;
        double s_r;
        double arg;
+       double energy;
+
+       printf("WARNING! - tersoff_mult_2bp is obsolete.\n");
+       printf("WARNING! - repulsive part handled in 3bp/j2 routine.\n");
 
        /* use newtons third law */
        if(ai<aj) return 0;
@@ -167,17 +171,13 @@ int tersoff_mult_2bp(t_moldyn *moldyn,t_atom *ai,t_atom *aj,u8 bc) {
 #endif
 
        /* virial */
-       //virial_calc(ai,&force,&dist_ij);
-       //virial_calc(aj,&force,&dist_ij);
-       //ai->virial.xx-=force.x*dist_ij.x;
-       //ai->virial.yy-=force.y*dist_ij.y;
-       //ai->virial.zz-=force.z*dist_ij.z;
-       //ai->virial.xy-=force.x*dist_ij.y;
-       //ai->virial.xz-=force.x*dist_ij.z;
-       //ai->virial.yz-=force.y*dist_ij.z;
+       virial_calc(ai,&force,&dist_ij);
 
        /* energy 2bp contribution */
-       moldyn->energy+=f_r*f_c;
+       energy=f_r*f_c;
+       moldyn->energy+=energy;
+       ai->e+=0.5*energy;
+       aj->e+=0.5*energy;
 
        return 0;
 }
@@ -316,6 +316,14 @@ int tersoff_mult_3bp_k1(t_moldyn *moldyn,
                exchange->zeta_ij+=f_c_ik*g;
        }
 
+#ifdef DEBUG
+       if((ai==&(moldyn->atom[0]))|
+          (aj==&(moldyn->atom[864]))|
+          (ak==&(moldyn->atom[1003]))) {
+               printf(" -> %f %f %f\n",exchange->ci2di2,frac,h_cos);
+       }
+#endif
+
        /* store even more data for second k loop */
        exchange->g[kcount]=g;
        exchange->dg[kcount]=dg;
@@ -336,11 +344,15 @@ int tersoff_mult_3bp_j2(t_moldyn *moldyn,t_atom *ai,t_atom *aj,u8 bc) {
        t_tersoff_exchange *exchange;
        t_3dvec force;
        double f_a,df_a,b,db,f_c,df_c;
+       double f_r,df_r;
+       double scale;
        double mu,B,chi;
+       double lambda,A;
        double d_ij;
        unsigned char brand;
        double ni,tmp;
        double S,R,s_r,arg;
+       double energy;
 
        params=moldyn->pot_params;
        exchange=&(params->exchange);
@@ -350,14 +362,18 @@ int tersoff_mult_3bp_j2(t_moldyn *moldyn,t_atom *ai,t_atom *aj,u8 bc) {
                S=params->S[brand];
                R=params->R[brand];
                B=params->B[brand];
+               A=params->A[brand];
                mu=params->mu[brand];
+               lambda=params->lambda[brand];
                chi=1.0;
        }
        else {
                S=params->Smixed;
                R=params->Rmixed;
                B=params->Bmixed;
+               A=params->Amixed;
                mu=params->mu_m;
+               lambda=params->lambda_m;
                chi=params->chi;
        }
 
@@ -379,6 +395,10 @@ int tersoff_mult_3bp_j2(t_moldyn *moldyn,t_atom *ai,t_atom *aj,u8 bc) {
        f_a=-B*exp(-mu*d_ij);
        df_a=mu*f_a/d_ij;
 
+       /* f_r, df_r */
+       f_r=A*exp(-lambda*d_ij);
+       df_r=lambda*f_r/d_ij;
+
        /* b, db */
        if(exchange->zeta_ij==0.0) {
                b=chi;
@@ -394,8 +414,8 @@ int tersoff_mult_3bp_j2(t_moldyn *moldyn,t_atom *ai,t_atom *aj,u8 bc) {
        }
 
        /* force contribution */
-       v3_scale(&force,&(exchange->dist_ij),df_a*f_c+f_a*df_c);
-       v3_scale(&force,&force,-0.5*b);
+       scale=-0.5*(f_c*(df_r+b*df_a)+df_c*(f_r+b*df_a));
+       v3_scale(&force,&(exchange->dist_ij),scale);
        v3_add(&(ai->f),&(ai->f),&force);
        v3_sub(&(aj->f),&(aj->f),&force); // dri rij = - drj rij
 
@@ -407,18 +427,23 @@ int tersoff_mult_3bp_j2(t_moldyn *moldyn,t_atom *ai,t_atom *aj,u8 bc) {
                        printf("total i: %f %f %f\n",ai->f.x,ai->f.y,ai->f.z);
                if(aj==&(moldyn->atom[0]))
                        printf("total j: %f %f %f\n",aj->f.x,aj->f.y,aj->f.z);
+               printf("energy: %f = %f %f %f %f\n",0.5*f_c*(b*f_a+f_r),
+                                                   f_c,b,f_a,f_r);
+               printf("        %f %f %f\n",exchange->zeta_ij,.0,.0);
        }
 #endif
 
        /* virial */
-       //virial_calc(ai,&force,&(exchange->dist_ij));
-       //virial_calc(aj,&force,&(exchange->dist_ij));
+       if(aj<ai)
+               virial_calc(ai,&force,&(exchange->dist_ij));
 
        /* dzeta prefactor = - 0.5 f_c f_a db */
        exchange->pre_dzeta=-0.5*f_a*f_c*db;
 
        /* energy contribution */
-       moldyn->energy+=0.5*f_c*b*f_a;
+       energy=0.5*f_c*(b*f_a+f_r);
+       moldyn->energy+=energy;
+       ai->e+=energy;
 
        /* reset k counter for second k loop */
        exchange->kcount=0;
@@ -537,10 +562,12 @@ int tersoff_mult_3bp_k2(t_moldyn *moldyn,
 #endif
 
        /* virial */
-       //virial_calc(aj,&force,&dist_ij);
+       //v3_scale(&force,&force,-1.0);
+       if(aj<ai)
+               virial_calc(ai,&force,&dist_ij);
 
        /* derivative wrt k */
-       v3_scale(&force,&dist_ik,-1.0*dfcg); // dri rij = - drj rij
+       v3_scale(&force,&dist_ik,-1.0*dfcg); // dri rik = - drk rik
        v3_scale(&tmp,&dcosdrk,fcdg);
        v3_add(&force,&force,&tmp);
        v3_scale(&force,&force,pre_dzeta);
@@ -557,7 +584,9 @@ int tersoff_mult_3bp_k2(t_moldyn *moldyn,
 #endif
 
        /* virial */
-       virial_calc(ak,&force,&dist_ik);
+       //v3_scale(&force,&force,-1.0);
+       if(aj<ai)
+               virial_calc(ai,&force,&dist_ik);
        
        /* increase k counter */
        exchange->kcount++;