Medusa  1.1
Coordinate Free Mehless Method implementation
Monomials_fwd.hpp
Go to the documentation of this file.
1 #ifndef MEDUSA_BITS_APPROXIMATIONS_MONOMIALS_FWD_HPP_
2 #define MEDUSA_BITS_APPROXIMATIONS_MONOMIALS_FWD_HPP_
3 
11 #include <medusa/Config.hpp>
12 #include <cmath>
13 #include <array>
14 #include <Eigen/Core>
15 #include <iosfwd>
16 
17 namespace mm {
18 
19 template <int dimension>
20 struct Lap;
21 template <int dimension>
22 struct Der1;
23 template <int dimension>
24 struct Der2;
25 template <int dimension>
26 struct Derivative;
27 
37 template <class vec_t>
38 class Monomials {
39  public:
40  typedef vec_t vector_t;
41  typedef typename vector_t::scalar_t scalar_t;
42  enum { dim = vec_t::dim };
44 
45  private:
47  Eigen::Matrix<int, dim, Eigen::Dynamic> powers_;
48 
50  void setFromPowers(const std::vector<std::vector<int>>& powers);
51 
53  static std::vector<std::vector<int>> generatePowers(int max_order, int dim);
54 
55  public:
57  Monomials() = default;
58 
67  Monomials(int order);
68 
75  Monomials(const std::vector<std::vector<int>>& powers) { setFromPowers(powers); }
76 
84  static Monomials<vec_t> tensorBasis(int order);
85 
87  int size() const { return powers_.cols(); }
88 
90  const Eigen::Matrix<int, dim, Eigen::Dynamic>& powers() const { return powers_; }
91 
101  scalar_t eval(int index, const vector_t& point,
102  const std::vector<vector_t>& /* support */ = {}) const;
103 
116  template <typename operator_t>
117  scalar_t evalOp(int index, const vector_t& point, operator_t op,
118  const std::vector<vector_t>& support = {}, scalar_t scale = 1) const;
120  scalar_t evalOp(int index, const vector_t& point, Lap<dim> op,
121  const std::vector<vector_t>& support = {}, scalar_t scale = 1) const;
123  scalar_t evalOp(int index, const vector_t& point, Der1<dim> op,
124  const std::vector<vector_t>& support = {}, scalar_t scale = 1) const;
126  scalar_t evalOp(int index, const vector_t& point, Der2<dim> op,
127  const std::vector<vector_t>& support = {}, scalar_t scale = 1) const;
129  scalar_t evalOp(int index, const vector_t& point, Derivative<dim> op,
130  const std::vector<vector_t>& support = {}, scalar_t scale = 1) const;
131 
133  scalar_t evalAt0(int index, const std::vector<vector_t>& /* support */ = {}) const;
135  template <typename operator_t>
136  scalar_t evalOpAt0(int index, const operator_t& op, const std::vector<vector_t>& support = {},
137  scalar_t scale = 1) const {
138  return op.applyAt0(*this, index, support, scale);
139  }
141  scalar_t evalOpAt0(int index, const Lap<dim>& lap, const std::vector<vector_t>& = {},
142  scalar_t scale = 1) const;
144  scalar_t evalOpAt0(int index, const Der1<dim>& der1, const std::vector<vector_t>& = {},
145  scalar_t scale = 1) const;
147  scalar_t evalOpAt0(int index, const Der2<dim>& der2, const std::vector<vector_t>& = {},
148  scalar_t scale = 1) const;
149 
151  scalar_t evalOpAt0(int index, const Derivative<dim>& der, const std::vector<vector_t>& = {},
152  scalar_t scale = 1) const;
153 
155  template <class V>
156  friend std::ostream& operator<<(std::ostream& os, const Monomials<V>& m);
157 };
158 
159 } // namespace mm
160 
161 #endif // MEDUSA_BITS_APPROXIMATIONS_MONOMIALS_FWD_HPP_
mm
Root namespace for the whole library.
Definition: Gaussian.hpp:14
scalar_t
Scalar scalar_t
Type of the elements, alias of Scalar.
Definition: MatrixBaseAddons.hpp:16
mm::sh::lap
static const shape_flags lap
Indicates to calculate laplace shapes.
Definition: shape_flags.hpp:24
dim
@ dim
Number of elements of this matrix.
Definition: MatrixBaseAddons.hpp:14
mm::Monomials::vector_t
vec_t vector_t
Vector type.
Definition: Monomials_fwd.hpp:40
mm::Monomials::eval
scalar_t eval(int index, const vector_t &point, const std::vector< vector_t > &={}) const
Evaluates index-th monomial' at point.
Definition: Monomials.hpp:67
mm::Monomials::evalAt0
scalar_t evalAt0(int index, const std::vector< vector_t > &={}) const
Evaluate index-th monomial at zero.
Definition: Monomials.hpp:173
mm::Monomials::evalOp
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.
Config.hpp
mm::Monomials::operator<<
friend std::ostream & operator<<(std::ostream &os, const Monomials< V > &m)
Output basic info about given Monomial basis.
Definition: Monomials.hpp:269
mm::Monomials::dim
@ dim
Dimensionality of the function domain.
Definition: Monomials_fwd.hpp:43
mm::Monomials::Monomials
Monomials()=default
Construct empty monomial basis with size = 0.
mm::Monomials::Monomials
Monomials(const std::vector< std::vector< int >> &powers)
Construct monomial basis from monomials with specific powers.
Definition: Monomials_fwd.hpp:75
mm::Monomials
A class representing Monomial basis.
Definition: Monomials_fwd.hpp:38
mm::Monomials::scalar_t
vector_t::scalar_t scalar_t
Scalar type.
Definition: Monomials_fwd.hpp:41
mm::Der2
Represents a second derivative wrt. var1 and var2.
Definition: Monomials_fwd.hpp:24
mm::Monomials::setFromPowers
void setFromPowers(const std::vector< std::vector< int >> &powers)
Constructs basis from a vector of powers.
Definition: Monomials.hpp:54
mm::Derivative
Represents a general derivative .
Definition: Monomials_fwd.hpp:26
mm::Lap
Represents the Laplacian operator.
Definition: Monomials_fwd.hpp:20
mm::Der1
Represents a first derivative wrt. var.
Definition: Monomials_fwd.hpp:22
mm::Monomials::powers
const Eigen::Matrix< int, dim, Eigen::Dynamic > & powers() const
Get saved monomial powers.
Definition: Monomials_fwd.hpp:90
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
mm::Monomials::evalOpAt0
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.
Definition: Monomials_fwd.hpp:136
mm::Monomials::size
int size() const
Return number of monomials in this basis.
Definition: Monomials_fwd.hpp:87
mm::Monomials::powers_
Eigen::Matrix< int, dim, Eigen::Dynamic > powers_
A vector describing monomials with the powers of every coordinate.
Definition: Monomials_fwd.hpp:47
mm::Monomials::generatePowers
static std::vector< std::vector< int > > generatePowers(int max_order, int dim)
Generate powers for dim-d monomials up to max_order.
Definition: Monomials.hpp:24