6#include "ddc/chunk_span.hpp"
7#include "ddc/discrete_domain.hpp"
8#include "ddc/kokkos_allocator.hpp"
18 bool const is_uniform,
26 return is_uniform && ((N_BE_MIN != 0 && N_BE_MAX != 0) || is_periodic);
56 using tag_type =
typename InterpolationMesh::continuous_dimension_type;
84 ddc::detail::TypeSeq<
IDimX...>,
85 ddc::detail::TypeSeq<interpolation_mesh_type>>>;
89 ddc::detail::TypeSeq<
IDimX...>,
90 ddc::detail::TypeSeq<interpolation_mesh_type>,
91 ddc::detail::TypeSeq<bsplines_type>>>;
95 ddc::detail::TypeSeq<bsplines_type>,
97 ddc::detail::TypeSeq<
IDimX...>,
98 ddc::detail::TypeSeq<interpolation_mesh_type>>>>;
102 ddc::detail::TypeSeq<
IDimX...>,
103 ddc::detail::TypeSeq<interpolation_mesh_type>,
104 ddc::detail::TypeSeq<deriv_type>>>;
109 static constexpr bool s_odd = BSplines::degree() % 2;
139 std::unique_ptr<ddc::detail::Matrix> matrix;
156 "Incompatible boundary conditions");
160 if constexpr (bsplines_type::is_uniform()) {
195 return m_batched_interpolation_domain;
288 template <
class Layout>
304 = std::nullopt)
const;
311 void allocate_matrix(
317 void build_matrix_system();
337 IDimX...>::compute_offset(interpolation_domain_type
const& interpolation_domain)
340 if constexpr (bsplines_type::is_periodic()) {
343 std::experimental::mdspan<
345 std::experimental::extents<std::size_t, bsplines_type::degree() + 1>>
const
350 if constexpr (bsplines_type::degree() % 2 == 0) {
351 offset =
jmin.uid() -
start.uid() + bsplines_type::degree() / 2 - BSplines::degree();
353 int const mid = bsplines_type::degree() / 2;
355 - BSplines::degree();
393 throw std::runtime_error(
"ddc::BoundCond not handled");
406 throw std::runtime_error(
"ddc::BoundCond not handled");
441 throw std::runtime_error(
"ddc::BoundCond not handled");
454 throw std::runtime_error(
"ddc::BoundCond not handled");
490 matrix = ddc::detail::MatrixMaker::make_new_sparse<ExecSpace>(
495 build_matrix_system();
517 IDimX...>::build_matrix_system()
521 std::array<
double, (bsplines_type::degree() / 2 + 1) * (bsplines_type::degree() + 1)>
525 bsplines_type::degree() + 1,
526 bsplines_type::degree() / 2 + 1);
534 for (std::size_t
i = 0;
i < bsplines_type::degree() + 1; ++
i) {
535 for (std::size_t
j = 1;
j < bsplines_type::degree() / 2 + 1; ++
j) {
536 derivs(
i,
j) *= ddc::detail::ipow(m_dx,
j);
541 for (std::size_t
i = 0;
i < s_nbc_xmin; ++
i) {
542 for (std::size_t
j = 0;
j < bsplines_type::degree(); ++
j) {
543 matrix->set_element(
i,
j,
derivs(
j, s_nbc_xmin -
i - 1 + s_odd));
550 std::experimental::mdspan<
552 std::experimental::extents<std::size_t, bsplines_type::degree() + 1>>
const
555 int start = interpolation_domain().front().uid();
560 for (std::size_t
s = 0;
s < bsplines_type::degree() + 1; ++
s) {
561 int const j = ddc::detail::
562 modulo(
int(
jmin.uid() - m_offset +
s),
570 std::array<
double, (bsplines_type::degree() / 2 + 1) * (bsplines_type::degree() + 1)>
572 std::experimental::mdspan<
574 std::experimental::extents<
576 bsplines_type::degree() + 1,
586 for (std::size_t
i = 0;
i < bsplines_type::degree() + 1; ++
i) {
587 for (std::size_t
j = 1;
j < bsplines_type::degree() / 2 + 1; ++
j) {
588 derivs(
i,
j) *= ddc::detail::ipow(m_dx,
j);
594 for (std::size_t
j = 0;
j < bsplines_type::degree(); ++
j) {
595 for (std::size_t
i = 0;
i < s_nbc_xmax; ++
i) {
611template <
class Layout>
659 KOKKOS_LAMBDA(
typename batch_domain_type::discrete_element_type
j) {
660 for (
int i = s_nbc_xmin;
i > 0; --
i) {
663 * ddc::detail::ipow(
dx_proxy,
i + s_odd - 1);
676 KOKKOS_LAMBDA(
typename batch_domain_type::discrete_element_type
j) {
696 KOKKOS_LAMBDA(
typename batch_domain_type::discrete_element_type
j) {
697 for (
int i = 0;
i < s_nbc_xmax; ++
i) {
701 * ddc::detail::ipow(
dx_proxy,
i + s_odd);
709 batched_spline_tr_domain(),
715 KOKKOS_LAMBDA(
typename batch_domain_type::discrete_element_type
const j) {
722 Kokkos::View<double**, Kokkos::LayoutRight, exec_space>
bcoef_section(
725 batch_domain().size());
732 KOKKOS_LAMBDA(
typename batch_domain_type::discrete_element_type
const j) {
740 if (bsplines_type::is_periodic()) {
744 KOKKOS_LAMBDA(
typename batch_domain_type::discrete_element_type
const j) {
756 for (std::size_t
i(0);
i < bsplines_type::degree(); ++
i) {
Definition discrete_domain.hpp:51
A DiscreteElement identifies an element of the discrete dimension.
Definition discrete_element.hpp:146
KOKKOS_FUNCTION constexpr value_type & uid() noexcept
Definition discrete_element.hpp:223
A DiscreteVector is a vector in the discrete dimension.
Definition discrete_vector.hpp:254
Definition kokkos_allocator.hpp:17
A class for creating a spline approximation of a function.
Definition spline_builder.hpp:48
const ddc::detail::Matrix & get_interpolation_matrix() const noexcept
Get the interpolation matrix.
Definition spline_builder.hpp:267
static constexpr bool s_odd
Indicates if the degree of the splines is odd or even.
Definition spline_builder.hpp:109
ddc::DiscreteDomain< interpolation_mesh_type > interpolation_domain_type
The type of the domain for the interpolation mesh used by this class.
Definition spline_builder.hpp:78
batched_interpolation_domain_type batched_interpolation_domain() const noexcept
Definition spline_builder.hpp:193
batched_spline_tr_domain_type batched_spline_tr_domain() const noexcept
Definition spline_builder.hpp:236
SplineBuilder(batched_interpolation_domain_type const &batched_interpolation_domain, std::optional< int > cols_per_chunk=std::nullopt, std::optional< unsigned int > preconditionner_max_block_size=std::nullopt)
Definition spline_builder.hpp:145
batch_domain_type batch_domain() const noexcept
Definition spline_builder.hpp:211
typename ddc::detail::convert_type_seq_to_discrete_domain< ddc::type_seq_replace_t< ddc::detail::TypeSeq< IDimX... >, ddc::detail::TypeSeq< interpolation_mesh_type >, ddc::detail::TypeSeq< bsplines_type > > > batched_spline_domain_type
Definition spline_builder.hpp:87
void operator()(ddc::ChunkSpan< double, batched_spline_domain_type, Layout, memory_space > spline, ddc::ChunkSpan< double const, batched_interpolation_domain_type, Layout, memory_space > vals, std::optional< ddc::ChunkSpan< double const, batched_derivs_domain_type, Layout, memory_space > > const derivs_xmin=std::nullopt, std::optional< ddc::ChunkSpan< double const, batched_derivs_domain_type, Layout, memory_space > > const derivs_xmax=std::nullopt) const
Build a spline approximation of a function.
Definition spline_builder.hpp:621
SplineBuilder & operator=(SplineBuilder const &x)=delete
typename ddc::detail::convert_type_seq_to_discrete_domain< ddc::type_seq_remove_t< ddc::detail::TypeSeq< IDimX... >, ddc::detail::TypeSeq< interpolation_mesh_type > > > batch_domain_type
Definition spline_builder.hpp:82
ExecSpace exec_space
Definition spline_builder.hpp:59
static constexpr int s_nbc_xmax
The number of equations which define the boundary conditions at the upper bound.
Definition spline_builder.hpp:119
batched_derivs_domain_type batched_derivs_xmax_domain() const noexcept
Definition spline_builder.hpp:250
interpolation_domain_type interpolation_domain() const noexcept
Get the domain from which the approximation is defined.
Definition spline_builder.hpp:206
MemorySpace memory_space
Definition spline_builder.hpp:61
SplineBuilder(SplineBuilder const &x)=delete
batched_spline_domain_type batched_spline_domain() const noexcept
Get the domain on which the approximation is defined.
Definition spline_builder.hpp:229
InterpolationMesh interpolation_mesh_type
The type of the interpolation mesh used by this class.
Definition spline_builder.hpp:66
SplineBuilder(SplineBuilder &&x)=default
Create a new SplineBuilder by copy.
static constexpr int s_nbc_xmin
The number of equations which define the boundary conditions at the lower bound.
Definition spline_builder.hpp:114
typename ddc::detail::convert_type_seq_to_discrete_domain< ddc::type_seq_replace_t< ddc::detail::TypeSeq< IDimX... >, ddc::detail::TypeSeq< interpolation_mesh_type >, ddc::detail::TypeSeq< deriv_type > > > batched_derivs_domain_type
Definition spline_builder.hpp:100
BSplines bsplines_type
The type of the BSplines which are compatible with this class.
Definition spline_builder.hpp:71
batched_derivs_domain_type batched_derivs_xmin_domain() const noexcept
Definition spline_builder.hpp:241
typename ddc::detail::convert_type_seq_to_discrete_domain< ddc::type_seq_merge_t< ddc::detail::TypeSeq< bsplines_type >, ddc::type_seq_remove_t< ddc::detail::TypeSeq< IDimX... >, ddc::detail::TypeSeq< interpolation_mesh_type > > > > batched_spline_tr_domain_type
Definition spline_builder.hpp:93
ddc::DiscreteDomain< bsplines_type > spline_domain() const noexcept
Definition spline_builder.hpp:216
static constexpr ddc::BoundCond s_bc_xmax
The boundary condition implemented at the upper bound.
Definition spline_builder.hpp:129
SplineBuilder & operator=(SplineBuilder &&x)=default
Copy a SplineBuilder.
static constexpr ddc::BoundCond s_bc_xmin
The boundary condition implemented at the lower bound.
Definition spline_builder.hpp:124
The top-level namespace of DDC.
Definition aligned_allocator.hpp:11
constexpr int n_boundary_equations(ddc::BoundCond const bc, std::size_t const degree)
Definition spline_boundary_conditions.hpp:35
constexpr bool enable_chunk
Definition chunk_traits.hpp:16
KOKKOS_FUNCTION Coordinate< typename DDim::continuous_dimension_type > rmax(DiscreteDomain< DDim > const &d)
Definition non_uniform_point_sampling.hpp:182
ddc::Span2D< double > DSpan2D
Definition view.hpp:128
BoundCond
Definition spline_boundary_conditions.hpp:11
SplineSolver
Definition spline_builder.hpp:13
void for_each(DiscreteDomain< DDims... > const &domain, Functor &&f) noexcept
iterates over a nD domain in serial
Definition for_each.hpp:48
KOKKOS_FUNCTION Coordinate< typename DDim::continuous_dimension_type... > coordinate(DiscreteElement< DDim... > const &c)
Definition coordinate.hpp:29
KOKKOS_FUNCTION constexpr auto remove_dims_of(DiscreteDomain< DDimsA... > const &DDom_a, DiscreteDomain< DDimsB... > const &DDom_b) noexcept
Definition discrete_domain.hpp:438
KOKKOS_FUNCTION constexpr auto replace_dim_of(DiscreteDomain< DDimsA... > const &DDom_a, DiscreteDomain< DDimsB... > const &DDom_b) noexcept
Definition discrete_domain.hpp:485
void parallel_for_each(std::string const &label, ExecSpace const &execution_space, DiscreteDomain< DDims... > const &domain, Functor &&f) noexcept
iterates over a nD domain using a given Kokkos execution space
Definition parallel_for_each.hpp:155
KOKKOS_FUNCTION Coordinate< typename DDim::continuous_dimension_type > rmin(DiscreteDomain< DDim > const &d)
Definition non_uniform_point_sampling.hpp:175
constexpr bool is_spline_interpolation_mesh_uniform(bool const is_uniform, ddc::BoundCond const BcXmin, ddc::BoundCond const BcXmax, int degree)
Definition spline_builder.hpp:17
KOKKOS_FUNCTION detail::ddim_impl_t< DDim, MemorySpace > const & discrete_space()
Definition discrete_space.hpp:207
Definition chunk_span.hpp:30