BSplinebasis
Loading...
Searching...
No Matches
numerical.h
1/*
2 * This file contains an additional numerical integration routine for the
3 * Splines based on the Gauss-Legendre routines in boost/math/quadrature.
4 *
5 * ########################################################################
6 * The contents of this file is free and unencumbered software released into the
7 * public domain. For more information, please refer to <http://unlicense.org/>
8 * ########################################################################
9 */
10
11#ifndef BSPLINE_INTEGRATION_NUMERICAL_H
12#define BSPLINE_INTEGRATION_NUMERICAL_H
13
14#include <bspline/Spline.h>
15#include <bspline/exceptions/BSplineException.h>
16#include <bspline/internal/misc.h>
17
18#include <boost/math/quadrature/gauss.hpp>
19
20namespace bspline::integration {
21using namespace boost::math::quadrature;
23using namespace bspline::exceptions;
24
44template <size_t ordergl, typename T, typename F, size_t order1, size_t order2>
47 // Will also check whether the two grids are equivalent.
48 const Support newSupport = m1.getSupport().calcIntersection(m2.getSupport());
49 const size_t nintervals = newSupport.numberOfIntervals();
50
51 T result = static_cast<T>(0);
52 for (size_t interv = 0; interv < nintervals; interv++) {
53 const auto ai = newSupport.absoluteFromRelative(interv);
54 const auto m1Index = m1.getSupport().intervalIndexFromAbsolute(ai).value();
55 const auto m2Index = m2.getSupport().intervalIndexFromAbsolute(ai).value();
56
57 const T &xstart = m1.getSupport().at(m1Index);
58 const T &xend = m1.getSupport().at(m1Index + 1);
59 const T xm = (xstart + xend) / static_cast<T>(2);
60 const auto &c1 = m1.getCoefficients().at(m1Index);
61 const auto &c2 = m2.getCoefficients().at(m2Index);
63 [&c1, &c2, &xm, &f](const T &x) {
64 using namespace bspline::internal;
65 return f(x) * evaluateInterval(x, c1, xm) *
66 evaluateInterval(x, c2, xm);
67 },
68 xstart, xend);
69 }
70 return result;
71}
72} // namespace bspline::integration
73#endif // BSPLINE_INTEGRATION_NUMERICAL_H
Represents a global Grid.
Definition Grid.h:27
const T & at(size_t i) const
Gives access to the i-th element of the Grid.
Definition Grid.h:218
Represents the Spline's Support.
Definition Support.h:33
Exceptions and error codes.
Definition BSplineException.h:19
Integration routines for Splines.
Definition BilinearForm.h:21
T integrate(const F &f, const bspline::Spline< T, order1 > &m1, const bspline::Spline< T, order2 > &m2)
Calculates matrix element of user-provided function.
Definition numerical.h:45