Basic Concepts in 1-D -Basic Concepts in 1-D - OOutlineutlineIgel/Downloads/Nmgiifembasic.pdfBasic...

28
Numerical Methods in Geophysics Finite Elements Basic Concepts in 1-D - Outline Basic Concepts in 1-D - Outline Basics - Formulation - Basis functions - Stiffness matrix Poisson’s equation - Regular grid - Boundary conditions - Irregular grid Numerical Examples

Transcript of Basic Concepts in 1-D -Basic Concepts in 1-D - OOutlineutlineIgel/Downloads/Nmgiifembasic.pdfBasic...

Page 1: Basic Concepts in 1-D -Basic Concepts in 1-D - OOutlineutlineIgel/Downloads/Nmgiifembasic.pdfBasic Concepts in 1-D -Basic Concepts in 1-D - OOutlineutline Basics - Formulation-B asis

Numerical Methods in Geophysics Finite Elements

Basic Concepts in 1-D - OutlineBasic Concepts in 1-D - Outline

Basics- Formulation- Basis functions- Stiffness matrix

Poisson’s equation

- Regular grid- Boundary conditions- Irregular grid

Numerical Examples

Basics- Formulation- Basis functions- Stiffness matrix

Poisson’s equation

- Regular grid- Boundary conditions- Irregular grid

Numerical Examples

Page 2: Basic Concepts in 1-D -Basic Concepts in 1-D - OOutlineutlineIgel/Downloads/Nmgiifembasic.pdfBasic Concepts in 1-D -Basic Concepts in 1-D - OOutlineutline Basics - Formulation-B asis

Numerical Methods in Geophysics Finite Elements

FormulationFormulation

Let us start with a simple linear system of equations

| * y

and observe that we can generally multiply both sides of this equation with y without changing its solution. Note that x,y and b are vectors and A is a matrix.

bAx=

nyybyAx ℜ∈=→

