Sie sind auf Seite 1von 13

METU, Dept. of Mechanical Eng.

ME 705, Fall 2016, Dr. C. Sert

Handout 11
Implementing the SIMPLE Algorithm

An Alternative Implementation of Velocity Under-relaxation

In SIMPLE we need under-relaxation because

 the solution is segregated (sequential), i.e. 𝑥-momentum equation is solved for 𝑢 by assuming 𝑣 and 𝑝 to
be known, and 𝑦-momentum equation is solved for 𝑣 by assuming 𝑢 and 𝑝 to be known.
 nonlinear terms are linearized by calculating mass flow rates using old velocities.
 neighbor contributions are neglected in relating pressure corrections to velocity corrections

To compensate all these and to end up with a converging solution, we used pressure and velocity under-relaxation
as follows

𝑝 = 𝑝𝑜𝑙𝑑 + 𝛼𝑝 𝑝′

𝑢𝑛𝑒𝑤 = 𝛼𝑉 𝑢 + (1 − 𝛼𝑉 )𝑢𝑜𝑙𝑑

𝑣 𝑛𝑒𝑤 = 𝛼𝑉 𝑣 + (1 − 𝛼𝑉 )𝑣 𝑜𝑙𝑑
However in practice velocity under-relaxation is not used like this. Instead it is directly applied to the solution of 𝑢∗
and 𝑣 ∗ velocities by modifying, for example, Eqn. (12a) as follows (a bit of mathematics is required to see how this
works)
𝑢 𝑢
𝑎𝑖,𝑗 ∗ 𝑢 ∗ 𝑜𝑙𝑑 𝑜𝑙𝑑 𝑢
𝑎𝑖,𝑗 𝑜𝑙𝑑
𝑢𝑖,𝑗 = ∑ 𝑎𝑛𝑏 𝑢𝑛𝑏 − (𝑝𝑖+1,𝑗 − 𝑝𝑖,𝑗 )Δ𝑦 + 𝑏𝑖,𝑗 + (1 − 𝛼𝑉 ) 𝑢𝑖,𝑗
𝛼
⏟𝑉 𝛼
⏟𝑉
𝑛𝑒𝑤
𝑛𝑏 𝑛𝑒𝑤
𝑢 𝑢
𝑎𝑖,𝑗 𝑎𝑖,𝑗

In the rest of this handout the “new” superscript will be dropped from the central coefficient for clarity, but we
need to remember how it makes use of the velocity under-relaxation.

Eqn. (12b) is modified in a similar way. After this modification velocities are updated without any extra relaxation
as follows

𝑢 = 𝑢∗ + 𝑢′ , 𝑣 = 𝑣∗ + 𝑣′
Mathematically we are not doing anything different than what we were doing before. But numerically this approach
is preferred because in this way 𝑢∗ and 𝑣 ∗ equations become more “diagonally dominant” due to the central
coefficients being divided by 𝛼𝑉 , which is a number less than 1. And this is a desired property for the convergence
of iterative algebraic system solvers such as Gauss-Seidel.

1
METU, Dept. of Mechanical Eng.
ME 705, Fall 2016, Dr. C. Sert

Simplified equations used in the code based on central differencing and ℎ = Δ𝑥 = Δ𝑦 with no body force

𝑢 ∗ 𝑢 ∗ 𝑜𝑙𝑑 𝑜𝑙𝑑 𝑢 𝑜𝑙𝑑


𝑎𝑖,𝑗 𝑢𝑖,𝑗 = ∑ 𝑎𝑛𝑏 𝑢𝑛𝑏 − (𝑝𝑖+1,𝑗 − 𝑝𝑖,𝑗 )ℎ + (1 − 𝛼𝑉 )𝑎𝑖,𝑗 𝑢𝑖,𝑗 (1𝑎)
𝑛𝑏
Velocity
𝑢 1 𝑚̇𝑒𝑢 𝑚̇𝑤
𝑢
𝑚̇𝑛𝑢 𝑚̇𝑠𝑢 underelaxation
𝑎𝑖,𝑗 = ( + + + + 4𝜇)
𝛼𝑉 2 2 2 2
Step 1

