← Back to team overview

dolfin team mailing list archive

Re: saving and loading function

 

On Wed, Jan 07, 2009 at 02:49:17PM +0100, Johan Hake wrote:
> On Wednesday 07 January 2009 14:28:09 Kent Andre wrote:
> > 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 ?
> 
> A check for the signature is not enough. Eventually we have to check for the 
> meshes in the two files being the same too.

Maybe we should add a signature() function for meshes also that
returns some kind of checksum for the mesh?

-- 
Anders


> > 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
> 
> In theory it should be possible to do:
> 
>   d1 = Function("d1.xml")
>   d2 = Function("d2.xml")
> 
> But you cannot use pass them as coefficient functions to assemble, as a mesh 
> pointercheck will strike in Form.h.
> 
> This is an unresolved issue in both the c++ and python interface. 
> 
> Johan
> 
> > 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-package
> > > > >s/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
> 
> 
> _______________________________________________
> DOLFIN-dev mailing list
> DOLFIN-dev@xxxxxxxxxx
> http://www.fenics.org/mailman/listinfo/dolfin-dev

Attachment: signature.asc
Description: Digital signature


Follow ups

References