Medusa  1.1
Coordinate Free Mehless Method implementation
Operators.hpp
Go to the documentation of this file.
1 #ifndef MEDUSA_BITS_APPROXIMATIONS_OPERATORS_HPP_
2 #define MEDUSA_BITS_APPROXIMATIONS_OPERATORS_HPP_
3 
4 #include "Operators_fwd.hpp"
5 #include "Monomials_fwd.hpp"
6 #include "RBFBasis_fwd.hpp"
7 
13 namespace mm {
14 template <typename Derived>
15 template <typename basis_t>
17  const basis_t&, int, typename basis_t::vector_t,
18  const std::vector<typename basis_t::vector_t>&, typename basis_t::scalar_t) const {
19  static_assert(!std::is_same<Derived, Derived>::value,
20  "Applying this operator to this basis not implemented.");
21 }
22 
23 template <typename Derived>
24 template <typename basis_t>
26  const basis_t& basis, int index, const std::vector<typename basis_t::vector_t>& support,
27  typename basis_t::scalar_t scale) const {
28  return apply(basis, typename basis_t::vector_t(0.0), index, support, scale);
29 }
30 
31 template <int dimension>
32 std::array<Der1<dimension>, dimension> Der1s<dimension>::operators() {
33  std::array<Der1<dim>, dim> ret;
34  for (int d = 0; d < dim; ++d) {
35  ret[d] = {d};
36  }
37  return ret;
38 }
39 template <int dimension>
40 std::array<Der2<dimension>, dimension*(dimension+1)/2> Der2s<dimension>::operators() {
41  std::array<Der2<dim>, dim*(dim+1)/2> ret;
42  int c = 0;
43  for (int d2 = 0; d2 < dim; ++d2) {
44  for (int d1 = 0; d1 <= d2; ++d1) {
45  ret[c] = {d1, d2};
46  ++c;
47  }
48  }
49  return ret;
50 }
51 
53 namespace operators_internal {
58 inline std::string idx_to_letter(int var) {
59  if (var < 0 || var >= 4) return "x_" + std::to_string(var);
60  return std::string(1, "xyzw"[var]);
61 }
62 } // namespace operators_internal
63 
64 
65 template <int dimension>
66 Der1<dimension>::Der1(int var) : var(var) {
67  assert_msg(0 <= var && var <= dim, "Variable %d should be in range [0, %d).", var, dim);
68 }
69 
70 template <int dimension>
71 std::string Der1<dimension>::name() const {
72  return format("Der1<%d> wrt. %s", dim, operators_internal::idx_to_letter(var));
73 }
74 
75 template <int dimension>
76 Der2<dimension>::Der2(int var1, int var2) : var1(var1), var2(var2) {
77  assert_msg(0 <= var1 && var1 <= dim, "Variable %d should be in range [0, %d).", var1, dim);
78  assert_msg(0 <= var2 && var2 <= dim, "Variable %d should be in range [0, %d).", var2, dim);
79  assert_msg(var2 >= var1,
80  "Second value provided %d should be higher or equal than the first %d", var2, var1);
81 }
82 
83 template <int dimension>
84 std::string Der2<dimension>::name() const {
85  return format("Der2<%d> wrt. %s and %s",
87 }
88 
89 } // namespace mm
90 
91 #endif // MEDUSA_BITS_APPROXIMATIONS_OPERATORS_HPP_
mm::sh::d1
static const shape_flags d1
Indicates to calculate d1 shapes.
Definition: shape_flags.hpp:23
RBFBasis_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
dim
@ dim
Number of elements of this matrix.
Definition: MatrixBaseAddons.hpp:14
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::Der2::Der2
Der2()
Default constructor for array preallocation purposes.
Definition: Operators_fwd.hpp:171
assert_msg
#define assert_msg(cond,...)
Assert with better error reporting.
Definition: assert.hpp:75
mm::Der1::var
int var
Index representing derived variable (x = 0, y = 1, z = 2)
Definition: Operators_fwd.hpp:144
mm::Der2::dim
@ dim
Dimensionality of the domain.
Definition: Operators_fwd.hpp:166
mm::sh::d2
static const shape_flags d2
Indicates to calculate d2 shapes.
Definition: shape_flags.hpp:25
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
Operators_fwd.hpp
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::Der2::name
std::string name() const
Human readable name.
Definition: Operators.hpp:84
mm::Der1::dim
@ dim
Dimensionality of the domain.
Definition: Operators_fwd.hpp:143
mm::operators_internal::idx_to_letter
std::string idx_to_letter(int var)
Convert variable index to its respective letter, 0 -> x, 1 -> y, etc.
Definition: Operators.hpp:58
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