Operator#

class ansys.dpf.core.dpf_operator.Operator(name=None, config=None, server=None, operator=None)#

Represents an operator, which is an elementary operation.

The operator is the only object used to create and transform data. When the operator is evaluated, it processes the input information to compute its output with respect to its description.

Parameters:
  • name (str) – Name of the operator. For example, "U". You can use the "html_doc" operator to retrieve a list of existing operators.

  • config (Config, optional) – The Configuration allows to customize how the operation will be processed by the operator. 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

Create an operator from the library of operators.

>>> from ansys.dpf import core as dpf
>>> disp_oper = dpf.operators.result.displacement()

Create an operator from a model.

>>> from ansys.dpf.core import Model
>>> from ansys.dpf.core import examples
>>> model = Model(examples.find_static_rst())
>>> disp_oper = model.results.displacement()

Overview#

connect

Connect an input on the operator using a pin number.

connect_operator_as_input

Connect an operator as an input on a pin.

get_output

Retrieve the output of the operator on the pin number.

run

Evaluate this operator.

eval

Evaluate this operator.

progress_bar

Enable or disable progress bar display when requesting the operator’s output.

config

Copy of the operator’s current configuration.

id

Retrieve the unique identifier of the operator.

inputs

Inputs connected to the operator.

outputs

Outputs from the operator’s evaluation.

specification

Returns the Specification (or documentation) of this Operator.

default_config

Retrieve the default configuration for an operator.

operator_specification

Documents an Operator with its description (what the Operator does),its inputs and outputs and some properties.

__del__

Delete this instance.

__str__

Describe the entity.

__add__

Add two fields or two fields containers.

__sub__

Subtract two fields or two fields containers.

__pow__

Raise each element of a field or a fields container to power 2.

__mul__

Multiply two fields or two fields containers.

__truediv__

Perform division with another operator or a scalar.

Import detail#

from ansys.dpf.core.dpf_operator import Operator

Property detail#

property Operator.progress_bar: bool#

Enable or disable progress bar display when requesting the operator’s output.

With this property, the user can choose to print a progress bar when the operator’s output is requested, default is False

property Operator.config#

Copy of the operator’s current configuration.

You can modify the copy of the configuration and then use operator.config = new_config or instantiate an operator with the new configuration as a parameter.

For information on an operator’s options, see the documentation for that operator.

Returns:

Copy of the operator’s current configuration.

Return type:

ansys.dpf.core.config.Config

Examples

Modify the copy of an operator’s configuration and set it as current config of the operator.

>>> from ansys.dpf import core as dpf
>>> op = dpf.operators.math.add()
>>> config_add = op.config
>>> config_add.set_work_by_index_option(True)
>>> op.config = config_add
property Operator.id: int#

Retrieve the unique identifier of the operator.

This property returns the unique ID associated with the operator. This property is lazily initialized.

Returns:

The unique identifier of the operator.

Return type:

int

Notes

Property available with server’s version starting at 10.0.

property Operator.inputs#

Inputs connected to the operator.

Returns:

Inputs connected to the operator.

Return type:

ansys.dpf.core.inputs

Examples

Use the displacement operator.

>>> from ansys.dpf import core as dpf
>>> from ansys.dpf.core import examples
>>> data_src = dpf.DataSources(examples.find_multishells_rst())
>>> disp_op = dpf.operators.result.displacement()
>>> disp_op.inputs.data_sources(data_src)
property Operator.outputs#

Outputs from the operator’s evaluation.

Returns:

Outputs from the operator’s evaluation.

Return type:

ansys.dpf.core.outputs

Examples

Use the displacement operator.

>>> from ansys.dpf import core as dpf
>>> from ansys.dpf.core import examples
>>> data_src = dpf.DataSources(examples.find_multishells_rst())
>>> disp_op = dpf.operators.result.displacement()
>>> disp_op.inputs.data_sources(data_src)
>>> disp_fc = disp_op.outputs.fields_container()
property Operator.specification#

Returns the Specification (or documentation) of this Operator.

Return type:

Specification

Attribute detail#

Operator.name#

Method detail#

Operator.connect(pin, inpt, pin_out=0)#

