Einführung in die Finite Element Methode Projekt 2 · Einführung in die Finite Element Methode...

Preview:

Citation preview

Einführung in die Finite Element MethodeProjekt 2

Juri Schmelzer und Fred Brockstedt

17.7.2014

Juri Schmelzer und Fred Brockstedt Einführung in die Finite Element Methode Projekt 2 17.7.2014 1 / 29

Project 2 -Tasks

1 Study Section 3.4 of the lecture notes2a) Write conforming mesh generator2b) Write non conforming mesh generator3 Rewrite the solver for hanging nodes4 Convergence analysis

Juri Schmelzer und Fred Brockstedt Einführung in die Finite Element Methode Projekt 2 17.7.2014 2 / 29

Agenda

1 Tasks

2 Mesh generator

3 Adapting the finite element solver

4 Convergence analysis

5 Demo

6 Questions

Juri Schmelzer und Fred Brockstedt Einführung in die Finite Element Methode Projekt 2 17.7.2014 3 / 29

Mesh generator

TaskWrite a conforming/non-conforming mesh generator.

Definition (Mesh)

A MeshM of a computational domain Ω ⊂ R2 is a collection of cellsKkMk=1 und M = |M|.

Algorithm1 Generate nodes2 Find the corresponding elements (triangles)3 Find hanging nodes

Juri Schmelzer und Fred Brockstedt Einführung in die Finite Element Methode Projekt 2 17.7.2014 4 / 29

Conforming mesh generatorSeries 4In series 4 we already wrote a mesh generator for conforming meshes, withthe help of Mesh2d.

Juri Schmelzer und Fred Brockstedt Einführung in die Finite Element Methode Projekt 2 17.7.2014 5 / 29

Adaptation of a conforming mesh generator

ProblemWith every uniform refinement, refine.m squares the amount of nodes.

GoalMesh with fewer nodes. Refine towards the origin using Mesh2d.

Juri Schmelzer und Fred Brockstedt Einführung in die Finite Element Methode Projekt 2 17.7.2014 6 / 29

Implementation

M = size(t,1); % find the triangle at the origint = sortrows(t, 1);ti = false(M,1);ti(1) = true;[p t] = refine(p,t,ti); % refine towards the

% triangle at the origin

ProblemMesh2d will malfunction. So patch line 129 in Mesh2d/refine.m with

t e ( s p l i t 1 , : )= s o r t ( t e ( s p l i t 1 , : ) ) ;

Juri Schmelzer und Fred Brockstedt Einführung in die Finite Element Methode Projekt 2 17.7.2014 7 / 29

Non conforming mesh generator

Juri Schmelzer und Fred Brockstedt Einführung in die Finite Element Methode Projekt 2 17.7.2014 8 / 29

Non conforming mesh generator

Definition (hanging node)A node of a meshM that is located in the interior of a geometric face ofone of its cells is known as hanging node.

Definition (non conforming mesh)A non conforming mesh is a mesh with hanging nodes.

Juri Schmelzer und Fred Brockstedt Einführung in die Finite Element Methode Projekt 2 17.7.2014 9 / 29

Non conforming mesh generator

Special case for unit square refined towards the originhandle special nodes (origin, first diagonal point) that are alwayspresent.find the corresponding triangles in the lower left and upper right.find the hanging nodes on the subdiagonal.

Juri Schmelzer und Fred Brockstedt Einführung in die Finite Element Methode Projekt 2 17.7.2014 10 / 29

Non conforming mesh generatorImplementation

r = r +1; % amount o f r e f i n emen t snodes = 1 . / 2 . ^ 0 : r ; % nodes on the d i a g on a l w i thou t

% 0 and 1 i n r e v e r s e o r d e rp = [0 0 ] ; % s t a r t a t the o r i g i n%% c r e a t e the t h r e e s p e z i a l nodes ,% numbered coun t e r c l o c k w i s ep ( end+1, : ) = [ nodes ( end ) 0 ] ;p ( end+1, : ) = [ nodes ( end ) nodes ( end ) ] ;p ( end+1, : ) = [0 nodes ( end ) ] ;

%% c r e a t e the t r i a n g l e st = [ 1 2 4

2 3 4] ;

Juri Schmelzer und Fred Brockstedt Einführung in die Finite Element Methode Projekt 2 17.7.2014 11 / 29

Non conforming mesh generator

the first onion ringCreate the 5 new points and the 6 new triangles.

Juri Schmelzer und Fred Brockstedt Einführung in die Finite Element Methode Projekt 2 17.7.2014 12 / 29

Non conforming mesh generator

%% c r e a t e 5 new nodesp ( end+1, : ) = [ nodes ( k ) 0 ] ; % boundary x−a x i s node

% save the p o i s i t i o n o f the f i r s t new% node f o r our t r i a n g l e c r e a t i o nnode Index = l e n g t h ( p ) ;

