How to solve local problem for each element cell of the mesh?

I want to use FEnicsx to implement multiscale method, suppose that we have a mesh, then for each cell K of such mesh, then for each basis functions \phi_{i} defined on K, we need to first refine K into finer mesh and use the finer meshes defined in K to solve L(\psi_{i})=-L(\phi_{i})$ and \psi_{i}=0 on the boundary of K, we have to store the value of \psi_{i} on the integration points for the finer meshes in K, how to do this?we need to solve this local functions for fine scale basis functions

You could use something along the lines of:

where you make a local assembler for lhs and rhs and solve for that (ref: Invert DG block diagonal matrix - #5 by rosilho)