!*************************************************************************************!
! TITLE: CFVR1709 - Eurocode 8-2004: Horizontal type 2 elastic spectrum
! SUBTITLE: Seismic Analysis on a 1 DOF beam according to Eurocode 8
!
! DESCRIPTION: This example compares spectrum accelerations given by CivilFEM to accelerations
! DESCRIPTION: obtained when solving on a 1 DOF beam and to the correct Eurocode spectrum
! DESCRIPTION: accelerations.
! DESCRIPTION:
! DESCRIPTION: The model is a single beam element with only one degree of freedom: horizontal
! DESCRIPTION: displacement at one of its ends.
! DESCRIPTION: The beam has no mass. A punctual mass is applied at the free end of the beam.
! DESCRIPTION:
! DESCRIPTION: 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
! DESCRIPTION:   to spectrum acceleration.
! DESCRIPTION:
! DESCRIPTION: The spectrum is defined with the following parameters:
! DESCRIPTION:
! DESCRIPTION: - Horizontal
! DESCRIPTION:
! DESCRIPTION: - Elastic
! DESCRIPTION:
! DESCRIPTION: - Type 2
! DESCRIPTION:
! DESCRIPTION: - Soil type C
! DESCRIPTION:
! DESCRIPTION: - 7% Damping
! DESCRIPTION:
! DESCRIPTION: - Base acceleration of 1.2753 cm/s<sup>2</sup>
!
! ELEMENT TYPE: BEAM4, MASS21
! MODULES:
! UNITS: User
! KEYWORD1: Seismic
! KEYWORD2: Eurocode 8
!
!*************************************************************************************!
   FINISH
  ~CFCLEAR,,1
  NomFile='CFVR1709'
  /TITLE, %NomFile%, Eurocode 8-2004: Horizontal type 2 elastic spectrum

! ----------------------------------------------------------------------
! Model definition
! ----------------------------------------------------------------------
! Setup: Code & Units
~UNITS,,LENG,CM
~UNITS,,TIME,S
~UNITS,,FORC,KP
~CODESEL,EC3-92,EC2-91,,,EC8-04
/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,EXX,EX,1         		               ! Ex   : Elastic Modulus
  ~CFGET,IZZ,SECTION,1,MECHPROP,IZZ,,2   ! Izz  : Moment of inertia
  ~CFGET,IYY,SECTION,1,MECHPROP,IYY,,2   ! Iyy  : Moment of inertia

! Seismic Spectrum
  ~DEFSPEC,ALL,1.2753,C,ELASTIC,2,1,1,7

  pi=3.141592654

! ----------------------------------------------------------------------
! DATA CHECK
! ----------------------------------------------------------------------
! Data comparison 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,II,1,20
   /PREP7
   ~CFGET,Per,SEISM,,SPEC,TH,,II,2       ! Period
		 ! Labels
			LABEL(   II,1) = 'Sa(%II%)y'
			LABEL(20+II,1) = 'Sa(%II%)y'
			K=12*EXX*IZZ/L**3        ! Bending stiffness around Z axis
			Mass=K*(Per/(2*pi))**2   ! Mass applied at end
			R,2,0,Mass,0
   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,HORIZONT,NONE,0,0.0001,
 ! Query results
   *GET,DispY,NODE,10,U,Y
 ! Correct values
   VALUE(20-II+1,1)=DispY*K/Mass ! Acceleration
 ! Obtained values
   ~CFGET,VALUE(20-II+1,2),SEISM,,SPEC,SDH,,II,2	 ! Y components of spectrum
   ~CFGET,VALUE(40-II+1,2),SEISM,,SPEC,SDH,,II,2	 ! Y components of spectrum
   ! CivilFEM gives the spectrum Normalized by gravity.
   ! To compare it must be changed to acceleration user units.
   VALUE(20-II+1,2) = VALUE(20-II+1,2)*981
   VALUE(40-II+1,2) = VALUE(40-II+1,2)*981
   /PREP7
   EDELE,2
*ENDDO

! Correct values
! ----------------------------------------------------------------------
   VALUE(21,1) = 2.2633  ! T=0.014s
   VALUE(22,1) = 2.6137
   VALUE(23,1) = 2.9641
   VALUE(24,1) = 3.3145
   VALUE(25,1) = 3.6649
   VALUE(26,1) = 4.0153
   VALUE(27,1) = 4.3657  ! TB=0.1s
   VALUE(28,1) = 4.3657  ! TC=0.25s
   VALUE(29,1) = 2.6729
   VALUE(30,1) = 1.9260
   VALUE(31,1) = 1.5054
   VALUE(32,1) = 1.2356
   VALUE(33,1) = 1.0478
   VALUE(34,1) = 0.9095  ! TD=1.2s
   VALUE(35,1) = 0.1842
   VALUE(36,1) = 0.0767
   VALUE(37,1) = 0.0418
   VALUE(38,1) = 0.0262
   VALUE(39,1) = 0.0180
   VALUE(40,1) = 0.0131  ! T=10s

! Warning and error tolerances
! ----------------------------------------------------------------------
  *DO,II,1,NComp
    TOLER(II, 1)= 1E-03 $ TOLER(II, 2)= 1E-03
  *ENDDO

! ----------------------------------------------------------------------
! Results Comparison
! ----------------------------------------------------------------------
  COMPARA.MAC
