You are on page 1of 16

Numerical Schemes for

Differential Equation, &


Boundary Conditions Impositions
Arkayan Laha
18RS018
Supervisor: Dr. Rumi De
Contents

1. Explicit and Implicit Numerical Schemes


2. Numerical Stability
3. Stability Criteria for Explicit Scheme(Von-Neumann Stability Criteria)
4. Stability Criteria for Implicit Scheme
5. Example of Explicit Schemes(Lax-Wendroff Method)
6. Example of Explicit Schemes(Crank-Nicolson Method)
7. Relative Comparison between Explicit and Implicit Methods
8. Dirichlet Boundary Conditions
9. Neumann Boundary Conditions
Explicit Numerical Schemes:
The state of a system at a later time is calculated from the state of the
system at the current state.
𝑑𝑦
For = 𝐹 𝑦 , 𝑦 𝑡 + ∆𝑡 = 𝐹 𝑦 𝑡 .
𝑑𝑡
Where y(t) is the current state, and y(t+Δt) is the state at the next step.
𝑑𝑦
Consider the differential equation = −𝑦 2 , t ∈ 0, 𝑎 with the
𝑑𝑡
initial condition 𝑦 0 = 𝑦0 .
For Forward Euler Method, 𝑦𝑘+1 = 𝑦𝑘 − ∆𝑡𝑦𝑘2 ,
𝑎 𝑘
With ∆𝑡 = ,𝑛 𝑖𝑠 𝑡ℎ𝑒 𝑛𝑢𝑚𝑏𝑒𝑟 𝑜𝑓 𝑡𝑖𝑚𝑒 𝑠𝑡𝑒𝑝𝑠, 𝑎𝑛𝑑 𝑡𝑘 = 𝑎 .
𝑛 𝑛
Implicit Numerical Schemes:
The state of the system at a later time is calculated from the state at the current
state and that at the later one.
𝑑𝑦
For = 𝐹 𝑦 , 𝑦 𝑡 + ∆𝑡 = 𝐹 𝑦 𝑡 , 𝑦(𝑡 + Δ𝑡) .
𝑑𝑡
𝑑𝑦
Consider the differential equation = −𝑦 2 , t ∈ 0, 𝑎 with the initial
𝑑𝑡
condition 𝑦 0 = 𝑦0 .
For Implicit Euler Method(also known as Euler Backward Method),
𝑦𝑘+1 − 𝑦𝑘 2
= −𝑦𝑘+1
∆𝑡
−1+ 1+4∆𝑡𝑦𝑘
Or, 𝑦𝑘+1 =
2∆𝑡
Numerical Stability:
Numerical stability has to do with the behavior of the solution at the
very large time.
If the solution remains well behaved even at large iterations of the
time, the solution is said to be numerically stable.
For explicit method, the numerical stability depends significantly on
the time step.
For implicit method, the numerical stability is independent of time
step and so it is called unconditionally stable method.
Von-Neumann Stability Analysis:
 It is used to check the stability of finite difference schemes for linear PDE.
 This is based on Discrete Fourier Transformation.
Consider the one dimensional Heat Equation:
𝜕𝑢(𝑥, 𝑡) 𝜕 2 𝑢(𝑥, 𝑡)
=𝐷
𝜕𝑡 𝜕𝑥 2
In discrete notation,
𝐷∆𝑡
𝑢𝑗𝑛+1 = 𝑢𝑗𝑛 +𝑟 𝑛 𝑛 𝑛
𝑢𝑗+1 − 2𝑢𝑗 + 𝑢𝑗−1 , where r = 2
∆𝑥
Insert 𝑢 𝑥𝑗 , 𝑡𝑛 = 𝐺 𝑛 (𝑘)𝑒 𝑖𝑘𝑥𝑗 into the FD Scheme, we
get the following:
𝐺 𝑛+1 𝑘 = [1 − 2𝑟 1 − cos 𝑘∆𝑥 ]𝐺 𝑛 (𝑘), where we use 𝑥𝑗 = 𝑗. ∆𝑥.
𝐺 𝑛+1 (𝑘)
We define a quantity called the growth factor as 𝐺 𝑘 = = 1 − 2𝑟 1 − cos 𝑘∆𝑥
𝐺 𝑛 (𝑘)
FD Scheme is stable if |𝐺 𝑘 | ≤ 1 for all k, i.e., 1 − 2𝑟 1 − cos 𝑘∆𝑥 ≤1
1
So the FD scheme is conditionally stable if 𝑟 ≤ .
2
So Explicit scheme is conditionally stable.
Source: ocw.mit.edu
Numerical Instability in Advection Equation:
𝜕𝑢 𝜕𝑢
The Advection- Diffusion equation is = −𝑣
𝜕𝑡 𝜕𝑥
𝑑𝑢𝑖 1 𝑣
In discrete notation = − 𝑣 𝑢𝑖+1 − 𝑢𝑖−1 , where 𝑣 = .
𝑑𝑡 2 ∆𝑥

