Skip to content

Commit 9ad54f9

Browse files
authored
Feat/any collection (#1461)
1 parent fe05883 commit 9ad54f9

23 files changed

+1055
-685
lines changed

src/ansys/dpf/core/__init__.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
from ansys.dpf.core.meshed_region import MeshedRegion
7373
from ansys.dpf.core.elements import element_types
7474
from ansys.dpf.core.result_info import ResultInfo
75-
from ansys.dpf.core.collection import Collection
75+
from ansys.dpf.core.collection_base import CollectionBase
7676
from ansys.dpf.core.workflow import Workflow
7777
from ansys.dpf.core.cyclic_support import CyclicSupport
7878
from ansys.dpf.core.element_descriptor import ElementDescriptor
@@ -103,6 +103,15 @@
103103

104104
from ansys.dpf.core.dpf_operator import available_operator_names
105105

106+
107+
from ansys.dpf.core.collection import CollectionFactory as _CollectionFactory
108+
109+
110+
# register classes for collection types:
111+
CustomTypeFieldsCollection = _CollectionFactory(CustomTypeField)
112+
GenericDataContainersCollection = _CollectionFactory(GenericDataContainer)
113+
StringFieldsCollection = _CollectionFactory(StringField)
114+
106115
# for matplotlib
107116
# solves "QApplication: invalid style override passed, ignoring it."
108117
os.environ["QT_STYLE_OVERRIDE"] = ""
@@ -115,3 +124,4 @@
115124

116125
settings.set_default_pyvista_config()
117126
settings._forward_to_gate()
127+

src/ansys/dpf/core/_custom_operators_helpers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def __operator_main__(operator_functor, data):
4545
external_operator_api.external_operator_put_out_string_field,
4646
),
4747
(scoping.Scoping, external_operator_api.external_operator_put_out_scoping),
48-
(collection.Collection, external_operator_api.external_operator_put_out_collection),
48+
(collection.CollectionBase, external_operator_api.external_operator_put_out_collection),
4949
(
5050
data_sources.DataSources,
5151
external_operator_api.external_operator_put_out_data_sources,

src/ansys/dpf/core/any.py

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from ansys.dpf.core import server as server_module
1212
from ansys.dpf.core import errors
1313
from ansys.dpf.core.check_version import server_meet_version
14-
from ansys.dpf.core.common import type_to_internal_object_keyword
14+
from ansys.dpf.core.common import create_dpf_instance
1515
from ansys.dpf.gate import any_abstract_api, integral_types
1616

1717

@@ -92,6 +92,8 @@ def _type_to_new_from_get_as_method(self):
9292
string_field,
9393
scoping,
9494
data_tree,
95+
custom_type_field,
96+
collection,
9597
)
9698

9799
return [
@@ -145,6 +147,16 @@ def _type_to_new_from_get_as_method(self):
145147
self._api.any_new_from_data_tree,
146148
self._api.any_get_as_data_tree,
147149
),
150+
(
151+
custom_type_field.CustomTypeField,
152+
self._api.any_new_from_custom_type_field,
153+
self._api.any_get_as_custom_type_field,
154+
),
155+
(
156+
collection.Collection,
157+
self._api.any_new_from_any_collection,
158+
self._api.any_get_as_any_collection,
159+
),
148160
]
149161

150162
@staticmethod
@@ -172,7 +184,7 @@ def new_from(obj, server=None):
172184
if isinstance(obj, type_tuple[0]):
173185
# call respective new_from function
174186
if isinstance(server, ansys.dpf.core.server_types.InProcessServer) or not (
175-
isinstance(obj, int) or isinstance(obj, str) or isinstance(obj, float) or isinstance(obj, bytes)
187+
isinstance(obj, (int, str, float, bytes))
176188
):
177189
any_dpf._internal_obj = type_tuple[1](obj)
178190
else:
@@ -227,7 +239,7 @@ def cast(self, output_type=None):
227239
self._internal_type = output_type if output_type is not None else self._internal_type
228240

229241
for type_tuple in Any._type_to_new_from_get_as_method(self):
230-
if self._internal_type == type_tuple[0]:
242+
if issubclass(self._internal_type, type_tuple[0]):
231243
# call the get_as function for the appropriate type
232244
internal_obj = type_tuple[2](self)
233245
if (
@@ -239,14 +251,7 @@ def cast(self, output_type=None):
239251
):
240252
obj = internal_obj
241253
else:
242-
# get current type's constructors' variable keyword for passing the internal_obj
243-
internal_obj_keyword = type_to_internal_object_keyword()[type_tuple[0]]
244-
245-
# wrap parameters in a dictionary for parameters expansion when calling
246-
# constructor
247-
keyword_args = {internal_obj_keyword: internal_obj, "server": self._server}
248-
# call constructor
249-
obj = type_tuple[0](**keyword_args)
254+
return create_dpf_instance(self._internal_type, internal_obj, self._server)
250255

251256
return obj
252257

0 commit comments

Comments
 (0)