X-Git-Url: https://hackdaworld.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;ds=sidebyside;f=moldyn.c;h=707fe032e2e51f87a13800e717f33a461f5e85b7;hb=c38fe34069adb9697683235f8b1e2311a3122e8f;hp=4b580890f3eaab417494fa497130f53570130ce4;hpb=e6f456c0fa807b86e1b25996e70efcdcfe390ea5;p=physik%2Fposic.git diff --git a/moldyn.c b/moldyn.c index 4b58089..707fe03 100644 --- a/moldyn.c +++ b/moldyn.c @@ -35,6 +35,7 @@ int moldyn_usage(char **argv) { printf("--- physics options ---\n"); printf("-T [K] (%f)\n",MOLDYN_TEMP); printf("-t [s] (%.15f)\n",MOLDYN_TAU); + printf("-C [m] (%.15f)\n",MOLDYN_CUTOFF); printf("-R (%d)\n",MOLDYN_RUNS); printf(" -- integration algo --\n"); printf(" -I (%d)\n",MOLDYN_INTEGRATE_DEFAULT); @@ -98,6 +99,9 @@ int moldyn_parse_argv(t_moldyn *moldyn,int argc,char **argv) { case 't': moldyn->tau=atof(argv[++i]); break; + case 'C': + moldyn->cutoff=atof(argv[++i]); + break; case 'R': moldyn->time_steps=atoi(argv[++i]); break; @@ -153,12 +157,12 @@ int moldyn_parse_argv(t_moldyn *moldyn,int argc,char **argv) { return 0; } -int moldyn_log_init(t_moldyn *moldyn,void *v) { +int moldyn_log_init(t_moldyn *moldyn) { moldyn->lvstat=0; t_visual *vis; - vis=v; + vis=&(moldyn->vis); if(moldyn->ewrite) { moldyn->efd=open(moldyn->efb,O_WRONLY|O_CREAT|O_TRUNC); @@ -204,7 +208,7 @@ int moldyn_log_init(t_moldyn *moldyn,void *v) { return 0; } -int moldyn_shutdown(t_moldyn *moldyn) { +int moldyn_log_shutdown(t_moldyn *moldyn) { if(moldyn->efd) close(moldyn->efd); if(moldyn->mfd) close(moldyn->efd); @@ -214,6 +218,33 @@ int moldyn_shutdown(t_moldyn *moldyn) { return 0; } +int moldyn_init(t_moldyn *moldyn,int argc,char **argv) { + + int ret; + + ret=moldyn_parse_argv(moldyn,argc,argv); + if(ret<0) return ret; + + ret=moldyn_log_init(moldyn); + if(ret<0) return ret; + + rand_init(&(moldyn->random),NULL,1); + moldyn->random.status|=RAND_STAT_VERBOSE; + + moldyn->status=0; + + return 0; +} + +int moldyn_shutdown(t_moldyn *moldyn) { + + moldyn_log_shutdown(moldyn); + rand_close(&(moldyn->random)); + free(moldyn->atom); + + return 0; +} + int create_lattice(unsigned char type,int element,double mass,double lc, int a,int b,int c,t_atom **atom) { @@ -270,7 +301,7 @@ int destroy_lattice(t_atom *atom) { return 0; } -int thermal_init(t_moldyn *moldyn,t_random *random) { +int thermal_init(t_moldyn *moldyn) { /* * - gaussian distribution of velocities @@ -282,8 +313,10 @@ int thermal_init(t_moldyn *moldyn,t_random *random) { double v,sigma; t_3dvec p_total,delta; t_atom *atom; + t_random *random; atom=moldyn->atom; + random=&(moldyn->random); /* gaussian distribution of velocities */ v3_zero(&p_total); @@ -402,9 +435,13 @@ double estimate_time_step(t_moldyn *moldyn,double nn_dist,double t) { int link_cell_init(t_moldyn *moldyn) { t_linkcell *lc; + int i; lc=&(moldyn->lc); + /* list log fd */ + lc->listfd=open("/dev/null",O_WRONLY); + /* partitioning the md cell */ lc->nx=moldyn->dim.x/moldyn->cutoff; lc->x=moldyn->dim.x/lc->nx; @@ -413,7 +450,14 @@ int link_cell_init(t_moldyn *moldyn) { lc->nz=moldyn->dim.z/moldyn->cutoff; lc->z=moldyn->dim.z/lc->nz; - lc->subcell=malloc(lc->nx*lc->ny*lc->nz*sizeof(t_list)); + lc->cells=lc->nx*lc->ny*lc->nz; + lc->subcell=malloc(lc->cells*sizeof(t_list)); + + printf("initializing linked cells (%d)\n",lc->cells); + + for(i=0;icells;i++) + list_init(&(lc->subcell[i]),1); + //list_init(&(lc->subcell[i]),lc->listfd); link_cell_update(moldyn); @@ -434,13 +478,13 @@ int link_cell_update(t_moldyn *moldyn) { ny=lc->ny; nz=lc->nz; - for(i=0;icells;i++) list_destroy(&(moldyn->lc.subcell[i])); for(count=0;countcount;count++) { - i=atom[count].r.x/lc->x; - j=atom[count].r.y/lc->y; - k=atom[count].r.z/lc->z; + i=(atom[count].r.x+(moldyn->dim.x/2))/lc->x; + j=(atom[count].r.y+(moldyn->dim.y/2))/lc->y; + k=(atom[count].r.z+(moldyn->dim.z/2))/lc->z; list_add_immediate_ptr(&(moldyn->lc.subcell[i+j*nx+k*nx*ny]), &(atom[count])); } @@ -461,12 +505,14 @@ int link_cell_neighbour_index(t_moldyn *moldyn,int i,int j,int k,t_list *cell) { lc=&(moldyn->lc); nx=lc->nx; ny=lc->ny; - nx=lc->nz; + nz=lc->nz; count1=1; count2=27; a=nx*ny; + cell[0]=lc->subcell[i+j*nx+k*a]; + printf("%d\n",i+j*nx+k*a); for(ci=-1;ci<=1;ci++) { bx=0; x=i+ci; @@ -488,12 +534,17 @@ int link_cell_neighbour_index(t_moldyn *moldyn,int i,int j,int k,t_list *cell) { z=(z+nz)%nz; bz=1; } - if(!(x|y|z)) continue; + if(!(ci|cj|ck)) continue; + printf(" %d %d %d \n",x,y,z); if(bx|by|bz) { cell[--count2]=lc->subcell[x+y*nx+z*a]; + printf("%d\n",x+y*nx+z*a); + printf("--- %d\n",count2); } else { cell[count1++]=lc->subcell[x+y*nx+z*a]; + printf("%d\n",x+y*nx+z*a); + printf("--- %d\n",count1); } } } @@ -512,6 +563,8 @@ int link_cell_shutdown(t_moldyn *moldyn) { for(i=0;inx*lc->ny*lc->nz;i++) list_shutdown(&(moldyn->lc.subcell[i])); + if(lc->listfd) close(lc->listfd); + return 0; } @@ -548,15 +601,10 @@ int moldyn_integrate(t_moldyn *moldyn) { moldyn->tau_square=moldyn->tau*moldyn->tau; moldyn->cutoff_square=moldyn->cutoff*moldyn->cutoff; - /* create the neighbour list */ - link_cell_update(moldyn); - /* calculate initial forces */ moldyn->potential_force_function(moldyn); for(i=0;itime_steps;i++) { - /* show runs */ - printf("."); /* neighbour list update */ link_cell_update(moldyn); @@ -599,9 +647,12 @@ int moldyn_integrate(t_moldyn *moldyn) { } if(v) { - if(!(i%v)) + if(!(i%v)) { visual_atoms(moldyn->visual,i*moldyn->tau, moldyn->atom,moldyn->count); + printf("\rsteps: %d",i); + fflush(stdout); + } } } @@ -679,9 +730,10 @@ int harmonic_oscillator(t_moldyn *moldyn) { u=0.0; for(i=0;ix; - nj=atom[i].r.y/lc->y; - nk=atom[i].r.z/lc->z; + ni=(atom[i].r.x+(moldyn->dim.x/2))/lc->x; + nj=(atom[i].r.y+(moldyn->dim.y/2))/lc->y; + nk=(atom[i].r.z+(moldyn->dim.z/2))/lc->z; + printf("%d %d %d\n",ni,nj,nk); c=link_cell_neighbour_index(moldyn,ni,nj,nk,neighbour); /* processing cell of atom i */ @@ -775,10 +827,15 @@ int lennard_jones(t_moldyn *moldyn) { u=0.0; for(i=0;ix; - nj=atom[i].r.y/lc->y; - nk=atom[i].r.z/lc->z; + ni=(atom[i].r.x+(moldyn->dim.x/2))/lc->x; + nj=(atom[i].r.y+(moldyn->dim.y/2))/lc->y; + nk=(atom[i].r.z+(moldyn->dim.z/2))/lc->z; + printf("hier atom = %08x\n",&(atom[i])); c=link_cell_neighbour_index(moldyn,ni,nj,nk,neighbour); + printf("da atom = %08x\n",&(atom[i])); + printf("da atom = %08x\n",&(moldyn->atom[i])); + + printf("c = %d (%d %d %d)\n",c,ni,nj,nk); /* processing cell of atom i */ this=&(neighbour[0]); @@ -787,7 +844,9 @@ int lennard_jones(t_moldyn *moldyn) { btom=this->current->data; if(btom==&(atom[i])) continue; + puts("foo"); v3_sub(&distance,&(atom[i].r),&(btom->r)); + puts("foo"); d=1.0/v3_absolute_square(&distance); /* 1/r^2 */ h1=d*d; /* 1/r^4 */ h2*=d; /* 1/r^6 */ @@ -801,6 +860,7 @@ int lennard_jones(t_moldyn *moldyn) { d*=eps; v3_scale(&force,&distance,d); v3_add(&(atom[i].f),&(atom[i].f),&force); + printf("test!!\n"); } while(list_next(this)!=L_NO_NEXT_ELEMENT); /* neighbours not doing boundary condition overflow */ @@ -810,6 +870,7 @@ int lennard_jones(t_moldyn *moldyn) { if(this->start!=NULL) { do { + printf("in bound: %d\n",j); btom=this->current->data; v3_sub(&distance,&(atom[i].r),&(btom->r)); d=v3_absolute_square(&distance); /* r^2 */ @@ -841,6 +902,7 @@ int lennard_jones(t_moldyn *moldyn) { if(this->start!=NULL) { do { + printf("out bound: %d\n",j); btom=this->current->data; v3_sub(&distance,&(atom[i].r),&(btom->r)); v3_per_bound(&distance,&(moldyn->dim));