Skip to content

Commit 317a1cb

Browse files
committed
added geometry and stress import
1 parent 6a6a066 commit 317a1cb

File tree

15 files changed

+947
-223
lines changed

15 files changed

+947
-223
lines changed

doc/ansys_stress.png

21.2 KB
Loading

doc/beam_stress.png

68.7 KB
Loading

doc/cellqual.png

-8.81 KB
Loading

doc/conf.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
# import sys
2121
# sys.path.insert(0, os.path.abspath('.'))
2222
import sphinx_rtd_theme
23-
#from pyansys import __version__
2423

2524
# -- General configuration ------------------------------------------------
2625

@@ -55,9 +54,9 @@
5554
# built documents.
5655
#
5756
# The short X.Y version.
58-
version = u'0.15'
57+
version = u'0.16'
5958
# The full version, including alpha/beta/rc tags.
60-
release = u'0.15'
59+
release = u'0.16'
6160

6261
# The language for content autogenerated by Sphinx. Refer to documentation
6362
# for a list of supported languages.

doc/examples.rst

Lines changed: 84 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ Examples
22
========
33

44
These 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

88
Loading 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
1414
be loaded using ReadArchive and then converted to a vtk object.
1515

1616

@@ -51,11 +51,14 @@ VTK.
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

5760
This 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
5962
numpy 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+
109132
Reading a Full File
110133
-------------------
111134
This 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

159185
This 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\nJacobian',
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+

doc/index.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Contents
1515
:maxdepth: 2
1616

1717
examples
18+
loading_results
1819

1920
Installation
2021
------------
@@ -37,7 +38,7 @@ be installed with Python bindings.
3738
License
3839
-------
3940

40-
pyansys is licensed under the MIT license.
41+
This module, pyansys is licensed under the MIT license.
4142

4243

4344

@@ -46,4 +47,4 @@ Indices and tables
4647

4748
* :ref:`genindex`
4849
* :ref:`modindex`
49-
* :ref:`search`
50+
* :ref:`search`

