Cfd Assignment q7
Cfd Assignment q7
7)
(U22me157,U22ME149,U22ME160)
Problem Statement:
The objective is to develop a numerical code to simulate the unsteady diffusion of a scalar in a one-
dimensional domain where the diffusivity varies linearly with position. The diffusion coefficient is
defined as D = Do(1 ± ßx), where Do is the base diffusivity, ß is a constant representing the variation
rate, and x is the spatial coordinate. The domain is assumed to have no circumferential losses,
implying a one-dimensional diffusion process. The goal is to numerically solve the governing
equation using the TDMA method and investigate the influence of different boundary conditions on
the diffusion process.
Assumptions :
• No heat generation.
• Nomenclature
Symbol Meaning
T Temperature, °C
t Time, s
r Density, kg/ m3
L Length of fin, m
D0, β Constant
ap Cell itself
aw West cell
ae East cell
x Scalar in x direction
α Thermal diffusivity
ap0 1 (constant)
Governing Equation and Boundary Conditions
The governing equation for unsteady diffusion is the Fick's second law:
where C is the concentration of the scalar, t is time, and D is the diffusion coefficient. The boundary
conditions can vary depending on the specific problem being considered. Common types of boundary
conditions include:
• Dirichlet boundary conditions: Specify the concentration at the boundaries.
• Neumann boundary conditions: Specify the flux at the boundaries.
• Robin boundary conditions: Combine Dirichlet and Neumann conditions.
The specific boundary conditions for this problem will be defined in the following sections.
Numerical Scheme: TDMA
The Tridiagonal Matrix Algorithm (TDMA) is a highly efficient method for solving systems of linear
equations that have a tridiagonal coefficient matrix, commonly encountered in the discretization of
second-order differential equations. The TDMA algorithm is based on a Gaussian elimination
approach specifically tailored for tridiagonal matrices, reducing the computational complexity and
making it computationally faster than general Gaussian elimination. It involves forward elimination
and back substitution steps to iteratively solve for the unknowns, providing a direct solution to the
system.
//#include<iostream>
#include<stdio.h>
#include<math.h>
#include<conio.h>
#include<io.h>
main()
{
mkdir("TDMA");
int i,step,m,n,nx,q,u,l=0;
printf("No.of cells: ");
scanf("%d",&m);
nx=m;
float
L,Do,dx,D,beta,dt,Th,Tc,ap,aw,ae,a0,rms=1,sum,residue,x[nx+1],T[nx+1],Told[nx+1],d[nx+1],a[nx+
1],b[nx+1],R[nx+1],s[nx+1],V[nx+1];
a0 = 1.0;
//------------grid generation---------------//
dx = L/nx;
x[1] = 0.5*dx;
x[0] = 0.0;
x[nx+1] = L;
for(i=2;i<=nx;i++)
x[i] = x[i-1] + dx;
//-------initialisation----------//
for(i=1;i<=nx;i++)
{
T[i] = 0.0;
Told[i]=0.0;
}
//---------iterative calculation with TDMA-------------//
for(step=1;step<=n;step++)
{
d[nx] = (ap-a[nx]);
//middle elements of main diagonal//
for(i=2;i<=nx-1;i++)
{
D = Do*(1 + beta*(i-0.5)*dx);
ap = (1+((2*D*dt)/(dx*dx)));
d[i] = ap;
}
//matrix AX=B//
//first element of resultant matrix//
D = Do*(1 + beta*(1-0.5)*dx);
aw = (-1)*((D*dt)/(dx*dx));
R[1] = ((a0*T[1])-(2*Th*b[1]));
V[1]=R[1];
//last element of resultant matrix//
D = Do*(1 + beta*(nx-0.5)*dx);
ae = (-1)*((D*dt)/(dx*dx));
R[nx] = ((a0*T[nx])-(2*Tc*a[nx]));
V[nx]=R[nx];
//middle elemets of resultant matrix//
for(i=2;i<=nx;i++)
{
R[i] = a0*T[i];
}
printf(" \n");
//forward sweep modification//
for(i=2;i<=nx;i++)
{
d[i]=d[i] -[bi]*a[i-1]/d[i-1];
R[i]=R[i] - b[i]*R[i-1]/d[i-1];
for(u=1;u<=nx;u++)
{
printf("%f\n",R[u]);
}
for(i=nx-1;i>0;i--)
T[i] = ((R[i] - (a[i]*T[i+1]))/d[i]);
Told[i]=T[i];
printf("%d\t%f\t%f\n \n",step,rms,T[i]);
}
rms = sqrt(sum/nx);
}
//printf("%d",step);
printf("%d",step);
return 0;
}