Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations GregLocock on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Stiffness and mass matrices of the model 2

Status
Not open for further replies.

matmar

Mechanical
Feb 5, 2003
1
Is it possible to get the stiffness and mass matrices of the model as a ASCII file? ABAQUS and ALGOR seems to have this feature but does ANSYS have it?
 
Replies continue below

Recommended for you

from

2. How can I get the complete stiffness matrix of an element out of ANSYS?
You can list all components of the global stiffness matrix in ANSYS by converting your model into a "super element". To do this:
1. Build your model normally. You do not need to apply any boundary conditions.
2. In the solution processor choose the Analysis Type to be substructuring (Solu -> New Analysis -> Substructuring).
3. Select Solu -> Analysis Options and give your substructure a name (defaults to the jobname) and select the Matrix to be generated to be the Stiffness Matrix. Click OK.
4. Next you need to define the master DOF. Master DOFs are all DOFs that will be considered when assembling the global stiffness matrix. Since you want all components of the matrix just define all DOFs to be master DOF: Solu -> Master DOFs -> Define -> Pick All -> All DOF -> OK.
4. Solve the Problem: Solu -> Solve LS. ANSYS will compute the solution and write the global stiffness matrix into a new file called "name.sub" (name being whatever name you defined in step 3). Do not delete this file. You will need it to later if you want to relist the global stiffness matrix.
5. Click: UM -> List -> Other -> Superelement Data. Set name to the name of your *.sub file, the name you defined in step 3, and set KOPT = Full Contents, then click OK.
6. ANSYS will list all the superelement data. The beginning is just a bunch of header information you do not have to worry about. Scroll down to: GLOBAL DOF SET NODES, LABELS = . Next ANSYS lists the order of the DOF vector for your global stiffness matrix. For example:

GLOBAL DOF SET NODES, LABELS =
1 UX 1 UY 2 UX 2 UY 3 UX
3 UY 4 UX 4 UY

This means that in the subsequent matrix the 1st row and 1st column are associated with the DOF UX at node 1, 2nd is UY1, 3rd UX2, etc. Then follows the listing of the stiffness matrix, e.g.:

ROW 1 MATRIX 1
103846.15 37500.000 -63461.538 -2884.6154 -51923.077
-37500.000 11538.462 2884.6154

ROW 2 MATRIX 1
37500.000 103846.15 2884.6154 11538.462 -37500.000
-51923.077 -2884.6154 -63461.538

etc.

Here, ROW 1 lists the elements of the first row of the stiffness matrix, i.e., K11=103846.15, K12=37500.00, K13=-62461.538, etc.
 
Another method:
Here are two file about extract mass&stiffness data from the *.full
(if u do modal analysis Ansys will produce the jobname.full)
The developer is Zhaoxin, one of my ex-classmate.


Extract.for:
******************************************************************************

program Extract
c *** primary function: Extract global mass and stiffness matrix from full
file.
c *** secondary function: Read and reformat full file
c
c *** zx(r) copyright(c) 2001
c *** Xin Zhao
c
c NOTICE - The .full file as output of ANSYS is needed.

c Be sure to set up for modal ANTYPE,2
c and full subspace MODOPT,SUBSP,nmode,0,0, ,OFF
c (nmode is not used - it can be any value

c If the free-free stiffness and mass matrices are desired,
c make sure there are no constraints on the model.

c #include "impcom.inc"

c ZHAOXIN
Use dflib
USE NUMERICAL_LIBRARIES
USE MATRIXOUT_
C END OF ZHAOXIN

external ihsort
external binset, binini, binrd, binclo, biniqr, bintfo
integer binset, biniqr

integer IOLENG, ROWLENG, WAVEFRONT, MAXNODE
parameter (IOLENG=16384, ROWLENG=1000, WAVEFRONT=10000,
x MAXNODE=100000)

integer ivect(100), npage, keyrw, units, code,
x nbuf,i, j, nunit, jloc, kbf, kext, n, lbuf, nmatrx,
x lll(ROWLENG), indx(ROWLENG),lenbac, nontp, numdof, irow,
x l(WAVEFRONT), nrow, mr, nterms, kunit, munit, kdof,
x baclst(MAXNODE), node, idof, sortlist(2,MAXNODE),
x nmass, nstif, nmax, lumpm

integer buffer(IOLENG)
double precision krow(ROWLENG), mrow(ROWLENG)

character*80 title(2)
character*106 pname,mname,kname
character*106 zmname,zkname !zhao xin
character*32 jobnam

integer iout,intpdp,lenfnm,reclng

c ***** arrays for reading file data *****
integer iarray(ROWLENG)
double precision darray(ROWLENG)
equivalence (darray(1),iarray(1))

C ZHAOXIN ¶¨Òå±äÁ¿

INTEGER tonumdof, status
REAL(8),ALLOCATABLE :: SMATRIX:),:),MMATRIX:),:),CMATRIX:),:)
TYPE (qwinfo) winfo
LOGICAL(4) result

C END OF ZHAOXIN
WRITE(*,'("Matrices extracting program")')
WRITE(*,'(" .full file from ANSYS is used as input. ",/,"
!(.full files are obtained from
!modal analysis by subspace method.)")')
WRITE(*,*)
WRITE(*,'("Xin Zhao 2001.5.4")')
WRITE(*,'("zerokingcn@yahoo.com")')
WRITE(*,*)

WRITE(*,'("¾ØÕóÌáÈ¡³ÌÐò")')
WRITE(*,'("Óû§ÇëÌṩ .fullÎļþ£¬.fullÎļþÓ¦µ±ÓÃANSYSµÄ
!subspace·½·¨½øÐÐģ̬·ÖÎö»ñµÃ¡£")')
WRITE(*,'("Ä£Ð͵ÄÕûÌå¾ØÕó°´Á½ÖÖ¸ñʽÊä³ö£¬¶ÔÓ¦µÄÎļþÀ©Õ¹
!Ãû·Ö±ðΪ.compressºÍ.txt¡£",/,".compressÎļþ´æ´¢ÁË×ø±ê±íʾµÄ
!ÕûÌå¾ØÕ󣬶ø.txtÎļþ´æ´¢ÁËÕûÌå¾ØÕóµÄÍêÈ«ÐÎʽ¡£")')
WRITE(*,'("½¨ÒéÓû§ÓÃд×Ö°å¶ø²»ÊÇnotepad´ò¿ª½á¹ûÎļþ£¬
!",/,"²»¹ý×îºÃÊÇÓÃTextPad´ò¿ª£¬Æä´ÎÒ²¿ÉÒÔÓÃUltraEdit¡£")')

WRITE(*,*)
WRITE(*,'("ÕÔê¿ 2001.5.4")')
WRITE(*,'("zerokingcn@yahoo.com")')
WRITE(*,*)


c ********** define the unit numbers **********
iout = 6
kunit = 2
munit = 3
c ********** define the number of integers per double precision
intpdp = biniqr (0,2)
c ********** define the number of characters in the file name
lenfnm = biniqr (0,3)
c ********** define the i/0 buffer page length (integer*4 words)
reclng = biniqr (0,1)
c
c ********** define the file names **********

c zhao xin
! result = DISPLAYCURSOR ($GCURSORON)
winfo%TYPE = QWIN$MAX
result=SETWSIZEQQ(iout, winfo)

write(*,'("Pls input .full file (exclude extension)")')
write(*,'("ÇëÊäÈëfullÎļþÃû³Æ£¨²»º¬À©Õ¹Ãû£©:"\)')
read(*,'(A106)') pname
c pname = 'MATRIX\veri1.full'
zmname=trim(pname)//'mass'
zkname=trim(pname)//'stiffness'

CALL CLEARSCREEN ($GWINDOW)
mname = trim(pname)//'mass.compress'

! zmname='mmatrix' !zhaoxin
kname = trim(pname)//'stiffness.compress'
! zkname='kmatrix' !zhaoxin
pname=trim(pname)//'.full'


c
c ********** initialize the bin routines **********
call binini (iout)
c
c ********** initialize the header common **********
title(1) = 'New title as given by ROM'
title(2) = 'New subtitle as given by ROM'
jobnam = 'file '
units = 0
c --- the value for code below should be changed to appropriate 3rd party cod
e
code = 200
call bintfo (title,jobnam,units,code)



c
c ********** open the file **********
c
c ***** set the i/o unit number
nunit =7
c ***** define buffer number *****
nbuf = 1
c ***** start address in the buffer *****
lbuf = 1
c ***** number of pages for nbuf *****
npage = 1
c ***** read key *****
keyrw = 1
c ***** length of each page *****
j = reclng
c ***** read external file format *****
kext = 1
c
i = binset (nbuf,nunit,keyrw,lbuf,j,npage,pname,lenfnm,kext,
x buffer(1))
c
c ***** check for error *****
if (i .ne. 0) then
write (iout,2004) trim(pname)
2004 format (/' *** ERROR ***'/' DATA FILE ',a,' DOES NOT EXIST ')
stop
go to 999
endif

c ********** open the ASCII files **********
open (unit=kunit,file=kname,status='unknown')
rewind 2
open (unit=munit,file=mname,status='unknown')
rewind 3

write (iout,2000) trim(pname), trim(mname), trim(kname)
2000 format (/' ***** WRITE OUT ANSYS MATRICES FROM ',A15,
x ' *****'//' MASS MATRIX ON FILE = ',A30/
x ' STIFFNESS MATRIX ON FILE = ',A30//
x ' Only the symmetric part of the matrices is written')

c ***** file header *****
n = 100
jloc = 0
call binrd (nbuf,jloc,n,ivect(1),kbf,buffer(1))

n = 20
call binrd (nbuf,jloc,n,ivect(1),kbf,buffer(1))

numdof = ivect(8)
lenbac = ivect(7)
nontp = ivect(2)
nmatrx = ivect(4)
lumpm = ivect(11)



C ZHAO XIN

! ALLOCATE (SMATRIX(nontp,nontp),MMATRIX(nontp,nontp),
! * CMATRIX(nontp,nontp))
tonumdof=numdof*lenbac
ALLOCATE (SMATRIX(tonumdof,tonumdof),MMATRIX(tonumdof,tonumdof),
* CMATRIX(tonumdof,tonumdof))
C ZHAO XIN

write (iout,2001) numdof,lenbac,lumpm
2001 format(/' Number of DOF per node=',i6/
x ' Number of nodes =',i6/
x ' Lumped mass flag =',i6)

n = numdof
call binrd (nbuf,jloc,n,ivect(1),kbf,buffer(1))

n = lenbac
call binrd (nbuf,jloc,n,baclst(1),kbf,buffer(1))

c ********** compress nodes into grid point order *********
nmax = 0
do i = 1,lenbac
sortlist(1,i) = baclst(i)
sortlist(2,i) = i
if (baclst(i) .gt. nmax) nmax = baclst(i)
enddo
write (iout,2002) nmax
2002 format (' Maximum node number =',i6)
call ihsort (2,lenbac,sortlist(1,1),1)
do i = 1,lenbac
sortlist(1,i) = i
enddo
call ihsort (2,lenbac,sortlist(1,1),2)
do i = 1,lenbac
baclst(i) = sortlist(1,i)
enddo

c ***** put headers on the files *****
write (kunit,2010) kname, pname
2010 format ('# ',A30/'#'/'# FROM ANSYS FILE: ',A30/'#')
write (munit,2011) mname, pname
2011 format ('# ',A30/'#'/'# FROM ANSYS FILE: ',A30/'#')

nmass = 0
nstif = 0
nrow = 0
do irow = 1,nontp

n = 10
call binrd (nbuf,jloc,n,lll(1),kbf,buffer(1))
mr = lll(1)
kdof = abs(lll(2))
node = (kdof-1)/numdof
idof = kdof - node*numdof
node = baclst(node+1)
kdof = (node-1)*numdof + idof
do i = 3,n
nrow = nrow + 1
l(nrow) = lll(i)
enddo

nterms = 10
call binrd (nbuf,jloc,nterms,indx(1),kbf,buffer(1))
do i = 1,nterms
idof = l(indx(i))
node = (idof-1)/numdof
idof = idof - node*numdof
node = baclst(node+1)
lll(i) = (node-1)*numdof + idof
enddo
n = 10
call binrd (nbuf,jloc,n,krow(1),kbf,buffer(1))
i = 1
if (lumpm .ge. 1) i = 2
n = n/intpdp-i


do i = 1,n
if (krow(i) .ne. 0.0d0) then
nstif = nstif + 1
if (kdof .lt. lll(i)) then
write (kunit,2005) kdof,lll(i),krow(i)
c ZHAOXIN Êä³ö¸Õ¶È¾ØÕó
SMATRIX(kdof,lll(i))=krow(i)
SMATRIX(lll(i),kdof)=krow(i)
c END OF ZHAOXIN

else
write (kunit,2005) lll(i),kdof,krow(i)
c ZHAOXIN Êä³ö¸Õ¶È¾ØÕó
SMATRIX(kdof,lll(i))=krow(i)
SMATRIX(lll(i),kdof)=krow(i)
c END OF ZHAOXIN

endif
endif
enddo

if (nmatrx.gt.1 .and. lumpm.eq.0) then
n = 10
call binrd (nbuf,jloc,n,mrow(1),kbf,buffer(1))
n = n/intpdp
do i = 1,n
if (mrow(i) .ne. 0.0d0) then
nmass = nmass + 1
if (kdof .lt. lll(i)) then
write (munit,2005) kdof,lll(i),mrow(i)
c ZHAOXIN Êä³öÒ»ÖÂÖÊÁ¿¾ØÕó
MMATRIX(kdof,lll(i))=mrow(i)
MMATRIX(lll(i),kdof)=mrow(i)
c END OF ZHAOXIN

2005 format (2i8,1pe20.12)
else
write (munit,2005) lll(i),kdof,mrow(i)
c ZHAOXIN
MMATRIX(kdof,lll(i))=mrow(i)
MMATRIX(lll(i),kdof)=mrow(i)
c END OF ZHAOXIN

endif
endif
enddo
else
mrow(1) = krow(n+2)
if (mrow(1) .ne. 0.0d0) then
nmass = nmass + 1
write (munit,2005) kdof,kdof,mrow(1)

c ZHAOXIN Êä³ö¼¯ÖÐÖÊÁ¿¾ØÕó
MMATRIX(kdof,kdof)=mrow(1)
c END OF ZHAOXIN

endif
endif

l(mr) = l(nrow)
l(nrow) = 0
nrow = nrow - 1

enddo

close (unit=kunit,status='keep')
close (unit=munit,status='keep')

write (iout,2008) nmass, nstif
2008 format (/' Number of mass matrix terms =',i8/
x ' Number of stiffness matrix terms=',i8)
999 call binclo (nbuf,'KEEP',buffer(1))

c zhao xin Êä³öµ½Îļþ

zmname=trim(zmname)//'.txt'; zkname=trim(zkname)//'.txt'
write (iout,2100) zmname, zkname
2100 format (/' ***** ÓÉANSYSµÄFULLÎļþ¶ÁÈ¡ÕûÌå¾ØÕó',
x ' *****'//' ÖÊÁ¿¾ØÕóдÈëÎļþ£º',A30/
x ' ¸Õ¶È¾ØÕóдÈëÎļþ£º',A30)

write (iout,2101) numdof,lenbac,lumpm,nmax,tonumdof
2101 format(/' ÿ¸ö½ÚµãµÄ×ÔÓɶÈÊýÄ¿ =',i6/
x ' ½Úµã¸öÊý =',i6/
x ' ÊÇ·ñÊǼ¯ÖÐÖÊÁ¿¾ØÕó =',i6,'£¨0:Ò»ÖÂÖÊÁ¿¾ØÕó£»
x1:¼¯ÖÐÖÊÁ¿¾ØÕó£©'/
x ' ×î´ó½Úµã±àºÅ =',i6/
x ' ×î´ó×ÔÓɶȱàºÅ =',i6/)

! CALL SCROLLTEXTWINDOW( INT2(5 ))

CALL MATRIXOUT (SMATRIX,zkname)
CALL MATRIXOUT (MMATRIX,zmname)
c zhao xin Êä³öµ½Îļþ
! MESSAGE=MESSAGEBOXQQ('SOLUTION IS DONE!', 'TRANSIENT ANALYSIS',
! * MB$ICONQUESTION.OR.MB$YESNO.OR.MB$DEFBUTTON1)
DO WHILE (.TRUE.)
END DO

end

subroutine ihsort (nper,n,table,iloc)
c *** primary function: quick heap sort of an integer table

c input arguments:
c nper (int,sc,in) - number of terms
c n (int,sc,in) - number of items in the table
c table (int,ar(nper,n),inout) - the table to be sorted
c iloc (int,sc,in) - location in table for sort

c output arguments:
c table (int,ar(nper,n),inout) - the sorted table


integer nper, n, table(nper,n), iloc, i,j,k,l,m, hold, ip

m = n
10 m = m/2
if (m .eq. 0) go to 50
k = n - m
j = 1
20 i = j
30 l = i + m
if (table(iloc,i) .le. table(iloc,l)) go to 40
do ip = 1,nper
hold = table(ip,i)
table(ip,i) = table(ip,l)
table(ip,l) = hold
enddo
i = i - m
if (i .ge. 1) go to 30
40 j = j + 1
if (j .gt. k) go to 10
go to 20

50 return
end

******************************************************************************
*

matrixout.f90

******************************************************************************
*
MODULE MATRIXOUT_

CONTAINS

SUBROUTINE MATRIXOUT (M,MNAME)
!-------------------------------------------------------------
! OUTPUT a matrix in matrix form
! Xin Zhao
!--------------------------------------------------------------
real*8 M:),:)
CHARACTER*(*) MNAME
CHARACTER*30 FILENAME
integer dimrow,dimcolumn

!----TRIM():Returns the argument with trailing blanks removed----

FILENAME=TRIM(MNAME)!//'.TXT'
OPEN(UNIT=2,FILE=FILENAME,STATUS='REPLACE')
dimrow=ubound(m,dim=1)
dimcolumn=ubound(m,dim=2)
WRITE (2,*) MNAME
! WRITE (*,*) MNAME
do i=1,dimrow
write(2,'(f20.6\)') (m(i,J),J=1,DIMCOLUMN)
WRITE(2,*)
! write(*,'(f14.6\)') (m(i,J),J=1,DIMCOLUMN)
! WRITE(*,*)
end do

END SUBROUTINE

END MODULE
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor