me471_lec03

Embed Size (px)

Citation preview

  • 8/9/2019 me471_lec03

    1/8

    Introduction to Galerkinand Variational Methods

    We have seen that the idea of using the weak form of a differential equation together with the idea

    of looking for the solution of the weak form in a nite dimensional subspace lead to an effectivemeans for generating approximate solutions to our model boundary value problem. This method of generating numerical approximations is called the Galerkin method.

    Before looking further at further examples of the Galerkin method methods, I will list a few commentsintended to enhance your understanding of the method, and how it relates to the concept of bestapproximation in a subspace.

    1. Energy inner product and norm . It is easy to see that the bilinear form a(u, v ), u ,v V satises all the requirements for an inner product on the linear space V. In particular, it isclear that a(u, u ) = 0 AE (u )2 + cu2 dx ≥ 0, and if a(u, u ) = 0 it must be true that u ≡ 0.This is obvious when c > 0, if c ≡ 0 then u = 0 so u = b =constant. Then since u V entailsu(0) = 0, it follows that b = 0 . Thus, the pair V, a(·, ·) forms an inner product space (wecall a the energy inner product), and we can dene the energy norm u E =

    a(u, u ) so that

    V, · E is a normed space.

    2. Best approximation . We now see that the problem of nding u V such that a(u, v) =(f, v ) v V takes place in a normed space, and we can now show that the Galerkin methodleads to the best approximation un to the solution from the nite dimensional subspace V n .That is un = min w n V n wn − u E . This follows directly from the observations: a(un , vn ) =(f, v n ) vn V n V , and a(u, vn ) = ( f, v n ) for u the actual solution. Subtracting we nd thata(u − un , vn ) = 0 vn V n so that u − un is perpendicular to V n . This property, as we’vepreviously seen, implies that un is the best approximation from V n .

    3. Need for sparse stiffness matrices. An objection to the use of polynomials as the basiselements {φi } of our approximating subspace is that the resulting stiffness matrix, [ a(φi , φj )],may have many nonzero entries, and this fact can pose a heavy computational burden. For

    example, with approximating subspace of, say, dimension 100, a fully populated stiffness matrixwould have 10,000 elements to be computed and would, in addition, be difficult to invert. Theideal basis functions should be easy to work with and lead to sparse stiffness matrices (i.e.,matrices with many 0 elements).

    4. Finite element basis functions . The nite element approach to choosing basis elements forthe Galerkin method is (in 1D) to divide the interval over which the equation is to be satisedinto a nite number of parts, and in each of these parts to use a polynomial approximation tothe solution. E.g., choose points x0 = 0 < x 1 , · · · < x n < x n +1 = in the interval [0 , ], andtake V n as the set of continuous functions that are linear in each subinterval [ x i , x i +1 ], i =0, . . . , n and vanish at 0 , (i.e., continuous, piecewise linear functions). V n is a subspace of C ([0, ]) of dimension n – corresponding to values of v V n at the points x i , i = 1 , . . . , n . Thischoice of basis functions leads to sparse stiffness matricies as we will discover shortly.

    5. A technical difficulty There is problem that has to be mentioned with the nite element basisfunctions just described. Consider the continuous piecewise linear functions with, say, n = 2for simplicity. A typical v V 2 looks like

    1

  • 8/9/2019 me471_lec03

    2/8

    x 0 x1 x2 x 3

    It is clear that the function v is continuous but has only one derivative, and this derivative isonly piecewise continuous (actually piecewise constant). Thus, V 2 is not a subspace of V whoseelements must have two continuous derivatives. The way around this dilemma is to extend thenotion of a solution, i.e., enlarge the space V so that it contains subspaces of nite elementpiecewise polynomials. We won’t worry about how to do this, and will verify by examples thatwe haven’t made the approximating subspaces too large. Thus, at least within the context of this course, the difficulties just discovered may be forgotten, and we may assume whenevernecessary that the space V contains the nite element subspaces to be introduced.

    To present the basic ideas of the nite element method and at the same time generalize our sampleproblem, we’ll consider a boundary value problem (BVP) for the ordinary differential equation of the type we’ve been studying, but with some extra features. Let p = 0 R be given and setV p = {w C 2 ([0, 1]) : w(0) = p}, i.e. functions having two continuous derivatives and taking aspecied value at the left end point. We formulate our BVP as follows:

    Problem P 1 : nd u V p satsifying L(u) = − u + u = f (x), 0 < x < 1, u (1) = q,

    where q R and f C ([0, 1]) are given.

    The new features of this BVP are: 1.) A nonzero boundary condition on the unknown functionhas been added at the left end point. 2.) The right hand boundary condition has been changed torequire that the rst derivative take a given value. (In the elastic rod case, this would correspondto a prescribed value of stress at x = 1 – recall σ = Eu . Note that the left end condition hasbeen incorporated into the denition of V p – conditions on the unknown function are called essentialconditions – whereas the right hand condition is given explicitly.

    Our approach to numerial approximation requires that we start with the weak form. How do we getit for this new problem? Recall that we showed the equvalence of the weak form and the BVP simplyby using integration by parts. We can do this with our new problem. Dene the linear subspaceof C 2 ([0, 1]) by V 0 = {w C 2 ([0, 1]) : w(0) = 0 } (note only the value at the left hand end point isrequired to be 0). For u V p satisfying P 1 and any v V 0 we have

    0 = 1

    0 v(Lu − f ) dx = 1

    0 (− u v + uv − fv ) dx,

    and integrating the rst term by parts

    1

    0− u v dx =

    1

    0(− (u v) + u v ) dx = − u v|10 +

    1

    0u v dx = − qv(1) +

    1

    0u v dx

    2

  • 8/9/2019 me471_lec03

    3/8

    where we’ve used the facts that v(0) = 0 and u (1) = q. Substuting we have

    − qv(1) + 1

    0(u v + uv − fv ) dx = − qv(1) + a(u, v) − (f, v ) = 0 ,

    where as before

    a(u, v) = 1

    0(u v + uv) dx, (f, v ) =

    1

    0fvdx, u V p , v V 0

    In summary, u V p satises P 1 implies

    a(u, v) = ( f, v ) + qv(1) for all v V 0 .

    But now we can reverse the process just completed and nd the P 1 is equivalent to

    Problem P 2 : nd u V p such that a(u, v) = ( f, v ) + qv(1) for all v V 0

    Note that the only difference between V p and V 0 is that functions in V p are required to take the value p = 0 at x = 0, where as those in V 0 vanish there. V 0 is a linear space (since v, w V 0 v + w andαv V 0 ), but V p is not – e.g. if v(0) = p then αv / V p unless α = 1. In fact, if v̂ V p is any xedelement of V p , then all other elements v are of the form v = v̂ + w, w V 0 (since the difference of any two elements of V p belongs to V 0 ). Thus, V p is just a translated version of the linear space V 0– the dimension of V p is dened as the dimension of V 0 (it is called an affine subspace of V ratherthan a linear subspace).

    Ignoring the fact P 1 and hence P 2 can be solved exactly for any f , we will try to nd an approximatenumerical solution. Using a small generalization of the previous Galerkin approach, we seek theapproximate solution u in a nite dimensional subspace of V p,n V p , and we require that P 2 besatised for all v V 0 ,n where V p,n and V 0 ,n are n dimensional subspaces of V (any u V p,n ison the form û + v with û a xed element of V p,n and v V 0 ,n ). (u will usually be called the trialfunction and any v will be called a test function.)

    Of course, we could work with polynomials again, but now we introduce the nite element ideas.We dene a grid of points in the interval [0 , 1], and call these points xi , i = 1 , . . . , n + 1 where0 = x1 < · · · < x n +1 = 1, and xi +1 − x i ≡ hi , i = 1 , . . . , n is the grid spacing. Usually, these pointswill be evenly spaced, hi = 1 /n , but at this point we won’t enforce this restriction. We take V p,nto be the space of continuous, piecewise linear functions u on [0, 1] such that u(0) = p, u is linearin each subinterval [ x i , x i +1 ], with u(x i ) = u i , i = 1 , . . . , n . We take V 0 ,n to be the same space butwith the value 0 specied at x = 0 . Any function in either space is determined entirely by its valuesat the n points x i , i = 2, . . . , n + 1, and this implies that the spaces are n dimensional. In fact we’llnow dene a useful system of basis functions with n elements.

    Consider three grid points xe − 1 , xe , xe +1 , and let v V 0 ,n (or V p,n ) have the values ve − 1 , ve , ve +1at these points as shown in the sketch below.

    3

  • 8/9/2019 me471_lec03

    4/8

    The trial or test functions are linear on each interval, or element, I e = [xe , x e +1 ] of the grid.Thus, on element e − 1 we have v = ve − 1 (xe − x)/h e − 1 + ve (x − xe − 1 )/h e − 1 and on element e,v = ve (xe +1 − x)/h e + ve +1 (x − xe )/h e . That is, on each element I e , a test or trial function v canbe expressed as a linear combination of two element basis functions H e1 (x) = ( xe +1 − x)/h e andH e2 (x) = ( x − xe )/h e , i.e., we can write v| I e =

    2j =1 ve + j − 1 H

    ej , where the notation v| I e indicates the

    restriction of v to element e. Combining the expressions for v on the separate elements, we arrive ata formula which holds for all of I

    v(x) =n +1

    i =1

    φi (x)vi

    with

    φ1 (x) = H 11 (x), x1 = 0 ≤ x < x 2 ,

    0, x2 ≤ x < 1 φn +1 (x) =

    0, 0 ≤ x ≤ xn ,H n2 (x), xn < x ≤ 1 = xn +1

    and

    φj (x) =

    0, 0 ≤ x < x j − 1H j − 12 (x), xj − 1 ≤ x < x j

    H j

    1 (x), xj ≤ x < x j+1

    0, xj +1 ≤ x ≤ 1

    , j = 2, . . . , n ,

    where v1 = 0 for a test function and v1 = p for the trial function. The φi ’s, sketched below, areoften called tent functions for obvious reasons.

    4

  • 8/9/2019 me471_lec03

    5/8

  • 8/9/2019 me471_lec03

    6/8

    and

    φj (x) =

    0, x ≤ xj − 11/h j − 1 , xj − 1 < x < x j− 1/h j , xj < x < x j +10, x ≥ xj +1

    , j = 2, . . . , n

    Thus, if c = 0 and the grid spacing is constant grid spacing we have

    K |c=0 = 1h

    1 − 1 0 0 · · · 0− 1 2 − 1 0 · · · 0

    0 . . . . . . . . .

    ......

    0 0 · · · − 1 2 − 10 0 · · · 0 − 1 1

    If c = 0, we must add the elements kc,ij = c 1

    0 φi φj dx. We nd for the diagonal elements

    kc,ee =

    I e − 1

    H e − 12 (x)2 dx +

    I e

    H e1 (x)2 dx =

    1

    3(he − 1 + he ), e = 2 , . . . , n ,

    and kc, 11 = h1 / 3, kc,n +1 ,n +1 = hn / 3. Of the off diagonal elements, only those on the rst subdiagonaland superdiagonal are nonzero, and we nd

    kc,e − 1 ,e = I e − 1 H e − 12 (x)H e1 (x) dx = he − 1 / 3,and kc,e,e +1 = he / 3.

    We now have all the elements necessary for obtaining the solution of the differential equation.

    function fem_ex00(n, c, f, p, q)% finite element solution of -u’’+cu=f, u(0)=p,u’(1)=q % using n intervals in [0,1]. Known value of u at x=0 is% included as a additional equation so we start with n+1 unknowns.x=linspace(0,1,n+1)’; h=1/n; % define grid points and spacing% construct the load vectorff=zeros(n+1,1);ff(2:n)=h*f; ff(n+1)=h*f/2+q;kk=kstif(n,c);% enforce boundary condition u(0)=u1=p at x=0kk(1,:)=0; kk(1,1)=1; ff(1)=p;uu=kk\ff; % solve for uuex=uexac(x,c,f, p, q);fprintf(1,’%10s%10s%10s%10s\n’,’x’, ’uapprox’, ’uexact’, ’error’);disp([x, uu, uex, abs(uex-uu)]);plot(x,uu,’k-’, x,uex, ’ko’);%===================================function kmat=kstif(n,c)% stiffness matrix for c=0% kk(1,1)=kk(n+1,n+1)=1/h, all other diagonal elements kk(i,i)=2/h% first sub and super diagonal elements kk=-1/h

    6

  • 8/9/2019 me471_lec03

    7/8

  • 8/9/2019 me471_lec03

    8/8

    A more quantative comparison is given in the output data

    >> fem_ex00(10,4,1,1,2)x uapprox uexact error0 1.0000 1.0000 0.0000

    0.1000 0.9226 0.9230 0.00040.2000 0.8723 0.8730 0.00070.3000 0.8470 0.8480 0.00100.4000 0.8458 0.8470 0.00120.5000 0.8685 0.8700 0.00140.6000 0.9162 0.9178 0.00160.7000 0.9907 0.9925 0.00180.8000 1.0951 1.0969 0.00190.9000 1.2334 1.2354 0.00201.0000 1.4114 1.4134 0.0020

    The computation above is not arranged in the usual FEM fashion. We have not taken advantage

    of the fact that all computations can be performed locally on elements . We will in our futurework arrange things so that the element stiffness matrix and load vectors are computed and thenassembled into the global stiffness matrix and load vector. For the problem just completed, thiselement approach would not achieve any gains in simplicity, but in more complex problems theassembly process becomes necessary for computational efficiency.

    8