displace stage type added
[physik/posic.git] / mdrun.c
diff --git a/mdrun.c b/mdrun.c
index eff1ee5..bd045fe 100644 (file)
--- a/mdrun.c
+++ b/mdrun.c
@@ -90,6 +90,9 @@ int add_stage(t_mdrun *mdrun,u8 type,void *params) {
        t_stage *stage;
 
        switch(type) {
+               case STAGE_DISPLACE_ATOM:
+                       psize=sizeof(t_displace_atom_params);
+                       break;
                case STAGE_INSERT_ATOMS:
                        psize=sizeof(t_insert_atoms_params);
                        break;
@@ -142,6 +145,7 @@ int mdrun_parse_config(t_mdrun *mdrun) {
        int wcnt;
        int i,o;
 
+       t_displace_atom_params dap;
        t_insert_atoms_params iap;
        t_continue_params cp;
        t_anneal_params ap;
@@ -332,7 +336,7 @@ int mdrun_parse_config(t_mdrun *mdrun) {
                                        csp.type|=CHSATTR_TCTRL;
                                }
                                if(!strncmp(word[i],"prelax",6)) {
-                                       csp.dp=atof(word[++i]);
+                                       csp.dp=atof(word[++i])*BAR;
                                        csp.type|=CHSATTR_PRELAX;
                                }
                                if(!strncmp(word[i],"trelax",6)) {
@@ -368,11 +372,17 @@ int mdrun_parse_config(t_mdrun *mdrun) {
                        mdrun->visualize=atoi(word[1]);
                else if(!strncmp(word[0],"stage",5)) {
                        // for every stage line, add a stage
-                       if(!strncmp(word[1],"ins_atoms",9)) {
+                       if(!strncmp(word[1],"displace",8)) {
+                               dap.nr=atoi(word[2]);   
+                               dap.dx=atof(word[3]);
+                               dap.dy=atof(word[4]);
+                               dap.dz=atof(word[5]);
+                               add_stage(mdrun,STAGE_DISPLACE_ATOM,&dap);
+                       }
+                       else if(!strncmp(word[1],"ins_atoms",9)) {
                                iap.ins_steps=atoi(word[2]);
                                iap.ins_atoms=atoi(word[3]);
                                iap.element=atoi(word[4]);
-                               iap.element=atoi(word[4]);
                                iap.brand=atoi(word[5]);
                                for(i=0;i<strlen(word[6]);i++) {
                                        switch(word[6][i]) {
@@ -401,20 +411,31 @@ int mdrun_parse_config(t_mdrun *mdrun) {
                                                        break;
                                        }
                                }
-                               // only rand mode by now
-                               if(word[8][0]=='t') {
-                                       iap.type=INS_TOTAL;
-                                       iap.cr=atof(word[9]);
-                               }
-                               else {
-                                       iap.type=INS_REGION;
-                                       iap.x0=atof(word[8]);
-                                       iap.y0=atof(word[9]);
-                                       iap.z0=atof(word[10]);
-                                       iap.x1=atof(word[11]);
-                                       iap.y1=atof(word[12]);
-                                       iap.z1=atof(word[13]);
-                                       iap.cr=atof(word[14]);
+                               switch(word[7][0]) {
+                                       // insertion types
+                                       case 'p':
+                                               iap.type=INS_POS;
+                                               iap.x0=atof(word[8]);
+                                               iap.y0=atof(word[9]);
+                                               iap.z0=atof(word[10]);
+                                               break;
+                                       case 'r':
+                                               if(word[8][0]=='t') {
+                                                       iap.type=INS_TOTAL;
+                                                       iap.cr=atof(word[9]);
+                                               }
+                                               else {
+                                                       iap.type=INS_REGION;
+                                                       iap.x0=atof(word[8]);
+                                                       iap.y0=atof(word[9]);
+                                                       iap.z0=atof(word[10]);
+                                                       iap.x1=atof(word[11]);
+                                                       iap.y1=atof(word[12]);
+                                                       iap.z1=atof(word[13]);
+                                                       iap.cr=atof(word[14]);
+                                               }
+                                       default:
+                                               break;
                                }
                                add_stage(mdrun,STAGE_INSERT_ATOMS,&iap);
                        }
@@ -451,8 +472,9 @@ int check_pressure(t_moldyn *moldyn,t_mdrun *mdrun) {
 
        double delta;
 
-       if(!(mdrun->sattr&SATTR_PRELAX))
+       if(!(mdrun->sattr&SATTR_PRELAX)) {
                return TRUE;
+       }
 
        delta=moldyn->p_avg-moldyn->p_ref;
 
@@ -483,13 +505,30 @@ int check_temperature(t_moldyn *moldyn,t_mdrun *mdrun) {
        return TRUE;
 }
 
+int displace_atom(t_moldyn *moldyn,t_mdrun *mdrun) {
+
+       t_displace_atom_params *dap;
+       t_stage *stage;
+       t_atom *atom;
+
+       stage=mdrun->stage.current->data;
+       dap=stage->params;
+
+       atom=&(moldyn->atom[dap->nr]);
+       atom->r.x+=dap->dx;
+       atom->r.y+=dap->dy;
+       atom->r.z+=dap->dz;
+
+       return 0;
+}
+
 int insert_atoms(t_moldyn *moldyn,t_mdrun *mdrun) {
 
        t_insert_atoms_params *iap;
        t_stage *stage;
        t_atom *atom;
        t_3dvec r,v,dist;
-       double d,dmin;
+       double d,dmin,o;
        int cnt,i;
        double x,y,z;
        double x0,y0,z0;
@@ -501,15 +540,32 @@ int insert_atoms(t_moldyn *moldyn,t_mdrun *mdrun) {
        cr_check=FALSE;
 
        v.x=0.0; v.y=0.0; v.z=0.0;
+       x=0; y=0; z=0;
+       o=0; dmin=0;
+
+       switch(mdrun->lattice) {
+               case CUBIC:
+                       o=0.5*mdrun->lc;
+                       break;
+               case FCC:
+                       o=0.25*mdrun->lc;
+                       break;
+               case DIAMOND:
+               case ZINCBLENDE:
+                       o=0.125*mdrun->lc;
+                       break;
+               default:
+                       break;
+       }
 
        switch(iap->type) {
                case INS_TOTAL:
                        x=moldyn->dim.x;
-                       x0=0.0;
+                       x0=-x/2.0;
                        y=moldyn->dim.y;
-                       y0=0.0;
+                       y0=-y/2.0;
                        z=moldyn->dim.z;
-                       z0=0.0;
+                       z0=-z/2.0;
                        cr_check=TRUE;
                        break;
                case INS_REGION:
@@ -521,6 +577,12 @@ int insert_atoms(t_moldyn *moldyn,t_mdrun *mdrun) {
                        z0=iap->z0;
                        cr_check=TRUE;
                        break;
+               case INS_POS:
+                       x0=iap->x0;
+                       y0=iap->y0;
+                       z0=iap->z0;
+                       cr_check=FALSE;
+                       break;
                default:
                        printf("%s unknown insertion mode: %02x\n",
                               ME,iap->type);
@@ -531,9 +593,25 @@ int insert_atoms(t_moldyn *moldyn,t_mdrun *mdrun) {
        while(cnt<iap->ins_atoms) {
                run=1;
                while(run) {
-                       r.x=(rand_get_double(&(moldyn->random))-0.5)*x+x0;
-                       r.y=(rand_get_double(&(moldyn->random))-0.5)*y+y0;
-                       r.z=(rand_get_double(&(moldyn->random))-0.5)*z+z0;
+                       if(iap->type!=INS_POS) {
+                               r.x=rand_get_double(&(moldyn->random))*x;
+                               r.y=rand_get_double(&(moldyn->random))*y;
+                               r.z=rand_get_double(&(moldyn->random))*z;
+                       }
+                       else {
+                               r.x=0.0;
+                               r.y=0.0;
+                               r.z=0.0;
+                       }
+                       r.x+=x0;
+                       r.y+=y0;
+                       r.z+=z0;
+                       // offset
+                       if(iap->type!=INS_TOTAL) {
+                               r.x+=o;
+                               r.y+=o;
+                               r.z+=o;
+                       }
                        run=0;
                        if(cr_check==TRUE) {
                                dmin=1000;      // for sure too high!
@@ -682,8 +760,8 @@ int mdrun_hook(void *ptr1,void *ptr2) {
        tau=mdrun->timestep;
 
        /* check whether relaxation steps are necessary */
-       if(!((check_pressure(moldyn,mdrun)==FALSE)|\
-            (check_temperature(moldyn,mdrun)==FALSE))) {
+       if((check_pressure(moldyn,mdrun)==TRUE)&\
+          (check_temperature(moldyn,mdrun)==TRUE)) {
        
                /* be verbose */
                stage_print("\n###########################\n");
@@ -692,6 +770,11 @@ int mdrun_hook(void *ptr1,void *ptr2) {
                
                /* stage specific stuff */
                switch(stage->type) {
+                       case STAGE_DISPLACE_ATOM:
+                               stage_print("  -> displace atom\n\n");
+                               displace_atom(moldyn,mdrun);
+                               change_stage=TRUE;
+                               break;
                        case STAGE_INSERT_ATOMS:
                                stage_print("  -> insert atoms\n\n");
                                iap=stage->params;
@@ -701,7 +784,7 @@ int mdrun_hook(void *ptr1,void *ptr2) {
                                }
                                insert_atoms(moldyn,mdrun);
                                iap->cnt_steps+=1;
-                                       break;
+                               break;
                        case STAGE_CONTINUE:
                                stage_print("  -> continue\n\n");
                                if(stage->executed==TRUE) {
@@ -710,7 +793,7 @@ int mdrun_hook(void *ptr1,void *ptr2) {
                                }
                                cp=stage->params;
                                steps=cp->runs;
-                                       break;
+                               break;
                        case STAGE_ANNEAL:
                                stage_print("  -> anneal\n\n");
                                ap=stage->params;
@@ -718,7 +801,9 @@ int mdrun_hook(void *ptr1,void *ptr2) {
                                        change_stage=TRUE;
                                        break;
                                }
-                               set_temperature(moldyn,moldyn->t_ref+ap->dt);
+                               if(moldyn->t_ref+ap->dt>=0.0)
+                                       set_temperature(moldyn,
+                                                       moldyn->t_ref+ap->dt);
                                ap->count+=1;
                                break;
                        case STAGE_CHAATTR: