Yes, just multiply the Expression
with a piecewise constant TestFunction
and assemble it into a Vector
. Something like this:
e = <some Expression>
DG = FunctionSpace(mesh, "DG", 0)
v = TestFunction(DG)
L = v*e*dx
b = assemble(L)
E = b.array()
or in one line just this:
E = assemble(TestFunction(FunctionSpace(mesh, "DG", 0))*e*dx).array()