Пример #1
0
    def _applyToSolver(self, solver, matrix):
        if matrix.NumGlobalNonzeros() <= matrix.NumGlobalRows():
            return

        self.Prec = ML.MultiLevelPreconditioner(matrix, False)

        self.Prec.SetParameterList({text_to_native_str("output"): 0,
                                    text_to_native_str("max levels") : 2,
                                    text_to_native_str("prec type") : text_to_native_str("MGV"),
                                    text_to_native_str("increasing or decreasing") : text_to_native_str("increasing"),
                                    text_to_native_str("aggregation: type") : text_to_native_str("METIS"),
                                    text_to_native_str("aggregation: local aggregates") : 1,
                                    text_to_native_str("aggregation: damping factor") : 4. / 3.,
                                    text_to_native_str("eigen-analysis: type") : text_to_native_str("power-method"),
                                    text_to_native_str("eigen-analysis: iterations") : 20,
                                    text_to_native_str("smoother: sweeps") : 1,
                                    text_to_native_str("smoother: pre or post") : text_to_native_str("both"),
                                    text_to_native_str("smoother: type") : text_to_native_str("Aztec"),
                                    text_to_native_str("smoother: Aztec as solver") : False,
                                    text_to_native_str("coarse: type") : text_to_native_str("Amesos-KLU"),
                                    text_to_native_str("coarse: max size") : 128
                                    })

        self.Prec.ComputePreconditioner()

        solver.SetPrecOperator(self.Prec)
Пример #2
0
    def _applyToSolver(self, solver, matrix):
        if matrix.NumGlobalNonzeros() <= matrix.NumGlobalRows():
            return

        self.Prec = ML.MultiLevelPreconditioner(matrix, False)

        self.Prec.SetParameterList({
            "output": 0,
            "max levels": 10,
            "prec type": "MGW",
            "increasing or decreasing": "increasing",
            "aggregation: type": "Uncoupled-MIS",
            "energy minimization: enable": True,
            "eigen-analysis: type": "power-method",
            "eigen-analysis: iterations": 20,
            "smoother: sweeps": 4,
            "smoother: damping factor": 0.67,
            "smoother: pre or post": 'post',
            "smoother: type": "symmetric Gauss-Seidel",
            "coarse: type": 'Amesos-KLU',
            "coarse: max size": 256
        })

        self.Prec.ComputePreconditioner()

        solver.SetPrecOperator(self.Prec)
    def _applyToSolver(self, solver, matrix):
        if matrix.NumGlobalNonzeros() <= matrix.NumGlobalRows():
            return
        
        self.Prec = ML.MultiLevelPreconditioner(matrix, False)

        self.Prec.SetParameterList({"output": 0,
                                    "max levels" : 3,
                                    "prec type" : "MGV",
                                    "increasing or decreasing" : "increasing",
                                    "aggregation: type" : "METIS",
                                    "aggregation: nodes per aggregate" : 512,
                                    "aggregation: next-level aggregates per process" : 128,
                                    "aggregation: damping factor" : 4. / 3.,
                                    "eigen-analysis: type" : "power-method",
                                    "eigen-analysis: iterations" : 20,
                                    "smoother: sweeps" : 1,
                                    "smoother: pre or post" : 'both',
                                    "smoother: type" : "Aztec",
                                    "smoother: Aztec as solver" : False,
                                    "coarse: type" : 'Amesos-KLU',
                                    "coarse: max size" : 128
                                    })

        self.Prec.ComputePreconditioner()
        
        solver.SetPrecOperator(self.Prec)
Пример #4
0
def perform_ML(Label, Map, Matrix, LHS, RHS, ExactSolution, NullSpace, List):
  if MyPID == 0:
    print "<p><p><div class=\"outputBox\"><pre>";
    print "<b><font color=midnightblue>Problem Label =", Label, "</font></b>";
    print "<b><font color=midnightblue>Operation = multilevel preconditioner</b>";
    print "Using", NumProcs, "processors."
    print "The AztecOO/ML output follows."
    print "</font>";

  Time = Epetra.Time(Matrix.Comm())

  # FIXME: ???
  #if NumProcs > 1:
  #List['coarse: type'] = 'symmetric Gauss-Seidel';

  Prec = ML.MultiLevelPreconditioner(Matrix, False);
  if NullSpace == "not-set":
    Prec.SetParameterList(List)
  else:
    Prec.SetParameterListAndNullSpace(List, NullSpace)

  Prec.ComputePreconditioner()

  PrecTime = Time.ElapsedTime()

  (ierr, iters, SolveTime, ConditionNumber) = iterative_solver(List, Matrix, LHS, RHS, Prec)
  del Prec;

  if MyPID == 0:
    add_result(List, Label + " ML", ierr, iters, PrecTime, SolveTime, ConditionNumber)
    print "&nbsp;<pre></div>";
    def _applyToSolver(self, solver, matrix):
        if matrix.NumGlobalNonzeros() <= matrix.NumGlobalRows():
            return

        self.Prec = ML.MultiLevelPreconditioner(matrix, False)
        self.Prec.SetParameterList({text_to_native_str("output"): 0, text_to_native_str("smoother: type") : text_to_native_str("Aztec"), text_to_native_str("smoother: Aztec as solver") : True})
        self.Prec.ComputePreconditioner()
        solver.SetPrecOperator(self.Prec)
