The Finite Volume Method: Basic Principles and Examples

Transcription

The Finite Volume Method: Basic Principles and Examples
The Finite Volume Method: Basic Principles and
Examples
Mainak Chowdhury
Indian Institute of Technology,Kanpur,
KANPUR (UP) - 208016.
Email: [email protected]
Under the guidance of
Dr. Gautam Biswas
IIT Kanpur
Mainak Chowdhury (IIT Kanpur)
December 15, 2009
1 / 49
Overview
1
Introduction
2
Diffusion: The steady case
3
Diffusion: The non-steady case
4
Diffusion and Convection
5
Acknowledgements
Mainak Chowdhury (IIT Kanpur)
December 15, 2009
2 / 49
Outline
1
Introduction
2
Diffusion: The steady case
3
Diffusion: The non-steady case
4
Diffusion and Convection
5
Acknowledgements
Mainak Chowdhury (IIT Kanpur)
December 15, 2009
3 / 49
What is finite volume method and what does it solve?
A finite volume method (FVM) is a prescription for spatial
discretization of a continuous system of differential equations.
The basic idea of FVM is that volume integrals of divergence terms
can be represented as surface integrals. (Divergence theorem)
The quantities at the surface can be approximated using different
interpolation techniques from discrete data(control variables).
Mainak Chowdhury (IIT Kanpur)
December 15, 2009
4 / 49
What is finite volume method and what does it solve?
A finite volume method (FVM) is a prescription for spatial
discretization of a continuous system of differential equations.
The basic idea of FVM is that volume integrals of divergence terms
can be represented as surface integrals. (Divergence theorem)
The quantities at the surface can be approximated using different
interpolation techniques from discrete data(control variables).
Ok. . . what kind of equations are we talking about?
Mainak Chowdhury (IIT Kanpur)
December 15, 2009
4 / 49
The Conservation Equation
Consider a control volume
n
δΩ
v
Figure: Definition of a control volume
Then for a conserved scalar U,
∂
∂t
R
Ω
UdΩ +
H
∂Ω
(U(~v .~n) − κ∇(U).~n)dS =
Mainak Chowdhury (IIT Kanpur)
R
Ω
QV dΩ +
H
∂Ω
(Q~S .~n)dS
December 15, 2009
5 / 49
The Conservation Equation
Consider a control volume
n
δΩ
v
Figure: Definition of a control volume
Then for a conserved scalar U,
∂
∂t
R
Ω
UdΩ +
H
∂Ω
(U(~v .~n) − κ∇(U).~n)dS =
R
Ω
QV dΩ +
H
∂Ω
(Q~S .~n)dS
This equation is the fundamental equation of many flow problems
where U is typically the momentum, energy, or density
The problem is steady when the time derivative is zero and non
steady otherwise.
Mainak Chowdhury (IIT Kanpur)
December 15, 2009
5 / 49
Outline
1
Introduction
2
Diffusion: The steady case
3
Diffusion: The non-steady case
4
Diffusion and Convection
5
Acknowledgements
Mainak Chowdhury (IIT Kanpur)
December 15, 2009
6 / 49
A 1-D steady diffusion problem
Let us consider a special case of conservation equation in one dimension.
dU
d
(κ
) + QV = 0
dx dx
Mainak Chowdhury (IIT Kanpur)
(1)
December 15, 2009
7 / 49
A 1-D steady diffusion problem
Let us consider a special case of conservation equation in one dimension.
dU
d
(κ
) + QV = 0
dx dx
Let us see how we can solve this equation.
Mainak Chowdhury (IIT Kanpur)
(1)
December 15, 2009
7 / 49
A 1-D steady diffusion problem
Let us consider a special case of conservation equation in one dimension.
dU
d
(κ
) + QV = 0
dx dx
Let us see how we can solve this equation.
(1)
Node
δx₂
δx₁
Uw x₁
Up
x₂
Ue
x
Δx
Control volume
Discretize the domain: Here the points xi divide the domain of
definition into several control volumes
Mainak Chowdhury (IIT Kanpur)
December 15, 2009
7 / 49
A 1-D steady diffusion problem (Contd.)
Integrate the diffusion equation over each control volume: This yields
Z x2
d
dU
( (κ
) + QV )dx = 0
(2)
dx
x1 dx
This can be simplified as
dU
dU
(κ
)x2 − (κ
)+
dx
dx x1
Z
x2
QV dx = 0
(3)
x1
Assume an interpolation profile: A linear function between nodes will
lead to the following equation
κx2
Ue − Up
Up − Uw
− κx1
+ QV ∆x = 0
δx2
δx1
(4)
where QV represents the average value of QV over the control
volume.
Mainak Chowdhury (IIT Kanpur)
December 15, 2009
8 / 49
A 1-D steady diffusion problem (Contd.)
Source term linearization: If we assume
QV = QVc + QVp Up
(5)
the equation corresponding to each control volume becomes
ap Up = ae Ue + aw Uw + b
(6)
ap = ae + aw − QVp ∆x
κx2
ae =
δx2
κx1
aw =
δx1
b = QVc ∆x
(7)
where
Mainak Chowdhury (IIT Kanpur)
(8)
(9)
(10)
December 15, 2009
9 / 49
Some issues regarding aforementioned scheme
Choice of the interpolating function
Positivity of coefficients
Boundedness of the iterations: A sufficient condition is that
P
|anb |
≤1
ap
where anb stands for coefficients of neighbouring terms to point p.
Choice of control nodes(structured/unstructured)
Mainak Chowdhury (IIT Kanpur)
December 15, 2009
10 / 49
Some issues regarding aforementioned scheme
Choice of the interpolating function
Positivity of coefficients
Boundedness of the iterations: A sufficient condition is that
P
|anb |
≤1
ap
where anb stands for coefficients of neighbouring terms to point p.
Choice of control nodes(structured/unstructured)
But is the above system of equations completely determined?
Mainak Chowdhury (IIT Kanpur)
December 15, 2009
10 / 49
The Boundary Conditions
They can be specified in a variety of ways:
Dirichlet
Neumann
A combination of the above
The boundary conditions enter the linear equations as source terms.
Mainak Chowdhury (IIT Kanpur)
December 15, 2009
11 / 49
The Boundary Conditions
They can be specified in a variety of ways:
Dirichlet
Neumann
A combination of the above
The boundary conditions enter the linear equations as source terms.
Together with the boundary conditions, the linear system of equations is
completely determined and is solvable by sparse matrix or iterative
techniques.
Mainak Chowdhury (IIT Kanpur)
December 15, 2009
11 / 49
Extension to 2 dimensions
Let us consider the Laplace equation in two dimensions:
∂2φ ∂2φ
+
=0
∂x 2
∂y 2
(11)
The control volume is now
C
j+1
D
C'
j+1/2
D'
j
B
A
j-1/2
B'
A'
j-1
i
i+1
i+1/2
i-1/2
i-1
Figure: The Control Volume ABCD
Mainak Chowdhury (IIT Kanpur)
December 15, 2009
12 / 49
Solving the Laplace equation
Consider the integral:
Z Z
(
ABCD
∂2φ ∂2φ
+
)dxdy = 0
∂x 2
∂y 2
By Green’s theorem, the above expression is equivalent to
I
∂φ
∂φ
( dy −
dx) = 0
∂x
∂y
The line integral is over the boundary of ABCD and can be
approximately evaluated as the length of each segment times the
value of the partial derivative at the midpoint of the segment.
Mainak Chowdhury (IIT Kanpur)
December 15, 2009
13 / 49
Solving the Laplace equation
The integral form of the Laplace equation applied to ABCD yields
∂φ
∂φ
∂φ
∂φ
|i,j− 1 ∆yAB −
|i,j− 1 ∆xAB +
|i+ 1 ,j ∆yBC −
| 1 ∆xBC
2
2
2
∂x
∂y
∂x
∂y i+ 2 ,j
∂φ
∂φ
∂φ
∂φ
+
|i,j+ 1 ∆yCD −
|i,j+ 1 ∆xCD + + |i− 1 ,j ∆yDA −
| 1 ∆xDA = 0
2
2
2
∂x
∂y
∂x
∂y i− 2 ,j
Estimating the derivatives at the intermediate points: One way of
doing this is to assign the average value of the partial derivative over
the control volume to its central point. This yields the following
expressions
∂φ
1
|i,j− 1 ≈
2
∂x
AreaA0 B 0 C 0 D 0
∂φ
1
| 1 ≈
∂y i,j− 2
AreaA0 B 0 C 0 D 0
Mainak Chowdhury (IIT Kanpur)
Z Z
Z Z
∂φ
1
( )dxdy =
∂x
AreaA0 B 0 C 0 D 0
I
∂φ
1
( )dxdy = −
∂y
AreaA0 B 0 C 0 D 0
φdy
I
December 15, 2009
φdx
14 / 49
Solving the Laplace equation
The right hand side of the last equation can be approximated as
I
φdy ≈ φi,j−1 ∆yA0 B 0 + φB ∆yB 0 C 0 + φi,j ∆yC 0 D 0 + φA ∆yD 0 A0
A0 B 0 C 0 D 0
Similarly
I
A0 B 0 C 0 D 0
φdx ≈ φi,j−1 ∆xA0 B 0 + φB ∆xB 0 C 0 + φi,j ∆xC 0 D 0 + φA ∆xD 0 A0
The area A0 B 0 C 0 D 0 can be approximated as
|A~0 B 0 x A~0 D 0 | = ∆xAB ∆yj−1,j − ∆yAB ∆xj−1,j
Mainak Chowdhury (IIT Kanpur)
December 15, 2009
15 / 49
Solving the Laplace equation
Assume
Distance between coordinate lines constant locally
Intermediate value is the average of node values at the corners,i.e.,
1
φA = (φi−1,j−1 + φi−1,j + φi,j + φi,j−1 )
4
The above assumptions give a linear equation in the unknowns at a node
and its surrounding nodes
Thus, we have
gi,j φi,j + gi−1,j+1 φi−1,j+1 + gi,j+1 φi,j+1 + gi+1,j+1 φi+1,j+1 + gi−1,j φi−1,j
+ gi+1,j φi+1,j + gi−1,j−1 φi−1,j−1 + gi,j−1 φi,j−1 + gi+1,j−1 φi+1,j−1 = 0
The g’s depend on the geometry of the mesh, more specifically on the
∆x’s and ∆y ’s.
Mainak Chowdhury (IIT Kanpur)
December 15, 2009
16 / 49
Some observations
The finite volume method in 2 dimensions presented so far, offers an
unifying framework to deal with differential equations, irrespective of
the grid coordinate system
By allowing flexibility in the choice of the coordinate system, the
boundary conditions can be more accurately represented, than in
finite difference methods.
Mainak Chowdhury (IIT Kanpur)
December 15, 2009
17 / 49
Simulations: The 2D Laplace equation
Consider the Laplace equation :
∇2 φ = 0
defined on the following:
θ=π/2
r=1
r=0.1
θ=0
Figure: The domain of definition
The boundary condition is given by:
φ=
Mainak Chowdhury (IIT Kanpur)
sin(θ)
r
December 15, 2009
18 / 49
The exact solution
The exact solution corresponding to the above conditions is given by:
φ=
sin(θ)
r
It is plotted below:
"EXACT_LAPLACE.OUT" using 1:2:3
10
8
6
4
2
0
1
0.8
0
Mainak Chowdhury (IIT Kanpur)
0.6
0.2
0.4
0.4
0.6
0.2
0.8
1 0
December 15, 2009
19 / 49
A contour plot of the solution
9.5
9
8.5
8
7.5
7
6.5
6
5.5
5
4.5
4
3.5
3
2.5
2
1.5
1
0.5
1
0.9
0.8
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0.1
0.2
Mainak Chowdhury (IIT Kanpur)
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1
December 15, 2009
20 / 49
Numerical Solutions
The following figures were obtained for a grid obtained from triangulation
of the solution region.
1.0
(solution variable - Analytical Solution)
0.24
0.18
0.8
1.0
(solution variable - Analytical Solution)
0.16
0.8
0.12
0.12
0.08
0.6
0.06
0.6
0.04
0.00
0.4
0.6
0.4
0.00
0.4
0.12
0.2
0.2
0.8
0.18
0.0
0.0
0.2
0.4
0.6
0.8
1.0
0.0
0.0
0.2
0.4
0.6
0.8
1.0
0.12
(a) Number of unknowns 448, RMS er- (b) Number of unknowns 3985, RMS
ror ≈0.0316
error ≈ 0.0134
Figure: The above plots show the error of the numerical solutions on an
unstructured grid.
Mainak Chowdhury (IIT Kanpur)
December 15, 2009
21 / 49
Numerical Solutions
The following figures were obtained for a cylindrical grid in the solution
region,with uniformly distributed ρ and θ.
"DIFF21X21.OUT" using 1:2:3
0
-0.005
-0.01
-0.015
-0.02
-0.025
-0.03
-0.035
-0.04
-0.045
-0.05
"DIFF51X51.OUT" using 1:2:3
0
-0.001
-0.002
-0.003
-0.004
-0.005
-0.006
-0.007
1
1
0.8
0
0.6
0.2
0.4
0.4
0.6
0.2
0.8
1 0
0.8
0
0.6
0.2
0.4
0.4
0.6
0.2
0.8
1 0
(a) Number of unknowns 400, RMS er- (b) Number of unknowns 2500, RMS
ror ≈0.0138
error ≈ 0.0015
Figure: The above plots show the error of the numerical solutions on a cylindrical
grid.
Mainak Chowdhury (IIT Kanpur)
December 15, 2009
22 / 49
Observations
Structure of the problem is important
Finite Volume method offers a simple way of exploiting this structure.
Requires coordinate transformation in finite difference methods.
Mainak Chowdhury (IIT Kanpur)
December 15, 2009
23 / 49
Outline
1
Introduction
2
Diffusion: The steady case
3
Diffusion: The non-steady case
4
Diffusion and Convection
5
Acknowledgements
Mainak Chowdhury (IIT Kanpur)
December 15, 2009
24 / 49
The time dependent 1 D diffusion with source term
Retaining the time derivative in the conservation equation we get,
d
dU
∂U
(κ
) + QV =
dx dx
∂t
(12)
This may be rewritten as
∂U
= φ(U, x)
(13)
∂t
The right hand side includes effects of the source term and the diffusion
term.
Mainak Chowdhury (IIT Kanpur)
December 15, 2009
25 / 49
Temporal discretization of RHS
Integrating the RHS, we have
Z
t+∆t
φ = (f φt+∆t + (1 − f )φt )∆t
t
for
0≤f ≤1
I
I
I
f=1:Fully implicit scheme
f=0.5:Crank-Nicholson scheme
f=0:Fully explicit scheme
Explicit schemes:More stringent restrictions on time steps, no
iteration required
Implicit schemes:Less severe time step restrictions, requires iterations
to arrive at the result
Mainak Chowdhury (IIT Kanpur)
December 15, 2009
26 / 49
Temporal discretization of the transient terms
Consider the following integral
Z Z
t1
t0
∂U
dtdx
∂t
This may be approximated as
(U t1 − U t0 )∆x
Forward Euler
t1 = t + ∆t, t0 = t
Backward Euler
t1 = t, t0 = t − ∆t
Mainak Chowdhury (IIT Kanpur)
December 15, 2009
27 / 49
Temporal discretization of the transient terms(contd.)
A second order scheme:
3
1
U t1 = U t − U t−∆t
2
2
3
1
U t0 = U t−∆t − U t−2∆t
2
2
Mainak Chowdhury (IIT Kanpur)
(14)
(15)
December 15, 2009
28 / 49
Simulations: 1D Transient Diffusion
Consider the following transient diffusion problem:
∂φ
= ∇2 φ
∂t
(16)
with boundary conditions
φ = 1 at x = 0
(17)
φ = 0 at x = ∞
(18)
φ = 0 at t = 0
(19)
The exact analytical solution to the above is
√
φ(x, t) = 1 − erf (x/2 t)
Mainak Chowdhury (IIT Kanpur)
December 15, 2009
29 / 49
Explicit scheme with 90% of allowed time step
1.0
solution variable
analytical value
0.8
0.6
0.4
0.2
0.0
0
Mainak Chowdhury (IIT Kanpur)
10
20
30
40
50
December 15, 2009
30 / 49
Explicit scheme with 110% of allowed time step
1.0
solution variable
analytical value
0.8
0.6
0.4
0.2
0.0
0
Mainak Chowdhury (IIT Kanpur)
10
20
30
40
50
December 15, 2009
31 / 49
Implicit scheme with the same time step
1.0
solution variable
analytical value
0.8
0.6
0.4
0.2
0.0
0
Mainak Chowdhury (IIT Kanpur)
10
20
30
40
50
December 15, 2009
32 / 49
Outline
1
Introduction
2
Diffusion: The steady case
3
Diffusion: The non-steady case
4
Diffusion and Convection
5
Acknowledgements
Mainak Chowdhury (IIT Kanpur)
December 15, 2009
33 / 49
The steady state equation
With no source terms the conservation equation reads, for any volume Ω,
I
(U(~v .~n) − κ∇(U).~n)dS = 0
∂Ω
Using divergence theorem,
∇.(U~v − κ∇(U)) = 0
In 1 D , the above equation reduces to
d 2U
d(Uv )
−κ 2 =0
dx
dx
Mainak Chowdhury (IIT Kanpur)
December 15, 2009
34 / 49
Solving the steady state equation
Node
δx₂
δx₁
Uw x₁
Up
x₂
Ue
x
Δx
Control volume
Integrating the equation over the control volume and using central
differencing for the diffusion term, we get
vx2 Ux2 − vx1 Ux1 = ae (Ue − Up ) − aw (Up − Uw )
Mainak Chowdhury (IIT Kanpur)
December 15, 2009
(20)
35 / 49
Interpolation schemes for estimating the LHS
Central Difference
Upwind Differencing
Hybrid Differencing
Power Law
Assume the general equation to be
hp Up = hw Uw + he Ue
(21)
hp = hw + he + vx2 − vx1
(22)
with
Mainak Chowdhury (IIT Kanpur)
December 15, 2009
36 / 49
The coefficient values in the different interpolation schemes
Scheme
Central Differencing
Upwind Differencing
Hybrid Differencing
Power Law
Mainak Chowdhury (IIT Kanpur)
hw
aw + vx1 /2
aw + max(vx1 , 0)
he
ae − vx2 /2
ae + max(0, −vx2 )
max(vx1 , (aw + vx1 /2), 0)
max(0, −vx2 , (ae − vx2 /2)
aw max(0, (1 − 0.1|Pe1 |)5 )
ae max(0, (1 − 0.1|Pe2 |)5 )
+max(vx1 , 0)
+max(−vx2 , 0)
December 15, 2009
37 / 49
Some issues in the choice of an interpolation scheme
Conservativeness: The interpolation scheme should give the same
value of the flux at the same face of adjacent volumes
Boundedness: This means that the value at any node should not
blow up.
Transportiveness:This represents the ability of the interpolation
scheme to address the relative strengths of diffusion and convection in
the interpolation process.
Accuracy
Mainak Chowdhury (IIT Kanpur)
December 15, 2009
38 / 49
A closer look at conservativeness
Linear
Interpolation
Control Volume
Volume Face
Control node
(a) A Linear Interpolation
Quadratic
Interpolation
Control Volume
Volume Face
Control node
(b) A Quadratic Interpolation
Figure: A Comparison of Linear vs Quadratic interpolation
However, not all quadratic schemes suffer from this problem. QUICK
interpolation is one of the most widely used today.
Mainak Chowdhury (IIT Kanpur)
December 15, 2009
39 / 49
A closer look at boundedness
A sufficient condition which will ensure converging solution (
[Versteeg et al]) is that
P
|anb |
≤ 1 for all nodes p
|ap |
< 1 for at least one node
(23)
(24)
All coefficients should have the same sign to ensure that increase in
any neighbouring node leads to increase of value at a particular node.
Mainak Chowdhury (IIT Kanpur)
December 15, 2009
40 / 49
A closer look at transportiveness
Define the Peclet number as
Pe =
vxi L
κxi
(25)
where L is the length of the domain of interest.
A high |Pe | indicates strong convection over diffusion, low value
indicates the converse.
Central Differencing tends to break down with high |Pe | as it gives
equal priority to “upstream” and “downstream” flows
Upwind differencing or power law schemes try to accommodate this
information
Mainak Chowdhury (IIT Kanpur)
December 15, 2009
41 / 49
A 2D convection and diffusion problem
Consider the problem of diffusion in the annular region of the following:
ω
φ=0
y
x
r=3
The equation for φ in the annular region is
2y
Mainak Chowdhury (IIT Kanpur)
∂φ
∂φ
1 ∂2φ ∂2φ
− 2x
=
(
+
)
∂x
∂y
Pe ∂x 2
∂y 2
(26)
December 15, 2009
42 / 49
Solution
The exact solution to the above problem in the annular region is
φ = 1 − log (x 2 + y 2 )/(2log 3)
(27)
It is plotted below:
0.9
Analytical Solution
1.4
0.8
1.2
0.7
Analytical Solution
1.0
0.6
0.8
0.5
0.6
0.4
0.4
0.3
0.2
0.2
0.0
0.0
0.2
0.4
0.6
0.8
1.0
1.2
1.4
0.1
Figure: Exact Solution
Consider the problem in the region R. This becomes a 2D problem .
Mainak Chowdhury (IIT Kanpur)
December 15, 2009
43 / 49
The numerical errors from the Finite Volume Method
The following plots were obtained from applying a finite volume method to
a Cartesian grid (21X21)
0.00018
1.2
0.00012
1.0
0.00006
0.8
0.00000
0.6
0.6
0.4
0.12
0.2
0.18
0.0
0.0
0.2
0.4
0.6
0.8
1.0
1.2
0.24
(Analytical Solution - solution variable)
1.4
0.01
1.2
0.00
1.0
0.1
0.8
0.2
0.6
0.3
0.4
0.4
0.2
0.0
0.0
1.4
0.2
0.4
0.6
0.8
1.0
1.2
0.3
(a) Pe = 0.05
0.02
1.4
0.5
(Analytical Solution - solution variable)
0.00024
(Analytical Solution - solution variable)
(Analytical Solution - solution variable)
1.4
0.6
(b) Pe = 20
Figure: The above plots illustrate the sensitivity of the numerical solutions to
high Pe. Note the false diffusion
Mainak Chowdhury (IIT Kanpur)
December 15, 2009
44 / 49
Summary-Why FVM?
Conservativeness:
I
I
Conservativeness is explicitly enforced
In sharp contrast to finite-difference and finite-element methods
Handling unstructured geometries:
I
I
I
Suitable for representing complicated geometries.
Easier incorporation of mixed boundary conditions over complicated
boundaries
Formulation stays the same
Mainak Chowdhury (IIT Kanpur)
December 15, 2009
45 / 49
Outline
1
Introduction
2
Diffusion: The steady case
3
Diffusion: The non-steady case
4
Diffusion and Convection
5
Acknowledgements
Mainak Chowdhury (IIT Kanpur)
December 15, 2009
46 / 49
Acknowledgements
I would like to thank Dr. G. Biswas, for his insightful comments and helpful
suggestions. I would also like to thank all members of the organising team
of the 8th Winter Academy for giving us this unique opportunity to learn
and interact with our fellow students from India and abroad.
Mainak Chowdhury (IIT Kanpur)
December 15, 2009
47 / 49
Bibliography
H.K. Versteeg and W. Malalasekera.
An introduction to Computational Fluid Dynamics: The Finite Volume
Method
Longman Scientific & Technical
C.A.J. Fletcher.
Computational Techniques for Fluid Dynamics
Springer-Verlag
J. Blazek.
Computational Fluid Dynamics: Principles and Appications
Elsevier
CFD-Wiki
www.cfd-online.com/Wiki
FiPy
http://www.ctcms.nist.gov/fipy/
Mainak Chowdhury (IIT Kanpur)
December 15, 2009
48 / 49
End
Thank you for your kind attention.
Mainak Chowdhury (IIT Kanpur)
December 15, 2009
49 / 49
End
Thank you for your kind attention.
Questions?
Mainak Chowdhury (IIT Kanpur)
December 15, 2009
49 / 49