This course included two assignments, implementing the Finite Volume Method in MATLAB for 2D diffusion and 2D convection-diffusion for scalar transport. The codes can be found in the MATLAB codes folder, along with the reports. Below is an explanation of the governing equations, discretization schemes, and results for both cases.
We consider the problem of 2D heat conduction as given below,
Figure 1: Domain for 2D heat conduction
The boundary conditions are,
-
Boundary 1:
$T = 15 \, ^\circ \text{C}$ -
Boundary 2:
$T(y) = 5\left(1 - \frac{y}{H}\right) + 15 \sin\left(\frac{\pi y}{H}\right)$ -
Boundary 3:
$T = 10 \, ^\circ \text{C}$ -
Boundary 4 (Insulated):
$\frac{\partial T}{\partial x} = 0$
The thermal conductivity is a function of space given as
The governing equation for 2D heat conduction with a source term is given as,
We use the Finite Volume Method with central difference scheme and source term linearization to discretize the equations. In finite volume method, the governing differential equation is first integrated over a control volume. The complete details of the theory for the Finite Volume Method can be found in [1]. Consider a control volume shown in Fig. 2.
Figure 2: 2D Control Volume for the Finite Volume Method
Integrating the governing differential equation over this 2D control volume, we get,
We assume that the source term remains constant over the volume and hence it is not integrated. Integrating the other terms,
All the variables are only stored at the cell centers, hence to calculate the gradients at the cell faces, we need different schemes. The central difference scheme uses following equation to calculate the fluxes at the faces using the values at the cell centers.
Substituting this into the previous equation and rearranging it in a form given as
A negative constant source term can lead to diverging results during the numerical procedure to solve the system of equations, hence we make the following adjustment for numerical stability shifting the source term to the LHS from the RHS, using
These equations are applied to each control volume in the discretized domain and the resulting system of linear equations is solved using the Gauss Seidel method. The code implementing the above described method is given here.
Results:
The temperature distribution in the domain using a 80x80 mesh is shown below
Figure 3: Temperature field in the domain
A grid convergence study is also performed to find the optimal mesh size. A stretch mesh with smaller elements near the boundary with large gradients is also used and the results are compared with larger grid sizes to compare the performance. The variation of the residual vs number of iteration for various convergence criteria is also conducted. The effect of changing the boundary conditions is also explored and the details of all the analysis can be found in the report.
Here, we consider the problem of heat convection and conduction with a given velocity field as shown in Fig. 4 below along with given mesh data. This data is required to run the MATLAB code and the data files containing the veclocity field and mesh points can be found in the MATLAB codes folder
Figure 4: Computational domain and the given velocity field
The dimensions for the domain and given physical values are
We apply the FVM discretization procedure as described previously using the central difference scheme for diffusive terms but here, we use the hybrid scheme for the convective term which is explained below. On integration, the convective term gives
Again as done in the FVM, all variables are stored at cell centers and values are not known at the cell faces. As the velocity profile is already known at the cell centers, it can be interpolated to the cell faces. But the calculate the unknown T at the cell faces, we need some discretization scheme for which we use the hybrid scheme.
The temperature values at the cell faces is calculated in the hybrid scheme as an upwind or central differencing scheme based on the cell Peclet number. Essentially, based on the ratio of convection to diffusion at each cell, either the central difference scheme (suitable for diffusion) or the first order upwind scheme (suitable for convection) is used. The formulation for the hybrid scheme is given considering the first term (
This is applied to each face to get the discretized equations. The system of linear equations generated is solved using the Gauss Seidel as well as an iterative 2D Tri Diagonal Matrix Algorithm (TDMA) considering different sweep directions. The MATLAB code for this is given in the codes folder as 2D_Convection_Diffusion.m.
Results:
Figure 5: Temperature distribution in the domain
The plot of the temperature distribution in given in Fig. 5 and using this, the unknown outlet temperature of the fluid can be calculated. Along with this the effect of changes in boundary conditions and the effect of different iterative techniques on the solution convergence is studied, details of which can be found in the report.
References:
[1] H. Versteeg and W. Malalasekera. An Introduction to Computational Fluid Dynamics - The Finite Volume Method. Longman Scientific & Technical, Harlow, England, 1st edition, 1995.