-
Notifications
You must be signed in to change notification settings - Fork 25
Add rescope example #961
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?
Add rescope example #961
Changes from 2 commits
9345f07
3b02343
603fbe6
93bbcff
6c48ea9
0a58a9a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
""" | ||
.. _ref_data_reordering_example: | ||
|
||
Data ordering and scopings | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
This example shows how to extract results and manipulate the order the data is shown in. | ||
|
||
""" | ||
|
||
# First, import the DPF-Core module as ``dpf`` and import the included examples file. | ||
from ansys.dpf import core as dpf | ||
from ansys.dpf.core import examples | ||
|
||
|
||
############################################################################### | ||
# Create a model object to establish a connection with an example result file. | ||
model = dpf.Model(examples.find_simple_bar()) | ||
|
||
# Extract results | ||
displacements = model.results.displacement() | ||
fields = displacements.outputs.fields_container() | ||
disp_field_0 = fields[0] | ||
|
||
# To improve performance, the result data comes ordered the same way it is stored on the server, | ||
# which is not necessarily by node or element ID. | ||
# The link between data position and corresponding entity ID is defined by the field's scoping. | ||
scoping = disp_field_0.scoping | ||
# This scoping is Nodal with several thousand entities (node IDs): | ||
print(scoping) | ||
# The first 10 node IDs in the scoping: | ||
print(scoping.ids[:10]) | ||
# One can indeed see that the node IDs are not in ascending, descending or any particular order. | ||
|
||
# We can compare it to the order the mesh's nodes are in: | ||
nodes_scoping = model.metadata.meshed_region.nodes.scoping | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @PProfizi From reading the example, it could be inferred that the mesh scopings are always ordered, which is not true. I mean, let's say that a user wants to have the data ordered by node Id. This example should address that. The solution offered in the example is to use the mesh scoping, but it can be the case that the mesh scoping is not ordered. I would remark that the ascending order of the mesh scopings is not mandatory. If a user wants a 100% ordered field, then the approach that works 100% of the times is:
With this approach we also make sure that we don't need to tackle the |
||
print(nodes_scoping) | ||
print(nodes_scoping.ids[:10]) | ||
|
||
# The mesh's node scoping is in this case in ascending order. | ||
PProfizi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# To force the field's date to follow the same ordering, use the rescope operator with the target | ||
# scoping as input: | ||
reordered_fields = dpf.operators.scoping.rescope_fc( | ||
fields_container=fields, | ||
mesh_scoping=nodes_scoping, | ||
).outputs.fields_container() | ||
reordered_disp_field_0 = reordered_fields[0] | ||
|
||
# The field's data is now ordered based on its new scoping, same as the mesh: | ||
print(reordered_disp_field_0.scoping.ids[:10]) | ||
|
||
# We can compare the values returned for the first entity of each field: | ||
print(f"Displacement values for first entity of initial field: {disp_field_0.data[0]}") | ||
print(f"Displacement values for first entity of rescoped field: {reordered_disp_field_0.data[0]}") |
Uh oh!
There was an error while loading. Please reload this page.