0% found this document useful (0 votes)
215 views17 pages

CVFD2D Slides 2up

The document discusses numerical methods for solving diffusion equations in two dimensions using the finite volume method. It introduces the control-volume finite-difference (CVFD) approach, which uses a structured mesh to discretize the domain and integrate the diffusion equation over each control volume. The document outlines the steps to derive the discrete equations, set up the coefficient matrix, impose boundary conditions, and solve the linear system to obtain the numerical solution. Matlab codes are provided to implement the CVFD method for various model problems.

Uploaded by

thanhndb
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
215 views17 pages

CVFD2D Slides 2up

The document discusses numerical methods for solving diffusion equations in two dimensions using the finite volume method. It introduces the control-volume finite-difference (CVFD) approach, which uses a structured mesh to discretize the domain and integrate the diffusion equation over each control volume. The document outlines the steps to derive the discrete equations, set up the coefficient matrix, impose boundary conditions, and solve the linear system to obtain the numerical solution. Matlab codes are provided to implement the CVFD method for various model problems.

Uploaded by

thanhndb
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

The Control-Volume Finite-Dierence

Approximation to the Diusion Equation


ME 448/548 Notes
Gerald Recktenwald
Portland State University
Department of Mechanical & Materials Engineering
gerry@pdx.edu
21 January 2014

ME 448/548: 2D Diusion Equation

Motivation

Numerical solution of the 2D Poisson equation is the next step in developing our
knowledge of CFD technique.

Introduce the Finite Volume Method


. Naturally deal with material discontinuity
. Can naturally enforce conservation of mass and energy
. Core idea in many (not all) commercial CFD codes
Extend analysis to two spatial dimensions
. More interesting practical applications
. More complex data structures
. More complex procedures to solve the Ax = b problem

ME 448/548: 2D Diusion Equation

Overview
Goals for this unit

Introduce the Poisson equation


. A model of steady heat conduction with a source term
. Form of the pressure equation for incompressible flow
. Precursor to the generalized advection diusion equation

Use the finite volume method to obtain discrete equations


Allow for non-uniform mesh, diusion coefficient, and source term.
Introduce a set of Matlab codes for 2D Control Volume Finite Dierence (CVFD)
Demonstrate solutions for three model problems.
Measure truncation error for a model problem with a simple solution
Apply to fully-developed flow in rectangular ducts

ME 448/548: 2D Diusion Equation

Model Problem
The two dimensional diusion equation in Cartesian coordinates is

@
@
@
@
+
+S =0
@x
@x
@y
@y
where

is the scalar field,

(1)

is the diusion coefficient, and S is the source term.

Example: Heat conduction in a rectangular domain

= k, thermal conductivity or

k
=
cp

S = volumetric heat source

ME 448/548: 2D Diusion Equation

2D Cartesian Finite Volume Mesh


"$%&'()(*
"$%!".&'

"%+'
"$%+'

#-%!#.&'

!#

!"(!#

#%,'

#-%,'

Interior node
Boundary node

j=0
i=0

!"+1

!"+2

Ambiguous corner node


!"
#-%&'()(*

!"

ME 448/548: 2D Diusion Equation

Finite Volume Mesh: Compass Point Notation


Nodes are labelled with their position
relative to the typical point P.
N

y
x

Capital letters designate node locations.


N, S, E, W are the names of north,
south, east and west neighbors.
at
N , S , E , W are the values of
the north, south, east and west neighbor
nodes.
Use of compass point names simplifies
the algebra. For example the value of
at point N is N or i,j+1, but N is
simpler to write.
Compass point notation is an historic
convention that does not extend to
unstructured meshes.

ME 448/548: 2D Diusion Equation

Finite Volume Mesh


Detailed notation for a typical 2D control
volume

xw

xe and xw are the x coordinates of the


east and west faces of the control
volume around P

xe

N
yn

yn
P

E
y

ys

ys
xw

Lowercase letters designate the interface


between the nodes.

xe

yn and ys are the y coordinates of the


