I would need to access both the local and global mesh data from each MPI process when running FEniCS in parallel. I know that the easiest way to do so is to init two different meshes:
from fenics import * local_mesh = UnitSquareMesh(20, 20) global_mesh = UnitSquareMesh(MPI.comm_self, 20, 20)
However, I would like a function which allows me to get the global mesh directly from the local one, something like:
local_mesh = UnitSquareMesh(20, 20) global_mesh = get_global_mesh(local_mesh)
At the moment, the only way I found to do so is to save the local mesh to a temp file and to reload it for each process, like in the following:
def get_global_mesh(local_mesh): # create mesh file in temp folder tmp_folder = ".tmp" mesh_path_str = tmp_folder + "/mesh.xmdf" # create local mesh file local_mesh_xdmf = fenics.XDMFFile(mesh_path_str) # write mesh to file local_mesh_xdmf.write(local_mesh) # create global mesh file global_mesh_xdmf = fenics.XDMFFile(fenics.MPI.comm_self, mesh_path_str) # create global empty mesh global_mesh = fenics.Mesh(fenics.MPI.comm_self) # load global mesh from file global_mesh_xdmf.read(global_mesh) # remove temp file fenics.MPI.comm_world.Barrier() if fenics.MPI.comm_world.Get_rank() == 0: shutil.rmtree(tmp_folder) return global_mesh
However, I was wondering if there is a cleaner way to do the same. I didn’t find anything in the FEniCS documentation. Any idea?
Thank you in advance.