libMesh
type_tensor_test.C
Go to the documentation of this file.
1 // Ignore unused parameter warnings coming from cppunit headers
2 #include <libmesh/ignore_warnings.h>
3 #include <cppunit/extensions/HelperMacros.h>
4 #include <cppunit/TestCase.h>
5 #include <libmesh/restore_warnings.h>
6 
7 // libmesh includes
8 #include <libmesh/tensor_value.h>
9 
10 // THE CPPUNIT_TEST_SUITE_END macro expands to code that involves
11 // std::auto_ptr, which in turn produces -Wdeprecated-declarations
12 // warnings. These can be ignored in GCC as long as we wrap the
13 // offending code in appropriate pragmas. We can't get away with a
14 // single ignore_warnings.h inclusion at the beginning of this file,
15 // since the libmesh headers pull in a restore_warnings.h at some
16 // point. We also don't bother restoring warnings at the end of this
17 // file since it's not a header.
18 #include <libmesh/ignore_warnings.h>
19 
20 using namespace libMesh;
21 
22 class TypeTensorTest : public CppUnit::TestCase
23 {
24 public:
25  void setUp() {}
26 
27  void tearDown() {}
28 
29  CPPUNIT_TEST_SUITE(TypeTensorTest);
30 
31  CPPUNIT_TEST(testInverse);
32 
33  CPPUNIT_TEST_SUITE_END();
34 
35 
36 private:
37  void testInverse()
38  {
39  // This random input tensor and its inverse came from Octave/Matlab:
40  // > format long e
41  // > A = rand(3)
42  // > inv(A)
43 
44  // The base class, TypeTensor, has a protected constructor. We
45  // are using the derived class, TensorValue, for our tests...
46  TensorValue<double> tensor(9.08973348886179e-01, 3.36455579239923e-01, 5.16389236893863e-01,
47  9.44156071777472e-01, 1.35610910092516e-01, 1.49881119060538e-02,
48  1.15988384086146e-01, 6.79845197685518e-03, 3.77028969454745e-01);
49 
50  TensorValue<double> inverse = tensor.inverse();
51 
52  TensorValue<double> true_inverse(-6.57484735104482e-01, 1.58926633961497e+00, 8.37330721137561e-01,
53  4.56430940967411e+00, -3.64404559823061e+00, -6.10654107858520e+00,
54  1.19965194510943e-01, -4.23210359257434e-01, 2.50483242797707e+00);
55 
56  for (unsigned i=0; i<3; ++i)
57  for (unsigned j=0; j<3; ++j)
58  CPPUNIT_ASSERT_DOUBLES_EQUAL(inverse(i,j), true_inverse(i,j), 1.e-12);
59  }
60 
61 };
62 
The libMesh namespace provides an interface to certain functionality in the library.
CPPUNIT_TEST_SUITE_REGISTRATION(TypeTensorTest)
TypeTensor< T > inverse() const
Definition: type_tensor.h:1022
This class defines a tensor in LIBMESH_DIM dimensional Real or Complex space.