Exemple #1
0
    def __init__(self, conf, **kwargs):
        try:
            from mumps import DMumpsContext
        except ImportError:
            self.mumps = None
            msg = 'cannot import MUMPS!'
            raise ImportError(msg)

        LinearSolver.__init__(self, conf, **kwargs)
        self.mumps = DMumpsContext()
        self.mumps_presolved = False
Exemple #2
0
 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            
Exemple #3
0
    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
Exemple #4
0
    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
    return (1-s)**2

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()
Exemple #6
0
    def picard_iteration(self, maxit=10):

        GD = self.GD
        e0 = 1.0
        k = 0
        while e0 > 1e-10:
            # 构建总系统
            A, F, isBdDof = self.get_total_system()

            # 处理边界条件, 这里是 0 边界
            gdof = len(isBdDof)
            bdIdx = np.zeros(gdof, dtype=np.int_)
            bdIdx[isBdDof] = 1
            Tbd = diags(bdIdx)
            T = diags(1 - bdIdx)
            A = T @ A @ T + Tbd
            F[isBdDof] = 0.0

            # 求解

            if False:
                x = spsolve(A, F)
            else:
                ctx = DMumpsContext()
                if ctx.myid == 0:
                    ctx.set_centralized_sparse(A)
                    x = F.copy()
                    ctx.set_rhs(x)  # Modified in place
                ctx.run(job=6)  # Analysis + Factorization + Solve
                ctx.destroy()  # Cleanup

            vgdof = self.vspace.number_of_global_dofs()
            pgdof = self.pspace.number_of_global_dofs()
            cgdof = self.cspace.number_of_global_dofs()

            e0 = 0.0
            start = 0
            end = vgdof
            self.cv[:] = x[start:end]

            start = end
            end += pgdof
            e0 += np.sum((self.cp - x[start:end])**2)
            self.cp[:] = x[start:end]

            start = end
            end += pgdof

            e0 += np.sum((self.cs - x[start:end])**2)
            self.cs[:] = x[start:end]
            e0 = np.sqrt(e0)  # 误差的 l2 norm
            k += 1

            for i in range(GD):
                start = end
                end += cgdof
                self.cu[:, i] = x[start:end]

            print(e0)

            if k >= maxit:
                print('picard iteration arrive max iteration with error:', e0)
                break