We first look at Poisson’s equation

)()( xfxu =∆−where u is a scalar field, f is a source term and in 1-D

2

22

x∂∂

=∇=∆

Page 3: Basic Concepts in 1-D -Basic Concepts in 1-D - OOutlineutlineIgel/Downloads/Nmgiifembasic.pdfBasic Concepts in 1-D -Basic Concepts in 1-D - OOutlineutline Basics - Formulation-B asis

Numerical Methods in Geophysics Finite Elements

Formulation – Poisson’s equationFormulation – Poisson’s equation

fvuv =∆−

We now multiply this equation with an arbitrary function v(x), (dropping the explicit space dependence)

... and integrate this equation over the whole domain. For reasons of simplicity we define our physical domain D in the interval [0, 1].

∫∫ =∆−DD

fvuv

dxfvdxuv ∫∫ =∆−1

0

1

0

Das Reh springt hoch,

das Reh springt weit,

warum auch nicht,

es hat ja Zeit.

... why are we doing this? ... be patient ...

Page 4: Basic Concepts in 1-D -Basic Concepts in 1-D - OOutlineutlineIgel/Downloads/Nmgiifembasic.pdfBasic Concepts in 1-D -Basic Concepts in 1-D - OOutlineutline Basics - Formulation-B asis

Numerical Methods in Geophysics Finite Elements

DiscretizationDiscretization

As we are aiming to find a numerical solution to our problem it is clear we have to discretize the problem somehow. In FE problems – similar to FD – the functional values are known at a discrete set of points.

... regular grid ...

... irregular grid ...

Domain DThe key idea in FE analysis is to approximate all functions in terms of basis functions ϕ, so that

i

N

iicuu ϕ∑

=

=≈1

~

Page 5: Basic Concepts in 1-D -Basic Concepts in 1-D - OOutlineutlineIgel/Downloads/Nmgiifembasic.pdfBasic Concepts in 1-D -Basic Concepts in 1-D - OOutlineutline Basics - Formulation-B asis

Numerical Methods in Geophysics Finite Elements

Basis functionBasis function

i

N

iicuu ϕ∑

=

=≈1

~

where N is the number nodes in our physical domain and ci are real constants.

With an appropriate choice of basis functions ϕi, the coefficients ci are equivalent to the actual function values at node point i. This – of course – means, that ϕi=1 at node i and 0 at all other nodes ...

Doesn’t that ring a bell?

Before we look at the basis functions, let us ...

Page 6: Basic Concepts in 1-D -Basic Concepts in 1-D - OOutlineutlineIgel/Downloads/Nmgiifembasic.pdfBasic Concepts in 1-D -Basic Concepts in 1-D - OOutlineutline Basics - Formulation-B asis

Numerical Methods in Geophysics Finite Elements

Partial IntegrationPartial Integration

... partially integrate the left-hand-side of our equation ...

dxfvdxuv ∫∫ =∆−1

0

1

0

[ ] dxuvuvdxvu ∫∫ ∇∇+∇=∇•∇−1

0

10

1

0

)(

we assume for now that the derivatives of u at the boundaries vanish so that for our particular problem

dxuvdxvu ∫∫ ∇∇=∇•∇−1

0

1

0

)(

Page 7: Basic Concepts in 1-D -Basic Concepts in 1-D - OOutlineutlineIgel/Downloads/Nmgiifembasic.pdfBasic Concepts in 1-D -Basic Concepts in 1-D - OOutlineutline Basics - Formulation-B asis

Numerical Methods in Geophysics Finite Elements

... so that we arrive at ...

... with u being the unknown. This is also true for our approximate numerical system

dxfvdxvu ∫∫ =∇∇1

0

1

0

... where ...

dxfvdxvu ∫∫ =∇∇1

0

1

0

~

i

N

iicu ϕ∑

=

=1

~

was our choice of approximating u using basis functions.

Page 8: Basic Concepts in 1-D -Basic Concepts in 1-D - OOutlineutlineIgel/Downloads/Nmgiifembasic.pdfBasic Concepts in 1-D -Basic Concepts in 1-D - OOutlineutline Basics - Formulation-B asis

Numerical Methods in Geophysics Finite Elements

Partial IntegrationPartial Integration

dxfvdxvu ∫∫ =∇∇1

0

1

0

~

... remember that v was an arbitrary real function ... if this is true for an arbitrary function it is also true if

jv ϕ=

... so any of the basis functions previously defined ...

... now let’s put everything together ...

Page 9: Basic Concepts in 1-D -Basic Concepts in 1-D - OOutlineutlineIgel/Downloads/Nmgiifembasic.pdfBasic Concepts in 1-D -Basic Concepts in 1-D - OOutlineutline Basics - Formulation-B asis

Numerical Methods in Geophysics Finite Elements

The discrete systemThe discrete system

The ingredients:kv ϕ=

i

N

iicu ϕ∑

=

=1

~

dxfvdxvu ∫∫ =∇∇1

0

1

0

~

dxfdxc kk

n

iii ϕϕϕ ∫∫ ∑ =∇⎟⎠

⎞⎜⎝

⎛∇

=

1

0

1

0 1

... leading to ...

Page 10: Basic Concepts in 1-D -Basic Concepts in 1-D - OOutlineutlineIgel/Downloads/Nmgiifembasic.pdfBasic Concepts in 1-D -Basic Concepts in 1-D - OOutlineutline Basics - Formulation-B asis

Numerical Methods in Geophysics Finite Elements

The discrete systemThe discrete system

... the coefficients ck are constants so that for one particular function ϕk this system looks like ...

dxfdxc kki

n

ii ϕϕϕ ∫∫∑ =∇∇

=

1

0

1

01

kiki gAb =... probably not to your surprise this can be written in matrix form

kiTik gbA =

Page 11: Basic Concepts in 1-D -Basic Concepts in 1-D - OOutlineutlineIgel/Downloads/Nmgiifembasic.pdfBasic Concepts in 1-D -Basic Concepts in 1-D - OOutlineutline Basics - Formulation-B asis

Numerical Methods in Geophysics Finite Elements

The solutionThe solution

... with the even less surprising solution

( ) kTiki gAb 1−

=

remember that while the bi’s are really the coefficients of the basis functions these are the actual function values at node points

i as well because of our particular choice of basis functions.

This become clear further on ...

Page 12: Basic Concepts in 1-D -Basic Concepts in 1-D - OOutlineutlineIgel/Downloads/Nmgiifembasic.pdfBasic Concepts in 1-D -Basic Concepts in 1-D - OOutlineutline Basics - Formulation-B asis

Numerical Methods in Geophysics Finite Elements

The basis functionsThe basis functions

... otherwise we are free to choose any function ...

The simplest choice are of course linear functions:

+ grid nodes

blue lines – basis functions ϕi

1

2

3

4

5

6

7

8

9

10

we are looking for functions ϕi with the following property ⎩

⎨⎧

≠==

=ijxxfor

xxforx

j

ii ,0

1)(ϕ

Page 13: Basic Concepts in 1-D -Basic Concepts in 1-D - OOutlineutlineIgel/Downloads/Nmgiifembasic.pdfBasic Concepts in 1-D -Basic Concepts in 1-D - OOutlineutline Basics - Formulation-B asis

Numerical Methods in Geophysics Finite Elements

The basis functions - gradientThe basis functions - gradient

To assemble the stiffness matrix we need the gradient (red) of the basis functions (blue)

12

345

6789

10

Page 14: Basic Concepts in 1-D -Basic Concepts in 1-D - OOutlineutlineIgel/Downloads/Nmgiifembasic.pdfBasic Concepts in 1-D -Basic Concepts in 1-D - OOutlineutline Basics - Formulation-B asis

Numerical Methods in Geophysics Finite Elements

The stiffness matrixThe stiffness matrix

Knowing the particular form of the basis functions we can now calculate the elements of matrix Aij and vector gi

dxfdxc kki

n

ii ϕϕϕ ∫∫∑ =∇∇

=

1

0

1

01

dxA kiik ∫ ∇∇=1

0

ϕϕ

kiki gAb =

dxfg kk ϕ∫=1

0

Note that ϕi are continuous functions defined in the interval [0,1], e.g.

⎪⎪⎪

⎪⎪⎪

<<−

≤<−−

= ++

+

−−

elsewhere

xxxforxxxx

xxxforxxxx

x iiii

i

iiii

i

i

0

)( 11

1

11

1

ϕLet us – for now – assume a

regular grid ... then

Page 15: Basic Concepts in 1-D -Basic Concepts in 1-D - OOutlineutlineIgel/Downloads/Nmgiifembasic.pdfBasic Concepts in 1-D -Basic Concepts in 1-D - OOutlineutline Basics - Formulation-B asis

Numerical Methods in Geophysics Finite Elements

The stiffness matrix – regular gridThe stiffness matrix – regular grid

⎪⎪⎪

⎪⎪⎪

<<−

≤<−−

= ++

+

−−

elsewhere

xxxforxxxx

xxxforxxxx

x iiii

i

iiii

i

i

0

)( 11

1

11

1

ϕ

⎪⎪⎪

⎪⎪⎪

<<−

≤<−+

=

elsewhere

dxxfordxx

xdxfordxx

xi

0

~0~

1

0~1~

)~(ϕ

... where we have used ...ϕi

1

~

−−=−=

ii

i

xxdxxxx

xi

dx

Page 16: Basic Concepts in 1-D -Basic Concepts in 1-D - OOutlineutlineIgel/Downloads/Nmgiifembasic.pdfBasic Concepts in 1-D -Basic Concepts in 1-D - OOutlineutline Basics - Formulation-B asis

Numerical Methods in Geophysics Finite Elements

Regular grid - GradientRegular grid - Gradient

⎪⎩

⎪⎨

⎧<<−

≤<−=∇

elsewheredxxfordx

xdxfordxxi

0

~0/10~/1

)~(ϕ1

~

−−=−=

ii

i

xxdxxxx

dx

xi

ϕi

1/dx

-1/dx

Page 17: Basic Concepts in 1-D -Basic Concepts in 1-D - OOutlineutlineIgel/Downloads/Nmgiifembasic.pdfBasic Concepts in 1-D -Basic Concepts in 1-D - OOutlineutline Basics - Formulation-B asis

Numerical Methods in Geophysics Finite Elements

Stiffness matix - elementsStiffness matix - elements

dxA kiik ∫ ∇∇=1

0

ϕϕ

12

345

6789

10

... we have to distinguish various cases ... e.g. ...

dxdx

dxdx

dxdxdxdxA

dxdxx

x

dxx

x

1111

0211

1

01111

1

1

1

1

==−−

=∇∇=∇∇= ∫∫∫∫++

ϕϕϕϕ

dxdx

dxdx

dx

dxdxdxA

dx

dx

dxx

x

x

dxx

211

02

0

2

2222

1

02222

2

2

2

2

=+=

∇∇+∇∇=∇∇=

∫∫

∫∫∫

+

ϕϕϕϕϕϕ

Page 18: Basic Concepts in 1-D -Basic Concepts in 1-D - OOutlineutlineIgel/Downloads/Nmgiifembasic.pdfBasic Concepts in 1-D -Basic Concepts in 1-D - OOutlineutline Basics - Formulation-B asis

Numerical Methods in Geophysics Finite Elements

Stiffness matix - elementsStiffness matix - elements

dxA kiik ∫ ∇∇=1

0

ϕϕ

12

345

6789

10

... and ...

dxdx

dx

dxdxdx

dxdxA

dx

dxx

x

dxx

x

11

11

02

21

1

02112

1

1

1

1

−=

−=

−=∇∇=∇∇=

∫∫∫++

ϕϕϕϕ

... and ...

1221 AA =

... so that finally the stiffness matrix looks like ...

Page 19: Basic Concepts in 1-D -Basic Concepts in 1-D - OOutlineutlineIgel/Downloads/Nmgiifembasic.pdfBasic Concepts in 1-D -Basic Concepts in 1-D - OOutlineutline Basics - Formulation-B asis

Numerical Methods in Geophysics Finite Elements

Stiffness matix - elementsStiffness matix - elements

dxA kiik ∫ ∇∇=1

0

ϕϕ

12

345

6789

10

⎟⎟⎟⎟⎟⎟

⎜⎜⎜⎜⎜⎜

−−−

−−−

=

11121

12111

1dx

Aij

... so far we have ignored sources and boundary conditions ...

Page 20: Basic Concepts in 1-D -Basic Concepts in 1-D - OOutlineutlineIgel/Downloads/Nmgiifembasic.pdfBasic Concepts in 1-D -Basic Concepts in 1-D - OOutlineutline Basics - Formulation-B asis

Numerical Methods in Geophysics Finite Elements

Boundary conditions - sourcesBoundary conditions - sources

... let us start restating the problem ...

)()( xfxu =∆−

... which we turned into the following formulation ...

dxfdxc kki

n

ii ϕϕϕ ∫∫∑ =∇∇

=

1

0

1

01

... assuming ...

with b.c. Ni

N

ii uucu ϕϕϕ )1()0(~

1

1

2++= ∑

=i

N

iicu ϕ∑

=

=1

~

where u(0) and u(1) are the values at the boundaries of the domain [0,1]. How is this incorporated into the algorithm?

Page 21: Basic Concepts in 1-D -Basic Concepts in 1-D - OOutlineutlineIgel/Downloads/Nmgiifembasic.pdfBasic Concepts in 1-D -Basic Concepts in 1-D - OOutlineutline Basics - Formulation-B asis

Numerical Methods in Geophysics Finite Elements

Boundary conditions - sourcesBoundary conditions - sources

dxfdxc kki

n

ii ϕϕϕ ∫∫∑ =∇∇

=

1

0

1

01)()( xfxu =∆−

... which we turned into the following formulation ...

... in pictorial form ...

dxudxudxfdxc knkkki

n

ii ∫∫∫∫∑ ∇∇+∇∇+=∇∇

=

1

0

1

01

1

0

1

0

1

2

)1()0( ϕϕϕϕϕϕϕ

boundary condition

boundary condition

source heterogeneity (f)

AT b = g

=

... the system feels the boundary conditions through the (modified) source term

Page 22: Basic Concepts in 1-D -Basic Concepts in 1-D - OOutlineutlineIgel/Downloads/Nmgiifembasic.pdfBasic Concepts in 1-D -Basic Concepts in 1-D - OOutlineutline Basics - Formulation-B asis

Numerical Methods in Geophysics Finite Elements

Numerical example – regular gridNumerical example – regular grid

)()( xfxu =∆−

Domain: [0,1]; nx=100; dx=1/(nx-1);f(x)=δ(1/2)Boundary conditions:u(0)=u(1)=0

f(nx/2)=1/dx;

for it = 1:nit,

uold=u;

du=(csh(u,1)+csh(u,-1));

u=.5*( f*dx^2 + du );

u(1)=0;

u(nx)=0;

end

Matlab FD code

% source terms=(1:nx)*0;s(nx/2)=1.;% boundary left u_1 int{ nabla phi_1 nabla phij }u1=0; s(1) =0;% boundary right u_nx int{ nabla phi_nx nabla phij }unx=0; s(nx)=0;

% assemble matrix Aij

A=zeros(nx);

for i=2:nx-1,for j=2:nx-1,

if i==j, A(i,j)=2/dx;

elseif j==i+1A(i,j)=-1/dx;

elseif j==i-1A(i,j)=-1/dx;

elseA(i,j)=0;

endend

endfem(2:nx-1)=inv(A(2:nx-1,2:nx-1))*s(2:nx-1)';fem(1)=u1;fem(nx)=unx;

Matlab FEM code

Page 23: Basic Concepts in 1-D -Basic Concepts in 1-D - OOutlineutlineIgel/Downloads/Nmgiifembasic.pdfBasic Concepts in 1-D -Basic Concepts in 1-D - OOutlineutline Basics - Formulation-B asis

Numerical Methods in Geophysics Finite Elements

Numerical example – regular gridNumerical example – regular grid

)()( xfxu =∆−

Domain: [0,1]; nx=100; dx=1/(nx-1);f(x)=δ(1/2)Boundary conditions:u(0)=u(1)=0

Matlab FD code (red)

Matlab FEM code (blue)

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 10

0.05

0.1

0.15

0.2

0.25

x

u(x)

F D (re d) - F E M (blue )

Page 24: Basic Concepts in 1-D -Basic Concepts in 1-D - OOutlineutlineIgel/Downloads/Nmgiifembasic.pdfBasic Concepts in 1-D -Basic Concepts in 1-D - OOutlineutline Basics - Formulation-B asis

Numerical Methods in Geophysics Finite Elements

Regular grid – non-zero b.c.Regular grid – non-zero b.c.

)()( xfxu =∆−

Domain: [0,1]; nx=100; dx=1/(nx-1);f(x)=δ(1/2)Boundary conditions:u(0)=0.15u(1)=0.05

Matlab FD code (red)

Matlab FEM code (blue)

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 10

0.05

0.1

0.15

0.2

0.25

0.3

0.35

0.4

x

u(x)

F D (re d) - F E M (blue ) -> Re gula r grid

% Quelle

s=(1:nx)*0;s(nx/2)=1.;

% Randwert links u_1 int{ nabla phi_1 nabla phij }

u1=0.15; s(2) =u1/dx;

% Randwert links u_nx int{ nabla phi_nx nabla phij }

unx=0.05; s(nx-1)=unx/dx;

Page 25: Basic Concepts in 1-D -Basic Concepts in 1-D - OOutlineutlineIgel/Downloads/Nmgiifembasic.pdfBasic Concepts in 1-D -Basic Concepts in 1-D - OOutlineutline Basics - Formulation-B asis

Numerical Methods in Geophysics Finite Elements

Stiffness matrix - irregular gridStiffness matrix - irregular grid

1

2

3

4

5

6

7

8

9

10

dxA kiik ∫ ∇∇=1

0

ϕϕ

2110

2

1121

1

02112

11

11

1

1

11

1

11

1

Ah

dxh

dxhh

dxdxA

h

hx

x

hx

x

=−

=−

=

−=∇∇=∇∇=

∫∫∫++

ϕϕϕϕ

iiii hh

A 11

1

+=−

i=1 2 3 4 5 6 7+ + + + + + +

h1 h2 h3 h4 h5 h6

Page 26: Basic Concepts in 1-D -Basic Concepts in 1-D - OOutlineutlineIgel/Downloads/Nmgiifembasic.pdfBasic Concepts in 1-D -Basic Concepts in 1-D - OOutlineutline Basics - Formulation-B asis

Numerical Methods in Geophysics Finite Elements

Numerical example – irregular gridNumerical example – irregular grid

Stiffness matrix A

for i=2:nx-1,

for j=2:nx-1,

if i==j,

A(i,j)=1/h(i-1)+1/h(i);

elseif i==j+1

A(i,j)=-1/h(i-1);

elseif i+1==j

A(i,j)=-1/h(i);

else

A(i,j)=0;

end

end

end

)()( xfxu =∆−

Domain: [0,1]; nx=100; dx=1/(nx-1);f(x)=δ(1/2)Boundary conditions:u(0)=u0; u(1)=u1

i=1 2 3 4 5 6 7+ + + + + + +

h1 h2 h3 h4 h5 h6

Page 27: Basic Concepts in 1-D -Basic Concepts in 1-D - OOutlineutlineIgel/Downloads/Nmgiifembasic.pdfBasic Concepts in 1-D -Basic Concepts in 1-D - OOutlineutline Basics - Formulation-B asis

Numerical Methods in Geophysics Finite Elements

Irregular grid – non-zero b.c.Irregular grid – non-zero b.c.

)()( xfxu =∆− FEM on Chebyshev grid

Domain: [0,1]; nx=100; dx=1/(nx-1);f(x)=δ(1/2)Boundary conditions:u(0)=0.15u(1)=0.05

Matlab FD code (red)

Matlab FEM code (blue)

+ FEM grid points 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 10

0.05

0.1

0.15

0.2

0.25

0.3

0.35

0.4

x

u(x)

FD (re d) - F E M (blue )

Page 28: Basic Concepts in 1-D -Basic Concepts in 1-D - OOutlineutlineIgel/Downloads/Nmgiifembasic.pdfBasic Concepts in 1-D -Basic Concepts in 1-D - OOutlineutline Basics - Formulation-B asis

Numerical Methods in Geophysics Finite Elements

Finite elements – summary of the basicsFinite elements – summary of the basics

In finite element analysis we approximate a function defined in a Domain D with a set of orthogonal basis functions with coefficients corresponding to the functional values at some node points.

The solution for the values at the nodes for some partial differential equations can be obtained by solving a linear system of equations involving the inversion of (sometimes sparse) matrices.

Boundary conditions are inherently satisfied with this formulation which is one of the advantages compared to finite differences.

In finite element analysis we approximate a function defined in a Domain D with a set of orthogonal basis functions with coefficients corresponding to the functional values at some node points.

The solution for the values at the nodes for some partial differential equations can be obtained by solving a linear system of equations involving the inversion of (sometimes sparse) matrices.

Boundary conditions are inherently satisfied with this formulation which is one of the advantages compared to finite differences.