10#include <initializer_list>
19#include <Kokkos_Core.hpp>
21#include "coordinate.hpp"
22#include "discrete_domain.hpp"
23#include "discrete_element.hpp"
24#include "discrete_space.hpp"
25#include "discrete_vector.hpp"
31struct NonUniformPointSamplingBase
42 using continuous_dimension_type = CDim;
47 template <
class DDim,
class MemorySpace>
50 template <
class ODDim,
class OMemorySpace>
53 Kokkos::View<Coordinate<CDim>*, MemorySpace> m_points;
55 DiscreteElement<DDim> m_reference;
62 using discrete_element_type = DiscreteElement<DDim>;
69 Impl(std::initializer_list<Coordinate<CDim>>
const points)
70 :
Impl(points.begin(), points.end())
75 template <
class InputRange>
76 explicit Impl(InputRange
const& points) :
Impl(points.begin(), points.end())
81 template <
class InputIt>
82 Impl(InputIt
const points_begin, InputIt
const points_end)
83 : m_reference(create_reference_discrete_element<DDim>())
85 using view_type = Kokkos::View<Coordinate<CDim>*, MemorySpace>;
86 if (!std::is_sorted(points_begin, points_end)) {
87 throw std::runtime_error(
"Input points must be sorted");
90 std::vector<Coordinate<CDim>> host_points(points_begin, points_end);
91 m_points = view_type(
"NonUniformPointSampling::points", host_points.size());
92 Kokkos::deep_copy(m_points, view_type(host_points.data(), host_points.size()));
95 template <
class OriginMemorySpace>
96 explicit Impl(
Impl<DDim, OriginMemorySpace>
const& impl)
97 : m_points(Kokkos::create_mirror_view_and_copy(MemorySpace(), impl.m_points))
98 , m_reference(impl.m_reference)
114 return m_points.size();
125 discrete_element_type
const& icoord)
const noexcept
127 return m_points((icoord -
front()).value());
132
133
134
135
136 template <
class DDim,
class InputRange>
137 static std::tuple<
typename DDim::
template Impl<DDim, Kokkos::HostSpace>,
DiscreteDomain<DDim>>
138 init(InputRange
const& non_uniform_points)
140 assert(!non_uniform_points.empty());
142 typename DDim::
template Impl<DDim, Kokkos::HostSpace> disc(non_uniform_points);
144 return std::make_tuple(std::move(disc), std::move(domain));
148
149
150
151
152
153 template <
class DDim,
class InputRange>
155 typename DDim::
template Impl<DDim, Kokkos::HostSpace>,
161 InputRange
const& domain_r,
162 InputRange
const& pre_ghost_r,
163 InputRange
const& post_ghost_r)
165 assert(!domain_r.empty());
171 std::vector<
typename InputRange::value_type> full_domain;
173 std::copy(pre_ghost_r.begin(), pre_ghost_r.end(), std::back_inserter(full_domain));
174 std::copy(domain_r.begin(), domain_r.end(), std::back_inserter(full_domain));
175 std::copy(post_ghost_r.begin(), post_ghost_r.end(), std::back_inserter(full_domain));
177 typename DDim::
template Impl<DDim, Kokkos::HostSpace> disc(full_domain);
179 DiscreteDomain<DDim> ghosted_domain(disc.front(), n + n_ghosts_before + n_ghosts_after);
180 DiscreteDomain<DDim> pre_ghost = ghosted_domain.take_first(n_ghosts_before);
181 DiscreteDomain<DDim> main_domain = ghosted_domain.remove(n_ghosts_before, n_ghosts_after);
182 DiscreteDomain<DDim> post_ghost = ghosted_domain.take_last(n_ghosts_after);
183 return std::make_tuple(
185 std::move(main_domain),
186 std::move(ghosted_domain),
187 std::move(pre_ghost),
188 std::move(post_ghost));
194 :
public std::is_base_of<detail::NonUniformPointSamplingBase, DDim>::type
204 is_non_uniform_point_sampling_v<
typename DDimImpl::discrete_dimension_type>,
207std::ostream& operator<<(std::ostream& out, DDimImpl
const& mesh)
209 return out <<
"NonUniformPointSampling(" << mesh.size() <<
")";
212template <
class DDim, std::enable_if_t<is_non_uniform_point_sampling_v<DDim>,
int> = 0>
214 DiscreteElement<DDim>
const& c)
216 return discrete_space<DDim>().coordinate(c);
219template <
class DDim, std::enable_if_t<is_non_uniform_point_sampling_v<DDim>,
int> = 0>
221 DiscreteElement<DDim> i)
223 return coordinate(i) - coordinate(i - 1);
226template <
class DDim, std::enable_if_t<is_non_uniform_point_sampling_v<DDim>,
int> = 0>
228 DiscreteElement<DDim> i)
230 return coordinate(i + 1) - coordinate(i);
233template <
class DDim, std::enable_if_t<is_non_uniform_point_sampling_v<DDim>,
int> = 0>
237 return coordinate(d.front());
240template <
class DDim, std::enable_if_t<is_non_uniform_point_sampling_v<DDim>,
int> = 0>
244 return coordinate(d.back());
247template <
class DDim, std::enable_if_t<is_non_uniform_point_sampling_v<DDim>,
int> = 0>
251 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)