Method of Finite Elements I - Homepage | ETH Zürich...Method of Finite Elements I PhD Candidate -...

27
Method of Finite Elements I PhD Candidate - Charilaos Mylonas HIL H33.1 Quadrature and Boundary Conditions, 26 March, 2018 Institute of Structural Engineering Method of Finite Elements I 1

Transcript of Method of Finite Elements I - Homepage | ETH Zürich...Method of Finite Elements I PhD Candidate -...

Page 1: Method of Finite Elements I - Homepage | ETH Zürich...Method of Finite Elements I PhD Candidate - Charilaos Mylonas HIL H33.1 Quadrature and Boundary Conditions, 26 March, 2018 Institute

Method of Finite Elements I

PhD Candidate - Charilaos MylonasHIL H33.1

Quadrature and Boundary Conditions, 26 March, 2018

Institute of Structural Engineering Method of Finite Elements I 1

Page 2: Method of Finite Elements I - Homepage | ETH Zürich...Method of Finite Elements I PhD Candidate - Charilaos Mylonas HIL H33.1 Quadrature and Boundary Conditions, 26 March, 2018 Institute

QuadratureBoundary conditions

Outline

1 Quadrature

Integration in 1D

Integration in 2D and 3D

2 Boundary conditions

Penalty method

Lagrange multiplier method

Institute of Structural Engineering Method of Finite Elements I 2

Page 3: Method of Finite Elements I - Homepage | ETH Zürich...Method of Finite Elements I PhD Candidate - Charilaos Mylonas HIL H33.1 Quadrature and Boundary Conditions, 26 March, 2018 Institute

QuadratureBoundary conditions

Integration in 1DIntegration in 2D and 3D

Outline

1 Quadrature

Integration in 1D

Integration in 2D and 3D

2 Boundary conditions

Penalty method

Lagrange multiplier method

Institute of Structural Engineering Method of Finite Elements I 3

Page 4: Method of Finite Elements I - Homepage | ETH Zürich...Method of Finite Elements I PhD Candidate - Charilaos Mylonas HIL H33.1 Quadrature and Boundary Conditions, 26 March, 2018 Institute

QuadratureBoundary conditions

Integration in 1DIntegration in 2D and 3D

Integration

Basic numerical integration

Riemann sum

Trapezoidal rule

Comments:

Both simple but inefficient!

useful techniques in other contexts

we use many more points than needed

in order to achieve good accuracy

Institute of Structural Engineering Method of Finite Elements I 4

Page 5: Method of Finite Elements I - Homepage | ETH Zürich...Method of Finite Elements I PhD Candidate - Charilaos Mylonas HIL H33.1 Quadrature and Boundary Conditions, 26 March, 2018 Institute

QuadratureBoundary conditions

Integration in 1DIntegration in 2D and 3D

Numerical Integration in 1D

example: Euler-Bernoulli beam

We are going to apply the Galerkin method to the Euler Bernoulli beam, but with the basis

N1(x) = x2

N2(x) = x3

N3(x) = x4 · · ·

Instead of the Hermite basis functions, and discretize only displacements! Strong form:

d2

dx2

(EI(x)

d2w

dx2

)= f(x)

multiply with test function u(x) and integrate by parts twice a

∫ 1

0

EI(x)d2w(x)

dx2

d2u(x)

dx2dx =

∫ 1

0

f(x)u(x)dx

aboundary terms [·]10 zero by basis selection

Institute of Structural Engineering Method of Finite Elements I 5

Page 6: Method of Finite Elements I - Homepage | ETH Zürich...Method of Finite Elements I PhD Candidate - Charilaos Mylonas HIL H33.1 Quadrature and Boundary Conditions, 26 March, 2018 Institute

QuadratureBoundary conditions

Integration in 1DIntegration in 2D and 3D

Numerical integration - Galerkin method

code

The full commented code of the following demo will be made available to you in case you would like

to play around. This code is a comparisson between analytical and numerical evaluation of integrals

needed in the implementation of the Galerkin procedure. In the following slides the most important

parts of the code are highlighted. Namely:

The definition of the load

the assembly of the system with analytical integration (symbolic integration)

