-
authorhackbard <hackbard>
Thu, 3 Apr 2003 13:32:42 +0000 (13:32 +0000)
committerhackbard <hackbard>
Thu, 3 Apr 2003 13:32:42 +0000 (13:32 +0000)
Makefile
defines.h
main.c
random.c

index e2b0539..ad7af49 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -14,3 +14,5 @@ all: morpheus
 
 clean:
        rm $(OBJS) $(OBJS2)
+
+remake: clean all
index 58befa1..a886a60 100644 (file)
--- a/defines.h
+++ b/defines.h
@@ -28,6 +28,8 @@
 
 #define DEFAULT_STEPS 5000
 
+#define RAND_BUF_SIZE 1048576 /* 1 MB */
+
 /* program defines, dont touch ;) */
 
 #define URAND_MAX 0xffffffff
diff --git a/main.c b/main.c
index 2e9cc0c..6916f22 100644 (file)
--- a/main.c
+++ b/main.c
@@ -26,6 +26,7 @@
 #include "display.h"
 
 /* global variables */
+u32 *rand_buf,*rand_current;
 u32 gr;
 int random_fd; /* /dev/urandom file descriptor */
 
@@ -65,10 +66,8 @@ int make_cryst(cell *cell)
 
 int distrib_c_conc(cell *cell_p,int c_c0,int c_slope,u32 c_conc,u32 x_max,u32 y_max,u32 z_max)
 {
- /* cryst. c to distribute */
-
  int i,j;
- u32 area,c_area,total;
+ u32 area,c_area,total,count;
  u32 x,y,z,sum_c_z;
 
  total=0;
@@ -77,17 +76,22 @@ int distrib_c_conc(cell *cell_p,int c_c0,int c_slope,u32 c_conc,u32 x_max,u32 y_
 
  for(i=0;i<z_max;i++)
  {
+  count=0;
   c_area=(c_conc*(c_c0+(i+1)*c_slope))/sum_c_z;
   for(j=0;j<area;j++)
-  { 
+  {
+   if(!(cell_p+j+i*area)->status&AMORPH) count++; 
+  }
+  for(j=0;j<area;j++)
+  {
    if(!(cell_p+j+i*area)->status&AMORPH)
    { 
-    (cell_p+j+i*area)->conc=c_area/area;
-    total+=c_area/area;
+    (cell_p+j+i*area)->conc=c_area/count;
+    total+=c_area/count;
    }
   }
   j=0;
-  while(j<c_area%area)
+  while(j<c_area%count)
   {
    x=rand_get(x_max);
    y=rand_get(y_max);
@@ -120,8 +124,10 @@ int process_cell(cell *cell_p,u32 x,u32 y,u32 z,u32 x_max,u32 y_max,u32 z_max,in
  cell *this_cell;
  int i,j,k;
  double pressure;
+
  this_cell=cell_p+x+y*x_max+z*x_max*y_max;
  pressure=p0*URAND_2BYTE_MAX;
+
  for(i=-range;i<=range;i++)
  {
   for(j=-range;j<=range;j++)
@@ -136,6 +142,7 @@ int process_cell(cell *cell_p,u32 x,u32 y,u32 z,u32 x_max,u32 y_max,u32 z_max,in
    }
   }
  }
+ pressure*=this_cell->conc;
  if(this_cell->status&AMORPH)
  {
   /* wrong probability! just test by now ...*/
@@ -271,11 +278,20 @@ int main(int argc,char **argv)
  for(i=1;i<=z_cell;i++) gr+=i;
  printfd("debug: gr = %d\n",gr);
 
+ /* allocate random number buffer */
+ printf("malloc will free %d bytes now ...\n",RAND_BUF_SIZE);
+ if((rand_buf=(u32 *)malloc(RAND_BUF_SIZE))==NULL)
+ {
+  puts("failed allocating memory for random numbers");
+  return -23;
+ }
+ rand_current=rand_buf+RAND_BUF_SIZE;
+
  /* allocate cells */
  printf("malloc will free %d bytes now ...\n",x_cell*y_cell*z_cell*sizeof(cell));
  if((cell_p=(cell *)malloc(x_cell*y_cell*z_cell*sizeof(cell)))==NULL)
  {
-  puts("failed allocating memory for cells\n");
+  puts("failed allocating memory for cells");
   return -23;
  }
  memset(cell_p,0,x_cell*y_cell*z_cell*sizeof(cell));
@@ -291,9 +307,10 @@ int main(int argc,char **argv)
   x=rand_get(x_cell);
   y=rand_get(y_cell);
   z=rand_get_lgp(slope_nel,start_nel,z_cell);
+  printfd("x = %u, y = %u, z = %u\n",x,y,z);
 
   /* todo */
-  // distrib_c_conc(cell_p,c_dist_c0,c_dist_slope,c_conc,x_cell,y_cell,z_cell);
+  distrib_c_conc(cell_p,c_dist_c0,c_dist_slope,c_conc,x_cell,y_cell,z_cell);
 
   // process_cell(cell_p+x+y*x_cell+z*x_cell*y_cell);
   process_cell(cell_p,x,y,z,x_cell,y_cell,z_cell,a_p_range,a_p_faktor,a_p_p0,&c_conc);
index 51f6774..5657eed 100644 (file)
--- a/random.c
+++ b/random.c
 /* global and extern variables */
 extern u32 gr;
 extern int random_fd;
+extern u32 *rand_buf,*rand_current;
 
 /* return random integer between 0 - max-1 */
 u32 rand_get(u32 max) 
 {
- u32 rand_int;
- if(read(random_fd,&rand_int,4)!=4)
+ if(rand_current==rand_buf+RAND_BUF_SIZE)
  {
-  puts("failed reading 4 bytes of random data");
-  return -23;
+  printfd("debug: reading new random bytes\n");
+  if(read(random_fd,rand_buf,RAND_BUF_SIZE)!=RAND_BUF_SIZE)
+  {
+   puts("failed reading viel bytes of random data");
+   return -23;
+  }
+  rand_current=rand_buf;
  }
  /* cells numbered 0...max-1 */
- return((u32)(rand_int*(max*1.0/URAND_MAX)));
+ return((u32)(*(rand_current++)*(max*1.0/URAND_MAX)));
 }
 
 /* get z value (linear growth of probability with depths) */
@@ -40,4 +45,3 @@ u32 rand_get_lgp(int slope_nel,int start_nel,u32 z_max)
  return(i-1); /* return values 0...z_cell-1 */
 }
 
-