!*************************************************************************************!
! TITLE: CFVR1716 - User defined spectrum
! SUBTITLE: User defined spectrum defined by points
!
! 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: - Spectrum is applied correctly and response acceleration is equal
! DESCRIPTION:   to spectrum acceleration.
! DESCRIPTION:
!
! ELEMENT TYPE: BEAM4, MASS21
! MODULES:
! UNITS: SI
! KEYWORD1: Seismic
! KEYWORD2: Eurocode 8
!
!*************************************************************************************!
   FINISH
  ~CFCLEAR,,1
  NomFile='CFVR1716'
  /TITLE, %NomFile%, User defined spectrum

! ----------------------------------------------------------------------
! Model definition
! ----------------------------------------------------------------------
! Setup: Code & Units
~UNITS,SI
~CODESEL,,,,,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 = 5			 ! 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
  NPoints = 18
  ~DEFSPEC,PERIH,0.02,0.04,0.06,0.09,0.11,0.13,0.15,0.50,0.75,1.00
  ~DEFSPEC,PERIH,1.25,1.50,1.75,2.00,3.33,4.67,6.00,7.33

  ~DEFSPEC,SAH,0.05,1.8583*9.81,2.1862*9.81,2.5142*9.81,2.8421*9.81,3.1700*9.81
  ~DEFSPEC,SAH,0.05,3.4980*9.81,3.8259*9.81,3.8259*9.81,2.5506*9.81,1.9130*9.81
  ~DEFSPEC,SAH,0.05,1.5304*9.81,1.2753*9.81,1.0931*9.81,0.9565*9.81,0.3443*9.81
  ~DEFSPEC,SAH,0.05,0.1757*9.81,0.1063*9.81,0.0711*9.81

  ~DEFSPEC,PERIV,0.007,0.01,0.02,0.03,0.036,0.046,0.05,0.15,0.46,0.77
  ~DEFSPEC,PERIV,1.08,1.38,1.69,2.00,3.33,4.67,6.00,7.33

  ~DEFSPEC,SAV,0.05,0.7379*9.81,0.9018*9.81,1.0658*9.81,1.2298*9.81,1.3937*9.81
  ~DEFSPEC,SAV,0.05,1.5577*9.81,1.7217*9.81,1.7217*9.81,0.8854*9.81,0.5960*9.81
  ~DEFSPEC,SAV,0.05,0.4491*9.81,0.3603*9.81,0.3009*9.81,0.2582*9.81,0.0413*9.81
  ~DEFSPEC,SAV,0.05,0.0161*9.81,0.0085*9.81,0.0053*9.81

  pi=3.141592654

! ----------------------------------------------------------------------
! DATA CHECK
! ----------------------------------------------------------------------
! Data comparison number
  NComp = NPoints*4
  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,NPoints
   /PREP7
   ~CFGET,Per,SEISM,,SPECT,TH,,1,II,1       ! Period
		 ! Labels
			LABEL(        II,1) = 'SaH(%II%)y'
			LABEL(NPoints+II,1) = 'SaH(%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(NPoints-II+1,1)=DispY*K/Mass ! Acceleration
 ! Obtained values
   ~CFGET,VALUE(  NPoints-II+1,2),SEISM,,SPECT,SDH,,1,II,1	 ! Y components of spectrum
   ~CFGET,VALUE(2*NPoints-II+1,2),SEISM,,SPECT,SDH,,1,II,1	 ! Y components of spectrum
   ! CivilFEM gives the spectrum Normalized by gravity, except if defined by points
   ! To compare it must be changed to acceleration user units.
   VALUE(NPoints-II+1,2) = VALUE(NPoints-II+1,2)*9.81
    /PREP7
   EDELE,2
*ENDDO

*DO,II,1,NPoints
   /PREP7
   ~CFGET,Per,SEISM,,SPECT,TV,,1,II,1       ! Period
		 ! Labels
			LABEL(2*NPoints+II,1) = 'SaV(%II%)y'
			LABEL(3*NPoints+II,1) = 'SaV(%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,VERTICAL,NONE,0,0.0001,
 ! Query results
   *GET,DispY,NODE,10,U,Y
 ! Correct values
   VALUE(3*NPoints-II+1,1)=DispY*K/Mass ! Acceleration
 ! Obtained values
   ~CFGET,VALUE(3*NPoints-II+1,2),SEISM,,SPECT,SDV,,1,II,1	 ! Y components of spectrum
   ~CFGET,VALUE(4*NPoints-II+1,2),SEISM,,SPECT,SDV,,1,II,1	 ! Y components of spectrum
   ! CivilFEM gives the spectrum Normalized by gravity.
   ! To compare it must be changed to acceleration user units.
   VALUE(3*NPoints-II+1,2) = VALUE(3*NPoints-II+1,2)*9.81
   /PREP7
   EDELE,2
*ENDDO

! Correct values
! ----------------------------------------------------------------------
   VALUE(NPoints+1,1) = 1.8583
   VALUE(NPoints+2,1) = 2.1862
   VALUE(NPoints+3,1) = 2.5142
   VALUE(NPoints+4,1) = 2.8421
   VALUE(NPoints+5,1) = 3.1700
   VALUE(NPoints+6,1) = 3.4980
   VALUE(NPoints+7,1) = 3.8259
   VALUE(NPoints+8,1) = 3.8259
   VALUE(NPoints+9,1) = 2.5506
   VALUE(NPoints+10,1) = 1.9130
   VALUE(NPoints+11,1) = 1.5304
   VALUE(NPoints+12,1) = 1.2753
   VALUE(NPoints+13,1) = 1.0931
   VALUE(NPoints+14,1) = 0.9565
   VALUE(NPoints+15,1) = 0.3443
   VALUE(NPoints+16,1) = 0.1757
   VALUE(NPoints+17,1) = 0.1063
   VALUE(NPoints+18,1) = 0.0711

   VALUE(3*NPoints+1,1) = 0.7379
   VALUE(3*NPoints+2,1) = 0.9018
   VALUE(3*NPoints+3,1) = 1.0658
   VALUE(3*NPoints+4,1) = 1.2298
   VALUE(3*NPoints+5,1) = 1.3937
   VALUE(3*NPoints+6,1) = 1.5577
   VALUE(3*NPoints+7,1) = 1.7217
   VALUE(3*NPoints+8,1) = 1.7217
   VALUE(3*NPoints+9,1) = 0.8854
   VALUE(3*NPoints+10,1) = 0.5960
   VALUE(3*NPoints+11,1) = 0.4491
   VALUE(3*NPoints+12,1) = 0.3603
   VALUE(3*NPoints+13,1) = 0.3009
   VALUE(3*NPoints+14,1) = 0.2582
   VALUE(3*NPoints+15,1) = 0.0413
   VALUE(3*NPoints+16,1) = 0.0161
   VALUE(3*NPoints+17,1) = 0.0085
   VALUE(3*NPoints+18,1) = 0.0053

! Warning and error tolerances
! ----------------------------------------------------------------------
  *DO,II,1,NComp
    TOLER(II, 1)= 1E-03 $ TOLER(II, 2)= 1E-03
  *ENDDO

! ----------------------------------------------------------------------
! Results Comparison
! ----------------------------------------------------------------------
  COMPARA.MAC
