arxiv:1905.09118v2 [math.na] 10 jan 2020

11
MATLAB Implementation of C1 finite elements: Bogner-Fox-Schmit rectangle ? Jan Valdman 1,2[0000-0002-6081-5362] 1 Institute of Mathematics, Faculty of Science, University of South Bohemia, Braniˇ sovsk´ a 31, 37005 ˇ Cesk´ e Budˇ ejovice, Czech Republic 2 The Czech Academy of Sciences, Institute of Information Theory and Automation, Pod vod´ arenskou vˇ ı 4, 18208 Praha 8, Czech Republic [email protected] Abstract. Rahman and Valdman (2013) introduced a new vectorized way to assemble finite element matrices. We utilize underlying vectoriza- tion concepts and extend MATLAB codes to implementation of Bogner- Fox-Schmit C1 rectangular elements in 2D. Our focus is on the detailed construction of elements and simple computer demonstrations including energies evaluations and their visualizations. Keywords: MATLAB vectorization, finite elements, energy evaluation 1 Introduction Boundary problems with fourth order elliptic operators [3] appear in many appli- cations including thin beams and plates and strain gradient elasticity [5]. Weak formulations and implementations of these problems require H2-conforming fi- nite elements, leading to C 1 continuity (of functions as well as of their gradients) of approximations over elements edges. This continuity condition is generally technical to achieve and few types of finite elements are known to quarantee it. We consider probably the simplest of them, the well known Bogner-Fox-Schmit rectangle [2], i.e., a rectangular C 1 element in two space dimensions. We are primarily interested in explaining the construction of BFS elements, their practical visualization and evalutions. Our MATLAB implementation is based on codes from [1,9,6]. The main focus of these papers were assemblies of finite element matrices and local element matrices were computed all at once by array operations and stored in multi-dimentional arrays (matrices). Here, we utilize underlying vectorization concepts without the particular interest in corresponding FEM matrices. More details on our recent implementations of C 1 models in nonlinear elastic models of solids can be found in [7,4,8]. The complementary software to this paper is available at https://www.mathworks.com/matlabcentral/fileexchange/71346 for download and testing. ? The work was supported by the Czech Science Foundation (GACR) through the grant GA18-03834S. arXiv:1905.09118v2 [math.NA] 10 Jan 2020

Upload: others

Post on 14-Jun-2022

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: arXiv:1905.09118v2 [math.NA] 10 Jan 2020

MATLAB Implementation of C1 finite elements:Bogner-Fox-Schmit rectangle?

Jan Valdman1,2[0000−0002−6081−5362]

1 Institute of Mathematics, Faculty of Science, University of South Bohemia,Branisovska 31, 37005 Ceske Budejovice, Czech Republic

2 The Czech Academy of Sciences, Institute of Information Theory and Automation,Pod vodarenskou vezı 4, 18208 Praha 8, Czech Republic

[email protected]

Abstract. Rahman and Valdman (2013) introduced a new vectorizedway to assemble finite element matrices. We utilize underlying vectoriza-tion concepts and extend MATLAB codes to implementation of Bogner-Fox-Schmit C1 rectangular elements in 2D. Our focus is on the detailedconstruction of elements and simple computer demonstrations includingenergies evaluations and their visualizations.

Keywords: MATLAB vectorization, finite elements, energy evaluation

1 Introduction

Boundary problems with fourth order elliptic operators [3] appear in many appli-cations including thin beams and plates and strain gradient elasticity [5]. Weakformulations and implementations of these problems require H2-conforming fi-nite elements, leading to C1 continuity (of functions as well as of their gradients)of approximations over elements edges. This continuity condition is generallytechnical to achieve and few types of finite elements are known to quarantee it.We consider probably the simplest of them, the well known Bogner-Fox-Schmitrectangle [2], i.e., a rectangular C1 element in two space dimensions.

We are primarily interested in explaining the construction of BFS elements,their practical visualization and evalutions. Our MATLAB implementation isbased on codes from [1,9,6]. The main focus of these papers were assemblies offinite element matrices and local element matrices were computed all at onceby array operations and stored in multi-dimentional arrays (matrices). Here,we utilize underlying vectorization concepts without the particular interest incorresponding FEM matrices. More details on our recent implementations ofC1 models in nonlinear elastic models of solids can be found in [7,4,8]. Thecomplementary software to this paper is available at

https://www.mathworks.com/matlabcentral/fileexchange/71346

