1# -------------------------------------------------------------------- 2 3from petsc4py import PETSc 4import unittest 5 6# -------------------------------------------------------------------- 7 8class BaseTestTAO(object): 9 10 COMM = None 11 12 def setUp(self): 13 self.tao = PETSc.TAO().create(comm=self.COMM) 14 15 def tearDown(self): 16 self.tao = None 17 18 def testSetRoutinesToNone(self): 19 tao = self.tao 20 objective, gradient, objgrad = None, None, None 21 constraint, varbounds = None, None 22 hessian, jacobian = None, None 23 tao.setObjective(objective) 24 tao.setGradient(gradient) 25 tao.setVariableBounds(varbounds) 26 tao.setObjectiveGradient(objgrad) 27 tao.setConstraints(constraint) 28 tao.setHessian(hessian) 29 tao.setJacobian(jacobian) 30 31 def testGetVecsAndMats(self): 32 tao = self.tao 33 x = tao.getSolution() 34 g = tao.getGradient() 35 l, u = tao.getVariableBounds() 36 r = None#tao.getConstraintVec() 37 H, HP = None,None#tao.getHessianMat() 38 J, JP = None,None#tao.getJacobianMat() 39 for o in [x, g, r, l, u ,H, HP, J, JP,]: 40 self.assertFalse(o) 41 42 def testGetKSP(self): 43 ksp = self.tao.getKSP() 44 self.assertFalse(ksp) 45 46# -------------------------------------------------------------------- 47 48class TestTAOSelf(BaseTestTAO, unittest.TestCase): 49 COMM = PETSc.COMM_SELF 50 51class TestTAOWorld(BaseTestTAO, unittest.TestCase): 52 COMM = PETSc.COMM_WORLD 53 54# -------------------------------------------------------------------- 55 56import numpy 57if numpy.iscomplexobj(PETSc.ScalarType()): 58 del BaseTestTAO 59 del TestTAOSelf 60 del TestTAOWorld 61 62if __name__ == '__main__': 63 unittest.main() 64