Coding practice of Anderson's CFD book: Computational Fluid Dynamics: The basics with applications
The Laval pipe, a classical 1D problem, based on Euler equation.
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:
Pay attention to B.C. at both inlet and outlet!
MacCormack Scheme.
Clearly, velocity peaks at central.
Usage:
- Compile:
g++ main.cc -o Laval
- Execute:
./Laval
- Animate:
python3 animate.py
MacCormack Scheme.
Usage:
- Compile:
g++ main.cc -o Laval
- Execute:
./Laval
- Animate:
python3 animate.py
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:
Viscous flow between 2 parallel plate.
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!
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.
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
orParaView
orEnSight
- Animate convergency history at (15, 5):
python3 animate.py
- Path of
Eigen3
may vary in different systems or platforms, adjust it accordingly.
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
orParaView
orEnSight
- 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.
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
orParaView
orEnSight
- 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.
Supersonic flow over a plate.
2 different thermal B.C. are examined.
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
orParaView
orEnSight
- Animate:
python3 animate.py
Pay attention to values at boundary, remember to update them!
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
orParaView
orEnSight
- Animate:
python3 animate.py