Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 8

CFD HOMEWORK #2

Name: Duong Tien Trung


Student ID: 201783553
Problem 1
𝑑2 𝑢
− 𝑢 = −𝑥 2 (1), 0 ≤ 𝑥 ≤ 1
𝑑𝑥 2
Boundary condition: u(0) = 0, 𝑢(1) = 0
2𝑐𝑜𝑠ℎ1−3
Exact solution: u = 2 + 𝑥 2 − 2𝑐𝑜𝑠ℎ𝑥 + ( ) 𝑠𝑖𝑛ℎ𝑥
𝑠𝑖𝑛ℎ1

Numerical method:
Introduce 5 nodes which are equally spaced within the domain [0,1].

From the boundary condition, 𝑢0 = 𝑢4 = 1.


Apply the second-order central difference approximation for the left-hand side of equation
(1):
𝑢𝑖−1 − 2𝑢𝑖 + 𝑢𝑖+1
− 𝑢𝑖 = −𝑥𝑖2
∆𝑥 2
Therefore:
𝑢0 − 2𝑢1 + 𝑢2
2
− 𝑢1 = −𝑥12 (2)
∆𝑥
𝑢1 − 2𝑢2 + 𝑢3
2
− 𝑢2 = −𝑥22 (3)
∆𝑥
𝑢2 − 2𝑢3 + 𝑢4
− 𝑢3 = −𝑥32 (4)
∆𝑥 2
Where 𝑥1 = 0.25, 𝑥2 = 0.5, 𝑥3 = 0.75.
Rearrange equations (2), (3) and (4), we have the system of equations:
−(2 + ∆𝑥 2 )𝑢1 + 𝑢2 = −𝑥12 ∆𝑥 2
𝑢1 − (2 + ∆𝑥 2 )𝑢2 + 𝑢3 = −𝑥22 ∆𝑥 2
𝑢2 − (2 + ∆𝑥 2 )𝑢3 = −𝑥32 ∆𝑥 2
Then, we have the system of equations in matrix form:
−(2 + ∆𝑥 2 ) 1 0 𝑢1 −𝑥12 ∆𝑥 2
[ 1 −(2 + ∆𝑥 2 ) 1 ] (𝑢2 ) = (−𝑥22 ∆𝑥 2 )
0 1 −(2 + ∆𝑥 2 ) 𝑢3 −𝑥32 ∆𝑥 2

−2.0625 1 0 𝑢1 −0.00390625
[ 1 −2.0625 1 𝑢
] ( 2 ) = ( −0.015625 )
0 1 −2.0625 𝑢3 −0.03515625
Solve the above system by using matrix multiplication in Excel, we obtain the solution:
𝑢1 = 0.0172, 𝑢2 = 0.0316, 𝑢3 = 0.0324.

Or we can obtain the solution by using interactive calculation in Excel:


From equations (2), (3) and (4), we have:
𝑢0 + 𝑥12 ∆𝑥 2 + 𝑢2
𝑢1 = (5)
2 + ∆𝑥 2
𝑢1 + 𝑥22 ∆𝑥 2 + 𝑢3
𝑢2 = (6)
2 + ∆𝑥 2
𝑢2 + 𝑥32 ∆𝑥 2 + 𝑢4
𝑢3 = (7)
2 + ∆𝑥 2
Enable the interactive calculation check-box:

Type the equations (5), (6) and (7) into cell u1, u2, u3 respectively, we also get the solution.
From the obtained solution, the graph comparing the numerical solution and exact solution
is drawn as below:

Problem 1
0.04
0.035
0.03
0.025
0.02
u

0.015 Numerical solution


0.01 Exact solution
0.005
0
0 0.2 0.4 0.6 0.8 1
x

Problem 2: Explicit method


One-dimensional heat equation:
𝜕𝑢 𝜕 2 𝑢
= 0 ≤ 𝑥 ≤ 1, 𝑡 ≥ 0 (1)
𝜕𝑡 𝜕𝑥 2
Initial condition:
𝑢(0, 𝑥) = 0
Boundary condition:
𝑢(𝑡, 0) = 0 𝑎𝑛𝑑 𝑢(𝑡, 1) = 1
For now, 𝜕𝑢⁄𝜕𝑡 will be represented by a forward difference approximation:
𝜕𝑢 𝑢𝑖𝑛+1 − 𝑢𝑖𝑛
≅ (2)
𝜕𝑡 ∆𝑡
Using the second-order central differencing of order ∆𝑥 2 for the diffusion term:
𝑛
𝜕 2 𝑢 𝑢𝑖+1 − 2𝑢𝑖𝑛 + 𝑢𝑖−1
𝑛

𝜕𝑥 2 ∆𝑥 2
Therefore, the equation (2) can be approximated by the following difference equation:
𝑢𝑖𝑛+1 − 𝑢𝑖𝑛 𝑢𝑖+1
𝑛
− 2𝑢𝑖𝑛 + 𝑢𝑖−1
𝑛
≅ (3)
∆𝑡 ∆𝑥 2
In this equation, 𝑢𝑖𝑛+1 is the only unknown and, therefore, it can be computed from the
following:
∆𝑡
𝑢𝑖𝑛+1 = 𝑢𝑖𝑛 + (𝑢𝑛 − 2𝑢𝑖𝑛 + 𝑢𝑖−1
𝑛 )
(4)
∆𝑥 2 𝑖+1
Thus, the second-order partial differential equation has been replaced by an algebraic equation.
Graphical representation of grid points of this problem is shown as below:

