!   TITLE:  rotate_volm_msh.mac (MESH)
!
!
!   OBJECTIVE:
!
!   This sub-macro takes a set of rotated volumes, of any arc length, and
!   volume meshes them.
!
!
!   COMMAND SYNTAX:
!
!
!                         (1)     (2)     (3)      (4)     (5)   (6)    (7)
!       ROTATE_VOLM_MSH, actcs,  mstyp, mshdens, elmszovr, etpa, etpv, elmnl,
!
!                        elmxl, mtrl,  rl,  ecs,  radrot, varcang, ell
!                         (8)   (9)   (10)  (11)   (12)    (13)    (14)
!
!
!   ARGUMENTS:
!
!           (1) actcs = active coordinate system (need not be cylindrical) whose
!                       Z axis the volumes are rotated about.
!
!           (9) mtrl = material properties # to be used in meshing operations.
!
!                      If multiple areas/materials are desired, then the macro
!                      command CREATE_ROTASET should be executed prior to use
!                      of this macro, and this argument should be specified:
!
!                       mtrl = 'array'
!
!
!   The remaining arguments are the arguments used in MSH_ALGORITHM.  See
!   MSH_ALGORITHM for a description of arguments 2-14.  Note that PERFLSZ,
!   PERFMSH, ATARGOV, and VOLSEL (in MSH_ALGORITHM) have pre-determined
!   values and are not at the discretion of the user.
!
!
!   DESCRIPTION:
!
!   The algorithm meshes a user selected set of areas as located relative to
!   the Z axis of a user specified C.S., ACTCS.  The Z axis of this C.S. is
!   located at the axis of rotation of the rotated volumes with the Z axis
!   oriented parallel to the axis of rotation. It then sweeps all the rotated
!   volumes in line with these areas, however many volumes and arc angles that
!   they occupy.
!
!   This macro is an extension of the MSH_ALGORITHM , enhancing the user meshing
!   capabilities to the special case of revolved volumes, thereby automating the
!   meshing process for volumes of revolution.  A cylindrical coordinate system
!   oriented as described in the above paragraph is all that is necessary for
!   successful execution.
!
!
!
*get,prkey_,active,0,prkey
/nopr
!
actcs_=arg1
a1_=arg2
b2_=arg3
c3_=arg4
e5_=arg5
f6_=arg6
g7_=arg7
h8_=arg8
!
*if,attrmat_,eq,0,then
    i9_=arg9
*else
    *if,arg9,eq,0,then
        i9_=attrmat_
    *else
        i9_=arg9
    *endif
*endif
!
j0_=ar10
k1_=ar11
n4_=ar12
o5_=ar13
p6_=ar14
!
!
csys,actcs_                             ! active CS
!
*get,acs_,active,,csys                  ! axis coordinate system (CS)
*get,acstyp_,cdsy,acs_,attr,kcs         ! axis CS type
!
*if,acstyp_,ne,1,then                   ! If axis CS is not cylindrical, then
    create_cs,0,'acs_',1,0,0,0,0,0,0    ! create cylindrical CS at same location.
*endif
!
entity_array,'a','rotaset_','array'     ! create array of selected areas
alimit_=ecount
!
*do,abc_,1,alimit_,1                    ! iterate through area array
    *do,xyz_,1,3600,1                   ! iterate through all volumes ( < 3600 )
        csys,acs_
        !
        *if,xyz_,eq,1,then              ! If volume iteration = 1 then
            asel,s,area,,rotaset_(abc_,1)   ! select area from array
        *else                           ! If volume iteration ~= 1 then
            asel,s,area,,atarg          ! select target area from previous mesh
        *endif
        !
        csys,0                          ! initialize global cartesian system
        asum                            ! retrieve area summary info
        *get,acx_,area,,cent,x          ! retrieve x,y,z coordinates of centroid
        *get,acy_,area,,cent,y
        *get,acz_,area,,cent,z
        k,,acx_,acy_,acz_               ! create KP @ centroid location
        aloctr_=km+1                    ! store KP# in parameter
        csys,acs_                       ! initialize axial CS
        aloc_=ky(aloctr_)               ! angular position with respect to ACS_
        kdele,aloctr_                   ! delete locator KP
        !
        vsla,s                          ! select volume(s) attached to area
        *get,vcnt_,volu,,count          ! count # of volumes attached to area
        !
        *if,xyz_,eq,1,then              ! If volume iteration = 1 then
            *if,vcnt_,gt,1,then             ! If volume count > 1 then
                cm,vset1,volu                   ! store volumes in component group
                vsel,u,loc,y,aloc_,aloc_+180    ! reselect volume in -y direction
                get_max_entity
                vfinal_=vm                      ! store last volume to mesh
                cmsel,s,vset1                   ! select component group
                vsel,r,loc,y,aloc_,aloc_+180    ! reselect volume in +y direction
                get_max_entity
                v2bmsh_=vm                      ! volume to be meshed
            *else                           ! If volume count ~> 1 then
                get_max_entity
                v2bmsh_=vm                  ! volume to be meshed
            *endif
            !
            v1st_=v2bmsh_                   ! assign the 1st volume to be meshed
        *else
            *if,vcnt_,gt,1,then             ! If volume count > 1 then
                cm,vset1,volu                   ! store volumes in component group
                vsel,r,loc,y,aloc_,aloc_+180    ! reselect volume in +y direction
                get_max_entity
                v2bmsh_=vm                      ! volume to be meshed
            *else                           ! If volume count ~> 1 then
                *exit
            *endif
        *endif
        !
        *if,xyz_,eq,1,then
            msh_algorithm,1,3,a1_,b2_,c3_,,e5_,f6_,g7_,h8_,i9_,j0_,k1_,v2bmsh_,n4_,o5_,p6_
        *else
            msh_algorithm,0,2,a1_,b2_,c3_,,e5_,f6_,g7_,h8_,i9_,j0_,k1_,v2bmsh_,n4_,o5_,p6_
        *endif
        !
        *get,vfintyp_,parm,vfinal_,type
        !
        *if,vfintyp_,ne,-1,then
            *if,v2bmsh_,eq,vfinal_,then
                *exit
            *endif
        *endif
    *enddo
*enddo
!
init_entity_num
!
allsel,all
!
csys,actcs_
!
lplot
!
!
*set,actcs_,
*set,acstyp_,
*set,acs_,
*set,aloc_,
*set,aloctr_,
*set,acx_,
*set,acy_,
*set,acz_,
*set,mata_,
*set,a1_,
*set,b2_,
*set,c3_,
*set,e5_,
*set,f6_,
*set,g7_,
*set,h8_,
*set,i9_,
*set,j0_,
*set,k1_,
*set,n4_,
*set,o5_,
*set,p6_,
*set,abc_,
*set,xyz_,
*set,alimit_,
*set,v2bmsh_,
*set,vfintyp_,
*set,vfinal_,
cmdele,vset1
!
*if,prkey_,eq,1,then
    /go
*endif