Chapter 1 Integrating PDE’s with XPP 1.1 Reaction-Diffusion Systems

advertisement
Chapter 1
Integrating PDE’s with XPP
1.1
Reaction-Diffusion Systems
We are interested in studying some generic reaction-diffusion equations
∂u
= f (u, v) + Du uxx
∂t
∂u
= g(u, v) + Dv uxx
∂t
(1.1)
(1.2)
A useful XPP program for doing so is Ermentrout’s rd2.ode, which is described in his book,
and available online. A copy appears in the appendix Section 1.3. The specific feature of the
discretization and solver that he suggests makes for a rapid code, with convergence to the solutions
even when a large timestep is used. (That method is CVODE.)
We will test this program with a set of RD equations that conserve the total amount of material
on a finite domain. To do so, we consider the bistable kinetics
un
− k1 u,
f (u, v) = v k0 + n
K + un
g(u, v) = −f (u, v)
(1.3)
on a domain 0 ≤ x ≤ 1, with Neumann boundary conditions. The code for running this system is
shown in Section 1.3, and some of the results are shown in Figs 1.3 and 1.2. The interesting feature
of this system is that it admits traveling waves on an infinite domain, but on a finite domain, the
wave is “pinned” to produce a polarized profile.
1
1
2
1.8
0.8
1.6
1.4
0.6
1.2
0.4
0.8
1
0.6
0.2
0.4
0.2
0
0
10
20
30
40
50
60
70
80
90
100
10
20
30
40
50
60
70
80
90
100
Figure 1.1: Exploring the wavepinning problem. Here we see the spatial profile of a reaction-diffusion
wave that gets “pinned” in the middle of the domain. The profiles are shown at successive times
from an initial condition, init v[1..100]=0.8; init u[80..100]=0.5*(1+cos(pi*[100-j]/20)). In addition,
the left side of the domain was initialized with (a) Left panel: init u[1..20]=0.5*(1+cos(pi*[j]/20)):
the waves move into the domain from both sides and ’freeze’. (b) init u[1..20]=2*(1+cos(pi*[j]/20))
Here the steady state is a flat distribution, as the wave from the left overtakes and flattens out the
wave from the right. See Figure 1.2 for details about how such figures can be most easily produced
from XPP.
2
1.2
Appendix: XPP codes
Reaction-Diffusion (rd2.ode)
Here is a useful code for integrating reaction-diffusion equations, direct from Bard Ermentrout’s
book. I have inserted some comments.
#
#
#
#
#
#
#
#
#
rd2.ode
generic 2 variable reaction diffusion with Neumann conds
p 140 in Ermentrout’s XPPaut book
Because some ODE’s and PDE’s can be stiff, it is useful to
use the CVODE integrator, but to avoid inverting a huge
matrix, one should write the program wisely.
The idea is to organize the discretization so that the
matrix has a banded structure.
# This is done in the following code.
f(u,v)=u*(1-u)*(u-a)-v
g(u,v)=(u-d*v-b)*c
u1’=f(u1,v1)+du*(u2-u1)/h^2
v1’=g(u1,v1)+dv*(v2-v1)/h^2
# The command \%[2..99] tells XPP that the following is an array
# The effect is to mix u’s and v’s in successive rows.
# In order to plot this with the array option, use Colskip = 2
# so as to show only u or only v
%[2..99]
u[j]’=f(u[j],v[j])+du*(u[j+1]+u[j-1]-2*u[j])/h^2
v[j]’=g(u[j],v[j])+dv*(v[j+1]+v[j-1]-2*v[j])/h^2
%
u100’=f(u100,v100)+du*(u99-u100)/h^2
v100’=g(u100,v100)+dv*(v99-v100)/h^2
par a=.25,d=0,b=.4,c=1,du=.2,dv=1,h=.1
# The following command tells XPP to use the banded form of CVODE,
# and informs the program of the lower and upper bandwidths
@ meth=cvode,bandup=2,bandlo=2
done
Wave-pinning reaction-diffusion
Here is the code for a wave-pinning RD system.
# Wave-pinning Reaction-Diffusion system
3
#
#
#
#
#
#
#
#
#
Modified from rd2.ode
generic 2 variable reaction diffusion with various boundary conditions
p 140 in Ermentrout’s XPPaut book
Because some ODE’s and PDE’s can be stiff, it is useful to
use the CVODE integrator, but to avoid inverting a huge
matrix, one should write the program wisely.
The idea is to organize the discretization so that the
matrix has a banded structure.
# This is done in the following code.
# Kinetic functions used for wave-pinning:
f(u,v)=v*(k0+u^n/(K^n+u^n))-k1*u
g(u,v)=-(v*(k0+u^n/(K^n+u^n))-k1*u)
#
#
#
#
#
#
#
#
#
From Alexandra Jilkine’s code, here is a convenient way to include
a variety of possible boundary conditions:
Neumann and Dirichlet conditions as well as mixed BC’s
can be implemented by setting the a,b,c, parameters
Dirichlet: b=0; Neumann a=0, c=0
cu0 = au0 u + bu0 u_x
cu1 = au1 u + bu1 u_x
cv0 = av0 u + bv0 u_x
cv1 = av1 u + bv1 u_x
# left boundary
u0=(cu0-bu0*u1/h)/(au0-bu0/h)
v0=(cv0-bv0*v1/h)/(av0-bv0/h)
#
#
#
#
The command %[1..100] tells XPP that the following is an array
The effect is to mix u’s and v’s in successive rows.
In order to plot this with the array option, use Colskip = 2
so as to show only u or only v
%[1..100]
u[j]’=f(u[j],v[j])+du*(u[j+1]+u[j-1]-2*u[j])/h^2
v[j]’=g(u[j],v[j])+dv*(v[j+1]+v[j-1]-2*v[j])/h^2
%
# Right boundary
u101=(cu1+bu1*u100/h)/(au1+bu1/h)
v101=(cv1+bv1*v100/h)/(av1+bv1/h)
4
# Parameters for wave-pinning:
par k0=0.0, K=0.3, k1=1, n=3
par du=.1,dv=1,h=.1
#No
par
par
#No
par
par
flux (Neumann) BC’s for left endpoint
cu0=0,au0=0,bu0=1
cv0=0,av0=0,bv0=1
flux (Neumann) BC’s for right endpoint
cu1=0,au1=0,bu1=1
cv1=0,av1=0,bv1=1
# Initialization of the chemical distribution
init v[1..100]=.8
init u[1..20]=1+1*cos(pi*[j]/20)
# SEE COMMENT BELOW FOR BETTER IC’S
# The following command tells XPP to use the banded form of CVODE,
# and informs the program of the lower and upper bandwidths
@ meth=cvode,bandup=2,bandlo=2
@ total=200
done
1.2.1
Array plots
After running this code, one can plot the results with an array. To do this, select Viewaxes (V),
Array (A), and fill in the entries as follows:
Column1: u1
NCols: 200
Row 1: 0
NRows:50
RowSkip:80
Zmin:0
Zmax:1
Autoplot(0/1):0
ColSkip:2
The resulting graph is as shown in Figure 1.3.
1.2.2
Line plots and the transpose option
It is also possible to make a line-plot with profiles of the variables versus x at a variety of times.
To do so, select File(F), Transpose (T) and fill in the entries as follows:
5
Column 1: U1
NCols: 200
Colskip: 2
Row 1: 1
NRows: 20
RowSkip: 200
The resulting graph is as shown in Figure 1.2. This graph can be produced by selecting IC’s in
the top left-hand ’button’ of the XPP viewer, to bring up the Initial Data window, and then selecting
the data rows to be plotted and clicking xvst at the bottom of that window. The convenience of this
is that multiple curves can be plotted without the need to ”freeze” and save the data. A description
of this shortcut is given on p 138 of Ermentrout’s XPP book.
1
0.8
0.6
0.4
0.2
0
10
20
30
40
50
60
70
80
90
100
Figure 1.2: Figure created by transpose option of XPP. Here we see the spatial profile of a reactiondiffusion wave that gets “pinned” in the middle of the domain. The profiles are shown at successive
times from the initial condition. All parameters and code as shown in program. Plotted here (after
transposing) are U1, U2, ..U9
6
time
196
0
1
Figure 1.3: Figure created by array option of rd2.ode.
1.2.3
Animating your results
Another way of visualizing the results is an animation feature of XPP, described on p 139 of the
XPP book. This feature uses the animation file cable100.ani, as follows:
# cable100.ani
# Bard Ermentrout’s file for animation
vtext .8;.95;t=;t
fcircle [1..100]/100;(u[j]+1)/2.2;.02;[j]/100
end
The file should be saved in the same directory as the XPP code for the PDE’s or array of interest.
To animate the results, run the code (rd2.ode or clone) and then select Viewaxes (V), Toon (T).
This brings up a new window. In that window, select the File button and select cable100.ani, and
click OK. Finally, click Go in the animation window to watch the results. An example of the early
time configuration of the wave is shown in Fig 1.4.
A nice feature of the animation option is that it helps to easily visualize the time behaviour, even
when some aspects could otherwise be missed. For example, in some situations, in the wave-pinning
problem, it looks at first sight that the final steady state emerges only after a bit of oscillation at or
behind the wave-front. An example of this sort occurs for the initial conditions init v[1..100]=0.525
init u[1..20]=1*(1+cos(pi*[j]/10)). Actually, it turns out that this stems from a bit of numerical
instability, and can be eliminated by setting a smaller ∆t.
7
Generally, the animation window in XPP does not directly lead to a way to save an image in
postscript (since it is meant to be viewed ‘live’), but to produce one, as I have done here in Fig 1.4,
you can use any screen capture software that saves a ‘clip’ from your screen into .jpg, or .gif, or .tiff
file. Then, import your image into xfig. The latter is a fairly basic, but useful drawing program
that operates with unix, linux, and on Mac unix-based OS. In xfig, I chose the ‘picture’ option
(camera icon on the Drawing toolbar), selected a rectangular area with two left mouse button clicks
(for top left and bottom right corner). This brings up an edit panel that allows you to type in or to
browse your directory for the image file to be imported (Picture filename, Browse). After selecting
the image file, click Apply (bottom of panel) and Close on the window that comes up, Apply and
Done (on the Edit Window). Your figure will have been imported into xfig. The advantage is that
it can then be saved as a .fig file and imported into a .eps file that Latex can easily include in its
figure environment.
Figure 1.4: Figure created by animation option of rd2.ode. This image is at the begining of the
sequence, when the wave is still moving into the domain. By t = 80 it will have become frozen.
There is very little chage seen between t = 100 and t = 200 in the simulation.
1.2.4
Generating a movie
Animation can also be used to generate an animated .gif file that can be played back with software
such as Quicktime (or other types). This feature is described on p 199 of Ermentrout’s XPP book.
To do this, first generate an animation as described in the previous section. To save it to a
“movie”, click the MPEG button in the animation window, and select AniGif(0/1): 1, then click
Ok. Next, click Skip in the animation window, and select an increment (e.g. 2 or 4, depending on
the size of your file.) Click Ok and run the animation once more. This will result in a file called
8
anim.gif. It can be loaded and played with Quicktime, though the colors may be a little strange,
compared with the original animation window. Obviously, by using a larger Skip increment, you
get smaller animation files that take less memory.
1.2.5
Setting the initial conditions
In the XPP code of a .ode file, it is not possible to define initial conditions that depend on parameters, and even formulae don’t appear to work very well. This seems to lead to the problem that
one needs to recompile the code every time a different inhomogeneous initial conditions (e.g. for
a PDE or array) is used. However, fortunately, there is a nice shortcut that can be implemented
from an active XPP window, and this allows use of a “formula” for the initial conditions.
To use this feature, run your code, and select Initialconds (I), Formula (U); then type u[1..100]
(enter), and type a formula such as the following:
0.3*(1+cos([j]*pi/25))
for the u-variable. Similarly, you can type in v[1..100], and put in 0.6 for the “formula” if you want
a homogeneous distribution of v. Fig 1.5 was produced by this method.
9
(a)
(b)
0.7
0.6
0.6
0.5
0.5
0.4
0.4
0.3
0.3
0.2
0.2
0.1
0.1
0
0
10
20
30
40
50
60
70
80
90
100
(c)
10
20
30
40
50
60
70
80
90
100
10
20
30
40
50
60
70
80
90
100
(d)
1.4
1.4
1.2
1.2
1
1
0.8
0.8
0.6
0.6
0.4
0.4
0.2
0.2
0
0
10
20
30
40
50
60
70
80
90
100
Figure 1.5: Simulation of Equations 1.1, 1.2 with functions given by Equation 1.3. Figure created
by the transpose option of rd2.ode, using formula initial conditions (called from the XPP window).
(a) The variable u[1..100] was set to 0.3*(1+cos([j]*pi/25)), and the value of v was 0.6 everywhere.
This results in a “pinned” pattern with multiple peaks. (b) However, if the value of v is higher, e.g.
v = 0.75 everywhere, then the pattern smoothes out and only a uniform state remains. (c) Here,
the initial conditions for u[1..100] were set to 0.8*(1+cos([j]*pi/20)) and v[1..100] set to 0.2. Here
we see that there is not “enough material” in the domain to lead to a homogenous distribution.
First the peaks seem to die out, but they leave in their wake a pinned polarized profile. (d) Finally,
with the same u distribution, but with v[1..100] is set to 0.15, we find that several peaks persist for
a long time, but then the leftmost peak dies out and the other two coalesce into a single plateau
inside the domain.
10
Download