4.8. APDL Math Examples

The following examples demonstrate various applications for APDL Math.

Example 4.1: Verify Orthogonality of Eigenmodes after a Modal Analysis

! PERFORM A STANDARD MODAL ANALYSIS
/SOLU
MODOPT,lanb,10
SOLVE
FINISH


! READ M AND Nod2Solv MATRICES FROM THE FULL FILE
*SMAT,MassMatrix,D,IMPORT,FULL,file.full,MASS
*SMAT,NodToSolv,D,IMPORT,FULL,file.full,NOD2SOLV

! READ THE MODE SHAPES FROM THE MODE FILE
*DMAT,Phi,D,IMPORT,MODE,file.mode

! CONVERT THEM TO THE SOLVER ORDERING
*MULT,NodToSolv,,Phi,,SOLVPhi

! CREATE PhiTMPhi = (Phi)T*M*Phi
*MULT,MassMatrix,,SOLVPhi,,APhi
*MULT,SOLVPhi,TRANS,APhi,,PhiTMPhi

! PRINT THIS MATRIX: IT SHOULD BE THE IDENTITY MATRIX [I]
*PRINT,PhiTMPhi,PhiTMPhi.txt

 

Example 4.2: Read a Matrix and a Load Vector from a FULL File and Solve

! READ THE STIFFNESS MATRIX FROM THE FULL FILE
*SMAT,MatK,D,IMPORT,FULL,file.full,STIFF

! READ THE MAPPING TABLE: INTERNAL -> SOLV
*SMAT,Nod2Solv,D,IMPORT,FULL,file.full,NOD2SOLV

! READ THE LOAD VECTOR FROM THE FULL FILE
*DMAT,VecB,D,IMPORT,FULL,file.full,RHS

! ALLOCATE THE SOLUTION VECTOR IN SOLVER SPACE BY SIMPLY COPYING B
*DMAT,VecX,D,COPY,VecB			

! FACTORIZE A USING THE SPARSE SOLVER FUNCTIONS
*LSENGINE,DSP,MySolver,MatK
*LSFACTOR,MySolver
 
! SOLVE THE LINEAR SYSTEM
*LSBAC,MySolver,VecB,VecX 		

! CONVERT THE SOLUTION TO THE INTERNAL SPACE
*MULT,Nod2Solv,T,VecX,,XNod

! PRINT THE SOLUTION
*PRINT,XNod

! FREE ALL OBJECTS
*FREE,ALL 

Example 4.3: Perform a Full Harmonic Sweep

! READ THE 3 MATRICES FROM THE FULL FILE
*SMAT,MatK,D,IMPORT,FULL,file.full,STIFF
*SMAT,MatM,D,IMPORT,FULL,file.full,MASS
*SMAT,MatC,D,IMPORT,FULL,file.full,DAMP

! READ THE MAPPING TABLE: FULL -> SOLV
*SMAT,Nod2Solv,D,IMPORT,FULL,file.full,NOD2SOLV

! READ THE LOAD VECTOR FROM THE FULL FILE
*DMAT,VecB,Z,IMPORT,FULL,file.full,RHS	

! ALLOCATE THE SOLUTION VECTOR IN SOLVER SPACE BY SIMPLY COPYING B
*DMAT,XSolv,Z,COPY,VecB

C=3.E8		! LIGHT CELERITY
			
*DO,FREQ,1.E9,10.E9,1.E9		! LOOP OVER FREQUENCY VALUES

  /com,** FREQUENCY = %FREQ%

  w=2*3.14*FREQ/C			! COMPUTE OMEGA (w)
  w2=w*w					! w*w

  ! FORM THE COMPLEX SYSTEM  A = K - w2*M + jw*C
  *SMAT,MatA,Z,COPY,MatK		
  *AXPY,-w2,0.,MatM,1.,0.,MatA
  *AXPY,0.,w,MatC,1.,0.,MatA
  
  ! FACTORIZE MATRIX A USING SPARSE SOLVER
  *LSENGINE,DSP,MySolver,MatA
  *LSFACTOR,MySolver

  ! SOLVE THE LINEAR SYSTEM
  *LSBAC,MySolver,VecB,XSolv		
