Escolar Documentos
Profissional Documentos
Cultura Documentos
AME 535a
Fall 2012
Contents
Problem definition
Mesh and Time Step definition
Method of Solution
Results and Plots
Discussion of results
Some additional plots
Scope for further work
Listing of the code and a description of the various subroutines used.
Problem Definition:
This project report details a numerical solution method to a steady, viscous entrance flow into a twodimensional plane channel. The channel walls are separated by a constant distance, 2h. The flow enters at
(x=0), with a uniform velocity (u0=1). The two-dimensional Navier-Stokes equations form the basis for
the solution, which are represented as follows in Cartesian coordinates:
The non-dimensional versions of the two equations are calculated and used in further analysis. The
simplifications of these equations leading to the specific form in which they are implemented in the
project are presented separately in hand-written form and attached to this project report.
As such, a constant mean pressure gradient is assumed. The value of this constant is found out to be equal
to (3/Re) i.e.
||
The equations in their final form as they are implemented in the problem are in the following form:
And a similar equation for the v-velocity component can be written as:
For such a flow, an analytical flow can be obtained for the steady state flow at the exit of the channel.
This solution has the following form:
The vertical profile of the horizontal velocity, u, hence looks like a parabola with the peak value being at
1.5 in our case. The numerically obtained solutions have been compared to this analytical solution in
order to test the accuracy of the numerical schemes employed.
The exact solution at the outflow is depicted in the plot below, which shows the vertical velocity profile
of the streamwise velocity component:
Mesh Definition:
The mesh is constructed such that there are nx points in the x-direction and ny points in the y-direction.
The nodal points are numbered starting from 1 in either direction. The nodal points form a grid and the
flow quantities are calculated at each of these grid points.
The distance between any two neighboring nodal points in the x-direction is defined by the quantity x,
and the distance between any two neighboring points in the y-direction is defined by the quantity y. The
distance between the points does not vary from one pair of neighboring points to the other in any given
direction. Hence, the grid is uniform in the x-direction and uniform in the y-direction. However, the
number of points nx can vary from the number of points ny in the y-direction. This difference is
especially protracted in the case of the particular problem being examined in this report. This is due to the
fact that the height of the channel is always fixed, with the y-coordinate going from y=-1 to y=1. The
length of the channel, xmax, however can be varied until convergence is achieved for a particular value of
Reynolds number.
Method of Solution
A pseudo-transient, fractional step method, alternatively known as the time-splitting method is used.
The steps involved in the solution are:
1. The nonlinear step that takes into account the convective terms of the Navier- Stokes equations.
This step results in an intermediate value of the velocity components denoted by u* and v*. At the
first time step, the initial conditions are fed as inputs to this step.
2. The pressure step that takes into account the pressure term in the Navier-Stokes equation. In the
form of the equation that we are solving in this project, this term involves the perturbation
pressure p(x,y). This step results in an intermediate value of the velocity components denoted by
u** and v**.
3. Two viscous steps. The two viscous steps take into account the effects of viscosity. After solving
both the viscous steps, a final value of both the velocity components is arrived at. These are
denoted as un+1 and vn+1. These are the values are the values of the velocity components after one
complete time step.
4. At the end of one complete time step, the final values of velocity are fed back in to the non-linear
step and the entire process is repeated until convergence is achieved.
5. The convergence is tested on the basis of the values of the streamwise velocity matrix. A preset
tolerance level is set, which is the minimum variation between the streamwise velocity values
between two consecutive time steps, at all the grid points, which is to be achieved in order to
achieve a convergent solution.
6. As soon as convergence is detected, the iterations stop and an rms error is calculated at the
outflow using the analytical solution as the benchmark.
7. Also, the flow rate is calculated at every point along the length of the channel by numerically
integrating the velocity values along the height of the channel. This computed value is compared
to the constant inlet flow rate and an rms error is again computed.
Each of the steps is explained in detail along with a presentation of relevant formulae and a brief
discussion of the discretization procedures followed to arrive at the said formulae.
Where
And,
The spatial derivatives that constitute the terms Fu and Fv are discretized using a standard central
difference scheme. The time advancement is done using the Adams-Bashforth method, i.e.
And,
As is evident, the Adams-Bashforth method is a three-level system that requires information at two
previous time levels as input. At the first step, as we have the values of velocity for only one previous
time step, a different two-level scheme must be employed to start the solution process. The method
chosen for this is the Euler time discretization. The formula for the same can be expressed as:
And
Here the level n=1, is taken as the initial condition. Consequently, the solution after the first time step is
the solution at time level n=2.
And,
Substituting these values into the equation for the Adams Bashforth method yields the following
equations:
And,
!
"
#
$
The algorithm that arises from the simplification of these equations has been implemented in the
subroutine Convec.m . The algorithm is as follows:
And,
!
"
#
$
The same substitution in the Euler method yields the following algorithm:
And,
This is discretized using a central difference scheme. In order to do so, we must introduce a fictitious
point beyond the computational domain at the point (xmax+dx). In terms of nodal values, this can be
viewed as the introduction of a fictitious node (nx+1). Such a discretization yields:
or,
Hence, all the terms that are related to the streamwise velocity at the (nx+1)th node are equated to the
respective values at the (nx-1)th node. Hence, a different algorithm takes shape that is implemented only at
the outflow boundary.
The values of u*and v* that are obtained from this step are passed onto the subroutine that performs the
calculations relating to the pressure step.
The value of the perturbation pressure at all the grid points is in turn obtained from a Poisson equation for
p:
% &%
%
Once the values of p are known, the values of u** and v** are calculated using the following equations:
Discretization of the left hand side of the Poisson equation for Pressure:
The spatial pressure derivatives are discretized using a central difference scheme as follows:
The above discretized versions of the derivatives are substituted in the Poisson equation to obtain the
following expression:
The right hand side of the above equation is known (the discretization is discussed in the next section).
Thus, we have a set of (nxny) linear equations in (nxny) unknowns. This is solved using the LU
decomposition with the help of the subroutines FACT and SOLVE.
The Neumann boundary conditions at all the boundaries mean that we must solve for the pressure terms at
all the nodal points, i.e. at (nx ny) points. This is achieved by introducing fictitious nodes at all the
boundaries akin to introducing an entire fictional boundary that surrounds the computational domain. The
Neumann boundary conditions are discretized using a second order, central difference scheme, so that the
following equalities hold good:
The above substitutions are made when writing the equations for the boundary points. The scheme is thus
implemented at all the points in the computational domain.
However, this method has a tendency to produce unusually large values of pressure. The values of
pressure are hence controlled by setting the value of p(nx,ny)=1. Thus, we now have one variable less to
solve for and we end up solving only for [(nxny)-1] unknowns.
Discretization of the right hand side of the Poisson equation for pressure:
The right hand side of the equation is discretized using two methods:
The Press Technique:
The Press technique involves the usage of backward difference formulae to discretize the spatial
derivatives of the velocity terms. This is done as follows:
Along the left boundary and the lower boundary of the domain, a three point forward difference formula
is used to discretize the spatial derivatives of the velocity terms. This is done as follows:
Thus the values of the right hand side of the equation are computed at all the points.
The Press0 technique:
In this approach, the spatial derivatives are discretized using a backward difference formula at all the
interior points. However, the values of the right hand side of the equation are set to zero along all four
boundaries.
The Press0 technique is effective in maintaining the stability of the scheme at higher Reynolds numbers.
At an Re of 100, the Press0 technique fares quite well, whereas the Press technique is not stable, causing
the solution to go out of bounds if run for even a moderately high number of time steps. However, at
lower Re, the Press technique seems to give more accurate solutions, especially with respect to the flow
rate calculations. This is further discussed in subsequent sections of the report.
Once both the sides of the equation have been discretized, an LU decomposition method is used to solve
the system of linear equations. The resulting values of pressure are used in the second half of the pressure
step to calculate the values of u** and v**, using the previously mentioned expressions:
The spatial derivatives of pressure are discretized using a central difference scheme as follows:
The values of u** and v** calculated in this step are passed to the viscous step.
The second order spatial derivative terms are discretized using a three point central difference scheme as
follows:
'
'
'
' (
) '
'
'
'
' (
) '
These can be written mathematically as a set of linear equations. Illustratively, for the equations solving
the streamwise velocity components, we have the following expression:
,-./0
Where [A] is a matrix of coefficients of size [(nx-1)(ny-2)], {u} is a matrix of unknowns of size [(nx1)1], and {R} is a matrix of constants of size [(nx-1)1].
The system of equations is solved using the Thomas algorithm. This algorithm is implemented using the
subroutines BANFAC and BANSOL.
The equations are solved at all the internal points and at the outflow boundary. At the outflow boundary,
the Neumann boundary conditions are applied for the streamwise velocity, as follows:
Which gives,
Where [A] is a matrix of coefficients of size [(nx-2)(ny-2)], {v} is a matrix of unknowns of size [(nx2)1], and {R} is a matrix of constants of size [(nx-2)1].
As there are no Neumann boundary conditions applicable to the vertical component of velocity, these
equations are only solved at internal points and Dirichlet boundary conditions are applied at the
boundaries. These equations are also solved using the Thomas algorithm.
The intermediate values u*** and v*** that are obtained from the first viscous step act as the right hand side
of the equations that finally solves for the values of un+1 and vn+1 in the second viscous step.
This is solved using a Crank-Nicolson method, as was the case in the first viscous step.
After applying the Crank-Nicolson scheme, the following expressions are obtained: ,k
The second order spatial derivative terms are discretized using a three point central difference scheme as
follows:
By applying this discretization and simplifying the expressions, we obtain the following equations:
'
'
( ' )
'
'
( ' )
'
'
( ' )
'
'
( ' )
These can be written mathematically as a set of linear equations. Illustratively, for the equations solving
the streamwise velocity components, we have the following expression:
,-./0
Where [A] is a matrix of coefficients of size [(nx-2)(ny-2)], {u} is a matrix of unknowns of size [(nx2)1], and {R} is a matrix of constants of size [(nx-2)1].
The system of equations is solved using the Thomas algorithm. This algorithm is implemented using the
subroutines BANFAC and BANSOL.
The equations in the second viscous step are first solved at a fixed value of x, and for all values of y from
y=2 to y=ny-1. Subsequently the value of x is incremented and the equations are once again solved for all
the aforementioned values of y.
The equations that solve for vn+1, have a similar matrix representation and are solved in the same way.
The values, un+1 and vn+1, represent the final values of the streamwise and vertical components of velocity
at the end of one complete time step. For the next time step, these values are passed back to the subroutine
that performs the convection step. The entire process is repeated until convergence is achieved.
Flow-Rate Calculation:
The flow rate is computed at each point along the channel length by numerically integrating along the ydirection. The numerically calculated flow rate is then compared to the constant inlet flow rate and an rms
error (q-rms) is calculated.
The numerical integration is performed using the built-in Matlab function trapz .
trapz calculates the area under a curve by splitting it up in to the sum of the areas of trapeziums.
Notation:
u-rms is the RMS error calculated by comparing the numerically calculated velocity values at the outflow
with the exact solution.
q-rms is the RMS error calculated by comparing the numerically calculated flow rate at every point in the
x-direction with the constant flow rate at the inlet of the channel.
For Re=1:
Results for the Press0 Technique:
Re
CFL
1
0.1
Time steps to
convergence
0.01
100
Tolerance
u-rms
1.00E-10
0.0119
q-rms
0.015
Re
CFL
1
0.1
Time steps to
convergence
0.01
88
Tolerance
u-rms
q-rms
1.00E-10
0.0062
0.0025
For Re=10:
Results for the Press0 Technique:
Re
CFL
10
0.1
Time steps to
convergence
0.01
600
Tolerance
u-rms
q-rms
1.00E-10
0.0039
0.0021
Re
CFL
10
0.1
Time Steps to
Convergence
0.01
696
Tolerance
1.00E-10
u-rms
q-rms
0.0057
0.0014
Discussion of results and comparison between the Press and Press0 technique:
Initially, it was decided that only one of the methods would be implemented and presented in the
report. However, a comparison between the two methods seemed to provide an interesting
insight into the numerical scheme under examination.
As the results will indicate, the Press0 technique fared poorly at lower Reynolds number
whereas the Press technique did quite well at Re=1, producing a significantly lower rms error for
the streamwise velocity component. However at higher values of Re, the Press0 technique fared
better than the Press technique. However, at all the values of Re, the Press technique produced
better results for the flow rate and these were closer to the constant flow rate value at the inlet.
The major difference between the two solution methods was evident at the highest Reynolds
number that was tested for in this project. At Re=100, the Press technique failed completely and
caused the solution to go out of bounds, a clear sign of instability. The Press0 technique
however, produced good results even at this high Reynolds number.
The reason for this difference between the two schemes can be attributed to the fact that the
Press technique assigns definite values to the boundary nodes in the calculation of the
perturbation pressure matrix. These definite values seem to be getting larger and larger at the
high Reynolds number, resulting in the solution going out of bounds. In fact, it was observed that
even the Press0 technique produced the best results when run for a coarser mesh, and when the
channel length was extended significantly.
One interpretation of this result could be that, at this high Reynolds number, with the refinement
of the grid, the increase in round-off error was over-powering the decreased discretization error,
hence resulting in a solution that tended to go out of bounds. This case could be run on a faster,
more capable computer, where in it would be possible to run the program with a higher precision
and hence lower round-off errors, and only then can this theory about the instability of the code
be validated. Another more obvious reason for the solution going out of bounds would be the
explicit nature of the scheme applied in the convection step, which is only conditionally stable
and tends to become unstable at higher values of Re.
The best results obtained for Re=100 have been presented in subsequent sections. Also,
improved results at Re=1 and Re=10, owing to mesh refinement and extension of the domain
length in the x-direction have been provided.
Grid
q-rms
60 21x21
35000
0.0046
0.0032
70 21x21
35000
0.0036
0.0024
u-rms
0.1
0.01
157
Tolerance
1.00E-10
u-rms
0.005
q-rms
2.80E-03
10
0.01
0.1
Tolerance
1.00E-10
u-rms
0.0027
q-rms
6.04E-04
u-rms
q-rms
0.1
0.01
154
1.00E-10
0.0041
0.0042
10
0.1
0.01
1003
1.00E-10
0.0014
4.11E-04
Tolerance
dt
Grid
Re
u-rms
q-rms
0.01 51x21
10
578 0.0036
0.01 101x41
10
965 0.0011
0.0018
3.24E04
10
0.01 101x21
10
549 0.0035
0.0015
Press Technique
xmax
dt
Grid
Re
5 0.01 51x21
10
5 0.01 101x41
10
10 0.01 101x21
10
671 0.0057
q-rms
0.0014
u-rms
0.0015
ssW'
The numerical scheme might be run on a more capable computer to reduce round off
errors. This would help the code to perform more satisfactorily at higher Reynolds
numbers and if there are any complications in the geometry of the system.
The usage of more accurate schemes is another way in which improvement can be done.
The use of explicit schemes can also be substituted for schemes which are stable for a
wider range of parameters.
The implementation of boundary conditions can be done more accurately, with a reduced
number of assumptions, hence producing a more realistic model of the flow.
A finite volume method can be implemented to model the same flow.
The use of a locally refined mesh can help to better capture the intricacies of the flow. To
be more precise, a more refined grid nearer to the channel walls will help to more
accurately model the boundary layer that is formed in that region.
There are many other ways in which to increase the efficacy of the numerical solution scheme
presented in this report. The author plans on pursuing these avenues in the near future.
Type of Script
Main Program
Main0.m
Main Program
Convec.m
Subroutine
Press.m
Subroutine
Press0.m
Subroutine
visc.m
Subroutine
redif.m
Subroutine
redif2.m
Subroutine
flowrate.m
Subroutine
Plotter.m
fact.m
solve.m
Subroutine
Subroutine
Subroutine
banfac.m
Subroutine
bansol.m
Subroutine
Function
Setting of input parameters,
Calculation of matrices
required by the different subroutines, testing for
convergence and calculation
of RMS error. Uses the
subroutine Press.m for the
pressure step.
Same function as Main.m. The
only difference being that it
calls Press0.m for the pressure
step.
Solves the convection step of
the solution as described in the
report.
Solves the pressure step of the
solution using the Press
technique, as described in the
report.
Solves the pressure step of the
solution using the Press0
technique.
Solves the two viscous steps
in the solution as described in
the report.
Solves the right hand side of
the first viscous step.
Solves the right hand side of
the second viscous step.
Calculates the flow-rate and
also calculates the rms error
by comparing the numerically
calculated flow rate with the
constant flow rate at the inlet.
Plots all the necessary graphs.
Performs LU decomposition.
Solves the Perturbation
Pressure equation by back
substitution.
Performs the forward sweep in
the Thomas Algorithm
Backward sweep of the
Thomas Algorithm