File Exchange

## MATLAB code to solve the Channel Flow Problem

version 1.0.0 (29.6 KB) by
Matlab code to solve the 2D steady state incompressible NavierStokes equations using SIMPLE algorithm for a Channel

Updated 14 Apr 2020

This is a MATLAB code that uses Finite Volume Method to discretize the channel flow domain to solve the continuity and the X,Y momentum equations using the Semi-Implicit Method for Pressure Linked Equation (SIMPLE). U,V velocities are declared and solved along the staggered mesh while the pressure uses the normal mesh generated after discretization. The upwind differencing scheme of interpolation is used for obtaining the face velocities at the staggered mesh faces. In addition the same code has certain lines commented out that can be un-commented to introduce a block or an obstacle in the centre of the pipe and obtain the corresponding contours. Pressure correction equations are overrelaxed. X,Y momentum under relaxed. After velocity update mass imbalance monitor is displayed to see it die out and satisfy mass conservation. Post-processing is done using contourf and quiver functions

### Cite As

R Surya Narayan (2020). MATLAB code to solve the Channel Flow Problem (https://www.mathworks.com/matlabcentral/fileexchange/75000-matlab-code-to-solve-the-channel-flow-problem), MATLAB Central File Exchange. Retrieved .

Jaki moran

thanks .i have some issue with your code.
why do you recorect the boundary in post process and in this case the averaging in velocity and pressure .can we use abtained velocity and pressure in resultand without recorecting as you do

Dongjun Lee

Perfect work.

can i ask you that it can be applicable to VOF model?

R Surya Narayan

@vaibhav khanna
Thanks for pointing out. In this case I have neglected it intentionally as all of them are equal and the net equates to zero. Nonetheless, your are right . I shall add the extra terms

Vaibhav Khanna

I found an issue with your discretization scheme. You have written ap = aw+an+as+ae but it should also have the mass fluxes terms that go ap term while applying the upwind discretization. Shouldn't it be ap = aw+an+as+ae+Fn-Fs+Fe-Fw where Fe,Fs,Fn, Fw are the convective terms in the discretization

R Surya Narayan

Yes. There are ghost cells for the boundaries.

ahmed gamal

Great, so according to your "%% POST PROCESSING AND DISPLAY PLOTS" section, the east and west boundaries are holding the faces of the boundary cells for pressure, as a result, the u velocities are defined over there, while the v velocities and the pressure have extra cells at these positions as Ghost cells. By the same way, the v velocities are defined on the upper and lower boundaries, while the u velocities and the pressure have extra cells at these positions as Ghost cells. Am i right??

R Surya Narayan

Regarding the boundaries, yes the velocities are attached to the boundaries.

ahmed gamal

yeah, i know it is a staggered grid, what i asked about was if the faces of the boundary cells of the scalar quantities were located outside the domain or they were attached to the boundaries of the physical domain!!
Also, the code takes much time to calculate the variables of the domain. I suggest if u wanted to use "for loops" to calculate variables through the equation, it would be better to insert the coefficients of the variable into the loops which calculates these variables, instead of using 6 for loops to calculate them outside the inner iterations, it should reduce the time of calculation of ur code.
However, it is quite better if u used them in a matrix form, specially for the pressure Poisson's equation.

R Surya Narayan

It's a staggered grid arrangement with the velocities at the center of cell faces and the pressures computed at the center of the cells. So the velocities can be thought of at the center of the cell faces of another grid that's staggered from the original grid by one-half cell distance.
The quiver plot however requires that you specify values at the cell corners (of the main grid). So the last few steps I basically try to interpolate to the corners.

ahmed gamal

im just wondering about the grid which u were using. Can u explain it more, please?

##### MATLAB Release Compatibility
Created with R2020a
Compatible with any release
##### Platform Compatibility
Windows macOS Linux