[teaching] add method to get dirichlet dof indices from space
On the Python side it might be nice to get access to the indices of the Dirichlet dofs from the space. It is possible now to get that from the 'scheme' but always as blocks which makes extracting the indices a bit cumbersome to explain:
db = np.array( scheme.dirichletBlocks ).flatten # these are blocked based on the local block size
dirichletIdx = np.where( db >= 0 ) # indices of all dirichlet dofs
This could perhaps be easily added to the space directly, e.g.,
dirichletIdx = space.dirichletDofs
The resulting indices simplifies implementing Dirichlet treatment when for example using scipy
:
chi_interior = np.ones(N)
chi_interior[dirichletIdx] = 0.0
I_interior = sps.spdiags(chi_interior, [0], N, N).tocsr()
chi_boundary = np.zeros(N)
chi_boundary[dirichletIdx] = 1
I_boundary = sps.spdiags(chi_boundary, [0], N, N).tocsr()
matrix_modified = I_interior * matrix + I_boundary
# for symmetric treatment use I_interior * matrix * I_interior + I_boundary
Or something like that.