On Wed, Nov 04, 2009 at 07:05:01PM +0000, Garth N. Wells wrote: > > > Anders Logg wrote: > > Was this introduced after the changes to DofMap I pushed today? > > > > No. I went back a few changesets and the problem persisted. It works in > C++, so I hoped that Johan could shed some light on the Python magic.
I think I can. There's nothing magic about it. The "problem" is that the [] operator in Python is handled by UFL, not by DOLFIN. This means that U[1] returns a UFL object, namely the first (second) component of the function U (which will be a UFL Indexed object). This can naturally not be saved to file since UFL does not handle saving to file. But plotting works just fine, U[1] will be component 1 of U which is the same as sigma[1], so what you see in the plot is the y-component of sigma, or actually the projection of this component onto piecewise linears, since this is what plot() does for objects that are not GenericFunction. If it is not a GenericFunction, it tries to project the object which works just fine since U[1] is a UFL expression. Johan and I have discussed the possibility of taking over [] from UFL or at least adding some hook to UFL that let's us do the right thing. Johan has used a hook in UFL for handling the () operator. This is what allows us to do things like u((0.5, 0.5)) to evaluate a Function in Python. -- Anders > Garth > > > > >> Something is wrong with sub-functions in Python. For the mixed-poisson > >> demo, doing > >> > >> (sigma, u) = problem.solve().split() > >> plot(u) > >> > >> the plot looks as expected. Doing > >> > >> U = problem.solve() > >> plot(U[1]) > >> > >> the plot is wrong. Also, it's not possible to do > >> > >> f = File("u.pvd") > >> f << U[1] > >> > >> I get the message > >> > >> TypeError: in method 'File___lshift__', argument 2 of type > >> 'dolfin::FunctionPlotData const &' > >> > >> Garth > >> _______________________________________________ > >> DOLFIN-dev mailing list > >> DOLFIN-dev@fenics.org > >> http://www.fenics.org/mailman/listinfo/dolfin-dev > >> > >> ------------------------------------------------------------------------ > >> > >> _______________________________________________ > >> DOLFIN-dev mailing list > >> DOLFIN-dev@fenics.org > >> http://www.fenics.org/mailman/listinfo/dolfin-dev > _______________________________________________ > DOLFIN-dev mailing list > DOLFIN-dev@fenics.org > http://www.fenics.org/mailman/listinfo/dolfin-dev
signature.asc
Description: Digital signature
_______________________________________________ DOLFIN-dev mailing list DOLFIN-dev@fenics.org http://www.fenics.org/mailman/listinfo/dolfin-dev