FitzHugh Nagumo 2D and then 3D

347 views
Skip to first unread message

Pier

unread,
Apr 22, 2012, 7:29:18 AM4/22/12
to reaction-diffusion
Hello everyone,

I am a student of Architecture and I have to program a FitzHugh Nagumo
model simulation of pattern formation using Processing. I reached to
program the Gray Scott model, which is similar than the FitzHugh
Nagumo, but then I can't build the other one. I was basing on this
paper http://www.sid.ir/en/VEWSSID/J_pdf/84320115715.pdf but I can't
achieve the pattern result. Can anyone please help me? I would like to
obtain a 2D simulation like this https://www.youtube.com/watch?v=tZHOGFA1KZE
and then a 3D one like this https://www.youtube.com/watch?v=oWgAtjDrc14.

I hope for an answer,

Pier Luigi Forte

Tim Hutton

unread,
Apr 22, 2012, 4:57:00 PM4/22/12
to reaction-...@googlegroups.com
Hi Pier Luigi,

Here's a very simple implementation of FHN:
https://code.google.com/p/reaction-diffusion/source/browse/trunk/FitzHughNagumo/fitz_hugh_nagumo.cpp#229
(in C++ but don't let that put you off, it's almost the same as Processing)

Here's the equivalent Gray-Scott:
https://code.google.com/p/reaction-diffusion/source/browse/trunk/GrayScott/gray_scott.cpp#166

The only other difference between the two systems is that the initial
conditions are a bit differerent, but you can see that in the two cpp
files linked above.

If this doesn't help then show us your Processing implementation, I'm
sure we can get it working for you.

RD patterns and Architecture are a great combination.

--
Tim Hutton - http://www.sq3.org.uk - http://profiles.google.com/tim.hutton/

Pier

unread,
Apr 22, 2012, 5:19:09 PM4/22/12
to reaction-diffusion
Dear Tim,

First of all thank you so much for your fast reply and interest in my
request. I'm not really experienced in C++ language even if it seems
to be similar than Processing one. Here it is the program I was
working on in Processing basing on the paper I mentioned in my
previous message, what is wrong?

int N = 300;

//System parameters
float diffU;
float diffV;
float paramA;
float paramB;
float paramE;

boolean rndInitCondition;

float[][] U = new float[N][N];
float[][] V = new float[N][N];

float[][] dU = new float[N][N];
float[][] dV = new float[N][N];

int[][] offset = new int[N][2];



void generateInitialState() {
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
U[i][j] = 1.0;
V[i][j] = 0.0;
}
}


for (int i = N/2-2; i < N/2+2; i++) {
for (int j = N/2-2; j < N/2+2; j++) {
U[i][j] = 0.5;
V[i][j] = 0.25;
}
}
}


void setup() {
size(N,N, P2D);
frameRate(25);
smooth();
colorMode(RGB,1.0);



//Set default parameters;
diffU = 0.01;
diffV = 0.1;
float A = 0.18;
float B = 0.14;
float E = 0.025;

rndInitCondition = true;

//Populate U and V with initial data
generateInitialState();

//Set up offsets
for (int i = 1; i < N-1; i++) {
offset[i][0] = (i-1);
offset[i][1] = (i+1);
}

offset[0][0] = N-1;
offset[0][1] = 1;

offset[N-1][0] = N-2;
offset[N-1][1] = 0;
}

void timestep(float paramA, float paramB, float paramE, float diffU,
float diffV) {
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {


float u = U[i][j];
float v = V[i][j];

int left = offset[i][0];
int right = offset[i][1];
int up = offset[j][0];
int down = offset[j][1];



float lapU = (U[left][j] + U[right][j] + U[i][up] + U[i]
[down] - 4*u);
float lapV = (V[left][j] + V[right][j] + V[i][up] + V[i]
[down] - 4*v);

dU[i][j] = diffU*lapU +(paramA-u)*(u-1)*u -v;
dV[i][j] = diffV*lapV + paramE*(paramB*u-v);
}
}


for (int i= 0; i < N; i++) {
for (int j = 0; j < N; j++){
U[i][j] += dU[i][j];
V[i][j] += dV[i][j];
}
}
}

void draw(){
for (int k = 0; k < 10; k++) {
timestep(A, B, E, diffU, diffV);
}

// Draw points

loadPixels();
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
pixels[N*j+i] = color((1-U[i][j]),0,0);

}
}
updatePixels();
}

Thank you for your help!

Pier

On 22 Apr, 22:57, Tim Hutton <tim.hut...@gmail.com> wrote:
> Hi Pier Luigi,
>
> Here's a very simple implementation of FHN:https://code.google.com/p/reaction-diffusion/source/browse/trunk/Fitz...
> (in C++ but don't let that put you off, it's almost the same as Processing)
>
> Here's the equivalent Gray-Scott:https://code.google.com/p/reaction-diffusion/source/browse/trunk/Gray...
>
> The only other difference between the two systems is that the initial
> conditions are a bit differerent, but you can see that in the two cpp
> files linked above.
>
> If this doesn't help then show us your Processing implementation, I'm
> sure we can get it working for you.
>
> RD patterns and Architecture are a great combination.
>
> On 22 April 2012 12:29, Pier <pier1...@gmail.com> wrote:
>
> > Hello everyone,
>
> > I am a student of Architecture and I have to program a FitzHugh Nagumo
> > model simulation of pattern formation using Processing. I reached to
> > program the Gray Scott model, which is similar than the FitzHugh
> > Nagumo, but then I can't build the other one. I was basing on this
> > paperhttp://www.sid.ir/en/VEWSSID/J_pdf/84320115715.pdfbut I can't
> > achieve the pattern result. Can anyone please help me? I would like to
> > obtain a 2D simulation like thishttps://www.youtube.com/watch?v=tZHOGFA1KZE
> > and then a 3D one like thishttps://www.youtube.com/watch?v=oWgAtjDrc14.

Tim Hutton

unread,
Apr 22, 2012, 5:48:06 PM4/22/12
to reaction-...@googlegroups.com
I get an error on line "timestep(A, B, E, diffU, diffV);" saying
"cannot find anything named E". I don't really want to start fixing
silly errors in your code - can you send 2 versions:
a) one where Gray-Scott is behaving as you expect
b) one where FHN isn't behaving as you expect

--

Pier

unread,
Apr 22, 2012, 5:53:52 PM4/22/12
to reaction-diffusion
Ok I will work on it and then provide you a better version with also
the Gray-Scott one

On 22 Apr, 23:48, Tim Hutton <tim.hut...@gmail.com> wrote:
> I get an error on line "timestep(A, B, E, diffU, diffV);" saying
> "cannot find anything named E". I don't really want to start fixing
> silly errors in your code - can you send 2 versions:
> a) one where Gray-Scott is behaving as you expect
> b) one where FHN isn't behaving as you expect
>
> >> > paperhttp://www.sid.ir/en/VEWSSID/J_pdf/84320115715.pdfbutI can't

Tim Hutton

unread,
Apr 22, 2012, 6:17:01 PM4/22/12
to reaction-...@googlegroups.com
Here's your FHN update step:

dU[i][j] = diffU*lapU +(A-u)*(u-1)*u -v;
dV[i][j] = diffV*lapV + E*(B*u-v);

Here's our FHN update step:

da[i][j] = k1*aval - k2*aval*aval - aval*aval*aval - bval + dda;
db[i][j] = epsilon * (k3*aval - a1*bval - a0) + delta*ddb;

Apart from the naming difference we seem to have an extra term a0,
which is -0.1 for the tip-splitting.
https://code.google.com/p/reaction-diffusion/source/browse/trunk/FitzHughNagumo/fitz_hugh_nagumo.cpp#36

Maybe translate our parameters into yours and add that missing a0
term, and see what happens? Or download Ready and try your parameters
in our code:
https://code.google.com/p/reaction-diffusion/
(see tip-splitting.vti)

I've just tried our tip-splitting.vti with a0=0 and I get the
attached, which is tip-splitting with bulbous ends.

--

2012-04-22_231400.png

Pier

unread,
Apr 22, 2012, 6:22:59 PM4/22/12
to reaction-diffusion
Yes, I noticed the difference in the equations, what version of FHN
equations did you used for your program?

