Skip to content

Instantly share code, notes, and snippets.

@shkiefer
shkiefer / MAPDL-mass.txt
Last active June 25, 2020 04:24
MAPDL-mass file setup
*cfopen, %_wb_userfiles_dir(1)%%f_name%, txt
*vwrite,'Component','CS_ID','mass_X','mass_Y','mass_Z','Ics_xx','Ics_yy','Ics_zz','Ics_xy','Ics_xz','Ics_yx','Ics_yz','Ics_zx','Ics_zy'
%12C,%12C,%12C,%12C,%12C,%12C,%12C,%12C,%12C,%12C,%12C,%12C,%12C,%12C
*dim,outVars,array,nCMs,12
finish
/filname, mass
@shkiefer
shkiefer / MAPDL-mass.txt
Last active June 25, 2020 04:16
MAPDL-mass arrays
f_name = 'my_mass'
nCMs = 2
*DIM, cms, STRING, 100, nCMs
cms(1,1) = 'my_comp_1'
cms(1,2) = 'my_comp_2'
*DIM, css, STRING, 100, nCMs
css(1,1) = 'cs_comp_1'
css(1,2) = 'cs_comp_2'
*do,j,1,nCMs
fini
/prep7
! get cs_mass location and angles
*GET,cs_x,CDSY,%css(1,j)%,LOC,X
*GET,cs_y,CDSY,%css(1,j)%,LOC,Y
*GET,cs_z,CDSY,%css(1,j)%,LOC,Z
*GET,cs_xy,CDSY,%css(1,j)%,ANG,XY
*GET,cs_yz,CDSY,%css(1,j)%,ANG,YZ
! get inertia about CG & mass
*get, mass_x, ELEM,0,MTOT,X
*get, mass_y, ELEM,0,MTOT,Y
*get, mass_z, ELEM,0,MTOT,Z
*get, cg_x, ELEM,0,MC,X
*get, cg_y, ELEM,0,MC,Y
*get, cg_z, ELEM,0,MC,Z
*get, moim_x, ELEM,0,IMC,X
@shkiefer
shkiefer / MAPDL-mass.txt
Last active June 18, 2020 07:42
MAPDL-mass, transformation matrix
! make transformation matrix T
PI=ACOS(-1)
c1=COS(cs_xy*PI/180.)
c2=COS(cs_yz*PI/180.)
c3=COS(cs_zx*PI/180.)
s1=SIN(cs_xy*PI/180.)
s2=SIN(cs_yz*PI/180.)
s3=SIN(cs_zx*PI/180.)
txx = c1*c3-s1*s2*s3
@shkiefer
shkiefer / MAPDL-mass.txt
Created June 18, 2020 07:47
MAPDL-mass, write & exit
*vwrite,cms(1,1),css(1,1),outVars(1,1),outVars(1,2),outVars(1,3),outVars(1,4),outVars(1,5),outVars(1,6),outVars(1,7),outVars(1,8),outVars(1,9),outVars(1,10),outVars(1,11),outVars(1,12)
%12c,%12.0f,%12.3e,%12.3e,%12.3e,%12.3e,%12.3e,%12.3e,%12.3e,%12.3e,%12.3e,%12.3e,%12.3e,%12.3e
*cfclos
finish
/filname
/post1
@shkiefer
shkiefer / MAPDL-mass_total_model.txt
Created June 24, 2020 06:27
Get coordinate system location and angles
ALLSEL
! define coordinate system to calculate mass properties about, my_cs is an 'apdl_name' or specific cs ID (integer)
cs_mass = my_cs
finish
! change filename to write output to mass.out to not overwrite default file.out
/filname, mass
fini
@shkiefer
shkiefer / MAPDL-mass_total_model.txt
Created June 24, 2020 06:35
form matrices and then *get mass properties about CG
fini
/sol
! prepare element matrices / calculate mass properties
irlf,-1
psolve,elform
psolve,elprep
! get translational mass
*get, mass_x, ELEM,0,MTOT,X
@shkiefer
shkiefer / MAPDL-mass_total_model.txt
Created June 24, 2020 06:41
translate mass properties from cg to coordinate system
! translate inertia components to cs_mass loc
xg = cg_x - cs_x
yg = cg_y - cs_y
zg = cg_z - cs_z
Ixx_cst = moim_x+mass_x*(yg**2+zg**2)
Iyy_cst = moim_y+mass_y*(xg**2+zg**2)
Izz_cst = moim_z+mass_z*(xg**2+yg**2)
Ixy_cst = moim_xy+mass_x*xg*yg
Iyz_cst = moim_yz+mass_y*yg*zg
Izx_cst = moim_zx+mass_z*zg*xg
@shkiefer
shkiefer / MAPDL-mass_total_model.txt
Created June 24, 2020 06:44
build transformation matrix
! make transformation matrix T
PI=ACOS(-1)
c1=COS(cs_xy*PI/180.)
c2=COS(cs_yz*PI/180.)
c3=COS(cs_zx*PI/180.)
s1=SIN(cs_xy*PI/180.)
s2=SIN(cs_yz*PI/180.)
s3=SIN(cs_zx*PI/180.)
txx = c1*c3-s1*s2*s3