H.1.8 Monomial Class Unit Test Program

This lightly commented program performs a unit test on the Monomial Class.

program Unit_Test

  use Caesar_Linear_Algebra_Module
  use Caesar_Multi_Mesh_Class
  use Caesar_Monomial_Class
  use Caesar_Numbers_Module, only: zero, one, two, three
  implicit none

  type(Communication_type) :: Comm
  type(Base_Structure_type) :: Row_Structure, Column_Structure
  type(Status_type) :: status
  type(real,1) :: Coefficient
  type(real) :: Delta_t, Exponent
  type(logical) :: Derivative
  type(integer) :: i, NDimensions, NRows, MaxNonzeros, &
                   NCells_X, NCells_Y, NCells_Z, &
                   Equation, NEquations, Variable
  type(real,1) :: Lengths
  type(ELL_Matrix_type) :: A_ELLM
  type(Mathematic_Vector_type) :: X_MV, B_MV, Phi_MV
  type(Multi_Mesh_type) :: Mesh
  type(Monomial_type) :: Constant_Term, Linear_Term, Quadratic_Term

  ! Initializations.

  call Initialize (Comm)
  call Output (Comm)
  call Initialize (status)
  MaxNonzeros = 3  ! Only need one, but why not test 3?

  ! Create a mesh.

  NCells_X = 14
  NCells_Y = 13
  NCells_Z = 12
  NDimensions = 3
  call Initialize (Lengths, NDimensions)
  Lengths = (/ 10.d0, 20.d0, 40.d0 /)
  call Initialize (Mesh, NDimensions, Lengths, NCells_X, NCells_Y, NCells_Z, &
                   'Uniform Mesh', status)
  Delta_t = zero
  Derivative = .false.
  Variable = 3
  Equation = 3
  NEquations = 3

  ! Initialize ELL Matrix and Mathematic Vectors.
 
  call Generate_Multiple (Row_Structure, NEquations, Cell_Structure(Mesh), &
                          'Rows')
  call Generate_Multiple (Column_Structure, NEquations, Cell_Structure(Mesh), &
                          'Columns')
  call Initialize (A_ELLM, MaxNonzeros, Row_Structure, Column_Structure, &
                   'Coefficients', status)
  call Initialize (X_MV, Column_Structure, 'Variables', status)
  call Initialize (B_MV, Row_Structure, 'Equations', status)
  NRows = Length_Total(Row_Structure)

  ! Initialize coefficent array and MV for past time step values (Phi).

  call Initialize (Coefficient, Length_PE(Cell_Structure(Mesh)))
  call Initialize (Phi_MV, Cell_Structure(Mesh), 'Phi')

  ! Set Phi_MV to two, using Coefficient as a temporary.

  Coefficient = two
  Phi_MV = Coefficient

  ! Initialize Constant Term.

  Exponent = zero
  Coefficient = (/ (three*i, i = First_Cell_PE(Mesh), &
                                 Last_Cell_PE(Mesh)) /)
  call Initialize (Constant_Term, Coefficient, Exponent, Phi_MV, 'Cells', &
                   Mesh, 'Source Term', Derivative, Delta_t, Phi_MV, &
                   Variable, Equation, NEquations, status)

  ! Initialize Linear Term.

  Exponent = one
  call Initialize (Linear_Term, Coefficient, Exponent, Phi_MV, 'Cells', &
                   Mesh, 'Removal Term', Derivative, Delta_t, Phi_MV, &
                   Variable, Equation, NEquations, status)

  ! Initialize Quadratic Term.

  Exponent = two
  call Initialize (Quadratic_Term, Coefficient, Exponent, Phi_MV, 'Cells', &
                   Mesh, 'Quadratic Term', Derivative, Delta_t, Phi_MV, &
                   Variable, Equation, NEquations, status)

  ! Output Terms.

  call Output ( Constant_Term, MAX(1, NRows/10), MIN(NRows, NRows/10+50))
  call Output (   Linear_Term, MAX(1, NRows/10), MIN(NRows, NRows/10+50))
  call Output (Quadratic_Term, MAX(1, NRows/10), MIN(NRows, NRows/10+50))

  ! Check state of Monomials.

  VERIFY(Valid_State( Constant_Term),0)
  VERIFY(Valid_State(   Linear_Term),0)
  VERIFY(Valid_State(Quadratic_Term),0)

  ! Add terms to the Matrix Equation and output.
  !
  ! Given that Phi=2 and Coefficient=3*i  (see above), then...
  !
  !                           A(i,i)                   B
  !
  !   General Monomial    C*E*Phi**(E-1)*Vol   C*(E-1)*Phi**E*Vol 
  !     
  !   Constant Term                                  -3*i*Vol
  !   Linear Term              3*i*Vol
  !   Quadratic Term          12*i*Vol               12*i*Vol
  !   ------------------------------------------------------------
  !   Sum of Terms            15*i*Vol                9*i*Vol

  call Add_to_Matrix_Equation ( Constant_Term, A_ELLM, B_MV)
  call Add_to_Matrix_Equation (   Linear_Term, A_ELLM, B_MV)
  call Add_to_Matrix_Equation (Quadratic_Term, A_ELLM, B_MV)
  call Output (A_ELLM, MAX(1, NRows/10), MIN(NRows, NRows/10+50))
  call Output (B_MV, MAX(1, NRows/10), MIN(NRows, NRows/10+50))

  ! Finalize Monomials, other objects and communications.

  call Finalize (Constant_Term)
  call Finalize (Linear_Term)
  call Finalize (Quadratic_Term)
  call Finalize (Phi_MV)
  call Finalize (Coefficient)
  call Finalize (B_MV)
  call Finalize (X_MV)
  call Finalize (A_ELLM)
  call Finalize (Mesh)
  call Finalize (Comm)

end



Michael L. Hall