0% found this document useful (0 votes)
8 views17 pages

Assignment

Uploaded by

Harsh Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views17 pages

Assignment

Uploaded by

Harsh Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

ME 543 - CFD

Assignment 1
Prof. Atul Soti

Code Explanation & Discussion session


Steps for Assignments
Formation of system of linear equations after discretization.
𝜕2𝑇
=0
𝜕𝑥 2
𝑇𝑖+1 − 2𝑇𝑖 + 𝑇𝑖−1
=0
Δ𝑥 2
𝑘 𝑘
𝑘+1 𝑇𝑖+1 + 𝑇𝑖−1
𝑇𝑖 =
2
Coding part (C/C++)

Step 1:
Invoking the header files as per requirement
Example: #include<stdio.h>
Here stdio is standard input ouput library

Step 2:
Making different function meant for various operations with proper arguments
Functions should be used to:
• Initialize the variables (using proper data types)
• Implementation of boundary conditions
• Linear solver (Jacobi, Gauss Seidel, etc.)
• Others
Step 3:
In the linear solver function loop should be used for error convergence.
Example: while(error>=tolerance)
{
//while loop example
}

Step 4:
Declaring main function.
• It should contain command to read input file
• Calling functions (can be call by reference/value) These should be inside time loop
• Writing an output file (preferably .dat file) if the problem is unsteady

Plotting part:

• Using tecplot for graphs and contours. Selecting “load data” from file in the menu bar, choosing the required
.dat file and making adjustments as per requirement.
• Using Matlab/Python. Plots should be made by reading the output file obtained from program.
Ques 1

Header Files

Printing results to
file

Variable Initialization and


Declaration and Defining Boundary
Initialization conditions

NOTATIONS
𝑇𝑖𝑘 = 𝑇_𝑜𝑙𝑑[i] ➔ Previous
i=0 to (N-1) ➔ N nodes iteration
𝑇𝑖𝑘+1 = 𝑇_𝑛𝑒𝑤[𝑖] ➔ Current
iteration
Ques 1
Jacobi (J) 𝑨𝒙 =𝒃 Gauss Seidel (G)

⋮ ⋱ ⋮ ⋮ = ⋮

(𝑘)
𝑏𝑖 − σ𝑁
𝑗=1 𝑎𝑖𝑗 ∗ 𝑥𝑗 𝑘+1 (𝑘)
(𝐾+1) 𝑗≠𝑖 (𝐾+1)
𝑏𝑖 − σ𝑖−1
𝑗=1 𝑎𝑖𝑗 ∗ 𝑥𝑗 − σ𝑁
𝑗=𝑖+1 𝑎𝑖𝑗 ∗ 𝑥𝑗
𝑥𝑖 = 𝑥𝑖 =
𝑎𝑖𝑖 𝑎𝑖𝑖
Ques 5

Printing results to file Initialization and


Variable Declaration and Initialization Defining Boundary
i=0 to (N-1) ➔ N nodes conditions

𝒌 = 𝜶(𝟏 + 𝜷𝑻)
Ques 5
Variable Thermal Conductivity

𝑑 𝑑𝑇
𝑘 =0
𝑑𝑥 𝑑𝑥
𝑑𝑇 𝑑𝑇
𝑘 𝑑𝑥 1− 𝑘 𝑑𝑥 1
𝑖+ 𝑖−
2 2 2
=0 𝑂 ∆𝑥
∆𝑥

𝑘 1 = 𝑘𝑎 𝑘 1 = 𝑘𝑏
𝑖−2 𝑖+2

𝑇𝑖+1 − 𝑇𝑖 𝑇𝑖 − 𝑇𝑖−1
𝑘𝑏 − 𝑘 (
∆𝑥 𝑎 ∆𝑥 )
=0
∆𝑥
2𝐾 𝐾
𝑖 𝑖−1 2𝐾 𝐾
𝑖 𝑖+1
𝑘𝑎 = 𝐾 +𝐾 𝑘𝑏 = 𝐾 +𝐾
𝑖 𝑖−1 𝑖 𝑖+1

𝐾𝑎 𝑇𝑖−1 + 𝑘𝑏 𝑇𝑖+1
𝑇𝑖 =
𝑘𝑎 + 𝑘𝑏
PLOTS

Ques 1 Ques 5
Ques 6 – a) FTCS

Variable Declaration,
Initialization and
Defining Boundary
conditions

NOTATIONS 2
𝑂 ∆𝑡 , ∆𝑥
𝑇𝑖𝑛 = 𝑇_𝑝𝑟𝑒𝑣[i] ➔ Current time step
𝑇𝑖𝑛+1 = 𝑇_𝑛𝑒𝑤[𝑖] ➔ New time step i=0 to (N-1) ➔ N nodes

