SimiLie
Loading...
Searching...
No Matches
levi_civita_tensor.hpp
1// SPDX-FileCopyrightText: 2024 Baptiste Legouix
2// SPDX-License-Identifier: MIT
3
4#pragma once
5
6#include <ddc/ddc.hpp>
7
8#include <similie/misc/permutation_parity.hpp>
9
10#include "tensor_impl.hpp"
11
12namespace sil {
13
14namespace tensor {
15
16// struct representing an identity tensor (no storage).
17template <TensorNatIndex... TensorIndex>
19{
20 static constexpr bool is_tensor_index = true;
21 static constexpr bool is_explicitely_stored_tensor = true;
22
23 using subindices_domain_t = ddc::DiscreteDomain<TensorIndex...>;
24
25 KOKKOS_FUNCTION static constexpr subindices_domain_t subindices_domain()
26 {
27 return ddc::DiscreteDomain<TensorIndex...>(
28 ddc::DiscreteElement<TensorIndex...>(ddc::DiscreteElement<TensorIndex>(0)...),
29 ddc::DiscreteVector<TensorIndex...>(
30 ddc::DiscreteVector<TensorIndex>(TensorIndex::size())...));
31 }
32
33 KOKKOS_FUNCTION static constexpr std::size_t rank()
34 {
35 return (TensorIndex::rank() + ...);
36 }
37
38 static_assert(((TensorIndex::size() == rank()) && ...));
39
40 KOKKOS_FUNCTION static constexpr std::size_t size()
41 {
42 return (TensorIndex::size() * ...);
43 }
44
45 KOKKOS_FUNCTION static constexpr std::size_t mem_size()
46 {
47 return 0;
48 }
49
50 KOKKOS_FUNCTION static constexpr std::size_t access_size()
51 {
52 return 3;
53 }
54
55 KOKKOS_FUNCTION static constexpr std::size_t mem_id(
56 std::array<std::size_t, sizeof...(TensorIndex)> const natural_ids)
57 {
58 return std::numeric_limits<std::size_t>::max();
59 }
60
61 KOKKOS_FUNCTION static constexpr std::size_t access_id(
62 std::array<std::size_t, sizeof...(TensorIndex)> const natural_ids)
63 {
64 if constexpr (rank() == 1) {
65 return 1;
66 } else {
67 int const parity = misc::permutation_parity(natural_ids);
68 if (parity == 0) {
69 return 0;
70 } else if (parity == 1) {
71 return 1;
72 } else {
73 return 2;
74 }
75 }
76 }
77
78 KOKKOS_FUNCTION static constexpr std::size_t access_id_to_mem_id(
79 [[maybe_unused]] std::size_t access_id)
80 {
81 return std::numeric_limits<std::size_t>::max();
82 }
83
84 template <class Tensor, class Elem, class Id, class FunctorType>
85 KOKKOS_FUNCTION static constexpr Tensor::element_type process_access(
86 const FunctorType& access,
87 Tensor tensor,
88 Elem elem)
89 {
90 if (elem.template uid<Id>() == 0) {
91 return 0;
92 } else if (elem.template uid<Id>() == 1) {
93 return access(tensor, elem);
94 } else {
95 return -access(tensor, elem);
96 }
97 }
98
99 KOKKOS_FUNCTION static constexpr std::array<std::size_t, rank()>
101 {
102 assert(false);
103 std::array<std::size_t, rank()> ids;
104 for (auto i = ids.begin(); i < ids.end(); ++i) {
105 *i = 0;
106 }
107 return ids;
108 }
109};
110
111} // namespace tensor
112
113} // namespace sil
constexpr int permutation_parity(std::array< std::size_t, N > lst)
Tensor(ddc::Chunk< ElementType, SupportType, Allocator >) -> Tensor< ElementType, SupportType, Kokkos::layout_right, typename Allocator::memory_space >
The top-level namespace of SimiLie.
Definition csr.hpp:14
static KOKKOS_FUNCTION constexpr std::size_t rank()
static KOKKOS_FUNCTION constexpr std::size_t access_id(std::array< std::size_t, sizeof...(TensorIndex)> const natural_ids)
static KOKKOS_FUNCTION constexpr subindices_domain_t subindices_domain()
static KOKKOS_FUNCTION constexpr std::size_t access_id_to_mem_id(std::size_t access_id)
static KOKKOS_FUNCTION constexpr std::size_t mem_id(std::array< std::size_t, sizeof...(TensorIndex)> const natural_ids)
static KOKKOS_FUNCTION constexpr std::size_t access_size()
static KOKKOS_FUNCTION constexpr Tensor::element_type process_access(const FunctorType &access, Tensor tensor, Elem elem)
static KOKKOS_FUNCTION constexpr std::size_t size()
static constexpr bool is_explicitely_stored_tensor
static KOKKOS_FUNCTION constexpr std::size_t mem_size()
ddc::DiscreteDomain< TensorIndex... > subindices_domain_t
static KOKKOS_FUNCTION constexpr std::array< std::size_t, rank()> mem_id_to_canonical_natural_ids(std::size_t mem_id)