libMesh
Loading...
Searching...
No Matches
Public Member Functions | List of all members
PackingTypesTest Class Reference
Inheritance diagram for PackingTypesTest:
[legend]

Public Member Functions

 LIBMESH_CPPUNIT_TEST_SUITE (PackingTypesTest)
 
 CPPUNIT_TEST (testDynamicEigenMatrix)
 
 CPPUNIT_TEST (testDynamicEigenVector)
 
 CPPUNIT_TEST (testNonFixedScalar)
 
 CPPUNIT_TEST_SUITE_END ()
 
void setUp ()
 
void tearDown ()
 
void testDynamicEigenMatrix ()
 
void testDynamicEigenVector ()
 
void testNonFixedScalar ()
 

Detailed Description

Definition at line 16 of file packing_types_test.C.

Member Function Documentation

◆ CPPUNIT_TEST() [1/3]

PackingTypesTest::CPPUNIT_TEST ( testDynamicEigenMatrix  )

◆ CPPUNIT_TEST() [2/3]

PackingTypesTest::CPPUNIT_TEST ( testDynamicEigenVector  )

◆ CPPUNIT_TEST() [3/3]

PackingTypesTest::CPPUNIT_TEST ( testNonFixedScalar  )

◆ CPPUNIT_TEST_SUITE_END()

PackingTypesTest::CPPUNIT_TEST_SUITE_END ( )

◆ LIBMESH_CPPUNIT_TEST_SUITE()

PackingTypesTest::LIBMESH_CPPUNIT_TEST_SUITE ( PackingTypesTest  )

◆ setUp()

void PackingTypesTest::setUp ( )
inline

Definition at line 29 of file packing_types_test.C.

30 {}

◆ tearDown()

void PackingTypesTest::tearDown ( )
inline

Definition at line 32 of file packing_types_test.C.

33 {}

◆ testDynamicEigenMatrix()

void PackingTypesTest::testDynamicEigenMatrix ( )
inline

Definition at line 37 of file packing_types_test.C.

38 {
39 LOG_UNIT_TEST;
40
41 typedef Eigen::Matrix<Real, Eigen::Dynamic, Eigen::Dynamic> DynamicEigenMatrix;
42 typedef std::vector<DynamicEigenMatrix> DynamicMatrixVector;
43 std::map<processor_id_type, DynamicMatrixVector> send_data;
44
45 // prepare unique data
46 for (const auto i : index_range(*TestCommWorld))
47 {
48 const auto j = TestCommWorld->rank();
49 send_data[i] = DynamicMatrixVector{ DynamicEigenMatrix(i+1, i+2) };
50 for (const auto row: make_range(i+1))
51 for (const auto col: make_range(i+2))
52 send_data[i][0](row, col) = row * 100000.0 + col * 1000.0 + 10.0 * i + j;
53 }
54
55 // verification
56 auto verify_data =
57 [](processor_id_type j, const DynamicMatrixVector & recv_data)
58 {
59 const auto i = TestCommWorld->rank();
60 const std::size_t rows = recv_data[0].rows();
61 const std::size_t cols = recv_data[0].cols();
62
63 CPPUNIT_ASSERT_EQUAL( rows, static_cast<std::size_t>(i+1) );
64 CPPUNIT_ASSERT_EQUAL( cols, static_cast<std::size_t>(i+2) );
65
66 for (const auto row: make_range(rows))
67 for (const auto col: make_range(cols))
68 CPPUNIT_ASSERT_EQUAL( recv_data[0](row, col), static_cast<Real>(row * 100000.0 + col * 1000.0 + j + 10.0 * i) );
69 };
70
71 // communicate
72 Parallel::push_parallel_vector_data(*TestCommWorld, send_data, verify_data);
73 }
Communicator * TestCommWorld
auto index_range(const T &sizable)
Helper function that returns an IntRange<std::size_t> representing all the indices of the passed-in v...
Definition int_range.h:153
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
uint8_t processor_id_type
Definition id_types.h:104
IntRange< T > make_range(T beg, T end)
The 2-parameter make_range() helper function returns an IntRange<T> when both input parameters are of...
Definition int_range.h:176

