Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
Umberto Zerbinati committed Jun 11, 2024
1 parent 471a273 commit 8ff43c4
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
5 changes: 3 additions & 2 deletions docs/src/PETScPC/oseen.py.rst
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,9 @@ We try a multiplicative preconditioner instead ::
w[:] = 0
dofs = BitArray(self.fes.ndof); dofs[:] = True
smooth = KrylovSolver(self.a, dofs, p=smoother,
solverParameters={"ksp_type": "gmres",
"ksp_max_it": 10,
solverParameters={"ksp_type": "fgmres",
"ksp_max_it": 10,
"ksp_view": '',
"pc_type": "mat"})
w += GMRes(self.a.mat, d, pre=smoother, x=w, maxsteps = 10, printrates=False)
r = d.CreateVector()
Expand Down
13 changes: 7 additions & 6 deletions ngsPETSc/ksp.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from ngsolve import la, BilinearForm, FESpace, BitArray, Projector
from ngsPETSc import Matrix, VectorMapping, PETScPreconditioner

def createFromBilinearForm(a, freeDofs, solverParameters, optionsPrefix):
def createFromBilinearForm(a, freeDofs, solverParameters):
"""
This function creates a PETSc matrix from an NGSolve bilinear form
"""
Expand All @@ -23,7 +23,7 @@ def createFromBilinearForm(a, freeDofs, solverParameters, optionsPrefix):
mat = Matrix(a.mat, (dofs, freeDofs, None), solverParameters["mat_type"])
return (a.mat, mat.mat)

def createFromMatrix(a, freeDofs, solverParameters, optionsPrefix):
def createFromMatrix(a, freeDofs, solverParameters):
"""
This function creates a PETSc matrix from an NGSolve bilinear form
"""
Expand All @@ -39,7 +39,7 @@ def createFromMatrix(a, freeDofs, solverParameters, optionsPrefix):
mat = Matrix(a, (dofs, freeDofs, None), solverParameters["mat_type"])
return (a, mat.mat)

def createFromPC(a, freeDofs, solverParameters, optionsPrefix):
def createFromPC(a, freeDofs, solverParameters):
class Wrap():
def __init__(self, a, freeDofs):
self.mapping = VectorMapping((a.dofs,freeDofs,{"bsize": 1}))
Expand Down Expand Up @@ -78,7 +78,7 @@ class KrylovSolver():
:arg optionsPrefix: special solver options prefix for this specific Krylov solver
"""
def __init__(self, a, dofsDescr=None, p=None, solverParameters=None, optionsPrefix=None, nullspace=None):
def __init__(self, a, dofsDescr=None, p=None, solverParameters=None, optionsPrefix="", nullspace=None):

Check failure on line 81 in ngsPETSc/ksp.py

View workflow job for this annotation

GitHub Actions / lint

C0301

ngsPETSc/ksp.py:81:0: C0301 Line too long (107/100)
# Grabbing parallel information
if isinstance(dofsDescr, FESpace):
freeDofs = dofsDescr.FreeDofs()
Expand All @@ -93,11 +93,11 @@ def __init__(self, a, dofsDescr=None, p=None, solverParameters=None, optionsPref
#Construct operator

Check failure on line 93 in ngsPETSc/ksp.py

View workflow job for this annotation

GitHub Actions / lint

C0303

ngsPETSc/ksp.py:93:27: C0303 Trailing whitespace
for key in parse:
if isinstance(a, key):
ngsA, pscA = parse[key](a, freeDofs, solverParameters, optionsPrefix)
ngsA, pscA = parse[key](a, freeDofs, solverParameters)
if p is not None:
for key in parse:
if isinstance(p, key):
ngsP, pscP = parse[key](p, freeDofs, solverParameters, optionsPrefix)
ngsP, pscP = parse[key](p, freeDofs, solverParameters)
else:
ngsP = ngsA; pscP = pscA
#Construct vector mapping
Expand All @@ -124,6 +124,7 @@ def __init__(self, a, dofsDescr=None, p=None, solverParameters=None, optionsPref
self.ksp.setOptionsPrefix(optionsPrefix)
self.ksp.setFromOptions()
self.pscX, self.pscB = pscA.createVecs()
self.ksp.setUp()

def solve(self, b, x):
"""
Expand Down
3 changes: 0 additions & 3 deletions ngsPETSc/nullspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@
This module contains all the function and class needed to wrap a PETSc Nullspace in NGSolve
'''
from petsc4py import PETSc


from ngsPETSc import VectorMapping


class NullSpace:
'''
This class creates a PETSc Null space from NGSolve vectors
Expand Down

0 comments on commit 8ff43c4

Please sign in to comment.