Space Space

𝑣 = 6, ∆𝑡 = 0.0001, 𝑇 = 3 𝑣 = 0.10, ∆𝑡 = 0.0001, 𝑇 = 3


Stability Criteria for Implicit Scheme:
Consider the one dimensional Heat Equation:
𝜕𝑢(𝑥, 𝑡) 𝜕 2 𝑢(𝑥, 𝑡)
=𝐷
𝜕𝑡 𝜕𝑥 2
𝑗 𝑗+1 𝑗+1 𝑗+1
For Implicit Scheme, 𝑢𝑛 = −𝛼𝑢𝑛−1 + 1 + 2𝛼 𝑢𝑛 − 𝛼𝑢𝑛+1 , where
∆𝑡
𝛼 = 𝐷 2 , and n and j are the respective space and time index.
∆𝑥
𝑗
Consider 𝑢𝑛 = 𝜁𝑗 (𝑘)𝑒 𝑖𝑘𝑛Δ𝑥 , where 𝜁𝑗 (𝑘) is the growth factor at time t.
1 𝜁 𝑗+1 (𝑘)
𝜁 𝑘 = , where 𝜁 𝑘 =
1+2𝛼(1−cos 𝑘Δ𝑥 ) 𝜁 𝑗 (𝑘)
𝜁𝑗 𝑘 ≤ 1 for any ∆𝑡 and ∆𝑥.
So Implicit scheme is unconditionally stable.
Example of Explicit Schemes:
Lax-Wendroff Method:
It is a numerical method for the solution of hyperbolic partial differential
equation(e.g. Advection Equation), based on finite differences.
This is 2nd order accurate in both space and time.
Suppose we have a hyperbolic differential equation of the form
𝜕𝑢 𝜕𝑓(𝑢 𝑥,𝑡 )
+ = 0 with definite initial conditions and boundary conditions.
𝜕𝑡 𝜕𝑥
For linear case, 𝑓 𝑢 = 𝐴𝑢, 𝐴 is a constant.
2
𝑛+1 𝑛 ∆𝑡 𝑛 𝑛 ∆𝑡 2 𝑛 𝑛 𝑛
𝑢𝑖 = 𝑢𝑖 − 𝐴 𝑢𝑖+1 − 𝑢𝑖−1 + 2
𝐴 [𝑢𝑖+1 − 2𝑢𝑖 + 𝑢𝑖−1 ]
2∆𝑥 2∆𝑥
Where 𝑛 is the time index and 𝑖 is the space index.
Examples of Implicit Schemes:
Crank-Nicolson Method:
This is a combination of the forward Euler Method at 𝑡 = 𝑡𝑛 , and backward Euler Method at
𝑡 = 𝑡𝑛+1 .
𝜕𝑢 𝜕𝑢 𝜕2 𝑢
For the PDE of the form = 𝐹(𝑢, 𝑥, 𝑡, , 2 ),
𝑛+1 𝑛
𝜕𝑡 𝜕𝑥 𝜕𝑥
𝑢𝑖 −𝑢𝑖 1
= (𝐹𝑖𝑛+1 + 𝐹𝑖𝑛 ), where 𝑖 is the space index and 𝑛 is time index.
∆𝑡 2

Consider the one dimensional Heat Equation:


𝜕𝑢(𝑥, 𝑡) 𝜕 2 𝑢(𝑥, 𝑡)
=𝐷
𝜕𝑡 𝜕𝑥 2
CN- Method gives the matrix equation of the form: 𝐴𝑢𝑛+1 = 𝑏 𝑛 , where
∆𝑡
𝐴𝑖𝑖 = 2(1 + 𝛼) , and 𝐴𝑖±1 = −𝛼, with 𝛼 = 𝐷 2 ,
∆𝑥
𝑛+1 𝑛+1 𝑛+1 𝑛+1 𝑇
𝑢 = (𝑢1 𝑢2 … … … … . 𝑢𝑁 ) ,
and 𝑏 𝑛 = (𝑏1𝑛 𝑏2𝑛 … … … … . 𝑏𝑁𝑛 )𝑇 , with 𝑏𝑖𝑛 = 𝛼𝑢𝑖−1
𝑛
+ 2 1 − 𝛼 𝑢𝑖𝑛 + 𝛼𝑢𝑖+1
𝑛
.
Comparison:
 For implicit schemes, one can use large time step which is not
