How can one save a plot of a pydpf result when using pypdf in standalone (IDE) mode?
This is the standard question from customers who are partaking in a pyanys discussion, how can they plot results to file.
They would like plots/images of the results that are created and pop up when using pyansys tools. If they were matplotlib plots it would be possible to write them to file.
How to do similar with the pydpf results.
Best Answers
-
As far as I'm aware we can export in .stl format for the mesh, and in .vtk format for results. There's also a plotter that uses the PyVista one (https://dpfdocs.pyansys.com/api/ansys.dpf.core.plotter.html?highlight=image), which seems to allow for exporting of images.
6 -
from ansys.dpf import core as dpf from ansys.dpf.core import examples from ansys.dpf.core.plotter import DpfPlotter # Here we create a Model and request its mesh and a displacement result model = dpf.Model(examples.msup_transient) mesh = model.metadata.meshed_region disp = model.results.displacement().outputs.fields_container()[0] # Then we plot and save the screenshot pl = DpfPlotter(notebook=False) # set notebook to false to disable showing in the current window pl.add_field(disp, mesh) pl.show_figure(screenshot='D:\my_screenshot.png') # set screenshot file_path
0
Answers
-
How can I define a particular view? For example, I want to view at a certain detail of a part.
0 -
There is a list of standard views that can be used for plots:
cpos_list = ['xy' ,'xz', 'yz', 'yx', 'zx', 'zy', 'iso']And you can use named selection to get a detail (set the name selection to whatever detail area you require, but include enough to make it meaningful, so a selection of elements and not a single node or element).
named_selections = model.metadata.available_named_selections nameselection = named_selections[0]
Then set up your result plot to those args (example for step n, von mises stress below):
cpos = cpos_list[0] # set a view mesh_scoping = model.metadata.named_selection(nameselection) time_sets_scoping = dpf.time_freq_scoping_factory.scoping_by_sets([n]) s_eqv_op = dpf.operators.result.stress_von_mises(data_sources=model, mesh_scoping = mesh_scoping, time_scoping = time_sets_scoping) s_eqv_fields = s_eqv_op.outputs.fields_container() vm_stress_nodal = s_eqv_fields[0] plot = DpfPlotter(notebook=False, off_screen=True) plot.add_field(vm_stress_nodal, mesh, show_edges=True, opacity=0.8) plot_path= os.path.join(set path) plot.show_figure(cpos = cpos, screenshot=plot_path, text = 'plot info')
0