0% found this document useful (0 votes)
13 views

Tutorial 6

The document describes how to numerically solve a 1D unsteady advection-diffusion equation using finite difference methods. It provides the discretization equations for the central and upwind schemes using implicit Euler time stepping. Matlab code is presented for the central scheme as an example. The tasks are to derive the upwind scheme discretization, write the Matlab code for it, and discuss scheme selection based on Peclet number.

Uploaded by

azurebirble12
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

Tutorial 6

The document describes how to numerically solve a 1D unsteady advection-diffusion equation using finite difference methods. It provides the discretization equations for the central and upwind schemes using implicit Euler time stepping. Matlab code is presented for the central scheme as an example. The tasks are to derive the upwind scheme discretization, write the Matlab code for it, and discuss scheme selection based on Peclet number.

Uploaded by

azurebirble12
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

EX2010 Tutorial 6

One-Dimensional Unsteady Advection-Diffusive Equation

Finite Difference Schemes

Description of problem

An unsteady advection-diffusive equation is written as

𝜕𝐶 𝜕𝐶 𝜕2 𝐶
+𝑢 −𝛤 =𝑆 (1)
𝜕𝑡 𝜕𝑥 𝜕𝑥 2

where u is the velocity, 𝛤 is the diffusion coefficient and S is the source term. Using
finite difference method, numerically solving the equation in a computational domain
𝑥 ∈ [0, 𝐿] with the following boundary conditions,
• At x = 0, C = 1
• At x = L, 𝐶 = 0
At the initial step, C = 0 in the entire domain.

A reminder

In Tutorial 5, you have been asked to discretise the steady 1D advection-diffusive


𝜕𝐶 𝜕2 𝐶
equation, 𝑢 −𝛤 = 𝑆. You shall have discretised the equation using the central
𝜕𝑥 𝜕𝑥 2
𝜕2 𝐶 𝜕𝐶
scheme for 𝜕𝑥 2 , linear forward/backward and central scheme for . The derivation
𝜕𝑥
leads to the following formula.

𝜕𝐶 𝜕2 𝐶
• Central scheme (central scheme for both 𝜕𝑥 and 𝜕𝑥 2)

𝑢 𝛤 𝛤 𝑢 𝛤
(− 2𝑖 − ∆𝑥𝑖 ) 𝐶𝑖−1 + 2 ∆𝑥𝑖 𝐶𝑖 + ( 2𝑖 − ∆𝑥𝑖 ) 𝐶𝑖+1 = ∆𝑥𝑆𝑖 (2)

Shiqiang Yan, Oct. 2023 1


𝜕2 𝐶
• Upwind scheme (central scheme for 𝜕𝑥 2, linear backward when u is positive,
𝜕𝐶
linear forward when u is negative for )
𝜕𝑥

𝛤 𝛤 𝛤
(𝑚𝑖𝑛⁡(−𝑢𝑖 , 0) − ∆𝑥𝑖 ) 𝐶𝑖−1 + (2 ∆𝑥𝑖 + 𝑎𝑏𝑠(𝑢𝑖 )) 𝐶𝑖 + (𝑚𝑖𝑛⁡(0, 𝑢𝑖 ) − ∆𝑥𝑖 ) 𝐶𝑖+1 = ∆𝑥𝑆𝑖 (3)

Please be noted that when deriving these equations, we have multiplied both sides of
𝜕𝐶 𝜕2 𝐶
the equations by ∆𝑥. In the other words, directly replacing the derivatives in 𝑢 𝜕𝑥 − 𝛤 𝜕𝑥 2 =
𝑆 using finite difference schemes, it leads to

1 𝑢𝑖 𝛤 1 2𝛤 1 𝑢 𝛤
(− − ∆𝑥𝑖 ) 𝐶𝑖−1 + ∆𝑥 ( ∆𝑥𝑖 ) 𝐶𝑖 + ∆𝑥 ( 2𝑖 − ∆𝑥𝑖 ) 𝐶𝑖+1 = 𝑆𝑖 (4)
∆𝑥 2

and
1 𝛤 1 2𝛤 1 𝛤
(𝑚𝑖𝑛⁡(−𝑢𝑖 , 0) − ∆𝑥𝑖 ) 𝐶𝑖−1 + ∆𝑥 ( ∆𝑥𝑖 + 𝑎𝑏𝑠(𝑢𝑖 )) 𝐶𝑖 + ∆𝑥 (𝑚𝑖𝑛⁡(0, 𝑢𝑖 ) − ∆𝑥𝑖 ) 𝐶𝑖+1 = 𝑆𝑖 (5)
∆𝑥

for the central and upwind schemes, respectively.

Discretising the time derivative using Euler’s method

Compared with the 1D stead advection-diffusive equation, the unsteady one has an
additional term. Accordingly, one only needs to add one additional term into the above
𝜕𝐶
discretised equation. This additional term is the finite difference scheme for 𝜕𝑡 , i.e.

𝜕𝐶 𝐶𝑖𝑘+1 −𝐶𝑖𝑘
= (6)
𝜕𝑡 ∆𝑡

For the central scheme (Eq. (3)), we have

𝐶𝑖𝑘+1−𝐶𝑖𝑘 1 𝑢𝑘+1 Γ𝑘+1 𝑘+1 1 2Γ𝑘+1 1 𝑢𝑘+1 Γ𝑘+1


