Best way to project a vector onto fes.FreeDofs()?

Hi,

I am currently applying the projection onto the free dofs and computing a norm like this:

preI = Projector(mask=fes.FreeDofs(True), range=True)
tol_res_free = preI * tol_res
tol_res_norm = Norm(tol_res_free)

I also tried a more manual bitarray / mask approach:

freedofs = fes.FreeDofs(True)

free_mask = np.zeros(fes.ndof, dtype=bool)
for i in range(fes.ndof):
    free_mask[i] = freedofs[i]

tol_res_norm = np.linalg.norm(tol_res.FV().NumPy()[free_mask])

In my tests, the Projector version was actually faster.

I was wondering whether there is a simpler or more efficient built-in way to do the same projection directly from the BitArray returned by fes.FreeDofs(True), conceptually something like:

freedofs = fes.FreeDofs(True)
tol_res_free = freedofs * tol_res
tol_res_norm = Norm(tol_res_free)

Is there a different better way to apply the free-dof projection to a vector, or is Projector(mask=fes.FreeDofs(True), range=True) already the intended / best way to do it?

Thanks.

Projector is already what you intend to do. Just using a faster c++ loop than the python one.