Visualizing Structural Matrices in ANSYS Using APDL
Visualizing Structural Matrices in ANSYS Using APDL
Aaron C Acton
19 November 2008
Abstract
This article presents a method of visualizing structural matrices used in finite-element analysis using ANSYS
and the ANSYS Parametric Design Language (APDL). The information is intended to provide some insight into
the nature of structural matrices used in finite-element codes. Some terms used in sparse-matrix arithmetic are
discussed, and methods for calculating certain quantities are provided. A test model is constructed to demon-
strate how the stiffness, mass, and damping matrices may be visualized for various systems. The effect of element
shape, element type (including superelements), element reordering, and equation reordering on structural ma-
trices is briefly investigated.
Since the magnitudes of the coefficients can vary by where ODNZ is the number of off-diagonal nonzero
many orders of magnitude, a logarithmic plot was ob- terms and DINZ the number of diagonal nonzero terms.
tained by taking the base-10 logarithm of the absolute Otherwise, in the case of an unsymmetric matrix,
value of each coefficient, log10 (abs(val)).
The following information was added to each plot: NNZ = ODNZ + DINZ .
matrix type (stiffness, damping, mass),
element type with keyoptions where appropriate, The nonzero terms reported by the supplied macro in
matrix file, this article represents the total number of nonzero terms
matrix symmetry, in the full matrix.
number of nonzero terms (NZ),
number of equations (EQN),
matrix sparseness (% Sparse), and 2.2 Number of Equations
matrix condition number (COND).
There will generally be more degrees of freedom (DOF)
Furthermore, if the effect of element sorting was of in- in a model than equations in the system since some may
terest (discussed in Section 6), the following was added: be condensed out before the matrices are written with
element sorting direction (WSORT), HBMAT. The following situations indicate when certain
maximum wavefront (WMAX), and DOF are not written to the matrix file with HBMAT:
root-mean-square wavefront (WRMS).
Alternatively, if the effect of equation reordering was When constraints (D) are specified in the model,
of interest (discussed in Section 7), the following was the rows and columns corresponding to these
added: DOF are eliminated from the system of equations.
When coupled sets (CP) and/or constraint equa-
equation reordering scheme.
tions (CE) are present, the rows and columns cor-
The meaning of these terms is discussed in the following responding to the slave DOF are eliminated from
sections. the system of equations.
2.4 Matrix Condition element with internal degrees of freedom that are stat-
ically condensed out prior to the element assemblage
The condition number of a matrix is a measure of how process [5]. It is expected, then, that the substructure
sensitive a solution is to numerical errors. A matrix matrix has less DOF and is more densely populated
with a condition number close to unity is said to be well than the assembled global matrix.
conditioned, while that with a large condition number is
said to be ill conditioned. This topic has been covered
elsewhere [3].
4 Matrix Type
The condition number can be computed in several
different ways, but the method used by the macro pro-
The macro provided in this article supports the plot-
vided with this article calculates the ratio of largest to
ting of real-value coefficients for stiffness, damping,
smallest pivot values (known as the condition number
consistent-mass, and lumped-mass matrices from the
in the two-norm), which can be obtained directly from
Harwell-Boeing file or from the BCS file. In the fol-
the jobname.DIAG file.
lowing sections, the structure of these matrices will be
investigated.
3 Finite Element Test Model The stiffness matrix is perhaps the most interesting
to investigate as the effect of element shape and element
Since the effect of geometry on the matrix structure
type can be immediately seen.
was not of interest in this article, the rectangular block
shown in Figure 2 was used for all tests. In most
cases, the geometry was meshed with hexahedrons,
4.1 Stiffness Matrix
while tetrahedrons were used in others (images shown
later). Depending on the shape of the geometry being meshed,
one may decide to choose either hexahedrons (also
called bricks), tetrahedrons (also called tets), or some
combination thereof, filling in nonconformities with
prisms and pyramids where necessary. The mesh and
stiffness matrix for a simple model consisting purely of
hexahedrons can be seen in Figure 3.
3.1 Substructuring
In contrast, Figure 4 shows the mesh and stiffness The number of nonzero terms increases substan-
matrix for the same geometry meshed with tetrahe- tially, and the number of equations decreases, causing
drons (element edge length kept constant). the sparseness to drop to near zero. The estimated
wavefront has also increased significantly.
Using component-mode synthesis (CMS) rather
than Guyan reduction results in the stiffness matrix
shown in Figure 6.
It is worth noting here that using tets in place of 4.2 Mass Matrix
bricks with equal element edge length has a significant
effect on the number of nonzero terms. In addition, the The typical formation of the structural mass matrix in
estimated maximum value for wavefront size increased implicit analyses creates coupling between degrees of
from 57 to 87 for this model (the topic of wavefront will freedom. This is known as consistent mass, and can be
be discussed further in Section 6). seen in Figure 7.
If the brick model is solved as a regular superele-
ment (Guyan reduction) with master DOF set accord-
ing to the specifications described in Section 3, the re-
sulting stiffness matrix becomes dense, as shown in Fig-
ure 5.
[C] = [M ]
Figure 9: Consistent-mass matrix from the FULL file
when using the Point Mass feature in Workbench Simula-
tion. Similarly, since beta damping (BETAD) is a stiffness-
matrix multiplier, it can be seen in Figure 11 that
the damping-matrix plot resembles the structure of the
Additional terms appear in the mass matrix to ac-
mass matrix.
count for the coupling between the point mass and the
nodes to which it is attached. Two workarounds for [C] = [K]
this issue are to turn on lumped-mass approximation
(to reduce the mass matrix to the diagonal form) or Other forms of damping, such as modal damping,
to reduce the size of geometry to which the feature is damping ratio, and damping obtained with speciality
scoped (to reduce the number of nodes included in the elements, may produce different plots than the ones
feature). shown above.
A. C. Acton / Visualizing structural matrices in ANSYS using APDL 6
5 Element Type close to unity whereas that for the mixed formula-
tion jumps to 1013 , indicating an ill-conditioned matrix.
The SOLID185 offers a two formulations applicable for This likely explains the requirement that a direct solver
general finite-stain deformation. The default pure- must be used for the mixed formulation [6]. Also, the
displacement formulation (KEYOPT(6)=0), used for sim- number of equations increased due to the inclusion of
ulating compressible materials, solves the standard the hydrostatic pressure.
static system of equations
It is also possible to look at the structural matri-
[K]{u} = {F } ces for some coupled-field elements. The static coupled
equations for a piezoelectric element, for example, is
and forms the stiffness matrix shown in Figure 12.
given by
" #( ) ( )
[K] [K Z ] {u} {F }
= ,
[K Z ]T [K d ] {V } {L}
" #( ) ( )
[K] [K ut ] {u} {F }
= ,
[0] [K t ] {T } {Q}
Figure 13: Stiffness matrix for mixed u-P element for-
mulation.
Note that the condition number (discussed in Sec- which produces the unsymmetric stiffness matrix shown
tion 2.4) for the pure formulation in this example is in Figure 15.
A. C. Acton / Visualizing structural matrices in ANSYS using APDL 7
Figure 15: Stiffness matrix for thermoelastic elements. Figure 16: Unsorted matrix for hex mesh.
Note that the weakly-coupled formulation would One technique of reordering the elements is to use
produce a symmetric matrix. geometric sorting (WSORT), for which a sorting direction
can be manually specified. The present topic of plot-
ting matrices provides an opportunity to see the effect
of sorting.
6 Element Reordering
7 Equation Reordering
References
All input files used for the examples presented in this article are included in the following sections. Header
information and page numbering has been removed to simplify copy-and-paste operations.
FINISH
/CLEAR
/RGB,INDEX,100,100,100,0
/RGB,INDEX,80,80,80,13
/RGB,INDEX,60,60,60,14
/RGB,INDEX,0,0,0,15
/GFILE,512
width = 5e-3
height = 2e-3
depth = 3e-3
*GET,jobname,ACTIVE,0,JOBNAM
/DELETE,%jobname%,DIAG
/DELETE,%matrix%,matrix
/DELETE,BCS_MATRIX,ASCII
/PREP7
/UNITS,SI
/VIEW,,1,2,3
!element = SOLID226,11
element = SOLID185
ET,1,SOLID185
!ALPHAD,5
!BETAD,0.005
!LUMPM,ON
!MAT,1
!MSHAPE,1
! steel
MP,EX,1,2E11
MP,NUXY,1,0.3
MP,DENS,1,7800
MP,KXX,1,43
! piezoelectric ceramic
MP,DENS,2,7500
MP,PERX,2,804.6
MP,PERZ,2,659.7
TB,PIEZ,2
TBDATA,16,10.5
TBDATA,14,10.5
TBDATA,3,-4.1
TBDATA,6,-4.1
TBDATA,9,14.1
TB,ANEL,2
TBDATA,1,13.2E10,7.1E10,7.3E10
TBDATA,7,13.2E10,7.3E10
TBDATA,12,11.5E10
TBDATA,16,3.0E10
TBDATA,19,2.6E10
TBDATA,21,2.6E10
BLOCK,0,width,0,height,0,depth
ESIZE,1e-3
VMESH,ALL
NSEL,S,LOC,X
D,ALL,UX,,,,,TEMP,VOLT
NSEL,S,LOC,Y
D,ALL,UY
NSEL,S,LOC,Z
D,ALL,UZ
NSEL,ALL
!/PNUM,LOC,1
!NOORDER
WSORT,%sort_dir%,,,,1E6
!/SHOW,PNG
!EPLOT
!/SHOW,CLOSE
!/SHOW,TERM
WFRONT
*GET,w_max,ACTIVE,0,WFRONT,MAX
*GET,w_rms,ACTIVE,0,WFRONT,RMS
FINISH
! README
!
! If plotting from HB file, choose either the FULL file (f2hb) or the
! SUB file (s2hb), then run hb2mat and mat2plot
!
! If plotting from BCS file, run only bm2mat and mat2plot
f2hb,matrix
!s2hb,matrix
hb2mat,matrix
!bm2mat,eqn_reord
mat2plot
A.2 Macro used to write matrix files from FULL file (f2hb.mac)
! full2hb.mac
!
! macro to write structural matrices from FULL file
!
! arguments
! 1 - matrix file to dump (stiff, damp, or mass)
/SOLU
!ANTYPE,MODAL
!MODOPT,QRDAMP,1
BCSOPT,,,,,,-1
SOLVE
FINISH
/AUX2
FILE,,full
HBMAT,%arg1%,,,ASCII,%arg1%,NO,NO
FINISH
A.3 Macro used to write matrix files from SUB file (s2hb.mac)
! sub2hb.mac
!
! reads SUB matrix file, output with HBMAT
!
! arguments
! 1 - matrix file to dump (stiff, damp, or mass)
element = MATRIX50
/SOLU
ANTYPE,SUBSTR
SEOPT,,3
!CMSOPT,fix,12
NSEL,S,EXT
M,ALL,ALL
NSEL,ALL
SOLVE
FINISH
/AUX2
FILE,,sub
HBMAT,arg1,,,ASCII,arg1,NO,NO
FINISH
! fix a column-pointer bug in v11 for SUB files (has no effect for FULL files)
colptr(ptrcrd) = indcrd+1
! optionally write the information to a text file for MATLAB/Octave sparse format
!*CFOPEN,smf,txt
!*VWRITE,nzcolind(1),nzrowind(1),nzvalues(1)
!(2F14.0,D25.15)
!*CFCLOS
! HBMAT written from SUB files always contains the full matrix,
! but that from FULL files does not
*IF,STRSUB(from_file,1,4),EQ,FULL,THEN
*IF,symmetric,EQ,1,THEN
nnz = 2*odnz+dinz
*ENDIF
*ENDIF
! read the pivot values from the DIAG file into a vector
/INQUIRE,diag,EXIST,%jobname%,DIAG
*IF,diag,EQ,1,THEN
*DIM,pivval,ARRAY,nrow
*VREAD,pivval(1),%jobname%,DIAG,,,nrow,,,2
(5X,E12.8)
/SOLU
BCSOPT,%arg1%,,,,ASCII,-1
SOLVE
FINISH
/INQUIRE,lines,LINES,%bcs_fil%,%bcs_ext%
*DIM,rowind,ARRAY,indcrd,2
*VFILL,rowind(1,1),RAMP,1,1
*VREAD,rowind(1,2),%bcs_fil%,%bcs_ext%,,,indcrd,,,2
(8F10.0)
*DIM,sparse,ARRAY,nnz,3
*VREAD,sparse(1,1),%bcs_fil%,%bcs_ext%,,jik,3,valcrd,,lines-valcrd
(2F10.0,E25.15)
*VOPER,mapping,rowind(1,1),SCAT,rowind(1,2)
*DO,ii,1,valcrd
sparse(ii,1) = mapping(sparse(ii,1))
sparse(ii,2) = mapping(sparse(ii,2))
*ENDDO
index = valcrd+1
*DO,ii,1,valcrd
*IF,sparse(ii,1),NE,sparse(ii,2),THEN
sparse(index,1) = sparse(ii,2)
sparse(index,2) = sparse(ii,1)
sparse(index,3) = sparse(ii,3)
index = index+1
*ENDIF
*ENDDO
! read the pivot values from the DIAG file into a vector
/INQUIRE,diag,EXIST,%jobname%,DIAG
*IF,diag,EQ,1,THEN
*DIM,pivval,ARRAY,nrow
*VREAD,pivval(1),%jobname%,DIAG,,,nrow,,,2
(5X,E12.8)
/PREP7
/VIEW,,,,1
VCLEAR,ALL
ACLEAR,ALL
EDELE,ALL
NDELE,ALL
/UDOC,,BODY,OFF
/UDOC,,TYPE,OFF
/PLOPTS,LOGO,OFF
/PLOPTS,DATE,OFF
/TRIAD,OFF
/PBF,TEMP,,1
/GLINE,ALL,-1
/PLOPTS,INFO,3
/TLABEL,-0.93,0.87,%matname% log10(abs(val))
/TLABEL,-0.93,0.80,%element%
/TLABEL,-0.93,0.73,%from_file%
/TLABEL,-0.93,0.66,%sym_str%
/TLABEL,-0.93,0.59,%nnz% NZ
/TLABEL,-0.93,0.52,%nrow% EQN
/TLABEL,-0.93,0.45,%sparseness%% Sparse
/TLABEL,-0.93,0.38,COND %cond%
*IF,STRSUB(from_file,1,3),EQ,BCS,THEN
/TLABEL,-0.93,0.31,%eqn_reord% ordering
*ELSE
/TLABEL,-0.93,0.31,WMAX %w_max%
/TLABEL,-0.93,0.24,WRMS %w_rms%
/TLABEL,-0.93,0.17,WSORT %sort_dir%
*ENDIF
CSYS,0
N,1
N,nrow+1,nrow
FILL
NGEN,ncol+1,nrow+1,ALL,,,,-1
/REP
ET,1,PLANE182
TYPE,1
! "ww" is simply the width+1, used to shorten the variable name and equation
ww=nrow+1
*DO,ii,1,nnz
*IF,sparse(ii,3),NE,0,THEN
rr = sparse(ii,1)
cc = sparse(ii,2)
EN,ii,rr*ww+cc,rr*ww+cc+1,(rr-1)*ww+cc+1,(rr-1)*ww+cc
BFE,ii,TEMP,,LOG10(ABS(sparse(ii,3)))
*ENDIF
*ENDDO
!/SHOW,PNG
EPLOT
!/SHOW,CLOSE
!/SHOW,TERM
FINISH