!*************************************************************************************!
! TITLE: CFVR3705 - Initial stresses on 2D Model
! SUBTITLE: Initial stresses on a 2D Model with irregular mesh.
!
! DESCRIPTION: A 2D model with an irregular mesh is used to analyze 
! DESCRIPTION: the results obtained when applying
! DESCRIPTION: initial stresses and gravity.
! DESCRIPTION:
!
! ELEMENT TYPE: PLANE182
! MODULES: GETC
! UNITS: SI
! KEYWORD1: Geotechnics
!*************************************************************************************!
 FINISH
 ~CFCLEAR,,1
 ~CFACTIV,GETC,Y
 *AFUN,DEG

 NomFile='CFVR3705'
 /TITLE, %NomFile%, Initial stresses. 2D Model.
! -------------------------------------------------------------------------------------
! Initial data
! -------------------------------------------------------------------------------------
! Parameters
 teta=30.0
 length=70
 height=30
 g=9.81

! CivilFEM SETUP
 ~UNITS,SI
 ~CODESEL,EC3-92,EC2-91,,,EC8-94

 /PREP7
! 1. Element types
! --------------------------------------------------
ET,1,PLANE182,,,2  ! Plain strain

! 2. Materials
! --------------------------------------------------
~CFMP,1,LIB,SOIL,,GC
~CFMP,1,DatGen,GAM,,10500

! 3.Modeling
! --------------------------------------------------
wpro,teta 
CSWPLA,11,0,1,1, 
BLC5,,,length,height

! 4.Meshing
! -------------------------------------------------
R,1 
MSHAPE,1,2D 
MSHKEY,0
ESIZE,1
AMESH,ALL
NROTAT,ALL 
NSEL,S,LOC,X,-length/2
NSEL,A,LOC,X,length/2 
D,ALL,UX
ALLSEL     
NSEL,S,LOC,Y,-height/2 
D,ALL,ALL
ALLSEL 

! 4. Solution
! --------------------------------------------------
/SOLU
~TIS,cfvr3705,ist,-Y,1 
INISTATE,READ,cfvr3705,ist
ACEL,g*SIN(-teta),g*COS(-teta) 
NROPT,FULL
SOLVE

! 5. Delete created files.
! --------------------------------------------------
 /DELETE,cfvr3705,ist

! -------------------------------------------------------------------------------------
! DATA CHECK
! -------------------------------------------------------------------------------------
! Data comparison number
 Ts=4
 NComp= Ts*3
 NComp_ch = 0

! Matrix dim.
 *DIM,LABEL,CHAR,Ncomp,1
 *DIM,LABEL_CH,CHAR,Ncomp_ch,1
 *DIM,VALUE,,Ncomp,3
 *DIM,VALUE_CH,CHAR,Ncomp_ch,3
 *DIM,TOLER,,Ncomp,2

! Labels
! -------------------------------------------------------------------------------------
 LABEL( 1)  = 'SX_1'
 LABEL( 2)  = 'SY_1'
 LABEL( 3)  = 'SZ_1'
 LABEL( 4)  = 'SXY_1'
 LABEL( 5)  = 'SX_2'
 LABEL( 6)  = 'SY_2'
 LABEL( 7)  = 'SZ_2'
 LABEL( 8)  = 'SXY_2'
 LABEL( 9)  = 'SX_3'
 LABEL( 10)  = 'SY_3'
 LABEL( 11)  = 'SZ_3'
 LABEL( 12)  = 'SXY_3'

! Obtained data 
! --------------
*DIM,Ele1,ARRAY,Ts 
*DIM,Ele2,ARRAY,Ts 
*DIM,Ele3,ARRAY,Ts

! + -------------Stresses obtained by CFVR3705.TIS file ------------- + !
!          - Sx -           - Sy -           - Sz -           - Sxy -        
 Ele1(1)= -93675.7    ,    -131146.    ,    -74940.5    ,     32450.2       
 Ele2(1)= -153298.    ,    -214617.    ,    -122639.    ,     53104.0         
 Ele3(1)= -43578.7    ,    -61010.2    ,    -34863.0    ,     15096.1      
! + ----------------------------------------------------------------- + !
 
 cont1=1	$	cont2=1
 *DO,II,1,NComp
	VALUE( II,1) = Ele%cont1%(cont2)
	cont2=cont2+1
	*IF,cont2,EQ,Ts+1,THEN
		cont2=1
		cont1=cont1+1
	*ENDIF
*ENDDO
	 
! Correct data 
! -------------
*DIM,NumElem,ARRAY,3
NumElem(1)=163,2064,2133
*DIM,Si,CHAR,Ts
Si(1)='X','Y','Z','XY'
cont3=1 
*DO,II,1,3
	ESEL,S,ELEM,,NumElem(II)
	NSLE,S,1
	*GET,MyNode,NODE,,NUM,MAX
	*DO,JJ,1,Ts
		*GET,VALUE(cont3,2),NODE, MyNode,S,%Si(JJ)%
		cont3=cont3+1
	*ENDDO
*ENDDO

! Warning and error tolerances 

   TOLER(1,1)  = .5E3	$	TOLER(1,2)  = .5E3
   TOLER(2,1)  = .5E4	$	TOLER(2,2)  = .5E4
   TOLER(3,1)  = .5E3	$	TOLER(3,2)  = .5E3
   TOLER(4,1)  = .5E3	$	TOLER(4,2)  = .5E3   
   TOLER(5,1)  = .5E4	$	TOLER(5,2)  = .5E4
   TOLER(6,1)  = .5E4	$	TOLER(6,2)  = .5E4
   TOLER(7,1)  = .5E4	$	TOLER(7,2)  = .5E4
   TOLER(8,1)  = .5E3	$	TOLER(8,2)  = .5E3
   TOLER(9,1)  = .5E3	$	TOLER(9,2)  = .5E3   
   TOLER(10,1) = .5E3	$	TOLER(10,2) = .5E3
   TOLER(11,1) = .5E3	$	TOLER(11,2) = .5E3   
   TOLER(12,1) = .5E3	$	TOLER(12,2) = .5E3

! -------------------------------------------------------------------------------------
! Results comparison
! -------------------------------------------------------------------------------------
  COMPARA.MAC
