Skip to content

Commit

Permalink
Fix neumann quadrature tests
Browse files Browse the repository at this point in the history
The tests in the targets `spline_quadrature_tests_xperiod_vx` and `spline_quadrature_tests_xnonperiod_vx` all rely on functions called `compute_error`. There are no namespaces to protect these functions so the compiler cannot distinguish between them when linking. As a result some of these functions (including the one for the Neumann quadrature) were not called. This has been fixed by adding anonymous namespaces. The Neumann test has also been fixed. The test case used was symmetric. As a result the errors were machine errors and convergence could not be observed. The new test case is a 5th degree polynomial.
  • Loading branch information
EmilyBourne committed Jan 24, 2024
1 parent ad29aa5 commit 8a770db
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
13 changes: 9 additions & 4 deletions tests/geometryXVx/neumann_quadrature_spline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#include "neumann_spline_quadrature.hpp"
#include "quadrature.hpp"

namespace {

TEST(NeumannSplineQuadratureTest, ExactForConstantFunc)
{
CoordVx const vx_min(0.0);
Expand Down Expand Up @@ -56,8 +58,8 @@ double compute_error(int n_elems)
using IDomainY = ddc::DiscreteDomain<IDimY>;
using DFieldY = ddc::Chunk<double, IDomainY>;

ddc::Coordinate<Y<N>> const y_min(0.0);
ddc::Coordinate<Y<N>> const y_max(M_PI);
ddc::Coordinate<Y<N>> const y_min(-1.0);
ddc::Coordinate<Y<N>> const y_max(1.0);

ddc::init_discrete_space<BSplinesY>(y_min, y_max, n_elems);

Expand All @@ -72,10 +74,11 @@ double compute_error(int n_elems)
DFieldY values(gridy);

ddc::for_each(gridy, [&](ddc::DiscreteElement<IDimY> const idx) {
values(idx) = cos(ddc::coordinate(idx));
double x = ddc::coordinate(idx);
values(idx) = (x + 1) * (x + 1) * (x + 1) * (x - 1) * (x - 1);
});
double integral = integrate(values);
return std::abs(2 - integral);
return std::abs(16.0 / 15.0 - integral);
}

template <std::size_t... Is>
Expand All @@ -97,3 +100,5 @@ TEST(NeumannSplineQuadratureTest, UniformConverge)
EXPECT_LE(order_error, 5e-2);
}
}

} // namespace
5 changes: 5 additions & 0 deletions tests/geometryXVx/quadrature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
#include "quadrature.hpp"
#include "simpson_quadrature.hpp"
#include "trapezoid_quadrature.hpp"

namespace {

struct RDimXPeriod
{
static bool constexpr PERIODIC = true;
Expand Down Expand Up @@ -169,3 +172,5 @@ TEST(QuadratureTest, SimpsonUniformConverge)
EXPECT_LE(order_error, 1e-2);
}
}

} // namespace
4 changes: 4 additions & 0 deletions tests/geometryXVx/quadrature_spline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#include "quadrature.hpp"
#include "spline_quadrature.hpp"

namespace {

TEST(SplineQuadratureTest, ExactForConstantFunc)
{
CoordX const x_min(0.0);
Expand Down Expand Up @@ -97,3 +99,5 @@ TEST(SplineQuadratureTest, UniformConverge)
EXPECT_LE(order_error, 5e-2);
}
}

} // namespace

0 comments on commit 8a770db

Please sign in to comment.