I have a DG function
mesh = UnitSquareMesh(50,50)
V = FunctionSpace(mesh,'DG',1)
u = Function(V)
I want to initialize this to a step function which is 0 for x < 1/2 and 1 for x > 1/2
My mesh edges lie on x=1/2. See this code
from dolfin import *
mesh = UnitSquareMesh(50,50)
V = FunctionSpace(mesh,'DG',1)
foo = Expression("0.0 + 1.0*(x[0] > 0.5)")
u = interpolate(foo, V)
print "Interpolation = ", assemble(inner(grad(u),grad(u))*dx)
u = project(foo, V)
print "Projection = ", assemble(inner(grad(u),grad(u))*dx)
The gradient should be zero but it does not come out like that. Atleast with projection I expected to get zero gradients.
Is there a way to set the function correctly ?