162 115 9MB
English Pages [355] Year 2024
Table of contents :
Preface
Introduction to the finite element method handbook
1. Basics of finite element method
Exemplary problem of two-dimensional bitmap projection
Approximation with B-spline basis functions
Derivation of the system of linear equations
Generation of the system of linear equations with the analytical method
The solution of the system of linear equations
Interpretation of the solution
MATLAB implementation of the bitmap projection problem
2. Discretization with different basis functions
Linear basis functions
Higher-order Ck basis functions in 1D
Lagrange polynomials
Refined isogeometric analysis in 1D
Two-dimensional generalization of basis functions with tensor products
Three-dimensional generalization of basis functions with tensor products
Non-regular meshes
MATLAB implementation of the generation of basis functions based on the knot vector
3. Weak formulations for different problems and methods
Heat transfer with isogeometric finite element method
Heat transfer with classical finite element method
Advection-diffusion equations
Stokes problem
Linear elasticity
Weak formulations and numerical integration
MATLAB implementation of the heat transfer problem
MATLAB implementation of the advection-diffusion with Galerkin method
4. Solvers of linear equations generated from finite element method
Gaussian elimination algorithm
Gaussian elimination with a pivoting algorithm
LU factorization algorithm
Algorithm of LU factorization with pivoting
Frontal solver algorithm
Multi-frontal solver algorithm
Direction-splitting algorithm
Pre-conditioner
Iterative solver algorithm
Selection of the solver based on problem kind
MATLAB implementation of the alternating-direction solver for the bitmap projection problem
5. Stabilization methods
Stabilization of finite element method
Stabilization of the advection-diffusion equations with the residual minimization method
Stabilization of the advection-diffusion equations with the Streamline Upwind Petrov-Galerkin (SUPG)
Stabilization of the Stokes problem with the residual minimization method
Stabilization of the Stokes problem with the Discontinuous Galerkin method (DG)
MATLAB implementation of the advection-diffusion problem with SUPG
MATLAB implementation of the advection-diffusion problem with residual minimization method
6. Computational grids
Generation and adaptation of computational grids
Algorithm of adaptation of triangular and tetrahedral elements
Algorithm of h-adaptation
Algorithm of p-adaptation
Algorithm of hp-adaptation
Approximation on the mesh with hanging nodes
Isogeometric analysis on adaptive grids
MATLAB implementation of the adaptive algorithm for the bitmap projection problem
7. Finite element method for non-stationary and non-linear problems
Non-stationary problems
Non-stationary problems as a generalization of a sequence of the isogeometric L2 projections
Examples of differential operators and right-hand-sides for selected problems
Explicit method
Implicit method
Crank-Nicolson scheme
Alpha scheme
Example of the non-stationary linear problem: propagation of pollution
MATLAB implementation of the alpha scheme for the heat transfer problem
Example of the non-stationary non-linear problem: non-linear flow in heterogeneous media
8. Mathematical foundations of the finite element method
Functional spaces
One-dimensional finite element
The one-dimensional strong and weak formulation for the elliptic problem
One-dimensional finite element method
Example of a one-dimensional finite element method
Two-dimensional finite element
The two-dimensional strong and weak formulation for the elliptic problem
Two-dimensional finite element method
Adaptive algorithm
The convergence of the finite element method
Isogeometric finite element method
The future of the finite element method
Appendices
Appendix 1
Appendix 2
Appendix 3
Appendix 3A
Appendix 4
Appendix 4A
Appendix 5
Appendix 5A
Appendix 6
Appendix 7
Classical and isogeometric finite element method Maciej Paszynski
Pod redakcją: Maciej Paszynski
Kraków 2024
Title:Classical and isogeometric finite element method Authors: Maciej Paszynski (AGH University of Science and Technology, Faculty of Computer Science, Electronics and Telecommunications) Reviewers:prof. dr hab. inż. Maciej Pietrzyk, dr hab. inż. Krzysztof Banaś Date of publication:01.01.2021 ISBN: 978-83-952566-9-1
AGH University of Krakow Al. Mickiewicza 30 30-059 Kraków
The publication is available under the Creative Commons Attribution-ShareAlike 4.0 license. Certain rights reserved to the authors and the AGH University of Krakow. Any use of the publication is permitted, provided that the authors and the AGH University of Krakow are credited, providing a link to the publication and information about the license along with the link https://creativecommons.org/licenses/by-sa/4.0/deed.pl.
Distribution of this manual in whole or in part in digital form (including PDF or HTML) and/or printed form requires marking: The original version of the e-textbook is available at: https://epodreczniki.open.agh.edu.pl/handbook/1088
Contents 0.1. Preface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 0.2. Introduction to the finite element method handbook . . . . . . . . . . . . . . . . . . . . . . 1 1. Basics of finite element method 1.1. Exemplary problem of two-dimensional bitmap projection . . . . . . . . 1.2. Approximation with B-spline basis functions . . . . . . . . . . . . . . . 1.3. Derivation of the system of linear equations . . . . . . . . . . . . . . . 1.4. Generation of the system of linear equations with the analytical method 1.5. The solution of the system of linear equations . . . . . . . . . . . . . . 1.6. Interpretation of the solution . . . . . . . . . . . . . . . . . . . . . . . 1.7. MATLAB implementation of the bitmap projection problem . . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
2 2. Discretization with different basis functions 2.1. Linear basis functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2.2. Higher-order Ck basis functions in 1D . . . . . . . . . . . . . . . . . . . . . . . . . . 2.3. Lagrange polynomials . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2.4. Refined isogeometric analysis in 1D . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2.5. Two-dimensional generalization of basis functions with tensor products . . . . . . . . . 2.6. Three-dimensional generalization of basis functions with tensor products . . . . . . . . 2.7. Non-regular meshes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2.8. MATLAB implementation of the generation of basis functions based on the knot vector 3 3. Weak formulations for different problems and methods 3.1. Heat transfer with isogeometric finite element method . . . . . . . . . . 3.2. Heat transfer with classical finite element method . . . . . . . . . . . . . 3.3. Advection-diffusion equations . . . . . . . . . . . . . . . . . . . . . . . . 3.4. Stokes problem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3.5. Linear elasticity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3.6. Weak formulations and numerical integration . . . . . . . . . . . . . . . 3.7. MATLAB implementation of the heat transfer problem . . . . . . . . . . 3.8. MATLAB implementation of the advection-diffusion with Galerkin method 4 4. Solvers of linear equations generated from finite element method 4.1. Gaussian elimination algorithm . . . . . . . . . . . . . . . . . . . . . 4.2. Gaussian elimination with a pivoting algorithm . . . . . . . . . . . . . 4.3. LU factorization algorithm . . . . . . . . . . . . . . . . . . . . . . . 4.4. Algorithm of LU factorization with pivoting . . . . . . . . . . . . . . 4.5. Frontal solver algorithm . . . . . . . . . . . . . . . . . . . . . . . . . 4.6. Multi-frontal solver algorithm . . . . . . . . . . . . . . . . . . . . . . 4.7. Direction-splitting algorithm . . . . . . . . . . . . . . . . . . . . . . 4.8. Pre-conditioner . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
3 4
. . . . . . .
9 9 11 15 17 22 24 25
. . . . . . . .
27 27 29 32 34 40 43 47 51
. . . . . . . .
55 55 62 67 69 73 79 82 82
. . . . . . . .
87 87 96 102 108 113 118 121 124
0.CONTENTS 4.9. Iterative solver algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124 4.10. Selection of the solver based on problem kind . . . . . . . . . . . . . . . . . . . . . . . . . . 127 4.11. MATLAB implementation of the alternating-direction solver for the bitmap projection problem 128 5 5. Stabilization methods 5.1. Stabilization of finite element method . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.2. Stabilization of the advection-diffusion equations with the residual minimization method 5.3. Stabilization of the advection-diffusion equations with the Streamline Upwind Petrov-Galerkin (SUPG) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.4. Stabilization of the Stokes problem with the residual minimization method . . . . . . . . 5.5. Stabilization of the Stokes problem with the Discontinuous Galerkin method (DG) . . . 5.6. MATLAB implementation of the advection-diffusion problem with SUPG . . . . . . . . . 5.7. MATLAB implementation of the advection-diffusion problem with residual minimization method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 6. Computational grids 6.1. Generation and adaptation of computational grids . . . . . . . . . 6.2. Algorithm of adaptation of triangular and tetrahedral elements . . 6.3. Algorithm of h-adaptation . . . . . . . . . . . . . . . . . . . . . . 6.4. Algorithm of p-adaptation . . . . . . . . . . . . . . . . . . . . . . 6.5. Algorithm of hp-adaptation . . . . . . . . . . . . . . . . . . . . . 6.6. Approximation on the mesh with hanging nodes . . . . . . . . . . 6.7. Isogeometric analysis on adaptive grids . . . . . . . . . . . . . . . 6.8. MATLAB implementation of the adaptive algorithm for the bitmap
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . projection problem
. . . . . . . .
131 . . . 131 . . . 133 . . . .
. . . .
9 Appendices Open AGH e-podręczniki - content available under the CC BY-SA license
. . . . . . . . . . problem . . . . . . . . . . . . . . . problem . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
137 138 143 145
. . . 149
. . . . . . . .
. . . . . . . .
7 7. Finite element method for non-stationary and non-linear problems 7.1. Non-stationary problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7.2. Non-stationary problems as a generalization of a sequence of the isogeometric L2 projections 7.3. Examples of differential operators and right-hand-sides for selected problems . . . . . . . . . 7.4. Explicit method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7.5. Implicit method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7.6. Crank-Nicolson scheme . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7.7. Alpha scheme . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7.8. Example of the non-stationary linear problem: propagation of pollution . . . . . . . . . . . . 7.9. MATLAB implementation of the alpha scheme for the heat transfer problem . . . . . . . . . 7.10. Example of the non-stationary non-linear problem: non-linear flow in heterogeneous media . 8 8. Mathematical foundations of the finite element method 8.1. Functional spaces . . . . . . . . . . . . . . . . . . . . . . . . . 8.2. One-dimensional finite element . . . . . . . . . . . . . . . . . . 8.3. The one-dimensional strong and weak formulation for the elliptic 8.4. One-dimensional finite element method . . . . . . . . . . . . . . 8.5. Example of a one-dimensional finite element method . . . . . . 8.6. Two-dimensional finite element . . . . . . . . . . . . . . . . . . 8.7. The two-dimensional strong and weak formulation for the elliptic 8.8. Two-dimensional finite element method . . . . . . . . . . . . . 8.9. Adaptive algorithm . . . . . . . . . . . . . . . . . . . . . . . . 8.10. The convergence of the finite element method . . . . . . . . . . 8.11. Isogeometric finite element method . . . . . . . . . . . . . . . . 8.12. The future of the finite element method . . . . . . . . . . . . .
. . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . .
153 153 156 158 162 165 176 178 181
. . . . . . . . . .
183 183 184 186 187 191 193 195 197 200 201
. . . . . . . . . . . .
207 207 208 211 212 217 219 221 223 228 232 233 235 237 2
0.1. Preface 9.1. Appendix 9.2. Appendix 9.3. Appendix 9.4. Appendix 9.5. Appendix 9.6. Appendix 9.7. Appendix 9.8. Appendix 9.9. Appendix 9.10. Appendix
0.1.
1. 2. 3. 3A 4. 4A 5. 5A 6. 7.
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
237 246 248 260 274 285 296 311 326 338
Preface
Authors This handbook provides a comprehensive introduction to the finite element method, including isogeometric analysis methods. The chapters are supplemented with sample MATLAB codes (which can be run in the free version of Octave). The author of the text is prof. dr hab. Maciej Paszyński. The authors of the MATLAB codes are doctor engineer Marcin Łoś, PhD, as well as doctor engineer Maciej Woźniak, PhD, from the Department of Computer Science and a member of my team of Algorithms and Adaptive Systems. Marcin Łoś and Maciej Woźniak are the authors of the codes in MATLAB in the chapters: • MATLAB implementation of the bitmap projection problem, • MATLAB implementation of the generation of basis functions based on the knot vector, • MATLAB implementation of the heat transfer problem, • MATLAB implementation of the advection-diffusion with Galerkin method, • MATLAB implementation of the alternating-direction solver for the bitmap projection problem, • MATLAB implementation of the advection-diffusion problem with SUPG, • MATLAB implementation of the advection-diffusion problem with residual minimization method, • MATLAB implementation of the adaptive algorithm for the bitmap projection problem, • MATLAB implementation of the alpha scheme for the heat transfer problem. Acknowledgments I would like to thank Maciek and Marcin for the advanced implementations in MATLAB. I would also like to thank my wife, habilitated doctor Anna Paszyńska, PhD, DSc from Jagiellonian University for helping to prepare many drawings for the textbook. I would like to thank the reviewers, prof. Maciej Pietrzyk and prof. Krzysztof Banas for their very thorough reading of the book and detailed reviews, the inclusion of which significantly increased the quality of the textbook. Audience My textbook is addressed to students of technical and IT studies, and therefore focuses on the practical and implementational aspects of individual issues related to the finite element method. However, my textbook does not deal with the mathematical theory of the convergence of the finite element method. Open AGH e-podręczniki - content available under the CC BY-SA license
3
0.2. Introduction to the finite element method handbook Readers interested in the mathematical foundations of the finite element method should read the chapter ”Mathematical foundations of the finite element method”. For readers who are more interested in the implementational aspects and a general introduction to the finite element method, I encourage you to skip this chapter at the first reading and start reading from the chapter ”Exemplary problem of two-dimensional bitmap projection”.
0.2.
Introduction to the finite element method handbook
Introduction This handbook describes both the classical finite element method and the isogeometric finite element method. The first scientific papers on the finite element method come from 1940 by Richard Courant (professor of mathematics, born in Lubliniec, Poland in 1888 in the then German territory, immigrated to the USA) and Alexander Hrennikoff (professor of civil engineering, born in Russia, emigrated to Canada), and Feng Kang in China in 1950 [1], [2], [3]. This method became popular in the years 1960-1970 thanks to the work of Olgierd Ziemkiewicz (civil engineering professor, Polish descent, lived in the UK)(civil engineering professor, Polish descent, lived in UK)[4]. In recent years, the isogeometric finite element method, promoted by the team of Prof. T. J. R. Hughes, has become popular. It uses basis functions from the B-spline family, characterized by a higher degree of continuity C k [5]. Parallel to the methods of isogeometric analysis, adaptive methods are being developed using the classical finite element method with hierarchical basis functions. hp adaptive algorithms, allowing for exponential convergence of solution accuracy in relation to the size of the computational grid, are being developed by the group with prof. Leszek Demkowicz (Polish mathematician and professor of mechanics, working at the University of Texas in Austin)[6], [7]. There are also attempts to combine adaptive methods with isogeometric analysis by creating new families of polynomials, possible to define on adaptive grids, enabling mixing polynomials from the B-spline family to various degrees [8]. The classical method of finite elements on regular meshes is a special case of the isogeometric finite element method. The classical method of finite elements on regular meshes is a special case of the isogeometric finite element method. The only difference is that the basis functions used in the classical finite element method are polynomials of degree p of continuity C p−1 inside the elements, and on the border of the finite elements they are of class. C 0 . Isogeometric method of finite elements generalizes base functions into polynomials of degree p which can be class C k over the entire calculation area. They can also be classes C p−1 only inside elements and classes C 0 at the interface of the elements. In particular, the B-spline functions used in the isogeometric method of finite elements are defined by the so-called knot vectors. The repetition of knots at the element boundary yields B-spline functions equivalent to classical Lagrange polynomials. The isogeometric finite element method is usually used on grids that are the image of regular (square or cubic) element groups, while the classical finite element method can use square or triangular elements in 2D and cubic, tetrahedral, prisms and pyramids in 3D. There are, however, modern methods for defining B-spline functions on triangular and tetrahedral elements, and then this equivalence (the fact that isogeometric finite element method increases the continuity of basic functions) is preserved. The classical finite element method approximates scalar fields and vectors appearing in piecewise continuous engineering calculations and the isogeometric finite element method in a globally continuous way. There are of course computational problems for which the isogeometric method gives a better approximation, and computational problems for which the classical finite element method gives better approximations. What elements, in my opinion, should the textbook on classical finite element method contain? Open AGH e-podręczniki - content available under the CC BY-SA license
4
0.2. Introduction to the finite element method handbook 1. Introduction of the finite element definition and classical functions base polynomials such as Lagrange polynomials and hierarchical polynomials used, for example, in the adaptive finite element method. These definitions should include at least rectangular elements and triangular in two dimensions. 2. Introduction of algorithms for the generation of computational meshes, in particular made of triangles and tetrahedra, and algorithmic adaptation of computational grids. 3. Presentation of a number of simple problems in a strong and weak form. 4. Presentation of algorithms for the generation of systems of equations, left matrix sides (called ‘stiffness matrix’ for some problems) and the right-hand side vector. 5. Presentation of solver algorithms used for solving systems of equations. 6. Presentation of sample computational problems with results. 7. Presentation of stabilization methods for computationally difficult problems, for example, the Discountinuous Galerkin (DG) method or the Streamline Upwind Petrov-Galerkin (SUPG) method. Ad.1) Formal definitions of the classical finite element method are described in the modules of the chapter ”Mathematical foundations of the finite element method”. The book also includes a number of informal definitions. In particular, triangular elements are described in the chapter ”Non-regular meshes”; Lagrange polynomials on rectangular and cubic elements are defined by repeating nodes in the node vector defining B-spline basis functions (remembering that Lagrange polynomial functions are included in B-spline functions) in the chapter ”Discretization with different basis functions”. Ad.2) The mesh generation algorithms are described in detail in the chapter ”Computational grids”. Ad.3) Weak and strong forms do not depend on the way of discretization. In the chapter ”Weak formulations for different problems and methods” a number of variational formulations are given, whether or not we use the classical or the isogeometric method. We have, in particular, heat transport equations, convection-diffusion equations, the Stokes problem, and the equations of the linear elasticity problem. These chapters also contain the digitization usually done with the help of the isogeometric finite element method; however, in the general part on strong and variational formulations, they are independent methods of discretization. Ad.4) The problem of the generation of systems of equations resulting from the discretization of the classical finite element method is illustrated in the chapter ”Heat transfer with classical finite element method” for a two-dimensional case. Relevant algorithms for the classical finite element methods can be found in the chapter ”Mathematical foundations of the finite element method”. There you can also find an example of the one-dimensional classical finite element method. Ad.5) The algorithms of solvers are described in the chapter ”Solvers of linear equations generated from finite element method”, in the modules ”Gaussian elimination algorithm”, ”Gaussian elimination with a pivoting algorithm”, ”LU factorization algorithm”, ”Frontal solver algorithm”, ”Multi-frontal solver algorithm”, ”Direction-splitting algorithm”, ”Pre-conditioner”. Ad.6) In the chapter ”Weak formulations for different problems and methods” and in the module ”Heat transfer with classical finite element method” there is an example of a weak and strong formulation for the two-dimensional problem of heat transport using the classical finite element method, and a number of algorithms concerning the generation of a system of equations. The section ”Mathematical foundations of the finite element method” provides an example of one-dimensional classical finite element method, and a series of useful algorithms. Ad.7) The DG stabilization method is described in the chapter ”Stabilization methods” and in the module ”Stabilization of the Stokes problem with the Discontinuous Galerkin method (DG)”. In the module ”Stabilization of the advection-diffusion equations with the Streamline Upwind Petrov-Galerkin (SUPG)”, the SUPG method is described which works for both classical and isogeometric finite element methods. Open AGH e-podręczniki - content available under the CC BY-SA license
5
0.2. Introduction to the finite element method handbook What elements in my opinion should the textbook on isogemetric finite element method include? 1. Introduction of B-spline basis functions defined on a group (a patch) of items. These definitions should include the method of defining functions with a knots vector. 2. Introduction to algorithms for mapping geometric objects by element patches in CAD systems, element-to-object geometric patch mapping, and an element patch of adaptive algorithms. 3. Presentation of a number of simple problems in a strong and weak form. 4. Presentation of algorithms for generation of systems of equations, the left matrix side (called ‘stiffness matrix’ for certain problems) and the right-side vector. 5. Presentation of solver algorithms used for solving systems of equations. 6. Presentation of sample computational problems with results. 7. Presentation of stabilization methods for computationally difficult problems, e.g., residual minimization methods, the SUPG method. Ad.1) This aspect is described in detail in the chapter ”Discretization with different basis functions”, the modules ”Linear basis functions”, ”Higher-order Ck basis functions in 1D”, ”Refined isogeometric analysis in 1D”, ”Two-dimensional generalization of basis functions with tensor products”, ”Three-dimensional generalization of basis functions with tensor products”. Ad.2) The aspect of adaptive calculations in the isogeometric method is briefly described in the chapter ”Computational grids” and the module ”Isogeometric analysis on adaptive grids”. The mapping aspect of CAD objects on groups of elements has been omitted from this book due to its breadth and belonging to related (but different) topics related to modeling geometry in CAD systems. Ad.3) This issue is illustrated in the chapters ”Exemplary problem of two-dimensional bitmap projection”, ”Approximation with B-spline basis functions”, ”Derivation of the system of linear equations”, ”Generation of the system of linear equations with the analytical method”, ”The solution of the system of linear equations” and ”Interpretation of the solution”. Ad.4) These algorithms are described in the chapter ”Solvers of linear equations generated from finite element method”, the modules ”Gaussian elimination algorithm”, ”Gaussian elimination with a pivoting algorithm”, ”LU factorization algorithm”, ”Frontal solver algorithm”, ”Multi-frontal solver algorithm”, ”Direction-splitting algorithm” and ”Pre-conditioner”. As such, all these algorithms are independent of whether we use the classical or isogeometric finite element method. Additionally, the modules ”Iterative solver algorithm” and ”Selection of the solver based on problem kind” refer to the isogeometric finite element method. Ad.5) The solvers algorithms are described in the chapter ”Solvers of linear equations generated from finite element method” in the modules ”Gaussian elimination algorithm”, ”Gaussian elimination with a pivoting algorithm”, ”LU factorization algorithm”, ”Frontal solver algorithm”, ”Multi-frontal solver algorithm”, ”Direction-splitting algorithm” and ”Pre-conditioner”. Ad.6) In the chapters ”Exemplary problem of two-dimensional bitmap projection” and ”Weak formulations for different problems and methods”, there are extensive calculation examples for the isogeometric finite element method provided. Ad.7) The stabilization method of the isogeometric finite element method has been described in the ”Stabilization methods” section in the modules ”Stabilization of the Stokes problem with the residual minimization method” and ”Stabilization of the advection-diffusion equations with the Streamline Upwind Petrov-Galerkin (SUPG)”. Additionally, the manual includes a chapter describing the extension of the finite element method for non-stationary problems (modeling the state of systems changing over time) and the aforementioned Open AGH e-podręczniki - content available under the CC BY-SA license
6
0.2. Introduction to the finite element method handbook chapter introducing the mathematical foundations of the finite element method. Please send all comments and questions regarding the content of the book to the e-mail address [email protected].
Open AGH e-podręczniki - content available under the CC BY-SA license
7
0.2. Introduction to the finite element method handbook
Open AGH e-podręczniki - content available under the CC BY-SA license
8
Chapter 1
1. Basics of finite element method 1.1.
Exemplary problem of two-dimensional bitmap projection
In this chapter, we will look at an example of a projection problem that we will use to build the intuition underlying the finite element method.
EXAMPLE
Example 1: The bitmap projection problem Let us imagine we have got a two-dimensional bitmap like in Pic. 1. This bitmap represents a satellite image of the topography. The bitmap is monochrome, each pixel of the bitmap has an integer value ranging from 0 to 255. A pixel value of 0, represented in the figure by black pixels, indicates the parts of the terrain with the highest average height. These are places located on the tops of the mountains. In turn, the pixel value equals to 255, represented in the drawing by white pixels and means the parts of the area whose average height is the lowest. These are places located in the valleys of the mountains.
9
1.1. Exemplary problem of two-dimensional bitmap projection
Figure 1: A two-dimensional bitmap representing the topography. The intensity of each pixel varies between the values 0 and 255. Value 0 (black) is the area with the highest altitude (mountain top), value 255 (white) is the area with the lowest altitude (lowest point in the valley).
Now let us look at the computer representation of the terrain described by such a bitmap. Our area has been divided into square areas represented by individual pixels. The only information we have for each such fragment of the area is its average height corresponding to the height represented by the pixel intensity. If reality were like our bitmap, then we would have to jump from one flat square platform to another flat square platform, and their heights would vary from 0 to 255, resulting from the difference between the minimum and maximum topography in certain units.
Open AGH e-podręczniki - content available under the CC BY-SA license
10
1.2. Approximation with B-spline basis functions
Figure 2: Continuous approximation of the terrain from a bitmap representing an elevation map. Now, for better illustration, the highest parts of the area are marked in red, and the lowest parts of the area are marked in dark blue.
Let us imagine now that we want to drag our computer representation of the terrain. We want the heights to change continuously, as if our universe were made of slender plastic. Of course, such a representation of the terrain will be closer to reality, but still only an approximation. We want to make a ”plastic” cast of our area as shown in Pic. 2. Our model is no longer a bitmap containing flat pixels, but rather a slim plastic cast of reality on which you can slide from one place to another.
1.2.
Approximation with B-spline basis functions
In order to write a computer program to calculate this continuous approximation of the terrain, we need to do the following. First, we have to describe our problem in a formal, mathematical way. In particular, we have to choose the mathematical definition of the object - bitmap, and the mathematical definition of our continuous description of the terrain represented by the bitmap. It seems reasonable to say that a bitmap is a function defined in an area Ω = [1, maxx] × [1, maxy] 3 (x, y) → BIT M AP (x, y) ∈ [0, 255]
Open AGH e-podręczniki - content available under the CC BY-SA license
11
1.2. Approximation with B-spline basis functions where by Ω we mark the entire area where our bitmap is spread. In turn, our continuous representation of the world will be represented by a function u of real values. Ω = [1, maxx] × [1, maxy] 3 (x, y) → u(x, y) ∈ [0, 255] We want our function to be ”smooth” and continuous. Mathematically, we write the condition that our function will be of the C 1 class, it means that at each point it will be smooth enough to compute its derivatives in directions perpendicular to the edges of our area. This practically means that at every point we can apply a ”ruler” to the graph of our function perpendicularly to one of the edges of our area, and measure the angle between this ruler and the base (a flat surface spread out at zero height). After all, the derivative is nothing but the tangent of this angle. In other words, our function will have no ”kinks” or gaps where you would not know how to use our ruler. At the bends, this ruler would jump from one position to another, and in the case of a hole, it would not be clear how to use it. Of course, the ability to measure the derivative (placing a ruler) in two directions perpendicular to the edge of the area also means the ability to apply a ruler and measure directional derivatives in any other directions not perpendicular to the edge. Hence, we can smoothly move across the plot of such a smooth function in any direction. How to get such a continuous smooth function? We have to decide how our function will be constructed. For example, we can divide the area over which the bitmap spans into certain elements, and based on these elements we can define a set of many smooth functions, from which we then ”glue” our u function. Let us imagine that at the height corresponding to the zero height (equal to the value of the zero pixel) Let us imagine that at the height corresponding to the zero height (equal to the value of the zero pixel) we build a flat two-dimensional mesh, of which the number of square elements is arbitrary. These meshes, according to the adopted nomenclature, will be called finite elements, because each of these elements has a limited finite area. We might have fewer elements than the pixels in the bitmap, and then several pixels will be spread over each such element. The boundaries between our elements do not have to match the boundaries of the pixels. They can be freely defined on a flat surface. It may also be the case that there are more elements than pixels, and then there will be many such elements in each pixel. Let us assume, however, that we have fewer elements than pixels. They form a regular grid of Nx ∗ Ny finite elements. Now, on each such element, we define a smooth function. We can use B-spline functions for this purpose. These functions were first introduced by the American mathematician of Romanian origin, Isaac Jakub Schoenberg [9]. B-spline functions are widely used in computer modeling and simulations thanks to the growing popularity of the field called isogeometric analysis disseminated by prof. T. J. R. Hughes [5]. The idea behind these methods is to use families of B-spline functions for finite element calculations. We denote these functions by Bi,j;2 (x, y), where i and j denote the numbering of our functions, and 2 means that they are polynomials with pieces of the second order, class C 1 .
Open AGH e-podręczniki - content available under the CC BY-SA license
12
1.2. Approximation with B-spline basis functions
Figure 3: Three exemplary B-spline functions spread on a two-dimensional mesh.
Pic. 3 shows three exemplary two-dimensional B-spline functions spanned over a two-dimensional mesh. Each such two-dimensional B-spline function is created by selecting and multiplying by itself two one-dimensional B-spline functions, one selected from the set of one-dimensional B-spline functions spanning along the horizontal axis of the mesh, and the other selected from the set of one-dimensional B-spline functions spanning along the vertical axis of the mesh. These sets are called the basis of one-dimensional B-spline functions. y x In turn, we denote these one-dimensional B-spline functions Bi;2 (x) and Bj;2 (y) where variables x and y identify the directions (coordinate axes) along which our B-splines (horizontal axis x and vertical axis y), i and j numbering areas of these functions (which next one-dimensional B-spline side we choose from such one-dimensional basis), and 2 means again that they are polynomials of the second degree, of the class C 1 (i.e. that we can compute the first derivatives of them).
Then the selected one-dimensional functions are multiplied by themselves, which gives us a smooth two-dimensional B-spline basis. Such a relaxation of a function by multiplying two-dimensional functions is called a tensor product of a function. y x Bi,j;2 (x, y) = Bi;2 (x)Bj;2 (y)
This is illustrated in Pic. 3 and Pic. 4.
Open AGH e-podręczniki - content available under the CC BY-SA license
13
1.2. Approximation with B-spline basis functions The two-dimensional B-spline functions given in this way have the shape of a slender ”hill”, with similarity among nine adjacent elements. The highest point of such a function - the hill - is in the center of the middle element. These functions go down to the zero value, assumed at the edges of the span defined by the nine elements on which the function is defined. These functions, according to the nomenclature, are called basis functions.
Figure 4: Two-dimensional B-spline functions glued by two one-dimensional B-spline functions.
Our continuous approximation of the terrain is obtained by adding together many such slender hills B-splines. Each of them will be scaled (raised up or down) so as to obtain a total of the continuous approximation of the terrain. If we correctly select the heights of individual hills, then we will get smooth approximations of our terrain as presented in Pic. . Now the question is how to choose the heights to which we will draw our basis functions. The first method that comes to mind is to choose the pixel value z BIT M AP (x, y) exactly at the highest point of the B-spline (in the middle of the hill). Unfortunately, this method has several disadvantages. First, if there are fewer B-spline basis functions than pixels, then we ignore all neighboring pixels in our B-spline area, choosing only one value from the center of the area. Our bitmap is likely to have some disturbances and the fact that we will hit a localkickback is a measurement error, or we may hit a local hole in the terrain, or a local tree or building that has disturbed the measurement of the terrain. Secondly, we will notice that our basis functions extend over a square of nine elements. Since each such B-spline function can be associated with the center of its element, and each of these functions extends over nine adjacent elements, it means that there is a total of nine such functions spread on each element, and that the adjacent functions overlap. So, if we were to stretch the functions so that their maximum point coincides with the central pixel, and we summed all these functions together to get our global function u, then on each element, even in the central point, our resulting approximation (the sum of these functions) would be higher than our central pixel. It is because the adjacent eight functions would also be non-zero on a given element and would raise the value of our approximation at this point up. Open AGH e-podręczniki - content available under the CC BY-SA license
14
1.3. Derivation of the system of linear equations
1.3.
Derivation of the system of linear equations
The problem of selecting coefficients for the linear combination of the B-spline function used for bitmap approximation (the problem of scaling individual B-splines) is a global problem, and it should be solved taking into account all the coefficients simultaneously. In order do to so, we conduct the following reasoning which is the basis of the intuition underlying the finite element method. Our goal is to approximate a bitmap using a smooth function u u(x, y) ≈ BIT M AP (x, y). Our slim feature u it is formed by the linear combination of many base functions PNx ,Ny y x u(x, y) = i=1,j=1 ui,j Bi (x)Bj (y) where u(x, y) =j (y) are the coefficients of this combination, the values which we must calculate. Our base functions are spread over Nx ∗ Ny mesh elements. So there are also Nx ∗ Ny base functions, and therefore we need to calculate Nx ∗ Ny coefficients ui,j . Each of these coefficients ui,j tells me how to scale one base function, a two dimensional B-spline function Bi,j;2 (x, y) = Bix (x)Bjy (y). How do we calculate these {ui,j }i = 1, .., Nx ; j = 1, ..., Ny coefficients?. Instead of choosing pixel values, we will use the averaging method. We also use our B-spline base functions for averaging. We want our approximation to approximate the bitmap u(x, y) ≈ BIT M AP (x, y). So let’s choose any B-spline function v(x, y) = Bk,l;2 (x, y) = Bkx Bly . We chose a function with indices k, l. For simplicity, we name it v. Three exemplary selections of our B-spline function are illustrated in the figure. We will call this function a test function. This is the standard nomenclature used in the finite element method. We then use our test function to compute the average of the bitmap surrounding the function. In other words, we want our approximation u to approximate our bitmap with such averaging distribution as our test function gives us. To write this operation mathematically, we multiply our approximation equations by the test function and calculate the integral R R u(x, y)v(x, y) = Ω BIT M AP (x, y)v(x, y). Ω The focal point has the greatest impact on the value of this mean, according to the appearance of the B-spline basis function, and the more distant points have a smaller effect on the mean value. Now we can note that one selection of the test function v gives us one equation. How many ways can we choose our test functions? Since each of them is a B-spline associated with the center of an element, and there are Nx ∗ Ny elements, it means we can choose Nx ∗ Ny test functions. Each of these selections of test functions gives us one equation, so we get a system of Nx ∗ Ny equations R R u(x, y)B1x (x)B1y (y) = BIT M AP (x, y)B1x (x)B1y (y) R R u(x, y)B1x (x)B2y (y) = BIT M AP (x, y)B1x (x)B2y (y) .. . R
u(x, y)Bkx (x)Bly (y) =
R
BIT M AP (x, y)Bkx (x)Bly (y)
.. .
Open AGH e-podręczniki - content available under the CC BY-SA license
15
1.3. Derivation of the system of linear equations R y y x x u(x, y)BN (x)BN (y) = BIT M AP (x, y)BN (x)BN (y) x x y −1 y −1 R R y y x x u(x, y)BN (x)BN (y) = BIT M AP (x, y)BN (x)BN (y). x x y y R
The question that needs to be asked now is that of the unknowns in our system of equations. We have Nx ∗ Ny equations, but where are the unknowns? To reach the unknowns, remember how our function is constructed u approximating a bitmap. P u(x, y) ≈ i,j ui,j Bix (x)Bjy (y) Our unknowns are coefficients {ui,j }i = 1, ..., Nx , j = 1, ..., Ny specifying how we ”pull” individual B-splines ”hills” in order to obtain the best bitmap approximation. So we put our linear combination of B-spline in place u and we get RP R y y x x BIT M AP (x, y)B1x (x) ∗ B1y (y) i,j ui,j Bi (x)Bj (y)B1 (x) ∗ B1 (y) = RP R y y x x BIT M AP (x, y)B1x (x) ∗ B2y (y) i,j ui,j Bi (x)Bj (y)B1 (x) ∗ B2 (y) = .. . RP
i,j
ui,j Bix (x)Bjy (y)Bkx (x) ∗ Bly (y) =
R
BIT M AP (x, y)Bkx (x) ∗ Bly (y)
.. . RP
R y y x x ui,j Bix (x)Bjy (y)BN (x) ∗ BN (y) = BIT M AP (x, y)BN (x) ∗ BN (y) x x y −1 y −1 RP R y y y x x x BIT M AP (x, y)BN (x) ∗ BN (y) i,j ui,j Bi (x)Bj (y)BNx (x) ∗ BNy (y) = x y i,j
We now use the algebraic property of the system of equations, which allows us to extract the sum with the coefficients over the individual integrals R x R P Bi (x)Bjy (y)B1x (x) ∗ B1y (y) = BIT M AP (x, y)B1x (x) ∗ B1y (y) i,j ui,j R x R P Bi (x)Bjy (y)B1x (x) ∗ B2y (y) = BIT M AP (x, y)B1x (x) ∗ B2y (y) i,j ui,j .. . P
ui,j
.. . P
ui,j
i,j
R
Bix (x)Bjy (y)Bkx (x) ∗ Bly (y) =
R
BIT M AP (x, y)Bkx (x) ∗ Bly (y)
R y y x x Bix (x)Bjy (y)BN (x) ∗ BN (y) = BIT M AP (x, y)BN (x) ∗ BN (y) x x y −1 y −1 R x R P y y x x Bi (x)Bjy (y)BN (x) ∗ BN (y) = BIT M AP (x, y)BN (x) ∗ BN (y) i,j ui,j x x y y i,j
R
Note now that the above system of equations can be written in matrix form. R In particular, coefficients marked in red ui , j form a vector of unknowns, Bix (x)Bjy (y)Bkx (x) ∗ Bly (y)dx integrals form a matrix whose lines are numbered i = 1, ..., Nx ; j = 1, ..., Ny , and columns from k = 1, ..., Nx ; l = 1, ..., Ny . This is because the integrals contain the products of two two-dimensional B-spline functions, two ”hills” spanning a finite element mesh. The first B-spline function, highlighted in black, is used for approximation, while the second B-spline function, highlighted in blue, is used to sample the bitmap (to compute the average of the bitmap). The vector of the right-hand side is the vector of integrals in which the bitmap is multiplied by the ”blue” testing B-spline used for averaging, and decomposed according to the distribution described by our test B-spline. In summary, we have thus obtained the following system of equations in which the unknowns are the coefficients {ui,j }i = 1, ..., Nx ; j = 1, ...Ny
Open AGH e-podręczniki - content available under the CC BY-SA license
16
1.4. Generation of the system of linear equations with the analytical method R x y x y R x y x y B1,p B1,p B1,p B1,p B B1,p B2,p B1,p R R 1,p y y y y x x x x B B B B B2,p B1,p B2,p B1,p 2,p 1,p 1,p 1,p .. .. . . R x R x y y y y x x BNx ,p BNy ,p B1,p B1,p BNx ,p BNy ,p B2,p B1,p R BIT M AP (x, y)B1x (x) ∗ B1y (y)dx R y BIT M AP (x, y)B1x (x) ∗ B2 (y)dx = .. . R y x BIT M AP (x, y)BN (x) ∗ B (y)dx Ny x
··· ··· .. . ···
R x y x y B B1,p BNx ,p BN u1,1 y ,p R 1,p y y x x B2,p B1,p BN BN u2,1 x ,p y ,p .. .. . . R x y y x uNx ,Ny BNx ,p BN BN BN x ,p y ,p y ,p
In a ”magical” way, solving the above system of equations will give us the best approximation factors for the bitmap through our B-splines. The aforementioned ”magic” results from determining the individual equations of our system, in which we postulated that on average - in the sense of the distribution determined by the B-spline testing functions our approximation will correspond to the bitmap.
1.4.
Generation of the system of linear equations with the analytical method
The next step is to generate a system of linear equations and solve it. Of course, we want the selected algorithms for the generation and solving of equation systems to be the fastest possible. First, we generate a matrix containing integrals from the products of two-dimensional B-spline functions. For the sake of simplicity, we can assume that the knot vectors are equidistant, and that the unit of distance along a given axis of the coordinate system is the distance between two nodes in the node vector. First note that R x y x y R x x R y y Bi,p Bj,p Bk,p Bl,p dxdy = Bi,p Bk,p dx Bj,p Bl,p dy In other words, because our two-dimensional B-splines are produced by multiplying one-dimensional B-splines, we can break our two-dimensional integrals into the product of two one-dimensional integrals in which we multiply and integrate pairs of one-dimensional B-splines. Hence, we need to generate the following matrix
R y y R x x B1,p B1,p dx B1,p B dy R y 1,p R x x y B2,p B1,p dx B1,p B1,p dy .. . R x R y y x BNx ,p B1,p dx BN B1,p dy y ,p
R x x R y y B1,p B2,p dx B1,p B dy R x x R y 1,p y B2,p B2,p dx B1,p B1,p dy .. . R x R y y x BNx ,p B2,p dx BN B1,p dy y ,p
··· ··· .. . ···
R x x R y y B1,p BNx ,p dx B1,p BNy ,p dy R x x R y y B2,p BNx ,p dx B1,p BNy ,p dy .. . R x R y y x BNx ,p BN dx B B dy Ny ,p Ny ,p x ,p (1.1)
Note that this matrix has the following structure. In the lines, the first B-splines in both single integrals (the x integrals and the y integrals) change. The lines change so that we have B splines first y y x x x x x x B1,p , B2,p , ..., BN for the fixed B1,p . Then we repeat all of them B1,p , B2,p , ..., BN for the fixed B2,p , x ,p x ,p and so on, there are blocks of all subsequent B-splines relative to x for consecutive established B-splines y y x x x Bj,p up to the last block in which they occur sequentially B1,p , B2,p , ..., BN for the fixed last BN x ,p y ,p
The situation is similar in the columns, but it applies to the second B-splines in each singular integral. So, y y y x the columns change so that we first have B-splines B1,p , B2,p , ..., BN for the fixed B1,p . Then we repeat y ,p Open AGH e-podręczniki - content available under the CC BY-SA license
17
1.4. Generation of the system of linear equations with the analytical method y y y x all of them B1,p , B2,p , ..., BN for the fixed B2,p , and so on, there are blocks of all subsequent B-splines y ,p x relative to y for consecutive established B-splines Bi,p up to the last block in which they occur sequentially y y y x B1,p , B2,p , ..., BNy ,p for the fixed last BNx ,p
A matrix that has such a structure is a Kronecker product of two smaller matrices, one with the same terms from the first single integrals (pairs of B-splines with respect to x), and the second in which there are only the terms of the second single integrals (pairs of B-splines with respect to y). The mathematical notation of such a Kronecker product is a symbol ⊗ between the two matrices mentioned. The symbol ”=” at the front means that the Kronecker product of these matrices results in our large matrix. R y y R x x R y y R x x R x x B1,p B1,p dy B B1,p dy · · · B1,p B1,p dx B1,p B2,p dx · · · B1,p BNx ,p dx R 1,p R x x R x x R x x R y y y y B1,p B1,p dy · · · B2,p B2,p dx · · · B2,p BNx ,p dx B1,p B1,p dy B2,p B1,p dx = ⊗ .. .. .. .. .. .. .. . . . . . . . R x R R R R y y y y x x x x x BNx ,p B1,p dx BN B dx · · · B B dx B B dy B B dy · · · 2,p Nx ,p Nx ,p Ny ,p 1,p Ny ,p 1,p x ,p
R y y B1,p BNy ,p dy R y y B1,p BNy ,p dy .. . R y y BNy ,p BN dy y ,p
Term ⊗ means that we multiply the appropriate terms of two matrices so as to get the original matrix (??.1).
Figure 5: Partition of the functions from the one-dimensional B-splines into segments.
We now need to compute the integrals of the products of the pairs of one-dimensional B-splines shown in Pic. 5. First note that if we multiply two one-dimensional B-splines by themselves whose graphs do not overlap (mathematicians say ”which have no common support”), for example N1;2 and B4;2 from the drawing Pic. 5, then the integral R B (x)B4;2 (x)dx = 0 [t0 ,t6 ] 1;2 Open AGH e-podręczniki - content available under the CC BY-SA license
18
1.4. Generation of the system of linear equations with the analytical method This is because in each interval shown in Pic. 5 one of the B-splines is equal to zero, i.e. R B1;2 (x)B4;2 (x)dx = R[t0 ,t6 ] R R B (x)B4;2 (x)dx + [t1 ,t2 ] B1;2 (x)B4;2 (x)dx + [t2 ,t3 ] B1;2 (x)B4;2 (x)dx+ [t0 ,t1 ] 1;2 R R R B (x)B4;2 (x)dx + [t4 ,t5 ] B1;2 (x)B4;2 (x)dx + [t5 ,t6 ] B1;2 (x)B4;2 (x)dx = [t3 ,t4 ] 1;2 R R R B (x) ∗ 0dx + [t1 ,t2 ] B1;2 (x) ∗ 0dx + [t2 ,t3 ] B1;2 (x) ∗ 0dx+ [t0 ,t1 ] 1;2 R R R 0 ∗ B4;2 (x)dx + [t4 ,t5 ] 0 ∗ B4;2 (x)dx + [t5 ,t6 ] 0 ∗ B4;2 (x)dx = [t3 ,t4 ] 0+0+0+0+0+0=0 Next, we can take the element diameter as the unit of length, then each [ti , ti+1 ] will have a diameter that equals one. Then we have to introduce the formulas for individual B-spline segments (shown on the right panel of the drawing Pic. 5). We mark these segments B1 , B 2 , B 3 . B1 (x) = 12 x2 B2 (x) = −x2 + x + B3 (x) = 12 (1 − x)2
1 2
Because only integrals of overlapping B-splines give non-zero values over each interval [ti , ti+1 ] we really need to compute the following integrals in the element matrix where the segments of the B-splines overlap. Since the given formulas for segments are valid over the interval 0,1, and the integral does not change during the shift (just like the volume under the table will not change if we move the table to another place on a flat floor), we can, for the sake of simplicity, calculate our integrals in the interval 0,1. R 1 R1 R1 B1 (x)B1 (x)dx 0 B1 (x)B2 (x)dx 0 B1 (x)B3 (x)dx 0 R1 R1 R 1 0 B2 (x)B1 (x)dx 0 B2 (x)B2 (x)dx 0 B2 (x)B3 (x)dx R1 R1 R1 B3 (x)B1 (x)dx 0 B3 (x)B2 (x)dx 0 B3 (x)B3 (x)dx 0 In other words, we only have 9 options for overlapping individual segments. Because the segments B1 i B3 are symmetrical, we have matrix symmetry, so we really have to calculate six integrals R 1 R1 R1 B (x)B (x)dx B (x)B (x)dx B (x)B (x)dx 1 1 1 2 1 3 R01 R01 0 == B2 (x)B2 (x)dx 0 B2 (x)B3 (x)dx 0 R1 == == B3 (x)B3 (x)dx 0 The symmetry of the segments also shows that the segment B3 is shaped like reflected segment B1 , R1 R1 and and that is why 0 B1 (x)B1 (x)dx = 0 B3 (x)B3 (x)dx, in other words, reflecting the function does not change the integral value (just like turning the table 180 degrees does not change the volume under the R1 R1 table), and 0 B2 (x)B3 (x)dx = 0 B1 (x)B2 (x)dx, so we really only need to calculate four integrals R 1 R1 R1 B1 (x)B1 (x)dx 0 B1 (x)B2 (x)dx 0 B1 (x)B3 (x)dx 0 R 1 == B2 (x)B2 (x)dx == 0 == == == We calculate one-dimensional integrals from polynomials R1 R1 R1 5 1 B1 (x)B1 (x)dx = 0 ( 12 x2 )( 12 x2 )dx = 0 14 x4 )dx = 14 ( x5 )|10 = 20 0 R1 R1 R1 B2 (x)B2 (x)dx = 0 (−x2 + x + 12 )(−x2 + x + 12 )dx = 0 (x4 − 2x3 + x + 14 )dx = 0 5 4 2 9 ( x5 )|10 − 2( x4 )10 + ( x2 )10 + ( 14 x)|10 = 15 + 14 = 20 R1 R1 R1 4 3 2 B1 (x)B2 (x)dx = 0 ( 12 x2 )(−x2 + x + 12 )dx = 0 (− x2 + x2 + x4 )dx = 0 5 4 3 1 1 13 (− x10 )|10 + ( x8 )|10 + ( x12 )|10 = − 10 + 18 + 12 = 120
Open AGH e-podręczniki - content available under the CC BY-SA license
19
1.4. Generation of the system of linear equations with the analytical method R1
R1 B1 (x)B3 (x)dx = 0 ( 12 x2 )( 12 (1 − x)2 )dx = 0 5 4 3 1 1 1 ( x20 )|10 − ( x8 )|10 + ( x12 )|10 = 20 − 18 + 12 = 120 Taking into account matrix and we get R 1 B1 (x)B1 (x)dx R01 0 B2 (x)B1 (x)dx R1 B3 (x)B1 (x)dx 0
R1 0
4
( x4 −
x3 2
+
x2 4 )dx
=
the symmetries of the computed integrals, we enter them into appropriate places in our R1 B (x)B2 (x)dx R01 1 B (x)B2 (x)dx R01 2 B3 (x)B2 (x)dx 0
R1 1 B1 (x)B3 (x)dx 20 0 R1 13 B (x)B3 (x)dx = 120 R01 2 1 B3 (x)B3 (x)dx 120 0
13 120 9 20 13 120
1 120 13 120 1 20
Summing up the pieces of the matrix generated in this way, we get two matrices that form our system of equations of the Kronecker product of matrices. 1 13 1 ··· 20 120 120 13 9 1 13 13 1 ··· 120 20 + 20 120 + 120 120 1 13 13 1 9 1 13 13 1 ··· 120 + 120 120 120 120 + 120 20 + 20 + 20 ··· 1 13 13 1 9 1 13 13 1 + + + + ··· 120 120 120 20 20 20 120 120 120 . . . . . . .. .. .. .. .. .. We add up as follows: . .. 1 13 13 1 9 1 13 13 1 ··· 120 120 + 120 20 + 20 + 20 120 + 120 120 1 13 13 1 9 1 13 13 · · · + + + 120 120 120 20 20 20 120 + 120 1 13 13 9 1 ··· 120 120 + 120 20 + 20 1 13 ··· 120 120 In addition to the terms of the matrix listed on the five diagonals, the remaining terms of the matrix are equal to 0. In other words, we move our matrix along the diagonal from the upper left corner of the matrix to the lower right corner, and sum the overlapping terms. In this way we will obtain two matrices which form, with the help of the so-called Kronecker product our matrix (??.1). Another problem to solve is to calculate the right-hand side integrals. The right-hand side integral is the sampling of the bitmap multiplied by individual testing functions (B-splines used to average the bitmap in the area where they are defined). From now on we use a new notation in which we introduce the two-dimensional B-spline function, the variable function (x, y), being the product of two one-dimensional functions B-spline y x Bk,l;2 (x, y) = Bk;2 (x)Bl;2 (y). Please note that multiplying the bitmap by v(x, y) = Bk,l;2 (x, y) means that we only need to calculate this integral after nine elements on which B-spline is defined Bk,l;2 (x, y). We need to solve two problems now. The first problem is what pattern do the nine fragments of our B-spline on the nine elements on which it is defined have. The second problem is how to calculate the integral of a bitmap multiplied by a polynomial. Please note that one-dimensional B-splines consist of three segments described according to (??.1). Therefore, our two-dimensional B-spline testing on the nine elements on which it is determined consists of the appropriate products of these segments. B1 (x)B1 (y), B2 (x)B1 (y), B3 (x)B1 (y) B1 (x)B2 (y), B2 (x)B2 (y), B3 (x)B2 (y) B1 (x)B3 (y), B2 (x)B3 (y), B3 (x)B3 (y) It is illustrated in the picture Pic. 6.
Open AGH e-podręczniki - content available under the CC BY-SA license
20
1 120 13 120 1 20
1.4. Generation of the system of linear equations with the analytical method
Figure 6: Partition of a two-dimensional B spline into individual segments.
Thus, the problem of computing the integral of the bitmap multiplied by the B-spline test function boils down to the problem of computing nine integrals. For example, if we want to calculate the integral for the testing B-spline Bk,l;2 (x, y), then we need to calculate the following nine integrals: R1R1 B (x)B1 (y)BIT M AP ((k − 1 + x) ∗ maxx/Nx , (l − 1 + y) ∗ maxy/Ny )dxdy, R01 R01 1 B (x)B1 (y)BIT M AP ((k + x) ∗ maxx/Nx , (l − 1 + y) ∗ maxy/Ny )dxdy, R01 R01 2 B (x)B1 (y)BIT M AP ((k + 1 + x) ∗ maxx/Nx , (l − 1 + y) ∗ maxy/Ny )dxdy, R01 R01 3 B (x)B2 (y)BIT M AP ((k − 1 + x) ∗ maxx/Nx , (l + y) ∗ maxy/Ny )dxdy, R01 R01 1 B (x)B2 (y)BIT M AP ((k + x) ∗ maxx/Nx , (l + y) ∗ maxy/Ny )dxdy, R01 R01 2 B (x)B2 (y)BIT M AP ((k + 1 + x) ∗ maxx/Nx , (l + y) ∗ maxy/Ny )dxdy, R01 R01 3 B (x)B3 (y)BIT M AP ((k − 1 + x) ∗ maxx/Nx , (l + 1 + y) ∗ maxy/Ny )dxdy, R01 R01 1 B (x)B3 (y)BIT M AP ((k + x) ∗ maxx/Nx , (l + 1 + y) ∗ maxy/Ny )dxdy, R01 R01 2 B3 (x)B3 (y)BIT M AP ((k + 1 + x) ∗ maxx/Nx , (l + 1 + y) ∗ maxy/Ny )dxdy. 0 0 In the above formulas, type expressions (k −1+x)∗maxx/Nx denote the conversion of B-spline coordinates which we integrate into the pixel indices of the bitmap on which it extends. The variables x and y vary from 0 to 1. Within one element, we have maxx/Nx pixels towards x and maxy/Ny pixels towards y , where maxx, maxy is the size of the bitmap (integer pixels towards x i y) but Nx , Ny is the number of mesh elements in the direction x i y. So x ∗ maxx/Nx varies from 0 to maxx/Nx , that is, it spans the number of pixels of the bitmap in direction x on a single element, while y ∗ maxy/Ny varies from 0 to the number of pixels in the bitmap direction y on a single element. In addition, we move our range so as to view the pixels of relevant elements on which our testing B-spline is stretched. For example, the expression (k − 1 + x) ∗ maxx/Nx means that we move through the pixels of the element number k towards x, (k + x) ∗ maxx/Nx means that we move through the pixels of the element number k + 1 towards x, (k + 1 + x) ∗ maxx/Nx means that we move through the pixels of the element number k +2 towards x. Likewise (l −1+ y)∗maxy/Ny means that we move through the pixels of the element number l towards y, (l+y)∗maxy/Ny means that we move through the pixels of the element number l + 1 towards y, and (l + 1 + y) ∗ maxy/Ny means that we move through the pixels of the element number +2l towards y. Open AGH e-podręczniki - content available under the CC BY-SA license
21
1.5. The solution of the system of linear equations So how do we calculate such pixel integrals? We need to break the integral into the sum of the integrals over individual pixels, for example for the first integral: R1R1 B1 (x)B1 (y)BIT M AP ((k − 1 + x) ∗ maxx/Nx , (l − 1 + y) ∗ maxy/Ny )dxdy = 0 0 P BIT M AP ((k − 1) ∗ maxx/Nx + i, (l − 1) ∗ maxy/Ny + j) R i=1,maxx/Nx ;j=1,maxy/N Ry B (x)dx B1 (y)dy 1 1 1 (i−1,i)∗ (j−1,j)∗ maxx/Nx
maxy/Ny
where the sum marked in red extends over all pixels from a single element (there are maxx/Nx ∗ maxy/Ny ), the bitmap is sampled at pixel points spread over the element, and the integrals marked in blue are calculated from the B-spline function over individual pixels. It is enough now that we calculate single integrals from three segments R R 3 B (x)dx = 12 x2 dx = 12 x3 , R 1 R 3 2 B2 (x)dx = (−x2 + x + 12 )dx = − x3 + x2 + 12 x, R R R 3 B3 (x)dx = 12 (1 − x)2 dx = (1 − 2x + x2 ) = x − x2 + x3 and we put them into the integral formulas, for example R
1 (i−1,i)∗ maxx/N
B1 (x)dx =
B1 (y)dy =
x
R
1 (j−1,j)∗ maxy/N
y
1 x3 2 3
3
1x 2 3
|
i maxx/Nx i−1 maxx/Nx
|
j maxy/Ny j−1 maxy/Ny
=
1 2 1 2
3 3 ! i − maxx/N x
3
=
i−1 maxx/Nx
j−1 maxy/Ny
3 3 ! j − maxy/N y
3
Calculating integrals of the test functions from the bitmap got a little complicated. To summarize, we need to compute many integrals from the bitmap, multiplied by various two-dimensional B-splines, so-called test functions. We calculate each of these integrals so that we break them into an integral over the nine elements on which the testing B-spline is spanned, and we sum these resulting nine integrals by entering the obtained number into one row of the right-hand side vector. In turn, to count the integral after each of these nine elements on which our testing B-spline is spanned, we break these integrals into individual pixels that lie on this element, sample our bitmap over these pixels and calculate the integral of our B-spline segments after all pixels. We sum it all together (sum of the nine elements on which the testing B-spline lies, sum of the pixels of elements).
1.5.
The solution of the system of linear equations
As a result of generating a system of equations, we got a matrix written in the form of the Kronecker product of two five-diagonal one-dimensional matrices, obtained from B-splines discretizations. We now need to solve the resulting system of equations. 1 13 1 1 13 1 ··· 20 120 120 20 120 120 13 13 1 13 1 1 13 ··· 120 120 2 60 120 2 60 1 1 13 11 13 1 13 11 · · · 20 60 120 20 120 60 120 60 . .. .. .. .. .. .. .. .. . . . . . . . 1 13 11 13 1 1 13 ⊗ · · · · · · · · · 120 60 20 60 120 120 60 .. .. .. .. .. .. .. . . . . . . . 1 13 11 13 1 1 · · · 120 60 · · · 120 20 60 120 1 13 1 13 · · · 120 ··· 60 2 120 1 13 1 · · · 20 120 120
··· 1 120 13 60
1 120
···
11 20
13 60
1 120
13 60 1 120
11 20 13 60 1 120
13 60 1 2 13 120
.. . .. .
···
··· .. . .. .
Open AGH e-podręczniki - content available under the CC BY-SA license
.. .
u1,1 u2,1 u3,1 .. . uk,l .. .
··· = 1 u N ,N x−2 y 120 13 u Nx−1 ,Ny 120 1 uNx ,Ny 20
22
1.5. The solution of the system of linear equations R BIT M AP (x, y)B1x (x) ∗ B1y (y)dxdy R BIT M AP (x, y)B2x (x) ∗ B1y (y)dxdy R BIT M AP (x, y)B3x (x) ∗ B1y (y)dxdy .. . R y x BIT M AP (x, y)Bk (x) ∗ Bl (y)dxdy .. . R y BIT M AP (x, y)B x Nx −2 (x) ∗ BNy (y)dxdy R y x BIT M AP (x, y)BNx −1 (x) ∗ BNy (y)dxdy R y x BIT M AP (x, y)BN (x) ∗ BN (y)dxdy x y
A solution of a system of equations in which the matrix has a Kronecker product structure is possible in a very short time. What does that mean ‘in a very short time’ ? The computational cost is expressed in the number of operations such as multiplication or addition of numbers necessary to solve the system of equations. In the case of a system of equations where the matrix has a Kronecker product structure, it is possible to solve the system of equations using an algorithm in which the number of operations const ∗ N where N is the number of unknowns (number of bitmap approximation coefficients on the mesh, expressed exactly through N = Nx ∗ Ny , where Nx , Ny are the mesh sizes, while const stands for some fixed integer number. The algorithm used in this case is called the alternating-directions algorithm. We consider two steps in the solution process. The first step is to take the first of the sub-matrix and arrange the vector of unknowns and the vector of right-hand sides into many sub-sectors, one vector for each column of the calculation grid elements. It was illustrated in Pic. 7, and in the formula below. 1 13 1 ··· 20 120 120 13 1 13 1 ··· 120 w1,1 w1,2 ··· w1,Ny−1 w1,Ny 2 60 120 1 13 11 13 1 w ··· w2,2 ··· w2,Ny−1 w2,Ny 20 60 120 120 60 2,1 . . . . . .. .. .. .. .. w3,1 w3,2 ··· w3,Ny−1 w3,Ny .. .. .. .. 1 13 11 13 1 · · · · · · 120 = . . · · · . . 60 20 60 120 .. .. .. .. .. w w · · · w w N ,1 N ,2 N ,N N ,N . . . . . x−2 x−2 y−1 x−2 y x−2 1 13 11 13 1 wN wNx−1 ,2 · · · wNx−1 ,Ny−1 wNx−1 ,Ny · · · 120 x−1 ,1 60 20 60 120 1 13 1 13 wNx ,1 wNx ,2 · · · wNx ,Ny−1 wNx ,Ny · · · 120 60 2 120 1 13 1 · · · 120 120 20 R R y BIT M AP (x, y)B1x (x) ∗ B1y (y)dxdy ··· BIT M AP (x, y)B1x (x) ∗ BN (y)dxdy y R R y BIT M AP (x, y)B2x (x) ∗ B1y (y)dxdy ··· BIT M AP (x, y)B2x (x) ∗ BN (y)dxdy y R R y BIT M AP (x, y)B3x (x) ∗ B1y (y)dxdy ··· BIT M AP (x, y)B3x (x) ∗ BN (y)dxdy y .. . R R y y x x BIT M AP (x, y)BN (x) ∗ B (y)dxdy · · · BIT M AP (x, y)B (x) ∗ B (y)dxdy 1 Nx −2 Ny x −2 R R y y BIT M AP (x, y)B x x (x) ∗ B (y)dxdy · · · BIT M AP (x, y)B (x) ∗ B (y)dxdy 1 Nx −1 Nx −1 Ny R R y y x x BIT M AP (x, y)BNx (x) ∗ B1 (y)dxdy ··· BIT M AP (x, y)BNx (x) ∗ BNy (y)dxdy We have introduced the auxiliary unknowns here w∗ which are used for solutions of the first system of equations. We get original unknowns u∗ after solving the second system of equations with v, which the right-hand side will be auxiliary unknowns w∗. So, we get a system of equations with a five-diagonal matrix, with many right-hand sides. Each sub-sector of each right-hand side corresponds to one column in the element grid, so it has the specified coordinate y, and the coordinate x varying from 1 to Nx . The unknowns are similarly ordered u∗, in which it the second indexes change with the lines, for example w1,1 , w1,2 , ..., w1,Ny while in the columns first indexes change. We solve this system of equations (how to do it we will desribe later), we get solutions w∗ and we move on to the second step of the alternating-directions solver algorithm. Open AGH e-podręczniki - content available under the CC BY-SA license
23
1.6. Interpretation of the solution
Figure 7: The pattern according to which we arrange the right sides when executing the floating-direction solver algorithm.
The second step is then to take an analogous second Kronecker product matrix, taking solutions w∗ from the first system of equations, arranging them according to the rows of mesh elements (compare Pic. 7), arranged in a similar way unknowns u∗ and on solving the obtained system of equations with many right-hand sides. 1 13 1 ··· 20 120 120 13 1 13 1 ··· 120 u1,1 u2,1 ··· uNx−1 ,1 uNx ,1 2 60 120 1 13 11 13 1 u ··· u2,2 ··· uNx−1 ,2 uNx ,2 20 60 120 120 60 1,2 . .. .. .. .. .. u u · · · u u 1,3 2,3 N ,3 N ,3 . . . . x−1 x .. .. .. .. 1 13 11 13 1 · · · · · · 120 60 = . ··· . . 20 60 120 . .. .. .. .. .. u 1,Ny−2 u2,Ny−2 · · · uNx−1 ,Ny−2 uNx ,Ny−2 . . . . . 1 13 11 13 1 u1,N u2,Ny−1 · · · uNx−1 ,Ny−1 uNx ,Ny−1 · · · 120 y−1 60 20 60 120 1 13 1 13 u1,Ny u2,Ny · · · uNx−1 ,Ny uNx ,Ny · · · 120 60 2 120 1 13 1 · · · 120 120 20 w1,1 w2,1 ··· wNx−1 ,1 wNx ,1 w w2,2 ··· wNx−1 ,2 wNx ,2 1,2 w1,3 w · · · w w 2,3 N ,3 N ,3 x−1 x .. .. .. .. . . ··· . . w 1,Ny−2 w2,Ny−2 · · · wNx−1 ,Ny−2 wNx ,Ny−2 w1,Ny−1 w2,Ny−1 · · · wNx−1 ,Ny−1 wNx ,Ny−1 w1,Ny
w2,Ny
···
wNx−1 ,Ny
wNx ,Ny
In this second system of equations, every sub-sector, of every right-hand side corresponds to one row in the element grid, so it has a fixed coordinate x, and the coordinate y changing from 1 to Ny . The unknowns u∗ are similarly ordered. There, the first indexes change with lines, for example w1,1 , w2,1 , ..., wNx ,1 while in the columns the second indexes change. We will solve each of these two systems of equations with many right-hand sides using the Gaussian elimination algorithm for the band matrix which has a linear computational cost.
1.6.
Interpretation of the solution
As a result of solving a system of linear equations, we obtain a vector of coefficients
Open AGH e-podręczniki - content available under the CC BY-SA license
24
1.7. MATLAB implementation of the bitmap projection problem u1,1 u2,1 u3,1 .. . uk,l .. . uNx−2 ,Ny uNx−1 ,Ny uNx ,Ny We remember that our solution (bitmap projection) is represented by a linear combination of two-dimensional B-spline functions PNx PNy y x u(x, y) = i=1 j=1 ui,j Bi (x)Bj (y) In order to get the solution value in point (x, y) belonging to the area Ω on which our bitmap is defined, we do not need, of course, to sum the values of all B-spline functions. We need to locate the element where the point (x, y) and all (p + 1)2 B-spline functions specified on this element. The other Bspline functions are zero at this point. In our case, Ω = [1, maxx] × [1, maxy], and we have equally distributed Nx B-spline functions of order p along x axis and Ny B-spline functions of order p alongy. We have Nx − p elements along x and Ny − p elements along y axis. Each element has dimension [maxx/(Nx − p)] × [maxy/(Ny − p)]. x So to get the element number along the axis x, we do division nex = int( maxx/(N ), and to calculate x −p) y the element number along the y-axis, we do division analogously y, we do division nez = int( maxy/(N ), y −p) where int is the integer value (rounded down).
Then, on our element y x [nex , ney ] the functions are determined {Bi,p (x)Bj,p }i=nex −p+1,nex +p−1,j=ney −p+1,ney −p−1 .
In order to calculate the solution value in point (x, y) we just need to calculate P u(x, y) = i=nex −p+1,nex +p−1,j=ney −p+1,ney −p−1 ui,j Bix (x)Bjy (y)
1.7.
MATLAB implementation of the bitmap projection problem
Below you can find a link to the MATLAB code that calculates the L2 isogeometric bitmap projection. The code uses the isogeometric finite element method in which the bitmap is approximated by a linear combination of B-spline polynomials. The code execution is also possible in the free Octave environment. Download code or see Appendix 1. We set the variables with the path to the input file in tif format f ilename =0 C : //U sers/M aciej/Dropbox/bitmapa.tif 0 then we give the number of mesh elements in the x and y directions nxx = 4, nyy = 4, and the degrees of the B-spline function in these directions pxx = 2, pyy = 2. Then we start the first procedure bitmap_f ast(f ilename, nxx, pxx, nyy, pyy).
Open AGH e-podręczniki - content available under the CC BY-SA license
25
1.7. MATLAB implementation of the bitmap projection problem The code computes the isogeometric L2 projection of a bitmap and draws the projection in the open window.
Open AGH e-podręczniki - content available under the CC BY-SA license
26
Chapter 2
2. Discretization with different basis functions 2.1.
Linear basis functions
The B-spline basis functions are defined according the the recursive formula, illustrated in Pic. 8.
k
Nk,1*
k+1 − 𝑘+ 2
−
k+2
k+1
k+2 − 𝑘+ 3 − 𝑘+ 3
𝑘
+
𝑘
k+3
*Nk+1,1
𝑘+ 1
Nk,2 k
k+1
k+2
k+3
Figure 8: Recursive definition of B-spline basis functions.
The linear B-splines are just ”pyramids” use to define the higher-order B-splines later. Both linear basis functions and higher-order basis functions can be described in a modern way using the convention adopted in the isogeometric finite element method, referring to the B-spline function and the so-called knot-vector notation. Let us consider a one-dimensional area [0, N ] divided into N compartments called finite elements. For the sake of simplification of our presentation, let us assume that we have five such intervals, i.e. N = 5. We introduce the notation of the knot vector, which is a sequence of non-decreasing coordinates of points. As a rule, for the sake of simplification, points with coordinates are integers. For example, a vector of knots [0 0 1 2 3 4 5 5] defines us linear basis functions on an interval [0, 5] divided into five elements [0, 1], [1, 2], [2, 3], [3, 4], [4, 5]. In order to illustrate the basis functions resulting from the various knot vectors, we recommend the 27
2.1. Linear basis functions attached MATLAB code. How to interpret the notation of a vector of knots? First, we need to define the degree and continuity of the basis functions. We do it as follows. The degree of basis functions is equal to the number of repetitions of the first (or last) point in the knot vector minus one. In other words, we look at how many times the first and last point in the knot vector is repeated. If this point is repeated twice (in our case 0 0 and 5 5), it means that the degree of basis functions is one (two minus one), i.e. we introduce linear basis functions. What are the formulas for linear basis functions defined with a knot vector? This is determined by the so-called Cox-de-Boor rule, the original formula of which is given below [10]:
Bi,0 (ξ) = 1 jeśli ξi ≤ ξ ≤ ξi+1 or 0 in other cases
Bi,p (ξ) =
(2.1)
ξ − ξi ξi+p+1 − ξ Bi,p−1 (ξ) + Bi+1,p−1 (ξ) ξi+p − ξi ξi+p+1 − ξi+1
(2.2)
How should this rule be understood? Vector N knots encode us N + p B-spline function, where p denotes the degree of B-spline function (in our case we are considering linear B-spline functions, so p = 1). B-spline function are marked Bi,p , where i = 1, ...N + p stands for the number (index) of the B-spline function, and p denotes the degree of B-spline function.
Derivation 1: Linear basis functions In our case, we have N = 5 and p = 1 and our vector of knots [0 p = 5 + 1 = 6 B-spline basis functions, or functions
0
1
2
3
4 5
5] codes us N +
B1,1 , B2,1 , B3,1 , B4,1 , B5,1 and B6,1 . In the Cox-de-Boor formula, points ξi denote individual knots in the knot vector, so we have ξ1 = 0, ξ2 = 1, ξ3 = 2, ξ4 = 3, ξ5 = 4 and ξ6 = 5. We now need to recreate our basis functions from the Cox-de-Boor formula B1,1 , ..., B6,1 . Formula Cox-DeBoor (??.1) - Cox-DeBoor (??.2) The formula is a recursive formula. We need to start by defining all zero-order B-spline functions on the interval [0, 5], according to the pattern Cox-DeBoor (??.1). Especially ξ1 = 0, ξ2 = 0, ξ3 = 1 (the first two knots in our vector are repeated). Therefore, the first zero degree B-spline basis function is degenerate to a point B1,0 = 1 dla x ∈ [ξ1 , ξ2 ] = [0, 0] = {0}, 0 in other points, B2,0 = 1 dla x ∈ [ξ2 , ξ3 ] = [0, 1], 0 in other points, B3,0 = 1 dla x ∈ [ξ3 , ξ4 ] = [1, 2], 0 in other points, B4,0 = 1 dla x ∈ [ξ4 , ξ5 ] = [2, 3], 0 in other points, B5,0 = 1 dla x ∈ [ξ5 , ξ6 ] = [3, 4], 0 in other points, B6,0 = 1 dla x ∈ [ξ6 , ξ7 ] = [4, 5], 0 in other points, B7,0 = 1 dla x ∈ [ξ7 , ξ8 ] = [5, 5] = {5}, 0 in other points. Now, using a combination of zero degree B-splines, we will obtain the first degree B-spline according to the formula Cox-DeBoor (??.1), for p = 1. Bi,1 (ξ) =
ξ−ξi ξi+1 −ξi Bi,0 (ξ)
+
ξi+2 −ξ ξi+2 −ξi+1 Bi+1,0 (ξ)
At this point, we note that the formula Cox-DeBoor (??.2) commonly used in the literature on the isogeometric finite element method has some drawbacks. It basically means that you cannot insert repeated knots into it, because, for example, inserting ξ1 − ξ2 = 0 − 0 = 0 will give us division by zero. This formula Open AGH e-podręczniki - content available under the CC BY-SA license
28
2.2. Higher-order Ck basis functions in 1D should therefore be subject to additional conditions which say that successive knots inserted into the denominator must be different, or if they are not different, then a given term should be changed to zero. We marked these elements in red: B1,1 (ξ) =
ξ−0 0−0 B1,0 (ξ)
+
1−ξ 1−0 B2,0 (ξ)
= 1 − ξ dla ξ ∈ [0, 1]
B2,1 (ξ) =
ξ−0 1−0 B2,0 (ξ)
+
2−ξ 2−1 B3,0 (ξ)
= ξ dla ξ ∈ [0, 1], 2 − ξ dla ξ ∈ [1, 2]
B3,1 (ξ) =
ξ−1 2−1 B3,0 (ξ)
+
3−ξ 3−2 B4,0 (ξ)
= ξ − 1 dla ξ ∈ [1, 2], 3 − ξ dla ξ ∈ [2, 3]
B4,1 (ξ) =
ξ−2 3−2 B4,0 (ξ)
+
4−ξ 4−3 B5,0 (ξ)
= ξ − 2 dla ξ ∈ [2, 3], 4 − ξ dla ξ ∈ [3, 4]
B5,1 (ξ) =
ξ−3 4−3 B5,0 (ξ)
+
5−ξ 5−4 B6,0 (ξ)
= ξ − 3 dla ξ ∈ [3, 4], 5 − ξ dla ξ ∈ [4, 5]
B6,1 (ξ) =
ξ−4 5−4 B6,0 (ξ)
+
5−ξ 5−5 B7,0 (ξ)
= ξ − 4 dla ξ ∈ [4, 5]
For the vector of knots [0
0
2.2.
1
2
3
4
5
5] we have six basis functions of the first order B1,1 , ..., B6,1 .
Higher-order Ck basis functions in 1D
The B-spline basis functions are defined according the the recursive formula, illustrated in Pic. 9.
Figure 9: Recursive definition of B-spline basis functions.
The higher order B-splines are defined by multiplications of one lower order B-splines and the diagonal line, and adding second lower order B-spline, shifted by one integral, and the opposite diagonal line. For example, the second order B-splines are defined by using two pyramids and two lines, shifted by one interval, as illustrated in the figure. The points can be collected into the so-called knot vector, using some special convention to define B-splines of arbitrary order.
Derivation 1: Higher order basic B-spline functions The vector of knots [0 0 0 1 2 3 4 5 5 5] in which the first and the last knot are repeated 3=2+1 times, defines the second order basis functions. In order to illustrate the basis functions resulting Open AGH e-podręczniki - content available under the CC BY-SA license
29
2.2. Higher-order Ck basis functions in 1D from the various knot vectors, we recommend the attached MATLAB code. So we now have ξ1 = ξ2 = ξ3 = 0, ξ4 = 1, ξ5 = 2, ξ6 = 3, ξ7 = 4, ξ8 = ξ9 = ξ10 = 5 Since the number of knots in the vector has changed, we need to redefine the new zero and first order basis functions (because there will be more of them and they will have different numbering). Zero-degree basis functions: B1,0 = 1 for x ∈ [ξ1 , ξ2 = [0, 0] = {0}, 0 in other points, B2,0 = 1 for x ∈ [ξ2 , ξ3 ] = [0, 0] = {0}, 0 in other points, B3,0 = 1 for x ∈ [ξ3 , ξ4 ] = [0, 1], 0 in other points, B4,0 = 1 for x ∈ [ξ4 , ξ5 ] = [1, 2], 0 in other points, B5,0 = 1 for x ∈ [ξ5 , ξ6 ] = [2, 3], 0 in other points, B6,0 = 1 for x ∈ [ξ6 , ξ7 ] = [3, 4], 0 in other points, B7,0 = 1 for x ∈ [ξ7 , ξ8 ] = [4, 5], 0 in other points, B8,0 = 1 for x ∈ [ξ8 , ξ9 ] = [5, 5] = {5}, 0 in other points, B9,0 = 1 for x ∈ [ξ9 , ξ10 ] = [5, 5] = {5}, 0 in other points Similarly, we need to redefine the first order basis functions for the new knot vector. Let us recall the formula for p=1 Bi,1 (ξ) =
ξ−ξi ξi+1 −ξi Bi,0 (ξ)
+
ξi+2 −ξ ξi+2 −ξi+1 Bi+1,0 (ξ)
where we insert the next knots: B1,1 (ξ) =
ξ−ξ1 ξ2 −ξ1 B1,0 (ξ)
+
ξ3 −ξ ξ3 −ξ2 B2,0 (ξ)
=
ξ−0 0−0 B1,0 (ξ)
+
0−ξ 0−0 B2,0 (ξ)
=0
B2,1 (ξ) =
ξ−ξ2 ξ3 −ξ2 B2,0 (ξ)
+
ξ4 −ξ ξ4 −ξ3 B3,0 (ξ)
=
ξ−0 0−0 B2,0 (ξ)
+
1−ξ 1−0 B3,0 (ξ)
= 1 − ξ for ξ ∈ [0, 1]
B3,1 (ξ) =
ξ−ξ3 ξ4 −ξ3 B3,0 (ξ)
+
ξ5 −ξ ξ5 −ξ4 B4,0 (ξ)
=
ξ−0 1−0 B3,0 (ξ)
+
2−ξ 2−1 B4,0 (ξ)
= ξ for ξ ∈ [0, 1], 2 − ξ for ξ ∈ [1, 2]
B4,1 (ξ) =
ξ−ξ4 ξ6 −ξ ξ5 −ξ4 B4,0 (ξ) + ξ6 −ξ5 B5,0 (ξ)
=
ξ−1 3−ξ 2−1 B4,0 (ξ) + 3−2 B5,0 (ξ)
= ξ − 1 for ξ ∈ [1, 2], 3 − ξ for ξ ∈ [2, 3]
B5,1 (ξ) =
ξ−ξ5 ξ7 −ξ ξ6 −ξ5 B5,0 (ξ) + ξ7 −ξ6 B6,0 (ξ)
=
ξ−2 4−ξ 3−2 B5,0 (ξ) + 4−3 B6,0 (ξ)
= ξ − 2 for ξ ∈ [2, 3], 4 − ξ for ξ ∈ [3, 4]
B6,1 (ξ) =
ξ−ξ6 ξ8 −ξ ξ7 −ξ6 B6,0 (ξ) + ξ8 −ξ7 B7,0 (ξ)
=
ξ−3 5−ξ 4−3 B6,0 (ξ) + 5−4 B7,0 (ξ)
= ξ − 3 for ξ ∈ [3, 4], 5 − ξ for ξ ∈ [4, 5]
B7,1 (ξ) =
ξ−ξ7 ξ8 −ξ7 B7,0 (ξ)
+
ξ9 −ξ ξ9 −ξ8 B8,0 (ξ)
=
ξ−4 5−4 B7,0 (ξ)
B8,1 (ξ) =
ξ−ξ8 ξ9 −ξ8 B8,0 (ξ)
+
ξ10 −ξ ξ10 −ξ9 B9,0 (ξ)
=
+
ξ−5 5−5 B8,0 (ξ)
+
5−ξ 5−5 B8,0 (ξ)
= ξ − 4 for ξ ∈ [4, 5]
5−ξ 5−5 B9,0 (ξ)
=0
Second degree basis functions are obtained again using the formula
Bi,0 (ξ) = 1 if ξi ≤ ξ ≤ ξi+1 or 0 in other cases
Bi,p (ξ) =
ξ − ξi ξi+p+1 − ξ Bi,p−1 (ξ) + Bi+1,p−1 (ξ) ξi+p − ξi ξi+p+1 − ξi+1
(2.3)
(2.4)
for p = 2, aassuming that the subsequent knots inserted into the denominator must be different, and if they are not different, then the given term is changed to zero. The elements that disappear are marked in red. In the final stage of the derivation, we insert the formulas calculated before B1,1 (ξ) = 0,B2,1 = 1−ξ for ξ ∈ [0, 1],B3,1 = ξ for ξ ∈ [0, 1], 2 − ξ for ξ ∈ [1, 2],B4,1 = ξ − 1 for ξ ∈ [1, 2], 3 − ξ for ξ ∈ [2, 3],B5,1 = ξ − 2 for ξ ∈ [2, 3], 4 − ξ for ξ ∈ [3, 4],B7,1 = ξ − 4 for ξ ∈ [4, 5], i B8,1 = 0. At this point, we write down the formulas for up to three elements on which the second-order B-spline function is determined.
Open AGH e-podręczniki - content available under the CC BY-SA license
30
2.2. Higher-order Ck basis functions in 1D
B1,2 (ξ) =
ξ − ξ1 ξ4 − ξ ξ−0 1−ξ B1,1 (ξ) + B2,1 (ξ) = B1,1 (ξ) + B2,1 (ξ) = (1 − ξ)2 for ξ ∈ [0, 1] ξ3 − ξ1 ξ4 − ξ2 0−0 1−0
ξ − ξ2 ξ5 − ξ B2,1 (ξ) + B3,1 (ξ) ξ4 − ξ2 ξ5 − ξ3 ξ−0 2−ξ = B2,1 (ξ) + B3,1 (ξ) 1−0 2−0 ξ−0 2−ξ = [1 − ξ for ξ ∈ [0, 1]] + [ξ for ξ ∈ [0, 1], 2 − ξ for ξ ∈ [1, 2]] 1−0 2−0 1 1 = ξ(1 − ξ) + (2 − ξ)ξ for ξ ∈ [0, 1], (2 − ξ)2 for ξ ∈ [1, 2] 2 2
B2,2 (ξ) =
ξ − ξ3 ξ6 − ξ B3,1 (ξ) + B4,1 (ξ) ξ5 − ξ3 ξ6 − ξ4 ξ−0 3−ξ = B3,1 (ξ) + B4,1 (ξ) 2−0 3−1 1 = ξ (ξ for ξ ∈ [0, 1], 2 − ξ for ξ ∈ [1, 2]) 2 3−ξ + (ξ − 1 for ξ ∈ [1, 2], 3 − ξ for ξ ∈ [2, 3]) 2 1 1 1 = ξ 2 for ξ ∈ [0, 1], ξ(2 − ξ) + (3 − ξ)(ξ − 1) for ξ ∈ [1, 2], 2 2 2
B3,2 (ξ) =
1 (3 − ξ)2 for ξ ∈ [2, 3] 2
ξ − ξ4 ξ7 − ξ ξ−1 4−ξ B4,1 (ξ) + B5,1 (ξ) = B4,1 (ξ) + B5,1 (ξ) ξ6 − ξ4 ξ7 − ξ5 3−1 4−2 ξ−1 = (ξ − 1 for ξ ∈ [1, 2], 3 − ξ for ξ ∈ [2, 3]) 2 4−ξ + (ξ − 2 for ξ ∈ [2, 3], 4 − ξ for ξ ∈ [3, 4]) 2 1 = (ξ − 1)2 for ξ ∈ [1, 2], 2 1 1 1 (ξ − 1)(3 − ξ) + (4 − ξ)(ξ − 2) for ξ ∈ [2, 3], (4 − ξ)2 for ξ ∈ [3, 4] 2 2 2 ξ − ξ5 ξ8 − ξ B5,2 (ξ) = B5,1 (ξ) + B6,1 (ξ) ξ7 − ξ5 ξ8 − ξ6 ξ−2 5−ξ = B5,1 (ξ) + B6,1 (ξ) 4−2 5−3 1 = (ξ − 2) [ξ − 2 for ξ ∈ [2, 3], 4 − ξ for ξ ∈ [3, 4]] 2 1 + (5 − ξ) [ξ − 3 for ξ ∈ [3, 4], 5 − ξ for ξ ∈ [4, 5]] 2 1 = (ξ − 2)2 for ξ ∈ [2, 3], 2 1 1 (ξ − 2)(4 − ξ) + (5 − ξ)(ξ − 3) for ξ ∈ [3, 4], 2 2 (5 − ξ) for ξ ∈ [4, 5] B4,2 (ξ) =
ξ − ξ6 ξ9 − ξ B6,1 (ξ) + B7,1 (ξ) ξ8 − ξ6 ξ9 − ξ7 ξ−3 5−ξ = B6,1 (ξ) + B7,1 (ξ) 5−3 5−4 ξ−3 5−ξ = [ξ − 3 for ξ ∈ [3, 4], 5 − ξ for ξ ∈ [4, 5]] + [0] 5−3 5−4 1 1 = (ξ − 3)2 for ξ ∈ [3, 4], (ξ − 3)(5 − ξ) for ξ ∈ [4, 5] 2 2
B6,2 (ξ) =
Open AGH e-podręczniki - content available under the CC BY-SA license
31
2.3. Lagrange polynomials ξ − ξ7 ξ10 − ξ B7,1 (ξ) + B8,1 (ξ) ξ9 − ξ7 ξ10 − ξ8 ξ−4 5−ξ = B7,1 (ξ) + B8,1 (ξ) 5−4 5−5 ξ−4 = [0] + 0 5−4 =0
B7,2 (ξ) =
We got six second order basis functions (leaving the last seventh equal to zero), B1,2 , ..., B6,2 .
2.3.
Lagrange polynomials
In this chapter we derive the basis functions called the classical Lagrange polynomials. 1st order Lagrange polynomials are equivalent to 1st order B-spline functions, they have exactly the same formulas. Second order Lagrange polynomials can be derived from the general formula for B-splines using a knot vector generating second-order B-splines in which all internal knots have been repeated p times, so [0
0
0
1
1
2
2
3
3
4
4
5
5
5]
The vector of knots defined in this way will generate basis functions equivalent to the second-degree Lagrange polynomials (quadratic polynomials) used in the traditional finite element method. In order to illustrate the basis functions resulting from the various knot vectors, we recommend the attached MATLAB code. What do such basis functions look like? We need to generate step-by-step all zero-degree polynomials, and first- and second-order polynomials, using the Cox-de-Boor formula. Let us start with zero-degree polynomials. We have now ξ1 = ξ2 = ξ3 = 0, ξ4 = ξ5 = 1, ξ6 = ξ7 = 2, ξ8 = ξ9 = 3, ξ10 = ξ11 = 4 and ξ12 = ξ13 = ξ14 = 5 B1,0 = 1 for x ∈ [ξ1 , ξ2 = [0, 0] = {0}, 0 in other points, B2,0 = 1 for x ∈ [ξ2 , ξ3 ] = [0, 0] = {0}, 0 in other points, B3,0 = 1 for x ∈ [ξ3 , ξ4 ] = [0, 1], 0 in other points, B4,0 = 1 for x ∈ [ξ4 , ξ5 ] = [1, 1] = {1}, 0 in other points, B5,0 = 1 for x ∈ [ξ5 , ξ6 ] = [1, 2], 0 in other points, B6,0 = 1 for x ∈ [ξ6 , ξ7 ] = [2, 2] = {2}, 0 in other points, B7,0 = 1 for x ∈ [ξ7 , ξ8 ] = [2, 3], 0 in other points, B8,0 = 1 for x ∈ [ξ8 , ξ9 ] = [3, 3] = {3}, 0 in other points, B9,0 = 1 for x ∈ [ξ10 , ξ11 ] = [3, 4], 0 in other points,B10,0 = 1 for x ∈ [ξ11 , ξ12 ] = [4, 4] = {4}, 0 in other points, B11,0 = 1 for x ∈ [ξ12 , ξ13 ] = [4, 5], 0 in other points, B12,0 = 1 for x ∈ [ξ13 , ξ14 ] = [5, 5] = {5}, 0 in other points, B13,0 = 1 for x ∈ [ξ14 , ξ15 ] = [5, 5] = {5}, 0 in other points. Similarly, we need to generate the first order basis functions for a new knot vector. We remember the pattern for p = 1 Bi,1 (ξ) =
ξ−ξi ξi+1 −ξi Bi,0 (ξ)
+
ξi+2 −ξ ξi+2 −ξi+1 Bi+1,0 (ξ)
where we insert the next knots:B1,1 (ξ) =
ξ−ξ1 ξ2 −ξ1 B1,0 (ξ)
+
ξ3 −ξ ξ3 −ξ2 B2,0 (ξ)
=
ξ−0 0−0 B1,0 (ξ)
+
0−ξ 0−0 B2,0 (ξ)
B2,1 (ξ) =
ξ−ξ2 ξ3 −ξ2 B2,0 (ξ)
+
ξ4 −ξ ξ4 −ξ3 B3,0 (ξ)
=
ξ−0 0−0 B2,0 (ξ)
+
1−ξ 1−0 B3,0 (ξ)
= 1 − ξ for ξ ∈ [0, 1],
B3,1 (ξ) =
ξ−ξ3 ξ4 −ξ3 B3,0 (ξ)
+
ξ5 −ξ ξ5 −ξ4 B4,0 (ξ)
=
ξ−0 1−0 B3,0 (ξ)
+
1−ξ 1−1 B4,0 (ξ)
= ξ for ξ ∈ [0, 1],
B4,1 (ξ) =
ξ−ξ4 ξ5 −ξ4 B4,0 (ξ)
+
ξ6 −ξ ξ6 −ξ5 B5,0 (ξ)
=
ξ−1 1−1 B4,0 (ξ)
+
2−ξ 2−1 B5,0 (ξ)
= 2 − ξ for ξ ∈ [1, 2],
Open AGH e-podręczniki - content available under the CC BY-SA license
= 0,
32
2.3. Lagrange polynomials B5,1 (ξ) =
ξ−ξ5 ξ6 −ξ5 B5,0 (ξ)
+
ξ7 −ξ ξ7 −ξ6 B6,0 (ξ)
=
ξ−1 2−1 B5,0 (ξ)
+
2−ξ 2−2 B6,0 (ξ)
= ξ − 1 for ξ ∈ [1, 2],
B6,1 (ξ) =
ξ−ξ6 ξ7 −ξ6 B6,0 (ξ)
+
ξ8 −ξ ξ8 −ξ7 B7,0 (ξ)
=
ξ−2 2−2 B6,0 (ξ)
+
3−ξ 3−2 B7,0 (ξ)
= 3 − ξ for ξ ∈ [2, 3],
B7,1 (ξ) =
ξ−ξ7 ξ8 −ξ7 B7,0 (ξ)
+
ξ9 −ξ ξ9 −ξ8 B8,0 (ξ)
=
ξ−2 3−2 B7,0 (ξ)
+
3−ξ 3−3 B9,0 (ξ)
= ξ − 2 for ξ ∈ [2, 3],
B8,1 (ξ) =
ξ−ξ8 ξ9 −ξ8 B8,0 (ξ)
+
ξ10 −ξ ξ10 −ξ9 B9,0 (ξ)
B9,1 (ξ) =
ξ−ξ9 ξ10 −ξ9 B9,0 (ξ)
+
=
ξ11 −ξ ξ11 −ξ10 B10,0 (ξ)
ξ−3 3−3 B8,0 (ξ)
=
+
ξ−4 4−3 B9,0 (ξ)
4−ξ 4−3 B9,0 (ξ)
+
= 4 − ξ for ξ ∈ [3, 4],
4−ξ 4−4 B10,0 (ξ)
= ξ − 3 for ξ ∈ [3, 4],
B10,1 (ξ) =
ξ−ξ10 ξ11 −ξ10 B10,0 (ξ)
+
ξ12 −ξ ξ12 −ξ11 B11,0 (ξ)
=
ξ−4 4−4 B10,0 (ξ)
+
5−ξ 5−4 B11,0 (ξ)5
B11,1 (ξ) =
ξ−ξ11 ξ12 −ξ11 B11,0 (ξ)
+
ξ13 −ξ ξ13 −ξ12 B12,0 (ξ)
=
ξ−4 5−4 B11,0 (ξ)
+
5−ξ 5−5 B12,0 (ξ)
= ξ − 4 for ξ ∈ [4, 5],
B12,1 (ξ) =
ξ−ξ12 ξ13 −ξ12 B12,0 (ξ)
+
ξ14 −ξ ξ14 −ξ13 B13,0 (ξ)
=
ξ−5 5−5 B11,0 (ξ)
+
5−ξ 5−5 B12,0 (ξ)
= 0.
− ξ for ξ ∈ [4, 5],
We can now generate all second order B spline functions using the formula again
Bi,0 (ξ) = 1 if ξi ≤ ξ ≤ ξi+1 or 0 in other cases
Bi,p (ξ) =
ξ − ξi ξi+p+1 − ξ Bi,p−1 (ξ) + Bi+1,p−1 (ξ) ξi+p − ξi ξi+p+1 − ξi+1
(2.5)
(2.6)
for p = 2, assuming that the subsequent knots inserted into the denominator must be different, and if they are not different, then the given term is changed to zero. The elements that disappear are marked red again. In the final stage of the derivation, we insert the formulas calculated before B1,1 (ξ) = 0, B2,1 = 1 − ξ for ξ ∈ [0, 1], B3,1 = ξ for ξ ∈ [0, 1], B4,1 = 2 − ξ for ξ ∈ [1, 2], B5,1 = ξ − 1 for ξ ∈ [1, 2], B6,1 = 3 − ξ for ξ ∈ [2, 3], B7,1 = ξ − 2 for ξ ∈ [2, 3], B8,1 = 4 − ξ for ξ ∈ [3, 4], B9,1 = ξ − 3 for ξ ∈ [3, 4], B10,1 = 5 − ξ for ξ ∈ [4, 5], B11,1 = ξ − 4 for ξ ∈ [4, 5],B12,1 = 0 We get B1,2 (ξ) =
ξ − ξ1 ξ4 − ξ ξ−0 1−ξ B1,1 (ξ) + B2,1 (ξ) = B1,1 (ξ) + B2,1 (ξ) = (1 − ξ)2 for ξ ∈ [0, 1]. ξ3 − ξ1 ξ4 − ξ2 0−0 1−0
ξ − ξ2 ξ5 − ξ ξ−0 1−ξ B2,1 (ξ) + B3,1 (ξ) = B2,1 (ξ) + B3,1 (ξ) ξ4 − ξ2 ξ5 − ξ3 1−0 1−0 ξ−0 1−ξ = [1 − ξ for ξ ∈ [0, 1]] + [ξ for ξ ∈ [0, 1]] 1−0 1−0 = ξ(1 − ξ) + (1 − ξ)ξ for ξ ∈ [0, 1] = 2ξ(1 − ξ) for ξ ∈ [0, 1].
B2,2 (ξ) =
ξ − ξ3 ξ6 − ξ ξ−0 2−ξ B3,1 (ξ) + B4,1 (ξ) = B3,1 (ξ) + B4,1 (ξ) ξ5 − ξ3 ξ6 − ξ4 1−0 2−1 ξ−0 1−ξ = [ξ for ξ ∈ [0, 1]] + [2 − ξ for ξ ∈ [1, 2]] 1−0 1−0 = ξ 2 for ξ ∈ [0, 1] + (1 − ξ)(2 − ξ) for ξ ∈ [1, 2].
B3,2 (ξ) =
ξ − ξ4 ξ7 − ξ ξ−1 2−ξ B4,1 (ξ) + B5,1 (ξ) = B4,1 (ξ) + B5,1 (ξ) ξ6 − ξ4 ξ7 − ξ5 2−1 2−1 ξ−1 2−ξ = [2 − ξ for ξ ∈ [1, 2]] + [ξ − 1 for ξ ∈ [1, 2]] 2−1 2−1 = (ξ − 1)(2 − ξ) + (2 − ξ)(ξ − 1) for ξ ∈ [1, 2] = 2(ξ − 1)(2 − ξ) for ξ ∈ [1, 2].
B4,2 (ξ) =
ξ − ξ5 ξ8 − ξ ξ−1 3−ξ B5,1 (ξ) + B6,1 (ξ) = B5,1 (ξ) + B6,1 (ξ) ξ7 − ξ5 ξ8 − ξ6 2−1 3−2 ξ−1 3−ξ = [ξ − 1 for ξ ∈ [1, 2]] + [3 − ξ for ξ ∈ [2, 3]] 2−1 3−2 = (ξ − 1)2 for ξ ∈ [1, 2] + (3 − ξ)2 for ξ ∈ [2, 3].
B5,2 (ξ) =
Open AGH e-podręczniki - content available under the CC BY-SA license
33
2.4. Refined isogeometric analysis in 1D ξ − ξ6 ξ9 − ξ ξ−2 3−ξ B6,1 (ξ) + B7,1 (ξ) = B6,1 (ξ) + B7,1 (ξ) ξ8 − ξ6 ξ9 − ξ7 3−2 3−2 ξ−2 3−ξ = [3 − ξ for ξ ∈ [2, 3]] + [ξ − 2 for ξ ∈ [2, 3]] 3−2 3−2 = (ξ − 2)(3 − ξ) for ξ ∈ [2, 3] + (3 − ξ)(ξ − 2) for ξ ∈ [2, 3] = 2(ξ − 2)(3 − ξ) for ξ ∈ [2, 3].
B6,2 (ξ) =
ξ − ξ7 ξ10 − ξ ξ−2 4−ξ B7,1 (ξ) + B8,1 (ξ) = B7,1 (ξ) + B8,1 (ξ) ξ9 − ξ7 ξ10 − ξ8 3−2 4−3 ξ−2 4−ξ = [ξ − 2 for ξ ∈ [2, 3]] + [4 − ξ for ξ ∈ [3, 4]] = (ξ − 2)2 for ξ ∈ [2, 3] + (4 − ξ)2 for ξ ∈ [3, 4]. 3−2 4−3 ξ − ξ8 ξ11 − ξ ξ−3 4−ξ B8,2 (ξ) = B8,1 (ξ) + B9,1 (ξ) = B8,1 (ξ) + B9,1 (ξ) ξ10 − ξ8 ξ11 − ξ9 4−3 4−3 ξ−3 4−ξ = [4 − ξ for ξ ∈ [3, 4]] + [ξ − 3 for ξ ∈ [3, 4]] 4−3 4−3 = (ξ − 3)(4 − ξ) + (4 − ξ)(ξ − 3) for ξ ∈ [3, 4] = 2(ξ − 3)(4 − ξ) for ξ ∈ [3, 4]. B7,2 (ξ) =
ξ − ξ9 ξ12 − ξ ξ−3 6−ξ B9,1 (ξ) + B10,1 (ξ) = B9,1 (ξ) + B10,1 (ξ) ξ11 − ξ9 ξ12 − ξ10 4−3 5−4 ξ−3 5−ξ = [ξ − 3 for ξ ∈ [3, 4]] + [5 − ξ for ξ ∈ [4, 5]] 4−3 5−4 = (ξ − 3)2 for ξ ∈ [3, 4] + (5 − ξ)2 for ξ ∈ [4, 5].
B9,2 (ξ) =
ξ − ξ10 ξ13 − ξ ξ−4 5−ξ B10,1 (ξ) + B11,1 (ξ) = B10,1 (ξ) + B11,1 (ξ) ξ12 − ξ10 ξ13 − ξ11 5−4 5−4 ξ−4 5−ξ = [5 − ξ for ξ ∈ [4, 5]] + [ξ − 4 for ξ ∈ [4, 5]] 5−4 5−4 = (ξ − 4)(5 − ξ) + (5 − ξ)(ξ − 4) for ξ ∈ [4, 5] = 2(ξ − 4)(5 − ξ) for ξ ∈ [4, 5].
B10,2 (ξ) =
ξ − ξ11 ξ14 − ξ ξ−4 8−ξ B11,1 (ξ) + B12,1 (ξ) = B11,1 (ξ) + B11,1 (ξ) ξ12 − ξ11 ξ14 − ξ12 5−4 5−5 ξ−4 = [ξ − 4 for ξ ∈ [4, 5]] = (ξ − 4)2 for ξ ∈ [4, 5]. 5−4
B11,2 (ξ) =
We just derived the basis functions spanned over the knot vector with repeated knots between each element. It can be mathematically proved that the functions derived here B1,2 , ..., B11,2 constitute a base equivalent to the so-called Lagrange polynomials. Thus, one can use the knot vector notation to derive the B-spline basis functions used in the isogeometric finite element method, or to derive the Lagrange equivalent basis used in the classical finite element method.
2.4.
Refined isogeometric analysis in 1D
In this chapter we will look at matrices generated from the above-described B-spline basic functions, and we will estimate the factorization cost resulting from systems of equations. In this way, we can indicate the basis functions that give faster calculations using the isogeometric finite element method. For the sake of simplicity, let us establish that we are solving a one-dimensional projection problem. Details of the computations with a two-dimensional projection were described in the first chapter. We then have the following matrices called mass matrices. Suppose we want to solve a one-dimensional projection problem u(x) ≈ BIT M AP (x). Details on the computations with the two-dimensional projections are described in chapter one. Here, for simplicity, let us assume we solve the one-dimensional projection problem. Our bitmap (which we approximate in chapter one) is now a one-dimensional bitmap. This one-dimensional bitmap is approximated by a linear combination of a B-spline function P x u = i=1,...,Nx ui Bi;p (x). Open AGH e-podręczniki - content available under the CC BY-SA license
34
2.4. Refined isogeometric analysis in 1D Let us assume that we have 16 finite elements (16 intervals). Of course, it does not mean that Nx = 16, because Nx is the number of basis functions. How many basis functions there will be depends on what our knot vector will look like - in other words, it depends on the span of basis functions and whether and where we repeat the knots between the elements. In order to generate a system of equations with our matrix to the problem projection, we multiply our equation by the individual B-splines which are used to average our equations u(x) = BIT M AP (x) according to the distribution described by the B-splines, and we integrate to compute average Z Z x x u(x)B1;p (x) dx = BITMAP(x)B1;p (x) dx, Z Z x x u(x)B2;p (x) dx = BITMAP(x)B2;p (x) dx, .. . Z
x u(x)BN (x) dx x −1;p
Z
Z X
=
x u(x)BN (x) dx = x ;p
We put our approximation here u(x) = Z X
Z
P
i=1,...,Nx
Z
x BITMAP(x)BN (x) dx, x −1;p x BITMAP(x)BN (x) dx. x ;p
x ui Bi;p (x) and we get the system of equations:
Z
x x i = 1, ..., Nx ui Bi;p (x)B1;p (x) dx =
i=
x x 1, ..., Nx ui Bi;p (x)B2;p (x) dx
Z =
x BIT M AP (x)B1;p (x) dx, x BIT M AP (x)B2;p (x) dx,
.. . Z X
Z
x x i = 1, ..., Nx ui Bi;p (x)BN (x) dx = x −1;p
Z X
i=
x x 1, ..., Nx ui Bi;p (x)BN (x) dx x ;p
Z =
x BIT M AP (x)BN (x) dx, x −1;p x BIT M AP (x)BN (x) dx. x ;p
We take the sum out Z
X
i = 1, ..., Nx
X
i = 1, ..., Nx
Z
x x ui Bi;p (x)B1;p (x) dx
Z =
x x ui Bi;p (x)B2;p (x) dx =
Z
x BIT M AP (x)B1;p (x) dx, x BIT M AP (x)B2;p (x) dx,
.. . Z x x x ui Bi;p (x)BN (x) dx = BIT M AP (x)BN (x) dx, x −1;p x −1;p Z Z X x x x i = 1, ..., Nx ui Bi;p (x)BN (x) dx = BIT M AP (x)BN (x) dx. x ;p x ;p
X
Z
i = 1, ..., Nx
We can write our system of equations as follows R x R x x x B1;p (x)B1;p (x)dx B1;p (x)B2;p (x)dx R R x x x x B (x)B (x)dx B (x)B 2;p 2;p 2;p 2;p (x)dx . . .. .. R R x x x BN −1;p (x)B1;p (x)dx Bx (x)B2;p (x)dx R xx R Nxx −1;p x x BNx ;p (x)BNx ;p (x)dx BNx ;p (x)B2;p (x)dx
··· ··· .. . ··· ···
R x x B (x)BN (x)dx u1 x ;p R 1;p x x B2;p (x)BN (x)dx u2 x ;p .. .. = . . R x x B (x)BN (x)dx uNx −1 x ;p R Nxx −1;p x BNx ;p (x)BN (x)dx uNx x ;p
Open AGH e-podręczniki - content available under the CC BY-SA license
35
2.4. Refined isogeometric analysis in 1D R
R BIT M AP (x)B1x (x)dx R BIT M AP (x)B2x (x)dx .. . x BIT M AP (x)BNx − 1(x)dx R x BIT M AP (x)BN (x)dx x
Please note that the system of equations is sparse because the integrals of the products of one-dimensional B-spline basis functions are non-zero only when basis functions related to rows and columns of the matrix overlap. Why is it like that? The integral is the sum of the samples of the function values which we integrate. Our sample is the product of two functions i-th andj-th, x x Bi;p (x)Bj;p (x). If so for a given point at which we evaluate one of the functions, for example i-th is equal x to zero, so we have 0 ∗ Bj;p (x) = 0. x Likewise, if the second function j-this is equal to zero at the sampling point, we have then Bi;p (x) ∗ 0 = 0.
Let us assume now that we span a knot vector over our sixteen elements 0 0 0 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 16 16 16. We obtain the third-degree B-spline functions used in the isogeometric finite element method. They are depicted in Pic. 10. This figure also illustrates the fact that successive rows and columns in the matrix are related to the following B-spline functions specified in the node vector. Note that each one-dimensional degree B-spline function p overlaps other p overlaps 2p + 1 other one-dimensional B-spline function. For example, cubic B-splines p = 3 overlaps 2 ∗ 3 + 1 = 7 adjacent B-splines. Non-zero values in the matrix appear in these rows and columns, for which the corresponding basis functions ”overlap”(they do not have zero intersection of supports). Our system of equations is therefore sparse, and it contains seven diagonals. For our case of the sixteen finite elements, we have N = 16 + 3 = 19 cubic B-spline base functions (in total we have Ne + p of them). Our the matrix therefore has dimensions 19 × 19 and contains 7 dense diagonals. This is illustrated in Pic. 11. Let us now estimate the matrix factorization cost for the cubic B-spline base used in the isogeometric finite element method, shown in Pic. 11. We run the Gaussian elimination algorithm that skips all zeros in matrix. It is described in chapter four. This cost is equal to the cost of factorizing a single row on submatrix of size 4 × 4. This cost is related to the multiplication of the first row of size 4, and subtracting this row from other rows which is 3*3*2 (the cost of subtracting the first row from others, along with multiplication by the value from the diagonal). We repeat this operation for 16 blocks of the matrix (corresponding to 16 elements), and for the last block, we complete the factorization, which costs 2*2*2 (cost of subtracting the second row from the others, along with multiplying by diagonal value) + 2*1 (cost of subtracting the third row from the fourth, with multiplication by the value of the diagonal) + 1 (scaling the last line). The total cost amounts to 4 * 16 + 3 * 3 * 2 * 16 + 2 * 2 * 2 + 2 * 1 + 1 = 64 + 18 * 16 + 8 + 2 + 1 = 363. Now consider the case where we repeat nodes in between individual finite elements. In general, if we want to get basis functions equivalent to Lagrange polynomials used in the classical finite element method, we need to repeat the nodes p − 1 times, where p is the order of the B-spline base. For cubic B-splines, we need to repeat knots two times: [0 0 0 0 1 1 1 2 2 2 3 3 3 4 4 4 5 5 5 6 6 6 7 7 7 8 8 8 9 9 9 10 10 10 11 11 11 12 12 12 13 13 13 14 14 14 15 15 15 16 16 16 16]. What is the matrix of our system of equations? Each cubic B-spline base function spans over four elements (it uses five knots, ranging from 0 0 0 0 1, then 0 0 0 1 2, them 0 0 1 2 3, then 0 1 2 3 4, and so on up to 10 11 12 13 14, then 11 12 13 14 15, then 12 13 14 15 15, then 13 14 15 15 15, then 14 15 15 15 15, Open AGH e-podręczniki - content available under the CC BY-SA license
36
2.4. Refined isogeometric analysis in 1D then to 15 16 16 16 16. How many such sequneces do we have in our knot vector? There are 16 * 3 + 1 = 49. Our matrix therefore has a dimension 49 × 49, and is shown on Pic. 12. The difference between the matrix just obtained for the base equivalent to Lagrange polynomials with respect to the matrix obtained earlier for the function build with B-spline functions is as follows. The matrix for the B-spline function is smaller but it has denser diagonals. The matrix obtained for the basis equivalent to the Lagrange base is larger but sparser on diagonals. Now let us estimate the matrix factorization cost for the base equivalent to the Lagrange base used in the standard finite element method, shown in Pic. 12. This cost is equal to is the cost factorization of a single size sub-matrix 49 × 49 by the full Gauss elimination algorithm, ie 4 + 3 + 2 (first, second, third, and fourth scaling cost line from diagonal to end of line) plus 3 * 3 * 2 (cost of subtruction of the first row from the rest rows, along with multiplication by the value of the diagonal) plus 2 * 2 * 2 (the cost of subtracting the second row from the rest, with multiplication by the diagonal value) + 1 * 2 (cost of subtracting of the third row from the fourth row, along with multiplying by value from the diagonal). The total cost for one block is 4 + 3 + 2 + 3 * 3 * 2 + 2 * 2 * 2 + 2 * 1 = 9 + 18 + 8 + 2 = 36. We have 16 items so the total cost is 36 * 16 = 576. Now let us see what happens if we mix Lagrange polynomials with B-spline functions. Let us introduce a knots vector 0 0 0 0 1 2 3 4 4 4 5 6 7 8 8 8 9 10 11 12 12 12 13 14 15 16 16 16 16 in which we repeated knots in groups of every four elements. We will obtain then the base functions and the matrix shown in Pic. 13. In this case, we have the basis of 25 functions. So our matrix has size 25 × 25, and it has dense diagonal blocks of size 7 by 7. These blocks are separated by C0 separators. What is the cost of factoring in this case? This cost is equal to the cost of factorizing a single row from submatrix of size 4 × 4. Namely 4 (cost of scaling a row of four columns) plus 3 * 3 * 2 (cost of subtracting the first row from others, along with multiplication by the value from the diagonal). This operation we repeat for 4 submatrices in a block (corresponding to 4 elements), and we repeat the whole thing 4 times (because we have 4 blocks in the matrix). So the total cost is (4 + 3 * 3 * 2 * 4)* 4 = 76 * 4 = 304. Let us summarize then. The classical finite element method for 16 elements and the base equivalent to the Lagrange base of the third order requires 576 floating-point operations to factorize the matrix (multiplications and additions / subtractions). The isogeometric finite element method for 16 elements of the base equivalent to the B-splines of the third order requires 363 floating-point operations. The hybrid method requires 304 floating-point operations. So, we can see that even in simple one-dimensional example, a hybrid method, between the cubic B-spline basis functions and the basis equivalent to the Lagrange’s base wins in terms of the computational cost over a pure cubic B-splines base and with a pure base equivalent to Lagrange’s base. This difference will be much larger (up to two orders of magnitude) for two-dimensional and three-dimensional problems. Such systematic repetition of knot points in the knot vector to reduce the computational cost of the finite element method is called the refined isogeometric analysis [11]. Please also note that by inserting C0 separators (by reducing the continuity on the interfaces between elements) we increase the approximation space and we increase the approximative power of our basis functions. Hence, adding these new features and reducing the continuity actually increases the accuracy of the approximation.
Figure 10: An example of a computational mesh for a one-dimensional projection problem containing sixteen finite elements and element matrices generated on them.
Open AGH e-podręczniki - content available under the CC BY-SA license
37
2.4. Refined isogeometric analysis in 1D
Figure 11: An example of a one-dimensional problem obtained by the knot vector [0 0 0 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 16 16 16] corresponding to the base B-spline functions of the third order spread over sixteen elements used by the isogeometric finite element method.
Open AGH e-podręczniki - content available under the CC BY-SA license
38
2.4. Refined isogeometric analysis in 1D
Figure 12: Example of a one-dimensional problem obtained with a knots vector [0 0 0 0 1 1 1 2 2 2 3 3 3 4 4 4 5 5 5 6 6 6 7 7 7 8 8 8 9 9 9 10 10 10 11 11 11 12 12 12 13 13 13 14 14 14 15 15 15 16 16 16 16] corresponding to the basis functions equivalent to Lagrange polynomials of the third order spanning over sixteen elements used by the classical finite element method.
Open AGH e-podręczniki - content available under the CC BY-SA license
39
2.5. Two-dimensional generalization of basis functions with tensor products
Figure 13: An example of a one-dimensional problem obtained using a knot vector [0 0 0 0 1 2 3 4 4 4 5 6 7 8 8 8 9 10 11 12 12 12 13 14 15 16 16 16 16] in which the nodes at the boundaries of groups of four elements were repeated, corresponding to the base functions B-spline of the third degree within groups of elements and Lagrange polynomials of the third degree spanning the boundaries of groups of elements.
2.5.
Two-dimensional generalization of basis functions with tensor products
In the previous chapters, we defined the basis functions on a one-dimensional interval. We will now show how this definition can be generalized to two-dimensional problems. First, consider the rectangular mesh on which we span Nx × Ny = 16 × 16 elements with one edge parallel to the axis x and the other edge is parallel to the axis y. So we have Nx = 16 elements along x i Ny = 16 elements along y. Consider the bitmap projection problem described in detail in Chapter One. We then define a knot vector along the axis x [0 0 0 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 16 16 16] and knot vector along the axis y [0 0 0 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 16 16 16]. These knot vectors define the third order B-spline basis functions of continuity two, which means that if we calculate the bitmap projections using such B-spline functions, our approximation will be very smooth, and Open AGH e-podręczniki - content available under the CC BY-SA license
40
2.5. Two-dimensional generalization of basis functions with tensor products we can calculate the first and second derivative at each bitmap point. It is like making a very slim plastic cast of our bitmap. x x Our knot vector along the axis x defines the following basic functions B1;3 (x), ..., B19;3 (x), the formula of which can be derived according to the Cox-de Boor formula, where we introduce third order B-splines that extend over four consecutive intervals. In particular, we have Nx +p = Nx +3 = 16+3 = 19 such functions.
Likewise, we derive the B-spline functions for the knot vector along axis y, and we get 19 third degree y y B-splines B1;3 (x), ..., B19;3 (x) according to the formula Bi,0 (ξ) = 1 if ξi ≤ ξ ≤ ξi+1 or 0 in other cases
Bi,p (ξ) =
ξ − ξi ξi+p+1 − ξ Bi,p−1 (ξ) + Bi+1,p−1 (ξ) ξi+p − ξi ξi+p+1 − ξi+1
(2.7)
(2.8)
Then we obtain our two-dimensional basis functions by multiplying the selected one basis function from the first set, spanning along the axis x, and one base function from the second pattern, spanning along the axis y. We can arrange them by lines (parallel to the axis x). y y y y x x x x B1;3 B1,3 , B2;3 B1,3 , ..., BN B1,3 , BN B1,3 , x −1;3 x ;3 y y y y x x x x B1;3 B2,3 , B2;3 B2,3 , ..., BNx −1;3 B2,3 , BNx ;3 B2,3 , ···, y y y y x x x x B1;3 BN , B2;3 BN , ..., BN BN , BN BN , x −1;3 x ;3 y −1,3 y −1,3 y −1,3 y −1,3 y y y y x x x x B1;3 BNy ,3 , B2;3 BNy ,3 , ..., BNx ;3 BNy ,3 , BNx ;3 BNy ,3 . In this way, we obtain a base of two-dimensional basis functions {Bi,j;3 (x, y)}i=1,...,Nx ,j=1,...,Ny = y y x x {Bi;3 (x)Bj;3 }i=1,...,Nx ,j=1,...,Ny = {Bi;3 (x)Bj;3 }i=1,...,19,j=1,...,19 spanned on a rectangular computational grid composed of 16 * 16 = 256 elements. They are shown in the picture Pic. 14.
Open AGH e-podręczniki - content available under the CC BY-SA license
41
2.5. Two-dimensional generalization of basis functions with tensor products
Figure 14: Exemplary two-dimensional cubic B-spline basis functions obtained from tensor product of two knot vectors [[0 0 0 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 16 16 16] along x axis and another knot vector [0 0 0 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 16 16 16] along y axis.
We can spread the bitmap approximation on them u(x, y) =
P16,16
i=1,j=1
ui,j Bix (x)Bjy (y)
by calculating the coefficients ui,j as described in chapter one. In particular, we will need to generate integrals from the products of pairs of B-spline functions R B x (x)Bjy (y)Bkx (x)Bly (y)dxdy dla i = 1, .., 19, j = 1, ..., 19. In the case of base functions spanning Ω i on a flat grid, these integrals can be broken down into the product of two integrals of pairs of B-splines in particular directions. R R B x (x)Bjy (y)Bkx (x)Bly (y)dxdy = Ωy Bix (x)Bkx (x)dxBjy (y)Bly (y)dy Ωx i where Ω is our rectangular mesh,Ωx is the edge of a rectangular grid along the axis x, Ωy is the edge of a rectangular grid along the axis y. Let us now deal with an interesting case in which our computational mesh is not a regular rectangle, but is stretched, for example, over a manifold, as shown in Pic. 15.
Open AGH e-podręczniki - content available under the CC BY-SA license
42
2.6. Three-dimensional generalization of basis functions with tensor products
Figure 15: Exemplary second order two-dimensional B-spline basis functions obtained from tensor product of two knot vectors [0 0 0 1 2 3 4 5 6 7 8 9 9 9] along x axis and another knot vector [0 0 1 2 3 4 5 6 7 8 9 9] along y axis.
In this case, we have linear (first degree) B-spline functions in the direction of the axis x and second order B-spline functions in the direction of the axis y. The plot of this basis function is presented in the picture Pic. 15 and its formula is y(y − 1)(1 − x). Then we define our knot vectors in the same way, we define one-dimensional basis functions in the same way, and then we have to define transformations from a rectangular mesh to a mesh spanning the edge of the manifold. ΩS and we have to name our axes differently x ˆ i yˆ span on the edge of the manifold. R yˆ yˆ x ˆ x ˆ Bi;3 (ˆ x)Bj;3 (ˆ y )Bk;3 (ˆ x)Bl;3 (ˆ y )dˆ xdˆ y ΩS and we need to change the variables in the integrals from the rectangle spanned on the R edge of the manifold which is on the rectangle ΩS Bix (ˆ x)Bjy (ˆ y )Bkx (ˆ x)Bly (ˆ y )dˆ xdˆ y = R y y x x B (x)B (y)B (x)B (y)|JacM ap(x, y)|dxdy j k l Ω i and then apply the Jacobian mapping M ap(x, y) which shifts a flat rectangle onto a rectangle stretched at the edge of the manifold. Note that to use the alternating directions solver algorithm, the Jacobian mapping of this map must be split into the product of the Jacobian functions of x and function of y, so JacM ap(x, y) = JacM apx (x)JacM apy (y). Otherwise, we will not separate the integrals Z ΩS
Bix (ˆ x)Bjy (ˆ y )Bkx (ˆ x)Bly (ˆ y ) dˆ x dˆ y Z = Ω
Z = Ω
Bix (x)Bjy (y)Bkx (x)Bly (y)|Jac M ap(x, y)| dx dy
Bix (x)Bkx (x)|Jac M apx (x)| dx
Z Ω
Bjy (y)Bly (y)|Jac M apy (y)| dy
This is not always possible, and then a multi-frontal or iterative solver should be used instead of the alternating-direction solver.
2.6.
Three-dimensional generalization of basis functions with tensor products
We will now show how the definitions of the basis functions can be generalized into three-dimensional problems. Open AGH e-podręczniki - content available under the CC BY-SA license
43
2.6. Three-dimensional generalization of basis functions with tensor products First, consider the rectangular mesh on which we define Nx × Ny × Nz = 16 × 16 × 16 elements with one edge parallel to the axis x, the other edge parallel to the axis y, and the third edge is parallel to the axis z. So we have Nx = 16 elements along the axis x i Ny = 16 elements along the axis y and Nz = 16 elements along the axis z. Consider again the bitmap approximation problem described in detail in Chapter One. This time, however, we need to focus on a three-dimensional bitmap. Bitmaps are also generated during, for example, head CT scans Pic. 16.
Figure 16: Slices of a three-dimensional bitmap obtained by computed tomography of the head.
We then define a knot vector along the axis x [0 0 0 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 16 16 16] and identical knot vector along the axis y [0 0 0 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 16 16 16] and along the axis z [0 0 0 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 16 16 16]. These knot vectors define the basis functions of B-splines of the third order with a continuity of two. x x Our knot vectors define the following basis functions B1;3 (x), ..., B19;3 (x) along the axisx, y y B1;3 (y), ..., B19;3 (y) along the axisy, and
Open AGH e-podręczniki - content available under the CC BY-SA license
44
2.6. Three-dimensional generalization of basis functions with tensor products z z B1;3 (z), ..., B19;3 (z) along the axisz,
The formulas of these one-dimensional B-spline functions can be derived according to the Cox-de Boor formula. There are 19 of them in each direction because Nx + p = Ny + p = Nz + p = 16 + 3 = 19. Then, our three-dimensional basis functions are obtained by multiplying the selected basis function from the first set, stretched along the x, one base function from the second set, stretched along the axis y, and one base function from the second set, stretched along the axis z. We can arrange them by levels (parallel to the plane OXY ) and lines (parallel to the axis x). y y y y x z x z x z x z B1;3 B1,3 B1,3 , B2;3 B1,3 B1,3 , ..., BN B1,3 B1,3 , BN B1,3 B1,3 , x −1;3 x ;3 y y y y x z x z x z x z B1;3 B2,3 B1,3 , B2;3 B2,3 B1,3 , ..., BN B2,3 B1,3 , BN B2,3 B1,3 , x −1;3 x ;3 ···, y y y y x z x z x z x z B1;3 BN B1,3 , B2;3 BN B1,3 , ..., BN BN B1,3 , BN BN B1,3 , x −1;3 x ;3 y −1,3 y −1,3 y −1,3 y −1,3 y y y y x z x z x z x z B1;3 BN B1,3 , B2;3 BN B1,3 , ..., BN BN B1,3 , BN BN B1,3 , x ;3 x ;3 y ,3 y ,3 y ,3 y ,3 ···, y y y y x z x z x z x z B1;3 B1,3 B2,3 , B2;3 B1,3 B2,3 , ..., BN B1,3 B2,3 , BN B1,3 B2,3 , x −1;3 x ;3 y y y y x z x z x z x z B1;3 B2,3 B2,3 , B2;3 B2,3 B2,3 , ..., BN B2,3 B2,3 , BN B2,3 B2,3 , x −1;3 x ;3 ···, y y y y x z x z x z x z B1;3 BN B2,3 , B2;3 BN B2,3 , ..., BN BN B2,3 , BN BN B2,3 , x −1;3 x ;3 y −1,3 y −1,3 y −1,3 y −1,3 y y y y x z x z x z x z B1;3 BN B2,3 , B2;3 BN B2,3 , ..., BN BN B2,3 , BN BN B2,3 , x ;3 x ;3 y ,3 y ,3 y ,3 y ,3 ···, y y y y x z x z x z x z B1;3 B1,3 BN , B2;3 B1,3 BN , ..., BN B1,3 BN , BN B1,3 BN , z ,3 z ,3 x −1;3 z ,3 x ;3 z ,3 y y y y x z x z x z x z B1;3 B2,3 BN , B2;3 B2,3 BN , ..., BN B2,3 BN , BN B2,3 BN , z ,3 z ,3 x −1;3 z ,3 x ;3 z ,3 ···, y y y y x z x z x z x z B1;3 BN BN , B2;3 BN BN , ..., BN BN BN , BN BN BN , z ,3 z ,3 x −1;3 z ,3 x ;3 z ,3 y −1,3 y −1,3 y −1,3 y −1,3 y y y y x z x z x z x z B1;3 BN BN , B2;3 BN BN , ..., BN BN BN , BN BN BN . z ,3 z ,3 x ;3 z ,3 x ;3 z ,3 y ,3 y ,3 y ,3 y ,3 In this way, we obtain the set of three-dimensional basis functions
{Bi,j,k;3 (x, y, z)}i=1,...,Nx ,j=1,...,Ny ,k=1,...,Nz y x z = {Bi;3 (x)Bj;3 (y)Bk;3 (z)}i=1,...,Nx ,j=1,...,Ny ,k=1,...,Nz y x = {Bi;3 (x)Bj;3 (y)}i=1,...,19,j=1,...,19 x z = {Bi;3 (x)Bk;3 (z)}i=1,...,19,k=1,...,19
spanned on a rectangular computational grid composed of 16 * 16 * 16 = 4096 elements. We can run the approximation of a three-dimensional bitmap on them u(x, y, z) P16,16,16 y y x i=1,j=1,k=1 ui,j,k Bi (x)Bj (y)Bk (z)
=
by calculating the coefficients ui,j,k as described in chapter one. In particular, we will need to generate integrals from the products of the triples of the B-spline function R y B x (x)Bjy (y)Bkz (z)Blx (x)Bm (y)Bnz (z)dxdydz for i = 1, .., 19, j = 1, ..., 19, k = 1, ..., 19. In the case of Ω i basis functions spread on a flat grid, these integrals can be broken down into the product of three integrals of B-spline triples in particular directions R R y y B x (x)Bjy (y)Bky (z)Blx (x)Bm (y)Bnz (z)dxdydz = Ωy Bix (x)Blx (x)dxBjy (y)Bm (y)dyBkz (z)Bnz (z)dz Ωx i Open AGH e-podręczniki - content available under the CC BY-SA license
45
2.6. Three-dimensional generalization of basis functions with tensor products where Ω is our rectangular mesh,Ωx , Ωy , Ωz are the axes stretched along the edges of the rectangular grid. Please note that if we want to use other basis functions, for example, the basis equivalent to Lagrange polynomials, the whole structure remains unchanged, we only define other knot vectors which give us a different number of basis functions. For example, to generate a base equivalent to Lagrange polynomials, we define a knot vector [0 0 0 0 1 1 1 2 2 2 3 3 3 4 4 4 5 5 5 6 6 6 7 7 7 8 8 8 9 9 9 10 10 10 11 11 11 12 12 12 13 13 13 14 14 14 15 15 15 16 16 16 16] along the axis x and the second knot vector [0 0 0 0 1 1 1 2 2 2 3 3 3 4 4 4 5 5 5 6 6 6 7 7 7 8 8 8 9 9 9 10 10 10 11 11 11 12 12 12 13 13 13 14 14 14 15 15 15 16 16 16 16] along the axis y and the third knot vector [0 0 0 0 1 1 1 2 2 2 3 3 3 4 4 4 5 5 5 6 6 6 7 7 7 8 8 8 9 9 9 10 10 10 11 11 11 12 12 12 13 13 13 14 14 14 15 15 15 16 16 16 16 ] along the axis z. Then we generate the base functions according to the formula
Bi,0 (ξ) = 1 if ξi ≤ ξ ≤ ξi+1 or 0 in other cases
Bi,p (ξ) =
ξ − ξi ξi+p+1 − ξ Bi,p−1 (ξ) + Bi+1,p−1 (ξ) ξi+p − ξi ξi+p+1 − ξi+1
(2.9)
(2.10)
and multiply them by ourselves (we create the tensor product). We can also generate third order B spline polynomials, for example [0 0 0 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 16 16 16] along the axis x, polynomials equivalent to Lagrange polynomial [0 0 0 0 1 1 1 2 2 2 3 3 3 4 4 4 5 5 5 6 6 6 7 7 7 8 8 8 9 9 9 10 10 10 11 11 11 12 12 12 13 13 13 14 14 14 15 15 15 16 16 16 16] along the axis y, and ”hybrid” polynomials [0 0 0 0 1 2 3 4 4 4 5 6 7 8 8 8 9 10 11 12 12 12 13 14 15 16 16 16 16] along the axis z. Then, similarly, we generate base functions according to the formula (??.9) and (??.10), and we multiply them by themselves (we form the tensor product). It is also possible to construct meshes in which patches of elements of various sizes and with a different number of elements are mixed, and knot vectors are created separately for each group of elements. An example is shown in Pic. 17.
Open AGH e-podręczniki - content available under the CC BY-SA license
46
2.7. Non-regular meshes
Figure 17: An example of a three-dimensional computational mesh obtained by merging three groups of elements with the B-spline second order base functions defined on them. In particular, on the first largest group of elements, the B-spline base functions were defined by using the knot vector 0 0 0 1 2 3 4 5 6 7 8 8 8 in the direction of the x axis and in the direction of the z axis, on the second middle group of elements the knot vector 0 0 was defined 0 1 2 3 4 4 4 in the direction of the x axis and in the direction of the z axis, and on the third group of elements a knot vector is defined 0 0 0 1 2 2 2 in the direction of the x or y axis. Moreover, we define a knot vector 0 0 0 1 2 2 3 3 4 4 4 in the y direction.
2.7.
Non-regular meshes
During the finite element calculations irregular meshes are also used. They are made of triangular elements in two dimensions or of tetrahedral elements in three dimensions. Unfortunately, the method of creating basis functions through knot vectors does not work on triangular or tetrahedral meshes. Before the isogeometric analysis, it was the most widely used version of the finite element method. Currently, calculations using the finite element method are often integrated with geometric objects created in CAD systems. Then, the need to generate a mesh of irregular elements on geometric objects already described with the B-spline and NURBS functions require additional work overhead and the need to reconcile elements on adjacent geometric objects. On irregular meshes, B-spline functions with higher regularity are not defined due to the fact that B-spline functions are defined on many adjacent rectangular elements. On triangular and tetrahedral elements, polynomials are defined as spanned over elements adjacent to a given vertex or edge. Examples of such functions are Lagrange polynomials or hierarchical polynomials. The method of defining basis functions on such elements is well described in the books of prof. Leszek
Open AGH e-podręczniki - content available under the CC BY-SA license
47
2.7. Non-regular meshes Demkowicz [6], [7]. First degree or higher degree polynomials can be defined on each triangular element. A popular way of defining these polynomials is shown in Pic. 18. The triangle marked on it defines the orientation of its three edges, which is important for the formal definition of basis functions and a finite element.
Figure 18: The method of defining the basis functions of the first and higher orders on triangular elements.
So, we now have the following options • The basis functions of the first-degree polynomials related to the three vertices of the triangle, reaching a maximum of 1 in individual triangle vertices, and 0 in the rest • Basis functions polynomials of degree p related to the three edges of the triangle, which are polynomial degrees p on the edge on which they are connected, reaching zeros in all vertices and on the other two edges. • Basis functions of polynomials of degree p related to the interior of the triangle, being a polynomial of degrees p over the interior of the triangle, reaching zero at all vertices and edges. For this purpose, we define two axes of the coordinate system on any triangular element ξ1 along one side of the triangle and ξ2 along the other side of the triangle. We define three functions that form the so-called barycentric coordinate system spread over a triangle λ1 (ξ1 , ξ2 ) = 1 − ξ1 − ξ2
λ2 (ξ1 , ξ2 ) = ξ1
λ3 (ξ1 , ξ2 ) = ξ2
reaching a maximum of 1 in each vertex of the triangle, and 0 in the others. Function λ1 is bound to the first vertex at (0,0) in the coordinate system spanned by the axes ξi and ξ2 . Function λ2 is related to the second vertex on the axis ξ1 . Function λ3 it is related to the third vertex on the axis ξ2 . These functions allow us to define our basis functions that we mark ψi . We start with the base functions related to the vertices of the triangle
ψ1 (ξ1 , ξ2 ) = λ1 (ξ1 , ξ2 ) = 1 − ξ1 − ξ2 ψ2 (ξ1 , ξ2 ) = λ2 (ξ1 , ξ2 ) = ξ1 ψ3 (ξ1 , ξ2 ) = λ3 (ξ1 , ξ2 ) = ξ2
Open AGH e-podręczniki - content available under the CC BY-SA license
48
2.7. Non-regular meshes So, of course, we have a base function ψ1 related to the first vertex at (0,0) in the coordinate system spanned by the axes ξ1 and ξ2 , base function ψ2 associated with the second vertex on the axis ξ1 , and base function ψ3 related to the third vertex on the axis ξ2 . Building the second-order basis functions on a triangle requires multiplying the basis functions defined on the vertices by themselves. We build functions
ψ4 (ξ1 , ξ2 ) = λ1 (ξ1 , ξ2 )λ2 (ξ1 , ξ2 ) = (1 − ξ1 − ξ2 )ξ1 ψ5 (ξ1 , ξ2 ) = λ2 (ξ1 , ξ2 )λ3 (ξ1 , ξ2 ) = ξ1 ξ2 ψ6 (ξ1 , ξ2 ) = λ3 (ξ1 , ξ2 )λ1 (ξ1 , ξ2 ) = ξ2 (1 − ξ1 − ξ2 ) So you can see that when multiplying two vertex functions related to the first and second vertices λ1 and λ2 gives us the possibility to define a quadratic function spanning the edge between these vertices. Self-multiplication of two vertex functions related to the second and third vertices, λ2 and λ3 gives us the possibility to define a quadratic function spanning the edge between these vertices. In turn, multiplication of the vertex functions related to the first and third vertices,λ1 , and λ3 gives us the possibility to define a quadratic function spanning the third edge of the triangle. The base function over the interior of an element is defined as the product of all functions λ1 , λ2 , λ3 . ψ7 (ξ1 , ξ2 ) = λ1 (ξ1 , ξ2 )λ2 (ξ1 , ξ2 )λ3 (ξ1 , ξ2 ) What does it look like in three dimensions where the elements are tetrahedral? In the case of three dimensions, we need to span the three axes of the coordinate system ξ1 , ξ2 , ξ3 along the three edges of the tetrahedron. Then we define analogous four functions
λ1 (ξ1 , ξ2 , ξ3 ) = 1 − ξ1 − ξ2 − ξ3 λ2 (ξ1 , ξ2 , ξ3 ) = ξ1 λ3 (ξ1 , ξ2 , ξ3 ) = ξ2 λ4 (ξ1 , ξ2 , ξ3 ) = ξ3 reaching a maximum of 1 in each vertex of the triangle, and 0 in the others. We define the basis functions related to the vertices of the tetrahedron
ψ1 (ξ1 , ξ2 , ξ3 ) = λ1 (ξ1 , ξ2 , ξ3 ) = 1 − ξ1 − ξ2 − ξ3 ψ2 (ξ1 , ξ2 , ξ3 ) = λ2 (ξ1 , ξ2 , ξ3 ) = ξ1 ψ3 (ξ1 , ξ2 , ξ3 ) = λ3 (ξ1 , ξ2 , ξ3 ) = ξ2 ψ4 (ξ1 , ξ2 , ξ3 ) = λ4 (ξ1 , ξ2 , ξ3 ) = ξ3 . So we have, of course basis function ψ1 related to the first vertex at (0,0,0) in the coordinate system spanned by the axes ξ1 , ξ2 , ξ3 , base function ψ2 associated with the second vertex on the axis ξ1 , base function ψ3 related to the third vertex on the axis ξ2 , and base function ψ4 related to the third vertex on the axis ξ3 . Open AGH e-podręczniki - content available under the CC BY-SA license
49
2.7. Non-regular meshes Building the second-order basis functions on a tetrahedron requires multiplying the basis functions defined on the vertices by itself. We build edge functions by multiplying two vertex functions
ψ4 (ξ1 , ξ2 , ξ3 ) = λ1 (ξ1 , ξ2 , ξ3 )λ2 (ξ1 , ξ2 , ξ3 ) = (1 − ξ1 − ξ2 − ξ3 )ξ1 ψ5 (ξ1 , ξ2 , ξ3 ) = λ2 (ξ1 , ξ2 , ξ3 )λ3 (ξ1 , ξ2 , ξ3 ) = ξ1 ξ2 ψ6 (ξ1 , ξ2 , ξ3 ) = λ3 (ξ1 , ξ2 , ξ3 )λ4 (ξ1 , ξ2 , ξ3 ) = ξ2 ξ3 ψ7 (ξ1 , ξ2 , ξ3 ) = λ4 (ξ1 , ξ2 , ξ3 )λ1 (ξ1 , ξ2 , ξ3 ) = ξ3 (1 − ξ1 − ξ2 − ξ3 ) . So you can see that when multiplying two vertex functions related to the first and second vertices λ1 and λ2 gives us the possibility of defining a function - a second degree polynomial - spanned on the edge between these vertices (the degree of a polynomial is the sum of all exponents of the powers of a non-zero monomial). Self-multiplication of two vertex functions related to the second and third vertices, λ2 and λ3 gives us the possibility to define a function - polynomial and second degree - spanned on the edge between these vertices. Self-multiplication of two vertex functions related to third and fourth vertices, λ3 and λ4 gives us the possibility to define a function - a polynomial of the second degree - spanning on the edge between these vertices. λ1 , and λ5 gives us the possibility to define a function - a polynomial of the second degree - spanned on the third edge of the triangle. The basis functions on the element faces are obtained by multiplying the appropriate three basis functions from the vertices surrounding the face
ψ8 (ξ1 , ξ2 , ξ3 ) = λ1 (ξ1 , ξ2 , ξ3 )λ2 (ξ1 , ξ2 , ξ3 )λ3 (ξ1 , ξ2 , ξ3 ) = (1 − ξ1 − ξ2 − ξ3 )ξ1 ξ2 ψ9 (ξ1 , ξ2 , ξ3 ) = λ2 (ξ1 , ξ2 , ξ3 )λ3 (ξ1 , ξ2 , ξ3 )λ4 (ξ1 , ξ2 , ξ3 ) = ξ1 ξ2 ξ3 ψ10 (ξ1 , ξ2 , ξ3 ) = λ1 (ξ1 , ξ2 , ξ3 )λ3 (ξ1 , ξ2 , ξ3 )λ4 (ξ1 , ξ2 , ξ3 ) = (1 − ξ1 − ξ2 − ξ3 )ξ2 ξ3 ψ11 (ξ1 , ξ2 , ξ3 ) = λ1 (ξ1 , ξ2 , ξ3 )λ2 (ξ1 , ξ2 , ξ3 )λ4 (ξ1 , ξ2 , ξ3 ) = (1 − ξ1 − ξ2 − ξ3 )ξ1 ξ3 Self-multiplication of three vertex functions related to the first, second and third vertices, λ1 , λ3 i λ3 gives us the possibility to define a function - a third degree polynomial ψ8 - stretched on the wall between these vertices. Similarly, self-multiplication of the three vertex functions related to the second, third and fourth vertices λ1 , λ3 , λ4 gives us the possibility to define a function - a third degree polynomial ψ9 - stretched on the wall between these vertices. Self-multiplication of the three vertex functions related to the first, third and fourth vertices λ1 , λ3 , λ4 gives us the possibility to define a function - a third degree polynomial ψ10 - stretched on the wall between these vertices. Finally, multiplying by themselves, the three vertex functions related to the first, second and fourth vertices, λ1 , λ2 , λ4 gives us the possibility to define a function - a third degree polynomial ψ11 - stretched on the wall between these vertices. The last basis function to define is the function related to the interior of the element. It can be obtained by multiplying the four basis vertex functions ψ12 (ξ1 , ξ2 , ξ3 ) = λ1 (ξ1 , ξ2 , ξ3 )λ2 (ξ1 , ξ2 , ξ3 )λ3 (ξ1 , ξ2 , ξ3 )λ4 (ξ1 , ξ2 , ξ3 ) = (1 − ξ1 − ξ2 − ξ3 )ξ1 ξ2 ξ3 . Open AGH e-podręczniki - content available under the CC BY-SA license
50
2.8. MATLAB implementation of the generation of basis functions based on the knot vector
2.8.
MATLAB implementation of the generation of basis functions based on the knot vector
Below you can find a link to the MATLAB code that calculates and draws B-spline basis functions based on a given node vector. The code execution is also possible in the free Octave environment. Download or see Appendix 2. After installing Octave, open the code. The running of the code starts with the spline () precedent which sets the example vector of knot_vector = [1,1,1,2,3,3,4,5,6,7,7,7] then calculates the number of basis functions using the compute_nr_basis_functions () procedure, and calculates the degree of basis functions (homogeneous for the whole vector of nodes) using the compute_p procedure, and the vector of x points where basis functions will be counted using the mesh () procedure. The code generates the values of the underlying functions at these points using compute_spline () and then draws the functions using the plot command in a loop. It is possible to modify the node vector in order to generate different bases.
EXERCISE
Exercise 1: 1st order Lagrange polynomials Exercise content:
Please generate a vector of nodes that generates a base equivalent to the Lagrange basis of polynomials of the first order on two elements [0,1] and [1,2]. Please run MATLAB code and draw base functions.
Solution:
[0 0 1 2 2]
EXERCISE
Exercise 2: 4th order Lagrange polynomials Exercise content:
Please generate a vector of nodes that generates a base equivalent to the Lagrange base of polynomials of the fourth degree on five elements [0,1] and [1,2] and [2,3] and [3,4] and [4,5]. Please run MATLAB code and draw base functions.
Solution:
Open AGH e-podręczniki - content available under the CC BY-SA license
51
2.8. MATLAB implementation of the generation of basis functions based on the knot vector [0 0 0 0 0 1 1 1 2 2 2 3 3 3 4 4 4 5 5 5 5 5]
EXERCISE
Exercise 3: 3rd order B-splines with C2 continuity Exercise content:
Please generate a vector of nodes that generates the base of B-spline polynomials of the third order with C2 continuity spread over three elements [0,0.1] and [0.1,0.9] and [0.9 1]. Please run MATLAB code and draw base functions.
Solution:
[0 0 0 0 0.1 0.9 1 1 1 1]
EXERCISE
Exercise 4: 3rd order B-splines with C1 contiunuity Exercise content:
Please generate a vector of nodes that generates a base of B-spline polynomials of the third order with continuity C1 spread over four elements [0,1] and [1,2] and [2,3] and [3,4]. Please run MATLAB code and draw base functions.
Solution:
[0 0 0 0 1 1 2 2 3 3 4 4 4 4]
EXERCISE
Exercise 5: Two-dimensional B-splines Exercise content:
Please modify the code so that it draws two-dimensional B-splines on the area resulting from the tensor product of two node vectors. Please use MATLAB’s meshgrid or surf function. Run the MATLAB code for the node vectors [0 0 0 0 1 2 3 4 4 4 4 x 0 0 1 2 3 4 4] and draw the base functions.
Open AGH e-podręczniki - content available under the CC BY-SA license
52
2.8. MATLAB implementation of the generation of basis functions based on the knot vector Solution:
function spline2D() knot_vectorx=[0 0 0 0 1 2 3 4 4 4 4] knot_vectory=[0 0 1 2 3 4 4] precision = 0.01 %macroscompute_nr_basis_functions = @(knot_vector,p) size(knot_vector, 2) - p - 1 mesh = @(a,c) a:precision*(c-a):c %splines in x px = compute_p(knot_vectorx) tx = check_sanity(knot_vectorx,px) nrx = compute_nr_basis_functions(knot_vectorx,px) x_begin = knot_vectorx(1) x_end = knot_vectorx(nrx+px) x=mesh(x_begin,x_end); %splines in y py = compute_p(knot_vectory) ty = check_sanity(knot_vectory,py) nry = compute_nr_basis_functions(knot_vectory,py) y_begin = knot_vectory(1)y_end = knot_vectory(nry+py) y=mesh(y_begin,y_end); %X and Y coordinates of points over the 2D mesh X,Y=meshgrid(x,y); hold onfor i=1:nrx %compute values of vx=compute_spline(knot_vectorx,px,i,X); for j=1:nry vy=compute_spline(knot_vectory,py,j,Y); surf(X,Y,vx.*vy); endfor endfor hold off
Open AGH e-podręczniki - content available under the CC BY-SA license
53
2.8. MATLAB implementation of the generation of basis functions based on the knot vector
Open AGH e-podręczniki - content available under the CC BY-SA license
54
Chapter 3
3. Weak formulations for different problems and methods 3.1.
Heat transfer with isogeometric finite element method
In the previous chapter, we introduced the formulation of the finite element method based on the example of bitmap approximation using the B-spline function. As a result, our equation looked like a strong formulation as follows:u(x, y) ≈ BIT M AP (x, y) where u(x, y) denotes the approximation of a bitmap using a linear combination of the B-spline function P u(x, y) = i=1,...,Nx ;j=1,...,Ny ui,j Bix (x)Bjy (y) and BIT M AP (x, y) meant a bitmap. Then, we showed that our strong formulation can be converted into a form called a weak formulation or a variational formulation using the averaging mechanism: R R u(x, y)v(x, y)dxdy = Ω BIT M AP (x, y)v(x, y)dxdy Ω In the weak formulation, our strong formulation is averaged over selected fragments of the bitmap area. For this purpose, we multiply the strong formulation by the so-called testing functions, which determine the method of calculating the mean (for example, if we use the B-spline function for this purpose, we will get distributions similar in shape to Gaussian distributions, i.e. the values from the middle of the area will have the greatest importance, and areas more and more distant from the midpoint will have less and less influence down to zero) and integrate the entire equation (remember that the integral intuitively represents sampling at individual points, taking into account the value and area of the sampled area, and summing the result). In this module, we will present other examples of applications of the finite element method in which, instead of bitmap projection, we will calculate solutions of various partial differential equations that approximate various physical phenomena. In the same way as we transformed our strong formulation of the bitmap projection problem into a weak formulation by integrating and multiplying by averaging functions, we will also do with various differential equations. One of the most common equations that start your adventure with the finite element method is the heat transport equation. Our unknown function u here is a function that assigns a temperature value to various points in the area in which we are solving our problem. In other words, u(x, y) represents the temperature value at point (x, y) of the domain Ω. The temperature distribution function sought is defined as follows:Ω 3 (x, y) → u(x, y) ∈ R.
55
3.1. Heat transfer with isogeometric finite element method The strong wording for the heat transport problem is as follows −∆u = f In this equation −∆u stands for the so-called Laplasjan, i.e. the sum of the second-degree partial derivatives, and to simplify the notation, we omitted the variables (x, y). ∆u(x, y) =
∂ 2 u(x,y) ∂x2
+
∂ 2 u(x,y) ∂y 2
while f (x, y) means the function representing the heat source. In those parts of the domain where the function f (x, y) is positive, there is ”heating”, while in those parts of the domain where the function f (x, y) is negative, there is ”cooling”. The weak wording is obtained as follows. We integrate and multiply our equation by selected functions v(x, y) called test functions which we will use to average our equation in the area where these functions are defined. Z −
Z ∆u(x, y)v(x, y)dxdy =
Ω
f (x, y)v(x, y)dxdy
(3.1)
Ω
In a similar way to the bitmap projection problem, any choice of test function v(x, y) for averaging our problem in the area where the test function is defined gives us one equation. Various test function selections v(x, y) gives different equations (??.1). R If we write our formula for partial derivatives, we get two separate integrals Ω ∆u(x, y)v(x, y)dxdy = R 2 ∂ 2 u(x,y) + ∂ u(x,y) v(x, y)dxdy ∂x2 ∂y 2 Ω The problem that we want to solve looks like this: We are looking for the temperature distribution, a function Ω 3 (x, y) ← u(x, y) ∈ R such that R ∂ 2 u(x,y) R 2 R v(x, y)dxdy + Ω ∂ u(x,y) v(x, y)dxdy = Ω f (x, y)v(x, y)dxdy ∂x2 ∂y 2 Ω for any test functions Ω 3 (x, y) → v(x, y) ∈ R(of course our temperature distribution and the testing function must be such that it is possible to calculate the integrals, as we know, not all functions can be used to calculate integrals, some functions give integrals that can be infinite), a(u, v) = l(v) R 2 R a(u, v) = Ω ∂ u(x,y) v(x, y)dxdy + Ω ∂x2 R l(v) = Ω f (x, y)v(x, y)dxdy
∂ 2 u(x,y) v(x, y)dxdy ∂y 2
Now note that if we were to now apply our B-spline functions introduced in the previous section to the PNx ,Ny temperature field approximation, u(x, y) = i=1,j=1 ui,j Bix (x)Bjy (y) then we would have to be able to compute the second order derivatives of the B spline function. In order for the second-degree derivatives to be computable, the basis functions used to approximate the temperature field must be smooth. B-splines are great for calculating derivatives of these. However, in order for these derivatives not to be zero (so that our system of equations, which is built similarly to bitmap approximation, does not end up equal to zero), the B-splines used here must be higher-order functions (at least of the class C 2 , i.e. they must be at least 3rd degree B-splines). If we wish to use higher order polynomials, we can now insert the integrals of our equation into the problem matrix, i.e. replace the bitmap projection problem matrix with our matrix. Now, in place of functions u we insert an approximation using the B-spline function PNx ,Ny x y u = i=1,j=1 ui,j Bi Bj , and in place of the test functions we also put B-spline function y Bkx Bl , k = 1, ..., Nx ; j = 1, ..., Ny . Similarly to the bitmap projection, we get a system of equations
Open AGH e-podręczniki - content available under the CC BY-SA license
56
3.1. Heat transfer with isogeometric finite element method y y y y x x x x a(B1,p B1,p , B1,p B1,p ) a(B1,p B1,p , B2,p B1,p ) ··· y y y y x x x x a(B B , B B ) a(B B B B ) ··· 2,p 1,p 1,p 1,p 2,p 1,p 2,p 1,p . . .. .. .. . y y y y x x x x a(BNx ,p BNy ,p , B1,p B1,p ) a(BNx ,p BNy ,p , B2,p B1,p ) · · · l(B1x (x) ∗ B1y (y)) y l(B1x (x) ∗ B2 (y)) = .. . y x l(BNx (x) ∗ BNy (y))
y y x x a(B1,p B1,p , BN BN ) x ,p y ,p y y x x a(B2,p B1,p , BN BN ) x ,p y ,p .. . y y x x a(BNx ,p BNy ,p , BNx ,p BNy ,p )
u1,1 u2,1 .. .
uNx ,Ny
where after taking into account the formulas on a i l we have
R R y y y y x x x x ∆(B1,p B1,p )B1,p B1,p ∆(B1,p B1,p )B2,p B1,p R R y y y y x x x x ∆(B2,p B1,p )B1,p B1,p ∆(B2,p B1,p )B2,p B1,p .. .. . . R R y y y y x x x x ∆(BN B )B B ∆(B B 1,p 1,p Nx ,p Ny ,p )B2,p B1,p Ny ,p x ,p R f (x, y)B1x (x)B1y (y) dx R y f (x, y)B1x (x)B2 (y) dx = .. . R y x f (x, y)BNx (x)BNy (y) dx
··· ··· .. . ···
R y y x x ∆(B1,p B1,p )BN BN u1,1 x ,p y ,p R y y x x ∆(B2,p B1,p )BN BN u2,1 x ,p y ,p .. .. . . R y y x x uNx ,Ny ∆(BN B )B B Nx ,p Ny ,p Ny ,p x ,p
(3.2) Of course, we must remember that R R 2 ∆u(x, y)v(x, y)dxdy = Ω ∂ u(x,y) + ∂x2 Ω
∂ 2 u(x,y) ∂y 2
v(x, y)dxdy
Now, if we generated the appropriate integrals and run one of the matrix factorization algorithms described in Chapter 5, it would turn out that the matrix is singular and the system of equations cannot be solved! Why would that happen? Because when we solve the heat transport problem and define the equation satisfied in the area Ω we need to specify the so-called boundary conditions, i.e. describe how the temperature behaves on the boundary of the area. Whenever we want to formulate our engineering problem with partial differential equations, for example the problem of heat transport, over some area Ω, we must first of all give the partial differential equation that describes the modeled phenomenon inside the region Ω Additionally, we must describe the so-called boundary conditions, i.e. provide some additional equations that describe the behavior of our phenomenon at the boundary of the area. Let us imagine that we want to estimate the temperature inside the room. Of course, we need to specify what partial differential equation describes the physical phenomenon of heat flow inside the room. This is of course the already known equation (strong formulation) with Laplasian ∆u(x, y) = f (x, y). If we give the equation itself only for the center of the room, but we do not take into account what is happening on the walls of the room, we have potentially an infinite number of possible solutions. So, our system of equations cannot be solved without specifying what is happening on the boundary. The correct definition of the boundary conditions usually gives us one possible solution. Our area Ω can represent the room interior. For the sake of simplicity, let’s assume that we are working in two dimensions (that our room is flat and two-dimensional). Let us assume that this room is L-shaped and its inner walls are adjacent to a radiator on the boundary of which the temperature is zero, and the remaining walls have windows through which external heat reaches us. Then the temperature on the inner walls of the room will be zero. We introduce the so-called Dirichlet boundary condition on the part of the boundary of the area (on the internal walls on which we measured the temperature). For these walls Open AGH e-podręczniki - content available under the CC BY-SA license
57
3.1. Heat transfer with isogeometric finite element method (part of the boundary ∂Ω) we denote symbols ΓD and we give the temperature values on this part of the boundary (on the walls of the area) u(x, y) = T (x, y) dla (x, y) ∈ ΓD where T (x, y) this is the temperature measured with a thermometer or a thermal imager. This situation is illustrated in Pic. 19.
Figure 19: The L-shaped area on which we calculate the temperature distribution. The ”inner” boundary of the area where the temperature is u = 0 is called the Dirichlet boundary, and the ”outer” boundary of the area where the heat flow velocity du / dn = g is called the Neumann boundary.
There may also be windows on a certain part of the boundary of the room, and outside the windows it can be hot (if it is summer) or cold (if it is winter) and the temperature around the glass can rise (in summer) or decrease (in winter) at any time. Then, by using a thermometer and a watch (or a ‘magic’ thermal imaging camera), we can measure the speed with which the temperature changes next to the glass. In this case, we introduce the so-called Neumann boundary condition on the part of the boundary of the area (on the windows where we measured the speed of temperature changes). This part of the boundary (i.e., the window) is marked with the symbol ΓN and we determine the speed of temperature changes ∂u(x,y) ∂n
= g(x, y) dla (x, y) ∈ ΓN
where g(x, y) is the heat flux on the boundary of the area. ∂u What does it mean here ∂n ? This indicates the speed of temperature change towards the boundary. From ∂u ∂u a mathematical point of view ∂n = ∂u ∂x n1 + ∂y n2 where n = (n1 , n2 ) is the vector perpendicular to the boundary of the area Ω, directed outwards, i.e. if the boundary is a wall perpendicular to the axis x to n = (1, 0), if the boundary is the bottom edge of the room, is n = (0, −1) itd. Sample vectors n = (n1 , n2 ) shown in Pic. 19.
How would we modify our equation system to include zero temperature on part of the boundary ΓD and the speed of heat flow through the part of boundary ΓN . For this purpose, we need to specify what our element group and our B-spline basis functions will look like spanned over the elements, giving a vector of nodes along the axis x and the knot vector along y. TThe simplest solution is to divide our area into four square sub-areas (four groups of elements) and glue them together (repeating the nodes on the glue interface so that the basis functions at this point have C0 continuity). Here we refer to the third chapter, which describes the way of defining basis functions with the help of node vectors and B-spline polynomials. Along the axis x we introduce a vector of nodes 0 0 0 1 2 2 3 4 4 4, similarly along the y axis we introduce a vector of nodes 0 0 0 1 2 2 3 4 4 4. We repeat the middle node to reduce the continuity of the B-spline in the middle of the area. This will
Open AGH e-podręczniki - content available under the CC BY-SA license
58
3.1. Heat transfer with isogeometric finite element method allow us to correctly enforce the Dirichlet boundary condition on one area quadrant. Note that the B-spline functions are smooth and span many elements, so it is impossible to force the values of the B-spline function at some point without reducing continuity (without repeating nodes in node vectors). The resulting basis functions are shown in Pic. 20. We obtained two bases of one-dimensional B-spline functions {Bi,2 (x)}i=1,...,5 and {Bj,2 (y)}j=1,...,5 . Then we will create tensor products from them Bi,j;2 (x, y) = Bi,2 (x)Bj,2 (y), i, j = 1, ..., 5.
Figure 20: Knot vectors [[0 0 1 2 2 3 4 4] along the x and y axes and the resulting B-spline base functions and their tensor product.
Note that our area Ω is stretched over a square [−1, 1]2 . But our 5 * 5 = 25 basis functions are spread over a square [0, 2]2 resulting from the definition of the node vector 0 0 1 2 2 3 4 4. So we need to ”remap” our physical area [−1, 1]2 to a group of elements on which our functions are defined B-spline [−1, 1]2 3 (x, y) → ψ(x, y) = (2(x + 1), 2(y + 1)) We extend our functions to the area [−1, 1]2 assuming that outside our region they are equal to zero, and we change the variables in the block integral [−1, 1]2 per block [0, 4]2 R 2 Then we remap all the integrals to our area where we span the integrals a(u, v) = Ω ∂ u(x,y) v(x, y)dxdy + ∂x2 R ∂ 2 u(x,y) R R ∂ 2 u(x,y) ∂ 2 u(x,y) v(x, y)dxdy = [−1,1]2 ∂x2 v(x, y)dxdy + [−1,1]2 ∂y2 v(x, y)dxdy = ∂y 2 Ω R R 2 ∂ 2 u(x,y) v(x, y)|Jac(ψ −1 )|dxdy + [0,4]2 ∂ u(x,y) v(x, y)|Jac(ψ −1 )|dxdy ∂y 2 [0,4]2 R ∂x2 l(v) = Ω f (x, y)v(x, y)dxdy = R R = [−1,1]2 f (x, y)v(x, y)dxdy = [0,4]2 f (x, y)v(x, y)|Jac(ψ −1 )|dxdy In the above formulas for the integrals, we put the absolute value of the Jacobian transformation of the change of variables from our area Ω=−1,12 on the area Ω = [−1, 1]2 on the area [0, 4]2 on which we unbuttoned the knot vectors. It is calculated like this. We know the mapping ψ : Ω → [0, 4]2 dane ψ(x, y) = (2(x + 1), 2(y + 1)). This means that new variables in the area [0, 4]2 (which we will mark for a moment (ξ, η) data are formulas (ξ, η) = (2(x + 1), 2(y + 1)). If I would like to calculate the variables (x, y) in the area [−1, 1]2 I just have to convert it 2(x + 1) = ξ so x = ξ/2 − 1, and 2(y + 1) = η, so y = η/2 − 1. So ψ −1 (ξ, η) = (ξ/2 − 1, η/2 − 1). For convenience, let’s change the variables back to symbols (x, y) czyli ψ −1 (ξ, η) = (x/2−1, y/2−1). Now, we need to count the partial derivatives ∂(x/2−1) = 1/2, ∂(x/2−1) = 0, ∂x ∂y
Open AGH e-podręczniki - content available under the CC BY-SA license
59
3.1. Heat transfer with isogeometric finite element method ∂(y/2−1) ∂x
and
= 0,
∂(y/2−1) ∂y
= 1/2. Our Jacobian integral is the determinant of the matrix of partial derivatives " # 1/2 0 −1 jac(ψ ) = | | = |1/2 ∗ 1/2| = |1/4| = 1/4 0 1/2 that is, our system of equations R R 2 a(u, v) = [0,4]2 ∂ u(x,y) v(x, y)1/4dxdy + [0,4]2 ∂x2 R l(v) = [0,4]2 f (x, y)v(x, y)1/4dxdy
∂ 2 u(x,y) v(x, y)1/4dxdy ∂y 2
Now, for the B-spline functions spanning on the edge of the Dirichlet area, we can force the Dirichlet condition in such a way that we zero the appropriate lines and right sides of the system of equations, and enter 1s on the diagonal. In other words, for the relevant lines corresponding to the B-splines i, j which are on the Dirichlet boundary R R R y y y y y y x x x x x x ∆(Bi,p Bj,p )B1,p B1,p u1,1 + · · · + ∆(Bi,p Bj,p )B2,p B1,p ui,j + · · · + ∆(Bi,p Bj,p )BN BN u = x ,p y ,p Nx ,Ny R y x = f (x, y)Bi,p Bj,p dxdy we replace them with 1 ∗ ui,j = 0 But how to express the Neuman condition? Unfortunately, this is not easily done without integration by parts. So we have to apply the formula for integration by parts. Since our problem is two-dimensional, the formula is relatively complicated. We will not introduce it here because it would require taking a course in R R R ∂u mathematical analysis. Ω ∆u(x, y)v(x, y)dxdy = − Ω ∇u(x, y) · ∇v(x, y)dxdy + ∂Ω ∂n vdS ∂u where ∇u(x, y) = ( ∂u ∂x , ∂y ) denotes gradient u that is a vector of partial derivatives of u, similarly ∂v ∂v ∇v(x, y) = ( ∂x , ∂y )
stands for gradient v that is, a vector of partial derivatives of a function v, while · denotes the dot product of their vectors, i.e. ∂u ∂v ∂v ( ∂u ∂x , ∂y ) · ( ∂x , ∂y ) =
∂u ∂v ∂x ∂x
So our entire equation −
R Ω
+
∂u ∂v ∂y ∂y .
∂ 2 u(x,y) v(x, y)dxdy ∂x2
after integration by parts it turns into
R ∂u ∂v Ω
∂x ∂x
− +
R Ω
∂ 2 u(x,y) v(x, y)dxdy ∂y 2
∂u ∂v ∂y ∂y
dxdy =
=
R
∂u vdS ∂Ω ∂n
R
Ω
f (x, y)v(x, y)dxdy
+
R Ω
f (x, y)v(x, y)dxdy
∂u What does it mean here ∂n ? It indicates the speed of temperature change towards the boundary. From a ∂u ∂u mathematical point of view ∂n = ∂u ∂x n1 + ∂y n2 where n = (n1 , n2 ) is the vector perpendicular to the edge of the area Ω, that is, for example, if the edge is a vertical face perpendicular to the axis x to n = (1, 0), if the edge is the floor of a room n = (0, −1) etc.
The field in which we solve ours problem Ω = [−1, 1] × [−1, 1] [−1, 0] × [−1, 0] has the shape of an inverted letter L. On the inner part of the edge of the area we mark ΓD = {(x, y) : x = 0, y ∈ [−1, 0] or x ∈ [−1, 0], y = 0} we assume the zero temperature expressed by the Dirichlet boundary condition u(x, y) = 0 dla (x, y) ∈ ΓD On the rest of the edge of the area we mark ΓN = Γ ΓD we introduce the so-called Neumann boundary condition. This part of the edge (i.e. the window) is marked with the symbol ΓN and we determine the speed of temperature changes ∂u(x,y) ∂n
= g(x, y) dla (x, y) ∈ ΓN
Open AGH e-podręczniki - content available under the CC BY-SA license
60
3.1. Heat transfer with isogeometric finite element method where g(x, y) is the set speed of temperature changes on the shore. In conclusion, the edge of our area ∂Ω was dicided into two fragments ∂Ω = ΩD ∪ ΩN and on the first we measured the temperature, on the second we measured the speed of temperature changes. So, we can break a fragment of our weak formulation with the edge integral into these three fragments of the border R ∂u(x,y) R ∂u(x,y) ∂n vdS = ∂ΩD ∂n v(x, y)dS+ ∂Ω R ∂u(x,y) ∂n v(x, y)dS ∂ΩN What to do next with these three integrals spanning over three parts of the border? The integral with the Neumann boundary condition is simple, because our Neumann boundary condition implies that R ∂u(x,y) = g(x, y), where g(x, y) is a given rate of temperature change, i.e. ∂ΩN ∂u(x,y) ∂n v(x, y)dS = R ∂n g(x, y)v(x, y)dS. Why do we have to convert the derivative in the normal direction into a given ∂ΩN function in this integral g? Since we want to set this boundary condition, we want to model in our simulation a situation where the heat really affects the interior of our room through the window. As for the Dirichlet boundary condition, it requires some additional treatment. If T (x, y) = 0 in the Dirichlet condition, i.e. u(x, y) = 0 dla (x, y) ∈ ΓD then the matter is simple. We know that the temperature is zero on this edge, so we do not have to calculate the average values at this point of the edge, we do not have to choose such testing functions v(x, y) which are not zero on the Dirichlet edge. In other words, I can assume that the testing functions v(x, y) = 0 dla (x, y) ∈ ΓD . In other words, then the integral R ∂u(x,y) ∂n v(x, y)dS = 0. ∂ΩD Our right side R R l(v) = ∂ΩD ∂u(x,y) v(x, y)dS + ∂ΩN ∂u(x,y) ∂n ∂n v(x, y)dS R R R + Ω f (x, y)v(x, y)dxdy = ∂ΩN g(x, y)v(x, y)dS + Ω f (x, y)v(x, y)dxdy So our problem looks like this a(u, v) = l(v) R ∂v ∂u ∂v a(u, v) = Ω ∂u + ∂x ∂x ∂y ∂y v(x, y)dxdy R R l(v) = ∂ΩN g(x, y)v(x, y)dS + Ω f (x, y)v(x, y)dxdy Note that since we have integrated by parts, then we can allow ourselves to reduce the degree of the B-spline function (now, our formula contains only first-order flares, and we are satisfied with the class functions C 1 ). Moreover, the higher the degree of B-splines, the more expensive it is to process. Simply generating the formula for a higher order B spline requires more operations, as does calculating the value of such a B spline. Bear in mind that the system of equations generated for higher order B-splines will be denser, will have fewer zeros, and therefore the factorization cost (the cost of solving such a system of equations) will be higher. The solution obtained with isogeometric finite element method is presented in Pic. 21.
Open AGH e-podręczniki - content available under the CC BY-SA license
61
3.2. Heat transfer with classical finite element method
Figure 21: Solution (temperature scalar field) on a dense grid.
3.2.
Heat transfer with classical finite element method
In this module I will give an example of the application of the traditional finite element method working on irregular meshes to solve the problem of heat transport in the L-shaped region, described in the module ”Heat transport by the isogeometric finite element method”. The main difference is the use of triangular elements and Lagrange polynomials spanning over triangular elements. From the point of view of factorization of systems of equations, the traditional finite element method generates a system of equations that has more unknowns than the isogeometric method. Moreover, at the finite element boundary, only Lagrange polynomials are used in the traditional finite element method C 0 , which means that when we calculate the derivatives of the solution, the derivatives will be discontinuous at the edges of the elements. The isogeometric method gives more smooth solutions, for which systems of equations have fewer unknowns, and generally the cost of factorization is lower, especially when we use the so-called ”refined isogeometric analysis” and split B-spline polynomials into groups of elements (in English such a group of elements is called an ”isogeometric patch”), while on the border of groups of elements we place C 0 separators. The strong and weak formulations for our L-shaped heat transport problem solved by the classical finite element method are the same as for the isogeometric method.a(u, v) = l(v) R ∂u ∂v ∂v a(u, v) = Ω ∂x ∂x + ∂u ∂y ∂y v(x, y)dxdy R R l(v) = ∂ΩN g(x, y)v(x, y)dS + Ω f (x, y)v(x, y)dxdy In our example problem of heat flow in an L-shaped area, we assume f (x, y) = 0(i.e. no heat sources). On the ”outer” part of the shore which we call the Neumann boundary ΓN = {(x, y) : x = −1 ∪ x = 1 ∪ y = 1 ∪ y = −1} we assume a known speed of temperature change. ∂u(x,y) ∂n
= g(x, y) dla (x, y)inΓN
In order to define the Neumann boundary condition, we introduce a polar coordinate system centered at (0,0) and the abscissa lying on the OX axis of the Cartesian coordinate system. In our example of heat flow in an L-shaped area, we assume the exemplary heat flow velocity function defined in the polar coordinate system
Open AGH e-podręczniki - content available under the CC BY-SA license
62
3.2. Heat transfer with classical finite element method R × (0, 2π) 3 (r, θ) → g(r, θ) = r2/3 sin2/3 (θ + π/2) where r = (x2 +y 2 )0.5 is the distance from the origin of the coordinate system, θ = atan2(y, x) is the angle between the point (x, y) and the axis x. So g(r, θ) = r2/3 sin2/3 (θ + π/2) = (x2 + y 2 )1/3 sin2/3 (atan2(y, x) + π/2) = g(x, y). On the ”inner” part of the shore which we call the Dirichlet shore ΓD = ∂Ω ΓN we assume a temperature value of zero u(x, y) = 0 dla (x, y)inΓD An example of a mesh made of triangular elements and the first degree Lagrange polynomials stretched over it is shown in Pic. 22-Pic. 23.
Figure 22: Base functions e2 and e5 aggregated on triangular elements.
Figure 23: Base functions e1, e3, e4 aggregated on triangular elements.
Let us assume that we use the first-degree Lagrange polynomials to approximate the solution. In the case of using linear basis functions, they are related to the vertices of triangular elements (in the sense that their maxima are above the vertices and are defined on the adjacent triangular elements). Open AGH e-podręczniki - content available under the CC BY-SA license
63
3.2. Heat transfer with classical finite element method If, on the other hand, one were to apply higher degree Lagrange polynomials, they would also be associated with the edges and interiors of the elements. Details are provided in the modules on how to define the basis functions. In the classical finite element method, our mesh and the resulting matrix of a system of linear equations do not have a regular shape, as is the case with a group of elements in the isogeometric finite element method. Therefore, a global numbering of basis functions related to the vertices of triangular elements should be generated. Each triangular element in turn has its own local vertex numbering. It is necessary to develop a map from global numbering to local numbering of each triangular element. It is drawn in Pic. 24.
3
3
Figure 24: Map between the global numbering of functions related to the vertices of triangles and the local numbering in individual triangles.
ˆ : (0, 1) − (0, 0) − (1, 0) we introduce three local base functions Then over the reference triangular element E ψˆ1 (ξ, η) = (1 − ξ)η ψˆ2 (ξ, η) = (1 − ξ)(1 − η) ψˆ3 (ξ, η) = ξ(1 − η) These functions are mapped to basis functions spanning over individual elements. For this purpose, we define maps that map the model element to individual elements ˆ E ˆ E ˆ E ˆ E ˆ E ˆ E
3 (ξ, η) → xE1 (ξ, η) = (ξ − 1, η) = (x, y) ∈ E1 3 (ξ, η) → xE2 (ξ, η) = (−ξ, −η + 1) = (x, y) ∈ E2 3 (ξ, η) → xE3 (ξ, η) = (ξ, η) = (x, y) 3 E3 ∈ (ξ, η) → xE4 (ξ, η) = (ξ + 1, η + 1) = (x, y) ∈ E4 3 (ξ, η) → xE5 (ξ, η) = (ξ, η − 1) = (x, y) ∈ E5 3 (ξ, η) → xE6 (ξ, η) = (1 − ξ, −η) = (x, y) ∈ E6
Then we calculate the inverse maps E1 E2 E3 E4 E5 E6
ˆ 3 (x, y) → x−1 E1 (x, y) = (x + 1, y) = (ξ, η) ∈ E −1 ˆ 3 (x, y) → xE2 (x, y) = (−x, −y + 1) = (ξ, η) ∈ E −1 ˆ 3 (x, y) → xE3 (x, y) = (x, y) = (ξ, η) ∈ E −1 ˆ 3 (x, y) → xE4 (x, y) = (x − 1, y − 1) = (ξ, η) ∈ E ˆ 3 (x, y) → x−1 E5 (x, y) = (x, y + 1) = (ξ, η) ∈ E −1 ˆ 3 (x, y) → x (x, y) = (−x + 1, −y) = (ξ, η) ∈ E E6
Having mapping formulas between the template element and individual elements, we can define basis
Open AGH e-podręczniki - content available under the CC BY-SA license
64
3.2. Heat transfer with classical finite element method functions on the first element ˆ1 ψ 1 (x, y) = ψˆ1 x−1 E1 (x, y) = ψ (x + 1, y) = (1 − (x + 1))y = −xy −1 2 2 ψ (x, y) = ψˆ xE1 (x, y) = ψˆ2 (x + 1, y) = (1 − (x + 1))(1 − y) = x(y − 1) ˆ3 ψ 3 (x, y) = ψˆ3 x−1 E1 (x, y) = ψ (x + 1, y) = (x + 1)(1 − y) (note that the first local function takes the value 1 at point (-1.1), the second local function takes the value 1 at point (-1.0), and the third local function takes the value 1 at point (0.0)), on the second element ˆ1 ψ 1 (x, y) = ψˆ1 x−1 E2 (x, y) = ψ (−x, −y + 1) = (1 + x)(−y + 1) = (1 + x)(1 − y) ˆ2 ψ 2 (x, y) = ψˆ2 x−1 E2 (x, y) = ψ (−x, −y + 1) = (1 + x)(1 − (−y + 1)) = (1 + x)y −1 ψ 3 (x, y) = ψˆ3 xE2 (x, y) = ψˆ3 (−x, −y + 1) = −x(1 − (−y + 1)) = −xy (note that the first local function is 1 at (0,0), the second local function is 1 at (0,1), and the third local function is 1 at (-1,1)), on the third element ˆ1 ψ 1 (x, y) = ψˆ1 x−1 E3 (x, y) = ψ (x, y) = (1 − x)y ˆ2 ψ 2 (x, y) = ψˆ2 x−1 E3 (x, y) = ψ (x, y) = (1 − x)(1 − y) −1 3 3 ψ (x, y) = ψˆ xE3 (x, y) = ψˆ3 (x, y) = x(1 − y) (note that the first local function is 1 at (0,1), the second local function is 1 at (0,0), and the third local function is 1 at (1,0)), on the fourth element ˆ1 ψ 1 (x, y) = ψˆ1 x−1 E4 (x, y) = ψ (x − 1, y − 1) = (1 − (x − 1))(y − 1) = x(1 − y) ˆ2 ψ 2 (x, y) = ψˆ2 x−1 E4 (x, y) = ψ (x − 1, y − 1) = (1 − (x − 1))(1 − (y − 1)) = xy −1 3 3 ψ (x, y) = ψˆ xE4 (x, y) = ψˆ3 (x − 1, y − 1) = (x − 1)(1 − (y − 1)) = (1 − x)y (note that the first local function takes the value 1 at point (1.0), the second local function takes the value 1 at point (1.1), and the third local function takes the value 1 at point (0.1)), on the fifth element ˆ1 ψ 1 (x, y) = ψˆ1 x−1 E5 (x, y) = ψ (x, y + 1) = (1 − x)(y + 1) ˆ2 ψ 2 (x, y) = ψˆ2 x−1 E5 (x, y) = ψ (x, y + 1) = (1 − x)(1 − (y + 1)) = (x − 1)y −1 3 3 ψ (x, y) = ψˆ xE5 (x, y) = ψˆ3 (x, y + 1)) = x(1 − (y + 1)) = −xy (note that the first local function is 1 at (0,0), the second local function is 1 at (0, -1), and the third local function is 1 at (1, -1)), and on the sixth element ˆ1 ψ 1 (x, y) = ψˆ1 x−1 E6 (x, y) = ψ (−x + 1, −y) = (1 − (−x + 1))(−y) = −xy ˆ2 ψ 2 (x, y) = ψˆ2 x−1 E6 (x, y) = ψ (−x + 1, −y) = (1 − (−x + 1))(1 − (−y)) = x(1 − y) −1 3 3 ψ (x, y) = ψˆ xE6 (x, y) = ψˆ3 (−x + 1, −y)) = (1 − x)(1 + y) (Note that the first local function is 1 at (1, -1), the second local function is 1 at (1,0), and the third local function is 1 at (0,0)). Functions on local elements are aggregated into global base functions e1 , e2 , e3 , e6 , e8 according to the mapping shown in Pic. 24. In other words e1 e2 e3 e6 e8
3 2 = ψE1 + ψE2 2 3 2 = ψE2 + ψE3 + ψE4 1 = ψE4 2 3 1 = ψE3 + ψE4 + ψE6 2 3 = ψE5 + ψE6
We approximate our solution (temperature distribution) by a combination of aggregated Lagrange polynomials Open AGH e-podręczniki - content available under the CC BY-SA license
65
3.2. Heat transfer with classical finite element method u(x, y) =
P
i=1,...,8
ui ei (x, y).
Because of the use of the zero Dirichlet condition on the ”inner” edge, we can immediately assume that the Lagrange polynomial coefficients related to the inner edge are equal to zero, i.e. u4 = u5 = u7 = 0, so we didn’t even derive the formulas for base functions e4 (x, y), e5 (x, y), e7 (x, y), because they are reset by a zero Dirichlet condition (forced by zeroing the coefficients). Generation of irregular global numbering of basis functions and irregular mapping of local element functions to global functions is a typical feature of the application of the finite element method on irregular meshes, for example with the use of Lagrange polynomials. In general, we also need to generate the global numbering and local numbering of the vertices of the triangular elements, and generate the formulas for the basis functions on all triangular elements The finite element method algorithm can be described as follows
EXAMPLE
Example 2: Algorithm 1 1 B(1 : 8, 1 : 8) = 0(creation of the matrix) 2 L(1 : 8) = 0(creation of the right hand side) 3 Loop with respect to triangular elements E ∈ {E1 , E2 , E3 , E4 , E6 } 4 First loop with respect to local functions ψki ∈ {ψk1 , ψk2 , ψk3 } of element Ek ) 5 i1 = row of the matrix related with ψki 6 L(i1)+ = l(ψki )|Ek 7 Second loop with respect to local functions ψkj ∈ {ψk1 , ψk2 , ψk3 } of element Ek ) 8 j1 = column of the matrix related with ψkj 9 B(i1, j1)+ = a(ψki , ψkj )|Ek 10 B(4, 1 : 8) = 0(enforcing Dirichlet b.c. at node 4) 11 B(5, 1 : 8) = 0(enforcing Dirichlet b.c. at node 5) 12 B(7, 1 : 8) = 0(enforcing Dirichlet b.c. at node 7) 13 L(4) = 0(enforcing Dirichlet b.c. at node 4) 14 L(5) = 0(enforcing Dirichlet b.c. at node 5) 15 L(7) = 0(enforcing Dirichlet b.c. at node 7) 16 B(4, 4) = 1(1 on diagonal at row 4) 17 B(5, 5) = 1(1 on diagonal at row 5) 18 B(7, 7) = 1(1 on diagonal at row 7) Please note that in the algorithm we calculate the integrals over individual elements of the left and right R functional. In other words, on line 6 we count L(i1)+ = l(ψki )|Ek = ∂ΩN ∩Ek g(x, y)v(x, y)dS that is, the integral over the element Ek z funkcji g(x, y)v(x, y) specified at the edge of the element Ek crossing the Neumann shore. So we need to check the 3 edges of the element Ek and check if any of these Open AGH e-podręczniki - content available under the CC BY-SA license
66
3.3. Advection-diffusion equations edges is not on the shore of Neumann, i.e. ∂Ek ∩ΓN 6= ∅ where ΓN = {(x, y) : x = −1∪x = 1∪y = 1∪y = −1}. If a fragment of the edge of an element lies on the Neumann boundary, compute the integral using a one-dimensional Gaussian quadrature on that boundary, as described in the module ”Variational formulation and numerical integration”. Moreover, in line 9 we need to calculate the integral over the element from the left-hand form B(i1, j1)+ = a(ψki ,ψkj )|Ek = R ∂u ∂v ∂v + ∂u ∂y ∂y v(x, y)dxdy Ek ∂x ∂x This integral should be calculated using 2D Gaussian quadratures on a triangular element Ek . After generating the system of equations and applying the exact solver, we get the solution shown in Pic. 25.
Figure 25: Solution (temperature scalar field) on a sparse mesh.
3.3.
Advection-diffusion equations
Now let us look at another class of computational problems, the so-called advection-diffusion problem. In this problem, the differential equation in the so-called strong form is given by a formula 2 ∂u ∂ u ∂2u βx ∂u = f (x, y) ∂x + βy ∂y − ∂x2 + ∂y 2 We are looking for a field of concentration, e.g. pollution Ω ∈ (x, y) → u(x, y) ∈ R in the area Ω. Value u(x, y) is the concentration of pollutants in a point (x, y). ∂u The term βx (x, y) ∂u ∂x + βy (x, y) ∂y here means the advection, that is, the dispersion of pollutants by the wind.
The terms (βx (x, y), βy (x, y)) denote the components of the wind speed field, i.e. at a point (x, y) the wind blows in a direction parallel to the axis x with the speed βx (x, y) in a direction parallel to the axis y with the speed βy (x, y). 2 2 On the other hand, the term ∂∂xu2 + ∂∂yu2 stands for diffusion, i.e. the distribution of pollutants by diffusion. If I am sitting in a room with a smoker, even if there is no airflow, the smoke of the cigarette will reach my nose by a diffusion mechanism. The rate of this diffusion is responsible for the coefficient . If, additionally, the windows and doors were open in the room, cigarette smoke would also be pushed by wind blowing at a Open AGH e-podręczniki - content available under the CC BY-SA license
67
3.3. Advection-diffusion equations speed of e.g. (1, 0)(if the window-door is in a plane parallel to the axis x and the airflow moves with speed 1 m/s). On the right-hand side, the function f (x, y) stands for the source of contamination, that is, if in point (x, y) there is a chimney that emits pollution, then f (x, y) > 0, if, however, in point (x, y) there is an aspirator of pollutants (recently such pollutants are sucked by the Chinese in the cities) then f (x, y) < 0. Additionally f (x, y) = 0 means that at point (x, y) no pollution occurs or diminishes. Note that the diffusion term contains Laplasian and the advection term contains the dot product of the vector β and wind speed vector. So we can rewrite our problem like this: β(x, y) · ∇u(x, y) − ∆u(x, y) = f (x, y) The weak formulation is obtained as follows. We integrate and multiply our equation by selected functions v(x, y) called test functions which we will use to average our equation in the area where these functions are defined Z
Z β(x, y) · ∇u(x, y) −
Ω
Z ∆u(x, y)v(x, y)dxdy =
Ω
f (x, y)v(x, y)dxdy
(3.3)
Ω
In a similar way to the bitmap projection problem, each selection of a test function v(x, y) for averaging our problem in the area where the test function is defined gives us one equation. Various test function selections v(x, y) give us different equations (??.2). So our problem that we want to solve looks like this: We are looking for pollution concentration, functions Ω 3 (x, y) ← u(x, y) ∈ R such that R R ∂u(x,y) β (x, y) ∂u(x,y) ∂x dxdy Ω βy (x, y) ∂y dxdy Ω x R ∂ 2 u(x,y) R ∂ 2 u(x,y) − Ω ∂x2 v(x, y)dxdy − Ω ∂y2 v(x, y)dxdy = R f (x, y)v(x, y)dxdy Ω for any test functions Ω 3 (x, y) → v(x, y) ∈ R(of course our pollutant concentration and test function must be regular enough to be able to compute the integrals). We denote our problem: Find Ω 3 (x, y) → u(x, y) ∈ R such that a(u, v) = l(v) R R ∂u(x,y) a(u, v) = Ω βx (x, y) ∂u(x,y) ∂x dxdy + Ω βy (x, y) ∂y dxdy R R 2 2 − Ω ∂ u(x,y) v(x, y)dxdy − Ω ∂ u(x,y) v(x, y)dxdy ∂y 2 R ∂x2 l(v) = Ω f (x, y)v(x, y)dxdy For the diffusion term, we apply the integration by parts formula, similar to the heat transport equations. We do it to reduce the degree of derivatives operating in the field of pollution concentration R R ∂u(x,y) a(u, v) = Ω βx (x, y) ∂u(x,y) ∂x dxdy + Ω βy (x, y) ∂y dxdy R ∂ 2 u(x,y) R ∂ 2 u(x,y) − Ω ∂x2 v(x, y)dxdy − Ω ∂y2 v(x, y)dxdy R R ∂u(x,y) = Ω βx (x, y) ∂u(x,y) ∂x dxdy + Ω βy (x, y) ∂y dxdy R ∂u(x,y) ∂v(x,y) R ∂u(x,y) ∂v(x,y) R ∂u + Ω ∂x ∂x dxdy + Ω ∂y ∂y dxdy − ∂Ω ∂n vdS Usually, our advection-diffusion problem, similar to the heat transport problem, should be equipped with boundary conditions. We divide the boundary ∂Ω = ΓD ∪ ΓN and we introduce Dirichlet boundary condition, on
Open AGH e-podręczniki - content available under the CC BY-SA license
68
3.4. Stokes problem ΓD part of the boundary ∂Ω, which tells us about the concentration of pollutants on the edge of the area u(x, y) = p(x, y) dla (x, y) ∈ ΓD where p(x, y) is a given derivative of the concentration of pollutants normal to the boundary of the area. ΓN fragment on the shore ∂u(x,y) ∂n
= g(x, y) dla (x, y) ∈ ΓN
where g(x, y) is the stream of pollutant concentration on the shore. Diffusion convection equations for a large value difference between the advection vector and the diffusion coefficient (e.g. two orders of magnitude or more, i.e. β = (1, 0), = 10−2 )/require special stabilization methods as described in chapter five. For small differences in values, the traditional or isogeometric finite element method works fine.
3.4.
Stokes problem
Now let’s look at another class of computational problems, the so-called Stokes problem. These equations describe the flow of a liquid [12], [13]. First, let us try to understand the meaning of these equations. How can fluid flowing in a two-dimensional area be described? Suppose we are looking for a solution to the Stokes problem (liquid flow problem) in a square shaped area Ω = [0, 1]2 . At each point (x, y) ∈ Ω of our area, we want to know the velocity of the liquid flow which is a vector and which assigns to each point two coordinates of the velocity field (velocities in the direction of the two axes of the coordinate system at this point)Ω 3 (x, y) → u(x, y) = (u1 (x, y), u2 (x, y)) ∈ R2 (where bold u stands for a vector of two components) and a scalar pressure field which assigns to each point one pressure value at that point Ω 3 (x, y) → p(x, y) ∈ R. So we have three unknowns at each point, two velocity components and one pressure component. Now, we need at least three equations to solve our problem. The Stokes equation in its general form is written as −∆u + ∇p = f . Remembering that the velocity field has two components, and recalling what Laplasian and gradient mean, we get two equations in the so-called strong form −∂
2
−∂
2
u1 (x,y) ∂x2 u2 (x,y) ∂x2
− −
∂ 2 u1 (x,y) ∂y 2 2
∂ u2 (x,y) ∂y 2
+
∂p(x,y) ∂x
= f1 (x, y)
+
∂p(x,y) ∂y
= f2 (x, y)
We get a third additional equation assuming the additional properties of the fluid for which we want to calculate the flow. Traditionally, the Stokes equation assumes that the fluid is incompressible and that there is no source or loss of fluid in the region. Mathematically, this condition is written in the form of the so-called divergence. We write specifically that the divergence is zero ∂ ∂ ∂u1 (x, y) ∂u2 (x, y) divu = 0 where divu = ∇ · u = , · (u1 , u2 ) = + =0 ∂x ∂y ∂x ∂y So we have the following system of equations to solve 2
∂ 2 u1 ∂y 2
+
∂p ∂x
= f1
2
∂ 2 u2 ∂y 2
+
∂p ∂y
= f2
− ∂∂xu21 − − ∂∂xu22 − ∂u1 ∂x
+
∂u2 ∂y
=0
To solve the partial differential equation that is satisfied in a given area, we must additionally determine what is happening at the edge of that area. In this way, we will specify the problem that we want to solve. Any other boundary conditions give us a different problem and, consequently, a different solution. In our
Open AGH e-podręczniki - content available under the CC BY-SA license
69
3.4. Stokes problem case, we introduce the so-called Dirichlet boundary conditions on the flow velocity, which tell us the values of the velocity field on the boundary of the region area. Suppose our area is a bay on the bank of a river that flows uniformly from left to right, along the upper boundary of our area Ω. We assume that the flow velocity on the upper edge of the area is u(x, y) = (1, 0) dla x ∈ (0, 1), y = 1. For the remainder of the boundary, we assume that the flow velocity is zero u(x, y) = (0, 0) dla x ∈ {0, 1}, y ∈ (0, 1) ∪ x ∈ (0, 1), y = 0. We have certain boundary conditions defining the values of the velocity field on the boundary of the area. Such conditions are called Dirichlet boundary conditions. In the Stokes problem, we also calculate pressure, so we must make some assumption about pressure. We assume that in total the pressure over the entire area is equilibrated (the pressure sampled in different places by multiplication by the test function and integrated gives a total of zero) R p(x, y)dxdy = 0. Ω We can now construct the so-called weak formulation of our problem, which will be suitable for simulation with the finite element method. The weak formulation is obtained as follows. We integrate and multiply our equation by selected functions called test functions which we will use to average our equation in the area where these functions are defined. The main difference to the projection problem is that we now have a system of three equations, so we need three test functions, one for each equation, we denote them v1 (x, y), v2 (x, y), q(x, y). We multiply the equations and integrate over the area R 2 1 (x,y) R 2 1 (x,y) R R − Ω ∂ u∂x v1 (x, y)dxdy − Ω ∂ u∂y v1 (x, y)dxdy + Ω ∂p(x,y) 2 2 ∂x v1 (x, y)dxdy = Ω f1 (x, y)v1 (x, y)dxdy R 2 2 (x,y) R 2 2 (x,y) R R − Ω ∂ u∂x v2 (x, y)dxdy − Ω ∂ u∂y v2 (x, y)dxdy + Ω ∂p(x,y) 2 2 ∂y v2 (x, y)dxdy = Ω f2 (x, y)v2 (x, y)dxdy R ∂u1 (x,y) R (x,y) q(x, y) + Ω ∂u2∂y q(x, y)dxdy = 0 ∂x Ω In a similar way to the bitmap projection problem, each selection of a test function v(x, y) for averaging our problem in the area where the test function is defined gives us one equation. Various test function selections v(x, y) : v1 (x, y), v2 (x, y), q(x, y) will give us different equations R ∂u1 (x,y) ∂v1 (x,y) R R R (x,y) ∂v1 (x,y) (x,y) dxdy + Ω ∂u1∂y dxdy + ∂Ω ∂u1∂n v1 (x, y)dS + Ω ∂p(x,y) ∂x ∂y ∂x v1 (x, y)dxdy = ΩR ∂x = Ω f1 (x, y)v1 (x, y)dxdy R ∂u2 (x,y) ∂v2 (x,y) R R R (x,y) ∂v2 (x,y) (x,y) dxdy + Ω ∂u2∂y dxdy + ∂Ω ∂u2∂n v2 (x, y)dS + Ω ∂p(x,y) ∂x ∂y ∂y v1 (x, y)dxdy = ΩR ∂x = Ω f2 (x, y)v2 (x, y)dxdy R ∂u1 (x,y) R (x,y) q(x, y) + Ω ∂u2∂y q(x, y)dxdy = 0 ∂x Ω where, after integration by parts, new terms appear - edge integrals calculated perpendicularly to the edge. In our Stokes problem to calculate flow in a gulf adjacent to a river, we assume that forces f1 (x, y) = f2 (x, y) = 0. In the boundary condition, we assume that the speed on the upper boundary is u(x, y) = (1, 0) dla x ∈ (0, 1), y = 1. In other words, we introduce the Dirichlet boundary condition for the flow velocity here. There is one technical problem with this formulation. Well, the flow field on the upper boundary is non-zero (directed to the right), while on the side edges (on the left and right boundary) the flow field is equal to zero. So, we have a jump from zero to one at the first coordinate of the velocity field. First of all, such a jump is not physical (it cannot be that the water at one point does not flow, and just next to it, it flows Open AGH e-podręczniki - content available under the CC BY-SA license
70
3.4. Stokes problem quite quickly, the transition from ”not flowing” to ”flowing” takes place in a smooth, regular manner). Secondly, if we would like a numerical solution to approximate using the finite element method, such a solution is presented as a linear combination of continuous polynomials. There are no such polynomials that jump from zero to one. Setting the problem this way will result in numerical singularities in the upper left and upper right edge of the area. To avoid this, in this case, the following trick is performed g(x, y) = 1 dla x ∈ (, 1 − ), y = 1 g(x, y) =
x
g(x, y) =
(1−x)
dla x ∈ (0, ), y = 1 dla x ∈ (1 − , 1), y = 1
u(x, y) = (g(x, y), 0) dla x ∈ (0, 1), y = 1 Then we actually have zero velocity in the corners of the area and there are no numerical singularities in the finite element calculations. We then do the so-called ”shift” of our problem. We divide the sought solution into two components u(x, y) = (h(x, y) + w(x, y), u2 (x, y)) where h(x, y) = g(x, y)(1 − y) is the so-called extension of our nonzero Dirichlet boundary to the whole area Ω. So, we actually do our shift only in relation to the first component of the velocity field (because the second component is equal to zero). Then the first equation is changing R ∂(h(x,y)+w(x,y)) ∂v1 (x,y) R R ∂v1 (x,y) dxdy + Ω ∂(h(x,y)+w(x,y)) dxdy + ∂Ω ∂(h(x,y)+w(x,y)) v1 (x, y)dS+ ∂x ∂x ∂y ∂y ∂n Ω R ∂p(x,y) + Ω ∂x v1 (x, y)dxdy = 0 A member with a given function h(x, y) is known and we can move it to the right-hand side R ∂w(x,y) ∂v1 (x,y) R R R ∂p(x,y) ∂v1 (x,y) dxdy + Ω ∂w(x,y) dxdy + ∂Ω ∂w(x,y) ∂x ∂x ∂y ∂y ∂n v1 (x, y)dS + Ω ∂x v1 (x, y)dxdy = Ω R ∂h(x,y) ∂v1 (x,y) R ∂h(x,y) ∂v1 (x,y) R ∂h(x,y) = Ω ∂x dxdy + Ω ∂y dxdy + ∂Ω ∂n v1 (x, y)dS ∂x ∂y We can calculate all the terms on the right-hand side. Another unknown w(x, y) entered on the left-hand side can be marked back as u1 (x, y); however, we must remember after solving our Stokes problem that we ought to add back the term with the boundary extension to it. We introduce markings on our left-hand and right-hand sides R a(u, v) = Ω ∇u : ∇vdxdy where : means summing up all components R R ∂u1 ∂v1 R ∂u2 ∂v2 R ∂u2 ∂v2 1 ∂v1 = Ω ∂u ∂x ∂x dxdy + Ω ∂y ∂y dxdy + Ω ∂x ∂x dxdy + Ω ∂y ∂y dxdy R b(p, v) = Ω pdivvdxdy R R ∂v2 1 = Ω p ∂v ∂x dxdy + Ω p ∂y dxdy R R R ∂v1 (x,y) ∂v2 (x,y) f (v) = Ω ∂h(x,y) dxdy + Ω ∂h(x,y) dxdy + ∂Ω ∂h(x,y) ∂x ∂x ∂y ∂y ∂n v1 (x, y)dS Our problem can now be written as follows
a(u, v) + b(p, v) = f (v) b(q, u) = 0
∀v
(3.4)
∀q
Note that we have replaced a system of three equations with a system of two equations. Our two equations are ”coded” in the first equation. Now, we can take the test functions v = (v1 , 0) to get the first solution, and v = (0, v2 ) to get the second equation.
Open AGH e-podręczniki - content available under the CC BY-SA license
71
3.4. Stokes problem Having thus described our problem, we can now assume that our sought solution (u, p) = (u1 (x, y), u2 (x, y), p(x, y)) it has speed terms equal to zero on the boundary u1 (x, y) = u2 (x, y) = 0 dla (x, y) na ∂Ω. Likewise, we can assume that our test functions are also equal to zero on the boundary v1 (x, y) = v2 (x, y) = 0 dla (x, y) na ∂Ω We now define the functions used for solution approximation and for testing. We define what our group of elements will look like, and our B-spline basis functions spanning the elements, giving a knot vector along axis x and knot vector along y. Here we refer to the third chapter, which describes the way of defining base functions with the help of knot vectors and B-spline functions. Along the axis x we introduce a knot vector 0 0 0 1 2 3 4 4 4, likewise along the axis y we introduce a knot vector 0 0 0 1 2 3 4 4 4. We obtained two bases of one-dimensional B-spline functions {Bi,2 (x)}i=1,...,6 and {Bj,2 (y)}j=1,...,6 . Then we will create tensor products from them Bi,j;2 (x, y) = Bi,2 (x)Bj,2 (y), i, j = 1, ..., 6. Note that our area Ω is stretched over a square [0, 1]2 , similar to our 6 * 6 = 36 basis functions which results from the definition of the knot vector 0 0 0 1 2 2 3 4 4 4. We now take our approximation of the velocity fields P u1 (x, y) ≈ i,j=1,...,6 ui,j 1 Bi,2 (x)Bj,2 (y) P u2 (x, y) ≈ i,j=1,...,6 ui,j 2 Bi,2 (x)Bj,2 (y) and pressure P p(x, y) ≈ i,j=1,...,6 pi,j Bi,2 (x)Bj,2 (y) We also use combinations of linear B-spline functions for testing P v1 (x, y) ≈ k,l=1,...,6 v1k,l Bk,2 (x)Bl,2 (y) P v2 (x, y) ≈ k,l=1,...,6 v2k,l Bk,2 (x)Bl,2 (y) and pressure P q(x, y) ≈ k,l=1,...,6 q k,l Bk,2 (x)Bl,2 (y) We select the basis functions (v, q) = (v1 , 0, 0) = (Bk,2 (x)Bl,2 (y), 0, 0) dla k = l, ..., 6 and put into the equation (??.3). We get matrices R B (x) R ∂Bk,2 (x) ∂Bl,2 (y) ∂Bj,2 (y) A1i,j=1,...,6;k,l=1,...,6 Ω i,2 Bl,2 (y)dxdy + Ω Bi,2 (x) ∂y Bk,2 (x) ∂y dxdy ∂x Bj,2 (y) ∂x R ∂Bi,2 (x) B1i,j=1,...,6;k,l=1,...,6 = Ω ∂x Bj,2 (y)Bk,2 (x)Bl,2 (y)d, 6) Then we take base functions (v, q) = (0, v1 , 0) = (0, Bk,2 (x)Bl,2 (y), 0) dla k = l, ..., 6 and put into the equation (??.3). We get matrices R ∂Bi,2 (x) R ∂B (x) ∂Bl,2 (x) ∂Bj,2 (y) A2i,j=1,...,6;k,l=1,...,6 = Ω ∂x Bj,2 (y) k,2 Bl,2 (y)dxdy + Ω Bi,2 (x) ∂y Bk,2 (y) ∂y dxdy ∂x R ∂Bl,2 (y) B2i,j=1,...,6;k,l=1,...,6 = Ω Bi,2 (x)Bj,2 (y)Bk,2 (x) ∂y dxdy Additionally, assuming base functions (v, q) = (0, 0, q) = (0, 0, Bk,2 (x)Bl,2 (y)) dla k = l, ..., 6 and put into the equation (??.3). We get matrices R ∂Bi,2 (x) Q1i,j=1,...,6;k,l=1,...,6 = Ω ∂x Bj,2 (y)Bk,2 (x)Bl,2 (y)dxdy R ∂Bj,2 (y) Q2i,j=1,...,6;k,l=1,...,6 = Ω Bi,2 (x) ∂y Bk,2 (x)Bl,2 (y)dxdy And the right-hand side R R ∂Bk,2 (x) F 1k,l=1,...,6 = Ω ∂h(x,y) Bl,2 (y)dxdy + ∂Ω ∂x ∂x
∂h(x,y) ∂n Bk,2 (x)Bl,2 (y)dS
Open AGH e-podręczniki - content available under the CC BY-SA license
72
3.5. Linear elasticity F 2k,l=1,...,6 =
R Ω
∂Bl,2 (y) ∂h(x,y) dxdy ∂y Bk,2 (x) ∂y
+
R ∂Ω
∂h(x,y) ∂n Bk,2 (x)Bl,2 (y)dS
Our system of equations is as follows A1 0 B1 u1 F1 0 A2 B2 u2 = F 2 Q1 Q2 0 p 0 To get an accurate solution of the Stokes equation requires additional stabilization of the finite element method. In the following modules, two methods of stabilization will be discussed, one based on the residual minimization method, the other based on the DG (Discontinuous Galerkin) method.
3.5.
Linear elasticity
In this module, we will present the strong and weak formulations for the equations of linear elasticity theory, which are very commonly used in calculations using the finite element method for stresses in various structures. Consider, for example, a three-dimensional platform supported by five supports, standing on the OXY plane, shown in Pic. 26. This platform has its own weight and certain stresses appear on it due to the influence of the gravitational field of the earth. For a more convenient formulation of the partial differential equations describing the displacement of the platform, we will now use the notation (x1 , x2 , x3 ) at any point of the platform. The solution sought this time will be the vector field of displacements Ω 3 (x1 , x2 , x3 ) → (u1 (x1 , x2 , x3 ), u2 (x1 , x2 , x3 ), u3 (x1 , x2 , x3 )) This means in particular that the displacement of the platform points under its weight in the direction of the axis z, are equal u3 (x1 , x2 , x3 ) in point (x1 , x2 , x3 ). Of course, the gravitational field works only in the direction of the Z axis, but the platform points are ”glued” to each other and if the platform point moves in the Z direction due to the weight of the platform, it is often associated with a point shift in the X and Y directions, which is described by the components u1 (x1 , x2 , x3 ) and u2 (x1 , x2 , x3 ). Of course, it is not easy to predict how these points will deform, and in particular it requires solving complicated equations of the linear theory of elasticity. To simplify the notation and due to the use of traditional notation, we introduce a designation for partial derivatives of individual coordinates of the displacement vector ui,j =
∂ui ∂xj
which represents the derivative in the j-th direction of the i-th component of the vector field. In order to derive the equations of the linear theory of elasticity, a so-called strain rate tensor is introduced ij =
∂ui ∂xj
∂u
+ ∂xj i
2
=
ui,j +uj,i 2
and stress tensor σij = cijkl kl We use the so-called Einstein summation convention, in which duplicating the indices in the formula means that we sum over these indices, i.e. in the equation of elasticity σij = cijkl kl repetition of indexes k, l means summotion P σij = k=1,...,3;l=1,...,3 cijkl kl .
Open AGH e-podręczniki - content available under the CC BY-SA license
73
3.5. Linear elasticity We have a four-dimensional matrix of coefficients here cijkl , i = 1, ..., 3; j = 1, ..., 3, k = 1, ..., 3; l = 1, .., 3. The definition of these 3 * 3 * 3 * 3 numbers clearly defines the material from which the structure I am analyzing is made of (the platform in our example). Fortunately, most of these factors will be zero. The so-called strong formulation of the linear theory of elasticity problem is formulated as follows σij,j + fi = 0 for i=1,2,3,inside Ω. The term fi stands for 3 coordinates of the force vector acting on our structure, for example it will be the force of gravity f = (g1 (x1 , x2 , x3 ), g2 (x1 , x2 , x3 ), g3 (x1 , x2 , x3 )) We introduce the following convention here. Indices repeated after the decimal point ij, j denote the computation of the partial derivative after the indexed variable. ∂σ
Term σij,j = ∂xijj thus denotes the sum of partial derivatives of the stress tensor. Moreover, we have three equations defacto (which makes sense since we are looking for the three coordinates of the displacement vector). P ∂σ1j j=1,2,3 ∂xj + f1 = 0 P ∂σ2j j=1,2,3 ∂xj + f2 = 0 P ∂σ3j j=1,2,3 ∂xj + f3 = 0 that is, taking into account the definition of the stress tensor P P ∂( k=1,...,3;l=1,...,3 c1jkl kl ) + f1 = 0 j=1,2,3 ∂xj P P ∂( k=1,...,3;l=1,...,3 c2jkl kl ) + f2 = 0 j=1,2,3 ∂xj P P ∂( k=1,...,3;l=1,...,3 c3jkl kl ) + f3 = 0 j=1,2,3 ∂xj that is, taking into account the definition of the strain velocity tensor P
∂(
uk,l +ul,k 2
))
uk,l +ul,k k=1,...,3;l=1,...,3 c2jkl ( 2
))
P
k=1,...,3;l=1,...,3
j=1,2,3
P
∂xj ∂(
P
∂(
P
j=1,2,3
P
j=1,2,3
c1jkl (
∂xj uk,l +ul,k k=1,...,3;l=1,...,3 c3jkl 2
∂xj
)
+ f1 = 0 + f2 = 0
+ f3 = 0
Our unknown here is the displacement vector field: We are looking at Ω 3 (x1 , x2 , x3 ) → (u1 (x1 , x2 , x3 ), u2 (x1 , x2 , x3 ), u3 (x1 , x2 , x3 )) In order to solve the equations of the linear theory of elasticity on a given structure, it is necessary to define the boundary conditions, i.e. to define what is happening at the edge of the structure. On part of the boundary, we can introduce a Dirichlet condition, for example specifying that the base of the structure is attached to the ground, and therefore the displacement of the base of the structure is zero u1 (x1 , x2 , x3 ) = 0, u2 (x1 , x2 , x3 ) = 0, u3 (x1 , x2 , x3 ) = 0, dla (x1 , x2 , x3 ) ∈ ΓD It is also possible to define the Neumann boundary condition σij nj = hi dla (x1 , x2 , x3 ) ∈ ΓN where n(x1 , x2 , x3 ) = (n1 (x1 , x2 , x3 ), n2 (x1 , x2 , x3 ), n3 (x1 , x2 , x3 )) which means versor perpendicular to the boundary at point (x1 , x2 , x3 ), and h = (h1 (x1 , x2 , x3 ), h2 (x1 , x2 , x3 ), h3 (x1 , x2 , x3 )) denotes a given function on the Neumann edge ΓN , that is, taking into account Einstein’s summation conventions σ11 n2 + σ12 n2 + σ13 n3 = h1 σ21 n2 + σ22 n2 + σ23 n3 = h2 σ31 n2 + σ32 n2 + σ33 n3 = h3 and also taking into account the definition of the stress tensor P P P ( k=1,...,3;l=1,...,3 c11kl kl )n2 + ( k=1,...,3;l=1,...,3 c12kl kl )n2 + ( k=1,...,3;l=1,...,3 c13kl kl )n3 = h1 P P P ( k=1,...,3;l=1,...,3 c21kl kl )n2 + ( k=1,...,3;l=1,...,3 c22kl kl )n2 + ( k=1,...,3;l=1,...,3 c23kl kl )n3 = h2
Open AGH e-podręczniki - content available under the CC BY-SA license
74
3.5. Linear elasticity P P P ( k=1,...,3;l=1,...,3 c31kl kl )n2 + ( k=1,...,3;l=1,...,3 c32kl kl )n2 + ( k=1,...,3;l=1,...,3 c33kl kl )n3 = h3 . The Neumann condition defines the forces in the equations of the theory of elasticity. We give a weak (also called variational) formulation that can be implemented using the finite element method based on the book [14]. The weak (variational) formulation given below is valid for a certain broad class of materials for which the mechanical properties can be described using two parameters, Young’s modulus E and the Poisson’s ratio E and the Poisson’s ratio µ. For a given force field Ω 3 (x1 , x2 , x3 ) → f = (g1 (x1 , x2 , x3 ), g2 (x1 , x2 , x3 ), g3 (x1 , x2 , x3 )) and a given Neumann boundary condition function Ω 3 (x1 , x2 , x3 ) → h = (h1 (x1 , x2 , x3 ), h2 (x1 , x2 , x3 ), h3 (x1 , x2 , x3 )) and a given tensor (four-dimensional matrix) of material coefficients cijkl calculate the displacement area of the structure material Ω 3 (x1 , x2 , x3 ) → (u1 (x1 , x2 , x3 ), u2 (x1 , x2 , x3 ), u3 (x1 , x2 , x3 )) satisfying the equations of linear elasticity a(w, u) = (w, f ) + (w, h)Γ for arbitrary test functions w = (w1 (x1 , x2 , x3 ), w2 (x1 , x2 , x3 ), w3 (x1 , x2 , x3 )), where R R (w, f ) = w1 (x1 , x2 , x3 )f1 (x1 , x2 , x3 )dx + Ω w2 (x1 , x2 , x3 )f2 (x1 , x2 , x3 )dy + Ω R w (x , x2 , x3 )f3 (x1 , x2 , x3 )dz Ω 3 1 R R (w, h) = w1 (x1 , x2 , x3 )h1 (x1 , x2 , x3 )dS + Γ w2 (x1 , x2 , x3 )h2 (x1 , x2 , x3 )dS + Γ R w (x , x , x3 )f3 (x1 , x2 , x3 )dS Γ 3 1 R2 a(w, u) = Ω (w)T D(u)dxdydz where
u1,1 w1,1 w2,2 u2,2 u3,3 w 3,3 (u) = , (w) = u2,3 + u3,2 w2,3 + w3,2 u1,3 + u3,1 w1,3 + w3,1 u1,2 + u2,1 w1,2 + w2,1 and 1−µ µ 1−µ µ µ µ E D = (1+2µ)(1−2µ) 0 0 0 0 0 0
µ µ 1−µ 0 0 0
0 0 0 1−2µ 2
0 0
0 0 0 0 1−2µ 2
0 0 0 0 0
0
1−2µ 2
is derived with the assumption that the general tensor of material properties cijkl can be described by two Young’s modulus parameters E and Poissona coefficient µ. The given variation formulation is relatively easy to implement. The isogeometric finite element method or the classical finite element method can be used for this purpose. Consider the following example.
Open AGH e-podręczniki - content available under the CC BY-SA license
75
3.5. Linear elasticity
EXAMPLE
Example 3: Platform deformation Let us assume that our area Ω is a platform with dimensions of 16 by 16 blocks, supported by five supports placed under blocks (1,1), (16,1), (1,16), (16,16) and (8,8), as shown in Pic. 26.
Open AGH e-podręczniki - content available under the CC BY-SA license
76
3.5. Linear elasticity
Figure 26: Platform on five supports.
We assume a zero Dirichlet condition at the base of the platform (i.e., we assume that the legs are attached to a flat, stable ground), while on the rest of the edge we do not assume any boundary condition. Such an assumption is sufficient because fixing the platform at the base of the legs gives us the possibility of obtaining an unambiguous solution (calculation of deformations resulting from the weight of the platform). We assume gravitational force f = (0, 0, −1) and h = 0(no Neumann b.c.) We have a(w, u)
=
(w, f )
Open AGH e-podręczniki - content available under the CC BY-SA license
+
(w, h)Γ
77
3.5. Linear elasticity R a(w, u) = (w)T D(u)dxdydz Ω R R (w, f ) = w (x , x2 , x3 )f1 (x1 , x2 , x3 )dx + w (x , x2 , x3 )f2 (x1 , x2 , x3 )dy + Ω 1 1 Ω 2 1 R R R + Ω w3 (x1 , x2 , x3 )f3 (x1 , x2 , x3 )dz = 0 ∗ f1 (x1 , x2 , x3 )dx + Ω 0 ∗ f2 (x1 , x2 , x3 )dy + Ω R + (−1) ∗ f3 (x1 , x2 , x3 )dz Ω (w, h) = (w, 0) = 0 Moreover, we assume Young’s modulus E = 1[GP a] and µ = 0.3 czyli 0.7 0.3 0.3 1 D = (1.6)(0.4) 0 0 0
0.3 0.7 0.3 0 0 0
0.3 0 0 0 0.3 0 0 0 0.7 0 0 0 [GP a] 0 0.2 0 0 0 0 0.2 0 0 0 0 0.2
Then the surface of the platform and each of the five bases can be treated as a separate group of elements and described by the following node vectors Platform: 0 0 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 16 16 x 0 0 0 1 1 1 x 0 0 0 1 1 1 Supports: 0 0 0 1 1 1 x 0 0 0 1 1 1 x 0 0 0 10 10 10 15 15 15 16 16 16 x 15 15 15 16 16 16 x 0 0 0 10 10 10 0 0 0 1 1 1 x 15 15 15 16 16 16 x 0 0 0 10 10 10 15 15 15 16 16 16 x 0 0 0 1 1 1 x 0 0 0 10 10 10 7 7 7 8 8 8 x 7 7 7 8 8 8 x 0 0 0 10 10 10 Each of the components of the vector strain field is approximated by a linear combination of the B-spline function on individual groups of elements P x1 x2 x3 1 u1 (x1 , x2 , x3 ) = i,j,k=1,...,Nx ,Ny ,Nz ui,j,k Bi,p (x1 )Bj,p (x2 )Bk,p (x3 ) P x1 x2 x3 2 u2 (x1 , x2 , x3 ) = i,j,k=1,...,Nx ,Ny ,Nz ui,j,k Bi,p (x1 )Bj,p (x2 )Bk,p (x3 ) P x1 x2 x3 u3 (x1 , x2 , x3 ) = i,j,k=1,...,Nx ,Ny ,Nz u3i,j,k Bi,p (x1 )Bj,p (x2 )Bk,p (x3 ) In our problem of linear elasticity, we simultaneously solve the three components of the displacement field and they fit together into one global matrix. We put the discretizations into the weak formulation, and behind the testing functions in we also take B-spline functions, generate a system of equations, solve it with an exact solver and obtain the solution shown in Pic. 27. The figure will show the norm from deformations, defined as ku1 (x1 , x2 , x3 )2 + u2 (x1 , x2 , x3 )2 + u3 (x1 , x2 , x3 )2 k. The obtained solution is not symmetrical, because the platform also has, apart from four supports located in the corners, a fifth support located asymmetrically.
Open AGH e-podręczniki - content available under the CC BY-SA license
78
3.6. Weak formulations and numerical integration
Figure 27: Norm of platform deformations.
3.6.
Weak formulations and numerical integration
For all of the above-mentioned variational formulations, in order to solve them with the finite element method, it is necessary to generate a system of linear equations. In particular, it is necessary to generate integrals that form a system of linear equations. Remembering that the rows and columns in the global system of equations correspond to the underlying functions - in our example they correspond to the B-spline functions - we generate the following system of equations
Open AGH e-podręczniki - content available under the CC BY-SA license
79
3.6. Weak formulations and numerical integration
y x B1,p B1,p x y y y x x B1,p B1,p a(B1,p B1,p , B1,p B1,p ) y y x x Bx By a(B2,p B1,p , B1,p B1,p ) 2,p 1,p . .. .. . y y y x x x BNx ,p BNy ,p a(BNx ,p BNy ,p , B1,p B1,p ) l(B1x (x) ∗ B1y (y)) y l(B1x (x) ∗ B2 (y)) = .. . y x l(BNx (x) ∗ BNy (y))
··· ··· ··· .. . ···
y x BN B 1,p ,p x u1,1 y y x x a(B1,p B1,p , BN B ) Ny ,p x ,p u2,1 y y x x a(B2,p B1,p , BN B ) . Ny ,p x ,p .. .. . uNx ,Ny y y x x a(BN BN , BN BN ) x ,p x ,p y ,p y ,p
B-spline functions that do not have a common support (which are defined over distant parts of the grid) generate zero integrals, and zero values in the matrix. Therefore, when generating a matrix, we should not iterate over the rows and columns of the matrix, but we should iterate over the elements of the computational grid, and over the basis functions that are defined on a given element. The resulting contributions of the integrals should be aggregated into the global matrix. Then our generation of integrals will avoid all non-zero terms of the matrix. The algorithm contains six nested loops: 1 for nex = 1, Nx (loop through elements along the axis x) 2 for ney = 1, Ny (loop through elements along the axis y) 3 for ibx1 = 1, p + 1(loop through p + 1 B-splines of the element along the axis x) 4 for iby1 = 1, p + 1( loop through p + 1 B-spline of the element along the axis y) 5 i = f (nex, ibx1)( calculate the B-spline index along the axis x) 6 j = f (ney, iby1) ( calculate the B-spline index along the axis y) 7 irow = g(nex, ibx1, ney, iby1)(global index of 2D B-spline) y x 8 l(irow)+ = l(Bi,p Bj,p )
9 for ibx2 = 1, p + 1( loop through p + 1 B-splines of the element along the axis x) 10 for iby2 = 1, p + 1(loop through p + 1 B-splines of the element along the axis y) 11 k = f (nex, ibx2)(calculate the B-spline index along the axis x) 12 l = f (ney, iby2)(calculate the B-spline index along the axis y) 13 irow = g(nex, ibx2, ney, iby2)(global index of 2D B-spline) y y x x 14 M (irow, icol)+ = a(Bi,p Bj,p , Bk,p Bl,p )
The function f (nex, ibx) computes the index of the one-dimensional B-spline basis function for element local function ibx defined along the axis x for segment nex. For uniform order B-splines p this index is equal to nex + ibx − 1. Functions g(nex, ibx, ney, iby) calculate the global index of a two-dimensional B-spline. In the case of uniform B-splines this formula is irow = i ∗ j where i = f (nex, ibx) and j = f (ney, iby). In turn, the computation of integrals is generally performed by numerical integration using points and weights of quadrature, for example Gauss quadrature. The one-dimensional integral of a polynomial on an interval can be calculated exactly as the sum of the values of this polynomial at selected points of the quadrature spread over the interval, multiplied by appropriate weights. The derivation and theory of numerical quadratures is beyond the scope of this manual.
Open AGH e-podręczniki - content available under the CC BY-SA license
80
3.6. Weak formulations and numerical integration Gauss quadratures are named after a German mathematician who invented this method of integration in 1826 [15]. The choice of quadrature depends on the type of basis function, and it is possible to reduce the number of quadrature points by using special quadratures dedicated to particular basis functions. In general, the basis functions on a single element are polynomials and the use of Gauss quadratures is justified. The following example illustrates the formation of points and Gaussian quadrature weights on an interval [0, 1] which guarantees the exact calculation of the integral function of two-dimensional B-splines of a degree not greater than 10. m_points1= (1.0-0.973906528517171720077964)*0.5; m_points2= (1.0-0.8650633666889845107320967)*0.5; m_points3= (1.0-0.6794095682990244062343274)*0.5; m_points4= (1.0-0.4333953941292471907992659)*0.5; m_points5= (1.0-0.1488743389816312108848260)*0.5; m_points6= (1.0+0.1488743389816312108848260)*0.5; m_points7= (1.0+0.4333953941292471907992659)*0.5; m_points8= (1.0+0.6794095682990244062343274)*0.5; m_points9= (1.0+0.8650633666889845107320967)*0.5; m_points10= (1.0+0.9739065285171717200779640)*0.5; m_weights1=0.0666713443086881375935688*0.5; m_weights2=0.1494513491505805931457763*0.5; m_weights3=0.2190863625159820439955349*0.5; m_weights4=0.2692667193099963550912269*0.5; m_weights5=0.2955242247147528701738930*0.5; m_weights6=0.2955242247147528701738930*0.5; m_weights7=0.2692667193099963550912269*0.5; m_weights8=0.2190863625159820439955349*0.5; m_weights9=0.1494513491505805931457763*0.5; m_weights10=0.0666713443086881375935688*0.5; The quadratures are originally tabulated for the interval [−1, 1] so here we scale them to a range [0, 1] adding 1 to the coordinates of the points and dividing the coordinates of the points by 2 (that is, multiplying by 0.5). Then, the numerical integration performed on line 14 (and subsequent ones) in the above code requires two additional loops after Gaussian’s quadrature points and weights, and it looks like this: 15 for m = 1, p/2 + 1(loop through Gaussian quadrature points along the axis x for B-splines of order p) 16 for n = 1, p/2 + 1(loop through Gaussian quadrature points along the axis y for B-splines of order p) 17 M (irow, icol)+ = y y x x a(Bi,p (m_points[m])Bj,p (m_points[n]), Bk,p (m_points[m])Bl,p (m_points[n])) ∗m_weights[m] ∗ m_weights[n] ∗ area
Open AGH e-podręczniki - content available under the CC BY-SA license
81
3.7. MATLAB implementation of the heat transfer problem In particular, for our example problem of heat transport in an L-shaped area we have x x ∂Bi,p ∂Bk,p M (u, v) = (m_points[m]) (m_points[m]) ∗ m_weights[m] ∂x ∂x ∂B y y ∂B + ∂yj,p (m_points[n]) ∂yl,p (m_points[n]) ∗ m_weights[n] In the above formula, we calculate the derivative values of the one-dimensional B-spline functions at the points of Gaussian quadrature (m_points[m], m_points[n]) multiplied by the weights of Gaussian quadrature ∗m_weights[m] ∗ m_weights[n].
3.7.
MATLAB implementation of the heat transfer problem
Below you can find a link to the MATLAB code for calculating the heat transport problem in an L-shaped area. The code execution is also possible in the free Octave environment. Download code or see Appendix 3. The code is activated by opening it in Octave and typing a command heat0 After a moment of calculation, the code opens an additional window and draws the solution in it. On line 641 knot = [0, 0, 0, 1, 2, 2, 2]; there is a saved vector of knots 0 0 0 1 2 2 2 which will be used on each of the three groups of elements (patches) used to solve the heat transport problem.
EXERCISE
Exercise 6: Solution of heat transport problem with Lagrange polynomials Exercise content:
Please modify the heat transport code so that it uses 2nd order Lagrange polynomials and that each patch of elements has 5 elements.
Solution:
(line641)knot = [0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 5]
3.8.
MATLAB implementation of the advection-diffusion with Galerkin method
Below you can find a link to the MATLAB code calculating the Galerkin advection-diffusion problem for the Eriksson-Johnson model problem. Let us recall first the advection-diffusion problem, the Eriksson-Johnson model problem (described, for example, in [16]) defined on a square area Ω = [0, 1]2 in the following way: We see u such as a(u, v) = l(v)∀v where Open AGH e-podręczniki - content available under the CC BY-SA license
82
3.8. MATLAB implementation of the advection-diffusion with Galerkin method R R ∂u(x,y) a(u, v) = Ω βx (x, y) ∂u(x,y) ∂x dxdy + Ω βy (x, y) ∂y dxdy R R ∂u(x,y) ∂v(x,y) ∂v(x,y) + Ω ∂u(x,y) ∂x ∂x dxdy + Ω ∂y ∂y dxdy R l(v) = ∂Ω f (x, y)vdxdy f (x, y) = sin(πy)(1 − x) is the extension of the Dirichlet boundary condition into the entire area, and β = (1, 0) represents the wind velocity blowing from the left side, and = 10−2 denotes the diffusion coefficient. The quantity P e = 1/ = 100 is called the Peclet number, and it defines the numerical sensitivity of the advection-diffusion problem. The definition of the Peclet number presented here is valid q 2 for unit wind speed kβk2 = βx + βy2 = 1. In the general case, the Peclet number defined on the individual grid elements according to the formula is considered P e = kβk2 ∗ h/(2 ∗ ). The Peclet number defined in this way can be used to test the stability of the simulation, the Peclet number less than one gives us the condition for the stability of the simulation on the element. In line 835 we create the knot vector with 5 elements for quadratic polynomials knot = simple_knot(5, 2); In line 836, the diffusion coefficient is set (for an advection coefficient of 1). epsilon = 2e − 2; The code execution is also possible in the free Octave environment. Download code or see (Appendix 3A). The code is run by opening it in Octave and typing a command advection0 . After a moment of calculation, the code opens an additional window and draws a numerical and exact solution to it. The code also computes the norm L2 and H1 from the solution Error : L224.00procent, H172.08procent and compares it to the L2 and H1 standards from the projection of the exact solution onto the space of B-spline functions spanning a given grid.Bestpossible : L21.56procent, H153.16procent Note that this norm will not be equal to zero, because the exact solution is not given by the B-spline functions, and even if we know the exact solution, it is not given by the B-spline functions, and its projection on the B-spline function space is also an approximation of the exact solution.
EXERCISE
Exercise 7: Solving the advection-diffusion problem for Pe = 100 by uniformly increasing the size of the computational mesh Exercise content:
Please modify the advection-diffusion code (for the diffusion coefficient of 0.02), so that it uses B-spline polynomials of the second degree spanning the interval 2k elements. What k should be used to get the exact solution? Why?
Open AGH e-podręczniki - content available under the CC BY-SA license
83
3.8. MATLAB implementation of the advection-diffusion with Galerkin method Solution:
(line 835)knot = simple_knot(2, 2)(two elements, quadratic B-splines), (line 835 knot = simple_knot(4, 2)(four elements, quadratic B-splines), (line 835)knot = simpl_knot(8, 2), (eight elements, quadratic B-splines), (line 835)knot = simple_knot(16, 2)(sixteen elements, quadratic B-splines), (line 835)knot = simple_knot(32, 2)(thirty-two elements, quadratic B-splines), (line 835)knot = simple_knot(64, 2)(sixty-four elements, quadratic B-splines). The advection-diffusion problem for an advection coefficient of one and a diffusion coefficient of 0.02 in the Galerkin method requires the size of the element to be lower or equal to the diffusion coefficient size, i.e. 0.02> 0.015625 = 1/64.
EXERCISE
Exercise 8: Solving the advection-diffusion problem for Pe = 1,000,000 using the Galerkin method. Exercise content:
Please modify the advection-diffusion code so that Pe = 1,000,000, and try to solve it with the Galerkin method for 64 elements and square B-spline functions.
Solution:
(line 846)epsilon = 1e − 6(Pe=1/1e-6=1,000,000) (line835)knot = simple_knot(64, 2)(sixty-four elements, square B-spline functions). Unfortunately, for Pe = 1,000,000 we would have to use 0.000001 pieces to get the exact solution.
EXERCISE
Exercise 9: Adaptive increase of apox machine and test mesh by breaking in half the element closest to the singularity for a large value of Pecklet number Exercise content:
Please modify the problem so that the Peclet number is one million. Please start from the grid 0 0.5 1 in the x direction and 0 0.25 0.5 0.75 1 in the y direction, and increase adaptively the number of points towards the right edge where the boundary layer is, keeping the degrees of B-spline polynomials in the approximation space and testing. Please check how this operation improves the accuracy of the solution.
Solution:
We introduce
=
10−6 and we modify the mesh in the x direction according to the sequence:0
Open AGH e-podręczniki - content available under the CC BY-SA license
84
3.8. MATLAB implementation of the advection-diffusion with Galerkin method 0.5 10 0.5 0.75 10 0.5 0.75 0.875 10 0.5 0.75 0.875 0.9375 10 0.5 0.75 0.875 0.9375 0.96875 10 0.5 0.75 0.875 0.9375 0.96875 0.984375 10 0.5 0.75 0.875 0.9375 0.96875 0.984375 0.9921875 10 0.5 0.75 0.875 0.9375 0.96875 0.984375 0.9921875 0.99609375 10 0.5 0.75 0.875 0.9375 0.96875 0.984375 0.9921875 0.99609375 0.998046875 10 0.5 0.75 0.875 0.9375 0.96875 0.984375 0.9921875 0.99609375 0.998046875 0.9990234375 10 0.5 0.75 0.875 0.9375 0.96875 0.984375 0.9921875 0.99609375 0.998046875 0.9990234375 0.9995117188 10 0.5 0.75 0.875 0.9375 0.96875 0.984375 0.9921875 0.99609375 0.998046875 0.9990234375 0.9995117188 0.9997558594 10 0.5 0.75 0.875 0.9375 0.96875 0.984375 0.9921875 0.99609375 0.998046875 0.9990234375 0.9995117188 0.9997558594 0.9998779297 10 0.5 0.75 0.875 0.9375 0.96875 0.984375 0.9921875 0.99609375 0.998046875 0.9990234375 0.9995117188 0.9997558594 0.9998779297 0.9999389648 10 0.5 0.75 0.875 0.9375 0.96875 0.984375 0.9921875 0.99609375 0.998046875 0.9990234375 0.9995117188 0.9997558594 0.9998779297 0.9999389648 0.9999694824 10 0.5 0.75 0.875 0.9375 0.96875 0.984375 0.9921875 0.99609375 0.998046875 0.9990234375 0.9995117188 0.9997558594 0.9998779297 0.9999389648 0.9999694824 0.9999847412 10 0.5 0.75 0.875 0.9375 0.96875 0.984375 0.9921875 0.99609375 0.998046875 0.9990234375 0.9995117188 0.9997558594 0.9998779297 0.9999389648 0.9999694824 0.9999847412 0.9999923706 10 0.5 0.75 0.875 0.9375 0.96875 0.984375 0.9921875 0.99609375 0.998046875 0.9990234375 0.9995117188 0.9997558594 0.9998779297 0.9999389648 0.9999694824 0.9999847412 0.9999923706 0.9999961853 0.9999980927 10 0.5 0.75 0.875 0.9375 0.96875 0.984375 0.9921875 0.99609375 0.998046875 0.9990234375 0.9995117188 0.9997558594 0.9998779297 0.9999389648 0.9999694824 0.9999847412 0.9999923706 0.9999961853 0.9999980927 0.9999990463 0.9999995232 10 0.5 0.75 0.875 0.9375 0.96875 0.984375 0.9921875 0.99609375 0.998046875 0.9990234375 0.9995117188 0.9997558594 0.9998779297 0.9999389648 0.9999694824 0.9999847412 0.9999923706 0.9999961853 0.9999980927 0.9999990463 0.9999995232 0.9999997616 0.9999998808 10 0.5 0.75 0.875 0.9375 0.96875 0.984375 0.9921875 0.99609375 0.998046875 0.9990234375 0.9995117188 0.9997558594 0.9998779297 0.9999389648 0.9999694824 0.9999847412 0.9999923706 0.9999961853 0.9999980927 0.9999990463 0.9999995232 0.9999997616 0.9999998808 0.9999999404 10 0.5 0.75 0.875 0.9375 0.96875 0.984375 0.9921875 0.99609375 0.998046875 0.9990234375 0.9995117188 0.9997558594 0.9998779297 0.9999389648 0.9999694824 0.9999847412 0.9999923706 0.9999961853 0.9999980927 0.9999990463 0.9999995232 0.9999997616 0.9999998808 0.9999999404 0.9999999702 1
Open AGH e-podręczniki - content available under the CC BY-SA license
85
3.8. MATLAB implementation of the advection-diffusion with Galerkin method
Open AGH e-podręczniki - content available under the CC BY-SA license
86
Chapter 4
4. Solvers of linear equations generated from finite element method 4.1.
Gaussian elimination algorithm
The Gaussian elimination algorithm is the most widely-known basic algorithm for solving systems of linear equations. The elimination algorithm, called the Gauss algorithm, was invented in China in 179. In Europe, the algorithm began to be used in 1771 by Leonard Euler, who called it the most natural way of solving systems of equations. It is wrongly called the Gauss elimination algorithm, from mathematician Carl Friedrich Gauss (1777-1855), who was still alive in 1771 [17].
EXAMPLE
Example 4: Gaussian elimination algorithm Let us illustrate the Gaussian elimination algorithm on the example of a matrix generated for five one-dimensional B-splines, for the right side set on a vector of ones, i.e. for R x x R x x R x x 1 B1,p B1,p dx B B2,p dx · · · B1,p B5,p dx u1 R 1,p R R x x x x x x B2,p B2,p dx · · · B2,p B5,p dx u2 1 B2,p B1,p dx .. .. .. .. .. = 1 . 1 . . . . R x x R x x R x x B5,p B1,p dx B5,p B2,p dx · · · B5,p B5,p dx u5 1 which after integration, according to the transformations presented in chapter 1, gives a matrix 1 13 1 0 0 u1 1 20 120 120 13 1 13 1 120 0 u2 1 2 60 120 1 13 11 13 1 = 120 60 1 20 60 120 u3 1 13 1 13 0 1 120 60 2 120 u4 1 13 1 0 0 u5 1 20 120 120 We start out by converting the matrices to floating point numbers
87
4.1. Gaussian elimination algorithm
0.05 0.10833 0.00833 0.10833 0.5 0.21666 0.00833 0.21666 0.55 0 0.00833 0.21666 0 0 0.00833
0 0 u1 1 0.00833 0 u2 1 0.21666 0.00833 u3 = 1 0.5 0.10833 u4 1 0.10833 0.05 u5 1
We continue by scaling the first line so that one is on the diagonal. In other words, we multiply the first row by the inverse of the line on the diagonal. Here we use pseudo code convection in which, on the right-hand side of the substitution, we describe the method of modifying the row, and on the left side we put the rows to which we substitute the result 1 1st = 1st A11,1 = 1st 0.05 = 1st 20 20∗0.05 20∗0.10833 20∗0.00833 20∗0 20∗0 u1 20∗1 0.10833 0.5 0.21666 0.00833 0 u2 1 13 0.00833 0.21666 0.55 0.00833 u3 = 1 60 0.00833 0.21666 0.5 0.10833 u4 1 0 0 0 0.00833 0.10833 0.05 u5 1 1 2.16666 0.16666 0 0 u1 20 0.10833 0.5 0.21666 0.00833 0 u2 1 13 0.00833 0.21666 0.55 0.00833 u3 = 1 60 0.00833 0.21666 0.5 0.10833 u4 1 0 0 0 0.00833 0.10833 0.05 u5 1
Then we subtract the second row from the third row, scaled in such a way as to get the zero diagonal (in the second column). In other words, we perform the subtractions 2nd = 2nd − 1st A2,1 = 2nd − 1st ∗ 0.10833 1 2.16666 0.10833−1 ∗ 0.10833 0.5−2.16666 ∗ 0.10833 0.00833 0.21666 0 0.00833 0 0 u1 20 u2 1−20 ∗ 0.10833 u3 = 1 1 u4 u5 1 In the second row in 1 2.16666 0 0.26528 0.00833 0.21666 0.00833 0 0 0
0.16666 0 0 0.21666−0.16666 ∗ 0.10833 0.00833−0 0−0 13 0.55 0.00833 60 0.21666 0.5 0.10833 0.00833 0.10833 0.05
the 4th column we subtract 0, in the 5th column we subtract zero from zero 0.16666 0 0 u1 20 0.19860 0.00833 0 u2 −1.1666 13 0.55 0.00833 1 u3 = 60 0.21666 0.5 0.10833 u4 1 0.00833 0.10833 0.05 u5 1
Similarly, we subtract the first row from the third row, scaled in such a way as to get the zero diagonal (in the first column). In other words, we do 3rd = 3rd − 1st A3,1 = 3rd − 1st 0.00833
Open AGH e-podręczniki - content available under the CC BY-SA license
88
4.1. Gaussian elimination algorithm
1 2.16666 0.16666 0 0.26528 0.19860 0.00833−1 ∗ 0.00833 0.21666−2.16666 ∗ 0.00833 0.55−0.16666 ∗ 0.00833 0 0.00833 0.21666 0 0 0.00833 u1 20 u2 −1.1666 u3 = 1−20 ∗ 0.00833 1 u4 u5 1 1 2.16666 0.16666 0 0 u1 20 0 0.26528 0.19860 0.00833 0 u2 −1.1666 0 0.19861 0.54861 0.21666 0.00833 u3 = 0.83333 0.5 0.10833 u4 1 0 0.00833 0.21666 0 0 0.00833 0.10833 0.05 u5 1
0 0.00833 0.21666−0 0.5 0.10833
0 0 0.00833−0 0.10833 0.05
We interrupt the process of subtracting the first line from the others, because in the following lines (fourth and fifth) there are zeros on the diagonal. Now, we are going to scale the second row to use it in a moment to generate zeros in the second column. We multiply the second row first by the inverse of the diagonal term 1 2nd = 2nd A12,2 = 2nd 0.26528 = 2nd 3, 76963 1 2.16666 0.16666 0 0 u1 0 0.26528∗3, 76963 0.19860∗3, 76963 0.00833∗3, 76963 0 u2 0 0.19861 0.54861 0.21666 0.00833 u3 0.00833 0.21666 0.5 0.10833 u4 0 0 0 0.00833 0.10833 0.05 u5 20 −1.1666∗3, 76963 0.83333 1 1 1 2.16666 0.16666 0 0 u1 20 0 1 0.74864 0.03140 0 u2 −4.39765 0 0.19861 0.54861 0.21666 0.00833 u3 = 0.83333 0.5 0.10833 u4 1 0 0.00833 0.21666 0 0 0.00833 0.10833 0.05 u5 1
=
Then we subtract the second row from the third row, scaled in such a way as to get the zero diagonal (in the second column). In other words, we perform the subtractions 3rd = 3rd − 2nd A3,2 = 3rd − 2st 0.19861 1 2.16666 0.16666 0 0 1 0.74864 0.03140 0 0.19861−1 ∗ 0.19861 0.54861−0.74864 ∗ 0.19861 0.21666−0.03140 ∗ 0.19861 0.00833 0.21666 0.5 0 0 0 0.00833 0.10833
Open AGH e-podręczniki - content available under the CC BY-SA license
0 0 0.00833−0 0.10833 0.05
89
4.1. Gaussian elimination algorithm u1 20 u2 −4.39765 u3 = 0.83333+4.39765 ∗ 0.19861 1 u4 u5 1 1 2.16666 0.16666 0 0 u1 20 0 1 0.74864 0.03140 0 u2 −4.39765 0 0 0.39992 0.21042 0.00833 u3 = 1.70674 0.5 0.10833 u4 1 0 0.00833 0.21666 0 0 0.00833 0.10833 0.05 u5 1 We now use the second row to generate a zero in the second column in the fourth row. To do this, we subtract the second row scaled by 0.00833 4th = 4th − 2nd A4,2 = 4th − 2nd 0.00833 1 2.16666 0.16666 0 0 0 1 0.74864 0.03140 0 0 0 0.39992 0.21042 0.00833 0 0.00833−1 ∗ 0.00833 0.21666−0.74864 ∗ 0.00833 0.5−0.03140 ∗ 0.00833 0.10833−0 0 0 0.00833 0.10833 0.05 u1 20 u2 −4.39765 u3 = 1.70674 u4 1+4.39765 ∗ 0.00833 u5 1 1 2.16666 0.16666 0 0 u1 20 0 1 0.74864 0.03140 0 u2 −4.39765 0 0 0.39992 0.21042 0.00833 u3 = 1.70674 0 0.21042 0.499738 0.10833 u4 1.03663 0 0 0 0.00833 0.10833 0.05 u5 1 We have three zeros in words to generate A4,3 , A5,3 and in A5,4 For this we will use the third row, first scale it so that we get the value 1 on the diagonal 3rd = 3rd A13,3 1 2.16666 0 1 0 0 0 0 0 0 1 2.16666 0 1 0 0 0 0 0 0
1 = 3rd 0.39992 = 3rd 2.50050
0 0 u1 20 u2 −4.39765 0.03140 0 0.21042∗2.50050 0.00833∗2.50050 u3 = 1.70674∗2.50050 0.499738 0.10833 1.03663 u4 0.10833 0.05 u5 1 0 0 u1 20 0.03140 0 u2 −4.39765 0.52615 0.02082 u3 = 4.2677 0.499738 0.10833 u4 1.03663 0.10833 0.05 u5 1
0.16666 0.74864 0.39992∗2.50050 0.21042 0.00833 0.16666 0.74864 1 0.21042 0.00833
Now, the third row can be used to generate the zeros in the third column below the diagonal 4rd = 4rd − 3rd A4,3 = 4rd − 3rd 0.21042
Open AGH e-podręczniki - content available under the CC BY-SA license
90
4.1. Gaussian elimination algorithm 1 2.16666 0.16666 0 0 0 1 0.74864 0.03140 0 0 0 1 0.52615 0.02082 0 0.21042−1 ∗ 0.21042 0.499738−0.52615 ∗ 0.21042 0.10833−0.02082 ∗ 0.21042 0 0 0 0.00833 0.10833 0.05 u1 20 u2 −4.39765 u3 = 4.2677 u4 1.03663−4.2677 ∗ 0.21042 u5 1 1 2.16666 0.16666 0 0 0 1 0.74864 0.03140 0 0 0 1 0.52615 0.02082 0 0 0.38902 0.10395 0 0 0 0.00833 0.10833 0.05 u1 20 u2 −4.39765 u3 = 4.2677 u4 0.13862 u5 1 5th = 5th − 3rd A5,3 = 5th − 3rd 0.00833 1 2.16666 0.16666 0 0 0 1 0.74864 0.03140 0 0 0 1 0.52615 0.02082 0 0 0 0.38902 0.10395 0 0 0.00833−1 ∗ 0.0.00833 0.10833−0.52615 ∗ 0.00833 0.05−0.02082 ∗ 0.00833 u1 20 u2 −4.39765 u3 = 4.2677 0.13862 u4 u5 1−4.2677 ∗ 0.00833 1 2.16666 0.16666 0 0 0 1 0.74864 0.03140 0 0 0 1 0.52615 0.02082 0 0 0.38902 0.10395 0 0 0 0 0.10394 0, 04982 u1 20 u2 −4.39765 u3 = 4.2677 u 0.13862 4 u5 0, 96445 The last step is to scale the fourth row 1 4th = 4th A14,4 = 4th 0.38902 = 4th 2.57056 1 2.16666 0.16666 0 0 0 1 0.74864 0.03140 0 0 0 1 0.52615 0.02082 0 0 0.38902∗2.57056 0.10395∗2.57056 0 0 0 0 0.10394 0, 04982
Open AGH e-podręczniki - content available under the CC BY-SA license
91
4.1. Gaussian elimination algorithm u1 20 u2 −4.39765 u3 = 4.2677 u4 0.13862∗2.57056 u5 0, 96445 1 2.16666 0.16666 0 0 1 0.74864 0.03140 0 0 1 0.52615 0 0 1 0 0 0 0 0.10394 u1 20 u2 −4.39765 u3 = 4.2677 u4 0.35633 u5 0.96445 And finally we subtract the fourth A5,4
0 0 0.02082 0.26721 0, 04982
row from the fifth so that we get a zero in position
5th = 5th − 4th 0.10394 1 2.16666 0.16666 0 0 0 1 0.74864 0.03140 0 0 0 1 0.52615 0.02082 0 0 1 0.26721 0 0 0 0 0.010394−1 ∗ 0.010394&0, 04982−0.26721 ∗ 0.010394 u1 20 u2 −4.39765 u3 = 4.2677 0.35633 u4 u5 0.96445−2.43385 ∗ 0.010394 1 2.16666 0.16666 0 0 0 1 0.74864 0.03140 0 0 0 1 0.52615 0.02082 0 0 1 0.26721 0 0 0 0 0&0.04704 u1 20 u2 −4.39765 u3 = 4.2677 u4 0.35633 u5 0.93915 Finally, we can scale the fifth row to have a one on the diagonal 1 5th = 5th − A15,5 = 5th 0,04704 = 5th 21, 2585 1 2.16666 0.16666 0 0 0 1 0.74864 0.03140 0 0 0 1 0.52615 0.02082 0 0 1 0.26721 0 0 0 0 0&0.047042∗21, 2585
Open AGH e-podręczniki - content available under the CC BY-SA license
92
4.1. Gaussian elimination algorithm u1 20 u2 −4.39765 u3 = 4.2677 0.35633 u4 u5 0.93915 ∗ 21.258 1 2.16666 0.16666 0 0 0 1 0.74864 0.03140 0 0 0 1 0.52615 0.02082 0 0 1 0.26721 0 0 0 0 0&1 u1 20 u2 −4.39765 u3 = 4.2677 u4 0.35633 u5 19.96445 Thus, we have obtained the upper triangular matrix. The algorithm we performed step-by-step can be summarized as follows:
ALGORITHM
Algorithm 1: Gauss elimination algorithm 1 for irow=1,N //loop through rows 2 for icol=irow+1,N // row scalling 3 A(irow,icol)=A(irow,icol)/A(irow,irow) 4 end loop 5 b(irow)=b(irow)/A(irow,irow) 6 A(irow,irow)=1.0 7 for irow2=irow+1,N //row subtractions 8 for icol=irow2+1,N 9 A(irow2,icol) = A(irow2,icol) - A(irow2,irow)* A(irow,icol) 10 end loop 11 b(irow2)=b(irow2)-A(irow2,irow)*b(irow2) 12 A(irow2,irow)=0 13 end loop 14 end loop The last step is to run the back substitution algorithm to solve our equation system starting with the last equation.
Open AGH e-podręczniki - content available under the CC BY-SA license
93
4.1. Gaussian elimination algorithm
EXAMPLE
Example 5: Back substitution algorithm In other words, our system of equations 1 2.16666 0.16666 0 0 0 1 0.74864 0.03140 0 0 0 1 0.52615 0.02082 0 0 1 0.26721 0 0 0 0 0&1 u1 20 u2 −4.39765 u3 = 4.2677 u4 0.35633 u5 19.96445 We write 1u1 + 1u2 + 1u3 + 1u4 + 1u5 = 19.96445
2.16666u2 + 0.74864u3 + 0.52615u4 + 0.26721u5
0.16666u3 0.03140u4 0.02082u5
= = = =
20 −4.39765 4.2677 0.35633
And we solve from the last equation u5 = 19.96445 u4 = 0.35633 − 0.26721u5 = 0.35633 − 0.26721 ∗ 19.96445 = −4.97837 u3 = 4.2677 − 0.52615u4 − 0.02082u5 = 4.2677 − 0.52615 ∗ (−4.97837) − 0.02082 ∗ 19.96445 = 6.47140 u2 = −4.39765 − 0.74864u3 − 0.03140u4 = −4.39765 − 0.74864 ∗ 6.47140 − 0.03140 ∗ (−4.97837) = −2.61466 u1 = 20 − 2.16666u2 − 0.16666u3 = 20 − 2.16666 ∗ (−2.61466) − 0.16666 ∗ 6.47140 = 24.58655 Now let us make the following observations. If we run, for example, MATLAB (or the free version of OCTAVE) and introduce our matrix A=[1/20 13/120 1/120 0 0 ; 13/120 1/2 13/60 1/120 0; 1/120 13/60 11/20 13/60 1/120; 0 1/120 13/60 1/2 13/120; 0 0 1/120 13/120 1/120] and the rigth side vector b=[1 1 1 1 1] and solve the system of equations with a solver written in MATLAB (by Tim Davis from the University of Florida, where the operation of solving the system of equations is marked with a backslash /) we will get a slightly different solution x = A\b0 x=42.0588, -10.8824, 9.1176, -10.8824, 42.0588
Open AGH e-podręczniki - content available under the CC BY-SA license
94
4.1. Gaussian elimination algorithm The reason for this is that we have ignored the so-called pivoting in our algorithm. The Gaussian elimination algorithm works without pivoting when the matrix has some specific properties - that is, if it is symmetric and positively defined. If the matrix is not symmetric or not positively specified, the non-pivoting Gaussian elimination algorithm works in some cases and does not work in some cases. In our case, the matrix is symmetrical, but it is not positively defined, which is especially manifested by the fact that the words from the diagonal have greater values than the words from outside the diagonal. In our example this is not the case, for example the term A1,1 = 0.05 marked blue). 0.05 0.10833 0.10833 0.5 0.00833 0.21666 0.00833 0 0 0
in red are smaller than terms, for example // A1,2 = A2,1 = 0.10833(marked in 0.00833 0.21666 0.55 0.21666 0.00833
0 0 0.00833 0 0.21666 0.00833 0.5 0.10833 0.10833 0.05
In this case, the Gaussian elimination algorithm will make a mistake by dividing, for example, the first line by a small line on the diagonal A1,1 = 0.05 This is because we store our numbers on the computer in an approximate manner, for example truncating everything after the fifth decimal place. To correct our error, add pivoting to the Gaussian elimination algorithm. The Gaussian elimination algorithm is expensive. This means that for a matrix of size N rows and columns, it will do approximately N 3 operation. So what is the largest matrix we can process with the Gaussian elimination algorithm in 24 hours? As of today (January 2019), the processor clocks are around 3 GHz. This means that the processor can execute every second 3 × 109 additions or multiplications. Day has 24 ∗ 60 ∗ 60 = 86400 seconds. So the processor can do 86400 ∗ 109 = 86400000000000 addition and multiplication operations during the day. The root of the third degree of this number is 1 (86400000000000) 3 ≈ 44208 thus the largest matrix that we can process has a size of 44208. It represents a computational grid with 210 elements in each direction. So, it is a relatively small computational grid. We need better algorithms. Moreover, we conducted all our estimates assuming that the processor is not waiting for the data, but is processing it all the time, and that we have enough RAM and the optimal cache structure of the processor. Usually, the situation is not so ideal, so in practice it is difficult to process with Gaussian elimination matrices larger than 10,000 which corresponds to a 100 by 100 mesh. If there are multiple right-hand sides, it is necessary to perform Gaussian elimination again for each right-hand side. It is possible to save the numbers by which we multiply the right side, so as to perform the elimination only once, and only update for each new right side. This is done by the LU factorization algorithm. The Gaussian elimination algorithm does not leave out zeros. Multiplying zeros by nonzero numbers does not generally make sense, it is a waste of time. The Gaussian elimination algorithm can be accelerated by dropping all zeros. If we know a priori where the zeros are in the matrix, we can leave them out and speed up Gaussian elimination. This will be the subject of a frontal and multi-frontal algorithm. If the matrix has the structure of a Kronecker product of two smaller matrices (which was the case in the example from chapter one), then it is possible to use the alternating directions solver algorithm with linear computational complexity. If we are satisfied with the result with a certain accuracy, e.g. 0.0001, it is possible to calculate the approximate solution using so-called iterative algorithms. However, these algorithms do not work for all types of matrices.
Open AGH e-podręczniki - content available under the CC BY-SA license
95
4.2. Gaussian elimination with a pivoting algorithm
4.2.
Gaussian elimination with a pivoting algorithm
Let us start Gaussian elimination again for our example, this time with a row swap (also called ”pivoting”).
EXAMPLE
Example 6: Gaussian elimination algorithm with line swap
0.05 0.10833 0.00833 0 0
0.10833 0.00833 0.5 0.21666 0.21666 0.55 0.00833 0.21666 0 0.00833
0 0 u1 1 0.00833 0 u2 1 0.21666 0.00833 u3 = 1 0.5 0.10833 u4 1 0.10833 0.05 u5 1
We start with the row pivoting operation. In the first column (marked in blue and red) we are looking for the highest value per module. It is an expression A2,1 = 0.10833(marked in red). So we swap the first line with the second one 0.10833 0.5 0.21666 0.00833 0 u1 1 0.05 0.10833 0.00833 0 0 u2 1 0.00833 0.21666 0.55 0.21666 0.00833 u3 = 1 0.00833 0.21666 0.5 0.10833 u4 1 0 0 0 0.00833 0.10833 0.05 u5 1 Now, we are performing the step of the ”normal” Gaussian elimination algorithm. We scale the first row to get one on the diagonal 1 1st = 1st A1,1 = 1st 0.10833 = 1st 9.231053 0.10833∗9.23105 0.5∗9.23105 0.21666∗9.23105 0.00833∗9.23105 0∗9.23105 u1 u2 0.05 0.10833 0.00833 0 0 0.00833 0.21666 0.55 0.21666 0.00833 u3 0 0.00833 0.21666 0.5 0.10833 u4 0 0 0.00833 0.10833 0.05 u5 1∗9.23105 1 1 1 1 1 4, 61553 2.00006 0, 07693 0 u1 9.2311 0.05 0.10833 0.00833 0 0 u2 1 0.00833 0.21666 0.55 0.21666 0.00833 u3 = 1 0.00833 0.21666 0.5 0.10833 u4 1 0 0 0 0.00833 0.10833 0.05 u5 1
=
Then we subtract the first row from the second to get zero in position A2,1 2nd = 2nd − 1st A2,1 = 2nd − 1st 0.05
Open AGH e-podręczniki - content available under the CC BY-SA license
96
4.2. Gaussian elimination with a pivoting algorithm
1 4.61553 2 0.07693 0 0 0.10833−4.61553 ∗ 0.05 0.00833−2 ∗ 0.05 0−0.07693 ∗ 0.05 0 0.00833 0.21666 0.55 0.21666 0.00833 0.00833 0.21666 0.5 0.10833 0 0 0 0.00833 0.10833 0.05 u1 9.23105 u2 1−9.23105 ∗ 0.05 u3 = 1 1 u4 u5 1 1 4.61553 2 0.07693 0 u1 9.23105 0 −0.12244 −0.09167 −0, 00385 0 u2 0.53844 0.00833 0.21666 0.55 0.21666 0.00833 u3 = 1 0.00833 0.21666 0.5 0.10833 u4 1 0 0 0 0.00833 0.10833 0.05 u5 1 We now subtract the first row from the third to get zero in position A3,1 1 4.61553 2 0.07693 0 −0.12244 −0.09167 −0, 00385 3rd = 3rd −1st A3,1 = 3rd −1st 0.00833 0 0.21666−4.61552 ∗ 0.00833 0.55−2 ∗ 0.00833 0.21666−0.07689 ∗ 0.00833 0.00833 0.21666 0.5 0 0 0 0.00833 0.10833 u1 9.23105 u2 0.53844 u3 = 1−9.23105 ∗ 0.00833 1 u4 u5 1 1 4.61553 2 0.07693 0 u1 9.23105 0 −0.12244 −0.09167 −0, 00385 0 u2 0.53844 0 0.17821 0.53334 0.21603 0.00833 u3 = 0.92310 0.21666 0.5 0.10833 u4 1 0 0.00833 0 0 0.00833 0.10833 0.05 u5 1 We are now doing the row pivoting operation again. 1 4.61553 2 0.07693 0 u1 9.23105 0 −0.12244 −0.09167 −0, 00385 0 u2 0.53844 0 0.17821 0.53334 0.21603 0.00833 u3 = 0.92310 0.21666 0.5 0.10833 u4 1 0 0.00833 0 0 0.00833 0.10833 0.05 u5 1 In the second column from the diagonal down (marked in blue and red) we are looking for the highest value per module. It is an expression A(3,1)=0.17821 (marked in red) because |0.17821| > | − 0.12244| = 0.12244. So we swap the second row with the third one. 1 4.61553 2 0.07693 0 u1 9.23105 0 0.17821 0.53334 0.21603 0.00833 u2 0.92310 0 −0.12244 −0.09167 −0, 00385 0 u3 = 0.53844 0.21666 0.5 0.10833 u4 1 0 0.00833 0 0 0.00833 0.10833 0.05 u5 1
Open AGH e-podręczniki - content available under the CC BY-SA license
97
4.2. Gaussian elimination with a pivoting algorithm 1 Now, we scale the new second row to get one on the diagonal 2nd = 2nd A12,2 = 2nd 0.17821 = nd 2 5.61135 1 4.61553 2 0.07693 0 0 0.17821∗5.61135 0.53334∗5.61135 0.21603∗5.61135 0.00833∗5.61135 0 −0.12244 −0.09167 −0, 00385 0 0 0.00833 0.21666 0.5 0.10833 0 0 0.00833 0.10833 0.05 u1 9.23105 u2 0.92310∗5.61135 u3 = 0.53844 1 u4 u5 1 1 4.61553 2 0.07693 0 u1 9.23105 0 1 2.99275 1.21222 0.046742 u2 5.17983 0 −0.12244 −0.09167 −0, 00385 u3 = 0.53844 0 0.21666 0.5 0.10833 u4 1 0 0.00833 0 0 0.00833 0.10833 0.05 u5 1 We now subtract the second row from the third scaled to get zero in position A3,2 = −0.12244 3rd = 3rd − 2nd A3,2 = 3rd − 2nd (−0.12244) 1 4.61553 2 0.07693 0 0 1 2.99287 1.21226 0.04676 0 0 −0.09167+2.99275 ∗ 0.12244 −0, 00385+1.21222 ∗ 0.12244 0+0.046742 ∗ 0.12244 0 0.00833 0.21666 0.5 0.10833 0 0 0.00833 0.10833 0.05 u1 9.23105 u2 5.17983 u3 = 0.53844+5.17983 ∗ 0.12244 1 u4 u5 1 1 4.61553 2 0.07693 0 u1 9.23105 0 1 2.99287 1.21226 0.04676 u2 5.1800 0 0 0.27479 0.14459 0.00573 u3 = 1.1727 0.5 0.10833 u4 1 0 0.00833 0.21666 0 0 0.00833 0.10833 0.05 u5 1
Likewise, we subtract the second row from the fourth 4th = 4th − 2nd A(4,2 = 4th − 2nd 0.00833 1 4.61553 2 0.07693 0 0 1 2.99287 1.21226 0.04676 0 0 0.27476 0.14457 0.005723 0 0.21666−2.99275 ∗ 0.00833 0.5−1.21210 ∗ 0.00833 0.10833−0.046742 ∗ 0.00833 0 0 0 0.00833 0.10833 0.05 u1 9.23105 u2 5.17983 u3 = 1.17265 u4 1−5.17983 ∗ 0.00833 u5 1
Open AGH e-podręczniki - content available under the CC BY-SA license
98
4.2. Gaussian elimination with a pivoting algorithm 1 0 0 0 0
4.61553 2 0.07693 1 2.99287 1.21226 0 0.27476 0.14457 0 0.19173 0.48990 0 0.00833 0.10833
0 u1 9.23105 0.04676 u2 5.17999 0.005723 u3 = 1.17270 0.10794 u4 0.95684 0.05 u5 1
We are left with a 3 by 3 sub matrix in the lower right corner, for which we continue Gaussian elimination with row pivoting. We first look for the maximum (per module) value in the third column from the diagonal down (marked in red andblue). It is the value from the diagonal A3,3 marked 1 4.61553 2 0.07693 0 u1 0 1 2.99287 1.21226 0.04676 u2 in red, so we don’t need to swap the rows. = 0 0.27476 0.14457 0.005723 0 u3 0 0.19173 0.48990 0.10794 u4 0 0 0 0.00833 0.10833 0.05 u5 9.23105 5.17983 1.17265 0.95685 1 We now scale row three to get one on the diagonal 3rd = 3rd A13,3 1 4.61553 0 1 0 0 0 0 0 0 1 4.61553 0 1 0 0 0 0 0 0
1 = 3rd 0.27476 = 3rd 3.63953
2 2.99287 0.27476∗3.63953 0.19173 0.00833 2 0.07693 2.99287 1.21226 1 0.52617 0.19173 0.48990 0.00833 0.10833
0.07693 0 u1 9.23105 u2 1.21226 0.04676 5.17983 u3 = 1.17265∗3.63953 0.14457∗3.63953 0.005723∗3.63953 0.48990 0.10794 0.95685 u4 0.10833 0.05 u5 1 0 u1 9.23105 0.04676 u2 5.17999 0.02082 u3 = 4.26763 0.10794 u4 0.95683 0.05 u5 1
We will now use the third row to generate the zeros in the third column below the diagonal 4th = 4th − 3rd A4,3 = 4th − 3rd 0.19173 1 4.61553 2 0.07693 0 1 2.99287 1.21226 0 0 1 0.52617 0 0 0.48990−0.52618 ∗ 0.19173 0 0 0 0.00833 0.10833 u1 9.23105 u2 5.17983 u3 = 4.26789 u4 0.95685−4.26789 ∗ 0.19173 u5 1
0 0.04676 0.02082 0.10794−0.02083 ∗ 0.19173 0.05
Open AGH e-podręczniki - content available under the CC BY-SA license
99
4.2. Gaussian elimination with a pivoting algorithm 1 0 0 0 0
4.61553 2 0.07693 0 u1 9.23105 1 2.99287 1.21226 0.04676 u2 5.17983 0 1 0.52617 0.02082 u3 = 4.26789 0 0 0.38901 0.10395 u4 0.13860 0 0.00833 0.10833 0.05 u5 1
5th = 5th − 3rd A5,3 = 5th − 3rd 0.00833 1 4.61553 2 0.07693 0 0 1 2.99287 1.21226 0.04676 0 0 1 0.52617 0.02082 0 0 0.38901 0.10395 0 0 0 0 0.10833−0.52618 ∗ 0.00833 0.05−0.02082 ∗ 0.00833 u1 9.23105 u2 5.17983 u3 = 4.26789 0.13860 u4 u5 1−4.26789 ∗ 0.00833 1 4.61553 2 0.07693 0 u1 9.23105 0 1 2.99287 1.21226 0.04676 u2 5.17983 0 0 1 0.52617 0.02082 u3 = 4.26789 0 0 0.38901 0.10395 u4 0.13860 0 0 0 0 0.10395 0.04983 u5 0.96445 Then we scale the fourth row so that it has a one on the diagonal 1 4th = 4th A14,4 = 4th 0.38901 = 4th 2.5706 1 4.61553 2 0.07693 0 u1 9.23105 0 u2 1 2.99287 1.21226 0.04676 5.17983 0 0 1 0.52617 0.02082 4.26789 u3 = 0 0 0 0.38365∗2.5706 0.10395∗2.5706 u 0.13860 ∗ 2.5706 4 0 0 0 0.10395 0.04982 u5 0.91110 1 4.61553 2 0.07693 0 u1 9.23105 0 5.17983 1 2.99287 1.21226 0.04676 u2 0 0 1 0.52617 0.02082 u3 = 4.26789We will now use the fourth row to 0 0 1 0.26721 u4 0 0.35629 0 0 0 0.10395 0.04983 u5 0.96444 generate a zero in the fourth column below the diagonal 5th = 5th − 4rd A5,4 = 5th − 4rd 0.10395 1 4.61553 2 0.07693 0 0 1 2.99287 1.21226 0.04676 0 0 1 0.52617 0.02082 0 0 1 0.26721 0 0 0 0 0 0.04983−0.26721 ∗ 0.10395 u1 9.23105 u2 5.17983 u3 = 4.26789 0.35629 u4 u5 0.96444−0.35629 ∗ 0.10395
Open AGH e-podręczniki - content available under the CC BY-SA license
100
4.2. Gaussian elimination with a pivoting algorithm 1 4.61553 2 0.07693 0 0 1 2.99287 1.21226 0.04676 0 0 1 0.52617 0.02082 0 0 1 0.26721 0 0 0 0 0 0.022053 u1 9.23105 u2 5.17983 u3 = 4.26789 u4 0.35629 u5 0.92740 Finally, we scale the fifth row so that it has a one on the diagonal 1 5th = 5th A15,5 = 5th 0.022053 = 5th 45.351 1 4.61553 2 0.07693 0 0 1 2.99287 1.21226 0.04676 0 0 1 0.52617 0.02082 0 0 1 0.26721 0 0 0 0 0 1 u1 9.23105 u2 5.17983 u3 = 4.26789 0.35629 u4 u5 0.92740∗45.351 1 4.61553 2 0.07693 0 0 1 2.99287 1.21226 0.04676 0 0 1 0.52617 0.02082 0 0 1 0.26721 0 0 0 0 0 1 u1 9.23105 u2 5.17983 u3 = 4.26789 u4 0.35629 u5 42.059 Writes 1u1 + 4.61553u2 + 2u3 + 0.07693u4 1u2 + 2.99287u3 + 1.21226u4 + 0.04676u5 1u3 + 0.52617u4 + 0.02082u5 1u4 + 0.26721u5 = 1u5 = 42.059
= = =
9.23105 5.17983 4.26789 0.35629
And we solve from the last equation u5 = 42.059 u4 = 0.35629 − 0.26721u5 = 0.35629 − 0.26721 ∗ 42.059 = −10.88229 u3 = 4.26789 − 0.52617u4 − 0.02082u5 = 4.26789 − 0.52617−10.88229 − 0.0208242.059 = 9.11815 u2 = 5.17983 − 2.99287u3 − 1.21226u4 − 0.04676u5 = = 5.17983 − 2.992879.11815 − 1.21226−10.88229 − 0.0467642.059 = −10, 88412 u1 = 9.23105 − 4.61553u2 − 2u3 − 0.07693u4 = 42.0679 This time our solution is correct. The Gaussian elimination algorithm should be enriched with row pivoting.
Open AGH e-podręczniki - content available under the CC BY-SA license
101
4.3. LU factorization algorithm
ALGORITHM
Algorithm 2: Gaussian elimination algorithm with line swap 1 for irow=1,N //loop by line 2 Find the largest value in a column A(row:N,irow) 3 Mark the row with the highest irowmax value 4 Swap rows irow, irowmax 5 for icol=irow+1,N // row scaling 6 A(irow,icol)=A(irow,icol)/A(irow,irow) 7 end loop 8 b(irow)=b(irow)/A(irow,irow) 9 A(irow,irow)=1.0 10 for irow2=irow+1,N //line subtraction 11 for icol=irow2+1,N 12 A(irow2,icol) = A(irow2,icol) - A(irow2,irow)* A(irow,icol) 13 end loop 14 b(irow2)=b(irow2)-A(irow2,irow)*b(irow2) 15 A(irow2,irow)=0 16 end loop 17end loop
4.3.
LU factorization algorithm
The LU factorization algorithm was invented by the Polish mathematician Tadeusz Banachiewicz in 1938 (a professor of astronomy working at Jagiellonian University and AGH University in Krakow), which is described in [18]. Note that the Gaussian elimination algorithm generates an upper triangular matrix U . It is also possible to generate a bottom triangular matrixL such that the original matrix of our problem A = LU . What is the advantage of having such a decomposition? Suppose we want to solve two problems for two right-hand sides b1 , b2 . Let’s also assume that we know the right side at the beginning b1 and that the other right-hand side b2 we will only know the other right-hand side b2 after solving the problem for the first right-hand side. Is there any way to use matrix factorization? A made for the previous right page b1 ? First we compute the LU factorization of the matrix A = LU then we have the equation LU x = b1 . We calculate first z by performing a forward substitution from equation Lz = b1 . Then we calculate x by solving the equation U x = z by backward substitution.
EXAMPLE
Open AGH e-podręczniki - content available under the CC BY-SA license
102
4.3. LU factorization algorithm
Example 7: LU factorization algorithm Let us see how to modify the Gaussian elimination algorithm to generate both matrices L i U . In order to obtain a matrixU , we run the usual Gauss elimination algorithm (but without the right-hand side). We obtain Matrix L by remembering the numbers by which we multiply each line during elimination. Initially 1 0 L= 0 0 0
0 1 0 0 0
0 0 1 0 0
0 0 0 1 0
0 0 0 0 1
and
0.05 0.10833 0.00833 0 0 0.10833 0.5 0.21666 0.00833 0 U = 0.55 0.21666 0.00833 0.00833 0.21666 0.00833 0.21666 0.5 0.10833 0 0 0 0.00833 0.10833 0.05 During each multiplication, we update the matrix L 1 1st = 1st A11,1 = 1st 0.05 = 1st 20 0.05 ∗ 20 0.10833 ∗ 20 0.00833 ∗ 20 0 ∗ 20 0 ∗ 20 0.10833 0.5 0.21666 0.00833 0 U = 0.21666 0.55 0.21666 0.00833 0.00833 0 0.00833 0.21666 0.5 0.10833 0 0 0.00833 0.10833 0.05 In particular, we put the words from the diagonal of the original matrix on the diagonal. 0.05 0 0 0 0 0 1 0 0 0 L= 0 1 0 0 0 0 0 1 0 0 0 0 0 0 1 1 2.16666 0.16666 0 0 0.10833 0.5 0.21666 0.00833 0 U = 0.55 0.21666 0.00833 0.00833 0.21666 0.00833 0.21666 0.5 0.10833 0 0 0 0.00833 0.10833 0.05 When subtracting lines, into the matrix U we insert the number used to scale the line 2nd = 2nd −1st ∗ A2,1 = 2nd − 1st ∗ 0.10833. 0.05 0 0 0 0 0.10833 1 0 0 0 L= 0 1 0 0 0 0 0 1 0 0 0 0 0 0 1
Open AGH e-podręczniki - content available under the CC BY-SA license
103
4.3. LU factorization algorithm
1 0.10833 − 1 ∗ 0.10833 U 0.00833 0 0 1 2.16666 0 0.26528 U = 0.00833 0.21666 0.00833 0 0 0
2.16666 0.5 − 2.16666 ∗ 0.10833 0.21666 0.00833 0 0.16666 0.19860 0.55 0.21666 0.00833
0.16666 0 0.21666 − 0.16666 ∗ 0.10833 0.00833 0.55 0.21666 0.21666 0.5 0.00833 0.10833
0 0 0.00833 0.10833 0.05
0 0 0.00833 0 0.21666 0.00833 0.5 0.10833 0.10833 0.05
3rd = 3rd − 1st A3,1 = 3rd − 1st 0.00833 0.05 0 0 0 0 0.10833 1 0 0 0 L= 0.00833 0 1 0 0 0 0 1 0 0 0 0 0 0 1 1 2.16666 0 0.26528 U = 0.00833 − 1 ∗ 0.00833 0.21666 − 2.16666 ∗ 0.00833 0 0.00833 0 0 1 2.16666 0.16666 0 0 0 0.26528 0.19860 0.00833 0 U = 0.19861 0.54861 0.21666 0.00833 0.5 0.10833 0 0.00833 0.21666 0 0 0.00833 0.10833 0.05
0.16666 0 0 0.19860 0.00833 0 0.55 − 0.16666 ∗ 0.00833 0.21666 0.00833 0.21666 0.5 0.10833 0.00833 0.10833 0.05
1 2nd = 2nd A12,2 = 2nd 0.26528 = 2nd 3.76963 0.05 0 0 0 0 0.10833 0.26528 0 0 0 L= 0 1 0 0 0.00833 0 0 1 0 0 0 0 0 0 1 1 2.16666 0.16666 0 0 0 0.26528 ∗ 3.76963 0.19860 ∗ 3.76963 0.00833 ∗ 3.76963 0 U = 0.19861 0.54861 0.21666 0.00833 0 0 0.00833 0.21666 0.5 0.10833 0 0 0.00833 0.10833 0.05 1 2.16666 0.16666 0 0 0 1 0.74864 0.03140 0 U = 0 0.19861 0.54861 0.21666 0.00833 0.5 0.10833 0 0.00833 0.21666 0 0 0.00833 0.10833 0.05
3rd = 3rd − 2nd A3,2 = 3rd − 2st 0.19861
Open AGH e-podręczniki - content available under the CC BY-SA license
104
4.3. LU factorization algorithm
0.05 0 0 0 0 0.10833 0.26528 0 0 0 L= 0.00833 0.19861 1 0 0 0 0 1 0 0 0 0 0 0 1 1 2.16666 0.16666 0 1 0.74864 U = 0 0.19861 − 1 ∗ 0.19861 0.54861 − 0.74864 ∗ 0.19861 0.00833 0.21666 0 0 0 0.00833 1 2.16666 0.16666 0 0 0 1 0.74864 0.03140 0 U = 0 0.39992 0.21042 0.00833 0 0.5 0.10833 0 0.00833 0.21666 0 0 0.00833 0.10833 0.05 4th = 4th − 2nd A4,2 = 4th − 2nd 0.00833 0.05 0 0 0 0 0.10833 0.26528 0 0 0 L= 0.00833 0.19861 1 0 0 0.00833 0 1 0 0 0 0 0 0 1 1 2.16666 0.16666 0 1 0.74864 U = 0 0 0.39992 0 0.00833 − 1 ∗ 0.00833 0.21666 − 0.74864 ∗ 0.00833 0 0 0.00833 1 2.16666 0.16666 0 0 0 1 0.74864 0.03140 0 U = 0 0.39992 0.21042 0.00833 0 0 0.21042 0.499738 0.10833 0 0 0 0.00833 0.10833 0.05 1 3rd = 3rd A13,3 = 3rd 0.39992 = 3rd 2.50050 0.05 0 0 0 0 0.10833 0.26528 0 0 0 L= 0.00833 0.19861 0.39992 0 0 0.00833 0 1 0 0 0 0 0 0 1 1 2.16666 0.16666 0 0 1 0.74864 0.03140 U = 0 0 0.39992 ∗ 2.50050 0.21042 0 0.21042 0.499738 0 0 0 0.00833 0.10833
0 0 0.03140 0 0.21666 − 0.03140 ∗ 0.19861 0.00833 0.5 0.10833 0.10833 0.05
0 0 0.03140 0 0.21042 0.00833 0.5 − 0.03140 ∗ 0.00833 0.10833 0.10833 0.05
0 0 0.00833 ∗ 2.50050 0.10833 0.05
Open AGH e-podręczniki - content available under the CC BY-SA license
105
4.3. LU factorization algorithm 1 0 U = 0 0 0
2.16666 0.16666 1 0.74864 0 1 0 0.21042 0 0.00833
0 0.03140 0.52615 0.499738 0.10833
0 0 0.02082 0.10833 0.05
4rd = 4rd − 3rd A4,3 = 4rd − 3rd 0.21042 0.05 0 0 0 0 0.10833 0.26528 0 0 0 L= 0.00833 0.19861 0.39992 0 0 0.00833 0.21042 1 0 0 0 0 0 0 1 1 2.16666 0.16666 0 0 1 0.74864 0.03140 U = 0 1 0.52615 0 0 0 0.21042 − 1 ∗ 0.21042 0.499738 − 0.52615 ∗ 0.21042 0 0 0.00833 0.10833 1 2.16666 0.16666 0 0 0 1 0.74864 0.03140 0 U = 0 1 0.52615 0.02082 0 0 0 0.38902 0.10395 0 0 0 0.00833 0.10833 0.05 5th = 5th − 3rd ∗ A5,3 = 5th − 3rd 0.00833 0.05 0 0 0 0 0.10833 0.26528 0 0 0 L= 0.00833 0.19861 0.39992 0 0 0.00833 0.21042 1 0 0 0 0 0.00833 0 1 1 2.16666 0.16666 0 0 1 0.74864 0.03140 U = 0 0 1 0.52615 0 0 0.38902 0 0 0 0.00833 − 1 ∗ 0.0.00833 0.10833 − 0.52615 ∗ 0.00833 1 2.16666 0.16666 0 0 0 1 0.74864 0.03140 0 U = 0 1 0.52615 0.02082 0 0 0 0.38902 0.10395 0 0 0 0 0.10394 0.04982 1 4th = 4th A14,4 = 4th 0.38902 = 4th 2.57056 0.05 0 0 0 0.10833 0.26528 0 0 L= 0 0.00833 0.19861 0.39992 0.00833 0.21042 0.38902 0 0 0 0.00833 0
0 0 0.02082 0.10833 − 0.02082 ∗ 0.21042 0.05
0 0 0.02082 0.10395 0.05 − 0.02082 ∗ 0.00833
0 0 0 0 1
Open AGH e-podręczniki - content available under the CC BY-SA license
106
4.3. LU factorization algorithm 1 0 U = 0 0 0 1 0 U = 0 0 0
2.16666 0.16666 1 0.74864 0 1 0 0 0 0
0 0.03140 0.52615 2.57056 ∗ 0.38902 0.10394
0 0 0.02082 2.57056 ∗ 0.10395 0, 04982
2.16666 0.16666 0 0 1 0.74864 0.03140 0 0 1 0.52615 0.02082 0 0 1 0.26721 0 0 0.10394 0.04982
5th = 5th − 4th ∗ 0.10394 0.05 0 0 0 0 0.10833 0.26528 0 0 0 L= 0 0 0.00833 0.19861 0.39992 0.00833 0.21042 0.38902 0 0 0 0 0.00833 0.10394 1 1 2.16666 0.16666 0 0 1 0.74864 0.03140 U = 0 1 0.52615 0 0 0 1 0 0 0 0 0.010394 − 1 ∗ 0.010394 1 2.16666 0.16666 0 0 0 1 0.74864 0.03140 0 U = 0 1 0.52615 0.02082 0 0 0 0 1 0.26721 0 0 0 0 0.04704
0 0 0.02082 0.26721 0.04982 − 0.26721 ∗ 0.010394
1 5th = 5th − A15,5 = 5th 0,04704 = 5th ∗ 21.2585 0.05 0 0 0 0 0.10833 0.26528 0 0 0 L= 0 0 0.00833 0.19861 0.39992 0.00833 0.21042 0.38902 0 0 0 0 0.00833 0.10394 0.047042 1 2.16666 0.16666 0 0 0 1 0.74864 0.03140 0 U = 0 1 0.52615 0.02082 0 0 0 1 0.26721 0 0 0 0 0&0.047042 ∗ 21.2585
As a result, we got 0.05 0.10833 L∗U = 0.00833 0 0
the following matrices L i U . 0 0 0.26528 0 0.19861 0.39992 0.00833 0.21042 0 0.00833
0 0 0 0.38902 0.10394
0 1 0 0 ∗0 0 0 0 0.047042 0
2.16666 0.16666 0 0 1 0.74864 0.03140 0 0 1 0.52615 0.02082 0 0 1 0.26721 0 0 0&1
To verify our algorithm, we can finally check that LU = A.
Open AGH e-podręczniki - content available under the CC BY-SA license
107
4.4. Algorithm of LU factorization with pivoting
4.4.
Algorithm of LU factorization with pivoting
How to convert Gaussian elimination with pivoting to LU factorization with pivoting? An additional matrix must be entered P that is responsible for pivoting.
EXAMPLE
Example 8: Algorithm of LU factorization with pivoting We start from 1 0 0 0 0 0 1 0 0 0 P= 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 1 0 0 0 0 0 1 0 0 0 L= 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 0.05 0.10833 0.00833 0 0 0.10833 0.5 0.21666 0.00833 0 U= 0.55 0.21666 0.00833 0.00833 0.21666 0.00833 0.21666 0.5 0.10833 0 0 0 0.00833 0.10833 0.05 In the first step, we do a pivot in the first column U, so we swap the first and the second rows. We markit by swapping the first and second lines in the matrix P. 1 0 0 0 0 0 1 0 0 0 L= 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 Additionally we swap rows in U 0.10833 0.5 0.21666 0.00833 0 0.05 0.10833 0.00833 0 0 U= 0.55 0.21666 0.00833 0.00833 0.21666 0.00833 0.21666 0.5 0.10833 0 0 0 0.00833 0.10833 0.05 Then we scale the new first row, storing the value from the diagonal of the matrix U in matrix L. 1 1st = 1st ∗ A(1, 1) = 1st 0.10833 = 1st ∗ 9.231053 0.10833 ∗ 9.23105 0.5 ∗ 9.23105 0.21666 ∗ 9.23105 0.05 0.10833 0.00833 U= 0.00833 0.21666 0.55 0 0.00833 0.21666 0 0 0.00833
0.00833 ∗ 9.23105 0 0 0 0.21666 0.00833 0.5 0.10833 0.10833 0.05
Open AGH e-podręczniki - content available under the CC BY-SA license
108
4.4. Algorithm of LU factorization with pivoting 0.10833 0 0 0 0 0 1 0 0 0 L= 0 1 0 0 0 0 0 1 0 0 0 0 0 0 1 1 4.61553 2.00006 0.07693 0 0.05 0.10833 0.00833 0 0 U= 0.55 0.21666 0.00833 0.00833 0.21666 0.00833 0.21666 0.5 0.10833 0 0 0 0.00833 0.10833 0.05 We subtract rows by writing the value at the beginning of the row to be eliminated in the corresponding row in the matrix L(denoted in blue) nd st 2nd = 2nd − 1st ∗ 0.05 2 − 1 ∗ A(2, 1) = 0.10833 0 0 0 0 0.05 1 0 0 0 L= 0 1 0 0 0 0 0 1 0 0 0 0 0 0 1 1 4.61553 2 0.07693 0 0 0.10833 − 4.61553 ∗ 0.05 0.00833 − 2 ∗ 0.05 0 − 0.07693 ∗ 0.05 0 U= 0.21666 0.55 0.21666 0.00833 0.00833 0.00833 0.21666 0.5 0.10833 0 0 0 0.00833 0.10833 0.05 1 4.61553 2 0.07693 0 0 −0.12244 −0.09167 −0, 00385 0 U= 0.55 0.21666 0.00833 0.00833 0.21666 0.00833 0.21666 0.5 0.10833 0 0 0 0.00833 0.10833 0.05 rd rd st rd st 3 = 3 − 1 ∗ A(3, 1) = 3 − 1 ∗ 0.00833 0.10833 0 0 0 0 0.05 1 0 0 0 L= 0.00833 0 1 0 0 0 0 1 0 0 0 0 0 0 1 1 4.61553 2 0.07693 0 0 −0.12244 −0.09167 −0, 00385 0 U = 0 0.21666 − 4.61552 ∗ 0.00833 0.55 − 2 ∗ 0.00833 0.21666 − 0.07689 ∗ 0.00833 0.00833 − 0 0.00833 0.21666 0.5 0.10833 0 0 0 0.00833 0.10833 0.05 1 4.61553 2 0.07693 0 0 −0.12244 −0.09167 −0, 00385 0 U= 0.53334 0.21603 0.00833 0 0.17821 0.21666 0.5 0.10833 0 0.00833 0 0 0.00833 0.10833 0.05 We now pivot the second column again, replacing the second row with the third because |0.17821| > |−0.12244| = 0.12244. We replace the columns in the matrix U
Open AGH e-podręczniki - content available under the CC BY-SA license
109
4.4. Algorithm of LU factorization with pivoting 1 4.61553 2 0.07693 0 0 0.17821 0.53334 0.21603 0.00833 U= 0 0 −0.12244 −0.09167 −0, 00385 0.21666 0.5 0.10833 0 0.00833 0 0 0.00833 0.10833 0.05 We mark it by swapping the second and third rows in the matrix P 0 1 0 0 0 0 0 1 0 0 P= 1 0 0 0 0 0 0 0 1 0 0 0 0 0 1 Now we scale the new second row, saving the value from the diagonal in the matrix L 1 4.61553 2 0.07693 0 0 0.17821 0.53334 0.21603 0.00833 U= 0 0 −0.12244 −0.09167 −0, 00385 0.21666 0.5 0.10833 0 0.00833 0 0 0.00833 0.10833 0.05 nd nd nd 2nd = 2 /A(2, 2) = 2 /0.17821 = 2 ∗ 5.61135 0.10833 0 0 0 0 0.05 0.17821 0 0 0 L= 0 1 0 0 0.00833 0 0 1 0 0 0 0 0 0 1 1 4.61553 2 0.07693 0 0 0.17821 ∗ 5.61135 0.53334 ∗ 5.61135 0.21603 ∗ 5.61135 0.00833 ∗ 5.61135 U= −0.12244 −0.09167 −0, 00385 0 0 0.00833 0.21666 0.5 0.10833 0 0 0 0.00833 0.10833 0.05 1 4.61553 2 0.07693 0 0 1 2.99275 1.21222 0.046742 U= 0 0 −0.12244 −0.09167 −0, 00385 0.21666 0.5 0.10833 0 0.00833 0 0 0.00833 0.10833 0.05 We subtract the rows and write the values at the beginning of the rows in the matrix L rd nd rd nd 3rd = 3 − 2 ∗ A(3, 2) = 3 − 2 ∗ (−0.12244) 0.10833 0 0 0 0 0.05 0.17821 0 0 0 L= 0.00833 −0.12244 1 0 0 0 0 1 0 0 0 0 0 0 1 1 4.61553 2 0.07693 0 0 1 2.99287 1.21226 0.04676 U = 0 0 −0.09167 + 2.99275 ∗ 0.12244 −0, 00385 + 1.21222 ∗ 0.12244 0 + 0.046742 ∗ 0.12244 0.21666 0.5 0.10833 0 0.00833 0 0 0.00833 0.10833 0.05
Open AGH e-podręczniki - content available under the CC BY-SA license
110
4.4. Algorithm of LU factorization with pivoting 1 4.61553 2 0.07693 0 0 1 2.99287 1.21226 0.04676 U= 0 0.27479 0.14459 0.00573 0 0.5 0.10833 0 0.00833 0.21666 0 0 0.00833 0.10833 0.05 4th = 4th − 2nd ∗ A(4, 2) = 4th − 2nd ∗ 0.00833 0.10833 0 0 0 0 0.05 0.17821 0 0 0 L= 0.00833 −0.12244 1 0 0 0.00833 0 1 0 0 0 0 0 0 1 1 4.61553 2 0.07693 0 0 1 2.99287 1.21226 0.04676 U = 0 0 0.27476 0.14457 0.005723 0 0 0.21666 − 2.99275 ∗ 0.00833 0.5 − 1.21210 ∗ 0.00833 0.10833 − 0.046742 ∗ 0.00833 0 0 0.00833 0.10833 0.05 1 4.61553 2 0.07693 0 0 1 2.99287 1.21226 0.04676 U= 0 0.27476 0.14457 0.005723 0 0.19173 0.48990 0.10794 0 0 0 0.00833 0.10833 0.05 In the third column, you don’t have to do pivoting because the value from the diagonal A(3, 3) = 0.27476(denoted in red) is the largest, so we do not need to swap the rows in U neither in P So we scale the third row by writing the appropriate value in the matrix L. 1 4.61553 2 0.07693 0 0 1 2.99287 1.21226 0.04676 U= 0 0.27476 0.14457 0.005723 0 0.19173 0.48990 0.10794 0 0 0 0.00833 0.10833 0.05 rd rd rd rd 3 = 3 /A(3, 3) = 3 /0.27476 = 3 ∗ 3.63953 0.10833 0 0 0 0 0.05 0.17821 0 0 0 L= 0.00833 −0.12244 0.27476 0 0 0.00833 0 1 0 0 0 0 0 0 1 1 4.61553 2 0.07693 0 0 1 2.99287 1.21226 0.04676 U = 0 0 0.27476 ∗ 3.63953 0.14457 ∗ 3.63953 0.005723 ∗ 3.63953 0 0.19173 0.48990 0.10794 0 0 0 0.00833 0.10833 0.05 We eliminate the rows by writing the appropriatevalues into the matrix L 1 4.61553 2 0.07693 0 0 1 2.99287 1.21226 0.04676 U= 0 1 0.52617 0.02082 0 0 0.19173 0.48990 0.10794 0 0 0 0.00833 0.10833 0.05 4th = 4th − 3rd ∗ A(4, 3) = 4th − 3rd ∗ 0.19173
Open AGH e-podręczniki - content available under the CC BY-SA license
111
4.4. Algorithm of LU factorization with pivoting 0.10833 0 0 0 0 0.05 0.17821 0 0 0 L= 0.00833 −0.12244 0.27476 0 0 0.00833 0.19173 1 0 0 0 0 0 0 1 1 4.61553 2 0.07693 0 0 1 2.99287 1.21226 0.04676 U= 0 1 0.52617 0.02082 0 0 0 0.48990 − 0.52618 ∗ 0.19173 0.10794 − 0.02083 ∗ 0.19173 0 0 0 0.00833 0.10833 0.05 1 4.61553 2 0.07693 0 0 1 2.99287 1.21226 0.04676 U= 0 1 0.52617 0.02082 0 0 0 0.38901 0.10395 0 0 0 0.00833 0.10833 0.05 th th rd th rd 5 = 5 − 3 ∗ A(5, 3) = 5 − 3 ∗ 0.00833 0.10833 0 0 0 0 0.05 0.17821 0 0 0 L= 0.00833 −0.12244 0.27476 0 0 0.00833 0.19173 1 0 0 0 0 0.00833 0 1 1 4.61553 2 0.07693 0 0 1 2.99287 1.21226 0.04676 U = 0 0 1 0.52617 0.02082 0 0 0.38901 0.10395 0 0 0 0 0.10833 − 0.52618 ∗ 0.00833 0.05 − 0.02082 ∗ 0.00833 1 4.61553 2 0.07693 0 0 1 2.99287 1.21226 0.04676 U= 0 1 0.52617 0.02082 0 0 0 0.38901 0.10395 0 0 0 0 0.10395 0.04983 We scale the fourth row by saving the appropriate value in the matrix L 4th = 4th 1/A(4, 4) = 4th /0.38901 = 4th ∗ 2.5706 0.10833 0 0 0 0 0.05 0.17821 0 0 0 L= 0 0 0.00833 −0.12244 0.27476 0.00833 0.19173 0.38901 0 0 0 0 0.00833 0 1 1 4.61553 2 0.07693 0 0 1 2.99287 1.21226 0.04676 U = 0 0 1 0.52617 0.02082 0 0 0.38901 ∗ 2.5706 0.10395 ∗ 2.5706 0 0 0 0 0.10395 0.04982 We eliminate rows by writing the appropriate values in the matrix L
Open AGH e-podręczniki - content available under the CC BY-SA license
112
4.5. Frontal solver algorithm 1 4.61553 2 0.07693 0 0 1 2.99287 1.21226 0.04676 U= 0 1 0.52617 0.02082 0 0 0 1 0.26721 0 0 0 0 0.10395 0.04983 5th = 5th − 4rd ∗ A(5, 4) = 5th − 4rd ∗ 0.10395 0.10833 0 0 0 0 0.05 0.17821 0 0 0 L= 0 0 0.00833 −0.12244 0.27476 0.00833 0.19173 0.38901 0 0 0 0 0.00833 0.10395 1 1 4.61553 2 0.07693 0 0 1 2.99287 1.21226 0.04676 U = 0 0 1 0.52617 0.02082 0 0 0 1 0.26721 0 0 0 0 0.04983 − 0.26721 ∗ 0.10395 We scale the fifth row by saving the appropriate value in the matrix L 1 4.61553 2 0.07693 0 0 1 2.99287 1.21226 0.04676 U= 0 1 0.52617 0.02082 0 0 0 1 0.26721 0 0 0 0 0 0.022053 5th = 5th /A(5, 5) = 5th /0.022053 = 5th ∗ 45.351 0.10833 0 0 0 0 0.05 0.17821 0 0 0 L = 0.00833 −0.12244 0.27476 0 0 0 0.00833 0.19173 0.38901 0 0 0 0.00833 0.10395 0.022053 1 4.61553 2 0.07693 0 0 1 2.99287 1.21226 0.04676 U= 0 1 0.52617 0.02082 0 0 0 1 0.26721 0 0 0 0 0 1 We have got the following LUP decomposition of the matrix A 0.10833 0 0 0.05 0.17821 0 0.00833 −0.12244 0.27476 LUP = 0.00833 0.19173 0 0 0 0.00833 1 4.61553 2 0.07693 0 0 1 0 0 0 0 1 2.99287 1.21226 0.04676 0 0 1 0 0 0 0 1 0.52617 0.02082 ∗ 1 0 0 0 0 0 0 1 0.26721 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 1 We can check its correctness LUP = A.
4.5.
0 0 0 0.38901 0.10395
0 0 0 0 0.022053
∗
Frontal solver algorithm
The frontal solver algorithm was the first algorithm to modify Gaussian elimination using additional knowledge of the finite element method. The aim of the algorithm’s modification was to avoid the zeros in Open AGH e-podręczniki - content available under the CC BY-SA license
113
4.5. Frontal solver algorithm the matrix resulting from interactions between basis functions located far from each other and spread on a computational grid. This algorithm was proposed by Bruce Irons in 1970. Bruce Irons gained worldwide fame after inventing this algorithm [19]. His scientific results deserve even more recognition, because he struggled with multiple sclerosis. The idea of the algorithm is to generate local matrices resulting from the interaction of basis functions on individual finite elements. Instead of generating the entire matrix or the entire system of equations, we arrange the finite elements in the selected order. We generate a fragment of the matrix resulting from the interaction basis functions on the first element. The rows and columns of element matrices correspond to the individual basis functions spread on the given element. The terms of the matrix denote the interaction of basis functions from the row and column (the integral of the product of basis functions calculated on a given element). Some rows of the matrix can be fully generated, some only partially, because some columns will be missing due to the fact that the basis functions span on a given element extending over neighboring elements and interact (having common supports) with the basis functions of subsequent elements (with subsequent columns of the matrix).
ALGORITHM
Algorithm 3: Frontal solver algorithm Consider the frontal solver algorithm in the following example. Let us assume that we use the isogeometric finite element method for three one-dimensional elements, Consider the frontal solver algorithm in the following example. Let us assume that we use the isogeometric finite element method for three one-dimensional elements, for square B-spline functions. So we have five B-spline functions spanning over three elements. Element matrices for the isogeometric finite element method, as described in chapter one, contain interactions between segments of B-splines spread over a single interval - a finite element R 1 R1 R1 1 13 1 B1 (x)B1 (x)dx 0 B1 (x)B2 (x)dx 0 B1 (x)B3 (x)dx 20 120 120 0 R1 R1 R 1 13 9 13 0 B2 (x)B1 (x)dx 0 B2 (x)B2 (x)dx 0 B2 (x)B3 (x)dx = 120 20 120 R1 R1 R1 1 13 1 B3 (x)B1 (x)dx 0 B3 (x)B2 (x)dx 0 B3 (x)B3 (x)dx 120 120 20 0 For mesh, the global matrix looks like this: 1 a four-element 13 1 ··· 20 120 120 13 9 1 13 13 1 ··· 120 20 + 20 120 + 120 120 1 13 13 1 9 1 13 13 1 ··· 120 + 120 120 120 120 + 120 20 + 20 + 20 ··· 1 13 13 1 9 1 13 13 1 120 120 + 120 20 + 20 + 20 120 + 120 120 1 13 13 1 9 13 ··· 120 120 + 120 20 + 20 120 1 13 1 ··· 120 120 20 The frontal solver algorithm generates element matrices one by one and adds them to the global matrix, eliminating fully aggregated rows. So in the first step, our element matrix looks like this:
Open AGH e-podręczniki - content available under the CC BY-SA license
114
4.5. Frontal solver algorithm
B1(x) B2(x) B3(x) B1(x) 1 13 1 20 120 120 13 9 13 B2(x) 120 20 120 1 13 1 B3(x) 120 120 20 To better illustrate the operation of the algorithm, we will leave the numbers in the fractional form, remembering, of course, that they are stored in the computer in the floating-point form. In the first element, we are able to eliminate the first row that contains the segment of the first B-spline that has been trimmed to the edge of our mesh. So, we eliminate the first row. We scale the first row to get one on thediagonal 1 13 1 20 ∗20 120 ∗20 120 ∗20 13 9 13 120 20 120 1
13
120 120 u1 1∗20 u2 = 1 u 1 3 13 1 1 6 6 13 9 13 120 20 120 1
13
1 20
1
120 120 20 u1 20 u2 = 1 u3 1 Since the first row is fully generated, we can eliminate it (run Gaussian elimination which subtracts this row from the rest of the rows available in the matrix). This is because even if the following lines are not fully generated, we can subtract the first line from them. As we generate the rest of these non-generated lines, we add the missing terms to them. Since adding and subtracting lines is commutative, we can subtract the fully generated line first and then add the missing remainder to those lines. 2nd = 2nd − 1st ∗ A(2, 1) = 2nd − 1st ∗ 13/120 13 1 1 6 6 13 13 9 13 13 13 13 120 −1 120 20 − 6 120 120 − 16 120 1
13
120 120 u1 20 13 u2 = 1−20 120 u 1 " 3 13 1 31 1 6 6 144 1
13
1 20
13 144
#
1
120 120 20 u1 20 7 u2 = − 6 u3 1 rd rd 3 = 3 − 1st ∗ A(3, 1) = 3rd − 1st 1/120 13 1 1 6 6 31 13 0 144 144 1 1 13 31 1 1 13 1 −1 − − 120 144 120 20 144 120 120 120 u1 20 u2 = − 76 1 u 1−20 120 " 3 # 1 1 13 6 6 31 13 1841 864 0 144 144 17280 17280
Open AGH e-podręczniki - content available under the CC BY-SA license
115
4.5. Frontal solver algorithm u1 20 7 u2 = − 6 5 u3 6 At this point we are not able to eliminate the second row because all the B splines in it are also spanned over the second element. So we cannot multiply the second row by the column value because we would leave out the rest of the row (we will not multiply the part of the row that has not been generated yet). So, we need to generate the matrix of the second element 1 20
13 120 1
13 120 9 20 13 120
1 120 13 120 1 20
120 u2 1 u3 = 1 u4 1
and add it to part of the already factored matrix of the first element. 13 1 1 0 6 6 0 31 1 13 13 1 144 + 20 144 + 120 120 1841 13 864 9 13 0 17280 + 120 17280 + 20 120 1 13 1 0 120 20 120 u1 0 u − 7 +1 2 6 = 5 u3 6 +1 u4
1
In this matrix, we can already leave the first row and the first column alone, because they have already been factored (the first row has been subtracted from the remaining rows, and in the first column below the diagonal are all zeros) 119 13 1 − 2160 720 120 3713 143 13 17280 720 120 1
13
1
120 120 20 u2 − 16 11 u3 = 6 u4 1 At this point, again, the first row is fully generated, so we can eliminate it, while the following rows are waiting for the rest of the generation to be generated, which is related to the fact that the B-spline basis functions extend over the following elements and intersect (they have common carriers). function domains with other consecutive B-spline functions that appear on subsequent elements. So we eliminate the first row in our frontal matrix 1st = 1st 720 119 119 720 13 720 1 720 − 2160 720 119 119 120 119 3713 143 13 17280 720 120 1
13
120 120 u2 − 16 720 119 11 u3 = 6 u 1 4 13 6 1 − 357 119 3713 143 13 17280 720 120 1 120
13 120
1 20
1 20
Open AGH e-podręczniki - content available under the CC BY-SA license
116
4.5. Frontal solver algorithm u2 − 120 119 11 u3 = 6 u4 1 We now eliminate the first row by subtracting it from the not-fully-summed up second and third rows. The first column is fully summed so we can generate zeros in it. 3713 2nd = 2nd − 1st 17280 13 6 1 − 357 119 3713 143 13 17280 13 6 17280 17280 −1 17280 3713 720 − 357 3713 120 − 119 3713 1
13
120 120 u2 − 120 119 11 120 3713 u3 = 6 + 119 17280 u 1 " 4 13 6 9270521 1 − 357 119 318129840 1
13
1 20
6697589 − 53021640
#
1
20 120 120 120 u2 − 119 35129 u3 = 17136 u4 1 1 3rd = 2rd − 1st 120 13 6 1 − 357 119 9270521 6697589 0 − 53021640 318129840 1 1 13 13 1 1 6 1 −1 + − 120 357 120 120 120 20 119 120 u2 − 120 119 35129 u3 = 17136 1 u 1+ 120 119 120 4 13 6 1 − 357 119 9270521 6697589 − 53021640 0 318129840 2327 59 0 21420 1190 u2 − 120 119 27703 u3 = 17136 120 u4 119 So, we eliminated the first row, and we cannot eliminate the remaining rows anymore because they are not fully summed (the B-spline functions related to these rows have remaining parts on other elements) so we cannot multiply them by the value in the column because we would skip the rest of the rows. (we will not multiply any part of the rows that has not yet been generated).
In our example, we generate an element matrix (along with the right side) related to the last third element " # 1 20 13 120
13 120 9 20
1 120 13 . 120
13 120
1 20
u3 1 u4 = 1 u5 1 and we add it to our frontal matrix 13 6 1 − 357 119 0 9270521 1 6697589 13 − 53021640 + 120 318129840 + 20 2327 13 59 9 0 21420 + 120 1190 + 20 1 13 0 120 120
0
1 120 13 120 1 20
Open AGH e-podręczniki - content available under the CC BY-SA license
117
4.6. Multi-frontal solver algorithm u2 − 120 119 u 27703 +1 3 17136 = 120 u4 119 +1 u5 1 13 6 1 − 357 119 0 9270521 1 6697589 13 − 53021640 + 120 318129840 + 20 2327 13 59 9 0 21420 + 120 1190 + 20 1 13 0 120 120 120 u2 − 119 u 27703 +1 3 17136 = 120 u4 119 +1
0
1 120 13 120 1 20
u5 1 In this matrix, we can already leave the first row and the first column alone, because they have already been factored (the first row has been subtracted from the remaining rows, and in the first column below the diagonal are all zeros) 25177013 953578 1 − 53021640 318129840 120 1859 1189 13 8568 23800 120 1
13
1
20 120 120 44839 u3 17136 239 u4 = 119 u5 1 This is the last matrix for the algorithm; moreover, it is dense, so we can run a Gaussian pivoting elimination algorithm to solve it, back-substituting to solve the rest of the equations.
Now let us make the following observations. The frontal solver algorithm in the form shown above allows only pivoting within rows that have been fully summed. If the matrix is not symmetric and positively defined, this is a problem and the resulting solution may not be correct. The frontal solver algorithm can be generalized to any multidimensional meshes, but its main disadvantage is the fact that the size of the frontal matrix (to which we add individual elements) may increase and the cost of this solver is high. The size of the frontal matrix is related to the size of the interface between the added and eliminated elements and the rest of the computational mesh. This interface is called a solver front. In general, the size of the front depends on the size and shape of the computational grid. When viewing the elements of a two-dimensional grid row by row, rows whose functions also span over the following rows will have to wait for elimination until we include the next row in the frontal matrix. Therefore, the size of the frontal matrix will be equal to the number of basis functions on the mesh cross-section, which in two dimensions is N 0.5 where N is a number of base functions on the grid.
4.6.
Multi-frontal solver algorithm
The multi-frontal solver algorithm was proposed in 1987 as a modification of the frontal solver algorithm by Iain Duff and John Reid [20]. The idea behind the multi-frontal algorithm is to perform the elimination as in the frontal solver algorithm but over many elements simultaneously.
EXAMPLE
Example 9: Multi-frontal solver algorithm Open AGH e-podręczniki - content available under the CC BY-SA license
118
4.6. Multi-frontal solver algorithm In other words, in our example in this chapter, we have a matrix that was created by combining three 1 20
13 120 9 20 13 120
13 elemental matrices 120 1 120
1 120 13 120 1 20
Also in this section, to better illustrate the operation of the algorithm, we will leave the numbers as fractional, of course remembering that they are stored in the computer in the floating-point form. So we generate all three elemental matrices, and locate (mark in red) the matrix rows that we can eliminate " # 1 20 13 120
13 120 9 20
1 120 13 120
u1 1 u2 = 1 u 1 h 3 1 20
13 120
1 120
13 120
9 20
1 20
13 120
" # u2 1 u3 = 1 u " 4 1 20 13 120
13 120 9 20
13 120
1 20
i
#
1 120 13 120
13 120
1 20
u3 1 = u4 1 u5 1 In our case, when we operate on B-spline functions, we cannot unfortunately eliminate any rows from a single element matrix unless we merge three element matrices, or unless the rows are located at the edge of the area. This means that we can eliminate the first row from the frontal matrix related to the first element 1st = 1st /A(1, 1) = 1st /20= 1st ∗ 20 1 13 1 20 ∗20 120 ∗20 120 ∗20 13 9 13 120 20 120 1
13
120 120 u1 1∗20 u2 = 1 u 1 3 13 1 1 6 6 13 9 13 120 20 120 1
13
1 20
1
120 120 20 u1 20 u2 = 1 u3 1 13 nd nd 2 = 2 − 1st ∗ A(2, 1) = 2nd − 1st 120 13 1 1 6 6 13 13 9 13 13 13 1 13 − − 120 −1 120 20 6 120 120 6 120 1
13
120 120 u1 20 13 u2 = 1−20 120 u3 1
1 20
Open AGH e-podręczniki - content available under the CC BY-SA license
119
4.6. Multi-frontal solver algorithm
13 6 31 144 13 120
1 0 1
1 6 13 144 1 20
120 u1 20 7 u2 = − 6 u3 1 3rd = 3rd − 1st ∗ A(3, 1) = 3rd − 1st /120 13 1 1 6 6 31 13 0 144 144 1 1 13 31 1 1 13 1 −1 120 − 144 120 20 − 144 120 120 120 u1 20 u2 = − 76 1 u 1−20 120 3 13 1 1 6 6 31 13 0 144 144 864 0 1841 17280 17280 u1 20 7 u2 = − 6 5 u3 6 In the matrix related to the second element, it is not possible to eliminate any row because all rows are missing some columns that will be added when we combine this matrix with neighboring matrices. Similarly, in the matrix related to the last element, we can eliminate the last row. In this matrix, we change the order of the lines so that the line to be eliminated is at the beginning 1st = 1st /A(1, 1) = 1st /20= 1st ∗ 20 1 13 1 20 ∗20 120 ∗20 120 ∗20 13 9 13 120 20 120 1
13
120 120 u5 1∗20 u4 = 1 u 1 3 13 1 1 6 6 13 9 13 120 20 120 1
13
1 20
1
120 120 20 u5 20 u4 = 1 u3 1 13 nd nd 2 = 2 − 1st ∗ A(2, 1) = 2nd − 1st 120 13 1 1 6 6 13 13 9 13 13 13 13 120 −1 120 20 − 6 120 120 − 16 120 1
13
120 120 u5 20 13 u4 = 1−20 120 u 1 3 13 1 1 6 6 31 13 0 144 144 1 120
13 120
1 20
1 20
Open AGH e-podręczniki - content available under the CC BY-SA license
120
4.7. Direction-splitting algorithm u5 20 7 u4 = − 6 u3 1 3rd = 3rd − 1st ∗ A(3, 1) = 3rd − 1st /120 13 1 1 6 6 31 13 0 144 144 1 1 13 31 1 1 13 1 −1 120 − 144 120 20 − 144 120 120 120 u5 20 u4 = − 76 1 u 1−20 120 3 13 1 1 6 6 31 13 0 144 144 864 0 1841 17280 17280 u5 20 7 u4 = − 6 5 u3 6 So at this point, we have two sub-matrices resulting from the elimination of one row in the first and third matrices # " 31 144 1841 " 17280 #
u2 = u " 3 31 144 1841 " 17280 #
13 144 864 "17280# − 76 5 6 # 13 144 864 17280 " # − 76 5 6
u4 = u3 Such subarrays, obtained by eliminating certain rows, are called Schur’s complement matrices. Additionally, we obviously have " # a matrix related to the second element (with variables u2 , u3 , u4 ). 1 20 13 120
13 120 9 20
1 120 13 120
13 120
1 20
u2 1 u3 = 1 u4 1 Missing parts from rows related to the variables u2 , u3 are in the first sub-matrix called Schur’s Complement, while the missing parts of rows related to the variables u3 , u4 are in a sub-matrix called the Schur’s Complement associated with the third element. The " multi-frontal solver algorithm will now merge the frontal matrices. # 1 31 13 13 1 20 + 144 120 144 120 13 9 864 13 1841 864 13 13 1 31 + 1841 20 + 17280 120 + 17280 + 17280 120 + 144 20 + 144 120 17280 u2 1 = u 3 1 u4 1 We can now complete the factorization by running the Gaussian elimination algorithm on the merged matrix.
4.7.
Direction-splitting algorithm
The alternating-direction solver algorithm was first proposed by Jim Douglas in 1956 in the context of non-stationary simulations using the finite difference method [21].
Open AGH e-podręczniki - content available under the CC BY-SA license
121
4.7. Direction-splitting algorithm The stationary version for the isogeometric finite element method was proposed by Longfei Gao in his doctoral dissertation under the supervision of prof. Victor Manuel Calo [22]. Consider the system of equations we got in the first chapter (related to the bitmap projection problem). As a result of the generation of the system of equations, we got a matrix written in the form of a Kronecker product of two five-diagonal matrices, and the right-hand side counted for individual testing B-splines 1 13 1 1 13 1 ··· ··· u1,1 20 120 120 20 120 120 13 13 1 13 1 1 13 1 ··· ··· 120 120 u2,1 2 60 120 2 60 120 1 13 11 13 1 13 11 13 1 1 u3,1 ··· ··· 20 60 120 20 60 120 120 60 120 60 . . .. .. .. .. .. .. .. .. .. . .. . . . . . . . . . . 1 13 11 13 1 1 13 11 13 1 ⊗ · · · · · · · · · u · · · 120 = k,l 60 20 60 120 120 60 20 60 120 .. .. .. .. .. .. .. .. .. .. .. . . . . . . . . . . . 1 13 11 13 1 1 13 11 13 1 · · · 120 60 · · · 120 60 20 60 120 20 60 120 uNx−2 ,Ny 1 13 1 13 1 13 1 13 · · · 120 · · · 120 60 2 120 60 2 120 uNx−1 ,Ny 1 13 1 1 13 1 · · · 20 · · · 120 uNx ,Ny 120 120 120 20 R y x BITMAP(x, y)B1 (x)B1 (y) dx dy R BITMAP(x, y)B2x (x)B1y (y) dx dy R y x BITMAP(x, y)B3 (x)B1 (y) dx dy .. . R BITMAP(x, y)Bkx (x)Bly (y) dx dy .. . R y BITMAP(x, y)B x Nx −2 (x)BNy (y) dx dy R y x (x)BN (y) dx dy BITMAP(x, y)BN x −1 y R y x BITMAP(x, y)BN (x)BN (y) dx dy x y The solution of a system of equations in which the matrix has the structure of a Kronecker product is possible in a very short time. What does this mean in a very short time? A computational cost is expressed in the number of operations, such as the multiplication or addition of numbers necessary to solve a system of equations. In the case of a system of equations in which the matrix has the structure of a Kronecker product, it is possible to solve the system of equations using an algorithm in which the number of operations equals const ∗ N where N is the number of unknowns (the number of bitmap approximation coefficients on the mesh, expressed exactly by N = Nx ∗ Ny where Nx , Ny is the mesh dimension, and const stands for some fixed number. The algorithm used in this case is called a alternating directions solver algorithm. We consider two steps in the solution process. The first step is to take the first of the sub-matrix and arrange the vector of unknowns and the vector of right-hand sides into many sub-vectors, one vector for each column of computational mesh elements. It is illustrated in Pic. 28, and in the formula below. 1 13 1 ··· 20 120 120 13 1 13 1 ··· 120 w1,1 w1,2 ··· w1,Ny−1 w1,Ny 2 60 120 1 13 11 13 1 w ··· w2,2 ··· w2,Ny−1 w2,Ny 20 60 120 120 60 2,1 . . . . . .. .. .. .. .. w3,1 w · · · w w 3,2 3,Ny−1 3,Ny .. .. .. .. 1 13 11 13 1 ··· · · · 120 = . . · · · . . 60 20 60 120 . . . . . w .. .. .. .. .. Nx−2 ,1 wNx−2 ,2 · · · wNx−2 ,Ny−1 wNx−2 ,Ny 1 13 11 13 1 wN wNx−1 ,2 · · · wNx−1 ,Ny−1 wNx−1 ,Ny · · · 120 x−1 ,1 60 20 60 120 1 13 1 13 wNx ,1 wNx ,2 · · · wNx ,Ny−1 wNx ,Ny · · · 120 60 2 120 1 13 1 · · · 120 120 20
Open AGH e-podręczniki - content available under the CC BY-SA license
122
4.7. Direction-splitting algorithm R BITMAP(x, y)B1x (x)B1y (y) dx dy R BITMAP(x, y)B2x (x)B1y (y) dx dy R BITMAP(x, y)B3x (x)B1y (y) dx dy .. . R x BITMAP(x, y)BN (x)B1y (y) dx dy x −2 R y BITMAP(x, y)B x Nx −1 (x)B1 (y) dx dy R x BITMAP(x, y)BN (x)B1y (y) dx dy x
··· ··· ··· .. . ··· ··· ···
R y BITMAP(x, y)B1x (x)BN (y) dx dy y R y BITMAP(x, y)B2x (x)BN (y) dx dy y R y BITMAP(x, y)B3x (x)BN (y) dx dy y .. . R y x BITMAP(x, y)BNx −2 (x)BNy (y) dx dy R y x BITMAP(x, y)BN (x)BN (y) dx dy x −1 y R y x BITMAP(x, y)BN (x)B (y) dx dy Ny x
We have introduced the auxiliary unknowns here w∗ which are used to solve the first system of equations. Original unknowns u∗ we will get after solving the second system of equations in which the right side will be auxiliary unknowns w∗. So we got a system of equations with a five-diagonal matrix with many right sides. Each right-hand side, corresponds to one column on the element grid, so it has a fixed coordinate y, and the coordinate x varying from 1 to Nx . The u* unknowns, in which the second indexes change with lines, for example, are similarly ordered w1,1 , w1,2 , ..., w1,Ny while the first indexes in the columns change. When we solve this system of equations, we get solutions w∗ and we go to the second step of the variable-direction solver algorithm. The second step, then, is to take an analogous second Kronecker product matrix, take solutions w∗ from the first system of equations, arranging them according to the rows of mesh elements (cf. Pic. 28), arranging the unknown unknowns in a similar way u∗ solving the obtained system of equations with many right-hand sides.
Figure 28: The pattern according to which we arrange the right sides when executing the floating-direction solver algorithm.
1 20 13 120 1 120
. .. ···
13 120 1 2 13 60
1 120 13 60 11 20
1 120 13 60
1 120
···
1 120
13 60
11 20
13 60
1 120
.. .
.. . ···
.. . .. .
1 120
···
···
.. . .. .
13 60 1 120
···
··· .. . .. .
11 20 13 60 1 120
.. .
13 60 1 2 13 120
··· 1 120 13 120
u1,1 u1,2 u1,3 .. .
u 1,Ny−2 u1,Ny−1 u1,Ny
u2,1 u2,2 u2,3 .. . u2,Ny−2 u2,Ny−1 u2,Ny
··· ··· ··· ··· ··· ··· ···
uNx−1 ,1 uNx−1 ,2 uNx−1 ,3 .. . uNx−1 ,Ny−2 uNx−1 ,Ny−1 uNx−1 ,Ny
uNx ,1 uNx ,2 uNx ,3 .. .
= uNx ,Ny−2 uNx ,Ny−1 uNx ,Ny
1 20
Open AGH e-podręczniki - content available under the CC BY-SA license
123
4.8. Pre-conditioner
w1,1 w1,2 w1,3 .. .
w 1,Ny−2 w1,Ny−1 w1,Ny
w2,1 w2,2 w2,3 .. . w2,Ny−2 w2,Ny−1 w2,Ny
··· ··· ··· ··· ··· ··· ···
wNx−1 ,1 wNx−1 ,2 wNx−1 ,3 .. . wNx−1 ,Ny−2 wNx−1 ,Ny−1 wNx−1 ,Ny
wNx ,1 wNx ,2 wNx ,3 .. .
wNx ,Ny−2 wNx ,Ny−1 wNx ,Ny
In this second system of equations, each sub-sector, each right-hand side, corresponds to one row in the element grid, so it has a fixed coordinate x, and a coordinate x, and a coordinate y varying from 1 to Ny . The unknowns are similarly ordered u∗, in which the first indexes change, for example w1,1 , w2,1 , ..., wNx ,1 while the second indexes change in the columns. Each of the above equations can now be solved using the Gaussian elimination algorithm for the band matrix.
4.8.
Pre-conditioner
When our system of equations Ax = b is difficult to solve, then we can construct a preconditioner M (another matrix) such that if we multiply our equation on the left by M −1 czyli M −1 Ax = M −1 b and additionally in between Ax we put M −1 M (we can do it because M −1 M is an identity matrix), then a new system of equations M −1 AM −1 M x = M −1 b may be easier to solve. Of course, it all depends on the clever structure of the matrix M . An example is given in the Iterative solver chapter. Preconditioners for iterative algorithms are described in chapter 8 of the textbook by Yousef Saad [23].
4.9.
Iterative solver algorithm
Iterative solvers algorithms are described in a very extensive way in the textbook of Yousef Saad [23]. Probably the first iterative solver was the method of solving the 4 by 4 equation system proposed by Gauss. Discussing the general family of iterative solver algorithms is beyond the scope of this manual. In this module, we will discuss an iterative solver applicable to the projection problem where the area has any shape that is not a regular square. Our example problem to be solved is a two-dimensional projection problem defined in an area that does not have a square shape (for example, the problem of projecting a bitmap onto a folded area). Then our system of equations to solve looks likeR this R R y y y y x x x x B B B1,p B1,p B2,p B1,p ··· Bx By Bx By u1,1 1,p 1,p B1,p B1,p Ω Ω Ω 1,p 1,p Nx ,p Ny ,p R R R y y x x B1,p B1,p B1,p Bx By Bx By ··· Bx By Bx By Ω B2,p u2,1 Ω 2,p 1,p 2,p 1,p Ω 2,p 1,p Nx ,p Ny ,p .. .. .. .. .. . . . . . R R R y y x x uNx ,Ny Bx By Bx By Bx By Bx By · · · Ω BN BN BN BN Ω Nx ,p Ny ,p 1,p 1,p Ω Nx ,p Ny ,p 2,p 1,p x ,p x ,p y ,p y ,p
Open AGH e-podręczniki - content available under the CC BY-SA license
124
4.9. Iterative solver algorithm R BIT M AP (x, y)B1x (x) ∗ B1y (y) Ω R y Ω BIT M AP (x, y)B1x (x) ∗ B2 (y) = .. . R y x BIT M AP (x, y)BNx (x) ∗ BNy (y) Ω where Ω where Ω is no longer a square but our ”folded” area. The derivation of this system of equations proceeds in the same way as described in chapter one for bitmap projection tasks, the only difference is that we are now projecting onto a ”folded” area. For example, we want to calculate and visualize what a bitmap will look like when superimposed over a pleated material (e.g., a curtain). Of course, for each integral over the area of Ω we can change the variables to a square area, and then the jacobian of this transformation will be included in the integral R R B x (x)Bjy (y)Bkx (x)Bly (y)dxdy = [0,1]2 Bix (x)Bjy (y)Bkx (x)Bly (y)|Jac(x, y)|dxdy Ω i We would like to use a variable-direction solver to factorize our matrix, however, this is not possible because we cannot separate variables in Jacobian, we do not know how to process |Jac(x, y)| = |Jacx (x)| ∗ |Jacy (y)|. Fortunately, we can apply the following preconditioner iterative algorithm
ALGORITHM
Algorithm 4: Iterative solver algorithm with preconditioner Our goal is to solve a system of equations Ax = y, where A is, for example, the matrix of our bitmap projection problem into a ”rippled” area. The size of the matrix A to Nx Ny while its terms are given in our example by R Ai,j = [0,1]2 Bix (x)Bjy (y)Bkx (x)Bly (y)|Jac(x, y)|dx. 1. We define our ”preconditioner” or matrix M which arises from the matrix A by settig the Jacobian to one. In other words, the matrix terms are given by R Mi,j = B x (x)Bjy (y)Bkx (x)Bly (y)dx. In our example, this means replacing the [0,1]2 i projection into an undulating area with a projection into a flat area. 2. Let as denote y = M x 1. We choose any ”starting point”(any vector y0 B-spline approximation coefficients of Nx Ny ). We can take for example y0 i,j = pixel value at the point where the maximum of the B-spline value is Bix (x)Bjy (y). But I might as well take y0 i,j = 0 and our algorithm will also work properly (although it will probably require a bit more iteration). 2. Then we calculate the so-called residuum r = M −1 b − M −1 AM −1 y0 = M −1 (b − AM −1 M y0 ). We do it in the following steps
• denote M −1 y0 = z0 and we solve a system of equations M z0 = y0 . Note that this means solving the same system of equations as in chapter one. R R R y y y y y y x x x x x x B B B B B B B B · · · B B B B y0 1,1 z01,1 2 2 2 1,p 1,p 1,p 2,p 1,p 1,p 1,p 1,p 1,p 1,p Nx ,p Ny ,p [0,1] [0,1] [0,1] R R R y y x x Bx By Bx By ··· Bx By Bx By y0 2,1 [0,1]2 2,p 1,p 2,p 1,p [0,1]2 2,p 1,p Nx ,p Ny ,p z02,1 [0,1]2 B2,p B1,p B1,p B1,p .. .. .. .. .. .. = . . . . . . R R R y y y y y y x x x x x x y z B B B B B B B B · · · B B B B 0 Nx ,Ny 0Nx ,Ny [0,1]2 Nx ,p Ny ,p 1,p 1,p [0,1]2 Nx ,p Ny ,p 2,p 1,p [0,1]2 Nx ,p Ny ,p Nx ,p Ny ,p We can do this with a linear-directional variable complexity.
Open AGH e-podręczniki - content available under the CC BY-SA license
125
4.9. Iterative solver algorithm • Then we have r = M −1 (b − Az0 ) where b − Az0 = v this is the solution coefficient vector, i.e. M −1 v = r. We need to multiply A(with Jacobian) by the resulting solution coefficient vector. We’re going to get a vector v1,1 v 2,1 = b − Az0 = = ···
v
vNx ,Ny
BIT M AP (x, y)B1x (x) RΩ BIT M AP (x, y)B2x (x) Ω R
B1y (y) B1y (y)
−
P
−
P
y x BIT M AP (x, y)BN (x) ∗ BN (y) − Ω x y
P
R
∗ ∗
i=1,...,Nx ;j=1,...,Ny i=1,...,Nx ;j=1,...,Ny
z0i,j
y y x x B1,p B1,p Bi,p Bj,p
Ω
y y x x B2,p B1,p Bi,p Bj,p
Ω
y y x x BN BN Bi,p Bj,p x ,p y ,p
R
z0i,j
RΩ
z0i,j
R
··· i=1,...,Nx ;j=1,...,Ny
• We solve M r = v. R R R Bx By Bx By Bx By Bx By ··· Bx By Bx By [0,1]2 1,p 1,p 1,p 1,p [0,1]2 1,p 1,p 2,p 1,p [0,1]2 1,p 1,p Nx ,p Ny ,p R R R y y x x Bx By Bx By ··· Bx By Bx By [0,1]2 2,p 1,p 2,p 1,p [0,1]2 2,p 1,p Nx ,p Ny ,p [0,1]2 B2,p B1,p B1,p B1,p . . . . .. .. .. .. R R R y y y y y y x x x x x x B B B B B B B B · · · B B B B 2 2 2 Nx ,p Ny ,p 1,p 1,p Nx ,p Ny ,p 2,p 1,p Nx ,p Ny ,p Nx ,p Ny ,p [0,1] [0,1] [0,1] r1,1 r2,1 . . . rNx ,Ny R R P y y x x BIT M AP (x, y)B1x (x) ∗ B1y (y) − i=1,...,Nx ;j=1,...,Ny z0i,j Ω B1,p B1,p Bi,p Bj,p Ω R P R y y x x BIT M AP (x, y)B2x (x) ∗ B1y (y) − i=1,...,Nx ;j=1,...,Ny z0i,j Ω B2,p B1,p Bi,p Bj,p Ω = ··· R R P y y y x x x BIT M AP (x, y)B (x) ∗ B (y) − z B B B B 0i,j Nx Ny i=1,...,Nx ;j=1,...,Ny Ω Ω Nx ,p Ny ,p i,p j,p Again, we can do this with a alternating-direction solver with linear computational complexity. Having the residuum counted r we can correct our proposed solution y1 = y0 + r The melt condition is sufficiently low residuum. In other words, I have to count the quota from the P 0.5 2 residuum (check how small the whole residuum is, for example ||r|| = |r | i=1,...,N x;j=1,...,N y i,j If ||r|| > we mark y0 := y1 and go to the point 5. Finally, we calculate our final solution (bitmap projection coefficients on the corrugated area) by solving the system of equations M xf inal = yf inal . Our final solution is yf inal . R R R Bx By Bx By Bx By Bx By ··· Bx By Bx By xf inal 1,1 [0,1]2 1,p 1,p 1,p 1,p [0,1]2 1,p 1,p 2,p 1,p [0,1]2 1,p 1,p Nx ,p Ny ,p R R R y y x x xf inal Bx By Bx By ··· Bx By Bx By 2,1 [0,1]2 2,p 1,p 2,p 1,p [0,1]2 2,p 1,p Nx ,p Ny ,p [0,1]2 B2,p B1,p B1,p B1,p = .. .. .. .. .. . . . . . R R R y y y y y y x x x x x x xf inal Nx ,Ny B B B B B B B B · · · [0,1]2 BNx ,p BNy ,p BNx ,p BNy ,p [0,1]2 Nx ,p Ny ,p 1,p 1,p [0,1]2 Nx ,p Ny ,p 2,p 1,p yf inal 1,1 y f inal 2,1 = .. . yf inal Nx ,Ny Again, we can do this with an alternating-direction solver with linear computational complexity.
Open AGH e-podręczniki - content available under the CC BY-SA license
126
4.10. Selection of the solver based on problem kind
4.10.
Selection of the solver based on problem kind
The finite element method can be used to solve many engineering problems. The general scheme of the method’s operation is similar, regardless of the problem considered. In our case, for the sake of simplicity, we have chosen the bitmap projection problem. The basic steps of the finite element method are listed below. The last step is to select an algorithm to solve the generated system of equations. This algorithm depends on the matrix structure, which indirectly depends on the engineering problem under consideration.
ALGORITHM
Algorithm 5: The simulation process using the finite element method 1. Selecting a differential equation describing an engineering problem or a physical phenomenon we want to simulate. 2. The simplest possible engineering problem is a projection problem, such as the bitmap projection problem described in Chapter One. In this problem, the differential equation is replaced with the problem: Find a function u ∈ C 1 (Ω) one that approximates the given bitmap, i.e. u(x, y) ≈ BIT M AP (x, y), where Ω is the area where our engineering problem is defined. 3. The next step is to transform our problem into a so-called weak form, in which this is our equation u(x, y) ≈ BIT M AP (x, y), where Ω it is sampled using a number of so-called test functions v(x, y) and averaged using integrals. In our exemplary bitmap projection problem, R R the weak form is the following: Ω u(x, y)v(x, y)dxdy = Ω BIT M AP (x, y)v(x, y)dxdy where v(x, y) is a test function. This equation must be satisfied for all test functions we have chosen. 4. The next stage is the generation of the finite element mesh covering the given area and selecting the base functions spanning the finite elements. At this stage, the area in which we solve our engineering problem is divided into finite elements. Then, on the finite elements, we span selected basic functions, the linear combination of which will approximate our desired function u In our bitmap projection example described in chapter one, area Ω that is, the rectangle on which the bitmap is spanned, is divided into Nx × Ny rectangular elements. Next, we span the B-spline base functions of the second order on this area, using the vector wick 0 0 0 1 2 3 ... N_x-1 N_x N_x N_x in the direction of x axis, and knot vector 0 0 0 1 2 3 ... N_y-1 N_y N_y N_y in the direction of y axis. So we have databases of two-dimensional B-spline functions Bi,j (x, y) = Bix (x)Bjy (y), i = 1, ..., Nx , j = 1, ..., Ny . 5. We now discretize the weak formulation with the help of selected base functions stretched on a computational grid. The function you are looking for u we express as a linear combination of basis functions. Likewise, we choose individual base functions for individual testing functions. In the bitmap projection example described in Chapter One, the B-spline base functions selected in the previous step are now used to approximate P y x the solution u = i=1,...,Nx ;j=1,...,Ny ai,j Bi (x)Bj (y), similarly, we choose B-spline functions as test functions Bkx (x)Bly (y). Thus we obtain the following system of equations
Open AGH e-podręczniki - content available under the CC BY-SA license
127
4.11. MATLAB implementation of the alternating-direction solver for the bitmap projection problem R x y x y R x y x y B1,p B1,p B1,p B1,p B B1,p B2,p B1,p R R 1,p y y y y x x x x B B B B B2,p B1,p B2,p B1,p 2,p 1,p 1,p 1,p .. .. . . R x R x y y y y x x BNx ,p BNy ,p B1,p B1,p BNx ,p BNy ,p B2,p B1,p R BIT M AP (x, y)B1x (x) ∗ B1y (y)dx R y BIT M AP (x, y)B1x (x) ∗ B2 (y)dx = .. . R y x BIT M AP (x, y)BN (x) ∗ B (y)dx Ny x
··· ··· .. . ···
R x y x y B B1,p BNx ,p BN u1,1 y ,p R 1,p y y x x B2,p B1,p BN BN u2,1 x ,p y ,p .. .. = . . R x y y x uNx ,Ny BNx ,p BN BN BN x ,p y ,p y ,p
6. The last stage is the solution of the generated system of equations. We have six representative solver algorithms for solving equation systems generated during finite element calculations. They are the Gaussian elimination algorithm, the LU factorization algorithm, the frontal solver algorithm, the multi-frontal solver algorithm, the variable-directional solver algorithm, and the iterative algorithm. For problems where the matrices are symmetric and positively defined, iterative algorithms based on Krylov’s methods are often used, for example the conjugate gradients algorithm. There are also iterative algorithms for a wider class of problems, such as the GMRES algorithm. Iterative solvers algorithms are described in a very extensive way in the textbook of Yousef Saad [23]. The number of iterations for iterative solvers depends on the type of problem being solved, on the structure and properties of the matrix after discretization. In particular, the convergence of the conjugate gradients solver is influenced by the matrix condition number, i.e., the product of the modulus of the highest eigenvalue of the matrix and the modulus of the highest eigenvalue of the inverse matrix. If the matrix condition number is too large, then so-called preconditioners are created, i.e., matrices by which our system of equations is multiplied in such a way that the solution is the same, but the matrix conditioning factor is better. Unfortunately, the problem of selecting a preconditioner depends on the problem being solved (there are no universal algorithms that are always effective). Exact solvers in turn can solve any problem; they can factorize each matrix, but their cost is usually greater than the cost of iterative solvers. For homogeneous two-dimensional meshes, the cost is of the order O(N 1.5 ). For homogeneous three-dimensional meshes, the cost is in the order O(N 2 ). The exception is the alternating-direction solver algorithm, the cost of which is linear O(N ). The alternating-direction solver algorithm can be used when the matrix has a Kronecker product structure. This is the case, for example, in the projection problem, or during non-stationary simulations using the explicit method. The multi-frontal solver algorithm is used for problems for which the matrices are not symmetric or are not positively defined. The multi-frontal solver algorithm is a special implementation of the Gaussian elimination or LU factorization algorithm. The iterative version of the alternating-direction algorithm described in this manual is used to simulate explicitly on irregular geometries.
4.11.
MATLAB implementation of the alternating-direction solver for the bitmap projection problem
Below you can find a link to the MATLAB code that calculates the L2 bitmap projection using the isogeometric finite element method. In particular, this code implements a variable-direction solver algorithm. Open AGH e-podręczniki - content available under the CC BY-SA license
128
4.11. MATLAB implementation of the alternating-direction solver for the bitmap projection problem The code execution is also possible in the free Octave environment. Download code or see Appendix 4. We set the variables with the path to the input file in tif format f ilename =0 C : //U sers/M aciej/Dropbox/bitmapa.tif 0 then we give the number of mesh elements in the x and y directions, and the degrees of the B-spline function in these directions nx = 4 ny = 4 px = 2 py = 2 Then we start the first procedure bitmap_splitting(f ilename, nx, ny, px, py). The code, after building the system of equations and solving it, draws the bitmap projections in the open window.
EXERCISE
Exercise 10: Projection of the terrain Exercise content:
Please convert the bitmap projection code to draw projections of the area.
Solution:
Solution:download code or see Appendix 4A.
Open AGH e-podręczniki - content available under the CC BY-SA license
129
4.11. MATLAB implementation of the alternating-direction solver for the bitmap projection problem
Open AGH e-podręczniki - content available under the CC BY-SA license
130
Chapter 5
5. Stabilization methods 5.1.
Stabilization of finite element method
When performing calculations using the finite element method, we perform following steps
ALGORITHM
Algorithm 6: Finite element method algorithm 1. We determine the area where we want to perform our calculations and generate a grid of elements covering a given area. For example we consider the area Ω = [0, 1]2 covered with a mesh of 4 by 4 elements (patch of 16 elements on which we will later span the B-spline base functions). 2. We choose a differential equation in the strong form that models the physical phenomenon that we want to simulate in our area, for example the heat-transfer problem −∆u = f . 3. We establish the boundary conditions that describe what happens to the boundary of our area, for example u = 0 for x = 0, y ∈ (0, 1); u = 1 for x = 1, y ∈ (0, 1), ∂u ∂y = 0 for x ∈ (0, 1), y ∈ {0, 1}. 4. We transform the strong formulation into the so-called weak formulation, for example R R b(u, v) = l(v); b(u, v) = Ω ∇u · ∇vdxdy; l(v) = Ω xv(x, y)dxdy where the x function on the right-hand side is the extension of the boundary condition into the entire area (i.e., such a function that takes 0 on the left boundary of the area and 1 on the right and her derivatives in the y direction are equal to 0 as required by the boundary conditions). 5. We will establish a finite-dimensional base of functions used for approximation of our solution, for example using the knot vectors on ours element grid 0 0 0 1 2 3 4 4 4 on the x axis and 0 0 0 1 2 3 4 4 4 on the y axis, which corresponds to the basis of the B-spline functions y y x x Bi,2 Bj,2 , i, j = 1, ..., 6. They create approximation space Uh = span{Bi,2 Bj,2 }i,j=1,...,6 . 6. We will establish a finite-dimensional basis of functions for testing of the strong formulation, for example the same as for approximation, using knot vectors on our mesh of elements 0 0 0 1 2 3 4 4 4 on the x-axis and 0 0 0 1 2 3 4 4 4 on the y-axis, which corresponds to the base B-spline y y x x functions Bk,2 Bl,2 k, l = 1, ..., 6. They form the testing space Vh = span{Bk,2 Bl,2 }k,l=1,...,6 .
131
5.1. Stabilization of finite element method 7. Thus, we create a discrete version of our problem bh (uh , vh ) = l(vh )∀vh ∈ Vh , where in we replace the abstract perfect solution u by the approximate solution P y x uh = i,j=1,...,6 ui,j Bi,2 (x)Bj,2 (x), and as testing functions we choose the elements P y x of a finite-dimensional testing space vh = k,l=1,...,6 vk,l Bk,2 (x)Bl,2 (x). 8. Generate a system of linear equations by inserting into the weak formulation our base functions for approximation and for testing y y x R ∂B x y ∂Bk,2 y x ∂Bj,2 x ∂Bl,2 { Ω ∂xi,2 Bj,2 B + B B = i,2 k,2 l,2 ∂x ∂y ∂y }i,j=1,...,6;k,l=1,...,6 {uk,l }k,l=1,...,6 R y x { Ω xBk,2 Bl,2 }k,l=1,...,6 9. We solve the obtained system of linear equations, using for example LU factorization algorithm with pivoting. 10. We modify our solution by subtracting the shifted condition uh = uh − x. This chapter focuses on the issue of stabilization of the finite element computations. The most important mathematical theorem allowing the study of the stability of the finite element method was independently proposed by prof. Ivo Babuśka, prof. Franco Brezzi, and prof. Olga Ładyżenska [24], [25]. They discovered (at about the same time independently of each other) equivalent conditions, now called inf-sup (”inf-sup condition”). The inf-sup condition is still used to this day by scientists who study the stability of the finite element method. This condition can be defined in abstract infinite dimensional h (u,v) mathematical spaces infu∈U supv∈V bkukkvk = γ > 0 or in finite dimensional spaces resulting from our approximation of the solution with the basis of the B-spline function, used to approximate and h (u,v) test the solution infu∈U supv∈V bkukkvk = γ > 0. It may happen that even if mathematicians have proved the fulfillment of the inf-sup condition over infinite dimensional spaces - that is, when we will start to solve a problem in finitely spaces dimension - the inf-sup condition will no longer be met. h (u,vh ) infu∈U supvh ∈Vh bkukkv = γ > 0 then even if the approximation space were infinitely dimensional, our hk simulation will be unstable anyway. The problem with the inf-sup condition is that by selecting our finite dimensional sets (so-called bases) of functions, we do not have an approximation of the solution to test our equations to be sure that the solution obtained with their help on the computer will be sufficiently accurate. The supremum may no longer be realized when we restrict our test space to the finite dimensional space. To check this, we apply very much advanced math tools such as the inf-sup condition. For a large class of problems solved on computers using the finite elements method, this condition is satisfied, and we get quite exact solutions. However, there is also a fairly large class of problems for which the inf-sup condition is not met. This condition can be written as follows. We choose the version formulated by prof. Ivo Babuśka (all versions of this condition are described in the work of Leszek Demkowicz, ICES Report 0608, 2006 ”Babuśka Brezzi?”)[26]: h (uh ,vh ) infuh ∈Uh supvh ∈Vh bku = γh > 0 If this condition is met, it will be possible to solve the system of h kkvh k equations generated using the finite element method and solving it will be a pretty good approximation to P y x the ideal solution u ≈ uh = i,j=1,...,6 ui,j Bi,2 (x)Bj,2 (x).
If this condition is not met, then either the generated layout equations will not be solvable for example, the Gaussian elimination algorithm will tip over because of the diagonal of the matrix will result in a numeric zero (a very small number which will not divide a row in the matrix), or the obtained solution of the system equations will be an incorrect solution to our problem, e.g. numerical oscillations will arise. In such a situation, it is necessary to stabilize our problem, which relies on: 1. functional modification bh (uh , vh )(on adding any additional stabilizing members to it, which is the case approximation and testing space of infinite dimensional, v ideally. These are zero, but in terms of space, they are finite dimensions which are not zero and improve the stability of our problem - an example of this method is the stabilization of the SUPG for equations advection-diffusion), or Open AGH e-podręczniki - content available under the CC BY-SA license
132
5.2. Stabilization of the advection-diffusion equations with the residual minimization method 2. modifying the equations of the problem and the standard in which we try to meet inf-sup condition UhUh (for example in the Discontinuous Galerkin DG method, we break functions and modify the equations by adding terms equal to zero in infinite dimensional space, but not equal to zero in the approximation space. We modify the equation on the discrete level and the norm which gives the inf-sup condition also satisfied at the level of finite-dimensional discrete spaces), or 3. on such reformulation of the problem that the approximation space and the test space are different and that the size of the space could be increased (towards the infinite dimensional test space where the supremum is met)Vh (on taking another space testing than of the approximation space, thanks to which the inf-sup condition will be a better approximation - this is how, for example, the method of minimization of the reziduum works). All these stabilization methods make it possible to mathematically prove the inf-sup condition has been met. However, the mathematical tools needed to check that this condition is met are very mathematically advanced, so we will limit ourselves only to the application of several stabilization methods (SUPG, residuum minimization and the DG method) which will improve the stability, but we will not provide explanations as to why they work. The method of minimizing the residuum also lies at the heart of the Discontinuous Petrov-Galerkin (DPG) method. This DPG method proposed by prof. Leszek Demkowicz is very popular in stabilization of adaptive finite elements computations. In the DPG method, the approximation and test spaces are broken to enable local static condensation on individual finite elements [27], [28], [29].
5.2.
Stabilization of the advection-diffusion equations with the residual minimization method
Let us consider the advection-diffusion problem (calculating the propagation of pollutants in a given area by means of diffusion and the advection ”wind”) b(u, v) = l(v) Z Z ∂u(x, y) ∂u(x, y) b(u, v) = βx (x, y) dx dy βy (x, y) dx dy ∂x ∂y Ω ZΩ Z ∂u(x, y) ∂v(x, y) ∂u(x, y) ∂v(x, y) dx dy + dx dy ∂x ∂x ∂y ∂y Ω Ω Z l(v) = f (x, y)v(x, y) dx dy Ω
We denote by U a set of functions that includes the solution to the advection-diffusion problem u ∈ U . Then by V let’s denote the set of functions that we use for testing in our variational (also called weak) formulation. In this chapter, we will describe, using abstract mathematical language, how the method of minimizing the residual is derived [30]. Our original problem is: We seek u ∈ U such that b(u, v) = l(v) for all test functions v ∈ V . We can mark the left-hand side mathematically Bu and the right-hand side l by introducing certain mathematical operators (mathematicians will say that B : U → V 0 and hBu, vi = b(u, v). Then our problem comes down to finding the scalar field u such that Bu − l = 0. The expression r = Bu − l it is called a residuum. If we only have an approximate solution, for example denoted uh
Open AGH e-podręczniki - content available under the CC BY-SA license
133
5.2. Stabilization of the advection-diffusion equations with the residual minimization method then our residuum will express an error, the greater the residuum, the greater the error of the approximate solution rh = Buh − l. How to measure the solution error, i.e. the residuum size? To measure how big the residuum is, we have to introduce some standard (i.e. a measure of size)rh = kBuh − lk. Now we can say that we are looking for such a solution to our problem uh so that the residual (or error) is as small as possible. Mathematically, this condition is written in the form of minimizing the norm 1 uh = argminwh ∈U kBwh − lk2V 0 2 It writes in before the norm
1 2
and the norm is squared.
The practical problem is that we do not know how to calculate the norm from the difference kBwh − lk. This standard measures distances in an abstract mathematical space V 0 (mathematicians will say that this space is dual to the space of testing functions). To solve this problem, we perform a math trick of projecting a norm from space V 0 to the testing space V . A space projection operator is introduced V into space V 0 . This operator is called the Riesz operator RV : V 3 v → (v, .) ∈ V 0 . The inverse operator projects V 0 back into space V , so RV−1 : V 0 3 (v, .) → v ∈ V . So the application of the Riesz operator projects our problem to the space of test functios V . So we have 1 uh = argminwh ∈Uh kRV−1 (Bwh − l)kV 2 . So we are looking for the point where the function reaches its 2 minimum. This point is reached when the derivatives of this function are equal to zero. Since we have a functional here, mathematicians will say we’re looking for one uh here all Gateaux derivatives are equal to zero in all directions hRV−1 (Buh − l), RV−1 (B wh )iV = 0 ∀ wh ∈ Uh where wh stands for all possible ”directions” from a finite dimensional function space Uh (in which, by the way, we are looking for a solution to our advection-diffusion problem). Technically speaking, at this point we need to construct a finite dimensional space of functions Uh in which we will look for our solution. We do this of course in our textbook using the B-spline basis functions, spanning them along the nodal vectors along the x axis and along the y axis. Along the x we introduce a knot vector [0 0 0 1 2 3 4 4 4], likewise along the axis y we introduce a knot vector [0 0 0 1 2 3 4 4 4]. We obtained two bases of one-dimensional B-spline functions {Bi,2 (x)}i=1,...,6 and {Bj,2 (y)}j=1,...,6 . Then we will create tensor products from them Bi,j;2 (x, y) = Bi,2 (x)Bj,2 (y), i, j = 1, ..., 6. Note that our area Ω it is stretched over a square [0, 1]2 , similar to our 6 * 6 = 36 basis functions which results from the definition of the knot vector [0 0 0 1 2 2 3 4 4 4]. Our approximation space is then spanned by the tensor products of our one-dimensional B-spline functions Uh = gen{Bi,j;2 (x, y) = Bi,2 (x)Bj,2 (y), i, j = 1, ..., 6}. So it is a 6 * 6 = 36-dimensional space, So we have 36 directions (B-spline base polynomials) in which we will count directional derivatives and we will equate them to zero. We mark r = RV−1 (Buh − l) and then our problem of minimizing the reziduum can be written as hr, RV−1 (B wh )i = 0 which is synonymous hBwh , ri = 0
∀ wh ∈ Uh
∀wh ∈ Uh .
We now add a second equation using the definition of a residuum r = Buh − l, I multiply the residuum definitions by the test functions from the space of test functions and we get the equation: (r, v)V = hBuh − l, vi
∀v ∈ V.
Open AGH e-podręczniki - content available under the CC BY-SA license
134
5.2. Stabilization of the advection-diffusion equations with the residual minimization method So we have a system of equations: find a residuum in an infinite dimensional space of test functions r ∈ V and solutions in a finite dimensional space of functions uh ∈ Uh (r, v)V − hBuh − l, vi = 0 hBwh , ri = 0
∀v ∈ V
∀wh ∈ Uh
If we were able to solve this equation, we would get the best possible approximation of our problem in the space of approximating functions Uh . Unfortunately, this is not possible, because the infinite space of test functions generates an infinite number of equations that should be solved. So, we have to choose a second different base to approximate the test space. Here comes the first significant difference between the residual minimization method and the traditional finite element method. In the method of minimizing the residual we have two different spaces, one for approximation of the solution, the other for testing. Of course, we also span the testing space using the B-spline function. For example, we can use the same element patch for the approximation space (but this is not required!) or we can increase the degree of the B-spline function. We specify what our patch of elements will look like and our B-spline basis functions spread over elements, giving a knot vector along the axis x and knot vector along the axis y. Here we refer to the third chapter, which describes the way of defining the base functions using node vectors and B-spline polynomials. Along the axis x we introduce a knot vector [0 0 0 0 11 2 2 3 3 4 4 4 4], likewise along the axis y we introduce a knot vector [0 0 0 0 1 1 2 2 3 3 4 4 4 4]. Generally, the test spaces must be larger than the approximation space. We can achieve this effect by increasing the number of elements or increasing the degree of the B-spline function, or reducing the continuity of the B-spline function, or by mixing the three approaches together. We obtain two bases of one-dimensional B-spline functions ˜k,3 (x)}k=1,...,10 and {B ˜l,3 (y)}l=1,...,10 . Then we will create tensor products from them B ˜k,l;3 (x, y) = {B ˜ Bk,3 (x)Bl,3 (y), k, l = 1, ..., 10. ˜k,l;3 (x, y) = B ˜k,3 (x)Bl,3 (y), i, j = 1, ..., 10}. Our space testing is Vh = gen{B Having a discrete testing space, we finally obtain our discrete (i.e. finite dimensional) system of equations that we want to solve. We are looking for (rm , uh )Vm ×Uh
(rm , vm )Vm − hBuh − l, vm i = 0 hBwh , rm i = 0
∀v ∈ Vm
(5.1)
∀wh ∈ Uh
(5.2)
This is where the so-called inner product appears in a discrete testing space (∗, ∗)Vm . To guess what dot product to use in our problem, we need to look at our original equation written in the weak form
Open AGH e-podręczniki - content available under the CC BY-SA license
135
5.2. Stabilization of the advection-diffusion equations with the residual minimization method
b(u, v) = l(v) Z Z ∂u(x, y) ∂u(x, y) b(u, v) = βx (x, y) v(x, y) dx dy + βy (x, y) v(x, y) dx dy ∂x ∂y Ω Ω Z Z ∂u(x, y) ∂v(x, y) ∂u(x, y) ∂v(x, y) + dx dy + dx dy ∂x ∂x ∂y ∂y Ω Z Ω l(v) = f (x, y)v(x, y) dx dy Ω
and see what form the test functions are v w formie b(u, v). We see here that we are dealing with partial ∂v(x,y) derivatives ∂v(x,y) and with the function itself v(x, y). Our inner product should therefore contain ∂x , ∂y derivatives and values of functions R R R ∂u(x,y) ∂u(y,y) ∂u(y,y) (u, v)Vm = Ω u(x, y)v(x, y)dxdy + Ω ∂u(x,y) ∂x ∂x dxdy + Ω ∂y ∂y dxdy In conclusion, in the residual minimization method, we need to define a separate approximation space, and a separate (larger) testing space, and choose the inner product of the testing space. We then get a system of equations in which the unknown is our solution u and additionally, a residuum r. How well the residual minimization method works depends largely on our choice of test space and inner product. If the inner product is sufficiently accurate, and the testing space is large enough, everything will work perfectly, and we will get the best possible solution in the approximation space Uh (but not better than the approximation space allows). The mathematical justification is that the problem of minimizing the residual with an infinite-dimensional test space realizes the inf-sup stability condition with a constant equal to 1. If the testing space is narrowed down to a finite-dimensional space, the inf-sup condition may no longer be perfectly realized in this space. Increasing the testing space will improve the feasibility of the inf-sup stability condition. Our system of equations to be solved in the residual minimization method is as follows ! ! ! G B r f = BT 0 u 0 Let’s see what our system of equations looks like on the example of specific approximation and testing spaces.
EXAMPLE
Example 10: System of equations for the residual minimization method for the advection-diffusion problem with quadratic C1 trial space and cubic C1 test space We now define the functions used to approximate the solution and for testing. We specify what our patch of elements will look like and our B-spline base functions spread over elements, giving a knot vector along the axis x and knot vector aloing axis y. Here we refer to the third chapter, which describes the way of defining the base functions using node vectors and B-spline polynomials. Along the axis x we introduce a knot vector [0 0 0 1 2 3 4 4 4], similarly along axis y we introduce a knot vector [0 0 0 1 2 3 4 4 4]. We obtained two bases of one-dimensional B-spline functions {Bi,2 (x)}i=1,...,6 and {Bj,2 (y)}j=1,...,6 .
Open AGH e-podręczniki - content available under the CC BY-SA license
136
5.3. Stabilization of the advection-diffusion equations with the Streamline Upwind Petrov-Galerkin (SUPG) Then we will create tensor products from them Bi,j;2 (x, y) = Bi,2 (x)Bj,2 (y), i, j = 1, ..., 6. We assume our area Ω is span on a square [0, 1]2 , similar to our 6 * 6 = 36 basis functions which results from the definition of the knot vectors [0 0 0 1 2 2 3 4 4 4]. Now note that the inner product matrix G it is stretched over the testing space. Also note that our problem matrix B it is spread over rows from the testing space and columns from the approximation space. Let us first write the matrix of our problem B . R ∂Bi,2 (x) ˜k,3 (x)B ˜l,3 (y) B1i,j=1,...,6;k,l=1,...,10 = Ω βx ∂x Bj,2 (y)B R ˜k,3 (x) ∂ B˜l,3 (y) dxdy B2i,j=1,...,6;k,l=1,...,10 = Ω βy Bi,2 (x)Bj,2 (y)B ∂y A1i,j=1,...,6;k,l=1,...,10 =
R
A2i,j=1,...,6;k,l=1,...,10 =
R
Ω Ω
˜ (x) ∂B ∂Bi,2 (x) ˜l,3 (y)dxdy Bj,2 (y) k,3 B ∂x ∂x
Bi,2 (x)
˜ l,3 (y) ∂B ∂Bj,2 (y) ˜ Bk,3 (x) ∂y dxdy ∂y
and the right side R ˜k,3 (x)B ˜l,3 (y)dxdy Fk,l=1,...,10 = Ω f (x, y)B Our matrix looks like this B = A1 + A2 + B1 + B2 Note that now it is NOT a square matrix (we have a different number of rows and columns). Let us first write the matrix of our problem G. R ˜i,3 (x)B ˜j,3 (y)B ˜k,3 (x)B ˜l,3 (y)dxdy G1i,j=1,...,10;k,l=1,...,10 = Ω B R ∂ B˜i,3 (x) ˜j,3 (y) ∂ B˜k,3 (x) B ˜l,3 (y)dxdy G2i,j=1,...,10;k,l=1,...,10 = Ω ∂x B ∂x R ˜i,3 (x) ∂ B˜j,3 (y) B ˜k,3 (x) ∂ B˜l,3 (y) dxdy G3i,j=1,...,10;k,l=1,...,10 = Ω B ∂y ∂y Our matrix looks like this G = G1 + G2 + G3 Note that now it IS a square matrix with the number of rows and columns corresponding to the size of the testing space.
5.3.
Stabilization of the advection-diffusion equations with the Streamline Upwind Petrov-Galerkin (SUPG)
In this chapter we will describe a method of stabilizing the advection-diffusion equations called Streamline Upwind Petrov-Galerkin (SUPG), introduced by prof. T. J. R. Hughes. This method is described, for example, in the work [31]. Let us recall first the advection-diffusion problem, from the example of the Eriksson-Johnson model problem, described, for example in [32]. This problem is defined in a square area Ω = [0, 1]2 in the following way: we seek a function u such that a(u, v) = l(v)∀v where
Z
a(u, v) =
l(v) =
R ∂Ω
Z ∂u(x, y) ∂u(x, y) βx (x, y) dx dy + βy (x, y) dx dy ∂x ∂y Ω Ω Z Z ∂u(x, y) ∂v(x, y) ∂u(x, y) ∂v(x, y) + dx dy + dx dy ∂x ∂x ∂y ∂y Ω Ω
f (x, y)vdxdy
Open AGH e-podręczniki - content available under the CC BY-SA license
137
5.4. Stabilization of the Stokes problem with the residual minimization method f (x, y) = sin(πy)(1 − x) is an extension of the Dirichlet boundary condition to the entire area, while β = (1, 0) represents the wind blowing from left to right, while = 10−6 is the diffusion coefficient. The SUPG stabilization method (Streamline Upwind Petrov-Galerkin) modifies our equation by adding certain terms that do not change the ”sense” of the equation, but enforce the inf-sup condition a(u, v) + P P ∀v ∈ V K (R(u) + f, τ β · ∇v)K = l(v) + K (f, τ β · ∇v)K where R(u) = β · ∇u + ∆u − f = ∂u ∂x + ∆u − f represents the residual of our solution, that is, the error between the left and right-hand sides resulting from the discretization of our problem. In other words, on a continuous level, in the abstract infinite dimensional functional spaces (which theoretically allow for an exact approximation of the solution) the residual is zero (in abstract infinite dimensional spaces we do not go wrong). However, since we are using a computational grid and a finite number of approximation functions, residuum will measure us the error of the method. a discrete-level β 1 τ −1 = hβxx + hyy + 3 h2 +h 2 x
y
= 10−6 β = (1, 0) hx , hy is the element dimension (we divide our integrals into individual elements and on each element we calculate the modified integral using the formula containing the element diameter), and R (u, v)K = K uvdx denotes the dot product over the element K.
5.4.
Stabilization of the Stokes problem with the residual minimization method
Consider the Stokes problem that requires additional stabilization. Let us write it as a single functional (5.3)
B((u, p), (v, q)) = L(v) where B((u, p), (v, q)) =
L(v) =
! a(u, v) + b(p, v) b(q, u)
! f (v 0
and a(u, v) =
R
b(p, v) =
R
∂u1 ∂v1 dxdy Ω ∂x ∂x
Ω
1 p ∂v ∂x dxdy +
+ R Ω
∂u1 ∂v1 dxdy Ω ∂y ∂y
R
+
R
∂u2 ∂v2 dxdy Ω ∂x ∂x
+
R
∂u2 ∂v2 dxdy Ω ∂y ∂y
2 p ∂v ∂y dxdy
We denote by U × P function space in which we are looking for a solution to the Stokes problem (u, p) ∈ U × P. Then we denote by V × Q space of functions that we use for testing in our variational (also called weak) formulation. In this chapter we will describe, using an abstract mathematical language, how the method of minimizing the residual is derived [30]. Our original problem can be written as follows: we are looking for a function (u, p) ∈ U × P such that B((u, p), (v, q)) = L(v) for all test functions (v, q) ∈ V × Q. You can mark the left side mathematically B(u, p) and the right side L by introducing certain mathematical operators (mathematicians will say that B : (U × P ) → (V × Q)0 and Open AGH e-podręczniki - content available under the CC BY-SA license
138
5.4. Stabilization of the Stokes problem with the residual minimization method hB(u, p), (v, q)i = B((u, p), (v, q)). Then our problem reduces to finding (u, p) such that B(u, p) − l = 0. This expression is called a residuum r = B(u, p) − l. If we only have an approximate solution, for example denoted (uh , ph ) then our residual will express an error, the greater the residual, the greater the error of the approximate solution rh = B(uh , ph ) − l. How to measure the solution error, i.e. expressed by the residuum? To measure how big the residual is, we need to introduce some norm (i.e. a measure of size) rh = kB(uh , ph ) − lk. I can now say that we are looking for a solution to our problem (uh , ph ) that the residuum (or error) would be as little as possible. Mathematically, this condition is written in the form of minimizing the norm 1 (uh , ph ) = argmin(wh ,sh )∈U ×P kB(wh , sh ) − lk2(V,Q)0 2 It writes in before the norm
1 2
and the norm is squared.
The practical problem is that we don’t know how to calculate the norm from the difference kB(wh , sh ) − lk. This standard measures distances in an abstract mathematical space (V × Q)0 (mathematicians will say that this space is dual to the space of test functions). To solve this problem, we perform the math trick of projecting a norm from (V × Q)0 to the testing space V × Q. A projector operator is introduced (V × Q) into space (V × Q)0 . This operator is called the Riesz operator R(V,Q) : (V ×Q) 3 (v, q) → ((v, q), .) ∈ (V ×Q)0 . The inverse operator, −1 on the other hand, projects the space (V × Q)0 back into space V × Q, so R(V,Q) : V 0 3 (v, .) → v ∈ V . So if we use the inverse Riesz operator, we move our problem to the space of test functions V × Q. So we have 1 −1 (uh , ph ) = argmin(wh ,sh )∈(Uh ×Ph ) kR(V,Q) (B(wh , sh ) − l)k2V ×P . So we are looking for the point at which 2 the function reaches its minimum. This point is reached when the derivatives of this function are equal to zero. Since we have a functional here, mathematicians will say we’re looking for one (uh , ph ) where the derivatives of Gateaux are zero in all directions −1 −1 hR(V,Q) (B(uh , ph ) − l), R(V,Q) (B, (wh , sh ))iV = 0 ∀(wh , sh ) ∈ Uh × Ph where (wh , sh ) stands for all possible ”directions” from a finite dimensional function space Uh × Ph (in which we are also looking for a solution to our Stokes problem).
Technically speaking, at this point we have to construct a finite dimensional space of functions Uh × Ph in which we will look for our solution. We do this of course in our textbook using the B-spline basis functions, spanning them along the knot vectors along the x-axis and along the y-axis. Along the axis x we introduce knot vector [0 0 0 1 2 3 4 4 4], likewise along the axis y we introduce a knot vector [0 0 0 1 2 3 4 4 4]. We obtained two bases of one-dimensional B-spline basis functions {Bi,2 (x)}i=1,...,6 and {Bj,2 (y)}j=1,...,6 . Then we create tensor products from them Bi,j;2 (x, y) = Bi,2 (x)Bj,2 (y), i, j = 1, ..., 6. Note that our area Ω it is stretched over a square [0, 1]2 , similar to our 6 * 6 = 36 basis functions which results from the definition of the knot vectors [0 0 0 1 2 2 3 4 4 4]. Our approximation space is then spanned by the tensor products of our one-dimensional B-spline functions. Now instead we have two velocity coordinates and one pressure scalar value, so we get
Open AGH e-podręczniki - content available under the CC BY-SA license
139
5.4. Stabilization of the Stokes problem with the residual minimization method
Uh × Qh = gen{Bi,j;2 (x, y) = Bi,2 (x)Bj,2 (y), i, j = 1, . . . , 6, Bi,j;2 (x, y) = Bi,2 (x)Bj,2 (y), i, j = 1, . . . , 6, Bi,j;2 (x, y) = Bi,2 (x)Bj,2 (y), i, j = 1, . . . , 6} We denote −1 r = R(V,Q) (B(uh , ph ) − l)
and then we can rewrite −1 hr, R(V,Q) (B (wh , sh ))i = 0
∀ (wh , sh ) ∈ Uh × Ph
which is synonymous hB(wh , sh ), ri = 0
∀(wh , sh ) ∈ Uh × Ph .
We now add a second equation using the definition of the residuum r = B(uh , ph ) − l, we multiply the residuum definition by the test functions from the space of test functions and we get the equation: (r, v)V = hB(uh , ph ) − l, (v, q)i
∀(v, q) ∈ V × Q.
So we have a system of equations: finding a residual in an infinite dimensional space of test functions r ∈ V × Q and solutions in a finite dimensional function space uh , ph ) ∈ Uh × Ph
(r, v)V − hB(uh , ph ) − l, (v, q)i = 0 hB(wh , sh ), ri = 0
∀(v, q) ∈ V × Q, ∀(wh , sh ) ∈ Uh × Ph
If we were able to solve this equation, we would get the best possible approximation of our problem in the space of approximating functions Uh × Ph . Unfortunately, this is not possible, because the infinite space of test functions generates an infinite number of equations that should be solved. So we have to choose a second different base to approximate the test space. Here comes the first significant difference between the Residual Minimization Method and the traditional Finite Element Method. In the method of minimizing the residuum, we have two different spaces, one for the approximation of the solution, the other for testing. Of course, the testing space is also spanned using the B-spline function. For example, we can use the same element patch for the approximating space (but this is not required!), but we increase the degree of the B-spline function. We define what our patch of elements will look like and our B-spline basis functions spread over the elements, giving a knot vector along the axis x and knot vector along the y. We refer here to the third chapter, which describes the way of defining the base functions using knot vectors and B-spline functions. Along the axis x we introduce a knot vector [0 0 0 1 2 3 4 4 4], likewise along the axis y we introduce a knot vector [0 0 0 1 2 3 4 4 4]. So we use C1-continuous B-splines for approximation. For testing we will increase their degree, and leave C1 continuity. Along the axis x we introduce a knot vector [0 0 0 0 1 1 2 2 3 3 4 4 4 4], likewise along the axis y we introduce a knot vector [0 0 0 0 1 1 2 2 3 3 4 4 4 4]. Generally, the test spaces must be larger than the approximation space. We can achieve this effect by increasing the number of elements or increasing the degree of the B-spline function, or reducing the continuity of the B-spline function basis, or by mixing the three approaches together. The approximation space should be a subspace of the testing space. ˜k,3 (x)}k=1,...,10 and We obtain two bases of one-dimensional B-spline functions used for testing {B ˜l,3 (y)}l=1,...,7 . Then we will create tensor products B ˜k,l;3 (x, y) = B ˜k,3 (x)B ˜l,3 (y), k, l = 1, ..., 10. {B
Open AGH e-podręczniki - content available under the CC BY-SA license
140
5.4. Stabilization of the Stokes problem with the residual minimization method Our testing space, taking into account two test function coordinates for the velocity field and one test ˜k,3 (x)B ˜l,3 (y), i, j = 1, ..., 10; B ˜k,3 (x)B ˜l,3 (y), i, j = function coordinate for pressure, is Vh × Qh = gen{B ˜ 1, ..., 10; Bk,3 (x)Bl,3 (y), i, j = 1, ..., 10}. Having a discrete testing space, we finally obtain our discrete (so finite dimensional) system of equations that we want to solve. We are looking for (rm , (uh , ph ))Vm ×Uh ×Ph
(rm , (vm , qh ))Vm ×Qh − hB(uh , ph ) − l, (vm , qm )i = 0 hB(wh , qh ), rm i = 0
∀(vm , qm ) ∈ Vm × Qm , ∀(wh , qh ) ∈ Uh × Ph
This is where the so-called inner product appears in a discrete testing space (∗, ∗)Vm ×QM . To guess what dot product to use in our ! problem, we need to look at our original equation in the weak a(u, v) + b(p, v) form B((up), (v, q)) = b(q, u) and see what form the test functions are in (v, q) in its components R R ∂u1 ∂v1 R ∂u2 ∂v2 R ∂u2 ∂v2 1 ∂v1 a(u, v) = Ω ∂u ∂x ∂x dxdy + Ω ∂y ∂y dxdy + Ω ∂x ∂x dxdy + Ω ∂y ∂y dxdy R R ∂v2 1 b(p, v) = Ω p ∂v ∂x dxdy + Ω p ∂y dxdy Our innner product should therefore contain derivatives of functions v1 , v2 and function values q.
((u, p), (v, q))Vm ×Qm = Z Z ∂u1 (x, y) ∂v1 (x, y) = p(x, y)q(x, y) dx dy + dx dy ∂x ∂x Ω ZΩ Z ∂u1 (x, y) ∂v1 (x, y) ∂u2 (x, y) ∂v2 (x, y) + dx dy + dx dy ∂y ∂y ∂x ∂x Ω Ω Z ∂u2 (x, y) ∂v2 (x, y) + dx dy ∂y ∂y Ω In conclusion, in the residual minimization method, we need to define a separate approximation space, and a separate (larger) testing space, and choose the inner product of the testing space. We then get a system of equations in which the unknown is our solution (u, p) and additionally, a residuum r. How well the minimization residual works will largely depend on our choice of the test space and the inner product. If the inner product is sufficiently accurate, and the test space is large enough, everything will work perfectly well, and we will get the best possible solution in the approximation space Uh (but not better than the approximation space allows). The mathematical justification is that the residual minimization problem with an infinite-dimensional test space realizes the inf-sup stability condition with a constant equal to 1. If the testing space is narrowed down to a finite-dimensional space, the inf-sup condition may no longer be perfectly realized in this space. Increasing the testing space will improve the feasibility of the inf-sup stability condition. Our system of equations to be solved by the residual minimization method is as follows ! ! ! G B r f = BT 0 u 0 Let’s see what our system of equations looks like on the example of specific approximation and testing spaces.
Open AGH e-podręczniki - content available under the CC BY-SA license
141
5.4. Stabilization of the Stokes problem with the residual minimization method
EXAMPLE
Example 11: System of equations of the residuum minimization method for the Stokes problem for approximation polynomials (2,1) and testing polynomials (3,1) We now define the functions used to approximate the solution and for testing. We define what our patch of elements will look like and our B-spline basis functions spread over elements, giving a vector of nodes along the axis x and vector of nodes along the axis y. We refer here to the third chapter, which describes the way of defining the base functions using knot vectors and B-spline functions. Along the axis x we introduce a knot vector [0 0 0 1 2 3 4 4 4], likewise along the axis y we introduce a knot vector [0 0 0 1 2 3 4 4 4]. We obtained two bases of one-dimensional B-spline functions {Bi,2 (x)}i=1,...,6 and {Bj,2 (y)}j=1,...,6 . Then we create tensor products from them Bi,j;2 (x, y) = Bi,2 (x)Bj,2 (y), i, j = 1, ..., 6. We assume our area Ω it is stretched over a square [0, 1]2 , similar to our 6 * 6 = 36 basis functions which results from the definition of the knot vector [0 0 0 1 2 2 3 4 4 4]. We now take our approximation of the velocity fields P u1 (x, y) ≈ i,j=1,...,6 ui,j 1 Bi,2 (x)Bj,2 (y) P u2 (x, y) ≈ i,j=1,...,6 ui,j 2 Bi,2 (x)Bj,2 (y) and pressure P p(x, y) ≈ i,j=1,...,6 pi,j Bi,2 (x)Bj,2 (y) In the residual minimization method, a different, larger space is used for testing than for the approximation. So let us assume that we unbind the testing functions with a knot vector [0 0 0 0 1 1 2 2 3 3 4 4 4 4] along the x-axis, likewise along the y-axis we introduce a knot vector [0 0 0 0 1 1 2 2 3 3 4 4 4 4]. In other words, for approximation we use B-spline functions of quadratic C1 continuity; for testing we use B-spline functions of the third order also with C1 continuity. Mathematicians say that it is good for the approximation space to be a sub-space of the testing space. Now, we obtain two bases of one-dimensional B-spline functions ˜i,3 (x)}i=1,...,10 and {B ˜j,3 (y)}j=1,...,10 . We create tensor products B ˜i,j;3 (x, y) {B ˜ ˜ Bi,2 (x)Bj,3 (y), i, j = 1, ..., 6.
=
So for testing we use a combination of linear B-spline functions from the test spacer P ˜k,3 (x)B ˜l,3 (y) v1 (x, y) ≈ k,l=1,...,10 v1k,l B P ˜k,3 (x)B ˜l,3 (y) v2 (x, y) ≈ k,l=1,...,10 v2k,l B and pressure P ˜k,3 (x)B ˜l,3 (y) q(x, y) ≈ k,l=1,...,10 q k,l B Now note that the inner product matrix G it is stretched over the testing space. Also note that our problem matrix B is spread over rows from the testing space and columns from the approximation space.
Open AGH e-podręczniki - content available under the CC BY-SA license
142
5.5. Stabilization of the Stokes problem with the Discontinuous Galerkin method (DG) Let us first write the matrix of our problem B. ˜k,3 (x)B ˜l,3 (y), 0, 0) dla k = l, ..., 10 and put into We now take functions first (v, q) = (v1 , 0, 0) = (B the equation (??.1). We get matrices R B (x) R ˜ k,3 (x) ∂B ˜l,3 (y)dxdy + Bi,2 (x) ∂Bj,2 (y) B ˜k,3 (x) ∂ B˜l,3 (y) dxdy A1i,j=1,...,6;k,l=1,...,10 Ω i,2 B ∂x Bj,2 (y) ∂x ∂y ∂y Ω R ∂Bi,2 (x) ˜k,3 (x)B ˜l,3 (y) B1i,j=1,...,6;k,l=1,...,10 = Ω ∂x Bj,2 (y)B ˜k,3 (x)B ˜l,3 (y), 0) dla k = l, ..., 10 and put into Then we take base functions (v, q) = (0, v1 , 0) = (0, B the equation (??.1). We get matrices R ∂Bi,2 (x) R ˜ l,3 (x) ∂B (x) ∂B ∂Bj,2 (y) ˜ A2i,j=1,...,6;k,l=1,...,10 = Ω ∂x Bj,2 (y) k,3 Bl,3 (y)dxdy+ Ω Bi,2 (x) ∂y Bk,3 (y) ∂y dxdy ∂x B2i,j=1,...,6;k,l=1,...,10 =
R Ω
˜k,3 (x) ∂ B˜l,3 (y) dxdy Bi,2 (x)Bj,2 (y)B ∂y
˜k,3 (x)B ˜l,3 (y)) dla k = l, ..., 10 and Additionally, assuming base functions (v, q) = (0, 0, q) = (0, 0, B put into the equation (??.1). We get matrices R ∂Bi,2 (x) ˜k,3 (x)B ˜l,3 (y)dxdy Q1i,j=1,...,6;k,l=1,...,10 = Ω ∂x Bj,2 (y)B R ∂Bj,2 (y) ˜ ˜l,3 (y)dxdy Q2i,j=1,...,6;k,l=1,...,10 = Ω Bi,2 (x) ∂y Bk,3 (x)B R R ∂h(x,y) ˜ k,3 (x) ∂B ˜l,3 (y)dxdy + ˜ ˜ and right-hand side F 1k,l=1,...,10 = Ω ∂h(x,y) B ∂x ∂x ∂n Bk,3 (x)Bl,3 (y)dS ∂Ω R R ∂h(x,y) ˜k,3 (x) ∂ B˜l,3 (y) dxdy + ˜ ˜ F 2k,l=1,...,10 = Ω ∂h(x,y) ∂y B ∂y ∂n Bk,3 (x)Bl,3 (y)dS ∂Ω A1 0 B1 Our matrix looks like this 0 A2 B2 Q1 Q2 0 Note that now it IS NOT a square matrix (we have a different number of rows and columns). Let us first write the matrix of our problem G. R ˜i,3 (x)B ˜j,3 (y)B ˜k,3 (x)B ˜l,3 (y)dxdy G1i,j=1,...,10;k,l=1,...,10 = Ω B R ∂ B˜i,3 (x) ˜j,3 (y) ∂ B˜k,3 (x) B ˜l,3 (y)dxdy G2i,j=1,...,10;k,l=1,...,10 = Ω ∂x B ∂x R ˜i,3 (x) ∂ B˜j,3 (y) B ˜k,3 (x) ∂ B˜l,3 (y) dxdy G3i,j=1,...,10;k,l=1,...,10 = Ω B ∂y ∂y G1 0 0 Our matrix looks like this 0 G2 + G3 0 0 0 G2 + G3 Note that now it IS a square matrix with the number of rows and columns corresponding to the size of the testing space.
5.5.
Stabilization of the Stokes problem with the Discontinuous Galerkin method (DG)
One of the possible methods of stabilizing the Stokes equations is the DG (Discontinuous Galerkin) method. In this method, the basis functions used to approximate and test the solutions are ”cut” into pieces with scissors at the boundary of individual elements. So if we want to use B-spline polynomials, we can continue to use them, but over each element they will be cut into local pieces. In this chapter, we build on the DG formulation of Stokes equations [28]. We use the formulation derived in the previous chapter. Additionally, the average of the values of the dissected basis functions on the edges of two adjacent Open AGH e-podręczniki - content available under the CC BY-SA license
143
5.5. Stabilization of the Stokes problem with the Discontinuous Galerkin method (DG) elements is introduced a(u, v) + b(p, v) = f (v) ∀v b(q, u) = 0 ∀q R R R ∂u1 ∂v1 R ∂u2 ∂v2 R 1 ∂v1 a(u, v) = Ω ∇u : ∇vdxdy = Ω ∂u ∂x ∂x dxdy + Ω ∂y ∂y dxdy + Ω ∂x ∂x dxdy + Ω R R R ∂v2 1 b(p, v) = Ω pdivvdxdy = Ω p ∂v ∂x dxdy + Ω p ∂y dxdy R R R ∂v1 (x,y) ∂v2 (x,y) f (v) = Ω ∂h(x,y) dxdy + Ω ∂h(x,y) dxdy + ∂Ω ∂h(x,y) ∂x ∂x ∂y ∂y ∂n v1 (x, y)dS
∂u2 ∂v2 ∂y ∂y dxdy
In the case of formulation for the DG method, it is necessary to introduce additional terms describing jumps of basis functions [ψ(x)] = ψ|T1 (x) − ψ|T2 (x) where T1 i T2 stands for two adjacent elements, and we calculate here the difference from the ”cleaved” value of the B-spline function marked ψ on the element on one side and on the other side. Additionally, the average of the values of the dissected base functions on the edges of two adjacent ψ| (x)+ψ| (x) elements is entered {ψ} = T1 2 T2 . Our functional a(u, v) should be modified for DG method as follows R 1 ∂v1 P ∂u1 ∂v1 ∂u2 ∂v1 ∂u2 ∂v1 aDG (u, v) = K∈Ωh K ∂u + + + ∂x ∂x ∂y ∂y ∂x ∂x ∂y ∂y R η ∂u1 ∂v1 P ∂v1 ∂u2 ∂v2 ∂u2 ∂v2 1 + F ∈Fh F hF [ ∂x ][ ∂x ] + [ ∂u ∂y ][ ∂y ] + [ ∂x ][ ∂x ] + [ ∂y ][ ∂y ] R ∂u1 ∂v1 P ∂u1 ∂v1 ∂u2 ∂v2 ∂u2 ∂v2 − F ∈Fh F { ∂n }[ ] + { }[ ] + { }[ ] + { }[ ] ∂x ∂n ∂y ∂n ∂x ∂n ∂y 1 2 1 2 R ∂u1 ∂v1 P ∂v1 ∂u2 ∂v2 ∂u2 ∂v2 1 − F ∈Fh F [ ∂x ]{ ∂n1 } + [ ∂u ]{ } + [ ]{ } + [ ]{ } ∂y ∂n2 ∂x ∂n1 ∂y ∂n2 In the above formulas, the integrals are computed element by element. Thus Ωh means the collection of all elements from the patch on which our B-spline functions are spread, K ∈ Ωh denotes a single element selected from a family of elements (so we sum our element integrals over all elements in the patch), Fh stands for the collection of all edges between patch elements, F ∈ Fh denotes a single edge selected from this family (so we sum our edge integrals over all edges from the patch), hF denotes the edge length F , and η denotes the stabilization parameter. Its proper value needs to be found experimentally. Unfortunately, the disadvantage of this stabilization method is the fact that we have to run a few calculations and find this parameter value η for which the simulation will give correct results.Typically, you experiment with values that differ by an order of magnitude, e.g. 0.1, 1, 10, 100, 1000, 10000 etc. Symbol n = (n1 , n2 ) denotes the unit vector perpendicular to the edge F . In our case, when we consider the B-spline base functions spanned over a regular 2D patch of elements, we assume n = (1, 0) or n = (0, 1). Our functional b(p, v) should be modified for DG method as follows R 1 P ∂v2 bDG (p, v) = − K∈Ωh K p ∂v ∂x + p ∂y R P + F ∈Fh F ([v1 ]n1 p + [v2 ]n2 p) The meaning of the symbols in integrals is similar to that of a functional a(u, v). Our stabilized Stokes problem now looks like this: aDG (u, v) + bDG (p, v) = f (v) ∀v bDG (q, u) + SDG (p, q) = 0
∀q
According to the book Daniele Antoni Di Pietro, Alexandre Ern, Mathematical Aspects of Discontinuous Galerkin Methods, to stabilize the Stokes problem we need to add the term R P SDG (p, q) = F ∈F internal hF F [p][q] h
Open AGH e-podręczniki - content available under the CC BY-SA license
144
5.6. MATLAB implementation of the advection-diffusion problem with SUPG where Fhinternal stands for all inner edges, so we sum here the integrals calculated on all edges of the elements inside the patch (avoid the edges located on the edge). As before, hF denotes the edge length. In order to solve the Stokes equations stabilized by the DG method, we generate a similar system of equations, taking into account the above modifications. It is also possible to consider various modifications. We will assume the following facts about the approximating and testing functions. Let us assume that the test functions will be continuous, in the sense that over individual segments of the knot vector in the isogeometric analysis, or over individual finite elements in the sense of the classical finite element method, they will be continuous, but will be discontinuous between the elements or between the knot vector segments. So we have ”broken” test polynomials. Let us also assume that approximation functions are continuous. Then, all terms containing jumps and averages from the approximating function will disappear, in particular we will get modified expressions R 1 ∂v1 P ∂u1 ∂v1 ∂u2 ∂v1 ∂u2 ∂v1 aDG (u, v) = K∈Ωh K ∂u + + + ∂x ∂x ∂y ∂y ∂x ∂x ∂y ∂y R ∂u1 ∂v1 P ∂u1 ∂v1 ∂u2 ∂v2 ∂u2 ∂v2 − F ∈Fh F { ∂n1 }[ ∂x ] + { ∂n }[ ] + { }[ ] + { }[ ] ∂y ∂n1 ∂x ∂n2 ∂y 2 R ∂v1 P 2 bDG (p, v) = − K∈Ωh K p ∂x + p ∂v ∂y R P + F ∈Fh F ([v1 ]n1 p + [v2 ]n2 p) SDG (p, q) = 0 We will assume the following facts about the approximating and testing functions. Let us assume that the approximating functions will be continuous pieces in the sense that over individual segments of the knot vector in the isogeometric analysis, or over individual finite elements in the sense of the classical finite element method, they will be continuous, but will be discontinuous between the elements or between the segments of the knot vector. So we have ”broken” approximation polynomials. Let us also assume that the test functions are continuous. Then we have R 1 ∂v1 P ∂u1 ∂v1 ∂u2 ∂v1 ∂u2 ∂v1 aDG (u, v) = K∈Ωh K ∂u + + + ∂x ∂x ∂y ∂y ∂x ∂x ∂y ∂y R ∂u1 ∂v1 P ∂v1 ∂u2 ∂v2 ∂u2 ∂v2 1 − F ∈Fh F [ ∂x ]{ ∂n1 } + [ ∂u ]{ } + [ ]{ } + [ ]{ } ∂y ∂n2 ∂x ∂n1 ∂y ∂n2 R ∂v1 P 2 bDG (p, v) = − K∈Ωh K p ∂x + p ∂v ∂y SDG (p, q) = 0 If we put continuous approximation and test spaces into the DG formulation, we will get the same original Stokes formulation without stabilization. Different variants of approximation and testing spaces can be helpful when testing various forms of stabilization and for debugging the code generating the matrix of the DG method.
5.6.
MATLAB implementation of the advection-diffusion problem with SUPG
Below you can find a link to the MATLAB code calculating the advection-diffusion problem with the finite element method with Streamline Upwind Petrov-Galerkin (SUPG) stabilization for the model Eriksson-Johnson problem. Let us recall first the advection-diffusion problem, the Eriksson-Johnson model problem (described, for example, in [30]), defined on a square domain Ω = [0, 1]2 in the following way. We seek u such as a(u, v) = l(v)∀v where
Open AGH e-podręczniki - content available under the CC BY-SA license
145
5.6. MATLAB implementation of the advection-diffusion problem with SUPG
Z
a(u, v) =
l(v) =
R ∂Ω
Z ∂u(x, y) ∂u(x, y) βx (x, y) dx dy + βy (x, y) dx dy ∂x ∂y Ω Ω Z Z ∂u(x, y) ∂v(x, y) ∂u(x, y) ∂v(x, y) + dx dy + dx dy ∂x ∂x ∂y ∂y Ω Ω
f (x, y)vdxdy
f (x, y) = sin(πy)(1 − x) is an extension of the Dirichlet boundary condition to the entire area, while β = (1, 0) represents the wind blowing from left to right, while = 10−2 is the diffusion coefficient. The quantity P e = 1/ = 100 is called the Peklet number, and it defines the sensitivity of the advection-diffusion problem. In line 848 we setup the diffusion coefficient = 10−2 . Its inverse is the so-called Peclet number P e = 1 . SUPG parameters are setup in lines 849 and 850. Then a vector of nodes is created (always natural numbers counted from zero)knot_x [0 0 0 1 2 2 2] for the trial space,
=
and the knot vector along x axis from (0,1) interval, points_x = [0 0.5 1] which will contain the basis of B-spline functions used to approximate the solution to the Eriksson-Johnson problem. The node vectors for the approximating space and the points on which we span the node vectors are defined separately for the x axis and for the y axis. The code execution is also possible in the free Octave environment. Download code or see Appendix 5. The code is activated by opening it in Octave and typing a command advection_supg_adapt After a moment of calculation, the code opens an additional window and draws a numerical and exact solution in it. The code calculates the residuum error Residualnorm : L20.015808, H10.100417 The code also computes the norm L2 and H1 from the solution Error : L231.41procent, H138.74percent and compares to the L2 and H1 standards from the exact solution. Bestpossible : L22.06procent, H128.73percent You can see that in order to improve the accuracy of the solution, it is necessary to compact the mesh.
EXERCISE
Exercise 11: Uniform mesh refinement Exercise content:
Open AGH e-podręczniki - content available under the CC BY-SA license
146
5.6. MATLAB implementation of the advection-diffusion problem with SUPG Increase the number of points to five in the x and y directions, keeping the degrees of the B-spline polynomials. Please check how this operation improves the accuracy of the solution.
Solution:
knot_x = [0 0 0 1 2 3 4 4 4]; points_x = [0 0.25 0.5 0.75 1]; similarly in the y direction.Error: L2 19.64percent H1 45.47percent Best possible: L2 1.38 percent H1 51.91 percent
EXERCISE
Exercise 12: Adaptive mesh refinement Exercise content:
Please increase the number of points adaptively towards the right bank [0 0.5 0.9 0.95 1] where the coastal layer is, keeping the degrees of B-spline polynomials. Please check how this operation improves the accuracy of the solution
Solution:
knot_x = [0 0 0 1 2 3 4 4 4]; points_x = [0 0.5 0.9 0.95 1]; in y direction knot_y = [0 0 0 1 2 3 4 points_y = [0 0.25 0.5 0.75 1]; Error: L2 11.22percent H1 48.34percent Best possible: L2 0.45percent H1 19.23percent
4
4];
EXERCISE
Exercise 13: Adaptive increasing the trial grid and test by breaking in half the element closest to the singularity for a large value Peclet number Exercise content:
Please modify the problem so that the Peclet number is one million. Please start from the grid [0 0.5 1] in the x direction and [0 0.25 0.5 0.75 1] in the y direction, and increase adaptively the number of points towards the right edge where the boundary layer is, keeping the degrees of B-spline polynomials in the trial space and test. Please check how this operation improves the accuracy of the solution.
Solution:
Open AGH e-podręczniki - content available under the CC BY-SA license
147
5.6. MATLAB implementation of the advection-diffusion problem with SUPG We introduce = 10−6 and we adapt the mesh in the x direction according to: [0 0.5 1] [0 0.5 0.75 1] [0 0.5 0.75 0.875 1] [0 0.5 0.75 0.875 0.9375 1] [0 0.5 0.75 0.875 0.9375 0.96875 1] [0 0.5 0.75 0.875 0.9375 0.96875 0.984375 1] [0 0.5 0.75 0.875 0.9375 0.96875 0.984375 0.9921875 1] [0 0.5 0.75 0.875 0.9375 0.96875 0.984375 0.9921875 0.99609375 1] [0 0.5 0.75 0.875 0.9375 0.96875 0.984375 0.9921875 0.99609375 0.998046875 1] [0 0.5 0.75 0.875 0.9375 0.96875 0.984375 0.9921875 0.99609375 0.998046875 0.9990234375 1] [0 0.5 0.75 0.875 0.9375 0.96875 0.984375 0.9921875 0.99609375 0.998046875 0.9990234375 0.9995117188 1] [0 0.5 0.75 0.875 0.9375 0.96875 0.984375 0.9921875 0.99609375 0.998046875 0.9990234375 0.9995117188 0.9997558594 1] [0 0.5 0.75 0.875 0.9375 0.96875 0.984375 0.9921875 0.99609375 0.998046875 0.9990234375 0.9995117188 0.9997558594 0.9998779297 1] [0 0.5 0.75 0.875 0.9375 0.96875 0.984375 0.9921875 0.99609375 0.998046875 0.9990234375 0.9995117188 0.9997558594 0.9998779297 0.9999389648 1] [0 0.5 0.75 0.875 0.9375 0.96875 0.984375 0.9921875 0.99609375 0.998046875 0.9990234375 0.9995117188 0.9997558594 0.9998779297 0.9999389648 0.9999694824 1] [0 0.5 0.75 0.875 0.9375 0.96875 0.984375 0.9921875 0.99609375 0.998046875 0.9990234375 0.9995117188 0.9997558594 0.9998779297 0.9999389648 0.9999694824 0.9999847412 1] [0 0.5 0.75 0.875 0.9375 0.96875 0.984375 0.9921875 0.99609375 0.998046875 0.9990234375 0.9995117188 0.9997558594 0.9998779297 0.9999389648 0.9999694824 0.9999847412 0.9999923706 1] [0 0.5 0.75 0.875 0.9375 0.96875 0.984375 0.9921875 0.99609375 0.998046875 0.9990234375 0.9995117188 0.9997558594 0.9998779297 0.9999389648 0.9999694824 0.9999847412 0.9999923706 0.9999961853 0.9999980927 1] [0 0.5 0.75 0.875 0.9375 0.96875 0.984375 0.9921875 0.99609375 0.998046875 0.9990234375 0.9995117188 0.9997558594 0.9998779297 0.9999389648 0.9999694824 0.9999847412 0.9999923706 0.9999961853 0.9999980927 0.9999990463 0.9999995232 1] [0 0.5 0.75 0.875 0.9375 0.96875 0.984375 0.9921875 0.99609375 0.998046875 0.9990234375 0.9995117188 0.9997558594 0.9998779297 0.9999389648 0.9999694824 0.9999847412 0.9999923706 0.9999961853 0.9999980927 0.9999990463 0.9999995232 0.9999997616 0.9999998808 1] [0 0.5 0.75 0.875 0.9375 0.96875 0.984375 0.9921875 0.99609375 0.998046875 0.9990234375 0.9995117188 0.9997558594 0.9998779297 0.9999389648 0.9999694824 0.9999847412 0.9999923706 0.9999961853 0.9999980927 0.9999990463 0.9999995232 0.9999997616 0.9999998808 0.9999999404 1]
Open AGH e-podręczniki - content available under the CC BY-SA license
148
5.7. MATLAB implementation of the advection-diffusion problem with residual minimization method [0 0.5 0.75 0.875 0.9375 0.96875 0.984375 0.9921875 0.99609375 0.998046875 0.9990234375 0.9995117188 0.9997558594 0.9998779297 0.9999389648 0.9999694824 0.9999847412 0.9999923706 0.9999961853 0.9999980927 0.9999990463 0.9999995232 0.9999997616 0.9999998808 0.9999999404 0.9999999702 1]
5.7.
MATLAB implementation of the advection-diffusion problem with residual minimization method
Below you can find a link to the MATLAB code calculating the advection-diffusion problem by the finite element method with stabilization by minimizing the residual for the model Eriksson-Johnson problem. First, let us recall the advection-diffusion problem, the Eriksson-Johnson model problem (described, for example, in [30] defined on a square domain Ω = [0, 1]2 in the following way: We seek u such as a(u, v) = l(v)∀v where Z a(u, v) =
l(v) =
R ∂Ω
Z ∂u(x, y) ∂u(x, y) βx (x, y) dx dy + βy (x, y) dx dy ∂x ∂y Ω Ω Z Z ∂u(x, y) ∂v(x, y) ∂u(x, y) ∂v(x, y) + dx dy + dx dy ∂x ∂x ∂y ∂y Ω Ω
f (x, y)vdxdy
f (x, y) = sin(πy)(1 − x) is an extension of the Dirichlet boundary condition to the entire area, while β = (1, 0) represents the wind blowing from left to right, while = 10−2 denotes diffusion coefficient. The quantity P e = 1/ = 100 is called the Peclet number, and it defines the sensitivity of the advection-diffusion problem. In line 830 we specify the diffusion coefficient ϵ=10−2. Its inverse is the Peclet number P e = 1 . We construct the knot vector knot_trial_x = [0 0 0 1 2 2 2] for the approximation space, and vector of point along x axis, between od 0 and 1, points_x = [0 0.5 1]. At these points, we construct the basis of B-spline functions for approximation of the Eriksson-Johnson problem. In a similar way, we define the knot vector for the test space knot_test_x = [0 0 0 0 1 2 2 2 2]. According to the idea of the residual minimization method, there must be more testing functions than approximating functions. In our example, we use the quadratic B-spline function with C1 continuity for the approximation space (trial) and the third degree B-spline function with C1 continuity for the test space (test). The node vectors for the approximating and testing space, and the points on which we span the node vectors, are defined separately for the x axis and for the y axis. The code execution is also possible in the free Octave environment. Download code or see Appendix 5A. The code is activated by opening it in Octave and typing a command advection_igrm_adapt After a moment of calculation, the code opens an additional window and draws a numerical and exact solution in it. In the second window, the code draws a residuum, computed additionally by the residuum minimization method. It is a measure of the local solution error. The code calculates the residuum error Residualnorm : L20.015808, H10.100417 Open AGH e-podręczniki - content available under the CC BY-SA license
149
5.7. MATLAB implementation of the advection-diffusion problem with residual minimization method The code computes also the L2 and H1 norms of the solution Error : L245.90percent, H161.85percent and compares to L2 and H1 norm of the exact solution. Bestpossible : L22.02percent, H114.20percent You can see that in order to improve the accuracy of the solution, it is necessary to increase the mesh.
EXERCISE
Exercise 14: Uniform increase of trial grid and test Exercise content:
Please increase the number of points to five in x and y directions, keeping the degrees of B-spline polynomials in the trial and test space. Please check how this operation improves the accuracy of the solution.
Solution:
knot_trial_x = [0 knot_test_x = [0 points_x = [0
0 0
0 0
0.25
0.5
1 0
2 1
0.75
3 1
4 2
4 2
4]; 3
3
4
4
4
4];
1];
similarly in the x direction. Residual norm: L2 0.009895, H1 0.080162 Error: L2 37.83percent H1 50.92percent Best possible: L2 0.41percent H1 36.77percent
EXERCISE
Exercise 15: Adaptive enlargement of the trial grid and test Exercise content:
Please increase adaptively the number of points towards the right bank [0 0.5 0.9 0.95 1] where the coastal layer is, keeping the degrees of B-spline polynomials in the trial and test space. Please check how this operation improves the accuracy of the solution.
Solution:
knot_trial_x = [0 knot_test_x = [0 points_x = [0
0.5
0 0
0 0
0.9
1 0
2 1
0.95
3 1
4 2
4 2
4]; 3
3
4
4
4
4];
1];in the y direction
Open AGH e-podręczniki - content available under the CC BY-SA license
150
5.7. MATLAB implementation of the advection-diffusion problem with residual minimization method knot_trial_y = [0 knot_test_y = [0 points_y = [0
0 0
0.25
0 0 0.5
1 0
2 1
3 1
0.75
4 2
4 2
4]; 3
3
4
4
4
4];
1];
Residual norm: L2 0.001154 H1 0.027074Error: L2 3.92percent H1 36.15percent Best possible: L2 1.00percent H1 46.50percent
EXERCISE
Exercise 16: Adaptive increasing the trial grid and test by breaking in half the element closest to the singularity for a large Peclet number Exercise content:
Please modify the problem so that the Peclet number is one million. Please start from the grid [0 0.5 1] in the x direction and [0 0.25 0.5 0.75 1] in the y direction, and increase adaptively the number of points towards the right edge where the boundary layer is, keeping the degrees of B-spline polynomials in the trial space and test. Please check how this operation improves the accuracy of the solution.
Solution:
We enter = 10−6 and we modify the grid according to the sequence [0 0.5 1] [0 0.5 0.75 1] [0 0.5 0.75 0.875 1] [0 0.5 0.75 0.875 0.9375 1] [0 0.5 0.75 0.875 0.9375 0.96875 1] [0 0.5 0.75 0.875 0.9375 0.96875 0.984375 1] [0 0.5 0.75 0.875 0.9375 0.96875 0.984375 0.9921875 1] [0 0.5 0.75 0.875 0.9375 0.96875 0.984375 0.9921875 0.99609375 1] [0 0.5 0.75 0.875 0.9375 0.96875 0.984375 0.9921875 0.99609375 0.998046875 1] [0 0.5 0.75 0.875 0.9375 0.96875 0.984375 0.9921875 0.99609375 0.998046875 0.9990234375 1] [0 0.5 0.75 0.875 0.9375 0.96875 0.984375 0.9921875 0.99609375 0.998046875 0.9990234375 0.9995117188 1] [0 0.5 0.75 0.875 0.9375 0.96875 0.984375 0.9921875 0.99609375 0.998046875 0.9990234375 0.9995117188 0.9997558594 1] [0 0.5 0.75 0.875 0.9375 0.96875 0.984375 0.9921875 0.99609375 0.998046875 0.9990234375 0.9995117188 0.9997558594 0.9998779297 1]
Open AGH e-podręczniki - content available under the CC BY-SA license
151
5.7. MATLAB implementation of the advection-diffusion problem with residual minimization method [0 0.5 0.75 0.875 0.9375 0.96875 0.984375 0.9921875 0.99609375 0.998046875 0.9990234375 0.9995117188 0.9997558594 0.9998779297 0.9999389648 1] [0 0.5 0.75 0.875 0.9375 0.96875 0.984375 0.9921875 0.99609375 0.998046875 0.9990234375 0.9995117188 0.9997558594 0.9998779297 0.9999389648 0.9999694824 1] [0 0.5 0.75 0.875 0.9375 0.96875 0.984375 0.9921875 0.99609375 0.998046875 0.9990234375 0.9995117188 0.9997558594 0.9998779297 0.9999389648 0.9999694824 0.9999847412 1] [0 0.5 0.75 0.875 0.9375 0.96875 0.984375 0.9921875 0.99609375 0.998046875 0.9990234375 0.9995117188 0.9997558594 0.9998779297 0.9999389648 0.9999694824 0.9999847412 0.9999923706 1] [0 0.5 0.75 0.875 0.9375 0.96875 0.984375 0.9921875 0.99609375 0.998046875 0.9990234375 0.9995117188 0.9997558594 0.9998779297 0.9999389648 0.9999694824 0.9999847412 0.9999923706 0.9999961853 0.9999980927 1] [0 0.5 0.75 0.875 0.9375 0.96875 0.984375 0.9921875 0.99609375 0.998046875 0.9990234375 0.9995117188 0.9997558594 0.9998779297 0.9999389648 0.9999694824 0.9999847412 0.9999923706 0.9999961853 0.9999980927 0.9999990463 0.9999995232 1] [0 0.5 0.75 0.875 0.9375 0.96875 0.984375 0.9921875 0.99609375 0.998046875 0.9990234375 0.9995117188 0.9997558594 0.9998779297 0.9999389648 0.9999694824 0.9999847412 0.9999923706 0.9999961853 0.9999980927 0.9999990463 0.9999995232 0.9999997616 0.9999998808 1] [0 0.5 0.75 0.875 0.9375 0.96875 0.984375 0.9921875 0.99609375 0.998046875 0.9990234375 0.9995117188 0.9997558594 0.9998779297 0.9999389648 0.9999694824 0.9999847412 0.9999923706 0.9999961853 0.9999980927 0.9999990463 0.9999995232 0.9999997616 0.9999998808 0.9999999404 1] [0 0.5 0.75 0.875 0.9375 0.96875 0.984375 0.9921875 0.99609375 0.998046875 0.9990234375 0.9995117188 0.9997558594 0.9998779297 0.9999389648 0.9999694824 0.9999847412 0.9999923706 0.9999961853 0.9999980927 0.9999990463 0.9999995232 0.9999997616 0.9999998808 0.9999999404 0.9999999702 1]
Open AGH e-podręczniki - content available under the CC BY-SA license
152
Chapter 6
6. Computational grids 6.1.
Generation and adaptation of computational grids
The purpose of calculations using the finite element method is to simulate a selected physical phenomenon in a given area. In addition, a projection task such as that shown in the introductory modules in this manual has applications in computer graphics. Many examples can be given, such as • calculation of the temperature distribution on the selected heat-treated part, • calculation of stresses in a specific part of the building structure, • calculation of the deformation of the designed mobile phone when it hits the ground, • calculation of car model deformations during a road accident, • calculation of the blood flow field in the designed bypass in the central circulatory system, • calculation of acoustic wave propagation on a human head model, including the inner ear model, • calculating the propagation of electromagnetic waves on a human head model while talking on a mobile phone, and many other applications, engineering and scientific ones. Each of these simulations requires generating a computational mesh covering a specific area with finite elements. Classic computational mesh generators most often generate meshes made of triangular elements in two dimensions, and meshes made of tetrahedral elements in three dimensions. There are also used meshes made of rectangular elements in two dimensions and cubic elements in three dimensions, and additionally prismatic elements and pyramids. Theoretically, it is also possible to create finite elements built of any polygons in two dimensions or polyhedra in three dimensions (see the polyDPG project). Computational meshes built of any elements should have specific properties.
PROPERTY
Property 1: Properties of computational meshes
153
6.1. Generation and adaptation of computational grids 1. We need to be able to define functions, often called shape functions, spanning over finite elements. Shape functions can be spanned in many ways, they can be associated with vertices, edges, faces and interiors of elements (for example, Lagrange’s hierarchical polynomials). Shape functions are most often polynomials. In the case of using the Galerkin method (the classic version of the finite element method), appropriate shape functions from adjacent elements related to edges or faces are merged into global basis functions used to approximate the solution. If we want the linear combination of our basis functions to have higher continuity (so that the derivative can be calculated at each point), then these functions are spread over many adjacent elements (for example, B-spline basis functions). Therefore, it is difficult to define higher continuity basis functions on triangular or tetrahedral meshes. 2. We must be able to exactly integrate our shape functions spanning the elements. This means that we must be able to define numerical integration quadratures having a finite number of points, strictly defined, so that it is possible to integrate polynomials with the zero error on a given element. Therefore, processing meshes made of polygons or polyhedra is problematic (but possible). Numerical integration does not have to be exact (e.g. it is difficult to compute numerical integrals with zero error on ”crooked” manifolds) but the error of the integration must be of sufficiently low order to ensure convergence of the solution. 3. Finite elements must have the right proportions. It is not good if the finite element is too elongated. A measure of the ”elongation” of an element is the calculation of the area or volume R of the element using the integral E 1dx. If the area or volume of an element is small (of the order 10−6 or less), If the area or volume of an element is small (of the order 10−6 or less), then such an element will generate numerical problems. In particular, if we generate the matrix used in the calculations of the finite element method on our mesh, then this matrix will have small numbers, and during factorization the solver, e.g. Gaussian elimination, will fail, which will be manifested by the presence of values close to zero on the diagonal of the matrix and the inability to divide the row). In the case of irregular meshes, the ratio of the diameter of the circumscribed circle to the diameter of the inscribed circle is tested. Various mathematical theories describing the convergence of the finite element method assume certain proportions of these diameters in order to guarantee the convergence of the method. 4. Finite elements that make up a computational mesh cannot have duplicate vertices, edges and faces. During the finite element calculations, we calculate integrals over the entire calculation area. These integrals are broken down into individual finite elements and summed. If some elements are duplicated, we can sum up the incorrectly calculated integral. In addition, the uncertainties in the equation system are often related to the coefficients of the basis functions associated with the vertices, edges, or faces of the elements. In addition, the basis functions used in the finite element method are glued together from pieces called shape functions spanned over the individual elements. If the objects in our data structure representing vertices, edges, or faces that are duplicated, this can lead to duplicate unknowns in the equation system, and cut our underlying functions into pieces related to individual elements. This will lead to incorrect calculation results by the finite element method. 5. During the finite element calculations, a regular ”patch” of elements, for example forming a regular rectangle or a cube, is often created, and this ”patch” is mapped by transformation to the real geometry of our modeled area using a specific projection. Then the geometry of our object is ”encoded” in the form of a Jacobian change of variables from the area modeled to our ”patch”. Of course, this requires certain regularities in the mesh covering the physical area. In particular, it is not always possible to obtain this for meshes composed of triangular and tetrahedral elements. For triangular and tetrahedral elements, integration takes place over a single element (no need to construct patches and transformations to the reference space are made for single
Open AGH e-podręczniki - content available under the CC BY-SA license
154
6.1. Generation and adaptation of computational grids elements, which can always be performed. 6. The sum of all finite elements must cover the entire area (not only the lack of overlapping or duplication of elements, but also the lack of holes between elements - this is important, for example, for curvilinear areas, manifolds) 7. When using CAD (Computer Aided Design) systems, the geometry of the modeled object is determined by CAD objects described using B-spline, NURBS or T-spline functions (or similar), for which transformations are known to map these objects to regular patches of elements. They are automatically created by CAD systems when designing such objects. This enables easy decomposition of the created object into regular patches of elements and then performing calculations using the isogeometric finite element method. So, in this case we have a set of basis function parameters (B-spline or NURBS) that describe the geometry of the mapped object, and a second set of parameters of the same basis functions that describe the approximated physical quantities.
Figure 29: Left panel: Delaunay triangulation (the circle described on an element does not contain vertices of other elements). Right panel: Triangulation that does not satisfy the Delaunay condition (the red circle contains the vertex of the blue element).
One of the frequently used methods of generating a computational mesh made of triangular elements is Delauney triangulation (see Pic. 29). Based on Delauney’s ideas, the whole school of generation and adaptation of computational grids is still developing [33], [34]. The computational mesh built using Delauney’s triangulation is built of triangular elements in two dimensions. We can span a circle on each triangular element (because it is possible to span a circle at any three points). The exemplary construction is presented in Pic. 30. Two-dimensional Delauney triangulation has the following property, the circles described in Delauney triangulation triangles do not contain the vertex points of other triangles.
Open AGH e-podręczniki - content available under the CC BY-SA license
155
6.2. Algorithm of adaptation of triangular and tetrahedral elements
Figure 30: Relationship between the triangular mesh and the Voronoi tessellation process.
It is also possible to construct a Delauney triangulation in three dimensions. Then the computational mesh is built of tetrahedral elements. At the vertices of the tetrahedral element, we can unfasten the sphere (we need four points to unbend the sphere). Delauney’s triangulation in three dimensions, in turn, has the following property, spheres described on Delauney tetrahedra will not contain vertex points of other tetrahedra.
6.2.
Algorithm of adaptation of triangular and tetrahedral elements
In the case of triangular or tetrahedral meshes, it is possible to refine the meshes in order to increase the accuracy of the approximation over these meshes. The mesh densification algorithm is called the adaptation algorithm. It must be constructed in such a way as not to damage the properties of the original mesh, for example, that the elements do not become more and more ”elongated” as a result of adaptation, which would disrupt the proportion between the mesh edges and the possibility of generating long thin elements for which calculating the integral gives very small numbers, of the order 0.000001 or less. This, in turn, would cause numerical errors in the factorization of the system of equations of the finite element method. The algorithm for adapting triangular meshes maintaining the proportions of elements was proposed by Maria Cecilia Rivara [35]. It is described in pseudocode, and illustrated in Pic. 31.
ALGORITHM
Algorithm 7: Rivara algorithm
Open AGH e-podręczniki - content available under the CC BY-SA license
156
6.2. Algorithm of adaptation of triangular and tetrahedral elements 1 procedure BREAK (triangle t) 2 e = longest edge of triangle t 3 if e is located on the boundary of the mesh, then break t from the interior of the longest edge to the opposite vertex, and return 4 t’ = triangle on the other side of ege e 5 if e!=e’ then BREAK(t’) 6 t* = new element on the other side of edge e 7 break t and t* from the longest edge to the oppositevertex
Figure 31: Exemplary application of the Rivara algorithm breaking triangular elements.
Open AGH e-podręczniki - content available under the CC BY-SA license
157
6.3. Algorithm of h-adaptation
EXAMPLE
Example 12: Application of the Rivara algorithm According to panel (a), our goal is to break the element located in the upper left corner of the mesh. So, we call the procedure BREAK (t1). The algorithm finds the longest edge e1 of the element, and identifies its longest edge (panel (b) in red). This edge is not on the boundary, so we pull out element t2 on the other side of the edge and find its longest edge e2 (panel (c) marked in blue). Since the edge e1 is not equal to the edge e2, we recursively call the procedure BREAK (t2). The procedure finds the longest edge of the element (panel (c) marked in blue) and because it is not located on the edge, the situation repeats: we identify the element t3 on the other side and its longest edge e3 (panel (d) marked in green). Since this edge is not equal to the blue edge, we recursively call it BREAK (t3). The longest edge of the t3 element is the green edge e3, it is not located on the edge, and on its other side there is an element t4 (panel (e)) whose longest edge is also the green edge e3. So we break the elements t3 and t4 from the longest edge to the opposite vertex (panel (f)). We go back to the previous call to the BREAK procedure, back to the element t2. The new element on the other side of longest edge e2 is the element t4 (panel (g)). So we break the elements t2 and t4 from the longest edge to the vertex opposite. We go back to our previous call to BREAK, back to element t1. The new element on the other side of the longest edge e1 is the element t5 (panel (s)). So we break the elements t1 and t5 from the longest edge to the vertex opposite (panel (j)).
6.3.
Algorithm of h-adaptation
The goal of the h adaptation algorithm is to improve the accuracy of approximation on computational meshes by breaking selected elements into smaller ones. The h adaptation algorithm can be implemented only when we construct such basic functions that can be spread on the elements of finished texts. In the case of unstructured meshes composed of triangular elements, it is possible to use the Rivary algorithm described in this chapter. In the case of meshes of structural elements, built of structural elements, on which basis functions are defined according to given node vectors, adaptation is also possible, if it concerns structural elements, and we use C 0 separators, or T-spline basis functions defined later in this book, or some alternative advanced ways. The chapter ”Approximation with hanging nodes” describes the method of joining together the base functions spanning on adjacent broken elements of various sizes. The h-adaptation algorithm can be implemented in the form of an a priori or a posteriori algorithm, and using isotropic or anisotropic adaptations. The adaptive algorithm can use one computational mesh, the so-called coarse mesh, or two, coarse and fine computational meshes. In our classification by a priori adaptive algorithm, we mean an algorithm that makes a decision before constructing and solving a problem on a fine mesh, after solving a problem on an actual coarse mesh. For this reason, the term ”a priori” as if ”in advance” is understood here without additional calculations related to, for example, problem solving on an additional fine mesh. By a posterior adaptive algorithm we mean an algorithm that makes decisions about adaptation after performing some additional calculations (not only solving the problem on a coarse mesh), for example after generating a fine mesh and solving a problem on a fine mesh. • A priori h-adaptation algorithm uses one computational grid, and error estimation is based on local Open AGH e-podręczniki - content available under the CC BY-SA license
158
6.3. Algorithm of h-adaptation calculations on individual elements (for example, it is possible to estimate errors based on the first and / or second directional derivatives of the solution locally on finite elements). Many methods of selecting adaptations are described in Mark Ainsworth and John Tinsley Oden [36](there is a discrepancy in the nomenclature of methods between our module and this article, resulting from the fact that we call the apriory methods meaning the methods that only uses a coarse mesh and a posteriori methods meaning the methods using both coarse and fine meshes. In the paper the method using one mesh is called a’posteriori because it is run after solving the problem on the mesh. Also, in that paper, the a priori method would make decisions about adaptation before solving the computational problem, looking for example at the coefficients of the model and the shape of the computational grid). • The a posteriori h-adaptation algorithm uses two computational meshes, a sparse mesh and a dense mesh, and the error estimation on individual elements is done by comparing the solutions on the sparse and dense meshes. • The h-isotropic adaptation algorithm can work in a’priori and a’posteriori versions, and it divides selected elements into four (rectangular elements in two dimensions) or eight (hexahedral elements in three dimensions) new elements (various breaking of triangular elements in two dimensions, and tetrahedral, prismatic and pyramids in three dimensions; recently the finite element method on polygons has also been used, e.g. the PolyDPG metod). • Anisotropic h-adaptation algorithm can work in a’priori and a’posteriori versions, and it divides selected elements into two new elements in the selected direction. As prof. Zienkiewicz, one of the creators of the finite element method said, we will get sufficient accuracy in many engineering problems using square polynomials and h-adaptation. So we assume that the initial mesh is a glued group of elements described by vectors of nodes [0 0 0 1 1 1] and [0 0 0 1 1 1]. The a priori anisotropic h-adaptation algorithm can be written as follows:
PROPERTY
Property 2: A priori anisotropic h-adaptation algorithm 1. non-uniform h adaptations performed a’propri (initial grid, accuracy, maximum number of steps) 2. current grid = initial grid 3. solve your computational problem on the current mesh (for example, bitmap projection or heat transport) by computing the current solution u 4. loop for i = 1 up to the maximum number of steps x y 5. Kmaxerr = 0; Kmaxerr = 0; Kmaxerr =0
6. for each element K the current grid, do the following 7. calculate the approximation error on the element K by computing the solution gradient R ∂(B−u) 2 in some norm on the element Kerr = k∇(B − u)k = | ∂x | + | ∂(B−u) |2 dxdy, ∂y R x and norms from directional derivatives Kerr = k∇x (B − u)k = | ∂(B−u) |2 dxdy and ∂x R y Kerr = k∇y (B − u)k = k ∂(B−u) |2 dxdy ∂y 8. if Kerr > Kmaxerr then Kmaxerr = Kerr x x x 9. if Kerr > Kmaxerr then Kmaxerr = Kerr
Open AGH e-podręczniki - content available under the CC BY-SA license
159
6.3. Algorithm of h-adaptation y y y 10. if Kerr > Kmaxerr then Kmaxerr = Kerr
11. end of the loop by elements 12. if Kmaxerr > the accuracy required then STOP 13. loop by elements K mesh 14. if Kerr > 0.33 ∗ Kmaxerr then break the element in two directions into four new elements and generate new local basis functions, continue to loop over the elements x x 15. if Kerr > 0.33 ∗ Kmaxerr then break the element in the direction of the axis x for two new elements, and generate new base functions, continue looping over the elements y y 16. if Kerr > 0.33 ∗ Kmaxerr then break the element in the direction of the axis y and generate new base functions, continue looping over the elements
17. end the loop over the elements 18. end of the adaptation loop. By an error in the example bitamp projection task, we mean an error in the norm H 1 representing the difference between a continuous approximation of, for example, a cast of terrain, the height of which at different points is described by the shades of bitmap pixels. In this way we may get the smooth approximation of the terrain represented by the bitmap. For the bitmap we can also implement the error estimations in L2 norm, targeting the values of the bitmap. If it is necessary to break a given element (perform h-adaptation for this element), we have three scenarios to choose from. The first option is to break an element into four smaller pieces. The second option is to break the element into two new elements in the direction of the axis x. The third possibility is breaking a given element into two smaller elements in the direction of the axis y. In the adaptive algorithm, usually no adaptation is performed on all mesh elements, but only on those elements where the error is greater than 33 percent of the maximum error (calculated over all elements). This is, of course, an arbitrarily adopted value, selected on the basis of numerical experiments by prof. Leszek Demkowicz. In the proposed version of the algorithm, we first try to adapt in both directions (break the element in both directions), and then (if it is not indicated) we try to break the element in one of two directions. This is obviously an example version of the algorithm, various modifications are possible. The most advanced version of the adaptive algorithm is the hp adaptation algorithm described in another module. Generating new base functions consists in generating new local node vectors for broken elements. For example, if we have an element described by a node vector [0 0 0 1 1 1] in the direction of the axis x and vector of nodes [0 0 0 1 1 1] in the direction of the axis y, and we break this element into four new elements, then we have a vector of nodes [0 0 0 0.5 0.5 1 1 1] in the direction of the axis x and knot vector [0 0 0 0.5 0.5 1 1 1] in the direction of the axis y. If we will break this element into two new elements in the direction of the axis x, than we get the knot vector [0 0 0 0.5 0.5 1 1 1] in the direction of the axis x and knot vector [0 0 0 0 1 1 1] in the direction of the axis y. If we will break this element into two new elements in the direction of the axis y, than we get the knot vector [0 0 0 1 1 1] in the direction of the axis x and vector of nodes [0 0 0 0.5 0.5 1 1 1] in the direction of the axis y. By merging many patches (groups of elements) on which different B-spline polynomials are spanned, we will obtain a computational mesh on which local modifications of the degree of the B-spline function will be possible, for example using the described p-adaptation algorithm. The method of merging the base Open AGH e-podręczniki - content available under the CC BY-SA license
160
6.3. Algorithm of h-adaptation functions obtained on large and small broken elements is described in the chapter ”Approximation with hanging nodes”.
ALGORITHM
Algorithm 8: Automatic aposteriori h-adaptation algorithm Automatic h-adaptation algorithm (initial grid, required accuracy, maximum number of iterations) 1. coarse mesh = initial mesh 2. loop i = 1 up to the maximum number of iterations 3. Solve a computational problem on the current caorse mesh (for example, bitmap projection or heat transport problem) by obtaining uh 4. make copy of the coarse mesh 5. Break each coarse mesh element into four elements to obtain fine mesh 6. Solve the computational problem on the current fine mesh and obtain a solution uh/2 7. Maximum error Kmax = 0 8. take copy of the coarse mesh 9. Loop by elements K coarse mesh 10. For each coarse mesh element, estimate the relative error (the norm of the difference between the solution on the coarse and fine mesh)Krel = kuh − uh/2 kK 2 ∂uh −uh/2 2 ∂uh −uh/2 2 R uh − uh/2 + + ∂x ∂y K
=
11. If Krel > Kmax then Kmax = Krel 12. End of the loop by elements 13. If Kmax > required accuracy, then it’s over. 14. Loop by elements K coarse mesh 15. If Krel > 0.33Kmax then select the optimal method of adapting the element from the coarse mesh and apply it to the element K coarse mesh 16. End of the loop through the elements 17. End of iteration So we have three options for adapting a single element: 1. Break an element into four new elements 2. Breaking an element into two new elements in the horizontal direction 3. Breaking an element into two new elements vertically How is the decision about the type of adaptation of a single element made? The decision is made in accordance with the following Algorithm.
Open AGH e-podręczniki - content available under the CC BY-SA license
161
6.4. Algorithm of p-adaptation
ALGORITHM
Algorithm 9: Algorithm for selecting the optimal strategy for component adaptation 1. Choosing the optimal strategy for component adaptation K(solution on a sparse mesh narrowed to an element uh , dense mesh solution narrowed to the element uh/2 ) 2. Loop through possible types of element adaptation from 1 to 3 3. The fastest error rate = 0 4. Optimal adaptation = 0 5. Make a copy J of the element K and make the considered adaptation on it 6. Calculate the projection w solutions on a dense mesh uh/2 on the element being adapted J 7. Calculate how much the relative error will drop if we will adapt the code, the error will drop (code)= kuh/2 − uh kK − kuh/2 − wkK 8. Calculate how many unknowns (how many base functions) we have to add to implement the adaptation represented by the code, adaptation cost (code) 9. Calculate and remember the rate of error decrease (code) = error decrease (code)/ adaptation cost (code) 10. If the error decrease rate (code) is greater than the fastest error decrease speed, then remember the largest error decrease value = error decrease rate (code), optimal adaptation = code 11. End of the loop after possible types of adaptation 12. Perform on an element K the optimal adaptation found In other words, we choose the type of adaptation for the element that achieves the highest error reduction at the lowest cost. This quantity is represented by the rate of error decrease, which increases with decreasing error but decreases with the cost incurred (with the number of functions added to the element because the cost of the calculation on a given element depends on the number of unknowns, which are coefficients of the base functions).
6.4.
Algorithm of p-adaptation
The purpose of the p-adaptation algorithm is to increase the accuracy of approximation on computational grids by increasing the degree of polynomials spanning the computational grid. The p adaptation algorithm is possible to implement only when we construct such basis functions spanning on finite elements for which it is possible to raise the degree of polynomials. In the case of traditional B-spline functions, described in greater detail in this manual, it is only possible to increase the degree of the B-spline function globally on a local finite element patch. In other words, suppose we have a node vector describing the basis of second order B-splines with C1 continuity in the direction of the axis x [0 0 0 1 2 3 4 4 4], and an identical node vector describing the base of the second order B-splines in the direction of the axis y [0 0 0 1 2 3 4 4 4]. These vectors span two one-dimensional bases of B-splines in the direction of individual axes
Open AGH e-podręczniki - content available under the CC BY-SA license
162
6.4. Algorithm of p-adaptation y y x x B1;2 (x), ..., B6;2 (x); B1;2 (y), ..., B6;2 (y)
which through a tensor product define the basis of two-dimensional basis functions y x {Bi;2 (x)Bj;2 (y)}i = 1, ..., 6; j = 1, ..., 6
The following adaptations are possible: • increasing the degree of B-spline function in the direction of the x-axis by 1, by modifying the vector of nodes in the direction of the axis x [0 0 0 0 1 2 3 4 4 4 4]. We will then y y x x get the bases B1;3 (x), ..., B7;3 (x); B1;2 (y), ..., B6;2 (y) and two-dimensional functions y x {Bi;2 (x)Bj;2 (y)}i = 1, ..., 7; j = 1, ..., 6 • increasing the degree of B-spline function in the direction of the axis y by 1, by modifying the vector of nodes in the direction of the axis y[0 0 0 0 1 2 3 4 4 4 4]. We will then y y x x get the bases B1;3 (x), ..., B7;3 (x); B1;2 (y), ..., B6;2 (y) and two-dimensional functions y x {Bi;2 (x)Bj;2 (y)}i = 1, ..., 6; j = 1, ..., 7 • increasing the degree of the B-spline function in the direction of both axes, by modifying the vector of nodes in both directions [0 0 0 0 1 2 3 4 4 4 4] and [0 0 0 0 1 2 3 4 4 4 4] by 1. Then we will get y y y x x x base B1;3 (x), ..., B7;3 (x); B1;3 (y), ..., B7;3 (y) and two-dimensional functions {Bi;2 (x)Bj;2 (y)}i = 1, ..., 7; j = 1, ..., 7. We can of course increase the degrees of the basis functions in one direction or the other by any degree (as long as our computer program can generate a higher degree B-spline without any problem). For B-spline functions, it is not possible to mix degrees of polynomials without placing C 0 separators between B-spline functions. However, it is possible to mix patches (groups of elements) separated by separators, on which B-spline polynomials have different continuity. For example, suppose we have a node vector describing the basis of second order B-splines with C1 continuity on 2 elements in the direction of the axis x and a node vector describing the basis of third order B-splines of C2 continuity on the next 2 elements in the x axis direction, namely [0 0 0 1 2 2 2] [2 2 2 2 3 4 4 4 4]. These vectors span the base together y y x x B1;2 (x), ..., B6;2 (x); B1;2 (y), ..., B6;2 (y).
We can ”assemble” these vectors with the base of second degree B-splines in the direction of the axis y [0 0 y y x x 0 1 2 3 4 4 4], i.e. B1;2 (x), ..., B6;2 (x); B1;2 (y), ..., B6;2 (y). These vectors span the basis of the B-spline function in the direction of the axis x in the following way x x x x x x x x x B1;2 (x), B2;2 (x), B3;2 (x), B4;2 (x), B5;3 (x), B6;3 (x), B7;3 (x), B8;3 (x), B9;3 (x).
Through the tensor product, we obtain the basis of two-dimensional basis functions y y x x {Bi;2 (x)Bj;2 (y)}i = 1, ..., 4; j = 1, ..., 6} ∪ {Bi;2 (x)Bj;2 (y)}i = 5, ..., 9; j = 1, ..., 6}
Note that the groups of elements glued in this way do not give a continuous approximation at point 2. On the left side we have one polynomial maxing out 1 at point 2, on the right side we have another polynomial maxing out at 1 and at point 2. The node vector pair [0 0 0 1 2 2 2] [2 2 2 2 3 4 4 4 4] is equivalent to the vector [0 0 0 1 2 2 2 2 3 4 4 4 4]. Of course, the algorithm that interprets such a vector of nodes must notice that starting from node 2, which was repeated 4 times, the degree of polynomials is increased by 1. Additionally, the last polynomial x in the first subgroup B4;2 (x) are to be joined with the first polynomial in the second subgroup of elements x B5;3 (x). Such a merge is possible because the first and last terms of B-splines are identical polynomials x regardless of their degree. We will then obtain a second order polynomial B4;2 (x) which extends to the last element in the first subgroup and the first element in the second subgroup. So, our bases now look like this Open AGH e-podręczniki - content available under the CC BY-SA license
163
6.4. Algorithm of p-adaptation x x x x x x x x B1;2 (x), B2;2 (x), B3;2 (x), B4;2 (x), B5;3 (x), B6;3 (x), B7;3 (x), B8;3 (x). y y x x B1;2 (x), ..., B6;2 (x); B1;2 (y), ..., B6;2 (y) y y x x {Bi;2 (x)Bj;2 (y)}i = 1, ..., 4; j = 1, ..., 6} ∪ {Bi;2 (x)Bj;2 (y)}i = 5, ..., 8; j = 1, ..., 6}
ALGORITHM
Algorithm 10: Homogeneous p adaptation algorithm performed apropri The general form of p-adaptation algorithm can be written as follows: 1. homogeneous p adaptation performed a’propri (initial grid, accuracy, maximum number of steps) 2. current grid = initial grid 3. solve your computational problem on the current mesh (for example, bitmap projection or heat transport) by computing the current solution u 4. loop for i = 1 up to the maximum number of steps x y 5. Kmaxerr = 0; Kmaxerr = 0; Kmaxerr =0
6. for each item K current grids do the following 7. compute approximation error on element K by computing the solution gradient R ∂(B−u) 2 seminorm on the element Kerr = k∇(B − u)k = | ∂x | + | ∂(B−u) |2 dxdy, and ∂y R ∂(B−u) x seminorms from directional derivatives Kerr = k∇x (B − u)k = | ∂x |2 dxdy and R ∂(B−u) 2 y Kerr = k∇y (B − u)k = k ∂y | dxdy 8. if Kerr > Kmaxerr then Kmaxerr = Kerr x x x 9. if Kerr > Kmaxerr then Kmaxerr = Kerr y y y 10. if Kerr > Kmaxerr then Kmaxerr = Kerr
11. end of loop by elements 12. if Kmaxerr < the accuracy required then STOP 13. loop by elements K mesh 14. if Kerr > 0.33 ∗ Kmaxerr then rise the degree of polynomial approximation in two directions, continue looping over the elements x x 15. if Kerr > 0.33 ∗ Kmaxerr then rise the degree of polynomial approximation in the direction of the axis x, continue looping through the elements x y 16. if Kerr > 0.33 ∗ Kmaxerr then rise the degree of polynomial approximation in the direction of the axis y, continue looping through the elements
17. end the loop over the elements 18. end of the adaptation loop If a given element requires modification of the degree of polynomials in order to improve the quality of approximation, one of the three described scenarios is possible, increasing the degree of basis functions in the direction of the axis x, increasing the degree of basic functions in the direction of the axis y, or raise the degree in both directions. Open AGH e-podręczniki - content available under the CC BY-SA license
164
6.5. Algorithm of hp-adaptation In the adaptive algorithm, usually no adaptation is performed on all mesh elements, but only on those elements where the error is greater than 33 percent of the maximum error (counted over all elements). This is, of course, an arbitrarily accepted value. In the proposed version of the algorithm, we first try to adapt in both directions (raise the degree of the polynomial by 1 in both directions), and then (if it is not indicated) we try to raise the degree of the polynomial in one of the two directions. This is, of course, an exemplary version of the algorithm, various modifications are possible. The most advanced version of the adaptive algorithm is the hp adaptive algorithm described in another module. By merging many patches (groups of elements) on which different B-spline polynomials are spanned, we will obtain a computational mesh on which local modifications of the degree of the B-spline function will be possible, for example using the described p-adaptation algorithm. When an element patch consists of one element, the basis functions spread over this element correspond to the classical p-adaptation algorithm working on Lagrange polynomials. This is because the node vectors are separated by C 0 separator, as is the case with classical Lagrange polynomials. Both bases then generate an identical space of polynomials. The mathematical properties of the p-adaptation algorithm were first described by Prof. Ivo Babuśka of the University of Texas at Austin [37].
6.5.
Algorithm of hp-adaptation
The automatic hp adaptation algorithm was first described in detail in the books of prof. Leszek Demkowicz, a Polish mathematician working at the University of Texas in Austin. The analysis of the mathematical properties of the hp-adaptation Algorithm was performed by prof. Ivo Babuška, an American of Czech descent, also working at the University of Texas in Austin [6], [7], [38], [39].
ALGORITHM
Algorithm 11: Algorithm of authomatic hp adaptation 1. Algorithm for automatic hp adaptation (initial mesh, required accuracy, maximum number of iterations) 2. coarse mesh = initial mesh 3. loop i = 1 up to the maximum number of iterations 4. solve a computational problem on the current coarse mesh (e.g. bitmap projection problem or heat transport problem) by obtaining a solution uh,p 5. coarse mesh = initial mesh 6. break each coarse mesh element into 4 elements (for rectangular elements in two dimensions) or 8 elements (for cubic elements in three dimensions)(it is also possible to break triangular elements in two dimensions and tetrahedral elements, prismatic elements and pyramids in three dimensions) and increase the degree of polynomials by one in each direction on each element (which is natural for rectangular and cubic elements, but requires clarification for elements of a different type) 7. solve a computational problem on the current fine mesh and obtain a solution uh/2,p+1 8. maximum error Kmax = 0
Open AGH e-podręczniki - content available under the CC BY-SA license
165
6.5. Algorithm of hp-adaptation 9. loop by elements K coarse mesh 10. for each element of the coarse mesh, estimate the relative error (the norm of the difference between the solution on the coarse and fine mesh)Krel = kuh,p − uh/2,p+1 kK 2 ∂uh,p −uh/2,p+1 2 ∂uh,p −uh/2,p+1 2 R uh,p − uh/2,p+1 + + ∂x ∂y K
=
11. if Krel > Kmax then Kmax = Krel 12. end of loop by elements 13. if Kmax > required accuracy, then it’s over. 14. loop by elements K sparse mesh 15. if Krel > 0.33Kmax then select the optimal method of adapting the element from the coarse mesh and apply it to the element K coarse mesh 16. end of loop through items 17. end of iteration
Figure 32: Initial mesh, all elements are separated by C0 separators, base functions created by the tensor product of square polynomials in the horizontal and vertical directions are stretched on each mesh element.
Open AGH e-podręczniki - content available under the CC BY-SA license
166
6.5. Algorithm of hp-adaptation
Figure 33: Solution (temperature scalar field) on a sparse mesh.
Figure 34: The dense mesh was created by breaking each element of the sparse mesh into four elements and raising the degree of polynomials in the horizontal and vertical directions by one for each element.
Open AGH e-podręczniki - content available under the CC BY-SA license
167
6.5. Algorithm of hp-adaptation
Figure 35: Solution (temperature scalar field) on a dense grid.
Open AGH e-podręczniki - content available under the CC BY-SA license
168
6.5. Algorithm of hp-adaptation
Figure 36: Choosing the optimal adaptation strategy for each element of the sparse mesh, by comparing the solutions on the sparse and dense mesh.
The hp-adaptation algorithm is illustrated in Pic. 32, Pic. 33, Pic. 34, Pic. 35, Pic. 36. The convention for drawing computational meshes is as follows. Colors in the drawings Pic. 32, Pic. 34 and Pic. 36 denote the degrees of polynomials spanning over the edges and interior of the elements. One polynomial degree is provided on each edge, while a horizontal degree and a vertical degree are provided on each interior of the element. For example, in the picture Pic. 32 all polynomials on all edges have degree 2, and all polynomials on the inside of all elements have degree 2 in the vertical and horizontal directions. In the picture Pic. 34 all polynomials on all edges have degree 3, and all polynomials on the inside of all elements have degree 3 in the vertical and horizontal directions. See the drawing Pic. 36. When viewing elements by rows from left to right, in the first row on the first element all polynomials on the edges have degree 2, except for the polynomial on the lower edge of the element which has degree 1. On the first element the polynomials in the interior have degree 2 in the vertical and horizontal directions. On the second element, on the left, top and bottom edges, the polynomials have a degree 2, while on the inside, a degree 3 in the vertical direction and a degree 2 in the horizontal direction. On the third and fourth elements, all polynomials on the edges are of degree 3. Likewise, the polynomials in the interior in the vertical and horizontal directions. In the second row of items, the first item (i.e., the fifth global) has degree 3 polynomials on the left and right edges, and a degree 1 polynomial on the top and bottom edges. Inside, the element has degree 1 polynomials in the horizontal direction and degree 3 polynomials in the vertical direction. The second
Open AGH e-podręczniki - content available under the CC BY-SA license
169
6.5. Algorithm of hp-adaptation element in the second line has a polynomial degree 2 in the horizontal direction and a polynomial degree 3 in the vertical direction. On the third and fourth elements, all polynomials on all edges have degree 3, and all polynomials on the inside of all elements have degree 3 in the vertical and horizontal directions. The remaining elements in the third and fourth lines have polynomials symmetrically distributed with the polynomials in the first and second lines on the first and second elements. What is the optimal method of adapting a single element? Note that in the case of the hp adaptation algorithm, we have many possibilities to modify a single element: 1. Leaving the item unchanged 2. It is possible to break an element into two new elements vertically 3. It is possible to break an element into two new elements in the horizontal direction 4. It is possible to break an element into four new elements (two in the horizontal direction and two in the vertical direction). Moreover, for each broken element it is possible to modify the degree of polynomials inside the element 1. Leave element orders unchanged 2. It is possible to raise the order inside the element horizontally (ph , pv ) → (ph + 1, pv ) 3. It is possible to raise the order inside the element in a vertical direction (ph , pv ) → (ph , pv + 1) 4. It is possible to raise the order inside the element horizontally and vertically (ph , pv ) → (ph +1, pv +1) The orders at the edges of the modified elements are determined on the basis of the minimum rule. In other words, the degree of the polynomial at the edge divided by two adjacent elements is set as a minimum of degrees inside the elements in the appropriate direction. For a vertical edge surrounded by two elements (p1h , p2v ) and (p2h , p2v ) we set the degree p = min{p1v , p2 , v}. For a horizontal edge surrounded by two elements (p1h , p2v ) and (p2h , p2v ) we set the degree p = min{p1h , p2 , h}. So we have a lot of possibilities to adapt a single element (estimating on the basis of the possible types of adaptation we have 4 (modifications of the degree of the element without breaking the element) + 4 * 4 (breaking the element into two elements in the horizontal direction and four possibilities of modifying the degree of each element) + 4 * 4 (break an element into two elements vertically and four possibilities to modify the degree of each element) + 4 * 4 * 4 * 4 (break an element into four elements and four possibilities to modify the degree of each element). A total of 4 + 4 * 4 + 4 * 4 + 4 * 4 * 4 * 4 = 292 possibilities. How is the decision about the type of adaptation of a single element made? The decision is made in accordance with the following Algorithm.
ALGORITHM
Algorithm 12: Algorithm for selecting the optimal strategy for the adaptation of the element 1. Selecting the optimal adaptation strategy for the element K(a solution on a coarse mesh restricted to an element uh,p , fine mesh solution restricted to the element uh/2,p+1 )
Open AGH e-podręczniki - content available under the CC BY-SA license
170
6.5. Algorithm of hp-adaptation 2. Loop through possible types of element adaptation from 1 to 292 (represented by CODE) 3. The fastest error decrease rate = 0 4. Optimal adaptation = 0 1. Copy J, element K, and make the considered adaptation on it 2. Calculate the projection w solutions on a dense mesh uh/2,p+1 on the element being adapted J 3. Calculate by how much the relative error will drop if we make the adaptation represented by CODE, the error decrease rate (CODE) =kuh/2,p+1 − uh,p kK − kuh/2,p+1 − wkK 4. Calculate how many unknowns (how many base functions) we have to add to implement the adaptation represented by the CODE, adaptation cost (CODE) 5. Calculate and remember the error decrease rate (CODE) = error decrease (CODE)/ adaptation cost (CODE) 6. If the error decrease rate (CODE) is greater than the fastest error decrease rate, remember the greatest error decrease rate value = error rate (CODE), OPTIMAL CODE = CODE 7. End of the loop after possible types of adaptation (represented by CODE) 8. Perform on element K the optimal adaptation represented by OPTIMAL CODE In other words, we choose the type of adaptation for the element that gives the greatest error reduction at the lowest cost. This quantity is represented by the error decrease rate, which increases with the decrease in error but decreases with the cost incurred (with the number of functions added to the element because the cost of the calculation on a given element depends on the number of unknowns which are coefficients of the basis functions). This algorithm is illustrated in Pic. 37.
Open AGH e-podręczniki - content available under the CC BY-SA license
171
6.5. Algorithm of hp-adaptation
Figure 37: Selecting an optimal component adaptation strategy from a plurality of possibilities, based on the calculated error decrease rate.
For the exemplary problem of heat transport in the L-shaped area, it is possible to obtain an adaptive hp mesh that allows solving the problem with the relative error of 0.0001. Such a grid is shown in Pic. 38, Pic. 39, Pic. 40, Pic. 41, Pic. 42, Pic. 43, Pic. 44.
Figure 38: Hp-adaptive mesh resulting in a solution of the heat transport problem over the L-shape domain with accuracy of 0.001 expressed in the relative error in H1 norm, computed between the coarse and fine mesh solution.
Open AGH e-podręczniki - content available under the CC BY-SA license
172
6.5. Algorithm of hp-adaptation
Figure 39: Adaptive hp mesh allowing to solve the problem of heat transport in the L-shaped area with an accuracy of 0.001 in terms of relative error (difference in the H1 norm between the solution on a coarse mesh and a fine mesh).
Figure 40: Zoom 10 times towards the singularity at the central point.
Figure 41: Zoom 100 times towards the central point where the singularity is located.
Open AGH e-podręczniki - content available under the CC BY-SA license
173
6.5. Algorithm of hp-adaptation
Figure 42: Zoom 1000 times towards the central point where the singularity is located.
Figure 43: Zoom 10000 times towards the central point where the singularity is located.
Figure 44: Zoom 100000 times towards the central point where the singularity is located.
The automatic hp adaptation algorithm is therefore very complicated and difficult to implement. So why is it worth our interest? Consider possible different adaptation algorithms for the exemplary L-shaped heat transport problem, i.e. 1. A homogeneous adaptation algorithm where the number of elements is increased evenly over the entire area
Open AGH e-podręczniki - content available under the CC BY-SA license
174
6.5. Algorithm of hp-adaptation 2. A homogeneous p adaptation algorithm, using a mesh made of 3 elements and increasing uniformly the degree of polynomials inside all elements horizontally and vertically, and the degree of polynomials on all edges 3. A homogeneous p adaptation algorithm, using a grid made of 12 elements and increasing uniformly the degree of polynomials inside all elements horizontally and vertically, and the degree of polynomials on all edges 4. An automatic p adaptation algorithm, increasing the degree of polynomials in the interiors of selected elements in selected directions, and modifying the degrees on the edges according to the minimum rule 5. An automatic adaptation algorithm, breaking selected elements in selected directions 6. An automatic hp adaptation algorithm, described in this chapter If we draw a graph of the convergence of these algorithms in such a way that on the horizontal axis we place the size of the grid understood as the number of basis functions on the entire grid, which corresponds to the number of unknown coefficients of these basis functions, i.e. the size of the matrix of the system of equations to be solved, and on the vertical axis, the relative error calculated in H1 standard between the solution on the coarse mesh and the dense mesh kuh,p − uh/2,p+1 kH 1 =
R Ω
∂(uh,p −uh/2,p+1
∂(uh,p −uh/2,p+1
(uh,p −uh/2,p+1 )2 +( )2 +( ∂x ∂x R ∂(uh/2,p+1 ∂(uh/2,p+1 (uh/2,p+1 )2 +( )2 +( )2 ∂x ∂x Ω
)2
then it turns out that only the automatic hp adaptation algorithm has the feature of exponential convergence. It is definitely the fastest and can solve a given computational problem with an accuracy that is impossible to achieve by other adaptive algorithms.
Figure 45: Convergence of various adaptive algorithms.
then it turns out that only the automatic hp adaptation algorithm has the feature of exponential convergence. It is definitely the fastest and can solve a given computational problem with an accuracy that is impossible to achieve by other adaptive algorithms. Open AGH e-podręczniki - content available under the CC BY-SA license
175
6.6. Approximation on the mesh with hanging nodes In practice, most engineering problems require accuracy in the range of 5 percent and square polynomials. However, there are computational tasks where high accuracy of the solution is essential. Examples of such computational tasks are, for example, simulations of flows around the wings of aircraft, which require very high accuracy in the boundary layer on the wings of the aircraft, or simulations of the propagation of electromagnetic waves in the geological formation layers to identify oil deposits that require very high accuracy in the vicinity of the receiver antenna.
6.6.
Approximation on the mesh with hanging nodes
The problem of approximation on a mesh with hanging nodes is presented in detail in the paper [40]. Now consider the case of a mesh in which we have one large element [0, 2] × [1, 3] and two small elements [0, 1] × [0, 1] and [0, 1] × [1, 2]. The easiest way to construct basis functions on such elements are linear B-spline functions (which de facto correspond to linear Lagrange polynomials). We obtain them by spanning the node vectors [0 0 1 1 2 2] in the direction of the axis x and [0 0 1 1] in the direction of the axis yy, for two small elements, and [0 0 2 2] in the direction of the axis x, and [1 1 3 3] in the direction of the axis y. Note that our node vectors [0 0 1 1 2 2] and [0 0 1 1] span the following base functions y y x x x B1;1 (x), B2;1 (x), B3;1 (x); B1;1 (y), ..., B1;2 (y) on small elements, which by multiplication (constructing a y y y y x x x x tensor product) gives two-dimensional basis functions B1;1 (x)B1;1 (y), B1,1 (x)B1;2 (y), B2;1 (x)B1;1 (y), B2,1 (x)B1;2 (y) y y y y x x x x on the first element, and B2;1 (x)B1;1 (y), B2,1 (x)B1;2 (y), B3;1 (x)B1;1 (y), B3,1 (x)B1;2 (y) on second small element. Moreover, on a large element our vectors of nodes [0 0 2 2] and [1 1 3 3] span base functions y y x x B4;1 (x), B5;1 (x); B3;1 (y), ..., B4;2 (y). The tensor product of these one-dimensional basis functions gives the y y y y x x x x following two-dimensional basis functions B4;1 (x)B3;1 (y), B4,1 (x)B4;2 (y), B5;1 (x)B3;1 (y), B5,1 (x)B4;2 (y). We denote by B1small1 restricting the base function y x B1;1 (x)B2;1 (y) to the common edge on the first small element Pic. 46, and by B1small2 restricting the base y x function B2;1 (x)B2;1 (y) to the common edge on the second small element Pic. 46. y x We denote by B1big restricting the base function B4;1 (x)B3;1 (y) to the common edge on the big element Pic. 46. y x Let us denote by B2small1 restricting the base function B2;1 (x)B2;1 (y) to the common edge on the first y small2 x element Pic. 47, and przez B2 narrowing the base function B3;1 (x)B2;1 (y) to the common edge on the second element Pic. 47. y x Let us also denote by B2big restricting the base function B5;1 (x)B3;1 (y) to a common edge on a large element Pic. 47.
Open AGH e-podręczniki - content available under the CC BY-SA license
176
6.6. Approximation on the mesh with hanging nodes
Figure 46: The first large and the first two small base functions on the edge of one large and two small broken elements.
Figure 47: The second large and the next two small base functions on the edge of one large and two small broken elements.
The problem then arises: if we want to approximate some continuous function (for example a temperature scalar field) over such a grid, our approximation should be continuous. In the case of groups of elements of uniform size, the B-spline basis functions span naturally across many elements, and the approximation at element boundaries is naturally continuous. In the case of elements divided into smaller elements that share edges with a larger element, as in our case, we have a number of local functions on large and small elements that are not glued together over the edge, and they have different plots above the shared edge. The vertex between two small elements on a common edge, located in the middle of a large element, is called a hanging node or a constrained node. This is because the basis functions that span over it on small elements must be used to adjust the approximation to a large basis function on a large element. How do we do this ”adjustment”? In our case, we use local basis functions on small elements to map corresponding large basis functions on large elements. In our case, we just need to map the functions B1big (x, y) by a linear combination of functions B1small1 (x, y), B1small2 (x, y), B2small1 (x, y), B2small2 (x, y). In other words, we need to find such coefficients bsmall1 , bsmall2 , bsmall1 , bsmall2 żeby B1b ig(x, y) = 1 1 2 2 small1 small1 small2 small2 small1 small1 small2 small2 b1 B1 (x, y) + b1 B1 (x, y) + b2 B2 (x, y) + b2 B2 (x, y), dla x ∈ (0, 2)y = 1 i.e. stretched on a common edge This process is illustrated in Pic. 48. You can see here Open AGH e-podręczniki - content available under the CC BY-SA license
177
6.7. Isogeometric analysis on adaptive grids that this combination is B1b ig(x, y) = 1.0 ∗ B1small1 (x, y) + 0.5 ∗ B1small2 (x, y) + 0.5 ∗ B2small1 (x, y), czyli 1.0, 0.5, 0.5, 0.0. In addition, we need to map the functions B2big (x, y) by a linear combination of functions B1small1 (x, y), B1small2 (x, y), B2small1 (x, y), B2small2 (x, y). In other words, we need to find such coefficients csmall1 , csmall2 , csmall1 , csmall2 żeby B2b ig(x, y) = csmall1 B1small1 (x, y) + csmall2 B1small2 (x, y) + 1 1 2 2 1 1 small1 small1 small2 small2 c2 B2 (x, y) + c2 B2 (x, y), dla x ∈ (0, 2)y = 1 that is, stretched on a common edge. This process is illustrated in Pic. 49. We can see tere That this combination is B2b ig(x, y) = 0.5 ∗ B1small2 (x, y) + 0.5 ∗ B2small1 (x, y) + 1.0 ∗ B2small2 (x, y)+, czyli 0.0, 0.5, 0.5, 1.0.
Figure 48: The first big base function obtained by merging small base functions.
Figure 49: The second large basis function obtained by merging small basis functions.
In general, where we have higher order polynomials span over the large and small elements, we can just project the basis functions from the large edge into the small basis functions over two small edges.
6.7.
Isogeometric analysis on adaptive grids
Adaptive meshes made of rectangular elements of various sizes also allow for calculations using isogeometric analysis. First, if the group of the elements are separated with C 0 separators, then on each block of elements we can generate knot vectors describing the basis functions, and merge them as described in the chapter Approximation on meshes with hanging nodes. Another widely used approach is the use of T-spline basis functions. They were invented in 2003 by Thomas Sederberg and other authors [41]. They even have a patent in the USA [42]. T-spline functions are used in isogeometric analysis [43]. They are a modification of the B-spline function which allows them to be spanned on adaptive nets. Each B-spline function spans a series of horizontal and vertical segments that define the group of elements on which it is defined (on which it takes non-zero values). The point at which it takes its maximum value is either at the center of the element (for even-order B spline) or at the vertex at the element edges (for odd-order B-spline). So, we can think of B spline functions as functions related Open AGH e-podręczniki - content available under the CC BY-SA license
178
6.7. Isogeometric analysis on adaptive grids to element centers or mesh vertices (depending on the degree of the B spline function). B-spline order functionp unzips on 2p − 1 items. For example, for a second order B spline function we have 2 ∗ 2 − 1 = 3 elements, i.e., one element with the center (maximum function) and one element on the left and one element on the right. If we draw a horizontal line from the center of the B-spline to the left and right, and find the intersection of this line with the edges of the elements, then for a second-degree B-spline we need to find two intersections on the left and two intersections on the right, and we get all the segments unfastened on the elements on which our B-spline is unfastened. The idea behind the T-spline function is to generalize this idea to adaptive meshes. Consider an even degree of the T-spline function. If we have an adapted mesh with elements of different sizes, then we can bind each T-spline function to the center of some element. Then, along the lines in the vertical and horizontal directions, we find intersections with the edges of the elements. For the second-degree T-spline, we need to find two intersections in each direction. In this way, we get three segments in the vertical and horizontal directions on which we span T-spline functions according to the formula for B-spline functions. We just take four points and put it in the formula for B-spline. The process of determining the vertical and horizontal segments for the T-spline function is illustrated in Pic. 50.
Figure 50: Spreading the T-spline function on a two-dimensional mesh adapted towards the edge.
Such a way of defining the T-spline function on a mesh adapted towards a point, as shown in Pic. 50 has one drawback. Note that if we want to use our T-spline functions for approximation, we will have to build a matrix in which the rows and columns represent the individual T-spline functions, while the terms of this matrix denote the integrals of the products of these functions and their values. These integrals are non-zero if the corresponding T-spline functions intersect. For an example set of T-spline functions, the generated matrix (for example, for a bitmap projection problem or for a heat transport problem) appears as shown in Pic. 50. You can see that this matrix is relatively dense. In order to reduce the areas in which T-spline functions are defined, extensions are introduced to extend the edges on which nodes hang in the adaptive mesh (in English these extensions are called ”T-junction extensions”). This is illustrated in Pic. 51. When the mesh is modified to add these additional edges, the mesh is now said to be ”analysis suitable”. The idea of mesh modification algorithm for T-spline functions is described in detail in the paper [44].
Open AGH e-podręczniki - content available under the CC BY-SA license
179
6.7. Isogeometric analysis on adaptive grids
Figure 51: Grid with T-junction extensions added.
After modifying the mesh, we generate new T-spline functions, see Pic. 52.
Figure 52: T-spline functions span on a mesh modified for numerical analysis by adding edge extensions of hanging nodes (analysis suitable mesh with T-junction extensions).
The newly generated T-splines functions generate a computational mesh that is larger but the
Open AGH e-podręczniki - content available under the CC BY-SA license
180
6.8. MATLAB implementation of the adaptive algorithm for the bitmap projection problem computational cost of its factorization is cheaper, see [45] and Pic. 53.
Figure 53: Matrix generated from modified T-splines functions.
6.8.
MATLAB implementation of the adaptive algorithm for the bitmap projection problem
Below you can find a link to the MATLAB code that computes the L2 bitmap projection using the adaptive finite element method. In particular, this code has an implementation of the h-adaptation algorithm in MATLAB. The code execution is also possible in the free Octave environment. Download code or see Appendix 6. In order to run the codes, we save them in the Octave working directory. We set the variables with the path to the input file in tif format f ilename =0 C : //U sers/M aciej/Dropbox/bitmapa.tif 0 then we give the number of mesh elements in the x and y directions, and the degrees of B-spline in these directions elementsx = 4, elementsy = 4 are the size of the initial grid. We enter the maximum approximation error maxerror = 0.5, and indicate whether the mesh edges are to be drawn maxlevel = 4 and indicate whether the mesh edges are to be drawn edges = 1. Then we start the first procedure bitmap_h(f ilename, elementsx, elementsy, maxerror, maxlevel, edges). After executing the adaptation sequence, the code draws the bitmap in the open window. Open AGH e-podręczniki - content available under the CC BY-SA license
181
6.8. MATLAB implementation of the adaptive algorithm for the bitmap projection problem
Open AGH e-podręczniki - content available under the CC BY-SA license
182
Chapter 7
7. Finite element method for non-stationary and non-linear problems 7.1.
Non-stationary problems
In the case of non-stationary problems, the solution sought depends both on time and space. In the general strong form, in which the computational problem is described by a partial differential equation ∂u(x,y;t) ∂t
− L (u (x, y; t)) = f (x, y; t)
the derivative with respect to time now appears ∂u(x,y;t) ∂t
representing the changes over time of the searched scalar field Ω × [0, t] 3 (x, t) → u (x, y; t) ∈ R. The meaning of the searched field depends on the type of problem being solved. The type of problem to be solved is ”coded” in the operator L (u (x, y; t)), describing the modeled physical phenomenon by means of partial differential operators. Similarly to solving stationary problems (not changing with time), it is necessary to provide boundary conditions (i.e. information about what is happening on the boundary of the simulated area). Additionally, in the case of simulation of non-stationary problems, it is necessary to provide the initial condition (i.e. provide information about the state of the modeled phenomenon at the beginning of the simulation)u(x, y; 0) = u0 (x, y). There is also a right-hand side in the equation f (x, y; t) describing the ”force” that supplies energy (momentum, mass, etc. depending on the modeled phenomenon) to the system. There are two methodologies for solving the non-stationary problems. In the first, discretization is performed first with respect to time, and then with respect to space. In the second, discretization is performed first in space, and then over time (this method is called the method of lines). In our considerations, we will use the first method. Thus, in order to solve the non-stationary problem, we introduce time steps t0 = 0 < t1 < t2 < · · · tk−1 < t < tk+1 < · · · < tN and states of the modeled phenomenon in particular time steps, represented by a scalar field u(t) 183
7.2. Non-stationary problems as a generalization of a sequence of the isogeometric L2 projections u0 = u(t0 ), u1 = u(t1 ), u2 = u(t2 ), · · · , uk−1 = u(tk−1 ), uk = u(tk ), uk+1 = u(tk+1 ), · · · , uN = u(tN ) We approximate the derivative in time using the finite difference method
∂u ∂t
≈
ut+1 −ut dt
So we get the equation ut+1 −ut dt
− L(u) = f .
Now the question arises, at what moment in time to take the state of the modeled phenomenon, represented by the scalar field u(t). We have several possibilities: 1. take the state at the previous time moment ut , 2. take the state at the actual time moment ut+1 , 3. take the state as the combination of the previous and actual time moments αut + (1 − α)ut+1 . The first way gives us the explicit method, also called the Euler method (forward Euler) ut+1 −ut dt
− L(ut ) = f .
The second way gives us the implicit method, also called backward Euler ut+1 −ut dt
− L(ut+1 ) = f .
The third way gives us the implicit method, and depending on how the linear combination is defined, it will be the Crank-Nicolson method, or the alpha method. ut+1dt−ut − L(αut + (1 − α)ut+1 ) = f . Explicit methods always allow for a quick solution in linear time, but only small time steps can be used in them (otherwise the simulation will become unstable). Implicit methods allow the use of larger time steps (if they are absolutely stable, and checking if the method is indeed absolutelty stable it requires advanced mathematical knowledge). Implicit methods usually require expensive solvers. In this tutorial we shows how to get linear time solvers for implicit methods on tensor product patches of elements employed by the isogeometric analysis. These methods are derived from a family of methods called Runge-Kutta methods [46].
7.2.
Non-stationary problems as a generalization of a sequence of the isogeometric L2 projections
Notice that the Euler method is actually equivalent to a sequence of isogeometric L2 projections, similar to the calculation of a bitmap projection. This time, however, our ”bitmap” is the state of the system in the previous time step, plus changes caused by the ”physics” of the modeled phenomenon during the time step, plus changes caused by the force acting on our system during the time step. The method of treating the non-stationary equation as sequences of isogeometric projections is described in [47]. To develop a solver using the Euler method in the isogeometric finite element method, we need to transform a strong formulation into a weak formulation. So we multiply our equation by the test functions (ut+1 , w) = (ut + dt ∗ L(ut ) + dt ∗ ft , w) We will use a linear combination of the B-spline function to approximate the state of our system at a given moment in time. For this purpose, we select the basis of two-dimensional B-spline functions, specifying the node vectors in the direction of the axis of the coordinate system. To establish attention, we can choose a two-dimensional basis of the second order B-spline function Open AGH e-podręczniki - content available under the CC BY-SA license
184
7.2. Non-stationary problems as a generalization of a sequence of the isogeometric L2 projections y x {Bi,2 (x)Bj,2 (y)}i=1,...,Nx ;j=1,...,Ny .
They will be used to approximate the simulated scalar field at given time moment P y x u(x, y; t + 1) ≈ i=1,...,Nx ;j=1,...,Ny ut+1 i,j Bi (x)Bj (y). Similarly, for testing, we will use the B-spline basis functions: {Bkx (x)Bly (y)}k=1,...,Nx ;l=1,...,Ny Our equation now looks identical to the isgeometric L2 projection problem P y y t+1 x x ∀k = 1, ..., Nx ; l = 1, ..., Ny i=1,...,Nx ;j=1,...,Ny ui,j (Bi (x)Bj (y), Bk (x)Bl (y)) = RHS
Our right side is not a bitmap, however, but a projection of the sum of three elements: P 1. The state of our system at the previous moment in time (ut , w) = i=1,...,Nx ;j=1,...,Ny uti,j (Bix (x)Bjy (y), Bkx (x)Bly (y)) multiplied by the test function and integrated over the area). Of course, we also use a linear combination of B-spline basis functions to represent the state of our system in the previous time step P u(x, y; t) = ut = i=1,...,Nx ;j=1,...,Ny uti,j Bix (x)Bjy (y) 2. Changes induced by the ”physics” of the simulated phenomenon during the time step. These changes are calculated by applying the differential operator representing the modeled phenomenon to the state of the system at the previous moment. The state of the system is of course represented by a linear combination of the B-spline function. So the differential operator is applied to the B-spline function P (dt ∗ L(ut ), w) = i=1,...,Nx ;j=1,...,Ny dt ∗ uti,j (L(Bix (x)Bjy (y)), Bkx (x)Bly (y)). For the heat transfer problem, we have P ∂ 2 (Bix (x)Bjy (y)) t + i=1,...,Nx ;j=1,...,Ny dt ∗ ui,j ( ∂x2
∂ 2 (Bix (x)Bjy (y)) , Bkx (x)Bly (y)). ∂y 2
We can integrate by parts ∂(B x (x)B y (y)) P ∂(Bix (x)Bjy (y)) ∂(Bkx (x)Bly (y)) y ∂(Bkx (x)Bly (y)) y i j t x x dt∗u ( B (y), B (y)) + (B (x) , B (x) ) i,j i j k i=1,...,Nx ;j=1,...,Ny l ∂x ∂x ∂y ∂y which due to the structure of the tensor product of the B-spline function, and due to the fact that the derivative in the y direction of the B-spline function of the variable x gives 0, and the derivative in the x direction of the B-spline function of the variable y gives 0, we get P ∂Bjy (y) ∂Bly (y) ∂Bix (x) y ∂Bkx (x) y t x x i=1,...,Nx ;j=1,...,Ny dt ∗ ui,j ( ∂x Bj (y), ∂x Bl (y)) + (Bi (x) ∂y , Bk (x) ∂y ) . 3. Changes caused by the force acting on the system during the time step (ft , w) (ft (x, y), Bkx (x)Bly (y)) In the explicit method, the system matrix is a mass matrix {Mx ⊗ My }i,j,k,l R x R Bi (x)Bkx (x)Bjy (y)Bly (y) = Bix (x)Bjy (y)Bkx (x)Bly (y) = Mi,j,k,l
=
=
which has the structure of a Kronecker product and can be factored in linear time by an alternating-direction solver. The disadvantage of the method is explicitly the fact that a single time step cannot be too long, otherwise the method will be unstable. It will show up with an explosion of numerical simulations. This is due to the so-called Courant-Friedrichs-Lewy condition (CFL condition). In general, it says numerical simulation in which we model a scalar field u(x, t) is stable if C = u∗dt < Cmax where h u = maxu(x, t) denotes the maximum value of the simulated field, dt denotes the time step, h denotes element dimension (which in case of IGA translates to the knot points span), and Cmax is a problem specific constant. The practical significance of this condition is as follows: if we increase the number of mesh elements (increase the number of points in the knot vector) then h will decrease. To make sure our simulation does not ”explode,” we have to decrease the time step. This is a big limitation because it means that increasing accuracy in space forces time step sizes to decrease, which means a higher simulation cost. One solution to this problem is the use of implicit simulations with time integration schemes that allow the use of alternating direction solvers.
Open AGH e-podręczniki - content available under the CC BY-SA license
185
7.3. Examples of differential operators and right-hand-sides for selected problems
7.3.
Examples of differential operators and right-hand-sides for selected problems
To formulate a non-stationary problem, you need to define the left-had side operator and the right-hand side function L (u (x, y; t)) = F(x, y, z). Examples of differential operators L (u (x, y; t)) in non-stationary formulations describe various modelled physical phenomena. Additionally, we will comment on the physical meaning of the boundary and initial conditions. We list here examples of linear and non-linear operators.
EXAMPLE
Example 13: Homogeneous heat transport 2
2
Operator modeling homogeneous heat transport L∞ (u) = ∆u = ∂ u(x,y;t) + ∂ u(x,y;t) . In this case, ∂x2 ∂y 2 the initial condition gives us information about the temperature distribution in the modeled area at the initial moment of the simulation. Boundary conditions in turn determine the temperature at the boundary of the domain, or the rate of heat change on the boundary of the domain (how quickly heat escapes from our area, or how quickly it flows into our area), or the heat flux depending on the temperature difference, or the boundary condition describing the phenomenon radiation. The right-hand side function L (u (x, y; t)) = F(x, y; t) depending on the assumption of positive or negative values, can model a heater or cooler located in the area under consideration, which locally supplies heat (increases the temperature) or lowers the temperature through the cooling mechanism (heat discharge).
EXAMPLE
Example 14: Diffusion Operator modeling diffusion through a material with specific = ∇ (K∇u) = properties L∈ (u) ∂u(x,y;t) ∂u(x,y;t) ∂ ∂ K(x, y; t) + K(x, y; t) . Here, the initial state gives us information ∂x ∂x ∂y ∂y about the initial concentration of the substance, the diffusion of which in a given area is simulated. Diffusion is a special case of heat transport equations, and analogous kinds of boundary conditions are also possible. Diffusion coefficient R2 × [0, T ] 3 (x, y) × t → K(x, y; t) ∈ R2×2 may even be a matrix-valued function. The boundary condition describes the concentration on the boundary or the speed of ”escape” or ”inflow” of the substance under consideration, or the diffusion flux depending on the concentration difference, or the phenomenon of radiation. The right-hand side function L (u (x, y; t)) = F(x, y; t) here means the source of the diffusible substance, or its loss (suction).
EXAMPLE
Example 15: Flow in a heterogeneous medium Open AGH e-podręczniki - content available under the CC BY-SA license
186
7.4. Explicit method ∂ Flow in a heterogeneous medium L3 (u) = ∇ (Kexp(µu)) ∇u = ∂x K(x, y; t)exp(µu(x, y; t)) ∂u(x,y;t) + ∂x ∂u(x,y;t) ∂ . In this case, we model the pressure scalar field in the ∂y K(x, y; t)exp(µu(x, y; t)) ∂y geological area into which we pump the liquid under pressure. The right-hand side function, assuming positive values, models the position of the pump pumping the liquid under pressure, and assuming negative values, it models a suction pump, used, for example, in the oil extraction process. The initial condition here means the initial distribution of the pressure field in the modeled area. Boundary condition means the value or changes of pressure on the edge of the modeled area.
EXAMPLE
Example 16: Pollution propagation Pollution propagation L4(u) ∂ = ∂x K(x, y; t) ∂u(x,y;t) + ∂x
∂ ∂y
= β · ∇u + ∇ · (K∇u) = ∂u(x,y;t) ∂u(x,y;t) u(x,y;t) K(x, y; t) ∂y + βx (x, y; t) ∂x + βy (x, y; t) ∂y .
In this example, we model the concentration of pollutants in a given area. The positive value of the right-hand side function L (u (x, y; t)) = F(x, y, z) means the source of pollution (e.g., chimney), the negative value of the right-hand side function means the pollution suction pump (e.g., such pumps placed in the main squares in cities that suck the pollution from the atmosphere). The initial state means the initial concentration of pollutants in the modeled area. Boundary conditions mean the concentration of pollutants on the boundary, or the speed of the blowing in of pollutants from outside the area, or the interaction of a pollutant field with the ground.
EXAMPLE
Example 17: Flow equations for incompressible fluids Non-stationary nonlinear flow equations for incompressible fluids, called the Navier-Stokes equations, are a vector equation in which the velocity vector field and the pressure scalar field are sought ∂u L5 (u, p) = ∂t − µ∆u + (u · ∇)u + ∇p = f ; divp = 0 . A typical model problem in which we solve the Navier-Stokes equations is, for example, a flow in a square-shaped region, forced by a river flowing along the upper edge of the region. The non-linear term in non-stationary equations can be treated ”explicite”. ut+1 − µ∆ut+1 + ∇pt+1 = f − (ut · ∇)ut . Commonly used algorithms for solving Navier-Stokes equations are the pressure correction algorithms called SIMPLE, SIMPLEC or PISO. Modern numerical schemes used in the Navier-Stokes equations simulations can be found in paper [48].
7.4.
Explicit method
In the Euler method used to solve non-stationary problems, the differential operator describing the ”physics” of the simulated phenomenon is computed at the previous time instant ut+1 −ut dt
− L(ut ) = ft+1
Thus, all parts of the equation are calculated on the basis of the state at the previous moment, and only the state correction at the current moment is performed: Open AGH e-podręczniki - content available under the CC BY-SA license
187
7.4. Explicit method ut+1 = ut + dt ∗ L(ut ) + dt ∗ ft+1 We choose the so-called test functions w and we multiply our equation (ut+1 , w) = (ut + dt ∗ L(ut ) + dt ∗ ft+1 , w) Symbol (u, w) here stands for the dot product in space L2 i.e. integration (while in the following formula the bracket means ”ordinary” bracket) R R (u w)dxdy = Ω (ut + dt ∗ L(ut ) + dt ∗ ft+1 )wdxdy Ω t+1 Note that our problem is similar in structure to the bitmap projection problem (ut+1 (x, y), w(x, y)) = (BIT M AP A(x, y), w(x, y)) and in fact we can use the same code which, instead of reading the pixels of the bitmap, will sample the right side pixel by pixel. So what exactly is our equation and the right-hand side? We will use a linear combination of the B-spline function to approximate the state of our system at a given moment in time. For this purpose, we select the basis of two-dimensional B-spline functions, specifying the knot vectors in the direction of the axis of the coordinate system, for example, the two-dimensional basis of y x the second-order B-spline function {Bi,2 (x)Bj,2 (y)}i=1,...,Nx ;j=1,...,Ny ui,j They will be used to approximate the simulated scalar field of the current time instant u(x, y; t + 1) ≈ P y t+1 x i=1,...,Nx ;j=1,...,Ny ui,j Bi (x)Bj (y) and at the previous moment in time P u(x, y; t) ≈ i=1,...,Nx ;j=1,...,Ny uti,j Bix (x)Bjy (y) Similarly, we will use the B-spline base functions for testing: w(x, y) ∈ {Bkx (x)Bly (y)}k=1,...,Nx ;l=1,...,Ny wk,l Assuming the differential operator L describing ”physics” is linear, our equation now looks like this: P y y t+1 x x i=1,...,Nx ;j=1,...,Ny ui,j (Bi (x)Bj (y), Bk (x)Bl (y)) = P = i=1,...,Nx ;j=1,...,Ny uti,j (Bix (x)Bjy (y), Bkx (x)Bly (y))+
+dt∗
X
uti,j L(Bix (x)Bjy (y), Bkx (x)Bly (y))+dt∗(ft+1 (x, y), Bkx (x)Bly (y)) ∀k = 1, ..., Nx ; l = 1, ..., Ny
i=1,...,Nx ;j=1,...,Ny
We do not establish a specific problem here, the conclusions presented here refer to any physical problem that can be simulated with the method described. For example, for the problem of heat transport we have P y y t+1 x x i=1,...,Nx ;j=1,...,Ny ui,j (Bi (x)Bj (y), Bk (x)Bl (y)) = P = i=1,...,Nx ;j=1,...,Ny uti,j (Bix (x)Bjy (y), Bkx (x)Bly (y))+. 2 x P ∂ (Bi (x)Bjy (y)) ∂ 2 (Bix (x)Bjy (y)) y t x +dt ∗ i=1,...,Nx ;j=1,...,Ny ui,j + dt ∗ , Bk (x)Bl (y) + ∂x2 ∂y 2 +(ft+1 (x, y), Bkx (x)Bly (y)) ∀k = 1, ..., Nx ; l = 1, ..., Ny that is, remembering that the symbol (u, w) here stands for the dot product in space L2 i.e. integration, we have (in the next formula the bracket means ”ordinary” bracket) R P t+1 B x (x)Bjy (y)Bkx (x)Bly (y)dxdy = i=1,...,Nx ;j=1,...,Ny ui,j Ω i R P = i=1,...,Nx ;j=1,...,Ny uti,j Ω Bix (x)Bjy (y)Bkx (x)Bly (y)dxdy+
Open AGH e-podręczniki - content available under the CC BY-SA license
188
7.4. Explicit method
t i=1,...,Nx ;j=1,...,Ny ui,j
+dt ∗
P
+dt ∗
R Ω
R Ω
∂ 2 (Bix (x)Bjy (y)) ∂x2
(ft+1 (x, y)Bkx (x)Bly (y))dxdy
+
∂ 2 (Bix (x)Bjy (y)) ∂y 2
Bkx (x)Bly (y)dxdy+
∀k = 1, ..., Nx ; l = 1, ..., Ny
Coming back to the bitmap analogy, we have R R u (x, y)w(x, y)dxdy = Ω BIT M AP A(x, y)w(x, y)dxdy Ω t+1 that is, our ”bitmap function” is given P BIT M AP A(x, y) = i=1,...,Nx ;j=1,...,Ny uti,j Bix (x)Bjy (y)+ 2 x P ∂ (Bi (x)Bjy (y)) ∂ 2 (Bix (x)Bjy (y)) t + i=1,...,Nx ;j=1,...,Ny ui,j dt + + dt ∗ ft+1 (x, y) ∂x2 ∂y 2 and we can actually use the same code which, instead of reading the pixels of the bitmap, will sample the above right-hand side ”pixel by pixel”. Normally, on the right-hand side, we can split the red term (assuming that the domain is large enough that the edge integral can be ignored because the modeled area or its derivatives are zero R P there) i=1,...,Nx ;j=1,...,Ny ut+1 B x (x)Bjy (y)Bkx (x)Bly (y)dxdy = i,j Ω i R P = i=1,...,Nx ;j=1,...,Ny uti,j Ω Bix (x)Bjy (y)Bkx (x)Bly (y)dxdy+ R ∂(Bix (x)Bjy (y)) ∂(Bix (x)Bjy (y)) ∂(Bkx (x)Bly (y)) ∂(Bkx (x)Bly (y)) P −dt ∗ i=1,...,Nx ;j=1,...,Ny uti,j Ω + + dxdy+ ∂x ∂y ∂x ∂y R +dt ∗ Ω (ft+1 (x, y)Bkx (x)Bly (y))dxdy ∀k = 1, ..., Nx ; l = 1, ..., Ny Note that the terms (red and blue) in which we calculate the values of the solution from the previous time, mean sampling the sum of all B-splines multiplied by the coefficients calculated in the previous time step. Such integration is performed according to the chapter ”Variational formulation and numerical integration”. In particular, note that these integrals can be broken down into the sum of the integrals of individual mesh elements, and on a given mesh element only (p + 1)2 B-spline base functions, where p denotes the degree of the B-spine function. Explicit method simulations are limited by the size of the time step. Increasing the spatial accuracy (increasing the mesh size of the finite element method to solve the right-to-left projection problem) requires reducing the size of the time step, otherwise the simulation will start to behave unstably (colloquially the simulation will ”explode”). This is expressed by the Courant-Friedrichs-Levi (CFL) condition udt dx
< Cmax
where u is the maximum value of the simulated phenomenon (traditionally it is the maximum speed, thanks to which the condition has a dimensionless form, which only applies to tasks with dominant convection and a constant or variable speed field), dt is the length of the time step, dx stands for element size (element diameter). The CFL condition was originally proposed for the finite difference method, however it also works for the finite element method. Constant Cmax cannot be exceeded by the quotient udt dx .
If this happens (for example, the time step will be too large) then the simulation will start to behave unstably (colloquially speaking ”it will explode”)[49]. Below I present examples of two simulations of wave propagation for an elastic material, calculated using the explicit method. In the first case, the CFL condition is not met, in the second case it is met. They have been numbered with the IGA-ADS code [47].
Open AGH e-podręczniki - content available under the CC BY-SA license
189
7.4. Explicit method
https://vimeo.com/370070805 Stabilne
Open AGH e-podręczniki - content available under the CC BY-SA license
190
7.5. Implicit method
https://vimeo.com/370070745 Niestabilne
7.5.
Implicit method
In the implicit method called ”backward Euler”, which is used to solve non-stationary problems, the differential operator describing the ”physics” of the modeled phenomenon is calculated in the ”current” instant of time ut+1 −ut dt
− L(ut+1 ) = ft+1 .
So at each time step it is necessary to solve the equation for the next state ut+1 . Let us follow the operation of the backward Euler method in the case of the isogeometric finite element method. To develop a solver that uses the method implicitly in the isogeometric finite element method, we need to transform a strong formulation into a weak formulation. So we multiply our equation by the test functions (ut+1 , w) − (dt ∗ L(ut+1 ), w) = (ut + dt ∗ ft+1 , w). We will use a linear combination of the B-spline function to approximate the state of our system at a given
Open AGH e-podręczniki - content available under the CC BY-SA license
191
7.5. Implicit method moment in time. For this purpose, we select the basis of two-dimensional B-spline functions, specifying the node vectors in the direction of the axis of the coordinate system, for example, the two-dimensional basis of the second-order B-spline function y x {Bi,2 (x)Bj,2 (y)}i=1,...,Nx ;j=1,...,Ny ui,j .
They will be used to approximate the simulated scalar field of the current time instant P u(x, y; t) ≈ i=1,...,Nx ;j=1,...,Ny uti,j Bix (x)Bjy (y). Similarly, we will use the B-spline base functions for testing: w(x, y) ∈ {Bkx (x)Bly (y)}k=1,...,Nx ;l=1,...,Ny wk,l Assuming the differential operator L describing ”physics” is linear, our equation now looks like this: P y y y t+1 x x x i=1,...,Nx ;j=1,...,Ny ui,j (Bi (x)Bj (y) − dt ∗ L(Bi (x)Bj (y)), Bk (x)Bl (y)) = RHS ∀k = 1, ..., Nx ; l = 1, ..., Ny We do not establish a specific problem here, the conclusions presented here refer to any physical problem that can be simulated with the method described. For example, for the problem of heat transport we have P ut+1 i,j i=1,...,Nx ;j=1,...,Ny ∂ 2 (Bix (x)Bjy (y)) ∂ 2 (Bix (x)Bjy (y)) y x (Bi (x)Bj (y) − dt ∗ + , Bkx (x)Bly (y)) = RHS ∂x2 ∂y 2 ∀k = 1, ..., Nx ; l = 1, ..., Ny Thanks to the weak formulation, we can integrate by parts P ut+1 i=1,...,Nx ;j=1,...,Ny i,j ∂(Bix (x)Bjy (y)) ∂(Bkx (x)Bly (y)) ∂(Bix (x)Bjy (y)) ∂(Bkx (x)Bly (y)) (Bix (x)Bjy (y), Bkx (x)Bly (y)) − dt ∗ ( , ) − dt ∗ ( , ) = RHS . ∂x ∂x ∂y ∂y ∀k = 1, ..., Nx ; l = 1, ..., Ny Due to the structure of the tensor product of the B-spline function and due to the fact that the derivative in the y direction of the B-spline in the x-axis direction gives 0 (because these functions are constant in the y-axis direction) and similarly for the derivative in the y-direction of the B-spline in the x-axis direction, we have P ut+1 i=1,...,Nx ;j=1,...,Ny i,j ∂Bjy (y) ∂Bly (y) ∂Bix (x) y ∂Bkx (x) y (Bix (x)Bjy (y), Bkx (x)Bly (y)) − dt ∗ ( ∂x Bj (y), ∂x Bl (y)) − dt ∗ (Bix (x) ∂y , Bkx (x) ∂y ) = RHS . ∀k = 1, ..., Nx ; l = 1, ..., Ny Note that our system of equations to solve is (Mx ⊗ My − dt ∗ Sx ⊗ My − dt ∗ Mx ⊗ Sy ) ut+1 = F (t) where R R {Mx ⊗ My }i,j,k,l = Bix (x)Bkx (x)Bjy (y)Bly (y) = Bix (x)Bjy (y)Bkx (x)Bly (y) = Mi,j,k,l is a mass matrix which is a Kronecker product of two one-dimensional mass matrices, R ∂Bix (x) ∂Bkx (x) y R ∂Bix (x) y ∂Bkx (x) y y {Sx ⊗ My }i,j,k,l = ∂x ∂x Bj (y)Bl (y) = ∂x Bj (y) ∂x Bl (y) is the Kronecker product of the one-dimensional stiffness matrix and the one-dimensional mass matrix, and R R ∂Bjy (y) ∂Bly (y) ∂Bjy (y) x ∂Bly (y) {Mx ⊗ Sy }i,j,k,l = Bix (x)Bkx (x) ∂y = Bix (x) ∂y Bk (x) ∂y is the Kronecker product of ∂y the one-dimensional mass matrix and the one-dimensional stiffness matrix. Each of these matrices can be factored in linear time using the variable-directional solver algorithm. However, it is no longer possible to factorize their sum in linear time. This is possible only when we introduce a time step scheme that allows the matrix to be separated into sub-matrices in time sub-steps so that the factorization cost remains linear.
Open AGH e-podręczniki - content available under the CC BY-SA license
192
7.6. Crank-Nicolson scheme The Peaceman-Rachford diagram allows splitting the time step into two sub-steps (Mx ⊗ My − dt ∗ Sx ⊗ My ) ut+1/2 = F (t + 1/2) + (dt ∗ Mx ⊗ Sy ) ut (Mx ⊗ My − dt ∗ Mx ⊗ Sy ) ut+1 = F (t + 1/2) + (dt ∗ Sx ⊗ My ) ut+1/2 where we can merge the left side matrices into a single matrix with a Kronecker product structure that can be factored in linear time using the alternating direction solver algorithm (Mx − dt ∗ Sx ) ⊗ My ut+1/2 = F (t + 1/2) + (dt ∗ Mx ⊗ Sy ) ut Mx ⊗ (My − dt ∗ Sy ) ut+1 = F (t + 1/2) + (dt ∗ Sx ⊗ My ) ut+1/2
The right-hand side function here represents the changes caused by the force acting on the system during the time step. It is the sum of two elements: P 1. The state of our system at the previous moment in time (ut , w) = i=1,...,Nx ;j=1,...,Ny uti,j (Bix (x)Bjy (y), Bkx (x)Bly (y)) multiplied by the test function and area integrated). Of course, we also use a linear combination of B-spline basis functions to represent the state of our system in the previous time step P u(x, y; t) = ut = i=1,...,Nx ;j=1,...,Ny uti,j Bix (x)Bjy (y). 2. Changes caused by a force acting on the system during the time step (ft+1 , w) (ft+1 (x, y), Bkx (x)Bly (y)).
7.6.
=
Crank-Nicolson scheme
We introduce time steps t0 = 0 < t1 < t2 < · · · tk−1 < t < tk+1 < · · · < tN and states of the modeled phenomenon in particular time steps, represented by a scalar field u(t) u0 = u(t0 ), u1 = u(t1 ), u2 = u(t2 ), · · · , uk−1 = u(tk−1 ), uk = u(tk ), uk+1 = u(tk+1 ), · · · , uN = u(tN ). We approximate the derivative in time using the finite difference method
∂u ∂t
≈
ut+1 −ut . dt
So we get the equation ut+1 −ut dt
− L(u) = f .
The implicit method, called the Crank-Nicolson method (invented by Mrs. Phyllis Nicolson, a female British mathematician and John Crank, an American mathematician and physicist in 1947) works as follows [50]. In this method, we apply our differential operator to the mean value of the previous and next states: ut+1 −ut dt
− L( 12 (ut + ut+1 )) = ft+1 .
If the differential operator is linear, then we can break it into two terms ut+1 − dt 12 L(ut+1 ) = ut + dtft+1 + dt 12 L(ut ) leaving our ”unknown” on the left-hand side ut+1 . Then we use the isogeometric finite element method. To develop a solver that uses the method implicitly in the isogeometric finite element method, we need to transform a strong formulation into a weak formulation. So we multiply our equation by the test functions (ut+1 , w) − dt 12 (L(ut+1 ), w) = (ut , w) + dt(ft+1 , w) + dt 12 (L(ut ), w) We will use a linear combination of the B-spline function to approximate the state of our system at a given moment in time. For this purpose, we select the basis of two-dimensional B-spline functions, defining the node vectors in the direction of the coordinate system axis.
Open AGH e-podręczniki - content available under the CC BY-SA license
193
7.6. Crank-Nicolson scheme For example, we can choose a two-dimensional basis of a second order B spline y x {Bi,2 (x)Bj,2 (y)}i=1,...,Nx ;j=1,...,Ny ui,j
These will be used to approximate the simulated scalar field to the current time instant P y x u(x, y; t + 1) ≈ i=1,...,Nx ;j=1,...,Ny ut+1 i,j Bi (x)Bj (y) Similarly, for testing, we will use the B-spline base functions: w(x, y) ∈ {Bkx (x)Bly (y)}k=1,...,Nx ;l=1,...,Ny wk,l Assuming that the differential operator describing ”physics” is linear, that is L(αu + βw) = αL(u) + βL(w) our equation now looks like this: P y y y t+1 1 x x x i=1,...,Nx ;j=1,...,Ny ui,j (Bi (x)Bj (y) − dt 2 L(Bi (x)Bj (y)), Bk (x)Bl (y)) = RHS . ∀k = 1, ..., Nx ; l = 1, ..., Ny For example, for the problem of heat transport we have P ut+1 i,j i=1,...,Nx ;j=1,...,Ny ∂ 2 (Bix (x)Bjy (y)) ∂ 2 (Bix (x)Bjy (y)) y 1 (Bix (x)Bj (y) − dt 2 + , Bkx (x)Bly (y)) = RHS . ∂x2 ∂y 2 ∀k = 1, ..., Nx ; l = 1, ..., Ny Thanks to the weak formulation, we can integrate by parts P ut+1 i=1,...,Nx ;j=1,...,Ny i,j ∂(Bix (x)Bjy (y)) ∂(Bkx (x)Bly (y)) ∂(Bix (x)Bjy (y)) ∂(Bkx (x)Bly (y)) (Bix (x)Bjy (y), Bkx (x)Bly (y)) − dt 12 ( , ) − dt ∗ ( , ) = RHS . ∂x ∂x ∂y ∂y ∀k = 1, ..., Nx ; l = 1, ..., Ny Due to the structure of the tensor product of the B-spline function and due to the fact that the derivative in the y direction of the B-spline in the x-axis direction gives 0 (because these functions are constant in the y-axis direction) and similarly for the derivative in the y-direction of the B-spline in the x-axis direction, we have P ut+1 i=1,...,Nx ;j=1,...,Ny i,j ∂Bjy (y) ∂Bly (y) ∂Bix (x) y ∂Bkx (x) y (Bix (x)Bjy (y), Bkx (x)Bly (y)) − dt 12 ( ∂x Bj (y), ∂x Bl (y)) − dt ∗ (Bix (x) ∂y , Bkx (x) ∂y ) = RHS . ∀k = 1, ..., Nx ; l = 1, ..., Ny Note that our system of equations to solve is Mx ⊗ My − dt 12 Sx ⊗ My − dt ∗ Mx ⊗ Sy ut+1 = F (t) where R R {Mx ⊗ My }i,j,k,l = Bix (x)Bkx (x)Bjy (y)Bly (y) = Bix (x)Bjy (y)Bkx (x)Bly (y) = Mi,j,k,l is a mass matrix which is a Kronecker product of two one-dimensional mass matrices, R ∂Bix (x) ∂Bkx (x) y R ∂Bix (x) y ∂Bkx (x) y y {Sx ⊗ My }i,j,k,l = ∂x ∂x Bj (y)Bl (y) = ∂x Bj (y) ∂x Bl (y) is the Kronecker product of the one-dimensional stiffness matrix and the one-dimensional mass matrix, and R R ∂Bjy (y) ∂Bly (y) ∂Bjy (y) x ∂Bly (y) {Mx ⊗ Sy }i,j,k,l = Bix (x)Bkx (x) ∂y = Bix (x) ∂y Bk (x) ∂y is the Kronecker product of ∂y the one-dimensional mass matrix and the one-dimensional stiffness matrix. Each of these matrices can be factored in linear time using the alternating-directional solver algorithm. However, it is no longer possible to factorize their sum in linear time. This is possible only when we introduce a time step scheme that allows the matrix to be split into sub-matrices in time sub-steps so that the factorization cost remains linear. The Peaceman-Reachford scheme allows you to split the time step into two sub-steps Mx ⊗ My − dt 12 Sx ⊗ My ut+1/2 = F (t + 1/2) + dt 12 Mx ⊗ Sy ut Mx ⊗ My − dt 12 Mx ⊗ Sy ut+1 = F (t + 1/2) + dt 12 Sx ⊗ My ut+1/2
Open AGH e-podręczniki - content available under the CC BY-SA license
194
7.7. Alpha scheme where we can merge the left-hand side matrices into a single matrix with a Kronecker product structure that can be factored in linear time using the variable direction solver algorithm Mx − dt 12 Sx ⊗ My ut+1/2 = F (t + 1/2) + dt 12 Mx ⊗ Sy ut Mx ⊗ My − dt 12 Sy ut+1 = F (t + 1/2) + dt 12 Sx ⊗ My ut+1/2 Finally, let us take a look at what the right-hand side operator looks like. The right-hand side function here represents the changes caused by the force acting on the system during the time step, plus the changes caused by the physics of the phenomenon in the previous time step (ut+1 , w) − dt 12 (L(ut+1 ), w) = (ut , Bkx (x)Bly (y)) + dt(ft+1 , Bkx (x)Bly (y)) + dt 12 (L(ut ), Bkx (x)Bly (y)).
In particular, our right-hand side is not a bitmap, but a projection of the sum of three elements: P 1. The state of our system at the previous moment in time (ut , w) = i=1,...,Nx ;j=1,...,Ny uti,j (Bix (x)Bjy (y), Bkx (x)Bly (y)) multiplied by the test function and area integrated). Of course, we also use a linear combination of B-spline basis functions to represent the state of our system in the previous time step P u(x, y; t) = ut = i=1,...,Nx ;j=1,...,Ny uti,j Bix (x)Bjy (y). 2. Changes induced by the ”physics” of the simulated phenomenon during the time step. These changes are calculated by applying the differential operator representing the modeled phenomenon to the state of the system at the previous moment. The state of the system is of course represented by a linear combination of the B-spline function. So the differential operator is applied to the B-spline P y y t x x function (dt 12 L(ut ), w) = i=1,...,Nx ;j=1,...,Ny dt ∗ ui,j (L(Bi (x)Bj (y)), Bk (x)Bl (y)). For 2 P ∂ (Bix (x)Bjy (y)) example, for the problem of heat transport we have i=1,...,Nx ;j=1,...,Ny dt 12 uti,j ( + ∂x2 ∂ 2 (Bix (x)Bjy (y)) , Bkx (x)Bly (y)). Thanks to the weak formulation, we can integrate by parts ∂y 2 ∂(B x (x)B y (y)) P ∂(Bix (x)Bjy (y)) ∂(Bkx (x)Bly (y)) y ∂(Bkx (x)Bly (y)) y i j 1 t x x dt u ( B (y), B (y)) + (B (x) , B (x) ) i,j i j k i=1,...,Nx ;j=1,...,Ny l 2 ∂x ∂x ∂y ∂y
which due to the structure of the tensor product of the B-spline function, and due to the fact that the derivative in the y direction of the B-spline function of the variable x gives 0, and the derivative in the x direction of the variable yy gives, we get ofx the B-spline function P ∂Bj (y) ∂Bly (y) ∂Bi (x) y ∂Bkx (x) y 1 t x x dt u ( B (y), B (y)) + (B (x) , B (x) ) . From i j k i=1,...,Nx ;j=1,...,Ny l 2 i,j ∂x ∂x ∂y ∂y the ”matrix” point of view, this term gives us dt 12 (Sx ⊗ Mx + Mx ⊗ Sy )ut . 3. Changes caused by a force acting on the system during the time step (ft+1 , w) (ft+1 (x, y), Bkx (x)Bly (y)).
7.7.
=
Alpha scheme
In the implicit method called alpha schema, used to solve non-stationary problems, our differential operator describing the ”physics” of the simulated phenomenon is applied to the linear combination of the previous and next state values: ut+1 −ut dt
− L(αut + (1 − α)ut+1 )) = ft+1 .
If the differential operator is linear, then we can break it into two terms ut+1 − dtαL(ut+1 ) = ut + dtft+1 + dt(1 − α)L(ut ) leaving our ”unknown” on the left-hand side ut+1 . Note that for the value of alpha = 1, this scheme is an implicit Euler scheme (the so-called backward Euler), for the value of alpha = 0 it is an explicit scheme (the so-called Euler scheme) and for the value of alpha = 1/2 it is the Crank-Nicolson scheme (which is also implicit). The Euler scheme was first described in 1768 in a textbook by Leonhard Euler. The Crank-Nicolson diagram was invented in 1947 by Phyllis Nicolson, a female British mathematician, and John Crank, an Open AGH e-podręczniki - content available under the CC BY-SA license
195
7.7. Alpha scheme American mathematician and physicist [51], [52]. We use the isogeometric finite element method. To develop a solver that uses the method implicitly in the isogeometric finite element method, we need to transform a strong formulation into a weak formulation.So we multiply our equation by the test functions (ut+1 , w) − dtα(L(ut+1 ), w) = (ut , w) + dt(ft+1 , w) + dt(1 − α)(L(ut ), w). We will use a linear combination of the B-spline function to approximate the state of our system at a given moment in time. For this purpose, we select the basis of two-dimensional B-spline functions, defining the node vectors in the direction of the coordinate system axis. To establish attention, we can choose a two-dimensional basis of the second order B-spline function y x {Bi,2 (x)Bj,2 (y)}i=1,...,Nx ;j=1,...,Ny ui,j .
They will be used to approximate the simulated scalar field of the current time instant u(x, y; t + 1) ≈ P y t+1 x i=1,...,Nx ;j=1,...,Ny ui,j Bi (x)Bj (y) Similarly, for testing, we will use the B-spline base functions: w(x, y) ∈ {Bkx (x)Bly (y)}k=1,...,Nx ;l=1,...,Ny wk,l Assuming that the differential operator describing ”physics” is linear, our equation now looks like this: P y y y t+1 x x x i=1,...,Nx ;j=1,...,Ny ui,j (Bi (x)Bj (y) − dtαL(Bi (x)Bj (y)), Bk (x)Bl (y)) = RHS . ∀k = 1, ..., Nx ; l = 1, ..., Ny For example, for the problem of heat transport we have P ut+1 i,j i=1,...,Nx ;j=1,...,Ny ∂ 2 (Bix (x)Bjy (y)) ∂ 2 (Bix (x)Bjy (y)) y x (Bi (x)Bj (y) − dtα + , Bkx (x)Bly (y)) = RHS . ∂x2 ∂y 2 ∀k = 1, ..., Nx ; l = 1, ..., Ny Thanks to the weak formulation, we can integrate by parts P ut+1 i=1,...,Nx ;j=1,...,Ny i,j ∂(Bix (x)Bjy (y)) ∂(Bkx (x)Bly (y)) ∂(Bix (x)Bjy (y)) ∂(Bkx (x)Bly (y)) (Bix (x)Bjy (y), Bkx (x)Bly (y)) − dtα( , ) − dt ∗ ( , ) = RHS . ∂x ∂x ∂y ∂y ∀k = 1, ..., Nx ; l = 1, ..., Ny Due to the structure of the tensor product of the B-spline function and due to the fact that the derivative in the y direction of the B-spline in the x-axis direction gives 0 (because these functions are constant in the y-axis direction) and similarly for the derivative in the y-direction of the B-spline in the x-axis direction we have P ut+1 i=1,...,Nx ;j=1,...,Ny i,j ∂Bjy (y) ∂Bly (y) ∂Bix (x) y ∂Bkx (x) y (Bix (x)Bjy (y), Bkx (x)Bly (y)) − dtα( ∂x Bj (y), ∂x Bl (y)) − dt ∗ (Bix (x) ∂y , Bkx (x) ∂y ) = RHS . ∀k = 1, ..., Nx ; l = 1, ..., Ny Note that our system of equations to solve is (Mx ⊗ My − dtαSx ⊗ My − dt ∗ Mx ⊗ Sy ) ut+1 = F (t) where R R {Mx ⊗ My }i,j,k,l = Bix (x)Bkx (x)Bjy (y)Bly (y) = Bix (x)Bjy (y)Bkx (x)Bly (y) = Mi,j,k,l is a mass matrix which is a Kronecker product of two one-dimensional mass matrices, R ∂Bix (x) ∂Bkx (x) y R ∂Bix (x) y ∂Bkx (x) y y {Sx ⊗ My }i,j,k,l = ∂x ∂x Bj (y)Bl (y) = ∂x Bj (y) ∂x Bl (y) is the Kronecker product of the one-dimensional stiffness matrix and the one-dimensional mass matrix, and R R ∂Bjy (y) ∂Bly (y) ∂Bjy (y) x ∂Bly (y) {Mx ⊗ Sy }i,j,k,l = Bix (x)Bkx (x) ∂y = Bix (x) ∂y Bk (x) ∂y is the Kronecker product of ∂y the one-dimensional mass matrix and the one-dimensional stiffness matrix.
Open AGH e-podręczniki - content available under the CC BY-SA license
196
7.8. Example of the non-stationary linear problem: propagation of pollution Each of these matrices can be factored in linear time using the variable-directional solver algorithm. However, it is no longer possible to factorize their sum in linear time. This is possible only when we introduce a time step scheme that allows the matrix to be split into sub-matrices in time sub-steps so that the factorization cost remains linear. The Peaceman-Reachford scheme allows you to split the time step into two sub-steps (Mx ⊗ My − dtαSx ⊗ My ) ut+1/2 = F (t + 1/2) + (dt(1 − α)Mx ⊗ Sy ) ut (Mx ⊗ My − dtαMx ⊗ Sy ) ut+1 = F (t + 1/2) + (dt(1 − α)Sx ⊗ My ) ut+1/2 where we can merge the left-hand side matrices into a single matrix with a Kronecker product structure that can be factored in linear time using the variable direction solver algorithm (Mx − dtαSx ) ⊗ My ut+1/2 = F (t + 1/2) + (dt(1 − α)Mx ⊗ Sy ) ut Mx ⊗ (My − dtαSy ) ut+1 = F (t + 1/2) + (dt(1 − α)Sx ⊗ My ) ut+1/2 . Finally, let us take a look at what the right-hand side operator looks like. The right-hand side function here represents the changes caused by the force acting on the system during the time step, plus the changes caused by the physics of the phenomenon in the previous time step (ut+1 , w) − dt(1 − α)(L(ut+1 ), w) = (ut , Bkx (x)Bly (y)) + dt(ft+1 , Bkx (x)Bly (y)) + dt(1 − α)(L(ut ), Bkx (x)Bly (y)) In particular, our right side is not a bitmap, but a projection of the sum of three elements: P 1. The state of our system in previous time step (ut , w) = i=1,...,Nx ;j=1,...,Ny uti,j (Bix (x)Bjy (y), Bkx (x)Bly (y))(also multiplied by the test functions and integrated over the domain). Of course, we also use a linear combination of B-spline basis functions to represent the state of our system in the previous time step P u(x, y; t) = ut = i=1,...,Nx ;j=1,...,Ny uti,j Bix (x)Bjy (y). 2. Changes induced by the ”physics” of the simulated phenomenon during the time step. These changes are calculated by applying the differential operator representing the modeled phenomenon to the state of the system at the previous moment. The state of the system is of course represented by a linear combination of the B-spline function. So the differential operator is applied to the B-spline function (dt(1 − α)L(ut ), w) = P y y t x x i=1,...,Nx ;j=1,...,Ny dt ∗ ui,j (L(Bi (x)Bj (y)), Bk (x)Bl (y)). For example, for the problem of heat 2 P ∂ (Bix (x)Bjy (y)) ∂ 2 (Bix (x)Bjy (y)) transport we have i=1,...,Nx ;j=1,...,Ny dt(1 − α)uti,j ( + , Bkx (x)Bly (y)). 2 ∂x ∂y 2 P Thanks to the weak formulation, we can integrate by parts i=1,...,Nx ;j=1,...,Ny dt(1 − ∂(B x (x)B y (y)) ∂(Bix (x)Bjy (y)) ∂(Bkx (x)Bly (y)) y ∂(Bkx (x)Bly (y)) i j α)uti,j ( Bjy (y), Bl (y)) + (Bix (x) , Bkx (x) ) ∂x ∂x ∂y ∂y which due to the structure of the tensor product of the B-spline function, and due to the fact that the derivative in the y direction of the B-spline function of the variable x gives 0, and the derivative in the x direction of the B-spline function of the variable y gives, we get P ∂Bjy (y) ∂Bly (y) ∂Bix (x) y ∂Bkx (x) y t x x dt(1 − α)u ( B (y), B (y)) + (B (x) , B (x) ) . i,j i j k i=1,...,Nx ;j=1,...,Ny l ∂x ∂x ∂y ∂y From the ”matrix” point of view, this term gives us dt(1 − α)(Sx ⊗ Mx + Mx ⊗ Sy )ut . 3. Changes caused by a force acting on the system during the time step (ft+1 , w) (ft+1 (x, y), Bkx (x)Bly (y)).
7.8.
=
Example of the non-stationary linear problem: propagation of pollution
An example of a linear non-stationary problem is the problem of a pollutant propagation simulation [53]. In this problem we calculate the scalar field of pollution concentration
Open AGH e-podręczniki - content available under the CC BY-SA license
197
7.8. Example of the non-stationary linear problem: propagation of pollution R3 3 (x, y, z) × [0, T ] → c(x, y, z; t) ∈ R such as ∂c ∂t
+ u · ∇c − ∇ · (K∇c) = e
which, after rewriting, gives us ∂c ∂t
∂c ∂c ∂c + ux ∂x + uy ∂y + uz ∂z −
∂ ∂x
∂c Kx ∂x −
In the formula above, the first term
∂c ∂t
∂ ∂y
∂c Ky ∂y −
∂ ∂z
∂c Kz ∂z
represents changes in the field of pollution concentration over time,
the second term ∂c ∂c ∂c ux ∂x + uy ∂y + uz ∂z is a term of advection (also called convection) which means transport of pollutants by the wind, represented by a given vector field R3 3 (x, y, z) × [0, T ] → ∂ ∂ ∂c ∂c ∂ ∂c (ux (x, y, z; t, , uy (x, y, z; t); uz (x, y, z; t))) ∈ R3 , the third segment − ∂x Kx ∂x − ∂y Ky ∂y − ∂z Kz ∂z means diffusion, i.e. spontaneous transport of pollutant particles on the principle of diffusion. All terms of the differential operator describing the contamination propagation process are linear, that is L(c1 + c2 ) = L(c1 ) + L(c2 ). Thanks to this, we can build a system of linear equations and apply the solvers and algorithms described in the textbook.
The right-hand side indicates the emission sources, and it is positive where there is a pollution source (for example a chimney). Diffusion coefficients (Kx , Ky , Kz ) are the diffusion velocity in the x, y and z directions. In order to solve the advection-diffusion problem, we still need to determine what is happening on the boundary of the area. For example, we can assume the speed of the influx of pollutants at the edge of the area ∂c ∂x nx
∂c ∂c + ∂y ny + ∂z nz = g where (nx , ny , nz ) is the unit vector orthogonal to the edge. We also need to provide an initial condition (initial pollutant concentration)
c(x, 0) = 0. Finally, we present two exemplary simulations, the first one showing the influx of pollutants from the west to the Krakowska Valley for the area obtained by generating a tetrahedral mesh based on topographic data from the NASA database, and the second one showing the dispersion of smoke from the chimney through the wind of variable direction. They were counted with the codes described in the bibliographic articles [47].
Open AGH e-podręczniki - content available under the CC BY-SA license
198
7.8. Example of the non-stationary linear problem: propagation of pollution
https://vimeo.com/370070786 Pollution
Open AGH e-podręczniki - content available under the CC BY-SA license
199
7.9. MATLAB implementation of the alpha scheme for the heat transfer problem
https://vimeo.com/370070721 Chimney
7.9.
MATLAB implementation of the alpha scheme for the heat transfer problem
Below you can find a link to the MATLAB code performing simulations for the alpha scheme for the two-dimensional heat transport problem. In line 621 we enter the time step size dt = 0.01, in line 622 we enter the parameter alpha = 0.5, where alpha=0 means explicit Euler, alpha=1 implicit Euler, and alpha=0.5 means Cranck-Nicolson scheme. In line 623 we specify the time steps number K = 20; The code execution is also possible in the free Octave environment. Download code or see Appendix 7.
Open AGH e-podręczniki - content available under the CC BY-SA license
200
7.10. Example of the non-stationary non-linear problem: non-linear flow in heterogeneous media The code is activated by opening it in Octave and typing a command heat_time During operation, the code prints successive time steps Iter 1, t = 0.010000 Iter 2, t = 0.020000 Iter 3, t = 0.030000 ... The code generates a file at any time in the current directory out_*.png, e.g. out_0.png out_1.png out_2.png ... containing solutions from individual time steps.
7.10.
Example of the non-stationary non-linear problem: non-linear flow in heterogeneous media
An example of a non-stationary problem described in this module is the non-linear flow problem in a non-uniform medium [54].
EXAMPLE
Example 18: The problem of non-stationary non-linear flow in a heterogeneous medium In this problem, we are looking for a scalar pressure field R3 3 (x, y, z) × [0, T ] → u(x, y, z; t) ∈ R in a heterogeneous area. This problem is related to the issue of oil extraction. We assume that the area in which we model our flow consists of heterogeneous material representing oil deposits located in the crevices of geological layers. We assume that boreholes were made in which a pump pumping liquid under high pressure was placed, the purpose of which is to pump out the oil reservoir, in particular towards suction pumps located in separate wells. Equation modeling pressure changes due to pump operation ∂u ∂t
− ∇ · (κ exp(µu) ∇u) = f
which after rewritting ∂u(x,y,z;t) ∂t
+
∂ ∂y
κ(x, y, z) exp(µ(x, y, z)u(x, y, z; t)) ∂u(x,y,z;t) ∂x ∂u(x,y,z;t) κ(x, y, z; u(x, y, z; t)) exp(µu(x, y, z; t)) = f (x, y, z; t) ∂y −
∂ ∂x
+
In the equation above, the function κ(x, y, z) determines the permeability of the area. This function is shown in Pic. 54. The value range varies from 0 to 1000. Value 0 means no permeability, value 1000
Open AGH e-podręczniki - content available under the CC BY-SA license
201
7.10. Example of the non-stationary non-linear problem: non-linear flow in heterogeneous media means very high permeability (e.g. a crude oil fracture in a rock).
Figure 54: Map of the value of the medium permeability function.
Factor µ = 1000 is a geological model parameter. Note that the nonlinear flow equation is very similar to the heat transport equation. The only difference is the non-linear coefficient κ(x, y, z) exp(µ(x, y, z)u(x, y, z; t) which means that the rate of pressure changes in a given area changes proportionally to the permeability coefficient and to the current pressure value, and it happens in a non-linear manner, determined by the exponential function. This coefficient is the cause of the non-linearity of our equation. If this term was left on the left-hand side of the equation, then this equation would require linearization, for example, using the Newton-Raphson algorithm. In the case of nonlinear problems, however, it is possible to use the explicit method which gives the possibility to shift the non-linear term to the right-hand side of the equation. We approximate the derivative over time using the finite difference method ut+1 − ut − dt ∗ ∇ · (κ exp(µu) ∇u) = dt ∗ f The right-hand side function models the pumping and suction pumps P P f (x, t) = p∈P φ (kxp − xk) − s∈S u(x, t)φ (kxs − xk) P Where p∈P φ (kxp − xk) are pumping pumps (providing non-zero pressure) and P − s∈S φ (kxp − xk) are suction pumps (”delivering” negative pressure). The sum goes over all positions of the P pumping and S suction pumps in our modeled system. The pressure applied by the pump drops with the distance from the center of the pump according to the formula also illustrated in Pic. 55 t − 12 t + 12 for t ≤ r r r φ(t) = . 0 for t > r
Open AGH e-podręczniki - content available under the CC BY-SA license
202
7.10. Example of the non-stationary non-linear problem: non-linear flow in heterogeneous media
Figure 55: Pressure variation function with distance from the center of the pump position.
In order to simulate using the isogeometric finite element method, we introduce discretization using the B-spline basis functions y x z {Bi,2 (x)Bj,2 (y)Bk,2 (z)}i=1,...,Nx ;j=1,...,Ny ;k=1,...,Nz
They will be used to approximate the simulated scalar pressure field to the current time instant P y x z u(x, y, z; t + 1) ≈ i=1,...,Nx ;j=1,...,Ny ;k=1,...,Nz ut+1 i,j,k Bi (x)Bj (y)Bk (z) Similarly, for testing, we will use the B-spline basis functions: y {Blx (x)Bm (y)Bnz (z)}l=1,...,Nx ;m=1,...,Ny ;n=1,...,Nz
Our equation is multiplied by the test function and integrated over the area of the three-dimensional simulation (we mark the integration with a parenthesis representing the dot product in the L2 space) (ut+1 , w) = (ut , w) − dt(∇ · (κ exp(µu) ∇u), w) + dt(f, w) We can isolate the term on the right-hand side through the parts, assuming that our area is so large that the pressure changes on the edge are zero (then the marginal integral resulting from integration by parts will disappear) (ut+1 , w) = (ut , w) + dt(κ exp(µu) ∇u, ∇w) + dt(f, w). As in the general case of the explicit method, on the left-hand side we now have a mass matrix that can be factored in a linear time, and on the right-hand side we have our ”bitmap” which describes the state at the previous moment plus changes during the time step dt resulting from the physics of nonlinear flow in a heterogeneous medium and modification of pressure fields in the vicinity of pumping and suction pumps. Examples of simulations, the first one in which there is a pumping pump in the center of the bed area that fills the entire area with liquid under pressure, and the second simulation in which three suction pumps suck off the liquid with oil previously pumped into the bed, are shown in the films. They were numbered with the code described in the articles of the bibliography described in item [47]. The locations of the pumps and sucks can be determined by using the evolutionary algorithm, tuned to maximize the extraction and minimize the contamination of groundwaters [54]. Open AGH e-podręczniki - content available under the CC BY-SA license
203
7.10. Example of the non-stationary non-linear problem: non-linear flow in heterogeneous media
https://vimeo.com/370080742 Pumping into the deposit
Open AGH e-podręczniki - content available under the CC BY-SA license
204
7.10. Example of the non-stationary non-linear problem: non-linear flow in heterogeneous media
https://vimeo.com/370070766 Deposit suction
Open AGH e-podręczniki - content available under the CC BY-SA license
205
7.10. Example of the non-stationary non-linear problem: non-linear flow in heterogeneous media
Open AGH e-podręczniki - content available under the CC BY-SA license
206
Chapter 8
8. Mathematical foundations of the finite element method 8.1.
Functional spaces DEFINITION
Definition 1: Functional spaces over a one-dimensional area For Ω = (xl , xr ) ⊂ R L2 (Ω) = {v : Ω → R :
v(x)2 dx < ∞} R along with the norm kuk2L2 (Ω) = Ω u(x)2 dx R and the dot product (u, v) L2 (Ω) = Ω u(x)v(x)dx R 2 H 1 (Ω) = {v : Ω → R : Ω v(x)2 + dv(x) dx < ∞} dx R
Ω
where the derivative dv(x) understood in a weak sense, that is, we define it in dx it is R R terms of integration by parts Ω u dv(x) = − Ω du(x) dx dx dx vdx for all ”smooth” functions R 2 dv(x) u ∈ C0∞ (Ω) = {v : Ω → R : Ω v(x)2 + dx dx < ∞} infinitely many differentiable times defined on closed prefixes (a, b) ⊂ Ω. R 2 In space H 1 (Ω) we define the norm kuk2H 1 (Ω) = Ω u(x)2 + du(x) dx and scalar product (u, v)H 1 (Ω) = dx R du(x) dv(x) u(x)v(x) + dx dx dx Ω R 2 H01 (Ω) = {v : Ω → R : Ω v(x)2 + dv(x) dx < ∞; v(0) = 0} dx R 2 Along with the norm kuk2H 1 (Ω) = Ω du(x) dx dx 0 R dv(x) and the dot product (u, v) H01 (Ω) = Ω du(x) dx dx dx
DEFINITION
Definition 2: Functional spaces on a two-dimensional area
207
8.2. One-dimensional finite element For Ω ⊂ R2 L2 (Ω) = {v : Ω → R :
R
v(x1 , x2 )2 dx1 dx2 < ∞} R along with the norm kuk2L2 (Ω) = Ω v(x1 , x2 )2 dx1 dx2 R and the dot product (u, v)L2 (Ω) = Ω u(x1 , x2 )v(x1 , x2 )dx1 dx2 H 1 (Ω) = {v : Ω → R :
R
Ω
Ω
(v(x1 , x2 )2 +
dv(x1 ,x2 ) 2 dx1
+
dv(x1 ,x2 ) 2 )dx1 dx2 dx2
< ∞} where derivatives
dv(x1 ,x2 ) ,i dxi
= 1, 2 we understand in a weak sense R R 1 ,x2 ) 1 ,x2 ) u(x1 , x2 ) dv(x dx1 dx2 = − Ω du(x v(x1 , x2 )dx1 dx2 . In other words, they are defined by dxi dxi Ω integration over parts with smooth functions u ∈ C0∞ (Ω) infinitely many times differentiable defined over a compact area contained in Ω. In space R 2 du(x1 ,x2 ) 2 1 ,x2 ) H 1 (Ω) we define the norm kuk2H 1 (Ω) = Ω u(x1 , x2 )2 + du(x + dx1 dx2 dx1 dx2 R du(x1 ,x2 ) dv(x1 ,x2 ) 1 ,x2 ) dv(x1 ,x2 ) and the dot product (u, v)H 1 (Ω) = Ω u(x1 , x2 )v(x1 , x2 ) + du(x + dx1 dx2 . dx1 dx1 dx2 dx2 2
2
1 ,x2 ) 1 ,x2 ) (v(x1 , x2 )2 + dv(x + dv(x )dx1 dx2 < ∞, trv(x1 , x2 ) = 0} dx1 dx2 R 2 2 1 ,x2 ) 1 ,x2 ) along with the norm kuk2H 1 (Ω) = Ω du(x + du(x dx1 dx2 dx1 dx2 0 R du(x1 ,x2 ) dv(x1 ,x2 ) 1 ,x2 ) dv(x1 ,x2 ) and the dot product (u, v) H01 (Ω) = Ω du(x + dx1 dx2 dx1 dx1 dx2 dx2
H01 (Ω) = {v : Ω → R :
R
Ω
where the trace operator means determining the value of the function on the boundary, which in the case of functions that are elements of the Sobolev space requires introducing classes of equivalence of functions equal to the integral value.
8.2.
One-dimensional finite element
In this chapter, we provide strict mathematical definitions related to the classical finite element method. In particular, finite element definitions were given by Ciarlet in 1978, and in the context of the adaptive finite element method by Demkowicz in 2007 [55], [56]. Both of these definitions are provided below. Ciarlet’s definition uses the concept of degrees of freedom, while Demkowicz’s definition uses the concept of the shape function and projection-based interpolation operator. We will then show the relationship between these two definitions that show that they are equivalent. First, we define a finite element in one dimension, for a reference (often also called a standard) ˆ = [0, 1] ⊂ R, and then we will generalize this definition to any finite element defined on the interval K element defined in any interval K = [xl , xr ] ⊂ R. DEFINITION
Definition 3: One-dimensional reference finite element (based on Demkowicz 2007) We call a one-dimensional reference finite element ˆ X K ˆ , Πp K, defined by the following four steps ˆ = [0, 1] ⊂ R 1. Geometry:K
Open AGH e-podręczniki - content available under the CC BY-SA license
208
8.2. One-dimensional finite element 2. Selection of nodes:ˆ a1 , a ˆ2 nodes associated with vertices 0 and 1 of the element, and a ˆ3 node associated with the interior (0,1) of the element 3. Definition of element shape function ˆ = span{χ ˆ , j = 1, ..., p + 1} where P p K ˆ are degree polynomials p specified on X K ˆj ∈ P p K ˆ = (0, 1) and χ the interval K ˆ1 (ξ) = 1−ξ, χ ˆ2 (ξ) = ξ, χ ˆ3 (ξ) = (1−ξ)ξ, χ ˆl (ξ) = (1−ξ)ξ(2ξ−1)l−3 l = 4, ..., p + 1. ˆ → X K ˆ . For a given 1. Definition of the projection-based interpolation operator Πp : H 1 K ˆ , its projection based interpolant is Πp u ∈ X K ˆ is defined by the function u ∈ H 1 K following conditions: Πp u(ˆ a1 ) = u(ˆ a1 ) Πp u(ˆ a2 ) = u(ˆ a2 ) kΠp u − ukH01 (0,1) → min where kΠp u − ukH01 (0,1) =
R1 0
0
(Πp u) − u0
2
dξ this is the norm in the Sobolev space H01 (0, 1).
ˆ so that The minimization problem: find Πp u ∈ X K Πp u(0) = u(0) Πp u(1) = u(1) kΠp u − ukH01 (ˆa3 ) → min ˆ so that is equivalent to the problem: find Πp u ∈ X K Πp u(0) = u(0) Πp u(1) = u(1) R1 0 (Πp u) − u0 v 0 dξ = 0 0
ˆ ∀v ∈ X K
which of the following is equivalent to the problem of solving the system of equations: p 1 0 0 ··· 0 u1 u(0) 0 up u(1) 1 0 ··· 0 2 a31 a32 a33 ··· a3,p+1 up3 = b3 .. .. .. .. .. .. . . . . . . ap+1,1 ap+1,2 ap+1,3 · · · ap+1,p+1 upp+1 bp+1 P p where Πp u = i=1,...,p+1 ui χi is a linear combination of basis functions, R1 0 0 aij = 0 χ ˆi χ ˆj dξ R1 0 0 bj = 0 u χ ˆj dξ DEFINITION
Definition 4: One-dimensional reference finite element (based on Ciarlet 1978) We call a one-dimensional reference finite element
Open AGH e-podręczniki - content available under the CC BY-SA license
209
8.2. One-dimensional finite element
ˆ V∗ K ˆ ,X K ˆ K,
defined by the following four steps ˆ = (0, 1) ∈ R 1. Geometry:K 2. Selection of nodes:ˆ a1 , a ˆ2 nodes associated with the nodes 0 and 1 of the element, and a ˆ3 node associated with the interior (0,1) of the element ˆ 3. The definition of the space of degrees of freedom V ∗ K = span{ψi }i=1,...,p+1 as a dual ˆ . We associate the degrees of freedom with the element nodes and with the space to V K ˆ 3 f → f (ˆ ˆ 3 f → f (ˆ interior of the element ψ1 : V K a1 ) ∈ R, ψ2 : V K a2 ) ∈ R, R ˆ 3f →3 ψ3 : V K f 0 (ξ)(1 − 2ξ)dξ ∈ R. It is possible to extend this definition to further a ˆ3 degrees of freedom (here we give a definition for p = 2. ˆ ⊂ V K ˆ . The approximation space is spanned 4. Construction of an approximation space X K by the base of polynomials being a dual base to the base of the degrees of freedom ψi (χj ) = δij
PROPERTY
Property 3: Relationship between shape functions and degrees of freedom Let χj , j = 1, 2, ..., p + 1 denote shape functions according to definition 1, while ψi , i = 1, 2, ..., p + 1 for p = 2 means degrees of freedom according to definition 2, then ψi (χj ) = δij
PROPERTY
Property 4: The relationship between the projection-based interpolation operator and the shape functions Let ˆ be an interpolation operator according to Definition 1. Πp : H 1 (0, 1) → P p K Let χj , j = 1, 2, ..., p + 1 stand for shape functions as defined in definition 1. Then, there is a unique set of linear and continuous functionals ψj : H 1 (0, 1) → P p (0, 1) such that P Πp u = j=1,...,p+1 ψj (u) χj
DEFINITION
Definition 5: One-dimensional finite element (definition by shape Open AGH e-podręczniki - content available under the CC BY-SA license
210
8.3. The one-dimensional strong and weak formulation for the elliptic problem
functions and projection-based interpolation operator) We call a three-dimensional finite element (K, X (K) , Πp ) defined by the following four steps 1. Geometry:K = [xl , xr ] ⊂ R, xl , xr ∈ R 2. Selection of nodes:a1 , a2 nodes associated with vertices xl , xr of the element, and a3 knot associated with the interior K = [xl , xr ]R of the element ˆ } where xK : 3. Definition of the shape function of an element X (K) = {χ = χ ˆ · x−1 , χ ˆ ∈ X K K ˆ → K is the mapping from the pattern element K = [0, 1] on the element K = [xl , xr ] data K ˆ 3 ξ → xK (ξ) = xl + (xr − xl ) = x ∈ K K ˆ ˆ defined 4. Definition of the projection-based interpolation operator Πp : H 1 K → X K analogously to Definition 1. Reference elements are used to integrate the weak formulations. The reference elements are regular in shape. The reference element is mapped to the given element, and its geometry is described by the map mapping from the reference element to the given element. In the Jacobian integrals of this mapping, it represents the scaling of the area (volume) of the reference element for the given element.
PROPERTY
Property 5: Independence of the projection-based interpolation operator from the finite element Note that the definition of the projection-based interpolation operator is identical for all finite elements, because it was defined on the reference element.
8.3.
The one-dimensional strong and weak formulation for the elliptic problem DEFINITION
Definition 6: Strong formulation for one dimensional elliptical problem For area Ω = (0, l) ⊂ R we are looking for a scalar field Omega nix rightarrowu(x) in calR which 0 is a smooth function u ∈ C 0 such that − (a(x)u0 (x)) + b(x)u0 (x) + c(x)u(x) = f (x) dla x ∈ (0, l) along with the Dirichlet boundary condition u(0) = u0 and Robin’s boundary condition a(l)u0 (l) + βl u(l) = γl where u0 , βl , γl ∈ R, Ω 3 x → a(x), b(x), c(x), f (x) ∈ R are given functions a ∈ C 1 , b, c, f ∈ C 0 .
Open AGH e-podręczniki - content available under the CC BY-SA license
211
8.4. One-dimensional finite element method
DEFINITION
Definition 7: Extending the Dirichlet boundary condition for a one-dimensional elliptical problem Introduce the function u ˜(x) = (1 − xl )u0 such as u ˜(0) = u0 .
DEFINITION
Definition 8: Weak formulation for a one-dimensional elliptical problem For the area Omega = (0, l) subset calR for which the boundary is divided into a fragment of the Dirichlet boundary in x = 0 and a fragment of the Robin boundary in x = l, we are looking for a scalar field u ∈ V such That B(u, v) = L(v) − B(ˆ u, v) ∀v ∈ V where Rl 0 0 0 B(u, v) = 0 (a(x)u (x)v (x) + b(x)u (x)v(x) + c(x)u(x)v(x)) dx + βu(l)v(l) and Rl L(v) = 0 f (x)v(x)dx + γv(l) and u ˜ is an extension of the Dirichlet boundary condition over 1 the entire area, and V = {u ∈ H (Ω) : u(0) = 0}. We multiply the strong formulation by functions from the testing space and integrate Rl Rl 0 − 0 (a(x)u0 (x)) + b(x)u0 (x) + c(x)u(x) v(x)dx = 0 f (x)v(x)dx ∀v ∈ V = {u ∈ H 1 (Ω) : u(0) = 0} We integrate the first term through parts Rl Rl Rl a(x)u0 (x)v 0 (x)dx − a(0)u0 (0)v(0) − a(l)u0 (l)v(l) + 0 b(x)u0 (x)v(x)dx + 0 c(x)u(x)v(x)dx = 0R l = 0 f (x)v(x)dx ∀v ∈ L2 (0, l) We use the fact that v inV or v(0) = 0, and substitute the boundary condition a(l)u0 (l) + betal u(l) = gammal . Rl We mark B(u, v) = 0 (a(x)u0 (x)v 0 (x) + b(x)u0 (x)v(x) + c(x)u(x)v(x)) dx + βu(l)v(l) and L(v) = Rl f (x)v(x)dx + γv(l). 0 We substitute w = u − u ˜ to get w(0) = 0 and B(w, v) = L(v) − B(˜ u, v). For simplicity of notation instead of a symbol w we use once again the symbol u.
8.4.
One-dimensional finite element method DEFINITION
Definition 9: One-dimensional computational mesh A computational mesh is a family Thp of finite elements Thp = {(K, X (K) , Πp )}K such that ∪K∈Thp = Ω, measKi ∩ Kj = Ki for i = j; 0 for i 6= j.
Open AGH e-podręczniki - content available under the CC BY-SA license
212
8.4. One-dimensional finite element method
DEFINITION
Definition 10: One-dimensional reference mesh For a given computational mesh {Thp = (K, X (K) , Πp )}K a reference mesh is a family T h p+1 of 2 finite elements T h p+1 = {(K, X (K) , Πp )}K such that 2
∀K ∈ T h p+1 ∃K1 , K2 ∈ P(Thp , K) such that 2
K = K1 ∪ K2 , measK1 ∩ K2 = 0, X(K1 ), X(K2 ) ∈ P(Thp , X(K)), dimX(K) = dimX(K1 ) + 1 = dimX(K2 ) + 1 where P(Thp , K) and P(Thp , X(K)) denotes projections onto the first and the second component (K, X (K) , Πp ).
DEFINITION
Definition 11: Approximation space over one-dimensional computational mesh Approximation space over a one-dimensional computational mesh Thp = {(K, X (K) , Πp )}K is defined as Vhp = {v ∈ C(Ω) : ∀K ∈ P(Thp , K) : P(v, K) ∈ X(K)} where P(Thp , K) is a set of intervals representing the geometry of elements drawn from a triplet representing a one-dimensional computational mesh, P(v, K) is the projection of a function onto a compartment representing the geometry of an element.
DEFINITION
Definition 12: Mappings that define the assembly of local shape functions into global base functions over a computational mesh Let Thp = {(K, X (K) , Πp )}K denote one-dimensional computational mesh. hp Let {ehp i }i denote the basis Vhp = span{ei }.
Let χK k ∈ X (K) denote the shape functions over element K. K Then ∀K ∈ P(Thp , K), ∀i, ∃k : P(ehp i , K) = χk .
there exists an inverse operator I 2 3 (k, K) → i(k, K) ∈ I that rewrites i(k, K) the index of i-th global basis function related to k-th local shape function over an element K. In the cases considered in this manual, this mapping is isomorphic.
Open AGH e-podręczniki - content available under the CC BY-SA license
213
8.4. One-dimensional finite element method
DEFINITION
Definition 13: Approximation space over one-dimensional reference mesh Approximation space over one-dimensional reference mesh T h p+1 = {(K, X (K) , Πp )}K is defined as 2
V h p+1 = {v ∈ C(Ω) : ∀K ∈ P(T h p+1 , K) : P(v, K) ∈ X(K)} 2
2
where P(T h p+1 , K) is a set of intervals representing the geometry of elements drawn from a triple 2 representing a one-dimensional computational mesh, P(v, K) is the projection of a function onto a compartment representing the geometry of an element.
DEFINITION
Definition 14: Mappings that define the assembly of local shape functions into global base functions over a reference mesh Let T h p+1 = {(K, X (K) , Πp )}K denote one-dimensional reference mesh. 2
h
Let {ei2
p+1
h
}i denote the basis of space V h p+1 = span{ei2
p+1
2
}.
Let χK k ∈ X (K) denote shape functions over an element K. h
Then ∀K ∈ P(T h p+1 , K), ∀i, ∃k : P(ei2 2
p+1
, K) = χK k .
There exists and inverse operator I 2 3 (k, K) → i(k, K) ∈ I that assigns i(k, K) the index of global i-th basis functions related to k-th local shape function over an element K. In the cases considered in this manual, this mapping is isomorphic. The reference mesh is used to estimate the relative error on the computational mesh. Often, when a computational mesh is described in the context of a reference mesh, it is called a coarse mesh, and the reference mesh is called a fine mesh, because it is created by breaking elements of the coarse mesh into smaller elements and increasing the degree of polynomial approximation by one. DEFINITION
Definition 15: Finite element method problem over one-dimensional mesh For a given computational mesh Thp = {(K, X (K) , Πp )}K find coefficients {uhp i }i=1,...,N hp of an P P hp hp hp hp approximate solution V ⊃ Vhp 3 uhp = i=1,...,N hp ui ei such that i=m,...,N hp uhp m B(em , en ) = L(ehp N hp where n ), n = 1, ..., Rl dehp (x) dehp dehp hp hp hp hp hp n (x) m (x) hp B(em , en ) = 0 a(x) mdx + b(x) e (x) + c(x)e (x)e (x) dx + βehp n m n m (l)en (l) and dx dx Rl hp hp hp L(ehp n ) = 0 f (x)en (x)dx+γen (l). The basis {ei }i=1,...,N hp of approximation space Vhp is obtained by merging (glueing together) shape functions from space X (K) = P(Thp , X(K)) for particular finite elements from the computational mesh Thp into the global basis functions.
Open AGH e-podręczniki - content available under the CC BY-SA license
214
8.4. One-dimensional finite element method
DEFINITION
Definition 16: Finite element method problem over one-dimensional reference mesh h
p+1
For a given computational mesh T h p+1 = {(K, X (K) , Πp )}K find coefficients {ui2 } h 2 i=1,...,n 2 p+1 h h P p+1 2 p+1 of an approximate solution V ⊃ V h p+1 3 u h p+1 = u2 ei such that h 2 2 i=1,...,N 2 p+1 i h h h h h h P p+1 p+1 p+1 2 p+1 2 p+1 2 p+1 um B(em , en2 ) = L(en2 ), n = 1, ..., N hp where B(em , en2 ) = h m=1,...,N 2 p+1 h p+1 h p+1 h p+1 h h h Rl 2 2 2 p+1 p+1 2 p+1 a(x) dem dx (x) den dx (x) + b(x) dem dx (x) en2 (x) + c(x)em (x)en2 (x) dx+ 0 h h h h Rl p+1 p+1 2 p+1 2 p+1 +βem (l)ehp ) = 0 f (x)en2 (x)dx + γen2 (l). n (l) and L(en h
p+1
The basis {ei2 } of an approximation space Vhp is obtained by merging (glueing h i=1,...,N 2 p+1 together) shape functions from space X (K) = P(T h p+1 , X(K)) for particular elements from the 2 computational mesh T h p+1 into the global basis functions. 2
ANNOTATION
Annotation 1: Solution of finite element method problem over one-dimensional mesh Coefficients {uhp i }i=1,...,N hp are calculated by solving a system of equations Au = b where hp B(ehp ··· 1 , e1 ) .. A= . ··· hp B(ehp , e ) ··· 1 N hp hp u1 . u = .. . hp uN hp L(ehp 1 ) .. . b= . hp L(eN hp )
hp B(ehp , e ) hp 1 N .. . . hp B(ehp , e ) N hp N hp
The Dirichlet boundary condition is obtained by resetting the rows corresponding to the basis functions defined on the Dirichlet boundary, placing the one on the diagonal, and resetting the right-hand side. The effect of the boundary condition on our system of equations was transferred to the right-hand side by the shift operation. hp hp Integrals B(ehp m , en ) and L(en ) are calculated element by element by using Gaussian quadratures. hp k hp k hp k P hp k dem (x ) den (x ) k dem (x ) hp k k hp k hp k B(ehp , e ) = a(x ) + b(x ) e (x ) + c(x )e (x )e (x ) Jac(xk )wk + m n n m n k dx dx dx hp hp + βehp m (l)en (l) and L(en ) =
P
k
k k k hp f (xk )ehp n (x )Jac(x )w + γen (l)
Open AGH e-podręczniki - content available under the CC BY-SA license
215
8.4. One-dimensional finite element method where Jac(xk ) is the value at the Gaussian quadrature point of the Jacobian mapping from the master element to the element. Generation of the system of equations for a given computational mesh Thp = {(K, X (K) , Πp )}K can be obtained by using the following algorithm: 1 for K ∈ P(Thp , K) (loop through finite element mesh) 2 for ψk ∈ X(K)(loop through shape functions from element K) 3 b(i(k, K))+ = L(ψk )(calculation of K element contribution to the integral) 4 for ψl ∈ X(K)(loop through shape functions from element K) 5 A(i(k, K), i(l, K))+ = B(ψk , ψl )(calcuiation of K element contribution to the integral).
ANNOTATION
Annotation 2: Solution of finite element method problem over one-dimensional reference mesh h
Coefficients {ui2
h
B(e12
p+1
p+1
}
h
i=1,...,n 2 p+1
h
, e12
p+1
h
···
)
N
h
h
p+1
k
h
, en2
a(xk )
h p+1 2
, e12
p+1
)
.. .
. h h p+1 p+1 B(e 2 h p+1 , e 2 h p+1 ) N
N
2
2
2
p+1
2 Integrals B(em quadratures. 2 B(em P
h
p+1
B(e 2
.. A= . ··· h h 2 p+1 2 p+1 B(e1 , e h p+1 ) · · · N2 h p+1 u2 1. u = .. . h p+1 u 2 h p+1 N2 h p+1 L(e12 ) .. b= . . h 2 p+1 L(e h p+1 ) N
are calculated by solving a system of equations Au = b
p+1
h
p+1
, en2
) and L(ehp n ) are computed element by element using the Gaussian
)=
h p+1 2 dem (xk )
dx h 2 p+1
Jac(xk )wk + βem
h p+1
den2
(xk )
dx h 2 p+1
(l)en
h p+1 2
k
h
+ b(xk ) dem dx (x ) en2 h
(l) and L(en2
p+1
)=
P
p+1
h
h
k
p+1
2 (xk ) + c(xk )em
f (xk )en2
p+1
h
(xk )en2
p+1
(xk ) ∗ h
(xk )Jac(xk )wk + γen2
p+1
(l)
where Jac(xk ) is the value at the Gaussian quadrature point of the Jacobian mapping from the master element to the element. Generation of the system of equations for a given computational mesh T h p+1 = {(K, X (K) , Πp )}K 2
can be obtained by using the following algorithm: 1 for K ∈ P(T h p+1 , K) (loop through elements of the computational meshj) 2
2 for ψk ∈ X(K)(loop through shape functions of element K)
Open AGH e-podręczniki - content available under the CC BY-SA license
216
8.5. Example of a one-dimensional finite element method 3 b(i(k, K))+ = L(ψk )(loop through K element contribution to the integral) 4 for ψl ∈ X(K)(loop through shape functions over an element K) 5 A(i(k, K), i(l, K))+ = B(ψk , ψl )(computations of K element contribution to the integral).
8.5.
Example of a one-dimensional finite element method EXAMPLE
Example 19: An example of the one-dimensional finite element method Consider the strong formulation for the heat transport equation: For the area Ω = (0, 1) ⊂ R we are looking for a scalar field Ω 3 x → u(x) ∈ R given by a smooth d function u ∈ C 2 such that − dx k du dx = 0 dla x ∈ (0, 1) along with the Dirichlet boundary condition u(0) = u0 and Cauchy boundary condition ku0 (1) + hu(1) = huz . Weak formulation: For the area Ω = (0, 1) ⊂ R we are looking for a scalar field u ∈ V = {H 1 (Ω) : v(0) : 0} such that R1 dv B(u, v) = L(v) − B(ˆ u, v) ∀v ∈ V where B(u, v) = 0 k du dx dx dx + hu(1)v(1) and L(v) = huz v(1) where u ˆ = u0 (1 − x) is the extension of the Dirichlet b.c.into the entire area. Finite element space construction: Model element (geometry, shape functions, interpolation operator by projections) ˆ = (0, 1) K χ ˆ1 (x) = 1 − ξ;
χ ˆ2 (ξ) = ξ;
χ ˆ3 (x) = ξ(1 − ξ)
ˆ = span{χ X(K) ˆ1 , χ ˆ2 , χ ˆ3 } ˆ →X K ˆ Πp : H 1 K Πp u(0) = u(0) Πp u(1) = u(1) kΠp u − ukH01 (0,1) → min where kΠp u − ukH01 (0,1) =
R1 0
0
(Πp u) − u0
2
dξ
The first finite element (geometry, shape functions, interpolation operator by projections) K1 = (0, 0.5) χ11 (x) = 1 − 2x dla x ∈ (0, 0.5) dχ11 dx (x)
= −2 dla x ∈ (0, 0.5)
χ12 (x) = 2x dla x ∈ (0, 0.5) dχ12 dx (x)
= 2 dla x ∈ (0, 0.5)
χ13 (x) = 2x(1 − 2x) dla x ∈ (0, 0.5) dχ13 dx (x)
= 2 − 8x dla x ∈ (0, 0.5)
Open AGH e-podręczniki - content available under the CC BY-SA license
217
8.5. Example of a one-dimensional finite element method X(K1 ) = span{χ11 , χ12 , χ13 } ˆ → K1 , xK1 : K
xK1 (ξ) = 0.5ξ
Πp : H 1 (K1 ) → X (K1 ) Πp u(0) = u(0) Πp u(0.5) = u(0.5) kΠp u − ukH01 (0,0.5) → min 0
where k (Πp u) − u0 kH01 (0,0.5) =
R 0.5 0
0
(Πp u) − u0
2
dξ
Second finite element (geometry, shape functions, interpolation operator by projections) K2 = (0.5, 1) χ21 (x) = 2 − 2x dla x ∈ (0.5, 1) dχ21 dx (x)
= −2 dla x ∈ (0.5, 1)
χ22 (x) = 2x − 1 dla x ∈ (0.5, 1) dχ22 dx (x)
= 2 dla x ∈ (0.5, 1).
χ23 (x) = (2x − 1)(2 − 2x) dla x ∈ (0.5, 1) dχ13 dx (x)
= 6 − 8x dla x ∈ (0, 0.5)
X(K2 ) = span{χ21 , χ22 , χ23 } ˆ → K1 , xK2 : K
xK2 (ξ) = 0.5ξ + 0.5
Πp : H 1 (K2 ) → X (K2 ) Πp u(0.5) = u(0.5) Πp u(1) = u(1) kΠp u − ukH01 (0.5,1) → min where kΠp u − ukH 1 (0.5,1) =
R1 0.5
0
(Πp u) − u0
2
dξ
Global base functions e1 (x) = χ11 (x) e2 (x) = χ12 (x) + χ21 (x) e3 (x) = χ22 (x) e4 (x) = χ31 (x) e5 (x) = χ32 (x) Approximation space Vhp = V0.5,2 = span{e2 , e3 , e4 , e5 } ⊂ H 1 (0, 1), where the first base function has been removed to ensure that the Dirichlet boundary condition is satisfied at zero. Problem formulation of the finite element method on a computational mesh: For the area Ω = (0, 1) ⊂ R we are looking for coefficients {ui }i=1,...,5 linear combination u ≈ uhp = P i=1,...,5 ui ei ∈ Vhp such as B(uhp , vhp ) = L(vhp ) − B(ˆ u, v) ∀vhp ∈ Vhp : vhp (0) = 0
Open AGH e-podręczniki - content available under the CC BY-SA license
218
8.6. Two-dimensional finite element where B(uhp , vhp ) =
R1 0
k
duhp dvhp dx dx dx
+ huhp (1)vhp (1) and L(vhp ) = huz vhp (1).
The linear combination coefficients that solve the problem of the weak discrete formulation can be found by solving the following system of equations: B(e2 , e2 ) B(e2 , e3 ) B(e2 , e4 ) B(e2 , e5 ) u2 L(e2 ) − B(ˆ u, e2 ) B(e , e ) B(e , e ) B(e , e ) B(e , e ) u L(e ) − B(ˆ u, e3 ) 3 2 3 3 3 4 3 5 3 3 = . B(e4 , e2 ) B(e4 , e3 ) B(e4 , e4 ) B(e4 , e5 ) u4 L(e4 ) − B(ˆ u, e5 ) B(e5 , e2 ) B(e5 , e3 ) B(e5 , e4 ) B(e5 , e5 )
8.6.
u5
L(e5 ) − B(ˆ u, e5 )
Two-dimensional finite element DEFINITION
Definition 17: Two-dimensional reference finite element A two-dimensional reference finite element (see Pic. 56) is a triple ˆ X K ˆ , Πp K, defined by the following four steps ˆ = [0, 1]2 ⊂ R2 1. Geometry:K 2. Selection of nodes:ˆ a1 , a ˆ2 , a ˆ3 , a ˆ4 , nodes associated with element vertices (0,0), (1,0), (1,1) i (0,1), a ˆ5 , a ˆ6 , a ˆ7 , a ˆ8 nodes associated with element edges, and a ˆ9 node associated with the interior of the element. ˆ ˆ ,j = 3. Definition of element shape function X K = span{φˆj (ξ1 , ξ2 ) ∈ Q(ph ,pv ) K ˆ are polynomials of degree ph related to the variable 1, ..., (ph + 1)(pv + 1)} where Q(ph ,pv ) K ˆ = [0, 1]2 . For the shape ξ1 and polynomials of degree pv related to the variable ξ2 , defined on K functions associated with the edge nodes of the elements, we introduce polynomials of degree p1 , p3 ≤ ph ; p2 , p4 ≤ pv . We define the vertex shape functions φˆ1 (ξ1 , ξ2 ) = χ ˆ1 (ξ1 )χ ˆ1 (ξ2 ), ˆ ˆ ˆ φ2 (ξ1 , ξ2 ) = χ ˆ2 (ξ1 )χ ˆ1 (ξ2 ), φ3 (ξ1 , ξ2 ) = χ ˆ2 (ξ1 )χ ˆ2 (ξ2 ), φ4 (ξ1 , ξ2 ) = χ ˆ1 (ξ1 )χ ˆ2 (ξ2 ), then we define the edge shape functions, φˆ5,j (ξ1 , ξ2 ) = χ ˆ2+j (ξ1 )χ ˆ1 (ξ2 ), j = 1, ..., p1 − 1, φˆ6,j (ξ1 , ξ2 ) = χ ˆ2 (ξ1 )χ ˆ2+j (ξ2 ), j = 1, ..., p2 − 1, φˆ7,j (ξ1 , ξ2 ) = χ ˆ2+j (ξ1 )χ ˆ2 (ξ2 ), j = 1, ..., p3 − 1, ˆ φ8,j (ξ1 , ξ2 ) = χ ˆ1 (ξ1 )χ ˆ2+j (ξ2 ), j = 1, ..., p4 − 1, additionally, we define the interior shape functions φˆ9,i,j (ξ1 , ξ2 ) = χ ˆ2+i (ξ1 )χ ˆ2+j (ξ2 ), i = 1, ..., ph − 1; j = 1, ..., pv − 1. ˆ → X K ˆ . For a given 4. Definition of the projection-based interpolation operator Πp : H 1 K ˆ , its projection based interpolant Πp u ∈ X K ˆ is defined by the following function u ∈ H 1 K conditions: Πp u(0, 0) = u(0, 0) Πp u(1, 0) = u(1, 0) Πp u(0, 1) = u(0, 1) Πp u(1, 1) = u(1, 1) kΠp u − ukH 1 (K) ˆ → min 0
where kΠp u − ukH 1 (K) ˆ = 0
R
ˆ K
0
(Πp u) − u0
2
ˆ dξ1 dξ2 is a norm in Sobolew space H01 (K).
Open AGH e-podręczniki - content available under the CC BY-SA license
219
8.6. Two-dimensional finite element
Figure 56: Two-dimensional reference finite element.
DEFINITION
Definition 18: Two-dimensional finite element A two-dimensional finite element (see Pic. 57) is a triple (K, X (K) , Πp ) defined by the following four steps 1. Geometry:K ⊂ R2 2. Selection of nodes:a1 , a2 , a3 , a4 , nodes related to element vertices,a5 , a6 , a7 , a8 nodes associated with element edges, and a9 node associated with the interior of the element. ˆ∈X K ˆ } where 3. Definition of element shape function X (K) = {φ(x1 , x2 ) = φˆ · x−1 (x , x ), φ 1 2 K ˆ → K is the mapping from the reference element K ˆ = [0, 1]2 on element K ⊂ R2 dane xK : K ˆ 3 (ξ1 , ξ2 ) → xK (ξ1 , ξ2 ) = (x1 , x2 ) ∈ K K 4. Definition of the projection-based interpolation operator Πp : H 1 (K) → X (K). For a given function u ∈ H 1 (K), its projection based interpolant is Πp u ∈ X (K) is defined by the following conditions:Πp u(a1 ) = u(a1 ) Πp u(a2 ) = u(a2 ) Πp u(a3 ) = u(a3 ) Πp u(a4 ) = u(a4 ) kΠp u − ukH01 (K) → min where kΠp u − ukH01 (K) =
R K
0
(Πp u) − u0
2
dx1 dx2 is a norm in Sobolew space H01 (K).
Open AGH e-podręczniki - content available under the CC BY-SA license
220
8.7. The two-dimensional strong and weak formulation for the elliptic problem
Figure 57: Two-dimensional finite element.
8.7.
The two-dimensional strong and weak formulation for the elliptic problem DEFINITION
Definition 19: Formulation of a strong two-dimensional elliptical boundary problem Find R2 ⊃ Ω 3 (x1 , x2 ) → u(x1 , x2 ) ∈ R such as P P P ∂u(x1 ,x2 ) ∂u(x1 ,x2 ) ∂ − i=1,2 ∂x a (x , x ) + + c(x1 , x2 )u(x1 , x2 ) ij 1 2 j=1,2 j=1,2 bj (x1 , x2 ) ∂xj ∂xj i f (x1 , x2 )
=
u(x1 , x2 ) = uD (x1 , x2 ) for (x1 , x2 ) ∈ ΓD P ∂u(x1 ,x2 ) ni = g(x1 , x2 ) for (x1 , x2 ) ∈ ΓN j=1,2 aij (x1 , x2 ) ∂xj P
j=1,2
1 ,x2 ) aij (x1 , x2 ) ∂u(x ni + β(x1 , x2 )u(x1 , x2 ) = g(x1 , x2 ) for (x1 , x2 ) ∈ ΓR where ∂xj
aij, bj , c, f : R2 ⊃ Ω 3 (x1 , x2 ) → aij (x1 , x2 ), bj (x1 , x2 ), c(x1 , x2 ), f (x1 , x2 ) ∈ R are given functions and uD : R2 ⊃ ΓD 3 (x1 , x2 ) → uD (x1 , x2 ) ∈ R g : R2 ⊃ ΓN ∪ ΓR 3 (x1 , x2 ) → g(x1 , x2 ) ∈ R β : R2 ⊃ ΓR 3 (x1 , x2 ) → β(x1 , x2 ) ∈ R are given functions, and the boundary (see Pic. 58) is partitioned into the part where we introduce the Dirichle, Neuman and Robin boundary conditions ∂Ω = ΓD ∪ ΓN ∪ ΓR .
Open AGH e-podręczniki - content available under the CC BY-SA license
221
8.7. The two-dimensional strong and weak formulation for the elliptic problem
Figure 58: Computational domain.
DEFINITION
Definition 20: Weak formulation of the two-dimensional elliptical boundary problem Find u ∈ V such as B(u, v) = L(v) − B(ˆ u, v) ∀v ∈ V where Z B(u, v) =
X X
Ω
i=1,2 j=1,2
aij (x1 , x2 )
∂u(x1 , x2 ) ∂v(x1 , x2 ) + ∂xj ∂xj
∂u(x1 , x2 ) + bj (x1 , x2 ) v(x1 , x2 ) + c(x1 , x2 )u(x1 , x2 ) dx1 dx2 + ∂xj j=1,2 X
+
R
β(x1 , x2 )u(x1 , x2 )v(x1 , x2 )ds R R L(v) = Ω f (x1 , x2 )v(x1 , x2 )dx1 dx2 + ΓR g(x1 , x2 )v(x1 , x2 )ds ΓR
where u ˆD is the extension of the Dirichlet boundary condition tr (ˆ u) = uD over the entire area Ω and R V = {v ∈ L2 (Ω) : Ω kvk2 + k∇vk2 dx1 dx2 < ∞, tr(v) = 0 on ΓD }. We multiply the strong formulation by test functions from space V = {v ∈ L2 (Ω) : R kvk2 + k∇vk2 dx1 dx2 < ∞, tr(v) = 0 on ΓD } and we integrate Ω P R P ∂u(x1 ,x2 ) ∂ − Ω i=1,2 ∂x a (x , x ) v(x1 , x2 )dx1 dx2 + ij 1 2 j=1,2 ∂x i j R P R 1 ,x2 ) + Ω j=1,2 bj (x1 , x2 ) ∂u(x v(x , x )dx dx + c(x1 , x2 )u(x1 , x2 )v(x1 , x2 )dx1 dx2 = 1 2 1 2 ∂x Ω j R = Ω f (x1 , x2 )v(x1 , x2 )dx1 dx2 We integrate by parts (using the Green-Gauss-Ostrogradzki theorem) the term marked in brown R P P ∂u(x1 ,x2 ) ∂v(x1 ,x2 ) a (x , x ) dx dx 1 2 1 2 + i=1,2 j=1,2 ij ∂xj ∂xj Ω −
R
−
R
−
R
P
i=1,2
ΓD
i=1,2
1 ,x2 ) aij (x1 , x2 ) ∂u(x v(x1 , x2 )n(x1 , x2 )dS ∂xj
i=1,2
1 ,x2 ) aij (x1 , x2 ) ∂u(x v(x1 , x2 )n(x1 , x2 )dS ∂xj
P
ΓN ΓR
1 ,x2 ) aij (x1 , x2 ) ∂u(x v(x1 , x2 )n(x1 , x2 )dS ∂xj
P
Open AGH e-podręczniki - content available under the CC BY-SA license
222
8.8. Two-dimensional finite element method R P R 1 ,x2 ) + Ω j=1,2 bj (x1 , x2 ) ∂u(x v(x1 , x2 )dx1 dx2 + Ω c(x1 , x2 )u(x1 , x2 )v(x1 , x2 )dx1 dx2 = ∂xj R = Ω f (x1 , x2 )v(x1 , x2 )dx1 dx2 For the integral over the Dirichlet boundary, we use the property v ∈ V , czyli tr(v) = 0 on ΓD , and we get R P ∂u(x1 ,x2 ) v(x1 , x2 )n(x1 , x2 )dS = 0 i=1,2 aij (x1 , x2 ) ∂xj ΓD For the integral over the Neumann boundary, we use the boundary condition P ∂u(x1 ,x2 ) ni = g(x1 , x2 ) dla (x1 , x2 ) ∈ ΓN , so we get j=1,2 aij (x1 , x2 ) ∂xj R P 1 ,x2 ) a (x , x ) ∂u(x v(x1 , x2 )n(x1 , x2 )dS = ∂xj ΓN R i=1,2 ij 1 2 = ΓN g(x1 , x2 )v(x1 , x2 )n(x1 , x2 )dS For the integral over the Robin boundary, we utilize the boundary condition P ∂u(x1 ,x2 ) ni = g(x1 , x2 ) − β(x1 , x2 )u(x1 , x2 ) dla (x1 , x2 ) ∈ ΓR , so we get j=1,2 aij (x1 , x2 ) ∂xj R P 1 ,x2 ) a (x1 , x2 ) ∂u(x v(x1 , x2 )n(x1 , x2 )dS = ∂xj ΓR R i=1,2 ij R = − ΓR β(x1 , x2 )u(x1 , x2 )v(x1 , x2 )n(x1 , x2 )dS + ΓR g(x1 , x2 )v(x1 , x2 )n(x1 , x2 )dS
ANNOTATION
Annotation 3: Equivalence of strong and weak formulations Each solution to a weak formulation is also a solution to a strong formulation.
8.8.
Two-dimensional finite element method DEFINITION
Definition 21: Two-dimensional computational mesh The computational mesh is a finite-dimensional family Thp of finite elements Thp = {(K, X (K) , Πp )}K such that ∪K∈Thp = Ω, measKi ∩ Kj = Ki dla i = j; 0 for i 6= j.
DEFINITION
Definition 22: Two-dimensional reference mesh For a given computational mesh Thp = {(K, X (K) , Πp )}K two-dimensional reference mesh is a family T h p+1 of finite elements T h p+1 = {(K, X (K) , Πp )}K such that 2
2
∀K ∈ T h p+1 ∃K1 , K2 , K3 , K4 ∈ P(Thp , K) such that 2
K = K1 ∪ K2 ∪ K3 ∪ K4 , measKi ∩ Kj = Ki for i = j; 0 for i 6= j, X(K1 ), X(K2 ), X(K3 ), X(K4 ) ∈ P(Thp , X(K)), dimX(K) =, where dim(K1 ) + 7 = dim(K2 ) + 7 = dim(K3 ) + 7 = dim(K4 ) + 7
Open AGH e-podręczniki - content available under the CC BY-SA license
223
8.8. Two-dimensional finite element method P(Thp , K) and P(Thp , X(K)) mean projections on the first and second components (K, X (K) , Πp ). The dimension of the space of shape functions over the new four finite elements can be estimated by adding of seven new shape functions, corresponding to increasing the degree of polynomials by 1 inside the element horizontally and vertically (making a total of three additional polynomials - one with the degree increased vertically, the other with the degree increased in the horizontal direction, and the third with the degree increased in both directions), and adding four new shape functions obtained by adding new polynomials on the edges of the elements, with the degree of the polynomial increased by 1.
DEFINITION
Definition 23: Approximation space over a two-dimensional computational mesh Approximation space over a two-dimensional computational mesh Thp = {(K, X (K) , Πp )}K is Vhp = {v ∈ C(Ω) : ∀K ∈ P(Thp , K) : P(v, K) ∈ X(K)} where P(Thp , K) is a set of intervals representing the geometry of elements extracted from the triple representing a two-dimensional computational mesh, P(v, K) is a projection of a function onto an interval representing the element’s geometry.
DEFINITION
Definition 24: Mappings defining the composition of local shape functions into global base functions over a computational mesh Let Thp = {(K, X (K) , Πp )}K mean a two-dimensional computational mesh. hp Let {ehp i }i mean the base of space Vhp = span{ei }.
Let χK k ∈ X (K) denote the shape function over the element K. K Then ∀K ∈ P(Thp , K), ∀i, ∃k : P(ehp i , K) = χk .
There is an inverse mapping I 2 3 (k, K) → i(k, K) ∈ I that assigns a number i(k, K) global i-th base function related to local k-th shape function over the element K. In the cases discussed in this manual, this mapping is isomorphic.
DEFINITION
Definition 25: Approximation space above a two-dimensional reference mesh Approximation space above a two-dimensional reference mesh T h p+1 = {(K, X (K) , Πp )}K is 2
V h p+1 = {v ∈ C(Ω) : ∀K ∈ P(T h p+1 , K) : P(v, K) ∈ X(K)} 2
2
where P(T h p+1 , K) is a set of intervals representing the geometry of elements extracted from the 2
Open AGH e-podręczniki - content available under the CC BY-SA license
224
8.8. Two-dimensional finite element method triple representing a two-dimensional computational mesh, P(v, K) is a projection of a function onto an interval representing the element’s geometry.
DEFINITION
Definition 26: Mappings defining the composition of local shape functions into global base functions over a reference mesh Let T h p+1 = {(K, X (K) , Πp )}K stands for a two-dimensional reference mesh. 2
h
Let {ei2
p+1
h
}i means the base of space V h p+1 = span{ei2 2
p+1
}.
Let χK k ∈ X (K) denotes the shape function over the element K. h
Then ∀K ∈ P(T h p+1 , K), ∀i, ∃k : P(ei2 2
p+1
, K) = χK k .
There is an inverse mapping I 2 3 (k, K) → i(k, K) ∈ I which assigns a global index i(k, K) of base function based on the local index of k-th shape function over the element K. In the cases discussed in this manual, this mapping is isomorphic.
DEFINITION
Definition 27: Approximation space above a two-dimensional reference mesh Approximation space above a two-dimensional reference computational mesh T h p+1 = 2
h 2 p+1
{(K, X (K) , Πp )}K to V h p+1 = span{ej 2
h 2 p+1
h
: ∀K ∈ P(T h p+1 , K), ∀φj ∈ X(K), ∃!ei2
p+1
2
:
h 2 p+1
P(ei , K) = ψk } where ei is a global base function (element of V h p+1 ), and ψk is the local 2 shape function above the element K, I 2 3 (k, K) → i(k, K) ∈ I is a mapping that assigns a number i(k, K) global base function index related to local k-th shape function over the element K. The reference mesh is used to estimate the relative error over the computational mesh. Often, when a computational mesh is described in the context of a reference mesh, it is called a sparse mesh (or coarse mesh), and a reference mesh is called a fine mesh (or a dense mesh), because it is created by breaking the elements into smaller elements and increasing the polynomial order of approximation by one. DEFINITION
Definition 28: The problem of the finite element method over a two-dimensional computational mesh For a given computational mesh Thp = {(K, X (K) , Πp )}K find the coefficients {uhp i }i=1,...,N hp of P P hp hp hp hp the approximate solution V ⊃ Vhp 3 uhp = i=1,...,N hp ui ei such that m=1,...,N hp uhp m B(em , en ) = hp L(ehp where n )n = 1, ..., N hp B(ehp m , en ) =
Open AGH e-podręczniki - content available under the CC BY-SA license
225
8.8. Two-dimensional finite element method R P
i=1,2
Ω
P
j=1,2
P
+
aij (x1 , x2 )
j=1,2 bj (x1 , x2 )
hp ∂ehp m (x1 ,x2 ) ∂en (x1 ,x2 ) ∂xj ∂xj
∂ehp m (x1 ,x2 ) hp en (x1 , x2 ) ∂xj
+ c(x1 , x2 )ehp n (x1 , x2 ) dx1 dx2 +
hp β(x1 , x2 )ehp m (x1 , x2 )en (x1 , x2 )ds R R hp hp L(ehp n ) = Ω f (x1 , x2 )en (x1 , x2 )dx1 dx2 + ΓR g(x1 , x2 )en (x1 , x2 )ds.
+
R
ΓR
Base {ehp i }i=1,...,N hp of the approximation space Vhp is obtained by summing shape functions from space X (K) = P(Thp , X(K)) for particular elements from the mesh Thp into global base functions.
DEFINITION
Definition 29: The problem of the finite element method over a two-dimensional reference mesh For a given computational mesh T h p+1 = {(K, X (K) , Πp )}K find the coefficients 2 h h P p+1 h p+1 2 p+1 {ui } of approximate solution V ⊃ V h p+1 3 u h p+1 = u2 ei2 such h h 2 2 i=1,...,n 2 p+1 i=1,...,N 2 p+1 i h h h h P p+1 p+1 p+1 p+1 2 2 that B(em , en2 ) = L(en2 )n = 1, ..., N hp h p+1 um 2 m=1,...,N
h 2 p+1
h
p+1
B(em , en2 )= R P P i=1,2
Ω
j=1,2
h p+1 2 (x
aij (x1 , x2 ) ∂em h p+1 2 (x
∂em j=1,2 bj (x1 , x2 )
+
P
+
R
h
ΓR h
L(en2
p+1
2 β(x1 , x2 )em
p+1
)=
h
R Ω
1 ,x2 )
∂xj h
(x1 , x2 )en2 h
f (x1 , x2 )en2
p+1
1 ,x2 )
h p+1
∂en2
∂xj h
en2
p+1
p+1
(x1 ,x2 ) ∂xj h
(x1 , x2 ) + c(x1 , x2 )en2
p+1
(x1 , x2 ) dx1 dx2 +
(x1 , x2 )ds
(x1 , x2 )dx1 dx2 +
h
R ΓR
g(x1 , x2 )en2
p+1
(x1 , x2 )ds.
p+1
Base {ei2 } of the approximation space Vhp is obtained by summing shape functions h i=1,...,N 2 p+1 from space X (K) = P(T h p+1 , X(K)) for individual mesh elements T h p+1 into global basis functions. 2
2
ANNOTATION
Annotation 4: Solving the problem of the finite element method over a two-dimensional computational mesh Coefficients {uhp i }i=1,...,N hp is calculated by solving a system of equations Ax = b where hp hp B(ehp · · · B(ehp , e ) hp 1 , e1 ) 1 N .. .. , A= . ··· . hp hp hp B(ehp , e ) · · · B(e , e ) N hp 1 N hp N hp hp u1 . . x= . , uhp N hp
Open AGH e-podręczniki - content available under the CC BY-SA license
226
8.8. Two-dimensional finite element method
L(ehp 1 ) .. . b= . L(ehp ) hp N The Dirichlet boundary condition is obtained by setting to zero the rows corresponding to the basis functions defined on the Dirichlet boundary, placing one on the diagonal and setting zero on the right side. The effect of the boundary condition on our system of equations has been transferred to the right-hand side by a shift operation. hp hp Integrals B(ehp m , en ) and L(en ) are computed element by element using the appropriate Gaussian quadratures.
B(ehp , ehp n )= P P m P k
i=1,2
j=1,2
aij (xk1 , xk2 )
k k hp k k ∂ehp m (x1 ,x2 ) ∂en (x1 ,x2 ) ∂xj ∂xj
hp k k k k ∂em (x1 ,x2 ) hp k en (x1 , xk2 ) j=1,2 bj (x1 , x2 ) ∂xj
+
P
+
P
k
k k k k k k + c(xk1 , xk2 )ehp n (x1 , x2 ) Jac(x1 , x2 )w1 w2 +
ΓR k ΓR k ΓR k hp ΓR k k k β(xΓ1 R (z k ), xΓ2 R (z k ))ehp m (x1 (z ), x2 (z ))en (x1 (z ), x2 (z ))Jac(z )w
L(ehp )= P n k k hp k k P ΓR k ΓR k ΓR k k k k hp ΓR k k k + k f (x1 , x2 )en (x1 , x2 )Jac(x1 , x2 )w k g(x1 (z ), x2 (z ))en (x1 (z ), x2 (z ))Jac(z )w where [0, 1] 3 z → (xΓ1 R (z), xΓ2 R (z)) ∈ ΓR is a function that parameterizes the Robin boundary. Generation of a system of equations for a given computational mesh Thp = {(K, X (K) , Πp )}K can be obtained with the following algorithm: 1 for K ∈ P(Thp , K) (loop through elements of the computational mesh) 2 for ψk ∈ X(K)(loop through shape functions on an element K) 3 b(i(k, K))+ = L(ψk )(computing the local integral contribution to an element K) 4 for ψl ∈ X(K)(loop through shape functions on an element K) 5 A(i(k, K), i(l, K))+ = B(ψk , ψl )(computing the local integral contribution to an element K).
ANNOTATION
Annotation 5: Solving the problem of the finite element method over a two-dimensional reference mesh h
p+1
Coefficients {ui2 }i=1,...,N hp is calculated by solving a system of equations Ax = b where h h h h p+1 p+1 2 p+1 2 p+1 B(e1 , e1 ) · · · B(e 2 h p+1 , e12 ) N2 .. .. A= , . ··· . h h h h p+1 p+1 p+1 p+1 B(e12 , e 2 h p+1 ) · · · B(e 2 h p+1 , e 2 h p+1 ) N2 N2 N2 h p+1 u2 1. x = .. , h p+1 u 2 h p+1 N
2
Open AGH e-podręczniki - content available under the CC BY-SA license
227
8.9. Adaptive algorithm h p+1 L(e12 ) .. b= . . h 2 p+1 L(e h p+1 )
N
2
The Dirichlet boundary condition is obtained by setting to zero the rows corresponding to the basis functions defined on the Dirichlet boundary, placing one on the diagonal and zero in the right-hand side. The effect of the boundary condition on our system of equations has been transferred to the right-hand side by the shift operation. h
p+1
2 Integrals B(em h
p+1
h
h
, en2
p+1
) and L(ehp n ) are computed using the appropriate Gaussian quadratures.
p+1
2 2 B(em )= , en P P P
k
h p+1
k k j=1,2 aij (x1 , x2 )
i=1,2
2 ∂em
h p+1
k 2 (xk 1 ,x2 ) ∂en ∂xj
h p+1
h k 2 p+1 k (xk k k ∂em 1 ,x2 ) 2 en (x1 , xk2 ) j=1,2 bj (x1 , x2 ) ∂xj
+
P
+
P
k
k (xk 1 ,x2 ) ∂xj
h
+
p+1 k c(xk1 , xk2 )en2 (x1 , xk2 ) h
ΓR k ΓR k 2 β(xΓ1 R (z k ), xΓ2 R (z k ))ehp m (x1 (z ), x2 (z ))en
p+1
Jac(xk1 , xk2 )w1k w2k +
(xΓ1 R (z k ), xΓ2 R (z k ))Jac(z k )wk
L(ehp n )= h h P P p+1 ΓR k k k 2 p+1 (xk1 , xk2 )Jac(xk1 , xk2 )wk + k g(xΓ1 R (z k ), xΓ2 R (z k ))en2 (x1 (z ), xΓ2 R (z k ))Jac(z k )wk k f (x1 , x2 )en where Jac(xk ) is the value at the Gaussian Jacobian quadrature point of the mapping from the reference element to the given element, [0, 1] 3 z → (xΓ1 R (z), xΓ2 R (z)) ∈ ΓR is a function that parameterizes the Robin boundary. Generation of a system of equations for a given calculation mesh T h p+1 = {(K, X (K) , Πp )}K 2
can be obtained with the following algorithm: 1 for K ∈ P(T h p+1 , K) (loop through computational mesh elements) 2
2 for ψk ∈ X(K)(loop through shape functions on an element K) 3 b(i(k, K))+ = L(ψk )(computing the local integral contribution to an element K) 4 for ψl ∈ X(K)(loop through shape functions on an element K) 5 A(i(k, K), i(l, K))+ = B(ψk , ψl )(computing the local integral contribution to an element K).
8.9.
Adaptive algorithm DEFINITION
Definition 30: Interpolating function obtained by projection in one-dimension Let Thp = {(K, X (K) , Πp )}K will be a computational mesh. Let Vhp ⊂ V h p+1 ⊂ V will be approximation spaces on the computational mesh and the corresponding 2 reference mesh. Let Vw will be an intermediate approximation space Vhp ⊂ Vw ⊂ V h p+1 . 2
Let K ∈ Thp will be a finite element on a computational mesh.
Open AGH e-podręczniki - content available under the CC BY-SA license
228
8.9. Adaptive algorithm Let uhp ∈ Vhp , u h p+1 ∈ V h p+1 will be solutions on the computational mesh and reference mesh. 2
2
An interpolating function w ∈ Vw on the element K obtained by projecting from the solution on the reference grid u h p+1 ∈ V h p+1 we call w obtained by the following procedure 2
2
1. Interpolation in element vertex node w(ai ) = u h p+1 (ai ), i = 1, 2. 2
0
0
2. Projection on internal nodes kw −u h p+1 k 2 over the interior of the element.
L2 (a3 )
→ min where k·kL2 (a3 ) means the norm defined
DEFINITION
Definition 31: Interpolating function obtained by projection in two dimensions Let Thp = {(K, X (K) , Πp )}K be a calculation mesh. Let Vhp ⊂ V h p+1 ⊂ V will be approximation spaces on the computational mesh and the corresponding 2 reference mesh. Let Vw will be an intermediate approximation space Vhp ⊂ Vw ⊂ V h p+1 . 2
Let K ∈ Thp will be a finite element on a computational mesh. Let uhp ∈ Vhp , u h p+1 ∈ V h p+1 be solutions over the computational mesh and reference mesh. An 2 2 interpolating function w ∈ Vw on the element K obtained by projecting from the solution on the reference mesh u h p+1 ∈ V h p+1 we call w obtained by the following procedure 2
2
1. Interpolation in element vertex nodes w(ai ) = u h p+1 (ai ), i = 1, 2, 3, 4. 2
2. Projection on edge nodes k∇w · e − ∇u h p+1 · ekL2 (aj ) → min, j = 5, 6, 7, 8 where ∇w · e denotes 2 a directional derivative in a direction parallel to the edge, and k · kL2 (aj ) denotes the norm above the edge of the element. 3. Projection on internal nodes k∇w − ∇u h p+1 kL2 (a9 ) → min where k · kL2 (aj ) means the norm 2 defined over the interior of the element.
DEFINITION
Definition 32: Optimal extended approximation space Let Thp = {(K, X (K) , Πp )}K will be a computational mesh. Let Vhp ⊂ V h p+1 ⊂ V will be approximation spaces on the computational mesh and the corresponding 2 reference mesh. Let uhp ∈ Vhp , u h p+1 ∈ V h p+1 will be solutions on the computational mesh and reference mesh. 2
2
Approximation space Vopt we call the optimal extended approximation space above the computational mesh, if on each element K the interpolating function wopt obtained by projecting a solution on a reference mesh u h p+1 ∈ V h p+1 meets the following minimum 2
2
|u h p+1 −uhp |H 1 (K) −|u h p+1 −wopt |H 1 (K) 2
2
∆nrdof (Vhp ,Vopt ,K)
= maxVhp ⊂Vw ⊂V h p+1 2
|u h p+1 −uhp |H 1 (K) −|u h p+1 −w|H 1 (K) 2
2
∆nrdof (Vhp ,Vw ,K)
Open AGH e-podręczniki - content available under the CC BY-SA license
229
8.9. Adaptive algorithm where k · kH 1 (K) means a norm H 1 over the interior of the element, w is an interpolating function obtained by projection,u h p+1 ∈ V h p+1 on the Vw on the element K, and ∆nrdof (Vhp , Vw , K) denote 2 2 the number of unknowns necessary to be added to the approximation space on the grid in order to extend it to the space Vw over the element K.
Figure 59: Selection of the optimal approximation space over a two-dimensional finite element.
ANNOTATION
Annotation 6: The algorithm of generating the optimal extended approximation space above the computational mesh The optimal extended approximation space can be found element by element using the following algorithm 1 for K ∈ P(Thp , K) (loop through computational mesh elements) K 2 for Vopt (loop through the extended spaces above the element K)
3 rate_max = 0 4 Calculate the interpolating function w by projecting the solution on a reference mesh u h p+1 over the 2 K element K corresponding to the extended approximation space Vopt 5 Calculate the error decrease rate rate(w) =
|u h p+1 −uhp |H 1 (K) −|u h p+1 −wopt |H 1 (K) 2
2
∆nrdof (Vhp ,Vopt ,K)
)
6 If rate(w) ≥ rate_max wówczas rate_max = rate(w) K 7 Vopt answering rate_max is the optimal extended approximation space over the element K.
Open AGH e-podręczniki - content available under the CC BY-SA license
230
8.9. Adaptive algorithm
DEFINITION
Definition 33: Relative error in the calculation mesh Let Thp = {(K, X (K) , Πp )}K will be a computational mesh. Let Vhp ⊂ V h p+1 ⊂ V will be approximation spaces on the computational mesh and the corresponding 2 reference mesh. Let uhp ∈ Vhp , u h p+1 ∈ V h p+1 will be solutions on the computational mesh and reference mesh. 2
2
The relative error of the solution on the computational mesh is given by the formula err_rel(uhp ) =
ku h p+1 −uhp kH 1 (Ω) 2
ku h p+1 kH 1 (Ω)
.
2
ANNOTATION
Annotation 7: Algorithm of hp adaptation 1. Create Thp = {(K, X (K) , Πp )}K the initial computational grid and Vhp ⊂ V an approximation space on a computational mesh. 2. Generate a reference mesh and V h p+1 ⊂ V the approximation space on the reference mesh. 2
3. Calculate uhp ∈ Vhp , u h p+1 ∈ V h p+1 solutions on the computational mesh and reference mesh. 2
2
4. for K ∈ P(Thp , K) (loop through computational mesh elements) 5. rate_max = 0 K 5. for Vopt (loop through the extended spaces above the element K)
6. Calculate the interpolating function w by projecting the solution on a reference mesh u h p+1 on the 2 K element K corresponding to the extended approximation space Vopt 7. Calculate the error decrease rate rate(w) =
|u h p+1 −uhp |H 1 (K) −|u h p+1 −wopt |H 1 (K) 2
2
∆nrdof (Vhp ,Vopt ,K)
)
8. If rate(w) ≥ rate_max wówczas rate_max = rate(w) 9. endfor (end of loop through extended spaces) 10. Generate K Vopt answering rate_max optimal extended approximation space above the element K
11. endfor (end of loop after elements) 12. Eliminate conflicts between adjacent elements of the optimal extended approximation space (in two dimensions, the degrees of polynomials on the edges of the elements should be the minimum of degrees with the corresponding interior (walls in 3D), in addition, in three dimensions, the degrees of polynomials on the walls should be the minimum of the corresponding degrees inside the elements) 13. Calculate the relative error of the solution on the computational mesh
Open AGH e-podręczniki - content available under the CC BY-SA license
231
8.10. The convergence of the finite element method
err_rel(uhp ) =
ku h p+1 −uhp kH 1 (Ω) 2
ku h p+1 kH 1 (Ω) 2
14. If err_rel(uhp ) =
ku h p+1 −uhpkH 1 (Ω) 2
ku h p+1 kH 1 (Ω)
≤ then STOP
2
15. Go to step 2.
8.10.
The convergence of the finite element method
The following three lemmas apply as follows. The Lax-Milgram lemma and the more general infimum-supremum condition are used to check whether a given weak formulation has a unique solution. The Cea lemma allows for the estimation of the solution error and the rate of convergence for the finite element method.
LEMMA
Lemma 1: Lemat Laxa-Milgrama (simplified to the case of our spaces and formulations) Let V = {v ∈ L2 (Ω) :
R Ω
kvk2 + k∇vk2 dx1 dx2 < ∞, tr(v) = 0 on ΓD } for Ω ⊂ Rd
Let B : V × V → R will be a two-line form B(α1 u1 + α2 u2 , v1 ) = α1 B(u1 , v) + α2 B(u2 , v1 ) B(u1 , β1 v1 + β2 v2 ) = β1 B(u1 , v1 ) + β2 B(u1 , v2 ) α1 , α2 , β1 , β2 ∈ R, ∀u1 , u2 , v1 , v2 ∈ V , ciągłą ∃M > 0, |B(u, v)| ≤ M kukV kvkV ∀u, v ∈ V and coercive, i.e. ∃α > 0, |B(u, u)| ≥ αkuk2V ∀u ∈ V . Let L : V → R will be a linear form L(α1 v1 + α2 v2 ) = α1 L(v1 ) + α2 L(v2 ) α1 , α2 ∈ R, ∀v1 , v2 ∈ V , continuous, i.e. ∃C > 0, |L(v)| ≤ CkvkV ∀v ∈ V . Then the weak problem B(u, v) = L(v) − B(ˆ u, v) ∀v ∈ V has a unique solution, such that ku + u ˆkV ≤ kˆ ukV 1 + M α +
C α.
For more complicated cases of weak formulations B(u, v) = L(v) − B(ˆ u, v) ∀v ∈ V instead of the Lax-Milgram Lemma, we use the Babuska Lemma equivalent to the Brezzi Lemma [57].
LEMMA
Lemma 2: Lemat Cea (simplified to the case of our spaces and formulations) Consider the solution to the problem of the finite element method on a computational mesh. R Let V = H01 (Ω) = {v ∈ L2 (Ω) : Ω kvk2 + k∇vk2 dx1 dx2 < ∞, tr(v) = 0 on ΓD } for Ω ⊂ Rd Let B : V × V → R
Open AGH e-podręczniki - content available under the CC BY-SA license
232
8.11. Isogeometric finite element method be a two-line form B(α1 u1 + α2 u2 , v1 ) = α1 B(u1 , v) + α2 B(u2 , v1 ) B(u1 , β1 v1 + β2 v2 ) = β1 B(u1 , v1 ) + β2 B(u1 , v2 ) α1 , α2 , β1 , β2 ∈ R, ∀u1 , u2 , v1 , v2 ∈ V , continuous ∃M > 0, |B(u, v)| ≤ M kukV kvkV ∀u, v ∈ V and coercive ∃α > 0, |B(u, u)| ≥ αkuk2V ∀u ∈ V . Let L : V → R be a line form. L(α1 v1 + α2 v2 ) = α1 L(v1 ) + α2 L(v2 ) α1 , α2 ∈ R, ∀v1 , v2 ∈ V , continuous ∃C > 0, |L(v)| ≤ CkvkV ∀v ∈ V . Let u ∈ V be a solution of a weak problem B(u, v) = L(v) − B(ˆ u, v) ∀v ∈ V . Let Thp = {(K, X (K) , Πp )}K be a computational grid. Let Vhp ⊂ V be an approximation space on a computational grid. Let uhp ∈ Vhp be a solution to the problem of the finite element method on a computational mesh. B(uhp , vhp ) = L(vhp ) − B(ˆ u, vhp ) ∀vhp ∈ Vhp on the computational grid. Then ku − uhp kV ≤
M α minwhp ∈Vhp ku
− whp kV .
The meaning of the Cea Lemma is as follows. Ideally, the distance of the solution of the finite element method problem uhp ∈ Vhp on the computational grid Thp = {(K, X (K) , Πp )}K from the solution of the weak problem u ∈ V would be the minimum distance of solution u ∈ V of a weak problem from all elements of space Vh in which we are looking for a solution to the problem of the finite element method. M It would be if constant M α = 1. However it is α ≥ 1. This means that the error we make when solving the problem with the finite element method is burdened with an error resulting from the construction of the computational mesh. Thp = {(K, X (K) , Πp )}K (adaptation of the computational mesh increases the size of the space Vhp and makes our approximate solution uhp ∈ Vhp closer to the perfect solution u ∈ V . The remaining error is due to the ratio of the constants M continuity and α coercivity of the bilinear functional B : V × V → R. This error can be eliminated by using the stabilization methods described in the relevant modules of the manual.
ADDITIONAL INFORMATION
Additional information 1: HP convergence of the adaptive finite element method In his work [38] prof. Ivo Babuśka puts forward the mathematical theorems from which it implies that the hp algorithm of the adaptive finite element method for elliptic problems used to obtain the fastest possible exponential convergence err_rel = error_0exp(Cnrdof α ) where error_0, C, α are constants depending on the problem,err_rel
=
kuhp −u h p+1 kH 1 (Ω) 2
ku h p+1 kH 1 (Ω)
is the error in the computational
2
mesh relative to the reference mesh, nrdof is the problem size of the finite element method on the computational mesh (degrees of freedom).
8.11.
Isogeometric finite element method
Open AGH e-podręczniki - content available under the CC BY-SA license
233
8.11. Isogeometric finite element method
ANNOTATION
Annotation 8: Elements for the isogeometric finite element method Formal definitions of the reference one- and two-dimensional isogeometric finite elements differ from classical elements only in the shape functions and selection of nodes. Shape functions for isogeometric elements are defined in such a way that it is possible to sum them into global B-spline basis functions. All other mathematical formalism described in this chapter remains valid if we replace the classical elements with isogeometric elements. For isogeometric elements of degree p, it is necessary to define an appropriate number of nodes, specifically (p + 1) in one dimension and (p + 1)2 in two dimensions, and providing formulas for appropriate shape functions. For isogeometric analysis, there is also a specific mapping recipe that defines the composition of local shape functions into global basis functions over the computational grid. The global Lagrange basis function is made up of local shape functions differently, and the global B-spline basis function is made up of local shape functions differently. Below, as an example, we give the definitions of one and two-dimensional reference isogeometric second degree finite elements, for which the given shape functions can be summed into second order B-spline functions of continuity C 1 . Classical finite elements have local shape functions which, for the sake of distinction, can be grouped into global Lagrange basis functions. For example, for the second order p = 2, the local shape functions consist of the second order C 1 over the insides of individual finite elements, however on the interfaces between elements (over vertices in one dimension or over edges in two dimensions) they have continuity C 0 .
DEFINITION
Definition 34: A one-dimensional isogeometric finite element of the second degree We call a one-dimensional reference isogeometric finite element of the second degree ˆ X K ˆ , Πp K, defined by the following four steps ˆ = [0, 1] ⊂ R 1. Geometry:K 2. Selection of nodes:ˆ a1 , a ˆ2 nodes associated with vertices 0 and 1 of the element, and a ˆ3 node associated with the interior (0,1) of the element ˆ ˆ , j = 1, ..., 3} where 3. Definition of element shape function X K = span{χ ˆj ∈ P p K ˆ are degree polynomials p specified on the interval K ˆ = (0, 1) and χ Pp K ˆ1 (ξ) = 12 (1 − ξ)2 , χ ˆ2 (ξ) = 12 ξ 2 , χ ˆ3 (ξ) = −ξ 2 + x + 12 . ˆ →X K ˆ . For a given function 4. Definition of interpolation by projection operator Πp : H 1 K ˆ , its projection-based interpolant is Πp u ∈ X K ˆ is defined by the following u ∈ H1 K conditions: Πp u(ˆ a1 ) = u(ˆ a1 )
Open AGH e-podręczniki - content available under the CC BY-SA license
234
8.12. The future of the finite element method Πp u(ˆ a2 ) = u(ˆ a2 ) 0
k (Πp u) − u0 kH 1 (0,1) → min 0
where k (Πp u) − u0 kH 1 (0,1) =
R1 0
0
(Πp u) − u0
2
dξ is a norm in Sobolew’s space H 1 (0, 1).
DEFINITION
Definition 35: Two-dimensional isogeometric finite element of second degree A two-dimensional reference isogeometric finite element of the second degree is a four ˆ X K ˆ , Πp K, defined by the following four steps ˆ = [0, 1]2 ⊂ R2 1. Geometry:K 2. Selection of nodes:ˆ a1 , a ˆ2 , a ˆ3 , a ˆ4 , nodes associated with element vertices (0,0), (1,0), (1,1), (0,1), a ˆ5 , a ˆ6 , a ˆ7 , a ˆ8 the nodes associated with the element edges, and a ˆ9 the node associated with the interior of the element. ˆ = span{χ ˆ , j = 1, ..., 9} where 3. Definition of element shape function X K ˆj ∈ S (2,2) K ˆ are second order polynomials with respect to the variable ξ1 and relative to the S (2,2) K ˆ = [0, 1]2 . We define shape functions φˆ1 (ξ1 , ξ2 ) = χ variable ξ2 , defined at K ˆ1 (ξ1 )χ ˆ1 (ξ2 ), φˆ2 (ξ1 , ξ2 ) = χ ˆ2 (ξ1 )χ ˆ1 (ξ2 ), φˆ3 (ξ1 , ξ2 ) = χ ˆ2 (ξ1 )χ ˆ2 (ξ2 ), φˆ3 (ξ1 , ξ2 ) = χ ˆ1 (ξ1 )χ ˆ2 (ξ2 ), ˆ ˆ ˆ φ5,2 (ξ1 , ξ2 ) = χ ˆ3 (ξ1 )χ ˆ1 (ξ2 ), φ6,2 (ξ1 , ξ2 ) = χ ˆ2 (ξ1 )χ ˆ3 (ξ2 ), φ7 (ξ1 , ξ2 ) = χ ˆ3 (ξ1 )χ ˆ2 (ξ2 ), ˆ ˆ φ8 (ξ1 , ξ2 ) = χ ˆ1 (ξ1 )χ ˆ3 (ξ2 ), φ9 (ξ1 , ξ2 ) = χ ˆ3 (ξ1 )χ ˆ3 (ξ2 ). ˆ → X K ˆ . For a given 4. Definition of the projection-based interpolation operator Πp : H 1 K ˆ , its projection based interpolant is Πp u ∈ X K ˆ is defined by the function u ∈ H 1 K following conditions: Πp u(0, 0) = u(0, 0) Πp u(1, 0) = u(1, 0) Πp u(0, 1) = u(0, 1) Πp u(1, 1) = u(1, 1) 0
k (Πp u) − u0 kH 1 (K) ˆ → min 0
where k (Πp u) − u0 kH 1 (K) ˆ =
8.12.
R
0
ˆ K
(Πp u) − u0
2
ˆ dξ1 dξ2 it is a semorma in the Sobolev space H 1 (K).
The future of the finite element method
Among the current (at the end of 2019) trends regarding the further development of the finite element method, the following can be distinguished: 1. Scientific research on the development of better and better methods of stabilizing difficult simulations for which the classical Galerkin method behaves unstably. Methods based on minimizing the residual are particularly strongly developed, in which stabilization is achieved by defining the testing space larger than the approximation space. In the adaptive finite element method, the DPG stabilization method is the most popular. The recently discovered Fortin operator gives hope for precise Open AGH e-podręczniki - content available under the CC BY-SA license
235
8.12. The future of the finite element method determination of which testing space should be selected for a given approximation space in order to obtain automatic stabilization of the solution. Stabilization methods based on the discontinuous Galerkin formulation are also developing particularly intensively. 2. Deep neural networks are also of interest to the world of simulation using the finite element method. Research is being carried out on the use of neural networks to automatically find optimal testing functions in the Petrov-Galerkin formulation by the method of minimizing the residual in order to obtain automatic stabilization of the simulation. Scientists are also interested in the use of neural networks for automatic decision-making on the adaptation of computational grids. 3. The isogeometric finite element method is also enjoying growing popularity. This is due to the fact that in Computer Aided Design (CAD) systems, the design of objects on which simulations are carried out using the finite element method is performed using functions derived from the B-spline family, such as NURBS (Non-Uniform Rational B- splines), enabling the faithful reproduction of the circle geometry, T-splines, hierarchical B-spline functions, TH B-splines and LR B-splines. All these families try to solve problems with B-spline functions such as the ability to span on adaptive meshes, the ability to mix splines of different order, and perform local hp adaptations so that the ”partition of unity” property of the splines is preserved (meaning the summing of B-spline basis functions to one at each point in the domain). The integration of computer simulations with design allows you to bypass the costly stage of transforming the object model described with the use of functions from the spline family into a computational mesh covered with finite elements, often tetrahedral, and not having much in common with the geometry described in CAD systems. The authors of isogeometric analysis protect many aspects related to the integration of CAD systems with Computer Aided Engineering (CAE) systems by patent rights. 4. Parallel simulations are carried out on a large scale using the finite element method for non-stationary, often non-linear problems. The most frequently used algorithms of alternating-direction solvers and iterative solvers based on multi-grid methods, which combine projection elements between grids of different sizes, and iterative solvers. Increasing the computing power of computers enables the use of the finite element method in conjunction with inverse algorithms. In particular, model parameters are sought, such as the optimal position of pumps in the liquid fuel fossil extraction problem, in order to maximize extraction and minimize environmental pollution (e.g., groundwater). 5. The finite element method has found application in many areas of life. It is used for the design and analysis of cars, airplanes, mobile phones and building structures. It is used in medical simulations such as modeling blood flow in the central circulatory system, modeling tumor growth and modeling the propagation of electromagnetic waves to identify lesions. It is used in simulations of weather, climate, pollution propagation, and in simulations of extreme phenomena such as typhoons or earthquakes. The finite element method is a simulation tool. Like many tools, it can be used in many different ways. It is a powerful tool that can model reality and change the world we live in. We should always remember about the ethical messages resulting from our choices and goals we pursue, especially when we have such a powerful tool in our hands.
Open AGH e-podręczniki - content available under the CC BY-SA license
236
Chapter 9
Appendices 9.1.
Appendix 1
MATLAB code that calculates the L2 isogeometric bitmap projection (see chapter MATLAB implementation of the bitmap projection problem) 1
function bitmap_fast(filename ,nxx ,pxx ,nyy ,pyy)%, knot_vectorx , knot_vectory)
2 3
tic;
4 5 6
%number of basis functions compute_nr_basis_functions = @(knot_vector ,p) size(knot_vector , 2) - p - 1;
7 8 9
knot_vectorx = simple_knot(nxx ,pxx); knot_vectory = simple_knot(nyy ,pyy);
10 11 12
%RGB format X = imread(filename);
13 14 15 16
R = X(:,:,1); G = X(:,:,2); B = X(:,:,3);
17 18 19
ix = size(X,1); iy = size(X,2);
20 21 22
px = compute_p(knot_vectorx); py = compute_p(knot_vectory);
23 24 25
elementsx = number_of_elements(knot_vectorx ,px); elementsy = number_of_elements(knot_vectory ,py);
26 27 28
nx = number_of_dofs(knot_vectorx ,px); ny = number_of_dofs(knot_vectory ,py);
29 30 31 32 33
A = sparse(nx*ny ,nx*ny); FR = zeros(nx*ny ,1); FG = zeros(nx*ny ,1); FB = zeros(nx*ny ,1);
34 35 36
init=toc tic;
37 38 39
splinex = zeros(elementsx ,nx ,px+1); spliney = zeros(elementsy ,ny ,py+1);
237
9.1. Appendix 1
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
for ex = 1: elementsx; % suport of basis functions over an element in x directin [xl ,xh] = dofs_on_element(knot_vectorx ,px ,ex); % elemental span along x axis [ex_bound_l ,ex_bound_h] = element_boundary(knot_vectorx ,px ,ex); % quadrature points along x axis qpx = quad_points(ex_bound_l ,ex_bound_h ,px+1); % quadrature weights along x axis qwx = quad_weights(ex_bound_l ,ex_bound_h ,px+1); % loop through non -zero functions for bi = xl:xh % loop through quadrature points and weights for iqx = 1: size(qpx ,2) splinex(ex ,bi ,iqx)= compute_spline(knot_vectorx ,px ,bi ,qpx(iqx)); endfor endfor endfor
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
for ey = 1: elementsy; % suport of basis functions over an element in y directin [yl ,yh] = dofs_on_element(knot_vectory ,py ,ey); % elemental span along y axis [ey_bound_l ,ey_bound_h] = element_boundary(knot_vectory ,py ,ey); % quadrature points along y axis qpy = quad_points(ey_bound_l ,ey_bound_h ,py+1); % quadrature weights along y axis qwy = quad_weights(ey_bound_l ,ey_bound_h ,py+1); % loop through non -zero functions for bi = yl:yh % loop through quadrature points and weights for iqy = 1: size(qpy ,2) spliney(ey ,bi ,iqy)= compute_spline(knot_vectory ,py ,bi ,qpy(iqy)); endfor endfor endfor
77 78 79
init_splines=toc tic;
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
%integrals of B^x_i(x) B^y_j(y) B^x_k(x) B^y_l(y) %(i,k=1,...,Nx; j,l=1,...,Ny) %loop through elements along x for ex = 1: elementsx; % elemental span along x axis [xl ,xh] = dofs_on_element(knot_vectorx ,px ,ex); % left and right border of element along x [ex_bound_l ,ex_bound_h] = element_boundary(knot_vectorx ,px ,ex); %loop through elements along y for ey = 1: elementsy % elemental span along y axis [yl ,yh] = dofs_on_element(knot_vectory ,py ,ey); % left and right border of element along y [ey_bound_l ,ey_bound_h] = element_boundary(knot_vectory ,py ,ey); % jacobian = element size Jx = ex_bound_h - ex_bound_l; Jy = ey_bound_h - ey_bound_l; J = Jx*Jy; % quadrature points along x axis qpx = quad_points(ex_bound_l ,ex_bound_h ,px+1); % quadrature weights along x axis qwx = quad_weights(ex_bound_l ,ex_bound_h ,px+1);
Open AGH e-podręczniki - content available under the CC BY-SA license
238
9.1. Appendix 1 % quadrature points along y axis qpy = quad_points(ey_bound_l ,ey_bound_h ,py+1); % quadrature weights along y axis qwy = quad_weights(ey_bound_l ,ey_bound_h ,py+1); % loop through non -zero functions over an element for bi = xl:xh for bj = yl:yh for bk = xl:xh for bl = yl:yh % loop through quadrature points for iqx = 1: size(qpx ,2) for iqy = 1: size(qpy ,2) % B^x_k(x) funk = splinex(ex ,bk ,iqx); % B^y_l(y) funl = spliney(ey ,bl ,iqy); % B^x_i(x) funi = splinex(ex ,bi ,iqx); % B^y_j(y) funj = spliney(ey ,bj ,iqy); % B^x_i(x) B^y_j(y) B^x_k(x) B^y_l(y) fun = funi*funj*funk*funl;
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
% Integrals of B^x_i(x) B^y_j(y) B^x_k(x) B^y_l(y) % (i,k=1,...,Nx; j,l=1,...,Ny) int = fun*qwx(iqx)*qwy(iqy)*J; if (int !=0) A((bj -1)*nx+bi ,(bl -1)*nx+bk) = A((bj -1)*nx+bi ,(bl -1)*nx+bk) + int; endif endfor endfor endfor endfor endfor endfor endfor endfor
140 141
lhs=toc
142 143
tic;
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165
%Integra;s BITMAPA(x,y) B^x_k(x) B^y_l(y) %loop through elements along x for ex = 1: elementsx; % elemental span along y axis [xl ,xh] = dofs_on_element(knot_vectorx ,px ,ex); % left and right border of element along x [ex_bound_l ,ex_bound_h] = element_boundary(knot_vectorx ,px ,ex); %loop through elements along y for ey = 1: elementsy % elemental span along y axis [yl ,yh] = dofs_on_element(knot_vectory ,py ,ey); % borders of element [ey_bound_l ,ey_bound_h] = element_boundary(knot_vectory ,py ,ey); % jacobian = element size Jx = ex_bound_h - ex_bound_l; Jy = ey_bound_h - ey_bound_l; J = Jx * Jy; % quadrature points along x axis qpx = quad_points(ex_bound_l ,ex_bound_h ,px+1); % quadrature points along y axis qpy = quad_points(ey_bound_l ,ey_bound_h ,px+1);
Open AGH e-podręczniki - content available under the CC BY-SA license
239
9.1. Appendix 1
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192
% quadrature weights along x axis qwx = quad_weights(ex_bound_l ,ex_bound_h ,py+1); % quadrature weights along y axis qwy = quad_weights(ey_bound_l ,ey_bound_h ,py+1); %loop through non -zero functions for bk = xl:xh for bl = yl:yh %loop through quadrature points for iqx = 1: size(qpx ,2) for iqy = 1: size(qpy ,2) % B^x_k(x) funk = splinex(ex ,bk ,iqx); % B^y_l(y) funl = spliney(ey ,bl ,iqy); % Integral BITMAPA(x,y) B^x_k(x) B^y_l(y) over RGB colors intR = funk*funl*qwx(iqx)*qwy(iqy)*J*bitmp(R,qpx(iqx),qpy(iqy)); intG = funk*funl*qwx(iqx)*qwy(iqy)*J*bitmp(G,qpx(iqx),qpy(iqy)); intB = funk*funl*qwx(iqx)*qwy(iqy)*J*bitmp(B,qpx(iqx),qpy(iqy)); FR((bl -1)*nx+bk) = FR((bl -1)*nx+bk) + intR; FG((bl -1)*nx+bk) = FG((bl -1)*nx+bk) + intG; FB((bl -1)*nx+bk) = FB((bl -1)*nx+bk) + intB; endfor endfor endfor endfor endfor endfor
193 194 195
rhs=toc tic;
196 197 198 199 200
% solution of three systems of equations RR=A\FR; GG=A\FG; BB=A\FB;
201 202
%solution reconstruction
203 204 205 206 207
%preparing of matrices R1 = zeros(ix ,iy); G1 = zeros(ix ,iy); B1 = zeros(ix ,iy);
208 209 210
factor=toc tic;
211 212 213
funx_tab = zeros(nx ,ix); funy_tab = zeros(ny ,iy);
214 215 216 217 218 219 220 221 222 223 224
% loop through functions for bi = 1:nx % loop through pixels covering the support of functions for i=xx(knot_vectorx(bi)):xx(knot_vectorx(bi+px+1)) % coordinates transformation [1-length] -> [0-1] ii = (i-1)/(ix -1); % B^x_i(x) funx_tab(bi ,i) = compute_spline(knot_vectorx ,px ,bi ,ii); endfor endfor
225 226 227 228
% loop through functions for bj = 1:ny
Open AGH e-podręczniki - content available under the CC BY-SA license
240
9.1. Appendix 1
229 230 231 232 233 234 235 236
% loop through pixels covering the support of functions for j=yy(knot_vectory(bj)):yy(knot_vectory(bj+py+1)) % coordinates transformation [1-height] -> [0-1] jj = (j-1)/(iy -1); % B^y_j(y) funy_tab(bj ,j) = compute_spline(knot_vectory ,py ,bj ,jj); endfor endfor
237 238 239
preprocess=toc tic;
240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258
% loop through functions for bi = 1:nx for bj = 1:ny % loop through pixels covering the support of functions for i=xx(knot_vectorx(bi)):xx(knot_vectorx(bi+px+1)) for j=yy(knot_vectory(bj)):yy(knot_vectory(bj+py+1)) % B^x_i(x) funi = funx_tab(bi ,i);% compute_spline(knot_vectorx ,px ,bi ,ii); % B^y_j(y) funj = funy_tab(bj ,j);% compute_spline(knot_vectory ,py ,bj ,jj); ff = funi*funj; R1(i,j) = R1(i,j) + floor(ff*RR((bj -1)*nx+bi)); G1(i,j) = G1(i,j) + floor(ff*GG((bj -1)*nx+bi)); B1(i,j) = B1(i,j) + floor(ff*BB((bj -1)*nx+bi)); endfor endfor endfor endfor
259 260 261 262 263
RGB=X; RGB(:,:,1) = R1; RGB(:,:,2) = G1; RGB(:,:,3) = B1;
264 265
rebuild=toc
266 267
imshow(RGB);
268 269 270 271 272 273 274 275
function resx=xx(x) resx = floor ((ix -1)*x+1); endfunction
276 277 278 279 280 281
function resy=yy(y) resy = floor ((iy -1)*y+1); endfunction
282 283 284 285 286 287 288 289 290 291
function val=bitmp(M,x,y) val = zeros(size(x)); for i=1: size(x,1) for j=1: size(x,1) val(i,j)=M(xx(x(1,i)),yy(y(1,j))); endfor endfor endfunction
Open AGH e-podręczniki - content available under the CC BY-SA license
241
9.1. Appendix 1
292 293 294 295
%the function computes the order of function function p=compute_p(knot_vector)
296 297 298 299 300 301
%first knot point initial = knot_vector (1); %length of knot_vector kvsize = size(knot_vector ,2); p = 0;
302 303 304 305 306
%checking the repetitions of the first knot point while (p+2 p) %return false t = false; return endif else initial = knot_vector(i); counter = 1; endif endfor
347 348
initial = knot_vector(kvsize);
349 350 351 352 353 354
%warning of number of repetitions does not correspond with order for i=kvsize -p:kvsize if (initial != knot_vector(i)) %return false t = false;
Open AGH e-podręczniki - content available under the CC BY-SA license
242
9.1. Appendix 1
355 356 357
return endif endfor
358 359 360 361 362 363 364 365 366
%if the next knot point is different from previous ones for i=1: kvsize -1 if (knot_vector(i)>knot_vector(i+1)) %return false t = false; return endif endfor
367 368
return
369 370
endfunction
371 372 373 374 375
%the functions computes B-splines recursively according to the Cox -de -Boor function y=compute_spline(knot_vector ,p,nr ,x)
376 377 378 379 380
%function (x-x_i)/(x_{i-p}-x_i) fC= @(x,a,b) (x-a)/(b-a); %function (x_{i+p+1}-x)/(x_{i+p+1}-x_{i+1}) fD= @(x,c,d) (d-x)/(d-c);
381 382 383 384 385 386 387 388 389
%x_i a = knot_vector(nr); %x_{i-p} b = knot_vector(nr+p); %x_{i+1} c = knot_vector(nr+1); %x_{i+p+1} d = knot_vector(nr+p+1);
390 391 392 393 394 395
%linear function for p=0 if (p==0) y = 0 .* (x < a) + 1 .* (a [0-1] jj = (j-1)/(iy -1); % B^y_j(y) funy_tab(bj ,j) = compute_spline(knot_vectory ,py ,bj ,jj); end end
287 288 289
preprocess=toc tic;
290 291
% image reconstruction
292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310
% loop over functions for bi = 1:nx for bj = 1:ny % loop over nonzero pixels over given function for i=xx(knot_vectorx(bi)):xx(knot_vectorx(bi+px+1)) for j=yy(knot_vectory(bj)):yy(knot_vectory(bj+py+1)) % B^x_i(x) funi = funx_tab(bi ,i); % B^y_j(y) funj = funy_tab(bj ,j); ff = funi*funj; R1(i,j) = R1(i,j) + floor(ff*RR(bi ,bj)); G1(i,j) = G1(i,j) + floor(ff*GG(bi ,bj)); B1(i,j) = B1(i,j) + floor(ff*BB(bi ,bj)); end end end end
311 312 313 314 315
RGB=X; RGB(:,:,1) = R1; RGB(:,:,2) = G1; RGB(:,:,3) = B1;
316 317
rebuild=toc
318
Open AGH e-podręczniki - content available under the CC BY-SA license
279
9.5. Appendix 4
319
imshow(RGB);
320 321 322 323 324 325 326
% Subroutine to solve one direction as 1D problem with multiple RHS function [RR ,GG ,BB]= solve_direction(A,FR ,FG ,FB) % compute LU factorization of A matrix [L,U,P,Q] = lu(A); Q1=Q';
327 328 329 330 331 332 333 334 335 336
RR = zeros(size(FR ,1),size(FR ,2)); GG = zeros(size(FG ,1),size(FG ,2)); BB = zeros(size(FB ,1),size(FB ,2)); % loop over multiple RHS and color components for i=1: size(FR ,2) RR(:,i)=solveRHS(L,U,P,Q1 ,FR(:,i)); GG(:,i)=solveRHS(L,U,P,Q1 ,FG(:,i)); BB(:,i)=solveRHS(L,U,P,Q1 ,FB(:,i)); end
337 338
end
339 340 341 342 343 344 345 346
% Solves single RHS problem for predone LU factorization function res=solveRHS(L,U,P,Q1 ,b) y1 = L\(P*b); y2=U\y1; res=Q1\y2; end
347 348 349 350 351
% Scales [0-1] back to pixel coordinates function resx=xx(x) resx = floor ((ix -1)*x+1); end
352 353 354 355 356
% Scales [0-1] back to pixel coordinates function resy=yy(y) resy = floor ((iy -1)*y+1); end
357 358 359 360 361 362 363 364 365 366 367
% Helper subroutine for integration over bitmap function val=bitmp(M,x,y) val = zeros(size(x)); for i=1: size(x,1) for j=1: size(x,1) val(i,j)=M(xx(x(1,i)),yy(y(1,j))); end end end
368 369 370 371
% Subroutine computing order of polynomials function p=compute_p(knot_vector)
372 373 374 375 376 377
% first entry in knot_vector initial = knot_vector (1); % lenght of knot_vector kvsize = size(knot_vector ,2); p = 0;
378 379 380 381
% checking number of repetitions of first entry in knot_vector while (p+2 knot_vector(i+1)) % return FALSE t = false; return end end
443 444
return
Open AGH e-podręczniki - content available under the CC BY-SA license
281
9.5. Appendix 4
445
end
446 447 448 449
% Subroutine computing basis functions according to recursive Cox -de -Boor formulae function y=compute_spline(knot_vector ,p,nr ,x)
450 451 452 453 454
% function (x-x_i)/(x_{i-p}-x_i) fC= @(x,a,b) (x-a)/(b-a); % function (x_{i+p+1}-x)/(x_{i+p+1}-x_{i+1}) fD= @(x,c,d) (d-x)/(d-c);
455 456 457 458 459 460 461 462 463
% x_i a = knot_vector(nr); % x_{i-p} b = knot_vector(nr+p); % x_{i+1} c = knot_vector(nr+1); % x_{i+p+1} d = knot_vector(nr+p+1);
464 465 466 467 468 469
% linear function for p=0 if (p==0) y = 0 .* (x < a) + 1 .* (a = knot_point(b, high)) span = high - 1; elseif (x = knot_point(b, span + 1)) if (x < knot_point(b, span)) high = span; else low = span; endif span = floor ((low + high) / 2); endwhile endif endfunction
195 196 197 198 199 200 201 202 203 204 205 206 207 208
% Compute values at point x of (p+1) basis functions that are nonzero over the element % corresponding to specified span. % % span - span containing x, as computed by function find_span % x - point of evaluation % b - basis % % returns - vector of size (p+1) function out = evaluate_bspline_basis (span , x, b) p = b.p; out = zeros(p + 1, 1); left = zeros(p, 1); right = zeros(p, 1);
209 210 211 212 213 214
out (1) = 1; for j = 1:p left(j) = x - knot_point(b, span + 1 - j); right(j) = knot_point(b, span + j) - x; saved = 0;
215 216 217 218 219 220 221 222 223
for r = 1:j tmp = out(r) / (right(r) + left(j - r + 1)); out(r) = saved + right(r) * tmp; saved = left(j - r + 1) * tmp; endfor out(j + 1) = saved; endfor endfunction
224 225 226 227 228 229 230 231 232 233 234
% Compute values and derivatives of order up to der at point x of (p+1) basis functions % that are nonzero over the element corresponding to specified span. % % span - span containing x, as computed by function find_span % x - point of evaluation % b - basis % % returns - array of size (p+1) x (der + 1) containing values and derivatives function out = evaluate_bspline_basis_ders (span , x, b, der) p = b.p;
Open AGH e-podręczniki - content available under the CC BY-SA license
314
9.8. Appendix 5A
235 236 237 238 239
out = zeros(p + 1, der + 1); left = zeros(p, 1); right = zeros(p, 1); ndu = zeros(p + 1, p + 1); a = zeros(2, p + 1);
240 241 242 243 244 245
ndu(1, 1) = 1; for j = 1:p left(j) = x - knot_point(b, span + 1 - j); right(j) = knot_point(b, span + j) - x; saved = 0;
246 247 248 249 250 251 252 253 254
for r = 1:j ndu(j + 1, r) = right(r) + left(j - r + 1); tmp = ndu(r, j) / ndu(j + 1, r); ndu(r, j + 1) = saved + right(r) * tmp; saved = left(j - r + 1) * tmp; endfor ndu(j + 1, j + 1) = saved; endfor
255 256
out(:, 1) = ndu(:, p + 1);
257 258 259 260 261
for r = 0:p s1 = 1; s2 = 2; a(1, 1) = 1;
262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290
for k = 1:der d = 0; rk = r - k; pk = p - k; if (r >= k) a(s2 , 1) = a(s1 , 1) / ndu(pk + 2, rk + 1); d = a(s2 , 1) * ndu(rk + 1, pk + 1); endif j1 = max(-rk , 1); if (r - 1 f( xs(j), ys(i) ) % (this order is compatible with plotting functions) function vals = evaluate_on_grid(f, xs , ys) [X, Y] = meshgrid(xs , ys); vals = arrayfun(@(x, y) f([x y]), X, Y); endfunction
567 568 569 570 571 572
% Subdivide xr and yr into N equal size elements function [xs , ys] = make_grid(xr , yr , N) xs = linspace(xr(1), xr(2), N + 1); ys = linspace(yr(1), yr(2), N + 1); endfunction
573 574 575 576 577 578 579 580 581 582 583 584 585 586
% Plot 2D B-spline with coefficients u on a square given as product of xr and yr % % u - matrix of coefficients % xr , yr - intervals specifying the domain , given as two -element vectors % N - number of plot 'pixels ' in each direction % bx , by - 1D bases % % Domain given by xr and yr should be contained in the domain of the B-spline bases function surface_plot_spline(u, xr , yr , N, bx , by) [xs , ys] = make_grid(xr , yr , N); vals = evaluate_on_grid(@(x) evaluate2d(u, x, bx , by), xs , ys); surface_plot_values(vals , xs , ys); endfunction
587 588 589 590 591 592 593 594 595 596 597
% Plot arbitrary function on a square given as product of xr and yr % % f - function accepting 2D point as a two -element vector % xr , yr - intervals specifying the domain , given as two -element vectors % N - number of plot 'pixels ' in each direction function surface_plot_fun(f, xr , yr , N) [xs , ys] = make_grid(xr , yr , N); vals = evaluate_on_grid(f, xs , ys); surface_plot_values(vals , xs , ys); endfunction
598 599 600 601 602 603 604 605 606 607
% Plot array of values % % vals - 2D array of size [length(ys), length(xs)] % xs , ys - 1D arrays of coordinates function surface_plot_values(vals , xs , ys) surf(xs , ys , vals); xlabel('x'); ylabel('y'); endfunction
608 609 610 611 612
% Compute L2 -projection of f onto 1D B-spline space spanned by basis b % % f - real -valued function taking scalar argument
Open AGH e-podręczniki - content available under the CC BY-SA license
320
9.8. Appendix 5A
613 614 615 616 617 618
% b - 1D basis % % returns - vector of coefficients function u = project1d(f, b) n = number_of_dofs(b); k = b.p + 1;
619 620 621
M = sparse(n, n); F = zeros(n, 1);
622 623 624 625 626
for e = elements(b) J = jacobian1d(e, b); for q = quad_data1d(e, k, b) basis = basis_evaluator1d(q.x, b);
627 628 629 630 631 632 633
for i = dofs_on_element1d(e, b) v = basis(i); for j = dofs_on_element1d(e, b) u = basis(j); M(i + 1, j + 1) += u * v * q.w * J; endfor
634 635 636 637 638
F(i + 1) += f(q.x) * v * q.w * J; endfor endfor endfor
639 640 641
u = M \ F; endfunction
642 643 644 645 646 647 648 649 650 651 652 653 654 655
% Compute L2 -projection of f onto 2D B-spline space spanned by the tensor product % of bases bx and by % % f - real -valued function taking two -element vector argument % bx , by - 1D basis % % returns - matrix of coefficients function u = project2d(f, bx , by) nx = number_of_dofs(bx); ny = number_of_dofs(by); n = nx * ny; k = max([bx.p, by.p]) + 1; idx = @(dof) linear_index(dof , bx , by);
656 657 658
M = sparse(n, n); F = zeros(n, 1);
659 660 661 662 663
for e = elements(bx , by) J = jacobian2d(e, bx , by); for q = quad_data2d(e, k, bx , by) basis = basis_evaluator2d(q.x, bx , by);
664 665 666 667 668 669 670
for i = dofs_on_element2d(e, bx , by) v = basis(i); for j = dofs_on_element2d(e, bx , by) u = basis(j); M(idx(i), idx(j)) += u * v * q.w * J; endfor
671 672 673 674 675
F(idx(i)) += f(q.x) * v * q.w * J; endfor endfor endfor
Open AGH e-podręczniki - content available under the CC BY-SA license
321
9.8. Appendix 5A
676 677 678
u = reshape(M \ F, nx , ny); endfunction
679 680 681 682 683 684 685 686 687 688 689 690 691
% Exact solution (value and gradient) of the Eriksson -Johnson problem % % x - domain point as a vector % epsilon - diffusion coefficient function [u, du] = eriksson_exact(x, epsilon) a = pi * epsilon; del = sqrt (1 + 4 * a^2); r1 = (1 + del) / (2 * epsilon); r2 = (1 - del) / (2 * epsilon);
692
n = exp(-r1) - exp(-r2); e1 = exp(r1 * (x(1) - 1)); e2 = exp(r2 * (x(1) - 1)); c = e1 - e2; s = sin(pi * x(2));
693 694 695 696 697 698
dx = (r1 * e1 - r2 * e2) / n * s; dy = c / n * pi * cos(pi * x(2));
699 700 701 702 703 704
u = c / n * s; du = [dx , dy]; endfunction
705 706 707 708 709 710 711 712 713 714 715 716 717 718
% Integrate function over the domain of specified B-spline basis % Order quadratures is determined by orders of B-splines (p + 1). % Quadrature points are generated using the mesh defined by the basis. % % f - function accepting point as two -element vector % bx , by - 1D bases % % returns - integral of f over product of domains of bx and by function value = integrate2d(f, bx , by) k = max([bx.p by.p]) + 1;
719 720 721 722 723 724 725 726 727
value = 0; for e = elements(bx , by) J = jacobian2d(e, bx , by); for q = quad_data2d(e, k, bx , by) value += f(q.x) * q.w * J; endfor endfor endfunction
728 729 730 731 732 733 734 735 736 737 738
% % % % % % % % % %
Compute Sobolev -type norm of function on 2D domain f - function accepting point as two -element vector norm_type - function representing the norm bx , by - 1D bases Function f must return one or two output values: - value - gradient [optional] Gradient is necessary for computing higher -order norms (e.g. H1)
Open AGH e-podręczniki - content available under the CC BY-SA license
322
9.8. Appendix 5A
739 740 741 742 743 744 745 746
% % norm_type should accept function and a point , and commpute a quantity that upon being % integrated over the whole domain yields a square of the desired norm. function val = normfn(f, norm_type , bx , by) f = make_it_function(f, bx , by); val = integrate2d(@(x) norm_type(f, x), bx , by); val = sqrt(val); endfunction
747 748 749 750 751 752 753 754 755 756 757 758
% Compute difference in Sobolev -type norm of two functions on 2D domain % Avoids issues with subtracting functions returning gradient as the second output value % % f, b - function accepting point as two -element vector % norm_type - function representing the norm % bx , by - 1D bases % % See also: normfn function val = normfn_diff(f, g, norm_type , bx , by) f = make_it_function(f, bx , by); g = make_it_function(g, bx , by);
759 760 761 762
diff = @(x) minus_funs(f, g, x); val = normfn(diff , norm_type , bx , by); endfunction
763 764 765 766 767 768 769
% Integrand of L2 norm of f at point x function val = normL2(f, x) v = f(x); val = v^2; endfunction
770 771 772 773 774 775
% Integrand of H1 norm of f at point x function val = normH1(f, x) [v, dv] = f(x); val = v^2 + dot(dv , dv); endfunction
776 777 778
% Auxiliary functions
779 780 781 782 783 784 785 786 787
% f - either function handle or 2D array of coefficients of tensor product B-spline basis % % Allows using the same code for both regular functions and B-splines in the norm functions. function f = make_it_function(f, bx , by) if (~isa(f, 'function_handle ')) f = @(x) evaluate_with_grad2d(f, x, bx , by); endif endfunction
788 789 790 791 792 793
% Evaluate f and g at x, and compute the difference between all their output values % requested by the caller. Boilerplate to facilitate working with regular scalar functions % and those that also return the gradient. function varargout = minus_funs(f, g, x) n = nargout;
794 795 796
fv = cell(1, n); [fv {:}] = f(x);
797 798 799
gv = cell(1, n); [gv {:}] = g(x);
800 801
varargout = cell(1, n);
Open AGH e-podręczniki - content available under the CC BY-SA license
323
9.8. Appendix 5A
802 803 804 805
for i = 1:n varargout{i} = fv{i} - gv{i}; endfor endfunction
806 807 808 809
function error_analysis(u, exact , bx , by) bestu = project2d(exact , bx , by);
810
norm0 = normfn(exact , @normL2 , bx , by); norm1 = normfn(exact , @normH1 , bx , by);
811 812 813
err0 = normfn_diff(u, exact , @normL2 , bx , by); err1 = normfn_diff(u, exact , @normH1 , bx , by);
814 815 816
best_err0 = normfn_diff(bestu , exact , @normL2 , bx , by); best_err1 = normfn_diff(bestu , exact , @normH1 , bx , by);
817 818 819
rel0 = err0 / norm0; rel1 = err1 / norm1;
820 821 822
best_rel0 = best_err0 / norm0; best_rel1 = best_err1 / norm1;
823 824 825 826 827 828
printf('Error: printf('Best possible: endfunction
L2 %5.2f%% L2 %5.2f%%
H1 %5.2f%%\n', rel0 * 100, rel1 * 100); H1 %5.2f%%\n', best_rel0 * 100, best_rel1 * 100);
829 830 831
% Input data epsilon = 1e-2;
% diffusion coefficient
832 833 834 835
knot_trial_x = [0 0 0 1 2 2 2]; % knot vector for test space knot_test_x = [0 0 0 0 1 1 2 2 2 2]; % knot vector for test space points_x = [0 0.5 1];
836 837 838 839
knot_trial_y = [0 0 0 1 2 2 2]; % knot vector for test space knot_test_y = [0 0 0 0 1 1 2 2 2 2]; % knot vector for test space points_y = [0 0.5 1];
840 841 842 843 844 845
% Problem formulation beta = [1 0]; a = @(u, du , v, dv) epsilon * dot(du , dv) + dot(beta , du) * v; f = @(x) 0; g = @(t) sin(pi*t);
846 847
test_prod = @(u, du , v, dv) u * v + dot(du , dv);
848 849 850 851 852
% p P k
Setup = degree_from_knot(knot_trial_x); = degree_from_knot(knot_test_x); = max(p, P) + 1;
853 854
%points = linspace (0, 1, max(knot_trial) + 1);
855 856 857
bx = basis1d(p, points_x , knot_trial_x); by = basis1d(p, points_y , knot_trial_y);
858 859 860
Bx = basis1d(P, points_x , knot_test_x); By = basis1d(P, points_y , knot_test_y);
861 862 863 864
nx = number_of_dofs(bx); ny = number_of_dofs(by); n = nx * ny;
Open AGH e-podręczniki - content available under the CC BY-SA license
324
9.8. Appendix 5A
865 866 867 868
Nx = number_of_dofs(Bx); Ny = number_of_dofs(By); N = Nx * Ny;
869 870 871 872
N+n M = sparse(N + n, N + n); F = zeros(N + n, 1);
873 874 875
idx_test = @(dof) linear_index(dof , Bx , By); idx_trial = @(dof) linear_index(dof , bx , by) + N;
876 877 878 879 880 881 882
% Assemble the system - matrix and the right -hand side for e = elements(bx , by) J = jacobian2d(e, bx , by); for q = quad_data2d(e, k, bx , by) basis_trial = basis_evaluator2d(q.x, bx , by); basis_test = basis_evaluator2d(q.x, Bx , By);
883 884 885 886 887 888 889 890 891 892
% Gram matrix for i = dofs_on_element2d(e, Bx , By) [v, dv] = basis_test(i); for j = dofs_on_element2d(e, Bx , By) [u, du] = basis_test(j); val = test_prod(u, du , v, dv); M(idx_test(i), idx_test(j)) += val * q.w * J; endfor endfor
893 894 895 896 897 898 899
% Bilinear form for i = dofs_on_element2d(e, Bx , By) [v, dv] = basis_test(i); for j = dofs_on_element2d(e, bx , by) [u, du] = basis_trial(j); val = a(u, du , v, dv) * q.w * J;
900 901 902 903
M(idx_test(i), idx_trial(j)) -= val; M(idx_trial(j), idx_test(i)) += val; endfor
% B - upper right % B' - lower left
904 905 906 907 908
F(idx_test(i)) -= f(q.x) * v * q.w * J; endfor endfor endfor
909 910 911 912
% Boundary conditions fixed_trial_dofs = boundary_dofs2d(bx , by); fixed_test_dofs = boundary_dofs2d(Bx , By);
913 914 915 916 917 918 919 920
for d = fixed_test_dofs i = idx_test(d); M(i, :) = 0; M(:, i) = 0; M(i, i) = 1; F(i) = 0; endfor
921 922 923 924 925 926
for d = fixed_trial_dofs i = idx_trial(d); M(i, :) = 0; M(i, i) = 1; endfor
927
Open AGH e-podręczniki - content available under the CC BY-SA license
325
9.9. Appendix 6
928 929 930 931
u0 = project1d(g, by); for i = dofs(by) F(idx_trial ([0 i])) = u0(i + 1); endfor
932 933 934 935 936
% U r u
Solve = M \ F; = reshape(U(1:N), Nx , Ny); = reshape(U(N+1: end), nx , ny);
% residual % solution
937 938 939 940
% Plot the solution N = 50; exact = @(x) eriksson_exact(x, epsilon);
941 942 943 944 945 946 947
figure('name ', 'Solution ', 'Position ', [0 0 1000 400]); subplot (1, 2, 1); surface_plot_spline (u, [0 1], [0 1], N, bx , by); title('iGRM approximation '); zlim ([0 1.2]);
948 949 950 951 952
subplot (1, 2, 2); surface_plot_fun(exact , [0 1], [0 1], N); title('Exact solution '); zlim ([0 1.2]);
953 954 955 956
figure('name ', 'Residual ', 'Position ', [0 0 500 400]); surface_plot_spline (r, [0 1], [0 1], N, Bx , By); title('iGRM residual representation ');
957 958 959 960 961 962
% Error analysis res0 = normfn(r, @normL2 , Bx , By); res1 = normfn(r, @normH1 , Bx , By); printf('Residual norm: L2 %f H1 %f\n', res0 , res1); error_analysis(u, exact , bx , by); Listing 8: MATLAB code for solution of advection-diffusion problem (Erikkson-Johnson problem) for a given Pecklet number, using the residual minimization method.
Authors of the code in MATLAB: Marcin Łoś and Maciej Woźniak.
9.9.
Appendix 6
MATLAB code that computes the L2 bitmap projection using the adaptive finite element method (see chapter MATLAB implementation of the adaptive algorithm for the bitmap projection problem) 1 2 3 4 5 6 7 8 9 10 11
% This is a implementation of h-adaptive bitmap projection. % % How to use % % bitmap(filename as a string , number of elements along x axis , , number of elements along y axis , maximum rel % % Examples % % bitmap("mp.JPG", 10,10,0.1,3, false) % bitmap("basket.JPG", 20,20,0.5,1, true) function bitmap_h(filename ,elementsx ,elementsy ,maxerror ,max_refinement_level ,color_edges_black)
12 13 14
% read image from file XX = imread(filename);
15 16
% exctract red , green and blue components
Open AGH e-podręczniki - content available under the CC BY-SA license
326
9.9. Appendix 6
17 18 19
RR = XX(:,:,1); GG = XX(:,:,2); BB = XX(:,:,3);
20 21 22 23
% read size of image ix = size(XX ,1); iy = size(XX ,2);
24 25 26 27 28
% global count total_vertexes % global count total_elements
of vertexes = 0; of elements = 0;
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
% element structure contains: % * vertices - organized as followed: % % ul - ur % | | % dl - dr % % ul - up -left % ur - up -right % dl - down -left % dr - down -right % % * neighbours (elements) ogranized as followed % there can be up to two neighbours on each edge % default neighours (if there is one neighbour) are: % eul , elu , eru , edl % % eul eur % ___ ___ % elu | | eru % | | % eld |___ ___| erd % edl edr % % eul - element -up -left % eur - element -up -rgiht % elu - element -left -up % eld - element -left -down % eru - element -right -up % erd - element -right -down % edl - element -down -left % edr - element -down -right % % * active - we don't delete inactive elements , rather tag them as inactive % * index - index of element in global elements table % elements = struct('dl' ,{},'ul' ,{},'dr' ,{},'ur' ,{},'active ' ,{},'elu' ,{},'eld' ,{},'edl' ,{},'edr' ,{},'eul' ,{},'eu % % vertex data structure contains % * x and y coordinates % * r,g,b - red , green and blue components % * index - index of vertex in global vertexes table % * real - false if vertes is hanging node and has interpolated r,g,b components % vertexes = struct('x' ,{},'y' ,{},'r' ,{},'g' ,{},'b' ,{},'index ' ,{},'real ' ,{});
75 76 77
% initialize unbroken mesh init_mesh ();
78 79
redo_error_test = true;
Open AGH e-podręczniki - content available under the CC BY-SA license
327
9.9. Appendix 6
80
refinemenet_level = 0;
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
% repeat until we match maximum local estimation error or maximum refinemenet level while (redo_error_test && (refinemenet_level < max_refinement_level )) redo_error_test = false; % loop through elements for i=1: total_elements % check only active elements if (elements(i).active) % estimate realtive interpolation error in red , green and blue components [rr ,gg ,bb] = estimate_error(i); % if eny of the errors is higher than our maximum -> break element and repeat entire loop if ((rr >= maxerror) || (gg >= maxerror) || (bb >= maxerror)) redo_error_test = true; break_element(i); end end end refinemenet_level = refinemenet_level + 1; end
100 101 102 103 104 105 106
% interpolate all active elements - recreate bitmap red green and blue compoments for i=1: total_elements if (elements(i).active) interpolate_elem(i,color_edges_black ); end end
107 108 109 110 111 112
% recreate RGB=XX; RGB (:,:,1) RGB (:,:,2) RGB (:,:,3)
bitmap from red , green and blue compoments = RR; = GG; = BB;
113 114 115
% display image imshow(RGB);
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
% create vertex (non hanging node) function index=create_vertex(x,y) vert.x = x; vert.y = y; vert.r = RR(x,y); vert.g = GG(x,y); vert.b = BB(x,y); total_vertexes = total_vertexes + 1; vert.index = total_vertexes; vert.real = true; vertexes(total_vertexes) = vert; index = total_vertexes; end
131 132 133 134 135 136 137 138 139 140 141 142
% create vertex (hanging node) function index=create_vertex_rgb (x,y,r,g,b) vert.x = x; vert.y = y; vert.r = r; vert.g = g; vert.b = b; total_vertexes = total_vertexes + 1; vert.index = total_vertexes; vert.real = false;
Open AGH e-podręczniki - content available under the CC BY-SA license
328
9.9. Appendix 6
143 144 145
vertexes(total_vertexes) = vert; index = total_vertexes; end
146 147 148 149 150 151 152 153 154 155 156
% update vertex - when hanging node becomes non -hanging node function vert_update(index) vert = vertexes(index); vert.r = RR(vert.x,vert.y); vert.g = GG(vert.x,vert.y); vert.b = BB(vert.x,vert.y); vert.real = true; vertexes(index) = vert; end
157 158 159 160 161 162 163 164
% create initial element function element=create_element(v1 ,v2 ,v3 ,v4) element.dl = v1; element.ul = v2; element.dr = v3; element.ur = v4;
165 166
element.active = true;
167 168 169 170 171 172 173 174 175 176 177
% set all neighbours to null element.elu = 0; element.eld = 0; element.edl = 0; element.edr = 0; element.eul = 0; element.eur = 0; element.eul = 0; element.eru = 0; element.erd = 0;
178 179 180 181
total_elements = total_elements + 1; element.index = total_elements; end
182 183 184 185 186 187 188 189 190 191 192 193 194 195
% initialize mesh function init_mesh () % % vertexes mapping % % v2 -> ul % v4 -> ur % v1 -> dl % v3 -> dr % elem_width = floor(ix / elementsx); elem_hight = floor(iy / elementsy);
196 197 198
x = 0; y = 0;
199 200 201 202 203 204 205
% create all vertexes for i=0: elementsy -1 for j=0: elementsx -1 vertex = create_vertex(x+j*elem_width +1,y+1); end vertex = create_vertex(ix ,y+1);
Open AGH e-podręczniki - content available under the CC BY-SA license
329
9.9. Appendix 6
206 207 208 209 210 211
y = y + elem_hight; end for j=0: elementsx -1 vertex = create_vertex(x+j*elem_width +1,iy); end vertex = create_vertex(ix ,iy);
212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237
% crete all elements for i=1: elementsy for j=1: elementsx v1 = (i-1)*elementsy+j + i-1; v3 = v1+1; v2 = i*elementsy+j+1 + i-1; v4 = v2+1; element = create_element(v1 ,v2 ,v3 ,v4); index = element.index; % set neighbours for each element if(j~=1) element.elu = index -1; end if(j~= elementsx) element.eru = index +1; end if(i~=1) element.edl = index -elementsx; end if(i~= elementsy) element.eul = index+elementsx; end elements(index) = element; end end
238 239
end
240 241 242 243 244 245 246 247 248 249 250
% interpolate r,g,b components for hanging node % v1 and v2 are vertexes of given element on edges of broken edge % v3 is interpolated vertex between v1 and v2 function v3=interpolate_rgb(v1 ,v2 ,element) elem = elements(element); width = vertexes(elem.dr).x - vertexes(elem.dl).x; hight = vertexes(elem.ul).y - vertexes(elem.dl).y; vert1 = vertexes(v1); vert2 = vertexes(v2);
251 252 253 254 255
vert3.x vert3.y vert3.x vert3.y
= = = =
(vert1.x + vert2.x) /2; (vert1.y + vert2.y) /2; floor(vert3.x); floor(vert3.y);
256 257 258 259
xx = vert3.x - vertexes(elem.dl).x; yy = vert3.y - vertexes(elem.dl).y; [r,g,b] = inpoint(xx ,yy ,width ,hight ,elem);
260 261 262 263 264
vert3.r = r; vert3.g = g; vert3.b = b; vert3.real = false;
265 266 267 268
total_vertexes = total_vertexes + 1; vert3.index = total_vertexes; v3 = total_vertexes;
Open AGH e-podręczniki - content available under the CC BY-SA license
330
9.9. Appendix 6
269 270
vertexes(v3) = vert3; end
271 272 273 274 275 276 277 278 279 280 281
% interpolate r,g,b components of a element function interpolate_elem(element ,color_edges_black ) elem = elements(element); width = vertexes(elem.dr).x - vertexes(elem.dl).x; hight = vertexes(elem.ul).y - vertexes(elem.dl).y; width = abs(width); hight = abs(hight); dlx = vertexes(elem.dl).x; dly = vertexes(elem.dl).y;
282 283 284 285 286 287 288 289 290
for xx=0: width for yy=0: hight [r,g,b] = inpoint(xx ,yy ,width ,hight ,elem); RR(dlx+xx ,dly+yy) = r; GG(dlx+xx ,dly+yy) = g; BB(dlx+xx ,dly+yy) = b; end end
291 292 293 294 295 296 297
% create black edges on element if requested if (color_edges_black ) for xx=0: width RR(dlx+xx ,dly) = 0; GG(dlx+xx ,dly) = 0; BB(dlx+xx ,dly) = 0;
298
RR(dlx+xx ,dly+hight) = 0; GG(dlx+xx ,dly+hight) = 0; BB(dlx+xx ,dly+hight) = 0; end
299 300 301 302 303
for yy=0: hight RR(dlx ,dly+yy) = 0; GG(dlx ,dly+yy) = 0; BB(dlx ,dly+yy) = 0;
304 305 306 307 308 309 310 311 312 313 314
RR(dlx+width ,dly+yy) = 0; GG(dlx+width ,dly+yy) = 0; BB(dlx+width ,dly+yy) = 0; end end end
315 316 317 318 319 320 321 322
% computes r,g,b components of element in given point function [r,g,b]= inpoint(xx ,yy ,width ,hight ,elem) f1 = fi1(xx ,yy); f2 = fi2(xx ,yy); f3 = fi3(xx ,yy); f4 = fi4(xx ,yy);
323 324 325 326 327 328
r r r r r
= = = = =
vertexes(elem.dl).r * f1; r + vertexes(elem.ul).r * f2; r + vertexes(elem.dr).r * f3; r + vertexes(elem.ur).r * f4; floor(r);
329 330 331
g = vertexes(elem.dl).g * f1; g = g + vertexes(elem.ul).g * f2;
Open AGH e-podręczniki - content available under the CC BY-SA license
331
9.9. Appendix 6
332 333 334
g = g + vertexes(elem.dr).g * f3; g = g + vertexes(elem.ur).g * f4; g = floor(g);
335 336 337 338 339 340
b b b b b
= = = = =
vertexes(elem.dl).b * f1; b + vertexes(elem.ul).b * f2; b + vertexes(elem.dr).b * f3; b + vertexes(elem.ur).b * f4; floor(b);
341 342 343 344 345 346 347
% basis functions defined over element function ret=fi1(xx ,yy) x = xx/width; y = yy/hight; ret = (1-x) * (1-y); end
348 349 350 351 352 353
function ret=fi2(xx ,yy) x = xx/width; y = yy/hight; ret = (1-x) * y; end
354 355 356 357 358 359
function ret=fi3(xx ,yy) x = xx/width; y = yy/hight; ret = x * (1-y); end
360 361 362 363 364 365 366
function ret=fi4(xx ,yy) x = xx/width; y = yy/hight; ret = x * y; end end
367 368 369 370 371
% if neighbour is already bigger than element that we try to break - we should break it as well function break_neighbours(index) element = elements(index);
372 373 374 375 376
check_left (); check_right (); check_up (); check_down ();
377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394
function check_left () % no neighbours on the left if (element.elu == 0) return; end % two neighbours on the left if(element.eld ~= 0) return; end % only one neighbour on the left left = elements(element.elu); if (left.erd ~= 0) % neighbour on the left has two neighbours on the right break_element(element.elu); end end
Open AGH e-podręczniki - content available under the CC BY-SA license
332
9.9. Appendix 6
395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411
function check_right () % no neighbours on the right if (element.eru == 0) return; end % two neighbours on the right if (element.erd ~= 0) return; end % only one neighbour on the right right = elements(element.eru); if (right.eld ~= 0) % neighbour on the right has two neighbours on the left break_element(element.eru); end end
412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428
function check_up () % no neighbours on the top if (element.eul == 0) return; end % two neighbours on the top if (element.eur ~= 0) return; end % only one neighbour on the top up = elements(element.eul); if (up.edr ~= 0) % neighbour on the top has two neighbours on the bottom break_element(element.eul); end end
429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446
function check_down () % no neighbours on the bottom if (element.edl == 0) return; end % two neighbours on the bottom if (element.edr ~= 0) return; end % only one neighbour on the bottom down = elements(element.edl); if (down.eur ~= 0) % neighbour on the bottom has two neighbours on the top break_element(element.edl); end end end
447 448 449 450
% breaking element function break_element(index)
451 452 453 454 455 456 457
element = elements(index); if (~ element.active) disp('error !!!'); end break_neighbours(index); element = elements(index);
Open AGH e-podręczniki - content available under the CC BY-SA license
333
9.9. Appendix 6
458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482
% % % % % % % % % % % % % % % % % % % % % % % % %
vertexes of element are organized as followed ul - ur | | dl - dr they are mapped to local vertices v2 - v4 | e | v1 - v3
after breaking element vertices and new elements are organized as followed v2 | v6 | v1
- v9 e2 | - v7 e1 | - v5
- v4 e4 | - v8 e3 | - v3
e
-> e2 e4 e1 e3
v1 v2 v3 v4
= = = =
483 484 485 486 487
element.dl; element.ul; element.dr; element.ur;
488 489 490 491 492 493
v5=0; v6=0; v7=0; v8=0; v9=0;
494 495 496 497 498 499 500 501 502 503 504 505 506
% if we have two neighbours left if (element.eld ~= 0) eld = elements(element.eld); v6 = eld.ur; vert_update(v6); % if we have unbroken neighbour left else v6 = interpolate_rgb(v1 ,v2 ,index); end if (element.elu == 0) vert_update(v6); end
507 508 509 510 511 512 513 514 515 516 517 518 519
% if we have two neighbours right if (element.erd ~= 0) erd = elements(element.erd); v8 = erd.ul; vert_update(v8); % if we have unbroken neighbour right else v8 = interpolate_rgb(v3 ,v4 ,index); end if (element.eru == 0) vert_update(v8); end
520
Open AGH e-podręczniki - content available under the CC BY-SA license
334
9.9. Appendix 6
521 522 523 524 525 526 527 528 529 530 531 532
% if we have two neighbours up if (element.eur ~= 0) eur = elements(element.eur); v9 = eur.dl; vert_update(v9) % if we have unbroken neighbour up else v9 = interpolate_rgb(v2 ,v4 ,index); end if (element.eul == 0) vert_update(v9); end
533 534 535 536 537 538 539 540 541 542 543 544 545
% if we have two neighbours down if (element.edr ~= 0) edr = elements(element.edr); v5 = edr.ul; vert_update(v5); % if we have unbroken neighbour down else v5 = interpolate_rgb(v1 ,v3 ,index); end if (element.edl == 0) vert_update(v5); end
546 547 548
x = vertexes(v5).x; y = vertexes(v6).y;
549 550
v7 = create_vertex(x,y);
551 552 553
element.active = false; elements(element.index) = element;
554 555 556 557 558
e1 e2 e3 e4
= = = =
create_element(v1 ,v6 ,v5 ,v7); create_element(v6 ,v2 ,v7 ,v9); create_element(v5 ,v7 ,v3 ,v8); create_element(v7 ,v9 ,v8 ,v4);
559 560 561 562 563 564 565 566 567 568
% set neighbours between new elements e1.eru = e3.index; e1.eul = e2.index; e2.edl = e1.index; e2.eru = e4.index; e3.elu = e1.index; e3.eul = e4.index; e4.elu = e2.index; e4.edl = e3.index;
569 570 571 572 573 574 575 576 577 578 579 580 581 582 583
% set neighbours between new and old elements e1.edl = element.edl; if (element.edl ~= 0) edl = elements(element.edl); edl.eul = e1.index; elements(edl.index) = edl; end if (element.edr ~= 0) e3.edl = element.edr; edr = elements(element.edr); edr.eul = e3.index; elements(edr.index) = edr; else e3.edl = element.edl;
Open AGH e-podręczniki - content available under the CC BY-SA license
335
9.9. Appendix 6
584 585 586 587 588 589
if (element.edl ~= 0) edl = elements(element.edl); edl.eur = e3.index; elements(edl.index) = edl; end end
590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609
e2.elu = element.elu; if (element.elu ~= 0) elu = elements(element.elu); elu.eru = e2.index; elements(elu.index) = elu; end if (element.eld ~= 0) e1.elu = element.eld; eld = elements(element.eld); eld.eru = e1.index; elements(eld.index) = eld; else e1.elu = element.elu; if (element.elu ~= 0) elu = elements(element.elu); elu.erd = e1.index; elements(elu.index) = elu; end end
610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629
e2.eul = element.eul; if (element.eul ~= 0) eul = elements(element.eul); eul.edl = e2.index; elements(eul.index) = eul; end if (element.eur ~= 0) e4.eul = element.eur; eur = elements(element.eur); eur.edl = e4.index; elements(eur.index) = eur; else e4.eul = element.eul; if (element.eul ~= 0) eul = elements(element.eul); eul.edr = e4.index; elements(eul.index) = eul; end end
630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646
e4.eru = element.eru; if (element.eru ~= 0) eru = elements(element.eru); eru.elu = e4.index; elements(eru.index) = eru; end if (element.erd ~= 0) e3.eru = element.erd; erd = elements(element.erd); erd.elu = e3.index; elements(erd.index) = erd; else e3.eru = element.eru; if (element.eru ~= 0) eru = elements(element.eru); eru.eld = e3.index;
Open AGH e-podręczniki - content available under the CC BY-SA license
336
9.9. Appendix 6
647 648 649
elements(eru.index) = eru; end end
650 651 652 653 654 655
elements(e4.index) elements(e3.index) elements(e2.index) elements(e1.index) end
= = = =
e4; e3; e2; e1;
656 657 658 659 660 661 662 663 664
% estimate relative error of interpolation over given element function [error_r ,error_g ,error_b ]= estimate_error(index) element = elements(index); dl = element.dl; ul = element.ul; dr = element.dr; ur = element.ur;
665 666 667 668 669
xl yd xr yu
= = = =
vertexes(dl).x; vertexes(dl).y; vertexes(ur).x; vertexes(ur).y;
670 671 672
elementWidth = xr - xl; elementHeigth = yu - yd;
673 674 675 676 677 678
% interpolate using L2 norm and Gaussian x1 = elementWidth /2.0 - elementWidth / x2 = elementWidth /2.0 + elementWidth / y1 = elementHeigth /2.0 - elementHeigth y2 = elementHeigth /2.0 + elementHeigth
quadrature rule (sqrt (3.0) * 2.0); (sqrt (3.0) * 2.0); / (sqrt (3.0) * 2.0); / (sqrt (3.0) * 2.0);
679 680 681 682 683
x1 x2 y1 y2
= = = =
floor(x1); floor(x2); floor(y1); floor(y2);
684 685 686 687 688
[r1 ,g1 ,b1]= inpoint(x1 ,y1 ,elementWidth ,elementHeigth ,element); [r2 ,g2 ,b2]= inpoint(x1 ,y2 ,elementWidth ,elementHeigth ,element); [r3 ,g3 ,b3]= inpoint(x2 ,y1 ,elementWidth ,elementHeigth ,element); [r4 ,g4 ,b4]= inpoint(x2 ,y2 ,elementWidth ,elementHeigth ,element);
689 690 691 692
r1 = r1 - RR(x1+xl ,y1+yd); g1 = g1 - GG(x1+xl ,y1+yd); b1 = b1 - BB(x1+xl ,y1+yd);
693 694 695 696
r2 = r2 - RR(x1+xl ,y2+yd); g2 = g2 - GG(x1+xl ,y2+yd); b2 = b2 - BB(x1+xl ,y2+yd);
697 698 699 700
r3 = r3 - RR(x2+xl ,y1+yd); g3 = g3 - GG(x2+xl ,y1+yd); b3 = b3 - BB(x2+xl ,y1+yd);
701 702 703 704
r4 = r4 - RR(x2+xl ,y2+yd); g4 = g4 - GG(x2+xl ,y2+yd); b4 = b4 - BB(x2+xl ,y2+yd);
705 706 707 708
error_r = r1*r1 + r2*r2 + r3*r3 + r4*r4; error_g = g1*g1 + g2*g2 + g3*g3 + g4*g4; error_b = b1*b1 + b2*b2 + b3*b3 + b4*b4;
709
Open AGH e-podręczniki - content available under the CC BY-SA license
337
9.10. Appendix 7 error_r = double(error_r); error_g = double(error_g); error_b = double(error_b);
710 711 712 713 714 715 716 717
error_r = sqrt(error_r) * 100.0 / (255.0 * 2.0); error_g = sqrt(error_g) * 100.0 / (255.0 * 2.0); error_b = sqrt(error_b) * 100.0 / (255.0 * 2.0); end
718 719 720 721
end Listing 9: Adaptive bitmap projection.
Authors of the code in MATLAB: Marcin Łoś and Maciej Woźniak.
9.10.
Appendix 7
MATLAB code performing simulations for the alpha scheme for the two-dimensional heat transport problem (see chapter MATLAB implementation of the alpha scheme for the heat transfer problem) 1
format long;
2 3 4 5 6 7 8 9 10 11 12
% Build cartesian product of specified vectors. % Vector orientation is arbitrary. % % Order: first component changes fastest % % a1 , a2 , ... - sequence of n vectors % % returns - array of n-columns containing all the combinations of values in aj function c = cartesian(varargin) n = nargin;
13 14 15 16 17 18
[F{1:n}] = ndgrid(varargin {:}); for i = n:-1:1 c(i,:) = F{i}(:); end end
19 20 21 22 23
% Create a row vector of size n filled with val function r = row_of(val , n) r = val * ones(1, n); end
24 25 26 27 28 29 30 31 32
% Index conventions %-----------------% % DoFs % Elements % Knot elements % Linear indices -
zero -based zero -based zero -based one -based
33 34 35 36 37 38 39 40
% % % % % %
Create an one -dimensional basis object from specified data. Performs some simple input validation. For a standard , clamped B-spline basis first and last elements of the knot vector should be repeated (p+1) times.
Open AGH e-podręczniki - content available under the CC BY-SA license
338
9.10. Appendix 7
41 42 43 44 45 46 47 48 49
% p - polynomial order % points - increasing sequence of values defining the mesh % knot - knot vector containing integer indices of mesh points (starting from 0) % % returns - structure describing the basis function b = basis1d(p, points , knot) validateattributes(points , {}, {'increasing '}); validateattributes(knot , {}, {'nondecreasing '}); assert(max(knot) == length(points) - 1, sprintf('Invalid knot index: %d, points: %d)', max(knot), length(poi
50 51 52 53 54
b.p = p; b.points = points; b.knot = knot; endfunction
55 56 57 58 59
% Number of basis functions (DoFs) in the 1D basis function n = number_of_dofs(b) n = length(b.knot) - b.p - 1; endfunction
60 61 62 63 64
% Number of elements the domain is subdivided into function n = number_of_elements(b) n = length(b.points) - 1; endfunction
65 66 67 68 69
% Domain point corresponding to i-th element of the knot vector function x = knot_point(b, i) x = b.points(b.knot(i) + 1); endfunction
70 71 72 73 74 75
% Row vector containing indices of all the DoFs function idx = dofs1d(b) n = number_of_dofs(b); idx = 0 : n-1; endfunction
76 77 78 79 80 81 82 83 84 85 86 87 88 89
% Enumerate degrees of freedom in a tensor product of 1D bases % % b1 , b2 , ... - sequence of n 1D bases % % returns - array of indices (n-columns) of basis functions function idx = dofs(varargin) if (nargin == 1) idx = dofs1d(varargin {:}); else ranges = cellfun(@(b) dofs1d(b), varargin , 'UniformOutput ', false); idx = cartesian(ranges {:}); endif endfunction
90 91 92 93 94 95
% Row vector containing indices of all the elements function idx = elements1d(b) n = number_of_elements(b); idx = 0 : n-1; endfunction
96 97 98 99 100 101 102 103
% Enumerate element indices for a tensor product of 1D bases % % b1 , b2 , ... - sequence of n 1D bases % % returns - array of indices (n-columns) of element indices function idx = elements(varargin) if (nargin == 1)
Open AGH e-podręczniki - content available under the CC BY-SA license
339
9.10. Appendix 7
104 105 106 107 108 109
idx = elements1d(varargin {:}); else ranges = cellfun(@(b) elements1d(b), varargin , 'UniformOutput ', false); idx = cartesian(ranges {:}); endif endfunction
110 111 112 113 114
% Index of the first DoF that is non -zero over the specified element function idx = first_dof_on_element(e, b) idx = lookup(b.knot , e) - b.p - 1; endfunction
115 116 117 118 119 120 121 122 123
% Row vector containing indices of DoFs that are non -zero over the specified element % % e - element index (scalar) % b - 1D basis function idx = dofs_on_element1d(e, b) a = first_dof_on_element(e, b); idx = a : a + b.p; endfunction
124 125 126 127 128 129 130 131 132 133
% Row vector containing indices (columns) of DoFs that are non -zero over the specified element % % e - element index (pair) % bx , by - 1D bases function idx = dofs_on_element2d(e, bx , by) rx = dofs_on_element1d(e(1), bx); ry = dofs_on_element1d(e(2), by); idx = cartesian(rx , ry); endfunction
134 135 136 137 138 139 140 141 142 143
% Compute 1-based , linear index of tensor product DoF. % Column -major order - first index component changes fastest. % % dof - n-tuple index % b1 , b2 ,, ... - sequence of n 1D bases % % returns - linearized scalar index function idx = linear_index(dof , varargin) n = length(varargin);
144 145 146 147 148 149
idx = dof(n); for i = n-1 : -1 : 1 ni = number_of_dofs(varargin{i}); idx = dof(i) + idx * ni; endfor
150 151 152
idx += 1; endfunction
153 154 155 156 157
% Assuming clamped B-spline basis , compute the polynomial order based on the knot function p = degree_from_knot(knot) p = find(knot > 0, 1) - 2; endfunction
158 159 160 161 162 163 164 165 166
% Create a knot without interior repeated nodes % % elems - number of elements to subdivide domain into % p - polynomial degree function knot = simple_knot(elems , p) pad = ones(1, p); knot = [0 * pad , 0:elems , elems * pad]; endfunction
Open AGH e-podręczniki - content available under the CC BY-SA license
340
9.10. Appendix 7
167 168 169 170 171
% Spline evaluation functions are based on: % % The NURBS Book , L. Piegl , W. Tiller , Springer 1995
172 173 174 175 176 177
% Find index i such that x lies between points corresponding to knot(i) and knot(i+1) function span = find_span(x, b) low = b.p + 1; high = number_of_dofs(b) + 1;
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194
if (x >= knot_point(b, high)) span = high - 1; elseif (x = knot_point(b, span + 1)) if (x < knot_point(b, span)) high = span; else low = span; endif span = floor ((low + high) / 2); endwhile endif endfunction
195 196 197 198 199 200 201 202 203 204 205 206 207 208
% Compute values at point x of (p+1) basis functions that are nonzero over the element % corresponding to specified span. % % span - span containing x, as computed by function find_span % x - point of evaluation % b - basis % % returns - vector of size (p+1) function out = evaluate_bspline_basis (span , x, b) p = b.p; out = zeros(p + 1, 1); left = zeros(p, 1); right = zeros(p, 1);
209
out (1) = 1; for j = 1:p left(j) = x - knot_point(b, span + 1 - j); right(j) = knot_point(b, span + j) - x; saved = 0;
210 211 212 213 214 215 216 217 218 219 220 221 222 223
for r = 1:j tmp = out(r) / (right(r) + left(j - r + 1)); out(r) = saved + right(r) * tmp; saved = left(j - r + 1) * tmp; endfor out(j + 1) = saved; endfor endfunction
224 225 226 227 228 229
% % % % %
Compute values and derivatives of order up to der at point x of (p+1) basis functions that are nonzero over the element corresponding to specified span. span x
- span containing x, as computed by function find_span - point of evaluation
Open AGH e-podręczniki - content available under the CC BY-SA license
341
9.10. Appendix 7
230 231 232 233 234 235 236 237 238 239
% b - basis % % returns - array of size (p+1) x (der + 1) containing values and derivatives function out = evaluate_bspline_basis_ders (span , x, b, der) p = b.p; out = zeros(p + 1, der + 1); left = zeros(p, 1); right = zeros(p, 1); ndu = zeros(p + 1, p + 1); a = zeros(2, p + 1);
240 241 242 243 244 245
ndu(1, 1) = 1; for j = 1:p left(j) = x - knot_point(b, span + 1 - j); right(j) = knot_point(b, span + j) - x; saved = 0;
246 247 248 249 250 251 252 253 254
for r = 1:j ndu(j + 1, r) = right(r) + left(j - r + 1); tmp = ndu(r, j) / ndu(j + 1, r); ndu(r, j + 1) = saved + right(r) * tmp; saved = left(j - r + 1) * tmp; endfor ndu(j + 1, j + 1) = saved; endfor
255 256
out(:, 1) = ndu(:, p + 1);
257 258 259 260 261
for r = 0:p s1 = 1; s2 = 2; a(1, 1) = 1;
262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290
for k = 1:der d = 0; rk = r - k; pk = p - k; if (r >= k) a(s2 , 1) = a(s1 , 1) / ndu(pk + 2, rk + 1); d = a(s2 , 1) * ndu(rk + 1, pk + 1); endif j1 = max(-rk , 1); if (r - 1 f( xs(j), ys(i) ) % (this order is compatible with plotting functions) function vals = evaluate_on_grid(f, xs , ys) [X, Y] = meshgrid(xs , ys); vals = arrayfun(@(x, y) f([x y]), X, Y); endfunction
539 540 541 542 543 544
% Subdivide xr and yr into N equal size elements function [xs , ys] = make_grid(xr , yr , N) xs = linspace(xr(1), xr(2), N + 1); ys = linspace(yr(1), yr(2), N + 1); endfunction
Open AGH e-podręczniki - content available under the CC BY-SA license
346
9.10. Appendix 7
545 546 547 548 549 550 551 552 553 554 555 556 557 558
% Plot 2D B-spline with coefficients u on a square given as product of xr and yr % % u - matrix of coefficients % xr , yr - intervals specifying the domain , given as two -element vectors % N - number of plot 'pixels ' in each direction % bx , by - 1D bases % % Domain given by xr and yr should be contained in the domain of the B-spline bases function surface_plot_spline(u, xr , yr , N, bx , by) [xs , ys] = make_grid(xr , yr , N); vals = evaluate_on_grid(@(x) evaluate2d(u, x, bx , by), xs , ys); surface_plot_values(vals , xs , ys); endfunction
559 560 561 562 563 564 565 566 567 568
% Plot array of values % % vals - 2D array of size [length(ys), length(xs)] % xs , ys - 1D arrays of coordinates function surface_plot_values(vals , xs , ys) surf(xs , ys , vals); xlabel('x'); ylabel('y'); endfunction
569 570 571 572 573 574 575 576 577 578 579 580 581 582 583
% Compute L2 -projection of f onto 2D B-spline space spanned by the tensor product % of bases bx and by % % f - real -valued function taking two -element vector argument % bx , by - 1D basis % % returns - matrix of coefficients function u = project2d(f, bx , by) nx = number_of_dofs(bx); ny = number_of_dofs(by); n = nx * ny; k = max([bx.p, by.p]) + 1; idx = @(dof) linear_index(dof , bx , by);
584 585 586
M = sparse(n, n); F = zeros(n, 1);
587 588 589 590 591
for e = elements(bx , by) J = jacobian2d(e, bx , by); for q = quad_data2d(e, k, bx , by) basis = basis_evaluator2d(q.x, bx , by);
592 593 594 595 596 597 598
for i = dofs_on_element2d(e, bx , by) v = basis(i); for j = dofs_on_element2d(e, bx , by) u = basis(j); M(idx(i), idx(j)) += u * v * q.w * J; endfor
599 600 601 602 603
F(idx(i)) += f(q.x) * v * q.w * J; endfor endfor endfor
604 605 606
u = reshape(M \ F, nx , ny); endfunction
607
Open AGH e-podręczniki - content available under the CC BY-SA license
347
9.10. Appendix 7
608 609 610 611 612 613 614 615 616 617 618
% Auxiliary function saving plot to a file with name including iteration number function save_plot(u, iter , bx , by) N = 50; h = figure('visible ', 'off'); surface_plot_spline(u, [0 1], [0 1], N, bx , by); zlim ([0 0.8]); saveas(h, sprintf('out_%d.png', iter)); endfunction
619 620 621 622 623 624 625
% Input data knot = simple_knot (5, 2); dt = 0.01; alpha = 0.5; K = 20;
% % % %
knot vector time step size scheme parameter (0 - explicit Euler , 1 - implicit Euler , 1/2 - Crank -Nicolson number of time steps
626 627 628 629
% Problem formulation f = @(t, x) 1; init_state = @(x) 0;
630 631 632 633
% Setup p = degree_from_knot(knot); k = p + 1;
634 635
points = linspace (0, 1, max(knot) + 1);
636 637 638
bx = basis1d(p, points , knot); by = basis1d(p, points , knot);
639 640 641 642
nx = number_of_dofs(bx); ny = number_of_dofs(by); n = nx * ny;
643 644 645
M = sparse(n, n); F = zeros(n, 1);
646 647
idx = @(dof) linear_index(dof , bx , by);
648 649 650 651 652 653
% Assemble the matrix for e = elements(bx , by) J = jacobian2d(e, bx , by); for q = quad_data2d(e, k, bx , by) basis = basis_evaluator2d(q.x, bx , by);
654 655 656 657 658 659 660 661 662 663 664
for i = dofs_on_element2d(e, bx , by) [v, dv] = basis(i); for j = dofs_on_element2d(e, bx , by) [u, du] = basis(j); val = u * v + dt * alpha * dot(du , dv); M(idx(i), idx(j)) += val * q.w * J; endfor endfor endfor endfor
665 666 667 668
% Modify the matrix to account for uniform Dirichlet boundary conditions fixed_dofs = boundary_dofs2d(bx , by); [M, F] = dirichlet_bc_uniform(M, F, fixed_dofs , bx , by);
669 670
% Put the initial state into u
Open AGH e-podręczniki - content available under the CC BY-SA license
348
9.Bibliography
671
u = project2d(init_state , bx , by);
672 673 674
% Plot the initial state save_plot(u, 0, bx , by);
675 676 677 678 679
% Time stepping loop for m = 1:K t = m * dt; printf('Iter %d, t = %f\n', m, t);
680 681 682 683 684 685 686
% Assemble the right -hand side F(:) = 0; for e = elements(bx , by) J = jacobian2d(e, bx , by); for q = quad_data2d(e, k, bx , by) basis = basis_evaluator2d(q.x, bx , by);
687
% u - solution from the previous time step [U, dU] = evaluate_with_grad2d (u, q.x, bx , by); fval = alpha * f(t, q.x) + (1 - alpha) * f(t - dt , q.x);
688 689 690 691
for i = dofs_on_element2d(e, bx , by) [v, dv] = basis(i);
692 693 694 695 696 697 698 699
rhs = U * v - dt * (1 - alpha) * dot(dU , dv) + dt * fval; F(idx(i)) += rhs * q.w * J; endfor endfor endfor
700 701 702 703 704
% Impose boundary conditions for d = fixed_dofs F(idx(d)) = 0; endfor
705 706 707
% Solve u = reshape(M \ F, nx , ny);
708 709 710
% Plot the solution save_plot(u, m, bx , by);
711 712
endfor Listing 10: MATLAB code solving two-dimensional heat transfer problem with the alpha scheme.
Authors of the code in MATLAB: Marcin Łoś and Maciej Woźniak.
The publication is available under the Creative Commons Attribution-ShareAlike 4.0 license. Certain rights reserved to the authors and the AGH University of Krakow. Any use of the publication is permitted, provided that the authors and the AGH University of Krakow are credited, providing a link to the publication and information about the license along with the link https://creativecommons.org/licenses/by-sa/4.0/deed.pl. Document generation date: 2024/09/25 20:30:00
Bibliography [1]
Hrennikoff Alexander. “Solution of problems of elasticity by the framework method”. In: Journal of Applied Mechanics (1941). URL: http : / / webcache . googleusercontent . com / search ? q =
Open AGH e-podręczniki - content available under the CC BY-SA license
349
9.Bibliography cache:5jnjhdmMmaIJ:www.erpublications.com/sitepanel/download.php%253Ffilename% 253Ddownload/download_07_05_2016_18_17_34.pdf+&cd=1&hl=en&ct=clnk&gl=pl. [2]
Courant R. “Variational methods for the solution of problems of equilibrium and vibrations”. In: Bulletin of the American Mathematical Society (1943). URL: https : //www.ams.org/journals/bull/1943-49-01/S0002-9904-1943-07818-4/home.html.
[3]
Lax Peter. “Feng Kand”. In: (1993). URL: http://lsec.cc.ac.cn/fengkangprize/article2.pdf.
[4]
Zienkiewicz Olgierd. “The birth of the finite element method and of computational mechanics”. In: International Journal for Numerical Methods in Engineering (2004). URL: https://onlinelibrary.wiley.com/doi/abs/10.1002/nme.951.
[5]
Cottrell J. Austin, Hughes T. J. R., Bazilevs Yuri. Isogeometric Analysis: Toward Integration of CAD and FEA. Computational: John Wiley & Sons, 2009. URL: https : / / www . wiley . com / en - sg / Isogeometric+Analysis%253A+Toward+Integration+of+CAD+and+FEA-p-9780470748732.
[6]
Demkowicz Leszek. Computing with hp-Adaptive Finite Elements, Vol. I. One and Two Dimensional Elliptic and Maxwell Problems. CRC Press: Taylor & Francis, 2006. URL: https://www.crcpress. com/Computing-with-hp-ADAPTIVE-FINITE-ELEMENTS-Volume-1-One-and-Two-Dimensional/ Demkowicz/p/book/9781584886716.
[7]
Demkowicz Leszek, Kurtz Jason, Pardo David, Paszyński Maciej, Rachowicz Waldemar, Zdunek Adam A. Computing with hp-Adaptive Finite Elements, Vol. II. Frontiers: Three Dimensional Elliptic and Maxwell Problems with Applications. CRC Press: Taylor & Francis, 2007. URL: https://www.crcpress.com/Computing-with-hp-ADAPTIVE-FINITE-ELEMENTS-VolumeII - Frontiers - Three - Dimensional / Demkowicz - Kurtz - Pardo - Paszenski - Rachowicz Zdunek/p/book/9781584886723.
[8]
Johannessen Kjetil Andre, Kvamsdal Trond, Dokken Tor. “Isogeometric analysis using LR B-splines”. In: Computer Methods in Applied Mechanics and Engineering (2014). URL: https://www.sciencedirect.com/science/article/pii/S0045782513002417.
[9]
Schoenberg Isaac Jacob. Cardinal Spline Interpolation. SIAM: Society for Industrial, 1973. URL: https://books.google.pl/books?printsec=frontcover&vid=LCCN74159921.
[10]
Boor Carl de. “On Calculating with B-splines”. In: Journal of Approximation Theory (1972). URL: https://web.stanford.edu/class/cme324/classics/deboor.pdf.
[11]
Garcia Daniel, Pardo David, Dalcin Lisandro, Paszyński Maciej, Collier Nathan, Calo Victor Manuel. “The value of continuity: Refined isogeometric analysis and fast direct solvers”. In: Computer Methods in Applied Mechanics and Engineering (2017). URL: https://www.sciencedirect.com/science/ article/pii/S0045782516309586.
[12]
Donea J., Huerta J. Finite Element Methods for Flow Problems. Wiley, 2003. URL: https://onlinelibrary.wiley.com/doi/book/10.1002/0470013826. (accessed: 18.10.2019).
[13]
Wang C. Y. “Exact solutions of the steady-state Navier-Stokes equations”. In: Annual Review of Fluid Mechanics (1991). URL: https://www.annualreviews.org/doi/abs/10.1146/annurev.fl.23. 010191.001111. (accessed: 18.10.2019).
[14]
Hughes T. J. R. Linear static and dynamic finite element method. Dover, 2000. URL: https : / / store.doverpublications.com/0486411818.html. (accessed: 18.10.2019).
[15]
Gauss Johann Carl Friedrich. “Methodus nova integralium valores per approximationem inveniendi”. In: Comm. Soc. Sci. Göttingen Math. Band (1826). URL: https://gallica.bnf.fr/ark:/12148/ bpt6k2412190.r=Gauss.langEN. (accessed: 18.10.2019).
[16]
Chan J., Evans J. A. “A minimal-residual finite element method for the convection-diffusion equations”. In: ICES-REPORT 13-12 (2013). URL: https : / / www . oden . utexas . edu / media / reports/2013/1312.pdf. (accessed: 14.4.2020).
Open AGH e-podręczniki - content available under the CC BY-SA license
350
9.Bibliography [17]
Grcar Joseph, Demmel James, Gu Ming. The History of Gaussian Elimination. University of Berkeley, 2010. URL: https : / / math . berkeley . edu / ~mgu / Seminar / Fall2010 / Sept08 _ 2010 . pdf. (accessed: 10.18.2019).
[18]
Bunch James, Hopcroft John. “Triangular Factorization and Inversion by Fast Matrix Multiplication”. In: Mathematics of Computation (1974). URL: https://www.ams.org/journals/mcom/1974-28125/S0025-5718-1974-0331751-8/home.html. (accessed: 10.18.2019).
[19]
Irons Bruce. “A Frontal Solution Program for Finite Element Analysis”. In: International Journal for Numerical Methods in Engineering (1970). URL: https://onlinelibrary.wiley.com/doi/abs/ 10.1002/nme.1620020104. (accessed: 18.10.2019).
[20]
Duff Ian, Reid John. “The Multifrontal Solution of Indefinite Sparse Symmetric Linear”. In: ACM Transactions on Mathematical Software (TOMS) (1987). URL: https://dl.acm.org/citation. cfm?doid=356044.356047. (accessed: 18.10.2019).
[21]
Jr. Jim Douglas, Rachford H. H. “On the Numerical Solution of Heat Conduction Problems in Two and Three Space Variables”. In: Transactions of American Mathematical Society (1956). URL: https : / / www . ams . org / journals / tran / 1956 - 082 - 02 / S0002 - 9947 - 1956 - 0084194 4/home.html. (accessed: 10.18.2019).
[22]
Gao Longfei, Calo Victor Manuel. “Fast Isogeometric Solvers for Explicit Dynamics”. In: Computer Methods in Applied Mechanics and Engineering (2014). URL: https://www.sciencedirect.com/ science/article/pii/S004578251400036X. (accessed: 10.18.2019).
[23]
Saad Yousef. Iterative Methods for Sparse Linear Systems. Society for Industrial, 2003. URL: https: //www-users.cs.umn.edu/~saad/IterMethBook_2ndEd.pdf. (accessed: 18.10.2019).
[24]
Babuśka Ivo. “Error-Bounds for Finite Element Method”. In: Numerische Mathematik (1971). URL: https://link.springer.com/article/10.1007/BF02165003. (accessed: 18.10.2019).
[25]
Brezzi Franco. “On the Existence, Uniqueness and Approximation of Saddle-Point Problems Arising form Lagrange Multipliers”. In: R.A.I.R.O. (1974). URL: http://www.numdam.org/article/M2AN_ 1974__8_2_129_0.pdf. (accessed: 18.10.2019).
[26]
Demkowicz Leszek. “Babuśka Brezzi”. In: (2006). URL: https://www.oden.utexas.edu/ media/reports/2006/0608.pdf. (accessed: 18.10.2019).
[27]
Hughes T.J.R., Franca L.P., Mallet M. “A new finite element formulation for fluid dynamics: VI. Convergence analysis of the generalized SUPG formulation for linear time-dependent multidimensional advective–diffusive systems”. In: Computer Methods in Applied Mechanics and Engineering (1987). URL: https://www.sciencedirect.com/science/article/pii/0045782587901253. (accessed: 18.10.2019).
[28]
Pietro Daniele Antoni Di, Ern Alexandre. “Mathematical Aspects of Discontinuous Galerkin Methods”. In: (2011). URL: https://www.springer.com/gp/book/9783642229794. (accessed: 18.10.2019).
[29]
Demkowicz Leszek, Gopalakrishnan Jay. “Discontinuous Petrov–Galerkin (DPG) Method. Part 2. Fundamentals”. In: (2017). URL: https://doi.org/10.1002/9781119176817.ecm2105. (accessed: 18.10.2019).
[30]
Chan J., Evans J. A. A minimum-residual finite element method for the convection-diffusion equations. USA, 2013. URL: https://www.oden.utexas.edu/media/reports/2013/1312.pdf. (accessed: 18.10.2019).
[31]
Hughes T. J. R., Franca L. P., Mallet M. “A new finite element formulation for computational fluid dynamics: VI. Convergence analysis of the generalized SUPG formulation for linear time-dependent multidimensional advective-diffusive systems”. In: Computer Methods in Applied Mechanics and Engineering (1987). URL: https : / / www . sciencedirect . com / science / article / pii / 0045782587901253.
Open AGH e-podręczniki - content available under the CC BY-SA license
351
9.Bibliography [32]
Chan J., Evans J. A. “A minimum residual finite-element method for advection-diffusion equations”. In: The University of Texas at Austin (2013). URL: https : / / www . oden . utexas . edu / media / reports/2013/1312.pdf.
[33]
Delaunay Boris. “Sur la sphère vide”. In: Bulletin de l’Académie des Sciences de l’URSS Classe des Sciences Mathématiques et Naturelles (1934). URL: http : / / www . mathnet . ru / php / archive . phtml ? wshow = paper % 5C & jrnid = im % 5C & paperid = 4937 % 5C & option _ lang = eng. (accessed: 18.10.2019).
[34]
Shewchuk Jonathan Richard. Lecture Notes on Delaunay Mesh Generation. Berkeley, 2012. URL: https://people.eecs.berkeley.edu/~jrs/meshpapers/delnotes.pdf. (accessed: 18.10.2019).
[35]
Rivara Maria. “New longest-edge algorithms for the refinement and/or improvement of unstructured triangulations”. In: International Journal for Numerical Methods in Engineering (1997). URL: https: //onlinelibrary.wiley.com/doi/abs/10.1002/%5C(SICI%5C)1097-0207%5C(19970930%5C) 40:18%5C%3C3313AID-NME214%5C%3E3.0.CO;2-%5C#. (accessed: 18.10.2019).
[36]
Ainsworth Mark, Oden John Tinsley. “A posteriori error estimation in finite element analysis”. In: Computer Methods in Applied Mechanics and Engineering (1997). URL: https : / / www . oden . utexas.edu/sites/oden/wp-content/uploads/2013/06/1997-006.a_posteriori.pdf. (accessed: 29.03.2020).
[37]
Babuśka Ivo, Szabo B., Katz I. N. “The p-version of the Finite Element Method”. In: (1981). URL: https://doi.org/10.1137/0718033.
[38]
Babuška Ivo, Guo B. Q. “The hp-version of the finite element method, part 1”. In: Computational Mechanics (1986). URL: https : / / apps . dtic . mil / dtic / tr / fulltext / u2 / a260197 . pdf. (accessed: 18.10.2019).
[39]
Babuška Ivo, Guo B. Q. “The hp-version of the finite element method, part 2”. In: Computational Mechanics (1986). URL: https : / / apps . dtic . mil / dtic / tr / fulltext / u2 / a260197 . pdf. (accessed: 18.10.2019).
[40]
Demkowicz Leszek, Oden J. T., Rachowicz Waldemar, Hardy Oliver. “Toward a universal h-p adaptive finite element strategy, part 1. Constrained approximation and data structure”. In: Computer Methods in Applied Mechanics and Engineering 77.1–2 (1989), pp. 79–112. URL: https : / / doi . org / 10 . 1016/0045-7825(89)90129-1.
[41]
Sederberg Thomas W., Zheng Jianmin, Bakenov Almaz, Nasri Ahmad. “T-splines and T-NURCCS”. In: ACM Transactions on Graphics (2003). URL: https://dl.acm.org/citation.cfm?id=882295. (accessed: 18.10.2019).
[42]
Sederberg Thomas W. “System and method for defining T-spline and T-NURCC surfaces using local refinements”. In: US Patent (2003). URL: https://patents.google.com/patent/US7274364B2/ en. (accessed: 18.10.2019).
[43]
Bazilevs Y., Calo V. M., Cottrell J. A., Evans J. A., Hughes T. J. R., Lipton S., Scott M. A., Sederberg T. W. “Isogeometric analysis using T-splines”. In: Computer Methods in Applied Mechanics and Engineering (2010). URL: https://hal.archives-ouvertes.fr/hal-01517950/document. (accessed: 18.10.2019).
[44]
Veiga L. Beirao da, Buffa A., Sangalli G., Vazquez R. “Analysis-suitable T-splines of arbitrary degree: definition and properties”. In: Mathematical Models and Methods in Applied Sciences 23.11 (2013). URL: http://www-dimat.unipv.it/sangalli/AS_DC_high_order.pdf. (accessed: 20.12.2020).
[45]
Paszynska A., Paszynski M. “Computational Costs of Multi-Frontal Direct Solvers with Analysis-Suitable T-Splines”. In: Symmetry 12.12 (2013). URL: https://www.mdpi.com/20738994/12/12/2070/htm. (accessed: 20.12.2020).
Open AGH e-podręczniki - content available under the CC BY-SA license
352
9.Bibliography [46]
Ascher U. M., Ruuth S. J., Spiteri R. J. “Implicit-Explicit Runge-Kutta Methods for Time-Dependent Partial Differential Equations”. In: Applied Numerical Mathematics (1997). URL: http : //citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.48.1525&rep=rep1&type=pdf. (accessed: 18.10.2018).
[47]
Łoś Marcin, Woźniak Maciej, Paszyński Maciej, Lenharth Andrew, Hassan Muhamm Amber, Pingali Keshav. “IGA-ADS: Isogeometric analysis FEM using ADS solver”. In: Computer & Physics Communications (2017). URL: https : / / www . sciencedirect . com / science / article / pii / S0010465517300759. (accessed: 18.10.2019).
[48]
Guermond Jean-Luc, Minev Petar. “A new class of massively parallel direction splitting for the incompressible Navier–Stokes equations”. In: (2011). URL: https : / / www . sciencedirect . com / science/article/pii/S0045782511000429.
[49]
Courant Richard, Friedrichs Kurt Otto, Lewy Hans. “Über die partiellen Differenzengleichungen der mathematischen Physik”. In: Mathematische Annalen (in German) (1928). URL: https : / / link . springer.com/article/10.1007/BF01448839. (accessed: 18.10.2019).
[50]
Crank John, Nicolson Phyllis. “A practical method for numerical evaluation of solutions of partial differential equations of the heat conduction type”. In: Mathematical Proceedings of the Cambridge Philosophical Society 43 (1947), pp. 50–67. URL: http://doi.org/10.1017/S0305004100023197. accessed: 18.10.2019.
[51]
Euler Leonhard. Foundations of Differential Calculus. New York: Springer, 2000. URL: https : / / link.springer.com/book/10.1007%252Fb97699. accessed: 18.10.2019.
[52]
Crank John, Nicolson Phyllis. “A practical method for numerical evaluation of solutions of partial differential equations of the heat-conduction type”. In: Mathematical Proceedings of the Cambridge Philosophical Society 43 (1947), pp. 50–67. URL: http://doi.org/10.1017/S0305004100023197. accessed: 18.10.2019.
[53]
Oliver A., Montero G., Montenegro R., Rodríguez E., Escobar J. M., Pérez-Foguet A. “Adaptive finite element simulation of stack pollutant emissions over complex terrains”. In: Energy 43 (2012), pp. 421–431. URL: http : / / www . sciencedirect . com / science / article / pii / S0360544212008316. accessed: 18.10.2019.
[54]
Siwik Leszek, Woźniak Maciej, Łoś Marcin, Paszyński Maciej. “Fast and green parallel isogeometric analysis computations for multi-objective optimization of liquid fossil fuel reserve exploitation with minimal groundwater contamination”. In: Journal of Parallel and Distributed Computing 129 (2019), pp. 38–50. URL: https : / / www . sciencedirect . com / science / article / abs / pii / S0743731518306890. accessed: 18.10.2019.
[55]
Ciarlet Pierre. The Finite Element Method for Elliptic Problems. North Holland, 1978. URL: https: //www.elsevier.com/books/the-finite-element-method-for-elliptic-problems/ciarlet/ 978-0-444-85028-7. (accessed: 06.04.2020).
[56]
Demkowicz Leszek. Two-Dimensional hp Adaptive Finite Element Method for Elliptic and Maxwell Problems. Taylor & Francis, 2007. URL: https : / / www . crcpress . com / Computing - with - hp ADAPTIVE-FINITE-ELEMENTS-Volume-1-One-and-Two-Dimensional/Demkowicz/p/book/ 9781584886716. (accessed: 06.04.2020).
[57]
Demkowicz Leszek. “Babuśka ⇔Brezzi?” In: ICES Report (2006). URL: https : / / www . oden . utexas.edu/media/reports/2006/0608.pdf. (accessed: 06.04.2020).
Open AGH e-podręczniki - content available under the CC BY-SA license
353