9#include <sll/math_tools.hpp>
11#include "ddc_aliases.hpp"
21 template <
class Gr
id1D, std::
size_t Degree>
29 std::array<double, Degree + 1> m_coeffs;
40 template <
class IdxRange>
43 , m_xN(std::max(std::abs(rmin(idx_range)), std::abs(rmax(idx_range))))
45 for (
int i(0); i < m_degree + 1; ++i) {
46 m_coeffs[i] = double(rand() % 100) / 100.0;
64 void operator()(ddc::ChunkSpan<
double, ddc::DiscreteDomain<Grid1D>> chunk)
const
66 auto const& idx_range = chunk.idx_range();
68 for (ddc::DiscreteElement<Grid1D>
const i : idx_range) {
69 chunk(i) = eval(ddc::coordinate(i), 0);
79 double deriv(
double const x,
int const derivative)
const noexcept
81 return eval(x, derivative);
89 void deriv(ddc::ChunkSpan<
double, ddc::DiscreteDomain<Grid1D>> chunk,
int const derivative)
92 auto const& idx_range = chunk.idx_range();
94 for (ddc::DiscreteElement<Grid1D>
const i : idx_range) {
95 chunk(i) = eval(ddc::coordinate(i), derivative);
106 return std::abs(
deriv(m_xN, diff));
110 double eval(
double const x,
int const derivative)
const
113 int start = derivative < 0 ? 0 : derivative;
114 for (
int i(start); i < m_degree + 1; ++i) {
115 double v = double(falling_factorial(i, derivative)) * std::pow(x, i - derivative);
116 result += m_coeffs[i] * v;
121 double falling_factorial(
int i,
int d)
const
125 for (
int k(0); k < d; ++k) {
129 for (
int k(-1); k > d - 1; --k) {
An analytical evaluator to be used for exact comparisons in tests.
Definition polynomial_evaluator.hpp:23
void operator()(ddc::ChunkSpan< double, ddc::DiscreteDomain< Grid1D > > chunk) const
Evaluate the equation at the positions on which chunk is defined.
Definition polynomial_evaluator.hpp:64
Grid1D Dim
The grid dimension.
Definition polynomial_evaluator.hpp:26
double operator()(double const x) const noexcept
Evaluate the equation at x.
Definition polynomial_evaluator.hpp:55
void deriv(ddc::ChunkSpan< double, ddc::DiscreteDomain< Grid1D > > chunk, int const derivative) const
Evaluate the derivative of the equation at the positions on which chunk is defined.
Definition polynomial_evaluator.hpp:89
double deriv(double const x, int const derivative) const noexcept
Evaluate the derivative of the equation at x.
Definition polynomial_evaluator.hpp:79
Evaluator(IdxRange idx_range)
A constructor taking the range over which the evaluator will be applied.
Definition polynomial_evaluator.hpp:41
double max_norm(int diff=0) const
The maximum norm of this equation.
Definition polynomial_evaluator.hpp:104
A wrapper around a polynomial Evaluator that can be used in tests.
Definition polynomial_evaluator.hpp:17