Hi,
I want to assemble a bilinear form with trial and test function coming from a subspace of a function space $U$.
For instance assume we have a mesh $M$ with a submesh $Z\subset M$ and are looking for the subspace $U_Z \subset U$ spanned by all the basis functions in $U$ whose DoFs are associated to entities that are contained in the submesh $Z$.
The simplest concrete example is the CG1 function space with nodal basis on a mesh with boundary and $Z$ is the interior of $M$, so $U_Z$ corresponds to all functions whose DoFs are associated to the inner vertices of $M$. The assembly of a bilinear form with test and trial functions in $U_Z$ would then yield a matrix of size $(\dim U_Z)^2$.
Q: How to realize this in Fenics?
I'm thinking of a construction which allows me to specify a list of indices of the DoFs I'm interested in (which belong to $Z$) and pass it as an argument to the FunctionSpace
constructor:
Z_dofs = np.array([3,5,7])
# This is a fictional constructor
U_Z = FunctionSpace(mesh, 'Lagrange', 1, subspace = Z_dofs)
u = TrialFunction(U_Z)
...
Assembling a bilinear form over $U_Z$ would give a $3\times 3$ matrix in this example.
Clearly this is not possible at the moment, but is there some similar alternative?
Of course a brute force approach could loop through all relevant DoFs manually, construct u=Function(U)
and then set u.vector()
having zeros everywhere except for the current DoF to construct the matrix entry by entry. This seems not to be very smart though and is probably pretty slow for large meshes.
By the way this problem is already touched in the comments to this and that question but I'm not aware of a satisfying answer.
Thanks!