me471s03_lec08

7

Click here to load reader

Upload: hasen-bebba

Post on 01-Jun-2018

218 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: me471s03_lec08

8/9/2019 me471s03_lec08

http://slidepdf.com/reader/full/me471s03lec08 1/7

Laplace Equation Problem with Boundary Flux Prescribed

In this lecture we study an example which illustrates the application of both essential and naturalboundary conditions. We let D  be a rectangular domain and consider the boundary value problems

of the general form

−∆u =  f (x, y) ∈  D, u =  g1,   (x, y) ∈  ∂D1,  ∂u

∂n = g2   (x, y) ∈  ∂D2,

where ∂ D  =  ∂ D1 ∪ ∂D2, and the functions  f   : D  →  R, and  gj   :  ∂Dj  →  R, j  = 1, 2 are given. It isvery important to note that the weak form for this equation is

 D

∇w · ∇u dA =

 D

wf dA +

 ∂D2

w∂u

∂n d

where  w   is the test function and   u   is the trial function. The weak form reveals that if  ∂u/∂n  =g2() = 0 on   ∂D2, then the natural boundary condition can be ignored. However, if   g2   = 0 on∂D2  then the element and global load vectors must be modified to account for the contribution of 

 ∂D2 w∂u/∂nd. This is in complete analogy with the one dimensional case (in which  ∂D2 reduces toa single point). The weak form also reveals the form of the element stiffness and load matrices. Let

D  be divided into elements,  D  =  ∪nele   E e, so that the integral over  D  becomes the sum of integrals

over elements  E e, and the boundary integral becomes a sum of integrals over  ∂ D2 ∩ ∂E e.

 D

∇w · ∇u dA =

nele=1

 E e

∇w · ∇u dA

and  D

wf dA +

 ∂D2

w∂u

∂n d  =

nele=1

 E e

wf dA +

 ∂D2∩∂E e

w∂u

∂n d

Recall that if we represent  u  using global shape functions  u  =

 nnj=1 φjuj   (nn  =number of nodes)

and take w  =  φi, then  ∇w · ∇u =nn

j=1∇φi · ∇φjuj . Thus, we have for example

 E e

∇w · ∇u dA =

nnj=1

 E e

∇φi|E e · ∇φj |E e dA

uj  =

nn

j=1

K e

[u1, . . . , unn ]T 

where the  K e are nn × nn  matrices which have only  n2 nonzero element, where  n  is the number of nodes per element. By establishing a mapping between the local node numbers on each element andthe global node numbers in the problem we are able to focus on single elements and interpret eachK e as (a much smaller) n × n   element matrix. Similar remarks apply to the integrals appearing inthe load vector. In the discussion below, we assume the required mapping has been established andfocus on the element matrices. (In our programs, the array  nodes  gives the mapping when there isonly one degree of freedom (dof) per node. If there are several dof per node, then the matrix  index

gives the required map.)Let E  denote any element with boundary  ∂ E  (the element number e  is fixed for this discussion andwill not be indicated). Then on E  the trial function can be written as  u|E   =

 nj=1 H juj   =  H T U ,

with   n   the number of nodes per element (not   the total number of nodes!),   H   = [H 1, . . . , H  n]T ,the element shape functions, and  U   = [u1, . . . , un]T  the nodal values of the trial function on  E   (of 

Page 2: me471s03_lec08

8/9/2019 me471s03_lec08

http://slidepdf.com/reader/full/me471s03lec08 2/7

course, the numbering is in terms of local node numbers). Since  w  can be any of the  n  componentsof  H , we have can arrange the possible values of the integral over  E   into an n  component vector asfollows:    

E H xH T x   + H yH T y

 dA

U  = K U 

where K  is the n×n element stiffness matrix, H x = [∂H 1/∂x, . . . , ∂H n/∂x]T , and H y is the analogousmatrix of derivatives with respect to  y .  The element load vector can be treated in a similar way toyield the element load vector

 E 

Hf dA +

 ∂D2∩∂E 

Hg2 d =  F.