𝑢 𝑚̇𝑒𝑢 𝑢
𝑢
𝑚̇𝑤 𝑢 𝑚̇𝑛𝑢 𝑢 𝑚̇𝑠𝑢
𝑎𝑖+1,𝑗 =− +𝜇 , 𝑎𝑖−1,𝑗 =− +𝜇 , 𝑎𝑖,𝑗+1 =− +𝜇 , 𝑎𝑖,𝑗−1 =− +𝜇
2 2 2 2

y-momentum equation discretized for 𝑣 ∗ is very similar to the above one (1𝑏)

𝑃𝐶 ′ 𝑃𝐶 ′ 𝑃𝐶
𝑎𝑖,𝑗 𝑝𝑖,𝑗 = ∑ 𝑎𝑛𝑏 𝑝𝑛𝑏 + 𝑏𝑖,𝑗 (2)
𝑛𝑏
𝑃𝐶 𝑢 𝑢 𝑣 𝑣
𝑎𝑖,𝑗 = 𝑑𝑖,𝑗 + 𝑑𝑖−1,𝑗 + 𝑑𝑖,𝑗 + 𝑑𝑖,𝑗−1
𝑃𝐶 𝑢 𝑃𝐶 𝑢 𝑃𝐶 𝑣 𝑃𝐶 𝑣
𝑎𝑖+1,𝑗 = 𝑑𝑖,𝑗 , 𝑎𝑖−1,𝑗 = 𝑑𝑖−1,𝑗 , 𝑎𝑖,𝑗+1 = 𝑑𝑖,𝑗 , 𝑎𝑖,𝑗−1 = 𝑑𝑖,𝑗−1
Step 2

New definitions
𝑢 ℎ 𝑢 ℎ 𝑣 ℎ 𝑣 ℎ
where 𝑑𝑖,𝑗 = 𝑢 , 𝑑𝑖−1,𝑗 = 𝑢 , 𝑑𝑖,𝑗 = 𝑣 , 𝑑𝑖,𝑗−1 = 𝑣
used in the
𝑎𝑖,𝑗 𝑎𝑖−1,𝑗 𝑎𝑖,𝑗 𝑎𝑖,𝑗−1 code.
𝑃𝐶 ∗ ∗ ∗ ∗
𝑏𝑖,𝑗 = −𝑢𝑖,𝑗 + 𝑢𝑖−1,𝑗 − 𝑣𝑖,𝑗 + 𝑣𝑖,𝑗−1

′ ′ ′ 𝑢
𝑢𝑖,𝑗 = −(𝑝𝑖+1,𝑗 − 𝑝𝑖,𝑗 )𝑑𝑖,𝑗 (3𝑎)
Step 3

′ ′ ′ 𝑣
𝑣𝑖,𝑗 = −(𝑝𝑖,𝑗+1 − 𝑝𝑖,𝑗 )𝑑𝑖,𝑗 (3𝑏)

𝑝 = 𝑝𝑜𝑙𝑑 + 𝛼𝑝 𝑝′ (4𝑎)

𝑢 = 𝑢∗ + 𝑢′
Step 4

(4𝑏)

𝑣 = 𝑣∗ + 𝑣′ (4𝑐)

2
METU, Dept. of Mechanical Eng.
ME 705, Fall 2016, Dr. C. Sert

Boundary Conditions with Ghost Cells for the Lid-Driven Cavity Problem

Consider the same mesh of 9 pressure cells given in Handout 8. With the ghost cells totally there are 25 pressure
nodes, 20 u-velocity nodes and 20 v-velocity nodes.

BCs for the u and v velocities are implemented in the same way as described in Handout 8. In summary we solve
Eqns (1a) and (1b) only for the 6 unknown inner velocities. These calculations may need known velocities at the
boundaries or velocities of the ghost cells. We update the ghost cell velocities at the beginning of each SIMPLE
iteration by using a linear interpolation across the boundaries.

