Exemple #1
0
def Solve(a, f, petsc_opts, kvecs):
    ngs.ngsglobals.msg_level = 5
    gfu = ngs.GridFunction(a.space)
    with ngs.TaskManager():
        a.Assemble()
        f.Assemble()
        ngs.ngsglobals.msg_level = 5
        awrap = petsc.PETScMatrix(a.mat,
                                  V.FreeDofs(),
                                  format=petsc.PETScMatrix.AIJ)
        awrap.SetNearNullSpace(kvecs)
        c = petsc.KSP(awrap,
                      finalize=True,
                      name="msaKSP",
                      petsc_options=petsc_opts)
        gfu.vec.data = c * f.vec
        return gfu
Exemple #2
0
def Solve(a, f, petsc_opts, kvecs):
    ngs.ngsglobals.msg_level = 5
    gfu = ngs.GridFunction(a.space)
    with ngs.TaskManager():
        a.Assemble()
        f.Assemble()
        ngs.ngsglobals.msg_level = 5
        awrap = petsc.PETScMatrix(a.mat, V.FreeDofs(), format=petsc.PETScMatrix.AIJ)
        awrap.SetNearNullSpace(kvecs)

        c = petsc.KSP(awrap, finalize=True, name="msaKSP", petsc_options = petsc_opts)

        ngs.mpi_world.Barrier()
        ts = ngs.mpi_world.WTime()
        gfu.vec.data = c * f.vec
        ngs.mpi_world.Barrier()
        ts = ngs.mpi_world.WTime() - ts

        print("ndof ", a.space.ndofglobal)
        print("dofs / (sec * np) = ", (a.space.ndofglobal * a.space.dim) / (ts * max(ngs.mpi_world.size-1,1)))

        return gfu
Exemple #3
0
            ucf = CoefficientFunction((RBM[0], RBM[1]))
        upart.Set(ucf)
        v = gfu.vec.CreateVector()
        v.data = gfu.vec
        rbm_vecs.append(v)
    return rbm_vecs


petsc.Initialize()

mat_wrap = petsc.PETScMatrix(a.mat,
                             freedofs=V.FreeDofs(),
                             format=petsc.PETScMatrix.AIJ)
opts = {"ksp_type": "cg", "ksp_atol": 1e-30, "ksp_rtol": 1e-8, "pc_type": "ml"}
ksp = petsc.KSP(mat=mat_wrap,
                name="someksp",
                petsc_options=opts,
                finalize=False)
ksp.GetMatrix().SetNearNullSpace(rb_modes(V))

# import ngs_amg
# mat_wrap = petsc.FlatPETScMatrix(a.mat, freedofs=V.FreeDofs())
# ngs_amg_opts = {"energy" : "alg", "comp_sm" : True, "force_comp_sm" : True, "max_cv" : 500, "ass_frac" : 0.15, "skip_ass" : 3}
# ngs_pc = ngs_amg.AMG_EL2(blf=a, freedofs=V.FreeDofs(), **ngs_amg_opts)
# ngs_pc = petsc.NGs2PETSc_PC(mat=mat_wrap, pc=ngs_pc)
# ksp.SetPC(ngs_pc)

ksp.Finalize()

from time import time
t = -time()
gfu.vec.data = ksp * f.vec
Exemple #4
0
import ngs_petsc as petsc
petsc.Initialize()
opts = {
    "ksp_type": "gmres",
    "ksp_atol": 1e-30,
    "ksp_rtol": 1e-14,
    "ksp_max_its": 1e6,
    "ksp_monitor": "",
    "ksp_converged_reason": "",
    #"ksp_view" : "",
    "pc_type": "none"
}
# pmat = petsc.FlatPETScMatrix(a.mat, X.FreeDofs())
pmat = petsc.PETScMatrix(a.mat, X.FreeDofs())
inv_stokes = petsc.KSP(mat=pmat,
                       name="ngs",
                       petsc_options=opts,
                       finalize=False)

fs_opts = {"pc_fieldsplit_detect_saddle_point": ""}
# fs_opts = {"pc_fieldsplit_detect_saddle_point" : "", "fieldsplit_1_pc_type" : "jacobi"}
# fs_opts = {"pc_fieldsplit_schur_fact_type" : "full", "fieldsplit_pfield_pc_type" : "bjacobi"}
# fs_opts = dict()
fs_opts = {
    "pc_fieldsplit_type": "schur",
    "pc_fieldsplit_schur_fact_type": "diag",
    # "pc_fieldsplit_detect_saddle_point" : "",
    "pc_fieldsplit_schur_precondition": "selfp",
    "fieldsplit_0_pc_type": "jacobi",
    # "fieldsplit_0_ksp_monitor" : "",
    #"fieldsplit_0_ksp_converged_reason" : "",
    "fieldsplit_1_pc_type": "jacobi",
Exemple #5
0
ngp.Initialize()

wrapped_mat = ngp.PETScMatrix(a.mat,
                              freedofs=V.FreeDofs(),
                              format=ngp.PETScMatrix.IS_AIJ)

# gives access to the petsc4py mat
p4p_mat = wrapped_mat.GetPETScMat()
if comm.size > 1:
    p4p_mat.convert("mpiaij")

# this is a wrapper around a KSP
wrapped_ksp = ngp.KSP(mat=wrapped_mat,
                      name="someksp",
                      petsc_options={
                          "ksp_type": "cg",
                          "pc_type": "gamg"
                      },
                      finalize=False)

# this is the petsc4py KSP
ksp = wrapped_ksp.GetKSP()
ksp.setTolerances(1e-6, 0, 1e12, 20)
ksp.setMonitor(lambda a, b, c: print("it", b, "err", c))

wrapped_ksp.Finalize()

# can map between NGSolve and PETSc vectors
vec_map = wrapped_mat.GetRowMap()
psc_rhs = vec_map.CreatePETScVector()
psc_sol = vec_map.CreatePETScVector()