From 790e630a2446142efd37e8a416a1f44065ed697a Mon Sep 17 00:00:00 2001 From: hackbard Date: Wed, 17 Nov 2004 16:31:26 +0000 Subject: [PATCH] last changes, no more segfaults still need to find right parameter set --- dfe.c | 67 +++++++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 49 insertions(+), 18 deletions(-) diff --git a/dfe.c b/dfe.c index c507fa8..208b1a6 100644 --- a/dfe.c +++ b/dfe.c @@ -9,6 +9,10 @@ * * usage: ./dfe 100 50 2 1 1 10 * + * anmerkung frank: bisschen was ging so: ./dfe 1 5 2 1 1 10 + * ist auch schotter, aber mit richtigen parametern + * wirds. viel glueck!! + * * author: christian leirer, frank zirkelbach * * need api: cvs -d:pserver:anonymous@hackdaworld.dyndns.org:/my-code co api @@ -38,16 +42,16 @@ typedef struct s_gp { int main(int argc,char **argv) { - int x,y; + int x,y=0; int dx,dy; - int mx,my; + int mx=0,my=0; double lf[2]; double sf[2]; double mf; double lpp; int i; int size; - t_gp gp; + t_gp gp,cgp; t_gp *gp_ptr; t_list list; t_list_element *tmp; @@ -81,7 +85,7 @@ int main(int argc,char **argv) { fd=open("/dev/null",O_WRONLY); - list_init(&list,fd); + list_init(&list,1); size=X_*Y_; bmp_init(&bmp,1); @@ -90,7 +94,7 @@ int main(int argc,char **argv) { bmp.mode=WRITE; bmp_alloc_map(&bmp); - srandom(time(NULL)); + srand(time(NULL)); for(x=0;x=0&&ypp+=exp(-1.0*sqrt(x*x+y*y)/xi); - + lpp+=exp(-1.0*sqrt(x*x+y*y)/xi); } } } } + gp_ptr->pp=pp-lpp; if(lpp>(0.8*pp)) gp_ptr->status=FLUESSIG; else gp_ptr->status=FEST; list.current=tmp; @@ -129,6 +134,7 @@ int main(int argc,char **argv) { /* force on vortex */ list_reset(&list); + mf=0; do { lf[0]=0; lf[1]=0; sf[0]=0; sf[1]=0; @@ -145,16 +151,14 @@ int main(int argc,char **argv) { if(list_search_data(&list,&gp,2*sizeof(int))==L_SUCCESS) { memcpy(&gp,list.current->data,sizeof(t_gp)); if(gp.status&FEST) { - if(dy==0) sf[0]+=(-1.0/(dx*dx+dy*dy)*co*(dx/abs(dx))); - else if (dx==0) sf[1]+=(-1.0/(dx*dx+dy*dy)*co*(dy/abs(dy))); - /* hier ist die scheisse drin!! */ + if(dy==0) sf[0]+=(-1.0/(dx*dx)*co*(dx/abs(dx))); + else if (dx==0) sf[1]+=(-1.0/(dy*dy)*co*(dy/abs(dy))); else { - sf[0]+=(-1.0/(dx*dx+dy*dy)*co*dx/abs(dy)); - sf[1]+=(-1.0/(dx*dx+dy*dy)*co*dy/abs(dx)); + sf[0]+=(-1.0/(dx*dx+dy*dy)*co*1.0*dx/abs(dy)); + sf[1]+=(-1.0/(dx*dx+dy*dy)*co*1.0*dy/abs(dx)); } } else { - /* und hier wahrscheinlich auch */ if(dy==0) lf[0]+=(-1.0*(dx/abs(dx))*(by+co)); else if(dx==0) lf[1]+=(-1.0*(dy/abs(dy))*(by+co)); else{ @@ -169,6 +173,7 @@ int main(int argc,char **argv) { } gp_ptr->fx=sf[0]+lf[0]+((1.0*rand()/RAND_MAX)-0.5)/rs; gp_ptr->fy=sf[1]+lf[1]+((1.0*rand()/RAND_MAX)-0.5)/rs; + if(gp_ptr->y==0) gp_ptr->fy+=by; if(gp_ptr->status&FEST) { gp_ptr->fy+=(bf*exp(-y*1.0/100)); if(gp_ptr->fx>0) { @@ -188,7 +193,6 @@ int main(int argc,char **argv) { if(gp_ptr->fy>0) gp_ptr->fy=0; } } - if(gp_ptr->y==0) gp_ptr->fy+=by; /* wenn rand by dazu, arschloch !!1 */ if((mffx)||(mffy)) { mf=gp_ptr->fx>gp_ptr->fy?gp_ptr->fx:gp_ptr->fy; mx=gp_ptr->x; @@ -200,7 +204,7 @@ int main(int argc,char **argv) { /* move vortex with highest force */ gp.x=mx; gp.y=my; - printf("step %d: move vortex %d %d,",i,mx,my); + printf("step %d: want to move vortex %d %d,",i,mx,my); list_search_data(&list,&gp,2*sizeof(int)); gp_ptr=(t_gp *)list.current->data; dx=0; dy=0; @@ -213,9 +217,36 @@ int main(int argc,char **argv) { else dy=-1; } printf(" with direction dx=%d dy=%d | force: %f %f\n",dx,dy,gp_ptr->fx,gp_ptr->fy); - gp_ptr->x+=dx; - gp_ptr->y+=dy; - if(gp.y==0) list_add_element(&list,&gp,sizeof(t_gp)); + cgp.x=gp_ptr->x+dx; + cgp.y=gp_ptr->y+dy; + if(list_search_data(&list,&cgp,2*sizeof(int))==L_SUCCESS) { + printf("but there is allready a flussfaden! this parameter set suX!\n"); + } + else if(gp_ptr->y==0&&dy==-1) { + printf("but this wuld be stupid (out of target), skipped!\n"); + } + else { + printf("and i am doing it now! :)\n"); + gp_ptr->x+=dx; + gp_ptr->y+=dy; + if(gp.y==0) { + printf("adding moved flussfaden (y=0)\n"); + list_add_element(&list,&gp,sizeof(t_gp)); + } + } + if(gp_ptr->y==Y_-1) { + printf("flussfaden reached top of target, ending simulation!\n"); + return 1; + } + + /* + printf("alle flussfaden:\n"); + list_reset(&list); + do { + gp_ptr=(t_gp *)list.current->data; + printf("flussfaden bei %d %d\n",gp_ptr->x,gp_ptr->y); + } while(list_next(&list)!=L_NO_NEXT_ELEMENT); + */ /* plot every PLOT steps */ if(i%PLOT==0) { -- 2.39.2