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

How to integrate over one subdomain when using MPI and Python?

0 votes

Dear all,

In single process mode, I have 3 subdomains marked as 0,1, and 2. I can use assemble(udx(0)) to integrate udx for subdomain 0. However, I can't do that in MPI. I am working in Python. Can you give me an example how I can implement this integration in MPI?

Thank you.

asked Jun 29, 2016 by lxd FEniCS Novice (290 points)

Can you give us an example? The following code seems to be working fine for me, also with mpi

from dolfin import *

n = 10
mesh = UnitSquareMesh(2*n, 2*n)
V = FunctionSpace(mesh, "CG", 2)
u = Function(V)
u.vector()[:] = 1.

subdomains = CellFunction("size_t", mesh)
subdomains.set_all(0)

class Half(SubDomain):
    def inside(self, x, on_boundary):
        return x[1] <= 0.5      
half = Half()
half.mark(subdomains, 1)

dx = Measure("dx")(subdomain_data=subdomains)
print assemble(u*dx(1))
...