EvaluateRank0TestHelpers.hpp
1 // Distributed under the MIT License.
2 // See LICENSE.txt for details.
3 
4 #pragma once
5 
6 #include <type_traits>
7 
8 #include "DataStructures/Tags/TempTensor.hpp"
11 #include "Utilities/Gsl.hpp"
12 #include "Utilities/TMPL.hpp"
13 
14 namespace TestHelpers::TensorExpressions {
15 
16 /// \ingroup TestingFrameworkGroup
17 /// \brief Test that evaluating a right hand side tensor expression containing a
18 /// single rank 0 tensor correctly assigns the data to the evaluated left hand
19 /// side tensor
20 ///
21 /// \param data the data being stored in the Tensors
22 template <typename DataType>
23 void test_evaluate_rank_0(const DataType& data) noexcept {
24  const Tensor<DataType> R{{{data}}};
25 
26  // Use explicit type (vs auto) so the compiler checks the return type of
27  // `evaluate`
28  const Tensor<DataType> L_returned = ::TensorExpressions::evaluate(R());
29  Tensor<DataType> L_filled{};
31 
32  CHECK(L_returned.get() == data);
33  CHECK(L_filled.get() == data);
34 
35  // Test with TempTensor for LHS tensor
36  if constexpr (not std::is_same_v<DataType, double>) {
37  Variables<tmpl::list<::Tags::TempTensor<1, Tensor<DataType>>>> L_var{
38  data.size()};
39  Tensor<DataType>& L_temp =
40  get<::Tags::TempTensor<1, Tensor<DataType>>>(L_var);
42 
43  CHECK(L_temp.get() == data);
44  }
45 }
46 
47 } // namespace TestHelpers::TensorExpressions
TensorExpressions::evaluate
void evaluate(const gsl::not_null< Tensor< X, LhsSymmetry, LhsIndexList > * > lhs_tensor, const TensorExpression< Derived, X, RhsSymmetry, RhsIndexList, tmpl::list< RhsTensorIndices... >> &rhs_tensorexpression)
Evaluate a RHS tensor expression to a tensor with the LHS index order set in the template parameters.
Definition: Evaluate.hpp:153
Variables.hpp
Gsl.hpp
Tensor.hpp
TestHelpers::TensorExpressions::test_evaluate_rank_0
void test_evaluate_rank_0(const DataType &data) noexcept
Test that evaluating a right hand side tensor expression containing a single rank 0 tensor correctly ...
Definition: EvaluateRank0TestHelpers.hpp:23
make_not_null
gsl::not_null< T * > make_not_null(T *ptr) noexcept
Construct a not_null from a pointer. Often this will be done as an implicit conversion,...
Definition: Gsl.hpp:880
type_traits
TMPL.hpp