]> hackdaworld.org Git - physik/posic.git/commitdiff
small mods to support site energies and kinetic energies per atom
authorhackbard <hackbard@sage.physik.uni-augsburg.de>
Thu, 19 Jul 2007 16:04:08 +0000 (18:04 +0200)
committerhackbard <hackbard@sage.physik.uni-augsburg.de>
Thu, 19 Jul 2007 16:04:08 +0000 (18:04 +0200)
moldyn.c
moldyn.h
potentials/albe.c
potentials/harmonic_oscillator.c
potentials/lennard_jones.c
potentials/tersoff.c
sic.c

index 433be6824c9663f9bfa745ca0b82d08b566abd2b..7d2796507452a5f49dc3082f152677d5ca533d05 100644 (file)
--- a/moldyn.c
+++ b/moldyn.c
@@ -510,6 +510,7 @@ int create_lattice(t_moldyn *moldyn,u8 type,double lc,int element,double mass,
                atom[ret].brand=brand;
                atom[ret].tag=count+ret;
                check_per_bound(moldyn,&(atom[ret].r));
+               atom[ret].r_0=atom[ret].r;
        }
 
        /* update total system mass */
@@ -518,6 +519,40 @@ int create_lattice(t_moldyn *moldyn,u8 type,double lc,int element,double mass,
        return ret;
 }
 
