10#include <initializer_list>
19#include <Kokkos_Core.hpp>
31struct NonUniformPointSamplingBase
35void print_non_uniform_point_samplig(std::ostream& os, std::size_t size);
44 using continuous_dimension_type = CDim;
49 template <
class DDim,
class MemorySpace>
52 template <
class ODDim,
class OMemorySpace>
55 Kokkos::View<Coordinate<CDim>*, MemorySpace> m_points;
57 DiscreteElement<DDim> m_reference;
64 using discrete_element_type = DiscreteElement<DDim>;
71 Impl(std::initializer_list<Coordinate<CDim>>
const points)
72 :
Impl(points.begin(), points.end())
77 template <
class InputRange>
78 explicit Impl(InputRange
const& points) :
Impl(points.begin(), points.end())
83 template <
class InputIt>
84 Impl(InputIt
const points_begin, InputIt
const points_end)
85 : m_reference(create_reference_discrete_element<DDim>())
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))
100 , m_reference(impl.m_reference)
114 KOKKOS_FUNCTION std::size_t
size()
const
116 return m_points.size();
120 KOKKOS_FUNCTION discrete_element_type
front()
const noexcept
127 discrete_element_type
const& icoord)
const noexcept
129 return m_points((icoord -
front()).value());
134
135
136
137
138 template <
class DDim,
class InputRange>
139 static std::tuple<
typename DDim::
template Impl<DDim, Kokkos::HostSpace>,
DiscreteDomain<DDim>>
140 init(InputRange
const& non_uniform_points)
142 assert(!non_uniform_points.empty());
144 typename DDim::
template Impl<DDim, Kokkos::HostSpace> disc(non_uniform_points);
146 return std::make_tuple(std::move(disc), std::move(domain));
150
151
152
153
154
155 template <
class DDim,
class InputRange>
157 typename DDim::
template Impl<DDim, Kokkos::HostSpace>,
163 InputRange
const& domain_r,
164 InputRange
const& pre_ghost_r,
165 InputRange
const& post_ghost_r)
167 assert(!domain_r.empty());
173 std::vector<
typename InputRange::value_type> full_domain;
175 std::copy(pre_ghost_r.begin(), pre_ghost_r.end(), std::back_inserter(full_domain));
176 std::copy(domain_r.begin(), domain_r.end(), std::back_inserter(full_domain));
177 std::copy(post_ghost_r.begin(), post_ghost_r.end(), std::back_inserter(full_domain));
179 typename DDim::
template Impl<DDim, Kokkos::HostSpace> disc(full_domain);
181 DiscreteDomain<DDim> ghosted_domain(disc.front(), n + n_ghosts_before + n_ghosts_after);
182 DiscreteDomain<DDim> pre_ghost = ghosted_domain.take_first(n_ghosts_before);
183 DiscreteDomain<DDim> main_domain = ghosted_domain.remove(n_ghosts_before, n_ghosts_after);
184 DiscreteDomain<DDim> post_ghost = ghosted_domain.take_last(n_ghosts_after);
185 return std::make_tuple(
187 std::move(main_domain),
188 std::move(ghosted_domain),
189 std::move(pre_ghost),
190 std::move(post_ghost));
196 :
public std::is_base_of<detail::NonUniformPointSamplingBase, DDim>::type
206concept non_uniform_point_sampling = is_non_uniform_point_sampling_v<DDim>;
210template <
class DDimImpl>
211std::ostream& operator<<(std::ostream& os, DDimImpl
const& mesh)
212 requires(
concepts::non_uniform_point_sampling<
typename DDimImpl::discrete_dimension_type>)
214 detail::print_non_uniform_point_samplig(os, mesh.size());
218template <
concepts::non_uniform_point_sampling DDim>
220 DiscreteElement<DDim>
const& c)
222 return discrete_space<DDim>().coordinate(c);
225template <
concepts::non_uniform_point_sampling DDim>
227 DiscreteElement<DDim> i)
229 return coordinate(i) - coordinate(i - 1);
232template <
concepts::non_uniform_point_sampling DDim>
234 DiscreteElement<DDim> i)
236 return coordinate(i + 1) - coordinate(i);
239template <
concepts::non_uniform_point_sampling DDim>
243 return coordinate(d.front());
246template <
concepts::non_uniform_point_sampling DDim>
250 return coordinate(d.back());
253template <
concepts::non_uniform_point_sampling DDim>
257 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)