for download and testing.

? The work was supported by the Czech Science Foundation (GACR) through thegrant GA18-03834S.

arX

iv:1

905.

0911

8v2

[m

ath.

NA

] 1

0 Ja

n 20

20

Page 2: arXiv:1905.09118v2 [math.NA] 10 Jan 2020

2 Jan Valdman

0 0.5 1-0.2

0

0.2

0.4

0.6

0.8

1

2 3 4 5-0.5

0

0.5

1

Fig. 1. Reference basis functions Hi, i = 1, . . . , 4 on [0, 1] (left) and example of actualbasis functions Hi, i = 1, . . . , 4 on [a, b] = [2, 5] (right).

2 Construction of C1 finite elements

2.1 Hermite elements in 1D

We define four cubic polynomials

H1(x) := 2x3 − 3x2 + 1,

H2(x) := −2x3 + 3x2,

H3(x) := x3 − 2x2 + x,

H4(x) := x3 − x2

(1)

over a reference interval I := [0, 1] and can easily check the conditions:

H1(0) = 1, H1(1) = 0, H ′1(0) = 0, H ′1(0) = 0,

H2(0) = 0, H2(1) = 1, H ′2(0) = 0, H ′2(0) = 0,

H3(0) = 0, H3(1) = 0, H ′3(0) = 1, H ′3(0) = 0,

H4(0) = 0, H4(1) = 0, H ′4(0) = 0, H ′4(0) = 1,

(2)

so only one value or derivative is equal to 1 and all other three values are equalto 0. These cubic functions create a finite element basis on I. More generally, we

Page 3: arXiv:1905.09118v2 [math.NA] 10 Jan 2020

MATLAB Implementation of C1 finite elements 3

define

H1(x) := H1(x(x)),

H2(x) := H2(x(x)),

H3(x) := h H3(x(x)),

H4(x) := h H4(x(x))

(3)

for x ∈ I := [a, b], where x(x) := (x− a)/h is an affine mapping from I to I andh denotes the interval I size

h := b− a.

These functions are also cubic polynomials and satisfy again the conditions (2)with function arguments 0, 1 replaced by a, b. They create actual finite elementbasis which ensures C1 continuity of finite element approximations. The chainrule provides higher order derivatives:

H ′1(x) = H ′1(x) /h, H ′′1 (x) = H ′′1 (x) /h2,

H ′2(x) = H ′2(x) /h, H ′′2 (x) = H ′′2 (x) /h2,

H ′3(x) = H ′3(x), H ′′3 (x) = H ′′3 (x) /h,

H ′4(x) = H ′4(x), H ′′4 (x) = H ′′4 (x) /h.

(4)

Example 1. Example of basis functions defined on reference and actual intervalsare shown in Figure 1 and pictures can be reproduced by

draw_C1basis_1D

script located in the main folder.

2.2 Bogner-Fox-Schmit rectangular element in 2D

Products of functions

ϕj,k(x, y) := Hj(x) Hk(y), j, k = 1, . . . , 4

define 16 Bogner-Fox-Schmit (BFS) basis functions on a reference rectangle R :=[0, 1]× [0, 1]. For practical implementations, we reorder them as

ϕi(x, y) := ϕji,ki(x, y), i = 1, . . . , 16, (5)

where sub-indices are ordered in a sequence

(ji, ki)16i=1 =

(1, 1), (2, 1), (2, 2), (1, 2),(3, 1), (4, 1), (4, 2), (3, 2),(1, 3), (2, 3), (2, 4), (1, 4),(3, 3), (4, 3), (4, 4), (3, 4).

(6)

Page 4: arXiv:1905.09118v2 [math.NA] 10 Jan 2020

4 Jan Valdman

01

0.2

0.4

1

0.6

0.8

0.8

0.5 0.6

1

0.40.2

0 0

-0.151

-0.1

1

-0.05

0.80.5 0.6

0

0.40.2

0 0

01

0.05

1

0.1

0.80.5 0.6

0.15

0.40.2

0 0

-0.0251

-0.02

-0.015

1

-0.01

0.8

-0.005

0.5 0.6

0

0.40.2

0 0

Fig. 2. Bogner-Fox-Schmit basis functions ϕi(x, y) for i = 2 (top left), i = 6 (topright), i = 8 (bottom left), i = 13 (bottom right) defined over a reference rectangleR = [0, 1] × [0, 1].

