0% found this document useful (0 votes)
7 views23 pages

Cfd Assignment q7

This report details a numerical simulation of unsteady diffusion in a one-dimensional domain with linearly varying diffusivity, using the Tridiagonal Matrix Algorithm (TDMA). It outlines the governing equations, boundary conditions, and the implementation of the TDMA method, including the handling of different boundary conditions. The results are presented as concentration profiles over time, illustrating the effects of diffusivity variation and boundary conditions on the diffusion process.

Uploaded by

11silal04
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views23 pages

Cfd Assignment q7

This report details a numerical simulation of unsteady diffusion in a one-dimensional domain with linearly varying diffusivity, using the Tridiagonal Matrix Algorithm (TDMA). It outlines the governing equations, boundary conditions, and the implementation of the TDMA method, including the handling of different boundary conditions. The results are presented as concentration profiles over time, illustrating the effects of diffusivity variation and boundary conditions on the diffusion process.

Uploaded by

11silal04
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 23

ASSIGNMENT (Q.

7)
(U22me157,U22ME149,U22ME160)

Numerical Simulation of Unsteady Diffusion with Varying


Diffusivity
This report presents a numerical solution for the unsteady diffusion of a scalar in a one-dimensional
domain where the diffusivity varies linearly with position. The governing equation, boundary
conditions, and discretization scheme are detailed, followed by a description of the Tridiagonal Matrix
Algorithm (TDMA) implementation and its application to different boundary conditions. The results
of the numerical simulation are presented and analysed, concluding with a discussion of future work
and potential extensions to the model.

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.

• One dimensional analysis.

• Uniform grid size considered.

• Nomenclature
Symbol Meaning

T Temperature, °C

t Time, s

r Density, kg/ m3

k Thermal Conductivity W/mK

cp Specific heat capacity, kJ/kg.K

A Cross Sectional Area,m2

L Length of fin, m

∆x Size of one element, m

D0, β Constant

w West wall of a cell


e East wall of a cell.

ap Cell itself

aw West cell

ae East cell

∆t Time marching interval

Th Higher temperature at left side of fin

Tc Lower temperature at right side of fin

Ti Initial temperature of all cells

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.

Diffusivity Variation: D=Do(1±ẞx)


The diffusivity variation in this problem is defined by D = Do(1 ± ßx), where Do is the base
diffusivity, ß is a constant representing the variation rate, and x is the spatial coordinate. This equation
signifies a linear change in diffusivity along the spatial domain, either increasing or decreasing with
increasing x depending on the sign of ß. This variation in diffusivity introduces complexity to the
diffusion process as the rate of diffusion will vary along the domain, resulting in a non-uniform
distribution of the scalar. The choice of the sign for ß will determine the direction of the diffusivity
gradient, either increasing or decreasing with increasing x.

Discretization of the Domain


To solve the governing equation numerically, the domain is discretized into a series of nodes, dividing
the spatial domain into equal intervals. The concentration at each node is represented by Ci, and the
diffusion coefficient at each node is represented by Di. This discretization allows for the
approximation of the continuous differential equation by a system of algebraic equations. The time
derivative is also discretized using a finite difference approximation. This approach transforms the
partial differential equation into a set of linear equations that can be solved using the TDMA method.
The specific discretization scheme used will influence the accuracy and stability of the numerical
solution.

Formulation of the TDMA


After discretization, the governing equation is transformed into a system of linear equations, which
can be represented in matrix form as:
AC= B
where A is the tridiagonal coefficient matrix, C is the vector of unknowns (concentrations at each
node), and B is the vector containing the source terms and boundary conditions. The TDMA algorithm
solves this system of equations efficiently. It iteratively updates the solution vector C using the
following steps:
1. Forward Elimination: Eliminate the off-diagonal terms in the coefficient matrix A, moving
forward from the first to the last node.
2. Back Substitution: Solve for the unknowns starting from the last node and substituting
backwards towards the first node.
The TDMA algorithm is particularly suited for solving tridiagonal systems due to its computational
efficiency and ease of implementation.
Implementation of the TDMA
The implementation of the TDMA algorithm involves the following steps:
1. Initialization: Initialize the arrays for the coefficient matrix A, the solution vector C, and the
source term vector B. Initialize the initial conditions for the scalar concentration.
2. Forward Elimination: Perform the forward elimination steps by iterating through each node
and updating the coefficient matrix A and source term vector B. This step involves
eliminating the off-diagonal terms of the coefficient matrix A by multiplying each row with
the corresponding element on the diagonal and subtracting it from the next row.
3. Back Substitution: Perform the back substitution steps by iterating through each node starting
from the last node and updating the solution vector C. This step involves solving for the
unknown concentration at each node by using the updated values of the coefficient matrix A
and source term vector B.
4. Output: Print the solution vector C, which contains the concentration at each node, and
visualize the results.
The implementation can be carried out using various programming languages, such as Python or C++,
depending on the desired features and computational performance. It's essential to carefully choose
the appropriate discretization scheme and boundary conditions to ensure the accuracy and stability of
the numerical solution.

