How to use Pseudo - Transient solution to help solve Navier- Stokes

4 views (last 30 days)
I am trying to use the Pseudo - Transient method of solving the pressure variable in the Navier-Stokes equation. In this we set the Poisson's Equation equal to a time variable (dP/dT) where T is a pseudo time variable. I have already solved for a forcing function and assume T to start at 0 and increase 1 time step each iteration. I am not given any value for pressures, so for the first step I set all values of P = to 0s. Also, once the Tolerance of the problem reaches below 1e-6, for our case it is considered convergence. The function below is what I am trying to create to represent the Pseudo method.
pressure_ex = zeros(33,33)
dx = dy = 0.2094
RHS is the forcing function (from solving advection and diffusion equations)
nGhosts = the number of ghost cells needed for periodic boundary conditions (1)
My confusing is setting up the loops properly. What I am trying to do is; while the Tolerance of the equation is above 1e-6 continue to solve for values of pressure. (For first step the value of Pressure_expand should be equal to rhs(i,j). From there the values of Pressure_expand need to be set as the values of pressure_ex to solve for a new expand set. The tolernace also needs to be calculated per step as it determines when the while statement ends. Once the tolerance causes convergence I want it to output Pressure which would be the value of pressure_expand after the while loop ends. Again I am not sure on the arrangement of my code. Any advice would be great!
function [Pressure, New_Tolerance] = Pseudo(pressure_ex, dx, dy, Rhs, nGhosts)
DTao = 1e-2; %dT value explained
Tolerance = 1; %set to anything above 1 to start while loop?
Pressure_expand = zeros(33,33);
n=0 %stepsize
for i = 2:32 %With periodic boundary conditions require us to start 1 value in on both sides
for j= 2:32
while(Tolerance > 1e-6) %Unitl the Tolerance is less that 1e-6 keep iterating
Pressure_expand = periodicCopy(Pressure_expand,nGhosts);
Pressure_expand(i,j) = pressure_ex(i,j) - n*DTao*((pressure_ex(i+1,j) -2*pressure_ex(i,j) + pressure_ex(i-1,j))/(dx.^2) + (pressure_ex(i,j+1) - 2* pressure_ex(i,j) + pressure_ex(i,j-1))/(dy.^2)) + Rhs(i,j);
%Pressure_expand = periodicCopy(Pressure_expand,nGhosts);
New_Tolerance = sqrt(sum((Pressure_expand(i,j) - pressure_ex(i,j)).^2));
Tolerance = New_Tolerance;
pressure_ex = Pressure_expand;
n=n+1 %Increasing step by 1
end
end
end
%Pressure_expand = periodicCopy(Pressure_expand,nGhosts);
Pressure =Pressure_expand;
This is the periodicCopy function used above :
function matrixOut = periodicCopy(matrixIn,nGhosts)
% Note: The very corner ghost cells are never actually used
matrixOut = matrixIn;
% Periodic copy into left ghosts
% Remember, must exclude the ghosts themselves on the right boundary
matrixOut(:,1) = matrixIn(:,end-1);
% Periodic copy into right ghosts
matrixOut(:,end) = matrixIn(:,nGhosts+1);
% Periodic copy into top ghosts
matrixOut(1,:) = matrixIn(end-1,:);
% Periodic copy into bottom ghosts
matrixOut(end,:) = matrixIn(nGhosts+1,:);

Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!