libMesh
Public Member Functions | Private Member Functions | List of all members
TypeTensorTest Class Reference
Inheritance diagram for TypeTensorTest:
[legend]

Public Member Functions

void setUp ()
 
void tearDown ()
 
 LIBMESH_CPPUNIT_TEST_SUITE (TypeTensorTest)
 
 CPPUNIT_TEST (testInverse)
 
 CPPUNIT_TEST (testLeftMultiply)
 
 CPPUNIT_TEST (testRotation)
 
 CPPUNIT_TEST (testRowCol)
 
 CPPUNIT_TEST (testIsZero)
 
 CPPUNIT_TEST (testReplaceAlgebraicType)
 
 CPPUNIT_TEST_SUITE_END ()
 

Private Member Functions

void testInverse ()
 
void testLeftMultiply ()
 
void testOuterProduct ()
 
void testIsZero ()
 
void testRotation ()
 
void testRowCol ()
 
void testReplaceAlgebraicType ()
 

Detailed Description

Definition at line 11 of file type_tensor_test.C.

Member Function Documentation

◆ CPPUNIT_TEST() [1/6]

TypeTensorTest::CPPUNIT_TEST ( testInverse  )

◆ CPPUNIT_TEST() [2/6]

TypeTensorTest::CPPUNIT_TEST ( testLeftMultiply  )

◆ CPPUNIT_TEST() [3/6]

TypeTensorTest::CPPUNIT_TEST ( testRotation  )

◆ CPPUNIT_TEST() [4/6]

TypeTensorTest::CPPUNIT_TEST ( testRowCol  )

◆ CPPUNIT_TEST() [5/6]

TypeTensorTest::CPPUNIT_TEST ( testIsZero  )

◆ CPPUNIT_TEST() [6/6]

TypeTensorTest::CPPUNIT_TEST ( testReplaceAlgebraicType  )

◆ CPPUNIT_TEST_SUITE_END()

TypeTensorTest::CPPUNIT_TEST_SUITE_END ( )

◆ LIBMESH_CPPUNIT_TEST_SUITE()

TypeTensorTest::LIBMESH_CPPUNIT_TEST_SUITE ( TypeTensorTest  )

◆ setUp()

void TypeTensorTest::setUp ( )
inline

Definition at line 14 of file type_tensor_test.C.

14 {}

◆ tearDown()

void TypeTensorTest::tearDown ( )
inline

Definition at line 16 of file type_tensor_test.C.

16 {}

◆ testInverse()

void TypeTensorTest::testInverse ( )
inlineprivate

Definition at line 34 of file type_tensor_test.C.

References libMesh::TypeTensor< T >::inverse().

35  {
36  LOG_UNIT_TEST;
37 
38  // This random input tensor and its inverse came from Octave/Matlab:
39  // > format long e
40  // > A = rand(3)
41  // > inv(A)
42 
43  // The base class, TypeTensor, has a protected constructor. We
44  // are using the derived class, TensorValue, for our tests...
45  TensorValue<double> tensor(9.08973348886179e-01, 3.36455579239923e-01, 5.16389236893863e-01,
46  9.44156071777472e-01, 1.35610910092516e-01, 1.49881119060538e-02,
47  1.15988384086146e-01, 6.79845197685518e-03, 3.77028969454745e-01);
48 
49  TensorValue<double> inverse = tensor.inverse();
50 
51  TensorValue<double> true_inverse(-6.57484735104482e-01, 1.58926633961497e+00, 8.37330721137561e-01,
52  4.56430940967411e+00, -3.64404559823061e+00, -6.10654107858520e+00,
53  1.19965194510943e-01, -4.23210359257434e-01, 2.50483242797707e+00);
54 
55  for (unsigned i=0; i<3; ++i)
56  for (unsigned j=0; j<3; ++j)
57  LIBMESH_ASSERT_FP_EQUAL(inverse(i,j), true_inverse(i,j), 1e-12);
58  }
TypeTensor< T > inverse() const
Definition: type_tensor.h:1080
This class defines a tensor in LIBMESH_DIM dimensional Real or Complex space.

