This is a read only copy of the old FEniCS QA forum. Please visit the new QA forum to ask questions

Large error in reloaded function from xml

0 votes

I would like to load a function generated by another file. For example,

Python file generating the function f:

mesh = UnitSquareMesh(256,256)
V = FunctionSpace(mesh, "DG", 1)
f = Function(V)
# Solve a pde for f
File('mesh256.xml') << mesh
File('data.xml') << f

file reloading the function f:

mesh = Mesh("./mesh256.xml")
V = FunctionSpace(mesh, "DG",1)
f = Function(V,"./data.xml")
#mesh = UnitSquareMesh(256,256)
#V = FunctionSpace(mesh, "DG", 1)
ff = project(f,V)
print errornorm(f,ff)

I generate the mesh and data xml files and reload the function f. The error between f and ff is around 10^-17, which is reasonable. Basically, I want to reload the function and project/interpolate it to a coarse mesh. If I add

mesh = UnitSquareMesh(64,64)
V = FunctionSpace(mesh, "DG", 1)

before the projection of f, the error is 0.035, which I think is too large. Even if I use a finer mesh up to 256*256 as in the commented part, the error is still 0.021.

How could I save and reload a function and use it in a coarse mesh? And any idea why the error is so large?
I use version 1.5.0.

asked Feb 12, 2015 by Lingyun FEniCS Novice (170 points)
...