MCPcopy Create free account
hub / github.com/NGSolve/ngsolve / PETScPreconditioner

Class PETScPreconditioner

python/ngs2petsc.py:97–129  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

95#PETSc Preconditioner
96
97class 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
132from ngsolve.comp import RegisterPreconditioner

Callers 2

MakeGAMGPreconditionerFunction · 0.85
MakePETScPreconditionerFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected