Model#

Module contains the Model class to manage file result models.

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)
property metadata#

Model metadata.

Includes:

  • data_sources

  • meshed_region

  • time_freq_support

  • result_info

  • mesh_provider

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]
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 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.

Examples

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

Result

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.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()
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')
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()
property mesh_by_default#

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

class ansys.dpf.core.model.Metadata(data_sources, server)#

Contains the metadata of a data source.

Parameters
  • data_sources (DataSources) –

  • server (server.DPFServer) – Server with the channel connected to the remote or local instance.

property time_freq_support#

Time frequency support.

Returns

Time frequency support.

Return type

ansys.dpf.core.time_freq_support.TimeFreqSupport

Examples

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

Get the number of sets from the result file.

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

Get the time values for the active result.

>>> tf.time_frequencies.data
array([0.        , 0.019975  , 0.039975  , 0.059975  , 0.079975  ,
       0.099975  , 0.119975  , 0.139975  , 0.159975  , 0.179975  ,
       0.199975  , 0.218975  , 0.238975  , 0.258975  , 0.278975  ,
       0.298975  , 0.318975  , 0.338975  , 0.358975  , 0.378975  ,
       0.398975  , 0.417975  , 0.437975  , 0.457975  , 0.477975  ,
       0.497975  , 0.517975  , 0.53754972, 0.55725277, 0.57711786,
       0.59702054, 0.61694639, 0.63683347, 0.65673452, 0.67662783])
property data_sources#

Data sources instance.

This data source can be connected to other operators.

Returns

data_sources

Return type

DataSources

Examples

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

Connect the model data sources to the ‘U’ operator.

>>> ds = model.metadata.data_sources
>>> op = dpf.operators.result.displacement()
>>> op.inputs.data_sources.connect(ds)
property streams_provider#

Streams provider operator connected to the data sources.

This streams provider can be connected to other operators.

Returns

streams_provider

Return type

ansys.dpf.core.operators.metadata.streams_provider

Examples

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

Connect the model data sources to the U operator.

>>> streams = model.metadata.streams_provider
>>> op = dpf.operators.result.displacement()
>>> op.inputs.streams_container.connect(streams)
property meshed_region#

Meshed region instance.

Returns

mesh – Mesh

Return type

ansys.dpf.core.meshed_region.MeshedRegion

property mesh_provider#

Mesh provider operator.

This operator reads a mesh from the result file. The underlying operator symbol is the class:ansys.dpf.core.operators.mesh.mesh_provider operator.

Returns

mesh_provider – Mesh provider operator.

Return type

ansys.dpf.core.operators.mesh.mesh_provider

property result_info#

Result Info instance.

Returns

result_info

Return type

ansys.dpf.core.result_info.ResultInfo

property available_named_selections#

List of available named selections.

Returns

named_selections

Return type

list str

named_selection(named_selection)#

Scoping containing the list of nodes or elements in the named selection.

Parameters

named_selection (str) – name of the named selection

Returns

named_selection

Return type

ansys.dpf.core.scoping.Scoping