meshpro / optimesh

:spider_web: Mesh optimization, mesh smoothing.
575 stars 56 forks source link

IndexError: arrays used as indices must be of integer (or boolean) type #86

Closed lucascbarbosa closed 2 years ago

lucascbarbosa commented 2 years ago

I'm trying to test optimesh in an existent mesh I have but it is returning this error. I alre

Traceback (most recent call last):
  File "optimize_mesh.py", line 14, in <module>
    points, cells, "CVT (block-diagonal)", 1.0e-5, 100
  File "C:\Users\lucas\Anaconda3\envs\deeplearn37\lib\site-packages\optimesh\main.py", line 65, in optimize_points_cells
    optimize(mesh, method, *args, **kwargs)
  File "C:\Users\lucas\Anaconda3\envs\deeplearn37\lib\site-packages\optimesh\main.py", line 54, in optimize
    return _optimize(methods[method].get_new_points, mesh, *args, **kwargs)
  File "C:\Users\lucas\Anaconda3\envs\deeplearn37\lib\site-packages\optimesh\main.py", line 106, in _optimize
    new_points = get_new_points(mesh)
  File "C:\Users\lucas\Anaconda3\envs\deeplearn37\lib\site-packages\optimesh\cvt\block_diagonal.py", line 16, in get_new_points
    mask = np.any(mesh.ce_ratios < -0.5, axis=0)
  File "C:\Users\lucas\Anaconda3\envs\deeplearn37\lib\site-packages\meshplex\_mesh.py", line 290, in ce_ratios
    self.cell_partitions[0] / self.ei_dot_ei * 2 * (self.n - 1)
  File "C:\Users\lucas\Anaconda3\envs\deeplearn37\lib\site-packages\meshplex\_mesh.py", line 215, in cell_partitions
    self._compute_cell_values()
  File "C:\Users\lucas\Anaconda3\envs\deeplearn37\lib\site-packages\meshplex\_mesh.py", line 320, in _compute_cell_values
    e = self.points[self.idx[-1][..., mask]]
IndexError: arrays used as indices must be of integer (or boolean) type

The code:

import meshio
import numpy as np
import optimesh

path = 'C:/Users/lucas/OneDrive/Documentos/GitHub/INT/Manufatura Aditiva/Simulacao-GAN/Pipeline/2- Simulate_geometries/open-source/src/porosity_0.5273_theta_0.vtk'

mesh = meshio.read(path)

points = mesh.points
cells = mesh.cells

cells = np.asarray(cells,dtype='object')

points, cells = optimesh.optimize_points_cells(
    points, cells, "CVT (block-diagonal)", 1.0e-5, 100
)
nschloe commented 2 years ago

This has to go:

cells = np.asarray(cells,dtype='object')

optimesh only operates on triangular cells, so you need to extract those first.

lucascbarbosa commented 2 years ago

Still the same error but now with a warning above.

C:\Users\lucas\Anaconda3\envs\deeplearn37\lib\site-packages\optimesh\main.py:58: VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify 'dtype=object' when creating the ndarray.
  cells = np.asarray(cells)
Traceback (most recent call last):
  File "optimize_mesh.py", line 15, in <module>
    points, cells, "CVT (block-diagonal)", 1.0e-5, 100
  File "C:\Users\lucas\Anaconda3\envs\deeplearn37\lib\site-packages\optimesh\main.py", line 65, in optimize_points_cells
    optimize(mesh, method, *args, **kwargs)
  File "C:\Users\lucas\Anaconda3\envs\deeplearn37\lib\site-packages\optimesh\main.py", line 54, in optimize
    return _optimize(methods[method].get_new_points, mesh, *args, **kwargs)
  File "C:\Users\lucas\Anaconda3\envs\deeplearn37\lib\site-packages\optimesh\main.py", line 106, in _optimize
    new_points = get_new_points(mesh)
  File "C:\Users\lucas\Anaconda3\envs\deeplearn37\lib\site-packages\optimesh\cvt\block_diagonal.py", line 16, in get_new_points
    mask = np.any(mesh.ce_ratios < -0.5, axis=0)
  File "C:\Users\lucas\Anaconda3\envs\deeplearn37\lib\site-packages\meshplex\_mesh.py", line 290, in ce_ratios
    self.cell_partitions[0] / self.ei_dot_ei * 2 * (self.n - 1)
  File "C:\Users\lucas\Anaconda3\envs\deeplearn37\lib\site-packages\meshplex\_mesh.py", line 215, in cell_partitions
    self._compute_cell_values()
  File "C:\Users\lucas\Anaconda3\envs\deeplearn37\lib\site-packages\meshplex\_mesh.py", line 320, in _compute_cell_values
    e = self.points[self.idx[-1][..., mask]]
IndexError: arrays used as indices must be of integer (or boolean) type
nschloe commented 2 years ago

optimesh only operates on triangular cells, so you need to extract those first.

lucascbarbosa commented 2 years ago

Understood. I thought the mesh.cells did that, didn't it? How do I extract the cells correctly?

nschloe commented 2 years ago

You need to provide a numpy array with the triangle connectivity.