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

Public Member Functions

 LIBMESH_CPPUNIT_TEST_SUITE (PetscMatrixShellMatrixTest)
 
 CPPUNIT_TEST (testInitSizes)
 
 CPPUNIT_TEST (testGetContext)
 
 CPPUNIT_TEST (testMult)
 
 CPPUNIT_TEST_SUITE_END ()
 
void setUp ()
 
void tearDown ()
 
void testInitSizes ()
 
void testGetContext ()
 
void testMult ()
 

Detailed Description

Definition at line 44 of file petsc_matrix_shell_matrix_test.C.

Member Function Documentation

◆ CPPUNIT_TEST() [1/3]

PetscMatrixShellMatrixTest::CPPUNIT_TEST ( testGetContext  )

◆ CPPUNIT_TEST() [2/3]

PetscMatrixShellMatrixTest::CPPUNIT_TEST ( testInitSizes  )

◆ CPPUNIT_TEST() [3/3]

PetscMatrixShellMatrixTest::CPPUNIT_TEST ( testMult  )

◆ CPPUNIT_TEST_SUITE_END()

PetscMatrixShellMatrixTest::CPPUNIT_TEST_SUITE_END ( )

◆ LIBMESH_CPPUNIT_TEST_SUITE()

PetscMatrixShellMatrixTest::LIBMESH_CPPUNIT_TEST_SUITE ( PetscMatrixShellMatrixTest  )

◆ setUp()

void PetscMatrixShellMatrixTest::setUp ( )
inline

Definition at line 57 of file petsc_matrix_shell_matrix_test.C.

57{}

◆ tearDown()

void PetscMatrixShellMatrixTest::tearDown ( )
inline

Definition at line 58 of file petsc_matrix_shell_matrix_test.C.

58{}

◆ testGetContext()

void PetscMatrixShellMatrixTest::testGetContext ( )
inline

Definition at line 78 of file petsc_matrix_shell_matrix_test.C.

79 {
80 LOG_UNIT_TEST;
81
82 PetscMatrixShellMatrix<Number> mat(*TestCommWorld);
83 const numeric_index_type m = TestCommWorld->size();
84 mat.init(m, m, 1, 1);
85
86 // init() composes libmesh's own context onto the shell Mat, letting
87 // get_context() recover the wrapping object later given only the raw Mat.
88 CPPUNIT_ASSERT(PetscMatrixBase<Number>::get_context(mat.mat(), *TestCommWorld) == &mat);
89 }
This class provides a nice interface to the PETSc C-based data structures for parallel,...
This class allows to use a PETSc shell matrix as a PetscMatrix.
Communicator * TestCommWorld
dof_id_type numeric_index_type
Definition id_types.h:99

References libMesh::PetscMatrixShellMatrix< T >::init(), libMesh::PetscMatrixBase< T >::mat(), and TestCommWorld.

◆ testInitSizes()

void PetscMatrixShellMatrixTest::testInitSizes ( )
inline

Definition at line 60 of file petsc_matrix_shell_matrix_test.C.

61 {
62 LOG_UNIT_TEST;
63
64 PetscMatrixShellMatrix<Number> mat(*TestCommWorld);
65 const numeric_index_type m = TestCommWorld->size();
66 mat.init(m, m, /*m_l=*/1, /*n_l=*/1);
67
68 CPPUNIT_ASSERT_EQUAL(mat.m(), m);
69 CPPUNIT_ASSERT_EQUAL(mat.n(), m);
70 CPPUNIT_ASSERT_EQUAL(mat.local_m(), numeric_index_type(1));
71 CPPUNIT_ASSERT_EQUAL(mat.local_n(), numeric_index_type(1));
72
73 MatType type;
74 LibmeshPetscCall2((*TestCommWorld), MatGetType(mat.mat(), &type));
75 CPPUNIT_ASSERT(std::string(type) == MATSHELL);
76 }

References libMesh::PetscMatrixShellMatrix< T >::init(), libMesh::PetscMatrixBase< T >::local_m(), libMesh::PetscMatrixBase< T >::local_n(), libMesh::PetscMatrixBase< T >::m(), libMesh::PetscMatrixBase< T >::mat(), libMesh::PetscMatrixBase< T >::n(), and TestCommWorld.

◆ testMult()

void PetscMatrixShellMatrixTest::testMult ( )
inline

Definition at line 91 of file petsc_matrix_shell_matrix_test.C.

92 {
93 LOG_UNIT_TEST;
94
95 PetscMatrixShellMatrix<Number> mat(*TestCommWorld);
96 const numeric_index_type m = TestCommWorld->size();
97 mat.init(m, m, 1, 1);
98
99 LibmeshPetscCall2((*TestCommWorld),
100 MatShellSetOperation(mat.mat(), MATOP_MULT,
101 (void (*)(void))petsc_matrix_shell_matrix_test_mult));
102
103 PetscVector<Number> x(*TestCommWorld, m, 1);
104 PetscVector<Number> y(*TestCommWorld, m, 1);
105 x.set(TestCommWorld->rank(), 3.);
106 x.close();
107
108 LibmeshPetscCall2((*TestCommWorld), MatMult(mat.mat(), x.vec(), y.vec()));
109
110 LIBMESH_ASSERT_NUMBERS_EQUAL(Number(6.), y(TestCommWorld->rank()), TOLERANCE);
111 }
This class provides a nice interface to PETSc's Vec object.
static constexpr Real TOLERANCE

References libMesh::PetscVector< T >::close(), libMesh::PetscMatrixShellMatrix< T >::init(), libMesh::PetscMatrixBase< T >::mat(), libMesh::PetscVector< T >::set(), TestCommWorld, libMesh::TOLERANCE, and libMesh::PetscVector< T >::vec().


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