14#include <Kokkos_Core.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);
112 KOKKOS_FUNCTION Coordinate<CDim>
origin()
const noexcept
118 KOKKOS_FUNCTION discrete_element_type
front()
const noexcept
124 KOKKOS_FUNCTION Real
step()
const
130 KOKKOS_FUNCTION std::size_t
n_period()
const
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);
260concept periodic_sampling = is_periodic_sampling_v<DDim>;
264template <
class DDimImpl>
265std::ostream& operator<<(std::ostream& out, DDimImpl
const& mesh)
266 requires(
concepts::periodic_sampling<
typename DDimImpl::discrete_dimension_type>)
268 return out <<
"PeriodicSampling( origin=" << mesh.origin() <<
", step=" << mesh.step() <<
" )";
272template <
concepts::periodic_sampling DDim>
275 return discrete_space<DDim>().origin();
279template <
concepts::periodic_sampling DDim>
280KOKKOS_FUNCTION DiscreteElement<DDim>
front()
noexcept
282 return discrete_space<DDim>().front();
286template <
concepts::periodic_sampling DDim>
287KOKKOS_FUNCTION Real
step()
noexcept
289 return discrete_space<DDim>().step();
292template <
concepts::periodic_sampling DDim>
294 DiscreteElement<DDim>
const& c)
296 return discrete_space<DDim>().coordinate(c);
299template <
concepts::periodic_sampling DDim>
301 DiscreteElement<DDim>)
303 return Coordinate<
typename DDim::continuous_dimension_type>(step<DDim>());
306template <
concepts::periodic_sampling DDim>
308 DiscreteElement<DDim>)
310 return Coordinate<
typename DDim::continuous_dimension_type>(step<DDim>());
313template <
concepts::periodic_sampling DDim>
317 return coordinate(d.front());
320template <
concepts::periodic_sampling DDim>
324 return coordinate(d.back());
327template <
concepts::periodic_sampling DDim>
331 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(ScopeGuard &&x) noexcept=delete
ScopeGuard & operator=(ScopeGuard &&x) noexcept=delete
ScopeGuard(int, char **&)
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)