Professional Documents
Culture Documents
The Chemical Basis of Morphogenesis by Reaction Diffusion System
The Chemical Basis of Morphogenesis by Reaction Diffusion System
2
U UV
2
+ F(1 U)
V
t
= D
v
2
V + UV
2
(F + K)V
These equations were posed by P.Gray and S.K. Scott in 1983, thats why
its called the Gray-Scott model. In this model, the two partial dierential
equations are the mass-balance equations for U and V. In the model D
U
and D
V
are the diusivities, which represent the rate of speed by which U
and V diuse. For the sake of simplicity we can consider D
u
, D
v
, F and
k to be constants. In computer simulations there are also quantization
constants for time and space (t and x) that are used to break t and
2
into discrete intervals.
2.2 Gray-Scott model 12
The rst equation tells how quickly the quantity u increases. There are
three terms. The rst term, D
u
2
u is the diusion term. It species that
u will increase in proportion to the Laplacian (a sort of multidimensional
second derivative giving the amount of local variation in the gradient) of U.
When the quantity of U is higher in neighboring areas, u will increase.
2
u
will be negative when the surrounding regions have lower concentrations
of U, and in such cases the diusion term is negative and u decreases.
If we made an equation for u with only the rst term, we would have
U
t
= D
u
2
U, which is a diusion-only system equivalent to the heat
equation.
The second term is uv
2
. This is the reaction rate. The rst reaction
shown above requires one U and two V, such a reaction takes place at
a rate proportional to the concentration of U times the square of the
concentration of V. Also, it converts U into V: the increase in v is equal
to the decrease in u (as shown by the positive uv
2
in the second equation).
There is no constant on the reaction terms, but the relative strength of
the other terms can be adjusted through the constants D
u
, D
v
, F and k,
and the choice of the arbitrary time unit implicit in t.
The third term, F(1-u), is the replenishment term. Since the reaction
uses up U and generates V, all of the chemical U will eventually get used
up unless there is a way to replenish it. The replenishment term says that
u will be increased at a rate proportional to the dierence between its
current level and 1. As a result, even if the other two terms had no eect,
1 would be the maximum value for u. The constant F is the feed rate and
represents the rate of replenishment. In the systems this equation is mod-
eling, the area where the reaction occurs is physically adjacent to a large
2.2 Gray-Scott model 13
supply of U and separated by something that limits its ow, such as a
semi-permeable membrane; replenishment takes place via diusion across
the membrane, at a rate proportional to the concentration dierence [U]
across the membrane. The value 1 represents the concentration of U in
this supply area, and F corresponds to the permeability of the membrane.
The only signicant dierence in the v equation is in its third term. The
third term in the v equation is the dimishment term. Without the di-
minishment term, the concentration of V could increase without limit.
In practice, V could be allowed to accumulate for a long time without
interfering with further production of more V, but it naturally diuses
out of the system through the same (or a similar) process as that which
introduces the new supply of U. The diminishment term is proportional
to the concentration of V that is currently present, and also to the sum
of two constants F and k. F, as above, represents the permeability of
the membrane to U, and k represents the dierence between this rate
and that for V. Notice that there is nothing in the equations that states
whether the system exists in a two-dimensional space (like a Petri dish)
or in three dimensions, or even some other number of dimensions. In fact,
any number of dimensions is possible, and the resulting behavior is fairly
similar. The only signicant dierence is that in higher dimensions, there
are more directions for diusion to happen in and the rst term of the
equation becomes relatively stronger. It is for this reason that phenomena
depending on diusion for their action (such as gradient-sustained stable
spots) occur at higher k values in the 2-D system as compared to the
1-D system, and at yet higher values for the 3-D system
2.3 Euler forward method 14
2.3 Euler forward method
In mathematics and computational science, the Euler method, named
after Leonhard Euler, is a rst-order numerical procedure for solving or-
dinary dierential equations (ODEs) with a given initial value. It is the
most basic kind of explicit method for numerical integration of ordinary
dierential equations.
A method for solving ordinary dierential equations using the Euler
formula
From Calculus we know that calculating an integral is equivalent to com-
puting the area under the curve given by a(s) = f(s, y(s)) over the interval
[t
k
, t
k
+ h] by the (left) rectangular rule
Figure 2.3 Calculate area by left rectangular rule
_
t
k
+1
t
k
f(s, y(s))ds = hf(t
k
, y(t
k
)),
which after substitution and replacing exact values with approximate ones
2.4 Finite dierence method 15
(y
k
y(t
k
), y
k+1
y(t
k+1
)) results in
y
k+1
= y
k
+ hf(t
k
, y
k
) k = 0, ..., N 1.
Naturally, y
0
is given by the initial condition at t
0
in problem . The
formula y
k+1
= y
k
+hf(t
k
, y
k
) is called Forward Euler Method or Explicit
Euler Method. Note that the method increments a solution through an
interval while using derivative information from only the beginning of the
interval.
2.4 Finite dierence method
2.4.1 Dierence methods
We assume throughout our discussion that our mathematical problem
is well posed, that is ,if its solution exists then it is unique and depends
continuously on the given data.
In the nite dierence method, we superimpose on the region R of
interest a network or a mash by lines, as follows:
(1) one-dimensional case:
x
m
= a + mh, m = 0, 1, 2, .....
where h is the mash size in the x-direction.
(2)two-dimensional case:
x
l
= a + lh
1
, l = 0, 1, 2, ......
y
m
= b + mh
2
, m = 0, 1, 2, ......
2.4 Finite dierence method 16
where h
1
, h
2
are the mash sizes in x and y directions respectively. If we
are considering an initial value problem, then we also have the lines
t
n
= nk, n = 0, 1, 2, .....
where k is the step length in the t-direction. The points of intersection of
the network are called nodes. The network and nodes for boundary value
problem are shown in (see Fig. 2.4) The partial derivatives in the dier-
R
Y
X
0
h
k
Figure 2.4 The region R and nodes
ential equation are replaced by suitable dierence quotients, converting
the dierential equation to a dierence equation at each nodal point. We
may call this procedure as the discretization of the dierential equation.
The given data is used to modify the dierence equation at the nodes near
or on the boundary. The solution of this system of equations gives the
numerical solution of the given initial/boundary value problem.
2.4 Finite dierence method 17
2.4.2 Parabolic Partial Dierential Equations Two Space Di-
mensions
Parabolic partial dierential equations arise in various branches of sci-
ence and engineering,such as uid dynamics,heat ow, diusion, elastic
vibration etc. We assume that a steady state solution does not exist, and
one of the independent variables t has the role of time. We also assume
that unique solution exists, the solution being uniquely determined by the
dierential equations together with the initial and boundary conditions.
Two Space Dimensions
we can readily extend the one dimensional dierence schemes to higher
space dimension especially when the region is rectangular. The tow di-
mensional heat ow equation in the unit square R = [0 x, y 1] [0, T]
is given by
u
t
=
2
u
x
2
+
2
u
y
2
subject to the initial condition
u(x, y, 0) = f(x, y)
and the boundary conditions
u(0, y, t) = g
1
(y, t) u(1, y, t) = g
2
(y, t)
u(x, 0, t) = h
1
(x, t) u(x, 1, t) = h
2
(x, t) t > 0
We place a uniform mesh of spacing h on the square region 0 x, y 1
with Mh=1. Let k be the step size in the time direction such that t-
nk,n=0,1,.....N where Nk=T. The nodal points are dened by
x
l
= lh, l = 0, 1, 2, ..., M
2.4 Finite dierence method 18
y
m
= mh, m = 0, 1, 2, ..M
t
n
= nk, n = 0, 1, 2, ..., N
The solution value u(x, y, t) at the nodal point (l,m,n) is denoted by U
n
l,m
.Then may be written as
u
n+1
l,m
= u
n
l,m
+ (
2
x
+
2
y
)[u
n+1
l,m
+ (1 )u
n
l,m
]
where u
n
l,m
is an approximate value of U
n
l,m
.For example, the value = 0
gives the dierence scheme
u
n+1
l,m
= u
n
l,m
+ (
2
x
+
2
y
)u
n
l,m
which has order o accuracy (k + h
2
).
Using the Von Neumann method of stability analysis, We substitute
u
n
l,m
= A
n
e
i
1
lh
e
i
2
mh
in the explicit dierence scheme u
n+1
l,m
= u
n
l,m
+ (
2
x
+
2
y
)u
n
l,m
.The
propagating factor is given by
= 1 4(sin
2
1
+ sin
2
2
)
where
1
=
1
h/2 and
2
=
2
h/2.
For stability, we require that || 1 and hence
1 1 4(sin
2
1
+ sin
2
2
) 1
since 0 sin
2
1
, sin
2
2
1 the stability condition is obtained as
0 < 1/4
Again for = 1/2,we write the dierence scheme above
u
n+1
l,m
= u
n
l,m
+ (
2
x
+
2
y
)[u
n+1
l,m
+ (1 )u
n
l,m
equation as
u
n+1
l,m
= u
n
l,m
+
2
(
2
x
+
2
y
)(u
n+1
l,m
+ u
n
l,m
)
2.4 Finite dierence method 19
which is of order k
2
+ h
2
.using the Von Neumann method,we obtain
the propagating factor as
=
1 2(sin
2
1
+ sin
2
2
)
1 + 2(sin
2
1
+ sin
2
2
)
where
1
=
1
h/2 and
2
=
2
h/2. Since 0 sin
2
1
, sin
2
2
1 and
> 0,the condition || 1 is always satised. Hence the method above
eq
n
u
n+1
l,m
= u
n
l,m
+
2
(
2
x
+
2
y
)(u
n+1
l,m
+ u
n
l,m
) is unconditionally stable.
M
1 2 m-1
m
m+1
2M-2
M-1
y
h
h
A:(j-1)(M-1)+m
B:(j-1)(M-1)+m+1
C:j(M-1)+m
D:(j-1)(M-1)+m-1
E:(J-2)(m-1)+m
j A B
C
D
E
Figure 2.5 Application of the implicit method on the level n+1
On each time level, a system of linear algebraic equations is to be
solved.The coecient matrix of this system is a band matrix whose total
band with is 2M-1 as shown in 2.5 We number the unknowns in the
interior stating from left to right in the x-direction and from bottom to
top in the y-direction. When we apply above eq
n
u
n+1
l,m
= u
n
l,m
+
2
(
2
x
+
2
y
)(u
n+1
l,m
+u
n
l,m
) at A, the ve point A,B,C,D,E (and hence the unknowns
at these nodes ) enter the scheme. The points E and C are M-1 unite
2.4 Finite dierence method 20
away from A while B and D are one unit away from A. Hence the total
band width of this system of equations is 2M-1. If h is small, then the
band width is very large and the solution of this system of equations takes
a lot of computer time . To avoid this diculty we use the Alternating
Direction implicit methods. we can get idea about this dierential method
by a example. now we try to nd the solution of the two dimension
equation
u
t
=
2
u
x
2
+
2
u
y
2
subject to the initial condition
u(x, y, 0) = sin x sin y, 0 x, y 1
and the boundary conditions
u = 0, ontheboundaries, t 1
using the explicit method
u
n+1
l,m
= u
n
l,m
+ (u
n
l1,m
+ u
n
l+1,m
+ u
n
l,m1
+ u
n
l,m+1
4u
n
l,m
)
with h = 1/3 and = 1/8. Integrate upto two time levels. Compare the
results with the exact solution
u(x, y, t) = e
2
t
sin x sin y
The nodal points are given in Figure 2.6 For = 1/8,we have
u
n+1
l,m
=
1
2
u
n
l,m
+
1
8
(u
n
l1,m
+ u
n
l+1,m
+ u
n
l,m1
+ u
n
l,m+1
)
the initial and boundary conditions become
u
0
l,m
= sin(l/3)sin(m/3), l, m = 0, 1, 2, 3
2.5 Periodic Boundary Conditions 21
u
0
0,0
U
0
3,0
u
2
0,0
u
2
3,0
u
2
3,3
u
2
0,3
u
0
3,3
Zeroth level
First level
Second level
Figure 2.6 Representation of nodal points in Example
u
n
l,0
= u
n
0,m
= u
n
3,m
= u
n
l,3
= 0, l, m = 0, 1, 2, 3, andn = 0, 1, 2, ...
We get for n=0
u
1
l,m
=
1
2
u
0
l,m
+
1
8
(u
0
l1,m
+ u
0
l+1,m
+ u
0
l,m1
+ u
0
l,m+1
)
so now we can calculate every u
n
l,m
for l, m = 0, 1, 2, ...
2.5 Periodic Boundary Conditions
In mathematical models and computer simulations, periodic bound-
ary conditions (PBC) are a set of boundary conditions that are often
used to simulate a large system by modeling a small part that is far from
its edge. Periodic boundary conditions resemble the topologies of some
video games; a unit cell or simulation box of geometry suitable for perfect
three-dimensional tiling is dened, and when an object passes through
2.5 Periodic Boundary Conditions 22
one face of the unit cell, it reappears on the opposite face with the same
velocity. The simulation is of an innite perfect tiling of the system. In
topological terms, the space can be thought of as being mapped onto a
four-dimensional torus. The tiled copies of the unit cell are called im-
ages, of which there are innitely many. During the simulation, only
the properties of the unit cell need be recorded and propagated. The
minimum-image convention is a common form of PBC particle bookkeep-
ing in which each individual particle in the simulation interacts with the
closest image of the remaining particles in the system. An example occurs
in molecular dynamics, where PBC are usually applied to simulate bulk
gasses, liquids, crystals or mixtures. A common application uses PBCs to
simulate solvated macromolecules in a bath of explicit solvent.
Practical implementation:
To implement periodic boundary conditions in practice, at least two steps
are needed. he rst is to make an object which leaves the simulation cell
on one side enter back on the other. This is we used operation,
If (periodicx) then
if (x < 0) x=x+width
if (x >= width) x=x-width
endif
Chapter 3
Method Of Solution
According to Gray-Scott model there two equation as follows
U
t
= D
u
2
U UV
2
+ F(1 U)
V
t
= D
v
2
V + UV
2
(F + K)V
where U,V are input reactants and P is product of this reaction.
U + 2V 3V
V P
3.1 Problem formulation
we will assume that (0, L) (0, L) is an open square representing the
square reactor where the chemical reaction takes place, is its boundary
and is its outer normal. Then initial-boundary value problem for the
Gray-Scott model then we solve is a system of two partial dierential
equations with initial condition and periodic boundary conditions there
23
3.2 Numerical scheme 24
initial condition are
U(x, y, 0) =
_
_
0.5 if
1
3
x <
2
3
,
5
7
x <
6
7
and
1
3
y <
2
3
,
3
5
y <
4
5
1 elsewhere,
V (x, y, 0) =
_
_
0.25 if
1
3
x <
2
3
,
5
7
x <
6
7
and
1
3
y <
2
3
,
3
5
y <
4
5
0 elsewhere,
this model boundary condition is periodic boundary conditions
u(0, y, t) = u(1, y, t) u(x, 0, t) = u(x, 1, t)
v(0, y, t) = v(1, y, t) v(x, 0, t) = v(x, 1, t)
3.2 Numerical scheme
In this two-dimensional numerical experiments the following choices
for the model parameters are made: D
u
= 2e
5
D
v
= 1e
5
and f =
0.02 k = 0.059 but through the program can be changed k and f
value. we can get range on the domain [0, 1] [0, 1] where L =1 in above
dened. We choose the same time step, and tolerances as in 1D on a
spatial mesh of 100 100 mesh points with Dirichlet boundary conditions
and diusion coecients
u = (
x
i +
y
j)u =
u
x
i +
u
y
j
2
u = (u) = (
x
i +
y
j)(
u
x
i +
u
y
j)
=
2
u
x
2
+
2
u
y
2
In practice, we represent the concentration functions as two-dimensional
arrays of discrete samples. To evaluate U and V we approximate the space
3.2 Numerical scheme 25
derivative
2
U by a nite dierence. The second nite dierence in the
x direction is
2
u
x
2
u
i+1,j
+ u
i1,j
2u
i,j
h
2
The second nite dierence in the y direction is
2
v
y
2
u
i,j+1
+ u
i,j1
2u
i,j
h
2
where the i and j are array subscripts, and h is the distance between
adjacent samples.therefore we can get h value as h =
L
N
=
1
100
= 0.01
where L is domain length, N is mash size. Taking the corresponding
second dierence in the y direction, and summing, gives
2
U
i,j
u
i+1,j
+ u
i1,j
+ u
i,j+1
+ u
i,j1
4u
i,j
h
2
where u
i,j
represent an approximation to u(x
i
, y
j
). so above equation can
be used in our Gray-Scott model equation as follows
d
dt
U
i,j
(t) = D
u
2
U
i,j
U
i,j
V
2
i,j
+ F(1 U
i,j
)
d
dt
U
i,j
(t) = D
u
[
1
h
2
(u
i1,j
+u
i+1,j
+u
i,j1
+u
i,j+1
4u
i,j
)]u
i,j
v
2
i,j
+F(1u
i,j
)
as well as consider v concentration
d
dt
V
i,j
(t) = D
v
2
V
i,j
+ U
i,j
V
2
i,j
(F + k)V
i,j
d
dt
V
i,j
(t) = D
v
[
1
h
2
(v
i1,j
+v
i+1,j
+v
i,j1
+v
i,j+1
4v
i,j
)]+u
i,j
v
2
i,j
(F +k)v
i,j
using corresponding initial and boundary conditions.The discretization in
time is done my mean of the method of lines.To solve resulting systems
of ordinary dierential equations Euler method was used. This is Euler
forward method with adaptive time stepping. For details on the second
numerical scheme we use based of nite dierence method.
3.2 Numerical scheme 26
using Euler forward method
D
+
u
n
=
(u
n+1
u
n
u
n
)
t
u
n+1
u
n
t
= f(u
n
)
u
n+1
= u
n
+tf(u
n
)
This Euler methods are only rst order accurate.
u
n+1
i,j
u
n
i,j
t
= D
u
[
1
h
2
(u
n
i1,j
+u
n
i+1,j
+u
n
i,j1
+u
n
i,j+1
4u
n
i,j
)]u
n
i,j
v
n2
i,j
+F(1u
n
i,j
)
u
n+1
i,j
= u
n
i,j
+tD
u
[
1
h
2
(u
n
i1,j
+u
n
i+1,j
+u
n
i,j1
+u
n
i,j+1
4u
n
i,j
)]u
n
i,j
v
n2
i,j
+F(1u
n
i,j
)
v
n+1
i,j
v
n
i,j
t
= D
v
[
1
h
2
(v
n
i1,j
+v
n
i+1,j
+v
n
i,j1
+v
n
i,j+1
4v
n
i,j
)]+u
n
i,j
v
n2
i,j
(F+k)v
n
i,j
)
v
n+1
i,j
= v
n
i,j
+tD
v
[
1
h
2
(v
n
i1,j
+v
n
i+1,j
+v
n
i,j1
+v
n
i,j+1
4v
n
i,j
)]+u
n
i,j
v
n2
i,j
(F+k)v
n
i,j
)
then we can calculate each value of the u
0
0,0
, u
0
0,1
.....similarely we can nd
u
1
0,0
, u
1
0,1
, ....so on. which mean arbitrary U
n
i,j
can be found
In next chapter we will demonstrate founded solution how to represent in
program using Applet
Chapter 4
Program
This Gray Scott.java le is initialized Array of U and V using Gray-Scott method
and nite dierence method and this class is handle(base) Our program in mainly.
4.1 Program Code
package ptternformation;
/**
*
* @author W.A.B. Janith
*/
final class GrayScott {
double[][] u;
double[][] v;
private double[][] tmpU;
private double[][] tmpV;
double uMax;
27
4.1 Program Code 28
static final double DU = 2e-5;
static final double DV = 1e-5;
public double k = 0.059;
public double f = 0.02;
public double h = 0.01;
private double duDivh2;
private double dvDivh2;
int width, height;
public GrayScott(int width, int height, double f, double k, double h) {
this.width = width;
this.height = height;
this.f = f;
this.k = k;
this.h = h;
double v0 = f/(2*(f+k)) + Math.sqrt(f/(2*(f+k))*f/(2*(f+k)) - f*(f+k));
double u0 = f/(v0*v0+f);
duDivh2 = DU/(h*h);
dvDivh2 = DV/(h*h);
u = new double[width][height];
v = new double[width][height];
tmpU = new double[width][height];
tmpV = new double[width][height];
uMax = 0;
initialState();
}
public void initialState() {
uMax = 0.5;
double v0 = f/(2*(f+k)) + Math.sqrt(f/(2*(f+k))*f/(2*(f+k)) - f*(f+k));
double u0 = f/(v0*v0+f);
4.1 Program Code 29
for (int x = 0; x<width; x++) {
for (int y = 0; y<height; y++) {
tmpU[x][y] = 1;
tmpV[x][y] = 0;
}
}
for (int x = 0; x<(width/3); x++) {
for (int y = 0; y<height/3; y++) {
tmpU[1*width/3 + x][1*height/3 + y] = 0.5;
tmpV[1*width/3 + x][1*height/3 + y] = 0.25;
}
}
for (int x = 0; x<(width/7); x++) {
for (int y = 0; y<height/5; y++) {
tmpU[5*width/7 + x][3*height/5 + y] = 0.5;
tmpV[5*width/7 + x][3*height/5 + y] = 0.25;
}
}
}
public void setF(double f) {
this.f = f;
}
public void setK(double k) {
this.k = k;
}
public void timeStep(double dt) {
4.1 Program Code 30
double newMax = 0;
double uv2;
/*centre*/
for (int x = 1; x<width-1; x++) {
for (int y = 1; y<height-1; y++) {
uv2 = tmpU[x][y]*tmpV[x][y]*tmpV[x][y];
u[x][y] = tmpU[x][y] + dt*(duDivh2*(tmpU[x+1][y] + tmpU[x-1][y] +
tmpU[x][y+1] + tmpU[x][y-1] - 4*tmpU[x][y]) - uv2 + f*(1-tmpU[x][y]));
if (u[x][y]<0) u[x][y] = 0;
v[x][y] = tmpV[x][y] + dt*(dvDivh2*(tmpV[x+1][y] + tmpV[x-1][y] +
tmpV[x][y+1] + tmpV[x][y-1] - 4*tmpV[x][y]) + uv2 - k*tmpV[x][y]);
if (v[x][y]<0) v[x][y] = 0;
}
}
/*edges*/
int x, y;
for (x = 0; x<width; x++) {
y = 0;
uv2 = tmpU[x][y]*tmpV[x][y]*tmpV[x][y];
u[x][y] = tmpU[x][y] + dt*(duDivh2*(tmpU[pBC(x+1,width)][y] +
tmpU[pBC(x-1,width)][y] + tmpU[x][pBC(y+1, height)] + tmpU[x][pBC(y-1,
height)] - 4*tmpU[x][y]) - uv2 + f*(1-tmpU[x][y]));
if (u[x][y]<0) u[x][y] = 0;
v[x][y] = tmpV[x][y] + dt*(dvDivh2*(tmpV[pBC(x+1,width)][y] +
tmpV[pBC(x-1,width)][y] + tmpV[x][pBC(y+1, height)] + tmpV[x][pBC(y-1,
height)] - 4*tmpV[x][y]) + uv2 - k*tmpV[x][y]);
if (v[x][y]<0) v[x][y] = 0;
y = height - 1;
uv2 = tmpU[x][y]*tmpV[x][y]*tmpV[x][y];
u[x][y] = tmpU[x][y] + dt*(duDivh2*(tmpU[pBC(x+1,width)][y] +
tmpU[pBC(x-1,width)][y] + tmpU[x][pBC(y+1, height)] +
4.1 Program Code 31
tmpU[x][pBC(y-1, height)] - 4*tmpU[x][y]) - uv2 + f*(1-tmpU[x][y]));
if (u[x][y]<0) u[x][y] = 0;
v[x][y] = tmpV[x][y] + dt*(dvDivh2*(tmpV[pBC(x+1,width)][y] +
tmpV[pBC(x-1,width)][y] + tmpV[x][pBC(y+1, height)] +
tmpV[x][pBC(y-1, height)] - 4*tmpV[x][y]) + uv2 - k*tmpV[x][y]);
if (v[x][y]<0) v[x][y] = 0;
}
for (y = 0; y<height; y++) {
x = 0;
uv2 = tmpU[x][y]*tmpV[x][y]*tmpV[x][y];
u[x][y] = tmpU[x][y] + dt*(duDivh2*(tmpU[pBC(x+1,width)][y] +
tmpU[pBC(x-1,width)][y] + tmpU[x][pBC(y+1, height)] +
tmpU[x][pBC(y-1, height)] - 4*tmpU[x][y]) - uv2 + f*(1-tmpU[x][y]));
if (u[x][y]<0) u[x][y] = 0;
v[x][y] = tmpV[x][y] + dt*(dvDivh2*(tmpV[pBC(x+1,width)][y] +
tmpV[pBC(x-1,width)][y] + tmpV[x][pBC(y+1, height)] +
tmpV[x][pBC(y-1, height)] - 4*tmpV[x][y]) + uv2 - k*tmpV[x][y]);
if (v[x][y]<0) v[x][y] = 0;
x = width - 1;
uv2 = tmpU[x][y]*tmpV[x][y]*tmpV[x][y];
u[x][y] = tmpU[x][y] + dt*(duDivh2*(tmpU[pBC(x+1,width)][y] +
tmpU[pBC(x-1,width)][y] + tmpU[x][pBC(y+1, height)] +
tmpU[x][pBC(y-1, height)] - 4*tmpU[x][y]) - uv2 + f*(1-tmpU[x][y]));
if (u[x][y]<0) u[x][y] = 0;
v[x][y] = tmpV[x][y] + dt*(dvDivh2*(tmpV[pBC(x+1,width)][y] +
tmpV[pBC(x-1,width)][y] + tmpV[x][pBC(y+1, height)] +
tmpV[x][pBC(y-1, height)] - 4*tmpV[x][y]) + uv2 - k*tmpV[x][y]);
if (v[x][y]<0) v[x][y] = 0;
}
for (x = 0; x<width; x++) {
4.1 Program Code 32
for (y = 0; y<height; y++) {
tmpU[x][y] = u[x][y];
tmpV[x][y] = v[x][y];
}
}
}
private int pBC(int x, int max) { /*periodic boundary conditions*/
int xp = x;
while (xp<0) xp += max;
while (xp>=max) xp -= max;
return xp;
}
}
4.1 Program Code 33
This is RDCanvas.java le is just like a canvas so we can paint on canvas just like
change color
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package ptternformation;
import java.awt.*;
/**
*
* @author W.A.B. Janith
*/
final class RDCanvas extends Canvas implements Runnable {
public Thread runner = null;
int w, h;
Dimension preferredSize;
Image DB_Image;
Graphics DB_Graphics;
GrayScott grayScott;
int nColors = 85;
Color[] color = new Color[3*nColors];
double[][] u;
ReactionDiffusion controller;
double umax;
public RDCanvas(ReactionDiffusion controller, int w, int h) {
this.w = w;
this.h = h;
this.controller = controller;
preferredSize = new Dimension(w + 3, h + 3);
4.1 Program Code 34
u = new double[w][h];
for (int i = 0; i<nColors; i++) {
color[i] = new Color((int)(255*((double)i/nColors)), 0, 0);
}
for (int i = 0; i<nColors; i++) {
color[i+nColors] = new Color(255, (int)(255*((double)i/nColors)), 0);
}
for (int i = 0; i<nColors; i++) {
color[i+2*nColors] = new Color((int)(255*(1.0-(double)i/nColors)), 255,0);
}
grayScott = new GrayScott(w, h, controller.F0, controller.K0, 0.01);
}
@Override
public Dimension getPreferredSize() {
return preferredSize;
}
@Override
public void paint(Graphics g) {
update(g);
}
@Override
public void update(Graphics g) {
int cn;
double uMax = 0;
if (DB_Graphics == null) {
DB_Image = createImage(w+3, h+3);
4.1 Program Code 35
DB_Graphics = DB_Image.getGraphics();
}
for (int x = 0; x<w; x++) {
for (int y = 0; y<h; y++) {
cn = (int)((3*nColors-1.0)*u[x][y]/0.4);
if (cn>(3*nColors-1)) cn = 3*nColors - 1;
if (cn<0) cn = 0;
DB_Graphics.setColor(color[cn]);
DB_Graphics.drawLine(x+1,y+1,x+1,y+1);
}
}
/*draw border*/
DB_Graphics.setColor(Color.black);
DB_Graphics.drawLine(0,0,preferredSize.width-1,0);
DB_Graphics.drawLine(0,0,0,preferredSize.height-1);
DB_Graphics.drawLine(0,preferredSize.height-2,preferredSize.width-2,preferredSize.height-2);
DB_Graphics.drawLine(preferredSize.width-2,0,preferredSize.width-2,preferredSize.height-2);
DB_Graphics.drawLine(0,preferredSize.height-1,preferredSize.width-1,preferredSize.height-1);
DB_Graphics.drawLine(preferredSize.width-1,0,preferredSize.width-1,preferredSize.height-1);
g.drawImage(DB_Image, 0, 0, this);
}
@Override
public void run() {
Thread myThread = Thread.currentThread();
while (runner == myThread) {
for (int i = 0; i<10; i++) { /* 10 timesteps / frame */
grayScott.timeStep(1);
}
4.1 Program Code 36
umax = 0;
for (int x = 0; x<w; x++) {
for (int y = 0; y<h; y++) {
u[x][y] = grayScott.v[x][y];
if (u[x][y]>umax) umax = u[x][y];
}
}
repaint();
try {
Thread.sleep(50);
}
catch (InterruptedException e) {
}
}
}
}
4.1 Program Code 37
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package ptternformation;
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
/**
*
* @author W.A.B. Janith
*/
/*------------------------------->class ReactionDiffusion<-----------------------------------------------
<APPLET CODE="ReactionDiffusion.class" WIDTH=200 HEIGHT=250>
<PARAM NAME=xmax VALUE=100>
<PARAM NAME=ymax VALUE=100>
</APPLET>
*/
public final class ReactionDiffusion extends Applet implements ActionListener, AdjustmentListener {
Thread runner = null;
int w; /*APPLET WIDTH*/
int h; /*APPLET HEIGHT*/
int xmax, ymax; /*canvas size*/
int tpf = 10; /*timesteps per frame*/
double dt;
4.1 Program Code 38
Graphics DB_Graphics;
Image DB_Image;
GrayScott grayScott;
int nColors = 85;
Color[] color = new Color[3 * nColors];
double[][] u;
double umax;
private RDCanvas canvas;
Scrollbar kSlider, fSlider;
Button restartButton;
Label fLabel, kLabel;
final double K0 = 0.079;
final double F0 = 0.02;
@Override
public void init() {
w = getSize().width; /*applet width*/
h = getSize().height; /*applet height*/
u = new double[w][h];
String p;
/*canvas width*/
p = getParameter("xmax");
if (p == null) {
p = "100";
}
xmax = Integer.valueOf(p).intValue();
if (xmax < 10) {
xmax = 10;
}
4.1 Program Code 39
/*canvas height*/
p = getParameter("ymax");
if (p == null) {
p = "100";
}
ymax = Integer.valueOf(p).intValue();
if (ymax < 10) {
ymax = 10;
}
/*create components*/
restartButton = new Button("Restart");
restartButton.addActionListener(this);
canvas = new RDCanvas(this, xmax, ymax);
int pos = (int) (K0 * 100.0 / 0.15);
kSlider = new Scrollbar(Scrollbar.HORIZONTAL, pos, 1, 0, 200);
kSlider.addAdjustmentListener(this);
kLabel = new Label("k = ");
kLabel.setText("k = " + String.valueOf(K0));
pos = (int) (F0 * 100.0 / 0.15);
fSlider = new Scrollbar(Scrollbar.HORIZONTAL, pos, 1, 0, 200);
fSlider.addAdjustmentListener(this);
fLabel = new Label("f = ");
fLabel.setText("f = " + String.valueOf(F0));
GridBagLayout gridbag = new GridBagLayout();
GridBagConstraints c = new GridBagConstraints();
4.1 Program Code 40
setLayout(gridbag);
/*add components*/
gridbag.setConstraints(getCanvas(), c);
add(getCanvas());
c.gridy = 1;
gridbag.setConstraints(fLabel, c);
add(fLabel);
c.gridy = 2;
c.fill = GridBagConstraints.HORIZONTAL;
gridbag.setConstraints(fSlider, c);
add(fSlider);
c.gridy = 3;
c.fill = GridBagConstraints.NONE;
gridbag.setConstraints(kLabel, c);
add(kLabel);
c.gridy = 4;
c.fill = GridBagConstraints.HORIZONTAL;
gridbag.setConstraints(kSlider, c);
add(kSlider);
c.gridy = 5;
c.fill = GridBagConstraints.NONE;
gridbag.setConstraints(restartButton, c);
add(restartButton);
}
4.1 Program Code 41
@Override
public void start() {
if (canvas.runner == null) {
canvas.runner = new Thread(canvas, "CanvasRunner");
canvas.runner.start();
}
}
@Override
public void stop() {
canvas.runner = null;
}
@Override
public void paint(Graphics g) {
/*draw border*/
g.setColor(Color.green);
g.drawLine(0, 0, getWidth() - 1, 0);
g.drawLine(0, 0, 0, getHeight() - 1);
g.drawLine(getWidth() - 1, getHeight() - 1, 0, getHeight() - 1);
g.drawLine(getWidth() - 1, getHeight() - 2, 0, getHeight() - 2);
g.drawLine(getWidth() - 1, getHeight() - 1, getWidth() - 1, 0);
g.drawLine(getWidth() - 2, getHeight() - 1, getWidth() - 2, 0);
}
@Override
public void actionPerformed(ActionEvent e) {
if (getCanvas().runner != null) {
canvas.runner = null;
getCanvas().grayScott.initialState();
canvas.runner = new Thread(getCanvas(), "CanvasRunner");
4.1 Program Code 42
getCanvas().runner.start();
} else {
getCanvas().grayScott.initialState();
}
}
@Override
public void adjustmentValueChanged(AdjustmentEvent e) {
if (e.getAdjustable() == fSlider) {
getCanvas().grayScott.setF(fSlider.getValue() * 0.15 / 100.0);
fLabel.setText("f = " + String.valueOf(getCanvas().grayScott.f));
} else {
getCanvas().grayScott.setK(kSlider.getValue() * 0.15 / 100.0);
kLabel.setText("k = " + String.valueOf(getCanvas().grayScott.k));
}
}
/**
* @return the canvas
*/
public RDCanvas getCanvas() {
return canvas;
}
}
4.1 Program Code 43
This is main class so we must run rst this java le(class)
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package ptternformation;
import java.awt.Color;
import javax.swing.JFrame;
/**
*
* @author W.A.B. Janith
*/
public class main {
public static void main(String arg[]){
ReactionDiffusion theApplet = new ReactionDiffusion();
theApplet.init(); // Needed if overridden in applet
theApplet.start(); // Needed if overridden in applet
//... Create a window (JFrame) and make applet the content pane.
JFrame window = new JFrame("Sample Applet and Application");
window.setBackground(Color.ORANGE);
window.setContentPane(theApplet);
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
window.pack(); // Arrange the components.
//System.out.println(theApplet.getSize());
window.setVisible(true);
}
}
4.2 Program OUTPUT 44
4.2 Program OUTPUT
Figure 4.1
1
For f=0.02,k=0.079
Figure 4.2
2
or f=0.024,k=0.0765
Chapter 5
Conclusion
In this study we considered the large-time behavior of solutions U(x, y , t) and V
(x, y, t) of the Gray-Scott model on a two-dimensional domain (0, L) (0, L). We
focused on the parameters D
u
, D
v
and on the small L of the domain. We did look
at the nal proles of the model for two dierent values of F and K by doing some
numerical simulations. We tried to build the program which we saw in our project
results. It appears dierent patterns that for some values of F and k for small L, we
able to built a nice patterns of our numerical results using the Gray-Scott model.
45
Chapter 6
Discussion
In this dissertation we have investigated pattern formation in reaction-
diusion systems. We used a simple and well known model to explore
dierent pattern behaviors in two dimensions. This pattern generation
model is using in very important role because every biological pattern
was made by in reaction such as reaction diusions .as a example zebras
skin , tigers skin and our nger print also made in pattern by reaction
diusions . we developed a programs generate many varies pattern For a
variety of systems, reaction-diusion equations with more than two com-
ponents have been proposed, e.g. as models for the Belousov-Zhabotinsky
reaction, for blood clotting or planar gas discharge systems. So we can
implement our program in multi dimensional region.
In recent times, reaction-diusion systems have attracted much interest
as a prototype model for pattern formation. The above-mentioned pat-
terns (fronts, spirals, targets, hexagons, stripes and dissipative solutions)
can be found in various types of reaction-diusion systems in spite of large
discrepancies e.g. in the local reaction terms. It has also been argued that
46
47
reaction-diusion processes are an essential basis for processes connected
to morphogenesis in biology and may even be related to animal coats and
skin pigmentation. The chemical basis of morphogenesis Another reason
for the interest in reaction-diusion systems is that although they rep-
resent nonlinear partial dierential equation, there are often possibilities
for an analytical treatment. There are many experiments in the world be
investigated. Well-controllable experiments in chemical reaction-diusion
systems have up to now been realized in three ways. First, gel reactors
or lled capillary tubes may be used. Second, temperature pulses on cat-
alytic surfaces have been investigated. Third, the propagation of running
nerve pulses is modeled using reaction-diusion systems. Aside from these
generic examples, it has turned out that under appropriate circumstances
electric transport systems like plasmas or semiconductors can be described
in a reaction-diusion approach. For these systems various experiments
on pattern formation have been carried out.
Bibliography
[1] M.K.Jain,S.R.K.Iyengar,R.K.Jain, Computational Methods for Partial Dieren-
tial Equations, 3rd ed. (Wiley, new Delhi:India, 1993),
[2] Randall J. LeVeque, Finite Dierence Methods for Dierential Equations,
DRAFT VERSION for use in the course A Math 585-586 University of Wash-
ington Version of September, 2005.
[3] PATTERN FORMATION IN REACTION-DIFFUSION MODELS FAR FROM
THE TURING REGIME by THEODORE KOLOKOLNIKOV August 2004
[4] Pattern formation in the Gray-Scott model Je S. McGough and Kyle Riley
Department of Mathematics and Computer Science, South Dakota School of
Mines and Technology 501 E. St. Joseph St. Rapid City, SD 57701 USA
[5] Numerical Solutio of the 2D Gray-scott model ,Jan Mach,Faculty of Nuclear sci-
ences and PhysicalPhysical Engineering,Czech Teachnical University in Prague.
[6] Sole) PATTERN FORMATION IN NOISY SELF-REPLICATING SPOTS An-
dreea Munteanu1,and Ricard V. Sole, 1ICREA-Complex Systems Lab, Universi-
tat Pompeu Fabra (GRIB), Dr Aiguader 80, 08003 Barcelona, Spain 2Santa Fe
Institute, 1399 Hyde Park Road, Santa Fe NM 87501, USA
[7] http://www.wikipedia.org/
48