From 56f38f16133ec9163d5f0a45fd5226233b547f87 Mon Sep 17 00:00:00 2001 From: Beppo <53090100+beppo-dd@users.noreply.github.com> Date: Tue, 12 Oct 2021 13:40:39 +0200 Subject: [PATCH 1/7] Result._plot_point_scalars: Use argument return_cpos in any case ... before, it was used only, when `if animate`. Now, it used in any case of the call `plotter.show`. --- ansys/mapdl/reader/rst.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/ansys/mapdl/reader/rst.py b/ansys/mapdl/reader/rst.py index 542e7bff..afcea604 100644 --- a/ansys/mapdl/reader/rst.py +++ b/ansys/mapdl/reader/rst.py @@ -2752,6 +2752,11 @@ def _plot_point_scalars(self, scalars, rnum=None, grid=None, result_text = self.text_result_table(rnum) plotter.add_text(result_text, font_size=20, color=text_color) + # camera position added in 0.32.0 + show_kwargs = {} + if pv._version.version_info[1] > 31: + show_kwargs['return_cpos'] = return_cpos + if animate: if off_screen: # otherwise this never exits loop = False @@ -2761,11 +2766,6 @@ def _plot_point_scalars(self, scalars, rnum=None, grid=None, orig_pts = copied_mesh.points.copy() - # camera position added in 0.32.0 - show_kwargs = {} - if pv._version.version_info[1] > 31: - show_kwargs['return_cpos'] = return_cpos - plotter.show(interactive=False, auto_close=False, window_size=window_size, full_screen=full_screen, @@ -2822,7 +2822,8 @@ def q_callback(): elif screenshot: cpos = plotter.show(auto_close=False, interactive=interactive, window_size=window_size, - full_screen=full_screen) + full_screen=full_screen, + **show_kwargs) if screenshot is True: img = plotter.screenshot() else: @@ -2832,7 +2833,8 @@ def q_callback(): else: cpos = plotter.show(interactive=interactive, window_size=window_size, - full_screen=full_screen) + full_screen=full_screen, + **show_kwargs) if screenshot is True: return cpos, img From d5ad42d4158643722f330f2d9bd28d9926c2b021 Mon Sep 17 00:00:00 2001 From: Beppo <53090100+beppo-dd@users.noreply.github.com> Date: Tue, 12 Oct 2021 13:54:10 +0200 Subject: [PATCH 2/7] Result._plot_point_scalars: fix screenshot function on Windows OS MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit pyvista\plotting\plotting.py:4882: On Windows OS "in the event that the user hits the exit-button on the GUI then it must be finalized and deleted as accessing it will kill the kernel... proper screenshots cannot be saved if this happens" Therefore, when you used ´_plot_point_scalars(..., screenshot=...)´, you got at ansys\mapdl\reader\rst.py:2830: ´RuntimeError: This plotter is closed and unable to save a screenshot.´ The only solution is, to pass the ´screenshot´ argument to ´plotter.show´ as done in this patch. --- ansys/mapdl/reader/rst.py | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/ansys/mapdl/reader/rst.py b/ansys/mapdl/reader/rst.py index afcea604..403ad33e 100644 --- a/ansys/mapdl/reader/rst.py +++ b/ansys/mapdl/reader/rst.py @@ -2819,21 +2819,18 @@ def q_callback(): plotter.close() cpos = plotter.camera_position - elif screenshot: - cpos = plotter.show(auto_close=False, interactive=interactive, - window_size=window_size, - full_screen=full_screen, - **show_kwargs) - if screenshot is True: - img = plotter.screenshot() - else: - plotter.screenshot(screenshot) - plotter.close() + elif screenshot is True: + cpos, img = plotter.show(interactive=interactive, + window_size=window_size, + full_screen=full_screen, + screenshot=screenshot, + **show_kwargs) else: cpos = plotter.show(interactive=interactive, window_size=window_size, full_screen=full_screen, + screenshot=screenshot, **show_kwargs) if screenshot is True: From 1c00879617ff152dcf9231a0ce8594da963ea73a Mon Sep 17 00:00:00 2001 From: Beppo <53090100+beppo-dd@users.noreply.github.com> Date: Tue, 12 Oct 2021 15:08:51 +0200 Subject: [PATCH 3/7] Result._plot_point_scalars: future-safe pyvista version check ... the old version would break with version 1.0.0. I used the same compare operation as in tested manually. --- ansys/mapdl/reader/rst.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ansys/mapdl/reader/rst.py b/ansys/mapdl/reader/rst.py index 403ad33e..05c03f85 100644 --- a/ansys/mapdl/reader/rst.py +++ b/ansys/mapdl/reader/rst.py @@ -2754,7 +2754,7 @@ def _plot_point_scalars(self, scalars, rnum=None, grid=None, # camera position added in 0.32.0 show_kwargs = {} - if pv._version.version_info[1] > 31: + if pv._version.version_info >= (0, 32, 0): show_kwargs['return_cpos'] = return_cpos if animate: From 62edb6a7781cb8dc757bf216b6d6082785342dbb Mon Sep 17 00:00:00 2001 From: Beppo <53090100+beppo-dd@users.noreply.github.com> Date: Wed, 13 Oct 2021 13:48:12 +0200 Subject: [PATCH 4/7] cython._binary_reader.cells_with_*_nodes: Generalize and simplify by 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! --- ansys/mapdl/reader/cython/_binary_reader.pyx | 38 ++++++-------------- ansys/mapdl/reader/rst.py | 4 +-- 2 files changed, 13 insertions(+), 29 deletions(-) diff --git a/ansys/mapdl/reader/cython/_binary_reader.pyx b/ansys/mapdl/reader/cython/_binary_reader.pyx index 9f666bf8..6c24bf6f 100644 --- a/ansys/mapdl/reader/cython/_binary_reader.pyx +++ b/ansys/mapdl/reader/cython/_binary_reader.pyx @@ -1638,35 +1638,22 @@ 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 @@ -1674,25 +1661,22 @@ def cells_with_all_nodes(index_type [::1] offset, index_type [::1] cells, 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 diff --git a/ansys/mapdl/reader/rst.py b/ansys/mapdl/reader/rst.py index 05c03f85..3f2d2cd4 100644 --- a/ansys/mapdl/reader/rst.py +++ b/ansys/mapdl/reader/rst.py @@ -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(): From ae3a88e8b61f41fb57508f02a55e520ed1fa63fc Mon Sep 17 00:00:00 2001 From: Beppo <53090100+beppo-dd@users.noreply.github.com> Date: Wed, 13 Oct 2021 14:14:07 +0200 Subject: [PATCH 5/7] cython._binary_reader.cells_with_*_nodes: correct expression for `ncells` --- ansys/mapdl/reader/cython/_binary_reader.pyx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ansys/mapdl/reader/cython/_binary_reader.pyx b/ansys/mapdl/reader/cython/_binary_reader.pyx index 6c24bf6f..44a76ea3 100644 --- a/ansys/mapdl/reader/cython/_binary_reader.pyx +++ b/ansys/mapdl/reader/cython/_binary_reader.pyx @@ -1644,7 +1644,7 @@ def cells_with_all_nodes(index_type [::1] offset, index_type [::1] cells, Updates mask of cells containing all points in the point indices or mask. """ - cdef int ncells = offset - 1 + cdef int ncells = offset.size - 1 cdef int i, j cdef index_type cell_offset, next_cell_offset cdef uint8 [::1] cell_mask = np.ones(ncells, np.uint8) @@ -1666,7 +1666,7 @@ def cells_with_any_nodes(index_type [::1] offset, index_type [::1] cells, Updates mask of cells containing at least one point in the point indices or mask. """ - cdef int ncells = offset - 1 + cdef int ncells = offset.size - 1 cdef index_type cell_offset, next_cell_offset cdef int i, j From 1c6351efedc61a0e1b6557c14ed83bf43c85bb5d Mon Sep 17 00:00:00 2001 From: Beppo <53090100+beppo-dd@users.noreply.github.com> Date: Mon, 25 Oct 2021 14:38:52 +0200 Subject: [PATCH 6/7] _binary.reader: _file_out does not exist When you called `AnsysFile.close()` you got at line 255 'ansys.mapdl.reader._binary_reader.AnsysFile' object has no attribute '_file_out' as `_file_out` is never created (this line is the only occurrence). --- ansys/mapdl/reader/cython/_binary_reader.pyx | 1 - 1 file changed, 1 deletion(-) diff --git a/ansys/mapdl/reader/cython/_binary_reader.pyx b/ansys/mapdl/reader/cython/_binary_reader.pyx index 44a76ea3..d8363a2b 100644 --- a/ansys/mapdl/reader/cython/_binary_reader.pyx +++ b/ansys/mapdl/reader/cython/_binary_reader.pyx @@ -252,7 +252,6 @@ cdef class AnsysFile: def close(self): """Close the file""" del self._file - del self._file_out def read_element_data(self, int64_t [::1] ele_ind_table, int table_index, int64_t ptr_off): From 3f6e296cb1180d6235380e68b546ec2f7d1985a1 Mon Sep 17 00:00:00 2001 From: Beppo <53090100+beppo-dd@users.noreply.github.com> Date: Tue, 26 Oct 2021 15:48:06 +0200 Subject: [PATCH 7/7] Result._plot_point_scalars: correct pyvista version check for version 0.32.dev0 The actual development version is 0.32.dev0: `pv._version.version_info = (0, 32, "dev0")`. There, the string `"dev0"` can not be compared with `0`, so that comparison failed for this version. To solve this, I removed the last element on the right-hand side expression of the comparison. The new comparison `(0, 32, "dev0") > (0, 32)` works now as expected. Tested manually. --- ansys/mapdl/reader/rst.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ansys/mapdl/reader/rst.py b/ansys/mapdl/reader/rst.py index 3f2d2cd4..758930de 100644 --- a/ansys/mapdl/reader/rst.py +++ b/ansys/mapdl/reader/rst.py @@ -2754,7 +2754,7 @@ def _plot_point_scalars(self, scalars, rnum=None, grid=None, # camera position added in 0.32.0 show_kwargs = {} - if pv._version.version_info >= (0, 32, 0): + if pv._version.version_info >= (0, 32): show_kwargs['return_cpos'] = return_cpos if animate: