Model#

class ansys.dpf.core.model.Model(data_sources=None, server=None)#

Connects to a gRPC DPF server and allows access to a result using the DPF framework.

Parameters:
  • data_sources (str, dpf.core.DataSources, os.PathLike) – Accepts either a dpf.core.DataSources instance or the path of the result file to open as an os.PathLike object or a str. The default is None.

  • server (server.DPFServer, optional) – Server with the channel connected to the remote or local instance. The default is None, in which case an attempt is made to use the global server.

Examples

>>> from ansys.dpf import core as dpf
>>> from ansys.dpf.core import examples
>>> transient = examples.download_transient_result()
>>> model = dpf.Model(transient)

Overview#

operator

Operator associated with the data sources of this model.

plot

Plot the mesh of the model.

metadata

Model metadata.

results

Available results of the model.

mesh_by_default

If true, the mesh is connected by default to operators supporting the mesh input.

__str__

Return string representation of the model.

Import detail#

from ansys.dpf.core.model import Model

Property detail#

property Model.metadata#

Model metadata.

Includes:

  • data_sources

  • meshed_region

  • time_freq_support

  • result_info

  • mesh_provider

  • mesh_info

Returns:

metadata

Return type:

Metadata

Examples

>>> from ansys.dpf.core import Model
>>> from ansys.dpf.core import examples
>>> transient = examples.download_transient_result()
>>> model = Model(transient)

Get the meshed region of the model and extract the element numbers.

>>> meshed_region = model.metadata.meshed_region
>>> meshed_region.elements.scoping.ids[2]
np.int32(759)

Get the data sources of the model.

>>> ds = model.metadata.data_sources

Print the number of result sets.

>>> tf = model.metadata.time_freq_support
>>> tf.n_sets
35

Get the unit system used in the analysis.

>>> rinfo = model.metadata.result_info
>>> rinfo.unit_system
'MKS: m, kg, N, s, V, A, degC'
property Model.results#

Available results of the model.

Organizes the results from DPF into accessible methods. All the available results are dynamically created depending on the model’s class:ansys.dpf.core.result_info.

Returns:

results – Available results of the model if possible, else returns common results.

Return type:

Results, CommonResults

all types of results

Result provider helper wrapping all types of provider available for a given result file.

Type:

Result

Examples

>>> from ansys.dpf import core as dpf
>>> from ansys.dpf.core import examples
>>> model = dpf.Model(examples.find_electric_therm())
>>> v = model.results.electric_potential
>>> dissip = model.results.thermal_dissipation_energy

Examples

Extract the result object from a model.

>>> from ansys.dpf import core as dpf
>>> from ansys.dpf.core import examples
>>> model = dpf.Model(examples.find_simple_bar())
>>> results = model.results # printable object

Access the displacement at all times.

>>> from ansys.dpf.core import Model
>>> from ansys.dpf.core import examples
>>> transient = examples.download_transient_result()
>>> model = Model(transient)
>>> displacements = model.results.displacement.on_all_time_freqs.eval()
property Model.mesh_by_default#

If true, the mesh is connected by default to operators supporting the mesh input.

Method detail#

Model.operator(name)#

Operator associated with the data sources of this model.

Parameters:

name (str) – Operator name, which must be valid.

Examples

Create a displacement operator.

>>> from ansys.dpf.core import Model
>>> from ansys.dpf.core import examples
>>> transient = examples.download_transient_result()
>>> model = Model(transient)
>>> disp = model.operator('U')

Create a sum operator.

>>> sum = model.operator('accumulate')
Model.__str__()#

Return string representation of the model.

Model.plot(color='w', show_edges=True, **kwargs)#

Plot the mesh of the model.

Parameters:
  • color (str) – color of the mesh faces in PyVista format. The default is white with "w".

  • show_edges (bool) – Whether to show the mesh edges. The default is True.

  • **kwargs (optional) – Additional keyword arguments for the plotter. For additional keyword arguments, see help(pyvista.plot).

Examples

Plot the model using the default options.

>>> from ansys.dpf.core import Model
>>> from ansys.dpf.core import examples
>>> transient = examples.download_transient_result()
>>> model = Model(transient)
>>> model.plot()