cvfd2d slides 2up

Upload: thanhndb

Post on 01-Jun-2018

231 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/9/2019 CVFD2D Slides 2up

    1/17

    The Control-Volume Finite-Di ff erenceApproximation to the Di ff usion Equation

    ME 448/548 Notes

    Gerald RecktenwaldPortland State University

    Department of Mechanical & Materials [email protected]

    21 January 2014

    ME 448/548: 2D Diff usion Equation

    Motivation

    Numerical solution of the 2D Poisson equation is the next step in developing ourknowledge 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 Diff usion Equation 1

  • 8/9/2019 CVFD2D Slides 2up

    2/17

    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 ow Precursor to the generalized advection diff usion equation

    Use the nite volume method to obtain discrete equations Allow for non-uniform mesh, diff usion coeffi cient, and source term. Introduce a set of Matlab codes for 2D Control Volume Finite Diff erence (CVFD) Demonstrate solutions for three model problems. Measure truncation error for a model problem with a simple solution Apply to fully-developed ow in rectangular ducts

    ME 448/548: 2D Diff usion Equation 2

    Model Problem

    The two dimensional diff usion equation in Cartesian coordinates is

    x

    x

    + y

    y

    + S = 0 (1)

    where is the scalar eld, is the diff usion coeffi cient, and S is the source term.

    Example: Heat conduction in a rectangular domain

    = k, thermal conductivity or = kc p

    =

    S = volumetric heat source

    ME 448/548: 2D Diff usion Equation 3

  • 8/9/2019 CVFD2D Slides 2up

    3/17

    2D Cartesian Finite Volume Mesh

    x

    y

    1 2

    i = 0 2 j = 0

    2

    3

    3

    1

    1

    +1 +2

    Interior node

    Boundary node

    Ambiguous corner node

    ME 448/548: 2D Diff usion Equation 4

    Finite Volume Mesh: Compass Point Notation

    Nodes are labelled with their positionrelative to the typical point P.

    N

    S

    EW

    x

    y

    Capital letters designate node locations.

    N, S, E, W are the names of north,south, east and west neighbors.

    N , S , E , W are the values of atthe north, south, east and west neighbor nodes .

    Use of compass point names simpliesthe algebra. For example the value of at point N is N or i,j +1 , but N issimpler to write.

    Compass point notation is an historicconvention that does not extend tounstructured meshes.

    ME 448/548: 2D Diff usion Equation 5

  • 8/9/2019 CVFD2D Slides 2up

    4/17

    Finite Volume Mesh

    Detailed notation for a typical 2D controlvolume

    x w x e

    S

    PW E

    N

    x

    y

    xe xw

    yn

    y s y s

    yn

    Lowercase letters designate the interfacebetween the nodes.

    x e and x w are the x coordinates of theeast and west faces of the controlvolume around P

    yn and ys are the y coordinates of thenorth and south faces of the controlvolume around P

    Similarly, n , s , e , w are the valuesof at the north, south, east and westcontrol volume interfaces .

    ME 448/548: 2D Diff usion Equation 6

    Finite Volume Mesh

    Detailed notation for a typical 2D controlvolume

    x w x e

    S

    PW E

    N

    x

    y

    xe xw

    yn

    y s y s

    yn

    Regardless of whether the controlvolumes sizes are uniform, node P isalways located in the geometric center of each control volume.

    Thus,

    x P

    x w = xe

    x P =

    x

    2yP ys = yn yP =

    y2

    for uniform or non-uniform meshes

    ME 448/548: 2D Diff usion Equation 7

  • 8/9/2019 CVFD2D Slides 2up

    5/17

    Finite Volume Mesh

    Detailed notation for a typical 2D control

    volume

    x w x e

    S

    PW E

    N

    x

    y

    xe xw

    yn

    y s y s

    yn

    In contrast, the distances between the

    nodes is not assumed to be uniform

    x e = x E x P 6= x w = x P x W yn = yN yP 6= ys = yP yS

    x e = x E x P 6= x w = x P x W yn = yN yP 6= ys = yP yS Note the use of upper and lower casesubscripts: Upper case refers to nodes;

    lower case refers to interfaces.

    ME 448/548: 2D Diff usion Equation 8

    Convert the Di ff erential Equation to a Discrete Equation

    Integrate over the control volume

    Z yn

    ys Z xe

    x w

    x

    x

    dxdy

    = Z yn

    ys

    x e

    x w

    dy

    x e

    x w y

    e E P

    x e w P W

    x w y

    xw xe

    S

    PW E

    N

    x

    y

    xe x w

    yn

    y s ys

    yn

    The nal step is obtained by using central diff erence approximations for the derivatives atthe interfaces.

    ME 448/548: 2D Diff usion Equation 9

  • 8/9/2019 CVFD2D Slides 2up

    6/17

    Convert the Di ff erential Equation to a Discrete Equation

    Integrate the source term

    Z xe

    x w Z yn

    ysS dy dx S P x y (2)

    Note: The Control Volume Finite Di ff erence (CVFD) method treats the source term anddiff usion coeffi cients as piecewise constants. This is a rather crude approximation, say,compared to allowing the source term and diff usion coeffi cient to vary linearly within thecontrol volume.

    However, piecewise constant proles of S and allow the method to be conservative,i.e., conserving mass or energy, automatically. The conservative nature of the CVFDmethod is one of its primary strengths.

    ME 448/548: 2D Diff usion Equation 10

    Convert the Di ff erential Equation to a Discrete Equation

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

    a S S a W W + a P P a E E a N N = b (3)where

    a E = e

    x x e, a W =

    w

    x x w, a N =

    n

    y yn, a S =

    s

    y y s

    a P = a E + a W + a N + a S (4)

    b = S P (5)

    This is not a tridiagonal system of equations.

    ME 448/548: 2D Diff usion Equation 11

  • 8/9/2019 CVFD2D Slides 2up

    7/17

    Non-uniform

    Continuity of uxes at the interface requires

    P

    x x e =

    E

    x x e + = e

    x x e

    Use central diff erence approximations

    e E P

    x e= P

    e P x e

    (6)

    e E P

    x e= E

    E ex e+

    (7) x

    e

    material 1 material 2

    x e + x e -

    P E

    ME 448/548: 2D Diff usion Equation 12

    Non-uniform

    Equations 6 and 7 can be rearranged as

    e P = x e

    P

    e

    x e( E P ) (8)

    E e = x e+

    E

    e

    x e( E P ) (9)

    Add Equation 8 and Equation 9

    E P = e

    x e( E P ) x

    e P

    + x e+ E

    .

    x e

    material 1 material 2

    x e + x e -

    P E

    Cancel the factor of ( E P ) and solve for e / x e to get e

    x e=

    x e P

    + x e+

    E

    1=

    E P

    x e E + x e+ P .

    ME 448/548: 2D Diff usion Equation 13

  • 8/9/2019 CVFD2D Slides 2up

    8/17

    Non-uniform

    Thus, the diff usion coeffi cient at the interface that results in ux continuity is

    e = E P

    E + (1 ) P (10)where

    x e

    x e=

    x e x P x E x P

    (11)

    An analogous derivation gives formulas for w , n , and s .

    ME 448/548: 2D Diff usion Equation 14

    Solving the System of Equations

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

    a S S a W W + a P P a E E a N N = 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 andcolumn indices in the system Ax = b.

    ME 448/548: 2D Diff usion Equation 15

  • 8/9/2019 CVFD2D Slides 2up

    9/17

    Solving the System of Equations

    Order the nodes:

    n = i + ( j 1) nxn is the node number (row number)in Ax = b. i and j are the meshindices corresponding to x i and y j .

    With natural ordering the neighborsin the compass point notation havethese indices

    np = i + (j-1)*nxn e = n p + 1n w = n p - 1nn = np + nxns = np - nx

    x

    y

    1 2

    i = 0 2 j = 0

    2

    3

    3

    1

    1

    +1 +2

    Interior node

    Boundary node

    Ambiguous corner node

    ME 448/548: 2D Diff usion Equation 16

    Solving the System of Equations

    This leads to a vector of unknowns

    1,1 2,1

    ... nx, 1 1,2 2,2

    ... i,j

    ... nx,ny

    1 2...

    nx nx +1 nx +2

    ... n...

    N

    (13)

    ME 448/548: 2D Diff usion Equation 17

  • 8/9/2019 CVFD2D Slides 2up

    10/17

    Solving the System of Equations

    The coeffi cient matrix has 5 non-zero diagonals

    A = a S a pa W a E a N

    ME 448/548: 2D Diff usion Equation 18

    Algorithm for obtaining the numerical solution

    1. Dene physical parameters: L x , L y , (x, y ) and boundary conditions2. Dene the mesh: n x and n y if uniform3. Compute the coeffi cient matrix4. Solve the system of equations A = b, where is the vector of unknowns.5. Post-process to visualize the solution

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

    ME 448/548: 2D Diff usion Equation 19

  • 8/9/2019 CVFD2D Slides 2up

    11/17

    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

    Uniform Mesh Block-Uniform Mesh

    Lx1, nx 1 Lx2, nx 2

    Ly1, ny1

    Ly2, ny2

    Ly3, ny3

    x

    y

    x

    y

    ME 448/548: 2D Diff usion Equation 20

    Boundary Conditions (part 1)

    Boundarytype

    BoundaryCondition Post-processing in fvpost

    1 Specied T Compute q00 from discrete approximation to Fouriers law.q00 = k T b T i

    x b x iwhere T i and T b are interior and boundary temperatures, respectively.

    2 Specied q00 Compute T b from discrete approximation to Fouriers law.T b = T i + q00

    x b x ik

    where T i and T b are interior and boundary temperatures, respectively.

    ME 448/548: 2D Diff usion Equation 21

  • 8/9/2019 CVFD2D Slides 2up

    12/17

    Boundary Conditions (part 2)

    Boundarytype

    BoundaryCondition Post-processing in fvpost

    3 Convection From specied h and T , compute boundary temperature and heat uxthrough the cell face on the boundary. Continuity of heat ux requires

    kT b T ix b x i

    = h (T b T amb )

    which can be solved for T b to give

    T b = hT amb + ( k/ x e )T i

    h + ( k/ x e )

    where x e = x b x i4 Symmetry q00 = 0 . Set boundary T b equal to adjacent interior T i .

    ME 448/548: 2D Diff usion Equation 22

    Matlab codes for obtaining the numerical solution

    A set of general purpose codes has been written to facilitate experimentation with theCVFD method.

    Algorithm Tasks Core Routines

    Dene the mesh fvUniformMesh orfvUniBlockMesh

    Dene boundary conditions

    Compute nite-volume coeffi cients for interior cells fvcoef

    Adjust coeffi cients for boundary conditions fvbcSolve system of equations

    Assemble coeffi cient matrix fvAmatrix

    Solve

    Compute boundary values and/or uxes fvpost

    Plot results

    ME 448/548: 2D Diff usion Equation 23

  • 8/9/2019 CVFD2D Slides 2up

    13/17

    Model Problem 1

    Choose a source term that may be physically unrealistic, but one that gives an exact

    solution that is easy to evaluate

    S = " L x2

    +2L y

    2#sin xL x sin 2 yL yThe exact solution is

    = sin xL x

    sin2 yL y

    Main code to solve this problem is in demoModel1.m

    ME 448/548: 2D Diff usion Equation 24

    Model Problem 1

    The exact solution is

    = sin xL x

    sin2 yL y

    0

    0.5

    1

    00.20.40.60.81

    0

    0.5

    1

    1.5

    2

    yx

    ME 448/548: 2D Diff usion Equation 25

  • 8/9/2019 CVFD2D Slides 2up

    14/17

    Solutions to Model Problem 1 Show Correct Truncation Error

    The local truncation error at each node ise i O ( x 2) .Since the exact solution is known we can

    compute

    kek2N

    = q Pe2i

    N

    N e2N

    = e N .

    where N = n x n y is the total number of interior nodes in the domain, and e is theaverage truncation error per node.

    103 10

    2 101 10 0

    108

    107

    106

    105

    104

    103

    102

    101

    x

    M e a s u r e

    d e r r o r

    MeasuredTheoretical error ~ ( x)3

    Since e i O ( x 2) , N n 2x , and x = L x / (n x + 1) , we can estimate

    kek2N

    e

    N =

    O ( x 2)

    n x=

    O L 2x / (n x + 1)2

    n xO

    1

    n x

    3

    = O ( x 3) .

    ME 448/548: 2D Diff usion Equation 26

    Model Problem 2

    Uniform source term: S = 1 .

    Analytical solution is an inniteseries

    Code in demoModel2.m

    0

    0.5

    1

    00.20.40.60.81

    0

    0.010.02

    0.03

    0.04

    0.05

    0.06

    0.07

    0.08

    yx

    ME 448/548: 2D Diff usion Equation 27

  • 8/9/2019 CVFD2D Slides 2up

    15/17

    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.25 L x

    0.25 L y

    0.5 L y

    0.5 L x

    L x

    L y 1 = 1

    S 1 = 0

    2

    = 1

    S 2 = 1000

    The discontinuity and diff erence in material properties can be used to stress the solutionalgorithm.

    = 2

    1

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

    ME 448/548: 2D Diff usion Equation 28

    Model Problem 3

    0.25 L x

    0.25 L y

    0.5 L y

    0.5 L x

    L x

    L y

    1 = 1

    S 1 = 0

    2

    = 1

    S 2 = 1000

    Solution with = 100

    0

    0.5

    1

    00.20.40.60.81

    0

    5

    10

    15

    20

    25

    30

    35

    yx

    ME 448/548: 2D Diff usion Equation 29

  • 8/9/2019 CVFD2D Slides 2up

    16/17

    Model Problem 4: Fully Developed Flow in a Rectangular Duct

    For simple fully-developed ow the governing equation for the axial velocity w is

    " 2w x 2 + 2w y2 # dpdz = 0This corresponds to the generic model equation with

    = w, = (= constant ) , S = dpdz

    .

    ME 448/548: 2D Diff usion Equation 30

    Model Problem 4: Fully Developed Flow in a Rectangular Duct

    The symmetry in the problem allows alternative ways of dening the numerical model

    Full Duct

    x

    y

    L x

    L y

    Quarter Duct

    x y

    L x

    L y

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

    w(x, 0) = w(x, L y ) = w(0 , y ) = w (L x , y ) = 0 . (full duct)

    ME 448/548: 2D Diff usion Equation 31

  • 8/9/2019 CVFD2D Slides 2up

    17/17

    Model Problem 4: Fully Developed Flow in a Rectangular Duct

    The symmetry in the problem allows alternative ways of dening the numerical model

    Full Duct

    x

    y

    L x

    L y

    Quarter Duct

    x y

    L x

    L y

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

    w(L y , y ) = w(x, L x ) = 0 (quarter duct)

    and symmetry conditions on the other two planes

    u x x =0

    = u y y=0

    = 0 .

    ME 448/548: 2D Diff usion Equation 32