Let’s see how the pressure correction equation (PCE) need to be modified for the boundary cells. Here are the p-
cells and the known velocities that affect the PCE of the boundary p-cells.

As an example consider cell 𝑝2,2 . Continuity equation for this cell is (ℎ = Δ𝑥 = Δ𝑦)

3
METU, Dept. of Mechanical Eng.
ME 705, Fall 2016, Dr. C. Sert

ℎ ( 𝑢2,2 − 𝑢
⏟1,2 + 𝑣2,2 − 𝑣
⏟2,1 ) = 0 (5)
𝑢𝐿 𝑣𝐵

where 𝑢𝐿 and 𝑣𝐵 are the known velocities at the left and bottom boundaries. Cancel the constant ℎ and write the
unknown velocities as the summation of “star” and “prime” velocities.
∗ ′ ∗ ′
(𝑢2,2 + 𝑢2,2 ) − 𝑢𝐿 + (𝑣2,2 + 𝑣2,2 ) − 𝑣𝐵 = 0 (6)

Replace the velocity corrections with pressure corrections using Eqn. (3)
∗ ′ ′ 𝑢 ∗ ′ ′ 𝑣
[𝑢2,2 − (𝑝3,2 − 𝑝2,2 )𝑑2,2 ] − 𝑢𝐿 + [𝑣2,2 − (𝑝2,3 − 𝑝2,2 )𝑑2,2 ] − 𝑣𝐵 = 0 (7)

Therefore coefficients of the PCE will be


𝑃𝐶 𝑢 𝑣 𝑃𝐶 𝑢 𝑃𝐶 𝑣 𝑃𝐶 ∗ ∗
𝑎2,2 = ℎ(𝑑2,2 + 𝑑2,2 ) , 𝑎3,2 = ℎ𝑑2,2 , 𝑎2,3 = ℎ𝑑2,2 , 𝑏2,2 = ℎ(−𝑢2,2 + 𝑢𝐿 − 𝑣2,2 + 𝑣𝐵 )

Compared to the original PCE, i.e. Eqn (2)


𝑃𝐶
 To make the central coefficient 𝑎2,2 same as the general one we need to set 𝑑𝑢 and 𝑑𝑣 values of the
boundary faces with known normal speed to zero. Actually 𝑑𝑢 and 𝑑𝑣 values are only calculated for the
unknown u-cells and for boundary cells with known velocity they’ll never be modified from their initial zero
value.
 On the right hand side there is no change compared to the general form because in the code 𝑢𝐿 and 𝑣𝐵
∗ ∗
will be seen as 𝑢1,2 and 𝑢2,1 .

To summarize, there is nothing special we need to do for the boundary pressure nodes.

Fixing Pressure at a Node

As we discussed in class, for this lid driven cavity problem no pressure information is provided at the boundaries.
Pressure values will have no reference value to settle around. For such cases we usually set the pressure at a node
to a reference value. In the code we equated the pressure at the lower left corner (𝑝2,2 ) to zero for simplicity. To
do this we set the pressure correction at that p-cell to zero at each iteration, therefore the initial zero pressure will
not be modified.

Note that in incompressible flows the pressure values are not important, but the gradient of pressure is what
matters. Therefore setting the pressure to zero at the corner cell or setting it to a different value will not make any
difference on the velocity field. Only all the pressure values will go up or down by the same constant, which is not
important.

For flows with fully developed outlet boundaries we usually set pressure to zero at the outlet.

4
METU, Dept. of Mechanical Eng.
ME 705, Fall 2016, Dr. C. Sert

% 2D flow solver using the SIMPLE method.

% It is designed to solve the lid driven cavity problem.


% Uses central space differencing.
% Uses staggered mesh.
% Uses ghost cells for boundary conditions.
% Pressure is fixed to zero at the bottom-left corner cell.

