!*********************************************************************************************************************************************************!
!* Copyright (c) <2015> <Purdue University> All rights reserved.																					     *!
!*                                                                      																			     *!
!* Developed by:  Fang Jiang, Wenbin Yu                                                                                                                  *!
!*        <Prof. Yu’s Research Group>,                                                                                                                   *!
!*        <School of Aeronautics and Astronautics, Purdue University>                                                                                    *!
!*        <https://cdmhub.org/projects/ansysvabsgui2015>                                                                                                 *!
!*                                                                      																			     *!
!* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),    *!
!* to deal with the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,  *!
!* and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:            *!
!*                                                                      																			     *!
!* •Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimers.                        *!
!*                                                                      																			     *!
!* •Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimers in the documentation *!
!*  and/or other materials provided with the distribution.                                                                                               *!
!*                                                                      																			     *!
!* •Neither the names of < Prof. Yu’s Research Group, School of Aeronautics and Astronautics, Purdue University >,                                       *!
!*  nor the names of its contributors may be used to endorse or promote products derived from this Software without specific prior written permission.   *!
!*                                                                      																			     *!
!* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,   *!
!* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR     *!
!* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER     *!
!* DEALINGS WITH THE SOFTWARE. 																															 *!
!*********************************************************************************************************************************************************!
! /input,VABS_PreGen_7_elemno_layerid_theta1,mac

!#7
!============================================================
! element-layer-orientation block
!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
! If format_flag = 1
!~~~~~~~~~~~~~~~~~~~
! elem_no; layer_type; theta1
!------------------------------------------------------------
!Although the arrangement of elem no is not necessary to be consecutive, 
!every element starting from 1 to nelem should be present.
!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

isoflag = 1
*DO,i,0,matid_max,1
	*IF, exit_flat_MTID%i%, EQ, 1, THEN   
		*IF, orth_MTID%i%, NE, 0, THEN
			isoflag = 0
		*ENDIF
	*ENDIF
*ENDDO



!++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
! Layer ID array
!++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*IF, BSL_flag, EQ, 19870503, THEN           ! Heterogeneous section with multi-layer
!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*ABSET,'Calculating Element Layer ID', BAR
*DO,s,1,ORIL_NUM                            ! loop baseline number
 mm = (s/ORIL_NUM)*100
*ABCHECK,mm
	i = ORIL(s)                             ! "i" is the baseline number

	LD = LAMDIREC_BSL_%i%

	*DO,j,1,nlam_bsl_%i%_direc_%LD%         !loop layer numbers, "j" is the lamina number in the laminating order

		q = anum_BSL%i%(j)                  !get Area number from layer order
		ASEL,S,AREA,,q
		ESLA,S

		*GET, enumA%q%, ELEM, 0, COUNT
		!-----------------------------------------------------------	

		*Del, elistA%q%

		*Del, elayrA%q%

		*Del, etheta1A%q%

		*Del, eCENTx_A%q%

		*Del, eCENTy_A%q%

		*DIM, elistA%q%,   ARRAY, enumA%q%
		*DIM, elayrA%q%,   ARRAY, enumA%q%
		*DIM, etheta1A%q%, ARRAY, enumA%q%
		*DIM, eCENTx_A%q%, ARRAY, enumA%q%
		*DIM, eCENTy_A%q%, ARRAY, enumA%q%
		!----------------------------------------------------
		*VGET,	elistA%q%,	ELEM, , ELIST
		!----------------------------------------------------
		*DO,p,1,enumA%q%                                     ! "p" the looping element number in the 
			elayrA%q%(p) = alyr_BSL%i%(j)                    ! should all be the same value because elements are from the same area
			!------------------------------------------------
			eCENTx_A%q%(p) = CENTRX( elistA%q%(p) )
			eCENTy_A%q%(p) = CENTRY( elistA%q%(p) )
