By Mark S. Gockenbach (siam, 2010)


Computing the stiffness matrix and the load vector



Download 2.45 Mb.
Page23/25
Date09.06.2018
Size2.45 Mb.
#53772
1   ...   17   18   19   20   21   22   23   24   25

Computing the stiffness matrix and the load vector

Here are the main commands:


help Stiffness1

K=Stiffness1(T,fnk)

Assembles the stiffness matrix for the PDE

-div(k*grad u)=f in Omega,

u=0 on Gamma,

du/dn=0 on Bndy(Omega)-Gamma.

The input fnk can be a (positive) number k or a function

implementing a function k(x,y). If fnk is omitted, it is

assumed to be the constant 1. T describes the triangulation

of Omega. For a description of the data structure T, see

"help Mesh1".
help Load1

F=Load1(T,fnf)

Assembles the load vector for the BVP

-div(a*grad u)=f in Omega,

u=0 on Gamma,

du/dn=0 on Bndy(Omega)-Gamma.

The right hand side function f(x,y) must be implemented in the

function fnf.


Thus, to apply the finite element method to the BVP given above (assuming homogeneous boundary conditions), I need to define the coefficient a(x,y) and the forcing function f(x,y). As an example, I will reproduce the computations from Example 8.10 from the text, in which case a(x,y)=1 and f(x,y)=x.

a=1;

f=@(x,y)x;
Now I compute the stiffness matrix K and the load vector F:
K=Stiffness1(T,a);

F=Load1(T,f);


Finally, I solve the system Ku=F to get the nodal values:


u=K\F;

Given the vector of nodal values (and the mesh), you can graph the computed solution using the ShowPWLinFcn1 command:


help ShowPWLinFcn1

ShowPWLinFcn1(T,U,g)

This function draws a surface plot of a piecewise linear

function defined on a triangular mesh. The inputs are T,

the mesh (see "help Mesh1" for details about this data structure)

and the vector U, giving the nodal values of the function

(typically U would be obtained by solving a finite element

equation).

The optional input g is a vector of nodal values at the

constrained nodes. If g is not given, this vector is taken



to be zero.
ShowPWLinFcn1(T,u)


The above solution does not look very good (not smooth, for instance); this is because the mesh is rather coarse. I will now repeat the calculation on a finer mesh.
T=RectangleMeshD1(16);

ShowMesh1(T)


K=Stiffness1(T,a);

F=Load1(T,f);

u=K\F;

ShowPWLinFcn1(T,u)




For the sake of illustrating mixed boundary conditions, I will solve the same PDE with mixed boundary conditions:
T1=RectangleMeshTopD1(16);

K1=Stiffness1(T1,a);

F1=Load1(T1,f);

u1=K1\F1;



ShowPWLinFcn1(T1,u1)

There are other utility routines included, such as routines for estimating the and energy norms. For a complete list of routines provided, type "help Fem1".



Download 2.45 Mb.

Share with your friends:
1   ...   17   18   19   20   21   22   23   24   25




The database is protected by copyright ©ininet.org 2024
send message

    Main page