Skip to content

Commit 7d1587a

Browse files
authored
Merge branch 'master' into maint/bug_template_pip_freeze
2 parents a9294a0 + 22f0d8d commit 7d1587a

File tree

13 files changed

+64
-6
lines changed

13 files changed

+64
-6
lines changed

requirements/requirements_docs.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ sphinx-notfound-page==1.0.4
1414
sphinx-reredirects==0.1.3
1515
sphinx_design==0.6.1
1616
sphinxcontrib-napoleon==0.7
17+
vtk==9.3.1

requirements/requirements_test.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ pytest-cov==5.0.0
77
pytest-order==1.3.0
88
pytest-rerunfailures==15.0
99
pyvista==0.44.1
10+
vtk==9.3.1

src/ansys/dpf/core/any.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ def _type_to_new_from_get_as_method(self, obj):
123123
custom_type_field,
124124
collection,
125125
workflow,
126+
dpf_operator,
126127
)
127128

128129
if issubclass(obj, int):
@@ -196,6 +197,11 @@ def _type_to_new_from_get_as_method(self, obj):
196197
self._api.any_new_from_int_collection,
197198
self._api.any_get_as_int_collection,
198199
)
200+
elif issubclass(obj, dpf_operator.Operator):
201+
return (
202+
self._api.any_new_from_operator,
203+
self._api.any_get_as_operator,
204+
)
199205

200206
@staticmethod
201207
def new_from(obj, server=None):

src/ansys/dpf/core/dpf_operator.py

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ class Operator:
121121
122122
"""
123123

124-
def __init__(self, name, config=None, server=None):
124+
def __init__(self, name=None, config=None, server=None, operator=None):
125125
"""Initialize the operator with its name by connecting to a stub."""
126126
self.name = name
127127
self._internal_obj = None
@@ -136,14 +136,29 @@ def __init__(self, name, config=None, server=None):
136136
# step 2: get api
137137
self._api_instance = None # see _api property
138138

139-
# step3: init environment
139+
# step 3: init environment
140140
self._api.init_operator_environment(self) # creates stub when gRPC
141141

142-
# step4: if object exists: take instance, else create it (server)
143-
if self._server.has_client():
144-
self._internal_obj = self._api.operator_new_on_client(self.name, self._server.client)
142+
# step 4: if object exists, take the instance, else create it
143+
if operator is not None:
144+
if isinstance(operator, Operator):
145+
core_api = self._server.get_api_for_type(
146+
capi=data_processing_capi.DataProcessingCAPI,
147+
grpcapi=data_processing_grpcapi.DataProcessingGRPCAPI,
148+
)
149+
core_api.init_data_processing_environment(self)
150+
self._internal_obj = core_api.data_processing_duplicate_object_reference(operator)
151+
self.name = operator.name
152+
else:
153+
self._internal_obj = operator
154+
self.name = self._api.operator_name(self)
145155
else:
146-
self._internal_obj = self._api.operator_new(self.name)
156+
if self._server.has_client():
157+
self._internal_obj = self._api.operator_new_on_client(
158+
self.name, self._server.client
159+
)
160+
else:
161+
self._internal_obj = self._api.operator_new(self.name)
147162

148163
if self._internal_obj is None:
149164
raise KeyError(

src/ansys/dpf/gate/any_grpcapi.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ def _type_to_message_type():
4242
custom_type_field,
4343
collection_base,
4444
workflow,
45+
dpf_operator,
4546
)
4647

4748
return [(int, base_pb2.Type.INT),
@@ -58,6 +59,7 @@ def _type_to_message_type():
5859
(workflow.Workflow, base_pb2.Type.WORKFLOW),
5960
(collection_base.CollectionBase, base_pb2.Type.COLLECTION, base_pb2.Type.ANY),
6061
(dpf_vector.DPFVectorInt, base_pb2.Type.COLLECTION, base_pb2.Type.INT),
62+
(dpf_operator.Operator, base_pb2.Type.OPERATOR),
6163
]
6264

6365
@staticmethod
@@ -145,6 +147,10 @@ def any_get_as_int_collection(any):
145147
def any_get_as_workflow(any):
146148
return AnyGRPCAPI._get_as(any).workflow
147149

150+
@staticmethod
151+
def any_get_as_operator(any):
152+
return AnyGRPCAPI._get_as(any).operator
153+
148154
@staticmethod
149155
def _new_from(any, client=None):
150156
from ansys.grpc.dpf import dpf_any_pb2
@@ -230,3 +236,7 @@ def any_new_from_data_tree(any):
230236
@staticmethod
231237
def any_new_from_workflow(any):
232238
return AnyGRPCAPI._new_from(any, any._server)
239+
240+
@staticmethod
241+
def any_new_from_operator(any):
242+
return AnyGRPCAPI._new_from(any, any._server)

src/ansys/dpf/gate/operator_grpcapi.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ def get_list(op):
5151
def operator_get_config(op):
5252
return OperatorGRPCAPI.get_list(op).config
5353

54+
@staticmethod
55+
def operator_name(op):
56+
return OperatorGRPCAPI.get_list(op).op_name
57+
5458
@staticmethod
5559
def update_init(op, pin):
5660
from ansys.grpc.dpf import operator_pb2
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)