9#include <initializer_list>
16#include <Kokkos_Core.hpp>
18#include "ddc/coordinate.hpp"
19#include "ddc/discrete_domain.hpp"
20#include "ddc/discrete_element.hpp"
21#include "ddc/discrete_space.hpp"
22#include "ddc/discrete_vector.hpp"
28struct NonUniformPointSamplingBase
39 using continuous_dimension_type = CDim;
41 using continuous_element_type = Coordinate<CDim>;
47 template <
class DDim,
class MemorySpace>
50 template <
class ODDim,
class OMemorySpace>
53 Kokkos::View<continuous_element_type*, MemorySpace> m_points;
60 using discrete_element_type = DiscreteElement<DDim>;
67 Impl(std::initializer_list<continuous_element_type> points)
69 std::vector<continuous_element_type> host_points(points.begin(), points.end());
70 Kokkos::View<continuous_element_type*, Kokkos::HostSpace>
const
71 host(host_points.data(), host_points.size());
72 Kokkos::resize(m_points, host.extent(0));
73 Kokkos::deep_copy(m_points, host);
77 template <
class InputRange>
78 explicit Impl(InputRange
const& points)
80 if constexpr (Kokkos::is_view_v<InputRange>) {
81 Kokkos::deep_copy(m_points, points);
83 std::vector<continuous_element_type> host_points(points.begin(), points.end());
84 Kokkos::View<continuous_element_type*, Kokkos::HostSpace>
const
85 host(host_points.data(), host_points.size());
86 Kokkos::resize(m_points, host.extent(0));
87 Kokkos::deep_copy(m_points, host);
92 template <
class InputIt>
93 Impl(InputIt points_begin, InputIt points_end)
95 std::vector<continuous_element_type> host_points(points_begin, points_end);
96 Kokkos::View<continuous_element_type*, Kokkos::HostSpace>
const
97 host(host_points.data(), host_points.size());
98 Kokkos::resize(m_points, host.extent(0));
99 Kokkos::deep_copy(m_points, host);
102 template <
class OriginMemorySpace>
103 explicit Impl(
Impl<DDim, OriginMemorySpace>
const& impl)
104 : m_points(Kokkos::create_mirror_view_and_copy(MemorySpace(), impl.m_points))
120 return m_points.size();
126 return discrete_element_type {0};
131 coordinate(discrete_element_type
const& icoord)
const noexcept
133 return m_points(icoord.uid());
138
139
140
141
142 template <
class DDim,
class InputRange>
143 static std::tuple<
typename DDim::
template Impl<DDim, Kokkos::HostSpace>,
DiscreteDomain<DDim>>
144 init(InputRange
const non_uniform_points)
146 auto a = non_uniform_points.begin();
147 auto b = non_uniform_points.end();
148 auto n = std::distance(non_uniform_points.begin(), non_uniform_points.end());
151 typename DDim::
template Impl<DDim, Kokkos::HostSpace> disc(non_uniform_points);
153 return std::make_tuple(std::move(disc), std::move(domain));
157
158
159
160
161
162 template <
class DDim,
class InputRange>
164 typename DDim::
template Impl<DDim, Kokkos::HostSpace>,
170 InputRange
const& domain_r,
171 InputRange
const& pre_ghost_r,
172 InputRange
const& post_ghost_r)
175 auto n =
DiscreteVector<DDim> {std::distance(domain_r.begin(), domain_r.end())};
177 assert(domain_r.begin() < domain_r.end());
181 =
DiscreteVector<DDim> {std::distance(pre_ghost_r.begin(), pre_ghost_r.end())};
183 =
DiscreteVector<DDim> {std::distance(post_ghost_r.begin(), post_ghost_r.end())};
185 std::vector<
typename InputRange::value_type> full_domain;
187 std::copy(pre_ghost_r.begin(), pre_ghost_r.end(), std::back_inserter(full_domain));
188 std::copy(domain_r.begin(), domain_r.end(), std::back_inserter(full_domain));
189 std::copy(post_ghost_r.begin(), post_ghost_r.end(), std::back_inserter(full_domain));
191 typename DDim::
template Impl<DDim, Kokkos::HostSpace> disc(full_domain);
193 discrete_domain_type ghosted_domain
194 = discrete_domain_type(disc.front(), n + n_ghosts_before + n_ghosts_after);
195 discrete_domain_type pre_ghost
196 = discrete_domain_type(ghosted_domain.front(), n_ghosts_before);
197 discrete_domain_type main_domain
198 = discrete_domain_type(ghosted_domain.front() + n_ghosts_before, n);
199 discrete_domain_type post_ghost
200 = discrete_domain_type(main_domain.back() + 1, n_ghosts_after);
201 return std::make_tuple(
203 std::move(main_domain),
204 std::move(ghosted_domain),
205 std::move(pre_ghost),
206 std::move(post_ghost));
212 :
public std::is_base_of<detail::NonUniformPointSamplingBase, DDim>
222 is_non_uniform_point_sampling_v<
typename DDimImpl::discrete_dimension_type>,
225std::ostream& operator<<(std::ostream& out, DDimImpl
const& mesh)
227 return out <<
"NonUniformPointSampling(" << mesh.size() <<
")";
230template <
class DDim, std::enable_if_t<is_non_uniform_point_sampling_v<DDim>,
int> = 0>
232 DiscreteElement<DDim>
const& c)
234 return discrete_space<DDim>().coordinate(c);
237template <
class DDim, std::enable_if_t<is_non_uniform_point_sampling_v<DDim>,
int> = 0>
239 DiscreteElement<DDim> i)
241 return coordinate(i) - coordinate(i - 1);
244template <
class DDim, std::enable_if_t<is_non_uniform_point_sampling_v<DDim>,
int> = 0>
246 DiscreteElement<DDim> i)
248 return coordinate(i + 1) - coordinate(i);
251template <
class DDim, std::enable_if_t<is_non_uniform_point_sampling_v<DDim>,
int> = 0>
255 return coordinate(d.front());
258template <
class DDim, std::enable_if_t<is_non_uniform_point_sampling_v<DDim>,
int> = 0>
262 return coordinate(d.back());
265template <
class DDim, std::enable_if_t<is_non_uniform_point_sampling_v<DDim>,
int> = 0>
269 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)