The problem to be considered is adopted from our textbook Ex 5.9.1 but with the natural boundarycondition no longer homogeneous. Keeping the same notation for the geometry (so that  D  =  {(x, y) :

a < x < c,b < y < d}), we must account for the term ∂D2

w∂u/∂nd = db

  w∂u/∂x(c, y) dy  where

w  is a test function. We need to see what happens when a test function  w  (which if we neglect theconstraints imposed by the essential boundary conditions, can take any of the values H j , j  = 1, . . . , 4

in an element) is evaluated on the   x  =   c   edge (the right hand edge) of the rectangle. If  E   is anelement such that  ∂ E  ∩ ∂D2  =  ∂E 2  = ∅, then it is easy to see that

H j |∂E 2 =

0,   for j  = 1, 4hj(y),   for j  = 2, 3

where  h2(y) = (y3 − y)/y3 − y2, h3(y) = (y − y2)/y3 − y2. Of course, these functions are just thelinear 1D shape functions that we’ve studied when considering ODEs. To evaluate the contributionto the load vector from these elements, we only need to find the values of  y2, y3  for the element andintegrate the given function  g2(y) multiplied by  hj(y) between these limits. You will see this donein our example.

A bit of caution must be exercised when computing the contribution of the element flux to the loadvector. Namely, if an essential boundary condition is prescribed at one of the nodal points, say  k, on

∂E 2, then the test function  w  must vanish there – so that a 0 must be substituted for the componentH k   of  H , or the component  F k  must be set equal to 0. This can only happen if node  k   is an endpoint of  ∂ E 2  because we know that u  is not prescribed in the interior of the boundary element. (Atthis point we have not looked at elements with interior points – so  k  has to be an end point.)

We need to decide how to compute the integral   I   = y3y2

hj(y)g(y) dy. At this point, we haven’tstudied numerical integration so we’ll adopt what seems like a reasonable method and worry aboutaccuracy later. We assume that   g   can be accurately represented for   y2   ≤   y  ≤   y3   by its linearinterpolation g  ≈  g2h2(y) + g3h3(y) =

3

j=2 gjhj(y),  where gj  =  g(yj), j  = 2, 3.  In this case,

[I 2, I 3]T  =

   y3y2

[h2, h3]T [h2, h3] dy

[g2, g3]T  = B

g2g3

,

and the matrix  B  is easily found to be

B = (y3 − y2)

6

2 11 2

function laplace_ex02(bl, ur, nx, ny)

Page 3: me471s03_lec08

8/9/2019 me471s03_lec08

http://slidepdf.com/reader/full/me471s03lec08 3/7

Page 4: me471s03_lec08

8/9/2019 me471s03_lec08

http://slidepdf.com/reader/full/me471s03lec08 4/7

%-----------------------------------------

% initialization of matrices and vectors

%-----------------------------------------

ff=zeros(sdof,1); % initialization of system force vector

kk=zeros(sdof,sdof); % initialization of system matrix

index=zeros(nnel*ndof,1); % initialization of index vector

%-----------------------------------------------------------------

% computation of element matrices and vectors and their assembly

%-----------------------------------------------------------------

for iel=1:nel % loop for the total number of elements

for i=1:nnel

nd(i)=nodes(iel,i); % extract connected node for (iel)-th element

x(i)=gcoord(nd(i),1); % extract x value of the nodey(i)=gcoord(nd(i),2); % extract y value of the node

end

xleng = x(2)-x(1); % length of the element in x-axis

yleng = y(4)-y(1); % length of the element in y-axis

index=feeldof(nd,nnel,ndof);% extract system dofs associated with element

k=felp2dr4(xleng,yleng); % compute element matrix

kk=feasmbl1(kk,k,index); % assemble element matrices

end

%-----------------------------

% compute boundary contribution to load vector

%-----------------------------

% loop over elements on edge x=ur(1), bl(2)<=y<=ur(2)

% to compute contributions to load vector from flux

for elno=nx:nx:nx*ny

nd=nodes(elno,:); % global nodes of element number elno

y1=gcoord(nd(2),2); y2=gcoord(nd(3),2); % y coordinates of left edge

gv=bdryfnc([y1,y2],[bl(2),ur(2)]);

eflx=elflux(y1,y2,gv); % compute element contribution to load vector

ff(nd(2))=ff(nd(2))+eflx(1);

ff(nd(3))=ff(nd(3))+eflx(2);end

%-----------------------------

% apply boundary conditions

Page 5: me471s03_lec08

8/9/2019 me471s03_lec08

http://slidepdf.com/reader/full/me471s03lec08 5/7

%-----------------------------

[kk,ff]=feaplyc2(kk,ff,bcdof,bcval);

%----------------------------

% solve the matrix equation

%----------------------------

fsol=kk\ff;

%---------------------

% analytical solution

%---------------------

for i=1:nnode

x=gcoord(i,1)-bl(1); y=gcoord(i,2)-bl(2);

hx=ur(1)-bl(1); hy=ur(2)-bl(2);

esol(i)=100*hy*sinh(pi*x/hy)*sin(pi*y/hy)/(pi*cosh(pi*hx/hy));end

%------------------------------------

% print both exact and fem solutions

%------------------------------------

fprintf(1,’%10s%10s%10s%10s%10s\n’,’node’,’x’,’y’,’approx’,’exact’);

num=1:1:sdof;

fprintf(’%10d%10.4f%10.4f%10.4f%10.4f\n’, [num’ gcoord(:,1), gcoord(:,2),fsol esol’]’);

%---------------------------------------------------------------

function [index]=feeldof(nd,nnel,ndof)edof = nnel*ndof;

k=0;

for i=1:nnel

start = (nd(i)-1)*ndof;

for j=1:ndof

k=k+1;

index(k)=start+j;

end

end

%----------------------------------------------------------

function [kk]=feasmbl1(kk,k,index)

%----------------------------------------------------------% Purpose:

% Assembly of element matrices into the system matrix

%

% Synopsis:

Page 6: me471s03_lec08

8/9/2019 me471s03_lec08

http://slidepdf.com/reader/full/me471s03lec08 6/7

Page 7: me471s03_lec08

8/9/2019 me471s03_lec08

http://slidepdf.com/reader/full/me471s03lec08 7/7

end

kk(c,c)=1;

ff(c)=bcval(i);

end

%---------------------------------------------------------------

function [k]=felp2dr4(xleng,yleng)

%-------------------------------------------------------------------

% Purpose:

% element matrix for two-dimensional Laplace’s equation

% using four-node bilinear rectangular element

%

% Synopsis:

% [k]=felp2dr4(xleng,yleng)

%% Variable Description:

% k - element stiffness matrix (size of 4x4)

% xleng - element size in the x-axis

% yleng - element size in the y-axis

%-------------------------------------------------------------------

% element matrix

k(1,1)=(xleng*xleng+yleng*yleng)/(3*xleng*yleng);

k(1,2)=(xleng*xleng-2*yleng*yleng)/(6*xleng*yleng);

k(1,3)=-0.5*k(1,1);

k(1,4)=(yleng*yleng-2*xleng*xleng)/(6*xleng*yleng);

k(2,1)=k(1,2); k(2,2)=k(1,1); k(2,3)=k(1,4); k(2,4)=k(1,3);k(3,1)=k(1,3); k(3,2)=k(2,3); k(3,3)=k(1,1); k(3,4)=k(1,2);

k(4,1)=k(1,4); k(4,2)=k(2,4); k(4,3)=k(3,4); k(4,4)=k(1,1);

%-------------------------------------------------------------------

function eflx=elflux(y1,y2, gv)

% Compute int_y1^y2 [h2,h3]’g(y)dy, where h_j are the 1D linear

% shape functions, using linear interpolation. gv=[g(y1),g(y2)]^T

eflx=((y2-y1)/6)*[2 1;1 2]*gv;

%-------------------------------------------------------------------

function g=bdryfnc(y,dy)

hy=dy(2)-dy(1);

z=[(y(1)-dy(1))/hy; (y(2)-dy(1))/hy]g=100*sin(pi*z);