added 2 newview modes: c conc & a pressure
[physik/nlsop.git] / nlsop.c
diff --git a/nlsop.c b/nlsop.c
index f548b54..e9d72ab 100644 (file)
--- a/nlsop.c
+++ b/nlsop.c
@@ -34,6 +34,7 @@ int usage(void)
  puts("usage:");
  puts("-h \t\t help");
  puts("-n \t\t no user interaction");
+ puts("-Z \t\t cryst -> amorph c diffusion in z direction");
  printf("-a <value> \t slope of nuclear energy loss (default %f)\n",A_EL);
  printf("-b <value> \t nuclear energy loss offset (default %f)\n",B_EL);
  printf("-x <value> \t # x cells (default %d)\n",X);
@@ -86,7 +87,7 @@ int process_cell(d3_lattice *d3_l,u32 x,u32 y,u32 z,int r,double a,double b,int
    } 
   }
  }
// printf("debug: p = %f\n",p);
+ printf("debug: p = %f\n",p);
  if(!(*thiz&AMORPH))
  {
   if(get_rand(URAND_MAX)<=p) MAKE_AMORPH(thiz);
@@ -101,7 +102,7 @@ int process_cell(d3_lattice *d3_l,u32 x,u32 y,u32 z,int r,double a,double b,int
  return 1;
 }
 
-int distrib_c(d3_lattice *d3_l,double d_r,double a,double b)
+int distrib_c(d3_lattice *d3_l,double d_r,double a,double b,char z_diff)
 {
  u32 x,y,z;
  int i,j,k,c;
@@ -191,6 +192,39 @@ int distrib_c(d3_lattice *d3_l,double d_r,double a,double b)
        }
       }
      }
+     for(c=-1;c<=1;c++)
+     {
+      if(c!=0)
+      {
+       off=((i+c+d3_l->max_x)%d3_l->max_x)+j*d3_l->max_x+k*d3_l->max_x*d3_l->max_y;
+       carry=0;
+       /* case neighbour not amorph */
+       if(!(*(d3_l->status+off)&AMORPH))
+       {
+       carry=(*(d3_l->extra+off)-*(d3_l->extra+offset))/2;
+       if(carry!=0)
+        {
+         *(d3_l->extra+offset)+=carry;
+        *(d3_l->extra+off)-=carry;
+       }
+       }
+      }
+     }
+     /* cryst -> amorph diffusion in z direction */
+     if(z_diff)
+     {
+      for(c=1;c>=-1;c--)
+      {
+       off=i+j*d3_l->max_x+((k+c+d3_l->max_z)%d3_l->max_z)*d3_l->max_x*d3_l->max_y;
+       carry=0;
+       if(*(d3_l->status+off)&AMORPH) carry=(int)(d_r*(*(d3_l->extra+offset)));
+       if(carry!=0)
+       {
+        *(d3_l->extra+offset)-=carry;
+       *(d3_l->extra+off)+=carry;
+       }
+      }
+     } /* if z_diff */
     }
    } /* for z */
   } /* for y */
@@ -199,6 +233,38 @@ int distrib_c(d3_lattice *d3_l,double d_r,double a,double b)
  return 1;
 }
 
