Vulpes  0.1.0
Versatile and parallel compUtational Library for high-order discontinuous Polytopal Element Simulations
Loading...
Searching...
No Matches
vulpes::polynomial::SparsePolynomial< Dim, IndexType, CoefType, IsScaled > Class Template Reference

Template class to represent and operate on polynomials in nD. More...

#include <sparse_polynomial.hpp>

Inheritance diagram for vulpes::polynomial::SparsePolynomial< Dim, IndexType, CoefType, IsScaled >:
[legend]
Collaboration diagram for vulpes::polynomial::SparsePolynomial< Dim, IndexType, CoefType, IsScaled >:
[legend]

Public Types

using MonomialType = monomial::Monomial<Dim, IndexType, CoefType, IsScaled>
using ScalarType = CoefType

Public Member Functions

 SparsePolynomial ()=default
 SparsePolynomial (const CoefType &coef)
 Construct a sparse polynomial with one constant monomial with given coefficient, that is a constant.
 SparsePolynomial (const MonomialType &coef)
 Construct a sparse polynomial with a single monomial.
 SparsePolynomial (const std::array< const Polynomial< CoefType > *, Dim > &polynomials)
 Construct a sparse polynomial as a tensor product of Dim 1D polynomials.
CoefType evaluate (const Eigen::Vector< CoefType, Dim > &point) const
CoefType evaluate (const CoefType *point) const
template<std::size_t IntegralDim>
CoefType integrateAndEvaluate (const datastructure::SimplexDataView< IntegralDim, true, CoefType, std::size_t > &monomial_integrals, const CoefType *val_ptr) const
CoefType integrate (const datastructure::SimplexDataView< Dim, true, CoefType, std::size_t > &monomial_integrals) const
SparsePolynomial derivative (std::size_t component) const
auto & data ()
const auto & data () const
Eigen::Vector< SparsePolynomial, Dim > gradient () const
void updateMaxExp ()
SparsePolynomial< Dim *3, IndexType, CoefType, IsScaled > applyCartesianMapping () const
template<std::size_t PreDim, std::size_t PostDim>
SparsePolynomial< Dim+PreDim+PostDim, IndexType, CoefType, IsScaled > liftDimension () const
void permuteVariables (const std::array< std::size_t, Dim > &permutation)
template<typename U>
SparsePolynomial< Dim, IndexType, U, IsScaled > to () const
 Cast the polynomial to a different underlying type.
SparsePolynomial & operator+= (const SparsePolynomial &other)
SparsePolynomial & operator-= (const SparsePolynomial &other)
SparsePolynomial & operator*= (const SparsePolynomial &other)
 Multiplication by another polynomial.
SparsePolynomial & operator*= (const CoefType &scalar)
CoefType integrate (const datastructure::SimplexDataView< Dim, SimplexData, CoefType, std::size_t > &monomial_integrals) const
 Integrate the polynomial given the monomials integrals.
SparsePolynomial< Dim, IndexType, CoefType, IsScaled > primitive (std::size_t component) const
 Compute the primitive of the polynomial.

Static Public Attributes

static constexpr std::size_t dim = Dim

Protected Member Functions

template<bool IsAddition>
SparsePolynomial & add (const SparsePolynomial &other)
 Sum or subtract two sparse polynomials.
SparsePolynomial< Dim, IndexType, CoefType, IsScaled > * self ()

Protected Attributes

IndexType m_max_exp = 0
std::vector< MonomialType > m_monomials

Friends

std::ostream & operator<< (std::ostream &os, const SparsePolynomial &polynomial)
bool operator== (const SparsePolynomial &lhs, const SparsePolynomial &rhs)
 Equality operator.

Detailed Description

template<std::size_t Dim, typename IndexType, typename CoefType, bool IsScaled>
class vulpes::polynomial::SparsePolynomial< Dim, IndexType, CoefType, IsScaled >

Template class to represent and operate on polynomials in nD.

The class is able to handle also polynomials that are sum/difference of scaled monomials.

The monomials are stored in a SmallVector, ensuring static allocation for a small number of monomials.

This file contains the implementation of a polynomial class template that supports various operations, including addition, subtraction, multiplication, division, differentiation, integration, and more.

Note
The class is optimized for sparse storage, meaning that it is adapt to cases where most of the coefficients are zero.

Member Typedef Documentation

◆ MonomialType

template<std::size_t Dim, typename IndexType, typename CoefType, bool IsScaled>
using vulpes::polynomial::SparsePolynomial< Dim, IndexType, CoefType, IsScaled >::MonomialType = monomial::Monomial<Dim, IndexType, CoefType, IsScaled>

◆ ScalarType

template<std::size_t Dim, typename IndexType, typename CoefType, bool IsScaled>
using vulpes::polynomial::SparsePolynomial< Dim, IndexType, CoefType, IsScaled >::ScalarType = CoefType

Constructor & Destructor Documentation

◆ SparsePolynomial() [1/4]