the assembly of the system with numerical integration (Gauss-Legendre)

Institute of Structural Engineering Method of Finite Elements I 6

Page 7: Method of Finite Elements I - Homepage | ETH Zürich...Method of Finite Elements I PhD Candidate - Charilaos Mylonas HIL H33.1 Quadrature and Boundary Conditions, 26 March, 2018 Institute

QuadratureBoundary conditions

Integration in 1DIntegration in 2D and 3D

Numerical Integration in 1D results

1 syms x % C o o r d i n a t e a x i s

2 syms q ( x )

3 % The l o a d i n g o f t h e beam :

4 q ( x ) = x . ˆ 2 − 0.3∗ x . ˆ 4

5 NBASIS = 4 ;

6 f o r i = 1 : NBASIS

7 Phi ( i ) = x . ˆ ( i +1) ;

8 end

9 % Compute t h e i n t e g r a l s needed f o r t h e s t i f f n e s s m a t r i x :

10 f o r i =1:NBASIS

11 f o r j = 1 : NBASIS

12 K( i , j )= . . .

13 i n t ( EI∗ d i f f ( Phi ( i ) , 2 )∗ d i f f ( Phi ( j ) , 2 ) , 0 , L ) ;

14 end

15 % A n a l y t i c a l computat ion o f t h e l o a d v e c t o r :

16 f ( i ) = i n t ( q ( x ) ∗ Phi ( i ) , 0 , L ) ;

17 end

Institute of Structural Engineering Method of Finite Elements I 7

Page 8: Method of Finite Elements I - Homepage | ETH Zürich...Method of Finite Elements I PhD Candidate - Charilaos Mylonas HIL H33.1 Quadrature and Boundary Conditions, 26 March, 2018 Institute

QuadratureBoundary conditions

Integration in 1DIntegration in 2D and 3D

Numerical integration for LHS

1 q u a d r o r d e r = QUAD ORD;

2

3 %Loading t h e Gauss−Legendre q u a d r a t u r e nodes

4 % and w e i g h t s f o r a f i l e :

5 n o d e s w e i g h t s = W q u a d r o r d e r −1;

6 nodes = ( n o d e s w e i g h t s . nodes +1)∗L / 2 ;

7 w e i g h t s = W q u a d r o r d e r −1. w e i g h t s ;

8

9 f o r i =1: N b a s i s

10 f o r j =1: N b a s i s

11 V = e v a l ( s u b s ( EI ∗ d i f f ( Phi ( i ) , 2 ) ∗ d i f f ( Phi ( j ) , 2 ) , nodes ) ) ;

12 K approx ( i , j ) = V’ ∗ w e i g h t s ;

13 % Note t h a t we don ’ t i n t e g r a t e a n a l y t i c a l l y !

14 % we can g e t EXACT r e s u l t s w i t h o u t d o i n g so

15 end

16

17 f a p p r o x ( i ) = e v a l ( s u b s ( Phi ( i )∗q ( x ) , nodes ) ) ’∗ w e i g h t s ;

18 end

Institute of Structural Engineering Method of Finite Elements I 8

Page 9: Method of Finite Elements I - Homepage | ETH Zürich...Method of Finite Elements I PhD Candidate - Charilaos Mylonas HIL H33.1 Quadrature and Boundary Conditions, 26 March, 2018 Institute

QuadratureBoundary conditions

Integration in 1DIntegration in 2D and 3D

Numerical Results

Institute of Structural Engineering Method of Finite Elements I 9

Page 10: Method of Finite Elements I - Homepage | ETH Zürich...Method of Finite Elements I PhD Candidate - Charilaos Mylonas HIL H33.1 Quadrature and Boundary Conditions, 26 March, 2018 Institute

QuadratureBoundary conditions

Integration in 1DIntegration in 2D and 3D

Conclussions

Notice the errors in the approximation (1.7e−13 for quadrature of order 4!). This is close to

machine precission (the ”eps” command in matlab).

1D Quadrature order ”N” means we evaluate the function inside the integral ”N” times, and

we sum the results according to some weight (see next slide).

Instead of integrating analytically a function, we can get EXACT results by carefully selecting