true for explicit schemes. In that way, implicit scheme is
preferred over explicit scheme due to less number of iteration
steps.
Though implicit schemes require less time iteration steps,
implicit schemes are more complex to program and require
more computational effort in each solution step.
Classification of Boundary Conditions:
Dirichlet Boundary Condition: It specifies the value that a solution needs to take on the
boundary of the domain.
𝑑2𝑦
For an ODE of the form + 𝑓 𝑥, 𝑦 = 0 , the Dirichlet BC on the interval 𝑎, 𝑏 takes the following
𝑑𝑥 2
form:
𝑦 𝑎 = 𝛼 , and 𝑦 𝑏 = 𝛽.
In Finite difference, it would be
𝑦 𝑥1 = 𝛼, 𝑦 𝑥𝑛 = 𝛽, where 𝑥1 and 𝑥𝑛 are the extreme left and right grid points, or 𝑥1 =a, and 𝑥𝑛 = 𝑏.
For any general node 𝑖,
(𝑦𝑖+1 −2𝑦𝑖 + 𝑦𝑖−1 )/∆𝑥 2 = −𝑓𝑖
Where 𝑓𝑖 = 𝑓 𝑥𝑖 , 𝑦𝑖 .
𝜕𝑢 𝜕2 𝑢
For the heat equation = 𝐷 2,
𝜕𝑡 𝜕𝑥
𝑢1𝑛 = 𝛼, and 𝑢𝑁
𝑛
= 𝛽 for 𝑛 ∈ 𝑅.
For any general node 𝑖,
𝑑𝑢𝑖𝑛 𝑛 𝐷
= 𝐷(𝑢𝑖−1 + 2𝑢𝑖𝑛 + 𝑢𝑖+1
𝑛
), where 𝑖 is the space index and 𝑛 is time index with 𝐷 = .
𝑑𝑡 ∆𝑥 2
Neumann Boundary Conditions: It specifies the values of the normal derivative
applied at the boundary of the domain.
𝑑2 𝑦
For an ODE of the form + 𝑓 𝑥, 𝑦 = 0 , the Neumann BC on the interval 𝑎, 𝑏
𝑑𝑥 2
takes the following form:
𝑑𝑦 𝑑𝑦
= 𝛼 at 𝑥 = 𝑎, and = 𝛽 at 𝑥 = 𝑏.
𝑑𝑥 𝑑𝑥

