PyMFEM icon indicating copy to clipboard operation
PyMFEM copied to clipboard

Basic example from readme not working

Open jherkenhoff opened this issue 2 months ago • 3 comments

When trying to execute the example shown in the readme, I get the following error:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[5], [line 61](vscode-notebook-cell:?execution_count=5&line=61)
     58 import matplotlib.pyplot as plt
     59 import matplotlib.tri as tri
---> 61 triang = tri.Triangulation(verts[:,0], verts[:,1])
     63 fig, ax = plt.subplots()
     64 ax.set_aspect('equal')

TypeError: tuple indices must be integers or slices, not tuple

My versions:

  • Python: 3.12.3
  • PyMFEM: 4.8.0.1
  • Matplotlib: 3.10.1

jherkenhoff avatar Oct 23 '25 13:10 jherkenhoff

The problem: mesh.GetVertexArray() returns a tuple of 1D numpy arrays instead of a 2D numpy array. Thats why slicing [:, 0] does not work.

The example runs when replacing verts = mesh.GetVertexArray() with verts = np.array(mesh.GetVertexArray()). However, I think this should be considered only a hotfix, because the documentation states that it should return a 2D numpy array.

jherkenhoff avatar Oct 23 '25 13:10 jherkenhoff

Duplicate of #178

jherkenhoff avatar Oct 23 '25 13:10 jherkenhoff

@jherkenhoff Thank you for reminding this. I think the reason behind this is that the vertices data is not simple contiguous array data in MFEM, and it is nice to return an numpy array as a view to the original data (thus you can modify it if you need.). I will update the doc and example.

sshiraiwa avatar Oct 28 '25 14:10 sshiraiwa