D.7.13 Overlapped_Vector Class Unit Test Program

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

program Unit_Test
  use Caesar_Intrinsics_Module
  use Caesar_Base_Structure_Class
  use Caesar_Data_Index_Class
  use Caesar_Assembled_Vector_Class
  use Caesar_Distributed_Vector_Class
  use Caesar_Overlapped_Vector_Class
  use Caesar_Communication_Class
  use Caesar_Numbers_Module, only: one, four
  implicit none

  type(Communication_type) :: Comm
  type(Base_Structure_type) :: Cell_Structure, Node_Structure
  type(integer,2) :: Nodes_of_Cells_Index_Values
  type(Data_Index_type) :: Nodes_of_Cells_Index
  type(Assembled_Vector_type) :: Coordinates_Nodes_AV
  type(Distributed_Vector_type) :: Coordinates_Nodes_DV, Results_Cells_DV
  type(Overlapped_Vector_type) :: Coordinates_Nodes_of_Cells_OV
  type(Status_type) :: status
  type(character,name_length) :: Name_Name
  type(real,2) :: Coordinates, Results_Cells_BNV
  type(real,3) :: Processed_Coordinates
  type(integer) :: NodeSize, Dimensionality, DimSize, &
                   Many_Axis_Length, n, NDimensions, Nodes_per_Cell, &
                   NNodes
  type(logical) :: detailed_output, Success

  ! Initializations.

  call Initialize (Comm)
  call Output (Comm)
  call Initialize (status)
  call Initialize (Name_Name)
  Dimensionality = 2
  NDimensions = 2
  detailed_output = NPEs <= 8

  ! Set up the Shell Partition Structures.
  
  call Initialize_Shell_Partition (NDimensions, Cell_Structure, &
                                   Node_Structure, Nodes_of_Cells_Index, &
                                   detailed_output)

  ! Initialize AV, DV and OV Coordinate vectors.

  Name_Name = 'Coordinates of Nodes'
  call Initialize (Coordinates_Nodes_AV, Node_Structure, Dimensionality, &
                   Name_Name, status, NDimensions)
  call Initialize (Coordinates_Nodes_DV, Node_Structure, Dimensionality, &
                   Name_Name, status, NDimensions)
  Name_Name = 'Coordinates of Nodes of Cells'
  call Initialize (Coordinates_Nodes_of_Cells_OV, Nodes_of_Cells_Index, &
                   Dimensionality, Name_Name, status, NDimensions)
  Name_Name = 'Results of Cells'
  call Initialize (Results_Cells_DV, Cell_Structure, Dimensionality, &
                   Name_Name, status, NDimensions)

  ! Set up Coordinates array on IO PE only.

  NNodes = Length_Total(Node_Structure)
  if (this_is_IO_PE) then
    DimSize = NDimensions
    NodeSize = NNodes
  else
    DimSize = 0
    NodeSize = 0
  end if
  call Initialize (Coordinates, DimSize, NodeSize)
  if (this_is_IO_PE) then
    Coordinates(1,:) = (/ ( changetype(real,(n)), n = 1,NNodes ) /)
    Coordinates(2,:) = (/ ( one, n = 1,NNodes ) /)
  end if

  Name_Name = ''

  ! Set up Processed Coordinates array on every processor.

  Nodes_per_Cell = 2**NDimensions
  Many_Axis_Length = Nodes_per_Cell
  call Initialize (Processed_Coordinates, NDimensions, &
                   Length_PE(Cell_Structure), Many_Axis_Length)

  ! Set up Results_Cells_BNV array on every processor.

  Nodes_per_Cell = 2**NDimensions
  call Initialize (Results_Cells_BNV, NDimensions, &
                   Length_PE(Cell_Structure))

  ! Version number check.

  Coordinates_Nodes_of_Cells_OV = 123
  Success = Version(Coordinates_Nodes_of_Cells_OV) == 123
  call Output_Test ('Version number', Success)

  ! Send Coordinates into Assembled Vector, then Distributed Vector, 
  ! then Overlapped Vector, and access the data.

  Coordinates_Nodes_AV = Coordinates
  Coordinates_Nodes_DV = Coordinates_Nodes_AV
  Coordinates_Nodes_of_Cells_OV = Coordinates_Nodes_DV
  Processed_Coordinates = Coordinates_Nodes_of_Cells_OV

  ! Re-construct the original Nodes_of_Cells index values for comparison.

  call Initialize (Nodes_of_Cells_Index_Values, &
                   SIZE(Nodes_of_Cells_Index%Index2,1), &
                   SIZE(Nodes_of_Cells_Index%Index2,2))
  Nodes_of_Cells_Index_Values = Nodes_of_Cells_Index

  ! Check to see if the Processed Coordinates are correct.

  Success = Global_ALL(INT(Processed_Coordinates(1,:,:)) == &
            Nodes_of_Cells_Index_Values(:,:))
  call Output_Test ('Index', Success)

  Success = Global_ALL(Processed_Coordinates(2,:,:) == one)
  call Output_Test ('One', Success)

  ! Combination tests:

  !   Average test.

  call Collect_and_Average (Results_Cells_DV, Coordinates_Nodes_of_Cells_OV)
  Results_Cells_BNV = Results_Cells_DV

  Success = Global_ALL(Results_Cells_BNV(1,:) == &
            changetype(real, SUM(Nodes_of_Cells_Index_Values(:,:),2)) /  &
            changetype(real, Nodes_per_Cell))
  call Output_Test ('Average index', Success)
  Success = Global_ALL(Results_Cells_BNV(2,:) == one)
  call Output_Test ('Average one', Success)

  !   Max test.

  call Collect_and_MAX (Results_Cells_DV, Coordinates_Nodes_of_Cells_OV)
  Results_Cells_BNV = Results_Cells_DV

  Success = Global_ALL(INT(Results_Cells_BNV(1,:)) == &
            MAXVAL(Nodes_of_Cells_Index_Values(:,:),2))
  call Output_Test ('Max index', Success)
  Success = Global_ALL(Results_Cells_BNV(2,:) == one)
  call Output_Test ('Max one', Success)

  !   Min test.

  call Collect_and_MIN (Results_Cells_DV, Coordinates_Nodes_of_Cells_OV)
  Results_Cells_BNV = Results_Cells_DV

  Success = Global_ALL(INT(Results_Cells_BNV(1,:)) == &
            MINVAL(Nodes_of_Cells_Index_Values(:,:),2))
  call Output_Test ('Min index', Success)
  Success = Global_ALL(Results_Cells_BNV(2,:) == one)
  call Output_Test ('Min one', Success)

  !   Sum test.

  Results_Cells_DV = Coordinates_Nodes_of_Cells_OV  ! Sum is the default.
  Results_Cells_BNV = Results_Cells_DV

  Success = Global_ALL(INT(Results_Cells_BNV(1,:)) == &
            SUM(Nodes_of_Cells_Index_Values(:,:),2))
  call Output_Test ('Sum index', Success)
  Success = Global_ALL(Results_Cells_BNV(2,:) == four)
  call Output_Test ('Sum four', Success)

  ! Output statements.

  call Output (Coordinates_Nodes_of_Cells_OV, &
    MAX(1, Length_Total(Node_Structure)/10), &
    MIN(Length_Total(Node_Structure), Length_Total(Node_Structure)/10+50), &
    MAX(1, Length_Total(Cell_Structure)/10), &
    MIN(Length_Total(Cell_Structure), Length_Total(Cell_Structure)/10+50) &
  )

  ! Check state of various objects.

  VERIFY(Valid_State(Coordinates_Nodes_AV),0)
  VERIFY(Valid_State(Coordinates_Nodes_DV),0)
  VERIFY(Valid_State(Coordinates_Nodes_of_Cells_OV),0)
  VERIFY(Valid_State(Cell_Structure),0)
  VERIFY(Valid_State(Node_Structure),0)
  VERIFY(Valid_State(Nodes_of_Cells_Index),0)

  ! Finalize data structures and communications.

  call Finalize (Results_Cells_DV)
  call Finalize (Results_Cells_BNV)
  call Finalize (Nodes_of_Cells_Index_Values)
  call Finalize (Coordinates_Nodes_of_Cells_OV)
  call Finalize (Coordinates_Nodes_AV)
  call Finalize (Coordinates_Nodes_DV)
  call Finalize (Coordinates)
  call Finalize (Processed_Coordinates)
  call Finalize (Nodes_of_Cells_Index)
  call Finalize (Cell_Structure)
  call Finalize (Node_Structure)
  call Finalize (Comm)

end



Michael L. Hall