DDC 0.17.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 <iosfwd>
10#include <iterator>
11#include <span>
12#include <string>
13#include <tuple>
14#include <type_traits>
15
16#include <Kokkos_Core.hpp>
17
18#include "detail/tagged_vector.hpp"
19
23#include "type_seq.hpp"
24
25namespace ddc {
26
27template <concepts::discrete_dimension... 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
43namespace concepts {
44
45template <class T>
46concept sparse_discrete_domain = is_sparse_discrete_domain_v<T>;
47
48}
49
50namespace detail {
51
52template <class... Tags>
53struct ToTypeSeq<SparseDiscreteDomain<Tags...>>
54{
55 using type = ddc::TypeSeq<Tags...>;
56};
57
58template <ddc::concepts::discrete_dimension... DDims, ddc::concepts::discrete_dimension... ODDims>
59struct Rebind<SparseDiscreteDomain<DDims...>, ddc::TypeSeq<ODDims...>>
60{
61 using type = SparseDiscreteDomain<ODDims...>;
62};
63
64template <class InputIt1, class InputIt2>
65KOKKOS_FUNCTION bool equal(InputIt1 first1, InputIt1 last1, InputIt2 first2)
66{
67 for (; first1 != last1; ++first1, ++first2) {
68 if (!(*first1 == *first2)) {
69 return false;
70 }
71 }
72
73 return true;
74}
75
76template <class ForwardIt, class T = std::iterator_traits<ForwardIt>::value_type, 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 <class ForwardIt, class T = std::iterator_traits<ForwardIt>::value_type, class Compare>
98KOKKOS_FUNCTION bool binary_search(ForwardIt first, ForwardIt last, T const& value, Compare comp)
99{
100 first = ::ddc::detail::lower_bound(first, last, value, comp);
101 return (!(first == last) && !(comp(value, *first)));
102}
103
104template <ddc::concepts::discrete_dimension DDim>
105Kokkos::View<DiscreteElementType*, Kokkos::SharedSpace> extract_uid(
106 Kokkos::DefaultExecutionSpace const& exec_space,
107 Kokkos::View<DiscreteElement<DDim>*, Kokkos::SharedSpace> const& input)
108{
109 Kokkos::View<DiscreteElementType*, Kokkos::SharedSpace> output(input.label(), input.size());
110 Kokkos::parallel_for(
111 "SparseDiscreteDomainCtor",
112 Kokkos::RangePolicy<
113 Kokkos::DefaultExecutionSpace,
114 Kokkos::IndexType<std::size_t>>(exec_space, 0, 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 <concepts::discrete_dimension... DDims>
123{
124 template <concepts::discrete_dimension...>
125 friend class SparseDiscreteDomain;
126
127 static_assert(
128 type_seq_is_unique_v<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 <concepts::sparse_discrete_domain... 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 Kokkos::DefaultExecutionSpace const exec_space;
161 ((m_views[type_seq_rank_v<DDims, TypeSeq<DDims...>>]
162 = detail::extract_uid(exec_space, views)),
163 ...);
164 exec_space.fence("SparseDiscreteDomainCtor");
165 }
166
167 KOKKOS_DEFAULTED_FUNCTION SparseDiscreteDomain(SparseDiscreteDomain const& x) = default;
168
169 KOKKOS_DEFAULTED_FUNCTION SparseDiscreteDomain(SparseDiscreteDomain&& x) = default;
170
171 KOKKOS_DEFAULTED_FUNCTION ~SparseDiscreteDomain() = default;
172
173 KOKKOS_DEFAULTED_FUNCTION SparseDiscreteDomain& operator=(SparseDiscreteDomain const& x)
174 = default;
175
176 KOKKOS_DEFAULTED_FUNCTION SparseDiscreteDomain& operator=(SparseDiscreteDomain&& x) = default;
177
178 template <concepts::discrete_dimension... ODDims>
179 KOKKOS_FUNCTION constexpr bool operator==(SparseDiscreteDomain<ODDims...> const& other) const
180 {
181 if constexpr ((std::is_same_v<DDims, ODDims> && ...)) {
182 if (empty() && other.empty()) {
183 return true;
184 }
185 for (std::size_t i = 0; i < m_views.size(); ++i) {
186 if (m_views[i].size() != other.m_views[i].size()) {
187 return false;
188 }
189 if (!detail::
190 equal(m_views[i].data(),
191 m_views[i].data() + m_views[i].size(),
192 other.m_views[i].data())) {
193 return false;
194 }
195 }
196 return true;
197 } else {
198 return *this == SparseDiscreteDomain(other);
199 }
200 }
201
202#if !defined(__cpp_impl_three_way_comparison) || __cpp_impl_three_way_comparison < 201902L
203 // In C++20, `a!=b` shall be automatically translated by the compiler to `!(a==b)`
204 template <concepts::discrete_dimension... ODDims>
205 KOKKOS_FUNCTION constexpr bool operator!=(SparseDiscreteDomain<ODDims...> const& other) const
206 {
207 return !(*this == other);
208 }
209#endif
210
211 KOKKOS_FUNCTION constexpr std::size_t size() const
212 {
213 return (1UL * ... * get<DDims>(m_views).size());
214 }
215
216 KOKKOS_FUNCTION constexpr discrete_vector_type extents() const noexcept
217 {
218 return discrete_vector_type(get<DDims>(m_views).size()...);
219 }
220
221 KOKKOS_FUNCTION constexpr auto discrete_elements() const noexcept
222 {
223 return m_views;
224 }
225
226 template <concepts::discrete_dimension QueryDDim>
227 KOKKOS_FUNCTION constexpr DiscreteVector<QueryDDim> extent() const noexcept
228 {
229 return DiscreteVector<QueryDDim>(get<QueryDDim>(m_views).size());
230 }
231
232 KOKKOS_FUNCTION constexpr discrete_element_type front() const noexcept
233 {
234 return discrete_element_type(get<DDims>(m_views)(0)...);
235 }
236
237 KOKKOS_FUNCTION constexpr discrete_element_type back() const noexcept
238 {
239 return discrete_element_type(get<DDims>(m_views)(get<DDims>(m_views).size() - 1)...);
240 }
241
242 KOKKOS_FUNCTION constexpr SparseDiscreteDomain take_first(discrete_vector_type n) const
243 {
244 return SparseDiscreteDomain(front(), n);
245 }
246
247 KOKKOS_FUNCTION constexpr SparseDiscreteDomain take_last(discrete_vector_type n) const
248 {
249 return SparseDiscreteDomain(front() + prod(extents() - n), n);
250 }
251
252 KOKKOS_FUNCTION constexpr SparseDiscreteDomain remove_first(discrete_vector_type n) const
253 {
254 return SparseDiscreteDomain(front() + prod(n), extents() - n);
255 }
256
257 KOKKOS_FUNCTION constexpr SparseDiscreteDomain remove_last(discrete_vector_type n) const
258 {
260 }
261
262 KOKKOS_FUNCTION constexpr SparseDiscreteDomain remove(
263 discrete_vector_type n1,
264 discrete_vector_type n2) const
265 {
266 return SparseDiscreteDomain(front() + prod(n1), extents() - n1 - n2);
267 }
268
269 KOKKOS_FUNCTION constexpr DiscreteElement<DDims...> operator()(
270 DiscreteVector<DDims...> const& dvect) const noexcept
271 {
272 return DiscreteElement<DDims...>(get<DDims>(m_views)(get<DDims>(dvect))...);
273 }
274
275 template <class... DElems>
276 KOKKOS_FUNCTION bool contains(DElems const&... delems) const noexcept
277 {
278 static_assert(
279 sizeof...(DDims) == (0 + ... + DElems::size()),
280 "Invalid number of dimensions");
281 static_assert((is_discrete_element_v<DElems> && ...), "Expected DiscreteElements");
282 DiscreteElement<DDims...> const delem(delems...);
283 for (std::size_t i = 0; i < rank(); ++i) {
284 if (!detail::binary_search(
285 m_views[i].data(),
286 m_views[i].data() + m_views[i].size(),
287 detail::array(delem)[i],
288 std::less {})) {
289 return false;
290 }
291 }
292 return true;
293 }
294
295 template <class... DElems>
296 KOKKOS_FUNCTION DiscreteVector<DDims...> distance_from_front(
297 DElems const&... delems) const noexcept
298 {
299 static_assert(
300 sizeof...(DDims) == (0 + ... + DElems::size()),
301 "Invalid number of dimensions");
302 static_assert((is_discrete_element_v<DElems> && ...), "Expected DiscreteElements");
303 KOKKOS_ASSERT(contains(delems...))
304 return DiscreteVector<DDims...>(
305 (detail::lower_bound(
306 get<DDims>(m_views).data(),
307 get<DDims>(m_views).data() + get<DDims>(m_views).size(),
308 uid<DDims>(take<DDims>(delems...)),
309 std::less {})
310 - get<DDims>(m_views).data())...);
311 }
312
313 KOKKOS_FUNCTION constexpr bool empty() const noexcept
314 {
315 return size() == 0;
316 }
317
318 KOKKOS_FUNCTION constexpr explicit operator bool()
319 {
320 return !empty();
321 }
322
323 KOKKOS_FUNCTION auto begin() const
324 requires(sizeof...(DDims) == 1)
325 {
326 using DDim0 = std::tuple_element_t<0, std::tuple<DDims...>>;
327 return get<DDim0>(m_views).data();
328 }
329
330 KOKKOS_FUNCTION auto end() const
331 requires(sizeof...(DDims) == 1)
332 {
333 using DDim0 = std::tuple_element_t<0, std::tuple<DDims...>>;
334 return get<DDim0>(m_views).data() + get<DDim0>(m_views).size();
335 }
336
337 KOKKOS_FUNCTION auto cbegin() const
338 requires(sizeof...(DDims) == 1)
339 {
340 using DDim0 = std::tuple_element_t<0, std::tuple<DDims...>>;
341 return get<DDim0>(m_views).data();
342 }
343
344 KOKKOS_FUNCTION auto cend() const
345 requires(sizeof...(DDims) == 1)
346 {
347 using DDim0 = std::tuple_element_t<0, std::tuple<DDims...>>;
348 return get<DDim0>(m_views).data() + get<DDim0>(m_views).size();
349 }
350
351 KOKKOS_FUNCTION constexpr decltype(auto) operator[](std::size_t n)
352 requires(sizeof...(DDims) == 1)
353 {
354 return begin()[n];
355 }
356
357 KOKKOS_FUNCTION constexpr decltype(auto) operator[](std::size_t n) const
358 requires(sizeof...(DDims) == 1)
359 {
360 return begin()[n];
361 }
362};
363
364template <>
366{
367 template <concepts::discrete_dimension...>
368 friend class SparseDiscreteDomain;
369
370public:
371 using discrete_element_type = DiscreteElement<>;
372
373 using discrete_vector_type = DiscreteVector<>;
374
375 static KOKKOS_FUNCTION constexpr std::size_t rank()
376 {
377 return 0;
378 }
379
380 KOKKOS_DEFAULTED_FUNCTION constexpr SparseDiscreteDomain() = default;
381
382 // Construct a SparseDiscreteDomain from a reordered copy of `domain`
383 template <concepts::discrete_dimension... ODDims>
384 KOKKOS_FUNCTION constexpr explicit SparseDiscreteDomain(
385 SparseDiscreteDomain<ODDims...> const& /*domain*/)
386 {
387 }
388
389 KOKKOS_DEFAULTED_FUNCTION SparseDiscreteDomain(SparseDiscreteDomain const& x) = default;
390
391 KOKKOS_DEFAULTED_FUNCTION SparseDiscreteDomain(SparseDiscreteDomain&& x) = default;
392
393 KOKKOS_DEFAULTED_FUNCTION ~SparseDiscreteDomain() = default;
394
395 KOKKOS_DEFAULTED_FUNCTION SparseDiscreteDomain& operator=(SparseDiscreteDomain const& x)
396 = default;
397
398 KOKKOS_DEFAULTED_FUNCTION SparseDiscreteDomain& operator=(SparseDiscreteDomain&& x) = default;
399
400 KOKKOS_FUNCTION constexpr bool operator==(SparseDiscreteDomain const& /*other*/) const
401 {
402 return true;
403 }
404
405#if !defined(__cpp_impl_three_way_comparison) || __cpp_impl_three_way_comparison < 201902L
406 // In C++20, `a!=b` shall be automatically translated by the compiler to `!(a==b)`
407 KOKKOS_FUNCTION constexpr bool operator!=(SparseDiscreteDomain const& other) const
408 {
409 return !(*this == other);
410 }
411#endif
412
413 static KOKKOS_FUNCTION constexpr std::size_t size()
414 {
415 return 1;
416 }
417
418 static KOKKOS_FUNCTION constexpr discrete_vector_type extents() noexcept
419 {
420 return {};
421 }
422
423 static KOKKOS_FUNCTION detail::TaggedVector<
424 Kokkos::View<DiscreteElementType*, Kokkos::SharedSpace>>
425 discrete_elements() noexcept
426 {
427 return {};
428 }
429
430 static KOKKOS_FUNCTION constexpr discrete_element_type front() noexcept
431 {
432 return {};
433 }
434
435 static KOKKOS_FUNCTION constexpr discrete_element_type back() noexcept
436 {
437 return {};
438 }
439
440 KOKKOS_FUNCTION constexpr SparseDiscreteDomain take_first(discrete_vector_type /*n*/) const
441 {
442 return *this;
443 }
444
445 KOKKOS_FUNCTION constexpr SparseDiscreteDomain take_last(discrete_vector_type /*n*/) const
446 {
447 return *this;
448 }
449
450 KOKKOS_FUNCTION constexpr SparseDiscreteDomain remove_first(discrete_vector_type /*n*/) const
451 {
452 return *this;
453 }
454
455 KOKKOS_FUNCTION constexpr SparseDiscreteDomain remove_last(discrete_vector_type /*n*/) const
456 {
457 return *this;
458 }
459
460 KOKKOS_FUNCTION constexpr SparseDiscreteDomain remove(
461 discrete_vector_type /*n1*/,
462 discrete_vector_type /*n2*/) const
463 {
464 return *this;
465 }
466
467 KOKKOS_FUNCTION constexpr DiscreteElement<> operator()(
468 DiscreteVector<> const& /*dvect*/) const noexcept
469 {
470 return {};
471 }
472
473 static KOKKOS_FUNCTION bool contains() noexcept
474 {
475 return true;
476 }
477
478 static KOKKOS_FUNCTION bool contains(DiscreteElement<>) noexcept
479 {
480 return true;
481 }
482
483 static KOKKOS_FUNCTION DiscreteVector<> distance_from_front() noexcept
484 {
485 return {};
486 }
487
488 static KOKKOS_FUNCTION DiscreteVector<> distance_from_front(DiscreteElement<>) noexcept
489 {
490 return {};
491 }
492
493 static KOKKOS_FUNCTION constexpr bool empty() noexcept
494 {
495 return false;
496 }
497
498 KOKKOS_FUNCTION constexpr explicit operator bool()
499 {
500 return true;
501 }
502};
503
504template <concepts::discrete_dimension... QueryDDims, concepts::discrete_dimension... DDims>
505KOKKOS_FUNCTION constexpr SparseDiscreteDomain<QueryDDims...> select(
506 SparseDiscreteDomain<DDims...> const& domain)
507{
508 return SparseDiscreteDomain<QueryDDims...>(domain);
509}
510
511namespace detail {
512
513template <ddc::concepts::type_seq T>
514struct ConvertTypeSeqToSparseDiscreteDomain
515{
516};
517
518template <ddc::concepts::discrete_dimension... DDims>
519struct ConvertTypeSeqToSparseDiscreteDomain<ddc::TypeSeq<DDims...>>
520{
521 using type = SparseDiscreteDomain<DDims...>;
522};
523
524template <ddc::concepts::type_seq T>
525using convert_type_seq_to_sparse_discrete_domain_t = ConvertTypeSeqToSparseDiscreteDomain<T>::type;
526
527} // namespace detail
528
529// 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)
530template <concepts::discrete_dimension... DDimsA, concepts::discrete_dimension... DDimsB>
531KOKKOS_FUNCTION constexpr auto remove_dims_of(
532 SparseDiscreteDomain<DDimsA...> const& DDom_a,
533 SparseDiscreteDomain<DDimsB...> const& /*DDom_b*/) noexcept
534{
535 using TagSeqA = TypeSeq<DDimsA...>;
536 using TagSeqB = TypeSeq<DDimsB...>;
537
538 using type_seq_r = type_seq_remove_t<TagSeqA, TagSeqB>;
539 return detail::convert_type_seq_to_sparse_discrete_domain_t<type_seq_r>(DDom_a);
540}
541
542//! Remove the dimensions DDimsB from DDom_a
543//! @param[in] DDom_a The discrete domain on which to remove dimensions
544//! @return The discrete domain without DDimsB dimensions
545template <concepts::discrete_dimension... DDimsB, concepts::discrete_dimension... DDimsA>
546KOKKOS_FUNCTION constexpr auto remove_dims_of(
547 SparseDiscreteDomain<DDimsA...> const& DDom_a) noexcept
548{
549 using TagSeqA = TypeSeq<DDimsA...>;
550 using TagSeqB = TypeSeq<DDimsB...>;
551
552 using type_seq_r = type_seq_remove_t<TagSeqA, TagSeqB>;
553 return detail::convert_type_seq_to_sparse_discrete_domain_t<type_seq_r>(DDom_a);
554}
555
556namespace detail {
557
558// 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
559template <
560 ddc::concepts::discrete_dimension DDim1,
561 ddc::concepts::discrete_dimension DDim2,
562 ddc::concepts::discrete_dimension DDimA,
563 ddc::concepts::discrete_dimension... DDimsB>
564KOKKOS_FUNCTION constexpr std::conditional_t<
565 std::is_same_v<DDimA, DDim1>,
568replace_dim_of_1d(
569 [[maybe_unused]] SparseDiscreteDomain<DDimA> const& DDom_a,
570 [[maybe_unused]] SparseDiscreteDomain<DDimsB...> const& DDom_b) noexcept
571{
572 if constexpr (std::is_same_v<DDimA, DDim1>) {
573 return ddc::SparseDiscreteDomain<DDim2>(DDom_b);
574 } else {
575 return DDom_a;
576 }
577}
578
579} // namespace detail
580
581// Replace in DDom_a the dimension Dim1 by the dimension Dim2 of DDom_b
582template <
583 concepts::discrete_dimension DDim1,
584 concepts::discrete_dimension DDim2,
585 concepts::discrete_dimension... DDimsA,
586 concepts::discrete_dimension... DDimsB>
587KOKKOS_FUNCTION constexpr auto replace_dim_of(
588 SparseDiscreteDomain<DDimsA...> const& DDom_a,
589 [[maybe_unused]] SparseDiscreteDomain<DDimsB...> const& DDom_b) noexcept
590{
591 // TODO : static_asserts
592 using TagSeqA = TypeSeq<DDimsA...>;
593 using TagSeqB = TypeSeq<DDim1>;
594 using TagSeqC = TypeSeq<DDim2>;
595
596 using type_seq_r = ddc::type_seq_replace_t<TagSeqA, TagSeqB, TagSeqC>;
597 return ddc::detail::convert_type_seq_to_sparse_discrete_domain_t<type_seq_r>(
598 detail::replace_dim_of_1d<
599 DDim1,
600 DDim2,
601 DDimsA,
602 DDimsB...>(ddc::SparseDiscreteDomain<DDimsA>(DDom_a), DDom_b)...);
603}
604
605template <concepts::discrete_dimension... QueryDDims, concepts::discrete_dimension... DDims>
606KOKKOS_FUNCTION constexpr DiscreteVector<QueryDDims...> extents(
607 SparseDiscreteDomain<DDims...> const& domain) noexcept
608{
609 return DiscreteVector<QueryDDims...>(SparseDiscreteDomain<QueryDDims>(domain).size()...);
610}
611
612template <concepts::discrete_dimension... QueryDDims, concepts::discrete_dimension... DDims>
613KOKKOS_FUNCTION constexpr DiscreteElement<QueryDDims...> front(
614 SparseDiscreteDomain<DDims...> const& domain) noexcept
615{
616 return DiscreteElement<QueryDDims...>(SparseDiscreteDomain<QueryDDims>(domain).front()...);
617}
618
619template <concepts::discrete_dimension... QueryDDims, concepts::discrete_dimension... DDims>
620KOKKOS_FUNCTION constexpr DiscreteElement<QueryDDims...> back(
621 SparseDiscreteDomain<DDims...> const& domain) noexcept
622{
623 return DiscreteElement<QueryDDims...>(SparseDiscreteDomain<QueryDDims>(domain).back()...);
624}
625
626namespace detail {
627
628void print_sparse_discrete_domain(
629 std::ostream& os,
630 bool empty,
631 std::span<DiscreteVectorElement const> extents,
632 std::span<Kokkos::View<DiscreteElementType*, Kokkos::SharedSpace> const> elements);
633
634} // namespace detail
635
636/**
637 * Print a SparseDiscreteDomain. The extents are displayed, followed by a non-exhaustive
638 * list of the elements of each dimension: all of them for small dimensions, otherwise
639 * only the first and last ones.
640 *
641 * For example `SparseDiscreteDomain(extents=(2, 3), elements=[[1, 4], [3, 5, 9]])`,
642 * `SparseDiscreteDomain(extents=(100), elements=[[0, 2, 4, ..., 194, 196, 198]])`, or
643 * `SparseDiscreteDomain(empty)` if the domain contains no element.
644 */
645template <concepts::discrete_dimension... DDims>
646std::ostream& operator<<(std::ostream& os, SparseDiscreteDomain<DDims...> const& domain)
647{
648 detail::print_sparse_discrete_domain(
649 os,
650 domain.empty(),
651 detail::array(domain.extents()),
652 domain.discrete_elements().array());
653 return os;
654}
655
656} // 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(int argc, char **&argv)
ScopeGuard(ScopeGuard &&x) noexcept=delete
ScopeGuard & operator=(ScopeGuard &&x) noexcept=delete
ScopeGuard(ScopeGuard const &x)=delete
static KOKKOS_FUNCTION bool contains(DiscreteElement<>) noexcept
KOKKOS_FUNCTION constexpr SparseDiscreteDomain remove(discrete_vector_type, discrete_vector_type) const
static KOKKOS_FUNCTION detail::TaggedVector< Kokkos::View< DiscreteElementType *, Kokkos::SharedSpace > > discrete_elements() noexcept
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 bool operator==(SparseDiscreteDomain< ODDims... > const &other) const
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_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 decltype(auto) operator[](std::size_t n) const
SparseDiscreteDomain(Kokkos::View< DiscreteElement< DDims > *, Kokkos::SharedSpace > const &... views)
Construct a SparseDiscreteDomain with Kokkos::View explicitly listing the discrete elements.
KOKKOS_DEFAULTED_FUNCTION SparseDiscreteDomain & operator=(SparseDiscreteDomain &&x)=default
KOKKOS_FUNCTION constexpr std::size_t size() const
KOKKOS_FUNCTION bool contains(DElems const &... delems) const noexcept
KOKKOS_FUNCTION constexpr decltype(auto) operator[](std::size_t n)
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 SparseDiscreteDomain(DDoms const &... domains)
Construct a SparseDiscreteDomain by copies and merge of domains.
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 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.
constexpr bool is_non_uniform_point_sampling_v
KOKKOS_FUNCTION constexpr DiscreteElement< QueryDDims... > back(SparseDiscreteDomain< DDims... > const &domain) noexcept
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 constexpr SparseDiscreteDomain< QueryDDims... > select(SparseDiscreteDomain< DDims... > const &domain)
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.
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
constexpr bool is_periodic_sampling_v
KOKKOS_FUNCTION Real step() noexcept
Spacing step 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 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)
A compile-time sequence of types.
Definition type_seq.hpp:30