DDC 0.10.0
Loading...
Searching...
No Matches
sparse_discrete_domain.hpp
1// Copyright (C) The DDC development team, see COPYRIGHT.md file
2//
3// SPDX-License-Identifier: MIT
4
5#pragma once
6
7#include <cstddef>
8#include <functional>
9#include <iterator>
10#include <string>
11#include <tuple>
12#include <type_traits>
13
14#include <Kokkos_Core.hpp>
15
16#include "detail/tagged_vector.hpp"
17#include "detail/type_seq.hpp"
18
21
22namespace ddc {
23
24template <class DDim>
25struct SparseDiscreteDomainIterator;
26
27template <class... DDims>
29
30template <class T>
31struct is_sparse_discrete_domain : std::false_type
32{
33};
34
35template <class... Tags>
36struct is_sparse_discrete_domain<SparseDiscreteDomain<Tags...>> : std::true_type
37{
38};
39
40template <class T>
42
43
44namespace detail {
45
46template <class... Tags>
47struct ToTypeSeq<SparseDiscreteDomain<Tags...>>
48{
49 using type = TypeSeq<Tags...>;
50};
51
52template <class T, class U>
53struct RebindDomain;
54
55template <class... DDims, class... ODDims>
56struct RebindDomain<SparseDiscreteDomain<DDims...>, detail::TypeSeq<ODDims...>>
57{
58 using type = SparseDiscreteDomain<ODDims...>;
59};
60
61template <class InputIt1, class InputIt2>
62KOKKOS_FUNCTION bool equal(InputIt1 first1, InputIt1 last1, InputIt2 first2)
63{
64 for (; first1 != last1; ++first1, ++first2) {
65 if (!(*first1 == *first2)) {
66 return false;
67 }
68 }
69
70 return true;
71}
72
73template <
74 class ForwardIt,
75 class T = typename std::iterator_traits<ForwardIt>::value_type,
76 class Compare>
77KOKKOS_FUNCTION ForwardIt lower_bound(ForwardIt first, ForwardIt last, T const& value, Compare comp)
78{
79 ForwardIt it;
80 typename std::iterator_traits<ForwardIt>::difference_type count = last - first;
81 while (count > 0) {
82 it = first;
83 typename std::iterator_traits<ForwardIt>::difference_type const step = count / 2;
84 it += step;
85
86 if (comp(*it, value)) {
87 first = ++it;
88 count -= step + 1;
89 } else {
90 count = step;
91 }
92 }
93
94 return first;
95}
96
97template <
98 class ForwardIt,
99 class T = typename std::iterator_traits<ForwardIt>::value_type,
100 class Compare>
101KOKKOS_FUNCTION bool binary_search(ForwardIt first, ForwardIt last, T const& value, Compare comp)
102{
103 first = ::ddc::detail::lower_bound(first, last, value, comp);
104 return (!(first == last) && !(comp(value, *first)));
105}
106
107template <class DDim>
108Kokkos::View<DiscreteElementType*, Kokkos::SharedSpace> extract_uid(
109 Kokkos::View<DiscreteElement<DDim>*, Kokkos::SharedSpace> const& input)
110{
111 Kokkos::View<DiscreteElementType*, Kokkos::SharedSpace> output(input.label(), input.size());
112 Kokkos::parallel_for(
113 "SparseDiscreteDomainCtor",
114 output.size(),
115 KOKKOS_LAMBDA(std::size_t const i) { output(i) = input(i).uid(); });
116 return output;
117}
118
119} // namespace detail
120
121template <class... DDims>
123{
124 template <class...>
125 friend class SparseDiscreteDomain;
126
127 static_assert(
128 type_seq_is_unique_v<detail::TypeSeq<DDims...>>,
129 "The dimensions of a SparseDiscreteDomain must be unique");
130
131public:
132 using discrete_element_type = DiscreteElement<DDims...>;
133
134 using discrete_vector_type = DiscreteVector<DDims...>;
135
136private:
137 detail::TaggedVector<Kokkos::View<DiscreteElementType*, Kokkos::SharedSpace>, DDims...> m_views;
138
139public:
140 static KOKKOS_FUNCTION constexpr std::size_t rank()
141 {
142 return sizeof...(DDims);
143 }
144
145 KOKKOS_DEFAULTED_FUNCTION SparseDiscreteDomain() = default;
146
147 /// Construct a SparseDiscreteDomain by copies and merge of domains
148 template <class... DDoms, class = std::enable_if_t<(is_sparse_discrete_domain_v<DDoms> && ...)>>
149 KOKKOS_FUNCTION constexpr explicit SparseDiscreteDomain(DDoms const&... domains)
150 : m_views(domains.m_views...)
151 {
152 }
153
154 /** Construct a SparseDiscreteDomain with Kokkos::View explicitly listing the discrete elements.
155 * @param views list of Kokkos::View
156 */
157 explicit SparseDiscreteDomain(
158 Kokkos::View<DiscreteElement<DDims>*, Kokkos::SharedSpace> const&... views)
159 {
160 ((m_views[type_seq_rank_v<DDims, detail::TypeSeq<DDims...>>] = detail::extract_uid(views)),
161 ...);
162 }
163
164 KOKKOS_DEFAULTED_FUNCTION SparseDiscreteDomain(SparseDiscreteDomain const& x) = default;
165
166 KOKKOS_DEFAULTED_FUNCTION SparseDiscreteDomain(SparseDiscreteDomain&& x) = default;
167
168 KOKKOS_DEFAULTED_FUNCTION ~SparseDiscreteDomain() = default;
169
170 KOKKOS_DEFAULTED_FUNCTION SparseDiscreteDomain& operator=(SparseDiscreteDomain const& x)
171 = default;
172
173 KOKKOS_DEFAULTED_FUNCTION SparseDiscreteDomain& operator=(SparseDiscreteDomain&& x) = default;
174
175 template <class... ODims>
176 KOKKOS_FUNCTION constexpr bool operator==(SparseDiscreteDomain<ODims...> const& other) const
177 {
178 if constexpr ((std::is_same_v<DDims, ODims> && ...)) {
179 if (empty() && other.empty()) {
180 return true;
181 }
182 for (std::size_t i = 0; i < m_views.size(); ++i) {
183 if (m_views[i].size() != other.m_views[i].size()) {
184 return false;
185 }
186 if (!detail::
187 equal(m_views[i].data(),
188 m_views[i].data() + m_views[i].size(),
189 other.m_views[i].data())) {
190 return false;
191 }
192 }
193 return true;
194 } else {
195 return *this == SparseDiscreteDomain(other);
196 }
197 }
198
199#if !defined(__cpp_impl_three_way_comparison) || __cpp_impl_three_way_comparison < 201902L
200 // In C++20, `a!=b` shall be automatically translated by the compiler to `!(a==b)`
201 template <class... ODims>
202 KOKKOS_FUNCTION constexpr bool operator!=(SparseDiscreteDomain<ODims...> const& other) const
203 {
204 return !(*this == other);
205 }
206#endif
207
208 KOKKOS_FUNCTION constexpr std::size_t size() const
209 {
210 return (1UL * ... * get<DDims>(m_views).size());
211 }
212
213 KOKKOS_FUNCTION constexpr discrete_vector_type extents() const noexcept
214 {
215 return discrete_vector_type(get<DDims>(m_views).size()...);
216 }
217
218 KOKKOS_FUNCTION constexpr auto discrete_elements() const noexcept
219 {
220 return m_views;
221 }
222
223 template <class QueryDDim>
224 KOKKOS_FUNCTION constexpr DiscreteVector<QueryDDim> extent() const noexcept
225 {
226 return DiscreteVector<QueryDDim>(get<QueryDDim>(m_views).size());
227 }
228
229 KOKKOS_FUNCTION constexpr discrete_element_type front() const noexcept
230 {
231 return discrete_element_type(get<DDims>(m_views)(0)...);
232 }
233
234 KOKKOS_FUNCTION constexpr discrete_element_type back() const noexcept
235 {
236 return discrete_element_type(get<DDims>(m_views)(get<DDims>(m_views).size() - 1)...);
237 }
238
239 KOKKOS_FUNCTION constexpr SparseDiscreteDomain take_first(discrete_vector_type n) const
240 {
241 return SparseDiscreteDomain(front(), n);
242 }
243
244 KOKKOS_FUNCTION constexpr SparseDiscreteDomain take_last(discrete_vector_type n) const
245 {
246 return SparseDiscreteDomain(front() + prod(extents() - n), n);
247 }
248
249 KOKKOS_FUNCTION constexpr SparseDiscreteDomain remove_first(discrete_vector_type n) const
250 {
251 return SparseDiscreteDomain(front() + prod(n), extents() - n);
252 }
253
254 KOKKOS_FUNCTION constexpr SparseDiscreteDomain remove_last(discrete_vector_type n) const
255 {
257 }
258
259 KOKKOS_FUNCTION constexpr SparseDiscreteDomain remove(
260 discrete_vector_type n1,
261 discrete_vector_type n2) const
262 {
263 return SparseDiscreteDomain(front() + prod(n1), extents() - n1 - n2);
264 }
265
266 KOKKOS_FUNCTION constexpr DiscreteElement<DDims...> operator()(
267 DiscreteVector<DDims...> const& dvect) const noexcept
268 {
269 return DiscreteElement<DDims...>(get<DDims>(m_views)(get<DDims>(dvect))...);
270 }
271
272 template <class... DElems>
273 KOKKOS_FUNCTION bool contains(DElems const&... delems) const noexcept
274 {
275 static_assert(
276 sizeof...(DDims) == (0 + ... + DElems::size()),
277 "Invalid number of dimensions");
278 static_assert((is_discrete_element_v<DElems> && ...), "Expected DiscreteElements");
279 DiscreteElement<DDims...> const delem(delems...);
280 for (std::size_t i = 0; i < rank(); ++i) {
281 if (!detail::binary_search(
282 m_views[i].data(),
283 m_views[i].data() + m_views[i].size(),
284 detail::array(delem)[i],
285 std::less {})) {
286 return false;
287 }
288 }
289 return true;
290 }
291
292 template <class... DElems>
293 KOKKOS_FUNCTION DiscreteVector<DDims...> distance_from_front(
294 DElems const&... delems) const noexcept
295 {
296 static_assert(
297 sizeof...(DDims) == (0 + ... + DElems::size()),
298 "Invalid number of dimensions");
299 static_assert((is_discrete_element_v<DElems> && ...), "Expected DiscreteElements");
300 KOKKOS_ASSERT(contains(delems...))
301 return DiscreteVector<DDims...>(
302 (detail::lower_bound(
303 get<DDims>(m_views).data(),
304 get<DDims>(m_views).data() + get<DDims>(m_views).size(),
305 uid<DDims>(take<DDims>(delems...)),
306 std::less {})
307 - get<DDims>(m_views).data())...);
308 }
309
310 KOKKOS_FUNCTION constexpr bool empty() const noexcept
311 {
312 return size() == 0;
313 }
314
315 KOKKOS_FUNCTION constexpr explicit operator bool()
316 {
317 return !empty();
318 }
319
320 template <
321 std::size_t N = sizeof...(DDims),
322 class DDim0 = std::enable_if_t<N == 1, std::tuple_element_t<0, std::tuple<DDims...>>>>
323 KOKKOS_FUNCTION auto begin() const
324 {
325 return get<DDim0>(m_views).data();
326 }
327
328 template <
329 std::size_t N = sizeof...(DDims),
330 class DDim0 = std::enable_if_t<N == 1, std::tuple_element_t<0, std::tuple<DDims...>>>>
331 KOKKOS_FUNCTION auto end() const
332 {
333 return get<DDim0>(m_views).data() + get<DDim0>(m_views).size();
334 }
335
336 template <
337 std::size_t N = sizeof...(DDims),
338 class DDim0 = std::enable_if_t<N == 1, std::tuple_element_t<0, std::tuple<DDims...>>>>
339 KOKKOS_FUNCTION auto cbegin() const
340 {
341 return get<DDim0>(m_views).data();
342 }
343
344 template <
345 std::size_t N = sizeof...(DDims),
346 class DDim0 = std::enable_if_t<N == 1, std::tuple_element_t<0, std::tuple<DDims...>>>>
347 KOKKOS_FUNCTION auto cend() const
348 {
349 return get<DDim0>(m_views).data() + get<DDim0>(m_views).size();
350 }
351
352 template <
353 std::size_t N = sizeof...(DDims),
354 class = std::enable_if_t<N == 1, std::tuple_element_t<0, std::tuple<DDims...>>>>
355 KOKKOS_FUNCTION constexpr decltype(auto) operator[](std::size_t n)
356 {
357 return begin()[n];
358 }
359
360 template <
361 std::size_t N = sizeof...(DDims),
362 class = std::enable_if_t<N == 1, std::tuple_element_t<0, std::tuple<DDims...>>>>
363 KOKKOS_FUNCTION constexpr decltype(auto) operator[](std::size_t n) const
364 {
365 return begin()[n];
366 }
367};
368
369template <>
371{
372 template <class...>
373 friend class SparseDiscreteDomain;
374
375public:
376 using discrete_element_type = DiscreteElement<>;
377
378 using discrete_vector_type = DiscreteVector<>;
379
380 static KOKKOS_FUNCTION constexpr std::size_t rank()
381 {
382 return 0;
383 }
384
385 KOKKOS_DEFAULTED_FUNCTION constexpr SparseDiscreteDomain() = default;
386
387 // Construct a SparseDiscreteDomain from a reordered copy of `domain`
388 template <class... ODDims>
389 KOKKOS_FUNCTION constexpr explicit SparseDiscreteDomain(
390 SparseDiscreteDomain<ODDims...> const& /*domain*/)
391 {
392 }
393
394 KOKKOS_DEFAULTED_FUNCTION SparseDiscreteDomain(SparseDiscreteDomain const& x) = default;
395
396 KOKKOS_DEFAULTED_FUNCTION SparseDiscreteDomain(SparseDiscreteDomain&& x) = default;
397
398 KOKKOS_DEFAULTED_FUNCTION ~SparseDiscreteDomain() = default;
399
400 KOKKOS_DEFAULTED_FUNCTION SparseDiscreteDomain& operator=(SparseDiscreteDomain const& x)
401 = default;
402
403 KOKKOS_DEFAULTED_FUNCTION SparseDiscreteDomain& operator=(SparseDiscreteDomain&& x) = default;
404
405 KOKKOS_FUNCTION constexpr bool operator==(SparseDiscreteDomain const& /*other*/) const
406 {
407 return true;
408 }
409
410#if !defined(__cpp_impl_three_way_comparison) || __cpp_impl_three_way_comparison < 201902L
411 // In C++20, `a!=b` shall be automatically translated by the compiler to `!(a==b)`
412 KOKKOS_FUNCTION constexpr bool operator!=(SparseDiscreteDomain const& other) const
413 {
414 return !(*this == other);
415 }
416#endif
417
418 static KOKKOS_FUNCTION constexpr std::size_t size()
419 {
420 return 1;
421 }
422
423 static KOKKOS_FUNCTION constexpr discrete_vector_type extents() noexcept
424 {
425 return {};
426 }
427
428 static KOKKOS_FUNCTION constexpr discrete_element_type front() noexcept
429 {
430 return {};
431 }
432
433 static KOKKOS_FUNCTION constexpr discrete_element_type back() noexcept
434 {
435 return {};
436 }
437
438 KOKKOS_FUNCTION constexpr SparseDiscreteDomain take_first(discrete_vector_type /*n*/) const
439 {
440 return *this;
441 }
442
443 KOKKOS_FUNCTION constexpr SparseDiscreteDomain take_last(discrete_vector_type /*n*/) const
444 {
445 return *this;
446 }
447
448 KOKKOS_FUNCTION constexpr SparseDiscreteDomain remove_first(discrete_vector_type /*n*/) const
449 {
450 return *this;
451 }
452
453 KOKKOS_FUNCTION constexpr SparseDiscreteDomain remove_last(discrete_vector_type /*n*/) const
454 {
455 return *this;
456 }
457
458 KOKKOS_FUNCTION constexpr SparseDiscreteDomain remove(
459 discrete_vector_type /*n1*/,
460 discrete_vector_type /*n2*/) const
461 {
462 return *this;
463 }
464
465 KOKKOS_FUNCTION constexpr DiscreteElement<> operator()(
466 DiscreteVector<> const& /*dvect*/) const noexcept
467 {
468 return {};
469 }
470
471 static KOKKOS_FUNCTION bool contains() noexcept
472 {
473 return true;
474 }
475
476 static KOKKOS_FUNCTION bool contains(DiscreteElement<>) noexcept
477 {
478 return true;
479 }
480
481 static KOKKOS_FUNCTION DiscreteVector<> distance_from_front() noexcept
482 {
483 return {};
484 }
485
486 static KOKKOS_FUNCTION DiscreteVector<> distance_from_front(DiscreteElement<>) noexcept
487 {
488 return {};
489 }
490
491 static KOKKOS_FUNCTION constexpr bool empty() noexcept
492 {
493 return false;
494 }
495
496 KOKKOS_FUNCTION constexpr explicit operator bool()
497 {
498 return true;
499 }
500};
501
502template <class... QueryDDims, class... DDims>
503KOKKOS_FUNCTION constexpr SparseDiscreteDomain<QueryDDims...> select(
504 SparseDiscreteDomain<DDims...> const& domain)
505{
506 return SparseDiscreteDomain<QueryDDims...>(domain);
507}
508
509namespace detail {
510
511template <class T>
512struct ConvertTypeSeqToSparseDiscreteDomain;
513
514template <class... DDims>
515struct ConvertTypeSeqToSparseDiscreteDomain<detail::TypeSeq<DDims...>>
516{
517 using type = SparseDiscreteDomain<DDims...>;
518};
519
520template <class T>
521using convert_type_seq_to_sparse_discrete_domain_t =
522 typename ConvertTypeSeqToSparseDiscreteDomain<T>::type;
523
524} // namespace detail
525
526// Computes the subtraction DDom_a - DDom_b in the sense of linear spaces(retained dimensions are those in DDom_a which are not in DDom_b)
527template <class... DDimsA, class... DDimsB>
528KOKKOS_FUNCTION constexpr auto remove_dims_of(
529 SparseDiscreteDomain<DDimsA...> const& DDom_a,
530 SparseDiscreteDomain<DDimsB...> const& /*DDom_b*/) noexcept
531{
532 using TagSeqA = detail::TypeSeq<DDimsA...>;
533 using TagSeqB = detail::TypeSeq<DDimsB...>;
534
535 using type_seq_r = type_seq_remove_t<TagSeqA, TagSeqB>;
536 return detail::convert_type_seq_to_sparse_discrete_domain_t<type_seq_r>(DDom_a);
537}
538
539//! Remove the dimensions DDimsB from DDom_a
540//! @param[in] DDom_a The discrete domain on which to remove dimensions
541//! @return The discrete domain without DDimsB dimensions
542template <class... DDimsB, class... DDimsA>
543KOKKOS_FUNCTION constexpr auto remove_dims_of(
544 SparseDiscreteDomain<DDimsA...> const& DDom_a) noexcept
545{
546 using TagSeqA = detail::TypeSeq<DDimsA...>;
547 using TagSeqB = detail::TypeSeq<DDimsB...>;
548
549 using type_seq_r = type_seq_remove_t<TagSeqA, TagSeqB>;
550 return detail::convert_type_seq_to_sparse_discrete_domain_t<type_seq_r>(DDom_a);
551}
552
553namespace detail {
554
555// Checks if dimension of DDom_a is DDim1. If not, returns restriction to DDim2 of DDom_b. May not be useful in its own, it helps for replace_dim_of
556template <typename DDim1, typename DDim2, typename DDimA, typename... DDimsB>
557KOKKOS_FUNCTION constexpr std::conditional_t<
558 std::is_same_v<DDimA, DDim1>,
561replace_dim_of_1d(
562 [[maybe_unused]] SparseDiscreteDomain<DDimA> const& DDom_a,
563 [[maybe_unused]] SparseDiscreteDomain<DDimsB...> const& DDom_b) noexcept
564{
565 if constexpr (std::is_same_v<DDimA, DDim1>) {
566 return ddc::SparseDiscreteDomain<DDim2>(DDom_b);
567 } else {
568 return DDom_a;
569 }
570}
571
572} // namespace detail
573
574// Replace in DDom_a the dimension Dim1 by the dimension Dim2 of DDom_b
575template <typename DDim1, typename DDim2, typename... DDimsA, typename... DDimsB>
576KOKKOS_FUNCTION constexpr auto replace_dim_of(
577 SparseDiscreteDomain<DDimsA...> const& DDom_a,
578 [[maybe_unused]] SparseDiscreteDomain<DDimsB...> const& DDom_b) noexcept
579{
580 // TODO : static_asserts
581 using TagSeqA = detail::TypeSeq<DDimsA...>;
582 using TagSeqB = detail::TypeSeq<DDim1>;
583 using TagSeqC = detail::TypeSeq<DDim2>;
584
585 using type_seq_r = ddc::type_seq_replace_t<TagSeqA, TagSeqB, TagSeqC>;
586 return ddc::detail::convert_type_seq_to_sparse_discrete_domain_t<type_seq_r>(
587 detail::replace_dim_of_1d<
588 DDim1,
589 DDim2,
590 DDimsA,
591 DDimsB...>(ddc::SparseDiscreteDomain<DDimsA>(DDom_a), DDom_b)...);
592}
593
594template <class... QueryDDims, class... DDims>
595KOKKOS_FUNCTION constexpr DiscreteVector<QueryDDims...> extents(
596 SparseDiscreteDomain<DDims...> const& domain) noexcept
597{
598 return DiscreteVector<QueryDDims...>(SparseDiscreteDomain<QueryDDims>(domain).size()...);
599}
600
601template <class... QueryDDims, class... DDims>
602KOKKOS_FUNCTION constexpr DiscreteElement<QueryDDims...> front(
603 SparseDiscreteDomain<DDims...> const& domain) noexcept
604{
605 return DiscreteElement<QueryDDims...>(SparseDiscreteDomain<QueryDDims>(domain).front()...);
606}
607
608template <class... QueryDDims, class... DDims>
609KOKKOS_FUNCTION constexpr DiscreteElement<QueryDDims...> back(
610 SparseDiscreteDomain<DDims...> const& domain) noexcept
611{
612 return DiscreteElement<QueryDDims...>(SparseDiscreteDomain<QueryDDims>(domain).back()...);
613}
614
615} // namespace ddc
friend class DiscreteDomain
KOKKOS_DEFAULTED_FUNCTION constexpr DiscreteElement()=default
KOKKOS_FUNCTION constexpr bool operator!=(DiscreteVector< OTags... > const &rhs) const noexcept
KOKKOS_DEFAULTED_FUNCTION constexpr DiscreteVector()=default
KOKKOS_FUNCTION std::size_t size() const
KOKKOS_FUNCTION Coordinate< CDim > coordinate(discrete_element_type const &icoord) const noexcept
Convert a mesh index into a position in CDim
Impl(Impl< DDim, OriginMemorySpace > const &impl)
Impl & operator=(Impl &&x)=default
Impl & operator=(Impl const &x)=delete
Impl(InputIt const points_begin, InputIt const points_end)
Construct a NonUniformPointSampling using a pair of iterators.
KOKKOS_FUNCTION discrete_element_type front() const noexcept
Lower bound index of the mesh.
Impl(InputRange const &points)
Construct a NonUniformPointSampling using a C++20 "common range".
Impl(std::initializer_list< Coordinate< CDim > > const points)
Construct a NonUniformPointSampling using a brace-list, i.e. NonUniformPointSampling mesh({0....
NonUniformPointSampling models a non-uniform discretization of the CDim segment .
static std::tuple< typename DDim::template Impl< DDim, Kokkos::HostSpace >, DiscreteDomain< DDim > > init(InputRange const &non_uniform_points)
Construct an Impl<Kokkos::HostSpace> and associated discrete_domain_type from a range containing the ...
static std::tuple< typename DDim::template Impl< DDim, Kokkos::HostSpace >, DiscreteDomain< DDim >, DiscreteDomain< DDim >, DiscreteDomain< DDim >, DiscreteDomain< DDim > > init_ghosted(InputRange const &domain_r, InputRange const &pre_ghost_r, InputRange const &post_ghost_r)
Construct 4 non-uniform DiscreteDomain and an Impl<Kokkos::HostSpace> from 3 ranges containing the po...
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() noexcept
ScopeGuard(ScopeGuard &&x) noexcept=delete
ScopeGuard & operator=(ScopeGuard &&x) noexcept=delete
ScopeGuard(int, char **&)
ScopeGuard(ScopeGuard const &x)=delete
static KOKKOS_FUNCTION bool contains(DiscreteElement<>) noexcept
KOKKOS_FUNCTION constexpr SparseDiscreteDomain remove(discrete_vector_type, discrete_vector_type) const
KOKKOS_FUNCTION constexpr SparseDiscreteDomain take_first(discrete_vector_type) const
static KOKKOS_FUNCTION constexpr std::size_t rank()
KOKKOS_DEFAULTED_FUNCTION constexpr SparseDiscreteDomain()=default
KOKKOS_FUNCTION constexpr DiscreteElement operator()(DiscreteVector<> const &) const noexcept
KOKKOS_FUNCTION constexpr SparseDiscreteDomain remove_last(discrete_vector_type) const
static KOKKOS_FUNCTION DiscreteVector distance_from_front() noexcept
static KOKKOS_FUNCTION constexpr std::size_t size()
static KOKKOS_FUNCTION constexpr bool empty() noexcept
static KOKKOS_FUNCTION DiscreteVector distance_from_front(DiscreteElement<>) noexcept
KOKKOS_FUNCTION constexpr bool operator==(SparseDiscreteDomain const &) const
static KOKKOS_FUNCTION constexpr discrete_element_type back() noexcept
static KOKKOS_FUNCTION bool contains() noexcept
KOKKOS_FUNCTION constexpr SparseDiscreteDomain take_last(discrete_vector_type) const
KOKKOS_FUNCTION constexpr operator bool()
KOKKOS_DEFAULTED_FUNCTION SparseDiscreteDomain & operator=(SparseDiscreteDomain const &x)=default
KOKKOS_DEFAULTED_FUNCTION SparseDiscreteDomain & operator=(SparseDiscreteDomain &&x)=default
KOKKOS_FUNCTION constexpr SparseDiscreteDomain remove_first(discrete_vector_type) const
KOKKOS_DEFAULTED_FUNCTION SparseDiscreteDomain(SparseDiscreteDomain const &x)=default
KOKKOS_DEFAULTED_FUNCTION ~SparseDiscreteDomain()=default
static KOKKOS_FUNCTION constexpr discrete_element_type front() noexcept
KOKKOS_FUNCTION constexpr SparseDiscreteDomain(SparseDiscreteDomain< ODDims... > const &)
static KOKKOS_FUNCTION constexpr discrete_vector_type extents() noexcept
KOKKOS_DEFAULTED_FUNCTION SparseDiscreteDomain(SparseDiscreteDomain &&x)=default
KOKKOS_FUNCTION constexpr discrete_element_type back() const noexcept
KOKKOS_FUNCTION constexpr SparseDiscreteDomain remove_first(discrete_vector_type n) const
static KOKKOS_FUNCTION constexpr std::size_t rank()
KOKKOS_FUNCTION constexpr decltype(auto) operator[](std::size_t n) const
KOKKOS_DEFAULTED_FUNCTION SparseDiscreteDomain & operator=(SparseDiscreteDomain const &x)=default
KOKKOS_FUNCTION constexpr SparseDiscreteDomain take_last(discrete_vector_type n) const
KOKKOS_FUNCTION DiscreteVector< DDims... > distance_from_front(DElems const &... delems) const noexcept
KOKKOS_FUNCTION constexpr auto discrete_elements() const noexcept
KOKKOS_FUNCTION constexpr SparseDiscreteDomain remove(discrete_vector_type n1, discrete_vector_type n2) const
KOKKOS_FUNCTION constexpr SparseDiscreteDomain(DDoms const &... domains)
Construct a SparseDiscreteDomain by copies and merge of domains.
SparseDiscreteDomain(Kokkos::View< DiscreteElement< DDims > *, Kokkos::SharedSpace > const &... views)
Construct a SparseDiscreteDomain with Kokkos::View explicitly listing the discrete elements.
KOKKOS_FUNCTION auto cbegin() const
KOKKOS_FUNCTION constexpr decltype(auto) operator[](std::size_t n)
KOKKOS_DEFAULTED_FUNCTION SparseDiscreteDomain & operator=(SparseDiscreteDomain &&x)=default
KOKKOS_FUNCTION constexpr std::size_t size() const
KOKKOS_FUNCTION constexpr bool operator==(SparseDiscreteDomain< ODims... > const &other) const
KOKKOS_FUNCTION bool contains(DElems const &... delems) const noexcept
KOKKOS_FUNCTION constexpr SparseDiscreteDomain take_first(discrete_vector_type n) const
KOKKOS_DEFAULTED_FUNCTION SparseDiscreteDomain()=default
KOKKOS_DEFAULTED_FUNCTION SparseDiscreteDomain(SparseDiscreteDomain &&x)=default
KOKKOS_FUNCTION constexpr discrete_element_type front() const noexcept
KOKKOS_FUNCTION constexpr operator bool()
KOKKOS_FUNCTION constexpr bool empty() const noexcept
KOKKOS_FUNCTION constexpr DiscreteElement< DDims... > operator()(DiscreteVector< DDims... > const &dvect) const noexcept
KOKKOS_DEFAULTED_FUNCTION SparseDiscreteDomain(SparseDiscreteDomain const &x)=default
KOKKOS_FUNCTION constexpr SparseDiscreteDomain remove_last(discrete_vector_type n) const
KOKKOS_FUNCTION auto end() const
KOKKOS_FUNCTION auto cend() const
KOKKOS_FUNCTION auto begin() const
KOKKOS_FUNCTION constexpr discrete_vector_type extents() const noexcept
KOKKOS_FUNCTION constexpr DiscreteVector< QueryDDim > extent() const noexcept
KOKKOS_DEFAULTED_FUNCTION ~SparseDiscreteDomain()=default
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_non_uniform_point_sampling_v
KOKKOS_FUNCTION Coordinate< typename DDim::continuous_dimension_type > rmax(DiscreteDomain< DDim > const &d)
KOKKOS_FUNCTION constexpr DiscreteElement< QueryDDims... > back(SparseDiscreteDomain< DDims... > const &domain) noexcept
bool is_discrete_space_initialized() noexcept
KOKKOS_FUNCTION constexpr SparseDiscreteDomain< QueryDDims... > select(SparseDiscreteDomain< DDims... > const &domain)
void init_discrete_space(Args &&... args)
Initialize (emplace) a global singleton discrete space.
KOKKOS_FUNCTION constexpr auto remove_dims_of(SparseDiscreteDomain< DDimsA... > const &DDom_a, SparseDiscreteDomain< DDimsB... > const &) noexcept
detail::ddim_impl_t< DDim, Kokkos::HostSpace > const & host_discrete_space()
KOKKOS_FUNCTION constexpr DiscreteVector< QueryDDims... > extents(SparseDiscreteDomain< DDims... > const &domain) noexcept
KOKKOS_FUNCTION constexpr auto replace_dim_of(SparseDiscreteDomain< DDimsA... > const &DDom_a, SparseDiscreteDomain< DDimsB... > const &DDom_b) noexcept
KOKKOS_FUNCTION constexpr DiscreteElement< QueryDDims... > front(SparseDiscreteDomain< DDims... > const &domain) noexcept
KOKKOS_FUNCTION Coordinate< typename DDim::continuous_dimension_type > rlength(DiscreteDomain< DDim > const &d)
KOKKOS_FUNCTION Coordinate< typename DDim::continuous_dimension_type > distance_at_left(DiscreteElement< DDim > i)
KOKKOS_FUNCTION Coordinate< typename DDim::continuous_dimension_type > rmin(DiscreteDomain< DDim > const &d)
constexpr bool is_periodic_sampling_v
KOKKOS_FUNCTION Coordinate< typename DDim::continuous_dimension_type > coordinate(DiscreteElement< DDim > const &c)
KOKKOS_FUNCTION std::enable_if_t< is_periodic_sampling_v< DDim >, DiscreteElement< DDim > > front() noexcept
Lower bound index of the mesh.
constexpr bool is_sparse_discrete_domain_v
KOKKOS_FUNCTION constexpr auto remove_dims_of(SparseDiscreteDomain< DDimsA... > const &DDom_a) noexcept
Remove the dimensions DDimsB from DDom_a.
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.
KOKKOS_FUNCTION Coordinate< typename DDim::continuous_dimension_type > distance_at_right(DiscreteElement< DDim > i)
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.