G.3.2 Finalize_Solver Procedure

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

  subroutine Finalize_Solver (Solver, status)

    ! Use associations.

    use Caesar_Flags_Module, only: uninitialized_flag

    ! Input/Output variable.

    ! Solver to be finalized.
    type(Solver_type), intent(inout) :: Solver  

    ! Output variables.

    type(Status_type), intent(out), optional :: status  ! Exit status.

    ! Internal variables.

    type(Status_type), dimension(5) :: deallocate_status ! Deallocation Status.
    type(Status_type) :: consolidated_status             ! Consolidated Status.


    ! Verify requirements.

    VERIFY(Valid_State(Solver),7) ! Solver is valid.

    ! Unset initialization flag.

    Solver%Initialized = uninitialized_flag

    ! Deallocations and finalizations.

    ! Set deallocation status.

    call Initialize (deallocate_status)
    call Initialize (consolidated_status)

    ! Finalize internals.

    call Finalize (Solver%Epsilon,            deallocate_status(1))
    call Finalize (Solver%LAMG_levout,        deallocate_status(2))
    call Finalize (Solver%Maximum_Iterations, deallocate_status(3))
    call Finalize (Solver%Package,            deallocate_status(4))
    call Finalize (Solver%Stopping_Test,      deallocate_status(5))

    ! Process status variables.

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

    ! Verify guarantees.

    VERIFY(.not.Valid_State(Solver),7) ! Solver is not valid.

  end subroutine Finalize_Solver

Michael L. Hall