If your subdomains
are simply cell indices then
DG0 = FunctionSpace(mesh, 'DG', 0)
v = project(u, DG0)
#result = v.vector().array() # hack, not recommended, fast
result = [v(c.midpoint()) for c in cells(mesh)] # possibly slow, can be optimized using eval_cell
Note that, slow solution will still be much faster than JITing your solution above.
If your subdomains
consist of region larger than cells then you simply sum-up corresponding entries of result
given above.