diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index aafdda39715..6af762044db 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -301,12 +301,14 @@ jobs: with: files: docs/build/html dest: HTML-doc-${{env.PACKAGE_NAME}}.zip + if: always() - name: "Upload HTML Documentation" uses: actions/upload-artifact@v3 with: name: HTML-doc-${{env.PACKAGE_NAME}} path: HTML-doc-${{env.PACKAGE_NAME}}.zip + if: always() run_examples: name: "Run Examples with/without bin" diff --git a/ansys/dpf/core/meshed_region.py b/ansys/dpf/core/meshed_region.py index d1a73372a7b..83b27e5e4a7 100644 --- a/ansys/dpf/core/meshed_region.py +++ b/ansys/dpf/core/meshed_region.py @@ -18,6 +18,21 @@ from ansys.dpf.gate import meshed_region_capi, meshed_region_grpcapi +def update_grid(func): + # Decorate mesh setters to centralize the update logic of pyvista objects. + def wrapper(*args, **kwargs): + mesh = args[0] + if mesh._full_grid is not None: + # Treat each setter separately to improve performance by updating the minimum required. + if func.__name__ == 'set_coordinates_field': + # When setting node coordinates + from ansys.dpf.core.vtk_helper import vtk_update_coordinates + vtk_update_coordinates(vtk_grid=mesh._full_grid, coordinates_array=args[1].data) + + return func(*args, **kwargs) + return wrapper + + @class_handling_cache class MeshedRegion: """ @@ -275,6 +290,7 @@ def set_property_field(self, property_name, value): else: self._api.meshed_region_set_property_field(self, property_name, value) + @update_grid @version_requires("3.0") def set_coordinates_field(self, coordinates_field): """ diff --git a/ansys/dpf/core/plotter.py b/ansys/dpf/core/plotter.py index 88ebf656157..89887b7315e 100755 --- a/ansys/dpf/core/plotter.py +++ b/ansys/dpf/core/plotter.py @@ -391,6 +391,8 @@ def add_mesh(self, meshed_region, deform_by=None, scale_factor=1.0, **kwargs): >>> pl.add_mesh(mesh) """ + if meshed_region.grid is not None: + meshed_region.grid.clear_data() self._internal_plotter.add_mesh(meshed_region=meshed_region, deform_by=deform_by, scale_factor=scale_factor, @@ -767,6 +769,7 @@ def plot_contour( self._internal_plotter.add_scale_factor_legend(scale_factor, **kwargs) else: grid = mesh.grid + grid.clear_data() self._internal_plotter._plotter.add_mesh(grid, scalars=overall_data, **kwargs_in) background = kwargs.pop("background", None) diff --git a/ansys/dpf/core/vtk_helper.py b/ansys/dpf/core/vtk_helper.py index 7d48ef842b3..fd15a67de93 100644 --- a/ansys/dpf/core/vtk_helper.py +++ b/ansys/dpf/core/vtk_helper.py @@ -226,3 +226,8 @@ def compute_offset(): offset = compute_offset() return pv.UnstructuredGrid(offset, cells, vtk_cell_type, nodes) + + +def vtk_update_coordinates(vtk_grid, coordinates_array): + from copy import copy + vtk_grid.points = copy(coordinates_array) diff --git a/tests/test_meshregion.py b/tests/test_meshregion.py index 729236364ab..78add88c2bb 100644 --- a/tests/test_meshregion.py +++ b/tests/test_meshregion.py @@ -121,7 +121,15 @@ def test_set_coordinates_field_meshedregion(simple_bar_model): field_coordinates.data = new_data mesh.set_coordinates_field(field_coordinates) field_coordinates = mesh.nodes.coordinates_field + point_0 = list(mesh.grid.points[0]) assert np.allclose(field_coordinates.data[0], [1.0, 1.0, 1.0]) + assert np.allclose(point_0, [1.0, 1.0, 1.0]) + field_coordinates.data = field_coordinates.data * 2.0 + mesh.set_coordinates_field(field_coordinates) + field_coordinates = mesh.nodes.coordinates_field + point_1 = list(mesh.grid.points[0]) + assert np.allclose(field_coordinates.data[0], [2.0, 2.0, 2.0]) + assert np.allclose(point_1, [2.0, 2.0, 2.0]) def test_get_element_types_field_meshedregion(simple_bar_model):