|
2 | 2 | PropertyField
|
3 | 3 | =============
|
4 | 4 | """
|
| 5 | +from __future__ import annotations |
5 | 6 |
|
6 | 7 | import numpy as np
|
| 8 | +from typing import Union, TYPE_CHECKING |
| 9 | +if TYPE_CHECKING: |
| 10 | + from ansys.dpf.core.results import Result |
| 11 | + from ansys.dpf.core.field import Field |
| 12 | + from ansys.dpf.core.dpf_operator import Operator |
| 13 | + from ansys.dpf.core.meshed_region import MeshedRegion |
7 | 14 | from ansys.dpf.core.check_version import version_requires
|
8 | 15 | from ansys.dpf.core.common import natures, locations, _get_size_of_list
|
9 | 16 | from ansys.dpf.core import scoping, dimensionality
|
|
17 | 24 | dpf_array,
|
18 | 25 | dpf_vector,
|
19 | 26 | )
|
| 27 | +from ansys.dpf.core.plotter import DpfPlotter |
20 | 28 |
|
21 | 29 |
|
22 | 30 | class PropertyField(_FieldBase):
|
@@ -342,6 +350,51 @@ def name(self, value):
|
342 | 350 | self._field_definition, name=value
|
343 | 351 | )
|
344 | 352 |
|
| 353 | + def plot( |
| 354 | + self, |
| 355 | + meshed_region: MeshedRegion, |
| 356 | + deform_by: Union[Field, Result, Operator, None] = None, |
| 357 | + scale_factor: float = 1.0, |
| 358 | + **kwargs, |
| 359 | + ): |
| 360 | + """Plot the PropertyField on a MeshedRegion. |
| 361 | +
|
| 362 | + Parameters |
| 363 | + ---------- |
| 364 | + meshed_region: |
| 365 | + The mesh to plot the property field onto. |
| 366 | + deform_by: Field, Result, Operator, optional |
| 367 | + Used to deform the plotted mesh. Must output a 3D vector field. |
| 368 | + Defaults to None. |
| 369 | + scale_factor: |
| 370 | + Scaling factor to apply when warping the mesh. |
| 371 | + **kwargs: optional |
| 372 | + Additional keyword arguments for the plotter. For additional keyword |
| 373 | + arguments, see ``help(pyvista.plot)``. |
| 374 | +
|
| 375 | + Examples |
| 376 | + -------- |
| 377 | + Plot the displacement field from an example file. |
| 378 | +
|
| 379 | + >>> import ansys.dpf.core as dpf |
| 380 | + >>> from ansys.dpf.core import examples |
| 381 | + >>> model = dpf.Model(examples.find_multishells_rst()) |
| 382 | + >>> mesh = model.metadata.meshed_region |
| 383 | + >>> pf = mesh.property_field(property_name="mat") |
| 384 | + >>> pf.plot(meshed_region=mesh) |
| 385 | + """ |
| 386 | + pl = DpfPlotter(**kwargs) |
| 387 | + pl.add_field( |
| 388 | + field=self, |
| 389 | + meshed_region=meshed_region, |
| 390 | + deform_by=deform_by, |
| 391 | + scale_factor=scale_factor, |
| 392 | + show_axes=kwargs.pop("show_axes", True), |
| 393 | + **kwargs, |
| 394 | + ) |
| 395 | + kwargs.pop("notebook", None) |
| 396 | + return pl.show_figure(**kwargs) |
| 397 | + |
345 | 398 |
|
346 | 399 | class _LocalPropertyField(_LocalFieldBase, PropertyField):
|
347 | 400 | """Caches the internal data of a field so that it can be modified locally.
|
|
0 commit comments