ansys / pydpf-post

Data Processing Framework - Post Processing Module
https://post.docs.pyansys.com
MIT License
43 stars 10 forks source link

Add get_data_by_id method in DataObject #229

Closed GuillemBarroso closed 1 year ago

GuillemBarroso commented 1 year ago

Description of the feature

This PR includes an example on how to retrieve data from a field by ID.

In Post this feature can be exposed as a method of DataObject, so the users could:

  1. Retrieve all the data with its associated IDs

    simulation = post.load_simulation("my_example")
    my_named_selection = "test"
    my_selection = select(named_selection=my_named_selection)
    nodal_ids, nodal_disp = simulation.displacement(select=my_selection).get_data_by_id()
    assert len(nodal_ids) == len(nodal_disp) == n_nodes
    assert type(nodal_ids) == np.ndarray or ints
    assert type(nodal_disp) == np.ndarray of floats
  2. Retrieve data for one ID

    simulation = post.load_simulation("my_example")
    my_named_selection = "test"
    my_selection = select(named_selection=my_named_selection)
    nodal_id, nodal_disp = simulation.displacement(select=my_selection).get_data_by_id(5)
    assert len(nodal_id) == len(nodal_disp) == 1
    assert type(nodal_id) == np.array of ints
    assert type(nodal_disp) == np.array of floats # (containing the three components of the displacement for that node)
  3. Retrieve data for a list of IDs

    simulation = post.load_simulation("my_example")
    my_named_selection = "test"
    my_selection = select(named_selection=my_named_selection)
    nodal_ids, nodal_disp = simulation.displacement(select=my_selection).get_data_by_id([1, 5, 25])
    assert len(nodal_ids) == len(nodal_disp) == 3
    assert type(nodal_ids) == np.array of ints
    assert type(nodal_disp) == np.array of floats

Steps for implementing the feature

Implement the get_data_by_id() method in the data object.

Make only one server call to increase performance.

Useful links and references

N/A

PProfizi commented 1 year ago

Closing as stale for now. To reopen later.