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

Small question on projecting to a functionspace

0 votes

I am a bit puzzled by the following

import dolfin as df
mesh = df.UnitSquareMesh(20, 20)
V = df.FunctionSpace(mesh, 'CG', 1)
f = df.Expression("x[0]*x[0] + x[1]")
fv = df.project(f, V)
fv2 = df.project(fv, V)
print fv.vector().array() - fv2.vector().array()

I assume it is due to numerical errors when projecting, but it seems a bit strange that every time you project a function onto its own functionspace, it gets deformed a little bit.

asked Apr 7, 2016 by maartent FEniCS User (3,910 points)

1 Answer

+2 votes
 
Best answer

By default the projection is computed approximately with the conjugate gradient method.
You can reduce the difference between fv and fv2 down to numerical precision by tightening the solver tolerances, or by using a direct solver. For example,

fv = project(f, V, solver_type = "lu")
answered Apr 7, 2016 by Magne Nordaas FEniCS Expert (13,820 points)
selected Apr 7, 2016 by maartent

That's actually quite useful to know, thanks.

Just to add to Magne's answer, in the dev version of DOLFIN the default projection solver is LU.

...