I'd like to compute $u(y) = \int f(x,y) dx$, but don't see a really efficient way to do this in FEniCS. My first thought was to just assemble(f*v*dx) for two different meshes. (try1, below), but it seems I can't combine 1D and 2D meshes, and that the DG meshes have to have at least 2 basis functions in each direction, and I'm not sure how the mesh topology -> basis coefficient layout is controlled.
My next thought was to solve du/dx = f with a zero-BC on one side, to accumulate the integral on x = 1. That one gets all the way through assembling the problem, then fails with a singular matrix exception.
Is there a better way to do this in FEniCS? To solve this problem in general, I would suggest adding general convolutions to FEniCS, so that $u = \int h(\vec x-\vec y) v(\vec y) dy$ could be done by an appropriate matrix-multiply...
from dolfin import * m = UnitSquareMesh(12, 12) V = FunctionSpace(m, "Lagrange", 1) f = Function(V) f.interpolate(Expression("x-x")) # int_0^1 f dx = x - 0.5 def try1(): m2 = UnitSquareMesh(1, 12) V2 = FunctionSpace(m2, "DG", 0) u = Function(V2) print u.vector().array().shape v = TestFunction(V2) A = assemble(f*v*dx) print A.array()*12.0 def try2(): du = TrialFunction(V) v = TestFunction(VectorFunctionSpace(m, "Lagrange", 1)) bc = DirichletBC(V, Constant(0.0), lambda x,b: b and x < 1e-8) #bc2 = DirichletBC(V, Constant(0.0), lambda x,b: b and x < 1e-8) a = inner(grad(du), v)*dx L = f*v*dx #L2 = f*v*dx u = Function(V) solve(a == L, u, bcs=bc) print u.vector().array()