This lightly commented program performs a unit test on the Multi_Mesh Class.
program Unit_Test
use Caesar_Data_Structures_Module
use Caesar_Mathematics_Module
use Caesar_Multi_Mesh_Class
use Caesar_Numbers_Module, only: one, four, zero
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(Collected_Array_type) :: Coordinates_Nodes_of_Cells_CA
type(Status_type) :: status
type(character,name_length) :: Name_Name
type(real,2) :: Coordinates, Results_Cells_BNV
type(real,3) :: Processed_Coordinates
type(integer) :: c, NodeSize, d, Dimensionality, DimSize, i, j, &
Many_Axis_Length, n, NDimensions, Nodes_per_Cell, &
NNodes
type(character,80,1) :: Output_Buffer
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, OV and CA 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)
call Initialize (Coordinates_Nodes_of_Cells_CA, &
Coordinates_Nodes_of_Cells_OV, Name_Name, status)
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 = Node_Structure%Length_Total
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, &
Cell_Structure%Length_PE, Many_Axis_Length)
! Set up Results_Cells_BNV array on every processor.
Nodes_per_Cell = 2**NDimensions
call Initialize (Results_Cells_BNV, NDimensions, &
Cell_Structure%Length_PE)
! Version number check.
Coordinates_Nodes_of_Cells_CA = 123
Success = Version(Coordinates_Nodes_of_Cells_CA) == 123
call Output_Test ('Version number', Success)
! Send Coordinates into Assembled Vector, then Distributed Vector,
! then Collected Array, and access the data.
Coordinates_Nodes_AV = Coordinates
Coordinates_Nodes_DV = Coordinates_Nodes_AV
Coordinates_Nodes_of_Cells_CA = Coordinates_Nodes_DV
Processed_Coordinates = Coordinates_Nodes_of_Cells_CA
! 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 ('BNV-AV-DV-CA-BNA Index', Success)
Success = Global_ALL(Processed_Coordinates(2,:,:) == one)
call Output_Test ('BNV-AV-DV-CA-BNA One', Success)
! A different cycle that includes an Overlapped Vector.
Processed_Coordinates = zero
Coordinates_Nodes_AV = Coordinates
Coordinates_Nodes_DV = Coordinates_Nodes_AV
Coordinates_Nodes_of_Cells_OV = Coordinates_Nodes_DV
Coordinates_Nodes_of_Cells_CA = Coordinates_Nodes_of_Cells_OV
Processed_Coordinates = Coordinates_Nodes_of_Cells_CA
! Check to see if the Processed Coordinates are correct.
Success = Global_ALL(INT(Processed_Coordinates(1,:,:)) == &
Nodes_of_Cells_Index_Values(:,:))
call Output_Test ('BNV-AV-DV-OV-CA-BNA Index', Success)
Success = Global_ALL(Processed_Coordinates(2,:,:) == one)
call Output_Test ('BNV-AV-DV-OV-CA-BNA One', Success)
! Combination tests:
! Average test.
call Combine_with_Average (Results_Cells_DV, Coordinates_Nodes_of_Cells_CA)
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 Combine_with_MAX (Results_Cells_DV, Coordinates_Nodes_of_Cells_CA)
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 Combine_with_MIN (Results_Cells_DV, Coordinates_Nodes_of_Cells_CA)
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_CA ! 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_CA, &
MAX(1, Cell_Structure%Length_Total/10), &
MIN(Cell_Structure%Length_Total, Cell_Structure%Length_Total/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_CA),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_CA)
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