10#include <initializer_list>
18#include <Kokkos_Core.hpp>
20#include "ddc/coordinate.hpp"
21#include "ddc/discrete_domain.hpp"
22#include "ddc/discrete_element.hpp"
23#include "ddc/discrete_space.hpp"
24#include "ddc/discrete_vector.hpp"
30struct NonUniformPointSamplingBase
41 using continuous_dimension_type = CDim;
43#if defined(DDC_BUILD_DEPRECATED_CODE)
44 using continuous_element_type
45 [[deprecated(
"Use ddc::Coordinate<continuous_dimension_type> instead.")]]
52 template <
class DDim,
class MemorySpace>
55 template <
class ODDim,
class OMemorySpace>
58 Kokkos::View<Coordinate<CDim>*, MemorySpace> m_points;
65 using discrete_element_type = DiscreteElement<DDim>;
72 Impl(std::initializer_list<Coordinate<CDim>>
const points)
73 :
Impl(points.begin(), points.end())
78 template <
class InputRange>
79 explicit Impl(InputRange
const& points) :
Impl(points.begin(), points.end())
84 template <
class InputIt>
85 Impl(InputIt
const points_begin, InputIt
const points_end)
87 using view_type = Kokkos::View<Coordinate<CDim>*, MemorySpace>;
88 if (!std::is_sorted(points_begin, points_end)) {
89 throw std::runtime_error(
"Input points must be sorted");
92 std::vector<Coordinate<CDim>> host_points(points_begin, points_end);
93 m_points = view_type(
"NonUniformPointSampling::points", host_points.size());
94 Kokkos::deep_copy(m_points, view_type(host_points.data(), host_points.size()));
97 template <
class OriginMemorySpace>
98 explicit Impl(
Impl<DDim, OriginMemorySpace>
const& impl)
99 : m_points(Kokkos::create_mirror_view_and_copy(MemorySpace(), impl.m_points))
115 return m_points.size();
121 return discrete_element_type(0);
126 discrete_element_type
const& icoord)
const noexcept
128 return m_points(icoord.uid());
133
134
135
136
137 template <
class DDim,
class InputRange>
138 static std::tuple<
typename DDim::
template Impl<DDim, Kokkos::HostSpace>,
DiscreteDomain<DDim>>
139 init(InputRange
const& non_uniform_points)
141 assert(!non_uniform_points.empty());
143 typename DDim::
template Impl<DDim, Kokkos::HostSpace> disc(non_uniform_points);
145 return std::make_tuple(std::move(disc), std::move(domain));
149
150
151
152
153
154 template <
class DDim,
class InputRange>
156 typename DDim::
template Impl<DDim, Kokkos::HostSpace>,
162 InputRange
const& domain_r,
163 InputRange
const& pre_ghost_r,
164 InputRange
const& post_ghost_r)
166 assert(!domain_r.empty());
172 std::vector<
typename InputRange::value_type> full_domain;
174 std::copy(pre_ghost_r.begin(), pre_ghost_r.end(), std::back_inserter(full_domain));
175 std::copy(domain_r.begin(), domain_r.end(), std::back_inserter(full_domain));
176 std::copy(post_ghost_r.begin(), post_ghost_r.end(), std::back_inserter(full_domain));
178 typename DDim::
template Impl<DDim, Kokkos::HostSpace> disc(full_domain);
180 DiscreteDomain<DDim> ghosted_domain(disc.front(), n + n_ghosts_before + n_ghosts_after);
181 DiscreteDomain<DDim> pre_ghost = ghosted_domain.take_first(n_ghosts_before);
182 DiscreteDomain<DDim> main_domain = ghosted_domain.remove(n_ghosts_before, n_ghosts_after);
183 DiscreteDomain<DDim> post_ghost = ghosted_domain.take_last(n_ghosts_after);
184 return std::make_tuple(
186 std::move(main_domain),
187 std::move(ghosted_domain),
188 std::move(pre_ghost),
189 std::move(post_ghost));
195 :
public std::is_base_of<detail::NonUniformPointSamplingBase, DDim>::type
205 is_non_uniform_point_sampling_v<
typename DDimImpl::discrete_dimension_type>,
208std::ostream& operator<<(std::ostream& out, DDimImpl
const& mesh)
210 return out <<
"NonUniformPointSampling(" << mesh.size() <<
")";
213template <
class DDim, std::enable_if_t<is_non_uniform_point_sampling_v<DDim>,
int> = 0>
215 DiscreteElement<DDim>
const& c)
217 return discrete_space<DDim>().coordinate(c);
220template <
class DDim, std::enable_if_t<is_non_uniform_point_sampling_v<DDim>,
int> = 0>
222 DiscreteElement<DDim> i)
224 return coordinate(i) - coordinate(i - 1);
227template <
class DDim, std::enable_if_t<is_non_uniform_point_sampling_v<DDim>,
int> = 0>
229 DiscreteElement<DDim> i)
231 return coordinate(i + 1) - coordinate(i);
234template <
class DDim, std::enable_if_t<is_non_uniform_point_sampling_v<DDim>,
int> = 0>
238 return coordinate(d.front());
241template <
class DDim, std::enable_if_t<is_non_uniform_point_sampling_v<DDim>,
int> = 0>
245 return coordinate(d.back());
248template <
class DDim, std::enable_if_t<is_non_uniform_point_sampling_v<DDim>,
int> = 0>
252 return rmax(d) - rmin(d);
friend class DiscreteDomain
KOKKOS_FUNCTION constexpr bool operator!=(DiscreteVector< OTags... > const &rhs) const noexcept
The top-level namespace of DDC.
constexpr bool is_non_uniform_point_sampling_v
KOKKOS_FUNCTION Coordinate< typename DDim::continuous_dimension_type > rmax(DiscreteDomain< DDim > const &d)
KOKKOS_FUNCTION Coordinate< typename DDim::continuous_dimension_type > rlength(DiscreteDomain< DDim > const &d)
KOKKOS_FUNCTION Coordinate< typename DDim::continuous_dimension_type > distance_at_left(DiscreteElement< DDim > i)
KOKKOS_FUNCTION Coordinate< typename DDim::continuous_dimension_type > rmin(DiscreteDomain< DDim > const &d)
KOKKOS_FUNCTION Coordinate< typename DDim::continuous_dimension_type > coordinate(DiscreteElement< DDim > const &c)
KOKKOS_FUNCTION Coordinate< typename DDim::continuous_dimension_type > distance_at_right(DiscreteElement< DDim > i)