From 648f9c595ed484bdf787ed0ac009f253c1649857 Mon Sep 17 00:00:00 2001 From: Virginie Grandgirard Date: Fri, 13 Dec 2024 08:39:29 +0100 Subject: [PATCH] Add computation of max error for test_partial_derivatives. --- src/math_tools/partial_derivatives.hpp | 6 +++--- tests/math_tools/test_partial_derivatives.cpp | 16 +++++++++++++++- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/math_tools/partial_derivatives.hpp b/src/math_tools/partial_derivatives.hpp index 159cc5658..0d6226328 100644 --- a/src/math_tools/partial_derivatives.hpp +++ b/src/math_tools/partial_derivatives.hpp @@ -36,8 +36,8 @@ class PartialDerivative private: using IdxRangeX1X2 = IdxRange; using IdxX1X2 = typename IdxRangeX1X2::discrete_element_type; - using DFieldX1X2 = DField; - using DConstFieldX1X2 = DConstField; + using DFieldX1X2 = DField; + using DConstFieldX1X2 = DConstField; // Type for spline representation of the field using IdxRangeBSFieldX1 = typename FieldX1Builder::batched_spline_domain_type; @@ -66,6 +66,6 @@ class PartialDerivative FieldX1SplineCoeffs fieldx1_coefs = get_field(fieldx1_coefs_alloc); m_fieldx1_builder(fieldx1_coefs, get_const_field(field_x1x2)); - m_fieldx1_evaluator.deriv(dfield_dx1_x1x2, fieldx1_coefs); + m_fieldx1_evaluator.deriv(dfield_dx1_x1x2, get_const_field(fieldx1_coefs)); } }; \ No newline at end of file diff --git a/tests/math_tools/test_partial_derivatives.cpp b/tests/math_tools/test_partial_derivatives.cpp index 36fecac22..78313444c 100644 --- a/tests/math_tools/test_partial_derivatives.cpp +++ b/tests/math_tools/test_partial_derivatives.cpp @@ -115,7 +115,21 @@ TEST(PartialDerivative, PartialDerivativeDx) PartialDerivative partial_dx(builder_x, spline_evaluator_x); DFieldMemXY dfield_dx_xy_alloc(idxrange_xy); DFieldXY dfield_dx_xy = get_field(dfield_dx_xy_alloc); - partial_dx(dfield_dx_xy, field_xy); + partial_dx(dfield_dx_xy, get_const_field(field_xy)); + + double max_error = 0; + + ddc::parallel_for_each( + Kokkos::DefaultExecutionSpace(), + idxrange_xy, + KOKKOS_LAMBDA(IdxXY const idx_xy) { + IdxX idx_x(idx_xy); + IdxY idx_y(idx_xy); + dfield_dx_xy(idx_xy) = + Kokkos::max(abs(dfield_dx_xy(idx_xy) - + 2. * ddc::coordinate(idx_x) * ddc::coordinate(idx_y)), max_error); + }); + EXPECT_LE(max_error, 1e-12); } } // namespace