With this ordering, a finite element approximation v ∈ C1(R) rewrites as a linearcombination

v(x, y) =

16∑i=1

vi ϕi(x, y),

where:

– coefficients v1, . . . , v4 specify values of v,– coefficients v5, . . . , v8 specify values of ∂v

∂x ,

– coefficients v9, . . . , v12 specify values of ∂v∂y ,

– coefficients v13, . . . , v16 specify values of ∂2v∂x∂y

at nodesN1 := [0, 0], N2 := [1, 0], N3 := [1, 1], N4 := [0, 1].

Example 2. Four (out of 16) reference basis functions corresponding to the nodeN2 are shown in Figure 2 and pictures can be reproduced by

draw_C1basis_2D

script located in the main folder.

Page 5: arXiv:1905.09118v2 [math.NA] 10 Jan 2020

MATLAB Implementation of C1 finite elements 5

-1 -0.5 0 0.5 1-1

-0.8

-0.6

-0.4

-0.2

0

0.2

0.4

0.6

0.8

1

-3 -2.5 -2 -1.5 -1 -0.5 0 0.5 1 1.5 2-1.5

-1

-0.5

0

0.5

1

1.5

Fig. 3. Examples of a triangulation in rectangles: of a square domain (left) and ofa pincers domain (right) taken from [7] and used for nonlinear elasticity simulationssatisfying a non-selfpenetration condition.

More implementation details on functions evaluations For a generalrectangle R := [a, b]× [c, d], we define an affine mapping

(x, y)(x, y) := ((x− a)/hx, (y − c)/hy),

from R to R, where the rectangular lengths are

hx := b− a, hy := d− c.

It enables us to define BFS basis functions on R as

ϕi(x, y) := Hji

(x− ahx

)Hki

(y − chy

), i = 1, . . . , 16, (7)

Based on (4), higher order derivatives up to the second order,

∂ϕi∂x

,∂ϕi∂y

,∂2ϕi∂x2

,∂2ϕi∂y2

,∂2ϕi∂x∂y

, i = 1, . . . , 16 (8)

can be derived as well. All basis functions (7) are evaluated by the function

shapefun(points’,etype,h)

and their derivatives (8) by the function

shapeder(points’,etype,h)

For BFS elements, we have to set etype=’C1’ and a vector of rectangular lengthsh=[hx,hy]. The matrix points then contains a set of points x ∈ R in a referenceelement at which functions are evaluated. Both functions are vectorized and theiroutputs are stored as vectors, matrices or three-dimensional arrays.

Example 3. The command

Page 6: arXiv:1905.09118v2 [math.NA] 10 Jan 2020

6 Jan Valdman

[shape]=shapefun([0.5 0.5]’,’C1’,[1 1])

returns a (column) vector shape ∈ R16×1 of all BFS basis function defined onR := [0, 1]× [0, 1] and evaluated in the rectangular midpoint [0.5, 0.5] ∈ R. Thecommand

[dshape]=shapeder([0.5 0.5]’,’C1’,[2 3])

returns a three-dimensional array dshape ∈ R16×1×5 of all derivatives up to thesecond order of all BFS basis function defined on a general rectangle with lengthshx = 2 and hy = 3 and evaluated in the rectangular midpoint [0.5, 0.5] ∈ R.

For instance, if R := [1, 3] × [2, 5], values of all derivatives are evaluated inthe rectangular midpoint [2, 3.5] ∈ R.

More generally, if points ∈ Rnp×2 consists of np > 1 points, then shapefun

return a matrix of size R16×np and shapeder returns a three-dimensional arrayof size R16×np×5.

2.3 Representation of C1 functions and their visualization

Let us assume a triangulation T (Ω) into rectangles of a domain Ω. In corre-spondence with our implementation, we additionally assume that all rectanglesare of the same size, i.e., with lengths hx, hy > 0. Examples of T (Ω) are givenin Figure 3.

Let N denotes the set of all rectangular nodes and |N | := n the number ofthem. A C1 function v ∈ T (Ω) is represented in BSF basis by a matrix

V C1 =

v(N1), ∂v∂x (N1), ∂v∂y (N1), ∂2v

∂x∂y (N1)...

......

...

v(Nn), ∂v∂x (Nn), ∂v∂y (Nn), ∂2v∂x∂y (Nn)

containing values of v, ∂v∂x ,

∂v∂y ,

