Scalar Reaction-Diffusion Equation Analysis
Scalar Reaction-Diffusion Equation Analysis
Final Project
Hai Zhu
Problem 1.
Show that the function
1
v̄(ξ) = (Ex0.0d)
1 + exp(ξ)
satisfies both of the equations
v̄ 0 (ξ) = −v̄(ξ)(1 − v̄(ξ)) (Ex0.0e)
and
v̄ 00 (ξ) = 2v̄(ξ)(1 − v̄(ξ))(1/2 − v̄(ξ)), (Ex0.0f)
and also satisfies
v̄(ξ) → 1 as ξ → −∞,
v̄(ξ) → 0 as ξ → +∞, (Ex0.0g)
v̄(0) = 1/2.
1
AMATH 586 Hai Zhu Student ID: 1323888
Solution
1
v̄ 0 (ξ) = − eξ
(1 + eξ )2
= −v̄(ξ)(1 − v̄(ξ))
2e2ξ eξ
v̄ 00 (ξ) = −
(1 + eξ )3 (1 + eξ )2
1 2 eξ 1 2 eξ eξ
2v̄(ξ)(1 − v̄(ξ))( − v̄(ξ)) = − +
2 1 + eξ 1 + eξ 2 1 + eξ 1 + eξ 1 + eξ
2e2ξ eξ
= −
(1 + eξ )3 (1 + eξ )2
1 1
v̄(ξ) = → = 1 as ξ → −∞,
1+e ξ 1 + e−∞
1 1
v̄(ξ) = → = 0 as ξ → ∞,
1 + eξ 1 + e∞
1 1
v̄(0) = 0
=
1+e 2
From the above computation, we know v̄ is the solution of
2
AMATH 586 Hai Zhu Student ID: 1323888
If α 6= 1/2 then the effect of the reaction term is not symmetric. If 0 < α < 1/2 then some
values of v less than 1/2 are driven towards v = 1 by the reaction term. When coupled with
the symmetric diffusion this leads to a traveling wave propagating with some velocity c that
is positive if α < 1/2 or negative if α > 1/2. The traveling wave profile is given by the same
function v̄(x) that satisfies the boundary value problem, and has the form
v(x, t) = v̄((x − ct)/δ), (Ex0.0h)
where the speed c is given by r
2κ 1
c= −α . (Ex0.0i)
2
Problem 2.
(a) For any 0 < α < 1, show that v(x, t) = v̄((x − ct)/δ) is a traveling wave solution to
(Ex0.0c) provided that c satisfies (Ex0.0i).
(b) Suppose we define the width of the transition zone (wave front) in a traveling wave to be
the distance in x over which v falls from 0.99 to 0.01. Show that the width of wave front
is roughly 9δ. This can be used to choose a suitable value of h. For example, choosing
h ≈ δ would give roughly 9 grid points in the wave front, which is probably about the
minimum needed to resolve it well numerically. HINT: WLOG, we can pick t = 0 to
answer this since v(x, t) is a travelling wave. So look at v(x, 0) = 1 x .
1+e δ
Solution
(a) Let’s assume we can find a traveling wave solution of the form v̄((x − ct)/δ). Then
substitute into the reaction-diffusion equation, and see if we can find v̄, and whether it
coincides with the solution we get for symmetric case (α = 1/2).
c κ 1
− v̄ 0 = 2 v̄ 00 + v̄(α − v̄)(v̄ − 1) (Ex0.0j)
δ δ
q √
where c = 2κ (1/2 − α), δ = 2κ. Actually, we only need c to be some constant times
q
2κ
, so that we can get rid of other parameters. With a good choice of the constant,
we can also get rid of the effect of α
1 1
− ( − α)v̄ 0 = v̄ 00 + v̄(α − v̄)(v̄ − 1)
2 2
⇒2α(v̄ − v̄(v̄ − 1)) + (v̄ 00 + v̄ 0 − 2v̄ 2 (v̄ − 1)) = 0
0
3
AMATH 586 Hai Zhu Student ID: 1323888
Thus v(x, t) = v̄((x − ct)/δ) is a traveling wave solution to (Ex0.0c) provided that c
satisfies (Ex0.0i).
(b) Since v(x, t) is a traveling wave, we can take a look at the transition zone at t = 0, which
is v(x, 0) = 1 x .
1+e δ
Solve v(x, 0) = 0.99, and v(x, 0) = 0.01 gives x1 /δ ≈ −4.595, and x2 /δ ≈ 4.595. Thus
the transition zone is roughly 9δ.
4
AMATH 586 Hai Zhu Student ID: 1323888
Numerical solution The m-file AllenCahn_1d.m solves the equation (Ex0.0c) on the finite
domain a ≤ x ≤ b with no-flux (Neumann) boundary conditions
Traveling wave solutions will look similar to those observed for the Cauchy problem until the
wave gets near the boundary.
Problem 3. Download the m-file AllenCahn_1d.m and try it out. You should observe that
the initial discontinuity smooths out into a traveling wave. In parts (a) and (b) make sure
= .01 is what is set in the code.
(a) Try out both the fzero and newton approaches and observe the difference in efficiency.
(b) Modify the m-file so that it estimates the speed of the traveling wave using the following
observation: For a traveling wave,
Z b
d
v(x, t) dx = c (Ex0.0l)
dt a
as long as the wave front is far from the boundaries. Hence the speed at time tn can be
estimated from numerical results as
1 X n X
c≈ h Vj − h Vjn−N . (Ex0.0m)
Nk
j j
which computes the average speed over the past N time steps (it’s better to take N = 10
or so rather than computing from just one time step so that it behaves more smoothly).
Check that the observed speed approaches a value that agrees with the expected speed,
with an accuracy that is O(k) as the grid is refined. (Refine by the same factor in space
and time.)
(c) Using m = 99 and k = 0.005, change to = 0.001. Note that the numerical solution
converges to a traveling wave but that the speed is far from correct, even though the
wave front should be well resolved based on the result of Problem 2(b).
Reduce k with h fixed and note that the error in the speed can be greatly reduced on
this grid by choosing k appropriately.
(d) Try the values m = 99, k = 0.02, = 0.0001 and explain what you observe. Hint:
What equation is being solved by Newton’s method and how does this behave when k/
is large?
(e) Based on what you observed in parts (b) and (c), explain why we might want to choose
k = min(h, ) to achieve resonable results as we refine the grid.
5
AMATH 586 Hai Zhu Student ID: 1323888
(f) Since we need to take k ≤ to get reasonable solutions to the Allen-Cahn equation,
the reaction ODE is no longer considered to be stiff. This suggests that we could use
an explicit method in this step. Replace backward Euler with the 2-stage Runge-Kutta
method (5.30) and verify that better results are achieved than with the backward Eu-
ler method when stable values of k are used. In fact you should observe second-order
accuracy in the wave speed in this case.
(g) This m-file allows the use of either Crank-Nicolson or TR-BDF2. Since the initial data
is discontinuous, the results of Exercise 9.3 on HW4 suggest that TR-BDF2 may be a
better choice. Find parameter values that illustrate this.
Solution
(b) In order to estimate the speed at time tn , store the results of time tn , and time tn − 10 ∗ k.
Then compute the average speed. The following result is based on ratio h = 5k, tn =
tf inal = 0.3, (speed is given by c in problem 2):
6
AMATH 586 Hai Zhu Student ID: 1323888
The result by implementing fzero is nearly the same, except that the time is much
longer.
7
AMATH 586 Hai Zhu Student ID: 1323888
As we can tell from the plot, the error in the speed can be greatly reduced on this grid
by choosing k appropriately.
(d) By choosing far smaller than k, this numerical method can not give a smooth result of
traveling wave solution. Beyond that, we set α to be 0.3, which make the solution wave
travels to the right. Yet the numerical solution gives a high oscillating result traveling
to the left.
The following is the plot of the final plot:
To explain this, let’s first take a look at the behavior when we try to solve backward
Euler.
If we take a look at the correction vector during each time step, we can find that when
k/ is big, the correction vector can be much bigger than v itself, suppose g(v) is not 0.
This can be verified, if we produce the max norm of the correction vector. We may still
wonder, if newton method doesn’t converge in 10 steps, fzero will be used as a backup
method. So that the solution may still behave well. It turns out for these parameters,
the results are still not close to the real solution even if we use fzero directly.
For this numerical method, let’s consider what it really solves, if we assume the diffusion
and advection part are all solved precisely. For the diffusion part, this numerical method
will give us a solution that will smooth out as time goes by. And for the advection part,
it tries to absorb all the values to the nearest root of the polynomial P . When is small,
the advection part can be dominant, and the solution will be like
8
AMATH 586 Hai Zhu Student ID: 1323888
If we are implementing newton method, then when we try to get the root for Backward
Euler, it is in fact a combination of newton and fzero. So it hard to tell what it will be
like for a long period of time. But for short time, we can tell from the above two plots
that the results from newton and fezro are similar.
(e) Based on (c), if we choose k much bigger than , then the speed of this traveling wave
can not be well estimated. Based on (b), we usually want to let ratio of k/h be some
constant. Thus it might be a good choice if we let k = min h, .
(f) In order to use 2-stage Runge-Kuttta method, we may modify the code directly by adding
another method after newton and fzero as a replacement of Backward Euler. Or we can
implement 2-stage Runge-kutta first, and then solve the diffusion equation so that the
solution would still satisfy the boundary condition.
The part added is as bellow:
1 case 'rk2'
2 vstar = vn + 1/2*k/epsilon*g(vn);
3 v = vn + k/epsilon*g(vstar);
And the following is the error of estimated speed compared to real speed (ratio h = 5k):
9
AMATH 586 Hai Zhu Student ID: 1323888
So by changing to 2-stage Runge-Kutta method, we can get second order accuracy when
estimate wave speed. The result after exchanging the order of diffusion and reaction is
still pretty much the same, which would not be surprise, because the wave is still far
from the boundary.
And the following is the log-log plot:
(g) The following is just an example that shows TR-BDF2 is a better choice than CN. Here
I use tfinal= 0.1, k = 0.05, h = 0.03.( = 0.01, κ = 0.3, α = 0.3) So what we will see is
the result after 2 time steps:
10
AMATH 586 Hai Zhu Student ID: 1323888
11
AMATH 586 Hai Zhu Student ID: 1323888
Numerical methods for the diffusion equation in 2d. The Allen-Cahn equation in
two space dimensions involves two-dimensional diffusion. Before tackling the reaction-diffusion
equation, first consider the diffusion equation. The m-file heat_2d_noflux.m solves the heat
equation in the rectangular domain [ax , bx ] × [ay , by ] in two space dimensions with no-flux
(insulated) boundary conditions at each boundary,
• If diffmethod = ’CN_LOD’ then the Locally One Dimensional method is used based on
dimensional splitting. In this case only tridiagonal systems of dimension mx + 2 and
my + 2 must be solved in each time step.
Problem 4.
(a) In this code the Neumann boundary conditions are imposed using an idea similar to the
“second approach” on page 31 of the text, applied to the method of lines equation at
each grid point that lies on a boundary. Explain why this leads to the modification of
the matrix elements Tx(1,2), Tx(mx+2,mx+1), Ty(1,2), and Ty(my+2,my+1) seen in
the code for the unsplit Crank-Nicolson method.
(b) What boundary conditions are being imposed on U ∗ in the implementation of the LOD
method?
(c) For both the unsplit and LOD versions, test the code on an m × m grid in a square
domain, with different values of m = 24, 49, 99, 199.
Note that the code is written to compute the error and CPU time. Create log-log plots
of both the error for different m and the CPU time required for different m. You should
find that both methods are second order accurate. Does the splitting used in the LOD
method degrade the accuracy very much?
You should find that the unsplit method, which uses Gaussian elimination to solve the
large sparse linear system, is quite slow compared to the LOD method. Suppose that for
large m the CPU time grows like Cmq for some constants C and q. From your computed
results estimate C and q for each method. Approximately how long would it take to
solve this problem with m = 1999 with each method?
(d) Modify the heat_2d_noflux.m code to also implement the TR-BDF2 method in LOD
form.
12
AMATH 586 Hai Zhu Student ID: 1323888
Solution
(a) For the unsplit method, the code is dealing with the following vector:
v1,1 v1,2 · · · v1,my +2 · · · vmx +2,1 vmx +2,2 · · · vmx +2,my +2
Uijn+1 − Uijn κ 2 n
= (D U + Dy2 Uijn + Dx2 Uijn+1 + Dy2 Uijn+1 )
k 2 x ij
Let’s take a look at what happens at the boundary,
1
(v1,j − v−1,j ) = 0
2dx
1
(v1,j − 2v0,j + v−1,j ) = Dx2 U0j
2dx2
Eliminate v−1,j , we can get
1
Dx2 U0j = (−2v0,j + 2v1,j )
2dx2
Thus in the code we need to make modification of Tx(1,2). And once we define the
(mx + 2) × (my + 2) matrix, kron(Tx,Iy) will lead to the modification
of the my + 3
to 2(my + 2) columns, which
is exactly where v2,1 v2,2 · · · v2,my +2 would multiply.
v2,1 v2,2 · · · v2,my +2 are the points next to x = 0 boundary, that need our concern.
The same thing happens to Tx(mx+2,mx+1), Ty(1,2), and Ty(my+2,my+1).
1 % x−sweeps.
2 % Note that A2x is applied to all columns of the array v,
3 % and then the system A1x * v = rhs is solved for each column.
4 rhs = A2x*v;
5 v = A1x\rhs;
6
7 % y−sweeps.
8 % in second step, apply on rows:
9 rhs = A2y*v';
10 v = (A1y\rhs)';
13
AMATH 586 Hai Zhu Student ID: 1323888
The x-sweeps says vx∗ (ax , y, t) = vx∗ (bx , y, t) = 0. Because when we deal with v1,j
∗ and
∗
vmx +2,j , matrix A1x has been done the same kind of modification as in (a).
The y-sweeps says vy∗ (x, ay , t) = vy∗ (x, by , t) = 0. Because when we deal with vj,1
∗ and
∗
vj,m , matrix A2y has been done the same kind of modification as in (a).
y +2
This may lead us to wonder that after these two decoupled step, vx∗ (ax , y, t) = vx∗ (bx , y, t) =
0 is not satisfied. Because every value on x-slice has been changed, there is no guarantee
that the derivative with respect to x is still 0 on the boundary. That depends on how we
look at this problem, the value of v0,j∗ is unknown, where v ∗ to v ∗
1,j mx +2,j are grid points.
∗ ∗
We are allowed to still set v0,j = v2,j , which would make it possible to compute next time
step.
In fact, we are assuming that the value of the outside circle is changing according to
pattern of what this LOD method behaves.
Figure 7: unsplit method error vs. m Figure 8: unsplit CPU time vs. m
14
AMATH 586 Hai Zhu Student ID: 1323888
Figure 9: LOD method error vs. m Figure 10: LOD CPU time vs. m
(d) The following is the modified part for implementing TR-BDF2 when we try to set up
some necessary matrix:
15
AMATH 586 Hai Zhu Student ID: 1323888
1 switch diffmethod
2
3 case 'TRBDF2 LOD'
4
5 ex = ones(mx+2,1);
6 Tx = spdiags([ex −2*ex ex],[−1 0 1],mx+2,mx+2);
7 Tx(1,2) = 2;
8 Tx(mx+2,mx+1) = 2;
9 Tx = kappa/dxˆ2 * Tx;
10 % matrix for step1 CN
11 A1x = speye((mx+2)) − k/4 * Tx;
12 A2x = speye((mx+2)) + k/4 * Tx;
13 % matrix for step2 BDF
14 A3x = speye(mx+2) − k/3 * Tx;
15
16 ey = ones(my+2,1);
17 Ty = spdiags([ey −2*ey ey],[−1 0 1],my+2,my+2);
18 Ty(1,2) = 2;
19 Ty(my+2,my+1) = 2;
20 Ty = kappa/dyˆ2 * Ty;
21 % matrix for step1 CN
22 A1y = speye((my+2)) − k/4 * Ty;
23 A2y = speye((my+2)) + k/4 * Ty;
24 % matrix for step2 BDF
25 A3y = speye(my+2) − k/3 * Ty;
The following is the modified part for implementing TR-BDF2 when we compute during
one time step:
1 switch diffmethod
2
3 case 'TRBDF2 LOD'
4
5 % Use TR−BDF2 in LOD form:
6
7 % x−sweeps.
8 % Note that A2x is applied to all columns of the array v,
9 % and then the system A1x * v = rhs is solved for each column.
10 % TR step:
11 rhs = A2x*vn;
12 vnph = A1x\rhs;
13 % BDF2 step:
14 rhs = (4*vnph − vn) / 3;
15 vn = A3x\rhs;
16
17 % y−sweeps.
18 % in second step, apply on rows:
19 % TR step:
20 rhs = A2y*vn';
21 vnph = (A1y\rhs)';
22 % BDF2 step:
23 rhs = (4*vnph − vn)' / 3;
24 vn = (A3y\rhs)';
16
AMATH 586 Hai Zhu Student ID: 1323888
Figure 11: TR-BDF2 in LOD form er- Figure 12: TR-BDF2 in LOD form
ror vs. m CPU time vs. m
17
AMATH 586 Hai Zhu Student ID: 1323888
Problem 5. Combine the techniques from the m-files used above to create a program that
solves the two-dimensional Allen-Cahn equation in a general rectangular domain with no-flux
boundary conditions.
For diffusion use the LOD form of TR-BDF2. For the ODE solver use the 2-stage Runge-
Kutta method (5.30).
Test your code by solving the following problems with κ = 0.1, α = 0.5, = 0.001 on a
100 × 100 grid in −1 ≤ x ≤ 1, − 1 ≤ y ≤ 1:
(a) The example shown on the webpage above under Sample Results, which can be specified
by
v = zeros(size(X));
v(X>-0.8 & X<0.8 & Y>-0.3 & Y<0.3) = 1.0;
Print out plots of a few times for each problem to show that your code is working.
18
AMATH 586 Hai Zhu Student ID: 1323888
Solution
The LOD form of TR-BDF2 is the same as in problem 4(d). The ODE solver is also
the same as in problem 3(f). The part that contains the initial conditions is as follows:
(a) The following are the results for rectangular initial condition:
19
AMATH 586 Hai Zhu Student ID: 1323888
(b) The following are the results for periodic initial condition:
20
AMATH 586 Hai Zhu Student ID: 1323888
21
AMATH 586 Hai Zhu Student ID: 1323888
22
AMATH 586 Hai Zhu Student ID: 1323888
1
v 0 (t) = (g(v(t)) − w(t) + Ia ),
(Ex0.0r)
w0 (t) = βv(t) − γw(t).
Problem 6. (5 points)
(a) Write a code using ode15s to solve (Ex0.0r) and reproduce the figures shown above as a
test that it is working.
(b) Modify your code to also produce a phase plane plot (i.e., a plot of w(t) vs. v(t) as they
vary in time) similar to the plots on
[Link]
for example. Do this for each set of parameters used above, i.e. for
Ia = 0, v0 = 0.29,
Ia = 0, v0 = 0.31,
Ia = 0.2, v0 = 0.
(c) Experiment with varying and comment on what you observe, both in terms of how
the solution behaves (as a function of t and in the phase plane) and in terms of the
computational method.
Solution
23
AMATH 586 Hai Zhu Student ID: 1323888
(b) The following are the phase plot for different parameters:
24
AMATH 586 Hai Zhu Student ID: 1323888
(c) By changing values of , we can observe the solution barely change even if we change
the enormously. And when it comes to phase, I think it behaves the same way, which
means the ratio of w(t) vs. v(t) doesn’t change to much. The following is the computing
time for different :
25
AMATH 586 Hai Zhu Student ID: 1323888
The following is the figure for different , it looks like we can not distinguish one from
another.
26
AMATH 586 Hai Zhu Student ID: 1323888
Problem 7. (5 points)
Write a Matlab m-file to solve the one-dimensional FitzHugh-Nagumo equations (??). You
can base your code on AllenCahn_1d.m. You will have to keep track of w as well as v and
modify the reaction terms for the FitzHugh-Nagumo reactions. Again use the backward Euler
method for these terms. This will now require solving a system of 2 equations for Vjn+1 and
Wjn+1 at every grid point. Note, however, that the equation for w is linear and so it is possible
to express Wjn+1 as a function of Vjn+1 . Use this to reduce the problem to a scalar cubic
equation to be solved for Vjn+1 and use Newton’s method to solve this, similar to the approach
used in AllenCahn_1d.m. (You might want to first try using fzero at every point since this
is simpler, but you will find it runs very slowly.) Also implement the 2-stage explicit Runge-
Kutta method (5.30) and comment on whether this is an efficient approach relative to the
implicit method.
Test your code with the following two tests (feel free to experiment with more):
(b) Same situation as in part (a) but with initial data v(x, 0) = w(x, 0) = 0 and an applied
current Ia (x) = 0.8 exp(−5x2 ). This models a situation in which a stimulated nerve cell
sends out a train of pulses. Run the computation out to time t = 3 or so and you should
see several pulses generated.
Solution
The modified part of code is as follows:
1 %I = @(x) 0.8*exp(−5*x.ˆ2);
2 I = @(x) 0;
3
4 switch odemethod
5 case 'rk2'
6 vstar = vn + 1/2*k/epsilon*(g(vn)...
7 ...−(k*beta)*vnp/(1+k*gamma)−wn/(1+k*gamma)+I(x));
8 v = vn + k/epsilon*(g(vstar)−...
9 ...(k*beta)*vstar/(1+k*gamma)−wn/(1+k*gamma)+I(x));
10 w = (k*beta*v+wn)/(1+k*gamma);
11 case 'newton'
12 for inewton=1:10
13 Fvnp = vn + k/epsilon * (g(vnp)...
14 ...−(k*beta)*vnp/(1+k*gamma)−wn/(1+k*gamma)+I(x)) − vnp;
15 Fprime = k/epsilon * (gprime(vnp)−k*beta/(1+k*gamma)) − 1;
27
AMATH 586 Hai Zhu Student ID: 1323888
16 dv = Fvnp ./ Fprime;
17 vnp = vnp − dv;
18 if maxF < 1e−6
19 % convergence at all grid points
20 break
21 end
22 end
23
24 v = vnp;
25 ...
26 w = (k*beta*v+wn)/(1+k*gamma);
We don’t need to change the diffusion part, because w doesn’t have diffusion. And the
time difference between newton and 2-stage Runge-Kutta are as follows:
28
AMATH 586 Hai Zhu Student ID: 1323888
(b) The following are the figures of this traveling wave of different parameter:
29