Connect an input on the operator using a pin number.

Parameters:
  • pin (int) – Number of the input pin.

  • inpt (str, int, double, bool, list[int], list[float], Field, FieldsContainer, Scoping,)

  • ScopingsContainer – Operator, os.PathLike Object to connect to.

  • MeshedRegion – Operator, os.PathLike Object to connect to.

  • MeshesContainer – Operator, os.PathLike Object to connect to.

  • DataSources – Operator, os.PathLike Object to connect to.

  • CyclicSupport – Operator, os.PathLike Object to connect to.

  • dict – Operator, os.PathLike Object to connect to.

  • Outputs – Operator, os.PathLike Object to connect to.

  • pin_out (int, optional) – If the input is an operator, the output pin of the input operator. The default is 0.

Examples

Compute the minimum of displacement by chaining the "U" and "min_max_fc" operators.

>>> from ansys.dpf import core as dpf
>>> from ansys.dpf.core import examples
>>> data_src = dpf.DataSources(examples.find_multishells_rst())
>>> disp_op = dpf.operators.result.displacement()
>>> disp_op.inputs.data_sources(data_src)
>>> max_fc_op = dpf.operators.min_max.min_max_fc()
>>> max_fc_op.inputs.connect(disp_op.outputs)
>>> max_field = max_fc_op.outputs.field_max()
>>> max_field.data
DPFArray([[0.59428386, 0.00201751, 0.0006032 ]]...
Operator.connect_operator_as_input(pin, op)#

Connect an operator as an input on a pin.

Parameters:
Operator.get_output(pin=0, output_type=None)#

Retrieve the output of the operator on the pin number.

To activate the progress bar for server version higher or equal to 3.0, use my_op.progress_bar=True

Parameters:
  • pin (int, optional) – Number of the output pin. The default is 0.

  • output_type (ansys.dpf.core.common.types, type, optional) – Requested type of the output. The default is None.

Returns:

Output of the operator.

Return type:

type

static Operator.default_config(name, server=None)#

Retrieve the default configuration for an operator.

You can change the copy of the default configuration to meet your needs before instantiating the operator. The Configuration allows to customize how the operation will be processed by the operator.

Parameters:
  • name (str) – Name of the operator. For example "U". You can use the "html_doc" operator to retrieve a list of existing operators.

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

Returns:

Default configuration for the operator.

Return type:

class”ansys.dpf.core.config.Config

Operator.__del__()#

Delete this instance.

Operator.__str__()#

Describe the entity.

Returns:

Description of the entity.

Return type:

str

Operator.run()#

Evaluate this operator.

Operator.eval(pin=None)#

Evaluate this operator.

Parameters:

pin (int) – Number of the output pin. The default is None.

Returns:

output – Returns the first output of the operator by default and the output of a given pin when specified. Or, it only evaluates the operator without output.

Return type:

FieldsContainer, Field, MeshedRegion, Scoping

Examples

Use the eval method.

>>> from ansys.dpf import core as dpf
>>> import ansys.dpf.core.operators.math as math
>>> from ansys.dpf.core import examples
>>> data_src = dpf.DataSources(examples.find_multishells_rst())
>>> disp_op = dpf.operators.result.displacement()
>>> disp_op.inputs.data_sources(data_src)
>>> normfc = math.norm_fc(disp_op).eval()
Operator.__add__(fields_b)#

Add two fields or two fields containers.

Returns:

add

Return type:

operators.math.add_fc

Operator.__sub__(fields_b)#

Subtract two fields or two fields containers.

Returns:

minus

Return type:

operators.math.minus_fc

Operator.__pow__(value)#

Raise each element of a field or a fields container to power 2.

Operator.__mul__(value)#

Multiply two fields or two fields containers.

Returns:

mul

Return type:

operators.math.generalized_inner_product_fc

static Operator.operator_specification(op_name, server=None)#

Documents an Operator with its description (what the Operator does),its inputs and outputs and some properties.

Operator.__truediv__(inpt)#

Perform division with another operator or a scalar.

This method allows the use of the division operator (/) between an Operator instance and either another Operator or a scalar value (float).