north and south faces of the control
volume around P
Similarly, n, s, e, w are the values
of at the north, south, east and west
control volume interfaces.

ME 448/548: 2D Diusion Equation

Finite Volume Mesh

Detailed notation for a typical 2D control


volume

xw

xe

Regardless of whether the control


volumes sizes are uniform, node P is
always located in the geometric center
of each control volume.
Thus,

N
yn

xP

xw

xe

yP

ys

yn

yn
P

E
y

x
2
y
yP =
2

xP =

for uniform or non-uniform meshes

ys

ys
xw

xe

S
ME 448/548: 2D Diusion Equation

Finite Volume Mesh

Detailed notation for a typical 2D control


volume

xw

In contrast, the distances between the


nodes is not assumed to be uniform

x e = xE

xP 6= xw = xP

y n = yN

yP 6= ys = yP

xe

xW
yS

N
yn

yn
P

x e = xE

xP

6=

x w = xP

y n = yN

yP

6=

y s = yP

y
ys

yS

Note the use of upper and lower case


subscripts: Upper case refers to nodes;
lower case refers to interfaces.

ys
xw

xW

xe

S
ME 448/548: 2D Diusion Equation

Convert the Dierential Equation to a Discrete Equation


Integrate over the control volume

yn
ys

xe
xw

@
@x

@
@x

yn

ys

@
@x

dx dy

xe

@
@x

xe

yn

@
@x

E
e

xw

@
@x

E
y

dy

ys

ys
xw

xe

P
w

yn

xw

The final step is obtained by using central dierence approximations for the derivatives at
the interfaces.
ME 448/548: 2D Diusion Equation

Convert the Dierential Equation to a Discrete Equation


Integrate the source term

xe
xw

yn
ys

S dy dx SP

(2)

Note: The Control Volume Finite Dierence (CVFD) method treats the source term and
diusion coefficients as piecewise constants. This is a rather crude approximation, say,
compared to allowing the source term and diusion coefficient to vary linearly within the
control volume.
However, piecewise constant profiles of S and allow the method to be conservative,
i.e., conserving mass or energy, automatically. The conservative nature of the CVFD
method is one of its primary strengths.

ME 448/548: 2D Diusion Equation

10

Convert the Dierential Equation to a Discrete Equation


Putting pieces back into the model equation gives the discrete system of equations

aS

aW

+ aP

aE

aN

(3)

=b

where

aE =

x xe

aW =

x xw

aN =

y yn

aP = aE + aW + aN + aS
b = SP

aS =

y ys
(4)
(5)

This is not a tridiagonal system of equations.

ME 448/548: 2D Diusion Equation

11

Non-uniform
Continuity of fluxes at the interface requires
P

@
@x

xe

@
@x

xe +

material 1

@
@x

xe

material 2

Use central dierence approximations


E
e

xe
E

(6)

xe

xe-

xe

xe

(7)

xe+

xe+

ME 448/548: 2D Diusion Equation

12

Non-uniform
Equations 6 and 7 can be rearranged as
e

xe

xe

xe+

xe

material 1

(8)

P)

material 2

(9)

P)

Add Equation 8 and Equation 9


xe-

xe

Cancel the factor of (


e

xe

P)

P)

ME 448/548: 2D Diusion Equation

xe
P

xe

xe+

xe

and solve for

xe+

xe+

e/

xe to get

xe

+ xe+

.
P

13

Non-uniform
Thus, the diusion coefficient at the interface that results in flux continuity is
e

=
E

where

