| 95 | #PETSc Preconditioner |
| 96 | |
| 97 | class PETScPreconditioner(ngs.BaseMatrix): |
| 98 | def __init__(self,mat,freedofs=None, solverParameters=None): |
| 99 | ngs.BaseMatrix.__init__(self) |
| 100 | self.ngsmat = mat |
| 101 | self.vecmap = VectorMapping (mat.row_pardofs, freedofs) |
| 102 | self.pscmat = CreatePETScMatrix (mat, freedofs) |
| 103 | self.precond = psc.PC().create(comm=self.pscmat.getComm()) |
| 104 | |
| 105 | self.precond.setOperators(self.pscmat) |
| 106 | options_object = psc.Options() |
| 107 | if solverParameters is not None: |
| 108 | for optName, optValue in solverParameters.items(): |
| 109 | options_object[optName] = optValue |
| 110 | |
| 111 | self.precond.setOptionsPrefix(None) # optionsPrefix) |
| 112 | self.precond.setFromOptions() |
| 113 | self.precond.setUp() |
| 114 | self.pscx, self.pscy = self.pscmat.createVecs() |
| 115 | |
| 116 | def Shape(self): |
| 117 | return self.ngsmat.shape |
| 118 | def CreateVector(self,col): |
| 119 | return self.ngsmat.CreateVector(not col) |
| 120 | |
| 121 | def Mult(self,x,y): |
| 122 | self.vecmap.N2P(x,self.pscx) |
| 123 | self.precond.apply(self.pscx, self.pscy) |
| 124 | self.vecmap.P2N(self.pscy, y) |
| 125 | |
| 126 | def MultTrans(self,x,y): |
| 127 | self.vecmap.N2P(x,self.pscx) |
| 128 | self.precond.applyTranspose(self.pscx, self.pscy) |
| 129 | self.vecmap.P2N(self.pscy, y) |
| 130 | |
| 131 | |
| 132 | from ngsolve.comp import RegisterPreconditioner |
no outgoing calls
no test coverage detected