23#ifndef VULPES_QUADRATURE_FRUGAL_HPP_
24#define VULPES_QUADRATURE_FRUGAL_HPP_
50template <
typename FloatType, std::
size_t Dim>
52 Eigen::Matrix<FloatType, -1, -1>,
53 Eigen::Matrix<FloatType, -1, -1>,
54 Eigen::Matrix<FloatType, Dim, -1>>
58 const std::size_t n_pts =
vmath::pow(order + 1, Dim);
61 Eigen::Matrix<FloatType, -1, -1> vandermondeT(n_monomials, n_pts);
62 Eigen::Matrix<FloatType, Dim, -1> pts(Dim, n_pts);
64 for (std::size_t j = 0; j < n_pts; ++j) {
67 for (std::size_t d = 0; d < Dim; ++d) {
69 gl_rule.nodes[order - (idx % (order + 1))].point[0]);
72 for (std::size_t i = 0; i < n_monomials; ++i) {
75 for (std::size_t d = 0; d < Dim; ++d) {
81 Eigen::ColPivHouseholderQR<
decltype(vandermondeT)> qr(vandermondeT);
82 Eigen::Matrix<FloatType, -1, -1> Q = qr.householderQ();
83 Eigen::Matrix<FloatType, -1, -1> R =
84 qr.matrixQR().template triangularView<Eigen::Upper>();
85 Eigen::VectorXi permutationIndices = qr.colsPermutation().indices();
86 Eigen::Matrix<FloatType, -1, -1> R_truncated =
87 R.block(0, 0, n_monomials, n_monomials);
88 Eigen::Matrix<FloatType, Dim, -1> pts_truncated =
89 pts(Eigen::placeholders::all, permutationIndices.head(n_monomials));
91 return std::tuple(Q, R_truncated, pts_truncated);
95template <
typename FloatType,
typename IndexType, std::
size_t Dim>
98 using MatrixType = Eigen::Matrix<FloatType, -1, -1>;
99 using QRType = std::tuple<MatrixType, MatrixType, MatrixType>;
100 static std::vector<QRType> s_vandermonde_collection;
101 static std::vector<bool> s_vandermonde_collection_built;
102 assert(integrals.dim() > 0);
103 const std::size_t order = integrals.dim() - 1;
104 if (s_vandermonde_collection.size() <= order) {
105 s_vandermonde_collection.resize(order + 1);
106 s_vandermonde_collection_built.resize(order + 1,
false);
108 if (!s_vandermonde_collection_built[order]) {
109 s_vandermonde_collection_built[order] =
true;
110 s_vandermonde_collection[order] =
113 const auto& [Q, R, pts] = s_vandermonde_collection[order];
114 const Eigen::Map<
const Eigen::Vector<FloatType, -1>> integral_map(
115 integrals.begin(), integrals.numel());
116 assert(integrals.numel() == pts.cols());
117 const Eigen::Vector<FloatType, -1> y =
118 R.template triangularView<Eigen::Upper>().solve(
119 Q.transpose() * integral_map);
123 for (int64_t i = 0; i < pts.cols(); ++i) {
124 std::array<FloatType, Dim> pt;
125 for (std::size_t d = 0; d < Dim; ++d) {
128 rule.
nodes.emplace_back(pt, y(i));
std::conditional_t< Dim==2, TriMatrix< Simplex, false, DataType, IndexType, const DataType * >, std::conditional_t< Dim==3, TetraTensor< Simplex, false, DataType, IndexType, const DataType * >, const DataType * > > SimplexDataView
Definition tensor.hpp:507
Definition monomial.hpp:44
std::array< T, Dim > getMonomial(std::size_t n)
Computes the Dim-D monomial exponents for a given linear index.
Definition monomial.hpp:199
std::tuple< Eigen::Matrix< FloatType, -1, -1 >, Eigen::Matrix< FloatType, -1, -1 >, Eigen::Matrix< FloatType, Dim, -1 > > vandermondeDecomposition(std::size_t order)
Definition frugal.hpp:55
qrule::QuadratureRule< FloatType, Dim > computeFrugalQuadrature(datastructure::SimplexDataView< Dim, true, FloatType, IndexType > integrals)
Definition frugal.hpp:96
QuadratureRule1Dmp gmpGaussLegendreQuadrature(std::size_t n, std::size_t precision)
Computes a Gauss-Legendre quadrature rule with arbitrary precision.
Definition gauss.cpp:41
V to(const U &src)
Converts a value of one pseudo-arithmetic type to another.
Definition vmath.hpp:321
constexpr T binomial(T n, T k)
Definition vmath.hpp:386
constexpr U pow(U base, V exp, U result=U(1))
Computes the power of a number.
Definition vmath.hpp:171
Definition cell_manager.hpp:38
Represents a quadrature rule consisting of a set of points and associated weights.
Definition qrule.hpp:69
std::size_t degree
Polynomial degree of accuracy of the rule.
Definition qrule.hpp:73
std::vector< QuadraturePoint< T, Dim > > nodes
List of quadrature points.
Definition qrule.hpp:71