refSoln = load ('Ghia_Re100_Uvel'); % u velocity variation along the vertical centerline


% from Ghia's reference solution. The data is available
% at 4 different Reynolds numbers (100, 1000, 3200 and
% 5000). refSoln has 2 columns, y and u.

Nx = 30; % Number of pressure cells in both x and y directions


% (not including ghost cells)
% Provide an even value to avoid a possible error in
% the post-processing part.
rho = 1.0; % Density [kg/m^3]
visc = 0.01; % Dynamic viscosity [Pa s]
alphaP = 0.5; % Pressure relaxation
alphaV = 0.5; % Velocity relaxation
maxIter = 10000; % Maximum number of SIMPLE iterations
maxGSiter = 1; % Maximum number of iterations for GS solution of all equation sets.

u_TOP = 1.0; % Tangential velocities at the boundaries [m/s] Be careful !!!


u_BOTTOM = 0.0;
v_LEFT = 0.0;
v_RIGHT = 0.0;

Ny = Nx;
h = 1/Nx; % h is the cell size (=dx=dy). Cavity is a square of size 1x1.

% Allocate memory. Note that staggered grid with ghost cells is being used.
u = zeros(Nx+1,Ny+2); % x velocity values
uStar = zeros(Nx+1,Ny+2); % Temporary x velocity values
uPrime = zeros(Nx+1,Ny+2); % x velocity correction
Note that the
v = zeros(Nx+2,Ny+1); % y velocity values mesh is staggered.
vStar = zeros(Nx+2,Ny+1); % Temporary y velocity values
vPrime = zeros(Nx+2,Ny+1); % y velocity correction

p = zeros(Nx+2,Ny+2); % Pressure values


pOld = zeros(Nx+2,Ny+2); % Pressure values of the previous iteration
pPrime = zeros(Nx+2,Ny+2); % Pressure correction

dU = zeros(Nx+1,Ny+2); % Parameter used in the PCE and in u' - p' relation


dV = zeros(Nx+2,Ny+1); % Parameter used in the PCE and in v' - p' relation

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Initialize the solution
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

u(:,:) = 0.0; v(:,:) = 0.0; p(:,:) = 0.0;


uOld = u; % uOld and vOld are used to check steady state convergence
vOld = v;

% Print the header for the data that'll be written on the screen
fprintf(' iter u at (0.5,0.5) v at (0.5,0.5)\n');
fprintf('=========================================\n');

5
METU, Dept. of Mechanical Eng.
ME 705, Fall 2016, Dr. C. Sert

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Start the SIMPLE iterations
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

for n = 1:maxIter
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Update ghost cell velocities using linear interpolation
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

for i = 1:Nx+1
uOld(i,1) = 2*u_BOTTOM - uOld(i,2); % Bottom boundary
uOld(i,Ny+2) = 2*u_TOP - uOld(i,Ny+1); % Top boundary
end Update ghost cell
velocities using
for j = 1:Ny+1 linear interpolation.
vOld(1,j) = 2*v_LEFT - vOld(2,j); % Left boundary
vOld(Nx+2,j) = 2*v_RIGHT - vOld(Nx+1,j); % Right boundary
end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% STEP 1a. Solve the x momentum equation (Eqn. 1a of Handout 11) using
% Gauss-Seidel. The result is stored in uStar.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% First setup the coefficients


for i = 2:Nx % These i and j are the indices of the u-cell
for j = 2:Ny+1 Calculate the
mdot_e = rho * h * 0.5 * (uOld(i,j) + uOld(i+1,j)); coefficients of the
mdot_w = -rho * h * 0.5 * (uOld(i,j) + uOld(i-1,j));
mdot_n = rho * h * 0.5 * (vOld(i,j) + vOld(i+1,j)); x-momentum eqn.
mdot_s = -rho * h * 0.5 * (vOld(i,j-1) + vOld(i+1,j-1));

% Center cell coefficient with applied under-relaxation


au_C(i,j) = (0.5 * (mdot_e + mdot_w + mdot_n + mdot_s) + 4*visc) / alphaV;

