13#include <Kokkos_Core.hpp>
15#include "ddc/coordinate.hpp"
16#include "ddc/discrete_domain.hpp"
17#include "ddc/discrete_element.hpp"
18#include "ddc/discrete_space.hpp"
19#include "ddc/discrete_vector.hpp"
20#include "ddc/real_type.hpp"
26struct UniformPointSamplingBase
33
38 using continuous_dimension_type = CDim;
40#if defined(DDC_BUILD_DEPRECATED_CODE)
41 using continuous_element_type
42 [[deprecated(
"Use ddc::Coordinate<continuous_dimension_type> instead.")]]
49 template <
class DDim,
class MemorySpace>
52 template <
class ODDim,
class OMemorySpace>
56 Coordinate<CDim> m_origin;
65 using discrete_element_type = DiscreteElement<DDim>;
69 Impl()
noexcept : m_origin(0), m_step(1) {}
73 template <
class OriginMemorySpace>
74 explicit Impl(
Impl<DDim, OriginMemorySpace>
const& impl)
75 : m_origin(impl.m_origin)
83
84
85
86
87 Impl(Coordinate<CDim> origin, Real step) : m_origin(origin), m_step(step)
107 return discrete_element_type(0);
118 discrete_element_type
const& icoord)
const noexcept
120 return m_origin + Coordinate<CDim>(icoord.uid() * m_step);
125
126
127
128
129
130
131
132
133 template <
class DDim>
134 static std::tuple<
typename DDim::
template Impl<DDim, Kokkos::HostSpace>,
DiscreteDomain<DDim>>
139 typename DDim::
template Impl<DDim, Kokkos::HostSpace>
140 disc(a, Coordinate<CDim>((b - a) / (n - 1)));
142 return std::make_tuple(std::move(disc), std::move(domain));
146
147
148
149
150
151
152
153
154
155
156 template <
class DDim>
158 typename DDim::
template Impl<DDim, Kokkos::HostSpace>,
172 Real
const discretization_step = (b - a) / (n - 1);
173 typename DDim::
template Impl<DDim, Kokkos::HostSpace>
174 disc(a - n_ghosts_before.value() * discretization_step, discretization_step);
175 DiscreteDomain<DDim> ghosted_domain(disc.front(), n + n_ghosts_before + n_ghosts_after);
176 DiscreteDomain<DDim> pre_ghost = ghosted_domain.take_first(n_ghosts_before);
177 DiscreteDomain<DDim> main_domain = ghosted_domain.remove(n_ghosts_before, n_ghosts_after);
178 DiscreteDomain<DDim> post_ghost = ghosted_domain.take_last(n_ghosts_after);
179 return std::make_tuple(
181 std::move(main_domain),
182 std::move(ghosted_domain),
183 std::move(pre_ghost),
184 std::move(post_ghost));
188
189
190
191
192
193
194
195
196
197 template <
class DDim>
199 typename DDim::
template Impl<DDim, Kokkos::HostSpace>,
210 return init_ghosted(a, b, n, n_ghosts, n_ghosts);
216 :
public std::is_base_of<detail::UniformPointSamplingBase, DDim>::type
226 is_uniform_point_sampling_v<
typename DDimImpl::discrete_dimension_type>,
229std::ostream& operator<<(std::ostream& out, DDimImpl
const& mesh)
231 return out <<
"UniformPointSampling( origin=" << mesh.origin() <<
", step=" << mesh.step()
235template <
class DDim, std::enable_if_t<is_uniform_point_sampling_v<DDim>,
int> = 0>
237 DiscreteElement<DDim>
const& c)
239 return discrete_space<DDim>().coordinate(c);
245 is_uniform_point_sampling_v<DDim>,
249 return discrete_space<DDim>().origin();
254KOKKOS_FUNCTION std::enable_if_t<is_uniform_point_sampling_v<DDim>, DiscreteElement<DDim>>
257 return discrete_space<DDim>().front();
264 return discrete_space<DDim>().step();
267template <
class DDim, std::enable_if_t<is_uniform_point_sampling_v<DDim>,
int> = 0>
268KOKKOS_FUNCTION Coordinate<
typename DDim::continuous_dimension_type> distance_at_left(
269 DiscreteElement<DDim>)
271 return Coordinate<
typename DDim::continuous_dimension_type>(step<DDim>());
274template <
class DDim, std::enable_if_t<is_uniform_point_sampling_v<DDim>,
int> = 0>
275KOKKOS_FUNCTION Coordinate<
typename DDim::continuous_dimension_type> distance_at_right(
276 DiscreteElement<DDim>)
278 return Coordinate<
typename DDim::continuous_dimension_type>(step<DDim>());
281template <
class DDim, std::enable_if_t<is_uniform_point_sampling_v<DDim>,
int> = 0>
282KOKKOS_FUNCTION Coordinate<
typename DDim::continuous_dimension_type> rmin(
285 return coordinate(d.front());
288template <
class DDim, std::enable_if_t<is_uniform_point_sampling_v<DDim>,
int> = 0>
289KOKKOS_FUNCTION Coordinate<
typename DDim::continuous_dimension_type> rmax(
292 return coordinate(d.back());
295template <
class DDim, std::enable_if_t<is_uniform_point_sampling_v<DDim>,
int> = 0>
296KOKKOS_FUNCTION Coordinate<
typename DDim::continuous_dimension_type> rlength(
299 return rmax(d) - rmin(d);
friend class DiscreteDomain
KOKKOS_FUNCTION constexpr bool operator!=(DiscreteVector< OTags... > const &rhs) const noexcept
The top-level namespace of DDC.
constexpr bool is_uniform_point_sampling_v
KOKKOS_FUNCTION std::enable_if_t< is_uniform_point_sampling_v< DDim >, DiscreteElement< DDim > > front() noexcept
Lower bound index of the mesh.
KOKKOS_FUNCTION std::enable_if_t< is_uniform_point_sampling_v< DDim >, Coordinate< typename DDim::continuous_dimension_type > > origin() noexcept
Lower bound index of the mesh.
KOKKOS_FUNCTION constexpr Coordinate< typename DDim::continuous_dimension_type > coordinate(DiscreteElement< DDim > const &c)
KOKKOS_FUNCTION std::enable_if_t< is_uniform_point_sampling_v< DDim >, Real > step() noexcept
Spacing step of the mesh.