Line data Source code
1 0 : // Distributed under the MIT License.
2 : // See LICENSE.txt for details.
3 :
4 : #pragma once
5 :
6 : #include "DataStructures/Tensor/Tensor.hpp"
7 : #include "Utilities/Gsl.hpp"
8 : #include "Utilities/Kokkos/KokkosMacros.hpp"
9 : #include "Utilities/MakeWithValue.hpp"
10 :
11 : /// @{
12 : /*!
13 : * \ingroup GeneralRelativityGroup
14 : * \brief Computes trace of a rank 3 tensor, which is symmetric in its last two
15 : * indices, tracing the symmetric indices.
16 : *
17 : * \details For example, if \f$ T_{abc} \f$ is a tensor such that \f$T_{abc} =
18 : * T_{acb} \f$ then \f$ T_a = g^{bc}T_{abc} \f$ is computed, where \f$ g^{bc}
19 : * \f$ is the inverse metric. Note that indices \f$a,b,c,...\f$ can represent
20 : * either spatial or spacetime indices, and can have either valence. You may
21 : * have to add a new instantiation of this template if you need a new use case.
22 : *
23 : * These functions can be called in Kokkos kernels with `double`s.
24 : */
25 : template <typename DataType, typename Index0, typename Index1>
26 1 : KOKKOS_FUNCTION void trace_last_indices(
27 : gsl::not_null<Tensor<DataType, Symmetry<1>, index_list<Index0>>*>
28 : trace_of_tensor,
29 : const Tensor<DataType, Symmetry<2, 1, 1>,
30 : index_list<Index0, Index1, Index1>>& tensor,
31 : const Tensor<DataType, Symmetry<1, 1>,
32 : index_list<change_index_up_lo<Index1>,
33 : change_index_up_lo<Index1>>>& metric);
34 :
35 : SPECTRE_KOKKOS_DISABLE_EXEC_CHECK
36 : template <typename DataType, typename Index0, typename Index1>
37 : KOKKOS_FUNCTION Tensor<DataType, Symmetry<1>, index_list<Index0>>
38 1 : trace_last_indices(
39 : const Tensor<DataType, Symmetry<2, 1, 1>,
40 : index_list<Index0, Index1, Index1>>& tensor,
41 : const Tensor<DataType, Symmetry<1, 1>,
42 : index_list<change_index_up_lo<Index1>,
43 : change_index_up_lo<Index1>>>& metric) {
44 : Tensor<DataType, Symmetry<1>, index_list<Index0>> trace_of_tensor{};
45 : trace_last_indices(make_not_null(&trace_of_tensor), tensor, metric);
46 : return trace_of_tensor;
47 : }
48 : /// @}
49 :
50 : /// @{
51 : /*!
52 : * \ingroup GeneralRelativityGroup
53 : * \brief Computes trace of a rank-2 symmetric tensor.
54 : * \details Computes \f$g^{ab}T_{ab}\f$ or \f$g_{ab}T^{ab}\f$ where \f$(a,b)\f$
55 : * can be spatial or spacetime indices.
56 : *
57 : * These functions can be called in Kokkos kernels with `double`s.
58 : */
59 : template <typename DataType, typename Index0>
60 1 : KOKKOS_FUNCTION void trace(
61 : gsl::not_null<Scalar<DataType>*> trace,
62 : const Tensor<DataType, Symmetry<1, 1>, index_list<Index0, Index0>>& tensor,
63 : const Tensor<DataType, Symmetry<1, 1>,
64 : index_list<change_index_up_lo<Index0>,
65 : change_index_up_lo<Index0>>>& metric);
66 :
67 : SPECTRE_KOKKOS_DISABLE_EXEC_CHECK
68 : template <typename DataType, typename Index0>
69 1 : KOKKOS_FUNCTION Scalar<DataType> trace(
70 : const Tensor<DataType, Symmetry<1, 1>, index_list<Index0, Index0>>& tensor,
71 : const Tensor<DataType, Symmetry<1, 1>,
72 : index_list<change_index_up_lo<Index0>,
73 : change_index_up_lo<Index0>>>& metric) {
74 : Scalar<DataType> trace{};
75 : ::trace(make_not_null(&trace), tensor, metric);
76 : return trace;
77 : }
78 : /// @}
|