1212
1313from ansys .dpf .core .server_types import BaseServer
1414from ansys .dpf .core .scoping import Scoping
15- from ansys .dpf .core .time_freq_support import TimeFreqSupport
15+ from ansys .dpf .core .label_space import LabelSpace
1616from ansys .dpf .core import server as server_module
1717from ansys .dpf .gate import (
1818 collection_capi ,
1919 collection_grpcapi ,
20- label_space_capi ,
21- label_space_grpcapi ,
2220 data_processing_capi ,
2321 data_processing_grpcapi ,
24- object_handler ,
2522 dpf_vector ,
2623 dpf_array
2724)
@@ -216,7 +213,9 @@ def _get_entries(self, label_space_or_index):
216213 Entries corresponding to the request.
217214 """
218215 if isinstance (label_space_or_index , dict ):
219- client_label_space = self ._create_client_label_space (label_space_or_index )
216+ client_label_space = LabelSpace (
217+ label_space = label_space_or_index , obj = self , server = self ._server
218+ )
220219 num = self ._api .collection_get_num_obj_for_label_space (self , client_label_space )
221220 out = []
222221 for i in range (0 , num ):
@@ -268,9 +267,10 @@ def get_label_space(self, index):
268267 Scoping of the requested entry. For example,
269268 ``{"time": 1, "complex": 0}``.
270269 """
271- return self ._create_dict_from_client_label_space (
272- self ._api .collection_get_obj_label_space_by_index (self , index )
273- )
270+ return LabelSpace (
271+ label_space = self ._api .collection_get_obj_label_space_by_index (self , index ),
272+ server = self ._server
273+ ).__dict__ ()
274274
275275 def get_available_ids_for_label (self , label = "time" ):
276276 """Retrieve the IDs assigned to an input label.
@@ -333,11 +333,6 @@ def __getitem__(self, index):
333333
334334 return self ._get_entries (index )
335335
336- @property
337- def _label_space_api (self ):
338- return self ._server .get_api_for_type (capi = label_space_capi .LabelSpaceCAPI ,
339- grpcapi = label_space_grpcapi .LabelSpaceGRPCAPI )
340-
341336 @property
342337 def _data_processing_core_api (self ):
343338 core_api = self ._server .get_api_for_type (
@@ -346,27 +341,6 @@ def _data_processing_core_api(self):
346341 core_api .init_data_processing_environment (self )
347342 return core_api
348343
349- def _create_client_label_space (self , label_space ):
350- client_label_space = object_handler .ObjHandler (
351- self ._data_processing_core_api ,
352- self ._label_space_api .label_space_new_for_object (self )
353- )
354- for key , id in label_space .items ():
355- self ._label_space_api .label_space_add_data (client_label_space , key , id )
356- return client_label_space
357-
358- def _create_dict_from_client_label_space (self , client_label_space ):
359- if isinstance (client_label_space , dict ):
360- return client_label_space
361- out = {}
362- client_label_space = object_handler .ObjHandler (
363- self ._data_processing_core_api , client_label_space
364- )
365- for i in range (0 , self ._label_space_api .label_space_get_size (client_label_space )):
366- out [self ._label_space_api .label_space_get_labels_name (client_label_space , i )] = \
367- self ._label_space_api .label_space_get_labels_value (client_label_space , i )
368- return out
369-
370344 def _add_entry (self , label_space , entry ):
371345 """Update or add an entry at a requested label space.
372346
@@ -377,7 +351,7 @@ def _add_entry(self, label_space, entry):
377351 entry : Field or Scoping
378352 DPF entry to add.
379353 """
380- client_label_space = self . _create_client_label_space (label_space )
354+ client_label_space = LabelSpace (label_space = label_space , obj = self , server = self . _server )
381355 self ._api .collection_add_entry (self , client_label_space , entry )
382356
383357 def _get_time_freq_support (self ):
@@ -387,6 +361,7 @@ def _get_time_freq_support(self):
387361 -------
388362 time_freq_support : TimeFreqSupport
389363 """
364+ from ansys .dpf .core .time_freq_support import TimeFreqSupport
390365 from ansys .dpf .gate import support_capi , support_grpcapi , object_handler , \
391366 data_processing_capi , data_processing_grpcapi
392367 data_api = self ._server .get_api_for_type (
@@ -581,3 +556,54 @@ def get_integral_entries(self):
581556 return dpf_array .DPFArray (vec )
582557 except NotImplementedError :
583558 return self ._api .collection_get_data_as_double (self , 0 )
559+
560+
561+ class StringCollection (Collection ):
562+ """Creates a collection of strings with a list.
563+
564+ The collection of integral is the equivalent of an array of
565+ data sent server side. It can be used to efficiently stream
566+ large data to the server.
567+
568+ Parameters
569+ ----------
570+ list : list[float], numpy.array
571+ list to transfer server side
572+
573+ Notes
574+ -----
575+ Used by default by the ``'Operator'`` and the``'Workflow'`` when a
576+ list is connected or returned.
577+ """
578+
579+ def __init__ (self , list = None , server = None , collection = None , local : bool = False ):
580+ super ().__init__ (server = server , collection = collection )
581+ self ._sub_type = str
582+ if self ._internal_obj is None :
583+ if self ._server .has_client ():
584+ if local :
585+ self ._internal_obj = self ._api .collection_of_string_new_local (
586+ self ._server .client
587+ )
588+ else :
589+ self ._internal_obj = self ._api .collection_of_string_new_on_client (
590+ self ._server .client
591+ )
592+ else :
593+ self ._internal_obj = self ._api .collection_of_string_new ()
594+ if list is not None :
595+ self ._set_integral_entries (list )
596+
597+ def create_subtype (self , obj_by_copy ):
598+ return str (obj_by_copy )
599+
600+ def _set_integral_entries (self , input ):
601+ for s in input :
602+ self ._api .collection_add_string_entry (self , s )
603+
604+ def get_integral_entries (self ):
605+ num = self ._api .collection_get_size (self )
606+ out = []
607+ for i in range (num ):
608+ out .append (self ._api .collection_get_string_entry (self , i ))
609+ return out
0 commit comments