1)
#mesh.init(j, k) # this may be needed for some j, k
boundary_adjacent_cells = [c for c in cells(mesh)
if any(f.exterior() for f in facets(v)
for v in vertices(c))]
2)
cell_domains = CellFunction('size_t', mesh)
#cell_domains.set_all(0) # needed in older versions of DOLFIN
for c in boundary_adjacent_cells:
cell_domains[c] = 42
# for example
foo = assemble(qux*dx(42), cell_domains=cell_domains)
# or any other DOLFIN function doing assembly,
# taking cell_domains argument
# e.g. solve(), FooSolver.solve(), ...
# or we can define measure
dxb = Measure('dx')[cell_domains]
If you're asking how to avoid restricted problem being singular, one possibility is to eliminate null space using DirichletBC
which is little tricky. There is also probably more efficient and cleaner Restriction
functionality but is not polished yet - see restriction
demo.