Assignment
Assignment
Assignment 1
Prof. Atul Soti
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
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
𝒌 = 𝜶(𝟏 + 𝜷𝑻)
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
• 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𝑔 , 𝑏𝑖 = 𝑔, 𝑐𝑖 = 𝑔, 𝑑𝑖 = −𝑇𝑖𝑛
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