DDC 0.12.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
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 = TypeSeq<Tags...>;
56};
57
58template <class T, class U>
59struct RebindDomain;
60
61template <class... DDims, class... ODDims>
62struct RebindDomain<SparseDiscreteDomain<DDims...>, detail::TypeSeq<ODDims...>>
63{
64 using type = SparseDiscreteDomain<ODDims...>;
65};
66
67template <class InputIt1, class InputIt2>
68KOKKOS_FUNCTION bool equal(InputIt1 first1, InputIt1 last1, InputIt2 first2)
69{
70 for (; first1 != last1; ++first1, ++first2) {
71 if (!(*first1 == *first2)) {
72 return false;
73 }
74 }
75
76 return true;
77}
78
79template <class ForwardIt, class T = std::iterator_traits<ForwardIt>::value_type, class Compare>
80KOKKOS_FUNCTION ForwardIt lower_bound(ForwardIt first, ForwardIt last, T const& value, Compare comp)
81{
82 ForwardIt it;
83 typename std::iterator_traits<ForwardIt>::difference_type count = last - first;
84 while (count > 0) {
85 it = first;
86 typename std::iterator_traits<ForwardIt>::difference_type const step = count / 2;
87 it += step;
88
89 if (comp(*it, value)) {
90 first = ++it;
91 count -= step + 1;
92 } else {
93 count = step;
94 }
95 }
96
97 return first;
98}
99
100template <class ForwardIt, class T = std::iterator_traits<ForwardIt>::value_type, 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::DefaultExecutionSpace const& exec_space,
110 Kokkos::View<DiscreteElement<DDim>*, Kokkos::SharedSpace> const& input)
111{
112 Kokkos::View<DiscreteElementType*, Kokkos::SharedSpace> output(input.label(), input.size());
113 Kokkos::parallel_for(
114 "SparseDiscreteDomainCtor",
115 Kokkos::RangePolicy<
116 Kokkos::DefaultExecutionSpace,
117 Kokkos::IndexType<std::size_t>>(exec_space, 0, output.size()),
118 KOKKOS_LAMBDA(std::size_t const i) { output(i) = input(i).uid(); });
119 return output;
120}
121
122} // namespace detail
123
124template <class... DDims>
126{
127 template <class...>
128 friend class SparseDiscreteDomain;
129
130 static_assert(
131 type_seq_is_unique_v<detail::TypeSeq<DDims...>>,
132 "The dimensions of a SparseDiscreteDomain must be unique");
133
134public:
135 using discrete_element_type = DiscreteElement<DDims...>;
136
137 using discrete_vector_type = DiscreteVector<DDims...>;
138
139private:
140 detail::TaggedVector<Kokkos::View<DiscreteElementType*, Kokkos::SharedSpace>, DDims...> m_views;
141
142public:
143 static KOKKOS_FUNCTION constexpr std::size_t rank()
144 {
145 return sizeof...(DDims);
146 }
147
148 KOKKOS_DEFAULTED_FUNCTION SparseDiscreteDomain() = default;
149
150 /// Construct a SparseDiscreteDomain by copies and merge of domains
151 template <concepts::sparse_discrete_domain... DDoms>
152 KOKKOS_FUNCTION constexpr explicit SparseDiscreteDomain(DDoms const&... domains)
153 : m_views(domains.m_views...)
154 {
155 }
156
157 /** Construct a SparseDiscreteDomain with Kokkos::View explicitly listing the discrete elements.
158 * @param views list of Kokkos::View
159 */
160 explicit SparseDiscreteDomain(
161 Kokkos::View<DiscreteElement<DDims>*, Kokkos::SharedSpace> const&... views)
162 {
163 Kokkos::DefaultExecutionSpace const exec_space;
164 ((m_views[type_seq_rank_v<DDims, detail::TypeSeq<DDims...>>]
165 = detail::extract_uid(exec_space, views)),
166 ...);
167 exec_space.fence("SparseDiscreteDomainCtor");
168 }
169
170 KOKKOS_DEFAULTED_FUNCTION SparseDiscreteDomain(SparseDiscreteDomain const& x) = default;
171
172 KOKKOS_DEFAULTED_FUNCTION SparseDiscreteDomain(SparseDiscreteDomain&& x) = default;
173
174 KOKKOS_DEFAULTED_FUNCTION ~SparseDiscreteDomain() = default;
175
176 KOKKOS_DEFAULTED_FUNCTION SparseDiscreteDomain& operator=(SparseDiscreteDomain const& x)
177 = default;
178
179 KOKKOS_DEFAULTED_FUNCTION SparseDiscreteDomain& operator=(SparseDiscreteDomain&& x) = default;
180
181 template <class... ODims>
182 KOKKOS_FUNCTION constexpr bool operator==(SparseDiscreteDomain<ODims...> const& other) const
183 {
184 if constexpr ((std::is_same_v<DDims, ODims> && ...)) {
185 if (empty() && other.empty()) {
186 return true;
187 }
188 for (std::size_t i = 0; i < m_views.size(); ++i) {
189 if (m_views[i].size() != other.m_views[i].size()) {
190 return false;
191 }
192 if (!detail::
193 equal(m_views[i].data(),
194 m_views[i].data() + m_views[i].size(),
195 other.m_views[i].data())) {
196 return false;
197 }
198 }
199 return true;
200 } else {
201 return *this == SparseDiscreteDomain(other);
202 }
203 }
204
205#if !defined(__cpp_impl_three_way_comparison) || __cpp_impl_three_way_comparison < 201902L
206 // In C++20, `a!=b` shall be automatically translated by the compiler to `!(a==b)`
207 template <class... ODims>
208 KOKKOS_FUNCTION constexpr bool operator!=(SparseDiscreteDomain<ODims...> const& other) const
209 {
210 return !(*this == other);
211 }
212#endif
213
214 KOKKOS_FUNCTION constexpr std::size_t size() const
215 {
216 return (1UL * ... * get<DDims>(m_views).size());
217 }
218
219 KOKKOS_FUNCTION constexpr discrete_vector_type extents() const noexcept
220 {
221 return discrete_vector_type(get<DDims>(m_views).size()...);
222 }
223
224 KOKKOS_FUNCTION constexpr auto discrete_elements() const noexcept
225 {
226 return m_views;
227 }
228
229 template <class QueryDDim>
230 KOKKOS_FUNCTION constexpr DiscreteVector<QueryDDim> extent() const noexcept
231 {
232 return DiscreteVector<QueryDDim>(get<QueryDDim>(m_views).size());
233 }
234
235 KOKKOS_FUNCTION constexpr discrete_element_type front() const noexcept
236 {
237 return discrete_element_type(get<DDims>(m_views)(0)...);
238 }
239
240 KOKKOS_FUNCTION constexpr discrete_element_type back() const noexcept
241 {
242 return discrete_element_type(get<DDims>(m_views)(get<DDims>(m_views).size() - 1)...);
243 }
244
245 KOKKOS_FUNCTION constexpr SparseDiscreteDomain take_first(discrete_vector_type n) const
246 {
247 return SparseDiscreteDomain(front(), n);
248 }
249
250 KOKKOS_FUNCTION constexpr SparseDiscreteDomain take_last(discrete_vector_type n) const
251 {
252 return SparseDiscreteDomain(front() + prod(extents() - n), n);
253 }
254
255 KOKKOS_FUNCTION constexpr SparseDiscreteDomain remove_first(discrete_vector_type n) const
256 {
257 return SparseDiscreteDomain(front() + prod(n), extents() - n);
258 }
259
260 KOKKOS_FUNCTION constexpr SparseDiscreteDomain remove_last(discrete_vector_type n) const
261 {
263 }
264
265 KOKKOS_FUNCTION constexpr SparseDiscreteDomain remove(
266 discrete_vector_type n1,
267 discrete_vector_type n2) const
268 {
269 return SparseDiscreteDomain(front() + prod(n1), extents() - n1 - n2);
270 }
271
272 KOKKOS_FUNCTION constexpr DiscreteElement<DDims...> operator()(
273 DiscreteVector<DDims...> const& dvect) const noexcept
274 {
275 return DiscreteElement<DDims...>(get<DDims>(m_views)(get<DDims>(dvect))...);
276 }
277
278 template <class... DElems>
279 KOKKOS_FUNCTION bool contains(DElems const&... delems) const noexcept
280 {
281 static_assert(
282 sizeof...(DDims) == (0 + ... + DElems::size()),
283 "Invalid number of dimensions");
284 static_assert((is_discrete_element_v<DElems> && ...), "Expected DiscreteElements");
285 DiscreteElement<DDims...> const delem(delems...);
286 for (std::size_t i = 0; i < rank(); ++i) {
287 if (!detail::binary_search(
288 m_views[i].data(),
289 m_views[i].data() + m_views[i].size(),
290 detail::array(delem)[i],
291 std::less {})) {
292 return false;
293 }
294 }
295 return true;
296 }
297
298 template <class... DElems>
299 KOKKOS_FUNCTION DiscreteVector<DDims...> distance_from_front(
300 DElems const&... delems) const noexcept
301 {
302 static_assert(
303 sizeof...(DDims) == (0 + ... + DElems::size()),
304 "Invalid number of dimensions");
305 static_assert((is_discrete_element_v<DElems> && ...), "Expected DiscreteElements");
306 KOKKOS_ASSERT(contains(delems...))
307 return DiscreteVector<DDims...>(
308 (detail::lower_bound(
309 get<DDims>(m_views).data(),
310 get<DDims>(m_views).data() + get<DDims>(m_views).size(),
311 uid<DDims>(take<DDims>(delems...)),
312 std::less {})
313 - get<DDims>(m_views).data())...);
314 }
315
316 KOKKOS_FUNCTION constexpr bool empty() const noexcept
317 {
318 return size() == 0;
319 }
320
321 KOKKOS_FUNCTION constexpr explicit operator bool()
322 {
323 return !empty();
324 }
325
326 KOKKOS_FUNCTION auto begin() const
327 requires(sizeof...(DDims) == 1)
328 {
329 using DDim0 = std::tuple_element_t<0, std::tuple<DDims...>>;
330 return get<DDim0>(m_views).data();
331 }
332
333 KOKKOS_FUNCTION auto end() const
334 requires(sizeof...(DDims) == 1)
335 {
336 using DDim0 = std::tuple_element_t<0, std::tuple<DDims...>>;
337 return get<DDim0>(m_views).data() + get<DDim0>(m_views).size();
338 }
339
340 KOKKOS_FUNCTION auto cbegin() const
341 requires(sizeof...(DDims) == 1)
342 {
343 using DDim0 = std::tuple_element_t<0, std::tuple<DDims...>>;
344 return get<DDim0>(m_views).data();
345 }
346
347 KOKKOS_FUNCTION auto cend() const
348 requires(sizeof...(DDims) == 1)
349 {
350 using DDim0 = std::tuple_element_t<0, std::tuple<DDims...>>;
351 return get<DDim0>(m_views).data() + get<DDim0>(m_views).size();
352 }
353
354 KOKKOS_FUNCTION constexpr decltype(auto) operator[](std::size_t n)
355 requires(sizeof...(DDims) == 1)
356 {
357 return begin()[n];
358 }
359
360 KOKKOS_FUNCTION constexpr decltype(auto) operator[](std::size_t n) const
361 requires(sizeof...(DDims) == 1)
362 {
363 return begin()[n];
364 }
365};
366
367template <>
369{
370 template <class...>
371 friend class SparseDiscreteDomain;
372
373public:
374 using discrete_element_type = DiscreteElement<>;
375
376 using discrete_vector_type = DiscreteVector<>;
377
378 static KOKKOS_FUNCTION constexpr std::size_t rank()
379 {
380 return 0;
381 }
382
383 KOKKOS_DEFAULTED_FUNCTION constexpr SparseDiscreteDomain() = default;
384
385 // Construct a SparseDiscreteDomain from a reordered copy of `domain`
386 template <class... ODDims>
387 KOKKOS_FUNCTION constexpr explicit SparseDiscreteDomain(
388 SparseDiscreteDomain<ODDims...> const& /*domain*/)
389 {
390 }
391
392 KOKKOS_DEFAULTED_FUNCTION SparseDiscreteDomain(SparseDiscreteDomain const& x) = default;
393
394 KOKKOS_DEFAULTED_FUNCTION SparseDiscreteDomain(SparseDiscreteDomain&& x) = default;
395
396 KOKKOS_DEFAULTED_FUNCTION ~SparseDiscreteDomain() = default;
397
398 KOKKOS_DEFAULTED_FUNCTION SparseDiscreteDomain& operator=(SparseDiscreteDomain const& x)
399 = default;
400
401 KOKKOS_DEFAULTED_FUNCTION SparseDiscreteDomain& operator=(SparseDiscreteDomain&& x) = default;
402
403 KOKKOS_FUNCTION constexpr bool operator==(SparseDiscreteDomain const& /*other*/) const
404 {
405 return true;
406 }
407
408#if !defined(__cpp_impl_three_way_comparison) || __cpp_impl_three_way_comparison < 201902L
409 // In C++20, `a!=b` shall be automatically translated by the compiler to `!(a==b)`
410 KOKKOS_FUNCTION constexpr bool operator!=(SparseDiscreteDomain const& other) const
411 {
412 return !(*this == other);
413 }
414#endif
415
416 static KOKKOS_FUNCTION constexpr std::size_t size()
417 {
418 return 1;
419 }
420
421 static KOKKOS_FUNCTION constexpr discrete_vector_type extents() noexcept
422 {
423 return {};
424 }
425
426 static KOKKOS_FUNCTION constexpr discrete_element_type front() noexcept
427 {
428 return {};
429 }
430
431 static KOKKOS_FUNCTION constexpr discrete_element_type back() noexcept
432 {
433 return {};
434 }
435
436 KOKKOS_FUNCTION constexpr SparseDiscreteDomain take_first(discrete_vector_type /*n*/) const
437 {
438 return *this;
439 }
440
441 KOKKOS_FUNCTION constexpr SparseDiscreteDomain take_last(discrete_vector_type /*n*/) const
442 {
443 return *this;
444 }
445
446 KOKKOS_FUNCTION constexpr SparseDiscreteDomain remove_first(discrete_vector_type /*n*/) const
447 {
448 return *this;
449 }
450
451 KOKKOS_FUNCTION constexpr SparseDiscreteDomain remove_last(discrete_vector_type /*n*/) const
452 {
453 return *this;
454 }
455
456 KOKKOS_FUNCTION constexpr SparseDiscreteDomain remove(
457 discrete_vector_type /*n1*/,
458 discrete_vector_type /*n2*/) const
459 {
460 return *this;
461 }
462
463 KOKKOS_FUNCTION constexpr DiscreteElement<> operator()(
464 DiscreteVector<> const& /*dvect*/) const noexcept
465 {
466 return {};
467 }
468
469 static KOKKOS_FUNCTION bool contains() noexcept
470 {
471 return true;
472 }
473
474 static KOKKOS_FUNCTION bool contains(DiscreteElement<>) noexcept
475 {
476 return true;
477 }
478
479 static KOKKOS_FUNCTION DiscreteVector<> distance_from_front() noexcept
480 {
481 return {};
482 }
483
484 static KOKKOS_FUNCTION DiscreteVector<> distance_from_front(DiscreteElement<>) noexcept
485 {
486 return {};
487 }
488
489 static KOKKOS_FUNCTION constexpr bool empty() noexcept
490 {
491 return false;
492 }
493
494 KOKKOS_FUNCTION constexpr explicit operator bool()
495 {
496 return true;
497 }
498};
499
500template <class... QueryDDims, class... DDims>
501KOKKOS_FUNCTION constexpr SparseDiscreteDomain<QueryDDims...> select(
502 SparseDiscreteDomain<DDims...> const& domain)
503{
504 return SparseDiscreteDomain<QueryDDims...>(domain);
505}
506
507namespace detail {
508
509template <class T>
510struct ConvertTypeSeqToSparseDiscreteDomain;
511
512template <class... DDims>
513struct ConvertTypeSeqToSparseDiscreteDomain<detail::TypeSeq<DDims...>>
514{
515 using type = SparseDiscreteDomain<DDims...>;
516};
517
518template <class T>
519using convert_type_seq_to_sparse_discrete_domain_t = ConvertTypeSeqToSparseDiscreteDomain<T>::type;
520
521} // namespace detail
522
523// 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)
524template <class... DDimsA, class... DDimsB>
525KOKKOS_FUNCTION constexpr auto remove_dims_of(
526 SparseDiscreteDomain<DDimsA...> const& DDom_a,
527 SparseDiscreteDomain<DDimsB...> const& /*DDom_b*/) noexcept
528{
529 using TagSeqA = detail::TypeSeq<DDimsA...>;
530 using TagSeqB = detail::TypeSeq<DDimsB...>;
531
532 using type_seq_r = type_seq_remove_t<TagSeqA, TagSeqB>;
533 return detail::convert_type_seq_to_sparse_discrete_domain_t<type_seq_r>(DDom_a);
534}
535
536//! Remove the dimensions DDimsB from DDom_a
537//! @param[in] DDom_a The discrete domain on which to remove dimensions
538//! @return The discrete domain without DDimsB dimensions
539template <class... DDimsB, class... DDimsA>
540KOKKOS_FUNCTION constexpr auto remove_dims_of(
541 SparseDiscreteDomain<DDimsA...> const& DDom_a) noexcept
542{
543 using TagSeqA = detail::TypeSeq<DDimsA...>;
544 using TagSeqB = detail::TypeSeq<DDimsB...>;
545
546 using type_seq_r = type_seq_remove_t<TagSeqA, TagSeqB>;
547 return detail::convert_type_seq_to_sparse_discrete_domain_t<type_seq_r>(DDom_a);
548}
549
550namespace detail {
551
552// 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
553template <typename DDim1, typename DDim2, typename DDimA, typename... DDimsB>
554KOKKOS_FUNCTION constexpr std::conditional_t<
555 std::is_same_v<DDimA, DDim1>,
558replace_dim_of_1d(
559 [[maybe_unused]] SparseDiscreteDomain<DDimA> const& DDom_a,
560 [[maybe_unused]] SparseDiscreteDomain<DDimsB...> const& DDom_b) noexcept
561{
562 if constexpr (std::is_same_v<DDimA, DDim1>) {
563 return ddc::SparseDiscreteDomain<DDim2>(DDom_b);
564 } else {
565 return DDom_a;
566 }
567}
568
569} // namespace detail
570
571// Replace in DDom_a the dimension Dim1 by the dimension Dim2 of DDom_b
572template <typename DDim1, typename DDim2, typename... DDimsA, typename... DDimsB>
573KOKKOS_FUNCTION constexpr auto replace_dim_of(
574 SparseDiscreteDomain<DDimsA...> const& DDom_a,
575 [[maybe_unused]] SparseDiscreteDomain<DDimsB...> const& DDom_b) noexcept
576{
577 // TODO : static_asserts
578 using TagSeqA = detail::TypeSeq<DDimsA...>;
579 using TagSeqB = detail::TypeSeq<DDim1>;
580 using TagSeqC = detail::TypeSeq<DDim2>;
581
582 using type_seq_r = ddc::type_seq_replace_t<TagSeqA, TagSeqB, TagSeqC>;
583 return ddc::detail::convert_type_seq_to_sparse_discrete_domain_t<type_seq_r>(
584 detail::replace_dim_of_1d<
585 DDim1,
586 DDim2,
587 DDimsA,
588 DDimsB...>(ddc::SparseDiscreteDomain<DDimsA>(DDom_a), DDom_b)...);
589}
590
591template <class... QueryDDims, class... DDims>
592KOKKOS_FUNCTION constexpr DiscreteVector<QueryDDims...> extents(
593 SparseDiscreteDomain<DDims...> const& domain) noexcept
594{
595 return DiscreteVector<QueryDDims...>(SparseDiscreteDomain<QueryDDims>(domain).size()...);
596}
597
598template <class... QueryDDims, class... DDims>
599KOKKOS_FUNCTION constexpr DiscreteElement<QueryDDims...> front(
600 SparseDiscreteDomain<DDims...> const& domain) noexcept
601{
602 return DiscreteElement<QueryDDims...>(SparseDiscreteDomain<QueryDDims>(domain).front()...);
603}
604
605template <class... QueryDDims, class... DDims>
606KOKKOS_FUNCTION constexpr DiscreteElement<QueryDDims...> back(
607 SparseDiscreteDomain<DDims...> const& domain) noexcept
608{
609 return DiscreteElement<QueryDDims...>(SparseDiscreteDomain<QueryDDims>(domain).back()...);
610}
611
612} // 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_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 constexpr bool operator==(SparseDiscreteDomain< ODims... > const &other) 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)