Medusa  1.1
Coordinate Free Mehless Method implementation
mm::Monomials< vec_t > Class Template Reference

#include <Monomials_fwd.hpp>

Detailed Description

template<class vec_t>
class mm::Monomials< vec_t >

A class representing Monomial basis.

This class satisfies the Basis function concept.

Usage example:

Monomials<Vec2d> basis(2); // {1, y, x, y^2, xy, x^2}
std::cout << basis << std::endl; // Monomials 2D: [0, 0; 0, 1; 1, 0; 0, 2; 1, 1; 2, 0], ...
double value = basis.eval(2, {0.3, -2.4}); // value = 0.3
basis = Monomials<Vec2d>::tensorBasis(1); // tensor basis {1, x, y, xy}
basis = Monomials<Vec2d>({{1, 0}, {2, 3}}); // from powers
// Evaluate derivative or any other supported operator.
double der = basis.evalOp(1, {0.3, -2.4}, Derivative<2>({2, 1})); // der = 2*3*(-2.4)^2
Examples
test/end2end/poisson_explicit.cpp.

Definition at line 38 of file Monomials_fwd.hpp.

Public Member Functions

 Monomials ()=default
 Construct empty monomial basis with size = 0. More...
 
 Monomials (int order)
 Construct a basis of all monomials of combined order lower or equal to order. More...
 
 Monomials (const std::vector< std::vector< int >> &powers)
 Construct monomial basis from monomials with specific powers. More...
 
int size () const
 Return number of monomials in this basis. More...
 
const Eigen::Matrix< int, dim, Eigen::Dynamic > & powers () const
 Get saved monomial powers. More...
 
scalar_t eval (int index, const vector_t &point, const std::vector< vector_t > &={}) const
 Evaluates index-th monomial' at point. More...
 
template<typename operator_t >
scalar_t evalOp (int index, const vector_t &point, operator_t op, const std::vector< vector_t > &support={}, scalar_t scale=1) const
 Apply an operator at a given point. More...
 
scalar_t evalOp (int index, const vector_t &point, Lap< dim > op, const std::vector< vector_t > &support={}, scalar_t scale=1) const
 Evaluate Laplacian. More...
 
scalar_t evalOp (int index, const vector_t &point, Der1< dim > op, const std::vector< vector_t > &support={}, scalar_t scale=1) const
 Evaluate 1st derivative. More...
 
scalar_t evalOp (int index, const vector_t &point, Der2< dim > op, const std::vector< vector_t > &support={}, scalar_t scale=1) const
 Evaluate 2nd derivative. More...
 
scalar_t evalOp (int index, const vector_t &point, Derivative< dim > op, const std::vector< vector_t > &support={}, scalar_t scale=1) const
 Evaluate general derivative. More...
 
scalar_t evalAt0 (int index, const std::vector< vector_t > &={}) const
 Evaluate index-th monomial at zero. More...
 
template<typename operator_t >
scalar_t evalOpAt0 (int index, const operator_t&op, const std::vector< vector_t > &support={}, scalar_t scale=1) const
 Evaluate an operator on index-th monomial at zero. More...
 
scalar_t evalOpAt0 (int index, const Lap< dim > &lap, const std::vector< vector_t > &={}, scalar_t scale=1) const
 Evaluate Laplacian lap at zero. More...
 
scalar_t evalOpAt0 (int index, const Der1< dim > &der1, const std::vector< vector_t > &={}, scalar_t scale=1) const
 Evaluate first derivative operator der1 at zero. More...
 
scalar_t evalOpAt0 (int index, const Der2< dim > &der2, const std::vector< vector_t > &={}, scalar_t scale=1) const
 Evaluate second derivative operator der2 at zero. More...
 
scalar_t evalOpAt0 (int index, const Derivative< dim > &der, const std::vector< vector_t > &={}, scalar_t scale=1) const
 Evaluate general derivative operator at zero. More...
 

Static Public Member Functions

static Monomials< vec_t > tensorBasis (int order)
 Construct a tensor basis of monomials ranging from 0 up to order (inclusive) in each dimension. More...
 

Public Types

enum  { dim = vec_t::dim }
 Store dimension of the domain. More...
 
typedef vec_t vector_t
 Vector type. More...
 
typedef vector_t::scalar_t scalar_t
 Scalar type. More...
 

Friends

template<class V >
std::ostream & operator<< (std::ostream &os, const Monomials< V > &m)
 Output basic info about given Monomial basis. More...
 

Private Member Functions

void setFromPowers (const std::vector< std::vector< int >> &powers)
 Constructs basis from a vector of powers. More...
 

Static Private Member Functions

static std::vector< std::vector< int > > generatePowers (int max_order, int dim)
 Generate powers for dim-d monomials up to max_order. More...
 

