-
Notifications
You must be signed in to change notification settings - Fork 25
Add example on how to get data by ID #726
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Codecov Report
@@ Coverage Diff @@
## master #726 +/- ##
==========================================
+ Coverage 88.56% 88.64% +0.07%
==========================================
Files 71 71
Lines 8088 8081 -7
==========================================
Hits 7163 7163
+ Misses 925 918 -7 |
@rlagha, a couple comments:
Thoughts? |
start = time.time() | ||
nodal_disp_get_entity = np.zeros([mesh_selection.nodes.n_nodes, 3]) | ||
for idx, node_id in enumerate(ids): | ||
node_disp = disp_selection.get_entity_data_by_id(node_id) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@guillem , this one is useless in this case. the right one in the one you wrote above.
we use the get_by_id:
-when we loop over several fields for example nodal stresses and displacements and want to get for a given node of the displacement field it's nodal stress for example.
-when we have a user defined scoping, which is different from the field scoping, and we want to extract data from the field. this can be important when we want to read the data once from the file in one request and then work on different named selections and extract data from the field instead of reading each time from a file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @rlagha. Yes, exactly.
Depending on what you want to do you should use one approach or the other. That is why I included the two of them in the example and a comparison between them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@guillem, this can be important to mention these remarks in the example.
start = time.time() | ||
nodal_disp_get_entity = np.zeros([mesh_selection.nodes.n_nodes, 3]) | ||
for idx, node_id in enumerate(ids): | ||
node_disp = disp_selection.get_entity_data_by_id(node_id) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@guillem, this can be important to mention these remarks in the example.
# for that node | ||
nodal_disp_index = np.zeros([mesh_selection.nodes.n_nodes, 3]) | ||
for idx, node_id in enumerate(ids): | ||
node_disp = data[idx] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@guillem, this is true when you have nodal or elemental results. When you read stresses for example as Elemental nodal data, then you will need to use field.get_entity_data(idx) instead of data[idx], otherwise you will get only the first stress tensor, this is also true for layered results.
We may need to add a similar loop with field.get_entity_data(); when the server is in in-process mode I think that you will not have overhead, if the server is remote then you may need to use as_local_field option and field.get_entity_data()
Co-authored-by: Maxime Rey <[email protected]>
…pydpf-core into examples/get-data-by-id
Fix #725.
This PR proposes a new example showing how to retrieve data from a field by ID. The example follows:
5.1. Index approach
5.2. get_entity_data_by_id approach