!   TITLE:  gear.mac (PART_LIB)
!
!
!   OBJECTIVE:
!
!   This sub-macro creates a spur-gear profile and performs analysis.
!
!
!   COMMAND SYNTAX:
!
!              (1)   (2)      (3)     (4)       (5)      (6)   (7)  (8)
!        GEAR, cs, d_pitch, w_face, ang_pres, P_point, P_diam,  N, Z_pos
!
!
!   ARGUMENTS:
!
!       (1) gcs = coordinate system to build gear profile around. The Z axis
!                 is the axis of rotation of the gear.
!
!       (2) d_pitch = pitch diameter of gear.
!
!       (3) w_face = face width of gear.
!
!       (4) ang_pres = gear pressure angle (degrees).
!
!       (5) P_point = pitch point. This is angle at which the pitch circles
!                     of 2 gears are tangent, and therefore load against
!                     each other. (this is for the user to specify the desired
!                     location f
!
!       (6) P_diam = diametral pitch of gear (# teeth/inch). [If this argument
!                    is specified, then the number of teeth (argument 6) is
!                    ignored.]
!
!       (7) N = number of teeth on gear. [If this argument is specified, then
!               the diametral pitch (argument 5) must be left blank.]
!
!       (8) Z_pos = position along Z axis of the plane of the gear, relative
!                   to gear CS (gcs).
!
!
!   DESCRIPTION:
!
!   A spur gear is created and, if desired, it may be meshed according to the
!   proportions of the gear teeth, loaded and solved automatically. Otherwise,
!   it may be created as areas only, and manipulated as the user desires.
!
!   The pertinent gear data is entered in the arguments to create the gear. The
!   input data (arguments 6 and 7) may be either diametral pitch OR number of
!   gear teeth, but not both. If diametral pitch (P_diam) is specified, the
!   algorithm uses it to calculate gear parameters and over-rides number of
!   teeth (N, argument 7) if it is specified.
!
!   A gear may be built with a tooth pitch point at a user specified angle
!   location. This will allow for separate gear constructions to be assembled
!   in the event that a contact analysis is desired.
!
!
!
gcs_=arg1
dpitch_=arg2
wface_=arg3
angpres_=arg4
ppoint_=arg5
pdiam_=arg6
nteeth_=arg7
zpos_=arg8
!
*get,acs2_,active,,csys
!
*if,pdiam_,ne,0,then
    *if,dpitch_,ne,0,then
        nteeth_=pdiam_*dpitch_
    *else
        dpitch_=nteeth_/pdiam_
    *endif
*else
    pdiam_=nteeth_/dpitch_
*endif
!
rpitch_=dpitch_/2                           ! pitch radius
modulo_=1/pdiam_                            ! modulo (metric gears)
pcirc_=pi/pdiam_                            ! circular pitch
rbase_=rpitch_*cos(angpres_*rconv)          ! radius of base circle
addend_=modulo_                             ! addendum distance
dedend_=1.25*modulo_                        ! dedendum distance
tthick_=pcirc_/2                            ! tooth thickness (on pitch circle)
!
dout2_=2*(rbase_+addend_+dedend_)
!
phip_=sqrt((rpitch_/rbase_)**2-1)
betap_=90-((pi/2)-phip_+atan(phip_))*dconv
theta_=((1/2)*(tthick_/rpitch_))*dconv
gamma_=betap_+theta_
!
involute_curve,gcs_,2*rbase_,dout2_,20,ppoint_+betap_,ppoint_+betap_,0,zpos_
!
csys,gcs_
create_cs,0,,0,0,0,0,ppoint_-theta_,0,0
!
lsymm,y,lm,,,,1,0
init_entity_num
!
create_arcs,rbase_,zpos_,,1,0.5*gamma_,2*gamma_
create_arcs,rbase_,zpos_,,1,-2*gamma_,-0.5*gamma_
create_arcs,dout2_/2,zpos_,,1,-2*gamma_,2*gamma_
!
create_cs,0,,0,0,0,0,2*theta_,0,0
k,,0.90*rbase_,0,zpos_
k,,1.01*rbase_,0,zpos_
!
create_cs,0,,0,0,0,0,-4*theta_,0,0
k,,0.90*rbase_,0,zpos_
k,,1.01*rbase_,0,zpos_
!
ln_series
!
create_cs,0,,0,0,0,0,2*theta_,0,0
create_arcs,0.95*rbase_,zpos_,,1,-2*gamma_,2*gamma_
!
isolate_lines
profile_close
!
create_cs,0,,1,0,0,0,0,0,0
isolate_lines
ksll,s
ksel,r,loc,x,rbase_
ksel,r,loc,y,-gamma_,gamma_
ksel,r,loc,z,zpos_
!
ln_fillet,,0.05*((dout2_/2)-rbase_)
!
isolate_lines
ksll,s
ksel,r,loc,x,dout2_/2
!
ln_fillet,,(0.05/2)*((dout2_/2)-rbase_)
!
create_area-lines
!





csys,0
!create_circle,rpitch_


*go,:skip



csys,0
!create_circle,rpitch_
!create_circle,rbase_
!create_circle,dout2_/2

!
!              (1)   (2)      (3)     (4)       (5)      (6)   (7)  (8)
!        GEAR, cs, d_pitch, w_face, ang_pres, P_point, P_diam,  N, Z_pos
!
mod_assemb_prep
GEAR,0,6,0.5,20,40,,40,0
CIR_ARA_PATTERN,,4*theta_


!
csys,acs2_
!
lplot
!
*set,iccs_,
*set,iccstyp_,
*set,acs_,
*set,dbc_,
*set,dout_,
*set,npts_,
*set,ainit_,
*set,afin_,
*set,ainc_,
*set,z_,
*set,jj_,
*set,kk_,
*set,strtang_,
*set,phi_,
*set,beta_,
*set,r_,
*set,r_inc,
*set,r0_,
*set,ro_,


:skip