]> hackdaworld.org Git - physik/posic.git/commitdiff
adapted all potential to new scheme + necessary mods to main code
authorhackbard <hackbard@sage.physik.uni-augsburg.de>
Wed, 16 Apr 2008 11:15:39 +0000 (13:15 +0200)
committerhackbard <hackbard@sage.physik.uni-augsburg.de>
Wed, 16 Apr 2008 11:15:39 +0000 (13:15 +0200)
moldyn.c
moldyn.h
potentials/albe.c
potentials/harmonic_oscillator.c
potentials/harmonic_oscillator.h
potentials/lennard_jones.c
potentials/lennard_jones.h
potentials/tersoff.c
sic.c

index def5079dbbd949fa55e4f65b9aa4a77e165077db..a1bfcaea95c82580dc636f5655649a61d0e8cf8f 100644 (file)
--- a/moldyn.c
+++ b/moldyn.c
@@ -257,6 +257,14 @@ int set_potential(t_moldyn *moldyn,u8 type) {
                        moldyn->func3b_k2=albe_mult_3bp_k2;
                        moldyn->check_2b_bond=albe_mult_check_2b_bond;
                        break;
+               case MOLDYN_POTENTIAL_HO:
+                       moldyn->func2b=harmonic_oscillator;
+                       moldyn->check_2b_bond=harmonic_oscillator_check_2b_bond;
+                       break;
+               case MOLDYN_POTENTIAL_LJ:
+                       moldyn->func2b=lennard_jones;
+                       moldyn->check_2b_bond=lennard_jones_check_2b_bond;
+                       break;
                default:
                        printf("[moldyn] set potential: unknown type %02x\n",
                               type);
index de6157c10decf7e8bedb6937488511b41394276b..18c09c177a1714667e753f970c2a9d2c5d915c3f 100644 (file)
--- a/moldyn.h
+++ b/moldyn.h
@@ -52,9 +52,9 @@ typedef struct s_atom {
 #define ATOM_ATTR_VA   0x04    /* visualize this atom */
 #define ATOM_ATTR_VB   0x08    /* visualize the bond of this atom */
 
-#define ATOM_ATTR_1BP          0x10    /* single paricle potential */
-#define ATOM_ATTR_2BP          0x20    /* pair potential */
-#define ATOM_ATTR_3BP          0x40    /* 3 body potential */ 
+#define ATOM_ATTR_1BP  0x10    /* single paricle potential */
+#define ATOM_ATTR_2BP  0x20    /* pair potential */
+#define ATOM_ATTR_3BP  0x40    /* 3 body potential */ 
 
 /* cell lists */
 typedef struct s_linkcell {
@@ -314,12 +314,15 @@ typedef struct s_ba {
 #define SCALE_DIRECT                   'D'
 
 /*
- * potential related phsical values / constants
- *
+ * usefull constants
  */
 
 #define ONE_THIRD              (1.0/3.0)
 
+/*
+ * element specific defines
+ */
+
 #define C                      0x06
 #define LC_C                   3.567                           /* A */
 #define M_C                    12.011                          /* amu */
@@ -330,11 +333,6 @@ typedef struct s_ba {
 
 #define LC_3C_SIC              4.3596                          /* A */
 
-#define LJ_SIGMA_SI            ((0.25*sqrt(3.0)*LC_SI)/1.122462)       /* A */
-//#define LJ_SIGMA_SI          (LC_SI/1.122462)                        /* A */
-//#define LJ_SIGMA_SI          (0.5*sqrt(2.0)*LC_SI/1.122462)          /* A */
-#define LJ_EPSILON_SI          (2.1678*EV)                             /* NA */
-
 /*
  * lattice types
  */
index ddfb3c6c707de47598d4f428f51167158cb7ff1f..c01ab15106d51834980fed6f9c0836c9336efcb1 100644 (file)
@@ -24,6 +24,12 @@ int albe_mult_set_params(t_moldyn *moldyn,int element1,int element2) {
 
        t_albe_mult_params *p;
 
+       // set cutoff before parameters (actually only necessary for some pots)
+       if(moldyn->cutoff==0.0) {
+               printf("[albe] WARNING: no cutoff!\n");
+               return -1;
+       }
+
        /* alloc mem for potential parameters */
        moldyn->pot_params=malloc(sizeof(t_albe_mult_params));
        if(moldyn->pot_params==NULL) {
index b203453598ae34a149a85dc1b79827d4f8402b01..611f518b3eeba9eeed5d9323685652b435ae10e2 100644 (file)
 #include "../math/math.h"
 #include "harmonic_oscillator.h"
 
+int harmonic_oscillator_set_params(t_moldyn *moldyn,int element) {
+
+       t_ho_params *p;
+
+       // set cutoff before parameters (actually only necessary for some pots)
+       if(moldyn->cutoff==0.0) {
+               printf("[harmonic oscillator] WARNING: no cutoff!\n");
+               return -1;
+       }
+
+       /* alloc mem for potential parameters */
+       moldyn->pot_params=malloc(sizeof(t_ho_params));
+       if(moldyn->pot_params==NULL) {
+               perror("[harmonic oscillator] pot params alloc");
+               return -1;
+       }
+
+       /* these are now ho parameters */
+       p=moldyn->pot_params;
+
+       switch(element) {
+               case SI:
+                       /* type: silicon */
+                       p->spring_constant=HO_SC_SI;
+                       p->equilibrium_distance=HO_ED_SI;
+                       break;
+               case C:
+                       /* type: carbon */
+                       p->spring_constant=HO_SC_C;
+                       p->equilibrium_distance=HO_ED_C;
+                       break;
+               default:
+                       printf("[harmonic oscillator] WARNING: element\n");
+                       return -1;
+       }
+
+
+       return 0;
+}
+
 int harmonic_oscillator(t_moldyn *moldyn,t_atom *ai,t_atom *aj,u8 bc) {
 
        t_ho_params *params;
@@ -55,3 +95,19 @@ int harmonic_oscillator(t_moldyn *moldyn,t_atom *ai,t_atom *aj,u8 bc) {
        return 0;
 }
 
+int harmonic_oscillator_check_2b_bond(t_moldyn *moldyn,
+                                      t_atom *ai,t_atom *aj,u8 bc) {
+
+       t_3dvec distance;
+       double d;
+
+       v3_sub(&distance,&(aj->r),&(ai->r));
+       if(bc) check_per_bound(moldyn,&distance);
+       d=v3_norm(&distance);
+
+       if(d>moldyn->cutoff)
+               return FALSE;
+
+       return TRUE;
+}
+
index c9c9891c56e5c1e9e37d946d38dfbdef6001d042..13125d939dcd22d86892928e5be4972cf4ac958f 100644 (file)
@@ -15,6 +15,19 @@ typedef struct s_ho_params {
 } t_ho_params;
 
 /* function prototype */
+int harmonic_oscillator_set_params(t_moldyn *moldyn,int element);
 int harmonic_oscillator(t_moldyn *moldyn,t_atom *ai,t_atom *aj,u8 bc);
+int harmonic_oscillator_check_2b_bond(t_moldyn *moldyn,
+                                      t_atom *ai,t_atom *aj,u8 bc);
+
+/* harmonic oscillator potential parameter defines */
+
+// silicon
+#define HO_SC_SI               1
+#define HO_ED_SI               (0.25*sqrt(3.0)*LC_SI)
+
+// carbon
+#define HO_SC_C                        1
+#define HO_ED_C                        (0.25*sqrt(3.0)*LC_C)
 
 #endif
index 4ff1b4371eb95dc496a66257c993f88786f25724..2424b9851acf651eee69e7efa840b269c68086c4 100644 (file)
 #include "../math/math.h"
 #include "lennard_jones.h"
 
+int lennard_jones_set_params(t_moldyn *moldyn,int element) {
+
+       t_lj_params *p;
+       t_atom a,b;
+
+       // set cutoff before parameters (actually only necessary for some pots)
+       if(moldyn->cutoff==0.0) {
+               printf("[lennard jones] WARNING: no cutoff!\n");
+               return -1;
+       }
+
+       /* atoms for correction term */
+       a.r.x=0.0; a.r.y=0.0; a.r.z=0.0;
+       b.r.x=0.0; b.r.y=0.0; b.r.z=moldyn->cutoff;
+
+       /* alloc mem for potential parameters */
+       moldyn->pot_params=malloc(sizeof(t_lj_params));
+       if(moldyn->pot_params==NULL) {
+               perror("[lennard jones] pot params alloc");
+               return -1;
+       }
+
+       /* these are now lennard jones parameters */
+       p=moldyn->pot_params;
+
+       switch(element) {
+               case SI:
+                       /* type: silicon */
+                       p->sigma6=LJ_SIGMA_SI*LJ_SIGMA_SI*LJ_SIGMA_SI;
+                       p->sigma6+=p->sigma6;
+                       p->sigma12=p->sigma6*p->sigma6;
+                       p->epsilon4=4.0*LJ_EPSILON_SI;
+                       p->uc=0.0; // calc it now!
+                       lennard_jones(moldyn,&a,&b,0);
+                       p->uc=moldyn->energy;
+                       moldyn->energy=0.0;
+                       break;
+               case C:
+                       /* type: carbon */
+                       p->sigma6=LJ_SIGMA_C*LJ_SIGMA_C*LJ_SIGMA_C;
+                       p->sigma6+=p->sigma6;
+                       p->sigma12=p->sigma6*p->sigma6;
+                       p->epsilon4=4.0*LJ_EPSILON_C;
+                       p->uc=0.0; // calc it now!
+                       lennard_jones(moldyn,&a,&b,0);
+                       p->uc=moldyn->energy;
+                       moldyn->energy=0.0;
+                       break;
+               default:
+                       printf("[lennard jones] WARNING: element\n");
+                       return -1;
+       }
+
+       return 0;
+}
+
 int lennard_jones(t_moldyn *moldyn,t_atom *ai,t_atom *aj,u8 bc) {
 
        t_lj_params *params;
@@ -63,3 +119,17 @@ int lennard_jones(t_moldyn *moldyn,t_atom *ai,t_atom *aj,u8 bc) {
        return 0;
 }
 
+int lennard_jones_check_2b_bond(t_moldyn *moldyn,t_atom *ai,t_atom *aj,u8 bc) {
+
+        t_3dvec dist;
+        double d;
+
+       v3_sub(&dist,&(aj->r),&(ai->r));
+       if(bc) check_per_bound(moldyn,&dist);
+       d=v3_absolute_square(&dist);
+
+       if(d>moldyn->cutoff_square)
+               return FALSE;
+
+       return TRUE;
+}
index 617658b66770aab159204405155a58937b9d4ea6..8c1c36b8f0191ddefd455527d92421e66a755680 100644 (file)
@@ -17,6 +17,18 @@ typedef struct s_lj_params {
 } t_lj_params;
 
 /* function prototype */
+int lennard_jones_set_params(t_moldyn *moldyn,int element);
 int lennard_jones(t_moldyn *moldyn,t_atom *ai,t_atom *aj,u8 bc);
+int lennard_jones_check_2b_bond(t_moldyn *moldyn,t_atom *ai,t_atom *aj,u8 bc);
+
+/* lennard jones potential parameters */
+
+// silicon
+#define LJ_SIGMA_SI            ((0.25*sqrt(3.0)*LC_SI)/1.122462)
+#define LJ_EPSILON_SI          (2.1678*EV) // TODO
+
+// carbob
+#define LJ_SIGMA_C             ((0.25*sqrt(3.0)*LC_C)/1.122462)
+#define LJ_EPSILON_C           (2.1678*EV) // TODO
 
 #endif
index b83bfd60bd871be79ddf3a06cd48966e67cd0ccc..d322b69af72f083af2b6a891b4e92091f73bf208 100644 (file)
@@ -24,6 +24,12 @@ int tersoff_mult_set_params(t_moldyn *moldyn,int element1,int element2) {
 
        t_tersoff_mult_params *p;
 
+       // set cutoff before parameters (actually only necessary for some pots)
+       if(moldyn->cutoff==0.0) {
+               printf("[tersoff] WARNING: no cutoff!\n");
+               return -1;
+       }
+
        /* alloc mem for potential parameters */
         moldyn->pot_params=malloc(sizeof(t_tersoff_mult_params));
         if(moldyn->pot_params==NULL) {
diff --git a/sic.c b/sic.c
index 0e14bb12f23f5e28e047a41046feec014195774e..a3c4f742afc5d90a443623b38989d830a18312c6 100644 (file)
--- a/sic.c
+++ b/sic.c
@@ -262,9 +262,11 @@ int main(int argc,char **argv) {
 
        /* choose potential */
 #ifdef ALBE
-       set_potential(&md,MOLDYN_POTENTIAL_AM);
+       if(set_potential(&md,MOLDYN_POTENTIAL_AM)<0)
+               return -1;
 #else
-       set_potential(&md,MOLDYN_POTENTIAL_TM);
+       if(set_potential(&md,MOLDYN_POTENTIAL_TM)<0)
+               return -1;
 #endif
 
        /* cutoff radius & bondlen */
@@ -282,15 +284,17 @@ int main(int argc,char **argv) {
         * potential parameters
         */
 
+#ifndef ALBE
        /*
          * tersoff mult potential parameters for SiC
         */
        tersoff_mult_set_params(&md,SI,C);
-
+#else
        /*
          * albe mult potential parameters for SiC
         */
        albe_mult_set_params(&md,SI,C);
+#endif
 
        /* set (initial) dimensions of simulation volume */
 #ifdef ALBE