dolfin team mailing list archive
-
dolfin team
-
Mailing list archive
-
Message #22135
Re: [Question #149919]: PETScKrylovMatrix multiplication in Python
Question #149919 on DOLFIN changed:
https://answers.launchpad.net/dolfin/+question/149919
Status: Answered => Open
Christian Clason is still having a problem:
Yes, via PETScKrylovSolver. Below is a minimal example for what I'm
trying to do.
Christian
from dolfin import *
def boundary(x,on_boundary):
return on_boundary
mesh = UnitSquare(32, 32)
V = FunctionSpace(mesh, 'CG', 1)
u0 = Constant(0.0)
bc = DirichletBC(V, u0, boundary)
u = TrialFunction(V)
v = TestFunction(V)
a = inner(grad(u), grad(v))*dx
class NewtonMatrix(PETScKrylovMatrix) :
def __init__(self) :
PETScKrylovMatrix.__init__(self, V.dim(), V.dim())
def mult(self, *args) :
du = Function(V)
du.vector()[:] = args[0][:]
f = du*v*dx
problem = VariationalProblem(a, L, bc)
dy = problem.solve()
args[1][:] = dy.vector()[:]
H = NewtonMatrix()
E = project(Constant('1'),V)
b = PETScVector(E.vector().size())
b.set_local(E.vector().array())
x = PETScVector(E.vector().size())
x.zero()
NewtonSolver = PETScKrylovSolver('cg', 'none');
NewtonSolver.solve(H, x, b);
--
You received this question notification because you are a member of
DOLFIN Team, which is an answer contact for DOLFIN.
Follow ups
References