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

How can I interpolate from DG0 to DG1 so that the new function has a gradient?

+3 votes

I want to interpolate from a piecewise constant function (DG0) to piecewise linear (DG1)
in such a way that the total integral remains the same, but the new function has a
gradient (which could just be the average difference between neighbouring DG0 cells).

i.e.

DG0 = FunctionSpace(mesh, "DG", 0)
DG1 = FunctionSpace(mesh, "DG", 1)
F0 = Function(DG0)
F0.interpolate(Expression("x[0]"))

will produce a piecewise constant function, F0. Now if I do:

F1.interpolate(F0)

or

F1 = project(F0, DG1)

the resulting function F1 is still piecewise constant. How can I make it incorporate the local gradient information. I realise it may involve solving an equation, but I don't know how to do it...

asked Jun 18, 2013 by chris_richardson FEniCS Expert (31,740 points)

What about projecting to CG1 and then to DG1?

1 Answer

+4 votes
 
Best answer

So Jan has got me answering my own question here, but this seems to work:

mesh = UnitSquareMesh(10,10)

DG0 = FunctionSpace(mesh, "DG", 0)
DG1 = FunctionSpace(mesh, "DG", 1)
CG1 = FunctionSpace(mesh, "CG", 1)

F0 = Function(DG0)
F0.interpolate(Expression("x[0]"))

F1 = Function(DG1)
F1.interpolate(project(F0, CG1))

Thanks...

answered Jun 18, 2013 by chris_richardson FEniCS Expert (31,740 points)
selected Jun 18, 2013 by logg
...