DPF-Core has a variety of plotting methods to generate 3D plots of ANSYS models directly from Python. These methods use VTK and leverage the pyvista Python library to simplify plotting. Please see the pyvista Documentation for additional details.
Plotting the Mesh from the Model Object¶
Model.plot() method can be used to
immediately plot the mesh of the model after loading it. In the
following example, a simple pontoon mesh is downloaded from the
internet and loaded using the
>>> import ansys.dpf.core as dpf >>> from ansys.dpf.core import examples >>> filename = examples.download_pontoon() >>> model = dpf.Model(filename) >>> model.plot()
The default plotter settings display the mesh with edges shown with lighting enabled. For a full listing of all the keyword arguments, please see plot.
Plotting using the MeshedRegion¶
MeshedRegion.plot() method plots the meshed
region. If the
MeshedRegion is generated from the model’s
metadata, it will generate an identical plot as in the
>>> mesh = model.metadata.meshed_region >>> mesh.plot()
However, when provided with a field as the first argument, it will plot the mesh using those values. In the following example, we will extract the nodal strain in the X direction.
First, extract the X component strain >>> strain = model.results.strain() >>> fields = strain.outputs.fields_container() >>> field = fields.select_component(0) >>> print(field) DPF elastic_strain_1.s Field Location: ElementalNodal Unit: Num. id(s): 8640 Shape: 69120 This ElementalNodal strain must be converted to nodal strain for it to be plotted. >>> nodal_field = field.to_nodal() >>> mesh.plot(nodal_field)
At the moment, only fields with Elemental and Nodal locations are
supported. Use the
to_nodal to convert to nodal or the
'nodal_to_elemental' operator to convert to elemental.