Skip to content

Commit f0174c0

Browse files
authored
fix(retro): fix retro-compatibility with pyvista<0.46.0 (#2539)
1 parent c9a1920 commit f0174c0

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

src/ansys/dpf/core/vtk_helper.py

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -185,18 +185,22 @@ def dpf_mesh_to_vtk_op(mesh, nodes=None, as_linear=True):
185185
celltypes_pv = mesh_to_pyvista.outputs.cell_types()
186186
if VTK9:
187187
grid = pv.UnstructuredGrid(cells_pv, celltypes_pv, nodes_pv)
188-
# setattr(grid, "_dpf_cache_op", [cells_pv, celltypes_pv, nodes_pv])
189-
pv.set_new_attribute(
190-
obj=grid, name="_dpf_cache_op", value=[cells_pv, celltypes_pv, nodes_pv]
191-
)
188+
if hasattr(pv, "set_new_attribute"): # For pyvista >=0.46.0
189+
pv.set_new_attribute(
190+
obj=grid, name="_dpf_cache_op", value=[cells_pv, celltypes_pv, nodes_pv]
191+
)
192+
else: # For pyvista <0.46.0 # pragma: nocover
193+
setattr(grid, "_dpf_cache_op", [cells_pv, celltypes_pv, nodes_pv])
192194
return grid
193195
else:
194196
offsets_pv = mesh_to_pyvista.outputs.offsets()
195197
grid = pv.UnstructuredGrid(offsets_pv, cells_pv, celltypes_pv, nodes_pv)
196-
# setattr(grid, "_dpf_cache_op", [cells_pv, celltypes_pv, nodes_pv, offsets_pv])
197-
pv.set_new_attribute(
198-
obj=grid, name="_dpf_cache_op", value=[cells_pv, celltypes_pv, nodes_pv, offsets_pv]
199-
)
198+
if hasattr(pv, "set_new_attribute"): # For pyvista >=0.46.0
199+
pv.set_new_attribute(
200+
obj=grid, name="_dpf_cache_op", value=[cells_pv, celltypes_pv, nodes_pv, offsets_pv]
201+
)
202+
else: # For pyvista <0.46.0 # pragma: nocover
203+
setattr(grid, "_dpf_cache_op", [cells_pv, celltypes_pv, nodes_pv, offsets_pv])
200204
return grid
201205

202206

@@ -356,11 +360,12 @@ def compute_offset():
356360

357361
# Quick fix required to hold onto the data as PyVista does not make a copy.
358362
# All of those now return DPFArrays
359-
# setattr(grid, "_dpf_cache", [node_coordinates, coordinates_field])
360-
pv.set_new_attribute(
361-
obj=grid, name="_dpf_cache", value=[node_coordinates, coordinates_field]
362-
)
363-
363+
if hasattr(pv, "set_new_attribute"): # For pyvista >=0.46.0
364+
pv.set_new_attribute(
365+
obj=grid, name="_dpf_cache_op", value=[node_coordinates, coordinates_field]
366+
)
367+
else: # For pyvista <0.46.0 # pragma: nocover
368+
setattr(grid, "_dpf_cache_op", [node_coordinates, coordinates_field])
364369
return grid
365370

366371
# might be computed when checking for VTK quadratic bug

0 commit comments

Comments
 (0)