+int calc_pressure(d3_lattice *d3_l,int range)
+{
+ int i,j,off;
+ double count;
+ int x,y,z;
+
+ for(x=0;x<d3_l->max_x;x++)
+ {
+  for(y=0;y<d3_l->max_y;y++)
+  {
+   for(z=0;z<d3_l->max_z;z++)
+   {
+    count=0;
+    for(i=-range;i<=range;i++)
+    {
+     for(j=-range;j<=range;j++)
+     {
+      if(i!=0 && j!=0)
+      {
+       off=((x+d3_l->max_x+i)%d3_l->max_x)+((y+d3_l->max_y+j)%d3_l->max_x)*d3_l->max_x+z*d3_l->max_x*d3_l->max_y;
+       if(*(d3_l->status+off)&AMORPH) count+=((double)*(d3_l->extra+off))/(i*i+j*j);
+      }
+     }
+    }
+    *(unsigned char *)(d3_l->v_ptr+x+y*d3_l->max_x+z*d3_l->max_x*d3_l->max_y)=(unsigned char)(count*255/MAX_VPTR);
+   }
+  }
+ }
+
+ return 1;
+}
+
 int distrib_c_old(d3_lattice *d3_l,int t_c,double a,double b)
 {
  int i,j,k,total,area;
@@ -370,14 +436,16 @@ int convert_file(char *cf,d3_lattice *d3_l)
 int main(int argc,char **argv)
 {
  u32 x,y,z,x_c,y_c,z_c;
- int i,quit,escape,nowait;
+ int i,quit,escape,switchmode,nowait;
  int refresh,resave;
+ char z_diff;
  char s_file[MAX_CHARS];
  char s_file_tmp[MAX_CHARS];
  char l_file[MAX_CHARS];
  char c_file[MAX_CHARS];
  char convert;
  char r_file[MAX_CHARS];
+#ifdef USE_DFB_API
  char x_txt[MAX_TXT];
  char y_txt[MAX_TXT];
  char z_txt[MAX_TXT];
@@ -395,9 +463,12 @@ int main(int argc,char **argv)
  char cd2_txt[MAX_TXT];
  char el2_txt[MAX_TXT];
  char dr_txt[MAX_TXT];
+ char mode_txt[MAX_TXT];
  char *arg_v[MAX_ARGV];
+#endif
  d3_lattice d3_l;
  info my_info;
+ unsigned char mode;
 
  d3_l.max_x=X;
  d3_l.max_y=Y;
@@ -406,6 +477,7 @@ int main(int argc,char **argv)
  my_info.range=RANGE;
  refresh=REFRESH;
  resave=RESAVE;
+ z_diff=0;
  my_info.a_el=A_EL;
  my_info.b_el=B_EL;
  my_info.a_cd=A_CD;
@@ -417,11 +489,13 @@ int main(int argc,char **argv)
  nowait=0;
  quit=0;
  escape=0;
+ switchmode=0;
  strcpy(s_file,"");
  strcpy(l_file,"");
  strcpy(c_file,"");
  convert=0;
  strcpy(r_file,"");
+ mode=0;
 
  for(i=1;i<argc;i++)
  {
@@ -457,10 +531,11 @@ int main(int argc,char **argv)
     case 'Y':
      y=atoi(argv[++i]);
      break;
+    */
     case 'Z':
-     z=atoi(argv[++i]);
+     z_diff=1;
      break;
-    */
+    /* */
     case 's':
      my_info.steps=atoi(argv[++i]);
      break;
@@ -567,6 +642,7 @@ int main(int argc,char **argv)
  d3_event_init(&d3_l);
 #endif
 
+#ifdef USE_DFB_API
  strcpy(a_txt,"args:");
  sprintf(s_txt,"steps: %d",my_info.steps);
  sprintf(r_txt,"pressure range: %d",my_info.range);
@@ -577,6 +653,7 @@ int main(int argc,char **argv)
  sprintf(cd_txt,"c distrib slope: %.2f",my_info.a_cd);
  sprintf(cd2_txt,"c distrib offset: %.2f",my_info.b_cd);
  sprintf(dr_txt,"diffusion rate: %.2f",my_info.d_r);
+ strcpy(mode_txt,"view: a/c mode");
  arg_v[1]=x_txt;
  arg_v[2]=y_txt;
  arg_v[3]=z_txt;
@@ -584,7 +661,7 @@ int main(int argc,char **argv)
  arg_v[5]=status_txt;
  arg_v[6]=conc_txt;
  arg_v[7]=NULL;
- arg_v[8]=NULL;
+ arg_v[8]=mode_txt;
  arg_v[9]=NULL;
  arg_v[10]=steps_txt;;
  arg_v[11]=cc_txt;
@@ -601,6 +678,7 @@ int main(int argc,char **argv)
  arg_v[22]=cd_txt;
  arg_v[23]=cd2_txt;
  arg_v[24]=dr_txt;
+#endif
 
  if(!strcmp(l_file,""))
  {
@@ -610,8 +688,9 @@ int main(int argc,char **argv)
    x_c=get_rand(d3_l.max_x);
    y_c=get_rand(d3_l.max_y);
    z_c=get_rand_lgp(d3_l.max_z,my_info.a_el,my_info.b_el);
-   distrib_c(&d3_l,my_info.d_r,my_info.a_cd,my_info.b_cd);
+   distrib_c(&d3_l,my_info.d_r,my_info.a_cd,my_info.b_cd,z_diff);
    process_cell(&d3_l,x_c,y_c,z_c,my_info.range,my_info.a_ap,my_info.b_ap,&(my_info.cc));
+#ifdef USE_DFB_API
    if(i%refresh==0)
    {
     sprintf(x_txt,"x: %d",x+1);
@@ -621,24 +700,44 @@ int main(int argc,char **argv)
     sprintf(conc_txt,"conc: %d",*(d3_l.extra+x+y*d3_l.max_x+z*d3_l.max_x*d3_l.max_y));
     sprintf(steps_txt,"step: %d",i);
     sprintf(cc_txt,"total c: %d",my_info.cc);
-#ifdef USE_DFB_API
-    d3_lattice_draw(&d3_l,x,y,z,24,arg_v);
-#endif
-    // scan_event(&d3_l,&x,&y,&z,&quit,&escape);
+    d3_lattice_draw(&d3_l,x,y,z,24,arg_v,mode);
    }
+#endif
    if(i%resave==0 && strcmp(s_file,"") && resave!=0)
    {
     sprintf(s_file_tmp,"%s_%d_of_%d",s_file,i,my_info.steps);
     save_to_file(s_file_tmp,&d3_l,&my_info);
+#ifdef NODFB
+    printf("saved %s\n",s_file_tmp);
+#endif
    }
    i++;
   }
  }
 
- if(strcmp(s_file,"")) save_to_file(s_file,&d3_l,&my_info);
+ if(strcmp(s_file,""))
+ {
+   printf("saved %s\n",s_file);
+   save_to_file(s_file,&d3_l,&my_info);
+ }
+
+#ifdef USE_DFB_API
+ /* allocating buffer for pressure values */
+ if((d3_l.v_ptr=malloc(d3_l.max_x*d3_l.max_y*d3_l.max_z*sizeof(unsigned char)))==NULL)
+ {
+  puts("cannot allocate buffer for pressure values");
+  return -1;
+ }
+ /* calc values */
+ calc_pressure(&d3_l,my_info.range);
 
  while((quit==0) && (escape==0) && (nowait==0))
  {
+  /* bahh! */
+  if(switchmode==0) mode=0;
+  if(switchmode==1) mode=1;
+  if(switchmode==2) mode=2;
+  /* end of bahh! */
   sprintf(x_txt,"x: %d",x+1);
   sprintf(y_txt,"y: %d",y+1);
   sprintf(z_txt,"z: %d",z+1);
@@ -646,13 +745,13 @@ int main(int argc,char **argv)
   sprintf(conc_txt,"conc: %d",*(d3_l.extra+x+y*d3_l.max_x+z*d3_l.max_x*d3_l.max_y));
   strcpy(steps_txt,"step: end!");
   sprintf(cc_txt,"total c: %d",my_info.cc);
-#ifdef USE_DFB_API
-  d3_lattice_draw(&d3_l,x,y,z,24,arg_v);
-  scan_event(&d3_l,&x,&y,&z,&quit,&escape);
-#endif
+  if(switchmode==0) strcpy(mode_txt,"view: a/c mode");
+  if(switchmode==1) strcpy(mode_txt,"view: c conc mode");
+  if(switchmode==2) strcpy(mode_txt,"view: a pressure mode");
+  d3_lattice_draw(&d3_l,x,y,z,24,arg_v,mode);
+  scan_event(&d3_l,&x,&y,&z,&quit,&escape,&switchmode);
  }
 
-#ifdef USE_DFB_API
  d3_lattice_release(&d3_l);
 #endif