Compress Gridfunction from base space to compressed space


the setting of my problem is the following:
I have a finite element space V_base defined on the whole mesh and a compressed space V_comp = Compress(V_base, active_dofs) on some DOFs given by the Bitarray active_dofs. On the base space, there is a gridfunction gf_base and I need it to be defined on the compressed space. Thus, I only want to delete some of the entries in the coefficient vector (the ones not marked by active_dofs).

Is there an efficient way for doing this?

At the moment I use the workaround of taking the numpy vector and creating a masked vector with the Bitarray:

gf_comp.vec.FV().NumPy()[:] = gf_base.vec.FV().NumPy()[active_dofs]

But this seems to be inefficient since the vector is copied everytime. I need this feature several times in each time step in my example. That’s why I’am looking for a more efficient way to solve it.

I also tried the ConvertOperator but since my space changes in each time step, I would have to create the ConvertMatrix in each time step (I havn’t found an Update functionallity) and this is also time and memory expensive.

Thanks for your help!