∆𝑡
+ ∆𝑥 (− 𝑖
2
− 𝑖
∆𝑥
) 𝐶𝑖−1 + ∆𝑥 ( 𝑖
∆𝑥
) 𝐶𝑖𝑘+1 + ∆𝑥 ( 𝑖
2
− 𝑖
∆𝑥
𝑘+1
) 𝐶𝑖+1 = S𝑖𝑘+1 (7)

for the implicit Euler’s method, and

𝐶𝑖𝑘+1−𝐶𝑖𝑘 1 𝑢𝑘 Γ𝑘 𝑘 1 2Γ𝑘 1 𝑢𝑘 Γ𝑘
+ ∆𝑥 (− 𝑖
− ∆𝑥𝑖 ) 𝐶𝑖−1 + ∆𝑥 ( ∆𝑥𝑖 ) 𝐶𝑖𝑘 + ∆𝑥 ( 2𝑖 − ∆𝑥𝑖 ) 𝐶𝑖+1
𝑘
= S𝑖𝑘 (8)
∆𝑡 2

for the explicit Euler’s method. For your convenience, all changes compared with the
Eq. (4) is highlighted in red. Generally, the implicit Euler’s method has better stability
and thus is used more popular than the Explicit one. Moving all terms in Eq. (7) related
to k-th time step to the right-hand side, multiplying ∆𝑥, it leads to

𝑢𝑘+1 Γ𝑘+1 𝑘+1 2Γ𝑘+1 ∆𝑥 𝑢𝑘+1 Γ𝑘+1 ∆𝑥


(− 𝑖
− 𝑖
) 𝐶𝑖−1 +( 𝑖
+ ∆𝑡 ) 𝐶𝑖𝑘+1 + ( 𝑖
− 𝑖 𝑘+1
) 𝐶𝑖+1 = ∆𝑥S𝑖𝑘+1 + ∆𝑡 𝐶𝑖𝑘 (9)
2 ∆𝑥 ∆𝑥 2 ∆𝑥

Compared with Eq. (2), the changes are highlighted in blue. Similarly, Eq. (8) can be
rearranged to

∆𝑡 𝑢𝑘 Γ𝑘 ∆𝑡 2Γ𝑘 ∆𝑡 𝑢𝑘 Γ𝑘
𝐶𝑖𝑘+1 = − ∆𝑥 (− 𝑖 𝑘
− ∆𝑥𝑖 ) 𝐶𝑖−1 − ∆𝑥 ( ∆𝑥𝑖 ) 𝐶𝑖𝑘 − ∆𝑥 ( 2𝑖 − ∆𝑥𝑖 ) 𝐶𝑖+1
𝑘
+ ∆𝑡S𝑖𝑘 + 𝐶𝑖𝑘 (10)
2

Shiqiang Yan, Oct. 2023 2


Matlab Coding

You can make minor change to the code you have developed in Tutorial 5 to solve the
unsteady problem. The following is the code for the central scheme, in which the
changes to accommodate the time derivative are highlighted in red, those due to the
change of the boundary condition at i = n is highlighted in orange.

function [ xs,ts, fs ] = unsteady1DCDE(L,n,f0, fL, u, Tau, S,


ts,te,nStep )
% finite difference method for solving 1D unseady
% convection-diffusive equation
% df/dt + u (df/dx) - Tau (d2f/dx2) = s
% with boundary condition
% x = 0, f = f0
% x = L, f = fL
%
% u -- velocity, constant
% Tau -- diffusion coefficient, constant
% S -- source term, constant
%
% n -- number of nodes
% L -- length of the domain

%1) generate the mesh


dx = L/(n-1.0);
xs = 0:dx:L;

dt = (te-ts)/nStep;
ts = ts:dt:ts;

% give initial condition


for i = 1:length(xs)
fs(1,i) = 0.0;
end

% 2) descretise the equation


for k = 1: nStep

% leading to A F = B
A = zeros(n);
B(1:n) = 0;

for i = 1:n
if i == 1 % left boundary
A(i,i) = 1.0;
B(i) = f0;
elseif i == n % right boundary
A(i,i) = 1.0;
B(i) = fL;
else
A(i,i-1) = - u/2.0 - Tau/dx;
A(i,i) = 2*Tau/dx + dx/dt;
A(i,i+1) = u/2.0 - Tau/dx;
B(i) = dx*S + dx/dt*fs(k,i);
end
end
% solving the linear system of equation
fs(k+1,:) = A\B';
end
end

Shiqiang Yan, Oct. 2023 3


Your Tasks

1) Following the above procedure, write the corresponding discretised upwind


scheme using the implicit Euler’s method.
2) Write the Matlab code for unsteady advection-diffusive equation using the
upwind scheme on the basis of the code you have generated when completing
Tutorial 5.
𝑢∆𝑥
3) In practices, we choose these two schemes based on Peclet Number (Pe = Γ ).
When Pe >=2 using the upwind scheme, otherwise using the central scheme.
Combine the code for the upwind and code for the central to develop the code
for the hybrid scheme, i.e. to use a condition of Pe to choose which schemes to
be used.

Shiqiang Yan, Oct. 2023 4

You might also like