Sunday, 19 February 2017

CFD Tutorial - 2 (Laasonen scheme)

                           Computational Fluid Dynamics 

Problem statement:
Given a rod of Length  L ,with boundary conditions,initial conditions as follows:

Boundary condition:
\begin{eqnarray}
T(0,t) = 0^{\circ}C \\
T(L,t)= 1^{\circ}C
\end{eqnarray}

Initial condition:

\begin{eqnarray}
T(x,0) = 0^{\circ}C
\end{eqnarray}

Compute the temperature for t = 0s to 20s for various values of $\Delta T = 0.1s,0.01s,0.001s$ .

Governing Equations:
PDE:
\begin{eqnarray}
\frac{\delta T}{\delta t} &=& \alpha \frac{\delta ^2 T}{\delta x^2}
\end{eqnarray}

Finite difference formulation using BTCS scheme (Implicit)
\begin{equation}
-\gamma T^{n+1}_{i-1}+T^{n+1}_{i}(2 \gamma +1) -\gamma T^{n+1}_{i+1} = T^n_{i}
\end{equation}

Pseudo Code


  • Initialize the variables $\alpha ,\Delta t,T,\Delta x, N_x , L$ .
     (Note here T is a matrix with $N_x$ columns ,and $20/(\Delta t) +1= N_y$ rows)
  •  For n = 2 to $N_y$ .
     Solve the equation below for $T^{n+1}$ using the TDMA algorithm.
     $$AT^{n+1} = T^{n}$$
    Where,
    $A =\begin{bmatrix}
    1 & 0 &0& \cdots &\cdots& 0 \\
    -\gamma &2\gamma + 1 &-\gamma &0 &\cdots &0&\\
    0 & -\gamma &2\gamma + 1 &-\gamma & \ddots &0\\
    0 & 0&\ddots &\ddots &\ddots & \ddots \\
    0 & \cdots&\cdots &\cdots &0 & 1 \\
    \end{bmatrix}$

The TDMA consists of converting the Tridiagonal matrix to an upper triangular matrix , then solving the system of equations by back substitution.

TDMA Algorithm:


  •  For i = 2:$(N_x-1)$
     $A[i,:] = A[i,:] - A[i-1,:]\frac{A[i,i-1]}{A[i,i]}$
     $T[n-1,i] = T[n-1,i] - T[n-1,i-1]\frac{A[i,i-1]}{A[i,i]}$
  •  Back substitution.
  •  End

Results :

Below are sample Graphs showing the Unconditional stability of the Implicit schemes.




Matlab Code:

https://github.com/RAAKASH/Intro-to-CFD-/tree/master/Assignment%202.

Note : 
  • Assignment 1.m is the file of the previous assignment/tutorial in the form of a function.
  • Assignment 2.m is the file of the present assignment/tutorial in the form of a function.
  • BTCS.m  is the same Assignment 2.m but has been optimized in time to get faster results.

2 comments:

  1. A new file BTCS.m has been added to the repository ,it is the time wise optimized code of BTCS scheme.

    ReplyDelete
  2. Also I have changed the timing function from 'cputime' to 'tic ,toc' because it is more accurate.

    ReplyDelete