points of evaluation (instead of regular intervals as in trapezoidal and Riemann sums).

The accuracy of the approximation depends on the Gaussian quadrature order

Institute of Structural Engineering Method of Finite Elements I 10

Page 11: Method of Finite Elements I - Homepage | ETH Zürich...Method of Finite Elements I PhD Candidate - Charilaos Mylonas HIL H33.1 Quadrature and Boundary Conditions, 26 March, 2018 Institute

QuadratureBoundary conditions

Integration in 1DIntegration in 2D and 3D

Optimal points and weights integration for polynomials:

Quadrature - Optimal weights given the nodes

For a polynomial f(x) = a0 + a1x+ · · ·+ anxn, the integral is approximated as∫ 1

−1

f(x)dx 'N∑i=1

wif(xi)

Assume xi are given. Also, for simplicity, f(x) = a0 + a1x+ a2x2 + a3x

3. Then,

a0

∫ 1

−1

dx+ a1

∫ 1

−1

xdx+ a2

∫ 1

−1

x2dx+ a3

∫ 1

−1

x3dx =

4∑i=1

wi(a0 + a1xi + a2x2i + a3x

3i )

We equate all the terms, for every ai term. we arrive at the following linear system:1 1 1 1

x1 x2 x3 x4

x21 x2

2 x23 x2

4

x31 x3

2 x33 x3

4

︸ ︷︷ ︸

Vandermonde matrix

w1

w2

w3

w4

=

∫ 1

−1dx∫ 1

−1xdx∫ 1

−1x2dx∫ 1

−1x3dx

Institute of Structural Engineering Method of Finite Elements I 11

Page 12: Method of Finite Elements I - Homepage | ETH Zürich...Method of Finite Elements I PhD Candidate - Charilaos Mylonas HIL H33.1 Quadrature and Boundary Conditions, 26 March, 2018 Institute

QuadratureBoundary conditions

Integration in 1DIntegration in 2D and 3D

Non-Gaussian Quadrature

Numerical computation of weights

N-point quadrature, extact for polynomials up to degree N-1

Weights can be negative, in practice they have values of very different scales and solution of

the system for high order quadrature is numerically unstable!

The technique will approximate well integrals of functions that are approximated well with the

corresponding polynomials.

Lower order quadrature works, but as we will see it is far from the best we can do! (half as

good).

Institute of Structural Engineering Method of Finite Elements I 12

Page 13: Method of Finite Elements I - Homepage | ETH Zürich...Method of Finite Elements I PhD Candidate - Charilaos Mylonas HIL H33.1 Quadrature and Boundary Conditions, 26 March, 2018 Institute

QuadratureBoundary conditions

Integration in 1DIntegration in 2D and 3D

Legendre polynomials

In the following, we will see how the Legendre polynomials are important for quadrature in 1D. We

are to use xi such that this integral is exact for every polynomial f(x) with degree n < 2N − 1. For

a given N , solution xi are roots of the Legendre orthogonal polynomial of degree N

Institute of Structural Engineering Method of Finite Elements I 13

Page 14: Method of Finite Elements I - Homepage | ETH Zürich...Method of Finite Elements I PhD Candidate - Charilaos Mylonas HIL H33.1 Quadrature and Boundary Conditions, 26 March, 2018 Institute

QuadratureBoundary conditions

Integration in 1DIntegration in 2D and 3D

Orthogonal polynomials

Legendre orthogonal polynomials Lnsatisfy (by construction)a:

〈Lk, Lm〉 =∫ 1

−1

Lk(x)Lm(x)dx =2

2m+ 1δmk

From now on this integral is going to be refered to as L2 inner product. Formulas for the first few

polynomials areb,

L0(x) = 1

L1(x) = x

L2(x) =1

2(3x

2 − 1)

L3(x) =1

8(5x

3 − 3x)

L4(x) =1

8(35x

4 − 30x2+ 3)

aThere are more general definitions of orthogonality and Gaussian quadrature where〈f, g〉w =

∫Ω f(x)g(x)w(x)dx. The resulting polynomials are useful in other important contexts (stochastic

finite elements!)bThey are computed with a process known as Gram-Schmidt orthogonalization

