← Back to team overview

dolfin team mailing list archive

Re: saving and loading function

 

It seems to me that the problem is that I have created two different
FunctionSpaces that are actually the same and that the test 
in Function is a pointer check. 

One could of course make a better check based on e.g. a signature. 
This should be trivial to do. But I will end up with using 
a bit more memory than needed. Is this an acceptable solution ? 

If I have two fields stored in the files d1.xml and d2.xml
How should I read these fields ? I would prefer a simple
variant like 

V = FunctionSpace(mesh, "CG", 1)
d1 = Function(V)
file = File("d1.xml")
file >> d1

d2 = Function(V)
file = File("d2.xml")
file >> d2

even though some additional memory is needed. 

Kent


On on., 2009-01-07 at 14:00 +0100, Johan Hake wrote:
> 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