コード例 #1
0
 def coreProcess(self, meshctxt, subp):
     subp.solver_mode = solvermode.AdvancedSolverMode(
         time_stepper=staticstep.StaticDriver(),
         nonlinear_solver=nonlinearsolver.NoNonlinearSolver(),
         symmetric_solver=matrixmethod.ConjugateGradient(
             preconditioner.ILUPreconditioner(),
             1.e-5,  # tolerance
             1000  # max_iterations
         ),
         asymmetric_solver=matrixmethod.BiConjugateGradient(
             preconditioner.ILUPreconditioner(),
             1.e-5,  # tolerance
             1000  # max_iterations
         ))
     meshctxt.begin_writing()
     try:
         try:
             evolve.evolve(meshctxt, 0.0)
         except:
             # TODO: Be more explicit about what exceptions
             # should be handled here, to distinguish actual
             # convergence failures from programming errors.
             self.solver_converged = False
         else:
             self.solver_converged = True
     finally:
         meshctxt.end_writing()
コード例 #2
0
ファイル: matrix_test.py プロジェクト: pk-organics/OOF3D
    def LU(self):
        # Test the ILU code on dense matrices.
        # A full identity matrix
        matrix = loadMatrix('identity-full')
        pcwrap = preconditioner.ILUPreconditioner()
        pc = pcwrap.create_preconditioner(matrix)
        unfact = pc.unfactored()
        saveMatrix(unfact, 'matrix.out')
        self.assert_(fp_file_compare('matrix.out',
                                     os.path.join(datadir, 'identity-full'),
                                     1.e-8))

        # Non-trivial test: a dense asymmetric matrix.
        matrix = loadMatrix('dense-asym-mat')
        pcwrap = preconditioner.ILUPreconditioner()
        pc = pcwrap.create_preconditioner(matrix)
        unfact = pc.unfactored()
        saveMatrix(unfact, 'matrix.out')
        self.assert_(fp_file_compare('matrix.out',
                                     os.path.join(datadir, 'ilu_unfactored'),
                                     1.e-8))
        # Check the preconditioner solutions...
        for vecname in ('rhs2.1', 'rhs2.2', 'rhs2.3'):
            vec = loadVector(vecname)
            result = pc.solve(vec)
            result.save('vector.out')
            self.assert_(fp_file_compare('vector.out',
                                         os.path.join(datadir,
                                                      vecname+'_ilu.out'),
                                         1.e-8))

        # A big(ger) dense matrix
        matrix = loadMatrix('big.mat')
        pcwrap = preconditioner.ILUPreconditioner()
        pc = pcwrap.create_preconditioner(matrix)
        unfact = pc.unfactored()
        saveMatrix(unfact, 'matrix.out')
        self.assert_(fp_file_compare('matrix.out',
                                     os.path.join(datadir, 'big.mat'),
                                     1.e-8))
        saveMatrix(pc.lower(), 'matrix.out')
        l_ok = fp_file_compare('matrix.out',
                               os.path.join(datadir, 'big_lower.out'),
                               1.e-8)
        saveMatrix(pc.upper(), 'matrix.out')
        u_ok = fp_file_compare('matrix.out',
                               os.path.join(datadir, 'big_upper.out'),
                               1.e-8)
        self.assert_(l_ok and u_ok)

        file_utils.remove('matrix.out')
        file_utils.remove('vector.out')
コード例 #3
0
 def resolve_symmetric(self, existingSolver):
     if (isinstance(existingSolver, ConjugateGradient)
             and existingSolver.tolerance == self.tolerance
             and existingSolver.max_iterations == self.max_iterations
             and isinstance(existingSolver.preconditioner,
                            preconditioner.ILUPreconditioner)):
         return existingSolver
     return ConjugateGradient(
         preconditioner=preconditioner.ILUPreconditioner(),
         tolerance=self.tolerance,
         max_iterations=self.max_iterations)
コード例 #4
0
 def resolve_asymmetric(self, subproblemcontext, existingSolver):
     krylov_guess = 30;    # Guess the krylov dimension for GMRES. 
     if (isinstance(existingSolver, GeneralizedMinResidual) and
         existingSolver.tolerance == self.tolerance and
         existingSolver.max_iterations == self.max_iterations and
         existingSolver.krylov_dimension == krylov_guess and
         isinstance(existingSolver.preconditioner,
                    preconditioner.ILUPreconditioner)):
         return existingSolver
     return GeneralizedMinResidual(
         preconditioner=preconditioner.ILUPreconditioner(),
         tolerance=self.tolerance,
         max_iterations=self.max_iterations,
         krylov_dimension=krylov_guess)
