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

Interpolate to discontinue(2ord) VectorSpace

0 votes

Hi, in my algorithm (about NS Equation) I need to calculate this term :
$$ U_h = V_h + \nabla \rho_h $$
$ U_h$ is in VectorFunctionSpace(Th, "DG", 2)
$ V_h$ is in VectorFunctionSpace(Th, "CG", 2)
$ \rho_h $ is in FunctionSpace(Th, "CG", 1)
I think $\nabla \rho_h $ is a constant vector on each element but discontinue , so I try these codes to make these functions are all in the same space without changing their value :

interpolate(V_h, VectorFunctionSpace(Th, "DG", 2))

interpolate(grad(rho_h), VectorFunctionSpace(Th, "DG", 2))

the first line is running, but the second line can't run errors are:

File "/usr/lib/python2.7/dist-packages/dolfin/fem/interpolation.py", line 64, in interpolate
Pv.interpolate(v)
TypeError: in method 'Function_interpolate', argument 2 of type 'dolfin::GenericFunction const &'

Thanks & Happy new year!

asked Jan 1, 2014 by HS.Sheng FEniCS Novice (570 points)
edited Jan 1, 2014 by HS.Sheng

1 Answer

+2 votes

Try

project(grad(rho_h), VectorFunctionSpace(Th, "DG", 2))
answered Jan 2, 2014 by mikael-mortensen FEniCS Expert (29,340 points)

Thanks a lot ,the codes are running !
Now I notice that Space( "DG", 1) is in Space( "DG", 2), so project will also not change their value . :)

...