Skip to content
  •  
  •  
  •  
21 changes: 14 additions & 7 deletions src/ansys/dpf/core/inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,18 @@

from enum import Enum
from textwrap import wrap
from typing import Generic, TypeVar
import warnings
import weakref

from ansys.dpf import core
from ansys.dpf.core.mapping_types import map_types_to_python
from ansys.dpf.core.outputs import Output, _Outputs

T = TypeVar("T")

class Input:

class Input(Generic[T]):
"""
Intermediate class internally instantiated by the :class:`ansys.dpf.core.dpf_operator.Operator`.

Expand Down Expand Up @@ -70,13 +73,15 @@ def __init__(self, spec, pin, operator, count_ellipsis=-1):
self.name += str(self._count_ellipsis + 1)
self._update_doc_str(docstr, self.name)

def connect(self, inpt):
def connect(self, inpt: T):
"""Connect any input (entity or operator output) to a specified input pin of this operator.

Parameters
----------
inpt : str, int, double, Field, FieldsContainer, Scoping, DataSources, MeshedRegion, Enum,
Output, Outputs, Operator, os.PathLike
inpt : str, int, float, bool, list[float], list[int], dict, Operator, PropertyField, ScopingsContainer,
DataSources, UnitSystem, CyclicSupport, DataTree, Workflow, StreamsContainer, FieldsContainer, Field,
CustomTypeField, MeshedRegion, Any, GenericDataContainer, Scoping, StringField, MeshesContainer, ResultInfo,
TimeFreqSupport, Output, Outputs, os.PathLike, UnitSystem, Enum # noqa: E501
Input of the operator.

"""
Expand Down Expand Up @@ -173,7 +178,7 @@ def connect(self, inpt):

self.__inc_if_ellipsis()

def __call__(self, inpt):
def __call__(self, inpt: T):
"""Allow instances to be called like a function."""
self.connect(inpt)

Expand Down Expand Up @@ -244,8 +249,10 @@ def connect(self, inpt):

Parameters
----------
inpt : str, int, double, bool, list[int], list[float], Field, FieldsContainer, Scoping, Enum,
ScopingsContainer, MeshedRegion, MeshesContainer, DataSources, CyclicSupport, Outputs, os.PathLike # noqa: E501
inpt : str, int, float, bool, list[float], list[int], dict, Operator, PropertyField, ScopingsContainer,
DataSources, UnitSystem, CyclicSupport, DataTree, Workflow, StreamsContainer, FieldsContainer, Field,
CustomTypeField, MeshedRegion, Any, GenericDataContainer, Scoping, StringField, MeshesContainer, ResultInfo,
TimeFreqSupport, Output, Outputs, os.PathLike, UnitSystem, Enum # noqa: E501
Input of the operator.

"""
Expand Down
1 change: 0 additions & 1 deletion src/ansys/dpf/core/operators/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from . import compression
from . import filter
from . import geo
from . import info
from . import invariant
from . import logic
from . import mapping
Expand Down
35 changes: 25 additions & 10 deletions src/ansys/dpf/core/operators/averaging/elemental_difference.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"""

from __future__ import annotations
from typing import TYPE_CHECKING

from warnings import warn
from ansys.dpf.core.dpf_operator import Operator
Expand All @@ -14,6 +15,12 @@
from ansys.dpf.core.config import Config
from ansys.dpf.core.server_types import AnyServerType

if TYPE_CHECKING:
from ansys.dpf.core.scoping import Scoping
from ansys.dpf.core.fields_container import FieldsContainer
from ansys.dpf.core.meshed_region import MeshedRegion
from ansys.dpf.core.field import Field


class elemental_difference(Operator):
r"""Transforms an Elemental Nodal or Nodal field into an Elemental field.
Expand Down Expand Up @@ -199,19 +206,25 @@ class InputsElementalDifference(_Inputs):

