
Numerical Methods Chemotaxis Cross-diffusion Nonlocal models Conclusions Reaction-Diffusion Models and Bifurcation Theory Lecture 4: Numerical methods, chemotaxis, cross-diffusion and nonlocal models Junping Shi College of William and Mary, USA Numerical Methods Chemotaxis Cross-diffusion Nonlocal models Conclusions Advection-reaction-diffusion equations General initial-boundary value problem: ut = D∆u − V ·∇u + f (x, u), x ∈ Ω, t > 0, u(x, 0) = u0(x) ≥ 0, x ∈ Ω, Bu(x, t)= g(x), x ∈ ∂Ω, t > 0. 1-D problem: ut = duxx − aux + f (x, u), x ∈ (0, L), t > 0, ≥ ∈ u(x, 0) = u0(x) 0, x (0, L), dux (0, t) − au(0, t) = −b, t > 0, −dux (L, t)+ au(L, t)= cu(L, t), t > 0. Boundary conditions can be Dirichlet, Neumann, etc. Most most equations cannot be solved analytically, hence to visualize the solutions, we need to use numerical solutions. Numerical Methods Chemotaxis Cross-diffusion Nonlocal models Conclusions Setup of the finite difference method A sample problem ut = duxx − aux + f (u), x ∈ (0, L), t > 0, u(x, 0) = u0(x) ≥ 0, x ∈ (0, L), ux (0, t)= ux (L, t) = 0, t > 0. We divide the interval [0, L] to n equal subintervals [xi , xi+1], i = 1, 2, ··· , n, n + 1, with xi = xi−1 +∆x, x1 =0 and ∆x = L/n (which we call grid size.) We also denote the step size (in the time direction) by ∆t. We define i i i i−1 uj = u(x , tj ), tj = tj−1 +∆t, x = x +∆x, 1 ≤ j ≤ m, 1 ≤ i ≤ n + 1. Basic algorithm: 1 2 n+1 1. the vector [u1 , u1 , ··· , u1 ] is known (initial condition); 1 2 n+1 1 2 n+1 2. For j = 1 to j = n, define [uj+1, uj+1, ··· , uj+1 ] from [uj , uj , ··· , uj ]. Numerical Methods Chemotaxis Cross-diffusion Nonlocal models Conclusions The grid Numerical Methods Chemotaxis Cross-diffusion Nonlocal models Conclusions Difference equations Approximate derivative by difference: ui − ui ui − ui i j+1 j i j j−1 ut (x , tj )= (forward difference), or ut (x , tj )= (backward ∆t ∆t difference) − ui+1 − ui ui − ui 1 i j j i j j ux (x , tj )= (forward difference), or ux (x , tj )= (backward ∆x ∆x difference) − ui+1 − 2ui + ui 1 i j j j ux (x , tj )= (central difference), (∆x)2 We use backward differences. Then ut = duxx − aux + f (u) becomes i i i+1 i i−1 i i−1 uj − uj− uj − 2uj + uj uj − uj 1 = d − a + f (ui ) ∆t (∆x)2 ∆x j i i+1 i i−1 i uj−1 = −ruj + (1 + 2r + s)uj − (r + s)uj − ∆t · f (uj ) d∆t a∆t where r = , s = . (∆x)2 ∆x This formula works for 2 ≤ i ≤ n but not i = 1 and i = n + 1 (boundary point) Numerical Methods Chemotaxis Cross-diffusion Nonlocal models Conclusions Boundary points i i+1 i i−1 i d∆t u − = −ru + (1 + 2r + s)u − (r + s)u − ∆tf (u ), where r = , j 1 j j j j (∆x)2 a∆t s = . ∆x 1 n+1 The definition of uj−1 and uj−1 would need the values outside of [0, L]. So we define 0 n+2 uj to be the value at x = −∆x and uj to be the value at x = L +∆x. u1 − u0 j j 0 1 Neumann boundary: ux (0) = 0: ux (0, tj )= = 0 so u = u . Then ∆x j j 1 2 1 0 1 2 1 1 uj−1 = −ruj + (1 + 2r + s)uj − (r + s)uj − ∆t · f (uj )= −ruj +(1+ r)uj − ∆t · f (uj ) n+1 n+2 n+1 n n+1 uj−1 = −ruj + (1 + 2r + s)uj − (r + s)uj − ∆t · f (uj )= n+1 n n+1 (1 + r + s)uj − (r + s)uj − ∆t · f (uj ) So we can put the equations in a matrix form: [uj−1]= A[uj ] − ∆t[f (uj )] where A is the (n + 1) × (n + 1) conversion matrix (for example n = 6) 1+ r −r 0 0 0 0 0 −r − s 1 + 2r + s −r 0 0 0 0 0 −r − s 1 + 2r + s −r 0 0 0 0 0 −r − s 1 + 2r + s −r 0 0 0 0 0 −r − s 1 + 2r + s −r 0 0 0 0 0 −r − s 1 + 2r + s −r − − 00 0 0 0 r s 1+ r + s Numerical Methods Chemotaxis Cross-diffusion Nonlocal models Conclusions Implicit finite difference method Instead of [uj−1]= A[uj ] − [f (uj )] will use [uj−1]= A[uj ] − [f (uj−1)] Then −1 [uj ]= A ([uj−1]+∆t[f (uj−1)]) Remarks: 1. The key of the above method is to define the (n + 1) × (n + 1) matrix A. The rows from i = 2 to i = n are same regardless of boundary conditions, and the row i = 1 and i = n + 1 may change with different boundary conditions. a∆t 2. It also works for diffusion (no advection) equation with s = = 0, or advection ∆x d∆t (no diffusion) equation r = = 0. (∆x)2 3. It is more accurate if n is larger. Usually we take ∆t = O((∆x)2). Numerical Methods Chemotaxis Cross-diffusion Nonlocal models Conclusions The code: Fisher-KPP equation and Neumann BC % Calculate the solution of Fisher-KPP equation with Neumann BC xl=0; %left endpoint xr=10; %right endpoint tfinal=10; %time to integrate dx=0.2; %spatial grid size dt=0.01; %time step size nx=(xr-xl)/dx+1; %number of spatial subintervals nt=tfinal/dt+1; %number of time steps diff=0.1; %diffusion coefficient a=1; %parameter: growth rate s=diff*dt/(dx*dx); %diffusion rate xmesh=linspace(xl,xr,nx); %vector in x direction tmesh=linspace(0,tfinal,nt); %vector in t direction U=zeros(nx,nt); %matrix of solution U(:,1)=0.4+0.1*sin(xmesh’); %initial condition Numerical Methods Chemotaxis Cross-diffusion Nonlocal models Conclusions The code: Fisher-KPP equation and Neumann BC A=zeros(nx,nx); %diffusion matrix A(1,1)=1+s; A(1,2)=-s; %first row A(nx,nx-1)=-s; A(nx,nx)=1+s; %last row for i=2:nx-1 %other rows A(i,i)=1+2*s; A(i,i-1)=-s; A(i,i+1)=-s; end AA=inv(A); %take the inverse matrix for i=1:nt-1 %for time t for j=1:nx %for space x F(j)=U(j,i)+dt*(a*U(j,i)-U(j,i)*U(j,i)); % logistic nonlinearity end U(:,i+1)=AA*(F’); %multiply the inverse matrix end surf(tmesh,xmesh,U,’EdgeColor’,’none’); %graph in 3D Numerical Methods Chemotaxis Cross-diffusion Nonlocal models Conclusions Numerical results: Neumann boundary Left: 3D view of the solution; Right: 2D view of the solution Numerical Methods Chemotaxis Cross-diffusion Nonlocal models Conclusions No flux boundary condition u1 − u0 j j 1 No flux boundary: dux (0) − au(0) = 0: dux (0, tj )= d = au so ∆x j 0 − a∆x 1 − s 1 uj = 1 d uj = 1 r uj . Then 1 2 1 0 1 uj−1 = −ruj + (1 + 2r+ s)uj − (r + s)uj − ∆t · f (uj )= 2 2 1 1 −ruj +(1+ r + s + s /r)uj − ∆t · f (uj ) 1+ r + s + s2/r −r 0 0 0 0 0 −r − s 1 + 2r + s −r 0 0 0 0 0 −r − s 1 + 2r + s −r 0 0 0 0 0 −r − s 1 + 2r + s −r 0 0 0 0 0 −r − s 1 + 2r + s −r 0 0 0 0 0 −r − s 1 + 2r + s −r 0 0000 −r − s 1+ r + Numerical Methods Chemotaxis Cross-diffusion Nonlocal models Conclusions Periodic boundary condition ut = duxx − aux + f (u), x ∈ (0, L), t > 0, u(x, 0) = u0(x) ≥ 0, x ∈ (0, L), u(0, t) = u(L, t), ux (0, t)= ux (L, t), t > 0. 1 n+1 In this case: we think uj = uj , and we use n × n matrix instead of (n + 1) × (n + 1) matrix 1 + 2r + s −r 0 0 0 0 −r − s −r − s 1 + 2r + s −r 0 0 0 0 0 −r − s 1 + 2r + s −r 0 0 0 0 0 −r − s 1 + 2r + s −r 0 0 0 0 0 −r − s 1 + 2r + s −r 0 0 0 0 0 −r − s 1 + 2r + s −r −r 0 0 0 0 −r − s 1 + 2r + s So periodic boundary condition corresponds to a cyclic matrix! Numerical Methods Chemotaxis Cross-diffusion Nonlocal models Conclusions Dirichlet Boundary condition 1 n+1 In this case, uj and uj are always 0, so we use an (n − 1) × (n − 1) matrix 1 + 2r + s −r 0 0 0 0 0 −r − s 1 + 2r + s −r 0 0 0 0 0 −r − s 1 + 2r + s −r 0 0 0 0 0 −r − s 1 + 2r + s −r 0 0 0 0 0 −r − s 1 + 2r + s −r 0 0 0 0 0 −r − s 1 + 2r + s −r 0 0 0 0 0 −r − s 1 + 2r + s Numerical Methods Chemotaxis Cross-diffusion Nonlocal models Conclusions The code: Fisher-KPP equation and Dirichlet BC A=zeros(nx-2,nx-2); A(1,1)=1+2*s; A(1,2)=-s; A(nx-2,nx-3)=-s; A(nx-2,nx-2)=1+2*s; for i=2:nx-3 A(i,i)=1+2*s; A(i,i-1)=-s; A(i,i+1)=-s; end AA=inv(A); for i=1:nt-1 for j=2:nx-1 F(j-1)=U(j,i)+dt*a*U(j,i)-dt*U(j,i)*U(j,i); end Utemp=AA*(F’); U(1,i+1)=0; U(nx,i+1)=0; for j=2:nx-1 U(j,i+1)=Utemp(j-1); end end Numerical Methods Chemotaxis Cross-diffusion Nonlocal models Conclusions Numerical results: Dirichlet Boundary Left: 3D view of the solution; Right: 2D view of the solution; Below: when t = tfinal (close to a steady state) 0.5 60 0.45 0.4 50 0.35 0.3 40 0.25 30 0.2 0.15 20 0.1 10 0.05 0 0 2 4 6 8 10 Numerical Methods Chemotaxis Cross-diffusion Nonlocal models Conclusions Numerical results: KPP-Fisher with advection and Dirichlet Boundary Left: 3D view of the solution; Right: 2D view of the solution; Below: when t = tfinal (close to a steady state) 0.5 60 0.45 0.4 50 0.35 0.3 40 0.25 30 0.2 0.15 20 0.1 10 0.05 0 0 2 4 6 8 10 Numerical Methods Chemotaxis Cross-diffusion Nonlocal models Conclusions Numerical methods for systems of equations ut = d1uxx − a1ux + f (u, v), x ∈ (0, L), t > 0, v = d v − a v + g(u, v), x ∈ (0, L), t > 0, t 2 xx 2 x u(x, 0) = u0(x), v(x, 0) = v0(x), x ∈ (0, L), ux (0, t)= ux (L, t) = 0, t > 0, vx (0, t)= vx (L, t) = 0, t > 0.
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages39 Page
-
File Size-