From a3be96600e47406fea517b899f9439ccd2045739 Mon Sep 17 00:00:00 2001 From: Umberto Zerbinati Date: Sat, 15 Jun 2024 02:48:28 +0100 Subject: [PATCH] Python action Signed-off-by: Umberto Zerbinati --- docs/src/PETScKSP/poisson.py.rst | 6 +++--- docs/src/PETScPC/oseen.py.rst | 2 +- ngsPETSc/ksp.py | 11 +++++++++-- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/docs/src/PETScKSP/poisson.py.rst b/docs/src/PETScKSP/poisson.py.rst index 1d538e4..e023dd0 100644 --- a/docs/src/PETScKSP/poisson.py.rst +++ b/docs/src/PETScKSP/poisson.py.rst @@ -140,12 +140,12 @@ Notice that because in NGSolve one needs to "register" the preconditioner before a = BilinearForm(grad(u)*grad(v)*dx) - el_bddc = Preconditioner(a, "local") + el_bddc = Preconditioner(a, "bddc") a.Assemble() - solver = KrylovSolver(a.mat, fes.FreeDofs(), p=None, + solver = KrylovSolver(a.mat, fes.FreeDofs(), p=el_bddc.mat, solverParameters={"ksp_type": "cg", "ksp_monitor": "", - "pc_type": "none", + "pc_type": "mat", "ngs_mat_type": "python", "ksp_rtol": 1e-10}) gfu = GridFunction(fes) diff --git a/docs/src/PETScPC/oseen.py.rst b/docs/src/PETScPC/oseen.py.rst index 2130cb5..8a2e8f5 100755 --- a/docs/src/PETScPC/oseen.py.rst +++ b/docs/src/PETScPC/oseen.py.rst @@ -117,7 +117,7 @@ Notice that while the smoother is very similar to the one used in :doc:`stokes.p Draw(gfu) vtk = VTKOutput(ma=mesh, coefs=[gfu], names = ["velocity"], - filename="Oseen_{}".format(nu.Get()), + filename="output/Oseen_{}".format(nu.Get()), subdivision=0) vtk.Do() diff --git a/ngsPETSc/ksp.py b/ngsPETSc/ksp.py index 6335b91..7a7ace1 100644 --- a/ngsPETSc/ksp.py +++ b/ngsPETSc/ksp.py @@ -93,14 +93,19 @@ def mult(self, mat, X, Y): dofs = a.row_pardofs comm = dofs.comm.mpi4py entrysize = a.local_mat.entrysizes[0] + _, rnumberGlobal = dofs.EnumerateGlobally(freeDofs) #samrc + elif "dofs" in solverParameters: + dofs = solverParameters["dofs"] + comm = dofs.comm.mpi4py + entrysize = dofs.entrysize + _, rnumberGlobal = dofs.EnumerateGlobally(freeDofs) #samrc else: dofs = None comm = PETSc.COMM_SELF entrysize = 1 - _, rnumberGlobal = dofs.EnumerateGlobally(freeDofs) #samrc + rnumberGlobal = sum(freeDofs) pythonA = Wrap(a, dofs, freeDofs, comm) pscA = PETSc.Mat().create(comm=comm) - print(comm.Get_rank(),sum(freeDofs)) pscA.setSizes(size=(rnumberGlobal*entrysize, rnumberGlobal*entrysize), bsize=entrysize) pscA.setType("python") @@ -145,6 +150,8 @@ def __init__(self, a, dofsDescr, p=None, nullspace=None, optionsPrefix="", solve if p is not None: for key in parse: if isinstance(p, key): + if hasattr(ngsA, "row_pardofs"): + solverParameters["dofs"] = ngsA.row_pardofs ngsP, pscP = parse[key](p, freeDofs, solverParameters) break else: