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