References libMesh::index_range(), libMesh::make_range(), libMesh::Real, and TestCommWorld.

◆ testDynamicEigenVector()

void PackingTypesTest::testDynamicEigenVector ( )
inline

Definition at line 75 of file packing_types_test.C.

76 {
77 LOG_UNIT_TEST;
78
79 typedef Eigen::Matrix<Real, Eigen::Dynamic, 1> DynamicEigenVector;
80 typedef std::vector<DynamicEigenVector> DynamicVectorVector;
81 std::map<processor_id_type, DynamicVectorVector> send_data;
82
83 // prepare unique data
84 for (const auto i : index_range(*TestCommWorld))
85 {
86 const auto j = TestCommWorld->rank();
87 send_data[i] = DynamicVectorVector{ DynamicEigenVector(i+1, 1) };
88 for (const auto row: make_range(i+1))
89 send_data[i][0](row) = row * 1000.0 + 10.0 * i + j;
90 }
91
92 // verification
93 auto verify_data =
94 [](processor_id_type j, const DynamicVectorVector & recv_data)
95 {
96 const auto i = TestCommWorld->rank();
97 const std::size_t rows = recv_data[0].rows();
98 const std::size_t cols = recv_data[0].cols();
99
100 CPPUNIT_ASSERT_EQUAL( rows, static_cast<std::size_t>(i+1) );
101 CPPUNIT_ASSERT_EQUAL( cols, 1lu );
102
103 for (const auto row: make_range(rows))
104 CPPUNIT_ASSERT_EQUAL( recv_data[0](row), static_cast<Real>(row * 1000.0 + j + 10.0 * i) );
105 };
106
107 // communicate
108 Parallel::push_parallel_vector_data(*TestCommWorld, send_data, verify_data);
109 }

References libMesh::index_range(), libMesh::make_range(), libMesh::Real, and TestCommWorld.

◆ testNonFixedScalar()

void PackingTypesTest::testNonFixedScalar ( )
inline

Definition at line 111 of file packing_types_test.C.

112 {
113 LOG_UNIT_TEST;
114
115 typedef Eigen::Matrix<std::vector<Real>, 3, 3> VectorEigenMatrix;
116 typedef std::vector<VectorEigenMatrix> VectorMatrixVector;
117 std::map<processor_id_type, VectorMatrixVector> send_data;
118
119 // prepare unique data
120 for (const auto i : index_range(*TestCommWorld))
121 {
122 const auto j = TestCommWorld->rank();
123 send_data[i] = VectorMatrixVector(1);
124 for (const auto row: make_range(3))
125 for (const auto col: make_range(3))
126 send_data[i][0](row, col).assign(row + col + 1, 10.0 * i + j);
127 }
128
129 // verification
130 auto verify_data =
131 [](processor_id_type j, const VectorMatrixVector & recv_data)
132 {
133 const auto i = TestCommWorld->rank();
134 const std::size_t rows = recv_data[0].rows();
135 const std::size_t cols = recv_data[0].cols();
136
137 CPPUNIT_ASSERT_EQUAL( rows, static_cast<std::size_t>(3) );
138 CPPUNIT_ASSERT_EQUAL( cols, static_cast<std::size_t>(3) );
139
140 for (const auto row: make_range(rows))
141 for (const auto col: make_range(cols))
142 {
143 CPPUNIT_ASSERT_EQUAL( recv_data[0](row, col).size(), static_cast<std::size_t>(row + col + 1) );
144 for (const auto & val : recv_data[0](row, col))
145 CPPUNIT_ASSERT_EQUAL( val, static_cast<Real>(j + 10.0 * i) );
146 }
147 };
148
149 // communicate
150 Parallel::push_parallel_vector_data(*TestCommWorld, send_data, verify_data);
151 }

References libMesh::index_range(), libMesh::make_range(), libMesh::Real, and TestCommWorld.


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