fixed cryst->amorph z direction diffusion bug
[physik/nlsop.git] / nlsop.c
diff --git a/nlsop.c b/nlsop.c
index 9f25c7a..d61d2ac 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);
@@ -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 */
@@ -372,12 +406,14 @@ int main(int argc,char **argv)
  u32 x,y,z,x_c,y_c,z_c;
  int i,quit,escape,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];
@@ -396,6 +432,7 @@ int main(int argc,char **argv)
  char el2_txt[MAX_TXT];
  char dr_txt[MAX_TXT];
  char *arg_v[MAX_ARGV];
+#endif
  d3_lattice d3_l;
  info my_info;
 
@@ -406,6 +443,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;
@@ -457,10 +495,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;
@@ -612,7 +651,7 @@ 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)