!   TITLE:  create_interface.mac (SM_TOOL)
!
!
!   OBJECTIVE:
!
!   This sub-macro creates an interface area on a specified volume that
!   overlaps an adjoining area on another volume.
!
!
!   COMMAND SYNTAX:
!
!                              (1)             (2)            (3)
!       CREATE_INTERFACE, 'vols_w_intfa', 'vols_c_intfa', store_group
!
!
!   ARGUMENTS:
!
!       (1) vols_w_intfa = volume(s) containing the desired interface
!                          regions (areas).
!                          [volume # OR component name ]
!
!       (2) vols_c_intfa = volume(s) on which it is desired to create
!                          the interface regions (areas).
!                          [volume # OR component name ]
!
!           *** NOTE: The arguments must be one of the two formats:
!
!               a.) N (where N > 0) = the volume number N.
!
!               b.) 'comp_name' = component group character name
!                                 containing the volumes. This may be
!                                 a part name within an assembly if
!                                 desired.
!                                 [ MUST BE IN SINGLE QUOTES ]
!
!       (3) store_group = component group character name in which it is
!                         desired to store the newly interfaced volumes.
!
!           *** NOTE: If all the volumes contained in the component group
!                     of argument 2 are altered by the interfacing
!                     operation, that component group name (argument 2)
!                     will be deleted from the database.
!
!                     If it is desired to include these new volumes in the
!                     component part name from which they originally belonged,
!                     or if a new component name is to be created for the
!                     newly created volumes, it may be specified in this
!                     argument.
!
!
!   DESCRIPTION:
!
!   Overlapping area(s) is/are created on the surface of the volume(s)
!   of argument 2. These interface areas directly overlap the area(s) [in
!   size and shape] of the interfacing volume(s) of argument 1 such that
!   the the mesh patterns in these areas will, at least closely, overlap.
!   This is for the purpose of creating interfacing mesh areas that will
!   accomodate coupling or constraints of close or coincident nodes.
!
!   The volumes do not share a common area (VGLUE operation), but have 2
!   overlapping areas, each attached to the interfacing volumes.
!
!
!
*get,prkey_,active,0,prkey
/nopr
!
volswa_=arg1
volsca_=arg2
volnam_=arg3
!
!
! Parameter type: 0=scalar, 1=array, 2=table, 3=character scalar,
!                 4=character array, -1=undefined
!
!
! Type of component Cname:
!       1=Nodes, 2=Elements, 6=Keypoints, 7=Lines, 8=Areas, 9=Volumes,
!       11-15=Subcomponents
!       (11=subcomponent at level 1, 12=subcomponent at level 2, etc.).
!
*get,volntyp_,parm,volnam_,type
!
*if,volntyp_,eq,0,then
    volnam_='new_grp'
    cmsel,s,volsca_
    *get,vscacnt_,volu,0,count
*elseif,volntyp_,eq,3,then
    *get,vncmtyp_,comp,volnam_,type
    !
    *if,vncmtyp_,eq,9,then
        cmsel,s,volnam_
        *get,vnamcnt_,volu,0,count
    *endif
*endif
!
init_entity_num,1
cm,modvset_,volu
!
*get,actvcs_,active,,csys
*get,actvtyp_,cdsy,actvcs_,attr,kcs
!
*if,actvtyp_,ne,0,then
    create_cs,0,,0,0,0,0,0,0,0
*endif
!
*get,activcs_,active,,csys
!
*get,argtyp1_,parm,volswa_,type
*get,argtyp2_,parm,volsca_,type
!
*if,argtyp1_,eq,0,then
    *if,volswa_,gt,0,then
        vsel,s,volu,,volswa_
        volswa_='vsetwa_'
        cm,%volswa_%,volu
    *endif
*endif
!
*if,argtyp2_,eq,0,then
    *if,volsca_,gt,0,then
        vsel,s,volu,,volsca_
        volsca_='vsetca_'
        cm,%volsca_%,volu
    *endif
*endif
!
cmsel,s,%volsca_%   ! store areas of volume(s) desired to create interface
aslv,s
entity_array,'a','vcaset_','array'
init_entity_num,1
!
cmsel,s,%volswa_%   ! create the glue volume(s)
vtran,activcs_,all
cmsel,u,%volswa_%
cm,vgset_,volu      ! vgset_ = volume glue set
init_entity_num,1
!
cmsel,s,%volsca_%   ! glue the volumes to the desired volume(s)
cmsel,a,vgset_
vglue,all
cmsel,u,modvset_    ! select all the glued volumes (unselect the rest of the model)
cm,vgvols_,volu     ! vgvols_ = glued volume component group
init_entity_num,1
!
cmsel,s,vgvols_
entity_array,'v','vgset_','array'
vgcnt_=ecount
!
*do,abcde__,1,vgcnt_,1
    vsel,s,volu,,vgset_(abcde__,1)
    aslv,s
    !
    entity_array,'a','avgset_','array'
    avgcnt_=ecount
    !
    *do,fghij__,1,avgcnt_,1
        arry_search,'vcaset_',avgset_(fghij__,1)
        !
        *if,fghij__,eq,1,then
            thits_=hits
        *else
            thits_=thits_+hits
        *endif
        !
        *if,thits_,ge,1,then
            *exit
        *endif
    *enddo
    !
    *if,thits_,eq,0,then
        vdele,vgset_(abcde__,1),,,1
    *endif
    !
    *set,avgset_(1)
    *set,thits_
*enddo
!
cmsel,s,vgvols_
cmsel,u,modvset_
cm,vnew_,volu
*get,vnewcnt_,volu,0,count
init_entity_num,1
!
*if,volntyp_,eq,3,then
    *if,vncmtyp_,eq,0,then
        cmsel,s,vnew_
        cm,volnam_,volu
    *else
        *if,vnewcnt_,eq,vnamcnt_,then
            cmsel,s,vnew_
            cm,volnam_,volu
        *else
            cmsel,s,volnam_
            cmsel,a,vnew_
            cm,volnam_,volu
        *endif
    *endif
*elseif,volntyp_,eq,0,then
    *if,vnewcnt_,eq,vscacnt_,then
        cmsel,s,vnew_
        cm,volsca_,volu
    *else
        cmsel,s,volsca_
        cmsel,a,vnew_
        cm,volsca_,volu
    *endif
*endif
!
init_entity_num,1
!
*if,argtyp1_,eq,0,then
    cmdele,vsetwa_
*endif
!
*if,argtyp2_,eq,0,then
    cmdele,vsetca_
*endif
!
vplot
!
csys,actvcs_
!
cmdele,vgvols_
cmdele,vgset_
cmdele,vnew_
!
*set,volswa_,
*set,volsca_,
*set,argtyp1_,
*set,argtyp2_,
*set,activcs_,
*set,actvcs_,
*set,actvtyp_,
*set,vgset_(1),
*set,vcaset_(1),
*set,avgcnt_,
*set,vgcnt_,
*set,ecount,
*set,abcde__,
*set,fghij__,
*set,hits,
*set,thits,
*set,hit(1),
*set,volnam_,
*set,vscacnt_,
*set,vnamcnt_,
*set,volntyp_,
*set,vnewcnt_,
*set,vncmtyp_,
!
*if,prkey_,eq,1,then
    /go
*endif