Hello,
I have an issue which I can’t figure out why it might be happening. The problem is as follows:
In an MPI parallelised code (For simplicity, lets says 2 processes P_0,P_1), suppose I have an array on each process A_0, A_1 which will always have a length matching the number of dofs and vertices on that process. (I will only be using CG1 elements so this should always hold true).
I also have two corresponding arrays which store the local vertex at which each value in A_k should lie on. Lets call these v_k.
Essentially, now I want to map the values of A_k onto a function u, but using v_k to ensure that they are mapped to the correct vertices.
If I am not mistaken, I can use vertex_to_dof_map
to do this. However, each time I have tried the vertex_to_dof_map
it gives me dof indices which are higher than that of the number of dofs owned by a process k.
Consider the MWI below:
from fenics import *
import numpy as np
# MPI communicator
comm = MPI.comm_world
rank = comm.Get_rank()
# Generate a mesh and functionspace
grid = RectangleMesh(Point(0,0),Point(10,10),10,10,"crossed")
V = FunctionSpace(grid,'CG',1)
u = Function(V)
# Connectivity
dofs = V.dofmap().dofs()
v2d = vertex_to_dof_map(V)
# Generate a random array on each process
A = np.random.uniform(0,1,len(dofs))
# Vertex mapping array
v = np.linspace(0,len(dofs)-1,len(dofs)).astype(int)
np.random.shuffle(v)
# Assign to the function vector
u.vector()[:] = A[v2d[v]]
The above code returns the errors (running with 2 processes):
IndexError: index 113 is out of bounds for axis 0 with size 109
IndexError: index 114 is out of bounds for axis 0 with size 112
If i investigate the ranges of the dofmap using:
print('Process:',rank,max(v2d),len(dofs),V.dofmap().ownership_range())
I get:
Process: 0 117 109 (0,109)
Process: 1 118 112 (109,221)
Clearly, some dof indices returned from vertex_to_dof_map
exceed that of the number of dofs on any process k - Am i missing something regarding the mapping used here? As far I as know, they should all be process (local) indices here and should work fine.
If run with 1 process, it all works out fine.
Any help would be greatly appreciated,
Thanks