DDC 0.10.0
Loading...
Searching...
No Matches
view.hpp
1// Copyright (C) The DDC development team, see COPYRIGHT.md file
2//
3// SPDX-License-Identifier: MIT
4
5#pragma once
6
7#include <cstddef>
8#include <ostream>
9#include <utility>
10
11#include <Kokkos_Core.hpp>
12
13namespace ddc::detail {
14
15template <std::size_t N, class ElementType, bool CONTIGUOUS = true>
16struct ViewNDMaker;
17
18template <std::size_t N, class ElementType>
19struct ViewNDMaker<N, ElementType, true>
20{
21 using type
22 = Kokkos::mdspan<ElementType, Kokkos::dextents<std::size_t, N>, Kokkos::layout_right>;
23};
24
25template <std::size_t N, class ElementType>
26struct ViewNDMaker<N, ElementType, false>
27{
28 using type
29 = Kokkos::mdspan<ElementType, Kokkos::dextents<std::size_t, N>, Kokkos::layout_stride>;
30};
31
32/// Note: We use the comma operator to fill the input parameters
33///
34/// If Is=[1, 2], `subspan(s, i0, (Is, all)...)` will be expanded as
35/// `subspan(s, i0, (1, all), (2, all))` which is equivalent to
36/// `subspan(s, i0, all, all)`
37template <
38 class ElementType,
39 class Extents,
40 class Layout,
41 class Accessor,
42 std::size_t I0,
43 std::size_t... Is>
44std::ostream& stream_impl(
45 std::ostream& os,
46 Kokkos::mdspan<ElementType, Extents, Layout, Accessor> const& s,
47 std::index_sequence<I0, Is...>)
48{
49 if constexpr (sizeof...(Is) > 0) {
50 os << '[';
51 for (std::size_t i0 = 0; i0 < s.extent(I0); ++i0) {
52 stream_impl(
53 os,
54 Kokkos::submdspan(s, i0, ((void)Is, Kokkos::full_extent)...),
55 std::make_index_sequence<sizeof...(Is)>());
56 }
57 os << ']';
58 } else {
59 os << '[';
60 for (std::size_t i0 = 0; i0 < s.extent(I0) - 1; ++i0) {
61 os << s(i0) << ',';
62 }
63 os << s(s.extent(I0) - 1) << ']';
64 }
65 return os;
66}
67
68/// Convenient function to dump a mdspan, it recursively prints all dimensions.
69/// Disclaimer: use with caution for large arrays
70template <class ElementType, class Extents, class Layout, class Accessor>
71std::ostream& operator<<(
72 std::ostream& os,
73 Kokkos::mdspan<ElementType, Extents, Layout, Accessor> const& s)
74{
75 return ddc::detail::stream_impl(os, s, std::make_index_sequence<Extents::rank()>());
76}
77
78} // namespace ddc::detail
79
80namespace ddc {
81
82template <std::size_t N, class ElementType>
83using SpanND = Kokkos::mdspan<ElementType, Kokkos::dextents<std::size_t, N>>;
84
85template <std::size_t N, class ElementType>
86using ViewND = SpanND<N, ElementType const>;
87
88template <class ElementType>
89using Span1D = SpanND<1, ElementType>;
90
91template <class ElementType>
92using Span2D = SpanND<2, ElementType>;
93
94template <class ElementType>
95using View1D = ViewND<1, ElementType>;
96
97template <class ElementType>
98using View2D = ViewND<2, ElementType>;
99
100using DSpan1D = ddc::Span1D<double>;
101
102using DSpan2D = ddc::Span2D<double>;
103
104using CDSpan1D = ddc::Span1D<double const>;
105
106using CDSpan2D = ddc::Span2D<double const>;
107
108using DView1D = View1D<double>;
109
110using DView2D = View2D<double>;
111
112} // namespace ddc
friend class DiscreteDomain
KOKKOS_FUNCTION constexpr bool operator!=(DiscreteVector< OTags... > const &rhs) const noexcept
Storage class of the static attributes of the discrete dimension.
Impl & operator=(Impl &&x)=default
Move-assigns.
Impl(RandomIt breaks_begin, RandomIt breaks_end)
Constructs an Impl by iterating over a range of break points from begin to end.
KOKKOS_INLINE_FUNCTION ddc::Coordinate< CDim > rmin() const noexcept
Returns the coordinate of the first break point of the domain on which the B-splines are defined.
Impl(std::vector< ddc::Coordinate< CDim > > const &breaks)
Constructs an Impl using a std::vector.
KOKKOS_INLINE_FUNCTION discrete_element_type eval_basis(DSpan1D values, ddc::Coordinate< CDim > const &x) const
Evaluates non-zero B-splines at a given coordinate.
KOKKOS_INLINE_FUNCTION std::size_t size() const noexcept
Returns the number of elements necessary to construct a spline representation of a function.
Impl(Impl< DDim, OriginMemorySpace > const &impl)
Copy-constructs from another Impl with a different Kokkos memory space.
~Impl()=default
Destructs.
KOKKOS_INLINE_FUNCTION ddc::DiscreteDomain< knot_discrete_dimension_type > break_point_domain() const
Returns the discrete domain which describes the break points.
KOKKOS_INLINE_FUNCTION ddc::DiscreteElement< knot_discrete_dimension_type > get_last_support_knot(discrete_element_type const &ix) const
Returns the coordinate of the last support knot associated to a DiscreteElement identifying a B-splin...
Impl(Impl &&x)=default
Move-constructs.
Impl(std::initializer_list< ddc::Coordinate< CDim > > breaks)
Constructs an Impl using a brace-list, i.e.
KOKKOS_INLINE_FUNCTION discrete_element_type eval_basis_and_n_derivs(ddc::DSpan2D derivs, ddc::Coordinate< CDim > const &x, std::size_t n) const
Evaluates non-zero B-spline values and derivatives at a given coordinate.
KOKKOS_INLINE_FUNCTION std::size_t ncells() const noexcept
Returns the number of cells over which the B-splines are defined.
KOKKOS_INLINE_FUNCTION discrete_domain_type full_domain() const
Returns the discrete domain including eventual additional B-splines in the periodic case.
KOKKOS_INLINE_FUNCTION ddc::DiscreteElement< knot_discrete_dimension_type > get_first_support_knot(discrete_element_type const &ix) const
Returns the coordinate of the first support knot associated to a DiscreteElement identifying a B-spli...
KOKKOS_INLINE_FUNCTION std::size_t npoints() const noexcept
The number of break points.
KOKKOS_INLINE_FUNCTION std::size_t nbasis() const noexcept
Returns the number of basis functions.
Impl(Impl const &x)=default
Copy-constructs.
KOKKOS_INLINE_FUNCTION discrete_element_type eval_deriv(DSpan1D derivs, ddc::Coordinate< CDim > const &x) const
Evaluates non-zero B-spline derivatives at a given coordinate.
KOKKOS_INLINE_FUNCTION double length() const noexcept
Returns the length of the domain.
Impl & operator=(Impl const &x)=default
Copy-assigns.
KOKKOS_INLINE_FUNCTION ddc::Coordinate< CDim > rmax() const noexcept
Returns the coordinate of the last break point of the domain on which the B-splines are defined.
The type of a non-uniform 1D spline basis (B-spline).
static constexpr std::size_t degree() noexcept
The degree of B-splines.
static constexpr bool is_periodic() noexcept
Indicates if the B-splines are periodic or not.
static constexpr bool is_uniform() noexcept
Indicates if the B-splines are uniform or not (this is not the case here).
NonUniformPointSampling models a non-uniform discretization of the CDim segment .
The top-level namespace of DDC.
constexpr bool is_non_uniform_bsplines_v
Indicates if a tag corresponds to non-uniform B-splines or not.