Gyselalib++
 
Loading...
Searching...
No Matches
evaluator_2d.hpp
1#pragma once
2#include <ddc/ddc.hpp>
3
4#include "ddc_aliases.hpp"
5
10{
14 template <class Eval1, class Eval2>
16 {
17 private:
18 Eval1 eval_func1;
19 Eval2 eval_func2;
20
21 public:
28 template <class IdxRange>
29 Evaluator(IdxRange idx_range)
30 : eval_func1(ddc::select<typename Eval1::Dim>(idx_range))
31 , eval_func2(ddc::select<typename Eval2::Dim>(idx_range))
32 {
33 }
34
41 double operator()(double const x, double const y) const noexcept
42 {
43 return eval_func1(x) * eval_func2(y);
44 }
45
51 template <class Grid1, class Grid2>
52 double operator()(ddc::Coordinate<Grid1, Grid2> const x) const noexcept
53 {
54 return eval_func1(ddc::get<Grid1>(x)) * eval_func2(ddc::get<Grid2>(x));
55 }
56
61 template <class Grid1, class Grid2>
62 void operator()(ddc::ChunkSpan<double, ddc::DiscreteDomain<Grid1, Grid2>> chunk) const
63 {
64 auto const& idx_range = chunk.idx_range();
65
66 ddc::for_each(idx_range, [=](ddc::DiscreteElement<Grid1, Grid2> const i) {
67 chunk(i) = eval_func1(ddc::coordinate(ddc::select<Grid1>(i)))
68 * eval_func2(ddc::coordinate(ddc::select<Grid2>(i)));
69 });
70 }
71
80 double deriv(double const x, double const y, int const derivative_x, int const derivative_y)
81 const noexcept
82 {
83 return eval_func1.deriv(x, derivative_x) * eval_func2.deriv(y, derivative_y);
84 }
85
93 template <class Grid1, class Grid2>
94 double deriv(
95 ddc::Coordinate<Grid1, Grid2> const x,
96 int const derivative_x,
97 int const derivative_y) const noexcept
98 {
99 return eval_func1.deriv(ddc::get<Grid1>(x), derivative_x)
100 * eval_func2.deriv(ddc::get<Grid2>(x), derivative_y);
101 }
102
109 template <class Grid1, class Grid2>
110 void deriv(
111 ddc::ChunkSpan<double, ddc::DiscreteDomain<Grid1, Grid2>> chunk,
112 int const derivative_x,
113 int const derivative_y) const
114 {
115 auto const& idx_range = chunk.idx_range();
116
117 ddc::for_each(idx_range, [=](ddc::DiscreteElement<Grid1, Grid2> const i) {
118 chunk(i) = eval_func1.deriv(ddc::coordinate(ddc::select<Grid1>(i)), derivative_x)
119 * eval_func2.deriv(ddc::coordinate(ddc::select<Grid2>(i)), derivative_y);
120 });
121 }
122
129 double max_norm(int diff1 = 0, int diff2 = 0) const
130 {
131 return eval_func1.max_norm(diff1) * eval_func2.max_norm(diff2);
132 }
133 };
134};
An analytical 2D evaluator combining 2 1D evaluators, to be used for exact comparisons in tests.
Definition evaluator_2d.hpp:16
double max_norm(int diff1=0, int diff2=0) const
The maximum norm of this equation.
Definition evaluator_2d.hpp:129
Evaluator(IdxRange idx_range)
A constructor taking the range over which the evaluator will be applied.
Definition evaluator_2d.hpp:29
double operator()(double const x, double const y) const noexcept
Evaluate the equation at (x,y)
Definition evaluator_2d.hpp:41
double operator()(ddc::Coordinate< Grid1, Grid2 > const x) const noexcept
Evaluate the equation at .
Definition evaluator_2d.hpp:52
void operator()(ddc::ChunkSpan< double, ddc::DiscreteDomain< Grid1, Grid2 > > chunk) const
Evaluate the equation at the positions on which chunk is defined.
Definition evaluator_2d.hpp:62
double deriv(ddc::Coordinate< Grid1, Grid2 > const x, int const derivative_x, int const derivative_y) const noexcept
Evaluate the derivative of the equation at .
Definition evaluator_2d.hpp:94
double deriv(double const x, double const y, int const derivative_x, int const derivative_y) const noexcept
Evaluate the derivative of the equation at (x,y)
Definition evaluator_2d.hpp:80
void deriv(ddc::ChunkSpan< double, ddc::DiscreteDomain< Grid1, Grid2 > > chunk, int const derivative_x, int const derivative_y) const
Evaluate the derivative of the equation at the positions on which chunk is defined.
Definition evaluator_2d.hpp:110
A wrapper around a 2D Evaluator that can be used in tests.
Definition evaluator_2d.hpp:10