!   TITLE:  rotate_volm_msh.mac (MESH)
!
!
!           Created provision for using ROTASET array for multiple area
!           materials.
!
!   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
i9_=arg9
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
!
*get,ptyp_,parm,i9_,type
!
*if,ptyp_,eq,0,then
    entity_array,'a','rotaset_','array'     ! create array of selected areas
    alimit_=ecount
*else
    *get,ptyp2_,parm,rotaset,type       ! determine whether ROTASET exists
    *get,alimit_,parm,rotaset,dim,x     ! # of areas (rows) in material array
    alimit_=alimit_-1
    *get,matpos_,parm,rotaset,dim,y     ! # of columns in material array
*endif
!
*do,abc_,1,alimit_,1                    ! iterate through area array
    *do,xyz_,1,3600,1                   ! iterate through all volumes ( < 3600 )
        csys,acs_
        !
        *if,ptyp_,eq,0,then
            *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
        *else
            *if,i9_,eq,'array',then
                *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
            *else
                *exit
            *endif
        *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,ptyp_,eq,0,then
            v_=v2bmsh_
            !
            *if,xyz_,eq,1,then
                msh_algorithm,1,3,a1_,b2_,c3_,,e5_,f6_,g7_,h8_,i9_,j0_,k1_,v_,n4_,o5_,p6_
            *else
                msh_algorithm,0,2,a1_,b2_,c3_,,e5_,f6_,g7_,h8_,i9_,j0_,k1_,v_,n4_,o5_,p6_
            *endif
        *else
            mata_=rotaset(abc_,matpos_)
            !
            *if,xyz_,eq,1,then
                msh_algorithm,1,3,a1_,b2_,c3_,,e5_,f6_,g7_,h8_,mata_,j0_,k1_,v2bmsh_,n4_,o5_,p6_
            *else
                msh_algorithm,0,2,a1_,b2_,c3_,,e5_,f6_,g7_,h8_,mata_,j0_,k1_,v2bmsh_,n4_,o5_,p6_
            *endif
        *endif
        !
        *get,vfintyp_,parm,vfinal_,type
        !
        *if,vfintyp_,ne,-1,then
            *if,v2bmsh_,eq,vfinal_,then
                *exit
            *endif
        *endif
    *enddo
    !
    *if,ptyp_,ne,0,then
        *if,i9_,ne,'array',then
            *exit
        *endif
    *endif
*enddo
!
init_entity_num
!
allsel,all
!
csys,actcs_
!
lplot
!
!
*if,ptyp_,eq,0,then
    *set,rotaset_(1),
*else
    *if,ptyp2_,ne,-1,then
        *set,rotaset(1),
        *set,amatmax_,
    *endif
*endif
!
*set,actcs_,
*set,acstyp_,
*set,acs_,
*set,aloc_,
*set,aloctr_,
*set,acx_,
*set,acy_,
*set,acz_,
*set,mata_,
*set,v_,
*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,ptyp_,
*set,ptyp2_,
*set,alimit_,
*set,matpos_,
*set,v2bmsh_,
*set,vfintyp_,
*set,vfinal_,
cmdele,vset1
!
*if,prkey_,eq,1,then
    /go
*endif