14#include <Kokkos_Core.hpp>
16#include "ddc/coordinate.hpp"
17#include "ddc/discrete_domain.hpp"
18#include "ddc/discrete_element.hpp"
19#include "ddc/discrete_space.hpp"
20#include "ddc/discrete_vector.hpp"
21#include "ddc/real_type.hpp"
27struct PeriodicSamplingBase
34
39 using continuous_dimension_type = CDim;
41#if defined(DDC_BUILD_DEPRECATED_CODE)
42 using continuous_element_type
43 [[deprecated(
"Use ddc::Coordinate<continuous_dimension_type> instead.")]]
50 template <
class DDim,
class MemorySpace>
53 template <
class ODDim,
class OMemorySpace>
57 Coordinate<CDim> m_origin;
61 std::size_t m_n_period;
68 using discrete_element_type = DiscreteElement<DDim>;
72 Impl()
noexcept : m_origin(0), m_step(1), m_n_period(2) {}
76 template <
class OriginMemorySpace>
77 explicit Impl(
Impl<DDim, OriginMemorySpace>
const& impl)
78 : m_origin(impl.m_origin)
80 , m_n_period(impl.m_n_period)
87
88
89
90
91
92 Impl(Coordinate<CDim> origin, Real step, std::size_t n_period)
95 , m_n_period(n_period)
116 return discrete_element_type(0);
133 discrete_element_type
const& icoord)
const noexcept
137 static_cast<
int>((icoord.uid() + m_n_period / 2) % m_n_period)
138 -
static_cast<
int>(m_n_period / 2))
144
145
146
147
148
149
150
151
152
153 template <
class DDim>
154 static std::tuple<
typename DDim::
template Impl<DDim, Kokkos::HostSpace>,
DiscreteDomain<DDim>>
155 init(Coordinate<CDim> a,
162 assert(n_period > 1);
163 typename DDim::
template Impl<DDim, Kokkos::HostSpace>
164 disc(a, Coordinate<CDim>((b - a) / (n - 1)), n_period);
166 return std::make_tuple(std::move(disc), std::move(domain));
170
171
172
173
174
175
176
177
178
179
180
181 template <
class DDim>
183 Impl<DDim, Kokkos::HostSpace>,
198 assert(n_period > 1);
199 Real
const discretization_step = (b - a) / (n - 1);
200 Impl<DDim, Kokkos::HostSpace>
201 disc(a - n_ghosts_before.value() * discretization_step,
204 DiscreteDomain<DDim> ghosted_domain(disc.front(), n + n_ghosts_before + n_ghosts_after);
205 DiscreteDomain<DDim> pre_ghost = ghosted_domain.take_first(n_ghosts_before);
206 DiscreteDomain<DDim> main_domain = ghosted_domain.remove(n_ghosts_before, n_ghosts_after);
207 DiscreteDomain<DDim> post_ghost = ghosted_domain.take_last(n_ghosts_after);
208 return std::make_tuple(
210 std::move(main_domain),
211 std::move(ghosted_domain),
212 std::move(pre_ghost),
213 std::move(post_ghost));
217
218
219
220
221
222
223
224
225
226
227 template <
class DDim>
229 Impl<DDim, Kokkos::HostSpace>,
241 return init_ghosted(a, b, n, n_period, n_ghosts, n_ghosts);
255 std::enable_if_t<is_periodic_sampling_v<
typename DDimImpl::discrete_dimension_type>,
int>
257std::ostream& operator<<(std::ostream& out, DDimImpl
const& mesh)
259 return out <<
"PeriodicSampling( origin=" << mesh.origin() <<
", step=" << mesh.step() <<
" )";
265 is_periodic_sampling_v<DDim>,
269 return discrete_space<DDim>().origin();
274KOKKOS_FUNCTION std::enable_if_t<is_periodic_sampling_v<DDim>, DiscreteElement<DDim>>
277 return discrete_space<DDim>().front();
284 return discrete_space<DDim>().step();
287template <
class DDim, std::enable_if_t<is_periodic_sampling_v<DDim>,
int> = 0>
288KOKKOS_FUNCTION Coordinate<
typename DDim::continuous_dimension_type> coordinate(
289 DiscreteElement<DDim>
const& c)
291 return discrete_space<DDim>().coordinate(c);
294template <
class DDim, std::enable_if_t<is_periodic_sampling_v<DDim>,
int> = 0>
295KOKKOS_FUNCTION Coordinate<
typename DDim::continuous_dimension_type> distance_at_left(
296 DiscreteElement<DDim>)
298 return Coordinate<
typename DDim::continuous_dimension_type>(step<DDim>());
301template <
class DDim, std::enable_if_t<is_periodic_sampling_v<DDim>,
int> = 0>
302KOKKOS_FUNCTION Coordinate<
typename DDim::continuous_dimension_type> distance_at_right(
303 DiscreteElement<DDim>)
305 return Coordinate<
typename DDim::continuous_dimension_type>(step<DDim>());
308template <
class DDim, std::enable_if_t<is_periodic_sampling_v<DDim>,
int> = 0>
309KOKKOS_FUNCTION Coordinate<
typename DDim::continuous_dimension_type> rmin(
312 return coordinate(d.front());
315template <
class DDim, std::enable_if_t<is_periodic_sampling_v<DDim>,
int> = 0>
316KOKKOS_FUNCTION Coordinate<
typename DDim::continuous_dimension_type> rmax(
319 return coordinate(d.back());
322template <
class DDim, std::enable_if_t<is_periodic_sampling_v<DDim>,
int> = 0>
323KOKKOS_FUNCTION Coordinate<
typename DDim::continuous_dimension_type> rlength(
326 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.
The top-level namespace of DDC.
KOKKOS_FUNCTION std::enable_if_t< is_periodic_sampling_v< DDim >, Real > step() noexcept
Spacing step of the mesh.
KOKKOS_FUNCTION std::enable_if_t< is_periodic_sampling_v< DDim >, Coordinate< typename DDim::continuous_dimension_type > > origin() noexcept
Lower bound index of the mesh.
constexpr bool is_periodic_sampling_v
KOKKOS_FUNCTION std::enable_if_t< is_periodic_sampling_v< DDim >, DiscreteElement< DDim > > front() noexcept
Lower bound index of the mesh.