doc/loading_results.rst

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
Working with a ANSYS Result File (rst)
2+
======================================
3+
4+
The ANSYS result file is a fortran formatted binary file containing the results
5+
written from an ANSYS analysis. The results, at a minimum, contain the geometry
6+
of the model analyzed along with the nodal and element results. Depending on
7+
the analysis, these results could be anything from modal displacements to
8+
nodal temperatures. At this time, only the following results are supported by
9+
this code
10+
- Nodal DOF results from a static analysis or harmonic analysis.
11+
- Nodal averaged component stresses (i.e. x, y, z, xy, xz, yz)
12+
13+
We're working on adding additional plotting and retrival functions to the code
14+
If you would like us to add an additional result type to be loaded,
15+
please open an issue in `GitHub <https://github.com/akaszynski/pyansys>`_ and
16+
include result file for the result type you wish to load.
17+
18+
19+
Loading the Result File
20+
~~~~~~~~~~~~~~~~~~~~~~~
21+
22+
As the ANSYS result files are binary files, the entire file does not need to be
23+
loaded into memory in order to retrieve results. This module
24+
accesses the results through a python object `result` which you can create with
25+
26+
.. code:: python
27+
28+
import pyansys
29+
result = pyansys.ResultReader('file.rst')
30+
31+
Upon initialization this result file contains several properties to include the
32+
time values from the analysis, node numbering, element numbering, etc.
33+
34+
35+
Result File Properties
36+
~~~~~~~~~~~~~~~~~~~~~~
37+
38+
The properties of the result file can be listed the below code. At the moment,
39+
the property listing is limited to only the number of results in the file.
40+
41+
.. code:: python
42+
43+
result_dic = result.ResultsProperties()
44+
45+
To obtain the time or frequency values of an analysis use:
46+
47+
.. code:: python
48+
49+
tval = result.GetTimeValues()
50+
51+
The sorted node and element numbering of a result can be obtained with:
52+
53+
.. code:: python
54+
55+
# sorted node numbering
56+
nnum = result.nnum
57+
58+
# sorted element numbering
59+
enum = result.enum
60+
61+
Geometry
62+
~~~~~~~~
63+
64+
The geometry of the model can be accessed directly from the dictionary by
65+
accessing
66+
67+
.. code:: python
68+
69+
result.geometry
70+
71+
Which contains the following keys
72+
73+
- ``'nnum'`` (sorted node numbering )
74+
- ``'nodes'`` (node positions)
75+
- ``'etype'`` (element type)
76+
- ``'enum'`` (non-sorted element numbers associated with elem array)
77+
- ``'elem'`` (numpy array showing nodes associated with each element, -1 indicates unused entry)
78+
- ``'ekey'`` (2xn element type reference array)
79+
80+
81+
Accessing Solution Results
82+
~~~~~~~~~~~~~~~~~~~~~~~~~~
83+
84+
The DOF solution for an analysis for each node in the analysis can be obtained
85+
using the code block below. These results correspond to the node numbers in
86+
the result file. This array is sized by the number of nodes by the number of
87+
degrees of freedom.
88+
89+
.. code:: python
90+
91+
# Create an array of results (nnod x dof)
92+
disp = result.GetNodalResult(0) # uses 0 based indexing
93+
94+
# which corresponds to the sorted node numbers from
95+
nnum = result.nnum
96+
97+
# The same results can be plotted using
98+
display_string = 'Displacement' # optional string
99+
result.PlotNodalResult(0, 'x', label=display_string) # x displacement
100+
101+
# normalized displacement can be plotted by excluding the direction string
102+
result.PlotNodalResult(0, label='Normalized')
103+
104+
Stress can be obtained as well using the below code. The nodal stress is
105+
computed in the same manner that ANSYS uses by to determine the stress at each
106+
node by averaging the stress evaluated at that node for all attached elements.
107+
For now, only component stresses can be displayed.
108+
109+
.. code:: python
110+
111+
# obtain the component node averaged stress for the first result
112+
# organized with one [Sx, Sy Sz, Sxy, Syz, Sxz] entry for each node
113+
stress = result.NodalStress(0) # results in a np array (nnod x 6)
114+
115+
# Display node averaged stress in x direction for result 6
116+
result.PlotNodalStress(5, 'Sx')
117+
118+

pyansys/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
__version__ = u'0.15'
1+
__version__ = u'0.16'
22

33
#from pyansys import Reader
44
#from pyansys.Reader import ResultReader

pyansys/archive_reader.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
# Attempt to load VTK dependent modules
2323
try:
24-
from vtkInterface import utilities
24+
import vtkInterface
2525
vtk_loaded = True
2626
except:
2727
warnings.warn('Unable to load vtk dependent modules')
@@ -132,7 +132,7 @@ def ParseVTK(self, use_cython=True, force_linear=False):
132132

133133

134134
# Create unstructured grid
135-
uGrid = utilities.MakeuGrid(offset, cells, cell_type, nodes)
135+
uGrid = vtkInterface.MakeuGrid(offset, cells, cell_type, nodes)
136136

137137
# Store original ANSYS cell and node numbering
138138
uGrid.AddPointScalars(nnum, 'ANSYSnodenum')
@@ -172,9 +172,9 @@ def ParseFEM(self, use_cython=True, raw=None):
172172
self.data = PythonParser.ParseForFEM(self.raw)
173173

174174
# Create unstructured grid
175-
self.uGrid = utilities.MakeuGrid(self.data['offset'], self.data['cells'],
176-
self.data['cell_type'],
177-
self.data['nodes'][:, :3])
175+
self.uGrid = vtkInterface.MakeuGrid(self.data['offset'], self.data['cells'],
176+
self.data['cell_type'],
177+
self.data['nodes'][:, :3])
178178

179179
# Store original ANSYS cell and node numbering
180180
self.uGrid.AddPointScalars(self.data['orignode'], 'ANSYSnodenum')

0 commit comments

Comments
 (0)