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;
43 template <
class DDim,
class MemorySpace>
46 template <
class ODDim,
class OMemorySpace>
50 Coordinate<CDim> m_origin;
54 DiscreteElement<DDim> m_reference;
61 using discrete_element_type = DiscreteElement<DDim>;
68 , m_reference(create_reference_discrete_element<DDim>())
74 template <
class OriginMemorySpace>
75 explicit Impl(
Impl<DDim, OriginMemorySpace>
const& impl)
76 : m_origin(impl.m_origin)
78 , m_reference(impl.m_reference)
85
86
87
88
89 Impl(Coordinate<CDim> origin, Real step)
92 , m_reference(create_reference_discrete_element<DDim>())
123 discrete_element_type
const& icoord)
const noexcept
125 return m_origin + Coordinate<CDim>((icoord -
front()) * m_step);
130
131
132
133
134
135
136
137
138 template <
class DDim>
139 static std::tuple<
typename DDim::
template Impl<DDim, Kokkos::HostSpace>,
DiscreteDomain<DDim>>
144 typename DDim::
template Impl<DDim, Kokkos::HostSpace>
145 disc(a, Coordinate<CDim>((b - a) / (n - 1)));
147 return std::make_tuple(std::move(disc), std::move(domain));
151
152
153
154
155
156
157
158
159
160
161 template <
class DDim>
163 typename DDim::
template Impl<DDim, Kokkos::HostSpace>,
177 Real
const discretization_step = (b - a) / (n - 1);
178 typename DDim::
template Impl<DDim, Kokkos::HostSpace>
179 disc(a - n_ghosts_before.value() * discretization_step, discretization_step);
180 DiscreteDomain<DDim> ghosted_domain(disc.front(), n + n_ghosts_before + n_ghosts_after);
181 DiscreteDomain<DDim> pre_ghost = ghosted_domain.take_first(n_ghosts_before);
182 DiscreteDomain<DDim> main_domain = ghosted_domain.remove(n_ghosts_before, n_ghosts_after);
183 DiscreteDomain<DDim> post_ghost = ghosted_domain.take_last(n_ghosts_after);
184 return std::make_tuple(
186 std::move(main_domain),
187 std::move(ghosted_domain),
188 std::move(pre_ghost),
189 std::move(post_ghost));
193
194
195
196
197
198
199
200
201
202 template <
class DDim>
204 typename DDim::
template Impl<DDim, Kokkos::HostSpace>,
215 return init_ghosted(a, b, n, n_ghosts, n_ghosts);
221 :
public std::is_base_of<detail::UniformPointSamplingBase, DDim>::type
231 is_uniform_point_sampling_v<
typename DDimImpl::discrete_dimension_type>,
234std::ostream& operator<<(std::ostream& out, DDimImpl
const& mesh)
236 return out <<
"UniformPointSampling( origin=" << mesh.origin() <<
", step=" << mesh.step()
240template <
class DDim, std::enable_if_t<is_uniform_point_sampling_v<DDim>,
int> = 0>
242 DiscreteElement<DDim>
const& c)
244 return discrete_space<DDim>().coordinate(c);
250 is_uniform_point_sampling_v<DDim>,
254 return discrete_space<DDim>().origin();
259KOKKOS_FUNCTION std::enable_if_t<is_uniform_point_sampling_v<DDim>, DiscreteElement<DDim>>
262 return discrete_space<DDim>().front();
269 return discrete_space<DDim>().step();
272template <
class DDim, std::enable_if_t<is_uniform_point_sampling_v<DDim>,
int> = 0>
273KOKKOS_FUNCTION Coordinate<
typename DDim::continuous_dimension_type> distance_at_left(
274 DiscreteElement<DDim>)
276 return Coordinate<
typename DDim::continuous_dimension_type>(step<DDim>());
279template <
class DDim, std::enable_if_t<is_uniform_point_sampling_v<DDim>,
int> = 0>
280KOKKOS_FUNCTION Coordinate<
typename DDim::continuous_dimension_type> distance_at_right(
281 DiscreteElement<DDim>)
283 return Coordinate<
typename DDim::continuous_dimension_type>(step<DDim>());
286template <
class DDim, std::enable_if_t<is_uniform_point_sampling_v<DDim>,
int> = 0>
287KOKKOS_FUNCTION Coordinate<
typename DDim::continuous_dimension_type> rmin(
290 return coordinate(d.front());
293template <
class DDim, std::enable_if_t<is_uniform_point_sampling_v<DDim>,
int> = 0>
294KOKKOS_FUNCTION Coordinate<
typename DDim::continuous_dimension_type> rmax(
297 return coordinate(d.back());
300template <
class DDim, std::enable_if_t<is_uniform_point_sampling_v<DDim>,
int> = 0>
301KOKKOS_FUNCTION Coordinate<
typename DDim::continuous_dimension_type> rlength(
304 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.