def __init__(self, op: Operator):
super().__init__(elemental_difference._spec().inputs, op)
self._field = Input(elemental_difference._spec().input_pin(0), 0, op, -1)
self._field: Input[Field | FieldsContainer] = Input(
elemental_difference._spec().input_pin(0), 0, op, -1
)
self._inputs.append(self._field)
self._mesh_scoping = Input(elemental_difference._spec().input_pin(1), 1, op, -1)
self._mesh_scoping: Input[Scoping] = Input(
elemental_difference._spec().input_pin(1), 1, op, -1
)
self._inputs.append(self._mesh_scoping)
self._mesh = Input(elemental_difference._spec().input_pin(7), 7, op, -1)
self._mesh: Input[MeshedRegion] = Input(
elemental_difference._spec().input_pin(7), 7, op, -1
)
self._inputs.append(self._mesh)
self._through_layers = Input(
self._through_layers: Input[bool] = Input(
elemental_difference._spec().input_pin(10), 10, op, -1
)
self._inputs.append(self._through_layers)

@property
def field(self) -> Input:
def field(self) -> Input[Field | FieldsContainer]:
r"""Allows to connect field input to the operator.

field or fields container with only one field is expected
Expand All @@ -232,7 +245,7 @@ def field(self) -> Input:
return self._field

@property
def mesh_scoping(self) -> Input:
def mesh_scoping(self) -> Input[Scoping]:
r"""Allows to connect mesh_scoping input to the operator.

average only on these entities
Expand All @@ -253,7 +266,7 @@ def mesh_scoping(self) -> Input:
return self._mesh_scoping

@property
def mesh(self) -> Input:
def mesh(self) -> Input[MeshedRegion]:
r"""Allows to connect mesh input to the operator.

Returns
Expand All @@ -272,7 +285,7 @@ def mesh(self) -> Input:
return self._mesh

@property
def through_layers(self) -> Input:
def through_layers(self) -> Input[bool]:
r"""Allows to connect through_layers input to the operator.

The maximum elemental difference is taken through the different shell layers if true (default is false).
Expand Down Expand Up @@ -307,11 +320,13 @@ class OutputsElementalDifference(_Outputs):

def __init__(self, op: Operator):
super().__init__(elemental_difference._spec().outputs, op)
self._field = Output(elemental_difference._spec().output_pin(0), 0, op)
self._field: Output[Field] = Output(
elemental_difference._spec().output_pin(0), 0, op
)
self._outputs.append(self._field)

@property
def field(self) -> Output:
def field(self) -> Output[Field]:
r"""Allows to get field output of the operator

Returns
Expand Down
32 changes: 22 additions & 10 deletions src/ansys/dpf/core/operators/averaging/elemental_difference_fc.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"""

from __future__ import annotations
from typing import TYPE_CHECKING

from warnings import warn
from ansys.dpf.core.dpf_operator import Operator
Expand All @@ -14,6 +15,13 @@
from ansys.dpf.core.config import Config
from ansys.dpf.core.server_types import AnyServerType

if TYPE_CHECKING:
from ansys.dpf.core.scoping import Scoping
from ansys.dpf.core.scopings_container import ScopingsContainer
from ansys.dpf.core.meshes_container import MeshesContainer
from ansys.dpf.core.fields_container import FieldsContainer
from ansys.dpf.core.meshed_region import MeshedRegion


class elemental_difference_fc(Operator):
r"""Transforms an Elemental Nodal or Nodal field into an Elemental field.
Expand Down Expand Up @@ -205,21 +213,25 @@ class InputsElementalDifferenceFc(_Inputs):

def __init__(self, op: Operator):
super().__init__(elemental_difference_fc._spec().inputs, op)
self._fields_container = Input(
self._fields_container: Input[FieldsContainer] = Input(
elemental_difference_fc._spec().input_pin(0), 0, op, -1
)
self._inputs.append(self._fields_container)
self._mesh = Input(elemental_difference_fc._spec().input_pin(1), 1, op, -1)
self._mesh: Input[MeshedRegion | MeshesContainer] = Input(
elemental_difference_fc._spec().input_pin(1), 1, op, -1
)
self._inputs.append(self._mesh)
self._scoping = Input(elemental_difference_fc._spec().input_pin(3), 3, op, -1)
self._scoping: Input[Scoping | ScopingsContainer] = Input(
elemental_difference_fc._spec().input_pin(3), 3, op, -1
)
self._inputs.append(self._scoping)
self._collapse_shell_layers = Input(
self._collapse_shell_layers: Input[bool] = Input(
elemental_difference_fc._spec().input_pin(10), 10, op, -1
)
self._inputs.append(self._collapse_shell_layers)

@property
def fields_container(self) -> Input:
def fields_container(self) -> Input[FieldsContainer]:
r"""Allows to connect fields_container input to the operator.

Returns
Expand All @@ -238,7 +250,7 @@ def fields_container(self) -> Input:
return self._fields_container

@property
def mesh(self) -> Input:
def mesh(self) -> Input[MeshedRegion | MeshesContainer]:
r"""Allows to connect mesh input to the operator.

The mesh region in this pin is used to perform the averaging, used if there is no fields support.
Expand All @@ -259,7 +271,7 @@ def mesh(self) -> Input:
return self._mesh

@property
def scoping(self) -> Input:
def scoping(self) -> Input[Scoping | ScopingsContainer]:
r"""Allows to connect scoping input to the operator.

Average only on these elements. If it is scoping container, the label must correspond to the one of the fields container.
Expand All @@ -280,7 +292,7 @@ def scoping(self) -> Input:
return self._scoping

@property
def collapse_shell_layers(self) -> Input:
def collapse_shell_layers(self) -> Input[bool]:
r"""Allows to connect collapse_shell_layers input to the operator.

If true, the data across different shell layers is averaged as well (default is false).
Expand Down Expand Up @@ -315,13 +327,13 @@ class OutputsElementalDifferenceFc(_Outputs):

def __init__(self, op: Operator):
super().__init__(elemental_difference_fc._spec().outputs, op)
self._fields_container = Output(
self._fields_container: Output[FieldsContainer] = Output(
elemental_difference_fc._spec().output_pin(0), 0, op
)
self._outputs.append(self._fields_container)

@property
def fields_container(self) -> Output:
def fields_container(self) -> Output[FieldsContainer]:
r"""Allows to get fields_container output of the operator

Returns
Expand Down
36 changes: 24 additions & 12 deletions src/ansys/dpf/core/operators/averaging/elemental_fraction_fc.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"""

from __future__ import annotations
from typing import TYPE_CHECKING

from warnings import warn
from ansys.dpf.core.dpf_operator import Operator
Expand All @@ -14,6 +15,11 @@
from ansys.dpf.core.config import Config
from ansys.dpf.core.server_types import AnyServerType

if TYPE_CHECKING:
from ansys.dpf.core.fields_container import FieldsContainer
from ansys.dpf.core.meshed_region import MeshedRegion
from ansys.dpf.core.scoping import Scoping


class elemental_fraction_fc(Operator):
r"""Transforms Elemental Nodal fields into Elemental fields. Each elemental
Expand Down Expand Up @@ -213,23 +219,29 @@ class InputsElementalFractionFc(_Inputs):

def __init__(self, op: Operator):
super().__init__(elemental_fraction_fc._spec().inputs, op)
self._fields_container = Input(
self._fields_container: Input[FieldsContainer] = Input(
elemental_fraction_fc._spec().input_pin(0), 0, op, -1
)
self._inputs.append(self._fields_container)
self._mesh = Input(elemental_fraction_fc._spec().input_pin(1), 1, op, -1)
self._mesh: Input[MeshedRegion] = Input(
elemental_fraction_fc._spec().input_pin(1), 1, op, -1
)
self._inputs.append(self._mesh)
self._scoping = Input(elemental_fraction_fc._spec().input_pin(3), 3, op, -1)
self._scoping: Input[Scoping] = Input(
elemental_fraction_fc._spec().input_pin(3), 3, op, -1
)
self._inputs.append(self._scoping)
self._denominator = Input(elemental_fraction_fc._spec().input_pin(6), 6, op, -1)
self._denominator: Input[FieldsContainer] = Input(
elemental_fraction_fc._spec().input_pin(6), 6, op, -1
)
self._inputs.append(self._denominator)
self._collapse_shell_layers = Input(
self._collapse_shell_layers: Input[bool] = Input(
elemental_fraction_fc._spec().input_pin(10), 10, op, -1
)
self._inputs.append(self._collapse_shell_layers)

@property
def fields_container(self) -> Input:
def fields_container(self) -> Input[FieldsContainer]:
r"""Allows to connect fields_container input to the operator.

Returns
Expand All @@ -248,7 +260,7 @@ def fields_container(self) -> Input:
return self._fields_container

@property
def mesh(self) -> Input:
def mesh(self) -> Input[MeshedRegion]:
r"""Allows to connect mesh input to the operator.

The mesh region in this pin is used to perform the averaging. It is used if there is no fields support.
Expand All @@ -269,7 +281,7 @@ def mesh(self) -> Input:
return self._mesh

@property
def scoping(self) -> Input:
def scoping(self) -> Input[Scoping]:
r"""Allows to connect scoping input to the operator.

Average only on these elements. If it is a scoping container, the label must correspond to the one of the fields containers.
Expand All @@ -290,7 +302,7 @@ def scoping(self) -> Input:
return self._scoping

@property
def denominator(self) -> Input:
def denominator(self) -> Input[FieldsContainer]:
r"""Allows to connect denominator input to the operator.

If a fields container is set in this pin, it is used as the denominator of the fraction instead of entity_average_fc.
Expand All @@ -311,7 +323,7 @@ def denominator(self) -> Input:
return self._denominator

@property
def collapse_shell_layers(self) -> Input:
def collapse_shell_layers(self) -> Input[bool]:
r"""Allows to connect collapse_shell_layers input to the operator.

If true, the data across different shell layers is averaged as well (default is false).
Expand Down Expand Up @@ -346,13 +358,13 @@ class OutputsElementalFractionFc(_Outputs):

def __init__(self, op: Operator):
super().__init__(elemental_fraction_fc._spec().outputs, op)
self._fields_container = Output(
self._fields_container: Output[FieldsContainer] = Output(
elemental_fraction_fc._spec().output_pin(0), 0, op
)
self._outputs.append(self._fields_container)

@property
def fields_container(self) -> Output:
def fields_container(self) -> Output[FieldsContainer]:
r"""Allows to get fields_container output of the operator

Returns
Expand Down
Loading
Loading