How to visualize which part of mesh is with which processor
- Post by: U Meenu Krishnan
- January 22, 2021
- No Comment
How to do parallelization for loop in python with MPI is well explained in “” Blog.
This post will give you the answer for the next step i.e, how to visualise which part of mesh is with which processor. This can be easily done using the Mesh Function command in FEniCS.
I have explained this using a simple example.
- A rectangular mesh (.msh) is generated using Gmsh.
- Using “meshio-convert”, convert the .msh file to .xdmf file.
- We can identify the processor number by first getting a handle to the world communicator by using command.
comm = MPI.COMM_WORLD
- Then get the rank of the processor by using the command
rank = comm.Get_rank()
- The .xdmf file is imported in the FEniCS code.
mesh = Mesh()
with XDMFFile("rectangle.xdmf") as infile:
infile.read(mesh)
- A mesh function is created for the mesh.
mf =MeshFunction("size_t", mesh, 2)
- Mark the mesh function with the allotted rank of the processor.
mf.set_all(rank)
- Then we can write the mesh function in a xdmf file, which can be viewed using the Paraview.
xdmf = XDMFFile("output" + ".xdmf")
xdmf.write(mf)
xdmf.close()
- You can run the script using the command :
mpirun -np 2 python3 test.py
In this command “2” indicates the number of processor you are using to solve the problem.
- When the same script is using 6 processors to solve the problem using the command:
mpirun -np 6 python3 test.py
Categories: FEniCS, Finite element method, Research Tools
Tagged: FEniCS, Parrallel computation, visualization of mesh