*ENDDO
*FREE,ALL

Example 4.4: Perform an UNSYM Modal Solve from a FULL File

! DEFINE THE ANALYSIS OPTIONS
/SOLU
ANTYPE,MODAL
MODOPT,UNSYM,10,-3

! LOAD K AND M MATRICES FROM AN EXISTING FULL FILE 
*SMAT,MatK,D,IMPORT,FULL,file.full,STIFF 
*SMAT,MatM,D,IMPORT,FULL,file.full,MASS 

! LAUNCH THE UNSYM ALGORITHM, APPLIED TO THE GIVEN MATRICES
*EIGEN,MatK,MatM,,EiV,EiM 
*PRINT,EiV 
FINISH

Example 4.5: Perform a DAMP Modal Solve from HBMAT Files

! DEFINE THE ANALYSIS OPTIONS
/SOLUTION
ANTYPE,MODAL
MODOPT,DAMP,10

! LOAD K, M and C MATRICES FROM EXISTING HBMAT ASCII FILES 
*SMAT,MatK,D,IMPORT,HBMAT,K.hbmat,ASCII
*SMAT,MatM,D,IMPORT,HBMAT,M.hbmat,ASCII
*SMAT,MatC,D,IMPORT,HBMAT,C.hbmat,ASCII

! LAUNCH THE DAMP ALGORITHM, APPLIED TO THE GIVEN MATRICES
*EIGEN,MatK,MatM,MatC,EiV,EiM 

*PRINT,EiV 
FINISH
 

Example 4.6: Import a Matrix from a .sub File, Modify the Values, and Update the File

! LOAD THE K MATRIX FROM A SUB FILE
*DMAT,MatK,D,IMPORT,SUB,file.sub,STIFF
*PRINT,MatK

! EXPORT THE MATRIX AS A STANDARD APDL ARRAY
*EXPORT,MatK,APDL,MATKAPDL

! MODIFY THE MATRIX
MATKAPDL(1,1) = 5.0

! IMPORT THE MODIFIED MATRIX INTO APDL MATH SPACE
*DMAT,MatK,,IMPORT,APDL,MATKAPDL

! EXPORT THE MODIFIED MATRIX TO THE SUB FILE
*EXPORT,MatK,SUB,file.sub,STIFF

Example 4.7: Calculate the Complex Mode Contribution Coefficients (CMCC)

APDLMath is used to calculate the CMCC based on Equation 3–1 in the Structural Analysis Guide. The real modes are read from the Jobname.modesym mode file, the mass matrix from the file.full file, and the complex modes from the Jobname.mode file. The resulting CMCC are printed out in the ASCII file Cmcc.txt. If the file Cmcc.txt already exists, the new coefficients will be appended to this file.

! ------------------------------------------------------------
! GET THE MASS MATRIX FROM FILE.FULL
! ------------------------------------------------------------

*SMAT,Mass,D,IMPORT,FULL,file.full,MASS
! GET THE FULL TO SOLV MAPPING	
*SMAT,NodToSolv,D,IMPORT,FULL,file.full,NOD2SOLV

! ------------------------------------------------------------
! GET THE COMPLEX MODES FROM FILE.MODE  : PhiC
! ------------------------------------------------------------

*DMAT,PhiF,Z,IMPORT,MODE,file.mode,1,300
*MULT,NodToSolv,,PhiF,,PhiC
*FREE,PhiF

! ------------------------------------------------------------
! GET THE REAL MODES FROM FILE.MODESYM    : PhiR
! ------------------------------------------------------------

*DMAT,PhiF,,IMPORT,MODE,file.modesym,1,300
*MULT,NodToSolv,,PhiF,,PhiR
*FREE,PhiF

! ------------------------------------------------------------
! COMPUTE AND NORMALIZE THE CMCC : PhiR(T).M.PhiC
! ------------------------------------------------------------

*MULT,Mass,,PhiC,,MPhiC            ! MPhiC = M.PhiC
*MULT,PhiR,T,MPhiC,,PhiRMPhiC      ! PhiRMPhiC = PhiR(T).MPhiC

