Vulpes  0.1.0
Versatile and parallel compUtational Library for high-order discontinuous Polytopal Element Simulations
Loading...
Searching...
No Matches
fe_modal_tensor.hpp
Go to the documentation of this file.
1// ----------------------------------------------------------------------
2//
3// Copyright (C) 2024 - 2026 by the Vulpes authors.
4// This file is part of Vulpes.
5//
6// Vulpes is free software; you can redistribute it and/or modify
7// it under the terms of the GNU General Public License as published by
8// the Free Software Foundation, either version 3 of the License, or
9// (at your option) any later version.
10//
11// Vulpes is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14// General Public License for more details.
15//
16// You should have received a copy of the GNU General Public License
17// along with Vulpes. If not, see <http://www.gnu.org/licenses/>.
18//
19// ----------------------------------------------------------------------
20
21// Author: Matteo Caldana <matteo.caldana@polimi.it>
22
23#ifndef VULPES_FE_FE_SPACES_FE_MODAL_TENSOR_HPP_
24#define VULPES_FE_FE_SPACES_FE_MODAL_TENSOR_HPP_
25
26#include <vector>
27
32
33namespace vulpes {
34namespace fe {
35
41template <std::size_t Dim, typename DofPolicy, bool EnableScaling = false>
43 Dim,
44 internal::real_t,
45 DofPolicy,
46 FeSpaceModalQ<Dim, DofPolicy, EnableScaling>> {
47 public:
48 inline static constexpr bool needBasisScaling() {
49 return (Dim == 3 && EnableScaling);
50 }
51
52 using Polynomial =
56 explicit FeSpaceModalQ(std::size_t order)
58 Dim,
60 DofPolicy,
61 FeSpaceModalQ<Dim, DofPolicy, EnableScaling>>(order) {
63
64 const auto n_basis_func = vmath::binomial(order + Dim, Dim);
65 assert(
66 (Dim == 1 && n_basis_func == (order + 1)) ||
67 (Dim == 2 && n_basis_func == (order + 1) * (order + 2) / 2) ||
68 (Dim == 3 &&
69 n_basis_func == (order + 1) * (order + 2) * (order + 3) / 6));
70
71 const auto legendre_q =
73 // pass from exact representation to approximate one
74 std::vector<Polynomial1D> legendre(legendre_q.size());
75 std::transform(
76 legendre_q.begin(), legendre_q.end(), legendre.begin(),
77 [](const auto& p) { return p.template to<internal::real_t>(); });
78
79 // loop on each element of the cartesian product of 1D polynomials
80 // such that the sum of the 1D degrees is smaller than size
81 for (std::size_t i = 0; i < n_basis_func; ++i) {
82 const std::array<std::size_t, Dim> cart_idx =
84 std::array<const Polynomial1D*, Dim> comps_1d;
85 // `1.0 / vmath::pow(2.0, Dim)` has exact double representation
86 internal::real_t normalization = 1.0 / vmath::pow(2.0, Dim);
87 for (std::size_t d = 0; d < Dim; ++d) {
88 comps_1d[d] = &legendre[cart_idx[d]];
89 normalization *= internal::real_t(2 * cart_idx[d] + 1);
90 }
91 // add the cartesian product of elements indicated by
92 // the cartesian index `cart_idx`
93 m_polys.emplace_back(comps_1d);
94 if (Dim == 2) {
95 // we match Lymph implementation but unit norm is not really needed
96 // since it does not hold on the polygon but only on the bbox
97 m_polys.back() *= internal::real_t(::sqrt(normalization));
98 }
99 }
100
101 for (const auto& p : m_polys) {
102 m_polys_fast.push_back(p.template to<double>());
103 }
104 }
105
106 // constraint on cell shape (simplex, tensor, general)
107 inline static constexpr FeType elemType() { //
108 return FeType::Poly;
109 };
110
111 template <typename CellType>
112 inline static constexpr auto getMapping(const CellType& cell) {
113 return geometry::CartesianMapping<double, Dim>{cell.bbox()};
114 };
115
122
123 const auto& getBasis() const { return m_polys; }
124 const auto& getBasisFast() const { return m_polys_fast; }
125
126 protected:
127 std::vector<Polynomial> m_polys;
128 std::vector<PolynomialFast> m_polys_fast;
129};
130
134template <std::size_t Dim, bool EnableScaling = false>
137
138} // namespace fe
139} // namespace vulpes
140
141#endif // VULPES_FE_FE_SPACES_FE_MODAL_TENSOR_HPP_
constexpr std::size_t order() const
Definition fe_space.hpp:149
Modal FE Space on polytopal elements (tensor product of Legendre polynomials on the bounding box)....
Definition fe_modal_tensor.hpp:46
std::vector< PolynomialFast > m_polys_fast
Definition fe_modal_tensor.hpp:128
static constexpr auto getMapping(const CellType &cell)
Definition fe_modal_tensor.hpp:112
static constexpr geometry::CellInitOptionsType cellInitOptions()
Definition fe_modal_tensor.hpp:116
FeSpaceModalQ(std::size_t order)
Definition fe_modal_tensor.hpp:56
std::vector< Polynomial > m_polys
Definition fe_modal_tensor.hpp:127
const auto & getBasisFast() const
Definition fe_modal_tensor.hpp:124
static constexpr FeType elemType()
Definition fe_modal_tensor.hpp:107
polynomial::SparsePolynomial< Dim, uint8_t, double, false > PolynomialFast
Definition fe_modal_tensor.hpp:54
const auto & getBasis() const
Definition fe_modal_tensor.hpp:123
polynomial::SparsePolynomial< Dim, uint8_t, internal::real_t, false > Polynomial
Definition fe_modal_tensor.hpp:52
static constexpr bool needBasisScaling()
Definition fe_modal_tensor.hpp:48
Definition mapping.hpp:60
Template class to represent and operate on polynomials.
Definition polynomial1d.hpp:44
Template class to represent and operate on polynomials in nD.
Definition sparse_polynomial.hpp:63
Definition fe_expr_base.hpp:58
mpf_class real_t
Definition fe_space.hpp:188
Definition dof_policy.hpp:45
FeType
Definition fe_space.hpp:48
@ Poly
Definition fe_space.hpp:48
geometry::Cell< Dim, double, int32_t > CellType
Definition fe_expr_base.hpp:41
FeSpaceModalQ< Dim, DofPolicyFeSpaceDP< Dim >, EnableScaling > FeSpaceModalLegendreDQ
Modal Discontinuous Legendre FE Space on bounding box elements.
Definition fe_modal_tensor.hpp:135
std::underlying_type_t< CellInitOptions > CellInitOptionsType
Definition cell.hpp:95
@ CellInitFaceKb
Definition cell.hpp:90
@ CellInitFaceDiameter
Definition cell.hpp:89
@ CellInitFaces
Definition cell.hpp:84
@ CellInitBBox
Definition cell.hpp:85
@ CellInitMeasure
Definition cell.hpp:87
@ CellInitNormals
Definition cell.hpp:80
@ CellInitDiameter
Definition cell.hpp:86
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::vector< Polynomial< T > > buildLegendrePolynomials(std::size_t deg)
Builds a set of Legendre polynomials up to a given degree.
Definition polynomial1d.hpp:548
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