微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

通过第一次迭代发散的 FitzHugh-Nagumo 扩散模型的实现 1. U&V2.有限差分方程3.他们使用的常量

如何解决通过第一次迭代发散的 FitzHugh-Nagumo 扩散模型的实现 1. U&V2.有限差分方程3.他们使用的常量

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

enter image description here

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


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

1. U&V

有两种物质,u和v(可以分别认为是激活剂和抑制剂)

enter image description here

2.有限差分方程

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

对于给定像素 (i,j) 在 n+1 次迭代中 u 的值定义为:

enter image description here

对于给定像素 (i,j) 在 n+1 次迭代中 v 的值定义为:

enter image description here

3.他们使用的常量

enter image description here


所以我遇到的问题是 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();
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?