*DO,ii,1,PhiRMPhiC_colDim,1        ! LOOP OVER ALL COLUMNS
 *VEC,v,z,LINK,PhiRMPhiC,ii        ! V = LINK TO iith Column
 *VEC,vr,d,COPY,v
 *NRM,vr,NRMINF,_vr_nrm
 *AXPY,,,,1./_vr_nrm,,v            ! V is normalized / NRM_INF(V)=1.
*ENDDO

*PRINT,PhiRMPhiC,Cmcc.txt          ! PRINT -> Cmcc.txt


Example 4.8: Import Matrices from Nastran DMIG Files and Create SUB Files for Mechanical APDL


Important:   When importing matrices from Nastran DMIG files, it is a requirement that the generalized coordinates for a CMS superelement appear last (SPOINTS must have highest ID number). Otherwise, the SUB file, generated from the imported matrices, will not be generated properly.


! DEFINITION OF NODES, ELEMENTS 
....

Nodes must be defined in Mechanical APDL to match Nastran Data to the Mechanical APDL model.

! IMPORT A STIFFNESS MATRIX FROM A NASTRAN DMIG FILE
*DMAT,KMat,D,IMPORT,DMIG,fileK.dmig

! IMPORT A MASS MATRIX FROM ANOTHER NASTRAN DMIG FILE
*DMAT,MMat,D,IMPORT,DMIG,fileM.dmig

The matrices must be in different files.

! ACCESS THE MATRICES VALUES IF NEEDED
*PRINT,KMat

KMat(1,1) = KMat(1,1)*2
...


! GENERATE A NEW SUB FILE WITH THESE 2 MATRICES
*EXPORT,KMat,SUB,newfile.sub,STIFF,,WAIT
*EXPORT,MMat,SUB,newfile.sub,MASS,,DONE

The two matrices are dumped into one single SUB file. The file is generated at the "DONE" keyword.


Example 4.9: Calculate the Participation Factors and Total Rigid Body Mass

APDL Math is used to calculate the participation factors and total rigid body mass based on the database file (test.db), the full file (test.full), and the mode file (test.mode) from a modal analysis. This procedure is particularly useful if the effect of boundary conditions and CP/CE is required.

/filname,test
resume,, db

! Generation of the rigid body motion vectors = rig_apdl
*get,numDof,common,,dofcom,,int,1
*get,maxNod,NODE,0,NUM,MAX,,,INTERNAL
dim1 = numDof*maxNod
dim2 = 6
*dim,rig_apdl,ARRAY,dim1,dim2
*vfill,rig_apdl,RIGID

! Get the name of the files
*dim,jobcurr,STRING,248
jobcurr(1)=''
*dim,jobcurrfull,STRING,248
jobcurrfull(1)=''
*dim,jobcurrmode,STRING,248
jobcurrmode(1)=''
*do,i,1,248,8
   *get,param,ACTIVE,0,JOBNAME,,START,i
   jobcurr(1) = strcat(jobcurr(1),param)
*enddo
jobcurrfull(1) = strcat(jobcurr(1),'.full')
jobcurrmode(1) = strcat(jobcurr(1),'.mode')

! Calculation of pfall = PhiRT x mass x rig
*smat,mass,D,IMPORT,FULL,jobcurrfull(1),MASS
*smat,NodToSolv,D,IMPORT,FULL,jobcurrfull(1),NOD2SOLV
*smat,usrtosolv,D,IMPORT,FULL,jobcurrfull(1),USR2SOLV

*dmat,rig,D,IMPORT,APDL,rig_apdl
*mult,usrtosolv,,rig,,rigsolv

*mult,mass,,rigsolv,,prodr

*dmat,PhiF,,IMPORT,MODE,jobcurrmode(1),1,4
*mult,NodToSolv,,PhiF,,PhiR
*free,PhiF

*mult,PhiR,T,prodr,,pfall
*print,pfall                   ! participation factors

*mult,rigsolv,T,prodr,,mtot
*print,mtot                  ! total rigid body mass