dolfin team mailing list archive
-
dolfin team
-
Mailing list archive
-
Message #22151
Re: [Question #149919]: PETScKrylovMatrix multiplication in Python
On Monday March 21 2011 14:08:35 Kent-Andre Mardal wrote:
> On 21 March 2011 21:10, Johan Hake <johan.hake@xxxxxxxxx> wrote:
> > On Monday March 21 2011 13:03:16 Kent-Andre Mardal wrote:
> > > Question #149919 on DOLFIN changed:
> > > https://answers.launchpad.net/dolfin/+question/149919
> > >
> > > Kent-Andre Mardal proposed the following answer:
> > > On 21 March 2011 19:33, Johan Hake
> > >
> > > <question149919@xxxxxxxxxxxxxxxxxxxxx>wrote:
> > > > Question #149919 on DOLFIN changed:
> > > > https://answers.launchpad.net/dolfin/+question/149919
> > > >
> > > > Johan Hake proposed the following answer:
> > > >
> > > > On Monday March 21 2011 11:24:28 Kent-Andre Mardal wrote:
> > > > > 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.
> > > >
> > > > I think the director methods works fine. These are the guys that
> >
> > reports
> >
> > > > the
> > > > error.
> > > >
> > > > But I think we need to change order of the #includes in dolfin_la.h
> > > > so PETScVector come before PETScKrylovSolver.
> > > >
> > > > Can you check that Kent?
> > > >
> > > > We need some sort of testing for this...
> > > >
> > > > Johan
> > >
> > > Simply changing the order of includes did not fix it.
> >
> > Sorry fo the iterations. It should of course be that PETScVector needs to
> > come
> > before PETScKrylovMatrix...
>
> I did (in kernel_modules) but it did not help.
Then I am not sure what will work. Need to spend time debugging which I
unfortunately does not have for now. File a bug and attach the test script.
Johan
> > Not sure how we in general should address that SWIG is sensitive on
> > declaration order, as it can become quite tedious to resolve. But, as in
> > C++
> > we can forward declare some types within foo_pre.i directly. In this way
> > we can just put all problematic types into something like:
> >
> > // Forward declaration of types
> > namespace dolfin {
> >
> > PETScVector;
> >
> > }
> >
> > We already do this for some types. We could "standardize" this so we have
> > such
> > a section in all foo_pre.i files.
> >
> > Johan
> >
> > > Kent
> > >
> > > > > 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.
> > > >
> > > > _______________________________________________
> > > > Mailing list: https://launchpad.net/~dolfin
> > > > Post to : dolfin@xxxxxxxxxxxxxxxxxxx
> > > > Unsubscribe : https://launchpad.net/~dolfin
> > > > More help : https://help.launchpad.net/ListHelp
> >
> > _______________________________________________
> > Mailing list: https://launchpad.net/~dolfin
> > Post to : dolfin@xxxxxxxxxxxxxxxxxxx
> > Unsubscribe : https://launchpad.net/~dolfin
> > More help : https://help.launchpad.net/ListHelp
Follow ups
References