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 using continuous_element_type = Coordinate<CDim>;
47 template <
class DDim,
class MemorySpace>
50 template <
class ODDim,
class OMemorySpace>
54 continuous_element_type m_origin {0};
58 std::size_t m_n_period {2};
65 using discrete_element_type = DiscreteElement<DDim>;
73 template <
class OriginMemorySpace>
74 explicit Impl(
Impl<DDim, OriginMemorySpace>
const& impl)
75 : m_origin(impl.m_origin)
77 , m_n_period(impl.m_n_period)
84
85
86
87
88
89 Impl(continuous_element_type origin, Real step, std::size_t n_period)
92 , m_n_period(n_period)
113 return discrete_element_type {0};
130 coordinate(discrete_element_type
const& icoord)
const noexcept
133 + continuous_element_type(
134 static_cast<
int>((icoord.uid() + m_n_period / 2) % m_n_period)
135 -
static_cast<
int>(m_n_period / 2))
141
142
143
144
145
146
147
148
149
150 template <
class DDim>
151 static std::tuple<
typename DDim::
template Impl<DDim, Kokkos::HostSpace>,
DiscreteDomain<DDim>>
152 init(Coordinate<CDim> a,
159 assert(n_period > 1);
160 typename DDim::
template Impl<DDim, Kokkos::HostSpace>
161 disc(a, Coordinate<CDim> {(b - a) / (n - 1)}, n_period);
163 return std::make_tuple(std::move(disc), std::move(domain));
167
168
169
170
171
172
173
174
175
176
177
178 template <
class DDim>
180 Impl<DDim, Kokkos::HostSpace>,
186 continuous_element_type a,
187 continuous_element_type b,
196 assert(n_period > 1);
197 Real discretization_step {(b - a) / (n - 1)};
198 Impl<DDim, Kokkos::HostSpace>
199 disc(a - n_ghosts_before.value() * discretization_step,
202 discrete_domain_type ghosted_domain
203 = discrete_domain_type(disc.front(), n + n_ghosts_before + n_ghosts_after);
204 discrete_domain_type pre_ghost
205 = discrete_domain_type(ghosted_domain.front(), n_ghosts_before);
206 discrete_domain_type main_domain
207 = discrete_domain_type(ghosted_domain.front() + n_ghosts_before, n);
208 discrete_domain_type post_ghost
209 = discrete_domain_type(main_domain.back() + 1, n_ghosts_after);
210 return std::make_tuple(
212 std::move(main_domain),
213 std::move(ghosted_domain),
214 std::move(pre_ghost),
215 std::move(post_ghost));
219
220
221
222
223
224
225
226
227
228
229 template <
class DDim>
231 Impl<DDim, Kokkos::HostSpace>,
237 continuous_element_type a,
238 continuous_element_type b,
243 return init_ghosted(a, b, n, n_period, n_ghosts, n_ghosts);
257 std::enable_if_t<is_periodic_sampling_v<
typename DDimImpl::discrete_dimension_type>,
int>
259std::ostream& operator<<(std::ostream& out, DDimImpl
const& mesh)
261 return out <<
"PeriodicSampling( origin=" << mesh.origin() <<
", step=" << mesh.step() <<
" )";
267 is_periodic_sampling_v<DDim>,
271 return discrete_space<DDim>().origin();
276KOKKOS_FUNCTION std::enable_if_t<is_periodic_sampling_v<DDim>, DiscreteElement<DDim>>
279 return discrete_space<DDim>().front();
286 return discrete_space<DDim>().step();
289template <
class DDim, std::enable_if_t<is_periodic_sampling_v<DDim>,
int> = 0>
290KOKKOS_FUNCTION Coordinate<
typename DDim::continuous_dimension_type> coordinate(
291 DiscreteElement<DDim>
const& c)
293 return discrete_space<DDim>().coordinate(c);
296template <
class DDim, std::enable_if_t<is_periodic_sampling_v<DDim>,
int> = 0>
297KOKKOS_FUNCTION Coordinate<
typename DDim::continuous_dimension_type> distance_at_left(
298 DiscreteElement<DDim>)
300 return Coordinate<
typename DDim::continuous_dimension_type>(step<DDim>());
303template <
class DDim, std::enable_if_t<is_periodic_sampling_v<DDim>,
int> = 0>
304KOKKOS_FUNCTION Coordinate<
typename DDim::continuous_dimension_type> distance_at_right(
305 DiscreteElement<DDim>)
307 return Coordinate<
typename DDim::continuous_dimension_type>(step<DDim>());
310template <
class DDim, std::enable_if_t<is_periodic_sampling_v<DDim>,
int> = 0>
311KOKKOS_FUNCTION Coordinate<
typename DDim::continuous_dimension_type> rmin(
314 return coordinate(d.front());
317template <
class DDim, std::enable_if_t<is_periodic_sampling_v<DDim>,
int> = 0>
318KOKKOS_FUNCTION Coordinate<
typename DDim::continuous_dimension_type> rmax(
321 return coordinate(d.back());
324template <
class DDim, std::enable_if_t<is_periodic_sampling_v<DDim>,
int> = 0>
325KOKKOS_FUNCTION Coordinate<
typename DDim::continuous_dimension_type> rlength(
328 return rmax(d) - rmin(d);
friend class DiscreteDomain
KOKKOS_FUNCTION constexpr bool operator!=(DiscreteVector< OTags... > const &rhs) const noexcept
Impl & operator=(Impl &&x)=default
Impl(continuous_element_type origin, Real step, std::size_t n_period)
Construct a Impl from a point and a spacing step.
KOKKOS_FUNCTION discrete_element_type front() const noexcept
Lower bound index of the mesh.
Impl(Impl const &)=delete
KOKKOS_FUNCTION std::size_t n_period() const
Number of steps in a period.
KOKKOS_FUNCTION continuous_element_type origin() const noexcept
Lower bound index of the mesh.
KOKKOS_FUNCTION continuous_element_type coordinate(discrete_element_type const &icoord) const noexcept
Convert a mesh index into a position in CDim
Impl(Impl< DDim, OriginMemorySpace > const &impl)
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.
std::tuple< Impl< DDim, Kokkos::HostSpace >, DiscreteDomain< DDim >, DiscreteDomain< DDim >, DiscreteDomain< DDim >, DiscreteDomain< DDim > > init_ghosted(continuous_element_type a, continuous_element_type 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.
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(continuous_element_type a, continuous_element_type 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.
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.