Fundamentals Integration
Fundamentals Integration
Quadrature
Tutorials
May 15, 2024
Welcome to the tutorial on the fundamentals of the Nektar++ framework where we will
look at how to perform 1D and 2D Gaussian Quadrature using the Nektar++ LibUtilities
library. If you have not already downloaded and installed Nektar++, please do so
by visiting http://www.nektar.info, where you can also find the User-Guide with the
instructions on how to install the library.
• Nektar++ compiled libraries and include files compiled from source so additional
code can be compiled with the framework libraries
Goals
• The concept of Gaussian integration using classical Gauss and Gauss-Lobatto rules
in a standard interval ξ ∈ [−1, 1];
3
4 Chapter 1 Introduction
Task 1.1
Prepare for the tutorial. Make sure that you have:
– CMakeList.txt
– LocIntegration2D.cpp
– StdIntegration1D.cpp
– StdIntegration2D.cpp
• Change to the
fundamentals-integration/tutorial
directory and configure the tutorial examples for compilation by typing
the command
cmake -DCMAKE_PREFIX_PATH=$NEKDIST/build .
• Change to the
$NEKDIST/tutorial/fundamentals-integration/complete
directory and configure the completed version of the tutorial examples
for compilation by again typing the command
cmake -DCMAKE_PREFIX_PATH=$NEKDIST/build
where u(ξ) may well be made up of products of polynomial bases. Since the form of u(ξ)
is problem specific, we need an automated way to evaluate such integrals. This suggests
the use of numerical integration or quadrature. The fundamental building block is the
approximation of the integral by a finite summation of the form
Z 1 q−1
X
u(ξ)dξ ≈ wi u(ξi ),
−1 i=0
Gaussian quadrature is a particularly accurate method for treating integrals where the
integrand, u(ξ), is smooth. In this technique the integrand is represented as a Lagrange
polynomial using the q points ξi , which are to be specified, that is,
q−1
X
u(ξ) = u(ξi )hi (ξ) + ε(u), (2.2)
i=0
where ε(u) is the approximation error. If we substitute equation (2.2) into (2.1) we
obtain a representation of the integral as a summation:
5
6 Chapter 2 Integration on a one-dimensional standard region
Z 1 q−1
X
u(ξ)dξ = wi u(ξi ) + R(u), (2.3)
−1 i=0
where
Z 1
wi = hi (ξ)dξ, (2.4)
−1
Z 1
R(u) = ε(u)dξ. (2.5)
−1
Equation (2.4) defines the weights wi in terms of the integral of the Lagrange polynomial
but to perform this integration we need to know the location of the abscissae or zeros
ξi . Since u(ξ) is represented by a polynomial of order (q − 1) we would expect the
relation above to be exact if u(ξ) is a polynomial of order (q − 1) or less [that is, when
u(ξ) ∈ Pq−1 ([−1, 1]) then R(u) = 0]. This would be true if, for example, we choose the
points so that they are equispaced in the interval. There is, however, a better choice of
zeros which permits exact integration of polynomials of higher order than (q − 1). This
remarkable fact was first recognised by Gauss and is at the heart of Gaussian quadrature.
We here consider only the result of the Gauss quadrature for integrals of the type shown
in equation (2.3) known as Legendre integration. There are three different types of
Gauss quadrature known as Gauss, Gauss-Radau, and Gauss-Lobatto, respectively. The
difference between the three types of quadrature lies in the choice of the zeros. Gauss
quadrature uses zeros which have points that are interior to the interval, −1 < ξi < 1 for
i = 0, . . . , q − 1. In Gauss-Radau the zeros include one of the end-points of the interval,
usually ξ = −1, and in Gauss-Lobatto the zeros include both end points of the interval,
that is, ξ = ±1.
α,β
Introducing ξi,P to denote the P zeros of the P th order Jacobi polynomial PPα,β such
that
PPα,β (ξi,P
α,β
) = 0, i = 0, 1, . . . , P − 1,
where
α,β α,β
ξ0,P < ξ1,P < · · · < ξPα,β
−1,P ,
Z 1 q−1
X
u(ξ)dξ = wi u(ξi ) + R(u),
−1 i=0
as:
2.1 Gaussian Quadrature 7
(1) Gauss-Legendre
0,0
ξi = ξi,q i = 0, . . . , q − 1
−2
2 d
wi0,0 = (Lq (ξ))|ξ=ξi i = 0, . . . , q − 1
[1 − (ξi )2 ] dξ
(2) Gauss-Radau-Legendre
−1
i=0
ξi =
ξ 0,1
i = 1, . . . , q − 1
i−1,q−1
(1 − ξi )
wi0,0 = i = 0, . . . , q − 1
q [Lq−1 (ξi )]2
2
(3) Gauss-Lobatto-Legendre
−1 i=0
ξi = 1,1
ξi−1,q−2 i = 1, . . . , q − 2
1 i=q−1
2
wi0,0 = i = 0, . . . , q − 1
q(q − 1)[Lq−1 (ξi )]2
R(u) = 0 if u(ξ) ∈ P2q−3 ([−1, 1])
In all of the above quadrature formulae Lq (ξ) is the Legendre polynomial (Lq (ξ) = Pq0,0 (ξ)).
α,β
The zeros of the Jacobi polynomial ξi,m do not have an analytic form and commonly
the zeros and weights are tabulated. Tabulation of data can lead to copying errors and
therefore a better way to evaluate the zeros is by the use of a numerical algorithm (see
the appendix in “Spectral/hp element methods for CFD”).
Chapter 3
Computational Exercises
In this first exercise we will demonstrate how to integrate the function f (ξ) = ξ 12 on
the standard segment ξ ∈ [−1, 1] using Gaussian quadrature. The Gaussian quadrature
weights and zeros are coded in the LIbUtilities library and for future reference this
can be found under the directory $NEKDIST/library/LibUtilities/Foundations/ .
For the following exercises we will access the zero and points from the PointsManager.
The PointsManager is a type of map (or manager) which requires a key defining known
Gaussian quadrature types called PointsKey.
Task 3.1
Implement a short block of code where you see the comments
“Write your code here” which evaluates the loop
Z 1 i<Q
X max
f (ξ)dξ ≃ wi f (zi ).
−1 i=0
make StdIntegation1D
8
3.1 One dimensional integration in a standard segment 9
in the tutorial directory. When your code compiles successfully1 then type
./StdIntegration1D
======================================================
| INTEGRATION ON A 1D STANDARD REGION |
======================================================
Integrate the function f(xi) = xi^12 on the standard
segment xi=[-1,1] with Gaussian quadrature
Q = 4: Error = 0.179594
Task 3.2
Evaluate the previous integral for a quadrature order of Q = Qmax where
Qmax = 7 is the number of quadrature points required for an exact evaluation
of the integral (calculate this value analytically). Verify that the error is zero
(up to numerical precision).
L i b U t i l i t i e s : : PointsType quadPointsType =
L i b U t i l i t i e s : : eGaussGaussLegendre ;
with
L i b U t i l i t i e s : : PointsType quadPointsType =
L i b U t i l i t i e s : : eGaussLobattoLegendre ;
Task 3.3
Evaluate the previous integral for a quadrature order of Q = Qmax where
Qmax = 7 and 8 to verify that to exactly integrate with Gauss-Lobatto type
integration you require an additional quadrature point and weights.
1
If you are unable to get your code to compile you can see a completed exercise in the
$NEKDIST/tutorial/fundamentals-integration/completed directory. The tutorial code is contained
within a #if WITHSOLUTION block
10 Chapter 3 Computational Exercises
where q1 and q2 are the number of quadrature points in the ξ1 and ξ2 directions. This
expression will be exact if u(ξ1 , ξ2 ) is a polynomial and q1 , q2 are chosen appropriately.
To numerically evaluate this expression the summation over ‘i’ must be performed q1
times at every ξ2i point, that is,
Z 1 −1
qX
u(ξ1 , ξ2 ) dξ1 dξ2 ≃ wi f (ξ1i ),
Q2 i=0
2 −1
qX
f (ξ1i ) = wj u(ξ1i , ξ2j ).
j=0
Task 3.4
Integrate the function f (ξ1 , ξ2 ) = ξ112 ξ214 on the standard quadrilateral element
Q ∈ [−1, 1] × [−1, 1] using Gaussian quadrature.
Using a series of one-dimensional Gaussian quadrature rules as outlined above
evaluate the integral by completing the first part of the code in the file
StdIntegration2D.cpp in the directory
$NekDist/tutorial/fundamentals-integration/tutorial .
The quadrature weights and zeros in each of the coordinate directions have
already been setup and are initially set to q1 = 6, q2 = 7 using a Gauss-Lobatto-
Legendre quadrature rule. Complete the code by writing a structure of loops
which implement the two-dimensional Gaussian quadrature rulea . The expected
output is given below). Also verify that the error is zero when q1 = 8, q2 = 9.
Recall that to compile the file you type
make StdIntegration2D
a
If you need help there is a completed version in the completed directory
3.2 Two-dimensional integration in a standard and local region 11
When executing the tutorial with the quadrature order q1 = 6, q2 = 7 you should get an
output of the form:
=============================================================
| INTEGRATION ON 2 DIMENSIONAL ELEMENTS |
=============================================================
Figure 3.1 To construct a C 0 expansion from multiple elements of specified shapes (for example,
triangles or rectangles), each elemental region Ωe is mapped to a standard region Ωst in which all
local operations are evaluated.
For elemental shapes with straight sides a simple mapping may be constructed using a
linear mapping similar to the vertex modes of a hierarchical/modal expansion. For the
straight-sided quadrilateral with vertices labeled as shown in figure 3.1(b) the mapping
can be defined as:
(1 − ξ1 ) (1 − ξ2 ) (1 + ξ1 ) (1 − ξ2 )
xi = χi (ξ1 , ξ2 ) = xA
i + xB i
2 2 2 2
(1 − ξ 1 ) (1 + ξ 2 ) (1 + ξ 1 ) (1 + ξ 2 )
+xD
i + xC
i . i = 1, 2 (3.1)
2 2 2 2
where J2D is the two-dimensional Jacobian due to the transformation, defined as:
∂x1 ∂x1
∂ξ1 ∂ξ2 ∂x1 ∂x2 ∂x1 ∂x2
J2D = ∂x2 ∂x2 = − . (3.2)
∂ξ1 ∂ξ2 ∂ξ2 ∂ξ1
∂ξ1 ∂ξ2
As we have assumed that we know the form of the mapping [i.e., x1 = χ1 (ξ1 , ξ2 ),
x2 = χ2 (ξ1 , ξ2 )] we can evaluate all the partial derivatives required to determine the
Jacobian. If the elemental region is straight-sided then we have seen that a mapping
from (x1 , x2 ) → (ξ1 , ξ2 ) is given by equations (3.1).
Task 3.5
We now consider how to integrate the function f (x1 , x2 ) = x12 14
1 x2 on a local
rectangular quadrilateral element using Gaussian quadrature. Consider the
local quadrilateral element with vertices
(xA A
1 , x2 ) = (0, −1), (xB B
1 , x2 ) = (1, −1),
(xC C
1 , x2 ) = (1, 1), (xD D
1 , x2 ) = (0, 0).
In the file LocIntegration2D.cpp you are provided with the same set up
as the previous task but now with a definition of the coordinate mapping
included. Evaluate the expression for the Jacobian analytically. Then write
a line of code in the loop for the Jacobian as indicated by the comments
“Write your code here” . When you have written your expression you can
compile the code with the command
make LocIntegration2D
Verify that the error is not equal to zero when q1 = 8, q2 = 9. Why might this
be the case?a .
a
Hint: What is the function in terms of ξ1 , ξ2 and what is the polynomial degree of the
Jacobian?
3.2 Two-dimensional integration in a standard and local region 13
Using the quadrature order specified in the file your output should look like:
===========================================================
| INTEGRATION ON 2D ELEMENT in Local Region |
===========================================================
• Use the PointsManager with a PointsKey to get hold of quadrature weights and
zeros.
14