2d cfd code based on matlab- as good as fluent!
DESCRIPTION
Developed while doing my Ph.D. on CFD at Texas Tech. As good as FLUENT-2D.TRANSCRIPT
![Page 1: 2D CFD Code Based on MATLAB- As Good As FLUENT!](https://reader033.vdocuments.us/reader033/viewer/2022061405/556dc754d8b42a78768b4605/html5/thumbnails/1.jpg)
An Introduction to My CFD Code (2D Version)
Jiannan(Jay) Tan
![Page 2: 2D CFD Code Based on MATLAB- As Good As FLUENT!](https://reader033.vdocuments.us/reader033/viewer/2022061405/556dc754d8b42a78768b4605/html5/thumbnails/2.jpg)
Highlights• 1. Based on MATLAB.• 2. Aiming on 2D, Steady, Laminar, viscous flow.• 3. Using unstructured, arbitrary-shape,
collocated grids.• 4. Navier-Stokes equations are solved and
velocity and pressure are calculated.• 5. Results are compared with those results
from FLUENT.• 6. A few benchmarking cases are tested.
![Page 3: 2D CFD Code Based on MATLAB- As Good As FLUENT!](https://reader033.vdocuments.us/reader033/viewer/2022061405/556dc754d8b42a78768b4605/html5/thumbnails/3.jpg)
How does the code work
2D Code
Part 1: Mesh reader Part 2: N-S Equation Solver
Files in certain format that contains the mesh information. For example, the FLUENT *.msh file.
Velocity filed U, V and Pressure P.
Part 3: Post-processing sub-programs
Visualized vector plots and contours.
![Page 4: 2D CFD Code Based on MATLAB- As Good As FLUENT!](https://reader033.vdocuments.us/reader033/viewer/2022061405/556dc754d8b42a78768b4605/html5/thumbnails/4.jpg)
The Data structure of Mesh
U,V,P
B(xb, yb)
A(xa, ya)
C(xc, yc)
4.Face normal
Cell ID = P
1. Point ID (x, y)2. Face ID (A, B, P, nb, property )3. Cell ID (3, face1, face2, face3)
3 elemental data groups which decide the whole mesh:
1.Flow flux
3.Face area
6.Volume
7.Presssure gradient
2.Face velocity components
5.Face velocity components’ gradient
7 important variables:
![Page 5: 2D CFD Code Based on MATLAB- As Good As FLUENT!](https://reader033.vdocuments.us/reader033/viewer/2022061405/556dc754d8b42a78768b4605/html5/thumbnails/5.jpg)
The N-S Euqation Solver
( ) ( ( ))U Pt
��������������
( ) 0U ��������������
Momentum equation:
Continuity equation:
1. Discretization: Gauss Theorem
2. Face Mass Flux and Face Scalar
3. SIMPLE Method
4. Least Square Method
5. Pressure-Correction Equation
6. Convergence Criteria
Steady flow
![Page 6: 2D CFD Code Based on MATLAB- As Good As FLUENT!](https://reader033.vdocuments.us/reader033/viewer/2022061405/556dc754d8b42a78768b4605/html5/thumbnails/6.jpg)
Methodology-SIMPLE MethodInitial guess of u, v and p
Solving the dicretized momentum equations and get interim velocity u, v
Calculating the face mass flux using momentum interpolation method
Solving the discretized continuity equation and geting the pressure
correction p’
Correcting the cell-central pressure and velocity
Convergence reached?
Post-processing
Resuming iteration with
new u, v and p
![Page 7: 2D CFD Code Based on MATLAB- As Good As FLUENT!](https://reader033.vdocuments.us/reader033/viewer/2022061405/556dc754d8b42a78768b4605/html5/thumbnails/7.jpg)
Discretizing Momentum Equations Using Gauss Theorem
ˆ ˆ( ) ( ( ))U n ds n ds P V ��������������
( ) ( ( ))U dv dv P dv ��������������( ) ( ( ))U P
��������������
. .
( ) [ ( ) ]n d E P Crossnb face nb face
F D D P V 1
.
( ) [ ] ( )n n np p e e p
nb face
a a S P V
Interim velocity u, v
MIM
![Page 8: 2D CFD Code Based on MATLAB- As Good As FLUENT!](https://reader033.vdocuments.us/reader033/viewer/2022061405/556dc754d8b42a78768b4605/html5/thumbnails/8.jpg)
Pressure-Correcton Equation
.
.
( ) ( ) ( ) ( )
( ) ( ) ( ) ( )
up e e nb nb e u e P E e
nb face
vp e e nb nb e v e P E e
nb face
a u a u S P P y
a v a v S P P x
.
.
( ) ( )
( )( ) ( )
( ) ( )
( )( ) ( )
nb nb e u enb face e
e P Eu up e p e
nb nb e v enb face e
e P Ev vp e p e
a u Sy
u P Pa a
a v Sx
v P Pa a
' ' '
' ' '
( )( )
( )( )
ee P E u
p e
ee P e v
p e
yu P P
a
xv P P
a
* * ' '
1
[( ) ( ) ( ) ( ) ] 0Nb
e e e ee
u y v x u y v x
Continuity Equation, assume u=u’+u*
2 2' ' ' '
1
[( )( ) ( ) ( ) ] 0Nb
P E e eu ve P P
y xP P u y v x
a a
' '
1
( ) . . . . .Nb
P P E Ee
a P a P Mass imbalance in to cell P
![Page 9: 2D CFD Code Based on MATLAB- As Good As FLUENT!](https://reader033.vdocuments.us/reader033/viewer/2022061405/556dc754d8b42a78768b4605/html5/thumbnails/9.jpg)
Momentum Interpolation Method
1. Used after interim velocity is achieved after solving momentum equations.
2. Applied in order to eliminate oscillating pressure field. Sometimes called ‘pressure smooth term’.
3. Used to calculate mass imbalance into each cell in this code.
![Page 10: 2D CFD Code Based on MATLAB- As Good As FLUENT!](https://reader033.vdocuments.us/reader033/viewer/2022061405/556dc754d8b42a78768b4605/html5/thumbnails/10.jpg)
Least Square Method
![Page 11: 2D CFD Code Based on MATLAB- As Good As FLUENT!](https://reader033.vdocuments.us/reader033/viewer/2022061405/556dc754d8b42a78768b4605/html5/thumbnails/11.jpg)
Backup slide: A failed try using LSM
![Page 12: 2D CFD Code Based on MATLAB- As Good As FLUENT!](https://reader033.vdocuments.us/reader033/viewer/2022061405/556dc754d8b42a78768b4605/html5/thumbnails/12.jpg)
Covergence Criteria
• The ratio of Maximum imbalance rate into a single cell over the inlet mass flow rate
![Page 13: 2D CFD Code Based on MATLAB- As Good As FLUENT!](https://reader033.vdocuments.us/reader033/viewer/2022061405/556dc754d8b42a78768b4605/html5/thumbnails/13.jpg)
Validation & Verification
1. Straight pipe flow
2. Jet flow
3. Flow around a cube
4. Z-pipe flow
![Page 14: 2D CFD Code Based on MATLAB- As Good As FLUENT!](https://reader033.vdocuments.us/reader033/viewer/2022061405/556dc754d8b42a78768b4605/html5/thumbnails/14.jpg)
Test Case 1: Flow in a straight channel
![Page 15: 2D CFD Code Based on MATLAB- As Good As FLUENT!](https://reader033.vdocuments.us/reader033/viewer/2022061405/556dc754d8b42a78768b4605/html5/thumbnails/15.jpg)
Case 1: FLUENT solution
U(max)=1.47
![Page 16: 2D CFD Code Based on MATLAB- As Good As FLUENT!](https://reader033.vdocuments.us/reader033/viewer/2022061405/556dc754d8b42a78768b4605/html5/thumbnails/16.jpg)
Test Case 1: Flow in a straight channel
U(max)=1.46
![Page 17: 2D CFD Code Based on MATLAB- As Good As FLUENT!](https://reader033.vdocuments.us/reader033/viewer/2022061405/556dc754d8b42a78768b4605/html5/thumbnails/17.jpg)
Test Case 2: Sudden Expansion-Jet Flow
![Page 18: 2D CFD Code Based on MATLAB- As Good As FLUENT!](https://reader033.vdocuments.us/reader033/viewer/2022061405/556dc754d8b42a78768b4605/html5/thumbnails/18.jpg)
Case 2: FLUENT solution: Velocity vector
U(max)=1.33
![Page 19: 2D CFD Code Based on MATLAB- As Good As FLUENT!](https://reader033.vdocuments.us/reader033/viewer/2022061405/556dc754d8b42a78768b4605/html5/thumbnails/19.jpg)
Case 2: FLUENT solution: Vortex pattern
![Page 20: 2D CFD Code Based on MATLAB- As Good As FLUENT!](https://reader033.vdocuments.us/reader033/viewer/2022061405/556dc754d8b42a78768b4605/html5/thumbnails/20.jpg)
Test Case 2: My code solution
U(max)=1.34
![Page 21: 2D CFD Code Based on MATLAB- As Good As FLUENT!](https://reader033.vdocuments.us/reader033/viewer/2022061405/556dc754d8b42a78768b4605/html5/thumbnails/21.jpg)
Case 2: Comparison of vortex length
![Page 22: 2D CFD Code Based on MATLAB- As Good As FLUENT!](https://reader033.vdocuments.us/reader033/viewer/2022061405/556dc754d8b42a78768b4605/html5/thumbnails/22.jpg)
Test case 3: Flow in a Z-pipe
![Page 23: 2D CFD Code Based on MATLAB- As Good As FLUENT!](https://reader033.vdocuments.us/reader033/viewer/2022061405/556dc754d8b42a78768b4605/html5/thumbnails/23.jpg)
Case 3: FLUENT solution: Velocity vector
U(max)=1.44
![Page 24: 2D CFD Code Based on MATLAB- As Good As FLUENT!](https://reader033.vdocuments.us/reader033/viewer/2022061405/556dc754d8b42a78768b4605/html5/thumbnails/24.jpg)
Case 3: FLUENT solution: Vortex pattern
![Page 25: 2D CFD Code Based on MATLAB- As Good As FLUENT!](https://reader033.vdocuments.us/reader033/viewer/2022061405/556dc754d8b42a78768b4605/html5/thumbnails/25.jpg)
Test case 3: My code solution
U(max)=1.44
![Page 26: 2D CFD Code Based on MATLAB- As Good As FLUENT!](https://reader033.vdocuments.us/reader033/viewer/2022061405/556dc754d8b42a78768b4605/html5/thumbnails/26.jpg)
Case 3: Comparison of vortex length
![Page 27: 2D CFD Code Based on MATLAB- As Good As FLUENT!](https://reader033.vdocuments.us/reader033/viewer/2022061405/556dc754d8b42a78768b4605/html5/thumbnails/27.jpg)
Test case 4: Flow past a square cylinder
![Page 28: 2D CFD Code Based on MATLAB- As Good As FLUENT!](https://reader033.vdocuments.us/reader033/viewer/2022061405/556dc754d8b42a78768b4605/html5/thumbnails/28.jpg)
Case 4: FLUENT solution: Velocity vector
U(max)=1.43
![Page 29: 2D CFD Code Based on MATLAB- As Good As FLUENT!](https://reader033.vdocuments.us/reader033/viewer/2022061405/556dc754d8b42a78768b4605/html5/thumbnails/29.jpg)
Case 4: FLUENT solution: Vortex pattern
![Page 30: 2D CFD Code Based on MATLAB- As Good As FLUENT!](https://reader033.vdocuments.us/reader033/viewer/2022061405/556dc754d8b42a78768b4605/html5/thumbnails/30.jpg)
Test case 4: My code solution
U(max)=1.41
![Page 31: 2D CFD Code Based on MATLAB- As Good As FLUENT!](https://reader033.vdocuments.us/reader033/viewer/2022061405/556dc754d8b42a78768b4605/html5/thumbnails/31.jpg)
Case 4: Comparison of vortex length
![Page 32: 2D CFD Code Based on MATLAB- As Good As FLUENT!](https://reader033.vdocuments.us/reader033/viewer/2022061405/556dc754d8b42a78768b4605/html5/thumbnails/32.jpg)
Case 4: Comparison of Cd
FLUENT My Code
Pressure Force 1.275 1.299
Viscous Force 0.601 0.541
Total Force 1.876 1.840
Cd 3.752 3.680
Density =1, viscosity =0.05, Frontal area =1, U=1
![Page 33: 2D CFD Code Based on MATLAB- As Good As FLUENT!](https://reader033.vdocuments.us/reader033/viewer/2022061405/556dc754d8b42a78768b4605/html5/thumbnails/33.jpg)
Backup slide: Case 4 FLUENT report
![Page 34: 2D CFD Code Based on MATLAB- As Good As FLUENT!](https://reader033.vdocuments.us/reader033/viewer/2022061405/556dc754d8b42a78768b4605/html5/thumbnails/34.jpg)
Futher Development• 1. Optimization• 2. Different methods to dicretized the momentum euqation.• 3. Different methods to calculate the pressure gradient.• 4. Different methods to do the iteration.• 5. Parallel computation.• 6. Mesh generator.• 7. More advanced models.• 8. Advanced post-processor.• 9. Commercialize the code, sell it to MATLAB :-D