At 𝑥 = 𝑎, 𝑦0 = 𝑦2 − 2𝛼. So at 𝑥 = 𝑎,
2(𝑦2 −𝑦1 −𝛼)
+ 𝑓 𝑥1 , 𝑦1 = 0
∆𝑥 2
2(𝑦𝑁−1 −𝑦𝑁 +𝛽)
At 𝑥 = 𝑏, 𝑦𝑁+1 = 𝑦𝑁−1 + 2𝛽. So at 𝑥 = 𝑏, +𝑓 𝑥𝑁 , 𝑦𝑁 = 0.
∆𝑥 2
For any general node 𝑖,
(𝑦𝑖+1 −2𝑦𝑖 + 𝑦𝑖−1 )/∆𝑥 2 = −𝑓𝑖
Where 𝑓𝑖 = 𝑓 𝑥𝑖 , 𝑦𝑖 .
Advection-Diffusion Equation in Neumann Boundary
Condition:
𝜕𝑢 𝜕𝑢 𝜕2 𝑢
The Advection- Diffusion equation is = −𝑣 + 𝐷 2.
𝜕𝑡 𝜕𝑥 𝜕𝑥
𝜕𝑢
We consider zero flux BC, i.e., = 0 at 𝑥 = 𝑥1 = 𝑎 and 𝑥 = 𝑥𝑁 = 𝑏.
𝜕𝑥
𝑑𝑢1
At 𝑥 = 𝑥1 , = 2𝐷 𝑢2 − 𝑢1 .
𝑑𝑡
𝑑𝑢𝑁
At 𝑥 = 𝑥𝑁 , = 2𝐷 𝑢𝑁−1 − 𝑢𝑁 .
𝑑𝑡
For any general node 𝑖,
𝑑𝑢𝑖 1
= − 𝑣 𝑢𝑖+1 − 𝑢𝑖−1 + 𝐷(𝑢𝑖+1 − 2𝑢𝑖 + 𝑢𝑖−1 ).
𝑑𝑡 2
𝐷 𝑣
Where 𝐷 = , and 𝑣 = .
2∆𝑥 2 ∆𝑥
Advection-Diffusion Equation in Neumann Boundary Condition(2nd Method):
𝜕𝑢 𝜕𝑢 𝜕2 𝑢
• The Advection- Diffusion equation is = −𝑣 + 𝐷 2.
𝜕𝑡 𝜕𝑥 𝜕𝑥
𝜕𝑢
• We consider zero flux BC, i.e., = 0 at 𝑥 = 𝑥1 = 𝑎 and 𝑥 = 𝑥𝑁 = 𝑏.
𝜕𝑥
• To impose the Boundary Condition at the left boundary, 𝑢(𝑥 + ∆𝑥) and 𝑢(𝑥 + 2∆𝑥) are
needed to be expanded in Taylor Series:
𝜕𝑢 1 2 𝜕 2 𝑢 1 3 𝜕 3 𝑢
𝑢 𝑥 + ∆𝑥 = 𝑢 𝑥 + ∆𝑥 + ∆𝑥 2
+ ∆𝑥 3
+ ⋯…………..
𝜕𝑥 2 𝜕𝑥 3! 𝜕𝑥
and
𝜕𝑢 1 2 𝜕2𝑢 1 3 𝜕3𝑢
𝑢 𝑥 + 2∆𝑥 = 𝑢 𝑥 + 2∆𝑥 + 4 ∆𝑥 2
+ 8 ∆𝑥 3
+ ⋯…………..
𝜕𝑥 2 𝜕𝑥 3! 𝜕𝑥
Multiplying the first equation by 8, and then subtracting the second equation from it, we get
𝜕𝑢
𝜕2 𝑢 8𝑢 𝑥+∆𝑥 −𝑢 𝑥+2∆𝑥 −7𝑢 𝑥 −6∆𝑥 𝜕𝑥
= +𝑂 ∆𝑥 2
𝜕𝑥 2 2∆𝑥 2
𝜕2 𝑢 8𝑢2 −𝑢3 −7𝑢1
The Boundary condition at 𝑥 = 𝑥1 gives =
𝜕𝑥 2 2∆𝑥 2
𝑑𝑢1 𝐷
So at 𝑥 = 𝑥1 , = 𝐷 8𝑢2 − 𝑢3 − 7𝑢1 , with 𝐷 = .
𝑑𝑡 2∆𝑥 2
• To impose the Boundary Condition at the right boundary, 𝑢(𝑥 − ∆𝑥) and 𝑢(𝑥 − 2∆𝑥) are
needed to be expanded in Taylor Series:
𝜕𝑢 1 2 𝜕 2 𝑢 1 3 𝜕 3 𝑢
𝑢 𝑥 − ∆𝑥 = 𝑢 𝑥 − ∆𝑥 + ∆𝑥 2
− ∆𝑥 3
+ ⋯…………..
𝜕𝑥 2 𝜕𝑥 3! 𝜕𝑥
And
𝜕𝑢 1 2 𝜕2 𝑢 1 3 𝜕3 𝑢
𝑢 𝑥 − 2∆𝑥 = 𝑢 𝑥 − 2∆𝑥 + 4 ∆𝑥 − 8 ∆𝑥 + ⋯…………..
𝜕𝑥 2 𝜕𝑥 2 3! 𝜕𝑥 3
Multiplying the first equation by 8, and then subtracting the second equation from it, we get
𝜕𝑢
𝜕2 𝑢 8𝑢 𝑥−∆𝑥 −𝑢 𝑥−2∆𝑥 −7𝑢 𝑥 +6∆𝑥
= 𝜕𝑥
+𝑂 ∆𝑥 2
𝜕𝑥 2 2∆𝑥 2
𝜕2 𝑢
8𝑢𝑁−1 −𝑢𝑁−2 −7𝑢𝑁
The Boundary condition at 𝑥 = 𝑥𝑁 gives =
𝜕𝑥 2
2∆𝑥 2
𝑑𝑢 𝐷
So at 𝑥 = 𝑥𝑁 , 𝑁 = 𝐷 8𝑢𝑁−1 − 𝑢𝑁−2 − 7𝑢𝑁 , with 𝐷 = .
𝑑𝑡 2∆𝑥 2
• For any general node 𝑖,
𝑑𝑢𝑖 1 𝑣
= − 𝑣 𝑢𝑖+1 − 𝑢𝑖−1 + 𝐷(𝑢𝑖+1 − 2𝑢𝑖 + 𝑢𝑖−1 ) , with 𝑣 = .
𝑑𝑡 2 ∆𝑥

You might also like