Vulpes  0.1.0
Versatile and parallel compUtational Library for high-order discontinuous Polytopal Element Simulations
Loading...
Searching...
No Matches
fe_space.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_SPACE_HPP_
24#define VULPES_FE_FE_SPACE_HPP_
25
26#include <gmpxx.h>
27
28#include <cstddef>
29#include <vector>
30
38
39namespace vulpes {
40namespace fe {
41
42template <typename DataType, std::size_t Dim>
44
48enum FeType : uint8_t { Simplex, Tensor, Poly };
49
72template <
73 std::size_t Dim,
74 typename FloatType,
75 typename DofPolicy,
76 typename FeSpace>
78 public:
79 inline static constexpr std::size_t dim = Dim;
80 inline static constexpr std::size_t fe_space_dim = 1;
81 inline static constexpr bool needBasisScaling() { return false; }
82 using real_t = FloatType;
83 using FeSpaceType = FeSpace;
84
85 explicit FeSpaceBase(std::size_t order)
86 : m_order(order),
88 DofPolicyBase<Dim, DofPolicy>::buildDofSubdimEntity(order)),
90 if constexpr (std::is_same_v<FloatType, mpf_class>) {
91 mpf_set_default_prec(256);
92 }
93 }
94
99 const auto& getBasis() const { return self()->getBasis(); }
104 const auto& getBasisFast() const { return self()->getBasisFast(); }
105
109 inline static constexpr FeType elemType() { return FeSpace::elemType(); };
110
115 template <typename CellType>
116 inline static constexpr auto getMapping(const CellType& cell) {
117 return FeSpace::getMapping(cell);
118 };
119
125 return FeSpace::cellInitOptions();
126 };
127
132 std::size_t getNumDofsForSubdimEntity(std::size_t dim) const {
134 }
135
145
149 constexpr std::size_t order() const { return m_order; }
150
165 template <typename MeshType>
166 constexpr MeshType::index_t dofToCellDof(
167 const MeshType& mesh,
168 MeshType::index_t cell_id,
169 MeshType::index_t owning_enty_id,
170 MeshType::index_t enty_dim,
171 MeshType::index_t enty_multiplicity) const {
172 return m_dof_policy.dofToCellDof(
173 mesh, cell_id, owning_enty_id, enty_dim, enty_multiplicity);
174 }
175
176 protected:
177 FeSpace* self() { return static_cast<FeSpace*>(this); }
178 const FeSpace* self() const { return static_cast<const FeSpace*>(this); }
179
180 const std::size_t m_order;
181 std::array<std::size_t, Dim + 1> m_dofs_for_subdim_entity;
182 DofPolicy m_dof_policy;
183};
184
186
187namespace internal {
188using real_t = mpf_class;
189
193inline double conditionNumber(const Eigen::MatrixXd& A) {
194 Eigen::JacobiSVD<Eigen::MatrixXd> svd(A);
195 const auto& singularValues = svd.singularValues();
196 const double condNum =
197 singularValues(0) / singularValues(singularValues.size() - 1);
198 return condNum;
199}
200
204template <typename FloatType, std::size_t Dim>
205Eigen::Matrix<FloatType, -1, -1> buildVandermonde(
206 const std::vector<Point<FloatType, Dim>>& points) {
207 const auto n = points.size();
208
209 Eigen::Matrix<FloatType, -1, -1> V = decltype(V)::Ones(n, n);
210 for (std::size_t p = 0; p < n; ++p) {
211 const auto& point = points[p];
212 for (std::size_t l = 1; l < n; ++l) {
213 const auto exps = monomial::getMonomial<Dim, std::size_t>(l);
214 for (std::size_t d = 0; d < Dim; ++d) {
215 V(p, l) *= vmath::pow(point[d], exps[d]);
216 }
217 }
218 }
219
220 return V;
221}
222
226template <typename FloatType>
227Eigen::Matrix<FloatType, -1, -1> computeInverse(
228 const Eigen::Matrix<FloatType, -1, -1>& matrix) {
229 using MatrixType = Eigen::Matrix<FloatType, -1, -1>;
230 // if we have exact rational representation, minimize number of operations
231 if constexpr (std::is_same_v<FloatType, mpq_class>) {
232 Eigen::PartialPivLU<MatrixType> lu_decomp(matrix);
233 return lu_decomp.inverse();
234 } else {
235 Eigen::FullPivLU<MatrixType> lu_decomp(matrix);
236 return lu_decomp.inverse();
237 }
238}
239
244template <std::size_t Dim, typename FloatType>
245Eigen::Matrix<FloatType, -1, -1> computeLagrangianPolyCoef(
246 const std::vector<Point<FloatType, Dim>>& points) {
247 const auto V = buildVandermonde<FloatType, Dim>(points);
248 return computeInverse(V);
249}
250
251} // namespace internal
252
253} // namespace fe
254} // namespace vulpes
255
256#endif // VULPES_FE_FE_SPACE_HPP_
FeSpaceBase(std::size_t order)
Definition fe_space.hpp:85
std::size_t getNumDofsForSubdimEntity(std::size_t dim) const
number of DoFs associated with each geometric entity (vtx = 0, edges = 1, faces = 2 or volume cells =...
Definition fe_space.hpp:132
FeSpace FeSpaceType
Definition fe_space.hpp:83
const auto & getBasis() const
get the polynomial basis in arbitrary precision
Definition fe_space.hpp:99
static constexpr FeType elemType()
constraint on cell shape (simplex, tensor, general)
Definition fe_space.hpp:109
static constexpr std::size_t fe_space_dim
Definition fe_space.hpp:80
static constexpr auto getMapping(const CellType &cell)
Get the geometrical mapping that maps a cell to the reference element (on which are defined the basis...
Definition fe_space.hpp:116
FloatType real_t
Definition fe_space.hpp:82
const auto & getBasisFast() const
get the polynomial basis in fixed precision
Definition fe_space.hpp:104
static constexpr bool needBasisScaling()
Definition fe_space.hpp:81
FeSpace * self()
Definition fe_space.hpp:177
static constexpr std::size_t dim
Definition fe_space.hpp:79
const std::size_t m_order
Definition fe_space.hpp:180
constexpr MeshType::index_t dofToCellDof(const MeshType &mesh, MeshType::index_t cell_id, MeshType::index_t owning_enty_id, MeshType::index_t enty_dim, MeshType::index_t enty_multiplicity) const
From the global descriptors of a dof, get the dof in local cell enumeration.
Definition fe_space.hpp:166
const FeSpace * self() const
Definition fe_space.hpp:178
DofPolicy m_dof_policy
Definition fe_space.hpp:182
std::array< std::size_t, Dim+1 > m_dofs_for_subdim_entity
Definition fe_space.hpp:181
static constexpr geometry::CellInitOptionsType cellInitOptions()
Statically define which geometrical features of a cell are needed during integration.
Definition fe_space.hpp:124
static constexpr bool dofsInteractionDistance()
Definition fe_space.hpp:142
constexpr std::size_t order() const
Get the polynomial order of the FE Space.
Definition fe_space.hpp:149
Definition fe_expr_base.hpp:58
Eigen::Matrix< FloatType, -1, -1 > buildVandermonde(const std::vector< Point< FloatType, Dim > > &points)
: Build Vandermonde matrix for a polynomial of P space
Definition fe_space.hpp:205
mpf_class real_t
Definition fe_space.hpp:188
double conditionNumber(const Eigen::MatrixXd &A)
: Estimate condition number of a dense matrix using SVD
Definition fe_space.hpp:193
Eigen::Matrix< FloatType, -1, -1 > computeInverse(const Eigen::Matrix< FloatType, -1, -1 > &matrix)
: Invert a matrix, use partial pivot if we have exact arithmetic
Definition fe_space.hpp:227
Eigen::Matrix< FloatType, -1, -1 > computeLagrangianPolyCoef(const std::vector< Point< FloatType, Dim > > &points)
: Compute the coefficients of interpolatory lagrangian polynomials of a set of points
Definition fe_space.hpp:245
Definition dof_policy.hpp:45
FeType
Definition fe_space.hpp:48
@ Poly
Definition fe_space.hpp:48
@ Simplex
Definition fe_space.hpp:48
@ Tensor
Definition fe_space.hpp:48
geometry::Cell< Dim, double, int32_t > CellType
Definition fe_expr_base.hpp:41
geometry::Point< DataType, Dim > Point
Definition fe_space.hpp:43
Eigen::Matrix< DataType, Dim, 1, Eigen::ColMajor > Point
Definition traits.hpp:34
std::underlying_type_t< CellInitOptions > CellInitOptionsType
Definition cell.hpp:95
std::array< T, Dim > getMonomial(std::size_t n)
Computes the Dim-D monomial exponents for a given linear index.
Definition monomial.hpp:199
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 class describing the template for a DoF policy.
Definition dof_policy.hpp:58
static constexpr bool dofsInteractionDistance()
Returns the distance of interaction of dofs in different cells.
Definition dof_policy.hpp:72