2

我正在尝试实现本文中描述的模型模拟了 Alan Turing 提出的二维 FitzHugh-Nagumo 模型的方程,作为形成动物皮肤图案的模型——换句话说:模拟两种物质在表面上扩散,它们如何相互作用,以及出现什么模式。这是论文的结果:

                                            在此处输入图像描述

我已经在 Processing/Java 中实现了它(至少我的解释),但它并没有像它应该的那样工作(值有很多不同,即使是第一次迭代),所以我想知道我的实现出了什么问题(包括在帖子的末尾)。


这些是论文中关于实施的 3 个相关部分:

1. U&V

有两种物质,u 和 v(可以分别认为是活化剂和抑制剂) 在此处输入图像描述

2. 有限差分方程

为uv的每个值(像素)定义了一个相当简单的像素卷积。下一代给定像素的值是使用它及其邻居的当前迭代值计算的。

给定像素 (i,j) 在 n+1 次迭代中的u值定义为: 在此处输入图像描述

给定像素 (i,j) 在 n+1 次迭代中的v值定义为: 在此处输入图像描述

3. 他们使用的常数

在此处输入图像描述


所以我遇到的问题是uv的值迅速发散到无穷大/NaN(我希望它们应该保持在 0...1 范围内,尽管论文没有明确提到这一点)。v似乎首先发散,将u与它一起带走,如此处所示(对于一些常数索引):

0.94296926 0.77225316 // u, v after random initialisation
0.91600573 -62633.082 // values after first iteration -- v has already diverged massively
63.525314 5.19890688E8 // second iteration -- even more divergence
-520088.38 -2.98866172E14 // ...and so on...
1.40978577E14 1.2764294E19
-Infinity -1.7436987E24
NaN NaN
NaN NaN

代码

//Parallel Simulation of Pattern formation in a reactiondiffusion system of Fitzhugh-Nagumo Using GPU CUDA
// Alfredo Gormantara and Pranowo1

static final float a = 2.8e-4; 
static final float b = 5.0e-3;
static final float k = -0.005;
static final float tau = 0.1;
static final float delta_t = 1e-3;

float[][] u; // activator
float[][] v; // inhibitor

void setup() {

  size(512, 512);

  frameRate(5);

  u = new float[height][width];
  v = new float[height][width];

  for (int i = 0; i < u.length; i++) {
    for (int j = 0; j < u[0].length; j++) {
      u[i][j] = random(1); // random of max of 1 ?
      v[i][j] = random(1); // random of max 1?
    }
  }

  loadPixels();
}

void draw() {

  float[][] u_n_1 = new float[height][width]; // array holding the n+1 iteration values of u
  float[][] v_n_1 = new float[height][width]; // array holding the n+1 iteration values of v

  float denom = 2f / width; // 2/MESH_SIZE -- I think mesh_size is dimension of the grid 
  denom*=denom; // square for denominator
  
  println(u[34][45], v[34][45]); // print vals of one location to see divergence

  for (int y = 0; y < height; y++) {

    int negative_y_i = y-1 < 0 ? height-1 : y-1; // wrap around grid
    for (int x = 0; x < width; x++) {

      final float u_n = u[y][x];
      final float v_n = v[y][x];

      int negative_x_i = x-1 < 0 ? width-1 : x-1; // wrap around grid

      // calculate laplace (12)
      float u_n_1_laplace = u[y][(x+1) % (width)] + u[y][negative_x_i] + u[(y+1) % (height)][x] + u[negative_y_i][x]; //n+1th iteration

      u_n_1_laplace -= (4 * u_n);
      u_n_1_laplace /= denom; // divide by (2/DIM)^2
      u_n_1_laplace *= a;

      // calculate n+1th iteration u value
      u_n_1[y][x] = u_n + delta_t*( u_n_1_laplace + u_n -(u_n*u_n*u_n) - v_n + k );

      // calculate laplace (14)
      float v_n_1_laplace = v[y][(x+1)% (width)] + v[y][negative_x_i] + v[(y+1)% (height)][x] + v[negative_y_i][x]; //n+1th iteration
      v_n_1_laplace -= (4 * u_n);
      v_n_1_laplace /= denom; // denom is really small, so value goes huge
      v_n_1_laplace *=b;

      v_n_1[y][x] =  v_n + (tau/delta_t)*( v_n_1_laplace + u_n - v_n);

      pixels[y*width + x] = color((int) ((u_n_1[y][x]-v_n_1[y][x])*255));
    }
  }

  u = u_n_1.clone(); // copy over new iteration values
  v = v_n_1.clone(); // copy over new iteration values
  updatePixels();
}

4

0 回答 0