H.1.1 Initialize_Monomial Procedure

The main documentation of the Initialize_Monomial Procedure contains additional explanation of this code listing.

  subroutine Initialize_Monomial (Monomial, Coefficient, Exponent, Phi_k_MV, &
                                  Locus, Mesh, Name, Derivative, Delta_t, &
                                  Phi_n_MV, Variable, Equation, NEquations, &
                                  status)

    ! Use associations.

    use Caesar_Flags_Module,   only: initialized_flag
    use Caesar_Numbers_Module, only: one

    ! Input variables.

    type(real), intent(in) :: Exponent                ! Monomial degree.
    type(real,1) :: Coefficient                       ! Monomial coefficient.
    type(character,*), intent(in) :: Locus            ! Evaluation locus.
    type(Multi_Mesh_type), target :: Mesh             ! Monomial Mesh.
    ! Previous iterate value of the independent variable.
    type(Mathematic_Vector_type), intent(inout) :: Phi_k_MV
    ! Past time step value of the independent variable.
    type(Mathematic_Vector_type), intent(inout), optional :: Phi_n_MV
    type(character,*), intent(in), optional :: Name   ! Monomial name.
    type(logical), intent(in), optional :: Derivative ! Time derivative toggle.
    type(real), intent(in), optional :: Delta_t       ! Time step size.
    type(integer), intent(in), optional :: Variable   ! Variable number.
    type(integer), intent(in), optional :: Equation   ! Equation number.
    type(integer), intent(in), optional :: NEquations ! Number of equations.

    ! Output variables.

    type(Monomial_type), intent(out) :: Monomial ! Monomial to be initialized.
    type(Status_type), intent(out), optional :: status  ! Exit status.

    ! Internal variables.

    type(Status_type), dimension(3) :: allocate_status  ! Allocation Status.
    type(Status_type) :: consolidated_status            ! Consolidated Status.

    !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    ! Verify requirements.

    VERIFY(.not.Valid_State(Monomial),5)  ! Monomial is not valid.
    VERIFY(Valid_State(Coefficient),5)    ! Coefficient is valid.
    VERIFY(Valid_State(Exponent),5)       ! Exponent is valid.

    ! Set up pointers.

    Monomial%Mesh => Mesh
    select case (Locus)
    case ("Cells")
      Monomial%Structure => Cell_Structure(Mesh)
    case ("Nodes")
      Monomial%Structure => Node_Structure(Mesh)
    case ("Faces")
      Monomial%Structure => Face_Structure(Mesh)
    end select

    ! Set time derivative toggle.

    if (PRESENT(Derivative)) then 
      Monomial%Derivative = Derivative
    else
      Monomial%Derivative = .false.
    end if

    ! Three more requirements: Coefficient, Phi_k_MV and Phi_n_MV are the 
    ! right size.

    VERIFY(SIZE(Coefficient)==Length_PE(Monomial%Structure),5) 
    VERIFY(Length_PE(Phi_k_MV)==Length_PE(Monomial%Structure),5)
    if (PRESENT(Phi_n_MV)) then 
      VERIFY(Length_PE(Phi_n_MV)==Length_PE(Monomial%Structure),5) 
    end if

    ! Allocations and initializations.

    call Initialize (allocate_status)
    call Initialize (consolidated_status)
    call Initialize (Monomial%Exponent, allocate_status(1))
    call Initialize (Monomial%Coefficient, Length_PE(Monomial%Structure), &
                     allocate_status(2))
    call Initialize (Monomial%Phi_k, Length_PE(Monomial%Structure), &
                     allocate_status(3))
    if (Monomial%Derivative) then 
      call Initialize (Monomial%Phi_n, Length_PE(Monomial%Structure), &
                       allocate_status(3))
    end if

    ! Set up internals.

    if (PRESENT(Name)) Monomial%Name = Name
    Monomial%Coefficient = Coefficient
    Monomial%Exponent    = Exponent
    Monomial%Locus       = Locus
    Monomial%Phi_k       = Phi_k_MV
    if (Monomial%Derivative) then 
      if (PRESENT(Phi_n_MV)) then 
        Monomial%Phi_n   = Phi_n_MV
      else
        Monomial%Phi_n   = Phi_k_MV
      end if
    end if
    if (PRESENT(Delta_t)) then 
      Monomial%Delta_t = Delta_t
    else
      Monomial%Delta_t = one
    end if
    if (PRESENT(Equation)) then
      Monomial%Equation = Equation
    else
      Monomial%Equation = 1
    end if
    if (PRESENT(Variable)) then
      Monomial%Variable = Variable
    else
      ! If not specified, use the variable for this equation.
      Monomial%Variable = Monomial%Equation
    end if
    if (PRESENT(NEquations)) then
      Monomial%NEquations = NEquations
    else
      Monomial%NEquations = 1
    end if

    ! Process status variables.

    consolidated_status = allocate_status
    if (PRESENT(status)) then
      WARN_IF(Error(consolidated_status), 5)
      status = consolidated_status
    else
      VERIFY(Normal(consolidated_status), 5)
    end if
    call Finalize (consolidated_status)
    call Finalize (allocate_status)

    ! Set initialization flag.

    Monomial%Initialized = initialized_flag

    ! Verify guarantees.

    VERIFY(Valid_State(Monomial),5)  ! Monomial is now valid.

    return
  end subroutine Initialize_Monomial



Michael L. Hall