0% found this document useful (0 votes)
18 views15 pages

final

The document outlines a computational fluid dynamics problem focused on developing a flow field in a two-dimensional domain. It includes mathematical formulations for velocity, vorticity, and boundary conditions, as well as a C++ implementation for simulating the flow. The simulation involves discretization and iterative updates to calculate the flow characteristics through a defined geometry.

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)
18 views15 pages

final

The document outlines a computational fluid dynamics problem focused on developing a flow field in a two-dimensional domain. It includes mathematical formulations for velocity, vorticity, and boundary conditions, as well as a C++ implementation for simulating the flow. The simulation involves discretization and iterative updates to calculate the flow characteristics through a defined geometry.

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/ 15

Problem statement 14: Develop[ the flow field in the 2 dimensional

domain for flow through the construction.

Vx=Uo ;
Vy=0

b a

L1 L2 L3

𝜕𝜔 1
(𝑖) ∭ ⃗ ⋅ ⃗⃗⃗⃗⃗
∙ ⅆ𝑉 + ∬ 𝜔𝑉 ⅆ𝐴 = ∬ ⃗⃗⃗⃗⃗
𝛻𝜔 ⋅ 𝐴
𝜕𝑡 𝑅𝑒

General form:
𝜂+1 𝜂+1 𝜂+1 𝜂+1 𝜂+1 𝜂
𝑎𝑝 𝜔𝑝 + 𝑎𝑤 𝜔𝑤 + 𝑎𝑒 𝜔𝑒 + 𝑎𝑛 𝜔𝑛 + 𝑎𝑠 𝜔𝑠 = 𝑎𝑝𝑜 𝜔𝑝

(𝑉𝑒 − 𝑉𝑤) (𝑉𝑛 − 𝑉𝑠) ∆𝑡 2 (∆𝑡 2 )


𝑎𝑝 = 1 + ( + )× + × ∙ (∆𝑥 2 + ∆𝑦 2 )
∆𝑥 ∆𝑦 2 𝑅𝑒 ((∆𝑥 ∙ ∆𝑦)2 )
−𝑉𝑤 1 ∆𝑡
𝑎𝑤 = ( − )∙
2 𝑅𝑒 ∙ ∆𝑥 ∆𝑥 𝑉𝑊+𝑉𝑃
𝑉𝑤 = ;
𝑉𝑒 1 ∆𝑡 2
𝑎𝑒 = ( − )∙
2 𝑅𝑒 ∙ ∆𝑥 ∆𝑥 𝑉𝑒 =
𝑉𝐸+𝑉𝑃
;
2
𝑉𝑛 1 ∆𝑡
𝑎𝑛 = ( − )∙ 𝑉𝑛 =
𝑉𝑁+𝑉𝑃
;
2 𝑅𝑒 ∙ ∆𝑦 ∆𝑦 2

−𝑉𝑠 1 ∆𝑡 𝑉𝑠 =
𝑉𝑆+𝑉𝑃
;
𝑎𝑠 = ( − )∙ 2
2 𝑅𝑒 ∙ ∆𝑦 ∆𝑦
𝑎𝑝𝑜 = 1
𝜕𝑣𝑥 𝜕𝑣𝑥
𝜔=− ; 𝜑 = 𝑈𝑜. 𝑎 𝜔=− ; 𝜑 = 𝑈𝑜. 𝑎
𝜕𝑦 𝜕𝑦

Vx=Uo ;
𝜕𝑣𝑥
𝜕𝑣𝑦 𝜔=− ;𝜑
Vy=0 𝜕𝑦 𝜕𝑣𝑦
𝜔= ; 𝜑 = 𝑈𝑜. 𝑎 𝜔= ;
𝜕𝑥 = 𝑈𝑜. 𝑎 𝜕𝑥
𝜑 = 𝑈𝑜. 𝑎
𝜔 = 0; 𝜕𝑣𝑥 𝜕𝜔 𝜕𝜑
𝜔=− ; = 0; =0
𝜑 = 𝑈𝑜. 𝑦 𝜕𝑦 𝜕𝑥 𝜕𝑥
𝜕𝑣𝑦 𝜑=0 𝜕𝑣𝑦
𝜔= ; 𝜑=0 𝜔= ; 𝜑=0
𝜕𝑥 𝜕𝑥

𝜕𝑣𝑥 𝜕𝑣𝑥
𝜔=− ; 𝜑=0 𝜔=− ; 𝜑=0
𝜕𝑦 𝜕𝑦
⃗ ⋅ ⃗⃗⃗⃗⃗
(𝑖𝑖) ∭ 𝜔 ⅆ𝑉 = − ∬ 𝛻⃗ 𝜑. ⅆ 𝐴

After discretization:
𝜑𝑝 = 𝜑𝑤 + 𝜑𝑤 + 𝜑𝑤 + 𝜑𝑤 + 𝜔𝑝 ∙ ∆𝑥 2
For obtaining velocity:
𝜕𝜑 −𝜕𝜑
𝑉𝑥 = ; 𝑉𝑦 =
𝜕𝑦 𝜕𝑥

After obtaining these velocities we need to modify 𝜔 values by using these


velocity values in equation (i)
𝜕𝜔 1
∭ ⃗ ⋅ ⃗⃗⃗⃗⃗
∙ ⅆ𝑉 + ∬ 𝜔𝑉 ⅆ𝐴 = 𝛻𝜔 ⋅ ⃗⃗⃗⃗⃗
∬ ⃗⃗⃗⃗⃗ ⅆ𝐴
𝜕𝑡 𝑅𝑒
#include <iostream>
#include <vector>
#include <math.h>
#include <fstream>
#include <string>
#include <bits/stdc++.h>

using namespace std;

bool isWall(int i, int j, int mx, int my, int lt2, double bigD, double smallD)
{
int c3 = (mx / 2) - (lt2 / 2);

double k1l = (bigD - smallD) / 2.0;


double dy = bigD / my;
int k1 = k1l / dy;
int k2 = my - k1 + 1;

if (i > c3 && i <= c3 + lt2)


{
if (1 <= j && j <= k1)
{
return true;
}
else if (k2 <= j && j <= my)
{
return true;
}
}
return false;
}
void writer(vector<std::vector<double>> &v, string name, int mx, int my, int
time, int k1, int k2, int c3, int lt2, double dy)
{
ofstream file("outputs/" + name + "_" + to_string(time) + ".csv");
for (int j = 1; j <= my; j++)
{
for (int i = 1; i <= mx; i++)
{
if (i > c3 && i <= c3 + lt2)
{
if (1 <= j && j <= k1)
{
file << 0 << ",";
continue;
}
if (k2 <= j && j <= my)
{
file << 0 << ",";
continue;
}
}
file << v[i][j] << ",";
}
file << "\n";
}
}
int main()
{
double entry_velocity, nu, lt, ht, dt, d, dy, beta, adv, dif, corr;
int mx, my;
int c3;
double sHt;
double length;
int lt2;

lt = 10.0;
ht = 2.2;
sHt = 0.6;
mx = 50;
my = 11;
entry_velocity = 2.0;
nu = 0.01;
dt = 0.0006;
dy = ht / my; // 0.2
d = dt / (dy * dy);
beta = 1;
length = 4.00;
lt2 = length / dy + 1; // 20
c3 = (mx / 2.0) - (lt2 / 2);

double k1l = (ht - sHt) / 2;


int k1 = k1l / dy;
int k2 = my - k1 + 1;
cout << k1 << " " << k2 << endl;

vector<vector<double>> omgN(mx + 2, vector<double>(my + 2, 0));


vector<vector<double>> psi(mx + 2, vector<double>(my + 2, 0));
vector<vector<double>> vx(mx + 2, vector<double>(my + 2, 0));
vector<vector<double>> vy(mx + 2, vector<double>(my + 2, 0));
vector<vector<double>> omgP(mx + 2, vector<double>(my + 2, 0));
vector<vector<double>> residue(mx + 2, vector<double>(my + 2, 0));

vector<double> y(my + 2, 0);


y[1] = dy / 2;

// GENERATING GRID
for (int j = 0; j < my + 2; j++)
{
for (int i = 0; i < mx + 2; i++)
{
if (isWall(i, j, mx, my, lt2, ht, sHt))
{
cout << " | ";
}
else
{
cout << " - ";
}
}
cout << endl;
}

for (int i = 2; i < my + 1; i++)


{
y[i] = y[1] + (i - 1) * dy;
}
// updation of boundary conditions

for (int i = 0; i < mx + 2; i++)


{
if (i <= c3 || i > c3 + lt2)
{
omgN[i][0] = -4 * (vx[i][1] / dy) - omgN[i][1]; // top
bigger section
omgN[i][my + 1] = 4 * (vx[i][my] / dy) - omgN[i][my]; // bottom
bigger section
}
else
{
omgN[i][k1] = -4 * (vx[i][k1 + 1] / dy) - omgN[i][k1 + 1]; // top
smaller section
omgN[i][k2] = 4 * (vx[i][k2 - 1] / dy) - omgN[i][k2 - 1]; //
bottom smaller section
}
}
for (int j = 0; j < my + 2; j++)
{
omgN[0][j] = -omgN[1][j]; // left or entrance
omgN[mx + 1][j] = omgN[mx][j]; // right or exit

if ((1 <= j && j <= k1) || k2 <= j && j <= my)


{
omgN[c3 + 1][j] = (4 * vy[c3][j] / dy) -
omgN[c3][j]; // orifice left wall
omgN[c3 + lt2][j] = (4 * vy[c3 + 3][j] / dy) - omgN[c3 + lt2 +
1][j]; // orifice right wall
}
}
int step = 1;
do
{
double ue, uw, vn, vs, we, ww, ws, wn;

for (int i = 1; i < mx + 1; i++)


{
for (int j = 1; j < my + 1; j++)
{
if (isWall(i, j, mx, my, lt2, ht, sHt))
continue;
ue = (vx[i][j] + vx[i + 1][j]) / 2;
uw = (vx[i][j] + vx[i - 1][j]) / 2;
vn = (vy[i][j] + vy[i][j + 1]) / 2;
vs = (vy[i][j] + vy[i][j - 1]) / 2;

// FIRST ORDER UPWIND SCHEME FOR VORTICITIES


we = (ue > 0) ? omgP[i][j] : omgP[i + 1][j];
ww = (uw > 0) ? omgP[i - 1][j] : omgP[i][j];
wn = (vn > 0) ? omgP[i][j] : omgP[i][j + 1];
ws = (vs > 0) ? omgP[i][j - 1] : omgP[i][j];

adv = (we * ue - ww * uw) * dy + (wn * vn - ws * vs) * dy;


dif = nu * (omgP[i][j + 1] + omgP[i][j - 1] + omgP[i + 1][j] +
omgP[i - 1][j] - (4 * omgP[i][j]));
omgN[i][j] = d * (dif - adv) + omgP[i][j];
}
}

double sum, rms;

do
{
sum = 0.0;

// Implementation of Stream function's boundary conditions


for (int i = 0; i < mx + 2; i++)
{
if (i <= c3 || i > c3 + lt2)
{
psi[i][my + 1] = 2 * entry_velocity * ht - psi[i][my]; //
top bigger section
psi[i][0] = -psi[i][1]; //
bottom bigger section
}
else
{
psi[i][k1] = -psi[i][k1 + 1]; //
top smaller section
psi[i][k2] = 2 * entry_velocity * ht - psi[i][k2 - 1]; //
bottom smaller section
}
}
for (int j = 0; j < my + 2; j++)
{
psi[0][j] = 2 * entry_velocity * y[j] - psi[1][j]; // entrance
wall
psi[mx + 1][j] = psi[mx][j]; // exit
wall

if ((1 <= j && j <= k1))


{
psi[c3 + 1][j] = -psi[c3][j]; // contraction wall upper
psi[c3 + lt2][j] = -psi[c3 + lt2 + 1][j];
}
if ((k2 <= j && j <= my))
{
psi[c3 + 1][j] = (2 * entry_velocity * ht) - psi[c3][j];
psi[c3 + lt2][j] = (2 * entry_velocity * ht) - psi[c3 +
lt2 + 1][j]; // contraction wall lower
}
}

// GAUSS SEIDEL FOR STREAM FUNCTION CALCULATION

for (int i = 1; i < mx + 1; i++)


{
for (int j = 1; j < my + 1; j++)
{
if (isWall(i, j, mx, my, lt2, ht, sHt))
continue;

residue[i][j] = omgN[i][j] * dy * dy + psi[i + 1][j] +


psi[i - 1][j] + psi[i][j + 1] + psi[i][j - 1] - (4 * psi[i][j]);
corr = residue[i][j] * (beta / 4);
psi[i][j] = psi[i][j] + corr;
sum = sum + (residue[i][j] * residue[i][j]);
}
}
rms = sqrt(sum / (mx * my));
// cout << "Hehe: " << rms << endl;
} while (rms > 1.0e-6);
cout << "\n STEP: " << step << "RMS: " << rms;

// velocity components updation


for (int i = 1; i < mx + 1; i++)
{
for (int j = 1; j < my + 1; j++)
{
if (isWall(i, j, mx, my, lt2, ht, sHt))
continue;
vx[i][j] = (psi[i][j + 1] - psi[i][j - 1]) / (2 * dy);
vy[i][j] = (psi[i - 1][j] - psi[i + 1][j]) / (2 * dy);
}
}

// updation of boundary conditions

for (int i = 0; i < mx + 2; i++)


{

if (i <= c3 || i > c3 + lt2) // top and bottom bigger section


{
vy[i][0] = -vy[i][1]; // top
vx[i][0] = -vx[i][1]; // top
omgN[i][0] = -4 * (vx[i][1] / dy) - omgN[i][1]; // top

vy[i][my + 1] = -vy[i][my]; //
bottom
vx[i][my + 1] = -vx[i][my]; //
bottom
omgN[i][my + 1] = 4 * (vx[i][my] / dy) - omgN[i][my]; //
bottom
}
else // Smaller section
{
vy[i][k1] = -vy[i][k1 + 1]; //
top
vx[i][k1] = -vx[i][k1 + 1]; //
top
omgN[i][k1] = -4 * (vx[i][k1 + 1] / dy) - omgN[i][k1 + 1]; //
top

vy[i][k2] = -vy[i][k2 - 1]; //


bottom
vx[i][k2] = -vx[i][k2 - 1]; //
bottom
omgN[i][k2] = 4 * (vx[i][k2 - 1] / dy) - omgN[i][k2 - 1]; //
bottom
}
}
for (int j = 0; j < my + 2; j++)
{
omgN[0][j] = -omgN[0][j]; // entry or left
vx[0][j] = 2 * entry_velocity - vx[0][j]; // entry or left
vy[0][j] = -vy[0][j]; // entry or left

omgN[mx + 1][j] = omgN[mx][j]; // exit or right


vx[mx + 1][j] = vx[mx][j]; // exit or right
vy[mx + 1][j] = vy[mx][j]; // exit or right
if (1 <= j && j <= k1) // upper contraction wall
{
omgN[c3 + 1][j] = (4 * vy[c3][j] / dy) - omgN[c3][j];
omgN[c3 + lt2][j] = (4 * vy[c3 + lt2 + 1][j] / dy) - omgN[c3 +
lt2 + 1][j];

vx[c3 + 1][j] = -vx[c3][j];


vy[c3 + 1][j] = -vy[c3][j];

vx[c3 + lt2][j] = -vx[c3 + lt2 + 1][j];


vy[c3 + lt2][j] = -vy[c3 + lt2 + 1][j];
}
else if (k2 <= j && j <= my) // lower contraction wall
{
omgN[c3 + 1][j] = (4 * vy[c3][j] / dy) - omgN[c3][j];
omgN[c3 + lt2][j] = (4 * vy[c3 + lt2 + 1][j] / dy) - omgN[c3 +
lt2 + 1][j];

vx[c3 + 1][j] = -vx[c3][j];


vy[c3 + 1][j] = -vy[c3][j];

vx[c3 + lt2][j] = -vx[c3 + lt2 + 1][j];


vy[c3 + lt2][j] = -vy[c3 + lt2 + 1][j];
}
}

step++;
// writeToFile(vx,vy,psi, omgN, mx, my, step, k1, k2, c3,dy);
// writeToFile(psi, mx, my, "psi", step, k1, k2, c3);
// writeToFile(omgN, mx, my, "vorticity", step, k1, k2, c3);
writer(vx, "vx", mx, my, step, k1, k2, c3, lt2, dy);
writer(omgN, "vorticity", mx, my, step, k1, k2, c3, lt2, dy);
writer(psi, "psi", mx, my, step, k1, k2, c3, lt2, dy);

omgP = omgN;

// cout << "\nStep: " << step;


} while (step < 200);
}


Series11
Series9
Series7
Series5
Series3
Series1
1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51

Velocity contours
8
7
6
5
4
3
2
1
0
1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49

Series1 Series2 Series3 Series4 Series5 Series6


Series7 Series8 Series9 Series10 Series11

for nu =1
Series15
Series13
Series11
Series9
Series7
Series5
Series3
Series1
1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49
-3.5--3 -3--2.5 -2.5--2 -2--1.5 -1.5--1 -1--0.5 -0.5-0 0-0.5 0.5-1
1-1.5 1.5-2 2-2.5 2.5-3 3-3.5 3.5-4 4-4.5 4.5-5 5-5.5
5.5-6 6-6.5 6.5-7 7-7.5 7.5-8 8-8.5 8.5-9 9-9.5 9.5-10
10-10.5 10.5-11 11-11.5 11.5-12 12-12.5 12.5-13 13-13.5 13.5-14

You might also like