Пример #6
0
def trilinos_ml_prec(A_epetra):
    mlList = {"max levels": 10,
              "output": 0,
              "smoother: pre or post": "both",
              "smoother: type": "Aztec"
              }

    prec = ML.MultiLevelPreconditioner(A_epetra, mlList)
    return prec
Пример #7
0
    def _applyToSolver(self, solver, matrix):
        if matrix.NumGlobalNonzeros() <= matrix.NumGlobalRows():
            return

        self.Prec = ML.MultiLevelPreconditioner(matrix, False)
        self.Prec.SetParameterList({
            "output": 0,
            "smoother: type": "symmetric Gauss-Seidel"
        })
        self.Prec.ComputePreconditioner()
        solver.SetPrecOperator(self.Prec)
Пример #8
0
    def _applyTrilinosSolver(self, A, LHS, RHS):

        Prec = ML.MultiLevelPreconditioner(A, False)
        
        Prec.SetParameterList(self.MLOptions)
        Prec.ComputePreconditioner()

        Prec.TestSmoothers()
        raw_input("Results of preconditioner tests shown above. Currently, the first tests in the 'Gauss-Seidel (sym)','Aztec preconditioner', and 'Aztec as solver' sections indicate the expected performance of the MultilevelSGSPreconditioner, MultilevelDDPreconditioner, and MultilevelSolverSmootherPreconditioner classes, respectively.\n\nPress enter to quit.")
        import sys
        sys.exit(0)
Пример #9
0
    def _applyToSolver(self, solver, matrix):
        if matrix.NumGlobalNonzeros() <= matrix.NumGlobalRows():
            return

        self.Prec = ML.MultiLevelPreconditioner(matrix, False)

        self.Prec.SetParameterList({
            text_to_native_str("output"):
            0,
            text_to_native_str("max levels"):
            10,
            text_to_native_str("prec type"):
            text_to_native_str("MGV"),
            text_to_native_str("increasing or decreasing"):
            text_to_native_str("increasing"),
            text_to_native_str("aggregation: type"):
            text_to_native_str("Uncoupled-MIS"),
            text_to_native_str("aggregation: damping factor"):
            4. / 3.,
            ##                                    "energy minimization: enable" : False,
            ##                                    "smoother: type" : "Aztec",
            ##                                    "smoother: type" : "symmetric Gauss-Seidel",
            ##                                    "eigen-analysis: type" : "power-method",
            text_to_native_str("eigen-analysis: type"):
            text_to_native_str("cg"),
            text_to_native_str("eigen-analysis: iterations"):
            10,
            text_to_native_str("smoother: sweeps"):
            2,
            text_to_native_str("smoother: damping factor"):
            1.0,
            text_to_native_str("smoother: pre or post"):
            text_to_native_str("both"),
            text_to_native_str("smoother: type"):
            text_to_native_str("symmetric Gauss-Seidel"),
            text_to_native_str("coarse: type"):
            text_to_native_str("Amesos-KLU"),
            text_to_native_str("coarse: max size"):
            128
        })

        self.Prec.ComputePreconditioner()

        solver.SetPrecOperator(self.Prec)
