Skip to content

cangyu/CFD-Basics

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

90 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CFD Basics

Coding practice of Anderson's CFD book: Computational Fluid Dynamics: The basics with applications

Laval (Chapter7)

The Laval pipe, a classical 1D problem, based on Euler equation.

(0) Subsonic-Supersonic Isentropic Flow

MacCormack Scheme.
Usage:

  • Compile: g++ main.cc -o Laval
  • Execute: ./Laval
  • Animate: python3 animate.py

The program will produce a flowfield history file named flow.txt, and the steady-state flowfield looks like:
steady-laval

Pay attention to B.C. at both inlet and outlet!

(1) Subsonic Isentropic Flow

MacCormack Scheme.
Clearly, velocity peaks at central.
Usage:

  • Compile: g++ main.cc -o Laval
  • Execute: ./Laval
  • Animate: python3 animate.py

(2) Conservative form for Subsonic-Supersonic Isentropic Flow

MacCormack Scheme.
Usage:

  • Compile: g++ main.cc -o Laval
  • Execute: ./Laval
  • Animate: python3 animate.py

(3) Shockwave Capture

MacCormack Scheme.
Add artificial viscosity at both prediction and correction steps.
Usage:

  • Compile: g++ main.cc -o Laval
  • Execute: ./Laval
  • Animate: python3 animate.py

The program will produce a flowfield history file named flow.txt, and the steady-state flowfield looks like:
steady-shock

Couette (Chapter8)

Viscous flow between 2 parallel plate.

(0) 1D simulation

The simplified G.E. is given as:

it is similiar with unsteady heat transfer equation, which is parabolic.
Crank-Nicolson method is used, which is unconditionally stable due to its implicitness. Hence, larger time-step can be taken via tuning the parameter E.
However, errors during iteration will get larger when E is increasing due to larger truncation error.
This well illustrates that, even with implict scheme, timestep can not go to infinity!(an optimal timestep in between)

Usage:

  • Compile: g++ main.cc -o Couette
  • Execute: ./Couette
  • Animate: python3 animate.py

The program will produce a flowfield history file named flow.txt, and the steady-state flowfield(with E=1.0) looks like:

Be careful with the index inside the Thomas algorithm!

(1) 2D simulation

Pressure-Correction method in general.
Classical schemes like SIMPLE, SIMPLER and PISO are used on staggered grids.
Grid with virtual nodes is adopted as illustrated in Chapter 8.4.1.
Variable placement follows the convention introduced in Chapter 6.8.4.

Standard TECPLOT ASCII data files will be produced every time-step.

(1.1) SIMPLE

Standard SIMPLE method is used to achieve final steady-state result.
The poisson equation is solved implicitly by solving a linear system.
Convergency history:

mass flux at (15, 5) u at i=15

Values on Boundary:

- Left Inlet Right Outlet Top Lid Bottom Wall
p' zero zero zero-gradient zero-gradient
u linear extrapolation linear extrapolation Ue 0
v 0 by computation 0 0

Values on virtual nodes are mostly calculated by linear extrapolation from neighbouring nodes.

Usage:

  • Compile: g++ main.cc -std=c++14 -I /usr/include/eigen3 -o Couette
  • Execute: ./Couette
  • View full flowfield: Tecplot or ParaView or EnSight
  • Animate convergency history at (15, 5): python3 animate.py
  • Path of Eigen3 may vary in different systems or platforms, adjust it accordingly.

(1.2) SIMPLER

It is similiar with SIMPLE in general, but a better p* is provided by calculating the pressure equation in advance within each iteration loop.
Convergency history:

u at i=15 v at i=15

Usage:

  • Compile: g++ main.cc -std=c++14 -I /usr/include/eigen3 -o Couette
  • Execute: ./Couette
  • View full flowfield: Tecplot or ParaView or EnSight
  • Animate convergency history at (15, 5): python3 animate.py
  • Path of Eigen3 may vary in different systems or platforms, adjust it accordingly.

SIMPLER is much more stable than SIMPLE in terms of the divergence term.

(1.3) PISO

In my opinion, PISO corrects pressure twice, while SIMPLER predicts once and corrects once.
Convergency history:

u at i=15 v at i=15

Usage:

  • Compile: g++ main.cc -std=c++14 -I /usr/include/eigen3 -o Couette
  • Execute: ./Couette
  • View full flowfield: Tecplot or ParaView or EnSight
  • Animate convergency history at (15, 5): python3 animate.py
  • Path of Eigen3 may vary in different systems or platforms, adjust it accordingly.

Pay attention to the B.C. of the pressure correction equation!
It seems unstable in the begining, may be improved if under-relaxation is used when updating pressure.

Plate (Chapter9)

Supersonic flow over a plate.
2 different thermal B.C. are examined.

(0) Isothermal B.C.

Wall temperature is fixed.
MacCormack scheme is adopted.
The back-and-forth alternation on derivatives aims at obtaining 2nd-order accuracy.

Flowfiled at Steady-State:

Pressure at bottom:

Values at outlet:

Standard TECPLOT data file in ASCII format will be produced every 100 steps.
An aditional file history.txt will be written for animation.

Usage:

  • Compile: g++ main.cc -std=c++14 -o Plate -O3
  • Execute: ./Plate
  • View: Tecplot or ParaView or EnSight
  • Animate: python3 animate.py

Pay attention to values at boundary, remember to update them!

(1) Adiabatic B.C.

Similar to previous, only wall temperature gradient is set to 0.
This is achieved by simply setting T(i, JMIN) = T(i, JMIN+1) inside program.

Flowfiled at Steady-State:

Pressure at bottom:

Values at outlet:

Standard TECPLOT data file in ASCII format will be produced every 100 steps.
An aditional file history.txt will be written for animation.

Usage:

  • Compile: g++ main.cc -std=c++14 -o Plate -O3
  • Execute: ./Plate
  • View: Tecplot or ParaView or EnSight
  • Animate: python3 animate.py

About

Coding practice of Anderson's CFD book.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published