Computational Fluid Dynamics Report
Computational Fluid Dynamics Report
On
Results of Gauss Siedel Code
Submitted by
Mr. Abhinash Majhi (B220622ME)
Introduction
The Gauss-Seidel method is an iterative technique used to solve a system of
linear equations. It is particularly useful for large systems where direct methods
(like Gaussian elimination) may be computationally expensive. The method
works by improving upon an initial guess for the solution, refining it with each
iteration.
In Gauss-Seidel, the solution to each equation is updated sequentially and
immediately used in the subsequent equations. This makes it faster to converge
compared to similar methods, like the Jacobi method, in certain cases.
However, it may not always converge, depending on the nature of the system
(e.g., the matrix must typically be diagonally dominant or positive definite).
The process involves solving each equation in the system for one of the
variables and then using the newly computed values in subsequent equations.
Key Characteristics:
Iterative: Starts with an initial guess and iterates towards the solution.
Sequential updates: New values are used immediately in subsequent
calculations.
Convergence: More likely when the matrix is diagonally dominant.
The Gauss-Seidel method assumes the following:
1. The system is a set of linear equations.
2. The matrix of coefficients is ideally diagonally dominant (the diagonal
element in each row is larger than the sum of other elements in that
row) or positive definite.
3. An initial guess for the solution is provided.
4. Sequential updates are made, using new values immediately in
subsequent calculations.
5. The method stops when the solution is accurate within a tolerance level.
These assumptions help ensure the method converges to the correct solution.
Question-1
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
int nx=50,ny=50;
float L=1.0,H=1.0,dx=1.0/(nx-1),dy=1.0/(ny-1),x[nx],y[ny],T[nx][ny];
int maxiter = 10000;
ofstream Tecplotfile;
for (int i=0;i<nx;i++)
{
x[i]=i*dx;
}
for (int j=0;j<ny;j++)
{
T[0][j] = 0;
y[j]=j*dy;
T[nx-1][j]=1;
}
for (int i=1;i<nx-1;i++)
{
for (int j=0;j<ny;j++)
{
T[i][j]=0;
}
}
for (int n=0;n<maxiter;n++)
{
for (int i=1;i<nx-1;i++)
{
for (int j=0;j<ny;j++)
{
float a = ((T[i+1][j]+T[i-1][j])/(dx*dx));
float b = 2*(1/(dx*dx));
T[i][j]=a/b;
}
}
}
Tecplotfile.open("cfdplot2.dat");
Tecplotfile << "Variables= x,y,z ZONE I=" << nx << ", J=" << ny << ", F=POINT" << endl;
for (int j = 0; j < ny; j++) {
for (int i = 0; i < nx; i++) {
Tecplotfile << x[i] << " " << y[j] << " " << T[i][j] << endl;
}} Tecplotfile.close();
return 0;
}
Question 2
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
int nx=100,ny=100;
float L=1.0,H=1.0,dx=L/(nx-1),dy=H/(ny-1),x[nx],y[ny],T[nx][ny];
int maxiter = 40000;
ofstream Tecplotfile;
}
for (int i=0;i<nx;i++)
{
x[i]=i*dx;
T[i][0]=1;
}
for (int i=1;i<nx;i++)
{
for (int j=1;j<ny;j++)
{
T[i][j]=0;
}
}
for (int n=0;n<maxiter;n++)
{
for (int i=1;i<nx-1;i++)
{
for (int j=1;j<ny-1;j++)
{
T[i][ny-1]=T[i][ny-2];
T[nx-1][j]=T[nx-2][j];
float a = ((T[i+1][j]+T[i-1][j])/(dx*dx)+(T[i][j+1]+T[i][j-1])/(dy*dy));
float b = 2*(1/(dx*dx)+1/(dy*dy));
T[i][j]=a/b;
}
}
}
Tecplotfile.open("cfdplot3.dat");
Tecplotfile << "Variables= x,y,z ZONE I=" << nx << ", J=" << ny << ", F=POINT" << endl;
for (int j = 0; j < ny; j++) {
for (int i = 0; i < nx; i++) {
Tecplotfile << x[i] << " " << y[j] << " " << T[i][j] << endl;
}
}
Tecplotfile.close();
return 0;
}
Question 3
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
ofstream Tecplotfile;
int nx=50,ny=50;
float L=1.0,H=1.0,dx=L/(nx-1),dy=H/(ny-1),x[nx],y[ny],T[nx][ny],nu1=1.0,nu2=1.0;
int maxiter = 10000;
}
}
for (int i=0;i<nx;i++)
{
x[i]=i*dx;
}
for (int j=0;j<ny;j++)
{
T[0][j]=1;
y[j]=j*dy;
}
float a = ((T[i+1][j]+T[i-1][j])/(dx*dx)+(T[i][j+1]+T[i][j-1])/(dy*dy));
float b = 2*(1/(dx*dx)+1/(dy*dy));
T[i][j]=a/b;
T[i][ny-1]=T[i][ny-2];
T[nx-1][j]=(T[nx-2][j])/(dx*nu1+1);
T[i][0]=(T[i][1])/(1-dy*nu2);
}
}
}
Tecplotfile.open("cfdplot4.dat");
Tecplotfile << "Variables= x,y,z ZONE I=" << nx << ", J=" << ny << ", F=POINT" << endl;
for (int j = 0; j < ny; j++) {
for (int i = 0; i < nx; i++) {
Tecplotfile << x[i] << " " << y[j] << " " << T[i][j] << endl;
}
}
a
Tecplotfile.close();
return 0;
}
Question 4
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
ofstream Tecplotfile;
int nx=50,ny=50;
float L=1.0,H=1.0,dx=L/(nx-1.0),dy=H/(ny-1.0),x[nx],y[ny],T[nx][ny],nu1=.1,nu2=.1,Sgen=.5,a=1.0;
}
}
}
Tecplotfile.open("new.dat");
Tecplotfile << "Variables= x,y,z ZONE I=" << nx << ", J=" << ny << ", F=POINT" << endl;
for (int j = 0; j < ny; j++) {
for (int i = 0; i < nx; i++) {
Tecplotfile << x[i] << " " << y[j] << " " << T[i][j] << endl;
}
}
Tecplotfile.close();
return 0;
}
These are the results for the above attached questions