Private Attributes

Eigen::Matrix< int, dim, Eigen::Dynamic > powers_
 A vector describing monomials with the powers of every coordinate. More...
 

Member Enumeration Documentation

◆ anonymous enum

template<class vec_t >
anonymous enum

Store dimension of the domain.

Enumerator
dim 

Dimensionality of the function domain.

Definition at line 43 of file Monomials_fwd.hpp.

Constructor & Destructor Documentation

◆ Monomials() [1/3]

template<class vec_t >
mm::Monomials< vec_t >::Monomials ( )
default

Construct empty monomial basis with size = 0.

◆ Monomials() [2/3]

template<class vec_t >
mm::Monomials< vec_t >::Monomials ( int  order)

Construct a basis of all monomials of combined order lower or equal to order.

Parameters
orderMaximal combined order of monomials to be used. If order is -1 then empty basis is constructed.

Example: If you call this with an order = 2 parameter and Vec2d template parameter, your basis will consist of \( \{1, x, y, x^2, xy, y^2\} \) (not necessarily in that order).

Definition at line 18 of file Monomials.hpp.

◆ Monomials() [3/3]

template<class vec_t >
mm::Monomials< vec_t >::Monomials ( const std::vector< std::vector< int >> &  powers)
inline

Construct monomial basis from monomials with specific powers.

Parameters
powersList of lists of size dim, each representing powers of a monomial. For example {{1, 2}, {0, 3}, {2, 0}} in 2D represents monomials \(\{x y^2, y^3, x^2\}\).

Definition at line 75 of file Monomials_fwd.hpp.

Member Function Documentation

◆ eval()

template<class vec_t >
vec_t::scalar_t mm::Monomials< vec_t >::eval ( int  index,
const vector_t point,
const std::vector< vector_t > &  = {} 
) const

Evaluates index-th monomial' at point.

Parameters
indexA number in [0, size()) specifying the index of a monomial to evaluate.
pointPoint in which to evaluate the monomial.
Returns
Value of requested monomial at given point.
Exceptions
Assertionfails if index is out of range or if an invalid derivative is requested.

Definition at line 67 of file Monomials.hpp.

◆ evalAt0()

template<class vec_t >
vec_t::scalar_t mm::Monomials< vec_t >::evalAt0 ( int  index,
const std::vector< vector_t > &  = {} 
) const

Evaluate index-th monomial at zero.

Definition at line 173 of file Monomials.hpp.

◆ evalOp() [1/5]

template<class vec_t >
vec_t::scalar_t mm::Monomials< vec_t >::evalOp ( int  index,
const vector_t point,
Der1< dim op,
const std::vector< vector_t > &  support = {},
scalar_t  scale = 1 
) const

Evaluate 1st derivative.

See also
evalOp

Definition at line 99 of file Monomials.hpp.

◆ evalOp() [2/5]

template<class vec_t >
vec_t::scalar_t mm::Monomials< vec_t >::evalOp ( int  index,
const vector_t point,
Der2< dim op,
const std::vector< vector_t > &  support = {},
scalar_t  scale = 1 
) const

Evaluate 2nd derivative.

See also
evalOp

Definition at line 115 of file Monomials.hpp.

◆ evalOp() [3/5]

template<class vec_t >
vec_t::scalar_t mm::Monomials< vec_t >::evalOp ( int  index,
const vector_t point,
Derivative< dim op,
const std::vector< vector_t > &  support = {},
scalar_t  scale = 1 
) const

Evaluate general derivative.

See also
evalOp

Definition at line 149 of file Monomials.hpp.

◆ evalOp() [4/5]

template<class vec_t >
vec_t::scalar_t mm::Monomials< vec_t >::evalOp ( int  index,
const vector_t point,
Lap< dim op,
const std::vector< vector_t > &  support = {},
scalar_t  scale = 1 
) const

Evaluate Laplacian.

See also
evalOp

Definition at line 79 of file Monomials.hpp.

◆ evalOp() [5/5]

template<class vec_t >
template<typename operator_t >
scalar_t mm::Monomials< vec_t >::evalOp ( int  index,
const vector_t point,
operator_t  op,
const std::vector< vector_t > &  support = {},
scalar_t  scale = 1 
) const

Apply an operator at a given point.

For \(\frac{d}{dx}\), the function computes \( \frac{d}{dx} p_i(x_s), x_s = \frac{x - c}{s} \).

Parameters
indexA number in [0, size()) specifying the index of a monomial to evaluate.
pointTranslated and scaled point \(x_s\) at which the basis function is evaluated.
opThe differential operator.
supportTranslated and scaled values of nodes in the support domain. Unused.
scaleThe scaling factor \(s\).
Returns
Value of the operator applied to index-th basis function at point point.
Exceptions
Assertionfails if index is out of range.
See also
Operator, Lap, Der1, Der2

