1#include <libmesh/libmesh_config.h>
3#ifdef LIBMESH_HAVE_PETSC
5#include <libmesh/petsc_matrix.h>
27#ifndef LIBMESH_USE_COMPLEX_NUMBERS
28#ifdef LIBMESH_DEFAULT_DOUBLE_PRECISION
34#if PETSC_RELEASE_GREATER_EQUALS(3, 23, 0)
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)
CPPUNIT_TEST(testPetscBinaryWrite)
void testPetscBinaryRead()
void testPetscCopyFromHash()
CPPUNIT_TEST_SUITE(PetscMatrixTest)
SPARSEMATRIXTEST CPPUNIT_TEST(testPetscBinaryRead)
void testPetscHDF5Write()
void testPetscBinaryWrite()
CPPUNIT_TEST(testPetscCopyFromHash)
libMesh::Parallel::Communicator * my_comm
std::string libmesh_suite_name
processor_id_type size() const
processor_id_type rank() const
bool summarized_logs_enabled()
This class provides a nice interface to the PETSc C-based AIJ data structures for parallel,...
std::unique_ptr< PetscMatrix< T > > copy_from_hash()
Creates a copy of the current hash table matrix and then performs assembly.
virtual void add(const numeric_index_type i, const numeric_index_type j, const T value) override
Add value to the element (i,j).
void finish_initialization()
Finish up the initialization process.
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.
void use_hash_table(bool use_hash)
Sets whether to use hash table assembly.
libMesh::PerfLog * unitlog
The libMesh namespace provides an interface to certain functionality in the library.
dof_id_type numeric_index_type
static constexpr Real TOLERANCE
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(PetscMatrixTest)