SpECTRE Documentation Coverage Report
Current view: top level - DataStructures/Tensor/EagerMath - Trace.hpp Hit Total Coverage
Commit: 1f2210958b4f38fdc0400907ee7c6d5af5111418 Lines: 4 5 80.0 %
Date: 2025-12-05 05:03:31
Legend: Lines: hit not hit

          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/MakeWithValue.hpp"
       9             : 
      10             : /// @{
      11             : /*!
      12             :  * \ingroup GeneralRelativityGroup
      13             :  * \brief Computes trace of a rank 3 tensor, which is symmetric in its last two
      14             :  * indices, tracing the symmetric indices.
      15             :  *
      16             :  * \details For example, if \f$ T_{abc} \f$ is a tensor such that \f$T_{abc} =
      17             :  * T_{acb} \f$ then \f$ T_a = g^{bc}T_{abc} \f$ is computed, where \f$ g^{bc}
      18             :  * \f$ is the inverse metric.  Note that indices \f$a,b,c,...\f$ can represent
      19             :  * either spatial or spacetime indices, and can have either valence.  You may
      20             :  * have to add a new instantiation of this template if you need a new use case.
      21             :  */
      22             : template <typename DataType, typename Index0, typename Index1>
      23           1 : void trace_last_indices(
      24             :     gsl::not_null<Tensor<DataType, Symmetry<1>, index_list<Index0>>*>
      25             :         trace_of_tensor,
      26             :     const Tensor<DataType, Symmetry<2, 1, 1>,
      27             :                  index_list<Index0, Index1, Index1>>& tensor,
      28             :     const Tensor<DataType, Symmetry<1, 1>,
      29             :                  index_list<change_index_up_lo<Index1>,
      30             :                             change_index_up_lo<Index1>>>& metric);
      31             : 
      32             : template <typename DataType, typename Index0, typename Index1>
      33           1 : Tensor<DataType, Symmetry<1>, index_list<Index0>> trace_last_indices(
      34             :     const Tensor<DataType, Symmetry<2, 1, 1>,
      35             :                  index_list<Index0, Index1, Index1>>& tensor,
      36             :     const Tensor<DataType, Symmetry<1, 1>,
      37             :                  index_list<change_index_up_lo<Index1>,
      38             :                             change_index_up_lo<Index1>>>& metric) {
      39             :   auto trace_of_tensor =
      40             :       make_with_value<Tensor<DataType, Symmetry<1>, index_list<Index0>>>(metric,
      41             :                                                                          0.);
      42             :   trace_last_indices(make_not_null(&trace_of_tensor), tensor, metric);
      43             :   return trace_of_tensor;
      44             : }
      45             : /// @}
      46             : 
      47             : /// @{
      48             : /*!
      49             :  * \ingroup GeneralRelativityGroup
      50             :  * \brief Computes trace of a rank-2 symmetric tensor.
      51             :  * \details Computes \f$g^{ab}T_{ab}\f$ or \f$g_{ab}T^{ab}\f$ where \f$(a,b)\f$
      52             :  * can be spatial or spacetime indices.
      53             :  */
      54             : template <typename DataType, typename Index0>
      55           1 : void trace(
      56             :     gsl::not_null<Scalar<DataType>*> trace,
      57             :     const Tensor<DataType, Symmetry<1, 1>, index_list<Index0, Index0>>& tensor,
      58             :     const Tensor<DataType, Symmetry<1, 1>,
      59             :                  index_list<change_index_up_lo<Index0>,
      60             :                             change_index_up_lo<Index0>>>& metric);
      61             : 
      62             : template <typename DataType, typename Index0>
      63           1 : Scalar<DataType> trace(
      64             :     const Tensor<DataType, Symmetry<1, 1>, index_list<Index0, Index0>>& tensor,
      65             :     const Tensor<DataType, Symmetry<1, 1>,
      66             :                  index_list<change_index_up_lo<Index0>,
      67             :                             change_index_up_lo<Index0>>>& metric) {
      68             :   Scalar<DataType> trace{};
      69             :   ::trace(make_not_null(&trace), tensor, metric);
      70             :   return trace;
      71             : }
      72             : /// @}

Generated by: LCOV version 1.14