template<std::size_t Dim, typename IndexType, typename CoefType, bool IsScaled>
vulpes::polynomial::SparsePolynomial< Dim, IndexType, CoefType, IsScaled >::SparsePolynomial ( )
default

◆ SparsePolynomial() [2/4]

template<std::size_t Dim, typename IndexType, typename CoefType, bool IsScaled>
vulpes::polynomial::SparsePolynomial< Dim, IndexType, CoefType, IsScaled >::SparsePolynomial ( const CoefType & coef)
inlineexplicit

Construct a sparse polynomial with one constant monomial with given coefficient, that is a constant.

◆ SparsePolynomial() [3/4]

template<std::size_t Dim, typename IndexType, typename CoefType, bool IsScaled>
vulpes::polynomial::SparsePolynomial< Dim, IndexType, CoefType, IsScaled >::SparsePolynomial ( const MonomialType & coef)
inlineexplicit

Construct a sparse polynomial with a single monomial.

◆ SparsePolynomial() [4/4]

template<std::size_t Dim, typename IndexType, typename CoefType, bool IsScaled>
vulpes::polynomial::SparsePolynomial< Dim, IndexType, CoefType, IsScaled >::SparsePolynomial ( const std::array< const Polynomial< CoefType > *, Dim > & polynomials)
inlineexplicit

Construct a sparse polynomial as a tensor product of Dim 1D polynomials.

Note
Since this is a sparse structure, this is effective if the 1D polynomials have at least few zeros.

Member Function Documentation

◆ add()

template<std::size_t Dim, typename IndexType, typename CoefType, bool IsScaled>
template<bool IsAddition>
SparsePolynomial & vulpes::polynomial::SparsePolynomial< Dim, IndexType, CoefType, IsScaled >::add ( const SparsePolynomial< Dim, IndexType, CoefType, IsScaled > & other)
inlineprotected

Sum or subtract two sparse polynomials.

◆ applyCartesianMapping()

template<std::size_t Dim, typename IndexType, typename CoefType, bool IsScaled>
SparsePolynomial< Dim *3, IndexType, CoefType, IsScaled > vulpes::polynomial::SparsePolynomial< Dim, IndexType, CoefType, IsScaled >::applyCartesianMapping ( ) const
inline

◆ data() [1/2]

template<std::size_t Dim, typename IndexType, typename CoefType, bool IsScaled>
auto & vulpes::polynomial::SparsePolynomial< Dim, IndexType, CoefType, IsScaled >::data ( )
inline

◆ data() [2/2]

template<std::size_t Dim, typename IndexType, typename CoefType, bool IsScaled>
const auto & vulpes::polynomial::SparsePolynomial< Dim, IndexType, CoefType, IsScaled >::data ( ) const
inline

◆ derivative()

template<std::size_t Dim, typename IndexType, typename CoefType, bool IsScaled>
SparsePolynomial vulpes::polynomial::SparsePolynomial< Dim, IndexType, CoefType, IsScaled >::derivative ( std::size_t component) const
inline

◆ evaluate() [1/2]

template<std::size_t Dim, typename IndexType, typename CoefType, bool IsScaled>
CoefType vulpes::polynomial::SparsePolynomial< Dim, IndexType, CoefType, IsScaled >::evaluate ( const CoefType * point) const
inline

◆ evaluate() [2/2]

template<std::size_t Dim, typename IndexType, typename CoefType, bool IsScaled>
CoefType vulpes::polynomial::SparsePolynomial< Dim, IndexType, CoefType, IsScaled >::evaluate ( const Eigen::Vector< CoefType, Dim > & point) const
inline

◆ gradient()

template<std::size_t Dim, typename IndexType, typename CoefType, bool IsScaled>
Eigen::Vector< SparsePolynomial, Dim > vulpes::polynomial::SparsePolynomial< Dim, IndexType, CoefType, IsScaled >::gradient ( ) const
inline

◆ integrate() [1/2]

CoefType vulpes::polynomial::PolynomialBase< CoefType, Dim, SparsePolynomial< Dim, IndexType, CoefType, IsScaled > >::integrate ( const datastructure::SimplexDataView< Dim, SimplexData, CoefType, std::size_t > & monomial_integrals) const
inlineinherited

Integrate the polynomial given the monomials integrals.

◆ integrate() [2/2]

template<std::size_t Dim, typename IndexType, typename CoefType, bool IsScaled>
CoefType vulpes::polynomial::SparsePolynomial< Dim, IndexType, CoefType, IsScaled >::integrate ( const datastructure::SimplexDataView< Dim, true, CoefType, std::size_t > & monomial_integrals) const
inline

◆ integrateAndEvaluate()

template<std::size_t Dim, typename IndexType, typename CoefType, bool IsScaled>
template<std::size_t IntegralDim>
CoefType vulpes::polynomial::SparsePolynomial< Dim, IndexType, CoefType, IsScaled >::integrateAndEvaluate ( const datastructure::SimplexDataView< IntegralDim, true, CoefType, std::size_t > & monomial_integrals,
const CoefType * val_ptr ) const
inline

