Operator Specification#
The OperatorSpecification Provides a documentation for each Operator
- class ansys.dpf.core.operator_specification.PinSpecification(name: str, type_names: list, document='', optional=False, ellipsis=False, name_derived_class='')#
Documents an input or output pin of an Operator
- Parameters:
name (str) – Name of the Pin.
type_names (list[str], list[type], list[ansys.dpf.core.types], ansys.dpf.core.types, type, str) – List of accepted types.
document (str, optional) – Explains what the pin is used for and what should be connect to it.
optional (bool, optional) – Whether it is optional to connect to Pin or not. Default is False.
ellipsis (bool, optional) – Whether data respecting this PinSpecification can be connected from this pin number to infinity. Default is False.
Examples
>>> from ansys.dpf import core as dpf >>> operator = dpf.operators.result.displacement() >>> pin_spec = operator.specification.inputs[4] >>> pin_spec.name 'data_sources' >>> pin_spec.type_names ['data_sources'] >>> pin_spec.document 'result file path container, used if no streams are set' >>> pin_spec.optional False
- name_derived_class#
alias of
str
- property type_names: list[str]#
returns: List of accepted types. :rtype: list[str], list[type]
- class ansys.dpf.core.operator_specification.ConfigSpecification(*arg, **kw)#
Dictionary of the available configuration options and their specification (
ansys.dpf.core.operator_specification.ConfigOptionSpec
)- clear() None. Remove all items from D. #
- copy() a shallow copy of D #
- fromkeys(value=None, /)#
Create a new dictionary with keys from iterable and values set to value.
- get(key, default=None, /)#
Return the value for key if key is in the dictionary, else default.
- items() a set-like object providing a view on D's items #
- keys() a set-like object providing a view on D's keys #
- pop(k[, d]) v, remove specified key and return the corresponding value. #
If the key is not found, return the default if given; otherwise, raise a KeyError.
- popitem()#
Remove and return a (key, value) pair as a 2-tuple.
Pairs are returned in LIFO (last-in, first-out) order. Raises KeyError if the dict is empty.
- setdefault(key, default=None, /)#
Insert key with a value of default if key is not in the dictionary.
Return the value for key if key is in the dictionary, else default.
- update([E, ]**F) None. Update D from dict/iterable E and F. #
If E is present and has a .keys() method, then does: for k in E: D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k]
- values() an object providing a view on D's values #
- class ansys.dpf.core.operator_specification.ConfigOptionSpec(name: str, type_names: list, default_value_str: str, document: str)#
- Documentation of a configuration option available for a given
Operator (
ansys.dpf.core.Operator
)
- name#
Name of the Configuration Option.
- Type:
str
- type_names#
List of accepted types.
- Type:
list[str]
- default_value_str#
Gives the stringified value of the default.
- Type:
str
- document#
Documents the Configuration Option.
- Type:
str
Examples
>>> from ansys.dpf import core as dpf >>> operator = dpf.operators.math.add() >>> config_spec = operator.specification.config_specification >>> config_spec.keys() dict_keys(['binary_operation', 'inplace', 'mutex', 'num_threads', 'permissive', 'run_in_parallel', 'use_cache', 'work_by_index']) >>> config_spec['inplace'] ConfigOptionSpec(name='inplace', type_names=['bool'], default_value_str='false', document='The output is written over the input to save memory if this config is set to true.')
- class ansys.dpf.core.operator_specification.Specification(operator_name: str | None = None, specification: ansys.dpf.core.operator_specification.Specification | None = None, server: ansys.dpf.core.server_types.BaseServer | None = None)#
Documents an Operator with its description (what the Operator does), its inputs and outputs and some properties.
Examples
Get the Specification of an operator by its name >>> from ansys.dpf import core as dpf >>> spec = dpf.operator_specification.Specification(“U”) >>> # or >>> spec = dpf.Operator.operator_specification(“U”)
Get the specification of an instantiated operator >>> from ansys.dpf import core as dpf >>> operator = dpf.operators.result.displacement() >>> spec = operator.specification
Display the Specification attributes >>> spec.description ‘Read/compute nodal displacements by calling the readers defined by the datasources.’ >>> 4 in spec.inputs.keys() True >>> spec.outputs.keys() dict_keys([0]) >>> spec.inputs[4].document ‘result file path container, used if no streams are set’
- property properties: dict#
some additional properties of the Operator, like the category, the exposure, the scripting and user names, and the plugin
Examples
>>> from ansys.dpf import core as dpf >>> operator = dpf.operators.math.add() >>> operator.specification.properties {'category': 'math', 'exposure': 'public', 'plugin': 'core', 'user_name': '+'}
- property description: str#
Returns a description of the operation applied by the Operator
- Return type:
str
Examples
>>> from ansys.dpf import core as dpf >>> operator = dpf.operators.math.scale() >>> operator.specification.description 'Scales a field by a constant factor...'
- property inputs: dict#
Returns a dictionary mapping the input pin numbers to their
PinSpecification
- Returns:
inputs
- Return type:
dict[int:PinSpecification]
Examples
>>> from ansys.dpf import core as dpf >>> operator = dpf.operators.mesh.mesh_provider() >>> 4 in operator.specification.inputs.keys() True >>> operator.specification.inputs[4] PinSpecification(name='data_sources', _type_names=['data_sources'], ...set', ellipsis=False, name_derived_class='')
- property outputs: dict#
Returns a dictionary mapping the output pin numbers to their
PinSpecification
- Returns:
outputs
- Return type:
dict[int:PinSpecification]
Examples
>>> from ansys.dpf import core as dpf >>> operator = dpf.operators.mesh.mesh_provider() >>> operator.specification.outputs {0: PinSpecification(name='mesh', _type_names=['abstract_meshed_region'], ...=False, name_derived_class='')}
- property config_specification: ConfigSpecification#
Documents the available configuration options supported by the Operator
- Return type:
- class ansys.dpf.core.operator_specification.CustomConfigOptionSpec(option_name: str, default_value, document: str)#
- class ansys.dpf.core.operator_specification.SpecificationProperties(user_name: str | None = None, category: str | None = None, scripting_name: str | None = None, exposure: ansys.dpf.core.operator_specification.Exposures = 'public', plugin: str | None = None, license: str | None = None, spec=None, **kwargs)#
Properties of an Operator.
- Parameters:
user_name (str) – Readable lower case name of the Operator. example: “custom operator”.
category (str, Categories) – Choose from Categories options. Arrange the different Operators in the documentation and in the code generation.
scripting_name (str) – Snake case name of the Operator. example: “custom_operator”.
exposure (Exposures) – Public by default, a hidden or private Operator doesn’t appear in the documentation.
plugin (str) – Snake case name of the plugin it belongs to.
license (str) – Optional license name to check out that is used to run the operator. The value “any_dpf_supported_increments” tells DPF than any DPF-accepted license is accepted by this operator (see here). # noqa
- class ansys.dpf.core.operator_specification.CustomSpecification(description=None, server=None)#
Allows to create an Operator Specification with its description (what the Operator does), its inputs and outputs and some properties. Inherits from Specification (which has only getters) to implement setters.
Designed to be used in an implementation of
CustomOperatorBase
for the propertyspecification
.Notes
Is only implemented for usage with type(server)=
ansys.dpf.core.server_types.InProcessServer
and server version higher than 4.0.Examples
>>> from ansys.dpf.core.custom_operator import CustomOperatorBase >>> from ansys.dpf.core import Field >>> from ansys.dpf.core.operator_specification import CustomSpecification, SpecificationProperties, PinSpecification >>> class AddFloatToFieldData(CustomOperatorBase): ... def run(self): ... field = self.get_input(0, Field) ... to_add = self.get_input(1, float) ... data = field.data ... data += to_add ... self.set_output(0, field) ... self.set_succeeded() ... ... @property ... def specification(self): ... spec = CustomSpecification() ... spec.description = "Add a custom value to all the data of an input Field" ... spec.inputs = { ... 0: PinSpecification("field", [Field], "Field on which float value is added."), ... 1: PinSpecification("to_add", [float], "Data to add.") } ... spec.outputs = { ... 0: PinSpecification("field", [Field], "Updated field.")} ... spec.properties = SpecificationProperties("custom add to field", "math") ... return spec ... ... @property ... def name(self): ... return "custom_add_to_field"
- property description: str#
Description of the operation applied by the Operator
- property inputs: dict#
Dictionary mapping the input pin numbers to their
PinSpecification
- Returns:
inputs
- Return type:
dict[int:PinSpecification]
- property outputs: dict#
Returns a dictionary mapping the output pin numbers to their
PinSpecification
- Returns:
outputs
- Return type:
dict[int:PinSpecification]
- property config_specification: ConfigSpecification#
Documents the available configuration options supported by the Operator
- Return type:
- property properties: SpecificationProperties#
Returns some additional properties of the Operator, like the category, the exposure, the scripting and user names and the plugin