-
Notifications
You must be signed in to change notification settings - Fork 25
updated the documentation, waiting for the pymadpl issue to be resolved. #226
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
Closed
Closed
Changes from 5 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
e636a08
20220412
mcMunich 83683d5
Update 00-cycles-to-failure.py
mcMunich 41f382a
Update 00-cycles-to-failure.py
mcMunich b74a11b
Merge branch 'pyansys:master' into 20220412
mcMunich ada4469
Update 00-cycles-to-failure.py
mcMunich 88a4773
Update examples/00-basic/00-cycles-to-failure.py
mcMunich c67c502
Update examples/00-basic/00-cycles-to-failure.py
mcMunich de92b81
Update examples/00-basic/00-cycles-to-failure.py
mcMunich 54d96f5
Update examples/00-basic/00-cycles-to-failure.py
mcMunich 0103a31
Update examples/00-basic/00-cycles-to-failure.py
mcMunich 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,103 @@ | ||
""" | ||
|
||
DPF-Core Fatigue Engineering Simple Example | ||
~~~~~~~~~~~~~~~~~~~~ | ||
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 (snData) | ||
|
||
The first step is to generate a simple model with high stress and save the | ||
results .rst 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 is imported and plotted. | ||
Then the von Mises stress is generated and plotted with DPF operators. | ||
The python package numpy 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 needs to be manipulated to use numpy interpolation. | ||
|
||
An empty field is created and filled with the resulting cycles to failure values. | ||
Cycles to failure result 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. | ||
|
||
Start MAPDL as a service to generate the rst file | ||
and import the DPF-Core module as ``dpf_core``. | ||
""" | ||
|
||
|
||
from ansys.mapdl.core import launch_mapdl | ||
from ansys.dpf import core as dpf | ||
import numpy as np | ||
myDir = r'c:\temp' | ||
|
||
## Material parameters from Ansys Mechanical - Structural Steel | ||
youngsSteel = 200e9 | ||
prxySteel = 0.3 | ||
snData = np.empty((11, 2)) # initialize empty np matrix | ||
snData[:, 0] = [10, 20, 50, 100, 200, 2000, 10000, 20000, 1e5, 2e5, 1e6] | ||
snData[:, 1] = [3.999e9, 2.8327e9, 1.896e9, 1.413e9, 1.069e9, 4.41e8, 2.62e8, 2.14e8, 1.38e8, 1.14e8, 8.62e7] | ||
|
||
#### Launch pymapdl to generate rst file in myDir | ||
mapdl = launch_mapdl(run_location=myDir) | ||
mcMunich marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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() | ||
mapdl.exit() | ||
print('apdl model solved.') | ||
|
||
# ##### pydpf is used to post process the .rst in order to estimate the cycles to failure | ||
model = dpf.Model(myDir + '\\file.rst') | ||
mcMunich marked this conversation as resolved.
Show resolved
Hide resolved
|
||
print(model) | ||
mesh = model.metadata.meshed_region | ||
|
||
# Get the von mises equivalent stress, requires an operator | ||
mcMunich marked this conversation as resolved.
Show resolved
Hide resolved
|
||
s_eqv_op = dpf.operators.result.stress_von_mises() | ||
s_eqv_op.inputs.data_sources.connect(model) | ||
vm_stress_fields = s_eqv_op.outputs.fields_container() | ||
vm_stress_nodal = vm_stress_fields[0] | ||
vm_stress_nodal.plot() | ||
|
||
# Use numpy to interpolate the results. | ||
mcMunich marked this conversation as resolved.
Show resolved
Hide resolved
|
||
vm_stress = vm_stress_nodal.data | ||
myNodes = vm_stress_nodal.scoping.ids | ||
xPoints = snData[:, 1][::-1] # the x values are the stress ranges in ascending order | ||
yValues = snData[:, 0][::-1] # y values are inverted cycles to failure | ||
|
||
myResult = np.ones((len(myNodes), 3)) | ||
myResult[:, 0] = myNodes | ||
myResult[:, 1] = vm_stress | ||
myResult[:, 2] = np.interp(myResult[:, 1], xPoints, yValues) | ||
Comment on lines
+95
to
+98
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. Please follow PEP8 when naming variables. Should be using pascal case here. |
||
|
||
##Create an empty field, add nodes/results and plot | ||
mcMunich marked this conversation as resolved.
Show resolved
Hide resolved
|
||
myResultField = dpf.Field(len(myNodes), dpf.natures.scalar, 'Nodal') | ||
my_scoping = dpf.Scoping() | ||
my_scoping.location = 'Nodal' | ||
my_scoping.ids = myResult[:, 0] | ||
myResultField.scoping = my_scoping | ||
myResultField.data = myResult[:, 2] | ||
mesh.plot(myResultField) |
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.
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.
It's best not to specify a directory. By default, PyMAPDL creates a temporary directory that's OS independent. It can be accessed simply by: