← Back to team overview

dolfin team mailing list archive

Re: [Question #149919]: PETScKrylovMatrix multiplication in Python

 

Question #149919 on DOLFIN changed:
https://answers.launchpad.net/dolfin/+question/149919

    Status: Open => Answered

Kent-Andre Mardal proposed the following answer:
Nice!
There may be some SWIG director methods missing for the matrices. I will
have a look
to check how to do it with or without these director methods.

Kent

On 21 March 2011 19:17, Christian Clason <
question149919@xxxxxxxxxxxxxxxxxxxxx> wrote:

> 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.
>
> _______________________________________________
> Mailing list: https://launchpad.net/~dolfin
> Post to     : dolfin@xxxxxxxxxxxxxxxxxxx
> Unsubscribe : https://launchpad.net/~dolfin
> More help   : https://help.launchpad.net/ListHelp
>

-- 
You received this question notification because you are a member of
DOLFIN Team, which is an answer contact for DOLFIN.