au_E(i,j) = - 0.5 * mdot_e + visc; % East neighbor coefficient


au_W(i,j) = - 0.5 * mdot_w + visc; % West neighbor coefficient
Velocity under-relaxation is
au_N(i,j) = - 0.5 * mdot_n + visc; % North neighbor coefficient applied directly to the x-
au_S(i,j) = - 0.5 * mdot_s + visc; % South neighbor coefficient momentum eqn.
dU(i,j) = h / au_C(i,j); % Will be used in the PCE equation and
end % updating the u velocity
end

% For the initial guess of the G-S solution use the previous iteration values
uStar = uOld;

% Gauss-Seidel iterations
for iter = 1:maxGSiter Gauss-Seidel solution of
for i = 2:Nx % These i and j are the indices of the u-cell the x-momentum eqn.
for j = 2:Ny+1
uStar(i,j) = (au_E(i,j) * uStar(i+1,j) + au_W(i,j) * uStar(i-1,j) ...
+ au_N(i,j) * uStar(i,j+1) + au_S(i,j) * uStar(i,j-1) ...
- h * (pOld(i+1,j) - pOld(i,j)) ...
+ (1-alphaV) * au_C(i,j) * uOld(i,j) ) / au_C(i,j); Velocity under-relaxation
end
end also affects the right
% WARNING: Here we typically check the convergence of Gauss-Seidel. hand side
end

6
METU, Dept. of Mechanical Eng.
ME 705, Fall 2016, Dr. C. Sert

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% STEP 1b. Solve the y momentum equation (Eqn. 1b of Handout 11) using
% Gauss-Seidel. The result is stored in vStar.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% First setup the coefficients


for i = 2:Nx+1 % These i and j are the indices of the v-cell
for j = 2:Ny
Calculate the
mdot_e = rho * h * 0.5 * (uOld(i,j) + uOld(i,j+1)); coefficients of the
mdot_w = -rho * h * 0.5 * (uOld(i-1,j) + uOld(i-1,j+1)); y-momentum eqn.
mdot_n = rho * h * 0.5 * (vOld(i,j) + vOld(i,j+1));
mdot_s = -rho * h * 0.5 * (vOld(i,j) + vOld(i,j-1));

% Center cell coefficient with applied under-relaxation


av_C(i,j) = (0.5 * (mdot_e + mdot_w + mdot_n + mdot_s) + 4*visc) / alphaV;

av_E(i,j) = - 0.5 * mdot_e + visc; % East neighbor coefficient Velocity under-relaxation is


av_W(i,j) = - 0.5 * mdot_w + visc; % West neighbor coefficient applied directly to the y-
av_N(i,j) = - 0.5 * mdot_n + visc; % North neighbor coefficient
av_S(i,j) = - 0.5 * mdot_s + visc; % South neighbor coefficient
momentum eqn.

dV(i,j) = h / av_C(i,j); % Will be used in the PCE equation and


end % updating the u velocity
end

% For the initial guess of the G-S solution use the previous iteration
% values
vStar = vOld;

% Gauss-Seidel iterations
for iter = 1:maxGSiter Gauss-Seidel solution of
for i = 2:Nx+1 % These i and j are the indices of the v-cell the y-momentum eqn.
for j = 2:Ny
vStar(i,j) = (av_E(i,j) * vStar(i+1,j) + av_W(i,j) * vStar(i-1,j) ...
+ av_N(i,j) * vStar(i,j+1) + av_S(i,j) * vStar(i,j-1) ...
- h * (pOld(i,j+1) - pOld(i,j)) ...
+ (1-alphaV) * av_C(i,j) * vOld(i,j) ) / av_C(i,j);
end Velocity under-relaxation
end also affects the right
% WARNING: Here we typically check the convergence of Gauss-Seidel.
end hand side

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% STEP 2. Solve the pressure correction equation (PCE) (Eqn. 2 of
% Handout 11) using Gauss-Seidel
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Calculate the
% First setup the coefficients
for i = 2:Nx+1 % These i and j are the indices of the p-cell coefficients of the
for j = 2:Ny+1 pressure correction eqn.

