more logging
[physik/posic.git] / mdrun.c
diff --git a/mdrun.c b/mdrun.c
index 07333ab..1bf983d 100644 (file)
--- a/mdrun.c
+++ b/mdrun.c
@@ -98,6 +98,9 @@ int add_stage(t_mdrun *mdrun,u8 type,void *params) {
                case STAGE_DISPLACE_ATOM:
                        psize=sizeof(t_displace_atom_params);
                        break;
+               case STAGE_DEL_ATOMS:
+                       psize=sizeof(t_del_atoms_params);
+                       break;
                case STAGE_INSERT_ATOMS:
                        psize=sizeof(t_insert_atoms_params);
                        break;
@@ -175,6 +178,7 @@ int mdrun_parse_config(t_mdrun *mdrun) {
        t_set_temp_params stp;
        t_set_timestep_params stsp;
        t_fill_params fp;
+       t_del_atoms_params delp;
 
        /* open config file */
        fd=open(mdrun->cfile,O_RDONLY);
@@ -207,6 +211,7 @@ int mdrun_parse_config(t_mdrun *mdrun) {
                memset(&stp,0,sizeof(t_set_temp_params));
                memset(&stsp,0,sizeof(t_set_timestep_params));
                memset(&fp,0,sizeof(t_fill_params));
+               memset(&delp,0,sizeof(t_del_atoms_params));
 
                // get command + args
                wcnt=0;
@@ -303,10 +308,12 @@ int mdrun_parse_config(t_mdrun *mdrun) {
                                        fp.lz=atoi(word[++i]);
                                        fp.lc=atof(word[++i]);
                                        mdrun->lc=fp.lc;
+                                       continue;
                                }
                                if(!strncmp(word[i],"eb",2)) {
                                        fp.fill_element=atoi(word[++i]);
                                        fp.fill_brand=atoi(word[++i]);
+                                       continue;
                                }
                                if(word[i][0]=='p') {
                                        i+=1;
@@ -342,6 +349,7 @@ int mdrun_parse_config(t_mdrun *mdrun) {
                                                fp.p_params.d.y=atof(word[++i]);
                                                fp.p_params.d.z=atof(word[++i]);
                                        }
+                                       continue;
                                }
                                if(word[i][0]=='d') {
                                        switch(word[++i][0]) {
@@ -382,6 +390,7 @@ int mdrun_parse_config(t_mdrun *mdrun) {
                                                default:
                                                        break;
                                        }
+                                       continue;
 
                                }
                                i+=1;
@@ -458,7 +467,9 @@ int mdrun_parse_config(t_mdrun *mdrun) {
                        csp.type=0;
                        for(i=1;i<wcnt;i++) {
                                if(!strncmp(word[i],"pctrl",5)) {
-                                       csp.ptau=0.01/(atof(word[++i])*GPA);
+                                       csp.ptau=atof(word[++i]);
+                                       if(csp.ptau>0)
+                                               csp.ptau=0.01/(csp.ptau*GPA);
                                        csp.type|=CHSATTR_PCTRL;
                                }
                                if(!strncmp(word[i],"tctrl",5)) {
@@ -509,6 +520,13 @@ int mdrun_parse_config(t_mdrun *mdrun) {
                                dap.dz=atof(word[5]);
                                add_stage(mdrun,STAGE_DISPLACE_ATOM,&dap);
                        }
+                       else if(!strncmp(word[1],"del_atoms",9)) {
+                               delp.o.x=atof(word[2]);
+                               delp.o.y=atof(word[3]);
+                               delp.o.z=atof(word[4]);
+                               delp.r=atof(word[5]);
+                               add_stage(mdrun,STAGE_DEL_ATOMS,&delp);
+                       }
                        else if(!strncmp(word[1],"ins_atoms",9)) {
                                iap.ins_steps=atoi(word[2]);
                                iap.ins_atoms=atoi(word[3]);
@@ -550,19 +568,32 @@ int mdrun_parse_config(t_mdrun *mdrun) {
                                                iap.z0=atof(word[10]);
                                                break;
                                        case 'r':
-                                               if(word[8][0]=='t') {
+                                               switch(word[8][0]) {
+
+                                               case '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]);
+                                                       break;
+                                               case 'r':
+                                                       iap.type=INS_RECT;
+                                                       iap.x0=atof(word[9]);
+                                                       iap.y0=atof(word[10]);
+                                                       iap.z0=atof(word[11]);
+                                                       iap.x1=atof(word[12]);
+                                                       iap.y1=atof(word[13]);
+                                                       iap.z1=atof(word[14]);
+                                                       iap.cr=atof(word[15]);
+                                                       break;
+                                               case 's':
+                                                       iap.type=INS_SPHERE;
+                                                       iap.x0=atof(word[9]);
+                                                       iap.y0=atof(word[10]);
+                                                       iap.z0=atof(word[11]);
+                                                       iap.x1=atof(word[12]);
+                                                       iap.cr=atof(word[13]);
+                                                       break;
+                                               default:
+                                                       break;
                                                }
                                        default:
                                                break;
@@ -719,6 +750,31 @@ int displace_atom(t_moldyn *moldyn,t_mdrun *mdrun) {
        return 0;
 }
 
+int del_atoms(t_moldyn *moldyn,t_mdrun *mdrun) {
+
+       t_stage *stage;
+       t_del_atoms_params *delp;
+       int i;
+       t_3dvec dist;
+       
+       stage=mdrun->stage.current->data;
+       delp=stage->params;
+
+       for(i=0;i<moldyn->count;i++) {
+               v3_sub(&dist,&(delp->o),&(moldyn->atom[i].r));
+//printf("%d ----> %f %f %f = %f | %f\n",i,dist.x,dist.y,dist.z,v3_absolute_square(&dist),delp->r*delp->r);
+               if(v3_absolute_square(&dist)<=(delp->r*delp->r)) {
+                       del_atom(moldyn,moldyn->atom[i].tag);
+                       printf("%s atom deleted: %d %d %d\n",ME,
+                               moldyn->atom[i].tag,moldyn->atom[i].element,
+                              moldyn->atom[i].brand);
+               }
+       }
+
+       return 0;
+
+}
+
 int insert_atoms(t_moldyn *moldyn,t_mdrun *mdrun) {
 
        t_insert_atoms_params *iap;
@@ -765,7 +821,7 @@ int insert_atoms(t_moldyn *moldyn,t_mdrun *mdrun) {
                        z0=-z/2.0;
                        cr_check=TRUE;
                        break;
-               case INS_REGION:
+               case INS_RECT:
                        x=iap->x1-iap->x0;
                        x0=iap->x0;
                        y=iap->y1-iap->y0;
@@ -774,6 +830,15 @@ int insert_atoms(t_moldyn *moldyn,t_mdrun *mdrun) {
                        z0=iap->z0;
                        cr_check=TRUE;
                        break;
+               case INS_SPHERE:
+                       x=2.0*iap->x1;
+                       x0=iap->x0-iap->x1;
+                       y=x;
+                       y0=iap->y0-iap->x1;
+                       z=x;
+                       z0=iap->z0-iap->x1;
+                       cr_check=TRUE;
+                       break;
                case INS_POS:
                        x0=iap->x0;
                        y0=iap->y0;
@@ -825,6 +890,14 @@ int insert_atoms(t_moldyn *moldyn,t_mdrun *mdrun) {
                                                dmin=d;
                                }
                        }
+                       if(iap->type==INS_SPHERE) {
+                               if((r.x-iap->x0)*(r.x-iap->x0)+
+                                  (r.y-iap->y0)*(r.y-iap->y0)+
+                                  (r.z-iap->z0)*(r.z-iap->z0)>
+                                  (iap->x1*iap->x1)) {
+                                       run=1;
+                               }
+                       }
                }
                add_atom(moldyn,iap->element,
                         iap->brand,iap->attr,&r,&v);
@@ -989,13 +1062,13 @@ int chsattr(t_moldyn *moldyn,t_mdrun *mdrun) {
                if(csp->ptau>0)
                        set_p_scale(moldyn,P_SCALE_BERENDSEN,csp->ptau);
                else
-                       set_p_scale(moldyn,P_SCALE_BERENDSEN,csp->ptau);
+                       set_p_scale(moldyn,P_SCALE_NONE,1.0);
        }
        if(csp->type&CHSATTR_TCTRL) {
                if(csp->ttau>0)
                        set_t_scale(moldyn,T_SCALE_BERENDSEN,csp->ttau);
                else
-                       set_t_scale(moldyn,T_SCALE_BERENDSEN,csp->ttau);
+                       set_t_scale(moldyn,T_SCALE_NONE,1.0);
        }
        if(csp->type&CHSATTR_PRELAX) {
                if(csp->dp<0)
@@ -1078,6 +1151,11 @@ int mdrun_hook(void *ptr1,void *ptr2) {
                                displace_atom(moldyn,mdrun);
                                change_stage=TRUE;
                                break;
+                       case STAGE_DEL_ATOMS:
+                               stage_print(" -> del atoms\n\n");
+                               del_atoms(moldyn,mdrun);
+                               change_stage=TRUE;
+                               break;
                        case STAGE_INSERT_ATOMS:
                                stage_print("  -> insert atoms\n\n");
                                iap=stage->params;
@@ -1183,8 +1261,9 @@ int mdrun_hook(void *ptr1,void *ptr2) {
 
                                        create_lattice(moldyn,
                                                       fp->lattice,fp->lc,
-                                                      mdrun->element1,
-                                                      DEFAULT_ATOM_ATTR,0,
+                                                      fp->fill_element,
+                                                      DEFAULT_ATOM_ATTR,
+                                                      fp->fill_brand,
                                                       fp->lx,fp->ly,fp->lz,
                                                       NULL,
                                                       &(fp->p_params),