Hi, consider
from dolfin import *
mesh = UnitSquareMesh(4,4)
class My_domain(SubDomain):
def inside(self,x,on_boundary):
return x[0]<=0.5
subdomain = CellFunction('size_t',mesh)
subdomain.set_all(0)
my_domain = My_domain()
my_domain.mark(subdomain,1 )
# dim V x dim V mass matrix with zero rows for basis functions
# with no support in subdomain
V = FunctionSpace(mesh,'CG',1)
u = TrialFunction(V)
v = TestFunction(V)
dx_sub = Measure('dx', domain=mesh, subdomain_id=1, subdomain_data=subdomain)
a = u*v*dx_sub
A = assemble(a)
A_ = A.array()
n_basis_in_sub = sum(1 for row in A_ if np.abs(row).sum() < DOLFIN_EPS)
print A_.shape, n_basis_in_sub
# mass matrix of space defined over subdomain
submesh = SubMesh(mesh, subdomain, 1)
V = FunctionSpace(submesh,'CG',1)
u = TrialFunction(V)
v = TestFunction(V)
a = u*v*dx
A = assemble(a)
A_ = A.array()
print A_.shape