X-Git-Url: https://www.hackdaworld.org/gitweb/?a=blobdiff_plain;f=moldyn.c;h=3c4d87399dcaceffb42f6d91ffe97a58bd8e841f;hb=c40d54eb3e319b17b2f6174c4eddcfd6ee3a407b;hp=92c4e58f3d78957a03704c40fbe62af686155a9b;hpb=fd4ecbff76b2e4fc70ca88e64fb76c85fa953888;p=physik%2Fposic.git diff --git a/moldyn.c b/moldyn.c index 92c4e58..3c4d873 100644 --- a/moldyn.c +++ b/moldyn.c @@ -20,6 +20,58 @@ #include "moldyn.h" #include "report/report.h" +/* + * global variables, pse and atom colors (only needed here) + */ + +static char *pse_name[]={ + "*", + "H", + "He", + "Li", + "Be", + "B", + "C", + "N", + "O", + "F", + "Ne", + "Na", + "Mg", + "Al", + "Si", + "P", + "S", + "Cl", + "Ar", +}; + +static char *pse_col[]={ + "*", + "White", + "He", + "Li", + "Be", + "B", + "Gray", + "N", + "Blue", + "F", + "Ne", + "Na", + "Mg", + "Al", + "Yellow", + "P", + "S", + "Cl", + "Ar", +}; + +/* + * the moldyn functions + */ + int moldyn_init(t_moldyn *moldyn,int argc,char **argv) { printf("[moldyn] init\n"); @@ -427,7 +479,6 @@ int moldyn_log_shutdown(t_moldyn *moldyn) { moldyn->vlsdir); system(sc); } - if(&(moldyn->vis)) visual_tini(&(moldyn->vis)); return 0; } @@ -558,6 +609,35 @@ int add_atom(t_moldyn *moldyn,int element,double mass,u8 brand,u8 attr, return 0; } +int del_atom(t_moldyn *moldyn,int tag) { + + t_atom *new,*old; + int cnt; + + old=moldyn->atom; + + new=(t_atom *)malloc((moldyn->count-1)*sizeof(t_atom)); + if(!new) { + perror("[moldyn]malloc (del atom)"); + return -1; + } + + for(cnt=0;cntcount;cnt++) { + new[cnt-1]=old[cnt]; + new[cnt-1].tag=cnt-1; + } + + moldyn->count-=1; + moldyn->atom=new; + + free(old); + + return 0; +} + /* cubic init */ int cubic_init(int a,int b,int c,double lc,t_atom *atom,t_3dvec *origin) { @@ -1371,9 +1451,6 @@ int moldyn_integrate(t_moldyn *moldyn) { moldyn->tau_square=moldyn->tau*moldyn->tau; moldyn->cutoff_square=moldyn->cutoff*moldyn->cutoff; - /* energy scaling factor */ - energy_scale=moldyn->count*EV; - /* get current time */ gettimeofday(&t1,NULL); @@ -1413,6 +1490,9 @@ return 0; moldyn->tau_square=moldyn->tau*moldyn->tau; moldyn->time_steps=sched->runs[sched->count]; + /* energy scaling factor (might change!) */ + energy_scale=moldyn->count*EV; + /* integration according to schedule */ for(i=0;itime_steps;i++) { @@ -1435,7 +1515,7 @@ return 0; /* check for log & visualization */ if(e) { - if(!(i%e)) + if(!(moldyn->total_steps%e)) dprintf(moldyn->efd, "%f %f %f %f\n", moldyn->time,moldyn->ekin/energy_scale, @@ -1443,7 +1523,7 @@ return 0; get_total_energy(moldyn)/energy_scale); } if(m) { - if(!(i%m)) { + if(!(moldyn->total_steps%m)) { momentum=get_total_p(moldyn); dprintf(moldyn->mfd, "%f %f %f %f %f\n",moldyn->time, @@ -1452,7 +1532,7 @@ return 0; } } if(p) { - if(!(i%p)) { + if(!(moldyn->total_steps%p)) { dprintf(moldyn->pfd, "%f %f %f %f %f\n",moldyn->time, moldyn->p/BAR,moldyn->p_avg/BAR, @@ -1460,14 +1540,14 @@ return 0; } } if(t) { - if(!(i%t)) { + if(!(moldyn->total_steps%t)) { dprintf(moldyn->tfd, "%f %f %f\n", moldyn->time,moldyn->t,moldyn->t_avg); } } if(s) { - if(!(i%s)) { + if(!(moldyn->total_steps%s)) { snprintf(dir,128,"%s/s-%07.f.save", moldyn->vlsdir,moldyn->time); fd=open(dir,O_WRONLY|O_TRUNC|O_CREAT, @@ -1482,14 +1562,14 @@ return 0; } } if(v) { - if(!(i%v)) { + if(!(moldyn->total_steps%v)) { visual_atoms(&(moldyn->vis),moldyn->time, moldyn->atom,moldyn->count); } } /* display progress */ - if(!(i%10)) { + if(!(moldyn->total_steps%10)) { /* get current time */ gettimeofday(&t2,NULL); @@ -1975,6 +2055,96 @@ int analyze_bonds(t_moldyn *moldyn) { + return 0; +} + +/* + * visualization code + */ + +int visual_init(t_visual *v,char *filebase) { + + char file[128+8]; + + strncpy(v->fb,filebase,128); + memset(file,0,128+8); + + return 0; +} + +int visual_atoms(t_visual *v,double time,t_atom *atom,int n) { + + int i,fd; + char file[128+64]; + t_3dvec dim; + double help; + + dim.x=v->dim.x; + dim.y=v->dim.y; + dim.z=v->dim.z; + + help=(dim.x+dim.y); + + sprintf(file,"%s/atomic_conf_%07.f.xyz",v->fb,time); + fd=open(file,O_WRONLY|O_CREAT|O_TRUNC,S_IRUSR|S_IWUSR); + if(fd<0) { + perror("open visual save file fd"); + return -1; + } + + /* write the actual data file */ + dprintf(fd,"# [P] %d %07.f <%f,%f,%f>\n", + n,time,help/40.0,help/40.0,-0.8*help); + for(i=0;i