aPC_C(i,j) = dU(i,j) + dU(i-1,j) + dV(i,j) + dV(i,j-1); % Center cell coefficient


aPC_E(i,j) = dU(i,j); % East neighbor coefficient
aPC_W(i,j) = dU(i-1,j); % West neighbor coefficient
aPC_N(i,j) = dV(i,j); % North neighbor coefficient
aPC_S(i,j) = dV(i,j-1); % South neighbor coefficient

bPC(i,j) = -uStar(i,j) + uStar(i-1,j) - vStar(i,j) + vStar(i,j-1); % RHS value


end
end

7
METU, Dept. of Mechanical Eng.
ME 705, Fall 2016, Dr. C. Sert

% IMPORTANT: In the cavity flow problem velocities at all boundaries are given. No pressure
% information is provided at the boundaries. It's better to fix pressure at a point.
% Let's fix it to zero at the bottom-left cell, i.e. set the pressure correction
% at this cell to zero.
i = 2;
j = 2;
aPC_C(i,j) = 1.0; % Center cell coefficient
aPC_E(i,j) = 0.0; % East neighbor coefficient Set the pressure correction of
aPC_W(i,j) = 0.0; % West neighbor coefficient the bottom-left cell to zero.
aPC_N(i,j) = 0.0; % North neighbor coefficient
aPC_S(i,j) = 0.0; % South neighbor coefficient
bPC(i,j) = 0.0; % RHS value

% Gauss-Seidel loop
Gauss-Seidel solution of
pPrime(:,:) = 0; % Initialize pPrime's to zero.
for iter = 1:maxGSiter the pressure correction
for i = 2:Nx+1 eqn.
for j = 2:Ny+1
pPrime(i,j) = (aPC_E(i,j) * pPrime(i+1,j) + aPC_W(i,j) * pPrime(i-1,j) ...
+ aPC_N(i,j) * pPrime(i,j+1) + aPC_S(i,j) * pPrime(i,j-1) ...
+ bPC(i,j) ) / aPC_C(i,j);
end
end
% WARNING: Here we typically check the convergence of Gauss-Seidel.
end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% STEP 3. Calculate velocity corrections using Eqn. 3 of Handout 11
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Calculate u corrections
for i = 2:Nx
for j = 2:Ny+1
uPrime(i,j) = -(pPrime(i+1,j) - pPrime(i,j)) * dU(i,j);
end Calculate velocity corrections.
end
No need to use velocity
% Calculate v corrections under-relaxation here. we
for i = 2:Nx+1 already used it above.
for j = 2:Ny
vPrime(i,j) = -(pPrime(i,j+1) - pPrime(i,j)) * dV(i,j);
end
end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% STEP 4. Correct p, u and v using Eqn. 4 of Handout 11
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Correct pressures and apply under-relaxation


for i = 2:Nx+1
for j = 2:Ny+1 Correct pressures and
p(i,j) = pOld(i,j) + alphaP * pPrime(i,j); apply pressure under-
end relaxation
end

8
METU, Dept. of Mechanical Eng.
ME 705, Fall 2016, Dr. C. Sert

% Correct u velocities. Note that under-relaxation was already applied in uStar calculation.
for i = 2:Nx
for j = 2:Ny+1
u(i,j) = uStar(i,j) + uPrime(i,j); Correct u velocities
end
end

% Correct v velocities. Note that under-relaxation was already applied in vStar calculation.
for i = 2:Nx+1
for j = 2:Ny
v(i,j) = vStar(i,j) + vPrime(i,j); Correct v velocities
end
end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Write some results on the screen
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Calculate u and v at (0.5,0.5)
uCenter = u(Nx/2+1, Ny/2+1);
vCenter = v(Nx/2+1, Ny/2+1);
fprintf('%5d %8.3e %8.3e\n', n, uCenter, vCenter);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Plot the u velocity variation along the vertical centerline of the
% cavity
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