p ( end+1, : ) = [ nodes ( k ) nodes ( k +1) ] ;p ( end+1, : ) = [ nodes ( k ) nodes ( k ) ] ;p ( end+1, : ) = [ nodes ( k+1) nodes ( k ) ] ;p ( end+1, : ) = [0 nodes ( k ) ] ;

Juri Schmelzer und Fred Brockstedt Einführung in die Finite Element Methode Projekt 2 17.7.2014 13 / 29

%% wr i t e down the 6 new t r i a n g l e s% the 2 bottom r i g h t t r i a n g l e st ( end+1, : ) = [ nodeIndex−5 node Index nodeIndex −3] ;t ( end+1, : ) = [ node Index node Index+1 nodeIndex −3] ;

% the 2 top r i g h t t r i a n g l e st ( end+1, : ) = [ nodeIndex−3 node Index+1 node Index +3] ;t ( end+1, : ) = [ node Index+1 node Index+2 node Index +3] ;

% 2 t r i a n g l e s to the top l e f tt ( end+1, : ) = [ nodeIndex−1 nodeIndex−3 node Index +4] ;t ( end+1, : ) = [ nodeIndex−3 node Index+3 node Index +4] ;

%% save the hang ing nodeshn ( end+1, : ) = [ node Index+1 node Index node Index +2] ;hn ( end+1, : ) = [ node Index+3 node Index+2 node Index +4] ;

Juri Schmelzer und Fred Brockstedt Einführung in die Finite Element Methode Projekt 2 17.7.2014 14 / 29

Non conforming mesh generator

AlgorithmIf the above points and elements have been generated, apply the followingalgorithm to refine the mesh.

1 take point on the diagonal [ 12n ,

12n ]

2 make boundary node and hanging node to the left and the bottom3 create the corresponding triangles4 save the hanging nodes and their neighbours

after the last iteration remove the two hanging nodes

Generating the non conforming meshRepeat for r refinements.

Juri Schmelzer und Fred Brockstedt Einführung in die Finite Element Methode Projekt 2 17.7.2014 15 / 29

Memory usage

Juri Schmelzer und Fred Brockstedt Einführung in die Finite Element Methode Projekt 2 17.7.2014 16 / 29

DefinitionP is a hanging Node if the following conditions are fullfilled:

P is part of a triangle in the 2D meshP lies on a side of an other triangle and is not on of its corner

In our case they are the middlepoint of two non-hanging Nodes.The assembling part of stiffness, mass, load and neumannload needs to berewritten for it.

Juri Schmelzer und Fred Brockstedt Einführung in die Finite Element Methode Projekt 2 17.7.2014 17 / 29

DefinitionP is a hanging Node if the following conditions are fullfilled:

P is part of a triangle in the 2D meshP lies on a side of an other triangle and is not on of its corner

In our case they are the middlepoint of two non-hanging Nodes.

The assembling part of stiffness, mass, load and neumannload needs to berewritten for it.

Juri Schmelzer und Fred Brockstedt Einführung in die Finite Element Methode Projekt 2 17.7.2014 17 / 29

DefinitionP is a hanging Node if the following conditions are fullfilled:

P is part of a triangle in the 2D meshP lies on a side of an other triangle and is not on of its corner

In our case they are the middlepoint of two non-hanging Nodes.The assembling part of stiffness, mass, load and neumannload needs to berewritten for it.

Juri Schmelzer und Fred Brockstedt Einführung in die Finite Element Methode Projekt 2 17.7.2014 17 / 29

How to compute the T-matrix?

Juri Schmelzer und Fred Brockstedt Einführung in die Finite Element Methode Projekt 2 17.7.2014 18 / 29

How to compute the T-matrix?

Juri Schmelzer und Fred Brockstedt Einführung in die Finite Element Methode Projekt 2 17.7.2014 18 / 29

The T-Matrix can be computed with the following steps:

1 If Pj(K ) is not hanging Node, than Ti ,j = 1 if Pj(K ) = Pi (M)

2 If Pj(K ) is a hanging Node, than get the neighbours of Pj(K ) i.e.Q1,Q2 and set Ti ,j = 1

2 if P(Q1) = Pi (M) ∨ P(Q2) = Pi (M) withP(Qi ) describing the index of Qi in the mesh

3 Any other entry is set to 0.With this we get a sparse matrix with 5 entries at most for our mesh.

Juri Schmelzer und Fred Brockstedt Einführung in die Finite Element Methode Projekt 2 17.7.2014 19 / 29

The T-Matrix can be computed with the following steps:1 If Pj(K ) is not hanging Node, than Ti ,j = 1 if Pj(K ) = Pi (M)

2 If Pj(K ) is a hanging Node, than get the neighbours of Pj(K ) i.e.Q1,Q2 and set Ti ,j = 1