∂2v∂x∂y in all nodes of T (Ω). In the spirit of the

finite element method, values of v on each rectangle T ∈ T (Ω) are obtained byan affine mapping to the reference element R. Our implementations allows toevaluate and visualize continuous fields

v,∂v

∂x,∂v

∂y,∂2v

∂x∂y

and also two additional (generally discontinuous) fields

∂2v

∂x2,∂2v

∂y2.

It is easy to evaluate a C1 function in a particular element point for all elements(rectangles) at once. A simple matrix-matrix MATLAB multiplication

Vfun=VC1_elems*shape

Page 7: arXiv:1905.09118v2 [math.NA] 10 Jan 2020

MATLAB Implementation of C1 finite elements 7

01

0.5

10

1

0-1 -1

-51

0

10

5

0-1 -1

-21

0

10

2

0-1 -1

-21

0

10

2

0-1 -1

-101

0

10

10

0-1 -1

-101

0

10

10

0-1 -1

Fig. 4. A function v(x, y) = (1−x2)2(1−y2)2 on Ω = (−1, 1)2 represented in terms of

BSF elements. Separate pictures show: v (top left), ∂2v∂x∂y

(top right), ∂v∂x

(middle left),∂v∂y

(middle right), ∂2v∂x2 (bottom left), ∂2v

∂y2 (bottom right).

where a matrix VC1_elems ∈ Rne×16 contains in each row all 16 coefficients(taken from VC1) corresponding to each element (ne denotes a number of el-ements) returns a matrix Vfun ∈ Rne×np containing all function values in allelements and all points. Alternate multiplications

V1=VC1_elems*squeeze(dshape(:,1,:)); % Dx

V2=VC1_elems*squeeze(dshape(:,2,:)); % Dy

V11=VC1_elems*squeeze(dshape(:,3,:)); % Dxx

V22=VC1_elems*squeeze(dshape(:,4,:)); % Dyy

V12=VC1_elems*squeeze(dshape(:,5,:)); % Dxy

return matrices V1, V2, V11, V22, V12 ∈ Rne×np containing values of all deriva-tives up to the second order in all elements and all points. A modification for

Page 8: arXiv:1905.09118v2 [math.NA] 10 Jan 2020

8 Jan Valdman

-1 -0.5 0 0.5 1-1

-0.5

0

0.5

1

0.2

0.4

0.6

0.8

0

0.2

0.4

0.6

0.8

Fig. 5. A function v(x, y) = (1 − x2)2(1 − y2)2 on Ω = (−1, 1)2 and its values inelements midpoints (left) and edges midpoints (right).

evaluation of function values at particular edges points is also available andessential for instance for models with energies formulated on boundary edges [8].

Example 4. We consider a function

v(x, y) = (1− x2)2(1− y2)2 (9)

on the domain Ω = (−1, 1)2. This function was also used in [4] as an initialvertical displacement in a time-dependent simulation of viscous von Karmanplates.

To represent v in terms of BFS elements, we additionally need to know valuesof

∂v

∂x(x, y) = −4x(1− x2)(1− y2)2 (10)

∂v

∂x(x, y) = −4y(1− x2)2(1− y2) (11)

∂2v

∂x∂y(x, y) = 16xy(1− x2)(1− y2) (12)

in nodes of a rectangular mesh T (Ω). The function and its derivatives up tothe second order are shown in Figure 4 and its values in elements and edgesmidpoints in Figure 5.

All pictures can be reproduced by

draw_C1example_2D

script located in the main folder.

Page 9: arXiv:1905.09118v2 [math.NA] 10 Jan 2020

MATLAB Implementation of C1 finite elements 9

-1 0 1-1

-0.5

0

0.5

1

-1 0 1-1

-0.5

0

0.5

1

-1 0 1-1

-0.5

0

0.5

1

Fig. 6. 1, 4 and 9 Gauss points shown on actual rectangles of a square domain with 4rectangles.

2.4 Evaluation of C1 functions and their numerical integration

Various energy formulations include evaluations of integrals of the types

||v||2 : =

∫Ω

|v(x, y)|2 dxdy, (13)

||∇v||2 : =

∫Ω

|∇v(x, y)|2 dxdy, (14)

||∇2v||2 : =

∫Ω

|∇2v(x, y)|2 dx dy, (15)

(f, v) : =

∫Ω

f v dx dy, (16)

where v ∈ H2(Ω) and f ∈ L2(Ω) is given. The expression