On 23 Apr, 00:17, Tim Hutton <tim.hut...@gmail.com> wrote:
> Here's your FHN update step:
>
>           dU[i][j] = diffU*lapU  +(A-u)*(u-1)*u -v;
>           dV[i][j] = diffV*lapV + E*(B*u-v);
>
> Here's our FHN update step:
>
>             da[i][j] = k1*aval - k2*aval*aval - aval*aval*aval - bval + dda;
>             db[i][j] = epsilon * (k3*aval - a1*bval - a0) + delta*ddb;
>
> Apart from the naming difference we seem to have an extra term a0,
> which is -0.1 for the tip-splitting.https://code.google.com/p/reaction-diffusion/source/browse/trunk/Fitz...
>
> Maybe translate our parameters into yours and add that missing a0
> term, and see what happens? Or download Ready and try your parameters
> in our code:https://code.google.com/p/reaction-diffusion/
> (see tip-splitting.vti)
>
> I've just tried our tip-splitting.vti with a0=0 and I get the
> attached, which is tip-splitting with bulbous ends.
>
> >> > paperhttp://www.sid.ir/en/VEWSSID/J_pdf/84320115715.pdfbutI can't
> >> > achieve the pattern result. Can anyone please help me? I would like to
> >> > obtain a 2D simulation like thishttps://www.youtube.com/watch?v=tZHOGFA1KZE
> >> > and then a 3D one like thishttps://www.youtube.com/watch?v=oWgAtjDrc14.
>
> >> > I hope for an answer,
>
> >> > Pier Luigi Forte
>
> >> --
> >> Tim Hutton -http://www.sq3.org.uk-http://profiles.google.com/tim.hutton/
>
> --
> Tim Hutton -http://www.sq3.org.uk-http://profiles.google.com/tim.hutton/
>
>  2012-04-22_231400.png
> 259KVisualizzaScarica

Tim Hutton

unread,
Apr 22, 2012, 6:24:41 PM4/22/12
to reaction-...@googlegroups.com
You can see the formula and the parameters on the right hand side of
the screenshot.

--

Pier

unread,
Apr 26, 2012, 7:37:50 AM4/26/12
to reaction-diffusion
Hello,

I worked on my Pocessing sketch and, in fact, the problem was the
formula I used. Using the formula you used basing on the PDF by
Hagberg and Meron, both tip-splitting and spiral turbulence work fine.
I will now try to put it in 3D. Thanks a lot Tim for your help!

On 23 Apr, 00:24, Tim Hutton <tim.hut...@gmail.com> wrote:
> You can see the formula and the parameters on the right hand side of
> the screenshot.
>
> >> >> > paperhttp://www.sid.ir/en/VEWSSID/J_pdf/84320115715.pdfbutIcan't

Tim Hutton

unread,
Apr 26, 2012, 8:38:39 AM4/26/12
to reaction-...@googlegroups.com
As you can see in Ready the same formula works in 3D but you might
need to tweak the parameters a little to get what you want. If you
design a building using 3D RD then please send us an update with some
pictures!

Pier

unread,
May 5, 2012, 4:30:35 AM5/5/12
to reaction-diffusion
Of course I will, I am working on the 3D model now cos the 2D works
fine. Regarding the 2D, I was wondering how to code the FitzHugh
Nagumo to obtain a parameter map (maybe about delta and epsylon) like
this http://www.youtube.com/watch?v=XYyX4GpzhmQ you made, how did you
code this?

On 26 Apr, 14:38, Tim Hutton <tim.hut...@gmail.com> wrote:
> As you can see in Ready the same formula works in 3D but you might
> need to tweak the parameters a little to get what you want. If you
> design a building using 3D RD then please send us an update with some
> pictures!
>

Robert Munafo

unread,
May 5, 2012, 10:16:43 AM5/5/12
to reaction-...@googlegroups.com
That parameter map movie (which is a Gray Scott simulation) was made
in one of the feasibility studies (test code) that Tim and Andrew and
I (and others maybe?) were working on during the month or two prior to
the start of the Ready project.

I'm not sure which one was used for the movie, but these two source
files definitely show the parameter map capability:

http://code.google.com/p/reaction-diffusion/source/browse/trunk/SpeedComparisons/GrayScott_double/gray_scott_double.cpp

