14#include <Kokkos_Core.hpp>
28struct PeriodicSamplingBase
32void print_periodic_sampling(std::ostream& os, CoordinateElement origin, Real step);
37
40 : detail::PeriodicSamplingBase
44 using continuous_dimension_type = CDim;
49 template <
class DDim,
class MemorySpace>
52 template <
class ODDim,
class OMemorySpace>
56 Coordinate<CDim> m_origin;
60 std::size_t m_n_period;
62 DiscreteElement<DDim> m_reference;
69 using discrete_element_type = DiscreteElement<DDim>;
77 , m_reference(create_reference_discrete_element<DDim>())
83 template <
class OriginMemorySpace>
84 explicit Impl(
Impl<DDim, OriginMemorySpace>
const& impl)
85 : m_origin(impl.m_origin)
87 , m_n_period(impl.m_n_period)
88 , m_reference(impl.m_reference)
95
96
97
98
99
100 Impl(Coordinate<CDim> origin, Real step, std::size_t n_period)
103 , m_n_period(n_period)
104 , m_reference(create_reference_discrete_element<DDim>())
107 assert(n_period > 0);
117 KOKKOS_FUNCTION Coordinate<CDim>
origin()
const noexcept
123 KOKKOS_FUNCTION discrete_element_type
front()
const noexcept
129 KOKKOS_FUNCTION Real
step()
const
135 KOKKOS_FUNCTION std::size_t
n_period()
const
142 discrete_element_type
const& icoord)
const noexcept
146 static_cast<
int>(((icoord -
front()) + m_n_period / 2) % m_n_period)
147 -
static_cast<
int>(m_n_period / 2))
153
154
155
156
157
158
159
160
161
162 template <
concepts::discrete_dimension DDim>
163 static std::tuple<
typename DDim::
template Impl<DDim, Kokkos::HostSpace>,
DiscreteDomain<DDim>>
164 init(Coordinate<CDim> a,
171 assert(n_period > 1);
172 typename DDim::
template Impl<DDim, Kokkos::HostSpace>
173 disc(a, Coordinate<CDim>((b - a) / (n - 1)), n_period);
175 return std::make_tuple(std::move(disc), std::move(domain));
179
180
181
182
183
184
185
186
187
188
189
190 template <
concepts::discrete_dimension DDim>
192 Impl<DDim, Kokkos::HostSpace>,
207 assert(n_period > 1);
208 Real
const discretization_step = (b - a) / (n - 1);
209 Impl<DDim, Kokkos::HostSpace>
210 disc(a - n_ghosts_before.value() * discretization_step,
213 DiscreteDomain<DDim> ghosted_domain(disc.front(), n + n_ghosts_before + n_ghosts_after);
214 DiscreteDomain<DDim> pre_ghost = ghosted_domain.take_first(n_ghosts_before);
215 DiscreteDomain<DDim> main_domain = ghosted_domain.remove(n_ghosts_before, n_ghosts_after);
216 DiscreteDomain<DDim> post_ghost = ghosted_domain.take_last(n_ghosts_after);
217 return std::make_tuple(
219 std::move(main_domain),
220 std::move(ghosted_domain),
221 std::move(pre_ghost),
222 std::move(post_ghost));
226
227
228
229
230
231
232
233
234
235
236 template <
concepts::discrete_dimension DDim>
238 Impl<DDim, Kokkos::HostSpace>,
250 return init_ghosted(a, b, n, n_period, n_ghosts, n_ghosts);
265concept periodic_sampling = discrete_dimension<T> && is_periodic_sampling_v<T>;
269template <
class DDimImpl>
270std::ostream& operator<<(std::ostream& os, DDimImpl
const& mesh)
271 requires(
concepts::periodic_sampling<
typename DDimImpl::discrete_dimension_type>)
273 detail::print_periodic_sampling(os, mesh.origin(), mesh.step());
278template <
concepts::periodic_sampling DDim>
281 return discrete_space<DDim>().origin();
285template <
concepts::periodic_sampling DDim>
286KOKKOS_FUNCTION DiscreteElement<DDim>
front()
noexcept
288 return discrete_space<DDim>().front();
292template <
concepts::periodic_sampling DDim>
293KOKKOS_FUNCTION Real
step()
noexcept
295 return discrete_space<DDim>().step();
298template <
concepts::periodic_sampling DDim>
300 DiscreteElement<DDim>
const& c)
302 return discrete_space<DDim>().coordinate(c);
305template <
concepts::periodic_sampling DDim>
307 DiscreteElement<DDim>)
309 return Coordinate<
typename DDim::continuous_dimension_type>(step<DDim>());
312template <
concepts::periodic_sampling DDim>
314 DiscreteElement<DDim>)
316 return Coordinate<
typename DDim::continuous_dimension_type>(step<DDim>());
319template <
concepts::periodic_sampling DDim>
323 return coordinate(d.front());
326template <
concepts::periodic_sampling DDim>
330 return coordinate(d.back());
333template <
concepts::periodic_sampling DDim>
337 return rmax(d) - rmin(d);
friend class DiscreteDomain
KOKKOS_FUNCTION constexpr bool operator!=(DiscreteVector< OTags... > const &rhs) const noexcept
Impl & operator=(Impl &&x)=default
KOKKOS_FUNCTION Coordinate< CDim > origin() const noexcept
Lower bound index of the mesh.
KOKKOS_FUNCTION discrete_element_type front() const noexcept
Lower bound index of the mesh.
KOKKOS_FUNCTION Coordinate< CDim > coordinate(discrete_element_type const &icoord) const noexcept
Convert a mesh index into a position in CDim
Impl(Impl const &)=delete
KOKKOS_FUNCTION std::size_t n_period() const
Number of steps in a period.
Impl(Impl< DDim, OriginMemorySpace > const &impl)
Impl(Coordinate< CDim > origin, Real step, std::size_t n_period)
Construct a Impl from a point and a spacing step.
KOKKOS_FUNCTION Real step() const
Spacing step of the mesh.
Impl & operator=(Impl const &x)=delete
PeriodicSampling models a periodic discretization of the provided continuous dimension.
static std::tuple< typename DDim::template Impl< DDim, Kokkos::HostSpace >, DiscreteDomain< DDim > > init(Coordinate< CDim > a, Coordinate< CDim > b, DiscreteVector< DDim > n, DiscreteVector< DDim > n_period)
Construct a Impl<Kokkos::HostSpace> and associated discrete_domain_type from a segment and a number ...
std::tuple< Impl< DDim, Kokkos::HostSpace >, DiscreteDomain< DDim >, DiscreteDomain< DDim >, DiscreteDomain< DDim >, DiscreteDomain< DDim > > init_ghosted(Coordinate< CDim > a, Coordinate< CDim > b, DiscreteVector< DDim > n, DiscreteVector< DDim > n_period, DiscreteVector< DDim > n_ghosts_before, DiscreteVector< DDim > n_ghosts_after)
Construct a periodic DiscreteDomain from a segment and a number of points n.
std::tuple< Impl< DDim, Kokkos::HostSpace >, DiscreteDomain< DDim >, DiscreteDomain< DDim >, DiscreteDomain< DDim >, DiscreteDomain< DDim > > init_ghosted(Coordinate< CDim > a, Coordinate< CDim > b, DiscreteVector< DDim > n, DiscreteVector< DDim > n_period, DiscreteVector< DDim > n_ghosts)
Construct a periodic DiscreteDomain from a segment and a number of points n.
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 > origin() noexcept
Lower bound index of the mesh.
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()
constexpr bool is_periodic_sampling_v
KOKKOS_FUNCTION Real step() noexcept
Spacing step of the mesh.
KOKKOS_FUNCTION DiscreteElement< DDim > front() noexcept
Lower bound index of the mesh.
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)