Model

Module contains the Model class to manage file result models.

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

This class connects to a gRPC DPF server and allows you to access a result using the DPF framework.

Parameters
  • data_sources (str, dpf.core.DataSources) – Accepts either a dpf.core.DataSources instance or a filename of the result file to open.

  • server (server.DPFServer, optional) – Server with channel connected to the remote or local instance. When None, attempts to use the 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
'Metric (m, kg, N, s, V, A)'
property results

Available results of the model. Organize the results from DPF into accessible methods. All the available results are dynamically created depending on the model’s ‘ResultInfo’

Returns

Available results of the model

Return type

Results

all types of results

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

Examples

Create a stress result from the model and choose its time and mesh scopings

>>> from ansys.dpf import core as dpf
>>> from ansys.dpf.core import examples
>>> model = dpf.Model(examples.electric_therm)
>>> v = model.results.electric_potential
>>> rf = model.results.reaction_force
>>> 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)

Returns an operator associated with the data sources of this model.

Parameters

name (str) – Operator name. Must be a valid operator name.

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

Examples

Plot the model with 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()
class ansys.dpf.core.model.Metadata(data_sources, server)

Contains the metadata of a data source.

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

DataSources 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

stream_provider operator connected to the data sources

This streams_provider can be connected to other operators.

Returns

streams_provider

Return type

operators.metadata.stream_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.MeshedRegion

property mesh_provider

Mesh provider operator

This operator reads a mesh from the result file.

Returns

mesh_provider – Mesh provider operator.

Return type

ansys.dpf.core.Operator

Notes

Underlying operator symbol is MeshProvider operator

property available_named_selections

Returns a list of available named selections

Returns

named_selections

Return type

list str

named_selection(named_selection)

Returns a 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

dpf.core.Scoping