2 if P(Q1) = Pi (M) ∨ P(Q2) = Pi (M) withP(Qi ) describing the index of Qi in the mesh

3 Any other entry is set to 0.With this we get a sparse matrix with 5 entries at most for our mesh.

Juri Schmelzer und Fred Brockstedt Einführung in die Finite Element Methode Projekt 2 17.7.2014 19 / 29

Code

defining the coordinates of the triangle, initialising the T-Matrix andsearching for hanging nodes in the triangle and which of them is a hangingNode

f o r k=1:Mc o o r d i n a t e s = p ( t ( k , : ) , : ) ;containHangNode=ismember ( t ( k , : ) , hang ( : , 1 ) ) ;T=z e r o s ( l e n g t h ( p ) , 3 ) ;m=f i n d ( containHangNode ) ;Q=[1 , 2 , 3 ] ;Q(m)= [ ] ;

Juri Schmelzer und Fred Brockstedt Einführung in die Finite Element Methode Projekt 2 17.7.2014 20 / 29

Code

If triangle without hanging node than creating the usual T-Matrix

i f ( abs ( containHangNode)==0)T( t ( k , 1 ) , 1 )=1 ;T( t ( k , 2 ) , 2 )=1 ;T( t ( k , 3 ) , 3 )=1 ;

Juri Schmelzer und Fred Brockstedt Einführung in die Finite Element Methode Projekt 2 17.7.2014 21 / 29

Code

setting 1 for nonhanging nodes in the triangle and 12 on the neighbours of

the hanging Nodes.

e l s ef o r l =1:3−max( s i z e (m) )T( t ( k ,Q( l ) ) ,Q( l ))=1;

endf o r l =1:max( s i z e (m) )

[~ , hang index ]= ismember ( t ( k ,m( l ) ) , hang ( : , 1 ) ) ;T( hang ( hang index , 2 ) ,m( l ))=1/2;T( hang ( hang index , 3 ) ,m( l ))=1/2;

endend

Juri Schmelzer und Fred Brockstedt Einführung in die Finite Element Methode Projekt 2 17.7.2014 22 / 29

Code

Calculating∑

K TKBKTTK = B and removing of hanging node rows and

columns

A=A+spa r s e (T)∗ e l emS t i f f n e s sP 1 ( c o o r d i n a t e s ) ∗ . . .s p a r s e (T ’ ) ;

endA( hang ( : , 1 ) , : ) = [ ] ; A ( : , hang ( : , 1 ) ) = [ ] ;

Juri Schmelzer und Fred Brockstedt Einführung in die Finite Element Methode Projekt 2 17.7.2014 23 / 29

Analytic solution

Problem

−∆u + u = f in Ω = [0, 1]2

∇u · n = g on ∂Ω

TaskChoose f and g such that u := e(−γ(x+y))

Solutionf = e(−γ(x+y)) − 2γ2e−γ(x+y)

g =

(−e−(x+y)γγ

−e−(x+y)γγ

)· n

Juri Schmelzer und Fred Brockstedt Einführung in die Finite Element Methode Projekt 2 17.7.2014 24 / 29

Exact solution of u

Juri Schmelzer und Fred Brockstedt Einführung in die Finite Element Methode Projekt 2 17.7.2014 25 / 29

Analytic solution

TaskChoose γ > 0 and compute the discretization error in the energy norm.

Remember Series 6

||en||e :=√a(u − un, u − un)

u is known and un is the solution of the solver.

a(u − un, u − un) =

∫Ωfudx︸ ︷︷ ︸

solve analyticaly

−∫

Ωfundx︸ ︷︷ ︸u·f

Solution∫ 10

∫ 10 f (x , y)u(x , y)dxdy = 1

4γ2

((1− 2γ2)(e−2γ − 1)2)

Juri Schmelzer und Fred Brockstedt Einführung in die Finite Element Methode Projekt 2 17.7.2014 26 / 29

Convergence Analysis

Juri Schmelzer und Fred Brockstedt Einführung in die Finite Element Methode Projekt 2 17.7.2014 27 / 29

Convegence Analysis

nodes conform hanging uniform9 0.0188 0.0072 0.007215 0.0857 0.0042 ≈ 0.007018 0.0549 0.0040 -24 0.0224 0.0040 ≈ 0.006027 0.0181 0.0040 -36 0.0163 0.0040 0.005148 0.0162 0.0040 ≈ 0.004451 0.0162 0.0040 -

Juri Schmelzer und Fred Brockstedt Einführung in die Finite Element Methode Projekt 2 17.7.2014 28 / 29

Questions

Questions, remarks and comments!

Juri Schmelzer und Fred Brockstedt Einführung in die Finite Element Methode Projekt 2 17.7.2014 29 / 29

Recommended