◆ liftDimension()

template<std::size_t Dim, typename IndexType, typename CoefType, bool IsScaled>
template<std::size_t PreDim, std::size_t PostDim>
SparsePolynomial< Dim+PreDim+PostDim, IndexType, CoefType, IsScaled > vulpes::polynomial::SparsePolynomial< Dim, IndexType, CoefType, IsScaled >::liftDimension ( ) const
inline

◆ operator*=() [1/2]

template<std::size_t Dim, typename IndexType, typename CoefType, bool IsScaled>
SparsePolynomial & vulpes::polynomial::SparsePolynomial< Dim, IndexType, CoefType, IsScaled >::operator*= ( const CoefType & scalar)
inline

◆ operator*=() [2/2]

template<std::size_t Dim, typename IndexType, typename CoefType, bool IsScaled>
SparsePolynomial & vulpes::polynomial::SparsePolynomial< Dim, IndexType, CoefType, IsScaled >::operator*= ( const SparsePolynomial< Dim, IndexType, CoefType, IsScaled > & other)
inline

Multiplication by another polynomial.

Warning
this might be expensive if the sparse polynomial has many monomials

◆ operator+=()

template<std::size_t Dim, typename IndexType, typename CoefType, bool IsScaled>
SparsePolynomial & vulpes::polynomial::SparsePolynomial< Dim, IndexType, CoefType, IsScaled >::operator+= ( const SparsePolynomial< Dim, IndexType, CoefType, IsScaled > & other)
inline

◆ operator-=()

template<std::size_t Dim, typename IndexType, typename CoefType, bool IsScaled>
SparsePolynomial & vulpes::polynomial::SparsePolynomial< Dim, IndexType, CoefType, IsScaled >::operator-= ( const SparsePolynomial< Dim, IndexType, CoefType, IsScaled > & other)
inline

◆ permuteVariables()

template<std::size_t Dim, typename IndexType, typename CoefType, bool IsScaled>
void vulpes::polynomial::SparsePolynomial< Dim, IndexType, CoefType, IsScaled >::permuteVariables ( const std::array< std::size_t, Dim > & permutation)
inline

◆ primitive()

SparsePolynomial< Dim, IndexType, CoefType, IsScaled > vulpes::polynomial::PolynomialBase< CoefType, Dim, SparsePolynomial< Dim, IndexType, CoefType, IsScaled > >::primitive ( std::size_t component) const
inlineinherited

Compute the primitive of the polynomial.

◆ self()

SparsePolynomial< Dim, IndexType, CoefType, IsScaled > * vulpes::polynomial::PolynomialBase< CoefType, Dim, SparsePolynomial< Dim, IndexType, CoefType, IsScaled > >::self ( )
inlineprotectedinherited

◆ to()

template<std::size_t Dim, typename IndexType, typename CoefType, bool IsScaled>
template<typename U>
SparsePolynomial< Dim, IndexType, U, IsScaled > vulpes::polynomial::SparsePolynomial< Dim, IndexType, CoefType, IsScaled >::to ( ) const
inline

Cast the polynomial to a different underlying type.

◆ updateMaxExp()

template<std::size_t Dim, typename IndexType, typename CoefType, bool IsScaled>
void vulpes::polynomial::SparsePolynomial< Dim, IndexType, CoefType, IsScaled >::updateMaxExp ( )
inline

◆ operator<<

template<std::size_t Dim, typename IndexType, typename CoefType, bool IsScaled>
std::ostream & operator<< ( std::ostream & os,
const SparsePolynomial< Dim, IndexType, CoefType, IsScaled > & polynomial )
friend

◆ operator==

template<std::size_t Dim, typename IndexType, typename CoefType, bool IsScaled>
bool operator== ( const SparsePolynomial< Dim, IndexType, CoefType, IsScaled > & lhs,
const SparsePolynomial< Dim, IndexType, CoefType, IsScaled > & rhs )
friend

Equality operator.

Warning
very expensive, the monomials are put in a std::set

Member Data Documentation

◆ dim

template<std::size_t Dim, typename IndexType, typename CoefType, bool IsScaled>
std::size_t vulpes::polynomial::SparsePolynomial< Dim, IndexType, CoefType, IsScaled >::dim = Dim
inlinestaticconstexpr

◆ m_max_exp

template<std::size_t Dim, typename IndexType, typename CoefType, bool IsScaled>
IndexType vulpes::polynomial::SparsePolynomial< Dim, IndexType, CoefType, IsScaled >::m_max_exp = 0
protected

◆ m_monomials

template<std::size_t Dim, typename IndexType, typename CoefType, bool IsScaled>
std::vector<MonomialType> vulpes::polynomial::SparsePolynomial< Dim, IndexType, CoefType, IsScaled >::m_monomials
protected

The documentation for this class was generated from the following files: