Sie sind auf Seite 1von 22

Navier2d Readme

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

A Quick CFD Introduction


The NS equations are complicated:
u
1
+ u u = p + 2 u + F
t

(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:

Unstructured mesh of a three-element airfoil created using mesh2d.


Navier2d is an unstructured mesh NS solver that means that triangles are used to form
the mesh. This type of mesh allows the automatic treatment of complex geometries.
CFD simulations typically involve two phases: building a mesh and then solving the NS
equations. I developed another MATLAB function mesh2d to automatically build
triangular meshes to be used with navier2d. You dont need to use mesh2d but Id be
happy if you did. It can be downloaded from the MATLAB file exchange:
http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=10307&obj
ectType=FILE

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.

Step 2 Integration Settings:


The settings used by the solver must be specified. The popup menu within the
Integration Settings frame selects the solver to be used. At the moment navier2d
includes three options:
1. Normal solves the NS equations for the velocity and pressure fields.
2. Tracer as above, but also solves an additional transport equation for a scalar
quantity within the flow (like a dye).
3. Thermal as above, but treats the scalar tracer field as the temperature of the
fluid and includes buoyancy terms in the momentum equations. This allows
the solution of coupled thermal problems (like thermal convection).
At the moment we only care about the first option Normal, so leave the menu at that
setting.
Clicking Initial will open a new window asking for the initial conditions for the [x,y]
velocity fields and the tracer field. Because we are not using the Tracer or Thermal
solver it doesnt matter what we set for S, but for [U,V] we can use the default setting of
zero.

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:

A couple of things to note:


1. The CFL number is related to the time-step size. Usually in CFD the time-step
size is restricted by the stability of the integration NOT the accuracy. Setting
CFL=1 will ensure that the integration is stable and happy. Smaller CFL
corresponds to smaller time-step sizes. The program can also limit the step
size based on viscous effects. If you want to know more about this kind of
thing email me
2. There is no box for density! I decided to absorb the density into the pressure
(to simplify the code). This means that the viscosity specified is the
KINEMATIC viscosity. Just to make sure that we are all talking the same
language the equations below are exactly the way that they are solved in
navier2d:

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.

Max steps = 2000


Max time = 45
CFL number = 1.25
Viscosity = 0.001
Everything else as is

Step 3 Boundary Conditions:


The boundary conditions for the flow must be specified. Clicking the Velocity/Pressure
button in the Boundary Conditions frame will open a new window showing the
boundary edges in the mesh:

It is required to specify a boundary condition at all of the nodes shown.

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:

Step 4 Animation Settings:


The last (optional) thing that is needed is to specify the animation settings. The program
will automatically animate a [U,V] quiver plot of the velocity field and a logarithmic plot
of the [x,y] residuals.
Two additional flow variables can also be displayed using a couple of different
visualizations. Click Set in the Animation Settings frame and select U velocity and
Pressure. Also choose 3D View in the popup menu.
Step 5 Go!!
Click Run and wait about 60 seconds (depending on your computer if you have a
Mac expect to wait about 4 times as long due to the lack of mex). You should get to the
following velocity field:

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:

Temperature field created by thermal convection around a heated pipe.

12

Flow Over a Cylinder


Ok, so a more interesting flow is the unsteady, vortex-shedding wake behind an
immersed cylinder. This sort of thing happens all the time in real-life situations and the
ability to predict quantities like the shedding frequency and lift/drag forces is important
from an engineering point-of-view.
Load the mesh file cylinder.mat
Set the boundary conditions. The easy BCs are the no-slip condition on the cylinder,
[U,V] = [0,0], and the velocity inlet condition, [U,V] = [1,0]. At this stage the BCs
should look like this:

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

domain. I say attempt because in reality a substantial amount of reflection is produced


by numerical outflow conditions and this is one area that people are actively trying to
improve in CFD.
Navier2d supports two types of outflow conditions. Both are created by treating the
pressure as the known variable. The first type tries to extrapolate the boundary values of
the pressure from the interior nodes while the second just fixes the value of the pressure
at the outflow to zero. Type 1 is the best choice and usually makes a reasonable attempt
at allowing pressure waves to pass through the boundary. I have noticed that type 1 can
be susceptible to instabilities, especially if discontinuous initial conditions are used.
I always try to use type 1 outflows, but if I need to specify discontinuous ICs I have
found that doing 100 steps with a type 2 outflow and then switching over to a type 1 for
the subsequent simulation works well enough.
Ok, enough about that, I hope it wasnt too confusing. Set all of the nodes on the right
wall to type 1 outflow. The full BCs should look like this:

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

These results can be used to predict a non-dimensional vortex shedding frequency,


known as the Strouhal number:
St =

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

So for our case with unit diameter and inlet velocity:


Cd = 2*drag = 1.38
This compares well with values obtained using the commercial package FLUENT [3] of
1.33 and the experimental value of 1.5 [4]. I have done a quick study of the variation of
Cd with Reynolds number and it seems to work:

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

This is important enough to get its own sub-heading


For large problems (200,000 triangles) you can start to run both MATLAB and your
computer out of memory. At the moment, most versions of Windows/MATLAB impose a
1.2GB page file limit. You should be able to run the program with meshes of about
300,000 triangles without exceeding this. Another consideration is the amount of physical
RAM your computer has. If your PF use exceeds the RAM size you will be using
virtual memory. This is bad. It will cause the CPU load to drop to about 5% as your
computer will spend most of its time trying to access your virtual memory addresses on
the hard drive.
I have a couple of ideas about these issues, but Im not sure if people are going to use big
meshes like this. If you are, can you contact me!!

20

Notes on the Algorithm


Ok, so if youve read this far youre doing well. Im sure that I would have been bored
ages ago. The following is a brief description of the numerical method used in navier2d.
Navier2d is a vertex centred Finite Volume (FV) code that uses the median dual mesh to
form the Control Volumes (CVs) about each vertex. Connecting the centroids of each
cell to their edge midpoints forms the median dual mesh and there have been various
reports in the literature likening this sort of FV scheme to a Galerkin FEM method.
The time and spatial linearisations are dealt with separately. Fully 2nd order piecewiselinear reconstructions are used to develop sparse operators, which approximate the
continuous differential terms. These methods are used by various authors [5] and can be
summarized:
1. Divergence/gradient: Green's theorem.
2. Laplacian: Green's theorem applied to face averaged gradients (unweighted
least squares).
3. Non-linear: Upwind piece-wise linear extrapolation with the HQUICK slope
limiter [6,15].
I have verified the 2nd order convergence by running the driven cavity problem for a
variety of meshes and measuring the slope of the error variation against the number of
mesh nodes.
The time integration of the equations is based on the well-known fractional step method
[7,8,9]. The non-staggered pressure/velocity arrangement was shown to support the
common mesh scale pressure oscillation and hence the standard 2nd order incremental
pressure correction method [10,11] was modified to incorporate Rhie-Chow Stabilization
[12]. This reduced the order of the time integration to 1st/2nd.
Unlike many other Navier-Stokes solvers this function makes use of a complete LU
factorisation for the Poisson pressure equation. Using the fill reducing UMFPACK
algorithm [13] this approach was shown to be far more efficient than standard iterative
approaches (like preconditioned BiCGSTAB), although this could well be limited to
MATLAB implementations and non-moving meshes.
The momentum equations are solved in a semi-implicit manner. The non-linear terms are
evaluated explicitly via a 2nd order TVD Runge-Kutta method [14]. The BiCGSTAB
method is used to solve the linear systems that arise due to the implicit treatment of the
viscous terms, which is similar to the Crank-Nicholson method.
If anyone is really dying to know more about the numerical method then please contact
me, although most of my working is on paper. I guess if someone asked really nicely I
could write an electronic version