Institute of Structural Engineering Method of Finite Elements I 14

Page 15: Method of Finite Elements I - Homepage | ETH Zürich...Method of Finite Elements I PhD Candidate - Charilaos Mylonas HIL H33.1 Quadrature and Boundary Conditions, 26 March, 2018 Institute

QuadratureBoundary conditions

Integration in 1DIntegration in 2D and 3D

Legendre orthogonal polynomials and quadrature

The roots of Legendre polynomials of degree N , used as integration nodes, yield the exact integral

for f polynomial of maximum degree 2N − 1.

Outline of proof:

1 consider a polynomial f2N−1(x) = a0 + a1x+ · · ·+ a2N−1x2N−1

2 Apply polynomial divission with Legendre polynomial of degree N :

f2N−1(x) = g(x)︸︷︷︸degree≤N−1

LN (x) + r(x)︸︷︷︸degree≤N−1

3 x(N)1 , · · · , x(N)

N are the N roots of the Legendre polynomial of degree N . For brevity, we

ommit the superscript x(N)i = xi. Chose the quadrature nodes to be these exact points:

: 0∫ 1

−1

g(x)Ln(x)dx+

∫ 1

−1

r(x)dx =

: 0N∑

i=1

wig(xi)Ln(xi) +

N∑i=1

wir(xi)

4 Since Ln(xi) = 0, the first term of the RHS vanishes. Moreover, since the degree of g(x) is

lower than N , the first integral term on the left is also zero! That is, through orthogonality

and the abillity to express polynomials of order N − 1 with a polynomial basis that contains

all the monomials (such as the Legendre basis order N)!

Institute of Structural Engineering Method of Finite Elements I 15

Page 16: Method of Finite Elements I - Homepage | ETH Zürich...Method of Finite Elements I PhD Candidate - Charilaos Mylonas HIL H33.1 Quadrature and Boundary Conditions, 26 March, 2018 Institute

QuadratureBoundary conditions

Integration in 1DIntegration in 2D and 3D

Considering again that we are evaluating the quadrature rule on the roots of Legendre polynomial of

degree N , the term LN becomes zero

f2N−1(xi) = g(xi): 0

LN (xi) + r(xi) = r(xi)

Finally we are left with ∫ 1

−1

f2N−1(x)dx =

∫ 1

−1

r(x) =

N∑i=1

wif2N−1(xi)

And we are left with the task of determining the weights as in the non-gaussian case. Therefore,

surprizingly, a N -point gauss quadrature rule is exact for polynomials up to degree 2N − 1.

In practice, the computational determination of weights wi and nodes xi of 1D Gaussian quadrature

rules happens through the so-called Golub-Welsch algorithm.

Institute of Structural Engineering Method of Finite Elements I 16

Page 17: Method of Finite Elements I - Homepage | ETH Zürich...Method of Finite Elements I PhD Candidate - Charilaos Mylonas HIL H33.1 Quadrature and Boundary Conditions, 26 March, 2018 Institute

QuadratureBoundary conditions

Integration in 1DIntegration in 2D and 3D

Quadrilaterals

Tensor-product Quadrature

Take tensor product of the 1D rules. Example: Quadrature in x:

w(ξ)i = w(ξ)

1 , w(ξ)2 , w

(ξ)3 , w

(ξ)4

ξi = ξ1, ξ2, ξ3, ξ4

Quadrature in y

w(η)i = w(η)

1 , w(η)2 , w

(η)3 , x

(η)4

ηi = η1, η2, η3, η4

Quadrature rule for quadrilateral:∫ 1

−1

∫ 1

−1

f(ξ, η)dxdy =

4∑i=1

4∑j=1

w(η)i w

(ξ)j f(ξi, ηj)

Institute of Structural Engineering Method of Finite Elements I 17

Page 18: Method of Finite Elements I - Homepage | ETH Zürich...Method of Finite Elements I PhD Candidate - Charilaos Mylonas HIL H33.1 Quadrature and Boundary Conditions, 26 March, 2018 Institute

QuadratureBoundary conditions