Handling Different Boundary Conditions


The implementation of the TDMA algorithm must account for different boundary conditions to
accurately simulate the diffusion process. The boundary conditions specify the state of the scalar at
the edges of the domain, influencing the solution by providing additional constraints. Different
boundary conditions require modifications to the coefficient matrix A and source term vector B in the
TDMA algorithm.
• Dirichlet Boundary Conditions: Set the concentration at the boundary nodes directly in the
source term vector B, eliminating the need for any special treatment in the coefficient matrix
A.
• Neumann Boundary Conditions: Modify the coefficient matrix A and source term vector B to
incorporate the flux values specified at the boundaries. The coefficient matrix A is modified to
include the flux terms, while the source term vector B is updated to reflect the boundary
conditions. This approach ensures that the numerical solution accurately reflects the flux
values at the boundaries.
• Robin Boundary Conditions: Modify the coefficient matrix A and source term vector B to
include both concentration and flux terms at the boundaries. This ensures that the numerical
solution satisfies the Robin boundary conditions, combining both concentration and flux
values at the boundaries.
The specific implementation of each boundary condition will depend on the chosen discretization
scheme and the formulation of the TDMA algorithm. The accurate implementation of boundary
conditions is critical for obtaining a realistic and reliable numerical solution.
Hand Calculations
Presentation of Results
The results of the numerical simulation are presented in the form of concentration profiles at different
time steps. The concentration profiles will illustrate the distribution of the scalar within the domain
and how it evolves over time. The impact of diffusivity variation and different boundary conditions on
the concentration profiles is analysed to understand the behaviour of the diffusion process. The
numerical solution provides insights into the influence of various factors on the diffusion process and
allows for the analysis of the concentration distribution at different time steps. The results can be
visualized using various graphical methods, such as plotting the concentration profiles as a function of
space and time. This visual representation provides a clear understanding of the diffusion process and
helps to interpret the influence of the diffusivity variation and different boundary conditions.

Graph for the sample calculation

Excell calculation is done for this problem


Excel worksheet link :
Excel calculation sheet CFD-Assignment Q7 (1).xlsx
Sample calculation snapshot of excel worksheet
C code for the solution:

//#include<iostream>
#include<stdio.h>
#include<math.h>
#include<conio.h>
#include<io.h>

//using namespace std;

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;

printf("Length of the rod: ");


scanf("%f",&L);
printf("delta time : ");
scanf("%f",&dt);
printf("time marching steps : ");
scanf("%d",&n);
printf("Value of Do: ");
scanf("%f",&Do);
printf("Value of beta: ");
scanf("%f",&beta);
printf("what is higher temperature ");
scanf("%f",&Th);
printf("what is lower temperature ");
scanf("%f",&Tc);
residue = 0.000001; //residue
//residue

//------------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++)
{

for(i=2;i<=nx+1;i++) //above diagonal


{
D = Do*(1 + beta*(i-0.5)*dx);
ae = (-1)*((D*dt)/(dx*dx));
a[i-1] = ae;
}

for(i=0;i<=nx-1;i++) //below diagonal


{
D = Do*(1 + beta*(i-0.5)*dx);
aw = (-1)*((D*dt)/(dx*dx));
b[i+1] = aw;
if(i==0)
{
D=Do;
aw = (-1)*((D*dt)/(dx*dx));
b[i+1]=aw;
}

//first element of main diagonal//


D = Do*(1 + beta*(1-0.5)*dx);
ap = (1+((2*D*dt)/(dx*dx)));
aw = (-1)*((D*dt)/(dx*dx));
d[1] = (ap-b[1]);
//last element of main diagonal//
D = Do*(1 + beta*(nx-0.5)*dx);
ap = (1+((2*D*dt)/(dx*dx)));
ae = (-1)*((D*dt)/(dx*dx));

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];
}

//printing of matrix a//


for(u=1;u<=nx;u++)
{
printf("%f\n",R[u]);
}

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];

//printing of modified resultanat//

for(u=1;u<=nx;u++)
{
printf("%f\n",R[u]);
}

T[nx] = R[nx]/d[nx]; //backword sweep

for(i=nx-1;i>0;i--)
T[i] = ((R[i] - (a[i]*T[i+1]))/d[i]);

sum = 0.0; //rms calulation


for(i=1;i<=nx;i++)
{

sum = sum + pow((Told[i]-T[i]),2);

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;
}

You might also like