10#include <initializer_list>
19#include <Kokkos_Core.hpp>
32struct NonUniformPointSamplingBase
36void print_non_uniform_point_samplig(std::ostream& os, std::size_t size);
43 : detail::NonUniformPointSamplingBase
47 using continuous_dimension_type = CDim;
52 template <
class DDim,
class MemorySpace>
55 template <
class ODDim,
class OMemorySpace>
58 Kokkos::View<Coordinate<CDim>*, MemorySpace> m_points;
60 DiscreteElement<DDim> m_reference;
67 using discrete_element_type = DiscreteElement<DDim>;
74 Impl(std::initializer_list<Coordinate<CDim>>
const points)
75 :
Impl(points.begin(), points.end())
80 template <
class InputRange>
81 explicit Impl(InputRange
const& points) :
Impl(points.begin(), points.end())
86 template <
class InputIt>
87 Impl(InputIt
const points_begin, InputIt
const points_end)
88 : m_reference(create_reference_discrete_element<DDim>())
90 using view_type = Kokkos::View<Coordinate<CDim>*, MemorySpace>;
91 if (!std::is_sorted(points_begin, points_end)) {
92 throw std::runtime_error(
"Input points must be sorted");
95 std::vector<Coordinate<CDim>> host_points(points_begin, points_end);
96 m_points = view_type(
"NonUniformPointSampling::points", host_points.size());
97 Kokkos::deep_copy(m_points, view_type(host_points.data(), host_points.size()));
100 template <
class OriginMemorySpace>
101 explicit Impl(
Impl<DDim, OriginMemorySpace>
const& impl)
102 : m_points(Kokkos::create_mirror_view_and_copy(MemorySpace(), impl.m_points))
103 , m_reference(impl.m_reference)
117 KOKKOS_FUNCTION std::size_t
size()
const
119 return m_points.size();
123 KOKKOS_FUNCTION discrete_element_type
front()
const noexcept
130 discrete_element_type
const& icoord)
const noexcept
132 return m_points((icoord -
front()).value());
137
138
139
140
141 template <
concepts::discrete_dimension DDim,
class InputRange>
142 static std::tuple<
typename DDim::
template Impl<DDim, Kokkos::HostSpace>,
DiscreteDomain<DDim>>
143 init(InputRange
const& non_uniform_points)
145 assert(!non_uniform_points.empty());
147 typename DDim::
template Impl<DDim, Kokkos::HostSpace> disc(non_uniform_points);
149 return std::make_tuple(std::move(disc), std::move(domain));
153
154
155
156
157
158 template <
concepts::discrete_dimension DDim,
class InputRange>
160 typename DDim::
template Impl<DDim, Kokkos::HostSpace>,
166 InputRange
const& domain_r,
167 InputRange
const& pre_ghost_r,
168 InputRange
const& post_ghost_r)
170 assert(!domain_r.empty());
176 std::vector<
typename InputRange::value_type> full_domain;
178 std::copy(pre_ghost_r.begin(), pre_ghost_r.end(), std::back_inserter(full_domain));
179 std::copy(domain_r.begin(), domain_r.end(), std::back_inserter(full_domain));
180 std::copy(post_ghost_r.begin(), post_ghost_r.end(), std::back_inserter(full_domain));
182 typename DDim::
template Impl<DDim, Kokkos::HostSpace> disc(full_domain);
184 DiscreteDomain<DDim> ghosted_domain(disc.front(), n + n_ghosts_before + n_ghosts_after);
185 DiscreteDomain<DDim> pre_ghost = ghosted_domain.take_first(n_ghosts_before);
186 DiscreteDomain<DDim> main_domain = ghosted_domain.remove(n_ghosts_before, n_ghosts_after);
187 DiscreteDomain<DDim> post_ghost = ghosted_domain.take_last(n_ghosts_after);
188 return std::make_tuple(
190 std::move(main_domain),
191 std::move(ghosted_domain),
192 std::move(pre_ghost),
193 std::move(post_ghost));
199 :
public std::is_base_of<detail::NonUniformPointSamplingBase, T>::type
209concept non_uniform_point_sampling = discrete_dimension<T> && is_non_uniform_point_sampling_v<T>;
213template <
class DDimImpl>
214std::ostream& operator<<(std::ostream& os, DDimImpl
const& mesh)
215 requires(
concepts::non_uniform_point_sampling<
typename DDimImpl::discrete_dimension_type>)
217 detail::print_non_uniform_point_samplig(os, mesh.size());
221template <
concepts::non_uniform_point_sampling DDim>
223 DiscreteElement<DDim>
const& c)
225 return discrete_space<DDim>().coordinate(c);
228template <
concepts::non_uniform_point_sampling DDim>
230 DiscreteElement<DDim> i)
232 return coordinate(i) - coordinate(i - 1);
235template <
concepts::non_uniform_point_sampling DDim>
237 DiscreteElement<DDim> i)
239 return coordinate(i + 1) - coordinate(i);
242template <
concepts::non_uniform_point_sampling DDim>
246 return coordinate(d.front());
249template <
concepts::non_uniform_point_sampling DDim>
253 return coordinate(d.back());
256template <
concepts::non_uniform_point_sampling DDim>
260 return rmax(d) - rmin(d);
friend class DiscreteDomain
KOKKOS_FUNCTION constexpr bool operator!=(DiscreteVector< OTags... > const &rhs) const noexcept
ScopeGuard & operator=(ScopeGuard const &x)=delete
ScopeGuard(int argc, char **&argv)
ScopeGuard(ScopeGuard &&x) noexcept=delete
ScopeGuard & operator=(ScopeGuard &&x) noexcept=delete
ScopeGuard(ScopeGuard const &x)=delete
The top-level namespace of DDC.
constexpr bool is_non_uniform_point_sampling_v
KOKKOS_FUNCTION Coordinate< typename DDim::continuous_dimension_type > rlength(DiscreteDomain< DDim > const &d)
bool is_discrete_space_initialized() noexcept
KOKKOS_FUNCTION Coordinate< typename DDim::continuous_dimension_type > coordinate(DiscreteElement< DDim > const &c)
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 > distance_at_right(DiscreteElement< DDim > i)
void init_discrete_space(Args &&... args)
Initialize (emplace) a global singleton discrete space.
detail::ddim_impl_t< DDim, Kokkos::HostSpace > const & host_discrete_space()
KOKKOS_FUNCTION detail::ddim_impl_t< DDim, MemorySpace > const & discrete_space()
Arg0 init_discrete_space(std::tuple< DDimImpl, Arg0 > &&a)
Move construct a global singleton discrete space and pass through the other argument.
std::tuple< Arg0, Arg1, Args... > init_discrete_space(std::tuple< DDimImpl, Arg0, Arg1, Args... > &&a)
Move construct a global singleton discrete space and pass through remaining arguments.
KOKKOS_FUNCTION Coordinate< typename DDim::continuous_dimension_type > rmax(DiscreteDomain< DDim > const &d)