-
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
Open
PProfizi
wants to merge
6
commits into
master
Choose a base branch
from
example/rescope
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Add rescope example #961
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
9345f07
Update 00-basic_example.py to mention the field's scoping and data or…
PProfizi 3b02343
Add 13-data_reordering.py example
PProfizi 603fbe6
Merge branch 'master' into example/rescope
PProfizi 93bbcff
Apply suggestions from code review
PProfizi 6c48ea9
Merge branch 'master' into example/rescope
PProfizi 0a58a9a
Merge branch 'master' into example/rescope
PProfizi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]) | ||
# You can 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 | ||
print(nodes_scoping) | ||
print(nodes_scoping.ids[:10]) | ||
|
||
# The mesh's node scoping is, in this case, in ascending order. | ||
# 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]}") |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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.
@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
default_value
pin of therescope
operator, as you are rescoping with exactly the same Ids you started with (not more, not less)