Penalty methodLagrange multiplier method

Outline

1 Quadrature

Integration in 1D

Integration in 2D and 3D

2 Boundary conditions

Penalty method

Lagrange multiplier method

Institute of Structural Engineering Method of Finite Elements I 18

Page 19: Method of Finite Elements I - Homepage | ETH Zürich...Method of Finite Elements I PhD Candidate - Charilaos Mylonas HIL H33.1 Quadrature and Boundary Conditions, 26 March, 2018 Institute

QuadratureBoundary conditions

Penalty methodLagrange multiplier method

Homogeneous constraints

Linear system from FE discretization

Consider a linear system from a FE discretization:

[K]u = fK11 . . . K1N

.

.

.. . .

.

.

.

KN1 . . . KNN

u1

.

.

.

uN

=

f1

.

.

.

fN

Homogeneous constraints

the constraint un = 0, in a matrix form consistent with our FE linear system reads,

N∑i=0

viui = 0

0 . . . 1 . . . 0

u1

.

.

.

un...

uN

= 0

Institute of Structural Engineering Method of Finite Elements I 19

Page 20: Method of Finite Elements I - Homepage | ETH Zürich...Method of Finite Elements I PhD Candidate - Charilaos Mylonas HIL H33.1 Quadrature and Boundary Conditions, 26 March, 2018 Institute

QuadratureBoundary conditions

Penalty methodLagrange multiplier method

Imposing homogeneous constr. with the Penalty method

Imposing the constraint

The constraint vector should be in a form consistent with the matrix (a bilinear form that

corresponds to a matrix).

In order to impose the constraint, we simply multiply with a large number p >> tr([K]) and add

that to our linear system.

[V] = Vij = vivj

[V] = vT v

[V] =

0 . . . 0

. . .

.

.

. 1...

. . .

0 . . . 0

This forces the degrees of freedom in the system to satisfy the constraint numerically (not explicitly).

Institute of Structural Engineering Method of Finite Elements I 20

Page 21: Method of Finite Elements I - Homepage | ETH Zürich...Method of Finite Elements I PhD Candidate - Charilaos Mylonas HIL H33.1 Quadrature and Boundary Conditions, 26 March, 2018 Institute

QuadratureBoundary conditions

Penalty methodLagrange multiplier method

Adding to the linear system

Adding the constraint

Simply set,

[K]← [K]pen

with

[K]pen = [K] + [V] · p

with p >> tr([K]) and solve

u = [K]−1penf

Inhomogeneous constraints and MFC:

What if, we need to set a displacement to a given value (inhomogeneous constraint), or a

displacement the same as another displacement (multi-DOF constraints)?

Institute of Structural Engineering Method of Finite Elements I 21

Page 22: Method of Finite Elements I - Homepage | ETH Zürich...Method of Finite Elements I PhD Candidate - Charilaos Mylonas HIL H33.1 Quadrature and Boundary Conditions, 26 March, 2018 Institute

QuadratureBoundary conditions

Penalty methodLagrange multiplier method

Multi- degree of freedom constraints

Equation for a multi-DOF constraint

Consider we have a constraint of the form 2u5 + 3u7 − 2u10 = 0. Again, written as an equation,

0 . . . 2 0 3 0 0 −2 . . . 0

u1

.

.

.

u5

u6

u7

u8

u9

u10

.

.

.

uN

= 0

Institute of Structural Engineering Method of Finite Elements I 22

Page 23: Method of Finite Elements I - Homepage | ETH Zürich...Method of Finite Elements I PhD Candidate - Charilaos Mylonas HIL H33.1 Quadrature and Boundary Conditions, 26 March, 2018 Institute

QuadratureBoundary conditions

Penalty methodLagrange multiplier method

Penalty, multi-DOF constraints

Application of the constraints

Not much change when being systematic about the application!

[V] =vT v

[V] =

0 . . . 0

. . .

4 0 6 0 0 −40 0 0 0 0 0

6 0 9 0 0 −6... 0 0 0 0 0 0

.

.

.

0 0 0 0 0 0

−4 0 −6 0 0 4

. . .

0 . . . 0

