!   TITLE:  thread_mesh.mac (PART_LIB)
!
!
!   This sub-macro unites a set of internal and external thread profile
!   entities in a 2D axisymmetric model. It then meshes the assembled
!   thread profile areas
!
!
!           thrdax = external thread area
!
!           mtrlx = material of the external thread
!
!           thrdai = internal thread area
!
!           mtrli = material of the internal thread
!
!           elml = minimum element edge length in thread areas
!
!
!
! THREAD_MESH, thrdax, mtrlx, thrdai, mtrli, elml
!
!
!
*get,prkey_,active,0,prkey
/nopr

thrdax=arg1
mtrlx=arg2
thrdai=arg3
mtrli=arg4
elml=arg5
!
!
asel,s,area,,thrdax
lsla,s
cm,lnsx,line        ! create line component group "lines of 'x' thread'
!
!
asel,s,area,,thrdai
lsla,s
cm,lnsi,line        ! create line component group "lines of 'i' thread'
!
!
init_entity_num
!
adele,thrdax
adele,thrdai
!
init_entity_num
!
*do,ijj,0,nscp-1,1
    init_entity_num
    !
    csys,ndselcs
       lsel,selv,loc,y,-((ijj*y_nd_d)+0.0005),-((ijj*y_nd_d)-0.0005)
    csys,min_d_cs
       lsel,r,loc,y,thrd_clr,y_nd_d
       !
    get_max_entity
    !
    *if,lm,ne,0,then
        lovlap,all
    *endif
*enddo
!
init_entity_num
!
csys,min_d_cs           ! recreate external thread area
!
lsel,selv,loc,y,-1.5*p_thrd,(7/8)*h_thrd
lsel,r,loc,x,0,1.03*thrd_ln
lsel,u,line,,lnsi
!
al,all
!
init_entity_num
!
thrdax=am
!
!
csys,mjr_d_cs+1         ! recreate internal thread area
!
lsel,selv,loc,y,-1.5*p_thrd,h_thrd-(0.041667*p_thrd)/(2*tan((thrd_ang/2)*rconv))
lsel,u,line,,lnsx
!
al,all
!
init_entity_num
!
thrdai=am
!
!
asel,s,area,,thrdax
msh_algorithm,1,1,0,,,,,,elml,elml+1.2*elml,mtrlx,,,,
!
asel,s,area,,thrdai
msh_algorithm,1,1,0,,,,,,elml,elml+1.2*elml,mtrli,,,,
!
init_entity_num
!
*set,nscp,
*set,elml,
*set,thrd_clr,

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