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"
13 #include "Utilities/Gsl.hpp"
14 
15 namespace TestHelpers::TensorExpressions {
16 
17 /// \ingroup TestingFrameworkGroup
18 /// \brief Test that evaluating a right hand side tensor expression containing a
19 /// single rank 0 tensor correctly assigns the data to the evaluated left hand
20 /// side tensor
21 ///
22 /// \param data the data being stored in the Tensors
23 template <typename DataType>
24 void test_evaluate_rank_0(const DataType& data) noexcept {
25  const Tensor<DataType> R{{{data}}};
26 
27  // Use explicit type (vs auto) so the compiler checks the return type of
28  // `evaluate`
29  const Tensor<DataType> L_returned = ::TensorExpressions::evaluate(R());
30  Tensor<DataType> L_filled{};
32 
33  CHECK(L_returned.get() == data);
34  CHECK(L_filled.get() == data);
35 
36  // Test with TempTensor for LHS tensor
37  if constexpr (not std::is_same_v<DataType, double>) {
38  Variables<tmpl::list<::Tags::TempTensor<1, Tensor<DataType>>>> L_var{
39  data.size()};
40  Tensor<DataType>& L_temp =
41  get<::Tags::TempTensor<1, Tensor<DataType>>>(L_var);
43 
44  CHECK(L_temp.get() == data);
45  }
46 }
47 
48 } // namespace TestHelpers::TensorExpressions
TensorExpression.hpp
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:24
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
TensorExpressions::evaluate
void evaluate(const gsl::not_null< Tensor< X, LhsSymmetry, LhsIndexList > * > lhs_tensor, const RhsTE &rhs_tensorexpression)
Evaluate a RHS tensor expression to a tensor with the LHS index order set in the template parameters.
Definition: Evaluate.hpp:81
Evaluate.hpp