+int add_atom(t_moldyn *moldyn,int element,double mass,u8 brand,u8 attr,
+             t_3dvec *r,t_3dvec *v) {
+
+       t_atom *atom;
+       void *ptr;
+       int count;
+       
+       atom=moldyn->atom;
+       count=(moldyn->count)++;
+
+       ptr=realloc(atom,(count+1)*sizeof(t_atom));
+       if(!ptr) {
+               perror("[moldyn] realloc (add atom)");
+               return -1;
+       }
+       moldyn->atom=ptr;
+
+       atom=moldyn->atom;
+       atom[count].r=*r;
+       atom[count].v=*v;
+       atom[count].element=element;
+       atom[count].mass=mass;
+       atom[count].brand=brand;
+       atom[count].tag=count;
+       atom[count].attr=attr;
+       check_per_bound(moldyn,&(atom[count].r));
+       atom[count].r_0=atom[count].r;
+
+       /* update total system mass */
+       total_mass_calc(moldyn);
+
+       return 0;
+}
+
 /* cubic init */
 int cubic_init(int a,int b,int c,double lc,t_atom *atom,t_3dvec *origin) {
 
@@ -630,38 +665,6 @@ int diamond_init(int a,int b,int c,double lc,t_atom *atom,t_3dvec *origin) {
        return count;
 }
 
-int add_atom(t_moldyn *moldyn,int element,double mass,u8 brand,u8 attr,
-             t_3dvec *r,t_3dvec *v) {
-
-       t_atom *atom;
-       void *ptr;
-       int count;
-       
-       atom=moldyn->atom;
-       count=(moldyn->count)++;
-
-       ptr=realloc(atom,(count+1)*sizeof(t_atom));
-       if(!ptr) {
-               perror("[moldyn] realloc (add atom)");
-               return -1;
-       }
-       moldyn->atom=ptr;
-
-       atom=moldyn->atom;
-       atom[count].r=*r;
-       atom[count].v=*v;
-       atom[count].element=element;
-       atom[count].mass=mass;
-       atom[count].brand=brand;
-       atom[count].tag=count;
-       atom[count].attr=attr;
-
-       /* update total system mass */
-       total_mass_calc(moldyn);
-
-       return 0;
-}
-
 int destroy_atoms(t_moldyn *moldyn) {
 
        if(moldyn->atom) free(moldyn->atom);
@@ -1097,8 +1100,10 @@ double e_kin_calc(t_moldyn *moldyn) {
        atom=moldyn->atom;
        moldyn->ekin=0.0;
 
-       for(i=0;i<moldyn->count;i++)
-               moldyn->ekin+=0.5*atom[i].mass*v3_absolute_square(&(atom[i].v));
+       for(i=0;i<moldyn->count;i++) {
+               atom[i].ekin=0.5*atom[i].mass*v3_absolute_square(&(atom[i].v));
+               moldyn->ekin+=atom[i].ekin;
+       }
 
        return moldyn->ekin;
 }
index 51ad482180fa44ff290109c0118dcb09b0185c09..a595585981d95ffac6742251bc9021c0ecb23849 100644 (file)
--- a/moldyn.h
+++ b/moldyn.h
@@ -33,11 +33,13 @@ typedef struct s_virial {
 
 /* the atom of the md simulation */
 typedef struct s_atom {
+       t_3dvec r_0;            /* initial position */
        t_3dvec r;              /* position */
        t_3dvec v;              /* velocity */
        t_3dvec f;              /* force */
        t_virial virial;        /* virial */
        double e;               /* site energy */
+       double ekin;            /* kinetic energy */
        int element;            /* number of element in pse */
        double mass;            /* atom mass */
        u8 brand;               /* brand id */
@@ -410,11 +412,11 @@ int moldyn_log_shutdown(t_moldyn *moldyn);
 
 int create_lattice(t_moldyn *moldyn,u8 type,double lc,int element,double mass,
                    u8 attr,u8 brand,int a,int b,int c,t_3dvec *origin);
+int add_atom(t_moldyn *moldyn,int element,double mass,u8 brand,u8 attr,
+             t_3dvec *r,t_3dvec *v);
 int cubic_init(int a,int b,int c,double lc,t_atom *atom,t_3dvec *origin);
 int fcc_init(int a,int b,int c,double lc,t_atom *atom,t_3dvec *origin);
 int diamond_init(int a,int b,int c,double lc,t_atom *atom,t_3dvec *origin);
-int add_atom(t_moldyn *moldyn,int element,double mass,u8 brand,u8 attr,
-             t_3dvec *r,t_3dvec *v);
 int destroy_atoms(t_moldyn *moldyn);
 
 int thermal_init(t_moldyn *moldyn,u8 equi_init);
index c0a5fe4aba2b7c42280d9bc68f6b87c52677a380..28008b0541b1d20a68351a46669d77f314b00bf6 100644 (file)
@@ -226,6 +226,7 @@ int albe_mult_3bp_j2(t_moldyn *moldyn,t_atom *ai,t_atom *aj,u8 bc) {
        double d_ij,r0;
        unsigned char brand;
        double S,R,s_r,arg;
+       double energy;
 
        params=moldyn->pot_params;
        exchange=&(params->exchange);
@@ -309,7 +310,9 @@ int albe_mult_3bp_j2(t_moldyn *moldyn,t_atom *ai,t_atom *aj,u8 bc) {
        exchange->pre_dzeta=-0.5*f_a*f_c*db;
 
        /* energy contribution */
-       moldyn->energy+=0.5*f_c*(f_r+b*f_a);
+       energy=0.5*f_c*(f_r+b*f_a);
+       moldyn->energy+=energy;
+       ai->e+=energy;
 
        /* reset k counter for second k loop */
        exchange->kcount=0;
index e2a80e4f3401e3d7562fa5152b99e7537a515336..b203453598ae34a149a85dc1b79827d4f8402b01 100644 (file)
@@ -25,6 +25,7 @@ int harmonic_oscillator(t_moldyn *moldyn,t_atom *ai,t_atom *aj,u8 bc) {
        t_3dvec force,distance;
        double d,f;
        double sc,equi_dist;
+       double energy;
 
        params=moldyn->pot_params;
        sc=params->spring_constant;
@@ -37,7 +38,10 @@ int harmonic_oscillator(t_moldyn *moldyn,t_atom *ai,t_atom *aj,u8 bc) {
        if(bc) check_per_bound(moldyn,&distance);
        d=v3_norm(&distance);
        if(d<=moldyn->cutoff) {
-               moldyn->energy+=(0.5*sc*(d-equi_dist)*(d-equi_dist));
+               energy=(0.5*sc*(d-equi_dist)*(d-equi_dist));
+               moldyn->energy+=energy;
+               ai->e+=0.5*energy;
+               aj->e+=0.5*energy;
                /* f = -grad E; grad r_ij = -1 1/r_ij distance */
                f=sc*(1.0-equi_dist/d);
                v3_scale(&force,&distance,f);
index 1277c466c919d98f3137c63dbab487bd2e70bc1e..4ff1b4371eb95dc496a66257c993f88786f25724 100644 (file)
@@ -25,6 +25,7 @@ int lennard_jones(t_moldyn *moldyn,t_atom *ai,t_atom *aj,u8 bc) {
        t_3dvec force,distance;
        double d,h1,h2;
        double eps,sig6,sig12;
+       double energy;
 
        params=moldyn->pot_params;
        eps=params->epsilon4;
@@ -41,7 +42,10 @@ int lennard_jones(t_moldyn *moldyn,t_atom *ai,t_atom *aj,u8 bc) {
                h2=d*d;                         /* 1/r^4 */
                h2*=d;                          /* 1/r^6 */
                h1=h2*h2;                       /* 1/r^12 */
-               moldyn->energy+=(eps*(sig12*h1-sig6*h2)-params->uc);
+               energy=(eps*(sig12*h1-sig6*h2)-params->uc);
+               moldyn->energy+=energy;         /* total energy */
+               ai->e+=0.5*energy;              /* site energy */
+               aj->e+=0.5*energy;
                h2*=d;                          /* 1/r^8 */
                h1*=d;                          /* 1/r^14 */
                h2*=6*sig6;
index 6bfcf30e0239ce2d0fa964607ff2ef9098ce403d..953b839bf893a95c2c6469c98fb8be3fa6c43913 100644 (file)
@@ -93,6 +93,7 @@ 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");
@@ -173,7 +174,10 @@ int tersoff_mult_2bp(t_moldyn *moldyn,t_atom *ai,t_atom *aj,u8 bc) {
        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;
 }
@@ -348,6 +352,7 @@ int tersoff_mult_3bp_j2(t_moldyn *moldyn,t_atom *ai,t_atom *aj,u8 bc) {
        unsigned char brand;
        double ni,tmp;
        double S,R,s_r,arg;
+       double energy;
 
        params=moldyn->pot_params;
        exchange=&(params->exchange);
@@ -436,7 +441,9 @@ int tersoff_mult_3bp_j2(t_moldyn *moldyn,t_atom *ai,t_atom *aj,u8 bc) {
        exchange->pre_dzeta=-0.5*f_a*f_c*db;
 
        /* energy contribution */
-       moldyn->energy+=0.5*f_c*(b*f_a+f_r);
+       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;
diff --git a/sic.c b/sic.c
index 6dc00274419ea5eb5e333bcae3e780e2e0651f4f..5f2a8db98637c8388e15a7682b45570651168943 100644 (file)
--- a/sic.c
+++ b/sic.c
 #include "potentials/tersoff.h"
 #endif
 
-#define INJECT         1600
+#define INJECT         1
 #define NR_ATOMS       1
 #define R_C            2.0
 #define T_C            10.0
-#define LCNT           20
+#define LCNT           2
 
 typedef struct s_hp {
        int a_count;    /* atom count */