2 #include <libmesh/lumped_mass_matrix.h> 3 #include <libmesh/parallel.h> 4 #include <libmesh/id_types.h> 5 #include <libmesh/int_range.h> 6 #include <libmesh/numeric_vector.h> 22 CPPUNIT_TEST(testNumerics);
24 CPPUNIT_TEST_SUITE_END();
30 _matrix = std::make_unique<LumpedMassMatrix<Number>>(*_comm);
39 _global_size += block_size;
42 _matrix->init(_global_size, UNUSED, _local_size, UNUSED);
54 CPPUNIT_ASSERT_EQUAL(_local_size,
numeric_index_type(_matrix->row_stop() - _matrix->row_start()));
58 std::vector<Real> gold_values(_local_size, 0);
61 for (
const auto i :
make_range(beginning_index, end_index))
62 for (
const auto j :
make_range(beginning_index, end_index))
64 const Real sgn = j % 2 ? 1 : -1;
65 _matrix->add(i, j, sgn * j);
66 gold_values[i - beginning_index] += j;
71 for (
const auto i :
make_range(beginning_index, end_index))
72 for (
const auto j :
make_range(beginning_index, end_index))
75 LIBMESH_ASSERT_NUMBERS_EQUAL(0, (*_matrix)(i, j), _tolerance);
77 LIBMESH_ASSERT_NUMBERS_EQUAL(gold_values[i - beginning_index], (*_matrix)(i, i), _tolerance);
81 for (
const auto i :
make_range(beginning_index, end_index))
83 const Real sgn = i % 2 ? 1 : -1;
84 _matrix->set(i, i, sgn * gold_values[i - beginning_index]);
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);
93 auto copy = _matrix->clone();
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());
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);
106 auto zero_copy = _matrix->zero_clone();
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());
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);
122 std::unique_ptr<LumpedMassMatrix<Number>>
_matrix;
libMesh::Parallel::Communicator * TestCommWorld
static constexpr Real TOLERANCE
numeric_index_type _local_size
The libMesh namespace provides an interface to certain functionality in the library.
uint8_t processor_id_type
Parallel::Communicator * _comm
dof_id_type numeric_index_type
std::unique_ptr< LumpedMassMatrix< Number > > _matrix
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...
CPPUNIT_TEST_SUITE_REGISTRATION(LumpedMassMatrixTest)