14#include <Kokkos_Core.hpp>
27struct PeriodicSamplingBase
31void print_periodic_sampling(std::ostream& os, CoordinateElement origin, Real step);
36
41 using continuous_dimension_type = CDim;
46 template <
class DDim,
class MemorySpace>
49 template <
class ODDim,
class OMemorySpace>
53 Coordinate<CDim> m_origin;
57 std::size_t m_n_period;
59 DiscreteElement<DDim> m_reference;
66 using discrete_element_type = DiscreteElement<DDim>;
74 , m_reference(create_reference_discrete_element<DDim>())
80 template <
class OriginMemorySpace>
81 explicit Impl(
Impl<DDim, OriginMemorySpace>
const& impl)
82 : m_origin(impl.m_origin)
84 , m_n_period(impl.m_n_period)
85 , m_reference(impl.m_reference)
92
93
94
95
96
97 Impl(Coordinate<CDim> origin, Real step, std::size_t n_period)
100 , m_n_period(n_period)
101 , m_reference(create_reference_discrete_element<DDim>())
104 assert(n_period > 0);
114 KOKKOS_FUNCTION Coordinate<CDim>
origin()
const noexcept
120 KOKKOS_FUNCTION discrete_element_type
front()
const noexcept
126 KOKKOS_FUNCTION Real
step()
const
132 KOKKOS_FUNCTION std::size_t
n_period()
const
139 discrete_element_type
const& icoord)
const noexcept
143 static_cast<
int>(((icoord -
front()) + m_n_period / 2) % m_n_period)
144 -
static_cast<
int>(m_n_period / 2))
150
151
152
153
154
155
156
157
158
159 template <
class DDim>
160 static std::tuple<
typename DDim::
template Impl<DDim, Kokkos::HostSpace>,
DiscreteDomain<DDim>>
161 init(Coordinate<CDim> a,
168 assert(n_period > 1);
169 typename DDim::
template Impl<DDim, Kokkos::HostSpace>
170 disc(a, Coordinate<CDim>((b - a) / (n - 1)), n_period);
172 return std::make_tuple(std::move(disc), std::move(domain));
176
177
178
179
180
181
182
183
184
185
186
187 template <
class DDim>
189 Impl<DDim, Kokkos::HostSpace>,
204 assert(n_period > 1);
205 Real
const discretization_step = (b - a) / (n - 1);
206 Impl<DDim, Kokkos::HostSpace>
207 disc(a - n_ghosts_before.value() * discretization_step,
210 DiscreteDomain<DDim> ghosted_domain(disc.front(), n + n_ghosts_before + n_ghosts_after);
211 DiscreteDomain<DDim> pre_ghost = ghosted_domain.take_first(n_ghosts_before);
212 DiscreteDomain<DDim> main_domain = ghosted_domain.remove(n_ghosts_before, n_ghosts_after);
213 DiscreteDomain<DDim> post_ghost = ghosted_domain.take_last(n_ghosts_after);
214 return std::make_tuple(
216 std::move(main_domain),
217 std::move(ghosted_domain),
218 std::move(pre_ghost),
219 std::move(post_ghost));
223
224
225
226
227
228
229
230
231
232
233 template <
class DDim>
235 Impl<DDim, Kokkos::HostSpace>,
247 return init_ghosted(a, b, n, n_period, n_ghosts, n_ghosts);
262concept periodic_sampling = is_periodic_sampling_v<DDim>;
266template <
class DDimImpl>
267std::ostream& operator<<(std::ostream& os, DDimImpl
const& mesh)
268 requires(
concepts::periodic_sampling<
typename DDimImpl::discrete_dimension_type>)
270 detail::print_periodic_sampling(os, mesh.origin(), mesh.step());
275template <
concepts::periodic_sampling DDim>
278 return discrete_space<DDim>().origin();
282template <
concepts::periodic_sampling DDim>
283KOKKOS_FUNCTION DiscreteElement<DDim>
front()
noexcept
285 return discrete_space<DDim>().front();
289template <
concepts::periodic_sampling DDim>
290KOKKOS_FUNCTION Real
step()
noexcept
292 return discrete_space<DDim>().step();
295template <
concepts::periodic_sampling DDim>
297 DiscreteElement<DDim>
const& c)
299 return discrete_space<DDim>().coordinate(c);
302template <
concepts::periodic_sampling DDim>
304 DiscreteElement<DDim>)
306 return Coordinate<
typename DDim::continuous_dimension_type>(step<DDim>());
309template <
concepts::periodic_sampling DDim>
311 DiscreteElement<DDim>)
313 return Coordinate<
typename DDim::continuous_dimension_type>(step<DDim>());
316template <
concepts::periodic_sampling DDim>
320 return coordinate(d.front());
323template <
concepts::periodic_sampling DDim>
327 return coordinate(d.back());
330template <
concepts::periodic_sampling DDim>
334 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)