Medusa  1.1
Coordinate Free Mehless Method implementation
Operators_fwd.hpp
Go to the documentation of this file.
1 #ifndef MEDUSA_BITS_APPROXIMATIONS_OPERATORS_FWD_HPP_
2 #define MEDUSA_BITS_APPROXIMATIONS_OPERATORS_FWD_HPP_
3 
11 #include <medusa/Config.hpp>
12 #include <array>
13 #include <vector>
14 #include <Eigen/Core>
15 #include "Monomials_fwd.hpp"
17 
18 namespace mm {
19 
32 template <typename Derived>
33 struct Operator {
34  typedef Derived operator_t;
35  static constexpr int size() { return 1; }
36  static constexpr int index(Derived) { return 0; }
37  std::string name() const { return Derived::name(); }
38  static std::string type_name() { return Derived::type_name(); }
39 
44  std::array<Derived, 1> operators() const { return {*static_cast<const Derived*>(this)}; }
45 
63  template <typename basis_t>
64  typename basis_t::scalar_t apply(
65  const basis_t& basis, int index, typename basis_t::vector_t point,
66  const std::vector<typename basis_t::vector_t>& support,
67  typename basis_t::scalar_t scale) const;
68 
73  template <typename basis_t>
74  typename basis_t::scalar_t applyAt0(
75  const basis_t& basis, int index,
76  const std::vector<typename basis_t::vector_t>& support,
77  typename basis_t::scalar_t scale) const;
78 };
80 template <typename Derived>
81 std::ostream& operator<<(std::ostream& os, const Operator<Derived>& op) { return os << op.name(); }
82 
84 template <int dimension>
85 struct Lap : public Operator<Lap<dimension>> {
87  enum { dim = dimension };
88  static std::string name() { return format("Laplacian<%d>", dim); }
89  static std::string type_name() { return name(); }
90 };
91 
96 template <int dimension>
97 struct Der1s {
99  enum { dim = dimension };
101  static int size() { return dim; }
102  static std::string name() { return format("Der1s<%d>", dim); }
103  static std::string type_name() { return name(); }
104 
106  static std::array<Der1<dimension>, dimension> operators();
107 
109  static int index(Der1<dim> d) { return d.var; }
110 };
112 template <int d>
113 std::ostream& operator<<(std::ostream& os, const Der1s<d>& op) { return os << op.name(); }
114 
119 template <int dimension>
120 struct Der2s {
122  enum { dim = dimension };
124  static int size() { return dim * (dim + 1) / 2; }
125  static std::string name() { return format("Der2s<%d>", dim); }
126  static std::string type_name() { return name(); }
127 
129  static std::array<Der2<dimension>, dimension * (dimension + 1) / 2> operators();
130 
132  static int index(Der2<dim> d) { return (d.var2 == 2 ? d.var1 + 1 : d.var1) + d.var2; }
133 };
135 template <int d>
136 std::ostream& operator<<(std::ostream& os, const Der2s<d>& op) { return os << op.name(); }
137 
138 
140 template <int dimension>
141 struct Der1 : public Operator<Der1<dimension>> {
143  enum { dim = dimension };
144  int var;
145 
147  Der1() : var(-1) {}
148 
153  Der1(int var);
154 
156  std::string name() const;
158  static std::string type_name() { return format("Der1<%d>", dim); }
159 };
160 
161 
163 template <int dimension>
164 struct Der2 : public Operator<Der2<dimension>> {
166  enum { dim = dimension };
167  int var1,
169 
171  Der2() : var1(-1), var2(-1) {}
172 
181  Der2(int var1, int var2);
182 
187  Der2(int var) : Der2(var, var) {}
188 
190  std::string name() const;
192  static std::string type_name() { return format("Der2<%d>", dim); }
193 };
194 
195 
200 template <int dimension>
201 struct Derivative : public Operator<Derivative<dimension>> {
203  enum { dim = dimension };
204  std::array<int, dim> orders;
205 
207  Derivative(const std::array<int, dim>& orders) : orders(orders) {}
208 
210  std::string name() { return format("Derivative<%d> wrt. %s", dim, orders); }
212  static std::string type_name() { return format("Derivative<%d>", dim); }
213 };
214 
215 } // namespace mm
216 
217 #endif // MEDUSA_BITS_APPROXIMATIONS_OPERATORS_FWD_HPP_
mm::Operator
Base class for a differential operator.
Definition: Operators_fwd.hpp:33
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::Derivative::Derivative
Derivative(const std::array< int, dim > &orders)
Parameter orders represent the derivative orders .
Definition: Operators_fwd.hpp:207
mm::Derivative::orders
std::array< int, dim > orders
Values .
Definition: Operators_fwd.hpp:204
mm::Der1s::dim
@ dim
Dimensionality of the domain.
Definition: Operators_fwd.hpp:99
mm::Operator::applyAt0
basis_t::scalar_t applyAt0(const basis_t &basis, int index, const std::vector< typename basis_t::vector_t > &support, typename basis_t::scalar_t scale) const
Like apply, but with point equal to 0.
Definition: Operators.hpp:25
mm::operator<<
std::ostream & operator<<(std::ostream &os, const Gaussian< S > &b)
Output basic information about given Gaussian RBF.
Definition: Gaussian.hpp:37
mm::Der2::Der2
Der2()
Default constructor for array preallocation purposes.
Definition: Operators_fwd.hpp:171
mm::Der2s::operator_t
Der2< dim > operator_t
Type of this family's members.
Definition: Operators_fwd.hpp:123
mm::Der1::var
int var
Index representing derived variable (x = 0, y = 1, z = 2)
Definition: Operators_fwd.hpp:144
mm::Der1s::index
static int index(Der1< dim > d)
Get index of operator d in the family.
Definition: Operators_fwd.hpp:109
mm::Der1::type_name
static std::string type_name()
Human readable type name.
Definition: Operators_fwd.hpp:158
mm::Der2::type_name
static std::string type_name()
Human readable type name.
Definition: Operators_fwd.hpp:192
mm::Der2::dim
@ dim
Dimensionality of the domain.
Definition: Operators_fwd.hpp:166
mm::Derivative::dim
@ dim
Dimensionality of the domain.
Definition: Operators_fwd.hpp:203
Config.hpp
mm::Der2s
Represents a family of all second derivatives.
Definition: Operators_fwd.hpp:120
mm::Der2::var2
int var2
Higher index representing derived variable (x = 0, y = 1, z = 2, ...)
Definition: Operators_fwd.hpp:168
mm::Der2
Represents a second derivative wrt. var1 and var2.
Definition: Monomials_fwd.hpp:24
assert.hpp
mm::Derivative::type_name
static std::string type_name()
Human readable type name.
Definition: Operators_fwd.hpp:212
mm::Der1::Der1
Der1()
Default constructor for array preallocation purposes.
Definition: Operators_fwd.hpp:147
Monomials_fwd.hpp
mm::Operator::apply
basis_t::scalar_t apply(const basis_t &basis, int index, typename basis_t::vector_t point, const std::vector< typename basis_t::vector_t > &support, typename basis_t::scalar_t scale) const
Apply this operator to a given basis function.
Definition: Operators.hpp:16
mm::Der1s::operator_t
Der1< dim > operator_t
Type of this family's members.
Definition: Operators_fwd.hpp:100
mm::Operator::operators
std::array< Derived, 1 > operators() const
Return an iterable of iterators represented by a family.
Definition: Operators_fwd.hpp:44
mm::Der1
Represents a first derivative wrt. var.
Definition: Monomials_fwd.hpp:22
mm::Der2s::operators
static std::array< Der2< dimension >, dimension *(dimension+1)/2 > operators()
Return an iterable of iterators represented by a family.
Definition: Operators.hpp:40
mm::Lap::dim
@ dim
Dimensionality of the domain.
Definition: Operators_fwd.hpp:87
mm::Derivative::name
std::string name()
Human readable name.
Definition: Operators_fwd.hpp:210
mm::Der2s::dim
@ dim
Dimensionality of the domain.
Definition: Operators_fwd.hpp:122
mm::Operator::operator_t
Derived operator_t
Type of the contained operators.
Definition: Operators_fwd.hpp:34
mm::Der2::name
std::string name() const
Human readable name.
Definition: Operators.hpp:84
mm::Der2::Der2
Der2(int var)
Initialization of specific 2nd derivative operator.
Definition: Operators_fwd.hpp:187
mm::Der1::dim
@ dim
Dimensionality of the domain.
Definition: Operators_fwd.hpp:143
mm::Der2s::index
static int index(Der2< dim > d)
Get index of operator d in the family.
Definition: Operators_fwd.hpp:132
mm::Der1s
Represents a family of all first derivatives.
Definition: Operators_fwd.hpp:97
mm::Der2::var1
int var1
Lower index representing derived variable (x = 0, y = 1, z = 2, ...)
Definition: Operators_fwd.hpp:167
mm::Der1::name
std::string name() const
Human readable name.
Definition: Operators.hpp:71
mm::Der1s::operators
static std::array< Der1< dimension >, dimension > operators()
Return an iterable of iterators represented by a family.
Definition: Operators.hpp:32