From c1412556f7cf0abeb79c44b4fbb90ba32a4ac0b3 Mon Sep 17 00:00:00 2001 From: Umberto Zerbinati Date: Wed, 19 Jun 2024 10:26:32 +0100 Subject: [PATCH] Fix mat type --- ngsPETSc/ksp.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/ngsPETSc/ksp.py b/ngsPETSc/ksp.py index 6f1e4e6..3d462a6 100644 --- a/ngsPETSc/ksp.py +++ b/ngsPETSc/ksp.py @@ -4,7 +4,7 @@ ''' from petsc4py import PETSc -from ngsolve import la, GridFunction, BaseMatrix +from ngsolve import la, GridFunction, BaseMatrix, BilinearForm from ngsPETSc import Matrix, VectorMapping @@ -25,9 +25,15 @@ class KrylovSolver(): :arg optionsPrefix: special solver options prefix for this specific Krylov solver """ - def __init__(self, a, fes, p=None, solverParameters=None, optionsPrefix=None, nullspace=None): - a.Assemble() - Amat = a.mat + def __init__(self, a, fes, p=None, solverParameters=None, optionsPrefix=None, nullspace=None): + if isinstance(BilinearForm): + a.Assemble() + Amat = a.mat + elif isinstance(a, (la.SparseMatrixd, la.ParallelMatrix)): + Amat = a + else: + raise TypeError("Provided operator is a '%s', and this is not supported." + % type(a).__name__) if p is not None: p.Assemble() Pmat = p.mat