From 3d3b98b6295ce39802bf3d2da992932ebaf386c5 Mon Sep 17 00:00:00 2001 From: "paul.profizi" Date: Tue, 18 Apr 2023 10:24:00 +0200 Subject: [PATCH 01/26] WIP --- src/ansys/dpf/core/vtk_helper.py | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/src/ansys/dpf/core/vtk_helper.py b/src/ansys/dpf/core/vtk_helper.py index db9cd33e23..92a7ef8584 100644 --- a/src/ansys/dpf/core/vtk_helper.py +++ b/src/ansys/dpf/core/vtk_helper.py @@ -171,7 +171,7 @@ def dpf_mesh_to_vtk_py(mesh, nodes, as_linear): Meshed Region to export to pyVista format nodes : dpf.Field - Field containing the nodes of the mesh. + Field containing the node coordinates of the mesh. as_linear : bool Export quadratic surface elements as linear. @@ -184,9 +184,9 @@ def dpf_mesh_to_vtk_py(mesh, nodes, as_linear): etypes = mesh.elements.element_types_field.data connectivity = mesh.elements.connectivities_field if nodes is None: - nodes = mesh.nodes.coordinates_field.data + node_coordinates = mesh.nodes.coordinates_field.data else: - nodes = nodes.data + node_coordinates = nodes.data elem_size = np.ediff1d(np.append(connectivity._data_pointer, connectivity.shape)) @@ -204,9 +204,12 @@ def dpf_mesh_to_vtk_py(mesh, nodes, as_linear): # Handle semiparabolic elements nullmask = connectivity.data == -1 - connectivity.data[nullmask] = 0 + # connectivity.data[nullmask] = 0 + # if nullmask.any(): + # nodes[0] = np.nan if nullmask.any(): - nodes[0] = np.nan + repeated_data_pointers = connectivity._data_pointer.repeat(repeats=elem_size) + connectivity.data[nullmask] = connectivity.data[repeated_data_pointers[nullmask]] # For each polyhedron, cell = [nCellFaces, nFace0pts, i, j, k, ..., nFace1pts, i, j, k, ...] # polys_ind = insert_ind[polyhedron_mask] @@ -217,7 +220,7 @@ def dpf_mesh_to_vtk_py(mesh, nodes, as_linear): # Check if polyhedrons are present if element_types.Polyhedron.value in etypes: cells = np.array(cells) - nodes = np.array(nodes) + nodes = np.array(node_coordinates) insert_ind = insert_ind + np.asarray(list(range(len(insert_ind)))) # Replace in cells values for polyhedron format # [NValuesToFollow, @@ -249,6 +252,7 @@ def compute_offset(): # convert kAns to VTK cell type offset = None + as_linear = False if as_linear: vtk_cell_type = VTK_LINEAR_MAPPING[etypes] @@ -256,7 +260,7 @@ def compute_offset(): ansquad8_mask = etypes == 6 if np.any(ansquad8_mask): # kAnsQuad8 - # simply copy the edge node indices to the midside points + # simply copy the edge node indices to the mid-side points offset = compute_offset() cell_pos = offset[ansquad8_mask] cells[cell_pos + 5] = cells[cell_pos + 1] @@ -275,17 +279,22 @@ def compute_offset(): else: vtk_cell_type = VTK_MAPPING[etypes] + # visualization bug within VTK with quadratic surf cells + ansquad8_mask = etypes == 6 + if np.any(ansquad8_mask): # kAnsQuad8 + pass # different treatment depending on the version of vtk if VTK9: # compute offset array when < VTK v9 - return pv.UnstructuredGrid(cells, vtk_cell_type, nodes) + grid = pv.UnstructuredGrid(cells, vtk_cell_type, node_coordinates) + return grid # might be computed when checking for VTK quadratic bug if offset is None: offset = compute_offset() - return pv.UnstructuredGrid(offset, cells, vtk_cell_type, nodes) + return pv.UnstructuredGrid(offset, cells, vtk_cell_type, node_coordinates) def dpf_mesh_to_vtk(mesh, nodes=None, as_linear=True): From e6a13ec5e220a595b05d5ebe4a1c0fc19e74db1e Mon Sep 17 00:00:00 2001 From: "paul.profizi" Date: Tue, 18 Apr 2023 12:20:18 +0200 Subject: [PATCH 02/26] Modified as_linear for quad8 to really transform them to quad4 --- src/ansys/dpf/core/vtk_helper.py | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/src/ansys/dpf/core/vtk_helper.py b/src/ansys/dpf/core/vtk_helper.py index 92a7ef8584..1be7d12802 100644 --- a/src/ansys/dpf/core/vtk_helper.py +++ b/src/ansys/dpf/core/vtk_helper.py @@ -252,21 +252,26 @@ def compute_offset(): # convert kAns to VTK cell type offset = None - as_linear = False + as_linear = True if as_linear: + # Map the vtk_cell_type to linear versions of the initial elements types vtk_cell_type = VTK_LINEAR_MAPPING[etypes] - # visualization bug within VTK with quadratic surf cells - ansquad8_mask = etypes == 6 - if np.any(ansquad8_mask): # kAnsQuad8 - - # simply copy the edge node indices to the mid-side points - offset = compute_offset() - cell_pos = offset[ansquad8_mask] - cells[cell_pos + 5] = cells[cell_pos + 1] - cells[cell_pos + 6] = cells[cell_pos + 2] - cells[cell_pos + 7] = cells[cell_pos + 3] - cells[cell_pos + 8] = cells[cell_pos + 4] + # Create a global mask of connectivity values to take + mask = np.full(cells.shape, False) + mask[compute_offset()] = True + # Get a mask of quad8 elements in etypes + quad8_mask = etypes == 6 + # If any quad8 + if np.any(quad8_mask): # kAnsQuad8 + # Get the starting indices of quad8 elements in cells + insert_ind_quad8 = insert_ind[quad8_mask] + insert_ind_quad8 += np.arange(insert_ind_quad8.size) + mask[insert_ind_quad8 + 1] = True + mask[insert_ind_quad8 + 2] = True + mask[insert_ind_quad8 + 3] = True + mask[insert_ind_quad8 + 4] = True + cells[insert_ind_quad8] //= 2 anstri6_mask = etypes == 4 # kAnsTri6 = 4 if np.any(anstri6_mask): @@ -277,6 +282,8 @@ def compute_offset(): cells[cell_pos + 5] = cells[cell_pos + 2] cells[cell_pos + 6] = cells[cell_pos + 3] + cells = cells[mask] + else: vtk_cell_type = VTK_MAPPING[etypes] # visualization bug within VTK with quadratic surf cells From d6f9c5f95b04084693e9d70a60b29d350eae80c0 Mon Sep 17 00:00:00 2001 From: "paul.profizi" Date: Tue, 18 Apr 2023 15:46:21 +0200 Subject: [PATCH 03/26] Fix as_linear=True --- src/ansys/dpf/core/meshed_region.py | 1 + src/ansys/dpf/core/plotter.py | 30 ++++++++++++++++++++++++----- src/ansys/dpf/core/vtk_helper.py | 29 ++++++++++------------------ 3 files changed, 36 insertions(+), 24 deletions(-) diff --git a/src/ansys/dpf/core/meshed_region.py b/src/ansys/dpf/core/meshed_region.py index 05d6e84eec..06361197fd 100644 --- a/src/ansys/dpf/core/meshed_region.py +++ b/src/ansys/dpf/core/meshed_region.py @@ -108,6 +108,7 @@ def __init__(self, num_nodes=None, num_elements=None, mesh=None, server=None): self._full_grid = None self._elements = None self._nodes = None + self.as_linear = None def _get_scoping(self, loc=locations.nodal): """ diff --git a/src/ansys/dpf/core/plotter.py b/src/ansys/dpf/core/plotter.py index cfa043a8c8..8bfcc5d658 100644 --- a/src/ansys/dpf/core/plotter.py +++ b/src/ansys/dpf/core/plotter.py @@ -125,7 +125,7 @@ def add_plane(self, plane, field=None, **kwargs): plane[f"{field.name}"] = field.data self._plotter.add_mesh(plane_plot, **kwargs) - def add_mesh(self, meshed_region, deform_by=None, scale_factor=1.0, **kwargs): + def add_mesh(self, meshed_region, deform_by=None, scale_factor=1.0, as_linear=True, **kwargs): kwargs = self._set_scalar_bar_title(kwargs) @@ -144,9 +144,17 @@ def add_mesh(self, meshed_region, deform_by=None, scale_factor=1.0, **kwargs): # otherwise we get two scalar bars when calling several plot_contour on the same mesh # but not for the same field. The PyVista UnstructuredGrid keeps memory of it. if not deform_by: - grid = meshed_region.grid + if as_linear != meshed_region.as_linear: + grid = meshed_region._as_vtk( + meshed_region.nodes.coordinates_field, as_linear=as_linear + ) + meshed_region.as_linear = as_linear + else: + grid = meshed_region.grid else: - grid = meshed_region._as_vtk(meshed_region.deform_by(deform_by, scale_factor)) + grid = meshed_region._as_vtk( + meshed_region.deform_by(deform_by, scale_factor), as_linear=as_linear + ) # show axes show_axes = kwargs.pop("show_axes", None) @@ -228,6 +236,7 @@ def add_field( deform_by=None, scale_factor=1.0, scale_factor_legend=None, + as_linear=True, **kwargs, ): # Get the field name @@ -276,7 +285,9 @@ def add_field( if not deform_by: grid = meshed_region.grid else: - grid = meshed_region._as_vtk(meshed_region.deform_by(deform_by, scale_factor)) + grid = meshed_region._as_vtk( + meshed_region.deform_by(deform_by, scale_factor, as_linear) + ) grid.set_active_scalars(None) self._plotter.add_mesh(grid, scalars=overall_data, **kwargs_in) @@ -448,7 +459,7 @@ def add_line(self, points, field=None, **kwargs): def add_plane(self, plane, field=None, **kwargs): self._internal_plotter.add_plane(plane, field, **kwargs) - def add_mesh(self, meshed_region, deform_by=None, scale_factor=1.0, **kwargs): + def add_mesh(self, meshed_region, deform_by=None, scale_factor=1.0, as_linear=True, **kwargs): """Add a mesh to plot. Parameters @@ -460,6 +471,9 @@ def add_mesh(self, meshed_region, deform_by=None, scale_factor=1.0, **kwargs): Defaults to None. scale_factor : float, optional Scaling factor to apply when warping the mesh. Defaults to 1.0. + as_linear : bool, optional + Whether to show quadratic elements as their linear equivalents (for faster rendering). + Defaults to ``True``. **kwargs : optional Additional keyword arguments for the plotter. More information are available at :func:`pyvista.plot`. @@ -481,6 +495,7 @@ def add_mesh(self, meshed_region, deform_by=None, scale_factor=1.0, **kwargs): meshed_region=meshed_region, deform_by=deform_by, scale_factor=scale_factor, + as_linear=as_linear, **kwargs, ) @@ -494,6 +509,7 @@ def add_field( label_point_size=20, deform_by=None, scale_factor=1.0, + as_linear=True, **kwargs, ): """Add a field containing data to the plotter. @@ -518,6 +534,9 @@ def add_field( Defaults to None. scale_factor : float, optional Scaling factor to apply when warping the mesh. Defaults to 1.0. + as_linear : bool, optional + Whether to show quadratic elements as their linear equivalents (for faster rendering). + Defaults to ``True``. **kwargs : optional Additional keyword arguments for the plotter. More information are available at :func:`pyvista.plot`. @@ -543,6 +562,7 @@ def add_field( label_point_size=label_point_size, deform_by=deform_by, scale_factor=scale_factor, + as_linear=as_linear, **kwargs, ) diff --git a/src/ansys/dpf/core/vtk_helper.py b/src/ansys/dpf/core/vtk_helper.py index 1be7d12802..ff1af4bdfd 100644 --- a/src/ansys/dpf/core/vtk_helper.py +++ b/src/ansys/dpf/core/vtk_helper.py @@ -204,16 +204,10 @@ def dpf_mesh_to_vtk_py(mesh, nodes, as_linear): # Handle semiparabolic elements nullmask = connectivity.data == -1 - # connectivity.data[nullmask] = 0 - # if nullmask.any(): - # nodes[0] = np.nan if nullmask.any(): repeated_data_pointers = connectivity._data_pointer.repeat(repeats=elem_size) connectivity.data[nullmask] = connectivity.data[repeated_data_pointers[nullmask]] - # For each polyhedron, cell = [nCellFaces, nFace0pts, i, j, k, ..., nFace1pts, i, j, k, ...] - # polys_ind = insert_ind[polyhedron_mask] - # cells = np.take(cells, sorted(set(insert_ind)-set(polys_ind))) # partition cells in vtk format cells = np.insert(connectivity.data, insert_ind, elem_size) @@ -252,7 +246,6 @@ def compute_offset(): # convert kAns to VTK cell type offset = None - as_linear = True if as_linear: # Map the vtk_cell_type to linear versions of the initial elements types vtk_cell_type = VTK_LINEAR_MAPPING[etypes] @@ -273,23 +266,21 @@ def compute_offset(): mask[insert_ind_quad8 + 4] = True cells[insert_ind_quad8] //= 2 - anstri6_mask = etypes == 4 # kAnsTri6 = 4 - if np.any(anstri6_mask): - if offset is None: - offset = compute_offset() - cell_pos = offset[anstri6_mask] - cells[cell_pos + 4] = cells[cell_pos + 1] - cells[cell_pos + 5] = cells[cell_pos + 2] - cells[cell_pos + 6] = cells[cell_pos + 3] + tri6_mask = etypes == 4 # kAnsTri6 = 4 + if np.any(tri6_mask): + insert_ind_tri6 = insert_ind[tri6_mask] + insert_ind_tri6 += np.arange(insert_ind_tri6.size) + mask[insert_ind_tri6 + 1] = True + mask[insert_ind_tri6 + 2] = True + mask[insert_ind_tri6 + 3] = True + cells[insert_ind_tri6] //= 2 cells = cells[mask] + insert_ind_mask = quad8_mask + tri6_mask + insert_ind = insert_ind[insert_ind_mask] else: vtk_cell_type = VTK_MAPPING[etypes] - # visualization bug within VTK with quadratic surf cells - ansquad8_mask = etypes == 6 - if np.any(ansquad8_mask): # kAnsQuad8 - pass # different treatment depending on the version of vtk if VTK9: From 3ee4ae5b00fecc13e27c7e72718f8f74cfd160fa Mon Sep 17 00:00:00 2001 From: "paul.profizi" Date: Wed, 19 Apr 2023 11:53:31 +0200 Subject: [PATCH 04/26] Fix as_linear=False with semi-parabolic --- src/ansys/dpf/core/vtk_helper.py | 46 ++++++++++++++++++++++++++------ 1 file changed, 38 insertions(+), 8 deletions(-) diff --git a/src/ansys/dpf/core/vtk_helper.py b/src/ansys/dpf/core/vtk_helper.py index ff1af4bdfd..6a1c5a2a04 100644 --- a/src/ansys/dpf/core/vtk_helper.py +++ b/src/ansys/dpf/core/vtk_helper.py @@ -202,11 +202,13 @@ def dpf_mesh_to_vtk_py(mesh, nodes, as_linear): insert_ind = np.cumsum(elem_size) insert_ind = np.hstack(([0], insert_ind))[:-1] - # Handle semiparabolic elements - nullmask = connectivity.data == -1 - if nullmask.any(): - repeated_data_pointers = connectivity._data_pointer.repeat(repeats=elem_size) - connectivity.data[nullmask] = connectivity.data[repeated_data_pointers[nullmask]] + # if not as_linear: + # # Pre-handle semi-parabolic elements + # semi_mask = connectivity.data == -1 + # if semi_mask.any(): + # # Modify -1 connectivity values + # repeated_data_pointers = connectivity._data_pointer.repeat(repeats=elem_size) + # connectivity.data[semi_mask] = connectivity.data[repeated_data_pointers[semi_mask]] # partition cells in vtk format cells = np.insert(connectivity.data, insert_ind, elem_size) @@ -253,6 +255,7 @@ def compute_offset(): # Create a global mask of connectivity values to take mask = np.full(cells.shape, False) mask[compute_offset()] = True + # Get a mask of quad8 elements in etypes quad8_mask = etypes == 6 # If any quad8 @@ -274,14 +277,41 @@ def compute_offset(): mask[insert_ind_tri6 + 2] = True mask[insert_ind_tri6 + 3] = True cells[insert_ind_tri6] //= 2 - cells = cells[mask] - insert_ind_mask = quad8_mask + tri6_mask - insert_ind = insert_ind[insert_ind_mask] else: vtk_cell_type = VTK_MAPPING[etypes] + # Handle semi-parabolic elements + semi_mask = cells == -1 + if semi_mask.any(): + cells_insert_ind = compute_offset() + # Create a global mask of connectivity values to take + mask = np.full(cells.shape, True) + # Build a map of size cells with repeated element beginning index + repeated_insert_ind = cells_insert_ind.repeat(repeats=elem_size + 1) + # Apply the semi-mask to get a unique set of indices of semi-parabolic elements in cells + semi_indices_in_cells = np.array(list(set(repeated_insert_ind[semi_mask]))) + semi_sizes = cells[semi_indices_in_cells] + semi_quad8 = semi_sizes == 8 + if semi_quad8.any(): + mask[semi_indices_in_cells[semi_quad8] + 5] = False + mask[semi_indices_in_cells[semi_quad8] + 6] = False + mask[semi_indices_in_cells[semi_quad8] + 7] = False + mask[semi_indices_in_cells[semi_quad8] + 8] = False + cells[semi_indices_in_cells[semi_quad8]] //= 2 + + vtk_cell_type[cells[cells_insert_ind[etypes == 6]] == 4] = VTK_LINEAR_MAPPING[6] + semi_tri6 = semi_sizes == 6 + if semi_tri6.any(): + mask[semi_indices_in_cells[semi_tri6] + 4] = False + mask[semi_indices_in_cells[semi_tri6] + 5] = False + mask[semi_indices_in_cells[semi_tri6] + 6] = False + cells[semi_indices_in_cells[semi_tri6]] //= 2 + vtk_cell_type[cells[cells_insert_ind[etypes == 4]] == 3] = VTK_LINEAR_MAPPING[4] + # Update cells with the mask + cells = cells[mask] + # different treatment depending on the version of vtk if VTK9: # compute offset array when < VTK v9 From 667a4ec7a276335f986a86460ea53f234fef5d2e Mon Sep 17 00:00:00 2001 From: "paul.profizi" Date: Wed, 19 Apr 2023 11:59:34 +0200 Subject: [PATCH 05/26] Add as_linear argument to MeshedRegion.plot and to Plotter.plot_contour() --- src/ansys/dpf/core/meshed_region.py | 6 ++++++ src/ansys/dpf/core/plotter.py | 12 ++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/ansys/dpf/core/meshed_region.py b/src/ansys/dpf/core/meshed_region.py index 06361197fd..6fdcc1c7d2 100644 --- a/src/ansys/dpf/core/meshed_region.py +++ b/src/ansys/dpf/core/meshed_region.py @@ -512,6 +512,7 @@ def plot( shell_layers=None, deform_by=None, scale_factor=1.0, + as_linear=True, **kwargs, ): """ @@ -528,6 +529,9 @@ def plot( Defaults to None. scale_factor : float, optional Scaling factor to apply when warping the mesh. Defaults to 1.0. + as_linear : bool, optional + Whether to show quadratic elements as their linear equivalents (for faster rendering). + Defaults to ``True``. **kwargs : optional Additional keyword arguments for the plotter. For additional keyword arguments, see ``help(pyvista.plot)``. @@ -552,6 +556,7 @@ def plot( show_axes=kwargs.pop("show_axes", True), deform_by=deform_by, scale_factor=scale_factor, + as_linear=as_linear, **kwargs, ) @@ -562,6 +567,7 @@ def plot( deform_by=deform_by, scale_factor=scale_factor, show_axes=kwargs.pop("show_axes", True), + as_linear=as_linear, **kwargs, ) return pl.show_figure(**kwargs) diff --git a/src/ansys/dpf/core/plotter.py b/src/ansys/dpf/core/plotter.py index 8bfcc5d658..27e29f6299 100644 --- a/src/ansys/dpf/core/plotter.py +++ b/src/ansys/dpf/core/plotter.py @@ -746,6 +746,7 @@ def plot_contour( meshed_region=None, deform_by=None, scale_factor=1.0, + as_linear=True, **kwargs, ): """Plot the contour result on its mesh support. @@ -765,6 +766,9 @@ def plot_contour( Defaults to None. scale_factor : float, optional Scaling factor to apply when warping the mesh. Defaults to 1.0. + as_linear : bool, optional + Whether to show quadratic elements as their linear equivalents (for faster rendering). + Defaults to ``True``. **kwargs : optional Additional keyword arguments for the plotter. For more information, see ``help(pyvista.plot)``. @@ -880,10 +884,14 @@ def plot_contour( bound_method=self._internal_plotter._plotter.add_mesh, **kwargs ) if deform_by: - grid = mesh._as_vtk(mesh.deform_by(deform_by, scale_factor)) + grid = mesh._as_vtk(mesh.deform_by(deform_by, scale_factor), as_linear=as_linear) self._internal_plotter.add_scale_factor_legend(scale_factor, **kwargs) else: - grid = mesh.grid + if as_linear != mesh.as_linear: + grid = mesh._as_vtk(mesh.nodes.coordinates_field, as_linear=as_linear) + mesh.as_linear = as_linear + else: + grid = mesh.grid grid.clear_data() self._internal_plotter._plotter.add_mesh(grid, scalars=overall_data, **kwargs_in) From b55124759d9c7a901cb79cd759d7bb2a8712ec8e Mon Sep 17 00:00:00 2001 From: "paul.profizi" Date: Wed, 19 Apr 2023 12:10:22 +0200 Subject: [PATCH 06/26] Fix as_linear --- src/ansys/dpf/core/vtk_helper.py | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/ansys/dpf/core/vtk_helper.py b/src/ansys/dpf/core/vtk_helper.py index 6a1c5a2a04..22e78fa91f 100644 --- a/src/ansys/dpf/core/vtk_helper.py +++ b/src/ansys/dpf/core/vtk_helper.py @@ -246,6 +246,7 @@ def compute_offset(): """Return the starting point of a cell in the cells array""" return insert_ind + np.arange(insert_ind.size) + cells_insert_ind = compute_offset() # convert kAns to VTK cell type offset = None if as_linear: @@ -253,29 +254,28 @@ def compute_offset(): vtk_cell_type = VTK_LINEAR_MAPPING[etypes] # Create a global mask of connectivity values to take - mask = np.full(cells.shape, False) - mask[compute_offset()] = True + mask = np.full(cells.shape, True) # Get a mask of quad8 elements in etypes quad8_mask = etypes == 6 # If any quad8 if np.any(quad8_mask): # kAnsQuad8 # Get the starting indices of quad8 elements in cells - insert_ind_quad8 = insert_ind[quad8_mask] - insert_ind_quad8 += np.arange(insert_ind_quad8.size) - mask[insert_ind_quad8 + 1] = True - mask[insert_ind_quad8 + 2] = True - mask[insert_ind_quad8 + 3] = True - mask[insert_ind_quad8 + 4] = True + insert_ind_quad8 = cells_insert_ind[quad8_mask] + # insert_ind_quad8 += np.arange(insert_ind_quad8.size) + mask[insert_ind_quad8 + 5] = False + mask[insert_ind_quad8 + 6] = False + mask[insert_ind_quad8 + 7] = False + mask[insert_ind_quad8 + 8] = False cells[insert_ind_quad8] //= 2 tri6_mask = etypes == 4 # kAnsTri6 = 4 if np.any(tri6_mask): - insert_ind_tri6 = insert_ind[tri6_mask] - insert_ind_tri6 += np.arange(insert_ind_tri6.size) - mask[insert_ind_tri6 + 1] = True - mask[insert_ind_tri6 + 2] = True - mask[insert_ind_tri6 + 3] = True + insert_ind_tri6 = cells_insert_ind[tri6_mask] + # insert_ind_tri6 += np.arange(insert_ind_tri6.size) + mask[insert_ind_tri6 + 4] = False + mask[insert_ind_tri6 + 5] = False + mask[insert_ind_tri6 + 6] = False cells[insert_ind_tri6] //= 2 cells = cells[mask] From e50a505ba553c7df9060171b24b5ad2deca989ec Mon Sep 17 00:00:00 2001 From: "paul.profizi" Date: Thu, 20 Apr 2023 17:04:38 +0200 Subject: [PATCH 07/26] Fix _PyVistaPlotter.add_field() --- src/ansys/dpf/core/plotter.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ansys/dpf/core/plotter.py b/src/ansys/dpf/core/plotter.py index 27e29f6299..bdd4d302ef 100644 --- a/src/ansys/dpf/core/plotter.py +++ b/src/ansys/dpf/core/plotter.py @@ -286,7 +286,7 @@ def add_field( grid = meshed_region.grid else: grid = meshed_region._as_vtk( - meshed_region.deform_by(deform_by, scale_factor, as_linear) + meshed_region.deform_by(deform_by, scale_factor), as_linear ) grid.set_active_scalars(None) self._plotter.add_mesh(grid, scalars=overall_data, **kwargs_in) From e555384c08f73b2dba35a5e70f6e371251dfac19 Mon Sep 17 00:00:00 2001 From: "paul.profizi" Date: Thu, 20 Apr 2023 19:05:10 +0200 Subject: [PATCH 08/26] Fix as_linear=False --- src/ansys/dpf/core/vtk_helper.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/ansys/dpf/core/vtk_helper.py b/src/ansys/dpf/core/vtk_helper.py index 22e78fa91f..0109b7cba6 100644 --- a/src/ansys/dpf/core/vtk_helper.py +++ b/src/ansys/dpf/core/vtk_helper.py @@ -301,14 +301,19 @@ def compute_offset(): mask[semi_indices_in_cells[semi_quad8] + 8] = False cells[semi_indices_in_cells[semi_quad8]] //= 2 - vtk_cell_type[cells[cells_insert_ind[etypes == 6]] == 4] = VTK_LINEAR_MAPPING[6] + quad8_mask = etypes == 6 + semi_quad8_mask = (cells[cells_insert_ind] == 4) & quad8_mask + vtk_cell_type[semi_quad8_mask] = VTK_LINEAR_MAPPING[6] semi_tri6 = semi_sizes == 6 if semi_tri6.any(): mask[semi_indices_in_cells[semi_tri6] + 4] = False mask[semi_indices_in_cells[semi_tri6] + 5] = False mask[semi_indices_in_cells[semi_tri6] + 6] = False cells[semi_indices_in_cells[semi_tri6]] //= 2 - vtk_cell_type[cells[cells_insert_ind[etypes == 4]] == 3] = VTK_LINEAR_MAPPING[4] + + tri6_mask = etypes == 4 + semi_tri6_mask = (cells[cells_insert_ind] == 3) & tri6_mask + vtk_cell_type[semi_tri6_mask] = VTK_LINEAR_MAPPING[4] # Update cells with the mask cells = cells[mask] From af60642bad50b9662e567f7733510a536cb6b5ec Mon Sep 17 00:00:00 2001 From: "paul.profizi" Date: Fri, 21 Apr 2023 17:06:38 +0200 Subject: [PATCH 09/26] Add as_linear argument to Model.plot() --- src/ansys/dpf/core/model.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/ansys/dpf/core/model.py b/src/ansys/dpf/core/model.py index e0bc7640b3..b0d19033eb 100644 --- a/src/ansys/dpf/core/model.py +++ b/src/ansys/dpf/core/model.py @@ -206,7 +206,7 @@ def __str__(self): txt += str(self.metadata.time_freq_support) return txt - def plot(self, color="w", show_edges=True, **kwargs): + def plot(self, color="w", show_edges=True, as_linear=True, **kwargs): """Plot the mesh of the model. Parameters @@ -215,6 +215,9 @@ def plot(self, color="w", show_edges=True, **kwargs): color of the mesh faces in PyVista format. The default is white with ``"w"``. show_edges : bool Whether to show the mesh edges. The default is ``True``. + as_linear : bool, optional + Whether to show quadratic elements as their linear equivalents (for faster rendering). + Defaults to ``True``. **kwargs : optional Additional keyword arguments for the plotter. For additional keyword arguments, see ``help(pyvista.plot)``. @@ -235,7 +238,12 @@ def plot(self, color="w", show_edges=True, **kwargs): kwargs["color"] = color kwargs["show_edges"] = show_edges pl = DpfPlotter(**kwargs) - pl.add_mesh(self.metadata.meshed_region, show_axes=kwargs.pop("show_axes", True), **kwargs) + pl.add_mesh( + self.metadata.meshed_region, + show_axes=kwargs.pop("show_axes", True), + as_linear=as_linear, + **kwargs + ) return pl.show_figure(**kwargs) @property From dc29a27dcbecd3e27e911233d5f6810f7f4b689d Mon Sep 17 00:00:00 2001 From: "paul.profizi" Date: Fri, 21 Apr 2023 17:11:21 +0200 Subject: [PATCH 10/26] Update the 00-basic_plotting.py example to showcase as_linear=False --- examples/06-plotting/00-basic_plotting.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/examples/06-plotting/00-basic_plotting.py b/examples/06-plotting/00-basic_plotting.py index 6841b4b72c..60b231d9a4 100644 --- a/examples/06-plotting/00-basic_plotting.py +++ b/examples/06-plotting/00-basic_plotting.py @@ -54,6 +54,19 @@ title="Mesh fc None", text="Mesh plot", ) + +# The plotter transforms quadratic elements into their linear equivalents by default +# for improved performance. This can be changed using the "as_linear=False" argument. +# Note: semi-parabolic elements are always changed to their linear equivalents. +mesh.plot( + as_linear=False, + field_or_fields_container=None, + shell_layers=None, + show_axes=True, + title="Mesh fc None", + text="Mesh plot as_linear=False", +) + # Additional PyVista kwargs are supported, such as: mesh.plot( off_screen=True, From f3d393e348e2e35de64da57187ecc6d1f50c75ea Mon Sep 17 00:00:00 2001 From: "paul.profizi" Date: Fri, 21 Apr 2023 17:12:16 +0200 Subject: [PATCH 11/26] Add a test for MeshedRegion.plot(as_linear=False) --- tests/test_plotter.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/test_plotter.py b/tests/test_plotter.py index 9435c4eb06..4da78e8c58 100644 --- a/tests/test_plotter.py +++ b/tests/test_plotter.py @@ -52,6 +52,7 @@ def test_mesh_bare_plot(multishells): model = core.Model(multishells) mesh = model.metadata.meshed_region mesh.plot() + mesh.plot(as_linear=False) @pytest.mark.skipif(not HAS_PYVISTA, reason="Please install pyvista") From 62175d98c4fe5d1d1ff285945fc6e8bebccffc37 Mon Sep 17 00:00:00 2001 From: "paul.profizi" Date: Fri, 21 Apr 2023 16:59:46 +0200 Subject: [PATCH 12/26] Try and fix 02-volume_averaged_stress.py for Docker --- examples/04-advanced/02-volume_averaged_stress.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/examples/04-advanced/02-volume_averaged_stress.py b/examples/04-advanced/02-volume_averaged_stress.py index 1cba0377d9..be293149c0 100644 --- a/examples/04-advanced/02-volume_averaged_stress.py +++ b/examples/04-advanced/02-volume_averaged_stress.py @@ -48,7 +48,7 @@ # Find the minimum list of elements by node to get the volume check # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -# get the connectivy and inverse connecitivity fields +# get the connectivity and inverse connectivity fields connectivity_field = mesh.elements.connectivities_field nodal_connectivity_field = mesh.nodes.nodal_connectivity_field @@ -83,10 +83,7 @@ # Get all nodes of the current elements for next iteration current_node_indexes.extend(connectivity.get_entity_data(index)) - node_index_to_el_ids[i] = dpf.Scoping( - ids=[elements_ids[index] for index in elements_indexes], - location=dpf.locations().elemental, - ) + node_index_to_el_ids[i] = [elements_ids[index] for index in elements_indexes] node_index_to_found_volume[i] = volume ############################################################################### @@ -128,7 +125,7 @@ volsum.data = datavolsum volsum.scoping.ids = nodes_ids_to_compute -# use component wise divide to averaged the stress by the volume +# use component wise divide to average the stress by the volume divide = ops.math.component_wise_divide(seqvsum, volsum) divide.run() From ff4bc03a01bfc10ba9545b9775eb42abf67a60e2 Mon Sep 17 00:00:00 2001 From: "paul.profizi" Date: Fri, 21 Apr 2023 18:56:36 +0200 Subject: [PATCH 13/26] Fix 04-extrapolation_stress_3d.py for Docker --- examples/04-advanced/04-extrapolation_stress_3d.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/04-advanced/04-extrapolation_stress_3d.py b/examples/04-advanced/04-extrapolation_stress_3d.py index 5483b1c9fd..0830c92de9 100644 --- a/examples/04-advanced/04-extrapolation_stress_3d.py +++ b/examples/04-advanced/04-extrapolation_stress_3d.py @@ -38,7 +38,7 @@ ############################################################################### # Get the data source's analysis of integration points and analysis reference -datafile = examples.download_extrapolation_3d_result() +datafile = examples.download_extrapolation_3d_result(return_local_path=True) # Get integration points (Gaussian points) data_integration_points = datafile["file_integrated"] From 3dc944954e516f0a34981fd013f86598ab7a92be Mon Sep 17 00:00:00 2001 From: "paul.profizi" Date: Mon, 24 Apr 2023 15:54:48 +0200 Subject: [PATCH 14/26] Revert "Update the 00-basic_plotting.py example to showcase as_linear=False" This reverts commit dc29a27dcbecd3e27e911233d5f6810f7f4b689d. --- examples/06-plotting/00-basic_plotting.py | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/examples/06-plotting/00-basic_plotting.py b/examples/06-plotting/00-basic_plotting.py index 60b231d9a4..6841b4b72c 100644 --- a/examples/06-plotting/00-basic_plotting.py +++ b/examples/06-plotting/00-basic_plotting.py @@ -54,19 +54,6 @@ title="Mesh fc None", text="Mesh plot", ) - -# The plotter transforms quadratic elements into their linear equivalents by default -# for improved performance. This can be changed using the "as_linear=False" argument. -# Note: semi-parabolic elements are always changed to their linear equivalents. -mesh.plot( - as_linear=False, - field_or_fields_container=None, - shell_layers=None, - show_axes=True, - title="Mesh fc None", - text="Mesh plot as_linear=False", -) - # Additional PyVista kwargs are supported, such as: mesh.plot( off_screen=True, From 0015031e32150a267473ab8c85dbe46721f7bc52 Mon Sep 17 00:00:00 2001 From: "paul.profizi" Date: Mon, 24 Apr 2023 15:59:40 +0200 Subject: [PATCH 15/26] Remove exposition of as_linear as an argument for public plotting methods. as_linear=False is not production-ready as internal edges of quadratic elements cannot be hidden --- src/ansys/dpf/core/meshed_region.py | 8 ++------ src/ansys/dpf/core/model.py | 7 ++----- src/ansys/dpf/core/plotter.py | 18 ++++-------------- 3 files changed, 8 insertions(+), 25 deletions(-) diff --git a/src/ansys/dpf/core/meshed_region.py b/src/ansys/dpf/core/meshed_region.py index 6fdcc1c7d2..181c3868e8 100644 --- a/src/ansys/dpf/core/meshed_region.py +++ b/src/ansys/dpf/core/meshed_region.py @@ -512,7 +512,6 @@ def plot( shell_layers=None, deform_by=None, scale_factor=1.0, - as_linear=True, **kwargs, ): """ @@ -529,9 +528,6 @@ def plot( Defaults to None. scale_factor : float, optional Scaling factor to apply when warping the mesh. Defaults to 1.0. - as_linear : bool, optional - Whether to show quadratic elements as their linear equivalents (for faster rendering). - Defaults to ``True``. **kwargs : optional Additional keyword arguments for the plotter. For additional keyword arguments, see ``help(pyvista.plot)``. @@ -556,7 +552,7 @@ def plot( show_axes=kwargs.pop("show_axes", True), deform_by=deform_by, scale_factor=scale_factor, - as_linear=as_linear, + as_linear=True, **kwargs, ) @@ -567,7 +563,7 @@ def plot( deform_by=deform_by, scale_factor=scale_factor, show_axes=kwargs.pop("show_axes", True), - as_linear=as_linear, + as_linear=True, **kwargs, ) return pl.show_figure(**kwargs) diff --git a/src/ansys/dpf/core/model.py b/src/ansys/dpf/core/model.py index b0d19033eb..ae1f566a36 100644 --- a/src/ansys/dpf/core/model.py +++ b/src/ansys/dpf/core/model.py @@ -206,7 +206,7 @@ def __str__(self): txt += str(self.metadata.time_freq_support) return txt - def plot(self, color="w", show_edges=True, as_linear=True, **kwargs): + def plot(self, color="w", show_edges=True, **kwargs): """Plot the mesh of the model. Parameters @@ -215,9 +215,6 @@ def plot(self, color="w", show_edges=True, as_linear=True, **kwargs): color of the mesh faces in PyVista format. The default is white with ``"w"``. show_edges : bool Whether to show the mesh edges. The default is ``True``. - as_linear : bool, optional - Whether to show quadratic elements as their linear equivalents (for faster rendering). - Defaults to ``True``. **kwargs : optional Additional keyword arguments for the plotter. For additional keyword arguments, see ``help(pyvista.plot)``. @@ -241,7 +238,7 @@ def plot(self, color="w", show_edges=True, as_linear=True, **kwargs): pl.add_mesh( self.metadata.meshed_region, show_axes=kwargs.pop("show_axes", True), - as_linear=as_linear, + as_linear=True, **kwargs ) return pl.show_figure(**kwargs) diff --git a/src/ansys/dpf/core/plotter.py b/src/ansys/dpf/core/plotter.py index bdd4d302ef..10de6861a1 100644 --- a/src/ansys/dpf/core/plotter.py +++ b/src/ansys/dpf/core/plotter.py @@ -459,7 +459,7 @@ def add_line(self, points, field=None, **kwargs): def add_plane(self, plane, field=None, **kwargs): self._internal_plotter.add_plane(plane, field, **kwargs) - def add_mesh(self, meshed_region, deform_by=None, scale_factor=1.0, as_linear=True, **kwargs): + def add_mesh(self, meshed_region, deform_by=None, scale_factor=1.0, **kwargs): """Add a mesh to plot. Parameters @@ -471,9 +471,6 @@ def add_mesh(self, meshed_region, deform_by=None, scale_factor=1.0, as_linear=Tr Defaults to None. scale_factor : float, optional Scaling factor to apply when warping the mesh. Defaults to 1.0. - as_linear : bool, optional - Whether to show quadratic elements as their linear equivalents (for faster rendering). - Defaults to ``True``. **kwargs : optional Additional keyword arguments for the plotter. More information are available at :func:`pyvista.plot`. @@ -495,7 +492,7 @@ def add_mesh(self, meshed_region, deform_by=None, scale_factor=1.0, as_linear=Tr meshed_region=meshed_region, deform_by=deform_by, scale_factor=scale_factor, - as_linear=as_linear, + as_linear=True, **kwargs, ) @@ -509,7 +506,6 @@ def add_field( label_point_size=20, deform_by=None, scale_factor=1.0, - as_linear=True, **kwargs, ): """Add a field containing data to the plotter. @@ -534,9 +530,6 @@ def add_field( Defaults to None. scale_factor : float, optional Scaling factor to apply when warping the mesh. Defaults to 1.0. - as_linear : bool, optional - Whether to show quadratic elements as their linear equivalents (for faster rendering). - Defaults to ``True``. **kwargs : optional Additional keyword arguments for the plotter. More information are available at :func:`pyvista.plot`. @@ -562,7 +555,7 @@ def add_field( label_point_size=label_point_size, deform_by=deform_by, scale_factor=scale_factor, - as_linear=as_linear, + as_linear=True, **kwargs, ) @@ -746,7 +739,6 @@ def plot_contour( meshed_region=None, deform_by=None, scale_factor=1.0, - as_linear=True, **kwargs, ): """Plot the contour result on its mesh support. @@ -766,9 +758,6 @@ def plot_contour( Defaults to None. scale_factor : float, optional Scaling factor to apply when warping the mesh. Defaults to 1.0. - as_linear : bool, optional - Whether to show quadratic elements as their linear equivalents (for faster rendering). - Defaults to ``True``. **kwargs : optional Additional keyword arguments for the plotter. For more information, see ``help(pyvista.plot)``. @@ -883,6 +872,7 @@ def plot_contour( kwargs_in = _sort_supported_kwargs( bound_method=self._internal_plotter._plotter.add_mesh, **kwargs ) + as_linear = True if deform_by: grid = mesh._as_vtk(mesh.deform_by(deform_by, scale_factor), as_linear=as_linear) self._internal_plotter.add_scale_factor_legend(scale_factor, **kwargs) From 32ce764af825b601fd96f8f53df3ff4bfb01bd65 Mon Sep 17 00:00:00 2001 From: "paul.profizi" Date: Mon, 24 Apr 2023 17:09:28 +0200 Subject: [PATCH 16/26] Fix as_linear superfluous arguments --- src/ansys/dpf/core/meshed_region.py | 2 -- src/ansys/dpf/core/model.py | 7 +------ 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/src/ansys/dpf/core/meshed_region.py b/src/ansys/dpf/core/meshed_region.py index 181c3868e8..06361197fd 100644 --- a/src/ansys/dpf/core/meshed_region.py +++ b/src/ansys/dpf/core/meshed_region.py @@ -552,7 +552,6 @@ def plot( show_axes=kwargs.pop("show_axes", True), deform_by=deform_by, scale_factor=scale_factor, - as_linear=True, **kwargs, ) @@ -563,7 +562,6 @@ def plot( deform_by=deform_by, scale_factor=scale_factor, show_axes=kwargs.pop("show_axes", True), - as_linear=True, **kwargs, ) return pl.show_figure(**kwargs) diff --git a/src/ansys/dpf/core/model.py b/src/ansys/dpf/core/model.py index ae1f566a36..e0bc7640b3 100644 --- a/src/ansys/dpf/core/model.py +++ b/src/ansys/dpf/core/model.py @@ -235,12 +235,7 @@ def plot(self, color="w", show_edges=True, **kwargs): kwargs["color"] = color kwargs["show_edges"] = show_edges pl = DpfPlotter(**kwargs) - pl.add_mesh( - self.metadata.meshed_region, - show_axes=kwargs.pop("show_axes", True), - as_linear=True, - **kwargs - ) + pl.add_mesh(self.metadata.meshed_region, show_axes=kwargs.pop("show_axes", True), **kwargs) return pl.show_figure(**kwargs) @property From e5ab0731df0d5dcd3969486ba971fa2042980a2e Mon Sep 17 00:00:00 2001 From: "paul.profizi" Date: Tue, 25 Apr 2023 14:55:22 +0200 Subject: [PATCH 17/26] Remove test of as_linear=False from test_mesh_bare_plot --- tests/test_plotter.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/test_plotter.py b/tests/test_plotter.py index 4da78e8c58..9435c4eb06 100644 --- a/tests/test_plotter.py +++ b/tests/test_plotter.py @@ -52,7 +52,6 @@ def test_mesh_bare_plot(multishells): model = core.Model(multishells) mesh = model.metadata.meshed_region mesh.plot() - mesh.plot(as_linear=False) @pytest.mark.skipif(not HAS_PYVISTA, reason="Please install pyvista") From 8d3b230d2db95c6c07314a94e88c58259dca5c30 Mon Sep 17 00:00:00 2001 From: "paul.profizi" Date: Tue, 25 Apr 2023 15:38:40 +0200 Subject: [PATCH 18/26] Try fix elemental_nodal_to_nodal_fc.outputs[1].type_names --- .../core/operators/averaging/elemental_nodal_to_nodal_fc.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/ansys/dpf/core/operators/averaging/elemental_nodal_to_nodal_fc.py b/src/ansys/dpf/core/operators/averaging/elemental_nodal_to_nodal_fc.py index a71bea04d9..eadb14e1e9 100644 --- a/src/ansys/dpf/core/operators/averaging/elemental_nodal_to_nodal_fc.py +++ b/src/ansys/dpf/core/operators/averaging/elemental_nodal_to_nodal_fc.py @@ -173,9 +173,7 @@ def _spec(): ), 1: PinSpecification( name="weights", - type_names=[ - "class dataProcessing::DpfTypeCollection" - ], + type_names=["class dataProcessing::CPropertyFieldsContainer"], optional=False, document="""Gives for each node, the number of times it was found in the elemental nodal From 1fce8d742b9bbdd74ce82975af5e37f6dc9e2753 Mon Sep 17 00:00:00 2001 From: "paul.profizi" Date: Tue, 25 Apr 2023 15:53:00 +0200 Subject: [PATCH 19/26] Remove previous fix to 04-extrapolation_stress_3d.py (return_local_path=True) --- examples/04-advanced/04-extrapolation_stress_3d.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/04-advanced/04-extrapolation_stress_3d.py b/examples/04-advanced/04-extrapolation_stress_3d.py index 0830c92de9..5483b1c9fd 100644 --- a/examples/04-advanced/04-extrapolation_stress_3d.py +++ b/examples/04-advanced/04-extrapolation_stress_3d.py @@ -38,7 +38,7 @@ ############################################################################### # Get the data source's analysis of integration points and analysis reference -datafile = examples.download_extrapolation_3d_result(return_local_path=True) +datafile = examples.download_extrapolation_3d_result() # Get integration points (Gaussian points) data_integration_points = datafile["file_integrated"] From b26f8f5934966dff843e1eb2e4b8f281f64dd5ba Mon Sep 17 00:00:00 2001 From: "paul.profizi" Date: Wed, 26 Apr 2023 18:36:53 +0200 Subject: [PATCH 20/26] Revert "Try fix elemental_nodal_to_nodal_fc.outputs[1].type_names" This reverts commit 8d3b230d2db95c6c07314a94e88c58259dca5c30. --- .../core/operators/averaging/elemental_nodal_to_nodal_fc.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/ansys/dpf/core/operators/averaging/elemental_nodal_to_nodal_fc.py b/src/ansys/dpf/core/operators/averaging/elemental_nodal_to_nodal_fc.py index eadb14e1e9..a71bea04d9 100644 --- a/src/ansys/dpf/core/operators/averaging/elemental_nodal_to_nodal_fc.py +++ b/src/ansys/dpf/core/operators/averaging/elemental_nodal_to_nodal_fc.py @@ -173,7 +173,9 @@ def _spec(): ), 1: PinSpecification( name="weights", - type_names=["class dataProcessing::CPropertyFieldsContainer"], + type_names=[ + "class dataProcessing::DpfTypeCollection" + ], optional=False, document="""Gives for each node, the number of times it was found in the elemental nodal From 1682d64818e3a3742644a474fe6dfea83fd9849b Mon Sep 17 00:00:00 2001 From: "paul.profizi" Date: Thu, 27 Apr 2023 12:44:53 +0200 Subject: [PATCH 21/26] Bypass bug on plot for 00-compute_and_average.py --- examples/09-averaging/00-compute_and_average.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/examples/09-averaging/00-compute_and_average.py b/examples/09-averaging/00-compute_and_average.py index 1c3c4cd9e8..fe0fc29cd5 100644 --- a/examples/09-averaging/00-compute_and_average.py +++ b/examples/09-averaging/00-compute_and_average.py @@ -99,8 +99,6 @@ def compute_von_mises_then_average(analysis): min_max.inputs.field.connect(avg_von_mises) max_val = min_max.outputs.field_max() - mesh.plot(avg_von_mises) - return max_val.data[0] @@ -139,8 +137,6 @@ def average_then_compute_von_mises(analysis): min_max.inputs.field.connect(avg_von_mises) max_val = min_max.outputs.field_max() - mesh.plot(avg_von_mises) - return max_val.data[0] From 1a639100c2d3e86bbe3ae8bb6a3f9540bad479a9 Mon Sep 17 00:00:00 2001 From: "paul.profizi" Date: Thu, 27 Apr 2023 13:59:55 +0200 Subject: [PATCH 22/26] Try rescoping input nodes field in vtk_helper.py --- src/ansys/dpf/core/vtk_helper.py | 5 +++++ tests/test_meshregion.py | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/ansys/dpf/core/vtk_helper.py b/src/ansys/dpf/core/vtk_helper.py index 503535688c..91fb50ae75 100644 --- a/src/ansys/dpf/core/vtk_helper.py +++ b/src/ansys/dpf/core/vtk_helper.py @@ -191,6 +191,11 @@ def dpf_mesh_to_vtk_py(mesh, nodes, as_linear): if nodes is None: node_coordinates = mesh.nodes.coordinates_field.data else: + nodes = dpf.operators.scoping.rescope( + fields=nodes, + mesh_scoping=mesh.nodes.scoping, + server=mesh._server, + ).outputs.fields_as_field() node_coordinates = nodes.data elem_size = np.ediff1d(np.append(connectivity._data_pointer, connectivity.shape)) diff --git a/tests/test_meshregion.py b/tests/test_meshregion.py index 98acbeeaf9..4bb6b6e750 100644 --- a/tests/test_meshregion.py +++ b/tests/test_meshregion.py @@ -65,7 +65,7 @@ def test_get_set_unit_meshedregion(simple_bar_model): def test_get_node_meshedregion(simple_bar_model): mesh = simple_bar_model.metadata.meshed_region node = mesh.nodes.node_by_index(1) - scop = mesh._get_scoping(dpf.core.locations.nodal) + scop = mesh.nodes.scoping assert node.id == scop.id(1) assert node.index == 1 From 1ce7669e98dffe9a7b16c92b591d8595b7254097 Mon Sep 17 00:00:00 2001 From: "paul.profizi" Date: Thu, 27 Apr 2023 15:50:30 +0200 Subject: [PATCH 23/26] Fix include_ids=True in MeshedRegion._as_vtk --- src/ansys/dpf/core/meshed_region.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ansys/dpf/core/meshed_region.py b/src/ansys/dpf/core/meshed_region.py index 06361197fd..f0110be70d 100644 --- a/src/ansys/dpf/core/meshed_region.py +++ b/src/ansys/dpf/core/meshed_region.py @@ -460,8 +460,8 @@ def _as_vtk(self, coordinates=None, as_linear=True, include_ids=False): if include_ids: self._nodeids = self.elements.scoping.ids self._elementids = self.nodes.scoping.ids - grid["node_ids"] = self._elementids - grid["element_ids"] = self._nodeids + grid["node_ids"] = self._nodeids + grid["element_ids"] = self._elementids # Quick fix required to hold onto the data as PyVista does not make a copy. # All of those now return DPFArrays From 83b1e4807498ed28be6c9cf3ffebfad8bd8f6952 Mon Sep 17 00:00:00 2001 From: "paul.profizi" Date: Thu, 27 Apr 2023 15:51:05 +0200 Subject: [PATCH 24/26] Remove rescope of nodes in dpf_mesh_to_vtk_py --- src/ansys/dpf/core/vtk_helper.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/ansys/dpf/core/vtk_helper.py b/src/ansys/dpf/core/vtk_helper.py index 91fb50ae75..503535688c 100644 --- a/src/ansys/dpf/core/vtk_helper.py +++ b/src/ansys/dpf/core/vtk_helper.py @@ -191,11 +191,6 @@ def dpf_mesh_to_vtk_py(mesh, nodes, as_linear): if nodes is None: node_coordinates = mesh.nodes.coordinates_field.data else: - nodes = dpf.operators.scoping.rescope( - fields=nodes, - mesh_scoping=mesh.nodes.scoping, - server=mesh._server, - ).outputs.fields_as_field() node_coordinates = nodes.data elem_size = np.ediff1d(np.append(connectivity._data_pointer, connectivity.shape)) From 528ba75a4294e55df533c2e4ca3f4066af850cb7 Mon Sep 17 00:00:00 2001 From: "paul.profizi" Date: Thu, 27 Apr 2023 15:54:09 +0200 Subject: [PATCH 25/26] Try updating grid holding onto coordinates field's data --- src/ansys/dpf/core/meshed_region.py | 10 ---------- src/ansys/dpf/core/vtk_helper.py | 9 ++++++++- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/src/ansys/dpf/core/meshed_region.py b/src/ansys/dpf/core/meshed_region.py index f0110be70d..a8d5b68a5f 100644 --- a/src/ansys/dpf/core/meshed_region.py +++ b/src/ansys/dpf/core/meshed_region.py @@ -463,16 +463,6 @@ def _as_vtk(self, coordinates=None, as_linear=True, include_ids=False): grid["node_ids"] = self._nodeids grid["element_ids"] = self._elementids - # Quick fix required to hold onto the data as PyVista does not make a copy. - # All of those now return DPFArrays - if coordinates is None: - coordinates_field = self.nodes.coordinates_field - coordinates = self.nodes.coordinates_field.data - else: - coordinates_field = coordinates - coordinates = coordinates.data - setattr(grid, "_dpf_cache", [coordinates, coordinates_field]) - return grid @property diff --git a/src/ansys/dpf/core/vtk_helper.py b/src/ansys/dpf/core/vtk_helper.py index 503535688c..174de24083 100644 --- a/src/ansys/dpf/core/vtk_helper.py +++ b/src/ansys/dpf/core/vtk_helper.py @@ -189,8 +189,10 @@ def dpf_mesh_to_vtk_py(mesh, nodes, as_linear): etypes = mesh.elements.element_types_field.data connectivity = mesh.elements.connectivities_field if nodes is None: - node_coordinates = mesh.nodes.coordinates_field.data + coordinates_field = mesh.nodes.coordinates_field + node_coordinates = coordinates_field.data else: + coordinates_field = nodes node_coordinates = nodes.data elem_size = np.ediff1d(np.append(connectivity._data_pointer, connectivity.shape)) @@ -326,6 +328,11 @@ def compute_offset(): if VTK9: # compute offset array when < VTK v9 grid = pv.UnstructuredGrid(cells, vtk_cell_type, node_coordinates) + + # Quick fix required to hold onto the data as PyVista does not make a copy. + # All of those now return DPFArrays + setattr(grid, "_dpf_cache", [node_coordinates, coordinates_field]) + return grid # might be computed when checking for VTK quadratic bug From 8edde828ca6712c5f4ced8b6ad612413dd0208dc Mon Sep 17 00:00:00 2001 From: "paul.profizi" Date: Thu, 27 Apr 2023 16:03:37 +0200 Subject: [PATCH 26/26] Fix MeshedRegion._as_vtk --- src/ansys/dpf/core/meshed_region.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ansys/dpf/core/meshed_region.py b/src/ansys/dpf/core/meshed_region.py index a8d5b68a5f..c988e14ac7 100644 --- a/src/ansys/dpf/core/meshed_region.py +++ b/src/ansys/dpf/core/meshed_region.py @@ -458,8 +458,8 @@ def _as_vtk(self, coordinates=None, as_linear=True, include_ids=False): # consider adding this when scoping request is faster if include_ids: - self._nodeids = self.elements.scoping.ids - self._elementids = self.nodes.scoping.ids + self._nodeids = self.nodes.scoping.ids + self._elementids = self.elements.scoping.ids grid["node_ids"] = self._nodeids grid["element_ids"] = self._elementids