From: hackbard Date: Mon, 15 Jan 2007 16:04:15 +0000 (+0000) Subject: cleaning + set hook function X-Git-Url: https://hackdaworld.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9f6af2cd82a72451741b68ca333f94c6c1d2eec5;p=physik%2Fposic.git cleaning + set hook function --- diff --git a/moldyn.c b/moldyn.c index d33de02..9db5cd9 100644 --- a/moldyn.c +++ b/moldyn.c @@ -19,6 +19,8 @@ int moldyn_init(t_moldyn *moldyn,int argc,char **argv) { + printf("[moldyn] init\n"); + memset(moldyn,0,sizeof(t_moldyn)); rand_init(&(moldyn->random),NULL,1); @@ -30,6 +32,7 @@ int moldyn_init(t_moldyn *moldyn,int argc,char **argv) { int moldyn_shutdown(t_moldyn *moldyn) { printf("[moldyn] shutdown\n"); + moldyn_log_shutdown(moldyn); link_cell_shutdown(moldyn); rand_close(&(moldyn->random)); @@ -40,12 +43,16 @@ int moldyn_shutdown(t_moldyn *moldyn) { int set_int_alg(t_moldyn *moldyn,u8 algo) { + printf("[moldyn] integration algorithm: "); + switch(algo) { case MOLDYN_INTEGRATE_VERLET: moldyn->integrate=velocity_verlet; + printf("velocity verlet\n"); break; default: printf("unknown integration algorithm: %02x\n",algo); + printf("unknown\n"); return -1; } @@ -56,6 +63,8 @@ int set_cutoff(t_moldyn *moldyn,double cutoff) { moldyn->cutoff=cutoff; + printf("[moldyn] cutoff [A]: %f\n",moldyn->cutoff); + return 0; } @@ -63,6 +72,8 @@ int set_temperature(t_moldyn *moldyn,double t_ref) { moldyn->t_ref=t_ref; + printf("[moldyn] temperature: %f\n",moldyn->t_ref); + return 0; } @@ -70,6 +81,8 @@ int set_pressure(t_moldyn *moldyn,double p_ref) { moldyn->p_ref=p_ref; + printf("[moldyn] pressure: %f\n",moldyn->p_ref); + return 0; } @@ -79,6 +92,18 @@ int set_pt_scale(t_moldyn *moldyn,u8 ptype,double ptc,u8 ttype,double ttc) { moldyn->t_tc=ttc; moldyn->p_tc=ptc; + printf("[moldyn] p/t scaling:\n"); + + printf(" p: %s",ptype?"yes":"no "); + if(ptype) + printf(" | type: %02x | factor: %f",ptype,ptc); + printf("\n"); + + printf(" t: %s",ttype?"yes":"no "); + if(ttype) + printf(" | type: %02x | factor: %f",ttype,ttc); + printf("\n"); + return 0; } @@ -101,7 +126,7 @@ int set_dim(t_moldyn *moldyn,double x,double y,double z,u8 visualize) { printf(" y: %f\n",moldyn->dim.y); printf(" z: %f\n",moldyn->dim.z); printf(" volume: %f\n",moldyn->volume); - printf(" visualize simulation box: %s\n",visualize?"on":"off"); + printf(" visualize simulation box: %s\n",visualize?"yes":"no"); return 0; } @@ -115,6 +140,8 @@ int set_nn_dist(t_moldyn *moldyn,double dist) { int set_pbc(t_moldyn *moldyn,u8 x,u8 y,u8 z) { + printf("[moldyn] periodic boundary conditions:\n"); + if(x) moldyn->status|=MOLDYN_STAT_PBX; @@ -124,6 +151,10 @@ int set_pbc(t_moldyn *moldyn,u8 x,u8 y,u8 z) { if(z) moldyn->status|=MOLDYN_STAT_PBZ; + printf(" x: %s\n",x?"yes":"no"); + printf(" y: %s\n",y?"yes":"no"); + printf(" z: %s\n",z?"yes":"no"); + return 0; } @@ -171,6 +202,8 @@ int moldyn_set_log(t_moldyn *moldyn,u8 type,int timer) { char filename[128]; int ret; + printf("[moldyn] set log: "); + switch(type) { case LOG_TOTAL_ENERGY: moldyn->ewrite=timer; @@ -183,6 +216,7 @@ int moldyn_set_log(t_moldyn *moldyn,u8 type,int timer) { return moldyn->efd; } dprintf(moldyn->efd,"# total energy log file\n"); + printf("total energy (%d)\n",timer); break; case LOG_TOTAL_MOMENTUM: moldyn->mwrite=timer; @@ -195,9 +229,11 @@ int moldyn_set_log(t_moldyn *moldyn,u8 type,int timer) { return moldyn->mfd; } dprintf(moldyn->efd,"# total momentum log file\n"); + printf("total momentum (%d)\n",timer); break; case SAVE_STEP: moldyn->swrite=timer; + printf("save file (%d)\n",timer); break; case VISUAL_STEP: moldyn->vwrite=timer; @@ -206,9 +242,10 @@ int moldyn_set_log(t_moldyn *moldyn,u8 type,int timer) { printf("[moldyn] visual init failure\n"); return ret; } + printf("visual file (%d)\n",timer); break; default: - printf("[moldyn] unknown log mechanism: %02x\n",type); + printf("unknown log type: %02x\n",type); return -1; } @@ -429,6 +466,8 @@ int thermal_init(t_moldyn *moldyn,u8 equi_init) { atom=moldyn->atom; random=&(moldyn->random); + printf("[moldyn] thermal init (equi init: %s)\n",equi_init?"yes":"no"); + /* gaussian distribution of velocities */ v3_zero(&p_total); for(i=0;icount;i++) { @@ -846,10 +885,14 @@ int moldyn_add_schedule(t_moldyn *moldyn,int runs,double tau) { schedule->tau=ptr; schedule->tau[count-1]=tau; + printf("[moldyn] schedule added:\n"); + printf(" number: %d | runs: %d | tau: %f\n",count-1,runs,tau); + + return 0; } -int moldyn_set_schedule_hook(t_moldyn *moldyn,void *hook,void *hook_params) { +int moldyn_set_schedule_hook(t_moldyn *moldyn,set_hook hook,void *hook_params) { moldyn->schedule.hook=hook; moldyn->schedule.hook_params=hook_params; @@ -912,6 +955,9 @@ int moldyn_integrate(t_moldyn *moldyn) { /* debugging, ignore */ moldyn->debug=0; + /* tell the world */ + printf("[moldyn] integration start, go get a coffee ...\n"); + /* executing the schedule */ for(sched->count=0;sched->counttotal_sched;sched->count++) { @@ -1199,9 +1245,9 @@ printf("\n\n"); for(i=0;ivt2-=v3_scalar_product(&(itom[i].r),&(itom[i].f)); -printf("compare: vt1: %f vt2: %f\n",moldyn->vt1,moldyn->vt2); +//printf("compare: vt1: %f vt2: %f\n",moldyn->vt1,moldyn->vt2); -pressure_calc(moldyn); +//pressure_calc(moldyn); return 0; } diff --git a/moldyn.h b/moldyn.h index c5cc064..8254568 100644 --- a/moldyn.h +++ b/moldyn.h @@ -71,7 +71,7 @@ typedef struct s_moldyn_schedule { int total_sched; int *runs; double *tau; - int (*hook)(void *moldyn,void *hook); + int (*hook)(void *moldyn,void *hook_params); void *hook_params; } t_moldyn_schedule; @@ -422,8 +422,10 @@ int link_cell_update(t_moldyn *moldyn); int link_cell_neighbour_index(t_moldyn *moldyn,int i,int j,int k,t_list *cell); int link_cell_shutdown(t_moldyn *moldyn); +typedef int (*set_hook)(void *,void *); + int moldyn_add_schedule(t_moldyn *moldyn,int runs,double tau); -int moldyn_set_schedule_hook(t_moldyn *moldyn,void *hook,void *hook_params); +int moldyn_set_schedule_hook(t_moldyn *moldyn,set_hook hook,void *hook_params); int moldyn_integrate(t_moldyn *moldyn); int velocity_verlet(t_moldyn *moldyn); diff --git a/run b/run index 5a3a768..5a20df0 100755 --- a/run +++ b/run @@ -1,4 +1,4 @@ -mkdir -p saves video +[ ! -d $1 ] && mkdir $1 ./clean $1 ./sic $@ if [ "$?" == "0" ]; then diff --git a/sic.c b/sic.c index e2e8626..a890270 100644 --- a/sic.c +++ b/sic.c @@ -11,6 +11,18 @@ #include "posic.h" +int hook(void *moldyn,void *hook_params) { + + t_moldyn *md; + + md=moldyn; + + /* decrease temperature in every hook */ + set_temperature(md,md->t_ref-100.0); + + return 0; +} + int main(int argc,char **argv) { /* check argv */ @@ -27,25 +39,16 @@ int main(int argc,char **argv) { t_ho_params ho; t_tersoff_mult_params tp; - /* misc parameters */ - double tau; - /* testing location & velocity vector */ t_3dvec r,v; - /* values */ - tau=1.0e-15; /* delta t = 1 fs */ - /* initialize moldyn */ - printf("[sic] moldyn init\n"); moldyn_init(&md,argc,argv); /* choose integration algorithm */ - printf("[sic] setting integration algorithm\n"); set_int_alg(&md,MOLDYN_INTEGRATE_VERLET); /* choose potential */ - printf("[sic] selecting potential\n"); //set_potential1b(&md,tersoff_mult_1bp,&tp); //set_potential2b(&md,tersoff_mult_2bp,&tp); //set_potential2b_post(&md,tersoff_mult_post_2bp,&tp); @@ -54,9 +57,8 @@ int main(int argc,char **argv) { //set_potential2b(&md,harmonic_oscillator,&ho); /* cutoff radius */ - printf("[sic] setting cutoff radius\n"); //set_cutoff(&md,TM_S_SI); - set_cutoff(&md,3*LC_SI); + set_cutoff(&md,2*LC_SI); /* * potential parameters @@ -105,19 +107,16 @@ int main(int argc,char **argv) { tersoff_mult_complete_params(&tp); /* set (initial) dimensions of simulation volume */ - printf("[sic] setting dimensions\n"); - set_dim(&md,10*LC_SI,10*LC_SI,10*LC_SI,TRUE); + set_dim(&md,6*LC_SI,6*LC_SI,6*LC_SI,TRUE); /* set periodic boundary conditions in all directions */ - printf("[sic] setting periodic boundary conditions\n"); set_pbc(&md,TRUE,TRUE,TRUE); /* create the lattice / place atoms */ - printf("[sic] creating atoms\n"); create_lattice(&md,DIAMOND,LC_SI,SI,M_SI, // ATOM_ATTR_1BP|ATOM_ATTR_2BP|ATOM_ATTR_3BP|ATOM_ATTR_HB, ATOM_ATTR_2BP|ATOM_ATTR_HB, - 0,10,10,10); + 0,6,6,6); moldyn_bc_check(&md); /* testing configuration */ @@ -141,7 +140,6 @@ int main(int argc,char **argv) { set_nn_dist(&md,0.25*sqrt(3.0)*LC_SI); /* diamond ! */ /* set temperature */ - printf("[sic] setting temperature -> %f\n",273+atof(argv[2])); //set_temperature(&md,273.0+1410.0); //set_temperature(&md,273.0+450.0); //set_temperature(&md,273.0); @@ -150,42 +148,43 @@ int main(int argc,char **argv) { set_temperature(&md,atof(argv[2])+273.0); /* set pressure */ - printf("[sic] setting pressure\n"); set_pressure(&md,ATM); /* set p/t scaling */ - printf("[sic] set p/t scaling\n"); //set_pt_scale(&md,P_SCALE_BERENDSEN,100.0, // T_SCALE_BERENDSEN,100.0); - //set_pt_scale(&md,0,0,T_SCALE_BERENDSEN,100.0); + set_pt_scale(&md,0,0,T_SCALE_BERENDSEN,100.0); //set_pt_scale(&md,P_SCALE_BERENDSEN,100.0,0,0); /* initial thermal fluctuations of particles (in equilibrium) */ - printf("[sic] thermal init\n"); thermal_init(&md,TRUE); /* create the simulation schedule */ - printf("[sic] adding schedule\n"); - moldyn_add_schedule(&md,10001,1.0); + moldyn_add_schedule(&md,100,1.0); + moldyn_add_schedule(&md,100,1.0); + moldyn_add_schedule(&md,100,1.0); + moldyn_add_schedule(&md,100,1.0); + moldyn_add_schedule(&md,100,1.0); + moldyn_add_schedule(&md,100,1.0); + moldyn_add_schedule(&md,100,1.0); + moldyn_add_schedule(&md,100,1.0); + + /* schedule hook function */ + moldyn_set_schedule_hook(&md,&hook,NULL); /* activate logging */ - printf("[sic] activate logging\n"); moldyn_set_log_dir(&md,argv[1]); - moldyn_set_log(&md,LOG_TOTAL_ENERGY,10); - moldyn_set_log(&md,VISUAL_STEP,100); + moldyn_set_log(&md,LOG_TOTAL_ENERGY,1); + moldyn_set_log(&md,VISUAL_STEP,10); /* * let's do the actual md algorithm now * * integration of newtons equations */ - - printf("[sic] integration start, go get a coffee ...\n"); moldyn_integrate(&md); /* close */ - - printf("[sic] shutdown\n"); moldyn_shutdown(&md); return 0;