Using tabulate_dof_coordinates in parallel

This is a method I wrote to find out a v2d map for a subspace, (i use fenics 2017.1.0). This works in serial, but i am unaware of how i can have the same thing with mpi. Any help would be appreciated.

def dofv_map(self, u_, W_):
    dim = W_.sub(0).dim()
    n = self.mesh.geometry().dim()
    u_coord = u_.function_space().tabulate_dof_coordinates().reshape(-1, n) 
    v_coord = self.mesh.coordinates().reshape((-1, n))

    lst_d2v = []
    for i, u in enumerate(u_coord):
        for j, v in enumerate(v_coord):
            if np.array_equal(u, v):
                lst_d2v.append((i, j))

    b = []
    for i in range(self.mesh.num_vertices()):
        for idx, tuple in enumerate(lst_d2v):
            if tuple[1] == i:
                b.append((i, lst_d2v[idx][0]))

    lst_v2d = []
    for i in range(len(b)/3):
        lst_v2d.append(b[3 * i][1] / 3)

    return lst_v2d

Pleaee supply a minimal reproducible example with enough variables to get a verifiable output of your code.

Thanks for your reply @dokken .
I have a sample code to share. I’m working with two meshes: mesh_m with a MixedFunctionSpace and the other with a VectorFunctionSpace - For simplicity, I’m using now the same mesh for both function spaces, but in reality, mesh_m with MixedFunctionSpace is a submesh of the other mesh (or in general all vertex/cell indices of mesh_m exist in the other). My goal is to establish a dof-to-dof mapping for the common vertex indices of the two mesh, all while ensuring MPI compatibility.

from dolfin import *
import numpy as np

import tabulate

nx = 5; ny = 5;
mesh_m = BoxMesh(Point(0, 0, 0), Point(1, 1, 1), 5, 5, 5)

P_m = VectorElement("CG", mesh_m.ufl_cell(), 2)
Q_m = FiniteElement("CG", mesh_m.ufl_cell(), 1)
R_m = MixedElement([P_m, Q_m])
W_m = FunctionSpace(mesh_m, R_m)

w_m = Function(W_m)
p_m, q_m = w_m.split(deepcopy=True)

dim = mesh_m.geometry().dim()

u_coord = p_m.function_space().tabulate_dof_coordinates().reshape(-1, dim)
v_coord = mesh_m.coordinates().reshape((-1, dim))

lst_d2v = []
for i, u in enumerate(u_coord):
    for j, v in enumerate(v_coord):
        if np.array_equal(u, v):
            lst_d2v.append((i, j))

b = []
for i in range(mesh_m.num_vertices()):
    for idx, tuple in enumerate(lst_d2v):
        if tuple[1] == i:
            b.append((i, lst_d2v[idx][0]))

lst_v2d = []
for i in range(len(b)/3):
    lst_v2d.append(b[3 * i][1] / 3)

# more generally, A_n is not defined on mesh_m, but will be on mesh where mesh_m \in mesh
A_n = VectorFunctionSpace(mesh_m, "CG", 1, dim=3)
a_n = Function(A_n)

v2d_map = vertex_to_dof_map(A_n)
v2d_map = v2d_map.reshape((-1, mesh_m.geometry().dim()))

map_dofs = []

for i in range(len(lst_v2d)):
    map_dofs.append((v2d_map[i][0] / 3, lst_v2d[i]))