21

References
[1]

E. Erturk1, T.C. Corke2 and C. Gkl1, Numerical Solutions of 2-D Steady


Incompressible Driven Cavity Flow at High Reynolds Numbers. International
Journal for Numerical Methods in Fluids (2005)

[2]

C. Williamson, Oblique and parallel modes of vortex shedding in the wake of


circular cylinder at low Reynolds numbers, Journal of Fluid Mechanics, 206:579,
1989.

[3]

A. Kulkarni, S. Moeykens. Flow Over a Cylinder, FLUENT tech report, 2005.

[4]

J. Anderson, Fundamentals of Aerodynamics, 2nd Ed., Chapter 3.

[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]

F. Harlow, E. Welch, Numerical calculation of time-dependent viscous


incompressible flow of fluid with free surface. Physics of Fluids, 1965; 8:21822189.

[8]

A. Chorin, Numerical Solution of the Navier-Stokes Equations. Math. Comput.


1968; 22:745-762.

[9]

J. Kim, P. Moin, Application of a fractional step method to the incompressible


Navier-Stokes Equations. J. Comp. Physics, 1985; 59:308-323.

[10]

S. Armfield, R. Street, Modified Fractional Step Methods for the Navier-Stokes


Equations. ANZIAM J. Volume 45(E), pp. 364-377, 2004.

[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]

Ch-Wang Shu, Total variation diminishing time discretisations, SIAM J. Sc.


Staist. Comput. 9 (1988), no. 6, 1073-1084.

22

Das könnte Ihnen auch gefallen