Hi,
I have code that has two identical meshes. I move one of them and solve a problem on it. Now I need to map back the solution to the mesh that I didn’t move. I have a simple code attached below that works fine in series. But when I use a parallel run even with 2 processes it gives me the attached error. I think it is because the process break the two meshes differently. Could you please help me fix this code to work for the parallel case?
from fenics import *
import numpy as np
#Defining two identical meshes
mesh1 = UnitSquareMesh(20,20) #we move this one
mesh2 = UnitSquareMesh(20,20) #we keep this one as the reference mesh
#See what the
File('test/ref_mesh.pvd')<<mesh1
#function spaces on the two meshes
V_1 = VectorFunctionSpace(mesh1,'P',1)
V_2 = VectorFunctionSpace(mesh2,'P',1)
W_1 = FunctionSpace(mesh1,'P',1)
W_2 = FunctionSpace(mesh2,'P',1)
#defining a vector to move mesh1 with
u = Expression(('sin(x[0])','cos(x[0])'),degree=0)
#Move mesh 1
ALE.move(mesh1,u)
#see what the moved mesh looks like
File('test/moved_mesh.pvd')<<mesh1
#Defining dof to vertex and vertex to dof maps for moved and reference regions
dof2v_W_1 = np.array(dof_to_vertex_map(W_1), dtype=int)
dof2v_W_2 = np.array(dof_to_vertex_map(W_2), dtype=int)
v2dof_W_1 = np.array(vertex_to_dof_map(W_1), dtype=int)
v2dof_W_2 = np.array(vertex_to_dof_map(W_2), dtype=int)
#defining the problem variables
p1 = Function(W_1)
v1 = TestFunction(W_1)
p0 = Expression('x[1]*x[1]+x[0]*x[0]',degree=0) #initial condition
p1 = interpolate(p0,W_1)
#the weak form and solution in the moved mesh
F = dot(grad(p1),grad(v1))*dx-p1*v1*dx
solve(F==0,p1)
#the solution in the moved mesh
File('test/P_in_moved_mesh.pvd')<< p1
#Define the function p2 on the reference domain and put its values in an auxillary vector Array
p2 = Function(W_2)
Array = p2.vector().get_local()
#set the values of the auxillary vector equal to the values of p1 from the moved mesh using the dof maps
Array[v2dof_W_2[dof2v_W_1]] = p1.vector().get_local()
#Let p2 be the solution p1 but mapped backed into the reference domain
p2.vector()[:]=Array
#see the result
File('test/P_in_ref_mesh.pvd')<< p2
And the error is:
Traceback (most recent call last):
File “test.py”, line 54, in
Traceback (most recent call last):
File “test.py”, line 54, in
Array[v2dof_W_2[dof2v_W_1]] = p1.vector().get_local()
Array[v2dof_W_2[dof2v_W_1]] = p1.vector().get_local()
ValueError: shape mismatch: value array of shape (223,) could not be broadcast to indexing result of shape (233,)
ValueError: shape mismatch: value array of shape (218,) could not be broadcast to indexing result of shape (229,)
--------------------------------------------------------------------------
mpirun noticed that process rank 0 with PID 8367 on node user1-HP-EliteBook-8470p exited on signal 6 (Aborted).