本文整理汇总了Python中PETScIO.matToSparse方法的典型用法代码示例。如果您正苦于以下问题:Python PETScIO.matToSparse方法的具体用法?Python PETScIO.matToSparse怎么用?Python PETScIO.matToSparse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PETScIO
的用法示例。
在下文中一共展示了PETScIO.matToSparse方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1:
# 需要导入模块: import PETScIO [as 别名]
# 或者: from PETScIO import matToSparse [as 别名]
x = IO.arrayToVec(uOld)
#F = IO.matToSparse(HiptmairMatrices[6]).tocsr()
#Finv = sp.linalg.inv(F)
#Finv = PETSc.Mat().createAIJ(size=Finv.shape,csr=(Finv.indptr, Finv.indices, Finv.data))
#Ct = A.getSubMatrix(u_is,b_is)
#C = A.getSubMatrix(b_is,u_is)
#print Ct.size
#Schur = A.getSubMatrix(u_is,u_is)-Ct*Finv*C
Schur = pc.getPythonContext().ExactReturn()
os.chdir(path)
ShiftedMass = ShiftedMass.sparray()
MO.StoreMatrix(ShiftedMass,"mass_"+str(iter)+"_"+str(nn))
MO.StoreMatrix(IO.matToSparse(Schur).tocsr(),"Schur_"+str(iter)+"_"+str(nn))
os.chdir('..')
XX= np.concatenate((u_k.vector().array(),p_k.vector().array(),b_k.vector().array(),r_k.vector().array()), axis=0)
SolTime[xx-1] = SolutionTime/iter
NSave[xx-1] = (float(NSits)/iter)
Mave[xx-1] = (float(Mits)/iter)
iterations[xx-1] = iter
TotalTime[xx-1] = time.time() - TotalStart
print SolTime
import pandas as pd
示例2: setUp
# 需要导入模块: import PETScIO [as 别名]
# 或者: from PETScIO import matToSparse [as 别名]
def setUp(self, pc):
A, P = pc.getOperators()
print A.size
self.Ct = A.getSubMatrix(self.u_is,self.b_is)
self.C = A.getSubMatrix(self.b_is,self.u_is)
self.D = A.getSubMatrix(self.r_is,self.b_is)
self.Bt = A.getSubMatrix(self.u_is,self.p_is)
self.B = A.getSubMatrix(self.p_is,self.u_is)
self.Dt = A.getSubMatrix(self.b_is,self.r_is)
# print self.Ct.view()
F = IO.matToSparse(A.getSubMatrix(self.u_is,self.u_is)).tocsr()
Finv = sp.linalg.inv(F)
Finv = PETSc.Mat().createAIJ(size=Finv.shape,csr=(Finv.indptr, Finv.indices, Finv.data))
#CFC = sp.csr_matrix( (data,(row,column)), shape=(self.W[1].dim(),self.W[1].dim()) )
#print CFC.shape
#CFC = PETSc.Mat().createAIJ(size=CFC.shape,csr=(CFC.indptr, CFC.indices, CFC.data))
#print CFC.size, self.AA.size
#MX = self.AA+self.F
MX = self.AA - self.C*Finv*self.Ct
self.FF = - self.C*Finv*self.Ct
# MO.StoreMatrix(B,"A")
# print FC.todense()
self.kspF.setType('preonly')
self.kspF.getPC().setType('lu')
self.kspF.setFromOptions()
self.kspF.setPCSide(0)
self.kspA.setType('preonly')
self.kspA.getPC().setType('lu')
self.kspA.setFromOptions()
self.kspA.setPCSide(0)
self.kspQ.setType('preonly')
self.kspQ.getPC().setType('lu')
self.kspQ.setFromOptions()
self.kspQ.setPCSide(0)
self.kspScalar.setType('preonly')
self.kspScalar.getPC().setType('lu')
self.kspScalar.setFromOptions()
self.kspScalar.setPCSide(0)
kspMX = PETSc.KSP()
kspMX.create(comm=PETSc.COMM_WORLD)
pcMX = kspMX.getPC()
kspMX.setType('preonly')
pcMX.setType('lu')
kspMX.setOperators(MX,MX)
OptDB = PETSc.Options()
#OptDB["pc_factor_mat_ordering_type"] = "rcm"
#OptDB["pc_factor_mat_solver_package"] = "mumps"
kspMX.setFromOptions()
self.kspMX = kspMX
# self.kspCGScalar.setType('preonly')
# self.kspCGScalar.getPC().setType('lu')
# self.kspCGScalar.setFromOptions()
# self.kspCGScalar.setPCSide(0)
self.kspVector.setType('preonly')
self.kspVector.getPC().setType('lu')
self.kspVector.setFromOptions()
self.kspVector.setPCSide(0)
print "setup"