You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: doc/loading_km.rst
+21-15Lines changed: 21 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,30 +7,39 @@ Reading a Full File
7
7
-------------------
8
8
This example reads in the mass and stiffness matrices associated with the above example. ``LoadKM`` sorts degrees of freedom such that the nodes are ordered from minimum to maximum, and each degree of freedom (i.e. X, Y, Z), are sorted within each node. The matrices ``k`` and ``m`` are sparse by default, but if ``scipy`` is not installed, or if the optional parameter ``as_sparse=False`` then they will be full numpy arrays.
9
9
10
-
By default ``LoadKM`` outputs the upper triangle of both matrices, to output the full matrix, set ``utri=False``. Additionally, the constrained nodes of the analysis can be identified by accessing ``fobj.const`` where the constrained degrees of freedom are True and all others are False. This corresponds to the degrees of reference in ``dof_ref``.
10
+
By default ``LoadKM`` outputs the upper triangle of both matrices. The constrained nodes of the analysis can be identified by accessing ``fobj.const`` where the constrained degrees of freedom are True and all others are False. This corresponds to the degrees of reference in ``dof_ref``.
11
+
12
+
By default dof_ref is unsorted. To sort these values, set ``sort==True``. It is enabled for this example to allow for plotting of the values later on.
11
13
12
14
.. code:: python
13
15
14
16
# Load pyansys
15
17
import pyansys
18
+
from pyansys import examples
16
19
17
20
# Create result reader object and read in full file
18
-
full = pyansys.FullReader(pyansys.examples.fullfile)
19
-
dof_ref, k, m = full.LoadKM(utri=False) # return the full matrix
21
+
full = pyansys.FullReader(examples.fullfile)
22
+
dof_ref, k, m = full.LoadKM(sort=True)
23
+
20
24
21
-
If you have ``scipy`` installed, you can solve solve for the natural frequencies and mode shapes of a system. Realize that constrained degrees of freedom must be removed from the ``k`` and ``m`` matrices for the correct solution.
25
+
ANSYS only stores the upper triangular matrix in the full file. To make the full matrix:
22
26
23
27
.. code:: python
24
28
25
-
import numpy as np
26
-
# remove the constrained degrees of freedom
27
-
#NOTE: There are more efficient way to remove these indices
28
-
free = np.logical_not(full.const).nonzero()[0]
29
-
k = k[free][:, free]
30
-
m = m[free][:, free]
29
+
k += sparse.triu(k, 1).T
30
+
m += sparse.triu(m, 1).T
31
+
32
+
If you have ``scipy`` installed, you can solve solve for the natural frequencies and mode shapes of a system.
33
+
34
+
.. code:: python
31
35
36
+
import numpy as np
32
37
from scipy.sparse import linalg
33
38
39
+
# condition the k matrix
40
+
# to avoid getting the "Factor is exactly singular" error
41
+
k += sparse.diags(np.random.random(k.shape[0])/1E20, shape=k.shape)
42
+
34
43
# Solve
35
44
w, v = linalg.eigsh(k, k=20, M=m, sigma=10000)
36
45
@@ -46,6 +55,7 @@ If you have ``scipy`` installed, you can solve solve for the natural frequencies
46
55
First four natural frequencies
47
56
1283.200 Hz
48
57
1283.200 Hz
58
+
49
59
5781.975 Hz
50
60
6919.399 Hz
51
61
@@ -59,11 +69,7 @@ You can also plot the mode shape of this finite element model. Since the constr
59
69
import vtkInterface
60
70
61
71
# Get the 4th mode shape
62
-
mode_shape = v[:, 3] # x, y, z displacement for each node
63
-
64
-
# create the full mode shape including the constrained nodes
0 commit comments