]> hackdaworld.org Git - physik/posic.git/commitdiff
lennard jones force
authorhackbard <hackbard>
Thu, 30 Mar 2006 19:00:00 +0000 (19:00 +0000)
committerhackbard <hackbard>
Thu, 30 Mar 2006 19:00:00 +0000 (19:00 +0000)
math/math.c
math/math.h
moldyn.c
moldyn.h
posic.c

index 9217c88aeda8398b58c42ed4e47266090e0c497b..6488248a39235d38d8e74aaa03933128a046f5ce 100644 (file)
@@ -76,7 +76,7 @@ double v3_norm(t_3dvec *a) {
        return(sqrt(v3_absolute_square(a)));
 }
 
-int v3_per_bounds(t_3dvec *a,t_3dvec *dim) {
+int v3_per_bound(t_3dvec *a,t_3dvec *dim) {
 
        double x,y,z;
 
index 5ef7163820bd4adf0e6934b107b97147456b12a3..77100f3ffe300b743a8db1d2f2a7e9761557b260 100644 (file)
@@ -27,6 +27,6 @@ int v3_copy(t_3dvec *trg,t_3dvec *src);
 int v3_cmp(t_3dvec *a,t_3dvec *b);
 double v3_absolute_square(t_3dvec *a);
 double v3_norm(t_3dvec *a);
-int v3_per_bounds(t_3dvec *a,t_3dvec *dim);
+int v3_per_bound(t_3dvec *a,t_3dvec *dim);
 
 #endif
index 82749b2f10abf978c9636e213585e21c8393741a..57ae62f75c69ffce130d8cae8af6e5ead6588965 100644 (file)
--- a/moldyn.c
+++ b/moldyn.c
@@ -226,10 +226,16 @@ int force_lennard_jones(t_moldyn *moldyn) {
        t_3dvec distance;
        t_3dvec force;
        double d,h1,h2;
+       double eps,sig6,sig12;
 
        atom=moldyn->atom;      
        count=moldyn->count;
        params=moldyn->pot_params;
+       eps=params->epsilon;
+       sig6=params->sigma6;
+       sig12=params->sigma12;
+
+       for(i=0;i<count;i++) v3_zero(&(atom[i].f));
 
        for(i=0;i<count;i++) {
                for(j=0;j<i;j++) {
@@ -242,6 +248,13 @@ int force_lennard_jones(t_moldyn *moldyn) {
                                h2=d*d;                         /* 1/r^8 */
                                h1*=d;                          /* 1/r^6 */
                                h1*=h2;                         /* 1/r^14 */
+                               h1*=sig12;
+                               h2*=sig6;
+                               d=-12.0*h1+6.0*h2;
+                               d*=eps;
+                               v3_scale(&force,&distance,d);
+                               v3_add(&(atom[j].f),&(atom[j].f),&force);
+                               v3_sub(&(atom[i].f),&(atom[i].f),&force);
                        }
                }
        }
index b43ed8eed5cffb1f0b6feaa8206a88bc45dfec5a..f515f41059e65c1be8910018a063d3bc1ecd685e 100644 (file)
--- a/moldyn.h
+++ b/moldyn.h
@@ -75,5 +75,6 @@ double get_total_energy(t_moldyn *moldyn);
 t_3dvec get_total_p(t_atom *atom,int count);
 
 double potential_lennard_jones(t_moldyn *moldyn);
+int force_lennard_jones(t_moldyn *moldyn);
 
 #endif
diff --git a/posic.c b/posic.c
index 6d901b4097298df45e88b695189e138da92c9ff6..79654cdb37403891a8ea285ced20e6cf3f75e949 100644 (file)
--- a/posic.c
+++ b/posic.c
@@ -75,6 +75,8 @@ int main(int argc,char **argv) {
        md.count=count;
        md.atom=si;
        md.potential=potential_lennard_jones;
+       md.force=force_lennard_jones;
+       md.cutoff_square=((LC_SI/4.0)*(LC_SI/4.0));
        md.pot_params=&lj;
        md.force=NULL;
        md.status=0;