-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create examples for pydpf-post and make small bug fixes (#300)
* Add Mesh.node_ids * Fix if evaluations in MechanicalSimulation._build_selection * Return first principal component by default if None is asked (combination of all three is not possible yet) * Add animation on deformed mesh * Add Mesh._core_object and DataObject._core_object * Add typehinting to Simulation.time_freq_support * Add Simulation.set_ids * Add Simulation.release_streams() * Add DataFrame._core_object and Mesh._core_object * Add Mesh.__str__ * Rename DataObject to DataFrame * Add DataFrame.__str__ and remove DataFrame.to_pandas and to_numpy * Allow import DataFrame from post * Add display_width logic to the Dataframe string representation * Finish renaming to DataFrame * Add testing to DataFrame * Update Mesh.__str__ * Update DataFrame signature * Finish testing Mesh methods * Fix Mesh.available_named_selections docstring * Remove useless tests for Simulation.boundary_conditions and Simulation.loads as these properties are not implemented yet. * Fix Codacy * Add Index and MultiIndex * Add ResultsIndex * Update Index and MultiIndex APIs and update DataFrame API * Update DataFrame._update_str * Add DataFrame.select * Update DataFrame.plot() to accept selection arguments. * Add DataFrame.iselect * Update Index classes and DataFrame creation. Refactor components treatment and DataFrame creation in result APIs * Add component selection to DataFrame.select * Add component selection to DataFrame.iselect * Working DataFrame.__str__ * Working DataFrame.__str__ * first fixes * First fix for harmonic * examples and tests * stringify * Bump ansys-sphinx-theme from 0.8.2 to 0.9.5 (#299) Bumps [ansys-sphinx-theme](https://github.com/ansys/ansys-sphinx-theme) from 0.8.2 to 0.9.5. - [Release notes](https://github.com/ansys/ansys-sphinx-theme/releases) - [Commits](ansys/ansys-sphinx-theme@v0.8.2...v0.9.5) --- updated-dependencies: - dependency-name: ansys-sphinx-theme dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Bump imageio from 2.25.0 to 2.26.0 (#298) Bumps [imageio](https://github.com/imageio/imageio) from 2.25.0 to 2.26.0. - [Release notes](https://github.com/imageio/imageio/releases) - [Changelog](https://github.com/imageio/imageio/blob/master/CHANGELOG.md) - [Commits](imageio/imageio@v2.25.0...v2.26.0) --- updated-dependencies: - dependency-name: imageio dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Bump pyvista from 0.36.1 to 0.38.3 (#294) Bumps [pyvista](https://github.com/pyvista/pyvista) from 0.36.1 to 0.38.3. - [Release notes](https://github.com/pyvista/pyvista/releases) - [Commits](pyvista/pyvista@v0.36.1...v0.38.3) --- updated-dependencies: - dependency-name: pyvista dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Bump sphinx-autodoc-typehints from 1.21.7 to 1.22 (#276) Bumps [sphinx-autodoc-typehints](https://github.com/tox-dev/sphinx-autodoc-typehints) from 1.21.7 to 1.22. - [Release notes](https://github.com/tox-dev/sphinx-autodoc-typehints/releases) - [Changelog](https://github.com/tox-dev/sphinx-autodoc-typehints/blob/main/CHANGELOG.md) - [Commits](tox-dev/sphinx-autodoc-typehints@1.21.7...1.22) --- updated-dependencies: - dependency-name: sphinx-autodoc-typehints dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * fixes * new example * bugs * bugs * revert * Update src/ansys/dpf/post/examples/__init__.py * DataFrame.plot handles shell_layers * Fix bug for 01-static-simulation.py * Remove debug plot * Add truncation to print * Fix truncation detection logic * Fix scale_factor default value for DataFrame.animate * Remove rogue Stringify * animation * examples * new examples * Improve examples * Invariants examples --------- Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: paul.profizi <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
- Loading branch information
1 parent
4ba5c9d
commit 23e8c30
Showing
34 changed files
with
814 additions
and
78 deletions.
There are no files selected for viewing
96 changes: 96 additions & 0 deletions
96
examples/00-Different-analysis-types/01-static-simulation.py
This file contains 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,96 @@ | ||
""" | ||
.. _ref_static_example: | ||
Static Simulation | ||
================= | ||
In this script static simulation is processed to extract results like stress, displacement. | ||
Selecting sub parts of the results by scoping on specific nodes or elements is also displayed here. | ||
""" | ||
|
||
############################################################################### | ||
# Perform required imports | ||
# ------------------------ | ||
# Perform required imports. # This example uses a supplied file that you can | ||
# get by importing the DPF ``examples`` package. | ||
|
||
from ansys.dpf import post | ||
from ansys.dpf.post import examples | ||
|
||
############################################################################### | ||
# Get ``Simulation`` object | ||
# ------------------------- | ||
# Get the ``Simulation`` object that allows access to the result. The ``Simulation`` | ||
# object must be instantiated with the path for the result file. For example, | ||
# ``"C:/Users/user/my_result.rst"`` on Windows or ``"/home/user/my_result.rst"`` | ||
# on Linux. | ||
|
||
example_path = examples.find_static_rst() | ||
simulation = post.load_simulation(example_path) | ||
|
||
# for no autocompletion, this line is equivalent to: | ||
simulation = post.StaticMechanicalSimulation(example_path) | ||
|
||
# print the simulation to get an overview of what's available | ||
print(simulation) | ||
|
||
displacement = simulation.displacement() | ||
print(displacement) | ||
|
||
|
||
############################################################################### | ||
# Select sub parts of displacement | ||
# --------------------------------- | ||
|
||
# To get X displacements | ||
x_displacement = displacement.select(comp="X") | ||
print(x_displacement) | ||
|
||
|
||
# equivalent to | ||
x_displacement = simulation.displacement(components=["X"]) | ||
print(x_displacement) | ||
|
||
# plot | ||
x_displacement.plot() | ||
|
||
# extract displacement on specific nodes | ||
nodes_displacement = displacement.select(node=[1, 10, 100]) | ||
nodes_displacement.plot() | ||
|
||
# equivalent to: | ||
nodes_displacement = simulation.displacement(node_ids=[1, 10, 100]) | ||
print(nodes_displacement) | ||
|
||
############################################################################### | ||
# Compute total displacement (norm) | ||
# --------------------------------- | ||
# Compute the norm of displacement on a selection of nodes | ||
|
||
nodes_displacement = simulation.displacement(node_ids=simulation.mesh.node_ids[10:], norm=True) | ||
print(nodes_displacement) | ||
nodes_displacement.plot() | ||
|
||
|
||
############################################################################### | ||
# Extract tensor stress, apply averaging, compute equivalent | ||
# ---------------------------------------------------------- | ||
# Extract raw elemental nodal stresses from the rst file | ||
elem_nodal_stress = simulation.stress() | ||
print(elem_nodal_stress) | ||
|
||
# Compute nodal stresses from the result file | ||
nodal_stress = simulation.stress_nodal() | ||
print(nodal_stress) | ||
|
||
# Compute elemental stresses from the result file | ||
elemental_stress = simulation.stress_elemental() | ||
print(elemental_stress) | ||
|
||
# extract elemental stresses on specific elements | ||
elemental_stress = elemental_stress.select(element=[5, 6, 7]) | ||
elemental_stress.plot() | ||
|
||
# Compute nodal eqv stresses from the result file | ||
eqv_stress = simulation.stress_eqv_von_mises_nodal() | ||
print(eqv_stress) | ||
eqv_stress.plot() |
64 changes: 64 additions & 0 deletions
64
examples/00-Different-analysis-types/02-modal-simulation.py
This file contains 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,64 @@ | ||
""" | ||
.. _ref_modal_example: | ||
Modal Simulation | ||
================ | ||
Simple post processing operations like viewing the different mode shapes is displayed | ||
in this example. | ||
""" | ||
|
||
############################################################################### | ||
# Perform required imports | ||
# ------------------------ | ||
# Perform required imports. # This example uses a supplied file that you can | ||
# get by importing the DPF ``examples`` package. | ||
|
||
from ansys.dpf import post | ||
from ansys.dpf.post import examples | ||
|
||
############################################################################### | ||
# Get ``Simulation`` object | ||
# ------------------------- | ||
# Get the ``Simulation`` object that allows access to the result. The ``Simulation`` | ||
# object must be instantiated with the path for the result file. For example, | ||
# ``"C:/Users/user/my_result.rst"`` on Windows or ``"/home/user/my_result.rst"`` | ||
# on Linux. | ||
|
||
example_path = examples.download_modal_frame() | ||
simulation = post.load_simulation(example_path) | ||
|
||
# for no autocompletion, this line is equivalent to: | ||
simulation = post.ModalMechanicalSimulation(example_path) | ||
|
||
############################################################################### | ||
# View the frequency domain | ||
# ------------------------- | ||
# Printing the time freq support can help pick the right modes | ||
|
||
print(simulation.time_freq_support) | ||
|
||
# set_ids returns the unique identifiers for the modes | ||
print(simulation.set_ids) | ||
|
||
############################################################################### | ||
# Extract all mode shapes and view them one by one | ||
# ------------------------------------------------ | ||
|
||
displacement_norm = simulation.displacement(all_sets=True, norm=True) | ||
print(displacement_norm) | ||
|
||
for set_id in simulation.set_ids: | ||
displacement_norm.plot(set_id=set_id) | ||
|
||
|
||
############################################################################### | ||
# Extract a selection of mode shapes and view them one by one | ||
# ----------------------------------------------------------- | ||
|
||
modes = [1, 2, 3] | ||
|
||
displacement_norm = simulation.displacement(modes=modes, norm=True) | ||
print(displacement_norm) | ||
|
||
for set_id in modes: | ||
displacement_norm.plot(set_id=set_id) |
76 changes: 76 additions & 0 deletions
76
examples/00-Different-analysis-types/03-transient-simulation.py
This file contains 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,76 @@ | ||
""" | ||
.. _ref_transient_example: | ||
Transient Simulation with Animation | ||
=================================== | ||
In this script transient simulation is processed to extract results like | ||
stress, strain, displacement. | ||
Extracting data for chosen time steps and animating is also displayed. | ||
""" | ||
|
||
############################################################################### | ||
# Perform required imports | ||
# ------------------------ | ||
# Perform required imports. # This example uses a supplied file that you can | ||
# get by importing the DPF ``examples`` package. | ||
|
||
from ansys.dpf import post | ||
from ansys.dpf.post import examples | ||
|
||
############################################################################### | ||
# Get ``Simulation`` object | ||
# ------------------------- | ||
# Get the ``Simulation`` object that allows access to the result. The ``Simulation`` | ||
# object must be instantiated with the path for the result file. For example, | ||
# ``"C:/Users/user/my_result.rst"`` on Windows or ``"/home/user/my_result.rst"`` | ||
# on Linux. | ||
|
||
example_path = examples.find_msup_transient() | ||
simulation = post.load_simulation(example_path) | ||
|
||
# for no autocompletion, this line is equivalent to: | ||
simulation = post.TransientMechanicalSimulation(example_path) | ||
|
||
# print the simulation to get an overview of what's available | ||
print(simulation) | ||
|
||
|
||
############################################################################### | ||
# Extract displacement at all times or on a selection | ||
# --------------------------------------------------- | ||
|
||
displacement = simulation.displacement(all_sets=True) | ||
print(displacement) | ||
displacement.animate(deform=True) | ||
|
||
|
||
# equivalent to | ||
x_displacement = simulation.displacement(all_sets=True, components=["X"]) | ||
print(x_displacement) | ||
displacement.animate(deform=True) | ||
|
||
# get the available time set ids in the simulation | ||
print(simulation.set_ids) | ||
|
||
# extract displacement on given time steps or select the times steps from teh already evaluated | ||
# displacements | ||
displacement = simulation.displacement(set_ids=simulation.set_ids[5:]) | ||
displacement = displacement.select(set_id=simulation.set_ids[5:]) | ||
print(displacement) | ||
|
||
############################################################################### | ||
# Extract strain at all times or on a selection | ||
# --------------------------------------------------- | ||
strain = simulation.elastic_strain_nodal(all_sets=True) | ||
print(strain) | ||
|
||
strain = simulation.elastic_strain_nodal(set_ids=simulation.set_ids[10:]) | ||
print(strain) | ||
|
||
|
||
############################################################################### | ||
# Animate strain eqv over all times | ||
# --------------------------------- | ||
|
||
strain_eqv = simulation.elastic_strain_eqv_von_mises_nodal(all_sets=True) | ||
strain_eqv.animate() |
70 changes: 70 additions & 0 deletions
70
examples/00-Different-analysis-types/04-harmonic-complex-results.py
This file contains 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,70 @@ | ||
""" | ||
.. _ref_harmonic_example: | ||
Harmonic Simulation | ||
=================== | ||
In this script harmonic simulation is processed and complex results are used. | ||
""" | ||
|
||
############################################################################### | ||
# Perform required imports | ||
# ------------------------ | ||
# Perform required imports. # This example uses a supplied file that you can | ||
# get by importing the DPF ``examples`` package. | ||
|
||
from ansys.dpf import post | ||
from ansys.dpf.post import examples | ||
|
||
############################################################################### | ||
# Get ``Simulation`` object | ||
# ------------------------- | ||
# Get the ``Simulation`` object that allows access to the result. The ``Simulation`` | ||
# object must be instantiated with the path for the result file. For example, | ||
# ``"C:/Users/user/my_result.rst"`` on Windows or ``"/home/user/my_result.rst"`` | ||
# on Linux. | ||
|
||
example_path = examples.download_harmonic_clamped_pipe() | ||
simulation = post.load_simulation(example_path) | ||
|
||
# for no autocompletion, this line is equivalent to: | ||
simulation = post.HarmonicMechanicalSimulation(example_path) | ||
|
||
# print the simulation to get an overview of what's available | ||
|
||
print(simulation) | ||
|
||
|
||
############################################################################### | ||
# Extract displacement over a list of frequencies sets | ||
# ---------------------------------------------------- | ||
# Printing the time freq support can help pick the right frequencies | ||
|
||
print(simulation.time_freq_support) | ||
|
||
displacement = simulation.displacement(set_ids=[1, 2]) | ||
print(displacement) | ||
|
||
subdisp = displacement.select(complex=0, set_id=1) | ||
subdisp.plot() | ||
|
||
subdisp = displacement.select(complex=1, set_id=1) | ||
subdisp.plot() | ||
|
||
subdisp = displacement.select(complex=0, set_id=2) | ||
subdisp.plot() | ||
|
||
############################################################################### | ||
# Extract stress eqv over a list of frequencies sets | ||
# -------------------------------------------------- | ||
|
||
stress_eqv = simulation.stress_eqv_von_mises_nodal(set_ids=[1, 2]) | ||
print(stress_eqv) | ||
|
||
sub_eqv = stress_eqv.select(complex=0, set_id=1) | ||
sub_eqv.plot() | ||
|
||
sub_eqv = stress_eqv.select(complex=1, set_id=1) | ||
sub_eqv.plot() | ||
|
||
sub_eqv = stress_eqv.select(complex=0, set_id=2) | ||
sub_eqv.plot() |
This file contains 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,5 @@ | ||
.. _ref_different_analysis: | ||
|
||
DPF-Post analysis types | ||
~~~~~~~~~~~~~~~~~~~~~~~ | ||
These examples show how to post process different simulation types using pydpf-post. |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
68 changes: 68 additions & 0 deletions
68
examples/02-Detailed-Examples/01-named-selections-modal-simulation.py
This file contains 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,68 @@ | ||
""" | ||
.. _ref_ns_modal_example: | ||
Extract results on named selections - Modal Simulation | ||
======================================================= | ||
In this script static simulation is processed to extract results like stress, displacement. | ||
Selecting sub parts of the results by scoping on specific nodes, elements is also displayed here. | ||
""" | ||
|
||
############################################################################### | ||
# Perform required imports | ||
# ------------------------ | ||
# Perform required imports. # This example uses a supplied file that you can | ||
# get by importing the DPF ``examples`` package. | ||
|
||
from ansys.dpf import post | ||
from ansys.dpf.post import examples | ||
|
||
############################################################################### | ||
# Get ``Simulation`` object | ||
# ------------------------- | ||
# Get the ``Simulation`` object that allows access to the result. The ``Simulation`` | ||
# object must be instantiated with the path for the result file. For example, | ||
# ``"C:/Users/user/my_result.rst"`` on Windows or ``"/home/user/my_result.rst"`` | ||
# on Linux. | ||
|
||
example_path = examples.download_modal_frame() | ||
simulation = post.load_simulation(example_path) | ||
|
||
# for no autocompletion, this line is equivalent to: | ||
simulation = post.ModalMechanicalSimulation(example_path) | ||
|
||
# print the simulation to get an overview of what's available | ||
print(simulation) | ||
|
||
############################################################################### | ||
# Get the available named selections | ||
# ---------------------------------- | ||
|
||
print(simulation.named_selections) | ||
|
||
############################################################################### | ||
# Extract displacements on named selections | ||
# ----------------------------------------- | ||
|
||
bar1_tot_displacement = simulation.displacement(named_selections=['BAR_1'], norm=True) | ||
print(bar1_tot_displacement) | ||
bar1_tot_displacement.plot() | ||
|
||
bar2_tot_displacement = simulation.displacement(named_selections=['BAR_2'], norm=True) | ||
print(bar2_tot_displacement) | ||
bar2_tot_displacement.plot() | ||
|
||
# both | ||
tot_displacement = simulation.displacement(named_selections=['BAR_1', 'BAR_2'], norm=True) | ||
print(tot_displacement) | ||
tot_displacement.plot() | ||
|
||
############################################################################### | ||
# Extract stress and averaged stress on named selections | ||
# ------------------------------------------------------ | ||
eqv_stress = simulation.stress_eqv_von_mises_nodal(named_selections=['_FIXEDSU']) | ||
print(eqv_stress) | ||
|
||
# without selection | ||
elemental_stress = simulation.stress_elemental(named_selections=['BAR_1']) | ||
print(elemental_stress) | ||
elemental_stress.plot() |
Oops, something went wrong.