ansys / pydpf-core

Data Processing Framework - Python Core
http://dpf.docs.pyansys.com/
MIT License
70 stars 25 forks source link

[Enhancement] Extract and plot isolines #50

Open pmaroneh opened 3 years ago

pmaroneh commented 3 years ago

It would be convenient to easily be able to extract and plot isolines from a dataset. Plotting of isolines can be done natively in Mechanical but the data of the isolines (coordinate, value) cannot be exported: image

akaszynski commented 3 years ago

See contouring within pyvista for this.

pmaroneh commented 3 years ago

Thanks @akaszynski. I also considered using matplotlib.pyplot.contour. I'll give it a shot later this week.

akaszynski commented 3 years ago

matplotlib is great for 2D data. pyvista & VTK is better suited for 3D data.

pmaroneh commented 3 years ago

See https://github.com/pyansys/DPF-Core/issues/59 for further info

PProfizi commented 2 years ago

Hi @pmaroneh, as mentioned in #59 , one can get the UnstructuredGrid vtk object from a field by using:

vtk_UnstructuredGrid = field.meshed_region.grid

I thus got a sort of working example:

from ansys.dpf import core as dpf from ansys.dpf.core import examples import pyvista as pv

model = dpf.Model(examples.multishells_rst) disp = model.results.displacement() x_disp = disp.Z() fc = x_disp.outputs.fields_container() field = fc[0] vtk_UnstructuredGrid = field.meshed_region.grid vtk_UnstructuredGrid.point_data["disp"] = field.data

contours = vtk_UnstructuredGrid.contour(scalars="disp")

pl = pv.Plotter() pl.add_mesh(vtk_UnstructuredGrid, color="w", opacity=0.1) pl.add_mesh(contours) pl.show()

image

We can then start an enhancement PR to implement a helper for this.