Пример #10
0
    A = as_backend_type(AA).mat()
    BB = assemble(b)
    LL = assemble(inner(grad(p), grad(q)) * dx)
    PP = assemble(pp)
    bcs.apply(PP)
    # bcs.apply(BB)make
    P = as_backend_type(PP).mat()
    B = as_backend_type(BB).mat()
    L = as_backend_type(LL).mat()
    b = as_backend_type(bb).vec()
    x = Epetra.Vector(0 * bb.array())
    # exit
    # A = as_backend_type(AA).mat()
    print toc()

    ML_Hiptmair = ml.MultiLevelPreconditioner(P, B, L, MLList)

    ML_Hiptmair.ComputePreconditioner()
    # ML_Hiptmair.ComputePreconditioner()
    solver = AztecOO.AztecOO(A, x, b)
    solver.SetPrecOperator(ML_Hiptmair)
    solver.SetAztecOption(AztecOO.AZ_solver, AztecOO.AZ_gmres)
    solver.SetAztecOption(AztecOO.AZ_output, 16)
    err = solver.Iterate(1550, 1e-5)

    # if (Solving == 'Direct'):
    #     ksp = PETSc.KSP().create()
    #     ksp.setOperators(A)

    #     ksp.setFromOptions()
Пример #11
0
def runit(size, prec, diff):
    # builds the linear system matrix and sets up starting solution and
    # right-hand side
    Comm = Epetra.PyComm()

    print "SIZE = ", size
    print "PREC = ", prec
    print "DIFF = ", diff

    GaleriList = {
        "nx": size,
        "ny": size,
        "mx": 1,
        "my": 1,
        "conv": 1.0,
        "diff": diff
    }

    Map = Galeri.CreateMap("Cartesian2D", Comm, GaleriList)
    Matrix = Galeri.CreateCrsMatrix("BentPipe2D", Map, GaleriList)

    Util = Epetra.Util()
    Util.SetSeed(0)
    LHS = Epetra.Vector(Map)
    RHS = Epetra.Vector(Map)
    n = LHS.MyLength()
    for i in xrange(0, n):
        LHS[i] = sin(i * 3.1415 / n) * sin(i * 3.1415 / n)
    Matrix.Multiply(False, LHS, RHS)
    LHS.PutScalar(0.0)

    # sets up the parameters for ML using a python dictionary
    if prec == "SA":
        MLList = {
            "max levels": 10,
            "output": 10,
            "increasing or decreasing": "increasing",
            "aggregation: type": "Uncoupled-MIS",
            "smoother: type (level 0)": "symmetric Gauss-Seidel",
            "smoother: damping factor": 0.67,
            "smoother: sweeps": 1,
            "smoother: pre or post": "both",
            "PDE equations": 1,
            "aggregation: damping factor": 1.333,
            "eigen-analysis: type": "power-method"
        }
    elif prec == "NSA":
        MLList = {
            "max levels": 10,
            "output": 10,
            "increasing or decreasing": "increasing",
            "aggregation: type": "Uncoupled-MIS",
            "smoother: type (level 0)": "symmetric Gauss-Seidel",
            "smoother: damping factor": 0.67,
            "smoother: sweeps": 1,
            "smoother: pre or post": "both",
            "PDE equations": 1,
            "aggregation: damping factor": 0.0000,
            "eigen-analysis: type": "power-method"
        }
    elif prec == "NSR":
        MLList = {
            "max levels": 10,
            "output": 10,
            "increasing or decreasing": "increasing",
            "aggregation: type": "Uncoupled-MIS",
            "smoother: type (level 0)": "symmetric Gauss-Seidel",
            "smoother: damping factor": 0.67,
            "smoother: sweeps": 1,
            "smoother: pre or post": "both",
            "PDE equations": 1,
            "aggregation: use tentative restriction": True,
            "aggregation: damping factor": 1.0000,
            "eigen-analysis: type": "power-method"
        }
    elif prec == "EMIN":
        MLList = {
            "max levels": 10,
            "output": 10,
            "increasing or decreasing": "increasing",
            "aggregation: type": "Uncoupled-MIS",
            "smoother: type (level 0)": "symmetric Gauss-Seidel",
            "smoother: damping factor": 0.67,
            "smoother: sweeps": 1,
            "smoother: pre or post": "both",
            "PDE equations": 1,
            "energy minimization: enable": True,
            "energy minimization: type": 2
        }

    # creates the preconditioner and computes it
    Prec = ML.MultiLevelPreconditioner(Matrix, False)
    Prec.SetParameterList(MLList)
    Prec.ComputePreconditioner()

    # sets up the solver, specifies Prec as preconditioner, and
    # solves using CG.
    Solver = AztecOO.AztecOO(Matrix, LHS, RHS)
    Solver.SetPrecOperator(Prec)
    Solver.SetAztecOption(AztecOO.AZ_solver, AztecOO.AZ_gmres)
    Solver.SetAztecOption(AztecOO.AZ_kspace, 30)
    Solver.SetAztecOption(AztecOO.AZ_output, 32)
    Solver.Iterate(400, 1e-8)

    del Prec