!			*GET, eCENTx_A%q%(p), ELEM, elistA%q%(p), CENT, X
!			*GET, eCENTy_A%q%(p), ELEM, elistA%q%(p), CENT, Y
			!------------------------------------------------
		*ENDDO
	*ENDDO
*ENDDO
*ABFINISH

!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*ELSEIF, BSL_flag, NE, 19870503       ! No baseline defined, should be "isotropic patched element"
!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

/INPUT, VABS_APDL_Generation/VABS_APDL_Patch_ELEM_info, mac

! ALLSEL,ALL
!*GET, nnode, NODE, 0, NUM, MAXD
!*GET, nelem, ELEM, 0, NUM, MAXD
!*DEL, elistISO
!*DEL, elayrISO
!*DIM, elistISO, ARRAY, nelem, 1, 1
!*DIM, elayrISO, ARRAY, nelem, 1, 1
!
!*VGET, elistISO, ELEM, , ELIST
!
!*ABSET,'Calculating Element Layer ID', BAR
!*DO,p,1,nelem 
! mm = (p/nelem)*100
!*ABCHECK,mm             
!	elayrISO(p) = LYRID1
!*ENDDO
!*ABFINISH

!~~~~~~~~~
	*ELSE
*ENDIF




!++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
!theta_1 array
!++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*IF, BSL_flag, EQ, 19870503, AND, isoflag, EQ, 0, THEN   ! mutlilayer (heterogeneous), multi-material
!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

	/INPUT, VABS_APDL_Generation/VABS_APDL_TILT, mac
	/INPUT, VABS_APDL_Generation/VABS_APDL_Patch_ELEM_info, mac

!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*ELSEIF, BSL_flag, EQ, 19870503, AND, isoflag, EQ, 1              ! mutlilayer (heterogeneous), single-material


*ABSET,'Calculating Element Theta_1', BAR
*DO,s,1,ORIL_NUM                         			! loop baseline number
 mm = (s/ORIL_NUM)*100
*ABCHECK,mm
	i=ORIL(s)                            			! "i" is the baseline number
	LD = LAMDIREC_BSL_%i%               			! "LD" is the baseline laminate direction

	*DO,j,1,nlam_bsl_%i%_direc_%LD%      			! Loop layer numbers, "j" is the lamina number in the laminating order

		q = anum_BSL%i%(j)               			! Get Area number from layer order

		*DO,p,1,enumA%q%                 			! "p" the looping element number in the 

			etheta1A%q%(p) = 0

		*ENDDO
	*ENDDO

*ENDDO
*ABFINISH

	/INPUT, VABS_APDL_Generation/VABS_APDL_Patch_ELEM_info, mac

!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*ELSEIF, BSL_flag, NE, 19870503, AND, isoflag, EQ, 1   ! isotropic patched section


!	 ALLSEL,ALL
!	*GET, nnode, NODE, 0, NUM, MAXD
!	*GET, nelem, ELEM, 0, NUM, MAXD
!	*DEL, etheta1ISO
!	*DIM, etheta1ISO, ARRAY, nelem, 1, 1
!	
!	*ABSET,'Calculating Element Theta_1', BAR
!	*DO,p,1,nelem 
!	 mm = (p/nelem)*100
!	*ABCHECK,mm             
!		etheta1ISO(p) = 0
!	*ENDDO
!	*ABFINISH


!~~~~~~
*ELSE
*ENDIF









!*abset,'This is a Status Bar',BOTH
!myparam = 0
!*do,i,1,20
!   j = 5*i
!   *abcheck,j
!   *if,_return,gt,0,then
!     myparam = 1
!   *endif
!   *if,myparam,gt,0,exit
!   /ang,,j
!   nplot,1
!   *if,_return,gt,0,then
!     myparam = 1
!   *endif
!   *if,myparam,gt,0,exit
!   nlist,all
!   *if,_return,gt,0,then
!     myparam = 1
!   *endif
!   *if,myparam,gt,0,exit
!*enddo
!*if,myparam,gt,0,then
!*msg,ui
!We are stopped.........
!*endif
!*abfinish