◆ evalOpAt0() [1/5]

template<class vec_t >
vec_t::scalar_t mm::Monomials< vec_t >::evalOpAt0 ( int  index,
const Der1< dim > &  der1,
const std::vector< vector_t > &  = {},
scalar_t  scale = 1 
) const

Evaluate first derivative operator der1 at zero.

See also
evalOpAt0

Definition at line 207 of file Monomials.hpp.

◆ evalOpAt0() [2/5]

template<class vec_t >
vec_t::scalar_t mm::Monomials< vec_t >::evalOpAt0 ( int  index,
const Der2< dim > &  der2,
const std::vector< vector_t > &  = {},
scalar_t  scale = 1 
) const

Evaluate second derivative operator der2 at zero.

See also
evalOpAt0

Definition at line 228 of file Monomials.hpp.

◆ evalOpAt0() [3/5]

template<class vec_t >
vec_t::scalar_t mm::Monomials< vec_t >::evalOpAt0 ( int  index,
const Derivative< dim > &  der,
const std::vector< vector_t > &  support = {},
scalar_t  scale = 1 
) const

Evaluate general derivative operator at zero.

See also
evalOpAt0

Definition at line 262 of file Monomials.hpp.

◆ evalOpAt0() [4/5]

template<class vec_t >
vec_t::scalar_t mm::Monomials< vec_t >::evalOpAt0 ( int  index,
const Lap< dim > &  lap,
const std::vector< vector_t > &  = {},
scalar_t  scale = 1 
) const

Evaluate Laplacian lap at zero.

See also
evalOpAt0

Definition at line 189 of file Monomials.hpp.

◆ evalOpAt0() [5/5]

template<class vec_t >
template<typename operator_t >
scalar_t mm::Monomials< vec_t >::evalOpAt0 ( int  index,
const operator_t&  op,
const std::vector< vector_t > &  support = {},
scalar_t  scale = 1 
) const
inline

Evaluate an operator on index-th monomial at zero.

See also
eval

Definition at line 136 of file Monomials_fwd.hpp.

◆ generatePowers()

template<class vec_t >
std::vector< std::vector< int > > mm::Monomials< vec_t >::generatePowers ( int  max_order,
int  dim 
)
staticprivate

Generate powers for dim-d monomials up to max_order.

Definition at line 24 of file Monomials.hpp.

◆ powers()

template<class vec_t >
const Eigen::Matrix<int, dim, Eigen::Dynamic>& mm::Monomials< vec_t >::powers ( ) const
inline

Get saved monomial powers.

Definition at line 90 of file Monomials_fwd.hpp.

◆ setFromPowers()

template<class vec_t >
void mm::Monomials< vec_t >::setFromPowers ( const std::vector< std::vector< int >> &  powers)
private

Constructs basis from a vector of powers.

Definition at line 54 of file Monomials.hpp.

◆ size()

template<class vec_t >
int mm::Monomials< vec_t >::size ( ) const
inline

Return number of monomials in this basis.

Definition at line 87 of file Monomials_fwd.hpp.

◆ tensorBasis()

template<class vec_t >
Monomials< vec_t > mm::Monomials< vec_t >::tensorBasis ( int  order)
static

Construct a tensor basis of monomials ranging from 0 up to order (inclusive) in each dimension.

If order is -1 then empty basis is constructed.

Example: tensorBasis(2) in 2D constructs the set \(\{1, x, x^2, y, yx, yx^2, y^2, y^2x, y^2x^2\}\).

Examples
test/approximations/Monomials_test.cpp, test/approximations/WLS_test.cpp, test/end2end/cantilever_beam_implicit.cpp, and test/end2end/poisson_implicit.cpp.

Definition at line 41 of file Monomials.hpp.

Friends And Related Function Documentation

◆ operator<<

template<class vec_t >
template<class V >
std::ostream& operator<< ( std::ostream &  os,
const Monomials< V > &  m 
)
friend

Output basic info about given Monomial basis.

Definition at line 269 of file Monomials.hpp.

Member Data Documentation

◆ powers_

template<class vec_t >
Eigen::Matrix<int, dim, Eigen::Dynamic> mm::Monomials< vec_t >::powers_
private

A vector describing monomials with the powers of every coordinate.

Definition at line 47 of file Monomials_fwd.hpp.


The documentation for this class was generated from the following files:
mm::Monomials::tensorBasis
static Monomials< vec_t > tensorBasis(int order)
Construct a tensor basis of monomials ranging from 0 up to order (inclusive) in each dimension.
Definition: Monomials.hpp:41