I have the following setup. I have two finite element spaces, T_h and T_H. The mesh of T_h is a true refinement of the mesh of T_H. Also, T_h uses a cg Lagrange basis of degree one, while T_H uses a dg Legendre basis of degree 2. I now want to calculate the mass matrix M between these two meshes, meaning
M_{i,j} = \int_\Omega \varphi_i \psi_j \, dx
where \varphi_i is the i-th basis function of the coarse space and \psi_j is the j-th basis function of the fine space.
As far as I understand this, this is only possible using interpolation on non-matching meshes since the functions must be defined on the same mesh for the dolfinx forms to work. Is there another option? For example, using the cell data from the refinement for some the calculation of some sort of prolongation matrix, to transform the normal mass matrix of the fine space into the matrix I am looking for?
youre right that the interpolation route is the way to go, and since your fine mesh is a true refinement you can make it exact. what youre calling the prolongation matrix is exactly the interpolation operator P, and then M = P^T M_fine.
one subtlety though: if you interpolate the coarse DG2 function straight into the fine CG1 space you lose the quadratic part, so the result would carry an interpolation error. instead interpolate the coarse function into a DG2 space built on the fine mesh first. that step is exact, because each coarse cell’s polynomial is exactly representable on its children. then assemble the mixed mass matrix between that fine DG2 space and your fine CG1 space on the fine mesh (bump the quadrature degree so the degree-3 product integrates exactly), and form M = P^T M_mixed.
the building block is create_nonmatching_meshes_interpolation_data, which handles the refined-mesh case fine. P can be applied matrix-free or assembled from the interpolation data.