## G.3.8 Solver Class Unit Test Program

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

```program Unit_Test

use Caesar_Data_Structures_Module
use Caesar_Mathematic_Vector_Class
use Caesar_ELL_Matrix_Class
use Caesar_Solver_Class
implicit none

type(Communication_type) :: Comm
type(Base_Structure_type) :: Row_Structure, Column_Structure
type(Status_type) :: status
type(character,name_length) :: MV_Name
type(integer) :: NRows
type(ELL_Matrix_type) :: A_ELLM
type(Mathematic_Vector_type) :: X_MV, B_MV, Residual_MV, Solution_MV
type(Solver_type) :: Solver

! Initializations.

call Initialize (Comm)
call Output (Comm)
call Initialize (status)
call Initialize (Solver, 'LAMG')

! Check state of the Solver.

VERIFY(Valid_State(Solver),0)

! Read in a linear system (this initializes and sets A_ELLM,
!                          B_MV, X_MV, Row_Structure and
!                          Column_Structure).

if (this_is_IO_PE) then
open (unit=8, &
File='source/class/linear_algebra/battery/Augustus_Prob0_MH_K2_8x8x8.hb')
end if
call Read_Harwell_Boeing (A_ELLM, RHS_MV=B_MV, Solution_MV=X_MV, &
Row_Structure=Row_Structure, &
Column_Structure=Column_Structure, Unit=8, &
status=status)
NRows = NRows_Total(A_ELLM)
call Output (A_ELLM, MAX(1, NRows/10), MIN(NRows, NRows/10+50))
call Output (X_MV, MAX(1, NRows/10), MIN(NRows, NRows/10+50))
call Output (B_MV, MAX(1, NRows/10), MIN(NRows, NRows/10+50))

! Initializations.

MV_Name = 'Calculated Solution'
call Initialize (Solution_MV, Column_Structure, MV_Name)
MV_Name = 'Calculated Residual'
call Initialize (Residual_MV, Row_Structure, MV_Name)

! Solve the system.

call Solve (Solver, A_ELLM, Solution_MV, B_MV)
call Output (Solution_MV, MAX(1, NRows/10), MIN(NRows, NRows/10+50))

! Calculate residual.

call Residual (Residual_MV, A_ELLM, Solution_MV, B_MV)
call Output (Residual_MV, MAX(1, NRows/10), MIN(NRows, NRows/10+50))

! Check state of the Solver.

VERIFY(Valid_State(Solver),0)

! Finalize objects and communications.

call Finalize (Solver)
call Finalize (A_ELLM)
call Finalize (X_MV)
call Finalize (B_MV)
call Finalize (Row_Structure)
call Finalize (Column_Structure)
call Finalize (Solution_MV)
call Finalize (Residual_MV)
call Finalize (Comm)

end
```

Michael L. Hall