-
Notifications
You must be signed in to change notification settings - Fork 25
Isosurface example #1056
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
Merged
Merged
Isosurface example #1056
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
e8d8579
Create examples for isosurfaces using fluid files
MichaelNale 30ab67b
Complete example for iso-surfaces with elbow file
MichaelNale f9bde32
Complete the example
MichaelNale 119d98c
Complete isosurface example for fluids
MichaelNale 2f14dc2
Update the PR :
MichaelNale cbc4624
Update the PR :
MichaelNale 36bfa4e
Merge branch 'master' into mnale/add_isosurface_example
MichaelNale bd35bd8
Update the PR :
MichaelNale ddb5a69
Update the PR : fix doc display
MichaelNale 863b815
Update the PR : fix format
MichaelNale 4e2c026
Update the PR : enhance the doc
MichaelNale 6af83ad
Merge branch 'master' into mnale/add_isosurface_example
MichaelNale e2d905e
Update the PR : correct docstrings and reformat code
MichaelNale 49a5f1d
Merge branch 'master' into mnale/add_isosurface_example
MichaelNale 9df35ef
Merge branch 'master' into mnale/add_isosurface_example
MichaelNale 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
""" | ||
.. _ref_fluids_isosurface: | ||
|
||
Compute iso-surfaces on fluid models | ||
------------------------------------------ | ||
|
||
This example demonstrates how to compute iso-surfaces on fluid models. | ||
""" | ||
|
||
############################################################################### | ||
# Import the ``dpf-core`` module and its examples files. | ||
# ~~~~~~~~~~~~~~~~~~ | ||
|
||
import ansys.dpf.core as dpf | ||
from ansys.dpf.core import examples | ||
from ansys.dpf.core.plotter import DpfPlotter | ||
|
||
############################################################################### | ||
# Specify the file path. | ||
# ~~~~~~~~~~~~~~~~~~ | ||
# We work on a cas/dat.h5 file with only nodal variables. | ||
|
||
path = examples.download_cfx_heating_coil() | ||
ds = dpf.DataSources() | ||
ds.set_result_file_path(path["cas"], "cas") | ||
ds.add_file_path(path["dat"], "dat") | ||
streams = dpf.operators.metadata.streams_provider(data_sources=ds) | ||
|
||
############################################################################### | ||
# Whole mesh scoping. | ||
# ~~~~~~~~~~~~~~~~~~ | ||
# We evaluate the mesh with the mesh_provider operator to scope the mesh_cut operator | ||
# with the whole mesh. | ||
|
||
whole_mesh = dpf.operators.mesh.mesh_provider(streams_container=streams).eval() | ||
print(whole_mesh) | ||
|
||
pl = DpfPlotter() | ||
pl.add_mesh(whole_mesh) | ||
cpos_whole_mesh = [ | ||
(4.256160478475664, 4.73662111240005, 4.00410065817644), | ||
(-0.0011924505233764648, 1.8596649169921875e-05, 1.125), | ||
(-0.2738679385987956, -0.30771426079547065, 0.9112125360807675), | ||
] | ||
pl.show_figure(cpos=cpos_whole_mesh, show_axes=True) | ||
|
||
############################################################################### | ||
# Extract the physics variable | ||
# ~~~~~~~~~~~~~~~~~ | ||
# Here we choose to work with the static pressure by default which is a scalar and | ||
# nodal variable without multi-species/phases. With a multi-species case, | ||
# select one using qualifier ellipsis pins and connecting a LabelSpace "species"/"phase". | ||
|
||
P_S = dpf.operators.result.static_pressure(streams_container=streams, mesh=whole_mesh).eval() | ||
print(P_S[0]) | ||
|
||
pl = DpfPlotter() | ||
pl.add_field(P_S[0]) | ||
cpos_mesh_variable = [ | ||
(4.256160478475664, 4.73662111240005, 4.00410065817644), | ||
(-0.0011924505233764648, 1.8596649169921875e-05, 1.125), | ||
(-0.2738679385987956, -0.30771426079547065, 0.9112125360807675), | ||
] | ||
pl.show_figure(cpos=cpos_mesh_variable, show_axes=True) | ||
|
||
############################################################################### | ||
# Evaluate iso-surfaces | ||
# ~~~~~~~~~~~~~~ | ||
# We can finally use the mesh_cut operator on this specific variable. | ||
# We choose to cut the whole with 5 iso-surface equally spaced between min and max. | ||
|
||
max_pressure = 361.8170 # Pa | ||
min_pressure = -153.5356 # Pa | ||
number_of_iso_surface = 5 | ||
step = (max_pressure - min_pressure) / number_of_iso_surface | ||
|
||
pl = DpfPlotter() | ||
c_pos_iso = [ | ||
(4.256160478475664, 4.73662111240005, 4.00410065817644), | ||
(-0.0011924505233764648, 1.8596649169921875e-05, 1.125), | ||
(-0.2738679385987956, -0.30771426079547065, 0.9112125360807675), | ||
] | ||
pl.add_mesh( | ||
meshed_region=whole_mesh, | ||
style="wireframe", | ||
show_edges=True, | ||
show_axes=True, | ||
color="black", | ||
opacity=0.3, | ||
) | ||
|
||
for i in range(number_of_iso_surface): | ||
iso_surface = dpf.operators.mesh.mesh_cut( | ||
field=P_S[0], iso_value=min_pressure, closed_surface=0, mesh=whole_mesh, slice_surfaces=True | ||
).eval() | ||
P_S_step = dpf.Field(location=dpf.locations.overall, nature=dpf.common.natures.scalar) | ||
P_S_step.append([min_pressure], i) | ||
P_S_step.name = "static pressure" | ||
P_S_step.unit = "Pa" | ||
pl.add_field( | ||
field=P_S_step, meshed_region=iso_surface, style="surface", show_edges=False, show_axes=True | ||
) | ||
min_pressure += step | ||
|
||
pl.show_figure(show_axes=True, cpos=c_pos_iso) | ||
|
||
############################################################################### | ||
# Important note | ||
# ------------------------------ | ||
# Iso-surfaces computation through the `mesh_cut` operator are only supported for Nodal Fields. | ||
# For Elemental variables, you must perform an averaging operation on the Nodes before | ||
# running the `mesh_cut` operator. This can be done by chaining the `elemental_to_nodal` operator | ||
# output with the `mesh_cut` operator input. |
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
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
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.