xref: /petsc/src/binding/petsc4py/test/test_pc.py (revision dcd9205a182b2f15c9088c83fb1fa060ac8df8e4)
1from petsc4py import PETSc
2import unittest
3
4class BaseTestPC:
5    KSP_TYPE = None
6    PC_TYPE = None
7    def setUp(self):
8        ksp = PETSc.KSP()
9        ksp.create(PETSc.COMM_SELF)
10        pc = ksp.getPC()
11        if self.KSP_TYPE:
12            ksp.setType(self.KSP_TYPE)
13        if self.PC_TYPE:
14            pc.setType(self.PC_TYPE)
15        self.ksp = ksp
16        self.pc = pc
17
18    def tearDown(self):
19        self.ksp = None
20        self.pc = None
21        PETSc.garbage_cleanup()
22
23class TestFIELDSPLITPC(BaseTestPC, unittest.TestCase):
24    PC_TYPE = PETSc.PC.Type.FIELDSPLIT
25
26    def testISoperations(self):
27        test_index = [0,1,2]
28        pc = self.pc
29        is_u = PETSc.IS().createGeneral(test_index, comm=PETSc.COMM_SELF)
30        pc.setFieldSplitIS(("u", is_u))
31
32        self.assertTrue((pc.getFieldSplitSubIS("u").getIndices() == test_index).all())
33        is_u = None
34
35
36if __name__ == '__main__':
37    unittest.main()
38