-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
eaf94d3
commit fdc6c0b
Showing
3 changed files
with
173 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,159 @@ | ||
// Copyright (C) The DDC development team, see COPYRIGHT.md file | ||
// | ||
// SPDX-License-Identifier: MIT | ||
|
||
#include <algorithm> | ||
#include <cmath> | ||
#include <cstddef> | ||
#include <stdexcept> | ||
#include <tuple> | ||
|
||
#include "ddc/discrete_space.hpp" | ||
#include "ddc/non_uniform_point_sampling.hpp" | ||
#if defined(BSPLINES_TYPE_NON_UNIFORM) | ||
#include <vector> | ||
#endif | ||
|
||
#include <ddc/ddc.hpp> | ||
#include <ddc/kernels/splines.hpp> | ||
|
||
#include <gtest/gtest.h> | ||
|
||
#include <Kokkos_Core.hpp> | ||
|
||
#include "cosine_evaluator.hpp" | ||
#include "spline_error_bounds.hpp" | ||
|
||
struct DimX | ||
{ | ||
static constexpr bool PERIODIC = true; | ||
}; | ||
|
||
using CoordX = ddc::Coordinate<DimX>; | ||
|
||
static constexpr std::size_t s_degree_x = 2; | ||
|
||
struct BSplinesX : ddc::UniformBSplines<DimX, s_degree_x> | ||
{ | ||
}; | ||
|
||
struct IDimX : ddc::NonUniformPointSampling<DimX> | ||
{ | ||
}; | ||
|
||
TEST(SplineBuilder, ShortInterpolationGrid) | ||
{ | ||
using execution_space = Kokkos::DefaultExecutionSpace; | ||
using memory_space = Kokkos::HostSpace; | ||
|
||
CoordX constexpr x0(0.); | ||
CoordX constexpr xN(1.); | ||
std::size_t constexpr ncells = 5; | ||
|
||
ddc::init_discrete_space<BSplinesX>(x0, xN, ncells); | ||
|
||
// One point missing | ||
std::vector<double> const range {0.1, 0.3, 0.5, 0.7}; | ||
|
||
ddc::DiscreteDomain<IDimX> const interpolation_domain | ||
= ddc::init_discrete_space<IDimX>(IDimX::init<IDimX>(range)); | ||
|
||
EXPECT_THROW( | ||
(ddc::SplineBuilder< | ||
execution_space, | ||
memory_space, | ||
BSplinesX, | ||
IDimX, | ||
ddc::BoundCond::PERIODIC, | ||
ddc::BoundCond::PERIODIC, | ||
ddc::SplineSolver::GINKGO, | ||
IDimX>(interpolation_domain)), | ||
std::runtime_error); | ||
} | ||
|
||
TEST(SplineBuilder, LongInterpolationGrid) | ||
{ | ||
using execution_space = Kokkos::DefaultExecutionSpace; | ||
using memory_space = Kokkos::HostSpace; | ||
|
||
CoordX constexpr x0(0.); | ||
CoordX constexpr xN(1.); | ||
std::size_t constexpr ncells = 5; | ||
|
||
ddc::init_discrete_space<BSplinesX>(x0, xN, ncells); | ||
|
||
// One point too much | ||
std::vector<double> const range {0.1, 0.3, 0.5, 0.7, 0.9, 0.95}; | ||
|
||
ddc::DiscreteDomain<IDimX> const interpolation_domain | ||
= ddc::init_discrete_space<IDimX>(IDimX::init<IDimX>(range)); | ||
|
||
EXPECT_THROW( | ||
(ddc::SplineBuilder< | ||
execution_space, | ||
memory_space, | ||
BSplinesX, | ||
IDimX, | ||
ddc::BoundCond::PERIODIC, | ||
ddc::BoundCond::PERIODIC, | ||
ddc::SplineSolver::GINKGO, | ||
IDimX>(interpolation_domain)), | ||
std::runtime_error); | ||
} | ||
|
||
TEST(SplineBuilder, BadShapeInterpolationGrid) | ||
{ | ||
using execution_space = Kokkos::DefaultExecutionSpace; | ||
using memory_space = Kokkos::HostSpace; | ||
|
||
CoordX constexpr x0(0.); | ||
CoordX constexpr xN(1.); | ||
std::size_t constexpr ncells = 5; | ||
|
||
ddc::init_discrete_space<BSplinesX>(x0, xN, ncells); | ||
|
||
// All points end up in the first cell ]0, 0.2[ | ||
std::vector<double> const range {0.1, 0.11, 0.12, 0.13, 0.14}; | ||
|
||
ddc::DiscreteDomain<IDimX> const interpolation_domain | ||
= ddc::init_discrete_space<IDimX>(IDimX::init<IDimX>(range)); | ||
|
||
EXPECT_THROW( | ||
(ddc::SplineBuilder< | ||
execution_space, | ||
memory_space, | ||
BSplinesX, | ||
IDimX, | ||
ddc::BoundCond::PERIODIC, | ||
ddc::BoundCond::PERIODIC, | ||
ddc::SplineSolver::GINKGO, | ||
IDimX>(interpolation_domain)), | ||
std::runtime_error); | ||
} | ||
|
||
TEST(SplineBuilder, CorrectInterpolationGrid) | ||
{ | ||
using execution_space = Kokkos::DefaultExecutionSpace; | ||
using memory_space = Kokkos::HostSpace; | ||
|
||
CoordX constexpr x0(0.); | ||
CoordX constexpr xN(1.); | ||
std::size_t constexpr ncells = 5; | ||
|
||
ddc::init_discrete_space<BSplinesX>(x0, xN, ncells); | ||
|
||
std::vector<double> const range {0.1, 0.11, 0.25, 0.23, 0.24}; | ||
|
||
ddc::DiscreteDomain<IDimX> const interpolation_domain | ||
= ddc::init_discrete_space<IDimX>(IDimX::init<IDimX>(range)); | ||
|
||
EXPECT_NO_THROW((ddc::SplineBuilder< | ||
execution_space, | ||
memory_space, | ||
BSplinesX, | ||
IDimX, | ||
ddc::BoundCond::PERIODIC, | ||
ddc::BoundCond::PERIODIC, | ||
ddc::SplineSolver::GINKGO, | ||
IDimX>(interpolation_domain))); | ||
} |