+ (1

xe
xe
=
xe
xE

An analogous derivation gives formulas for

w,

n,

(10)
P

xP
xP
and

(11)
s.

ME 448/548: 2D Diusion Equation

14

Solving the System of Equations


Regardless of uniform or variable , the discrete equation has a five-point stencil, and the
discrete equation for any interior node can be written.

aS

aW

+ aP

aE

aN

=b

(12)

To set up the matrix for this system of equations, we need to re-number the unknowns.
Important: i and j subscripts for the mesh are not the same as the row and
column indices in the system Ax = b.

ME 448/548: 2D Diusion Equation

15

Solving the System of Equations


Order the nodes:

"$%&'()(*
"$%!".&'

"%+'

n = i + (j

"$%+'

1)nx

#-%!#.&'

!#

n is the node number (row number)


in Ax = b. i and j are the mesh
indices corresponding to xi and yj .

!"(!#

#%,'

#-%,'

Interior node
Boundary node

With natural ordering the neighbors


in the compass point notation have
these indices
np = i + (j-1)*nx
ne = np + 1
nw = np - 1
nn = np + nx
ns = np - nx

!"+1

!"+2

j=0
i=0

Ambiguous corner node


!"
#-%&'()(*

!"

ME 448/548: 2D Diusion Equation

16

Solving the System of Equations


This leads to a vector of unknowns
0
1

B
B
B
B
B
B
B
B
B
B
B
B
B
B
B
@

ME 448/548: 2D Diusion Equation

1,1
2,1

...

nx,1
1,2
2,2

...

i,j

...

nx,ny

C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
A

()

B
B
B
B
B
B
B
B
B
B
B
B
B
B
B
@

1
2

...

nx
nx+1
nx+2

...

...

1
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
A

(13)

17

Solving the System of Equations


The coefficient matrix has 5 non-zero diagonals

A=

aS

a W ap

aE

aN

ME 448/548: 2D Diusion Equation

18

Algorithm for obtaining the numerical solution


1. Define physical parameters: Lx, Ly ,
2.
3.
4.
5.

(x, y) and boundary conditions


Define the mesh: nx and ny if uniform
Compute the coefficient matrix
Solve the system of equations A = b, where is the vector of unknowns.
Post-process to visualize the solution

The Poisson equation is steady. Each step is performed only once.

ME 448/548: 2D Diusion Equation

19

Structured Mesh
The CVFD Matlab codes use structured meshes. in size.

The cells in the domain are topologically equivalent to a rectangular array


The cells need not be uniform in size.
Each cell not on a boundary touches four other cells
Each row has the same number of cells
Each column has the same number of cells
Block-Uniform Mesh

Uniform Mesh

Ly3, ny3
y
Ly2, ny2
Ly1, ny1

y
Lx1, nx1

Lx2, nx2

ME 448/548: 2D Diusion Equation

20

Boundary Conditions (part 1)


Boundary
type

Boundary
Condition

Post-processing in fvpost

Specified T

Compute q 00 from discrete approximation to Fouriers law.


T
Ti
00
q =k b
xb xi
where Ti and Tb are interior and boundary temperatures, respectively.

Specified q 00

Compute Tb from discrete approximation to Fouriers law.


xi
00 xb
Tb = Ti + q
k
where Ti and Tb are interior and boundary temperatures, respectively.

ME 448/548: 2D Diusion Equation

21

Boundary Conditions (part 2)


Boundary Boundary
type
Condition
3

Convection

Post-processing in fvpost
From specified h and T1 , compute boundary temperature and heat flux
through the cell face on the boundary. Continuity of heat flux requires

T
k b
xb

Ti
= h(Tb
xi

Tamb )

which can be solved for Tb to give

Tb =
where xe = xb
4

Symmetry

hTamb + (k/ xe )Ti


h + (k/ xe )

xi

q 00 = 0. Set boundary Tb equal to adjacent interior Ti .

ME 448/548: 2D Diusion Equation

22

Matlab codes for obtaining the numerical solution


A set of general purpose codes has been written to facilitate experimentation with the
CVFD method.
Algorithm Tasks

Core Routines

Define the mesh

fvUniformMesh or
fvUniBlockMesh

Define boundary conditions


Compute finite-volume coefficients for interior cells

fvcoef

Adjust coefficients for boundary conditions

fvbc

Solve system of equations


Assemble coefficient matrix

fvAmatrix

Solve
Compute boundary values and/or fluxes

fvpost

Plot results
ME 448/548: 2D Diusion Equation

23

Model Problem 1

Choose a source term that may be physically unrealistic, but one that gives an exact
solution that is easy to evaluate
" 2 2#

2
x
2y
S=
+
sin
sin
Lx
Ly
Lx
Ly
The exact solution is

= sin

x
Lx

sin

2y
Ly

Main code to solve this problem is in demoModel1.m

ME 448/548: 2D Diusion Equation

24

Model Problem 1
The exact solution is
2

= sin

x
Lx

sin

2y
Ly

1.5

0.5

0
1
0.5
0
x

ME 448/548: 2D Diusion Equation

0.8

0.6

0.4

0.2

25

Solutions to Model Problem 1 Show Correct Truncation Error


The local truncation error at each node is
ei O( x2).
Since the exact solution is known we can
compute

e2i

Measured
Theoretical error ~ ( x)3

10

10
Measured error

kek2
=
N

qP

10

N e2
e
=p .
N
N

10

10

10

10

where N = nxny is the total number of


interior nodes in the domain, and e is the
average truncation error per node.
Since ei O( x2), N n2x, and

10

10

10

10

10

x = Lx/(nx + 1), we can estimate

O L2x/(nx + 1)2
kek2
e
O( x2)
p =
=
O
N
nx
nx
N

1
nx

= O( x ).

ME 448/548: 2D Diusion Equation

26

Model Problem 2

Uniform source term: S = 1.


0.08

Analytical solution is an infinite


series
Code in demoModel2.m

0.07
0.06
0.05
0.04
0.03
0.02
0.01
0
1
0.5
0
x

ME 448/548: 2D Diusion Equation

0.8

0.6

0.4

0.2

27

Model Problem 3
Heat conduction in a rectangle consisting of
two material regions.

Inner rectangle with high conductivity


Outer rectangle with low conductivity
Inner region has uniform heat source

0.5Ly

Ly

2 = 1

1 = 1

S2 = 1000

S1 = 0

0.25Ly
0.5Lx

0.25Lx

Lx

The discontinuity and dierence in material properties can be used to stress the solution
algorithm.
2

The analytical solution does not exist. Code in demoModel3.m

ME 448/548: 2D Diusion Equation

28

Model Problem 3

Solution with = 100


35
Ly

0.5Ly

2 = 1

1 = 1

S2 = 1000

S1 = 0

30
25

0.25Ly

20
0.25Lx

0.5Lx

15

Lx

10
5
0
1
0.5
0
x

ME 448/548: 2D Diusion Equation

0.8

0.6

0.4

0.2

29

Model Problem 4: Fully Developed Flow in a Rectangular Duct

For simple fully-developed flow the governing equation for the axial velocity w is
"
#
@ 2w
@ 2w
dp

+
=0
2
2
@x
@y
dz
This corresponds to the generic model equation with

= (= constant),

= w,

S=

dp
.
dz

ME 448/548: 2D Diusion Equation

30

Model Problem 4: Fully Developed Flow in a Rectangular Duct


The symmetry in the problem allows alternative ways of defining the numerical model
Full Duct

Quarter Duct
Ly

Ly

y
x

y
Lx

x
Lx

For the full duct simulation depicted on the left hand side, the boundary conditions are no
slip conditions on all four walls.

w(x, 0) = w(x, Ly ) = w(0, y) = w(Lx, y) = 0.

ME 448/548: 2D Diusion Equation

(full duct)

31

Model Problem 4: Fully Developed Flow in a Rectangular Duct


The symmetry in the problem allows alternative ways of defining the numerical model
Full Duct

Quarter Duct
Ly

Ly

y
x

y
Lx

x
Lx

For the quarter duct simulation depicted on the right hand side, the boundary conditions
are no slip conditions on the solid walls (x = Lx and y = Ly )

w(Ly , y) = w(x, Lx) = 0

(quarter duct)

and symmetry conditions on the other two planes

@u
@x
ME 448/548: 2D Diusion Equation

=
x=0

@u
@y

= 0.
y=0
32

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy