NiHu  2.0
Working with quadratures

Introduction

The purpose of this tutorial is to explain how you can work with quadratures in NiHu.

Defining and traversing a Gaussian quadrature

1D example

Quadratures are used to perform numerical integration over intrinsic domains. The most common regular quadratures in finite and boundary element methods are Gaussian quadratures. A Gaussian quadrature can be defined by specialising the template class NiHu::gaussian_quadrature with a specific domain class, and providing a quadrature order to the constructor:

In the above example, a line quadrature is created that integrates over the domain \( -1 \le \xi \le +1\) with a 7-th order quadrature. A 7-th order quadrature can accurately integrate polynomials of order up to 7. For the case of Gaussian quadratures, an \( n \)-th order quadrature consists of \( (n+1)/2 \) quadrature points.

A quadrature is a standard container of NiHu::quadrature_elem instances, where each NiHu::quadrature_elem contains a base point and a weight. As a consequence, a quadrature can be traversed using standard C++ traversing methods. For example, the quadrature locations and weights can be printed as

for (auto q : quadrature)
std::cout << q.get_xi() << '\t' << q.get_w() << '\n';

or, equivalently:

for (auto it = quadrature.begin(); it != quadrature.end(); ++it)
std::cout << it->get_xi() << '\t' << it->get_w() << '\n';

and the result reads as:

-0.861136   0.347855
-0.339981   0.652145
0.339981    0.652145
0.861136    0.347855

2D example

2 and 3-dimensional quadratures, as well as quadratures over triangles are defined similarly:

for (auto q : quad2)
std::cout << q.get_xi().transpose() << '\t' << q.get_w() << '\n';

with the output

-0.861136 -0.861136 0.121003
-0.861136 -0.339981 0.226852
-0.861136  0.339981 0.226852
-0.861136  0.861136 0.121003
-0.339981 -0.861136 0.226852
-0.339981 -0.339981 0.425293
-0.339981  0.339981 0.425293
-0.339981  0.861136 0.226852
 0.339981 -0.861136 0.226852
 0.339981 -0.339981 0.425293
0.339981 0.339981   0.425293
0.339981 0.861136   0.226852
 0.861136 -0.861136 0.121003
 0.861136 -0.339981 0.226852
0.861136 0.339981   0.226852
0.861136 0.861136   0.121003
NiHu::gaussian_quadrature< NiHu::line_domain >