DDC 0.11.0
Loading...
Searching...
No Matches
sparse_discrete_domain.hpp
1// Copyright (C) The DDC development team, see COPYRIGHT.md file
2//
3// SPDX-License-Identifier: MIT
4
5#pragma once
6
7#include <cstddef>
8#include <functional>
9#include <iterator>
10#include <string>
11#include <tuple>
12#include <type_traits>
13
14#include <Kokkos_Core.hpp>
15
16#include "detail/tagged_vector.hpp"
17#include "detail/type_seq.hpp"
18
21
22namespace ddc {
23
24template <class DDim>
25struct SparseDiscreteDomainIterator;
26
27template <class... DDims>
29
30template <class T>
31struct is_sparse_discrete_domain : std::false_type
32{
33};
34
35template <class... Tags>
36struct is_sparse_discrete_domain<SparseDiscreteDomain<Tags...>> : std::true_type
37{
38};
39
40template <class T>
42
43
44namespace detail {
45
46template <class... Tags>
47struct ToTypeSeq<SparseDiscreteDomain<Tags...>>
48{
49 using type = TypeSeq<Tags...>;
50};
51
52template <class T, class U>
53struct RebindDomain;
54
55template <class... DDims, class... ODDims>
56struct RebindDomain<SparseDiscreteDomain<DDims...>, detail::TypeSeq<ODDims...>>
57{
58 using type = SparseDiscreteDomain<ODDims...>;
59};
60
61template <class InputIt1, class InputIt2>
62KOKKOS_FUNCTION bool equal(InputIt1 first1, InputIt1 last1, InputIt2 first2)
63{
64 for (; first1 != last1; ++first1, ++first2) {
65 if (!(*first1 == *first2)) {
66 return false;
67 }
68 }
69
70 return true;
71}
72
73template <
74 class ForwardIt,
75 class T = typename std::iterator_traits<ForwardIt>::value_type,
76 class Compare>
77KOKKOS_FUNCTION ForwardIt lower_bound(ForwardIt first, ForwardIt last, T const& value, Compare comp)
78{
79 ForwardIt it;
80 typename std::iterator_traits<ForwardIt>::difference_type count = last - first;
81 while (count > 0) {
82 it = first;
83 typename std::iterator_traits<ForwardIt>::difference_type const step = count / 2;
84 it += step;
85
86 if (comp(*it, value)) {
87 first = ++it;
88 count -= step + 1;
89 } else {
90 count = step;
91 }
92 }
93
94 return first;
95}
96
97template <
98 class ForwardIt,
99 class T = typename std::iterator_traits<ForwardIt>::value_type,
100 class Compare>
101KOKKOS_FUNCTION bool binary_search(ForwardIt first, ForwardIt last, T const& value, Compare comp)
102{
103 first = ::ddc::detail::lower_bound(first, last, value, comp);
104 return (!(first == last) && !(comp(value, *first)));
105}
106
107template <class DDim>
108Kokkos::View<DiscreteElementType*, Kokkos::SharedSpace> extract_uid(
109 Kokkos::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 <class... DDoms, class = std::enable_if_t<(is_sparse_discrete_domain_v<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 template <
327 std::size_t N = sizeof...(DDims),
328 class DDim0 = std::enable_if_t<N == 1, std::tuple_element_t<0, std::tuple<DDims...>>>>
329 KOKKOS_FUNCTION auto begin() const
330 {
331 return get<DDim0>(m_views).data();
332 }
333
334 template <
335 std::size_t N = sizeof...(DDims),
336 class DDim0 = std::enable_if_t<N == 1, std::tuple_element_t<0, std::tuple<DDims...>>>>
337 KOKKOS_FUNCTION auto end() const
338 {
339 return get<DDim0>(m_views).data() + get<DDim0>(m_views).size();
340 }
341
342 template <
343 std::size_t N = sizeof...(DDims),
344 class DDim0 = std::enable_if_t<N == 1, std::tuple_element_t<0, std::tuple<DDims...>>>>
345 KOKKOS_FUNCTION auto cbegin() const
346 {
347 return get<DDim0>(m_views).data();
348 }
349
350 template <
351 std::size_t N = sizeof...(DDims),
352 class DDim0 = std::enable_if_t<N == 1, std::tuple_element_t<0, std::tuple<DDims...>>>>
353 KOKKOS_FUNCTION auto cend() const
354 {
355 return get<DDim0>(m_views).data() + get<DDim0>(m_views).size();
356 }
357
358 template <
359 std::size_t N = sizeof...(DDims),
360 class = std::enable_if_t<N == 1, std::tuple_element_t<0, std::tuple<DDims...>>>>
361 KOKKOS_FUNCTION constexpr decltype(auto) operator[](std::size_t n)
362 {
363 return begin()[n];
364 }
365
366 template <
367 std::size_t N = sizeof...(DDims),
368 class = std::enable_if_t<N == 1, std::tuple_element_t<0, std::tuple<DDims...>>>>
369 KOKKOS_FUNCTION constexpr decltype(auto) operator[](std::size_t n) const
370 {
371 return begin()[n];
372 }
373};
374
375template <>
377{
378 template <class...>
379 friend class SparseDiscreteDomain;
380
381public:
382 using discrete_element_type = DiscreteElement<>;
383
384 using discrete_vector_type = DiscreteVector<>;
385
386 static KOKKOS_FUNCTION constexpr std::size_t rank()
387 {
388 return 0;
389 }
390
391 KOKKOS_DEFAULTED_FUNCTION constexpr SparseDiscreteDomain() = default;
392
393 // Construct a SparseDiscreteDomain from a reordered copy of `domain`
394 template <class... ODDims>
395 KOKKOS_FUNCTION constexpr explicit SparseDiscreteDomain(
396 SparseDiscreteDomain<ODDims...> const& /*domain*/)
397 {
398 }
399
400 KOKKOS_DEFAULTED_FUNCTION SparseDiscreteDomain(SparseDiscreteDomain const& x) = default;
401
402 KOKKOS_DEFAULTED_FUNCTION SparseDiscreteDomain(SparseDiscreteDomain&& x) = default;
403
404 KOKKOS_DEFAULTED_FUNCTION ~SparseDiscreteDomain() = default;
405
406 KOKKOS_DEFAULTED_FUNCTION SparseDiscreteDomain& operator=(SparseDiscreteDomain const& x)
407 = default;
408
409 KOKKOS_DEFAULTED_FUNCTION SparseDiscreteDomain& operator=(SparseDiscreteDomain&& x) = default;
410
411 KOKKOS_FUNCTION constexpr bool operator==(SparseDiscreteDomain const& /*other*/) const
412 {
413 return true;
414 }
415
416#if !defined(__cpp_impl_three_way_comparison) || __cpp_impl_three_way_comparison < 201902L
417 // In C++20, `a!=b` shall be automatically translated by the compiler to `!(a==b)`
418 KOKKOS_FUNCTION constexpr bool operator!=(SparseDiscreteDomain const& other) const
419 {
420 return !(*this == other);
421 }
422#endif
423
424 static KOKKOS_FUNCTION constexpr std::size_t size()
425 {
426 return 1;
427 }
428
429 static KOKKOS_FUNCTION constexpr discrete_vector_type extents() noexcept
430 {
431 return {};
432 }
433
434 static KOKKOS_FUNCTION constexpr discrete_element_type front() noexcept
435 {
436 return {};
437 }
438
439 static KOKKOS_FUNCTION constexpr discrete_element_type back() noexcept
440 {
441 return {};
442 }
443
444 KOKKOS_FUNCTION constexpr SparseDiscreteDomain take_first(discrete_vector_type /*n*/) const
445 {
446 return *this;
447 }
448
449 KOKKOS_FUNCTION constexpr SparseDiscreteDomain take_last(discrete_vector_type /*n*/) const
450 {
451 return *this;
452 }
453
454 KOKKOS_FUNCTION constexpr SparseDiscreteDomain remove_first(discrete_vector_type /*n*/) const
455 {
456 return *this;
457 }
458
459 KOKKOS_FUNCTION constexpr SparseDiscreteDomain remove_last(discrete_vector_type /*n*/) const
460 {
461 return *this;
462 }
463
464 KOKKOS_FUNCTION constexpr SparseDiscreteDomain remove(
465 discrete_vector_type /*n1*/,
466 discrete_vector_type /*n2*/) const
467 {
468 return *this;
469 }
470
471 KOKKOS_FUNCTION constexpr DiscreteElement<> operator()(
472 DiscreteVector<> const& /*dvect*/) const noexcept
473 {
474 return {};
475 }
476
477 static KOKKOS_FUNCTION bool contains() noexcept
478 {
479 return true;
480 }
481
482 static KOKKOS_FUNCTION bool contains(DiscreteElement<>) noexcept
483 {
484 return true;
485 }
486
487 static KOKKOS_FUNCTION DiscreteVector<> distance_from_front() noexcept
488 {
489 return {};
490 }
491
492 static KOKKOS_FUNCTION DiscreteVector<> distance_from_front(DiscreteElement<>) noexcept
493 {
494 return {};
495 }
496
497 static KOKKOS_FUNCTION constexpr bool empty() noexcept
498 {
499 return false;
500 }
501
502 KOKKOS_FUNCTION constexpr explicit operator bool()
503 {
504 return true;
505 }
506};
507
508template <class... QueryDDims, class... DDims>
509KOKKOS_FUNCTION constexpr SparseDiscreteDomain<QueryDDims...> select(
510 SparseDiscreteDomain<DDims...> const& domain)
511{
512 return SparseDiscreteDomain<QueryDDims...>(domain);
513}
514
515namespace detail {
516
517template <class T>
518struct ConvertTypeSeqToSparseDiscreteDomain;
519
520template <class... DDims>
521struct ConvertTypeSeqToSparseDiscreteDomain<detail::TypeSeq<DDims...>>
522{
523 using type = SparseDiscreteDomain<DDims...>;
524};
525
526template <class T>
527using convert_type_seq_to_sparse_discrete_domain_t =
528 typename ConvertTypeSeqToSparseDiscreteDomain<T>::type;
529
530} // namespace detail
531
532// 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)
533template <class... DDimsA, class... DDimsB>
534KOKKOS_FUNCTION constexpr auto remove_dims_of(
535 SparseDiscreteDomain<DDimsA...> const& DDom_a,
536 SparseDiscreteDomain<DDimsB...> const& /*DDom_b*/) noexcept
537{
538 using TagSeqA = detail::TypeSeq<DDimsA...>;
539 using TagSeqB = detail::TypeSeq<DDimsB...>;
540
541 using type_seq_r = type_seq_remove_t<TagSeqA, TagSeqB>;
542 return detail::convert_type_seq_to_sparse_discrete_domain_t<type_seq_r>(DDom_a);
543}
544
545//! Remove the dimensions DDimsB from DDom_a
546//! @param[in] DDom_a The discrete domain on which to remove dimensions
547//! @return The discrete domain without DDimsB dimensions
548template <class... DDimsB, class... DDimsA>
549KOKKOS_FUNCTION constexpr auto remove_dims_of(
550 SparseDiscreteDomain<DDimsA...> const& DDom_a) noexcept
551{
552 using TagSeqA = detail::TypeSeq<DDimsA...>;
553 using TagSeqB = detail::TypeSeq<DDimsB...>;
554
555 using type_seq_r = type_seq_remove_t<TagSeqA, TagSeqB>;
556 return detail::convert_type_seq_to_sparse_discrete_domain_t<type_seq_r>(DDom_a);
557}
558
559namespace detail {
560
561// 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
562template <typename DDim1, typename DDim2, typename DDimA, typename... DDimsB>
563KOKKOS_FUNCTION constexpr std::conditional_t<
564 std::is_same_v<DDimA, DDim1>,
567replace_dim_of_1d(
568 [[maybe_unused]] SparseDiscreteDomain<DDimA> const& DDom_a,
569 [[maybe_unused]] SparseDiscreteDomain<DDimsB...> const& DDom_b) noexcept
570{
571 if constexpr (std::is_same_v<DDimA, DDim1>) {
572 return ddc::SparseDiscreteDomain<DDim2>(DDom_b);
573 } else {
574 return DDom_a;
575 }
576}
577
578} // namespace detail
579
580// Replace in DDom_a the dimension Dim1 by the dimension Dim2 of DDom_b
581template <typename DDim1, typename DDim2, typename... DDimsA, typename... DDimsB>
582KOKKOS_FUNCTION constexpr auto replace_dim_of(
583 SparseDiscreteDomain<DDimsA...> const& DDom_a,
584 [[maybe_unused]] SparseDiscreteDomain<DDimsB...> const& DDom_b) noexcept
585{
586 // TODO : static_asserts
587 using TagSeqA = detail::TypeSeq<DDimsA...>;
588 using TagSeqB = detail::TypeSeq<DDim1>;
589 using TagSeqC = detail::TypeSeq<DDim2>;
590
591 using type_seq_r = ddc::type_seq_replace_t<TagSeqA, TagSeqB, TagSeqC>;
592 return ddc::detail::convert_type_seq_to_sparse_discrete_domain_t<type_seq_r>(
593 detail::replace_dim_of_1d<
594 DDim1,
595 DDim2,
596 DDimsA,
597 DDimsB...>(ddc::SparseDiscreteDomain<DDimsA>(DDom_a), DDom_b)...);
598}
599
600template <class... QueryDDims, class... DDims>
601KOKKOS_FUNCTION constexpr DiscreteVector<QueryDDims...> extents(
602 SparseDiscreteDomain<DDims...> const& domain) noexcept
603{
604 return DiscreteVector<QueryDDims...>(SparseDiscreteDomain<QueryDDims>(domain).size()...);
605}
606
607template <class... QueryDDims, class... DDims>
608KOKKOS_FUNCTION constexpr DiscreteElement<QueryDDims...> front(
609 SparseDiscreteDomain<DDims...> const& domain) noexcept
610{
611 return DiscreteElement<QueryDDims...>(SparseDiscreteDomain<QueryDDims>(domain).front()...);
612}
613
614template <class... QueryDDims, class... DDims>
615KOKKOS_FUNCTION constexpr DiscreteElement<QueryDDims...> back(
616 SparseDiscreteDomain<DDims...> const& domain) noexcept
617{
618 return DiscreteElement<QueryDDims...>(SparseDiscreteDomain<QueryDDims>(domain).back()...);
619}
620
621} // namespace ddc
friend class DiscreteDomain
KOKKOS_DEFAULTED_FUNCTION constexpr DiscreteElement()=default
KOKKOS_FUNCTION constexpr bool operator!=(DiscreteVector< OTags... > const &rhs) const noexcept
KOKKOS_DEFAULTED_FUNCTION constexpr DiscreteVector()=default
KOKKOS_FUNCTION std::size_t size() const
KOKKOS_FUNCTION Coordinate< CDim > coordinate(discrete_element_type const &icoord) const noexcept
Convert a mesh index into a position in CDim
Impl(Impl< DDim, OriginMemorySpace > const &impl)
Impl & operator=(Impl &&x)=default
Impl & operator=(Impl const &x)=delete
Impl(InputIt const points_begin, InputIt const points_end)
Construct a NonUniformPointSampling using a pair of iterators.
KOKKOS_FUNCTION discrete_element_type front() const noexcept
Lower bound index of the mesh.
Impl(InputRange const &points)
Construct a NonUniformPointSampling using a C++20 "common range".
Impl(std::initializer_list< Coordinate< CDim > > const points)
Construct a NonUniformPointSampling using a brace-list, i.e. NonUniformPointSampling mesh({0....
NonUniformPointSampling models a non-uniform discretization of the CDim segment .
static std::tuple< typename DDim::template Impl< DDim, Kokkos::HostSpace >, DiscreteDomain< DDim > > init(InputRange const &non_uniform_points)
Construct an Impl<Kokkos::HostSpace> and associated discrete_domain_type from a range containing the ...
static std::tuple< typename DDim::template Impl< DDim, Kokkos::HostSpace >, DiscreteDomain< DDim >, DiscreteDomain< DDim >, DiscreteDomain< DDim >, DiscreteDomain< DDim > > init_ghosted(InputRange const &domain_r, InputRange const &pre_ghost_r, InputRange const &post_ghost_r)
Construct 4 non-uniform DiscreteDomain and an Impl<Kokkos::HostSpace> from 3 ranges containing the po...
Impl & operator=(Impl &&x)=default
KOKKOS_FUNCTION Coordinate< CDim > origin() const noexcept
Lower bound index of the mesh.
KOKKOS_FUNCTION discrete_element_type front() const noexcept
Lower bound index of the mesh.
KOKKOS_FUNCTION Coordinate< CDim > coordinate(discrete_element_type const &icoord) const noexcept
Convert a mesh index into a position in CDim
Impl(Impl const &)=delete
KOKKOS_FUNCTION std::size_t n_period() const
Number of steps in a period.
Impl(Impl< DDim, OriginMemorySpace > const &impl)
Impl(Coordinate< CDim > origin, Real step, std::size_t n_period)
Construct a Impl from a point and a spacing step.
KOKKOS_FUNCTION Real step() const
Spacing step of the mesh.
Impl & operator=(Impl const &x)=delete
PeriodicSampling models a periodic discretization of the provided continuous dimension.
static std::tuple< typename DDim::template Impl< DDim, Kokkos::HostSpace >, DiscreteDomain< DDim > > init(Coordinate< CDim > a, Coordinate< CDim > b, DiscreteVector< DDim > n, DiscreteVector< DDim > n_period)
Construct a Impl<Kokkos::HostSpace> and associated discrete_domain_type from a segment and a number ...
std::tuple< Impl< DDim, Kokkos::HostSpace >, DiscreteDomain< DDim >, DiscreteDomain< DDim >, DiscreteDomain< DDim >, DiscreteDomain< DDim > > init_ghosted(Coordinate< CDim > a, Coordinate< CDim > b, DiscreteVector< DDim > n, DiscreteVector< DDim > n_period, DiscreteVector< DDim > n_ghosts_before, DiscreteVector< DDim > n_ghosts_after)
Construct a periodic DiscreteDomain from a segment and a number of points n.
std::tuple< Impl< DDim, Kokkos::HostSpace >, DiscreteDomain< DDim >, DiscreteDomain< DDim >, DiscreteDomain< DDim >, DiscreteDomain< DDim > > init_ghosted(Coordinate< CDim > a, Coordinate< CDim > b, DiscreteVector< DDim > n, DiscreteVector< DDim > n_period, DiscreteVector< DDim > n_ghosts)
Construct a periodic DiscreteDomain from a segment and a number of points n.
ScopeGuard & operator=(ScopeGuard const &x)=delete
~ScopeGuard() noexcept
ScopeGuard(ScopeGuard &&x) noexcept=delete
ScopeGuard & operator=(ScopeGuard &&x) noexcept=delete
ScopeGuard(int, char **&)
ScopeGuard(ScopeGuard const &x)=delete
static KOKKOS_FUNCTION bool contains(DiscreteElement<>) noexcept
KOKKOS_FUNCTION constexpr SparseDiscreteDomain remove(discrete_vector_type, discrete_vector_type) const
KOKKOS_FUNCTION constexpr SparseDiscreteDomain take_first(discrete_vector_type) const
static KOKKOS_FUNCTION constexpr std::size_t rank()
KOKKOS_DEFAULTED_FUNCTION constexpr SparseDiscreteDomain()=default
KOKKOS_FUNCTION constexpr DiscreteElement operator()(DiscreteVector<> const &) const noexcept
KOKKOS_FUNCTION constexpr SparseDiscreteDomain remove_last(discrete_vector_type) const
static KOKKOS_FUNCTION DiscreteVector distance_from_front() noexcept
static KOKKOS_FUNCTION constexpr std::size_t size()
static KOKKOS_FUNCTION constexpr bool empty() noexcept
static KOKKOS_FUNCTION DiscreteVector distance_from_front(DiscreteElement<>) noexcept
KOKKOS_FUNCTION constexpr bool operator==(SparseDiscreteDomain const &) const
static KOKKOS_FUNCTION constexpr discrete_element_type back() noexcept
static KOKKOS_FUNCTION bool contains() noexcept
KOKKOS_FUNCTION constexpr SparseDiscreteDomain take_last(discrete_vector_type) const
KOKKOS_FUNCTION constexpr operator bool()
KOKKOS_DEFAULTED_FUNCTION SparseDiscreteDomain & operator=(SparseDiscreteDomain const &x)=default
KOKKOS_DEFAULTED_FUNCTION SparseDiscreteDomain & operator=(SparseDiscreteDomain &&x)=default
KOKKOS_FUNCTION constexpr SparseDiscreteDomain remove_first(discrete_vector_type) const
KOKKOS_DEFAULTED_FUNCTION SparseDiscreteDomain(SparseDiscreteDomain const &x)=default
KOKKOS_DEFAULTED_FUNCTION ~SparseDiscreteDomain()=default
static KOKKOS_FUNCTION constexpr discrete_element_type front() noexcept
KOKKOS_FUNCTION constexpr SparseDiscreteDomain(SparseDiscreteDomain< ODDims... > const &)
static KOKKOS_FUNCTION constexpr discrete_vector_type extents() noexcept
KOKKOS_DEFAULTED_FUNCTION SparseDiscreteDomain(SparseDiscreteDomain &&x)=default
KOKKOS_FUNCTION constexpr discrete_element_type back() const noexcept
KOKKOS_FUNCTION constexpr SparseDiscreteDomain remove_first(discrete_vector_type n) const
static KOKKOS_FUNCTION constexpr std::size_t rank()
KOKKOS_FUNCTION constexpr decltype(auto) operator[](std::size_t n) const
KOKKOS_DEFAULTED_FUNCTION SparseDiscreteDomain & operator=(SparseDiscreteDomain const &x)=default
KOKKOS_FUNCTION constexpr SparseDiscreteDomain take_last(discrete_vector_type n) const
KOKKOS_FUNCTION DiscreteVector< DDims... > distance_from_front(DElems const &... delems) const noexcept
KOKKOS_FUNCTION constexpr auto discrete_elements() const noexcept
KOKKOS_FUNCTION constexpr SparseDiscreteDomain remove(discrete_vector_type n1, discrete_vector_type n2) const
KOKKOS_FUNCTION constexpr SparseDiscreteDomain(DDoms const &... domains)
Construct a SparseDiscreteDomain by copies and merge of domains.
SparseDiscreteDomain(Kokkos::View< DiscreteElement< DDims > *, Kokkos::SharedSpace > const &... views)
Construct a SparseDiscreteDomain with Kokkos::View explicitly listing the discrete elements.
KOKKOS_FUNCTION auto cbegin() const
KOKKOS_FUNCTION constexpr decltype(auto) operator[](std::size_t n)
KOKKOS_DEFAULTED_FUNCTION SparseDiscreteDomain & operator=(SparseDiscreteDomain &&x)=default
KOKKOS_FUNCTION constexpr std::size_t size() const
KOKKOS_FUNCTION constexpr bool operator==(SparseDiscreteDomain< ODims... > const &other) const
KOKKOS_FUNCTION bool contains(DElems const &... delems) const noexcept
KOKKOS_FUNCTION constexpr SparseDiscreteDomain take_first(discrete_vector_type n) const
KOKKOS_DEFAULTED_FUNCTION SparseDiscreteDomain()=default
KOKKOS_DEFAULTED_FUNCTION SparseDiscreteDomain(SparseDiscreteDomain &&x)=default
KOKKOS_FUNCTION constexpr discrete_element_type front() const noexcept
KOKKOS_FUNCTION constexpr operator bool()
KOKKOS_FUNCTION constexpr bool empty() const noexcept
KOKKOS_FUNCTION constexpr DiscreteElement< DDims... > operator()(DiscreteVector< DDims... > const &dvect) const noexcept
KOKKOS_DEFAULTED_FUNCTION SparseDiscreteDomain(SparseDiscreteDomain const &x)=default
KOKKOS_FUNCTION constexpr SparseDiscreteDomain remove_last(discrete_vector_type n) const
KOKKOS_FUNCTION auto end() const
KOKKOS_FUNCTION auto cend() const
KOKKOS_FUNCTION auto begin() const
KOKKOS_FUNCTION constexpr discrete_vector_type extents() const noexcept
KOKKOS_FUNCTION constexpr DiscreteVector< QueryDDim > extent() const noexcept
KOKKOS_DEFAULTED_FUNCTION ~SparseDiscreteDomain()=default
The top-level namespace of DDC.
KOKKOS_FUNCTION std::enable_if_t< is_periodic_sampling_v< DDim >, Real > step() noexcept
Spacing step of the mesh.
KOKKOS_FUNCTION std::enable_if_t< is_periodic_sampling_v< DDim >, Coordinate< typename DDim::continuous_dimension_type > > origin() noexcept
Lower bound index of the mesh.
constexpr bool is_non_uniform_point_sampling_v
KOKKOS_FUNCTION Coordinate< typename DDim::continuous_dimension_type > rmax(DiscreteDomain< DDim > const &d)
KOKKOS_FUNCTION constexpr DiscreteElement< QueryDDims... > back(SparseDiscreteDomain< DDims... > const &domain) noexcept
bool is_discrete_space_initialized() noexcept
KOKKOS_FUNCTION constexpr SparseDiscreteDomain< QueryDDims... > select(SparseDiscreteDomain< DDims... > const &domain)
void init_discrete_space(Args &&... args)
Initialize (emplace) a global singleton discrete space.
KOKKOS_FUNCTION constexpr auto remove_dims_of(SparseDiscreteDomain< DDimsA... > const &DDom_a, SparseDiscreteDomain< DDimsB... > const &) noexcept
detail::ddim_impl_t< DDim, Kokkos::HostSpace > const & host_discrete_space()
KOKKOS_FUNCTION constexpr DiscreteVector< QueryDDims... > extents(SparseDiscreteDomain< DDims... > const &domain) noexcept
KOKKOS_FUNCTION constexpr auto replace_dim_of(SparseDiscreteDomain< DDimsA... > const &DDom_a, SparseDiscreteDomain< DDimsB... > const &DDom_b) noexcept
KOKKOS_FUNCTION constexpr DiscreteElement< QueryDDims... > front(SparseDiscreteDomain< DDims... > const &domain) noexcept
KOKKOS_FUNCTION Coordinate< typename DDim::continuous_dimension_type > rlength(DiscreteDomain< DDim > const &d)
KOKKOS_FUNCTION Coordinate< typename DDim::continuous_dimension_type > distance_at_left(DiscreteElement< DDim > i)
KOKKOS_FUNCTION Coordinate< typename DDim::continuous_dimension_type > rmin(DiscreteDomain< DDim > const &d)
constexpr bool is_periodic_sampling_v
KOKKOS_FUNCTION Coordinate< typename DDim::continuous_dimension_type > coordinate(DiscreteElement< DDim > const &c)
KOKKOS_FUNCTION std::enable_if_t< is_periodic_sampling_v< DDim >, DiscreteElement< DDim > > front() noexcept
Lower bound index of the mesh.
constexpr bool is_sparse_discrete_domain_v
KOKKOS_FUNCTION constexpr auto remove_dims_of(SparseDiscreteDomain< DDimsA... > const &DDom_a) noexcept
Remove the dimensions DDimsB from DDom_a.
KOKKOS_FUNCTION detail::ddim_impl_t< DDim, MemorySpace > const & discrete_space()
Arg0 init_discrete_space(std::tuple< DDimImpl, Arg0 > &&a)
Move construct a global singleton discrete space and pass through the other argument.
KOKKOS_FUNCTION Coordinate< typename DDim::continuous_dimension_type > distance_at_right(DiscreteElement< DDim > i)
std::tuple< Arg0, Arg1, Args... > init_discrete_space(std::tuple< DDimImpl, Arg0, Arg1, Args... > &&a)
Move construct a global singleton discrete space and pass through remaining arguments.