Readme PDF
Readme PDF
Readme PDF
Overview
Navier2d is a set of MATLAB functions designed to simulate the motion of
incompressible fluids via numerical solutions of the 2D, unsteady Navier-Stokes (NS)
equations.
The following document includes some introductory tutorials describing the use of
navier2d, followed by a general description of the algorithm. It is not intended to give a
general introduction in Computational Fluid Dynamics (CFD).
All code was written in MATLAB R13. I hope they work for earlier (and later) versions,
but I havent checked.
CFD simulations typically ask a lot of the available computer resources. Many simulators
are run on massively parallel super-computers so if youre under the impression that a
solution will be churned out in 5 or 10 seconds you may want to think again! I have tried
to make the code as fast as possible (for MATLAB) and all of the examples described
below can be completed in under 5 minutes on reasonable computers.
I wrote most of this for my undergraduate thesis in 2005 and Im making it available in
the hope that it will be useful. I dont pretend to be an expert.
If you use this software or have any comments or problems, I would like to get some
feedback:
d_engwirda@hotmail.com
(1)
u = 0
In general its too hard to solve these equations analytically so numerical approximations
are used and result in a process known as CFD. Most CFD programs (Navier2d included)
start off with a mesh of the flow domain:
Using Navier2d
Hopefully the zip file should contain separate windows and not windows folders.
The windows version makes use of some C mex files to replace inbuilt functionality in
MATLAB and results in a huge saving in CPU time. If you have a Mac and the
MATLAB compiler you can recompile my mex files and then use the windows version.
Typing navier2d at the command line in MATLAB starts the program. This should
display the following GUI:
Simulations are setup by accessing each of the four frames in this window and then
clicking Run.
A Simple Example
Hopefully, the use of navier2d will be illustrated in the following example, which
simulates the classic driven cavity flow.
Step1 - Load the mesh:
Click Load in the top left frame and select square.mat. You can use View and
Median to view the mesh.
Clicking the Set button will open a new window asking for a number of things either
relating to the solver or the material properties of the fluid. Most of these quantities
should be fairly self-explanatory. Some relate to the Thermal solver, but these can be
ignored unless that solver option is selected:
u
+ u u = p Navier 2 d + 2 u + T
t
u = 0
(2)
T
+ u T = 2T
t
Ok, hopefully that wasnt too confusing. For this simulation we want to set:
1.
2.
3.
4.
5.
Clicking the Select button will enable a mouse-driven select tool, which allows you to
select nodes interactively from the display. Maybe try having a play around with this to
see how to select/de-select multiple nodes. The Clear button can be used to de-select
everything.
For this problem first select all of the edges (they should all turn red). Clicking the Set
button then opens a new window allowing the BC type to be selected:
At the moment navier2d supports three BC types: known velocities and two outflow
types. For this problem we know the velocity on all the walls so select Velocity. This
should open another window asking for the combination of velocity types:
This window allows you to select between value and gradient types. Gradient types
ca be useful when imposing symmetry planes but we will get to that later. For this
problem select U and V. This should open yet another window asking for the values:
For the left, bottom and right walls we want the velocity to be zero (no-slip walls) so
click ok. Now go back and select all the edges along the top wall, go back through the
selections but specify a U value of 1m/s. This corresponds to a top wall sliding from left
to right. The final BCs should look like this:
Now that the simulation is finished you can access the main navier2d window and save
the data. Click Save and choose an appropriate filename, I use cavity1000 (because
the Reynolds number is 1000).
This data can now be manipulated in the future. As an example type load cavity1000 in
the command window in MATLAB. Then type cavity_benchmark(p,U,V,1). This is a
simple benchmarking function that I created to assess the accuracy of navier2d for this
problem. You should see the following:
The values 0.0155 and 0.0114 should be printed in the main window. This means that
there is 1.55% and 1.14% error in the [U,V] velocity fields between the navier2d results
and some benchmark results from the literature [1]. The mesh used in this example has
10
2113 nodes while the benchmark results were calculated using a 360,000 node mesh, so I
think 1% error is ok
NOTE: After a simulation has been run the flow variables are passed back to the GUI and
are used as the initial conditions unless re-initialised. This allows you to keep going from
where you left off.
A Thermal Example
While the cavity mesh is loaded a simple thermal convection problem can also be setup.
Select the Thermal solver.
Initilise all variables to zero.
Set the viscosity (Tracer) to 0.001. (Kappa in (2))
Set the velocity BCs along the top wall to zero. This means that all walls should have
[U,V] = [0,0].
Following a similar process as the Velocity/Pressure BCs, set BCs for the Tracer
(temperature). Place a dT/dn = 0 condition on the top and bottom walls in addition to T=1
on the left wall and T=-1 on the right wall.
Select the Tracer from the animation settings menu with a 3D mesh view.
Click Run. You should get the following velocity field:
11
At this stage I havent done any quantitative comparisons with benchmark results, but the
flow looks reasonable with fluid moving up the hot wall and down the cold wall. The
shape of the velocity contours also look similar to those (that I have seen) in the
literature.
If anyone was feeling particularly helpful and wanted to do a quantitative analysis of this
sort of flow using navier2d, could you contact me?
As you may guess the thermal solver is very new and not thoroughly tested, so if you
pick up any problems please let me know!! Ive also used the thermal solver to simulate
the unsteady thermal plume that is created from an immersed, heated object (like a hot
pipe in this case). Maybe this will give people some ideas, but its a cute picture
otherwise:
12
A number of possibilities exist for the BCs on the top and bottom walls. Derivative BCs
can be used to give an approximately stress free condition on these walls. Select all of
the nodes on these edges and set dU/dn=0 and V=0.
Outflow BCs should be used on the right wall. Outflow BCs attempt to allow fluid to
leave the domain in a continuous fashion, i.e. without causing any reflection back into the
13
14
Select the Normal solver and set the initial conditions [U,V] = [1,0]. Set the following
integration settings:
1. Max steps: 2500
2. Viscosity: 0.0067
3. Everything else as default
Select a 2D contour view of the vorticity.
Click Run and over the course of ~250 seconds you should see an oscillatory vortexshedding wake develop. The vorticity should look like this:
While this is a nice picture, the real point of CFD analysis is to try to characterise the
physics of the flow. Navier2d includes a module that will calculate the [x,y] forces
applied to a boundary due to pressure and skin friction effects and can be used in this
example to calculate the lift and drag forces on the cylinder in addition to the frequency
of the vortex shedding.
Re-initialise the flow with [U,V] = [1,0].
Click the Monitors button the animation frame and select [x,y] forces. This will open a
new window showing the boundary edges. Select the nodes on the cylinder surface:
15
Click Mark and these nodes should turn blue and means that the total [x,y] forces for
this boundary will be plotted in the [x,y] residual window.
Click Run and run the simulation. Save the flow when finished as cylinder150 (again
the Reynolds number is 150). Type load cylinder150 in the MATLAB command
window and then plot the [x,y] forces over time using the following:
figure
plot(time(10:end),-resx(10:end),'b', time(10:end),resy(10:end),'r')
Hopefully you should see this:
16
fD
U
You can make this as complex as you like. Some people like to try to take FFTs and get
dominant frequencies. I just zoom in on the plot and measure the time elapsed over the
last 5 cycles (in the drag force):
f = 0.5*(5-1)/(92.11-81.375) = 0.1863.
Since we have used unit diameter and inlet velocity this is equal to St. This compares
well with the experimental value of 0.184 obtained by Williamson [2].
Another important quantity is the mean drag coefficient obtained at fully developed flow.
Again by looking at the plots we can see that the flow is fairly well developed for
time>75sec, so take the mean drag force after this point:
drag = mean(-resx(time>75)) = 0.6908
The drag coefficient is given by the non-dimensional equation:
17
Cd =
2 * drag
U 2 D
This brings up a slightly subtle point with navier2d i.e. the density was never specified
but simply absorbed into the pressure:
p navier 2 d =
p real
This is ok, because since the modified pressure was used to calculate drag we have
actually already divided through by rho:
drag navier 2 d =
drag real
This means that in navier2d, the non-dimensional equation for the drag coefficient is
actually (and for the lift coefficent):
Cd =
2 * drag
U 2D
18
The force calculation is another relatively new module so again if any problems are
encountered please contact me. Coefficient calculations at higher Reynolds numbers are
probably going to need some kind of turbulence model (which I dont have yet).
Other Features
You can actually specify spatially varying initial conditions. This is done using eval in
MATALAB so only functions of x and y are allowed:
19
By doing some mathematics, it should be possible to specify some vortex ICs, like if
you wanted to study the decay of an elliptical vortex or something
Limitations
Hopefully navier2d should always complete a simulation. Whether that simulation has
any relevance to reality is another thing entirely
The mesh is of critical importance. If insufficient resolution is used the results will be
incorrect, guaranteed. The mesh should also consist of high quality elements which
means that the triangles should be as close to equilateral as possible. Mesh2d was written
to try to optimize this mesh quality.
For complex flows at high Reynolds numbers the size of the mesh can become huge
(25,000 triangles and up). Problems of this size will start to take a long time to solve.
People get around this by using supercomputers and parallel clusters but at this stage
navier2d is for scalar machines only.
Only the incompressible equations are solved, so the flow speed has to be sufficiently
low (M<0.3).
At this stage no turbulence model is implemented. At high Reynolds numbers this
becomes very important, because it is necessary to account for sub-grid scale effects.
There are heaps of turbulence models out there, but it seems (to me at least) that each are
severely limited in their own way. LES (Large Eddy Simulation) is one option that looks
good, but it also looks fairly complicated I would like to hear from you if you have any
ideas about appropriate turbulence models, or whether you even care if I have one!!
Memory
20
21
References
[1]
[2]
[3]
[4]
[5]
D. Kim and H. Choi, A second-order time accurate finite volume method for
unsteady incompressible flow on hybrid unstructured grids, Journal of
Computational Physics, 162:411-428, 2000.
[6]
http://www.simuserve.com/phoenics/d_polis/d_enc/enc_schm.htm
[7]
[8]
[9]
[10]
[11]
S. Armfield, R. Street, The Pressure Accuracy of Fractional Step Methods for the
Navier-Stoke Equations on Staggered Grids. ANZIAM J. Volume 44(E), pp. 2039, 2003.
[12]
C. Rhie and W. Chow, Numerical Study of the turbulent flow past and airfoil with
trailing edge separation, AIAA Journal, 21(11):1525-1532, 1983.
[13]
http://www.cise.ufl.edu/~davis/
[14]
22