]> hackdaworld.org Git - physik/posic.git/commitdiff
insert mixed atoms feature added (will be renamed an cleand up later)
authorhackbard <hackbard@sage.physik.uni-augsburg.de>
Mon, 18 Aug 2008 15:02:44 +0000 (17:02 +0200)
committerhackbard <hackbard@sage.physik.uni-augsburg.de>
Mon, 18 Aug 2008 15:02:44 +0000 (17:02 +0200)
still problematic!

mdrun.c
mdrun.h
moldyn.c
moldyn.h

diff --git a/mdrun.c b/mdrun.c
index 29d3160acdc9375864ff56788a293704e8c3ccee..31943efc65bd39680dc8dec02fec465ce39c7e90 100644 (file)
--- a/mdrun.c
+++ b/mdrun.c
@@ -96,6 +96,9 @@ int add_stage(t_mdrun *mdrun,u8 type,void *params) {
                case STAGE_INSERT_ATOMS:
                        psize=sizeof(t_insert_atoms_params);
                        break;
+               case STAGE_INSERT_MIXED_ATOMS:
+                       psize=sizeof(t_insert_mixed_atoms_params);
+                       break;
                case STAGE_CONTINUE:
                        psize=sizeof(t_continue_params);
                        break;
@@ -147,6 +150,7 @@ int mdrun_parse_config(t_mdrun *mdrun) {
 
        t_displace_atom_params dap;
        t_insert_atoms_params iap;
+       t_insert_mixed_atoms_params imp;
        t_continue_params cp;
        t_anneal_params ap;
        t_chaattr_params cap;
@@ -175,6 +179,7 @@ int mdrun_parse_config(t_mdrun *mdrun) {
 
                // reset
                memset(&iap,0,sizeof(t_insert_atoms_params));
+               memset(&imp,0,sizeof(t_insert_mixed_atoms_params));
                memset(&cp,0,sizeof(t_continue_params));
                memset(&ap,0,sizeof(t_anneal_params));
                memset(&cap,0,sizeof(t_chaattr_params));
@@ -247,6 +252,8 @@ int mdrun_parse_config(t_mdrun *mdrun) {
                                mdrun->lattice=FCC;
                        if(!strncmp(word[1],"diamond",7))
                                mdrun->lattice=DIAMOND;
+                       if(!strncmp(word[1],"none",4))
+                               mdrun->lattice=NONE;
                }
                else if(!strncmp(word[0],"element1",8)) {
                        mdrun->element1=atoi(word[1]);
@@ -441,6 +448,56 @@ int mdrun_parse_config(t_mdrun *mdrun) {
                                }
                                add_stage(mdrun,STAGE_INSERT_ATOMS,&iap);
                        }
+
+
+                       // HERE WE GO ...
+
+                       else if(!strncmp(word[1],"ins_m_atoms",11)) {
+                               imp.element1=atoi(word[2]);
+                               imp.element2=atoi(word[3]);
+                               imp.amount1=atoi(word[4]);
+                               imp.amount2=atoi(word[5]);
+                               imp.brand1=atoi(word[6]);
+                               imp.brand2=atoi(word[7]);
+                               imp.cr=atof(word[8]);
+                               /* do this later ...
+                               for(i=0;i<strlen(word[8]);i++) {
+                                       switch(word[8][i]) {
+                                               case 'b':
+                                                       imp.attr|=ATOM_ATTR_VB;
+                                                       break;
+                                               case 'h':
+                                                       imp.attr|=ATOM_ATTR_HB;
+                                                       break;
+                                               case 'v':
+                                                       imp.attr|=ATOM_ATTR_VA;
+                                                       break;
+                                               case 'f':
+                                                       imp.attr|=ATOM_ATTR_FP;
+                                                       break;
+                                               case '1':
+                                                       imp.attr|=ATOM_ATTR_1BP;
+                                                       break;
+                                               case '2':
+                                                       imp.attr|=ATOM_ATTR_2BP;
+                                                       break;
+                                               case '3':
+                                                       imp.attr|=ATOM_ATTR_3BP;
+                                                       break;
+                                               default:
+                                                       break;
+                                       }
+                               }
+                               */
+                               imp.attr1=ATOM_ATTR_HB|ATOM_ATTR_VA|ATOM_ATTR_1BP|ATOM_ATTR_2BP|ATOM_ATTR_3BP;
+                               imp.attr2=ATOM_ATTR_HB|ATOM_ATTR_VA|ATOM_ATTR_1BP|ATOM_ATTR_2BP|ATOM_ATTR_3BP;
+                               add_stage(mdrun,STAGE_INSERT_MIXED_ATOMS,&imp);
+                       }
+
+
+
+
+
                        else if(!strncmp(word[1],"continue",8)) {
                                cp.runs=atoi(word[2]);
                                add_stage(mdrun,STAGE_CONTINUE,&cp);
@@ -643,6 +700,104 @@ int insert_atoms(t_moldyn *moldyn,t_mdrun *mdrun) {
        return 0;
 }
 
+int insert_mixed_atoms(t_moldyn *moldyn,t_mdrun *mdrun) {
+
+       t_stage *stage;
+       t_insert_mixed_atoms_params *imp;
+       t_atom *atom;
+       double x,x0,y,y0,z,z0;
+       double dmin,d,c;
+       u8 retry;
+       t_3dvec r,v,dist;
+       int i;
+       
+
+       stage=mdrun->stage.current->data;
+       imp=stage->params;
+
+       x=moldyn->dim.x;
+       x0=-x/2.0;
+       y=moldyn->dim.y;
+       y0=-y/2.0;
+       z=moldyn->dim.z;
+       z0=-z/2.0;
+
+       v.x=0.0;
+       v.y=0.0;
+       v.z=0.0;
+
+       c=imp->cr*imp->cr;
+
+       while(imp->amount1|imp->amount2) {
+               if(imp->amount1) {
+                       retry=1;
+                       while(retry) {
+                               retry=0;
+                               r.x=rand_get_double(&(moldyn->random))*x;
+                               r.y=rand_get_double(&(moldyn->random))*y;
+                               r.z=rand_get_double(&(moldyn->random))*z;
+                               r.x+=x0;
+                               r.y+=y0;
+                               r.z+=z0;
+                               dmin=1000.0;    // for sure too high!
+                               for(i=0;i<moldyn->count;i++) {
+                                       atom=&(moldyn->atom[i]);
+                                       v3_sub(&dist,&(atom->r),&r);
+                                       check_per_bound(moldyn,&dist);
+                                       d=v3_absolute_square(&dist);
+                                       if(d<c) {
+                                               retry=1;
+                                               break;
+                                       }
+                                       if(d<dmin)
+                                               dmin=d;
+                                       
+                               }
+                       }
+                       add_atom(moldyn,imp->element1,pse_mass[imp->element1],
+                                 imp->brand1,imp->attr1,&r,&v);
+                       printf("%s (mixed) atom inserted (%d): %f %f %f\n",
+                               ME,imp->amount1,r.x,r.y,r.z);
+                       printf("  -> d2 = %f/%f\n",dmin,c);
+                       imp->amount1-=1;
+               }
+               if(imp->amount2) {
+                       retry=1;
+                       while(retry) {
+                               retry=0;
+                               r.x=rand_get_double(&(moldyn->random))*x;
+                               r.y=rand_get_double(&(moldyn->random))*y;
+                               r.z=rand_get_double(&(moldyn->random))*z;
+                               r.x+=x0;
+                               r.y+=y0;
+                               r.z+=z0;
+                               dmin=1000.0;    // for sure too high!
+                               for(i=0;i<moldyn->count;i++) {
+                                       atom=&(moldyn->atom[i]);
+                                       v3_sub(&dist,&(atom->r),&r);
+                                       check_per_bound(moldyn,&dist);
+                                       d=v3_absolute_square(&dist);
+                                       if(d<c) {
+                                               retry=1;
+                                               break;
+                                       }
+                                       if(d<dmin)
+                                               dmin=d;
+                                       
+                               }
+                       }
+                       add_atom(moldyn,imp->element2,pse_mass[imp->element2],
+                                 imp->brand2,imp->attr2,&r,&v);
+                       printf("%s (mixed) atom inserted (%d): %f %f %f\n",
+                               ME,imp->amount2,r.x,r.y,r.z);
+                       printf("  -> d2 = %f/%f\n",dmin,c);
+                       imp->amount2-=1;
+               }
+       }
+
+       return 0;
+}
+
 int chaatr(t_moldyn *moldyn,t_mdrun *mdrun) {
 
        t_stage *stage;
@@ -740,6 +895,7 @@ int mdrun_hook(void *ptr1,void *ptr2) {
        u8 change_stage;
 
        t_insert_atoms_params *iap;
+       t_insert_mixed_atoms_params *imp;
        t_continue_params *cp;
        t_anneal_params *ap;
 
@@ -787,6 +943,17 @@ int mdrun_hook(void *ptr1,void *ptr2) {
                                insert_atoms(moldyn,mdrun);
                                iap->cnt_steps+=1;
                                break;
+
+
+
+                       case STAGE_INSERT_MIXED_ATOMS:
+                               stage_print("  -> insert mixed atoms\n\n");
+                               imp=stage->params;
+                               insert_mixed_atoms(moldyn,mdrun);
+                               break;
+
+
+
                        case STAGE_CONTINUE:
                                stage_print("  -> continue\n\n");
                                if(stage->executed==TRUE) {
@@ -952,6 +1119,8 @@ int main(int argc,char **argv) {
                                       mdrun.m2,DEFAULT_ATOM_ATTR,1,mdrun.lx,
                                       mdrun.ly,mdrun.lz,&o);
                        break;
+               case NONE:
+                       break;
                default:
                        printf("%s unknown lattice type: %02x\n",
                               ME,mdrun.lattice);
diff --git a/mdrun.h b/mdrun.h
index d065d5767faa6e9517a25146e7ba1d77bdd1a214..b1c2e0660c52b1ee4d5fb0c7df7b4df0e4100e55 100644 (file)
--- a/mdrun.h
+++ b/mdrun.h
@@ -43,10 +43,11 @@ typedef struct s_stage {
 
 #define STAGE_DISPLACE_ATOM                    0x00
 #define STAGE_INSERT_ATOMS                     0x01
-#define STAGE_CONTINUE                         0x02
-#define STAGE_ANNEAL                           0x03
-#define STAGE_CHAATTR                          0x04
-#define STAGE_CHSATTR                          0x05
+#define STAGE_INSERT_MIXED_ATOMS               0x02
+#define STAGE_CONTINUE                         0x03
+#define STAGE_ANNEAL                           0x04
+#define STAGE_CHAATTR                          0x05
+#define STAGE_CHSATTR                          0x06
 
 typedef struct s_mdrun {
        char cfile[128];                        // config file
@@ -119,6 +120,18 @@ typedef struct s_insert_atoms_params {
        u8 attr;
 } t_insert_atoms_params;
 
+typedef struct s_insert_mixed_atoms_params {
+       int element1;
+       int element2;
+       int amount1;
+       int amount2;
+       u8 brand1;
+       u8 brand2;
+       u8 attr1;
+       u8 attr2;
+       double cr;
+} t_insert_mixed_atoms_params;
+
 #define INS_TOTAL                              0x01
 #define INS_REGION                             0x02
 #define INS_POS                                        0x03
index b79dea66946edb6032132b4b85df486e290916e4..eb3c4b03dfbcdb6b427c66d03aace481a6fe91ff 100644 (file)
--- a/moldyn.c
+++ b/moldyn.c
@@ -485,6 +485,10 @@ int create_lattice(t_moldyn *moldyn,u8 type,double lc,int element,double mass,
        count=moldyn->count;
 
        /* how many atoms do we expect */
+       if(type==NONE) {
+               new*=1;
+               printf("[moldyn] WARNING: create 'none' lattice called");
+       }
        if(type==CUBIC) new*=1;
        if(type==FCC) new*=4;
        if(type==DIAMOND) new*=8;
@@ -1574,9 +1578,11 @@ int moldyn_integrate(t_moldyn *moldyn) {
                printf("[moldyn] WARNING: cutoff > 0.5 x dim.y\n");
        if(moldyn->cutoff>0.5*moldyn->dim.z)
                printf("[moldyn] WARNING: cutoff > 0.5 x dim.z\n");
-       ds=0.5*atom[0].f.x*moldyn->tau_square/atom[0].mass;
-       if(ds>0.05*moldyn->nnd)
+       if(moldyn->count) {
+               ds=0.5*atom[0].f.x*moldyn->tau_square/atom[0].mass;
+               if(ds>0.05*moldyn->nnd)
                printf("[moldyn] WARNING: forces too high / tau too small!\n");
+       }
 
        /* zero absolute time */
        // should have right values!
index ca40103646abf12c1c3a0b2d6b806dd62a1bc9c3..11fdf6be8f0e961479bc60c0871d79a3eba4ba4c 100644 (file)
--- a/moldyn.h
+++ b/moldyn.h
@@ -352,6 +352,7 @@ typedef struct s_vb {
 #define FCC                    0x02
 #define DIAMOND                        0x04
 #define ZINCBLENDE             0x08
+#define NONE                   0x80
 
 /*
  * more includes