Пример #12
0
    "smoother: sweeps"                          : 1,
    "smoother: damping factor"              : 1.0,
    "smoother: pre or post"                     : "both",
    "smoother: type"                               : "Hiptmair",

    "subsmoother: type"                         : "Chebyshev",
    "subsmoother: Chebyshev alpha"    : 27.0,
    "subsmoother: node sweeps"           : 4,
    "subsmoother: edge sweeps"           : 4,

    "coarse: type"                                   : "Amesos-KLU",
    "coarse: max size"                           : 128

}

ML_Hiptmair = ml.MultiLevelPreconditioner(P11.down_cast().mat(),B.down_cast().mat(),P22.down_cast().mat(),MLList)
# ML_Hiptmair = ml.MultiLevelPreconditioner(P11.down_cast().mat(),MLList)
ML_Hiptmair.ComputePreconditioner()

DoF =B1.array().size + B2.array().size
PP = block_mat([[ConjGrad(P11,precond=bat.ML(P11),tolerance=1e-10,maxiter=50000,show=1),0],[0,ConjGrad(P22,precond=bat.ML(P22),tolerance=1e-10,maxiter=50000,show=1)]])

# PP = block_mat([[(P11),0],[0,MinRes(P22,precond=block.algebraic.trilinos.ML(P22),tolerance=1e-6,maxiter=50000,show=1)]])
print "DoF:",DoF


# PP = block_mat([[(P11),0],[0,(P22)]])
# Max.minres(AA, bb,0*bb, PP, 1e-10,50000,1e-8)

AAinv = MinRes(AA, precond = PP, tolerance=1e-8,maxiter=50000)
uu, pp = AAinv * bb
Пример #13
0
    Pname = "".join(["P", str(Nb[0] - 1)])
    # SaveEpertaMatrix(A_epetra,Aname)
    # SaveEpertaMatrix(P_epetra,Pname)

    # b_epetra = NullSpace(bb,'vec')
    # x_epetra = NullSpace(x.vector(),'vec')
    print '\n\n\n DoF = ', Nb[0], '\n\n\n'
    DoF[xx - 1] = Nb[0] - 1
    mlList = {
        "max levels": 200,
        "output": 10,
        "smoother: type": "symmetric Gauss-Seidel",
        "aggregation: type": "Uncoupled"
    }

    prec = ML.MultiLevelPreconditioner(P_epetra, False)
    prec.SetParameterList(mlList)
    prec.ComputePreconditioner()

    solver = AztecOO.AztecOO(A_epetra, x_epetra, b_epetra)
    solver.SetPrecOperator(prec)
    solver.SetAztecOption(AztecOO.AZ_solver, AztecOO.AZ_gmres)
    solver.SetAztecOption(AztecOO.AZ_output, 100)
    err = solver.Iterate(1550, 1e-5)

    print 'done'

    # Ap = sp.save(A)

    # SaveEpertaMatrix(A,"A")
    # SaveEpertaMatrix(P.down_cast().mat(),"P")
Пример #14
0
  "aggregation: type" : "Uncoupled",
  "smoother: type (level 0)"    : "Aztec",
  "smoother: damping factor": 0.67,
  "smoother: sweeps": 1,
  "smoother: pre or post": "post",
  "smoother: type (level 1)"    : "Aztec",
  "PDE equations": 5,
  "aggregation: use tentative restriction": False,
  "aggregation: damping factor": 0.000,
  "eigen-analysis: type": "power-method",
  "aggregation: block scaling": False,
  "energy minimization: enable": False,
  "energy minimization: type": 2
}

# creates the preconditioner and computes it
Prec = ML.MultiLevelPreconditioner(Matrix, False)
Prec.SetParameterList(MLList)
Prec.ComputePreconditioner()

# sets up the solver, specifies Prec as preconditioner, and
# solves using CG.
Solver = AztecOO.AztecOO(Matrix, LHS, RHS)
Solver.SetPrecOperator(Prec)
Solver.SetAztecOption(AztecOO.AZ_solver, AztecOO.AZ_gmres);
Solver.SetAztecOption(AztecOO.AZ_kspace, 30);
Solver.SetAztecOption(AztecOO.AZ_output, 1);
Solver.Iterate(200, 1e-8)

