Gyselalib++
 
Loading...
Searching...
No Matches
cosine_evaluator.hpp
1#pragma once
2#include <cmath>
3
4#include <ddc/ddc.hpp>
5
6#include <sll/math_tools.hpp>
7
8#include "ddc_aliases.hpp"
9
14{
18 template <class Grid1D>
20 {
21 public:
23 using Dim = Grid1D;
24
25 private:
26 static inline constexpr double s_2_pi = 2. * M_PI;
27
28 private:
29 double m_c0;
30
31 double m_c1;
32
33 public:
41 template <class IdxRange>
42 Evaluator(IdxRange idx_range) : m_c0(1.0)
43 , m_c1(0.0)
44 {
45 }
46
55 Evaluator(double c0, double c1) : m_c0(c0), m_c1(c1) {}
56
62 double operator()(double const x) const noexcept
63 {
64 return eval(x, 0);
65 }
66
71 void operator()(ddc::ChunkSpan<double, ddc::DiscreteDomain<Grid1D>> chunk) const
72 {
73 auto const& idx_range = chunk.idx_range();
74
75 for (ddc::DiscreteElement<Grid1D> const i : idx_range) {
76 chunk(i) = eval(ddc::coordinate(i), 0);
77 }
78 }
79
86 double deriv(double const x, int const derivative) const noexcept
87 {
88 return eval(x, derivative);
89 }
90
96 void deriv(ddc::ChunkSpan<double, ddc::DiscreteDomain<Grid1D>> chunk, int const derivative)
97 const
98 {
99 auto const& idx_range = chunk.idx_range();
100
101 for (ddc::DiscreteElement<Grid1D> const i : idx_range) {
102 chunk(i) = eval(ddc::coordinate(i), derivative);
103 }
104 }
105
111 double max_norm(int diff = 0) const
112 {
113 return ipow(s_2_pi * m_c0, diff);
114 }
115
116 private:
117 double eval(double const x, int const derivative) const noexcept
118 {
119 return ipow(s_2_pi * m_c0, derivative)
120 * std::cos(M_PI_2 * derivative + s_2_pi * (m_c0 * x + m_c1));
121 }
122 };
123};
An analytical evaluator to be used for exact comparisons in tests.
Definition cosine_evaluator.hpp:20
double deriv(double const x, int const derivative) const noexcept
Evaluate the derivative of the equation at x.
Definition cosine_evaluator.hpp:86
double max_norm(int diff=0) const
The maximum norm of this equation.
Definition cosine_evaluator.hpp:111
Evaluator(IdxRange idx_range)
A constructor taking the range over which the evaluator will be applied.
Definition cosine_evaluator.hpp:42
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 cosine_evaluator.hpp:96
Evaluator(double c0, double c1)
A constructor parametrising the equation.
Definition cosine_evaluator.hpp:55
Grid1D Dim
The grid dimension.
Definition cosine_evaluator.hpp:23
double operator()(double const x) const noexcept
Evaluate the equation at x.
Definition cosine_evaluator.hpp:62
void operator()(ddc::ChunkSpan< double, ddc::DiscreteDomain< Grid1D > > chunk) const
Evaluate the equation at the positions on which chunk is defined.
Definition cosine_evaluator.hpp:71
A wrapper around a cosine Evaluator that can be used in tests.
Definition cosine_evaluator.hpp:14