Skip to content

Commit

Permalink
cython._binary_reader.cells_with_*_nodes: Generalize and simplify by …
Browse files Browse the repository at this point in the history
…directly using `offset` for next cell offset

- Therefore the function `cell_lookup`, which was limited to 3D cells, is no longer necessary.
- Now, all cell types are supported, while the functions has even been simplified.
- Now, the functions do not need the parameter `celltypes` any more. Since they are only used in rst.py in the private method `Result._extract_node_components`, I took the liberty to remove the parameter A in the respective definition und the respective call.

Remark: Only tested with a pure python version of the functions, please test the cython function of the commit!
  • Loading branch information
beppo-dd committed Oct 13, 2021
1 parent 1c00879 commit 62edb6a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 29 deletions.
38 changes: 11 additions & 27 deletions ansys/mapdl/reader/cython/_binary_reader.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1638,61 +1638,45 @@ def affline_transform(float_or_double [:, ::1] points, float_or_double [:, ::1]
points[i, 2] = t20*x + t21*y + t22*z + t23


cdef inline int cell_lookup(uint8 celltype) nogil:
if celltype == VTK_HEXAHEDRON or celltype == VTK_QUADRATIC_HEXAHEDRON:
return 8
elif celltype == VTK_TETRA or celltype == VTK_QUADRATIC_TETRA:
return 4
elif celltype == VTK_PYRAMID or celltype == VTK_QUADRATIC_PYRAMID:
return 5
elif celltype == VTK_WEDGE or celltype == VTK_QUADRATIC_WEDGE:
return 6


def cells_with_all_nodes(index_type [::1] offset, index_type [::1] cells,
uint8 [::1] celltypes, uint8 [::1] point_mask):
uint8 [::1] point_mask):
"""
Updates mask of cells containing all points in the point indices
or mask.
"""
cdef int ncells = celltypes.size
cdef uint8 celltype
cdef int ncell_points, i, j
cdef index_type cell_offset
cdef int ncells = offset - 1
cdef int i, j
cdef index_type cell_offset, next_cell_offset
cdef uint8 [::1] cell_mask = np.ones(ncells, np.uint8)

with nogil:
for i in range(ncells):
celltype = celltypes[i]
ncell_points = cell_lookup(celltype)
cell_offset = offset[i] + 1
for j in range(cell_offset, cell_offset + ncell_points):
next_cell_offset = offset[i+1] + 1
for j in range(cell_offset, next_cell_offset):
if point_mask[cells[j]] != 1:
cell_mask[i] = 0

return np.asarray(cell_mask, dtype=np.bool)


def cells_with_any_nodes(index_type [::1] offset, index_type [::1] cells,
uint8 [::1] celltypes, uint8 [::1] point_mask):
uint8 [::1] point_mask):
"""
Updates mask of cells containing at least one point in the point
indices or mask.
"""
cdef int ncells = celltypes.size
cdef uint8 celltype
cdef int ncell_points
cdef index_type cell_offset
cdef int ncells = offset - 1
cdef index_type cell_offset, next_cell_offset
cdef int i, j

cdef uint8 [::1] cell_mask = np.zeros(ncells, np.uint8)

with nogil:
for i in range(ncells):
celltype = celltypes[i]
ncell_points = cell_lookup(celltype)
cell_offset = offset[i] + 1
for j in range(cell_offset, cell_offset + ncell_points):
next_cell_offset = offset[i+1] + 1
for j in range(cell_offset, next_cell_offset):
if point_mask[cells[j]] == 1:
cell_mask[i] = 1
break
Expand Down
4 changes: 2 additions & 2 deletions ansys/mapdl/reader/rst.py
Original file line number Diff line number Diff line change
Expand Up @@ -723,10 +723,10 @@ def _extract_node_components(self, node_components,
# need to extract the mesh
cells, offset = vtk_cell_info(grid)
if sel_type_all:
cell_mask = cells_with_all_nodes(offset, cells, grid.celltypes,
cell_mask = cells_with_all_nodes(offset, cells,
mask.view(np.uint8))
else:
cell_mask = cells_with_any_nodes(offset, cells, grid.celltypes,
cell_mask = cells_with_any_nodes(offset, cells,
mask.view(np.uint8))

if not cell_mask.any():
Expand Down

0 comments on commit 62edb6a

Please sign in to comment.