1 #include <libmesh/libmesh_config.h> 3 #ifdef LIBMESH_HAVE_PETSC 5 #include <libmesh/petsc_matrix.h> 17 this->libmesh_suite_name =
"SparseMatrixTest";
19 this->libmesh_suite_name =
"PetscMatrixTest";
27 #ifndef LIBMESH_USE_COMPLEX_NUMBERS 28 #ifdef LIBMESH_DEFAULT_DOUBLE_PRECISION 29 CPPUNIT_TEST(testPetscBinaryRead);
33 CPPUNIT_TEST(testPetscBinaryWrite);
34 #if PETSC_RELEASE_GREATER_EQUALS(3, 23, 0) 35 CPPUNIT_TEST(testPetscCopyFromHash);
40 CPPUNIT_TEST_SUITE_END();
44 auto mat_to_read = std::make_unique<PetscMatrix<Number>>(*my_comm);
48 #if LIBMESH_DOF_ID_BYTES == 4 && LIBMESH_DEFAULT_DOUBLE_PRECISION 49 mat_to_read->read(
"matrices/geom_1_extraction_op.petsc32");
50 #elif LIBMESH_DOF_ID_BYTES == 8 && LIBMESH_DEFAULT_DOUBLE_PRECISION 51 mat_to_read->read(
"matrices/geom_1_extraction_op.petsc64");
56 CPPUNIT_ASSERT_EQUAL(mat_to_read->m(),
dof_id_type(27));
57 CPPUNIT_ASSERT_EQUAL(mat_to_read->n(),
dof_id_type(27));
64 auto mat_ascii_format = std::make_unique<PetscMatrix<Number>>(*my_comm);
65 mat_ascii_format->init(mat_to_read->m(), mat_to_read->n(),
66 mat_to_read->local_m(), mat_to_read->local_n(),
69 mat_ascii_format->read_matlab(
"matrices/geom_1_extraction_op.m");
71 mat_ascii_format->add(-1, *mat_to_read);
72 CPPUNIT_ASSERT_LESS(
TOLERANCE, mat_ascii_format->l1_norm());
78 auto mat_to_read = std::make_unique<PetscMatrix<Number>>(*my_comm);
79 mat_to_read->read_matlab(
"matrices/geom_1_extraction_op.m");
80 mat_to_read->print_petsc_binary(
"geom_1_extraction_op.petsc");
87 auto mat_reread = std::make_unique<PetscMatrix<Number>>(*my_comm);
88 mat_reread->init(mat_to_read->m(), mat_to_read->n(),
89 mat_to_read->local_m(), mat_to_read->local_n(),
92 mat_reread->read_petsc_binary(
"geom_1_extraction_op.petsc");
94 mat_to_read->add(-1, *mat_reread);
95 CPPUNIT_ASSERT_LESS(
TOLERANCE, mat_to_read->l1_norm());
101 auto mat_to_read = std::make_unique<PetscMatrix<Number>>(*my_comm);
102 mat_to_read->read_matlab(
"matrices/geom_1_extraction_op.m");
103 mat_to_read->print_petsc_hdf5(
"geom_1_extraction_op.hdf5");
105 auto mat_reread = std::make_unique<PetscMatrix<Number>>(*my_comm);
106 mat_reread->read_petsc_hdf5(
"geom_1_extraction_op.hdf5");
108 mat_to_read->add(-1, *mat_reread);
109 CPPUNIT_ASSERT_LESS(
TOLERANCE, mat_to_read->l1_norm());
112 #if PETSC_RELEASE_GREATER_EQUALS(3, 23, 0) 124 for (
const auto j :
make_range(my_comm->size()))
125 mat.
add(my_comm->rank(), j, my_comm->rank() * j);
128 for (
const auto j :
make_range(my_comm->size()))
129 CPPUNIT_ASSERT_EQUAL((*copy)(my_comm->rank(), j), static_cast<Number>(my_comm->rank() * j));
static constexpr Real TOLERANCE
void init_without_preallocation(numeric_index_type m, numeric_index_type n, numeric_index_type m_l, numeric_index_type n_l, numeric_index_type blocksize)
Perform matrix initialization steps sans preallocation.
CPPUNIT_TEST_SUITE_REGISTRATION(PetscMatrixTest)
void testPetscHDF5Write()
The libMesh namespace provides an interface to certain functionality in the library.
void use_hash_table(bool use_hash)
Sets whether to use hash table assembly.
bool summarized_logs_enabled()
dof_id_type numeric_index_type
std::unique_ptr< PetscMatrix< T > > copy_from_hash()
Creates a copy of the current hash table matrix and then performs assembly.
void testPetscCopyFromHash()
virtual void add(const numeric_index_type i, const numeric_index_type j, const T value) override
Add value to the element (i,j).
libMesh::PerfLog * unitlog
void testPetscBinaryRead()
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...
This class provides a nice interface to the PETSc C-based AIJ data structures for parallel...
void testPetscBinaryWrite()
void finish_initialization()
Finish up the initialization process.