This is a read only copy of the old FEniCS QA forum. Please visit the new QA forum to ask questions

import mesh with mpi, without partition it

0 votes

Hi there,

Fenics 2016.1 with mpi

So, when we want to create mesh to be used later to solve independent problems we use mpi_comm_self (then one mesh for each process):

if rank_process==0:
    mesh = UnitSquareMesh(mpi_comm_self(), 10, 10)
if rank_process==1:
    mesh = UnitSquareMesh(mpi_comm_self(), 20, 20)

Then, what is the syntax when i import a mesh (without partition it!)

In a first program (that runs in serial without mpi) i have created a mesh and its meshfunction

mesh_= BoxMesh(Point(0.0, 0.0, 0.0), Point(length_0, length_1, length_2), n_0, n_1,n_2)
subdomains_ = MeshFunction('size_t', mesh_, 3)

Then i have marked it

class OmegaA(SubDomain):
    def inside(self, x, on_boundary):
    ....
OmegaA().mark(subdomains_ , id_A)       
OmegaB().mark(subdomains_ , id_B)   

and then i have saved it:

File(Folder_Mesh_fenics + 'mesh.xml.gz') << mesh_
File(Folder_Mesh_fenics + 'mesh_function.xml.gz') << subdomains_ 

Now, i want I want to import mesh.xml.gz and mesh_function.xml.gz in a program with mpirun.
If i use the classic import symtax

mesh = Mesh(filepath)

Then the mesh is partitioned. I don't want this. I want to keep it unpartitioned.

# Instead of this:
mesh = Mesh(filepath_DOMAIN)
# Something like this:
if rank_process==0:
    mesh = Mesh(mpi_comm_self(),filepath)  # Does not work
if rank_process==1:
    mesh = Mesh(mpi_comm_self(),filepath) # Does not work

If you wander why, i want to run independent calculation on the two subdomain (using submesh)
PS: i already know submesh with mpi is not immediate to get, for what i have read in the forum -> this will be my next issue. For now, i just want to get correctly the import.

Thanks for any help.

asked Apr 14, 2017 by fussegli FEniCS Novice (700 points)

1 Answer

0 votes

The code i have written works actually...

if rank_process==0:
    mesh = Mesh(mpi_comm_self(),filepath)

is the good syntax (i thought it would not work) to import the mesh.

answered Apr 15, 2017 by fussegli FEniCS Novice (700 points)

However,

subdomains_ = MeshFunction('size_t', mesh, filepath_functions)

and

subdomains_ = MeshFunction(mpi_comm_self(),'size_t', mesh, filepath_functions)

do not work...
Any idea?

EDIT: once i can import subdomains_ i will try
https://fenicsproject.org/qa/7203/mpi-submesh-and-partitioning?show=7203#q7203

from cbcpost.utils import create_submesh
submesh_A = create_submesh(mesh, subdomains_, id_A)
submesh_B = create_submesh(mesh, subdomains_, id_B)
...