!*************************************************************************************!
! TITLE: CFVR4705 - CALTRANS: Seismic Analysis Y-axis
! SUBTITLE: Seismic Analysis on a 1 DOF beam according to CALTRANS. (soil profile type D, structure within 10 miles of an active fault)
!
! DESCRIPTION: This example compares spectrum accelerations given by CivilFEM to accelerations
! DESCRIPTION: obtained when solving on a 1 DOF beam and to the correct CALTRANS spectum accelerations.
! DESCRIPTION:
! DESCRIPTION: The model is 1 element beam with only 1 DOF, which direction the CivilFEM spectrum
! DESCRIPTION: is set (the rest of the DOF are constrained). A different mass is applied at the
! DESCRIPTION: free end of the beam for the beam period to be equal to the 20 CivilFEM spectrum points.
! DESCRIPTION: After solving, the mass acceleration is obtained and compared to the CivilFEM spectrum
! DESCRIPTION: acceleration and to the correct value. Therefore, this example checks the following results:
! DESCRIPTION:
! DESCRIPTION: - CivilFEM spectrum is defined correctly by comparing to the correct value
! DESCRIPTION:
! DESCRIPTION: - CivilFEM spectrum is applied correctly and response acceleration is equal to spectrum acceleration
!
! ELEMENT TYPE: BEAM4, MASS21
! MODULES:
! UNITS: User
! KEYWORD1: Seismic
! KEYWORD2: CALTRANS
!
!*************************************************************************************!

   FINISH
  ~CFCLEAR,,1
  NomFile='CFVR4705'
  /TITLE, %NomFile%, CALTRANS: Seismic Analysis Y-axis

! ----------------------------------------------------------------------
! Model definition
! ----------------------------------------------------------------------
! CivilFEM Setup: Code & Units
~UNITS,,LENG,CM
~UNITS,,TIME,S
~UNITS,,FORC,KP
~CODESEL,,,,,CALTRANS
/PREP7
! Preprocessor
! ----------------------------------------------------------------------
! Materials: A-42
 ~CFMP,1,LIB,STEEL,EA,A42
! Modify density (Rho = 0)
 ~CFMP,1,USER
 ~CFMP,1,DatGen,RHO,,0
! Element Types
  ET,1,BEAM4   ! Type 1: 3D Beam
  ET,2,MASS21  ! Type 2: Mass
! Sections
 ~SSECLIB,1,1,1,1   !IPE 80
 ~BMSHPRO,1,BEAM,1,1,,,4,,0,,

! Nodes
  L = 10	         ! L    : Bar length
  N, 1
  N,10,L

! Elements
  TYPE,1
  MAT ,1
  REAL,1
  EN,1,1,10
  EPLOT

! Parameters
  *GET,AR20,EX,1         		         ! Ex   : Elastic Modulus
  ~CFGET,AR22,SECTION,1,MECHPROP,A,,2    ! Area : Bar area
  ~CFGET,AR23,SECTION,1,MECHPROP,IZZ,,2  ! Izz  : Moment of inertia
  ~CFGET,AR24,SECTION,1,MECHPROP,IYY,,2  ! Iyy  : Moment of inertia
  pi=3.141592654

! Seismic Spectrum
  ~DEFSPEC,ALL,0.3,E1,1,10,0.5

! ----------------------------------------------------------------------
! DATA CHECK
! ----------------------------------------------------------------------
! Data comparision number
  NComp = 40
  NComp_ch = 0

! Marix 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

*DO,ARG1,1,20,1
   /PREP7
   ~CFGET,AR26,SEISM,,SPEC,TV,,ARG1,1   ! Period
  ! Labels
   LABEL(ARG1,1) = 'Sa(%ARG1%)y'
   LABEL(20+ARG1,1) = 'Sa(%ARG1%)y'

   AR25=12*AR20*AR23/L**3     	! Bending stiffness around Z axis
   AR27=AR25*(AR26/(2*pi))**2  	! Mass applied at end
   R,2,0,AR27
   TYPE,2
   MAT, 1
   REAL,2
   EN,2,10
   FINISH
   /SOLU

 ! Solution
 ! ---------------------------------------------------------------------
 ! Displacements
   D,1,,,,,,ALL
   D,10,,,,,UX, ,UZ,ROTX,ROTY,ROTZ
   ~MODLSOL,1
   ~CMBMOD,NONE,VERTICAL,NONE,0,0.0001
 ! Query results
   *GET,ARG5,NODE,10,U,Y
 ! Correct values
   VALUE(20-ARG1+1,1)=ARG5*AR25/AR27 			 ! Aceleration
 ! Obtained values
   ~CFGET,VALUE(20-ARG1+1,2),SEISM,,SPEC,SDV,,ARG1,1	 ! Y components of linear horizontal spectrum
   ~CFGET,VALUE(40-ARG1+1,2),SEISM,,SPEC,SDV,,ARG1,1	 ! Y components of linear horizontal spectrum
   ! CivilFEM gives the spectrum Normalized by gravity.
   ! To compare it must be changed to acceleration user units.
   VALUE(20-ARG1+1,2) = VALUE(20-ARG1+1,2)*981
   VALUE(40-ARG1+1,2) = VALUE(40-ARG1+1,2)*981

   /PREP7
   EDELE,2
*ENDDO

! Correct values
! ----------------------------------------------------------------------
   VALUE(40,1)=  44.2627
   VALUE(39,1)=  72.0446
   VALUE(38,1)= 132.7882
   VALUE(37,1)= 199.1822
   VALUE(36,1)= 326.7907
   VALUE(35,1)= 365.5991
   VALUE(34,1)= 369.2484
   VALUE(33,1)= 378.2736
   VALUE(32,1)= 369.8070
   VALUE(31,1)= 356.0032
   VALUE(30,1)= 320.2525
   VALUE(29,1)= 291.4225
   VALUE(28,1)= 271.0009
   VALUE(27,1)= 238.0776
   VALUE(26,1)= 214.1693
   VALUE(25,1)= 181.2322
   VALUE(24,1)= 143.2260
   VALUE(23,1)= 143.2260
   VALUE(22,1)= 143.2260
   VALUE(21,1)= 143.2260

! Warning and error tolerances
! ----------------------------------------------------------------------
   *DO,II,1,NComp
     TOLER(II, 1)= 0.1 $ TOLER(II, 2)= 0.1
   *ENDDO

! ----------------------------------------------------------------------
! Results Comparison
! ----------------------------------------------------------------------
  COMPARA.MAC
