incorporated visual functions to moldyn api
[physik/posic.git] / sic.c
diff --git a/sic.c b/sic.c
index bf33e16..6e6369f 100644 (file)
--- a/sic.c
+++ b/sic.c
@@ -8,7 +8,6 @@
 #include <math.h>
  
 #include "moldyn.h"
-#include "posic.h"
 
 /* potential */
 #include "potentials/harmonic_oscillator.h"
 #include "potentials/tersoff.h"
 #endif
 
+//#define INJECT               800
 #define INJECT         1
 #define NR_ATOMS       1
-#define R_C            1.0
-#define T_C            10.0
-#define LCNT           5
-#define PRERUN         200
-#define POSTRUN                500
+#define R_C            1.5
+#define T_C            5.0
+//#define INJ_LENX     (1*ALBE_LC_SIC)
+//#define INJ_LENY     (1*ALBE_LC_SIC)
+//#define INJ_LENZ     (1*ALBE_LC_SIC)
+#define INJ_LENX       (1*ALBE_LC_SI)
+#define INJ_LENY       (1*ALBE_LC_SI)
+#define INJ_LENZ       (1*ALBE_LC_SI)
+#define INJ_TYPE_SILICON
+//#define INJ_TYPE_CARBON
+#define INJ_OFFSET     (ALBE_LC_SI/8.0)
+#define RELAX_S                20
+
+#define LCNTX          9
+#define LCNTY          9
+#define LCNTZ          9
+#define PRERUN         10
+#define POSTRUN                4000
+
+#define R_TITLE                "Silicon self-interstitial"
+#define LOG_E          10
+#define LOG_T          10
+#define LOG_P          10
+#define LOG_S          100
+#define LOG_V          20
 
 typedef struct s_hp {
        int a_count;    /* atom count */
@@ -36,7 +56,21 @@ typedef struct s_hp {
        char **argv;    /* args */
 } t_hp;
 
-int hook(void *moldyn,void *hook_params) {
+int hook_del_atom(void *moldyn,void *hook_params) {
+
+       t_moldyn *md;
+       t_hp *hp;
+
+       md=moldyn;
+       hp=hook_params;
+
+       set_pt_scale(md,0,0,T_SCALE_BERENDSEN,100.0);
+       del_atom(md,2);
+
+       return 0;
+}
+
+int hook_add_atom(void *moldyn,void *hook_params) {
 
        t_moldyn *md;
        t_3dvec r,v,dist;
@@ -66,27 +100,25 @@ int hook(void *moldyn,void *hook_params) {
 
        /* more relaxing time for too high temperatures */
        if(md->t-md->t_ref>T_C) {
-               moldyn_add_schedule(md,10,1.0);
+               moldyn_add_schedule(md,RELAX_S,1.0);
                return 0;
        }
 
        /* inject carbon atoms */
-       printf("injecting another %d carbon atoms ...(-> %d / %d)\n",
+       printf("injecting another %d atoms ... (-> %d / %d)\n",
               NR_ATOMS,hp->a_count+NR_ATOMS,INJECT*NR_ATOMS);
        for(j=0;j<NR_ATOMS;j++) {
                run=1;
                while(run) {
-                       /*
-                       r.x=(rand_get_double(&(md->random))-0.5)*md->dim.x*0.37;
-                       r.y=(rand_get_double(&(md->random))-0.5)*md->dim.y*0.37;
-                       r.z=(rand_get_double(&(md->random))-0.5)*md->dim.z*0.37;
-                       r.x=(1.0*atoi(hp->argv[3])-4.5)/9.0*ALBE_LC_SI;
-                       r.y=(1.0*atoi(hp->argv[4])-4.5)/9.0*ALBE_LC_SI;
-                       r.z=(1.0*atoi(hp->argv[5])-4.5)/9.0*ALBE_LC_SI;
-                       */
-                       r.x=(rand_get_double(&(md->random))-0.5)*LC_SI;
-                       r.y=(rand_get_double(&(md->random))-0.5)*LC_SI;
-                       r.z=(rand_get_double(&(md->random))-0.5)*LC_SI;
+                       r.x=1.0/8.0*ALBE_LC_SI;
+                       r.y=-1.0/8.0*ALBE_LC_SI;
+                       r.z=-1.0/8.0*ALBE_LC_SI;
+                       //r.x=(rand_get_double(&(md->random))-0.5)*INJ_LENX;
+                       r.x+=INJ_OFFSET;
+                       //r.y=(rand_get_double(&(md->random))-0.5)*INJ_LENY;
+                       r.y+=INJ_OFFSET;
+                       //r.z=(rand_get_double(&(md->random))-0.5)*INJ_LENZ;
+                       r.z+=INJ_OFFSET;
                        /* assume valid coordinates */
                        run=0;
                        for(i=0;i<md->count;i++) {
@@ -101,14 +133,18 @@ int hook(void *moldyn,void *hook_params) {
                        }
                }
                v.x=0; v.y=0; v.z=0;
+#ifdef INJ_TYPE_CARBON
                add_atom(md,C,M_C,1,
+#else
+               add_atom(md,SI,M_SI,0,
+#endif
                         ATOM_ATTR_1BP|ATOM_ATTR_2BP|ATOM_ATTR_3BP|ATOM_ATTR_HB,
                         &r,&v);
        }
        hp->a_count+=NR_ATOMS;
 
        /* add schedule for simulating injected atoms ;) */
-       moldyn_add_schedule(md,10,1.0);
+       moldyn_add_schedule(md,RELAX_S,1.0);
 
        return 0;
 }
@@ -165,8 +201,10 @@ int main(int argc,char **argv) {
        /* cutoff radius */
 #ifdef ALBE
        set_cutoff(&md,ALBE_S_SI);
+       //set_cutoff(&md,ALBE_S_C);
 #else
        set_cutoff(&md,TM_S_SI);
+       //set_cutoff(&md,TM_S_C);
 #endif
 
        /*
@@ -247,13 +285,13 @@ int main(int argc,char **argv) {
 
        /* set (initial) dimensions of simulation volume */
 #ifdef ALBE
-       set_dim(&md,LCNT*ALBE_LC_SI,LCNT*ALBE_LC_SI,LCNT*ALBE_LC_SI,TRUE);
-       //set_dim(&md,LCNT*ALBE_LC_C,LCNT*ALBE_LC_C,LCNT*ALBE_LC_C,TRUE);
-       //set_dim(&md,LCNT*ALBE_LC_SIC,LCNT*ALBE_LC_SIC,LCNT*ALBE_LC_SIC,TRUE);
+       set_dim(&md,LCNTX*ALBE_LC_SI,LCNTY*ALBE_LC_SI,LCNTZ*ALBE_LC_SI,TRUE);
+       //set_dim(&md,LCNTX*ALBE_LC_C,LCNTY*ALBE_LC_C,LCNTZ*ALBE_LC_C,TRUE);
+       //set_dim(&md,LCNTX*ALBE_LC_SIC,LCNTY*ALBE_LC_SIC,LCNTZ*ALBE_LC_SIC,TRUE);
 #else
-       //set_dim(&md,LCNT*LC_SI,LCNT*LC_SI,LCNT*LC_SI,TRUE);
-       //set_dim(&md,LCNT*LC_C,LCNT*LC_C,LCNT*LC_C,TRUE);
-       set_dim(&md,LCNT*TM_LC_SIC,LCNT*TM_LC_SIC,LCNT*TM_LC_SIC,TRUE);
+       set_dim(&md,LCNTX*LC_SI,LCNTY*LC_SI,LCNTZ*LC_SI,TRUE);
+       //set_dim(&md,LCNTX*LC_C,LCNTY*LC_C,LCNTZ*LC_C,TRUE);
+       //set_dim(&md,LCNTX*TM_LC_SIC,LCNTY*TM_LC_SIC,LCNTZ*TM_LC_SIC,TRUE);
 #endif
 
        /* set periodic boundary conditions in all directions */
@@ -264,12 +302,12 @@ int main(int argc,char **argv) {
        create_lattice(&md,DIAMOND,ALBE_LC_SI,SI,M_SI,
        //create_lattice(&md,DIAMOND,ALBE_LC_C,C,M_C,
 #else
-       //create_lattice(&md,DIAMOND,LC_SI,SI,M_SI,
+       create_lattice(&md,DIAMOND,LC_SI,SI,M_SI,
 #endif
                       ATOM_ATTR_1BP|ATOM_ATTR_2BP|ATOM_ATTR_3BP|ATOM_ATTR_HB,
        //               ATOM_ATTR_2BP|ATOM_ATTR_HB,
-                      0,LCNT,LCNT,LCNT,NULL);
-       //               1,LCNT,LCNT,LCNT,NULL);
+                      0,LCNTX,LCNTY,LCNTZ,NULL);
+       //               1,LCNTX,LCNTY,LCNTZ,NULL);
 
        /* create zinkblende structure */
        /*
@@ -277,20 +315,20 @@ int main(int argc,char **argv) {
        r.x=0.5*0.25*ALBE_LC_SIC; r.y=r.x; r.z=r.x;
        create_lattice(&md,FCC,ALBE_LC_SIC,SI,M_SI,
                       ATOM_ATTR_1BP|ATOM_ATTR_2BP|ATOM_ATTR_3BP|ATOM_ATTR_HB,
-                      0,LCNT,LCNT,LCNT,&r);
+                      0,LCNTX,LCNTY,LCNTZ,&r);
        r.x+=0.25*ALBE_LC_SIC; r.y=r.x; r.z=r.x;
        create_lattice(&md,FCC,ALBE_LC_SIC,C,M_C,
                       ATOM_ATTR_1BP|ATOM_ATTR_2BP|ATOM_ATTR_3BP|ATOM_ATTR_HB,
-                      1,LCNT,LCNT,LCNT,&r);
+                      1,LCNTX,LCNTY,LCNTZ,&r);
 #else
        r.x=0.5*0.25*TM_LC_SIC; r.y=r.x; r.z=r.x;
        create_lattice(&md,FCC,TM_LC_SIC,SI,M_SI,
                       ATOM_ATTR_1BP|ATOM_ATTR_2BP|ATOM_ATTR_3BP|ATOM_ATTR_HB,
-                      0,LCNT,LCNT,LCNT,&r);
+                      0,LCNTX,LCNTY,LCNTZ,&r);
        r.x+=0.25*TM_LC_SIC; r.y=r.x; r.z=r.x;
        create_lattice(&md,FCC,TM_LC_SIC,C,M_C,
                       ATOM_ATTR_1BP|ATOM_ATTR_2BP|ATOM_ATTR_3BP|ATOM_ATTR_HB,
-                      1,LCNT,LCNT,LCNT,&r);
+                      1,LCNTX,LCNTY,LCNTZ,&r);
 #endif
        */
 
@@ -334,7 +372,7 @@ int main(int argc,char **argv) {
        set_pressure(&md,BAR);
 
        /* set amount of steps to skip before average calc */
-       set_avg_skip(&md,PRERUN);
+       set_avg_skip(&md,(8.0/10.0*PRERUN));
 
        /* set p/t scaling */
        //set_pt_scale(&md,0,0,T_SCALE_BERENDSEN,100.0);
@@ -353,16 +391,18 @@ int main(int argc,char **argv) {
        memset(&hookparam,0,sizeof(t_hp));
        hookparam.argc=argc;
        hookparam.argv=argv;
-       moldyn_set_schedule_hook(&md,&hook,&hookparam);
+       moldyn_set_schedule_hook(&md,&hook_add_atom,&hookparam);
+       //moldyn_set_schedule_hook(&md,&hook_del_atom,&hookparam);
+       //moldyn_add_schedule(&md,POSTRUN,1.0);
 
        /* activate logging */
        moldyn_set_log_dir(&md,argv[1]);
-       moldyn_set_report(&md,"Frank Zirkelbach","Test 1");
-       moldyn_set_log(&md,LOG_TOTAL_ENERGY,1);
-       moldyn_set_log(&md,LOG_TEMPERATURE,1);
-       moldyn_set_log(&md,LOG_PRESSURE,1);
-       moldyn_set_log(&md,VISUAL_STEP,100);
-       moldyn_set_log(&md,SAVE_STEP,100);
+       moldyn_set_report(&md,"Frank Zirkelbach",R_TITLE);
+       moldyn_set_log(&md,LOG_TOTAL_ENERGY,LOG_E);
+       moldyn_set_log(&md,LOG_TEMPERATURE,LOG_T);
+       moldyn_set_log(&md,LOG_PRESSURE,LOG_P);
+       moldyn_set_log(&md,VISUAL_STEP,LOG_V);
+       moldyn_set_log(&md,SAVE_STEP,LOG_S);
        moldyn_set_log(&md,CREATE_REPORT,0);
 
        /*