← 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:
You can use the slice operator [:] or the cpp.down_cast functions, depending
on what
args are.

Eg. you could do:

du = Function(V)
du.vector()[:] = args[0][:]

Hope this helps, or else let me know.

Kent

On 21 March 2011 18:12, Christian Clason <
question149919@xxxxxxxxxxxxxxxxxxxxx> wrote:

> New question #149919 on DOLFIN:
> https://answers.launchpad.net/dolfin/+question/149919
>
> I am trying to solve a nonlinear pde-constrained optimization problem with
> a reduced Newton method, where instead of constructing the full Hessian, I
> compute the action of the Hessian on a function for use in a Krylov solver
> such as CG.
>
> I assume that this can be done by constructing a PETScKrylovMatrix and
> defining a suitable mult function. (If there is a more high-level way of
> doing this, I'd be grateful for a hint.) However, I'm a bit stumped by the
> interface between PETSc and Dolfin here. The core step in the matrix
> multiplication would be something like
>
> def mult(self, *args) :
>    du = Function(V,args[0])
>    L = du*v*dx
>    problem = VariationalProblem(a, L, bc)
>    y = problem.solve()
>    args[1] = y.vector()
>
> (assume that the function space V, test function v, boundary conditions bc
> and bilinear form a have all been defined previously). This however doesn't
> work, since args[0] and args[1] are not of proper type. How do I need to
> massage args[0] and args[1] to make this work? Any hints would be
> appreciated, especially a template for the use of PETScKrylovMatrix in
> Python.
>
> (If I can get this working, I'd be happy to turn this into a documented
> demo. I'm sure there are more people interested in using FEniCS as a
> framework for pde-constrained optimization.)
>
> --
> 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.