inducer / pymetis

A Python wrapper around Metis, a graph partitioning package
http://mathema.tician.de/software/pymetis
Other
164 stars 32 forks source link

add the parameter `ncommon` to `pymetis.part_mesh()` function #57

Closed zhf-0 closed 1 year ago

zhf-0 commented 1 year ago

When using pymetis.part_mesh to partition the mesh based on element, the value of ncommon will severely influence the balance of each subdomain. Considering the following mesh

2 --- 5 --- 8
|     |     |
1 --- 4 --- 7
|     |     |
0 --- 3 --- 6

and the program is

mesh = np.array([[0, 3, 4, 1],
                 [1, 4, 5, 2],
                 [3, 6, 7, 4],
                 [4, 7, 8, 5]])
from pymetis._internal import GType
gtype = GType.DUAL
_, elem_idx_list, _ = pymetis.part_mesh(2, mesh, gtype=gtype)

The output of elem_idx_list is

[0, 0, 0, 0]

which means four elements are divided into one subdomain, while the correct division is 2 elements in each subdomain.

The explanation of ncommon from the manual of metis is

Specifies the number of common nodes that two elements must have in order to put an edge between them in the dual graph. Given two elements e_1 and e_2 , containing n_1 and n_2 nodes, respectively, then an edge will connect the vertices in the dual graph corresponding to e_1 and e_2 if the number of common nodes between them is greater than or equal to min(ncommon, n_1 − 1, n_2 − 1). The default value is 1, indicating that two elements will be connected via an edge as long as they share one node. However, this will tend to create too many edges (increasing the memory and time requirements of the partitioning). The user should select higher values that are better suited for the element types of the mesh that wants to partition. For example, for tetrahedron meshes, ncommon should be 3, which creates an edge between two tets when they share a triangular face (i.e., 3 nodes).

After adding the parameter, the program is

_, elem_idx_list, _ = pymetis.part_mesh(2, mesh, gtype=gtype, ncommon=2)

and the elem_idx_list is

[0, 1, 0, 1]

Therefore, this parameter ncommon should be exposed to the user for customized usage. I add ncommon as the parameter with default value 1, to keep the interface unchanged.

zhf-0 commented 1 year ago

I modified the format of the changes, please approve the checks.

zhf-0 commented 1 year ago

I re-checked the format with flake8.

zhf-0 commented 1 year ago

I re-checked the format of doc

inducer commented 1 year ago

Thanks!

zhf-0 commented 1 year ago

Hello, I want to ask when the updated version of pymetis will be uploaded to PyPi and conda repositories. I want to install pymetis on other computers and don't want to install all requirements to re-compile it.

inducer commented 1 year ago

I've just released 2023.1.1. It should be making its way to the package index before too long.

zhf-0 commented 1 year ago

Thank you very much!