Skip to content

Commit

Permalink
Feat/any collection (#1461)
Browse files Browse the repository at this point in the history
  • Loading branch information
cbellot000 authored Mar 11, 2024
1 parent fe05883 commit 9ad54f9
Show file tree
Hide file tree
Showing 23 changed files with 1,055 additions and 685 deletions.
12 changes: 11 additions & 1 deletion src/ansys/dpf/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
from ansys.dpf.core.meshed_region import MeshedRegion
from ansys.dpf.core.elements import element_types
from ansys.dpf.core.result_info import ResultInfo
from ansys.dpf.core.collection import Collection
from ansys.dpf.core.collection_base import CollectionBase
from ansys.dpf.core.workflow import Workflow
from ansys.dpf.core.cyclic_support import CyclicSupport
from ansys.dpf.core.element_descriptor import ElementDescriptor
Expand Down Expand Up @@ -103,6 +103,15 @@

from ansys.dpf.core.dpf_operator import available_operator_names


from ansys.dpf.core.collection import CollectionFactory as _CollectionFactory


# register classes for collection types:
CustomTypeFieldsCollection = _CollectionFactory(CustomTypeField)
GenericDataContainersCollection = _CollectionFactory(GenericDataContainer)
StringFieldsCollection = _CollectionFactory(StringField)

# for matplotlib
# solves "QApplication: invalid style override passed, ignoring it."
os.environ["QT_STYLE_OVERRIDE"] = ""
Expand All @@ -115,3 +124,4 @@

settings.set_default_pyvista_config()
settings._forward_to_gate()

2 changes: 1 addition & 1 deletion src/ansys/dpf/core/_custom_operators_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def __operator_main__(operator_functor, data):
external_operator_api.external_operator_put_out_string_field,
),
(scoping.Scoping, external_operator_api.external_operator_put_out_scoping),
(collection.Collection, external_operator_api.external_operator_put_out_collection),
(collection.CollectionBase, external_operator_api.external_operator_put_out_collection),
(
data_sources.DataSources,
external_operator_api.external_operator_put_out_data_sources,
Expand Down
27 changes: 16 additions & 11 deletions src/ansys/dpf/core/any.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from ansys.dpf.core import server as server_module
from ansys.dpf.core import errors
from ansys.dpf.core.check_version import server_meet_version
from ansys.dpf.core.common import type_to_internal_object_keyword
from ansys.dpf.core.common import create_dpf_instance
from ansys.dpf.gate import any_abstract_api, integral_types


Expand Down Expand Up @@ -92,6 +92,8 @@ def _type_to_new_from_get_as_method(self):
string_field,
scoping,
data_tree,
custom_type_field,
collection,
)

return [
Expand Down Expand Up @@ -145,6 +147,16 @@ def _type_to_new_from_get_as_method(self):
self._api.any_new_from_data_tree,
self._api.any_get_as_data_tree,
),
(
custom_type_field.CustomTypeField,
self._api.any_new_from_custom_type_field,
self._api.any_get_as_custom_type_field,
),
(
collection.Collection,
self._api.any_new_from_any_collection,
self._api.any_get_as_any_collection,
),
]

@staticmethod
Expand Down Expand Up @@ -172,7 +184,7 @@ def new_from(obj, server=None):
if isinstance(obj, type_tuple[0]):
# call respective new_from function
if isinstance(server, ansys.dpf.core.server_types.InProcessServer) or not (
isinstance(obj, int) or isinstance(obj, str) or isinstance(obj, float) or isinstance(obj, bytes)
isinstance(obj, (int, str, float, bytes))
):
any_dpf._internal_obj = type_tuple[1](obj)
else:
Expand Down Expand Up @@ -227,7 +239,7 @@ def cast(self, output_type=None):
self._internal_type = output_type if output_type is not None else self._internal_type

for type_tuple in Any._type_to_new_from_get_as_method(self):
if self._internal_type == type_tuple[0]:
if issubclass(self._internal_type, type_tuple[0]):
# call the get_as function for the appropriate type
internal_obj = type_tuple[2](self)
if (
Expand All @@ -239,14 +251,7 @@ def cast(self, output_type=None):
):
obj = internal_obj
else:
# get current type's constructors' variable keyword for passing the internal_obj
internal_obj_keyword = type_to_internal_object_keyword()[type_tuple[0]]

# wrap parameters in a dictionary for parameters expansion when calling
# constructor
keyword_args = {internal_obj_keyword: internal_obj, "server": self._server}
# call constructor
obj = type_tuple[0](**keyword_args)
return create_dpf_instance(self._internal_type, internal_obj, self._server)

return obj

Expand Down
Loading

0 comments on commit 9ad54f9

Please sign in to comment.