コード例 #5
0
    def coreProcess(self, meshctxt, subp):
        subp.solver = staticstep.StaticDriver(
            matrixmethod.ConjugateGradient(
                preconditioner.ILUPreconditioner(),
                1.e-5,  # tolerance
                1000  # max_iterations
            ))
        subp.solver_linearity = linearity.Linear()

        meshctxt.begin_writing()
        try:
            meshctxt.solver_precompute()
            try:
                evolve.evolve(meshctxt, 0.0, 0.0, False)
            except:
                # TODO 3.1: Be more explicit about what exceptions should
                # be handled here, to distinguish actual convergence
                # failures from programming errors.
                self.solver_converged = False
            else:
                self.solver_converged = True
        finally:
            meshctxt.end_writing()
コード例 #6
0
ファイル: matrix_test.py プロジェクト: pk-organics/OOF3D
    def ILU(self):
        # Actual incomplete factorizations of sparse matrices.

        # A sparse identity matrix
        print >> sys.stderr,  "identity"
        matrix = loadMatrix('identity')
        pcwrap = preconditioner.ILUPreconditioner()
        pc = pcwrap.create_preconditioner(matrix)
        unfact = pc.unfactored()
        saveMatrix(unfact, 'matrix.out')
        self.assert_(fp_file_compare('matrix.out',
                                     os.path.join(datadir, 'identity'),
                                     1.e-8))
        # A sparse diagonal non-identity matrix.
        print >> sys.stderr,  "diag"
        matrix = loadMatrix('diag')
        pc = pcwrap.create_preconditioner(matrix)
        unfact = pc.unfactored()
        saveMatrix(unfact, 'matrix.out')
        self.assert_(fp_file_compare('matrix.out',
                                     os.path.join(datadir, 'diag'),
                                     1.e-8))

        # Non-trivial tests.  The reference files were checked against
        # SparseLib++'s ILU routine.

        # A 4x4 sparse matrix.
        print >> sys.stderr,  "matrix1"
        matrix = loadMatrix('matrix1')
        pc = pcwrap.create_preconditioner(matrix)
        saveMatrix(pc.lower(), 'matrix.out')
        l_ok = fp_file_compare('matrix.out',
                               os.path.join(datadir, 'matrix1_lower.out'),
                               1.e-8)
        saveMatrix(pc.upper(), 'matrix.out')
        u_ok = fp_file_compare('matrix.out',
                               os.path.join(datadir, 'matrix1_upper.out'),
                               1.e-8)
        self.assert_(l_ok and u_ok)

        # A 10x10 sparse matrix with 62 entries.
        print >> sys.stderr,  "sparse10x10.mat"
        matrix = loadMatrix('sparse10x10.mat')
        pc = pcwrap.create_preconditioner(matrix)
        saveMatrix(pc.lower(), 'matrix.out')
        l_ok = fp_file_compare('matrix.out',
                               os.path.join(datadir, 'sparse10_lower.out'),
                               1.e-8)
        saveMatrix(pc.upper(), 'matrix.out')
        u_ok = fp_file_compare('matrix.out',
                               os.path.join(datadir, 'sparse10_upper.out'),
                               1.e-8)
        self.assert_(l_ok and u_ok)
        unfact = pc.unfactored()
        saveMatrix(unfact, 'matrix.out')
        # Check that the factoring *isn't* exact.
        self.assert_(
            not fp_file_compare('matrix.out',
                                os.path.join(datadir, 'sparse10x10.mat'),
                                1.e-8, quiet=True))
        
        # A 50x50 sparse matrix with 157 entries.
        print >> sys.stderr,  "bigsparse2.mat"
        matrix = loadMatrix('bigsparse2.mat')
        pc = pcwrap.create_preconditioner(matrix)
        saveMatrix(pc.lower(), 'matrix.out')
        l_ok = fp_file_compare('matrix.out',
                               os.path.join(datadir, 'bigsparse2_lower.out'),
                               1.e-8)
        saveMatrix(pc.upper(), 'matrix.out')
        u_ok = fp_file_compare('matrix.out',
                               os.path.join(datadir, 'bigsparse2_upper.out'),
                               1.e-8)
        self.assert_(l_ok and u_ok)

        # A 50x50 sparse matrix with 297 entries.
        print >> sys.stderr,  "bigsparse.mat"
        matrix = loadMatrix('bigsparse.mat')
        pc = pcwrap.create_preconditioner(matrix)
        saveMatrix(pc.lower(), 'matrix.out')
        l_ok = fp_file_compare('matrix.out',
                                  os.path.join(datadir, 'bigsparse_lower.out'),
                                  1.e-8)
        saveMatrix(pc.upper(), 'matrix.out')
        u_ok = fp_file_compare('matrix.out',
                               os.path.join(datadir, 'bigsparse_upper.out'),
                               1.e-8)
        self.assert_(l_ok and u_ok)

        file_utils.remove('matrix.out')