finish
/clear
/filname,tuning_fork,1

! Input parameters

Grip_Width=5.00
Grip_Length=30.00
Radius=10.00
Rod_Width=5.00
Rod_Length=45.00
Depth=5.00

Emod=2.000e5
Density=7.850e-9
Poisson=0.300


! **************************************************************************************************************************

/prep7

et,1,plane182,,,3
mp,ex,1,  0.1 ! Young's modulus in [ N/mm^2 ]
mp,nuxy,1,0.1 ! Poisson ratio
mp,dens,1,0.1 ! Density in [ t/mm^3 ]
r,1,      0.1 ! Rod width in [ mm ]
r,2,      0.1 ! Grip width in [ mm ]

rectng,(Radius-(Rod_Width/2)),(Radius-(Rod_Width/2))+Rod_Width,0,Rod_Length     ! Area of rectangle
pcirc,(Radius-(Rod_Width/2)),(Radius-(Rod_Width/2))+Rod_Width,0,-90             ! Area of circular ring
nummrg,kp ! merging of identical geometry

wpcsys,0                    ! Positioning of the working level
wpoffs,(Grip_Width/2)       ! Shifting of the working level
wprota,,,90                 ! Turning of the working level
lsbw,5                      ! Intersection between working level and line 5
al,7,8,9,6,1

csys,0

k,9,0,-(Grip_Length+Radius) ! Grip geometry
k,10,(Grip_Width/2),-(Grip_Length+Radius)
a,9,10,6,5
real,1                      ! Rod width
!esize,1

lsel,s,line,,1
lsel,a,line,,3
LESIZE,ALL,,,4,,,,,0
lsel,s,line,,2
lsel,a,line,,4 
LESIZE,ALL,,,20,,,,,0
mshkey,1
amesh,1

lsel,s,line,,7
LESIZE,ALL,,,9,,,,,0
lsel,s,line,,6
LESIZE,ALL,,,6,,,,,0
lsel,s,line,,9
LESIZE,ALL,,,3,,,,,0
allsel,all
LCCAT,6,9
mshkey,1
amesh,2

real,2                      ! Grip width

lsel,s,line,,5
LESIZE,ALL,,,3,,,,,0
lsel,s,line,,10
lsel,a,line,,11
LESIZE,ALL,,,15,,,,,0
mshkey,1
amesh,3

allsel,all

CM,_Y,LINE  
*SET,_Z1,LSINQR(0,13)   
*IF,_z1,ne,0,then   
LSEL,R,LCCA 
*SET,_Z2,LSINQR(0,13)   
LDELE,ALL   
*SET,_Z3,_Z1-_Z2
*IF,_Z3,NE,0,THEN   
CMSEL,S,_Y  
CMDELE,_Y   
*ENDIF  
*ELSE   
CMSEL,S,_Y  
CMDELE,_Y   
*ENDIF  

arsym,x,all                 ! Mirroring of the surfaces and of the corresponding FE model

allsel,all

nummrg,all                  ! Merging of superimposed nodes

et,10,solid185
mp,ex,10,Emod               ! Young's modulus in [ N/mm^2 ]
mp,nuxy,10,Poisson          ! Poisson's ratio
mp,dens,10,Density          ! Density in [ t/mm^3 ]
r,10,

type,10
mat,10
real,10

esize,,4
VEXT,ALL, , ,0,0,Depth,,,,

allsel,all
aclear,all

finish

/solu

nsel,s,loc,y,-(Grip_Length+Radius)-0.01,-(Grip_Length+Radius)+0.01
d,all,all

allsel,all
antype,modal,new
modopt,lanb,10
solve

finish

/post1

allsel,all

save,db_after_solu,db

*GET,var_MTOTx,ELEM,0,MTOT,x
*GET,var_MTOTy,ELEM,0,MTOT,y
*GET,var_MTOTz,ELEM,0,MTOT,z

var_MTOTx=var_MTOTx*1e6
var_MTOTy=var_MTOTy*1e6
var_MTOTz=var_MTOTz*1e6
  

set,,1
*get,f1,freq,modal
set,,2
*get,f2,freq,modal
set,,3
*get,f3,freq,modal

! Definition of output file

/OUTPUT,'tuning_fork_output.txt'
/COM,Eigen-Frequency_1:
*VWRITE,f1
(F18.9)
/COM,Eigen-Frequency_2:
*VWRITE,f2
(F18.9)
/COM,Eigen-Frequency_3:
*VWRITE,f3
(F18.9)
/COM,Mass:
*VWRITE,var_MTOTx
(F18.9)
/OUTPUT

finish

/eof