Note that the value of the dependent variable at time level n is known from a previous solution
or given as initial data; i.e., the computed values at n+1 depend only on the past history.
We can solve this problem by using Excel.
At time t=0, we have the initial condition as follows:

And the boundary condition for time t ≥ 0 is shown as below:


From equation (4), the solution at time t=0.01 can be expressed as below:
∆𝑡
𝑢11 = 𝑢10 + (𝑢0 − 2𝑢10 + 𝑢00 ) (5)
∆𝑥 2 2
∆𝑡
𝑢21 = 𝑢20 + (𝑢0 − 2𝑢20 + 𝑢10 ) (6)
∆𝑥 2 3
∆𝑡
𝑢31 = 𝑢30 + 2
(𝑢40 − 2𝑢30 + 𝑢20 ) (7)
∆𝑥
Type the equations (5), (6) and (7) into cell u1, u2, u3 respectively, we also get the solution
for time t=0.01:

Therefore, we obtain solutions for other time steps:

From the obtained solutions, the graph comparing the solutions for numerous time steps is
drawn as follows:

Explicit method
1
0.9
0.8
0.7
t=0.04
0.6
t=0.08
0.5
u

0.4 t=0.12

0.3 t=0.16
0.2 t=0.20
0.1 t=infinite
0
0 0.25 0.5 0.75 1
x
Problem 3: Implicit method
One-dimensional heat equation:
𝜕𝑢 𝜕 2 𝑢
= 0 ≤ 𝑥 ≤ 1, 𝑡 ≥ 0 (1)
𝜕𝑡 𝜕𝑥 2
Initial condition:
𝑢(0, 𝑥) = 0
Boundary condition:
𝑢(𝑡, 0) = 0 𝑎𝑛𝑑 𝑢(𝑡, 1) = 1
For now, 𝜕𝑢⁄𝜕𝑡 will be represented by a backward difference approximation:
𝜕𝑢 𝑢𝑖𝑛+1 − 𝑢𝑖𝑛
≅ (2)
𝜕𝑡 ∆𝑡
Using the second-order central differencing of order ∆𝑥 2 for the diffusion term:
𝑛+1
𝜕 2 𝑢 𝑢𝑖+1 − 2𝑢𝑖𝑛+1 + 𝑢𝑖−1
𝑛+1

𝜕𝑥 2 ∆𝑥 2
Therefore, the equation (2) can be approximated by the following difference equation:
𝑢𝑖𝑛+1 − 𝑢𝑖𝑛 𝑢𝑖+1
𝑛+1
− 2𝑢𝑖𝑛+1 + 𝑢𝑖−1
𝑛+1
≅ (3)
∆𝑡 ∆𝑥 2
𝑛+1 𝑛+1 𝑛+1
In this equation, there are three unknowns: 𝑢𝑖−1 , 𝑢𝑖 and 𝑢𝑖+1 . The figure below shows
the grid points involved in equation (3).

From equation (3) we have:


∆𝑡 ∆𝑡
𝑢𝑖𝑛+1 = [𝑢𝑖𝑛 + 2
𝑛+1
(𝑢𝑖+1 𝑛+1 )
+ 𝑢𝑖−1 ] / (1 + 2 2 ) (4)
∆𝑥 ∆𝑥
We can solve this problem by using interactive calculation in Excel.
At time t=0, we have the initial condition as follows:

And the boundary condition for time t ≥ 0 is shown as below:

From equation (4), the solution at time t=0.01 can be expressed as below:
∆𝑡 ∆𝑡
𝑢11 = [𝑢10 + ( 𝑢 1
2 + 𝑢 1)
0 ] / (1 + 2 ) (5)
∆𝑥 2 ∆𝑥 2
∆𝑡 ∆𝑡
𝑢21 = [𝑢20 + 2
(𝑢31 + 𝑢11 )] / (1 + 2 2 ) (6)
∆𝑥 ∆𝑥
∆𝑡 ∆𝑡
𝑢31 = [𝑢30 + ( 𝑢 1
+ 𝑢 1)
] / (1 + 2 ) (7)
∆𝑥 2 4 2
∆𝑥 2
Enable the interactive calculation check-box:

Type the equations (5), (6) and (7) into cell u1, u2, u3 respectively, we also get the solution
for time t=0.01:
Therefore, we obtain solutions for other time steps:

From the obtained solutions, the graph comparing the solutions for numerous time steps is
drawn as follows:

Implicit method
1
0.9
0.8
0.7
t=0.04
0.6
0.5 t=0.08
u

0.4 t=0.12
0.3
t=0.16
0.2
t=0.20
0.1
0 t=infinite
0 0.25 0.5 0.75 1

You might also like