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

Public Member Functions

 LIBMESH_CPPUNIT_TEST_SUITE (LumpedMassMatrixTest)
 
 CPPUNIT_TEST (testNumerics)
 
 CPPUNIT_TEST_SUITE_END ()
 
void setUp ()
 
void tearDown ()
 
void testNumerics ()
 

Private Attributes

Parallel::Communicator_comm
 
std::unique_ptr< LumpedMassMatrix< Number > > _matrix
 
numeric_index_type _local_size
 
numeric_index_type _global_size
 
const Real _tolerance = TOLERANCE * TOLERANCE
 

Detailed Description

Definition at line 17 of file lumped_mass_matrix_test.C.

Member Function Documentation

◆ CPPUNIT_TEST()

LumpedMassMatrixTest::CPPUNIT_TEST ( testNumerics  )

◆ CPPUNIT_TEST_SUITE_END()

LumpedMassMatrixTest::CPPUNIT_TEST_SUITE_END ( )

◆ LIBMESH_CPPUNIT_TEST_SUITE()

LumpedMassMatrixTest::LIBMESH_CPPUNIT_TEST_SUITE ( LumpedMassMatrixTest  )

◆ setUp()

void LumpedMassMatrixTest::setUp ( )
inline

Definition at line 27 of file lumped_mass_matrix_test.C.

28 {
30 _matrix = std::make_unique<LumpedMassMatrix<Number>>(*_comm);
31
32 numeric_index_type root_block_size = 2;
33 _local_size = root_block_size + static_cast<numeric_index_type>(_comm->rank());
34 _global_size = 0;
35
36 for (processor_id_type p = 0; p < _comm->size(); ++p)
37 {
38 numeric_index_type block_size = root_block_size + static_cast<numeric_index_type>(p);
39 _global_size += block_size;
40 }
41
42 _matrix->init(_global_size, UNUSED, _local_size, UNUSED);
43 }
numeric_index_type _global_size
Parallel::Communicator * _comm
std::unique_ptr< LumpedMassMatrix< Number > > _matrix
processor_id_type size() const
processor_id_type rank() const
Communicator * TestCommWorld
dof_id_type numeric_index_type
Definition id_types.h:99
uint8_t processor_id_type
Definition id_types.h:104

References _comm, _global_size, _local_size, _matrix, libMesh::Parallel::Communicator::rank(), libMesh::Parallel::Communicator::size(), and TestCommWorld.

◆ tearDown()

void LumpedMassMatrixTest::tearDown ( )
inline

Definition at line 45 of file lumped_mass_matrix_test.C.

45{}

◆ testNumerics()

void LumpedMassMatrixTest::testNumerics ( )
inline

Definition at line 47 of file lumped_mass_matrix_test.C.

48 {
49 LOG_UNIT_TEST;
50
51 numeric_index_type beginning_index = _matrix->row_start();
52 numeric_index_type end_index = _matrix->row_stop();
53
54 CPPUNIT_ASSERT_EQUAL(_local_size, numeric_index_type(_matrix->row_stop() - _matrix->row_start()));
55
56 _matrix->zero();
57
58 std::vector<Real> gold_values(_local_size, 0);
59
60 // Test add
61 for (const auto i : make_range(beginning_index, end_index))
62 for (const auto j : make_range(beginning_index, end_index))
63 {
64 const Real sgn = j % 2 ? 1 : -1;
65 _matrix->add(i, j, sgn * j);
66 gold_values[i - beginning_index] += j;
67 }
68
69 _matrix->close();
70
71 for (const auto i : make_range(beginning_index, end_index))
72 for (const auto j : make_range(beginning_index, end_index))
73 {
74 if (i != j)
75 LIBMESH_ASSERT_NUMBERS_EQUAL(0, (*_matrix)(i, j), _tolerance);
76 else
77 LIBMESH_ASSERT_NUMBERS_EQUAL(gold_values[i - beginning_index], (*_matrix)(i, i), _tolerance);
78 }
79
80 // Test set
81 for (const auto i : make_range(beginning_index, end_index))
82 {
83 const Real sgn = i % 2 ? 1 : -1;
84 _matrix->set(i, i, sgn * gold_values[i - beginning_index]);
85 }
86
87 _matrix->close();
88
89 for (const auto i : make_range(beginning_index, end_index))
90 LIBMESH_ASSERT_NUMBERS_EQUAL(gold_values[i - beginning_index], (*_matrix)(i, i), _tolerance);
91
92 // Test clone
93 auto copy = _matrix->clone();
94 // Check that matrices have the same local/global sizes
95 CPPUNIT_ASSERT_EQUAL(copy->m(), _matrix->m());
96 CPPUNIT_ASSERT_EQUAL(copy->n(), _matrix->n());
97 CPPUNIT_ASSERT_EQUAL(copy->local_m(), _matrix->local_m());
98 CPPUNIT_ASSERT_EQUAL(copy->row_start(), _matrix->row_start());
99 CPPUNIT_ASSERT_EQUAL(copy->row_stop(), _matrix->row_stop());
100
101 for (const auto i : make_range(beginning_index, end_index))
102 for (const auto j : make_range(beginning_index, end_index))
103 LIBMESH_ASSERT_NUMBERS_EQUAL((*_matrix)(i, j), (*copy)(i, j), _tolerance);
104
105 // Test zero clone
106 auto zero_copy = _matrix->zero_clone();
107 // Check that matrices have the same local/global sizes
108 CPPUNIT_ASSERT_EQUAL(zero_copy->m(), _matrix->m());
109 CPPUNIT_ASSERT_EQUAL(zero_copy->n(), _matrix->n());
110 CPPUNIT_ASSERT_EQUAL(zero_copy->local_m(), _matrix->local_m());
111 CPPUNIT_ASSERT_EQUAL(zero_copy->row_start(), _matrix->row_start());
112 CPPUNIT_ASSERT_EQUAL(zero_copy->row_stop(), _matrix->row_stop());
113
114 for (const auto i : make_range(beginning_index, end_index))
115 for (const auto j : make_range(beginning_index, end_index))
116 LIBMESH_ASSERT_NUMBERS_EQUAL(0, (*zero_copy)(i, j), _tolerance);
117 }
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
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 _local_size, _matrix, _tolerance, libMesh::make_range(), and libMesh::Real.

Member Data Documentation

◆ _comm

Parallel::Communicator* LumpedMassMatrixTest::_comm
private

Definition at line 121 of file lumped_mass_matrix_test.C.

Referenced by setUp().

◆ _global_size

numeric_index_type LumpedMassMatrixTest::_global_size
private

Definition at line 123 of file lumped_mass_matrix_test.C.

Referenced by setUp().

◆ _local_size

numeric_index_type LumpedMassMatrixTest::_local_size
private

Definition at line 123 of file lumped_mass_matrix_test.C.

Referenced by setUp(), and testNumerics().

◆ _matrix

std::unique_ptr<LumpedMassMatrix<Number> > LumpedMassMatrixTest::_matrix
private

Definition at line 122 of file lumped_mass_matrix_test.C.

Referenced by setUp(), and testNumerics().

◆ _tolerance

const Real LumpedMassMatrixTest::_tolerance = TOLERANCE * TOLERANCE
private

Definition at line 124 of file lumped_mass_matrix_test.C.

Referenced by testNumerics().


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