𝛼(∆𝑡) 1 ∆𝑥 2
Stability Condition ➔ ≤ (∆𝑡) ≤ ∆𝑡 ≤ 0.00125
∆𝑥 2 2 2𝛼
Ques 6 – a) FTCS
𝑑𝑇 𝑑2𝑇 𝑇𝑖𝑛+1 −𝑇𝑖𝑛 𝑛
𝑇𝑖+1 − 2𝑇𝑖𝑛 + 𝑇𝑖−1
𝑛
=𝛼 2 =𝛼
∆𝑡 ∆𝑥 2
𝑑𝑡 𝑑𝑥
∆𝑡
𝑇𝑖𝑛+1 = 𝑐(𝑇𝑖+1
𝑛 𝑛
+ 𝑇𝑖−1 ) + 1 − 2𝑐 𝑇𝑖𝑛 𝑐=𝛼
∆𝑥 2
Ques 6 – b) BTCS
Ques 6 – c) CN
• All Notations, variable declaration and initialization same as FTCS
• No stability Condition
• FTCS – Explicit method ; BTCS and CN – Implicit Method
• Print results for required time steps into different file 𝑑𝑇 𝑑2𝑇 ∆𝑡
=𝛼 2 𝑔=𝛼
• LHS = Unknowns & RHS = knowns terms 𝑑𝑡 𝑑𝑥 ∆𝑥 2
• 2 approaches →
𝑑𝑡 = 0.01
• Iterative – Gauss Seidel and Jacobi
• Direct - TDMA i=0 to (N-1) ➔ N nodes

BTCS Crank Nicolson (CN)


𝑇𝑖𝑛+1 −𝑇𝑖𝑛 𝑛+1
𝑇𝑖+1 − 2𝑇𝑖𝑛+1 + 𝑇𝑖−1
𝑛+1 𝑇𝑖𝑛+1 − 𝑇𝑖𝑛 𝛼 𝑇𝑖+1
𝑛+1
− 2𝑇𝑖𝑛+1 + 𝑇𝑖−1
𝑛+1 𝑛
𝛼 𝑇𝑖+1 − 2𝑇𝑖𝑛 + 𝑇𝑖−1
𝑛
=𝛼 = +
∆𝑡 ∆𝑥 2 ∆𝑡 2 ∆𝑥 2 2 ∆𝑥 2

𝑛+1 𝑛+1 𝑔 𝑛+1 𝑔 𝑛


𝑔(𝑇𝑖+1 + 𝑇𝑖−1 ) − (1 + 2𝑔)𝑇𝑖𝑛+1 = −𝑇𝑖𝑛 𝑛+1
(𝑇𝑖+1 + 𝑇𝑖−1 ) − 1 + 𝑔 𝑇𝑖𝑛+1 = − (𝑇𝑖+1 𝑛
+ 𝑇𝑖−1 ) − (1 − 𝑔)𝑇𝑖𝑛
2 2
𝑂 ∆𝑡 , ∆𝑥 2
𝑂 ∆𝑡 2 , ∆𝑥 2
Iterative Approach - BTCS
• Iterate for each time step till the
result converges using T_new[i]
and T_old[i] → [ Belong to
current time step (n+1) ]
• T_prev[i] → [ Previous time
step (n) ] are updated after each
inner results for a ∆𝑡 and take
updates values of T_new[i]
• Iterative approach useful for
large size mesh (coarse mesh) as
∆𝑡, ∆𝑥 are large
NOTATIONS
𝑇𝑖𝑛 = 𝑇_𝑝𝑟𝑒𝑣[i] ➔ Current time step
results
𝑇𝑖𝑛+1 = 𝑇_𝑜𝑙𝑑[𝑖] ➔ New time step
old iteration results
𝑛+1
𝑇𝑖 = 𝑇_𝑛𝑒𝑤[𝑖] ➔ New time step
updated latest iteration
result
TDMA Approach - BTCS

• Direct Approach
• 𝒂𝒊 𝑻𝒏+𝟏
𝒊 + 𝒃𝒊 𝑻𝒏+𝟏 𝒏+𝟏
𝒊+𝟏 + 𝒄𝒊 𝑻𝒊−𝟏 = 𝒅𝒊
• i=0 to (N-1) ➔ N nodes (Discretization)
• i=0,N → Boundary nodes (excluded from TDMA)
• I = 1 to (N-2) for TDMA
𝑛+1 𝑛+1
𝑔(𝑇𝑖+1 + 𝑇𝑖−1 ) − (1 + 2𝑔)𝑇𝑖𝑛+1 = −𝑇𝑖𝑛

• 𝑎𝑖 = − 1 + 2𝑔 , 𝑏𝑖 = 𝑔, 𝑐𝑖 = 𝑔, 𝑑𝑖 = −𝑇𝑖𝑛

• Direct Approach is very useful for small mesh size


(fine mesh) as ∆𝑡, ∆𝑥 are small
• Avoids multiple iteration at each time steps and
gives exact results instead of approximate results

NOTATIONS
𝑇𝑖𝑛 = 𝑇_𝑝𝑟𝑒𝑣[i] ➔ Previous time
step
𝑇𝑖𝑛+1 = 𝑇_𝑛𝑒𝑤[𝑖] ➔ Current time step
PLOTS
Ques 6 – b) BTCS Ques 6 – c) CN
Plotting Results in Tecplot
Following Headings at start of results_file are important for Tecplot to read files automatically and plot
the results
• 1D Case – Temperature variation on line
• TITLE = Temperature
• VARIABLES = X, Temp
• ZONE T=BLOCK1 I= 21 , F=POINT
• 2D Case – Lid Driven cavity case
• TITLE = Velocity & Pressure
• VARIABLES = X, Y, u_star, v_star, u, v, p
• ZONE T=BLOCK1 I= 21 , J= 21 , F=POINT
• We can append the Iterative/Direct Solution plot with the Analytical solution plot to compare results
and draw conclusions as shown in above plots
• Represent different solution using different symbols and lines
• Contours, Vectors, & Streamlines can be plotted in 2D for verifying results with experimental
observations
• 1D Example in next slide
Ques 6 – c)CN (t=0.3 hours)
Analytical Solution TDMA Solution Combined Plot
THANK YOU

You might also like