Skip to content

Commit

Permalink
Add computation of max error for test_partial_derivatives.
Browse files Browse the repository at this point in the history
  • Loading branch information
gdgirard committed Dec 13, 2024
1 parent 9be6573 commit 648f9c5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/math_tools/partial_derivatives.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ class PartialDerivative
private:
using IdxRangeX1X2 = IdxRange<GridX1, GridX2>;
using IdxX1X2 = typename IdxRangeX1X2::discrete_element_type;
using DFieldX1X2 = DField<double, IdxRangeX1X2>;
using DConstFieldX1X2 = DConstField<double, IdxRangeX1X2>;
using DFieldX1X2 = DField<IdxRangeX1X2>;
using DConstFieldX1X2 = DConstField<IdxRangeX1X2>;

// Type for spline representation of the field
using IdxRangeBSFieldX1 = typename FieldX1Builder::batched_spline_domain_type;
Expand Down Expand Up @@ -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));
}
};
16 changes: 15 additions & 1 deletion tests/math_tools/test_partial_derivatives.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,21 @@ TEST(PartialDerivative, PartialDerivativeDx)
PartialDerivative<GridX, GridX, GridY, SplineXBuilder, SplineXEvaluator> 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

0 comments on commit 648f9c5

Please sign in to comment.