The rest are the same! (multiply by a large number and add to [K] before solution).

Institute of Structural Engineering Method of Finite Elements I 23

Page 24: Method of Finite Elements I - Homepage | ETH Zürich...Method of Finite Elements I PhD Candidate - Charilaos Mylonas HIL H33.1 Quadrature and Boundary Conditions, 26 March, 2018 Institute

QuadratureBoundary conditions

Penalty methodLagrange multiplier method

Non-homogeneous constraints with the Penalty method and multipleconstraints

Non-zero RHS

Say, we want to constrain u3 − 2u5 = 3 and at the same time u2 − u3 = 0. In matrix form, the

constraints read:

0 0 1 0 −2 . . .

︸ ︷︷ ︸v1

u1

u2

u3

u4

u5

.

.

.

= 3︸︷︷︸

a1

0 1 −1 0 0 . . .

︸ ︷︷ ︸v2

u1

u2

u3

u4

u5

.

.

.

= 0︸︷︷︸

a2

Institute of Structural Engineering Method of Finite Elements I 24

Page 25: Method of Finite Elements I - Homepage | ETH Zürich...Method of Finite Elements I PhD Candidate - Charilaos Mylonas HIL H33.1 Quadrature and Boundary Conditions, 26 March, 2018 Institute

QuadratureBoundary conditions

Penalty methodLagrange multiplier method

Application of BC and solution

Application of BC on system

In order to impose the constraint on the system, we proceed as such: Multiplying both equations with

the corresponding viT and summing up the constraints for the left-hand side we get,

[V ] =

2∑i=1

viT vi

and for the right-hand-side:

A =

2∑i=1

viT ai

[Kpen] = [K] + [V ] · p

fpen = f+ A · p

What changes, is that we also have a right-hand-side due to the non-homogeneous constraints!

Solution

Simply compute

u = [Kpen]−1fpen

Institute of Structural Engineering Method of Finite Elements I 25

Page 26: Method of Finite Elements I - Homepage | ETH Zürich...Method of Finite Elements I PhD Candidate - Charilaos Mylonas HIL H33.1 Quadrature and Boundary Conditions, 26 March, 2018 Institute

QuadratureBoundary conditions

Penalty methodLagrange multiplier method

Lagrange multipliers

constraints for LHS

Another method, just as general and simple to implement, is the Lagrange multiplier method: given

the constraint matrix [v] from the previous slide, set

[KLagr] =

[[K] [v]T

[v] 0

]

[KLagr] =

K11 . . . K1N v11 v21

.

.

.. . .

.

.

....

.

.

.

KN1 . . . KNN v1N v2N

v11 . . . v1N 0 0

v21 . . . v2N 0 0

Constraints at RHS

Instead of adding, we are again appending.

fLagr =

fP

Where, P is a vector containing the values of the non-homogeneous constraints. From the

previous example, P =

3

0

.

Institute of Structural Engineering Method of Finite Elements I 26

Page 27: Method of Finite Elements I - Homepage | ETH Zürich...Method of Finite Elements I PhD Candidate - Charilaos Mylonas HIL H33.1 Quadrature and Boundary Conditions, 26 March, 2018 Institute

QuadratureBoundary conditions

Penalty methodLagrange multiplier method

Comparisson

The clear advantage of Lagr. Multiplier method over penalty is accuracy.

Penalty has the advantage that does not introduce degrees of freedom to the linear system.

However, this rarely becomes a real problem with modern hardware.

Some linear system solvers rely on the matrix being positive definite for fast convergence -

Lagrange multipliers may not work with some linear system solvers

Lagrange multiplier method provides directly the constraint forces (as the values corresponding

to the rows and columns of the constraints).

When constraints are linearly dependent (a constraint vector can be expressed as linear

combination of other constraints in the same system) iterative solvers (i.e. GMRES) have to

be used. Linear independence of constraints is hard to judge in some cases (however, there are

linear algebra techniques one can perform to remedy that).

The multi-freedom homogeneous case for the Master-slave elimination method, is described

partially in the project description. This method is also exact (as Lagr. Multipliers).

Institute of Structural Engineering Method of Finite Elements I 27