del Prec
Пример #15
0
    "smoother: type (level 4)": "Hiptmair",
    "smoother: type (level 5)": "Hiptmair",
    "smoother: type (level 6)": "Hiptmair",
    "smoother: Hiptmair efficient symmetric": True,
    "subsmoother: type": "Chebyshev",
    "subsmoother: Chebyshev alpha": 27.0,
    "subsmoother: node sweeps": 4,
    "subsmoother: edge sweeps": 4,
    "coarse: type": "Amesos-KLU",
    "coarse: max size": 128,
    "coarse: pre or post": "post",
    "coarse: sweeps": 1
}

comm = Epetra.PyComm()
C = scipy_csr_matrix2CrsMatrix(System["C"].tocsr(), comm)
CurlCurl = scipy_csr_matrix2CrsMatrix(System["CurlCurl"].tocsr(), comm)
node = scipy_csr_matrix2CrsMatrix(System["node"].tocsr(), comm)

ML_Hiptmair = ML.MultiLevelPreconditioner(CurlCurl, C, node, MLList)
ML_Hiptmair.ComputePreconditioner()
x = System["rhs"][0]
b_epetra = TrilinosIO._numpyToTrilinosVector(x)
x_epetra = TrilinosIO._numpyToTrilinosVector(System["rhs"] * 0)

solver = AztecOO.AztecOO(CurlCurl, x_epetra, b_epetra)
solver.SetPrecOperator(ML_Hiptmair)
solver.SetAztecOption(AztecOO.AZ_solver, AztecOO.AZ_cg)
solver.SetAztecOption(AztecOO.AZ_output, 50)
err = solver.Iterate(155000, 1e-10)
Пример #16
0
Acurl,b = assemble_system(a,L1,bc)
Anode = assemble(l)


scipy.io.savemat( "System.mat", {"CurlCurl":Acurl.sparray(),"node":Anode.sparray(),"C":C,"rhs":b.array()},oned_as='row')
scipy.io.savemat( "node.mat", {"node":Anode.sparray()},oned_as='row')
scipy.io.savemat( "rhs.mat", {"rhs":b.array()},oned_as='row')

C = scipy_csr_matrix2CrsMatrix(C, comm)
Acurl = scipy_csr_matrix2CrsMatrix(Acurl.sparray(), comm)
Anode = scipy_csr_matrix2CrsMatrix(Anode.sparray(), comm)
# Acurl = as_backend_type(Acurl).mat()
# Anode = as_backend_type(Anode).mat()

ML_Hiptmair = ML.MultiLevelPreconditioner(Acurl,C,Anode,MLList,True)
ML_Hiptmair.ComputePreconditioner()
x = Function(V)

b_epetra = x_epetra = TrilinosIO._numpyToTrilinosVector(b.array())
x_epetra = TrilinosIO._numpyToTrilinosVector(x.vector().array())

tic()
#u = M.SolveSystem(A,b,V,"cg","amg",1e-6,1e-6,1)
print toc()

import PyTrilinos.AztecOO as AztecOO
solver = AztecOO.AztecOO(Acurl, x_epetra, b_epetra)
solver.SetPrecOperator(ML_Hiptmair)
solver.SetAztecOption(AztecOO.AZ_solver, AztecOO.AZ_cg);
solver.SetAztecOption(AztecOO.AZ_output, 50);
Пример #17
0
    #     "smoother: damping factor"              : 1.0,
    #     "smoother: pre or post"                     : "both",
    #     "smoother: type"                               : "Hiptmair",
    #     "subsmoother: type"                         : "Chebyshev",
    #     "subsmoother: Chebyshev alpha"    : 27.0,
    #     "subsmoother: node sweeps"           : 4,
    #     "subsmoother: edge sweeps"           : 4,
    #     "PDE equations" : 1,
    #     "coarse: type"                                   : "Amesos-MUMPS",
    #     "coarse: max size"                           : 25,
    #     "print unused" : 0

    # }

    MLList = Teuchos.ParameterList()
    ML.SetDefaults("maxwell", MLList)

    # MList.setParameters()
    MLList.set("default values", "maxwell")
    MLList.set("max levels", 10)
    MLList.set("prec type", "MGV")
    MLList.set("increasing or decreasing", "decreasing")
    MLList.set("aggregation: type", "Uncoupled-MIS")
    MLList.set("aggregation: damping factor", 4.0 / 3.0)
    # MLList.set("eigen-analysis: type", "cg")
    # MLList.set("eigen-analysis: iterations", 10)
    MLList.set("smoother: sweeps", 5)
    MLList.set("smoother: damping factor", 1.0)
    MLList.set("smoother: pre or post", "both")
    MLList.set("smoother: type", "Hiptmair")
    MLList.set("subsmoother: type", "Chebyshev")