DDC 0.10.0
Loading...
Searching...
No Matches
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 <iterator>
9#include <tuple>
10#include <type_traits>
11#include <utility>
12
13#include <Kokkos_Assert.hpp>
14#include <Kokkos_Macros.hpp>
15
16#include "detail/type_seq.hpp"
17
20
21namespace ddc {
22
23template <class DDim>
25
26template <class... DDims>
27class DiscreteDomain;
28
29template <class T>
30struct is_discrete_domain : std::false_type
31{
32};
33
34template <class... Tags>
35struct is_discrete_domain<DiscreteDomain<Tags...>> : std::true_type
36{
37};
38
39template <class T>
40inline constexpr bool is_discrete_domain_v = is_discrete_domain<T>::value;
41
42
43namespace detail {
44
45template <class... Tags>
46struct ToTypeSeq<DiscreteDomain<Tags...>>
47{
48 using type = TypeSeq<Tags...>;
49};
50
51template <class T, class U>
52struct RebindDomain;
53
54template <class... DDims, class... ODDims>
55struct RebindDomain<DiscreteDomain<DDims...>, detail::TypeSeq<ODDims...>>
56{
57 using type = DiscreteDomain<ODDims...>;
58};
59
60} // namespace detail
61
62template <class... DDims>
64{
65 template <class...>
66 friend class DiscreteDomain;
67
68 static_assert(
69 type_seq_is_unique_v<detail::TypeSeq<DDims...>>,
70 "The dimensions of a DiscreteDomain must be unique");
71
72public:
73 using discrete_element_type = DiscreteElement<DDims...>;
74
75 using discrete_vector_type = DiscreteVector<DDims...>;
76
77private:
78 DiscreteElement<DDims...> m_element_begin;
79
80 DiscreteElement<DDims...> m_element_end;
81
82public:
83 static KOKKOS_FUNCTION constexpr std::size_t rank()
84 {
85 return sizeof...(DDims);
86 }
87
88 KOKKOS_DEFAULTED_FUNCTION DiscreteDomain() = default;
89
90 /// Construct a DiscreteDomain by copies and merge of domains
91 template <class... DDoms, class = std::enable_if_t<(is_discrete_domain_v<DDoms> && ...)>>
92 KOKKOS_FUNCTION constexpr explicit DiscreteDomain(DDoms const&... domains)
93 : m_element_begin(domains.front()...)
94 , m_element_end((domains.front() + domains.extents())...)
95 {
96 }
97
98 /** Construct a DiscreteDomain starting from element_begin with size points.
99 * @param element_begin the lower bound in each direction
100 * @param size the number of points in each direction
101 */
102 KOKKOS_FUNCTION constexpr DiscreteDomain(
103 discrete_element_type const& element_begin,
104 discrete_vector_type const& size)
105 : m_element_begin(element_begin)
106 , m_element_end(element_begin + size)
107 {
108 }
109
110 KOKKOS_DEFAULTED_FUNCTION DiscreteDomain(DiscreteDomain const& x) = default;
111
112 KOKKOS_DEFAULTED_FUNCTION DiscreteDomain(DiscreteDomain&& x) = default;
113
114 KOKKOS_DEFAULTED_FUNCTION ~DiscreteDomain() = default;
115
116 KOKKOS_DEFAULTED_FUNCTION DiscreteDomain& operator=(DiscreteDomain const& x) = default;
117
118 KOKKOS_DEFAULTED_FUNCTION DiscreteDomain& operator=(DiscreteDomain&& x) = default;
119
120 template <class... ODims>
121 KOKKOS_FUNCTION constexpr bool operator==(DiscreteDomain<ODims...> const& other) const
122 {
123 if (empty() && other.empty()) {
124 return true;
125 }
126 return m_element_begin == other.m_element_begin && m_element_end == other.m_element_end;
127 }
128
129#if !defined(__cpp_impl_three_way_comparison) || __cpp_impl_three_way_comparison < 201902L
130 // In C++20, `a!=b` shall be automatically translated by the compiler to `!(a==b)`
131 template <class... ODims>
132 KOKKOS_FUNCTION constexpr bool operator!=(DiscreteDomain<ODims...> const& other) const
133 {
134 return !(*this == other);
135 }
136#endif
137
138 KOKKOS_FUNCTION constexpr std::size_t size() const
139 {
140 return (1UL * ... * extent<DDims>().value());
141 }
142
143 KOKKOS_FUNCTION constexpr discrete_vector_type extents() const noexcept
144 {
145 return m_element_end - m_element_begin;
146 }
147
148 template <class QueryDDim>
149 KOKKOS_FUNCTION constexpr DiscreteVector<QueryDDim> extent() const noexcept
150 {
151 return DiscreteElement<QueryDDim>(m_element_end)
152 - DiscreteElement<QueryDDim>(m_element_begin);
153 }
154
155 KOKKOS_FUNCTION constexpr discrete_element_type front() const noexcept
156 {
157 return m_element_begin;
158 }
159
160 KOKKOS_FUNCTION constexpr discrete_element_type back() const noexcept
161 {
162 return discrete_element_type((DiscreteElement<DDims>(m_element_end) - 1)...);
163 }
164
165 KOKKOS_FUNCTION constexpr DiscreteDomain take_first(discrete_vector_type n) const
166 {
167 return DiscreteDomain(front(), n);
168 }
169
170 KOKKOS_FUNCTION constexpr DiscreteDomain take_last(discrete_vector_type n) const
171 {
172 return DiscreteDomain(front() + (extents() - n), n);
173 }
174
175 KOKKOS_FUNCTION constexpr DiscreteDomain remove_first(discrete_vector_type n) const
176 {
177 return DiscreteDomain(front() + n, extents() - n);
178 }
179
180 KOKKOS_FUNCTION constexpr DiscreteDomain remove_last(discrete_vector_type n) const
181 {
182 return DiscreteDomain(front(), extents() - n);
183 }
184
185 KOKKOS_FUNCTION constexpr DiscreteDomain remove(
186 discrete_vector_type n1,
187 discrete_vector_type n2) const
188 {
189 return DiscreteDomain(front() + n1, extents() - n1 - n2);
190 }
191
192 KOKKOS_FUNCTION constexpr DiscreteElement<DDims...> operator()(
193 DiscreteVector<DDims...> const& dvect) const noexcept
194 {
195 return m_element_begin + dvect;
196 }
197
198 template <class... ODDims>
199 KOKKOS_FUNCTION constexpr auto restrict_with(DiscreteDomain<ODDims...> const& odomain) const
200 {
201 KOKKOS_ASSERT(
202 ((DiscreteElement<ODDims>(m_element_begin)
203 <= DiscreteElement<ODDims>(odomain.m_element_begin))
204 && ...))
205 KOKKOS_ASSERT(
206 ((DiscreteElement<ODDims>(m_element_end)
207 >= DiscreteElement<ODDims>(odomain.m_element_end))
208 && ...))
209 DiscreteVector<DDims...> const myextents = extents();
210 DiscreteVector<ODDims...> const oextents = odomain.extents();
211 return DiscreteDomain(
212 DiscreteElement<DDims...>((select_or<DDims>(
213 odomain.m_element_begin,
214 DiscreteElement<DDims>(m_element_begin)))...),
215 DiscreteVector<DDims...>(
216 (select_or<DDims>(oextents, DiscreteVector<DDims>(myextents)))...));
217 }
218
219 template <class... DElems>
220 KOKKOS_FUNCTION bool contains(DElems const&... delems) const noexcept
221 {
222 static_assert(
223 sizeof...(DDims) == (0 + ... + DElems::size()),
224 "Invalid number of dimensions");
225 static_assert((is_discrete_element_v<DElems> && ...), "Expected DiscreteElements");
226 DiscreteElement<DDims...> const delem(delems...);
227 for (std::size_t i = 0; i < rank(); ++i) {
228 if ((detail::array(delem)[i] < detail::array(m_element_begin)[i])
229 || (detail::array(delem)[i] >= detail::array(m_element_end)[i])) {
230 return false;
231 }
232 }
233 return true;
234 }
235
236 template <class... DElems>
237 KOKKOS_FUNCTION DiscreteVector<DDims...> distance_from_front(
238 DElems const&... delems) const noexcept
239 {
240 static_assert(
241 sizeof...(DDims) == (0 + ... + DElems::size()),
242 "Invalid number of dimensions");
243 static_assert((is_discrete_element_v<DElems> && ...), "Expected DiscreteElements");
244 return DiscreteVector<DDims...>(
245 (DiscreteElement<DDims>(take<DDims>(delems...))
246 - DiscreteElement<DDims>(m_element_begin))...);
247 }
248
249 KOKKOS_FUNCTION constexpr bool empty() const noexcept
250 {
251 return size() == 0;
252 }
253
254 KOKKOS_FUNCTION constexpr explicit operator bool()
255 {
256 return !empty();
257 }
258
259 template <
260 std::size_t N = sizeof...(DDims),
261 class DDim0 = std::enable_if_t<N == 1, std::tuple_element_t<0, std::tuple<DDims...>>>>
262 KOKKOS_FUNCTION auto begin() const
263 {
264 return DiscreteDomainIterator<DDim0>(front());
265 }
266
267 template <
268 std::size_t N = sizeof...(DDims),
269 class DDim0 = std::enable_if_t<N == 1, std::tuple_element_t<0, std::tuple<DDims...>>>>
270 KOKKOS_FUNCTION auto end() const
271 {
272 return DiscreteDomainIterator<DDim0>(m_element_end);
273 }
274
275 template <
276 std::size_t N = sizeof...(DDims),
277 class DDim0 = std::enable_if_t<N == 1, std::tuple_element_t<0, std::tuple<DDims...>>>>
278 KOKKOS_FUNCTION auto cbegin() const
279 {
280 return DiscreteDomainIterator<DDim0>(front());
281 }
282
283 template <
284 std::size_t N = sizeof...(DDims),
285 class DDim0 = std::enable_if_t<N == 1, std::tuple_element_t<0, std::tuple<DDims...>>>>
286 KOKKOS_FUNCTION auto cend() const
287 {
288 return DiscreteDomainIterator<DDim0>(m_element_end);
289 }
290
291 template <
292 std::size_t N = sizeof...(DDims),
293 class = std::enable_if_t<N == 1, std::tuple_element_t<0, std::tuple<DDims...>>>>
294 KOKKOS_FUNCTION constexpr decltype(auto) operator[](std::size_t n)
295 {
296 return begin()[n];
297 }
298
299 template <
300 std::size_t N = sizeof...(DDims),
301 class = std::enable_if_t<N == 1, std::tuple_element_t<0, std::tuple<DDims...>>>>
302 KOKKOS_FUNCTION constexpr decltype(auto) operator[](std::size_t n) const
303 {
304 return begin()[n];
305 }
306};
307
308template <>
309class DiscreteDomain<>
310{
311 template <class...>
312 friend class DiscreteDomain;
313
314public:
315 using discrete_element_type = DiscreteElement<>;
316
317 using discrete_vector_type = DiscreteVector<>;
318
319 static KOKKOS_FUNCTION constexpr std::size_t rank()
320 {
321 return 0;
322 }
323
324 KOKKOS_DEFAULTED_FUNCTION constexpr DiscreteDomain() = default;
325
326 /// Construct a DiscreteDomain by copies and merge of domains
327 template <class... DDoms, class = std::enable_if_t<(is_discrete_domain_v<DDoms> && ...)>>
328 KOKKOS_FUNCTION constexpr explicit DiscreteDomain(DDoms const&... /*domains*/)
329 {
330 }
331
332 /** Construct a DiscreteDomain starting from element_begin with size points.
333 * @param element_begin the lower bound in each direction
334 * @param size the number of points in each direction
335 */
336 KOKKOS_FUNCTION constexpr DiscreteDomain(
337 [[maybe_unused]] discrete_element_type const& element_begin,
338 [[maybe_unused]] discrete_vector_type const& size)
339 {
340 // Parameters `element_begin` and `size` are always unused, but needed for Doxygen
341 }
342
343 KOKKOS_DEFAULTED_FUNCTION DiscreteDomain(DiscreteDomain const& x) = default;
344
345 KOKKOS_DEFAULTED_FUNCTION DiscreteDomain(DiscreteDomain&& x) = default;
346
347 KOKKOS_DEFAULTED_FUNCTION ~DiscreteDomain() = default;
348
349 KOKKOS_DEFAULTED_FUNCTION DiscreteDomain& operator=(DiscreteDomain const& x) = default;
350
351 KOKKOS_DEFAULTED_FUNCTION DiscreteDomain& operator=(DiscreteDomain&& x) = default;
352
353 KOKKOS_FUNCTION constexpr bool operator==(DiscreteDomain const& /*other*/) const
354 {
355 return true;
356 }
357
358#if !defined(__cpp_impl_three_way_comparison) || __cpp_impl_three_way_comparison < 201902L
359 // In C++20, `a!=b` shall be automatically translated by the compiler to `!(a==b)`
360 KOKKOS_FUNCTION constexpr bool operator!=(DiscreteDomain const& other) const
361 {
362 return !(*this == other);
363 }
364#endif
365
366 static KOKKOS_FUNCTION constexpr std::size_t size()
367 {
368 return 1;
369 }
370
371 static KOKKOS_FUNCTION constexpr discrete_vector_type extents() noexcept
372 {
373 return {};
374 }
375
376 static KOKKOS_FUNCTION constexpr discrete_element_type front() noexcept
377 {
378 return {};
379 }
380
381 static KOKKOS_FUNCTION constexpr discrete_element_type back() noexcept
382 {
383 return {};
384 }
385
386 KOKKOS_FUNCTION constexpr DiscreteDomain take_first(discrete_vector_type /*n*/) const
387 {
388 return *this;
389 }
390
391 KOKKOS_FUNCTION constexpr DiscreteDomain take_last(discrete_vector_type /*n*/) const
392 {
393 return *this;
394 }
395
396 KOKKOS_FUNCTION constexpr DiscreteDomain remove_first(discrete_vector_type /*n*/) const
397 {
398 return *this;
399 }
400
401 KOKKOS_FUNCTION constexpr DiscreteDomain remove_last(discrete_vector_type /*n*/) const
402 {
403 return *this;
404 }
405
406 KOKKOS_FUNCTION constexpr DiscreteDomain remove(
407 discrete_vector_type /*n1*/,
408 discrete_vector_type /*n2*/) const
409 {
410 return *this;
411 }
412
413 KOKKOS_FUNCTION constexpr DiscreteElement<> operator()(
414 DiscreteVector<> const& /*dvect*/) const noexcept
415 {
416 return {};
417 }
418
419 template <class... ODims>
420 KOKKOS_FUNCTION constexpr DiscreteDomain restrict_with(
421 DiscreteDomain<ODims...> const& /*odomain*/) const
422 {
423 return *this;
424 }
425
426 static KOKKOS_FUNCTION bool contains() noexcept
427 {
428 return true;
429 }
430
431 static KOKKOS_FUNCTION bool contains(DiscreteElement<>) noexcept
432 {
433 return true;
434 }
435
436 static KOKKOS_FUNCTION DiscreteVector<> distance_from_front() noexcept
437 {
438 return {};
439 }
440
441 static KOKKOS_FUNCTION DiscreteVector<> distance_from_front(DiscreteElement<>) noexcept
442 {
443 return {};
444 }
445
446 static KOKKOS_FUNCTION constexpr bool empty() noexcept
447 {
448 return false;
449 }
450
451 KOKKOS_FUNCTION constexpr explicit operator bool()
452 {
453 return true;
454 }
455};
456
457template <class... QueryDDims, class... DDims>
458KOKKOS_FUNCTION constexpr DiscreteDomain<QueryDDims...> select(
459 DiscreteDomain<DDims...> const& domain)
460{
461 return DiscreteDomain<QueryDDims...>(domain);
462}
463
464namespace detail {
465
466template <class T>
467struct ConvertTypeSeqToDiscreteDomain;
468
469template <class... DDims>
470struct ConvertTypeSeqToDiscreteDomain<detail::TypeSeq<DDims...>>
471{
472 using type = DiscreteDomain<DDims...>;
473};
474
475template <class T>
476using convert_type_seq_to_discrete_domain_t = typename ConvertTypeSeqToDiscreteDomain<T>::type;
477
478} // namespace detail
479
480// Computes the cartesian product of DiscreteDomain types
481// Example usage : "using DDom = cartesian_prod_t<DDom1,DDom2,DDom3>;"
482template <typename... DDoms>
483struct cartesian_prod;
484
485template <typename... DDims1, typename... DDims2, typename... DDomsTail>
486struct cartesian_prod<DiscreteDomain<DDims1...>, DiscreteDomain<DDims2...>, DDomsTail...>
487{
488 using type = typename cartesian_prod<DiscreteDomain<DDims1..., DDims2...>, DDomsTail...>::type;
489};
490
491template <typename... DDims>
492struct cartesian_prod<DiscreteDomain<DDims...>>
493{
494 using type = DiscreteDomain<DDims...>;
495};
496
497template <>
498struct cartesian_prod<>
499{
500 using type = ddc::DiscreteDomain<>;
501};
502
503template <typename... DDoms>
504using cartesian_prod_t = typename cartesian_prod<DDoms...>::type;
505
506// 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)
507template <class... DDimsA, class... DDimsB>
508KOKKOS_FUNCTION constexpr auto remove_dims_of(
509 DiscreteDomain<DDimsA...> const& DDom_a,
510 DiscreteDomain<DDimsB...> const& /*DDom_b*/) noexcept
511{
512 using TagSeqA = detail::TypeSeq<DDimsA...>;
513 using TagSeqB = detail::TypeSeq<DDimsB...>;
514
515 using type_seq_r = type_seq_remove_t<TagSeqA, TagSeqB>;
516 return detail::convert_type_seq_to_discrete_domain_t<type_seq_r>(DDom_a);
517}
518
519//! Remove the dimensions DDimsB from DDom_a
520//! @param[in] DDom_a The discrete domain on which to remove dimensions
521//! @return The discrete domain without DDimsB dimensions
522template <class... DDimsB, class... DDimsA>
523KOKKOS_FUNCTION constexpr auto remove_dims_of(DiscreteDomain<DDimsA...> const& DDom_a) noexcept
524{
525 using TagSeqA = detail::TypeSeq<DDimsA...>;
526 using TagSeqB = detail::TypeSeq<DDimsB...>;
527
528 using type_seq_r = type_seq_remove_t<TagSeqA, TagSeqB>;
529 return detail::convert_type_seq_to_discrete_domain_t<type_seq_r>(DDom_a);
530}
531
532// Remove dimensions from a domain type
533template <typename DDom, typename... DDims>
534using remove_dims_of_t = decltype(remove_dims_of<DDims...>(std::declval<DDom>()));
535
536namespace detail {
537
538// 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
539template <typename DDim1, typename DDim2, typename DDimA, typename... DDimsB>
540KOKKOS_FUNCTION constexpr std::conditional_t<
541 std::is_same_v<DDimA, DDim1>,
542 ddc::DiscreteDomain<DDim2>,
543 ddc::DiscreteDomain<DDimA>>
544replace_dim_of_1d(
545 [[maybe_unused]] DiscreteDomain<DDimA> const& DDom_a,
546 [[maybe_unused]] DiscreteDomain<DDimsB...> const& DDom_b) noexcept
547{
548 if constexpr (std::is_same_v<DDimA, DDim1>) {
549 return ddc::DiscreteDomain<DDim2>(DDom_b);
550 } else {
551 return DDom_a;
552 }
553}
554
555} // namespace detail
556
557// Replace in DDom_a the dimension Dim1 by the dimension Dim2 of DDom_b
558template <typename DDim1, typename DDim2, typename... DDimsA, typename... DDimsB>
559KOKKOS_FUNCTION constexpr auto replace_dim_of(
560 DiscreteDomain<DDimsA...> const& DDom_a,
561 [[maybe_unused]] DiscreteDomain<DDimsB...> const& DDom_b) noexcept
562{
563 // TODO : static_asserts
564 using TagSeqA = detail::TypeSeq<DDimsA...>;
565 using TagSeqB = detail::TypeSeq<DDim1>;
566 using TagSeqC = detail::TypeSeq<DDim2>;
567
568 using type_seq_r = ddc::type_seq_replace_t<TagSeqA, TagSeqB, TagSeqC>;
569 return ddc::detail::convert_type_seq_to_discrete_domain_t<type_seq_r>(
570 detail::replace_dim_of_1d<
571 DDim1,
572 DDim2,
573 DDimsA,
574 DDimsB...>(ddc::DiscreteDomain<DDimsA>(DDom_a), DDom_b)...);
575}
576
577// Replace dimensions from a domain type
578template <typename DDom, typename DDim1, typename DDim2>
579using replace_dim_of_t = decltype(replace_dim_of<DDim1, DDim2>(
580 std::declval<DDom>(),
581 std::declval<typename detail::RebindDomain<DDom, detail::TypeSeq<DDim2>>::type>()));
582
583
584template <class... QueryDDims, class... DDims>
585KOKKOS_FUNCTION constexpr DiscreteVector<QueryDDims...> extents(
586 DiscreteDomain<DDims...> const& domain) noexcept
587{
588 return DiscreteVector<QueryDDims...>(DiscreteDomain<QueryDDims>(domain).size()...);
589}
590
591template <class... QueryDDims, class... DDims>
592KOKKOS_FUNCTION constexpr DiscreteElement<QueryDDims...> front(
593 DiscreteDomain<DDims...> const& domain) noexcept
594{
595 return DiscreteElement<QueryDDims...>(DiscreteDomain<QueryDDims>(domain).front()...);
596}
597
598template <class... QueryDDims, class... DDims>
599KOKKOS_FUNCTION constexpr DiscreteElement<QueryDDims...> back(
600 DiscreteDomain<DDims...> const& domain) noexcept
601{
602 return DiscreteElement<QueryDDims...>(DiscreteDomain<QueryDDims>(domain).back()...);
603}
604
605template <class DDim>
607{
608private:
609 DiscreteElement<DDim> m_value = DiscreteElement<DDim>();
610
611public:
612 using iterator_category = std::random_access_iterator_tag;
613
614 using value_type = DiscreteElement<DDim>;
615
616 using difference_type = std::ptrdiff_t;
617
618 KOKKOS_DEFAULTED_FUNCTION DiscreteDomainIterator() = default;
619
620 KOKKOS_FUNCTION constexpr explicit DiscreteDomainIterator(DiscreteElement<DDim> value)
621 : m_value(value)
622 {
623 }
624
625 KOKKOS_FUNCTION constexpr DiscreteElement<DDim> operator*() const noexcept
626 {
627 return m_value;
628 }
629
630 KOKKOS_FUNCTION constexpr DiscreteDomainIterator& operator++()
631 {
632 ++m_value;
633 return *this;
634 }
635
636 KOKKOS_FUNCTION constexpr DiscreteDomainIterator operator++(int)
637 {
638 auto tmp = *this;
639 ++*this;
640 return tmp;
641 }
642
643 KOKKOS_FUNCTION constexpr DiscreteDomainIterator& operator--()
644 {
645 --m_value;
646 return *this;
647 }
648
649 KOKKOS_FUNCTION constexpr DiscreteDomainIterator operator--(int)
650 {
651 auto tmp = *this;
652 --*this;
653 return tmp;
654 }
655
656 KOKKOS_FUNCTION constexpr DiscreteDomainIterator& operator+=(difference_type n)
657 {
658 if (n >= static_cast<difference_type>(0)) {
659 m_value += static_cast<DiscreteElementType>(n);
660 } else {
661 m_value -= static_cast<DiscreteElementType>(-n);
662 }
663 return *this;
664 }
665
666 KOKKOS_FUNCTION constexpr DiscreteDomainIterator& operator-=(difference_type n)
667 {
668 if (n >= static_cast<difference_type>(0)) {
669 m_value -= static_cast<DiscreteElementType>(n);
670 } else {
671 m_value += static_cast<DiscreteElementType>(-n);
672 }
673 return *this;
674 }
675
676 KOKKOS_FUNCTION constexpr DiscreteElement<DDim> operator[](difference_type n) const
677 {
678 return m_value + n;
679 }
680
681 friend KOKKOS_FUNCTION constexpr bool operator==(
682 DiscreteDomainIterator const& xx,
683 DiscreteDomainIterator const& yy)
684 {
685 return xx.m_value == yy.m_value;
686 }
687
688#if !defined(__cpp_impl_three_way_comparison) || __cpp_impl_three_way_comparison < 201902L
689 // In C++20, `a!=b` shall be automatically translated by the compiler to `!(a==b)`
690 friend KOKKOS_FUNCTION constexpr bool operator!=(
693 {
694 return xx.m_value != yy.m_value;
695 }
696#endif
697
698 friend KOKKOS_FUNCTION constexpr bool operator<(
699 DiscreteDomainIterator const& xx,
700 DiscreteDomainIterator const& yy)
701 {
702 return xx.m_value < yy.m_value;
703 }
704
705 friend KOKKOS_FUNCTION constexpr bool operator>(
706 DiscreteDomainIterator const& xx,
707 DiscreteDomainIterator const& yy)
708 {
709 return yy < xx;
710 }
711
712 friend KOKKOS_FUNCTION constexpr bool operator<=(
713 DiscreteDomainIterator const& xx,
714 DiscreteDomainIterator const& yy)
715 {
716 return !(yy < xx);
717 }
718
719 friend KOKKOS_FUNCTION constexpr bool operator>=(
720 DiscreteDomainIterator const& xx,
721 DiscreteDomainIterator const& yy)
722 {
723 return !(xx < yy);
724 }
725
726 friend KOKKOS_FUNCTION constexpr DiscreteDomainIterator operator+(
728 difference_type n)
729 {
730 return i += n;
731 }
732
733 friend KOKKOS_FUNCTION constexpr DiscreteDomainIterator operator+(
734 difference_type n,
736 {
737 return i += n;
738 }
739
740 friend KOKKOS_FUNCTION constexpr DiscreteDomainIterator operator-(
742 difference_type n)
743 {
744 return i -= n;
745 }
746
747 friend KOKKOS_FUNCTION constexpr difference_type operator-(
748 DiscreteDomainIterator const& xx,
749 DiscreteDomainIterator const& yy)
750 {
751 return (yy.m_value > xx.m_value) ? (-static_cast<difference_type>(yy.m_value - xx.m_value))
752 : (xx.m_value - yy.m_value);
753 }
754};
755
756} // namespace ddc
friend class ChunkSpan
KOKKOS_FUNCTION constexpr bool is_strided() const noexcept
KOKKOS_DEFAULTED_FUNCTION ~ChunkCommon() noexcept=default
KOKKOS_FUNCTION constexpr ElementType * data_handle() const
Access to the underlying allocation pointer.
KOKKOS_DEFAULTED_FUNCTION constexpr ChunkCommon()=default
Empty ChunkCommon.
allocation_mdspan_type m_allocation_mdspan
The raw view of the data.
KOKKOS_FUNCTION constexpr SupportType domain() const noexcept
Provide access to the domain on which this chunk is defined.
static KOKKOS_FUNCTION constexpr bool is_always_strided() noexcept
KOKKOS_FUNCTION constexpr allocation_mdspan_type allocation_mdspan() const
Provide a modifiable view of the data.
KOKKOS_FUNCTION constexpr ChunkCommon(allocation_mdspan_type allocation_mdspan, SupportType const &domain) noexcept
Constructs a new ChunkCommon from scratch.
KOKKOS_FUNCTION constexpr ChunkCommon(ElementType *ptr, SupportType const &domain)
Constructs a new ChunkCommon from scratch.
KOKKOS_DEFAULTED_FUNCTION constexpr ChunkCommon(ChunkCommon const &other)=default
Constructs a new ChunkCommon by copy, yields a new view to the same data.
static KOKKOS_FUNCTION constexpr bool is_always_unique() noexcept
KOKKOS_FUNCTION constexpr DiscreteDomain< QueryDDims... > domain() const noexcept
Provide access to the domain on which this chunk is defined.
KOKKOS_DEFAULTED_FUNCTION constexpr ChunkCommon & operator=(ChunkCommon const &other)=default
Copy-assigns a new value to this ChunkCommon, yields a new view to the same data.
KOKKOS_DEFAULTED_FUNCTION constexpr ChunkCommon(ChunkCommon &&other) noexcept=default
Constructs a new ChunkCommon by move.
KOKKOS_DEFAULTED_FUNCTION constexpr ChunkCommon & operator=(ChunkCommon &&other) noexcept=default
Move-assigns a new value to this ChunkCommon.
KOKKOS_FUNCTION constexpr size_type extent() const noexcept
KOKKOS_FUNCTION constexpr size_type stride() const
KOKKOS_FUNCTION constexpr bool is_exhaustive() const noexcept
KOKKOS_FUNCTION constexpr mapping_type mapping() const noexcept
static KOKKOS_FUNCTION constexpr int rank() noexcept
KOKKOS_FUNCTION constexpr bool is_unique() const noexcept
KOKKOS_FUNCTION constexpr accessor_type accessor() const
KOKKOS_FUNCTION constexpr SupportType::discrete_vector_type extents() const noexcept
KOKKOS_FUNCTION constexpr size_type size() const noexcept
SupportType m_domain
The mesh on which this chunk is defined.
static KOKKOS_FUNCTION constexpr int rank_dynamic() noexcept
static KOKKOS_FUNCTION constexpr size_type static_extent(std::size_t r) noexcept
static KOKKOS_FUNCTION constexpr bool is_always_exhaustive() noexcept
auto operator[](DiscreteElement< QueryDDims... > const &slice_spec) const
Slice out some dimensions.
Definition chunk.hpp:156
char const * label() const
Returns the label of the Chunk.
Definition chunk.hpp:263
auto operator[](DiscreteDomain< QueryDDims... > const &odomain)
Slice out some dimensions.
Definition chunk.hpp:183
const_allocation_mdspan_type allocation_mdspan() const
Provide a mdspan on the memory allocation.
Definition chunk.hpp:287
element_type & operator()(DVects const &... dvects) noexcept
Element access using a list of DiscreteVector.
Definition chunk.hpp:250
ElementType const * data_handle() const
Access to the underlying allocation pointer.
Definition chunk.hpp:271
auto allocation_kokkos_view()
Provide an unmanaged Kokkos::View on the memory allocation.
Definition chunk.hpp:303
auto allocation_kokkos_view() const
Provide an unmanaged Kokkos::View on the memory allocation.
Definition chunk.hpp:319
Chunk(SupportType const &domain, Allocator allocator=Allocator())
Construct a Chunk on a domain with uninitialized values.
Definition chunk.hpp:106
Chunk & operator=(Chunk const &other)=delete
Deleted: use deepcopy instead.
allocation_mdspan_type allocation_mdspan()
Provide a mdspan on the memory allocation.
Definition chunk.hpp:295
ElementType * data_handle()
Access to the underlying allocation pointer.
Definition chunk.hpp:279
element_type const & operator()(DVects const &... dvects) const noexcept
Element access using a list of DiscreteVector.
Definition chunk.hpp:214
view_type span_cview() const
Definition chunk.hpp:332
Chunk(Chunk const &other)=delete
Deleted: use deepcopy instead.
~Chunk() noexcept
Definition chunk.hpp:126
Chunk(std::string const &label, SupportType const &domain, Allocator allocator=Allocator())
Construct a labeled Chunk on a domain with uninitialized values.
Definition chunk.hpp:95
element_type & operator()(DElems const &... delems) noexcept
Element access using a list of DiscreteElement.
Definition chunk.hpp:231
Chunk()=default
Empty Chunk.
Chunk & operator=(Chunk &&other) noexcept
Move-assigns a new value to this field.
Definition chunk.hpp:140
Chunk(Chunk &&other) noexcept
Constructs a new Chunk by move.
Definition chunk.hpp:117
friend class Chunk
Definition chunk.hpp:83
span_type span_view()
Definition chunk.hpp:342
view_type span_view() const
Definition chunk.hpp:337
auto operator[](DiscreteDomain< QueryDDims... > const &odomain) const
Slice out some dimensions.
Definition chunk.hpp:173
element_type const & operator()(DElems const &... delems) const noexcept
Element access using a list of DiscreteElement.
Definition chunk.hpp:195
auto operator[](DiscreteElement< QueryDDims... > const &slice_spec)
Slice out some dimensions.
Definition chunk.hpp:163
static KOKKOS_FUNCTION constexpr discrete_vector_type extents() noexcept
KOKKOS_DEFAULTED_FUNCTION ~DiscreteDomain()=default
KOKKOS_FUNCTION constexpr DiscreteDomain(discrete_element_type const &element_begin, discrete_vector_type const &size)
Construct a DiscreteDomain starting from element_begin with size points.
KOKKOS_FUNCTION constexpr DiscreteDomain take_last(discrete_vector_type) const
KOKKOS_FUNCTION constexpr bool operator==(DiscreteDomain const &) const
KOKKOS_FUNCTION constexpr DiscreteDomain remove(discrete_vector_type, discrete_vector_type) const
KOKKOS_FUNCTION constexpr DiscreteDomain(DDoms const &...)
Construct a DiscreteDomain by copies and merge of domains.
static KOKKOS_FUNCTION constexpr std::size_t rank()
KOKKOS_FUNCTION constexpr DiscreteDomain remove_last(discrete_vector_type) const
KOKKOS_DEFAULTED_FUNCTION DiscreteDomain(DiscreteDomain const &x)=default
static KOKKOS_FUNCTION bool contains() noexcept
KOKKOS_DEFAULTED_FUNCTION constexpr DiscreteDomain()=default
KOKKOS_DEFAULTED_FUNCTION DiscreteDomain & operator=(DiscreteDomain &&x)=default
KOKKOS_FUNCTION constexpr operator bool()
static KOKKOS_FUNCTION constexpr std::size_t size()
static KOKKOS_FUNCTION constexpr bool empty() noexcept
static KOKKOS_FUNCTION bool contains(DiscreteElement<>) noexcept
static KOKKOS_FUNCTION constexpr discrete_element_type back() noexcept
static KOKKOS_FUNCTION DiscreteVector distance_from_front(DiscreteElement<>) noexcept
KOKKOS_FUNCTION constexpr DiscreteDomain remove_first(discrete_vector_type) const
static KOKKOS_FUNCTION constexpr discrete_element_type front() noexcept
KOKKOS_DEFAULTED_FUNCTION DiscreteDomain & operator=(DiscreteDomain const &x)=default
KOKKOS_FUNCTION constexpr DiscreteDomain take_first(discrete_vector_type) const
KOKKOS_FUNCTION constexpr DiscreteDomain restrict_with(DiscreteDomain< ODims... > const &) const
KOKKOS_FUNCTION constexpr DiscreteElement operator()(DiscreteVector<> const &) const noexcept
KOKKOS_DEFAULTED_FUNCTION DiscreteDomain(DiscreteDomain &&x)=default
static KOKKOS_FUNCTION DiscreteVector distance_from_front() noexcept
KOKKOS_DEFAULTED_FUNCTION DiscreteDomain(DiscreteDomain const &x)=default
KOKKOS_DEFAULTED_FUNCTION DiscreteDomain(DiscreteDomain &&x)=default
KOKKOS_FUNCTION constexpr DiscreteDomain remove_last(discrete_vector_type n) const
KOKKOS_FUNCTION bool contains(DElems const &... delems) const noexcept
KOKKOS_FUNCTION constexpr DiscreteDomain take_last(discrete_vector_type n) const
KOKKOS_FUNCTION auto begin() const
KOKKOS_FUNCTION constexpr DiscreteDomain remove(discrete_vector_type n1, discrete_vector_type n2) const
KOKKOS_FUNCTION constexpr auto restrict_with(DiscreteDomain< ODDims... > const &odomain) const
static KOKKOS_FUNCTION constexpr std::size_t rank()
KOKKOS_FUNCTION constexpr bool empty() const noexcept
KOKKOS_FUNCTION constexpr std::size_t size() const
friend class DiscreteDomain
KOKKOS_FUNCTION constexpr discrete_vector_type extents() const noexcept
KOKKOS_FUNCTION constexpr DiscreteVector< QueryDDim > extent() const noexcept
KOKKOS_FUNCTION constexpr discrete_element_type front() const noexcept
KOKKOS_FUNCTION constexpr DiscreteDomain(DDoms const &... domains)
Construct a DiscreteDomain by copies and merge of domains.
KOKKOS_DEFAULTED_FUNCTION DiscreteDomain & operator=(DiscreteDomain &&x)=default
KOKKOS_FUNCTION constexpr DiscreteDomain remove_first(discrete_vector_type n) const
KOKKOS_FUNCTION constexpr bool operator==(DiscreteDomain< ODims... > const &other) const
KOKKOS_FUNCTION auto cbegin() const
KOKKOS_FUNCTION auto end() const
KOKKOS_FUNCTION constexpr DiscreteDomain take_first(discrete_vector_type n) const
KOKKOS_DEFAULTED_FUNCTION ~DiscreteDomain()=default
KOKKOS_FUNCTION auto cend() const
KOKKOS_FUNCTION constexpr decltype(auto) operator[](std::size_t n) const
KOKKOS_FUNCTION DiscreteVector< DDims... > distance_from_front(DElems const &... delems) const noexcept
KOKKOS_FUNCTION constexpr discrete_element_type back() const noexcept
KOKKOS_DEFAULTED_FUNCTION DiscreteDomain & operator=(DiscreteDomain const &x)=default
KOKKOS_FUNCTION constexpr DiscreteElement< DDims... > operator()(DiscreteVector< DDims... > const &dvect) const noexcept
KOKKOS_DEFAULTED_FUNCTION DiscreteDomain()=default
KOKKOS_FUNCTION constexpr operator bool()
KOKKOS_FUNCTION constexpr DiscreteDomain(discrete_element_type const &element_begin, discrete_vector_type const &size)
Construct a DiscreteDomain starting from element_begin with size points.
KOKKOS_FUNCTION constexpr decltype(auto) operator[](std::size_t n)
KOKKOS_DEFAULTED_FUNCTION constexpr DiscreteElement()=default
KOKKOS_FUNCTION constexpr bool operator!=(DiscreteVector< OTags... > const &rhs) const noexcept
KOKKOS_DEFAULTED_FUNCTION constexpr DiscreteVector()=default
The top-level namespace of DDC.
constexpr bool is_borrowed_chunk_v
KOKKOS_FUNCTION auto get_domain(ChunkType const &chunk) noexcept
Access the domain (or subdomain) of a view.
constexpr bool enable_chunk< Chunk< ElementType, SupportType, Allocator > >
Definition chunk.hpp:30
KOKKOS_FUNCTION constexpr DiscreteElement< QueryDDims... > back(DiscreteDomain< DDims... > const &domain) noexcept
constexpr bool enable_borrowed_chunk
constexpr bool enable_chunk
constexpr bool is_chunk_v
KOKKOS_FUNCTION constexpr auto remove_dims_of(DiscreteDomain< DDimsA... > const &DDom_a, DiscreteDomain< DDimsB... > const &) noexcept
KOKKOS_FUNCTION constexpr auto remove_dims_of(DiscreteDomain< DDimsA... > const &DDom_a) noexcept
Remove the dimensions DDimsB from DDom_a.
KOKKOS_FUNCTION constexpr DiscreteElement< QueryDDims... > front(DiscreteDomain< DDims... > const &domain) noexcept
constexpr bool is_writable_chunk_v
KOKKOS_FUNCTION constexpr DiscreteVector< QueryDDims... > extents(DiscreteDomain< DDims... > const &domain) noexcept
Chunk(SupportType const &, Allocator) -> Chunk< typename Allocator::value_type, SupportType, Allocator >
KOKKOS_FUNCTION constexpr auto replace_dim_of(DiscreteDomain< DDimsA... > const &DDom_a, DiscreteDomain< DDimsB... > const &DDom_b) noexcept
Chunk(std::string const &, SupportType const &, Allocator) -> Chunk< typename Allocator::value_type, SupportType, Allocator >
constexpr bool is_discrete_domain_v
KOKKOS_FUNCTION constexpr DiscreteDomain< QueryDDims... > select(DiscreteDomain< DDims... > const &domain)
KOKKOS_FUNCTION constexpr DiscreteDomainIterator operator--(int)
friend KOKKOS_FUNCTION constexpr bool operator<=(DiscreteDomainIterator const &xx, DiscreteDomainIterator const &yy)
KOKKOS_FUNCTION constexpr DiscreteElement< DDim > operator*() const noexcept
friend KOKKOS_FUNCTION constexpr bool operator>=(DiscreteDomainIterator const &xx, DiscreteDomainIterator const &yy)
KOKKOS_DEFAULTED_FUNCTION DiscreteDomainIterator()=default
KOKKOS_FUNCTION constexpr DiscreteElement< DDim > operator[](difference_type n) const
KOKKOS_FUNCTION constexpr DiscreteDomainIterator & operator--()
KOKKOS_FUNCTION constexpr DiscreteDomainIterator operator++(int)
friend KOKKOS_FUNCTION constexpr DiscreteDomainIterator operator-(DiscreteDomainIterator i, difference_type n)
friend KOKKOS_FUNCTION constexpr DiscreteDomainIterator operator+(DiscreteDomainIterator i, difference_type n)
friend KOKKOS_FUNCTION constexpr bool operator>(DiscreteDomainIterator const &xx, DiscreteDomainIterator const &yy)
friend KOKKOS_FUNCTION constexpr bool operator!=(DiscreteDomainIterator const &xx, DiscreteDomainIterator const &yy)
friend KOKKOS_FUNCTION constexpr bool operator<(DiscreteDomainIterator const &xx, DiscreteDomainIterator const &yy)
KOKKOS_FUNCTION constexpr DiscreteDomainIterator & operator+=(difference_type n)
KOKKOS_FUNCTION constexpr DiscreteDomainIterator & operator++()
friend KOKKOS_FUNCTION constexpr DiscreteDomainIterator operator+(difference_type n, DiscreteDomainIterator i)
friend KOKKOS_FUNCTION constexpr bool operator==(DiscreteDomainIterator const &xx, DiscreteDomainIterator const &yy)
KOKKOS_FUNCTION constexpr DiscreteDomainIterator(DiscreteElement< DDim > value)
KOKKOS_FUNCTION constexpr DiscreteDomainIterator & operator-=(difference_type n)
friend KOKKOS_FUNCTION constexpr difference_type operator-(DiscreteDomainIterator const &xx, DiscreteDomainIterator const &yy)