-
Notifications
You must be signed in to change notification settings - Fork 25
Add example cycles_to_failure from McMunich #591
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
Changes from 10 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
728cf8c
Functioning cyclic_to_failure examples
PProfizi 00dc83c
Update style
PProfizi eb5e938
Add test_examples::test_download_cycles_to_failure
PProfizi 4b8db50
Merge branch 'master' into example/cycles_to_failure
PProfizi 27067c2
Comments from Jenna
PProfizi 1d2e279
Merge branch 'master' into example/cycles_to_failure
PProfizi 4161137
Update title of the example
PProfizi 80a1d9d
Apply suggestions from code review
PProfizi 52d1b1d
Remove section separation for a visually better example
PProfizi 24b2a53
Rework formatting of the explanation paragraph
PProfizi 2d8e02a
Update examples/02-modal-harmonic/06-cycles_to_failure.py
PProfizi 5e87e0f
Fix formatting of the description
PProfizi dfdd60d
Fix formatting of the description
PProfizi 9586e9c
Merge remote-tracking branch 'origin/example/cycles_to_failure' into …
PProfizi e4af395
Merge branch 'master' into example/cycles_to_failure
PProfizi ca053e6
Revert "Remove section separation for a visually better example"
PProfizi 0fde704
Reformat sections
PProfizi e5b8310
Reformat
PProfizi 9200596
Reformat
PProfizi 88d56fe
Reformat
PProfizi 2d00a08
Reformat
PProfizi d0db412
Reformat
PProfizi 2c8bf13
Apply suggestions from code review
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,131 @@ | ||
""" | ||
Calculate the number of cycles to fatigue failure | ||
~~~~~~~~~~~~~~~~~~~~ | ||
This example shows how to generate and use a result file to calculate the | ||
cycles to failure result for a simple model. | ||
|
||
Material data is manually imported, Structural Steel from Ansys Mechanical: | ||
|
||
Youngs Modulus (youngsSteel) | ||
|
||
Poisson's Ratio (prxySteel) | ||
|
||
Cycles to Failure (sn_data), as a Strength-Number of cycles curve | ||
|
||
|
||
The first step is to generate a simple model with high stress and save the | ||
results .rst file locally to myDir (default C:\temp). | ||
For this, we use a short pyMapdl script. | ||
|
||
|
||
The second step uses DPF-Core to generate the cycles to failure result. | ||
|
||
The locally saved .rst file is imported and plotted. | ||
Then the von Mises stress is generated and plotted with DPF operators. | ||
|
||
The numpy python package is then used to interpolate the cycles to failure values. | ||
|
||
The nodal von Mises equivalent stress value is used in the interpolation. | ||
|
||
Note: The cycles to failure data must be manipulated to use NumPy interpolation. | ||
|
||
An empty field is created and filled with the resulting cycles to failure values. | ||
|
||
The cycles to failure result is plotted. | ||
|
||
|
||
The cycles to failure result is the (interpolated) negative of the stress result. | ||
The higher the stress result, the lower the number of cycles to failure. | ||
""" | ||
|
||
from ansys.dpf import core as dpf | ||
from ansys.dpf.core import examples | ||
import numpy as np | ||
|
||
|
||
# The first step is to generate a simple model with high stress | ||
|
||
# # Material parameters from Ansys Mechanical Structural Steel | ||
youngsSteel = 200e9 | ||
prxySteel = 0.3 | ||
sn_data = np.empty((11, 2)) # initialize empty np matrix | ||
sn_data[:, 0] = [10, 20, 50, 100, 200, 2000, 10000, 20000, 1e5, 2e5, 1e6] | ||
sn_data[:, 1] = [3.999e9, 2.8327e9, 1.896e9, 1.413e9, 1.069e9, 4.41e8, 2.62e8, 2.14e8, 1.38e8, | ||
1.14e8, 8.62e7] | ||
|
||
|
||
# The .rst file used in this example is already available, but can be obtained using the short pyMAPDL code below: | ||
|
||
# # ### Launch pymapdl to generate rst file in myDir | ||
# from ansys.mapdl.core import launch_mapdl | ||
# import os | ||
# | ||
# | ||
# mapdl = launch_mapdl() | ||
# mapdl.prep7() | ||
# # Model | ||
# mapdl.cylind(0.5, 0, 10, 0) | ||
# mapdl.mp("EX", 1, youngsSteel) | ||
# mapdl.mp("PRXY", 1, prxySteel) | ||
# mapdl.mshape(key=1, dimension='3d') | ||
# mapdl.et(1, "SOLID186") | ||
# mapdl.esize(0.3) | ||
# mapdl.vmesh('ALL') | ||
# | ||
# # #### Boundary Conditions: fixed constraint | ||
# mapdl.nsel(type_='S', item='LOC', comp='Z', vmin=0) | ||
# mapdl.d("all", "all") | ||
# mapdl.nsel(type_='S', item='LOC', comp='Z', vmin=10) | ||
# nnodes = mapdl.get("NumNodes", "NODE", 0, "COUNT") | ||
# mapdl.f(node="ALL", lab="fy", value=-13e6 / nnodes) | ||
# mapdl.allsel() | ||
# | ||
# # #### Solve | ||
# mapdl.run("/SOLU") | ||
# sol_output = mapdl.solve() | ||
# rst = os.path.join(mapdl.directory, 'file.rst') | ||
# mapdl.exit() | ||
# print('apdl model solved.') | ||
|
||
|
||
# PyDPF-Core is then used to post-process the .rst file to estimate the cycles to failure. | ||
|
||
# Comment the following line if solving the MAPDL problem first. | ||
rst = examples.download_cycles_to_failure() | ||
|
||
# Import the result as a DPF Model object. | ||
model = dpf.Model(rst) | ||
print(model) | ||
|
||
############################################################################### | ||
# Get the von mises equivalent stress, requires an operator. | ||
s_eqv_op = dpf.operators.result.stress_von_mises(data_sources=model) | ||
vm_stress_fc = s_eqv_op.eval() | ||
vm_stress_field = vm_stress_fc[0] | ||
vm_stress_field.plot(text="VM stress field") | ||
|
||
############################################################################### | ||
# Use NumPy to interpolate the results. | ||
|
||
# Inverse the sn_data | ||
x_values = sn_data[:, 1][::-1] # the x values are the stress ranges in ascending order | ||
y_values = sn_data[:, 0][::-1] # y values are inverted cycles to failure | ||
|
||
# Interpolate cycles to failure for the VM values | ||
cycles_to_failure = np.interp(vm_stress_field.data, x_values, y_values) | ||
|
||
############################################################################### | ||
# Generate a cycles_to_failure DPF Field | ||
|
||
# Create an empty field | ||
cycles_to_failure_field = dpf.Field(nentities=len(vm_stress_field.scoping.ids), | ||
PProfizi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
nature=dpf.natures.scalar, | ||
location=dpf.locations.nodal) | ||
# Populate the field | ||
cycles_to_failure_field.scoping = vm_stress_field.scoping | ||
cycles_to_failure_field.meshed_region = vm_stress_field.meshed_region | ||
cycles_to_failure_field.data = cycles_to_failure | ||
|
||
# Plot the field | ||
sargs = dict(title="cycles", fmt="%.2e") | ||
cycles_to_failure_field.plot(text="Cycles to failure", scalar_bar_args=sargs) |
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.