23#ifndef VULPES_FE_FE_SPACES_FE_MODAL_SIMPLEX_HPP_
24#define VULPES_FE_FE_SPACES_FE_MODAL_SIMPLEX_HPP_
46 const T& x, std::size_t alpha, std::size_t beta, std::size_t N) {
47 const std::size_t alpha_1 = alpha + 1;
48 const std::size_t beta_1 = beta + 1;
49 const std::size_t alpha_beta_1 = alpha_1 + beta;
50 const T alpha_beta_1_T = T(alpha_beta_1);
52 const T gamma0 = T(
vmath::pow(2, alpha_beta_1)) / alpha_beta_1_T *
57 return jacobi_old_old;
60 const T alpha_1_beta_1_T = T(alpha_1 * beta_1);
61 const T alpha_beta_2_T = T(alpha_beta_1 + 1);
62 const T alpha_beta_3_T = T(alpha_beta_1 + 2);
65 const T gamma1 = alpha_1_beta_1_T / alpha_beta_3_T * gamma0;
67 (alpha_beta_2_T * x / 2 + (T(alpha) - T(beta)) / 2) /
vmath::sqrt(gamma1);
73 _2 / alpha_beta_2_T *
vmath::sqrt(T(alpha_1_beta_1_T / alpha_beta_3_T));
75 for (std::size_t i = 0; i < N - 1; ++i) {
76 const std::size_t h1 = 2 * (i + 1) + alpha + beta;
77 const T h1_2_T = T(h1 + 2);
78 const T anew = _2 / h1_2_T *
80 T(T((i + 2) * (i + 2 + alpha + beta) * (i + 2 + alpha) *
82 T(h1 + 1) / T(h1 + 3)));
83 const T bnew = -(T(alpha * alpha) - T(beta * beta)) / T(h1) / h1_2_T;
85 jacobi = (1 / anew) * (-aold * jacobi_old_old + (x - bnew) * jacobi_old);
88 jacobi_old_old = jacobi_old;
101 const Eigen::Vector<T, 2>& ab,
const std::array<std::size_t, 2>& ij) {
102 const T h1 =
jacobiP(ab[0], 0, 0, ij[0]);
103 const T h2 =
jacobiP(ab[1], 2 * ij[0] + 1, 0, ij[1]);
113 const Eigen::Vector<T, 3>& abc,
const std::array<std::size_t, 3>& ijk) {
114 const T h1 =
jacobiP(abc[0], 0, 0, ijk[0]);
115 const T h2 =
jacobiP(abc[1], 2 * ijk[0] + 1, 0, ijk[1]);
116 const T h3 =
jacobiP(abc[2], 2 * (ijk[0] + ijk[1]) + 2, 0, ijk[2]);
126inline Eigen::Vector<T, 2>
rs2ab(
const Eigen::Vector<T, 2>& rs) {
128 return {T(-1), rs[1]};
130 return {2 * (1 + rs[0]) / (T(1) - rs[1]) - 1, rs[1]};
137inline Eigen::Vector<T, 3>
rst2abc(
const Eigen::Vector<T, 3>& rst) {
138 const T a = (rst[1] + rst[2] != T(0))
139 ? 2 * (1 + rst[0]) / (-rst[1] - rst[2]) - 1
141 const T b = (rst[2] != T(1)) ? 2 * (1 + rst[1]) / (1 - rst[2]) - 1 : T(-1);
142 return {a, b, rst[2]};
149template <
typename T, std::
size_t Dim>
151 if constexpr (Dim == 1) {
153 }
else if constexpr (Dim == 2) {
155 }
else if constexpr (Dim == 3) {
158 static_assert(Dim * 0 &&
"evalSimplex not implemented for this Dim");
166template <
typename T, std::
size_t Dim>
168 const std::vector<Eigen::Vector<T, Dim>>& nodes,
169 const std::function<T(
const Eigen::Vector<T, Dim>&)>& f,
171 using MatrixType = Eigen::Matrix<T, -1, -1>;
173 MatrixType vandermonde = MatrixType::Ones(nodes.size(), n_monomials);
174 assert(vandermonde.cols() <= vandermonde.rows());
175 for (std::size_t j = 0; j < n_monomials; ++j) {
177 for (std::size_t i = 0; i < nodes.size(); ++i) {
178 const auto& pt = nodes[i];
179 for (std::size_t d = 0; d < Dim; ++d) {
180 vandermonde(i, j) *=
vmath::pow(pt[d], exps[d]);
184 Eigen::Vector<T, -1> evals(nodes.size());
185 for (std::size_t i = 0; i < nodes.size(); ++i) {
186 evals(i) = f(nodes[i]);
189 Eigen::ColPivHouseholderQR<MatrixType> qr_decomp(vandermonde);
190 const Eigen::Vector<T, -1> coef = qr_decomp.solve(evals);
192 const Eigen::Vector<T, -1> res = vandermonde * coef - evals;
193 assert(res.norm() < 1e-30);
203template <std::
size_t Dim,
typename DofPolicy>
208 FeSpaceModalP<Dim, DofPolicy>> {
218 for (std::size_t i = 0; i < basis_size; ++i) {
220 const auto sum = std::accumulate(exp.begin(), exp.end(), 0);
222 std::max(sum + 1, 2));
223 std::vector<Eigen::Vector<internal::real_t, Dim>> nodes;
224 constexpr double delta = 0.1;
225 for (
const auto& pt : nodes_mpq) {
227 pt.template cast<mpf_class>().array() /
234 [&](
const Eigen::Vector<internal::real_t, Dim>& x) {
239 m_polys.emplace_back(coef.size());
240 for (int64_t mono_id = 0; mono_id < coef.size(); ++mono_id) {
242 const std::array<std::size_t, Dim> exps =
248 const auto c_clip =
vmath::abs(c) < 1e-30 ? 0.0 : c;
249 m_polys.back().coef(args...) = c_clip;
258 template <
typename CellType>
272template <std::
size_t Dim>
FeSpaceBase(std::size_t order)
Definition fe_space.hpp:85
internal::real_t real_t
Definition fe_space.hpp:82
constexpr std::size_t order() const
Definition fe_space.hpp:149
Modal FE Space on simplex elements.
Definition fe_modal_simplex.hpp:208
polynomial::NdPolynomial< internal::real_t, Dim > Polynomial
Definition fe_modal_simplex.hpp:210
static constexpr auto getMapping(const CellType &cell)
Definition fe_modal_simplex.hpp:259
const auto & getBasis() const
Definition fe_modal_simplex.hpp:256
FeSpaceModalP(std::size_t order)
Definition fe_modal_simplex.hpp:211
std::vector< Polynomial > m_polys
Definition fe_modal_simplex.hpp:265
Definition fe_expr_base.hpp:58
T simplex2DP(const Eigen::Vector< T, 2 > &ab, const std::array< std::size_t, 2 > &ij)
Evaluate the 2D modal basis functions on simplex elements in barycentric coordinates.
Definition fe_modal_simplex.hpp:100
mpf_class real_t
Definition fe_space.hpp:188
Eigen::Vector< T, 2 > rs2ab(const Eigen::Vector< T, 2 > &rs)
Map from (r,s) to (a,b) coordinates for 2D simplex.
Definition fe_modal_simplex.hpp:126
Eigen::Vector< T, -1 > interpolateFunctionAtNodes(const std::vector< Eigen::Vector< T, Dim > > &nodes, const std::function< T(const Eigen::Vector< T, Dim > &)> &f, std::size_t deg)
Interpolate a function f at given nodes in the Dim-simplex and return the coefficients of the interpo...
Definition fe_modal_simplex.hpp:167
T evalSimplex(const Eigen::Vector< T, Dim > &x, std::size_t n)
Evaluate the modal basis function of index n at point x in the Dim-simplex.
Definition fe_modal_simplex.hpp:150
T simplex3DP(const Eigen::Vector< T, 3 > &abc, const std::array< std::size_t, 3 > &ijk)
Evaluate the 3D modal basis functions on simplex elements in barycentric coordinates.
Definition fe_modal_simplex.hpp:112
T jacobiP(const T &x, std::size_t alpha, std::size_t beta, std::size_t N)
Evaluate the Jacobi Polynomial of degree N and parameters (alpha,beta) at point x.
Definition fe_modal_simplex.hpp:45
Eigen::Vector< T, 3 > rst2abc(const Eigen::Vector< T, 3 > &rst)
Map from (r,s,t) to (a,b,c) coordinates for 3D simplex.
Definition fe_modal_simplex.hpp:137
Definition dof_policy.hpp:45
geometry::Cell< Dim, double, int32_t > CellType
Definition fe_expr_base.hpp:41
FeSpaceModalP< Dim, DofPolicyFeSpaceDP< Dim > > FeSpaceModalLegendreDP
Modal DiscontinuousLegendre FE Space on simplex elements with optimal conditioning for simplex elemen...
Definition fe_modal_simplex.hpp:273
std::array< T, 2 > getMonomial2D(std::size_t n)
Computes the 2D monomial exponents for a given linear index.
Definition monomial.hpp:132
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::array< T, 3 > getMonomial3D(std::size_t n)
Computes the 3D monomial exponents for a given linear index.
Definition monomial.hpp:177
std::conditional_t< Dim==1, Polynomial< T >, std::conditional_t< Dim==2, Polynomial2D< T, IsSpaceP >, Polynomial3D< T, IsSpaceP > > > NdPolynomial
wrapper for dense polynomials in 1D, 2D and 3D
Definition ndpolynomial.hpp:41
T gamma(const T &value)
Definition vmath.hpp:358
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
T abs(const T &value)
Computes the absolute value of a number.
Definition vmath.hpp:192
T sqrt(const T &value)
Definition vmath.hpp:201
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
static std::vector< Point< real_t, Dim > > computeNodes(std::size_t n_pts)
Definition fe_lagrange_simplex.hpp:48