@@ -2,15 +2,15 @@ Examples
22========
33
44These examples show how ANSYS binary and ASCII files can be read and displayed
5- using pyansys.
6-
5+ using pyansys. These examples are meant to demonstrate the capabilities of
6+ pyansys. For more details see the other reference pages.
77
88Loading and Plotting an ANSYS Archive File
99------------------------------------------
1010
1111.. _examples_ref :
1212
13- ANSYS archive files containing solid elements (both legacy and current), can
13+ ANSYS archive files containing solid elements (both legacy and current) can
1414be loaded using ReadArchive and then converted to a vtk object.
1515
1616
5151 grid.Plot()
5252
5353
54- Loading and Plotting an ANSYS Result File
55- -----------------------------------------
54+ Loading and Plotting Results from an ANSYS Result File
55+ ------------------------------------------------------
56+
57+ Loading the Result File
58+ ~~~~~~~~~~~~~~~~~~~~~~~
5659
5760This example reads in binary results from a modal analysis of a beam from
58- ANSYS. This section of code does not rely on vtk and can be used solely with
61+ ANSYS. This section of code does not rely on `` VTK `` and can be used solely with
5962numpy installed.
6063
6164.. code :: python
@@ -64,12 +67,10 @@ numpy installed.
6467 import pyansys
6568 from pyansys import examples
6669
67- # Sample result file and associated archive file
70+ # Sample result file
6871 rstfile = examples.rstfile
69- hexarchivefile = examples.hexarchivefile
70-
7172
72- # Create result reader object by loading the result file
73+ # Create result object by loading the result file
7374 result = pyansys.ResultReader(rstfile)
7475
7576 # Get beam natural frequencies
@@ -78,8 +79,9 @@ numpy installed.
7879 # Get the node numbers in this result file
7980 nnum = result.nnum
8081
81- # Get the 1st bending mode shape. Nodes are ordered according to nnum.
82- disp = result.GetResult(0 , True ) # uses 0 based indexing
82+ # Get the 1st bending mode shape. Results are ordered based on the sorted
83+ # node numbering (by default and same as `nnum` above).
84+ disp = result.GetNodalResult(0 ) # uses 0 based indexing
8385 print disp
8486
8587 .. code ::
@@ -92,20 +94,41 @@ numpy installed.
9294 [ 26.60384371 -17.14955041 -2.40527841]
9395 [ 31.50985156 -20.31588852 -2.4327859 ]]
9496
95- You can then load in the archive file associated with the result file and then
96- plots a nodal result.
97+ Plotting Nodal Results
98+ ~~~~~~~~~~~~~~~~~~~~~~
99+
100+ As the geometry of the model is contained within the result file, you can plot
101+ the result without having to load any additional geometry. Below, displacement
102+ for the first bending mode of the beam is plotted using ``VTK ``. To use this functionality,
103+ ``VTK `` must be installed.
97104
98105.. code :: python
99106
100- # Load CDB (necessary for display)
101- result.LoadArchive(hexarchivefile)
102-
103107 # Plot the displacement of Mode 0 in the x direction
104108 result.PlotNodalResult(0 , ' x' , label = ' Displacement' )
105-
109+
106110
107111 .. image :: hexbeam_disp.png
108112
113+
114+ Stress can be plotted as well using the below code. The nodal stress is
115+ computed in the same manner that ANSYS uses by to determine the stress at each
116+ node by averaging the stress evaluated at that node for all attached elements.
117+ For now, only component stresses can be displayed.
118+
119+ .. code :: python
120+
121+ # Display node averaged stress in x direction for result 6
122+ result.PlotNodalStress(5 , ' Sx' )
123+
124+
125+ .. image :: beam_stress.png
126+
127+ Here's the same result as viewed from ANSYS.
128+
129+ .. image :: ansys_stress.png
130+
131+
109132Reading a Full File
110133-------------------
111134This example reads in the mass and stiffness matrices associated with the above
@@ -151,10 +174,13 @@ Data from the full file can now be accessed from the object. If you have
151174
152175
153176 Built-In Examples
154- =================
177+ -----------------
178+
179+ The following examples can be run natively from pyansys by importing the
180+ examples subpackage.
155181
156- Display Cell Quality
157- --------------------
182+ Plot Cell Quality
183+ ~~~~~~~~~~~~~~~~~
158184
159185This built in example displays the minimum scaled jacobian of each element of a tetrahedral beam:
160186
@@ -169,11 +195,14 @@ This is the source code for the example:
169195
170196.. code :: python
171197
198+ import pyansys
199+
172200 # load archive file and parse for subsequent FEM queries
201+ from pyansys import examples
173202 if meshtype == ' hex' :
174- archive = pyansys.ReadArchive(hexarchivefile)
203+ archive = pyansys.ReadArchive(examples. hexarchivefile)
175204 else :
176- archive = pyansys.ReadArchive(tetarchivefile)
205+ archive = pyansys.ReadArchive(examples. tetarchivefile)
177206
178207 # create vtk object
179208 archive.ParseFEM()
@@ -183,4 +212,35 @@ This is the source code for the example:
183212
184213 # plot cell quality
185214 archive.uGrid.Plot(scalars = qual, stitle = ' Cell Minimum Scaled\n Jacobian' ,
186- rng = [0 , 1 ])
215+ rng = [0 , 1 ])
216+
217+
218+ Plot Nodal Stress
219+ ~~~~~~~~~~~~~~~~~
220+ This built in example plots the x component stress from a hexahedral beam.
221+
222+ .. code :: python
223+
224+ from pyansys import examples
225+ examples.DisplayStress()
226+
227+ .. image :: beam_stress.png
228+
229+ This is the source code for the example:
230+
231+ .. code :: python
232+
233+ import pyansys
234+
235+ # get location of the example file
236+ from pyansys import examples
237+ rstfile = examples.rstfile
238+
239+ # Create rsult object
240+ result = pyansys.ResultReader(rstfile)
241+
242+ # Plot node averaged stress in x direction for result 6
243+ result.PlotNodalStress(5 , ' Sx' )
244+
245+
246+
0 commit comments