!   TITLE:  thread_assemble.mac (PART_LIB)
!
!
!   This sub-macro assembles a set of internal and external thread
!   profiles together in a 2D axisymmetric model. It assembles them
!   surface to surface to determine stress and deflection under axial
!   loading conditions, showing the stress and D.O.F profiles through
!   an axisymmetric planar cut.
!
!       axis_cs = thread axis coordinate systems.  For axisymmetric
!             analysis, this will be the golbal cartesian c.s.,
!             0 (or blank).
!
!       y_ext = the y coordinate position of the external thread
!
!       d_min_i = the minor diameter of the internal thread
!
!       d_min_x = the minor diameter of the external thread
!
!       n_thrd_x = # of threads in the externally threaded member.
!              If the thread length is known or desired, leave
!              blank and specify the thread length, THRD_LNX.
!
!       thrd_lnx = threaded length of external thread.
!              If N_THRD_X is specified, this argument will be
!              ignored.
!
!       n_thrd_i = # of threads in the internally threaded member
!              If the thread length is known, or desired, leave
!              blank and specify the thread length, THRD_LNI.
!
!       thrd_lni = threaded length of internal thread.
!              If N_THRD_I is specified, this argument will be
!              ignored.
!
!       n_inch = # of threads per inch of the internal and threads.
!
!       stndrd = thread standard.
!
!           'j' = UNJ thread standard, which specifies a root
!                 radius, R_THRD.
!
!           'un' (or blank) = UN thread profile, flat surface
!                             at thread root.
!
!       thrd_clr = thread clearance between internal and external
!              thread minor diameters. This specification will
!              allow analysis of the thread stresses for dif-
!              ferent clearances.
!
!
!
!                    (1)     (2)     (3)      (4)      (5)       (6)
! THREAD_ASSEMBLE, axis_cs, y_ext, d_min_i, d_min_x, n_thrd_x, thrd_lnx,
!
!                  n_thrd_i, thrd_lni, n_inch, stndrd, thrd_clr
!                    (7)       (8)      (9)     (10)     (11)
!
!
!
*get,prkey_,active,0,prkey
/nopr

thrd_ass=1
!
!
axis_cs=arg1
y_ext=arg2
d_min_i=arg3
d_min_x=arg4
n_thrd_x=arg5
thrd_lnx=arg6
n_thrd_i=arg7
thrd_lni=arg8
n_inch=arg9
stndrd=ar10
thrd_clr=ar11
!
!
csys,axis_cs
!
csn=csn+1
!
*if,d_min_i,gt,0,then
    clocal,csn,0,d_min_i/2,y_ext,0,-90,0,0
*elseif,d_min_i,lt,0,then
    clocal,csn,0,d_min_i/2,y_ext,0,-90,-180,0
*endif
!
!
screw_thread_2d,'x',n_thrd_x,thrd_lnx,n_inch,stndrd,,
!
!
!
xxx=h_thrd-(0.041667*p_thrd)/(2*tan((thrd_ang/2)*rconv))
!
yyy=(0.250*p_thrd)/(2*tan((thrd_ang/2)*rconv))
!
thrd_h_x=(7/8)*h_thrd-h_thrd/4      ! external thread height
!
thrd_h_i=xxx-yyy            ! internal thread height
!
gap=thrd_h_x+thrd_h_i+5*h_thrd      ! Gap distance between external thread
!                   ! minor diameter and internal thread
!                   ! major diameter.
!
csys,axis_cs
!
csn=csn+1
!
*if,d_min_i,gt,0,then
    clocal,csn,0,gap+d_min_i/2,y_ext,0,-90,-180,0
*elseif,d_min_i,lt,0,then
    clocal,csn,0,gap+d_min_i/2,y_ext,0,-90,0,0
*endif
!
!
screw_thread_2d,'i',n_thrd_i,thrd_lni,n_inch,stndrd,,
!
!
xxx=thrd_h_x*tan((thrd_ang/2)*rconv)
!
zzz=xxx*(thrd_clr/thrd_h_x)
!
csys,mjr_d_cs
!
csn=csn+1
thrdacs=csn
clocal,thrdacs,0,-((xxx-zzz)+2*(.041667*p_thrd)),(gap-thrd_clr-thrd_h_i),0,0,0,0
!
csys,mjr_d_cs
atran,thrdacs,am,,,,0,1
!
init_entity_num
!
!
*set,thrd_ass,
*set,iii,
*set,iij,
*set,ijk,
*set,k_tip,
*set,n_thrd,
*set,n_inch,
*set,r_thrd,
*set,k1_thrd,
*set,k2_thrd,
*set,root_h,
*set,r_width,
*set,r2edge,
*set,prof,
*set,stndrd,
*set,d_mjr,
*set,d_min,
*set,zzzz,
*set,counter,
*set,incrm,
*set,lstart,
*set,xxx,
*set,yyy,
*set,zzz,
*set,gap,
*set,n_thrd_i,
*set,n_thrd_x,

*if,prkey_,eq,1,then
    /go
*endif