◆ testIsZero()

void TypeTensorTest::testIsZero ( )
inlineprivate

Definition at line 93 of file type_tensor_test.C.

References libMesh::TypeTensor< T >::is_zero().

94  {
95  LOG_UNIT_TEST;
96 
97  {
98  TensorValue<double> tensor;
99  CPPUNIT_ASSERT(tensor.is_zero());
100  }
101  {
102  TensorValue<double> tensor(0,1,2,3,4,5,6,7,8);
103  CPPUNIT_ASSERT(!tensor.is_zero());
104  }
105  }
bool is_zero() const
Definition: type_tensor.h:1288
This class defines a tensor in LIBMESH_DIM dimensional Real or Complex space.

◆ testLeftMultiply()

void TypeTensorTest::testLeftMultiply ( )
inlineprivate

Definition at line 60 of file type_tensor_test.C.

61  {
62  LOG_UNIT_TEST;
63 
64  TensorValue<Real> tensor(1, 2, 0, 3, 4, 0);
65  VectorValue<Real> vector(5, 6, 0);
66  auto left_mult = vector * tensor;
67  auto right_mult = tensor * vector;
68  LIBMESH_ASSERT_FP_EQUAL(23, left_mult(0), 1e-12);
69  LIBMESH_ASSERT_FP_EQUAL(34, left_mult(1), 1e-12);
70  LIBMESH_ASSERT_FP_EQUAL(17, right_mult(0), 1e-12);
71  LIBMESH_ASSERT_FP_EQUAL(39, right_mult(1), 1e-12);
72  }
This class defines a tensor in LIBMESH_DIM dimensional Real or Complex space.

◆ testOuterProduct()

void TypeTensorTest::testOuterProduct ( )
inlineprivate

Definition at line 74 of file type_tensor_test.C.

References libMesh::outer_product(), and libMesh::TOLERANCE.

75  {
76  LOG_UNIT_TEST;
77 
78  auto tol = TOLERANCE * TOLERANCE;
79  VectorValue<Real> a(2, 3, 4);
80  VectorValue<Real> b(5, 6, 7);
81  auto product = outer_product(a, b);
82  LIBMESH_ASSERT_FP_EQUAL(10, product(0, 0), tol);
83  LIBMESH_ASSERT_FP_EQUAL(12, product(0, 1), tol);
84  LIBMESH_ASSERT_FP_EQUAL(14, product(0, 2), tol);
85  LIBMESH_ASSERT_FP_EQUAL(15, product(1, 0), tol);
86  LIBMESH_ASSERT_FP_EQUAL(18, product(1, 1), tol);
87  LIBMESH_ASSERT_FP_EQUAL(21, product(1, 2), tol);
88  LIBMESH_ASSERT_FP_EQUAL(20, product(2, 0), tol);
89  LIBMESH_ASSERT_FP_EQUAL(24, product(2, 1), tol);
90  LIBMESH_ASSERT_FP_EQUAL(28, product(2, 2), tol);
91  }
TypeTensor< typename CompareTypes< T, T2 >::supertype > outer_product(const TypeVector< T > &a, const TypeVector< T2 > &b)
Definition: type_tensor.h:1393
static constexpr Real TOLERANCE

◆ testReplaceAlgebraicType()

void TypeTensorTest::testReplaceAlgebraicType ( )
inlineprivate

Definition at line 168 of file type_tensor_test.C.

References value.

169  {
170  typedef typename MetaPhysicL::ReplaceAlgebraicType<
171  std::vector<TypeTensor<double>>,
173  typename MetaPhysicL::ValueType<std::vector<TypeTensor<double>>>::type>::type>::type
174  ReplacedType;
175  constexpr bool assertion =
176  std::is_same<ReplacedType, std::vector<TypeNTensor<3,double>>>::value;
177  CPPUNIT_ASSERT(assertion);
178  }
static const bool value
Definition: xdr_io.C:54

◆ testRotation()

