class Mumps(): A = None ctx = None x = None def __init__(self, A, **kwagrs): self.ctx = DMumpsContext() self.A = A.tocsc() self.ctx.set_icntl(14, 60) self.ctx.set_centralized_sparse(A) # print 'Factoring' self.ctx.set_silent() # print 'Done' self.ctx.run(job=4) # Factorization def solve(self,b): # print 'Solving' self.x = b.copy() self.ctx.set_rhs(self.x) self.ctx.run(job=3) # Solve # print 'Done' return self.x def clean(self): self.ctx.destroy()
def solve(self): mesh = self.mesh NE = mesh.number_of_edges() NC = mesh.number_of_cells() itype = mesh.itype ftype = mesh.ftype A = self.get_left_matrix() b = self.get_right_vector() x = np.r_[self.uh, self.ph] #把self.uh,self.ph组合在一起 b = b - A @ x # Modify matrix bdIdx = np.zeros((A.shape[0], ), dtype=itype) bdIdx[NE] = 1 Tbd = spdiags(bdIdx, 0, A.shape[0], A.shape[1]) T = spdiags(1 - bdIdx, 0, A.shape[0], A.shape[1]) AD = T @ A @ T + Tbd scipy.sparse.save_npz('AD.npz', AD) b[NE] = self.ph[0] with open("b.csv", "w", newline="") as datacsv: csvwriter = csv.writer(datacsv, dialect=("excel")) csvwriter.writerow(['b']) csvwriter.writerows([b]) # solve x[:] = spsolve(AD, b) # solve from mumps import DMumpsContext ctx = DMumpsContext() if ctx.myid == 0: ctx.set_centralized_sparse(AD.tocoo()) x = b.copy() ctx.set_rhs(x) ctx.set_silent() ctx.run(job=6) self.uh[:] = x[:NE] self.ph[:] = x[NE:] print('ph', self.ph) print('pI', self.pI) return x
def solve(self): mesh = self.mesh NE = mesh.number_of_edges() NC = mesh.number_of_cells() itype = mesh.itype ftype = mesh.ftype A = self.get_left_matrix() b = self.get_right_vector() x = np.r_[self.uh, self.ph] #把self.uh,self.ph组合在一起 b = b - A @ x # Modify matrix bdIdx = np.zeros((A.shape[0], ), dtype=itype) bdIdx[NE] = 1 Tbd = spdiags(bdIdx, 0, A.shape[0], A.shape[1]) T = spdiags(1 - bdIdx, 0, A.shape[0], A.shape[1]) AD = T @ A @ T + Tbd b[NE] = self.ph[0] K = AD.todense() # solve x[:] = spsolve(AD, b) # solve from mumps import DMumpsContext ctx = DMumpsContext() if ctx.myid == 0: ctx.set_centralized_sparse(AD.tocoo()) x = b.copy() ctx.set_rhs(x) ctx.set_silent() ctx.run(job=6) self.uh[:] = x[:NE] self.ph[:] = x[NE:] print('ph', self.ph) print('pI', self.pI) return x
if args.reload[0] is not None: n = int(float(args.reload[1])*3600*24/args.DT) with open(args.reload[0], 'rb') as f: simulator = pickle.load(f) simulator.add_time(n) #writer = VTKMeshWriter(simulation=simulator.run) #writer.run() writer = VTKMeshWriter() simulator.run(ctx=ctx, writer=writer) else: ctx = DMumpsContext() ctx.set_silent() with open(args.mesh, 'rb') as f: mesh = pickle.load(f) # 导入地质网格模型 mesh.fluid_relative_permeability_0 = water mesh.fluid_relative_permeability_1 = oil simulator = TwoFluidsWithGeostressSimulator(mesh, args) writer = VTKMeshWriter(simulation=simulator.run, args=(ctx, None)) writer.run() #writer = VTKMeshWriter() #simulator.run(ctx=ctx, writer=writer) ctx.destroy() # 保存程序终止状态,用于后续计算测试