ansys.dpf.core.data_tree._LocalDataTree#
- class ansys.dpf.core.data_tree._LocalDataTree(data_tree)#
Bases:
DataTree
Represents an entity mapping attributes names to values.
- Parameters:
data (dict(string:object)) – Dictionary attributes names to its associated data to add to the data tree.
data_tree (ctypes.c_void_p, ansys.grpc.dpf.data_tree_pb2.DataTree message, optional)
server (DPFServer, optional) – Server with channel connected to the remote or local instance. The default is
None
, in which case an attempt is made to use the global server.
Examples
Create a data tree from a dictionary.
>>> from ansys.dpf import core as dpf >>> data_tree = dpf.DataTree({"num_entities":3, "list_of_raws":[1,2,3,4], "name": "George"}) >>> data_tree.get_as("name", dpf.types.string) 'George' >>> data_tree.get_as("list_of_raws", dpf.types.vec_int) [1, 2, 3, 4]
Create a data tree with add.
>>> from ansys.dpf import core as dpf >>> data_tree = dpf.DataTree() >>> data_tree.add(num_entities=3, list_of_raws=[1,2,3,4], name="George") >>> txt = data_tree.write_to_txt()
Create a data tree with a context manager.
>>> from ansys.dpf import core as dpf >>> data_tree = dpf.DataTree() >>> with data_tree.to_fill() as to_fill: ... to_fill.num_entities = 3 ... to_fill.list_of_raws = [1,2,3,4] >>> json = data_tree.write_to_json()
Notes
Class available with server’s version starting at 4.0 (Ansys 2022R2).
- _common_keys = ['_owner_data_tree', '_dict', '_common_keys', '_is_exited']#
- _owner_data_tree#
- _is_exited = False#
- add(*args, **kwargs)#
Add attributes with their value to the data tree.
- Parameters:
kwargs (int, float, string, list[int], list[double], list[str], DataTree) – Data to add.
- __cache_data__()#
- release_data()#
Release the data.
- __setattr__(key, value)#
Set an attribute for the DataTree object.
- Parameters:
key (str) – The name of the attribute to set. If the attribute is a reserved key (e.g., internal attributes starting with “_common_keys” or attributes defined in the class), it is set using the parent class’s __setattr__ method. Otherwise, it adds the attribute and its value to the data tree.
value (object) – The value of the attribute to set.
- __enter__()#
- __exit__(type_to_use, value, tb)#
- to_dict()#
Return a read-only dictionary representation of the DataTree.
- Return type:
dict
Examples
>>> from ansys.dpf import core as dpf >>> data_tree = dpf.DataTree() >>> sub = dpf.DataTree() >>> sub.add(str="hello world") >>> data_tree.add(id=3, sub_tree=sub) >>> data_tree.to_dict() {'id': '3', 'sub_tree': {'str': 'hello world'}}
- __del__()#
Delete this instance.