void TypeTensorTest::testRotation ( )
inlineprivate

Definition at line 107 of file type_tensor_test.C.

References libMesh::TensorValue< T >::extrinsic_rotation_matrix(), libMesh::TensorValue< T >::inverse_extrinsic_rotation_matrix(), and libMesh::TOLERANCE.

108  {
109  LOG_UNIT_TEST;
110 
111  {
112  Point x(1, 0, 0);
113  const auto R = RealTensorValue::extrinsic_rotation_matrix(90, 0, 0);
114  auto rotated = R * x;
115  constexpr auto tol = TOLERANCE * TOLERANCE;
116  LIBMESH_ASSERT_FP_EQUAL(0, rotated(0), tol);
117  LIBMESH_ASSERT_FP_EQUAL(1, rotated(1), tol);
118  LIBMESH_ASSERT_FP_EQUAL(0, rotated(2), tol);
119 
120  const auto invR = RealTensorValue::inverse_extrinsic_rotation_matrix(90, 0, 0);
121  rotated = invR * rotated;
122  LIBMESH_ASSERT_FP_EQUAL(1, rotated(0), tol);
123  LIBMESH_ASSERT_FP_EQUAL(0, rotated(1), tol);
124  LIBMESH_ASSERT_FP_EQUAL(0, rotated(2), tol);
125  }
126 
127  {
128  Point x(1, 1, 1);
129  const auto R = RealTensorValue::extrinsic_rotation_matrix(90, 90, 90);
130  auto rotated = R * x;
131 
132  constexpr auto tol = TOLERANCE * TOLERANCE;
133  LIBMESH_ASSERT_FP_EQUAL(1, rotated(0), tol);
134  LIBMESH_ASSERT_FP_EQUAL(-1, rotated(1), tol);
135  LIBMESH_ASSERT_FP_EQUAL(1, rotated(2), tol);
136 
137  const auto invR = RealTensorValue::inverse_extrinsic_rotation_matrix(90, 90, 90);
138  rotated = invR * rotated;
139  LIBMESH_ASSERT_FP_EQUAL(1, rotated(0), tol);
140  LIBMESH_ASSERT_FP_EQUAL(1, rotated(1), tol);
141  LIBMESH_ASSERT_FP_EQUAL(1, rotated(2), tol);
142  }
143  }
static constexpr Real TOLERANCE
A Point defines a location in LIBMESH_DIM dimensional Real space.
Definition: point.h:39

◆ testRowCol()

void TypeTensorTest::testRowCol ( )
inlineprivate

Definition at line 145 of file type_tensor_test.C.

References libMesh::TypeTensor< T >::column(), libMesh::Real, libMesh::TypeTensor< T >::row(), and libMesh::TOLERANCE.

146  {
147  LOG_UNIT_TEST;
148 
150  for (unsigned int i = 0; i < LIBMESH_DIM; i++)
151  for (unsigned int j = 0; j < LIBMESH_DIM; j++)
152  t(i, j) = Real(i * LIBMESH_DIM + j);
153 
154  constexpr Real tol = TOLERANCE * TOLERANCE;
155  for (unsigned int k = 0; k < LIBMESH_DIM; k++)
156  {
157  const auto row = t.row(k);
158  for (unsigned int l = 0; l < LIBMESH_DIM; l++)
159  LIBMESH_ASSERT_FP_EQUAL(Real(k * LIBMESH_DIM + l), row(l), tol);
160 
161  const auto col = t.column(k);
162  for (unsigned int l = 0; l < LIBMESH_DIM; l++)
163  LIBMESH_ASSERT_FP_EQUAL(Real(l * LIBMESH_DIM + k), col(l), tol);
164  }
165  }
static constexpr Real TOLERANCE
TypeVector< T > row(const unsigned int r) const
Definition: type_tensor.h:765
TypeVector< T > column(const unsigned int r) const
Definition: type_tensor.h:779
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
This class defines a tensor in LIBMESH_DIM dimensional Real or Complex space.

The documentation for this class was generated from the following file: