]> hackdaworld.org Git - physik/dfe.git/commitdiff
initial checkin
authorhackbard <hackbard>
Tue, 16 Nov 2004 16:40:28 +0000 (16:40 +0000)
committerhackbard <hackbard>
Tue, 16 Nov 2004 16:40:28 +0000 (16:40 +0000)
.cvsignore [new file with mode: 0644]
dfe.c [new file with mode: 0644]

diff --git a/.cvsignore b/.cvsignore
new file mode 100644 (file)
index 0000000..a8b9ca8
--- /dev/null
@@ -0,0 +1,4 @@
+list.*
+bmp.*
+dfe
+*.bmp
diff --git a/dfe.c b/dfe.c
new file mode 100644 (file)
index 0000000..42e2abf
--- /dev/null
+++ b/dfe.c
@@ -0,0 +1,242 @@
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <math.h>
+#include <time.h>
+#include <stdlib.h>
+
+/*
+ * compile: gcc -Wall -o dfe dfe.c bmp.c list.c -O3 -lm
+ *
+ * usage: ./dfe 100 50 2 1 1 10
+ *
+ * author: christian leirer, frank zirkelbach
+ *
+ * need api: cvs -d:pserver:anonymous@hackdaworld.dyndns.org:/my-code co api
+ * 
+ */
+
+#include "list.h"
+#include "bmp.h"
+
+typedef struct s_gp {
+  int x,y;
+  unsigned char status;
+#define FLUESSIG 0
+#define FEST 1
+  double fx,fy;
+  double op;
+  double pp;
+} t_gp;
+
+#define RANGE 10
+
+#define X_ 500
+#define Y_ 50
+
+#define STEPS 1000
+#define PLOT 10
+
+int main(int argc,char **argv) {
+
+  int x,y;
+  int dx,dy;
+  int mx,my;
+  double lf[2];
+  double sf[2];
+  double mf;
+  double lpp;
+  int i;
+  int size;
+  t_gp gp;
+  t_gp *gp_ptr;
+  t_list list;
+  t_list_element *tmp;
+  t_bmp bmp;
+  char string[128];
+  int fd;
+
+  double by;
+  double pp;
+  double xi;
+  double rs;
+  double co;
+  double bf;
+
+  /* parse argv */
+
+  if(argc!=7) {
+    printf("usage: %s <b-feld> <p-pot> <xi> <rand-scale> <coulomb> <b-force>\n",
+           argv[0]);
+    return -1;
+  }
+  
+  by=atof(argv[1]);
+  pp=atof(argv[2]);
+  xi=atof(argv[3]);
+  rs=atof(argv[4]);
+  co=atof(argv[5]);
+  bf=atof(argv[6]);
+
+  /* init */
+
+  fd=open("/dev/null",O_WRONLY);
+
+  list_init(&list,fd);
+
+  size=X_*Y_;
+  bmp_init(&bmp,1);
+  bmp.width=X_;
+  bmp.height=Y_;
+  bmp.mode=WRITE;
+  bmp_alloc_map(&bmp);
+
+  srandom(time(NULL));
+
+  for(x=0;x<X_;x++) {
+    memset(&gp,0,sizeof(t_gp));
+    //gp.status=FEST;
+    gp.x=x; gp.y=0;
+    list_add_element(&list,&gp,sizeof(t_gp));
+  }
+
+  /* mainloop */
+  for(i=0;i<STEPS;i++) {
+    /* determine status of vortex, liquid or solid */
+    list_reset(&list);
+    do {
+      lpp=0;
+      gp_ptr=(t_gp *)list.current->data;
+      tmp=list.current;
+      for(dx=-RANGE;dx<=RANGE;dx++) {
+        for(dy=-RANGE;dy<=RANGE;dy++) {
+          if((dx!=0)||(dy!=0)) {
+            x=(gp_ptr->x+X_+dx)%X_;
+            y=gp_ptr->y+dy;
+            if(y>=0) {
+              gp.x=x; gp.y=y;
+              if(list_search_data(&list,&gp,2*sizeof(int))==L_SUCCESS)
+                gp_ptr->pp+=exp(-1.0*sqrt(x*x+y*y)/xi);
+               
+            }
+          }
+        }
+      }
+      if(lpp>(0.8*pp)) gp_ptr->status=FLUESSIG;
+      else gp_ptr->status=FEST;
+      list.current=tmp;
+    }  
+    while(list_next(&list)!=L_NO_NEXT_ELEMENT);
+
+    /* force on vortex */
+    list_reset(&list);
+    do {
+      lf[0]=0; lf[1]=0;
+      sf[0]=0; sf[1]=0;
+     
+      tmp=list.current;
+      bf=0;
+      gp_ptr=(t_gp *)list.current->data;
+      for(dx=-RANGE;dx<=RANGE;dx++) {
+        for(dy=-RANGE;dy<=RANGE;dy++) {
+          if((dx!=0)||(dy!=0)) {
+            x=(gp_ptr->x+X_+dx)%X_;
+            y=gp_ptr->y+dy;
+            if(y>=0&&y<Y_) {
+              gp.x=x; gp.y=y;
+              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!! */
+                  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));
+                 }
+                }
+                else {
+                  /* und hier wahrscheinlich auch */
+                  if(dy==0) lf[0]+=(-1.0*(dx/abs(dx))*(by+co));
+                  if(dx==0) lf[1]+=(-1.0*(dy/abs(dy))*(by+co));
+                 else{
+                    lf[0]+=(-1.0*dx/abs(dy)*(by+co));
+                    lf[1]+=(-1.0*dy/abs(dx)*(by+co));
+                 }
+                }
+              }
+            }
+          }
+        }
+      }
+      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->status&FEST) {
+        gp_ptr->fy+=(bf*exp(-y/100));
+        if(gp_ptr->fx>0) {
+          gp_ptr->fx-=gp_ptr->pp;
+         if(gp_ptr->fx<0) gp_ptr->fx=0;
+       }
+       else {
+          gp_ptr->fx+=gp_ptr->pp;
+          if(gp_ptr->fx>0) gp_ptr->fx=0;
+        }
+        if(gp_ptr->fy>0) {
+          gp_ptr->fy-=gp_ptr->pp;
+          if(gp_ptr->fy<0) gp_ptr->fy=0;
+        }
+       else {
+          gp_ptr->fy+=gp_ptr->pp;
+          if(gp_ptr->fy>0) gp_ptr->fx=0;
+        }
+      }
+      if(gp_ptr->y==0) gp_ptr->fy+=by; /* wenn rand by dazu, arschloch !!1 */
+      if((mf<gp_ptr->fx)||(mf<gp_ptr->fy)) {
+        mf=gp_ptr->fx>gp_ptr->fy?gp_ptr->fx:gp_ptr->fy;
+        mx=gp_ptr->x;
+        my=gp_ptr->y;
+      }
+      list.current=tmp;
+    }
+    while(list_next(&list)!=L_NO_NEXT_ELEMENT);
+
+    /* move vortex with highest force */
+    gp.x=mx; gp.y=my;
+    printf("step %d: 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;
+    if(fabs(gp_ptr->fx)>fabs(gp_ptr->fy)) {
+      if(gp_ptr->fx>0) dx=1;
+      else dx=-1;
+    }
+    else {
+      if(gp_ptr->fy>0) dy=1;
+      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));
+
+    /* plot every PLOT steps */
+    if(i%PLOT==0) {
+      memset(bmp.map,0,3*size*sizeof(unsigned char));
+      list_reset(&list);
+      do {
+        gp_ptr=(t_gp *)list.current->data;
+        if(gp_ptr->status&FEST)
+          memset(bmp.map+gp_ptr->y*X_+gp_ptr->x,0xff,1);
+        else
+          memset(bmp.map+gp_ptr->y*X_+gp_ptr->x,0xff,3);
+      } while(list_next(&list)!=L_NO_NEXT_ELEMENT);
+      sprintf(string,"dfe_%d_of_%d.bmp",i,STEPS);
+      strcpy(bmp.file,string);
+      bmp_write_file(&bmp);
+    }
+
+  }
+
+  close(fd);
+
+  return 1;
+}