if mod(n,10) == 0
yCenter = h/2:h:1-h/2; Post processing
uCenter = u(Nx/2+1, 2:Ny+1);

plot(refSoln(:,2), refSoln(:,1), uCenter, yCenter, 'ko', 'MarkerFaceColor', 'k')


axis([-1 1 0 1]);
grid on
xlabel('u [m/s]');
ylabel('y [m]');
title('u velocity component along the vertical centerline');
drawnow;
end

uOld = u;
vOld = v;
pOld = p;

% WARNING: Here we typically calculate a residual, which is a measure of how good


% the mass and momentum conservation equations are satisfied, and plot it.

end % End of SIMPLE iterations loop

9
METU, Dept. of Mechanical Eng.
ME 705, Fall 2016, Dr. C. Sert

Sample Solutions

Solution 1: Nx = Ny = 30, visc = 0.01 (𝑅𝑒 = 100), 𝛼𝑉 = 𝛼𝑃 = 1

For the low Re flow, we could obtain this result


with no under-relaxation. There were a bit of
oscillations at the beginning of the solution but
solution managed to converge after ~250
iterations.

Dots are our solution and the solid line is Ghia’s


reference solution.

Solution 2: Same as Solution 1 but now visc = 0.001 (𝑅𝑒 = 1000)

For this higher Re flow, solution quickly diverged


when no under-relaxation is used.

With 𝛼𝑉 = 𝛼𝑃 = 0.5 again it diverged.

We need to lower 𝛼𝑉 down to 0.1 to obtain a


converging solution. It turns out that 𝛼𝑃 is not
that critical for convergence and can stay at 1.
Remember that for faster convergence it is
suggested to use 𝛼𝑃 = 1 − 𝛼𝑉 .

This solution is obtained with 𝛼𝑉 = 0.1, 𝛼𝑃 = 0.9.

10
METU, Dept. of Mechanical Eng.
ME 705, Fall 2016, Dr. C. Sert

Solution 3: To improve Solution 2 we changed Nx = Ny = 50

With this finer grid we are able to get a solution


with 𝛼𝑉 = 0.2, 𝛼𝑃 = 0.8. So refining the grid
relieves the necessity for velocity under-
relaxation a bit. the solution is better than the
previous one.

Solution 4: To test the mesh size – velocity under-relaxation relation observed in the previous solution node number
is further increased to Nx = Ny = 100. This time we were able to get a converged solution with 𝛼𝑉 = 0.3,
𝛼𝑃 = 0.7. So the observation holds. Unfortunately in MATLAB getting a converged solution with this somewhat fine
grid takes too much time.

First order Upwind Discretization

In the discretization of momentum equations it is possible to use upwinding for the convection term. In the x-
momentum equation the convection term is integrated as follows

∫ ⃗ ⋅ 𝑛⃗ 𝑑𝑆 ≈ 𝑚̇𝑒𝑢 𝑢𝑒𝑢 + 𝑚̇𝑤


𝜌𝑢𝑉 𝑢 𝑢
𝑢𝑤 + 𝑚̇𝑛𝑢 𝑢𝑛𝑢 + 𝑚̇𝑠𝑢 𝑢𝑠𝑢
𝜕∀𝑢

Calculation of mass flow rates will not change when we use upwinding, i.e. still central differencing of previous
known velocities will be used. But the unknown 𝑢 and 𝑣’s at the faces of the u-cell will be expressed in terms of
nodal values in a different way. With 1st order upwinding, convection integral for the u-cell (𝑖, 𝑗) will be evaluated
as
max(𝑚̇𝑒𝑢 , 0)𝑢𝑖,𝑗 − max(−𝑚̇𝑒𝑢 , 0)𝑢𝑖+1,𝑗 + max(𝑚̇𝑤 𝑢
, 0)𝑢𝑖,𝑗 − max(−𝑚̇𝑤 𝑢
, 0)𝑢𝑖−1,𝑗 +
max(𝑚̇𝑛𝑢 , 0)𝑢𝑖,𝑗 − max(−𝑚̇𝑛𝑢 , 0)𝑢𝑖,𝑗+1 + max(𝑚̇𝑠𝑢 , 0)𝑢𝑖,𝑗 − max(−𝑚̇𝑠𝑢 , 0)𝑢𝑖,𝑗−1

