Let's say I have a function with data in a CG2 Vector Function Space and would like to extract the values of the solution corresponding to the vertex dofs.
For simplicity, let's just define an Expression and interpolate the expression on both spaces:
from dolfin import *
mesh = UnitSquareMesh(32,32)
V = VectorFunctionSpace( mesh, "CG", 2 )
V_CG1 = VectorFunctionSpace( mesh, "CG", 1 )
vel_exp = Expression( ('1.0', '-1.0'), degree=1 )
vel = interpolate( vel_exp , V)
vel2 = interpolate( vel_exp , V_CG1)
Ideally, I'd like to be able to extract the vertex dofs from vel corresponding to the same values stored in vel2.
I was able to do this in serial by creating a map of the CG1 dof indices to the vertex CG2 indices:
import numpy as np
dofs = V.dofmap().dofs(mesh, 0)
dofs_CG1 = V_CG1.dofmap().dofs(mesh, 0)
n_dofs
Vdofs_vert = np.zeros( n_dofs, dtype = 'int' )
for i in xrange( n_dofs ):
j = dofs_CG1[i]
Vdofs_vert[j] = dofs[i]
And then vel.vector().array()[ Vdofs_vert ] would give the desired result. However this doesn't work in parallel since the global dof indices are returned with the dof maps.
Is there a simple way to do this in parallel? I would like to avoid using interpolate from CG2 to CG1 since it's slow and in my view, unnecessary.
Thanks!