Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
8 changes: 4 additions & 4 deletions src/ansys/dpf/core/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,12 +311,12 @@ def _deep_copy(dpf_entity, server=None):
if stream_type == 1:
out = serializer.get_output(0, types.bytes)
else:
out = serializer.outputs.serialized_string # Required for retro with 241
deserializer.connect(-1, stream_type)
deserializer.connect(0, out)
out = serializer.outputs.serialized_string1 # Required for retro with 241
deserializer.inputs.stream_type.connect(stream_type)
deserializer.inputs.serialized_string1.connect(out)
type_map = types_enum_to_types()
output_type = list(type_map.keys())[list(type_map.values()).index(dpf_entity.__class__)]
return deserializer.get_output(1, output_type)
return deserializer.get_output(pin=1, output_type=output_type)


class BaseService:
Expand Down
60 changes: 51 additions & 9 deletions src/ansys/dpf/core/dpf_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,13 @@

"""Operator."""

from __future__ import annotations

from enum import Enum
import logging
import os
import traceback
from typing import TYPE_CHECKING
import warnings

import numpy
Expand Down Expand Up @@ -58,6 +61,10 @@
operator_grpcapi,
)

if TYPE_CHECKING: # pragma: no cover
from ansys.dpf.core.inputs import _Inputs
from ansys.dpf.core.server import AnyServerType

LOG = logging.getLogger(__name__)
LOG.setLevel("DEBUG")

Expand Down Expand Up @@ -90,19 +97,31 @@ class Operator:

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

config : Config, optional
config:
The Configuration allows to customize how the operation
will be processed by the operator. The default is ``None``.

server : server.DPFServer, optional
server:
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.

operator:
An existing operator reference to wrap. If an operator reference is provided,
the name, server, inputs_type, and outputs_type parameters are ignored.

inputs_type:
The class to use for the inputs of the operator. If not specified,
the default Inputs class is used.

outputs_type:
The class to use for the outputs of the operator. If not specified,
the default Outputs class is used.

Examples
--------
Create an operator from the library of operators.
Expand All @@ -119,12 +138,22 @@ class Operator:

"""

def __init__(self, name=None, config=None, server=None, operator=None):
def __init__(
self,
name: str = None,
config: Config = None,
server: AnyServerType = None,
operator: Operator | int = None,
inputs_type: type[_Inputs] = Inputs,
outputs_type: type[_Outputs] = Outputs,
):
"""Initialize the operator with its name by connecting to a stub."""
self.name = name
self._internal_obj = None
self._description = None
self._inputs = None
self._inputs_class = inputs_type
self._outputs_class = outputs_type
self._id = None

# step 1: get server
Expand Down Expand Up @@ -168,9 +197,14 @@ def __init__(self, name=None, config=None, server=None, operator=None):
)

self._spec = Specification(operator_name=self.name, server=self._server)
# add dynamic inputs
if len(self._spec.inputs) > 0 and self._inputs is None:
self._inputs = Inputs(self._spec.inputs, self)
# add dynamic inputs if no specific Inputs subclass is used
if len(self._spec.inputs) > 0:
if self._inputs_class == Inputs:
self._inputs = self._inputs_class(self._spec.inputs, self)
else:
self._inputs = self._inputs_class(self)
else:
self._inputs = None

# step4: if object exists: take instance (config)
if config:
Expand Down Expand Up @@ -219,8 +253,13 @@ def _add_sub_res_operators(self, sub_results):

@property
def _outputs(self):
if self._spec and len(self._spec.outputs) != 0:
return Outputs(self._spec.outputs, self)
if self._outputs_class == Outputs:
if self._spec and len(self._spec.outputs) != 0:
return self._outputs_class(self._spec.outputs, self)
else:
return None
else:
return self._outputs_class(self)

@_outputs.setter
def _outputs(self, value):
Expand Down Expand Up @@ -831,6 +870,9 @@ def _find_outputs_corresponding_pins(
# Type match
if input_type_name == python_name:
corresponding_pins.append(pin)
# Treat bytes as str
elif input_type_name == "bytes" and python_name == "str":
corresponding_pins.append(pin)
# if the inpt has multiple potential outputs, find which ones can match
elif isinstance(inpt, (_Outputs, Operator, Result)):
if isinstance(inpt, Operator):
Expand Down
4 changes: 2 additions & 2 deletions src/ansys/dpf/core/inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

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

Expand Down Expand Up @@ -73,7 +73,7 @@ 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: T):
def connect(self, inpt: Union[T, Output[T]]):
"""Connect any input (entity or operator output) to a specified input pin of this operator."""
from pathlib import Path

Expand Down
13 changes: 7 additions & 6 deletions src/ansys/dpf/core/operators/averaging/elemental_difference.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,6 @@ class elemental_difference(Operator):
>>> result_field = op.outputs.field()
"""

