• Non ci sono risultati.

Mathematical methods for engineering. The finite element method

N/A
N/A
Protected

Academic year: 2021

Condividi "Mathematical methods for engineering. The finite element method"

Copied!
18
0
0

Testo completo

(1)

Mathematical methods for engineering.

The finite element method

Ana Alonso

University of Trento

Doctoral School in Environmental Engineering - January 25,

2012

(2)

FEM: Remarks on programming

 −∆u = f on Ω = (0, 1) × (0, 1) u = 0 in ∂Ω

Find u ∈ V such that Z

∇u · ∇v dx = Z

f v dx ∀v ∈ V

We consider a triangulation of the domain T h = {K k } nel k=1 and the finite dimensional space V h of piecewise linear functions on T h .

Find u h ∈ V h such that Z

∇u h · ∇v h dx = Z

f v h dx ∀v h ∈ V h

Ana Alonso Mathematical methods for engineering

(3)

The linear system

Let {φ i } ndof i =1 be a base of V h . Then u h (x ) =

ndof

X

j =1

U j φ j (x ) and in particular

Z

∇  ndof X

j =1

U j φ j (x )



·∇φ i (x ) dx = Z

f (x ) φ i (x ) dx ∀i = 1, . . . , ndof

ndof

X

j =1

U j Z

∇φ j (x )·∇φ i (x ) dx = Z

f (x ) φ i (x ) dx ∀i = 1, . . . , ndof

a i ,j = Z

∇φ j (x ) · ∇φ i (x ) dx , f i = Z

f (x ) φ i (x ) dx

A U = f

(4)

The element matrix A K and the element load f K

a i ,j = Z

∇φ j (x ) · ∇φ i (x ) dx =

nel

X

l =1

Z

K l

∇φ j (x ) · ∇φ i (x ) dx

Each element stiffness matrices is a 3 × 3 matrix.

S K =

s 1,1 s 1,2 s 1,3 s 2,1 s 2,2 s 2,3 s 3,1 s 3,2 s 3,3

 In order to calculate s i ,j = R

K ∇φ i · ∇φ j (local numeration) it is easier to work on the reference element.

Analogously f i =

Z

f (x ) φ i (x ) dx =

nel

X

l =1

Z

K l

f (x ) φ i (x ) dx

and we can consider an element load f K that is a vector with three components.

Ana Alonso Mathematical methods for engineering

(5)

Main steps

I Construction and representation of the triangulation.

I Computation of the element stiffness matrices A K and element loads f K .

I Assembly of the global stiffness matrix A and load vector f.

I Solution of the system of equations A U = f.

I Postprocesing.

(6)

Representation of the triangulation

1 2

3

4 5

6 7

8 9

10 11

12 13 14

15

16

elem =

1 1 3 2 . . . 14 3 4 7 7 . . . 16 2 3 2 8 . . . 15

To represent a triangulation we will use:

I A matrix coor containing for each node its coordinates.

I coor has two rows and nnod columns.

I In this way we have numerated the nodes.

I Another matrix elem containg for each element its nodes.

I elem has three rows and nel columns.

I In this way we have a local numeration for the nodes of each triangle.

Ana Alonso Mathematical methods for engineering

(7)

The reference element

0 1

1 P P

P

0 1

2

K ^

K

K K ˆ

This trasformation makes

 0 0

 

p 0 q 0

  1 0

 

p 1 q 1

  0 1

 

p 2 q 2



x = Bˆ x + d ˆ x = B −1 (x − d) with

B =

 p 1 − p 0 p 2 − p 0 q 1 − q 0 q 2 − q 0

 d =

 p 0

q 0



(8)

The element matrix

Concerning the gradients

∂φ i

∂x 1

= ∂ ˆ φ i

∂ˆ x 1

∂ˆ x 1

∂x 1

+ ∂ ˆ φ i

∂ˆ x 2

∂ˆ x 2

∂x 1

= ∂ ˆ φ i

∂ˆ x 1

m 1,1 + ∂ ˆ φ i

∂ˆ x 2

m 2,1 where M = B −1 . Analogously

∂φ i

∂x 2

= ∂ ˆ φ i

∂ˆ x 1

m 1,2 + ∂ ˆ φ i

∂ˆ x 2

m 2,2 Hence

Z

K

∇φ i · ∇φ j d x = |det (B)|

Z

K ˆ

B −T ∇ ˆ φ i · B −T ∇ ˆ φ j d ˆ x

Concerning the functions Z

K

φ i φ j d x = |det (B)| Z

K ˆ

φ ˆ i φ ˆ j d ˆ x

Ana Alonso Mathematical methods for engineering

(9)

The element matrix

Concerning the gradients

∂φ i

∂x 1

= ∂ ˆ φ i

∂ˆ x 1

∂ˆ x 1

∂x 1

+ ∂ ˆ φ i

∂ˆ x 2

∂ˆ x 2

∂x 1

= ∂ ˆ φ i

∂ˆ x 1

m 1,1 + ∂ ˆ φ i

∂ˆ x 2

m 2,1 where M = B −1 . Analogously

∂φ i

∂x 2

= ∂ ˆ φ i

∂ˆ x 1

m 1,2 + ∂ ˆ φ i

∂ˆ x 2

m 2,2 Hence

Z

K

∇φ i · ∇φ j d x = |det (B)|

Z

K ˆ

B −T ∇ ˆ φ i · B −T ∇ ˆ φ j d ˆ x

Concerning the functions Z

K

φ i φ j d x = |det (B)|

Z

K ˆ

φ ˆ i φ ˆ j d ˆ x

(10)

selem

function s=selem(K) for i=1:2

B(:,i)=K(:,i+1)-K(:,1);

end

GFref=[-1 1 0; -1 0 1]; % each column is the gradient

% of the corresponding base function

% in the reference element.

GF=inv(B)’*GFref;

for i=1:3 for j=1:3

s(i,j)=GF(:,i)’*GF(:,j);

end end

s=s*abs(det(B))/2; % 1/2 is the area of the reference

% element

Ana Alonso Mathematical methods for engineering

(11)

Assembly of the global stiffness matrix A

elem =

1 2 2 . . . 30 2 8 3 . . . 36 7 7 8 . . . 35

for l=1:number of elements

calculate the stiffness matrices of the element for i=1:3

for j=1:3

A(elem(i,l),elem(j,l))=A(elem(i,l),elem(j,l))+s(i,j) end

end

end

(12)

The load vector f

I For each element there is a 3 × 1 load vector f i K =

Z

K

f (x)φ i (x) d x i = 1, 2, 3.

I They are calculated using numerical integration.

Then the vector f is assembly

for l=1:number of elements

calculate the load vector of the element for i=1:3

f(elem(i,l))=f(elem(i,l))+fel(i) end

end

Ana Alonso Mathematical methods for engineering

(13)

felem - 1

] Three points quadrature rule:

Z

K

g (x ) dx ≈ |K | 3

3

X

k=1

g (P k )

For i = 1, 2, 3

f i = Z

K

f (x )φ i (x ) dx ≈ |K | 3

3

X

k=1

f (P ki (P k ) = |K |

3 f (P i )

because φ i (P k ) = δ i ,k .

(14)

felem - 2

function f=felem(K,fun) for i=1:3

x=K(1,i);

y=K(2,i);

f(i)=eval(fun);

end for i=1:2

B(:,i)=K(:,i+1)-K(:,1);

end

f=f*abs(det(B))/6; % abs(det(B))/2 is the area of K

Ana Alonso Mathematical methods for engineering

(15)

Input data

I The matrix coor and the matrix elem giving the triangulation.

I A vector bc giving the nodes in the boundary.

I The load f (as a string).

(16)

The program

function sol=femDir(coor,elem,bc,fun) ndof=length(coor);

nelem=length(elem);

A=zeros(ndof);

F=zeros(ndof,1);

for l=1:nelem

K=coor(:,elem(:,l));

s=selem(K);

f=felem(K,fun);

for i=1:3 for j=1:3

A(elem(i,l),elem(j,l))=A(elem(i,l),elem(j,l))+s(i,j);

end

F(elem(i,l))= F(elem(i,l))+f(i);

end end

bound=find(bc(1,:));

intern=find(bc(1,:)-1);

A=A(intern,intern);

F=F(intern);

x=A\F;

sol=zeros(ndof,1);

sol(intern)=x;

sol(bound)=0;

Ana Alonso Mathematical methods for engineering

(17)

creadata

function [coor,elem,bc]=creadata(N) ndof=(N+1)^2;

for j=1:N+1 for i=1:N+1

coor(1,(j-1)*(N+1)+i)=(i-1)/N;

coor(2,(j-1)*(N+1)+i)=(j-1)/N;

end end elem=[];

for j=1:N for i=1:N

k=(j-1)*(N+1)+i;

elemA=[k;k+1;k+N+1];

elemB=[k+1;k+1+N+1;k+N+1];

elem=[elem elemA elemB];

end end

bc=zeros(1,ndof);

for i=1:ndof

aux=coor(1,i)*coor(2,i)*(coor(1,i)-1)*(coor(2,i)-1);

if aux==0 bc(i)=1;

x=coor(1,i);

y=coor(2,i);

end

Ana Alonso Mathematical methods for engineering

(18)

Example

Solve

 −∆u = 8π 2 sin(2πx ) sin(2πy ) in Ω = (0, 1) × (0, 1)

u = 0 on ∂Ω

Solution: u = sin(2πx ) sin(2πy ).

Ana Alonso Mathematical methods for engineering

Riferimenti

Documenti correlati

Proceedings of the 15th International Conference on Signal Processing, Computational Geometry and Artificial Vision (ISCGAV '15).. Proceedings of the 14th International Conference

Proceedings of the 17th International Conference on Mathematical Methods, Computational Techniques and Intelligent Systems (MAMECTIS '15).. Proceedings of the 8th

This year the 16th International Conference on Mathematical and Computational Methods in Science and Engineering (MACMESE '14) was held in Kuala Lumpur, Malaysia, April 23-25,

As a matter of fact, we can observe that, in case Ω is a Lebesgue measurable subset of R n and A is the class of Lebesgue measurable subsets of Ω, simple random variables are

The first line indicates the type of boundary condition (0 for Dirichlet boundary condition and 1 for Neumann boundary condition), the second one contains the boundary data....

I nelem lines with the three nodes of each element and a label (for subdomains)... Choosing the

 Objects that occur in one grouping occur also in the other one but are repeated a different number of times. Arrangements

Applicants who are interested in applying also for scholarships for specific research subject (reserved scholarships) must specify it in the online