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;
44 template <
class DDim,
class MemorySpace>
47 template <
class ODDim,
class OMemorySpace>
51 Coordinate<CDim> m_origin;
55 std::size_t m_n_period;
57 DiscreteElement<DDim> m_reference;
64 using discrete_element_type = DiscreteElement<DDim>;
72 , m_reference(create_reference_discrete_element<DDim>())
78 template <
class OriginMemorySpace>
79 explicit Impl(
Impl<DDim, OriginMemorySpace>
const& impl)
80 : m_origin(impl.m_origin)
82 , m_n_period(impl.m_n_period)
83 , m_reference(impl.m_reference)
90
91
92
93
94
95 Impl(Coordinate<CDim> origin, Real step, std::size_t n_period)
98 , m_n_period(n_period)
99 , m_reference(create_reference_discrete_element<DDim>())
102 assert(n_period > 0);
137 discrete_element_type
const& icoord)
const noexcept
141 static_cast<
int>(((icoord -
front()) + m_n_period / 2) % m_n_period)
142 -
static_cast<
int>(m_n_period / 2))
148
149
150
151
152
153
154
155
156
157 template <
class DDim>
158 static std::tuple<
typename DDim::
template Impl<DDim, Kokkos::HostSpace>,
DiscreteDomain<DDim>>
159 init(Coordinate<CDim> a,
166 assert(n_period > 1);
167 typename DDim::
template Impl<DDim, Kokkos::HostSpace>
168 disc(a, Coordinate<CDim>((b - a) / (n - 1)), n_period);
170 return std::make_tuple(std::move(disc), std::move(domain));
174
175
176
177
178
179
180
181
182
183
184
185 template <
class DDim>
187 Impl<DDim, Kokkos::HostSpace>,
202 assert(n_period > 1);
203 Real
const discretization_step = (b - a) / (n - 1);
204 Impl<DDim, Kokkos::HostSpace>
205 disc(a - n_ghosts_before.value() * discretization_step,
208 DiscreteDomain<DDim> ghosted_domain(disc.front(), n + n_ghosts_before + n_ghosts_after);
209 DiscreteDomain<DDim> pre_ghost = ghosted_domain.take_first(n_ghosts_before);
210 DiscreteDomain<DDim> main_domain = ghosted_domain.remove(n_ghosts_before, n_ghosts_after);
211 DiscreteDomain<DDim> post_ghost = ghosted_domain.take_last(n_ghosts_after);
212 return std::make_tuple(
214 std::move(main_domain),
215 std::move(ghosted_domain),
216 std::move(pre_ghost),
217 std::move(post_ghost));
221
222
223
224
225
226
227
228
229
230
231 template <
class DDim>
233 Impl<DDim, Kokkos::HostSpace>,
245 return init_ghosted(a, b, n, n_period, n_ghosts, n_ghosts);
259 std::enable_if_t<is_periodic_sampling_v<
typename DDimImpl::discrete_dimension_type>,
int>
261std::ostream& operator<<(std::ostream& out, DDimImpl
const& mesh)
263 return out <<
"PeriodicSampling( origin=" << mesh.origin() <<
", step=" << mesh.step() <<
" )";
269 is_periodic_sampling_v<DDim>,
273 return discrete_space<DDim>().origin();
278KOKKOS_FUNCTION std::enable_if_t<is_periodic_sampling_v<DDim>, DiscreteElement<DDim>>
281 return discrete_space<DDim>().front();
288 return discrete_space<DDim>().step();
291template <
class DDim, std::enable_if_t<is_periodic_sampling_v<DDim>,
int> = 0>
292KOKKOS_FUNCTION Coordinate<
typename DDim::continuous_dimension_type> coordinate(
293 DiscreteElement<DDim>
const& c)
295 return discrete_space<DDim>().coordinate(c);
298template <
class DDim, std::enable_if_t<is_periodic_sampling_v<DDim>,
int> = 0>
299KOKKOS_FUNCTION Coordinate<
typename DDim::continuous_dimension_type> distance_at_left(
300 DiscreteElement<DDim>)
302 return Coordinate<
typename DDim::continuous_dimension_type>(step<DDim>());
305template <
class DDim, std::enable_if_t<is_periodic_sampling_v<DDim>,
int> = 0>
306KOKKOS_FUNCTION Coordinate<
typename DDim::continuous_dimension_type> distance_at_right(
307 DiscreteElement<DDim>)
309 return Coordinate<
typename DDim::continuous_dimension_type>(step<DDim>());
312template <
class DDim, std::enable_if_t<is_periodic_sampling_v<DDim>,
int> = 0>
313KOKKOS_FUNCTION Coordinate<
typename DDim::continuous_dimension_type> rmin(
316 return coordinate(d.front());
319template <
class DDim, std::enable_if_t<is_periodic_sampling_v<DDim>,
int> = 0>
320KOKKOS_FUNCTION Coordinate<
typename DDim::continuous_dimension_type> rmax(
323 return coordinate(d.back());
326template <
class DDim, std::enable_if_t<is_periodic_sampling_v<DDim>,
int> = 0>
327KOKKOS_FUNCTION Coordinate<
typename DDim::continuous_dimension_type> rlength(
330 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.