@@ -227,13 +227,16 @@ cdef class AnsysFile:
227227 # self._file = new ifstream(c_filename, binary)
228228 self ._file = open_fstream(c_filename)
229229
230- # def _read(self, int size):
231- # cdef char raw[10000]
232- # self._file_a.read(raw, size)
233- # return raw[:size]
230+ def _read (self , int size ):
231+ mx_sz = 10000
232+ if size > mx_sz:
233+ raise RuntimeError (f" Maximum read size is {mx_sz}" )
234+ cdef char raw[10000 ]
235+ self ._file.read(raw, size)
236+ return raw[:size]
234237
235- # def _seekg(self, int index):
236- # self._file_a .seekg(index)
238+ def _seekg (self , int index ):
239+ self ._file .seekg(index)
237240
238241 def read_record (self , int64_t ptr , int return_bufsize = 0 ):
239242 """ Read a record from the opened file"""
@@ -246,13 +249,11 @@ cdef class AnsysFile:
246249
247250 if return_bufsize:
248251 return ndarray, bufsize
249- else :
250- return ndarray
252+ return ndarray
251253
252254 def close (self ):
253255 """ Close the file"""
254256 del self ._file
255- del self ._file_out
256257
257258 def read_element_data (self , int64_t [::1] ele_ind_table , int table_index ,
258259 int64_t ptr_off ):
@@ -1638,61 +1639,45 @@ def affline_transform(float_or_double [:, ::1] points, float_or_double [:, ::1]
16381639 points[i, 2 ] = t20* x + t21* y + t22* z + t23
16391640
16401641
1641- cdef inline int cell_lookup(uint8 celltype) nogil:
1642- if celltype == VTK_HEXAHEDRON or celltype == VTK_QUADRATIC_HEXAHEDRON:
1643- return 8
1644- elif celltype == VTK_TETRA or celltype == VTK_QUADRATIC_TETRA:
1645- return 4
1646- elif celltype == VTK_PYRAMID or celltype == VTK_QUADRATIC_PYRAMID:
1647- return 5
1648- elif celltype == VTK_WEDGE or celltype == VTK_QUADRATIC_WEDGE:
1649- return 6
1650-
1651-
16521642def cells_with_all_nodes (index_type [::1] offset , index_type [::1] cells ,
1653- uint8 [::1] celltypes , uint8 [::1] point_mask ):
1643+ uint8 [::1] point_mask ):
16541644 """
16551645 Updates mask of cells containing all points in the point indices
16561646 or mask.
16571647 """
1658- cdef int ncells = celltypes.size
1659- cdef uint8 celltype
1660- cdef int ncell_points, i, j
1661- cdef index_type cell_offset
1648+ cdef int ncells = offset.size - 1
1649+ cdef int i, j
1650+ cdef index_type cell_offset, next_cell_offset
16621651 cdef uint8 [::1 ] cell_mask = np.ones(ncells, np.uint8)
16631652
16641653 with nogil:
16651654 for i in range (ncells):
1666- celltype = celltypes[i]
1667- ncell_points = cell_lookup(celltype)
16681655 cell_offset = offset[i] + 1
1669- for j in range (cell_offset, cell_offset + ncell_points):
1656+ next_cell_offset = offset[i+ 1 ] + 1
1657+ for j in range (cell_offset, next_cell_offset):
16701658 if point_mask[cells[j]] != 1 :
16711659 cell_mask[i] = 0
16721660
16731661 return np.asarray(cell_mask, dtype = np.bool)
16741662
16751663
16761664def cells_with_any_nodes (index_type [::1] offset , index_type [::1] cells ,
1677- uint8 [::1] celltypes , uint8 [::1] point_mask ):
1665+ uint8 [::1] point_mask ):
16781666 """
16791667 Updates mask of cells containing at least one point in the point
16801668 indices or mask.
16811669 """
1682- cdef int ncells = celltypes.size
1683- cdef uint8 celltype
1684- cdef int ncell_points
1685- cdef index_type cell_offset
1670+ cdef int ncells = offset.size - 1
1671+ cdef index_type cell_offset, next_cell_offset
16861672 cdef int i, j
16871673
16881674 cdef uint8 [::1 ] cell_mask = np.zeros(ncells, np.uint8)
16891675
16901676 with nogil:
16911677 for i in range (ncells):
1692- celltype = celltypes[i]
1693- ncell_points = cell_lookup(celltype)
16941678 cell_offset = offset[i] + 1
1695- for j in range (cell_offset, cell_offset + ncell_points):
1679+ next_cell_offset = offset[i+ 1 ] + 1
1680+ for j in range (cell_offset, next_cell_offset):
16961681 if point_mask[cells[j]] == 1 :
16971682 cell_mask[i] = 1
16981683 break
0 commit comments