(||v||2 + ||∇v||2 + ||∇2v||2)1/2

then defines the full norm in the Sobolev space H2(Ω). For v represented in theBFS basis we can evaluate above mentioned integrals numerically by quadraturerules. Our implementation provides three different rules with 1, 4 or 9 Gausspoints. Each quadrature rule is defined by coordinates of all Gauss points andtheir weights.

Example 5. Gauss points are displayed in Figure 6 and all pictures can be re-produced by

draw_ips

script located in the main folder.

Example 6. An analytical integration for the function v from (9) and f = x2y2

reveals that

||v||2 = 65536/99225 ≈ 0.660478710002520,

||∇v||2 = 131072/33075 ≈ 3.962872260015117,

||∇2v||2 = 65536/1225 ≈ 53.498775510204084,

(f, v) = 256/11025 ≈ 0.023219954648526

Page 10: arXiv:1905.09118v2 [math.NA] 10 Jan 2020

10 Jan Valdman

2 4 6 8 10

0.3

0.4

0.5

0.6

0.7|| v ||2

2 4 6 8 10

3.5

4

4.5

|| v ||2

2 4 6 8 10

40

45

50

|| 2v ||2

2 4 6 8 10

0

0.1

0.2

0.3

0.4

0.5

( f, v )

2 4 6 8 10

10-10

100

error of || v ||2

2 4 6 8 10

10-10

100

error of || v ||2

2 4 6 8 10

10-10

100

error of || 2v ||2

2 4 6 8 10

10-5

100error of ( f, v )

Fig. 7. Values of integrals (the left column) and their absolute error (the right column)for levels 1-10 of uniform refinements using three different quadrature rules: 1 Gausspoint - blue lines with diamonds, 4 Gauss points - yellow lines with circles, 9 Gausspoints - red lines with squares.

Page 11: arXiv:1905.09118v2 [math.NA] 10 Jan 2020

MATLAB Implementation of C1 finite elements 11

for a domain Ω = (−1, 1)2. We consider a sequence of uniformly refined mesheswith levels 1-10:

– the coarsest (level=1) mesh with 9 nodes and 4 elements is shown in Figure6,

– a finer (level=4) mesh with 289 nodes and 256 elements is shown in Figure3 (left),

– the finest (level=10) mesh consists of 1.050.625 nodes and 1.048.576 ele-ments, not shown here.

Figure 7 the depicts the convergence of numerical quadratures to the exact val-ues above. We notice that all three quadrature rules provide the same rates ofconvergence. The only exception is the evaluation of the second gradient integral||∇2v||2, where the numerical quadrature using 1 Gauss point deteriorates theconvergence.

All pictures can be reproduced by

start_integrate

script located in the main folder.

References

1. I. Anjam, J. Valdman: Fast MATLAB assembly of FEM matrices in 2D and 3D:Edge elements, Applied Mathematics and Computation 267, 252–263 (2015).

2. F.K. Bogner, R.L. Fox and L.A. Schmit: The generation of inter-element compat-ible stiffness and mass matrices by the use of interpolation formulas, Proceedingsof the Conference on Matrix Methods in Structural Mechanics, 397–444 (1965).

3. P.G. Ciarlet: The Finite Element Method for Elliptic Problems, SIAM, Philadel-phia (2002).

4. M. Friedrich, M. Kruzık, J. Valdman: Numerical approximation of von Karmanviscoelastic plates, Discrete and Continuous Dynamical Systems - Series S (ac-cepted).

5. S. Forest: Micromorphic approach for gradient elasticity, viscoplasticity, and dam-age, J. Eng. Mech. 135, No. 3 (2009).

6. P. Harasim, J. Valdman: Verification of functional a posteriori error estimates foran obstacle problem in 2D, Kybernetika 50, No. 6 , 978–1002 (2014).

7. S. Kromer, J. Valdman: Global injectivity in second-gradient Nonlinear Elasticityand its approximation with penalty terms, Mathematics and Mechanics of Solids24, No. 11, 3644–3673 (2019).

8. S. Kromer, J. Valdman: Surface penalization of Self-Interpenetration in second-gradient Nonlinear Elasticity, (in preparation).

9. T. Rahman, J. Valdman: Fast MATLAB assembly of FEM matrices in 2D and 3D:Nodal elements, Applied Mathematics and Computation 219, 7151–7158 (2013).