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

How to assemble functionals for many subdomains.

+2 votes
result=[assemble(u * dx(i), cell_domains=subdomains) for i in range(1000)]

I have plenty subdomains. This requires a lot of time to compile all. That is, how to assemble to array?

asked Jul 29, 2013 by dozaand FEniCS Novice (170 points)

1 Answer

+2 votes
 
Best answer

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.

answered Jul 29, 2013 by Jan Blechta FEniCS Expert (51,420 points)
selected Aug 8, 2013 by Jan Blechta
...