Showing posts with label Implicit. Show all posts
Showing posts with label Implicit. Show all posts

Friday, 10 March 2017

1-D Parabolic Equation PDE schemes

1-D Heat conduction equation (with no internal heat generation)

$\frac{\delta T}{\delta t} = \alpha \left ( \frac{\delta ^2 T}{\delta x^2} \right )$

Before we dwell any further in the discretization of the above PDE we need to know 3 important terms.

  1. Consistency
  2. Stability 
  3. Convergence
Here a finite difference scheme is said to be consistent when as $\Delta x,\Delta t \rightarrow 0$ , then the scheme  $\rightarrow$ to the original PDE.

A scheme is said to be stable when the ratio of the error propagation from one time step to another is less than $1$.

A scheme is said to converge when the above to conditions are met as well as the solution is close to the actual solution (analytic or numerical) of the PDE .
  
Note : Implicit schemes are mostly unconditionally stable ,while the explicit schemes are conditionally stable or unconditionally unstable
Explicit schemes
FTCS scheme

$\frac{T_{i} ^{n+1} -T_{i} ^{n}}{\Delta t} = \frac{T_{i+1} ^{n} -2T_{i} ^{n}+T_{i-1} ^{n}}{(\Delta x)^2}  + O(\Delta t,(\Delta x)^2)$

This scheme is conditionally stable , consistent ,convergent ,second order accurate in space,1st order accurate in time.
For more information on the stability criterion please check the tutorial 1 under the CFD tab.

CTCS scheme

$\frac{T_{i} ^{n+1} -T_{i} ^{n-1}}{2 \Delta t} = \frac{T_{i+1} ^{n} -2T_{i} ^{n}+T_{i-1} ^{n}}{(\Delta x)^2}  + O((\Delta t)^2,(\Delta x)^2)$

This scheme is unconditionally unstable. Hence this scheme is absolutely useless .Therefore the Dufort -Frankel scheme emerged.

Dufort Frankel scheme

$\frac{T_{i} ^{n+1} -T_{i} ^{n-1}}{2 \Delta t} = \frac{T_{i+1} ^{n} -2\left (\frac{T_{i} ^{n+1} +T_{i} ^{n-1}}{2}\right )+T_{i-1} ^{n}}{(\Delta x)^2}  + O((\Delta t)^2,(\Delta x)^2,(\frac{\Delta t}{\Delta x})^2)$

This scheme is unconditionally stable. Hence this scheme is brilliant . The error term can be easily derived , do this as an exercise.

Implicit schemes
BTCS scheme (laasonen scheme)

$\frac{T_{i} ^{n+1} -T_{i} ^{n}}{\Delta t} = \frac{T_{i+1} ^{n+1} -2T_{i} ^{n+1}+T_{i-1} ^{n+1}}{(\Delta x)^2}  + O(\Delta t,(\Delta x)^2)$

Unconditionally stable scheme . This scheme forms a tridiagonal matrix , which can be solved using matrix inversion ,or the Gauss elimination method or the TDMA (thomas) algorithm. For more information on the TDMA algorithm check tutorial 2 under the CFD tab .


Crank Nicolson scheme 

$\frac{T_{i} ^{n+1} -T_{i} ^{n}}{\Delta t} =  \frac{1}{2}\left (\frac{T_{i+1} ^{n+1} -2T_{i} ^{n+1}+T_{i-1} ^{n+1}}{(\Delta x)^2} +\frac{T_{i+1} ^{n} -2T_{i} ^{n}+T_{i-1} ^{n}}{(\Delta x)^2}    \right ) + O((\Delta t )^2,(\Delta x)^2)$

This is a really interesting scheme centered around the time step $n + 1/2$ . As can be seen the above scheme is second order accurate in time as well.
Unconditionally stable scheme . This scheme forms a tridiagonal matrix , which can be solved using matrix inversion ,or the Gauss elimination method or the TDMA (thomas) algorithm


Beta Formulation
Finally comes the $\beta $ formulation , this combines all the above mentioned schemes in a single shot .

$\frac{T_{i} ^{n+1} -T_{i} ^{n}}{\Delta t} =  \beta \left (\frac{T_{i+1} ^{n+1} -2T_{i} ^{n+1}+T_{i-1} ^{n+1}}{(\Delta x)^2}  \right )+(1-\beta) \left ( \frac{T_{i+1} ^{n} -2T_{i} ^{n}+T_{i-1} ^{n}}{(\Delta x)^2}   \right )  $

This scheme behaves like an FTCS scheme for $\beta < 1/2$
This scheme behaves like an BTCS scheme for $\beta > 1/2$
This scheme behaves like an Crank Nicolson scheme for $\beta = 1/2$ 


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.