Accordingly, coefficients of Eqn (1a) of this handout will be modified as follows

𝑢 1
𝑎𝑖,𝑗 = [max(𝑚̇𝑒𝑢 , 0) + max(𝑚̇𝑤
𝑢
, 0) + max(𝑚̇𝑛𝑢 , 0) + max(𝑚̇𝑠𝑢 , 0) + 4𝜇]
𝛼𝑉
𝑢 𝑢 𝑢 𝑢
𝑎𝑖+1,𝑗 = max(𝑚̇𝑒𝑢 , 0) + 𝜇 , 𝑎𝑖−1,𝑗 𝑢
= max(𝑚̇𝑤 , 0) + 𝜇 , 𝑎𝑖,𝑗+1 = max(𝑚̇𝑛𝑢 , 0) + 𝜇 , 𝑎𝑖,𝑗−1 = max(𝑚̇𝑠𝑢 , 0) + 𝜇

11
METU, Dept. of Mechanical Eng.
ME 705, Fall 2016, Dr. C. Sert

Let’s perform solutions with 1st order upwind discretization

More Solutions

Solution 5: Same as Solution 1, but with 1st order upwind scheme.

For this low Re flow, solution is as good as central


differencing.

Solution 6: Same as Solution 2, but with 1st order upwind scheme.

This Re=1000 solution is obtained with 𝛼𝑉 = 0.5,


𝛼𝑃 = 0.5, which did not provided a converged
solution with central differencing. Therefore with
first order upwinding larger under-relaxation
factors can be used, which speeds up
convergence.

However the solution is not accurate.

12
METU, Dept. of Mechanical Eng.
ME 705, Fall 2016, Dr. C. Sert

Solution 7: Same as Solution 6, but with Nx = 50, Ny = 50.

Even this 50x50 upwind solution is not as good as


the 30x30 central-differencing result of
Solution 2.

As far as accuracy is concerned, central


differencing should be preferred over1st order
upwinding.

But the interesting point is that some popular


commercial CFD software such as ANSYS Fluent
does not even have the central differencing as an
option, although 1st order upwind scheme is
available. The reason for not including central
differencing is that it requires very fine mesh to
get a solution as convection becomes more and
more dominant, i.e. as Reynolds number
increases. For example try to obtain a solution
for Re=5000 (still a very low value, but
challenging enough for our MATLAB code) with central differencing and 1st order upwinding.

Solution 8: visc = 0.0002 (Re = 5000), Nx = 50, Ny = 50.

With central differencing even with 𝛼𝑉 = 𝛼𝑃 = 0.01 the solution blows up. You need to use too very small under-
relaxation factors, which will result in a very slowly converging run. I do not have any result to present for central
differencing.

With the 1st order upwind scheme it is possible


to get a converged solution with
𝛼𝑉 = 𝛼𝑃 = 0.5. This is the reason why
commercial software serve it as an alternative.
With affordable coarse meshes it’ll give you an
answer. But the solution is not accurate. If you
do not have a good reference to compare
against or if you are not experienced enough
to evaluate the accuracy of the result, you may
accept it to be correct. And this is danger of
low order upwinding.

So our conclusion is “If a solution blows up, it is


not necessarily a bad thing. Most probably it is
telling you that your mesh is not good enough
to solve this problem, so listen to it and, if you
have the resources and time, refine your mesh
and resolve the problem”.

Question: What about high order upwind schemes such as 2nd order TVD schemes? Are they really the cure?

13

Das könnte Ihnen auch gefallen