http://code.google.com/p/reaction-diffusion/source/browse/trunk/Ready_old_CLI/calc_Gray_Scott/gray_scott_scalar.cpp

For Ready, the plan is to do parameter map by a simple process of
adding another one or two chemicals. You would do it like this:

* Start with whatever formula/model/system you're interested in
parameter-mapping (like FitzHugh Nagumo)
* Add one or two more chemicals (let's add two, to made a 2-D
parameter map) (so for FHN, in addition to chemicals a and b, now we
have c and d)
* Initialize your new chemicals using a gradient: chemical c is a
gradient from the top to the bottom, and chemical d is a gradient from
left to right.
* Alter the formulas for chemicals a and b, replacing two of the
parameters with c and d. For example, we might replace the parameters
"epsilon" and "delta" with c and d.
* The formulas for c and d should be: delta_c = 0; delta_d = 0; so
that c and d stay constant throughout the simulation.

The only thing that prevents us from doing this now is that there is
no support for a gradient fill rectangle primitive in the XML for
starting patterns. But that should be pretty easy to do.

FHM has a lot of parameters (a0, a1, epsilon, delta, k1, k2, k3) so
you could set up different parameter maps to explore different
possibilities.

On 5/5/12, Pier <pier...@gmail.com> wrote:
> Of course I will, I am working on the 3D model now cos the 2D works
> fine. Regarding the 2D, I was wondering how to code the FitzHugh
> Nagumo to obtain a parameter map (maybe about delta and epsylon) like
> this http://www.youtube.com/watch?v=XYyX4GpzhmQ you made, how did you
> code this?

--
Robert Munafo -- mrob.com
Follow me at: gplus.to/mrob - fb.com/mrob27 - twitter.com/mrob_27 -
mrob27.wordpress.com - youtube.com/user/mrob143 - rilybot.blogspot.com

Pier

unread,
May 5, 2012, 10:41:00 AM5/5/12
to reaction-...@googlegroups.com
Hello Robert! Just a few moments before your message I reached the Gray Scott parameter map so right now I will try to do the FitzHugh-Nagumo one and of course your tips will help me. I think that more maps are better to show all the parameters possibilities too. So, I will update you all! Thanks a lot!

Andrew Trevorrow

unread,
May 5, 2012, 7:04:15 PM5/5/12
to reaction-...@googlegroups.com
Robert:

> The only thing that prevents us from doing this now is that there is
> no support for a gradient fill rectangle primitive in the XML for
> starting patterns. But that should be pretty easy to do.

Tim added a <linear_gradient> element a couple of days ago,
and a new example file called grayscott_parameter_map.vti.

Andrew

Tim Hutton

unread,
May 8, 2012, 7:22:44 AM5/8/12
to reaction-...@googlegroups.com
One feature of that 3D video that perhaps isn't obvious is that the
wrap-around was turned off. Just now I've added the ability to do that
in Ready too: there's a "wrap" option in the XML "rule" element, and
an editable item in the Info Pane called "toroidal wrap-around".

Patterns/FitzHugh-Nagumo/tip-splitting.vti now has wrap="0", so in 3D
it gives the same look as in that 3D video.

Robert Munafo

unread,
May 8, 2012, 10:04:27 AM5/8/12
to reaction-...@googlegroups.com
Oh, good. I think the original question got answered anyway (is was
from "Pier <pier...@gmail.com>" who we haven't heard from in a
while.)

On 5/5/12, Andrew Trevorrow <and...@trevorrow.com> wrote:
> Tim added a <linear_gradient> element a couple of days ago,
> and a new example file called grayscott_parameter_map.vti.
>
> Andrew

Pier

unread,
Jun 27, 2012, 12:53:25 PM6/27/12
to reaction-...@googlegroups.com
As promised here you have the result of our implementations and developments on the use of the FHN as architectural morphologies generator. Hope you enjoy! You will find this project in the Venice Architecture Biennale 2012 this August-November because it was selected with others among many projects from different schools. Thank you for the first support to develop the FHN 2D! Here you have the website of the project:

http://ro-bo-tech.weebly.com/

Bye!
Reply all
Reply to author
Forward
0 new messages