← Back to team overview

dolfin team mailing list archive

Re: saving and loading function

 

On Wednesday 07 January 2009 13:39:34 Garth N. Wells wrote:
> Kent Andre wrote:
> > Is it no longer possible to save and load functions ?
> > The following example shows
> > the problem:
> >
> >
> > the script save_func.py:
> >
> > from dolfin import *
> >
> > mesh = UnitSquare(12,12)
> > V = FunctionSpace(mesh, "CG", 1)
> >
> > d = Constant(mesh, 1)
> >
> > d_proj = project(d, V)
> >
> > file = File("d.xml")
> > file << d_proj
> >
> >
> > the script load_func.py
> >
> > from dolfin import *
> > mesh = UnitSquare(12,12)
> > V = FunctionSpace(mesh, "CG", 1)
> >
> > d = Function(V)
> > file = File("d.xml")
> > file >> d
> >
> > Running these two gives:
> >
> >   File
> > "/home/kent-and/local/src/dolfin-dev/local/lib/python2.5/site-packages/do
> >lfin/cpp.py", line 6968, in __rshift__ return _cpp.File___rshift__(*args)
> > RuntimeError: *** Error: Unable to assign to function, not in the same
> > function space.
> >
> >
> > I assume that the reason is that I run these script in separate
> > sessions.
>
> Try something like
>
>    from dolfin import *
>
>    d = Function()
>    file = File("d.xml")
>    file >> d

This won't work. But

    d = Function("d.xml")

will.

Well, or at least should work. I got a segfault! :P

[hake-laptop:13797] *** Process received signal ***
[hake-laptop:13797] Signal: Segmentation fault (11)
[hake-laptop:13797] Signal code: Address not mapped (1)
[hake-laptop:13797] Failing at address: 0x9

Reading functions from file in PyDOLFIN has worked.

Johan


Follow ups

References