numerical simulation of potential flow

Upload: ismailahmet7795

Post on 06-Apr-2018

227 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/3/2019 Numerical Simulation of Potential Flow

    1/16

    Numerical Simulation of Potential Flowusing the Finite Element Method

    Cynthia Vanessa Flores (CSUN),Eduardo Rogerio Favaro(Ibilce-Unesp)

    Gilberto Pereira Sassi (ICMC-USP)Leonardo Koller Sacht(UFSC)

    Paulo Liboni (CCET - UFSCar)

    Yeranuhi Semerdjian (CSUN)

    Summer 2007

    Partially supported by NSF grant OISE-0526008.

    1 One Dimensional Model Problem

    Our model problem consists of a one-dimensional, two-point boundary-value prob-lem represented by the following linear ordinary differential equation of second order:

    u + u = x, 0 < x < 1u(0) = 0, u(1) = 0

    , (1)

    It is easy to verify that the exact analytical solution to (1) is u(x) = x sinhxsinh1

    .

    We can use the Finite Element Method to produce an approximation of the solutionby forming a variational statement to the classical boundary value problem. Oneway to produce a weaker variational statement is to choose a set of test and trial

    functions, H10 . This set consists of functions that vanish at the boundaries and whosefirst derivatives are square-integrable. Hence, the variational statement takes thefollowing form:

    10

    (u + u)v dx =

    10

    xv dx, (2)

    1

  • 8/3/2019 Numerical Simulation of Potential Flow

    2/16

    where u, v H10 are the trial and test functions respectively. The solution to (2) willensure that (1) and the boundary conditions are satisfied in a weighted averagesense. Manipulating (2), we arrive at

    10

    (uv + uv xv) dx = 0 v H10 , (3)

    1.1 Galerkin Approximations

    For practical purposes, we project H10 to an N-dimensional subspace, HN0 . In order

    to approximate the solution of our model problem, we also project the test and trialfunctions using a suitable basis {i}, i = 1,...,N for H

    N0 . Expressing the test and

    trial functions as linear combinations of the basis functions,

    uN(x) =Ni=1

    ii(x) (4)

    vN(x) =Ni=1

    ii(x) (5)

    we arrive at the following system of linear equations:

    N

    j=1

    Kijj = Fi, i = 1, 2,...,N, (6)

    where

    Kij =

    10

    i(x)

    j(x) + i(x)j(x)

    dx (7)

    and

    Fi =

    10

    xi dx. (8)

    The matrix K = [Kij] is called the stiffness matrix, and the vector F = [Fi] is calledthe load vector. Since the stiffness matrix is nonsingular, the approximate solutionon the space HN0 is uniquely determined by the system (6).

    The Finite Element Method involves dividing the domain, , into N 1 subdomainse called elements whose endpoints are nodal points. In the one-dimensional case,this creates N nodal points. The set of elements and nodal points make up the finite

    2

  • 8/3/2019 Numerical Simulation of Potential Flow

    3/16

    element mesh. This allows us to approximate the solution over each element withrelative ease. Generally, nodal points are assigned to points of discontinuity occur-ring in the domain. Since there are no discontinuities in the domain of our model

    problem, it is convenient to divide into elements of equal length h =1

    N.

    It is important to note that the choice of basis functions will facilitate the processof writing the code. We impose two conditions on the basis functions i. First, thei should be generated by simple functions defined piecewise, element by element.Second, the i should belong to H

    10 . We chose linear i such that:

    i(xj) =

    1 i = j0 i = j

    (9)

    where xj is a nodal point and i, j {1,...,N}. The piecewise construction of the i

    naturally defines these local basis functions over each element:

    eA() = 1

    h = x xA (10)

    eB() =

    h = xB x (11)

    where xA and xB are the left and right nodal points of element e respectively.Hence, we can define a local element stiffness matrix and local element load vectorexpressed by

    keij =e

    (ij + ij) d (12)

    fei =

    e

    (xA + )i d (13)

    Now, we can construct the Stiffness Matrix K and Load Vector F using

    Kij =Ne=1

    keij (14)

    Fi =

    N

    e=1 f

    e

    i (15)

    The theory behind the model problem can be easily extended to a generalizedboundary value problem of the form

    a0(x)u(x) + a1(x)u

    (x) + a2(x)u(x) = f(x) (16)

    3

  • 8/3/2019 Numerical Simulation of Potential Flow

    4/16

    1.2 Code Implementation

    Once our team was comfortable with the theory behind the one-dimensional case, webegan coding. To start off, we were provided with black-boxes (unfinished pieces

    of C++ code). In order to calculate the integrals (7) and (8) we wrote a numericalintegration routine called

    double basicintegration(double a, double b);

    over the interval [a, b]. To numerically compute the integrals, we used the GaussianQuadrate Method with ten points. To compute the global stiffness matrix, we usedan overlapping function given in one of the black boxes. The reason for the needto overlap arose from the way we interpreted the theory; we used two local basisfunctions which created a 2 2 local stiffness matrix. Thus to calculate the global

    stiffness matrix, we needed to combine the contributions from each local stiffnessmatrix. We built the local load vectors over every element using (8), and took thesum to construct the global load vector.

    Using a black box that implements the Gradient-Conjugate Method, we computedthe solution to the linear system (6). We were able to use this method because [Kij]satisfies the hypothesis. Here is a simple outline of our code:

    Define equation to be solved Ask for initial point, end point, and number of nodes Calculate local stiffness matrix and local load vector

    Assemble the global stiffness matrix and global load vector Solve system (6) print output

    Any plotting program can be used to view the graphical results of the approximatesolution. The solution of the model problem as approximated from our code can becompared to the analytic solution in the following figures:

    4

  • 8/3/2019 Numerical Simulation of Potential Flow

    5/16

    We observe that as the number of nodes increases, our approximation becomessmoother.

    An important technical note: our program uses Unix specific memory allocationmethods. Thus, the program crashes when used on a Windows Operating system.

    2 Two Dimensional Model Problem

    Our two dimensional model problem consists of the following differential equationand boundary conditions defined on a rectangular domain:

    d2udx2

    + d2udy2

    = f 0du

    dy= 15 for y = 4dudy

    = 15 for y = 0

    u = 20 for x = 0, x = 8

    (17)

    Following the same technique from the previous section, we arrive at the followingsystem of linear equations:

    Nj=1

    [Kijuj Fi + ei ] = 0 i = 1, 2,...,N (18)

    where

    Kij =Ne=1

    keij =Ne=1

    e

    [k(i

    x

    j

    x+

    i

    y

    j

    y)] dxdy (19)

    and Fi =Ne=1

    Fei =Ne=1

    e

    f i dxdy (20)

    for every element e. For our model problem, the load vector is the zero vector. Thecontributions of the boundary conditions are imposed through ei =

    2h

    ni ds

    where n = k(x)u and k(x) is the material modulus.

    2.1 Code Implementation

    Following the general technique used in the one-dimensional program, we realizedthat we had to make some minor modifications. First, we need to use a black boxcalled EasyMesh to create a finite element mesh. EasyMesh keeps track of the posi-tion of nodal points, elements, and different boundary conditions. Our previous code

    5

  • 8/3/2019 Numerical Simulation of Potential Flow

    6/16

    was not designed to solve any PDE with boundary conditions. But we did write aspecific program to solve the two-dimensional model problem with given boundaryconditions. An immediate consequence of our choice of local shape functions is that

    we no longer needed a numerical integration routine since we were integrating con-stant functions over triangular domains created using EasyMesh.

    As before, we initially programmed the code that computes the global matrix Kij asthe sum of the local stiffness matrices. In the same fashion as the one-dimensionalcase, we programmed the computation of the local Load Vectors of the problem toget the global Load Vector by summing the local Load Vectors. A small differenceto the two-dimensional model problem was the existence of i vector. This vector iscomputed with the same method as the Load Vector: by taking

    Ne=1

    ei . We used

    the black box from before to solve (18).

    When writing the code, there were many choices to be made. Lets discuss thesetwo different methods. The CGSolver uses specific data structure to save the matrixand vector data. As a result, before calculating the coefficient vectors, it becomesnecessary to save the Stiffness matrix and the Load Vector in the CGSolver structure.Here, we have to choose between the following: 1) perform all the calculations in thenative C++ matrix structure and save the results on the CGSolver structure OR 2)perform all the calculations using the CGSolver (witch uses less memory than theprevious choice but runs much slower because the computer needs to do excessiveroutine calling during computation).

    Using a mesh of about 1180 triangular elements, the program finished computingthe approximate solution in about one minute and thirty seconds. Since our futuregoals consisted of implementing the code with time dependency, we realized that ourcode needed optimization. This process was simple to implement once we realizedthat it was not necessary to create a local matrix over each element since this wouldrequire memory allocation for (N 1)

    keij

    NN

    . Therefore, it was natural to createthe global matrix first. For each Kij entry, the i, j indices also stand for the locationindex of a nodal point. Hence, if some element e contains both i and j nodal points,then that element contributes to the entry of the global stiffness matrix using (19).After implementing this algorithm, our program finished its task in approximatelytwelve seconds.

    3 Heat Conduction Equation

    Let us turn our attention to the following:

    6

  • 8/3/2019 Numerical Simulation of Potential Flow

    7/16

    2u

    x2+

    2u

    y2=

    1

    k

    u

    t, (21)

    where u is now time dependent.The variational statement for this problem takes the form:

    e

    e

    2uehx2

    +2uehy2

    +

    1

    k

    ueht

    veh dxdy = 0 (22)

    where

    ueh(x,y,t) =e

    i=1

    ui(t)ei (x, y), (23)

    and veh is a test function. Notice that in the approximate solution, the time depen-dency appears in the value of the functions at the nodes, not on the basis functions.

    As before, after manipulating the variational statement, we arrive at the followingsystem of linear equations:

    Miju(t) + Kiju(t) = Fi (24)

    where Mij denotes the Mass Matrix given locally by:

    Meij =

    e

    ei (x, y)ej (x, y) dxdy. (25)

    We solve this system by applying Eulers Method of Approximation:

    M

    u(ti+1) u(ti)

    t

    + Ku(ti+1) = F (26)

    Manipulating (26), we arrive at the following:

    (M + tK)u(ti+1) = tF + M u(ti), (27)

    which requires solving a linear system on every point in the discrete time domain.

    Due to time constraint, we were not able to work on the time dependent fluid flowsimulation, but it will be easy to implement the code in the future.

    7

  • 8/3/2019 Numerical Simulation of Potential Flow

    8/16

    4 Potential Flow

    4.1 The Navier-Stokes Equation

    Our goal throughout this project has been to approximate solutions (using the FiniteElement Method) to the Navier-Stokes equations for incompressible fluid flow:

    D(u)

    Dt= p + [(u + u T)] + g

    u = 0, (28)

    where u = (u,v ,w), and the variables are u and p, velocity and scalar pressure

    respectively. The symbol D(u)Dt

    represents the total derivative:

    D

    Dt

    =

    t

    + u . (29)

    Navier-Stokes equations are differential equations which observe the rate of changein velocity and pressure with respect to the position.

    Assuming that u = 0 (no vorticity) and the viscous term [(u +u T)] van-ishes, we get to the following set of partial differential equations for the 2-dimensionalfluid flow:

    2

    x2+

    2

    y2= 0, (30)

    u = x

    , v = y

    , (31)

    p

    +

    u

    2= constant, (32)

    where is the potential function of the velocity, u and v are the components of thevelocity, and (32) is Bernoullis Equation that relates pressure to velocity.

    4.2 Example 1

    Consider equation (30) on the [0, 1] [0, 1] square subject to the following Dirichletboundary conditions:

    (0, y) = 0, y [0, 1],(x, 0) = 0, x [0, 1],(1, y) = 0, y [0, 1],

    (x, 1) = sin(x), x [0, 1]

    (33)

    8

  • 8/3/2019 Numerical Simulation of Potential Flow

    9/16

    This PDE can be numerically solved with the Finite Element Method just as the 2-dimensional model problem. In fact, it is simpler because it does not involve Neumannboundary conditions; it only involves Dirichlet boundary conditions.

    9

  • 8/3/2019 Numerical Simulation of Potential Flow

    10/16

  • 8/3/2019 Numerical Simulation of Potential Flow

    11/16

    expressed by

    d(u)ij =

    ej

    xe

    ej dxdy, d(v)ij =

    ej

    ye

    ej dxdy, (35)

    for every element.See the picture below for the velocity field at each nodal point of the mesh.

    The last step was to calculate the pressure using Bernoullis Equation. For simplicity,we set = 1 and constant = 0. Now, calculating the pressure becomes straightfor-ward. The contours of the pressure can be viewed in the following figure:

    11

  • 8/3/2019 Numerical Simulation of Potential Flow

    12/16

    4.3 Example 2

    The next example simulates the fluid flow on a domain with a circular hole inside.For this case, there will be both Neumann and Dirichlet conditions imposed on theboundaries. The picture below shows the domain of the problem, its triangulardiscretization and labels to the different boundary conditions.

    12

  • 8/3/2019 Numerical Simulation of Potential Flow

    13/16

    The conditions are:at 2 : = 0;

    at 3 :

    n= 0;

    at 4 :

    n= 1.

    We use the same techniques as in the 2-D model problem to find a FEM approximationfor .The velocity and pressure are calculated as in Example 1. Here are the results:

    13

  • 8/3/2019 Numerical Simulation of Potential Flow

    14/16

    4.4 Example 3

    Consider the following domain:

    The boundary conditions are:at 2 : = 0;

    at 3 :

    n= 0;

    at 4 : = 50.

    The next two graphs show the velocity and pressure:

    14

  • 8/3/2019 Numerical Simulation of Potential Flow

    15/16

  • 8/3/2019 Numerical Simulation of Potential Flow

    16/16

    the flow would escape through the walls.

    After investigating on our thousand line code, we noticed that a little change of

    sign on the entries of the D-matrix was causing this strange behavior. Once we fixedthat, we got the results presented on previous sections, with satisfactory physicalbehavior.

    Acknowledgments The FEM team would like to thank CNPq grant, NSF grantOISE-0526008, USP, IRES, the advisors, Gustavo Nonato and Fabricio S. de Sousa,LCAD, SME, SMA, Maria Helena Noronha and the CSUN Department of Mathe-matics, Ali Tahzibi and ICMC-USP.

    References

    [1] O.C. Zienkiewicz and R.L. Taylor,The Finite Element Method

    , McGraw-Hill(vol. 1,2 and 3) (1989).

    [2] W.K. Brian et M.R. Dennis, The C Programming Language, Prentice HallSoftware Series.

    [3] L. Wiroj, Nodeless Finite Element Method For 2d Potential Flow Problems,Thammasat In. J. Tech., Vol 10, No. 4, October-December 2005.

    [4] F.S. Sousa, Simulao de Escoamento multifciso em malhas no estruturadas,Phd. Thesis, ICMC/USP, August 8 2005.

    16