inducer / pymetis

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

part_mesh is not stable #61

Closed mbbatukan closed 11 months ago

mbbatukan commented 11 months ago

Describe the bug The program usually ends up with a Segmentation fault.

To Reproduce Steps to reproduce the behavior:

import pymetis
import matplotlib.pyplot as plt

#     6    8    7
#     -----------
#    /|\   |   /|\
#   / | \  |  / | \
#  /  |  \ | /  |  \
# /   |   \|/   |   \
# -------------------
# 1   2    3    4   5

# Define the nodes in the truss
nodes = list(range(1, 9))

# Define the connectivity of the truss
# Horizontal elements
horizontal_elements = [[1, 2], [2, 3], [3, 4], [4, 5], [6, 8], [8, 7]]
# Vertical elements
vertical_elements = [[2, 6], [3, 8], [4, 7]]
# Diagonal elements
diagonal_elements = [[1, 6], [6, 3], [3, 7], [7, 5]]

# Combine horizontal, vertical and diagonal elements
connectivity = horizontal_elements + vertical_elements + diagonal_elements

print(f"{connectivity = }")
n_parts = 2
# Partition the mesh
objval, epart, npart = pymetis.part_mesh(n_parts, connectivity, gtype=pymetis.GType.NODAL)
print(f"Number of edge cuts: {objval}")
print(f"Element partition indices: {epart}")
print(f"Vertex partition indices: {npart}")

Expected behavior should print out the following:

Number of edge cuts: 2
Element partition indices: [1, 1, 1, 0, 1, 0, 1, 1, 0, 1, 1, 0, 0]
Vertex partition indices: [0, 1, 1, 1, 0, 0, 1, 0]

but mostly returns this:

Segmentation fault

Environment (please complete the following information):

Additional context N/A

inducer commented 11 months ago

Your indices are 1-based from the look of them. meshpy expects zero-based indices.