-
Notifications
You must be signed in to change notification settings - Fork 67
/
legendre_body.hpp
36 lines (30 loc) 路 1.1 KB
/
legendre_body.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#pragma once
#include "numerics/legendre.hpp"
#include "base/macros.hpp"
namespace principia {
namespace numerics {
namespace internal_legendre {
// Apparently, FORCE_INLINE has to be on the definition for it to work on
// namespace-level functions.
template<int degree_, template<typename, typename, int> class Evaluator>
FORCE_INLINE(constexpr)
PolynomialInMonomialBasis<double, double, degree_, Evaluator>
LegendrePolynomial() {
using Pn = PolynomialInMonomialBasis<double, double, degree_, Evaluator>;
if constexpr (degree_ == 0) {
return Pn(std::make_tuple(1));
} else if constexpr (degree_ == 1) {
return Pn({0, 1});
} else {
constexpr int n = degree_;
// NOTE(phl): Would like to make this declaration constexpr, but the type is
// not a literal type.
PolynomialInMonomialBasis<double, double, 1, Evaluator> const
multiplier({0, 2 * n - 1});
return (multiplier * LegendrePolynomial<degree_ - 1, Evaluator>() -
(n - 1) * LegendrePolynomial<degree_ - 2, Evaluator>()) / n;
}
}
} // namespace internal_legendre
} // namespace numerics
} // namespace principia