_inputs: InputsElementalDifference
_outputs: OutputsElementalDifference

def __init__(
self,
field=None,
Expand All @@ -84,9 +81,13 @@ def __init__(
config=None,
server=None,
):
super().__init__(name="elemental_difference", config=config, server=server)
self._inputs = InputsElementalDifference(self)
self._outputs = OutputsElementalDifference(self)
super().__init__(
name="elemental_difference",
config=config,
server=server,
inputs_type=InputsElementalDifference,
outputs_type=OutputsElementalDifference,
)
if field is not None:
self.inputs.field.connect(field)
if mesh_scoping is not None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,6 @@ class elemental_difference_fc(Operator):
>>> result_fields_container = op.outputs.fields_container()
"""

_inputs: InputsElementalDifferenceFc
_outputs: OutputsElementalDifferenceFc

def __init__(
self,
fields_container=None,
Expand All @@ -88,9 +85,13 @@ def __init__(
config=None,
server=None,
):
super().__init__(name="elemental_difference_fc", config=config, server=server)
self._inputs = InputsElementalDifferenceFc(self)
self._outputs = OutputsElementalDifferenceFc(self)
super().__init__(
name="elemental_difference_fc",
config=config,
server=server,
inputs_type=InputsElementalDifferenceFc,
outputs_type=OutputsElementalDifferenceFc,
)
if fields_container is not None:
self.inputs.fields_container.connect(fields_container)
if mesh is not None:
Expand Down
13 changes: 7 additions & 6 deletions src/ansys/dpf/core/operators/averaging/elemental_fraction_fc.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,6 @@ class elemental_fraction_fc(Operator):
>>> result_fields_container = op.outputs.fields_container()
"""

_inputs: InputsElementalFractionFc
_outputs: OutputsElementalFractionFc

def __init__(
self,
fields_container=None,
Expand All @@ -88,9 +85,13 @@ def __init__(
config=None,
server=None,
):
super().__init__(name="elemental_fraction_fc", config=config, server=server)
self._inputs = InputsElementalFractionFc(self)
self._outputs = OutputsElementalFractionFc(self)
super().__init__(
name="elemental_fraction_fc",
config=config,
server=server,
inputs_type=InputsElementalFractionFc,
outputs_type=OutputsElementalFractionFc,
)
if fields_container is not None:
self.inputs.fields_container.connect(fields_container)
if mesh is not None:
Expand Down
13 changes: 7 additions & 6 deletions src/ansys/dpf/core/operators/averaging/elemental_mean.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,6 @@ class elemental_mean(Operator):
>>> result_field = op.outputs.field()
"""

_inputs: InputsElementalMean
_outputs: OutputsElementalMean

def __init__(
self,
field=None,
Expand All @@ -80,9 +77,13 @@ def __init__(
config=None,
server=None,
):
super().__init__(name="entity_average", config=config, server=server)
self._inputs = InputsElementalMean(self)
self._outputs = OutputsElementalMean(self)
super().__init__(
name="entity_average",
config=config,
server=server,
inputs_type=InputsElementalMean,
outputs_type=OutputsElementalMean,
)
if field is not None:
self.inputs.field.connect(field)
if collapse_shell_layers is not None:
Expand Down
13 changes: 7 additions & 6 deletions src/ansys/dpf/core/operators/averaging/elemental_mean_fc.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,6 @@ class elemental_mean_fc(Operator):
>>> result_fields_container = op.outputs.fields_container()
"""

_inputs: InputsElementalMeanFc
_outputs: OutputsElementalMeanFc

def __init__(
self,
fields_container=None,
Expand All @@ -108,9 +105,13 @@ def __init__(
config=None,
server=None,
):
super().__init__(name="entity_average_fc", config=config, server=server)
self._inputs = InputsElementalMeanFc(self)
self._outputs = OutputsElementalMeanFc(self)
super().__init__(
name="entity_average_fc",
config=config,
server=server,
inputs_type=InputsElementalMeanFc,
outputs_type=OutputsElementalMeanFc,
)
if fields_container is not None:
self.inputs.fields_container.connect(fields_container)
if collapse_shell_layers is not None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,6 @@ class elemental_nodal_to_nodal(Operator):
>>> result_weight = op.outputs.weight()
"""

_inputs: InputsElementalNodalToNodal
_outputs: OutputsElementalNodalToNodal

def __init__(
self,
field=None,
Expand All @@ -98,9 +95,13 @@ def __init__(
config=None,
server=None,
):
super().__init__(name="elemental_nodal_To_nodal", config=config, server=server)
self._inputs = InputsElementalNodalToNodal(self)
self._outputs = OutputsElementalNodalToNodal(self)
super().__init__(
name="elemental_nodal_To_nodal",
config=config,
server=server,
inputs_type=InputsElementalNodalToNodal,
outputs_type=OutputsElementalNodalToNodal,
)
if field is not None:
self.inputs.field.connect(field)
if mesh_scoping is not None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,14 @@ class elemental_nodal_to_nodal_elemental(Operator):
>>> result_field = op.outputs.field()
"""

_inputs: InputsElementalNodalToNodalElemental
_outputs: OutputsElementalNodalToNodalElemental

def __init__(self, field=None, mesh_scoping=None, config=None, server=None):
super().__init__(
name="ElementalNodal_To_NodalElemental", config=config, server=server
name="ElementalNodal_To_NodalElemental",
config=config,
server=server,
inputs_type=InputsElementalNodalToNodalElemental,
outputs_type=OutputsElementalNodalToNodalElemental,
)
self._inputs = InputsElementalNodalToNodalElemental(self)
self._outputs = OutputsElementalNodalToNodalElemental(self)
if field is not None:
self.inputs.field.connect(field)
if mesh_scoping is not None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,16 @@ class elemental_nodal_to_nodal_elemental_fc(Operator):
>>> result_fields_container = op.outputs.fields_container()
"""

_inputs: InputsElementalNodalToNodalElementalFc
_outputs: OutputsElementalNodalToNodalElementalFc

def __init__(
self, fields_container=None, mesh_scoping=None, config=None, server=None
):
super().__init__(
name="ElementalNodal_To_NodalElemental_fc", config=config, server=server
name="ElementalNodal_To_NodalElemental_fc",
config=config,
server=server,
inputs_type=InputsElementalNodalToNodalElementalFc,
outputs_type=OutputsElementalNodalToNodalElementalFc,
)
self._inputs = InputsElementalNodalToNodalElementalFc(self)
self._outputs = OutputsElementalNodalToNodalElementalFc(self)
if fields_container is not None:
self.inputs.fields_container.connect(fields_container)
if mesh_scoping is not None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,6 @@ class elemental_nodal_to_nodal_fc(Operator):
>>> result_weights = op.outputs.weights()
"""

_inputs: InputsElementalNodalToNodalFc
_outputs: OutputsElementalNodalToNodalFc

def __init__(
self,
fields_container=None,
Expand All @@ -115,10 +112,12 @@ def __init__(
server=None,
):
super().__init__(
name="elemental_nodal_To_nodal_fc", config=config, server=server
name="elemental_nodal_To_nodal_fc",
config=config,
server=server,
inputs_type=InputsElementalNodalToNodalFc,
outputs_type=OutputsElementalNodalToNodalFc,
)
self._inputs = InputsElementalNodalToNodalFc(self)
self._outputs = OutputsElementalNodalToNodalFc(self)
if fields_container is not None:
self.inputs.fields_container.connect(fields_container)
if mesh is not None:
Expand Down
Loading
Loading