SimiLie
Loading...
Searching...
No Matches
lorentzian_sign_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 "tensor_impl.hpp"
9
10namespace sil {
11
12namespace tensor {
13
14// struct representing an identity tensor (no storage).
15template <class Q, TensorNatIndex... TensorIndex>
17{
18 static constexpr bool is_tensor_index = true;
19 static constexpr bool is_explicitely_stored_tensor = true;
20
21 using subindices_domain_t = ddc::DiscreteDomain<TensorIndex...>;
22
23 KOKKOS_FUNCTION static constexpr subindices_domain_t subindices_domain()
24 {
25 return ddc::DiscreteDomain<TensorIndex...>(
26 ddc::DiscreteElement<TensorIndex...>(ddc::DiscreteElement<TensorIndex>(0)...),
27 ddc::DiscreteVector<TensorIndex...>(
28 ddc::DiscreteVector<TensorIndex>(TensorIndex::size())...));
29 }
30
31 KOKKOS_FUNCTION static constexpr std::size_t rank()
32 {
33 return (TensorIndex::rank() + ...);
34 }
35
36 KOKKOS_FUNCTION static constexpr std::size_t size()
37 {
38 return (TensorIndex::size() * ...);
39 }
40
41 KOKKOS_FUNCTION static constexpr std::size_t mem_size()
42 {
43 return 0;
44 }
45
46 KOKKOS_FUNCTION static constexpr std::size_t access_size()
47 {
48 return 3;
49 }
50
51 KOKKOS_FUNCTION static constexpr std::size_t mem_id(
52 std::array<std::size_t, sizeof...(TensorIndex)> const natural_ids)
53 {
54 return std::numeric_limits<std::size_t>::max();
55 }
56
57 KOKKOS_FUNCTION static constexpr std::size_t access_id(
58 std::array<std::size_t, sizeof...(TensorIndex)> const natural_ids)
59 {
60 if (!std::all_of(natural_ids.begin(), natural_ids.end(), [&](const std::size_t id) {
61 return id == *natural_ids.begin();
62 })) {
63 return 0;
64 } else {
65 if (natural_ids[0] < Q::value) {
66 return 1;
67 } else {
68 return 2;
69 }
70 }
71 }
72
73 KOKKOS_FUNCTION static constexpr std::size_t access_id_to_mem_id(
74 [[maybe_unused]] std::size_t access_id)
75 {
76 return std::numeric_limits<std::size_t>::max();
77 }
78
79 template <class Tensor, class Elem, class Id, class FunctorType>
80 KOKKOS_FUNCTION static constexpr Tensor::element_type process_access(
81 const FunctorType& access,
82 Tensor tensor,
83 Elem elem)
84 {
85 if (elem.template uid<Id>() == 0) {
86 return 0.;
87 } else if (elem.template uid<Id>() == 1) {
88 return -access(tensor, elem);
89 } else {
90 return access(tensor, elem);
91 }
92 }
93
94 KOKKOS_FUNCTION static constexpr std::array<std::size_t, rank()>
96 {
97 assert(false);
98 std::array<std::size_t, rank()> ids;
99 for (auto i = ids.begin(); i < ids.end(); ++i) {
100 *i = 0;
101 }
102 return ids;
103 }
104};
105
106} // namespace tensor
107
108} // namespace sil
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::array< std::size_t, rank()> mem_id_to_canonical_natural_ids(std::size_t mem_id)
static KOKKOS_FUNCTION constexpr std::size_t access_id(std::array< std::size_t, sizeof...(TensorIndex)> const natural_ids)
ddc::DiscreteDomain< TensorIndex... > subindices_domain_t
static KOKKOS_FUNCTION constexpr subindices_domain_t subindices_domain()
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 KOKKOS_FUNCTION constexpr std::size_t rank()
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 mem_size()
static KOKKOS_FUNCTION constexpr std::size_t access_id_to_mem_id(std::size_t access_id)
static KOKKOS_FUNCTION constexpr std::size_t access_size()