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

CellFunction projection

0 votes

Hi!
How can I convert CellFunction("double", mesh) (2D case) into FunctionSpace(mesh, 'DG', 0)

I tried:

local_error = CellFunction("double", mesh)
project(local_error, FunctionSpace(mesh, 'DG', 0))

but it doesn`t work.

Thanks

asked Apr 1, 2016 by ashoka FEniCS Novice (270 points)

1 Answer

0 votes

A MeshFunction isn't a object that can be projected onto a function space.

However, you can copy the information of the MeshFunction into other function that belongs to a "compatible" function space (CellFunction->DG0, VertexFnction->CG1, etc). In your case the below code should be work:

DG = FunctionSpace(mesh, "DG", 0)
local_error = CellFunction("double", mesh)
u = Function(DG)
u.vector()[:] = local_error.array()

The above code works only because in this particular case the cell order is the same as the dof order in the DG0 space (see this discussion for some referenes).

Regards!

answered Apr 4, 2016 by hernan_mella FEniCS Expert (19,460 points)
edited Apr 5, 2016 by hernan_mella
...