@@ -83,9 +83,11 @@ program test_distribs_container
8383 call test_set_radius_distance_tol(success)
8484 call test_create([basis_graphite], success)
8585 call test_update([basis_graphite, basis_diamond], success)
86+ call test_read_write_gdfs([basis_graphite, basis_diamond], success)
8687
8788 call test_create([basis_diamond, basis_mgo], success)
8889 call test_update([basis_diamond, basis_mgo], success)
90+ call test_read_write_gdfs([basis_diamond, basis_mgo], success)
8991 ! call test_write_read(success)
9092 ! call test_write_2body(success)
9193 ! call test_write_3body(success)
@@ -232,6 +234,41 @@ subroutine test_set_history_len(success)
232234 success &
233235 )
234236
237+ ! Call the subroutine to set the history length when already allocated
238+ history_len = 3
239+ call distribs_container% set_history_len(history_len)
240+
241+ ! Check if the history length was set correctly
242+ call assert( &
243+ distribs_container% history_len .eq. history_len, &
244+ " History length was not set correctly after reallocation" , &
245+ success &
246+ )
247+
248+ call assert( &
249+ allocated (distribs_container% history_deltas) .and. &
250+ size (distribs_container% history_deltas, 1 ) .eq. history_len, &
251+ " History delta list was not reallocated" , &
252+ success &
253+ )
254+
255+ ! Call the subroutine to set the history length to zero
256+ history_len = 0
257+ call distribs_container% set_history_len(history_len)
258+
259+ ! Check if the history length was set correctly
260+ call assert( &
261+ distribs_container% history_len .eq. history_len, &
262+ " History length was not set to zero" , &
263+ success &
264+ )
265+
266+ call assert( &
267+ .not. allocated (distribs_container% history_deltas), &
268+ " History deltas was not deallocated" , &
269+ success &
270+ )
271+
235272 end subroutine test_set_history_len
236273
237274 subroutine test_is_converged (success )
@@ -392,6 +429,7 @@ subroutine test_create(basis, success)
392429 type (distribs_container_type) :: distribs_container
393430 type (basis_type), dimension (size (basis,1 )) :: basis_list
394431 character (len= 3 ), dimension (:), allocatable :: elements
432+ real (real32), dimension (:), allocatable :: energy_above_hull
395433
396434 ! Initialise basis_list
397435 do i = 1 , size (basis,1 )
@@ -584,6 +622,29 @@ subroutine test_create(basis, success)
584622 success &
585623 )
586624
625+ allocate (energy_above_hull(10 ))
626+ energy_above_hull = 0._real32
627+
628+ write (* ,* ) " Testing energy_above_hull error handling"
629+ call distribs_container% create( &
630+ basis_list, deallocate_systems= .false. , &
631+ energy_above_hull_list= energy_above_hull &
632+ )
633+ write (* ,* ) " Handled error: energy_above_hull provided but weight_by_hull is false"
634+ distribs_container% weight_by_hull = .true.
635+ call distribs_container% create( &
636+ basis_list, deallocate_systems= .false. , &
637+ energy_above_hull_list= energy_above_hull &
638+ )
639+ write (* ,* ) " Handled error: energy_above_hull and basis_list sizes do not match"
640+ deallocate (energy_above_hull)
641+ allocate (energy_above_hull(size (basis_list,1 )))
642+ energy_above_hull = 0._real32
643+ call distribs_container% create( &
644+ basis_list, deallocate_systems= .false. , &
645+ energy_above_hull_list= energy_above_hull &
646+ )
647+
587648 end subroutine test_create
588649
589650 subroutine test_update (basis , success )
@@ -597,6 +658,7 @@ subroutine test_update(basis, success)
597658 type (distribs_container_type) :: distribs_container
598659 type (basis_type), dimension (size (basis,1 )) :: basis_list
599660 character (len= 3 ), dimension (:), allocatable :: elements
661+ real (real32), dimension (:), allocatable :: energy_above_hull
600662
601663 ! Initialise basis_list
602664 do i = 1 , size (basis,1 )
@@ -652,6 +714,42 @@ subroutine test_update(basis, success)
652714 success &
653715 )
654716
717+ ! Check history length
718+ call distribs_container% set_history_len(10 )
719+ call distribs_container% update( &
720+ basis_list, deallocate_systems= .false. &
721+ )
722+ call assert( &
723+ distribs_container% history_deltas(1 ) .ne. huge (0._real32 ), &
724+ " History delta not set on update" , &
725+ success &
726+ )
727+
728+ allocate (energy_above_hull(10 ))
729+ energy_above_hull = 0._real32
730+
731+ write (* ,* ) " Testing energy_above_hull error handling"
732+ call distribs_container% update( &
733+ basis_list, deallocate_systems= .false. , &
734+ energy_above_hull_list= energy_above_hull &
735+ )
736+ write (* ,* ) " Handled error: energy_above_hull provided but weight_by_hull is false"
737+ distribs_container% weight_by_hull = .true.
738+ call distribs_container% update( &
739+ basis_list, deallocate_systems= .false. , &
740+ energy_above_hull_list= energy_above_hull &
741+ )
742+ write (* ,* ) " Handled error: energy_above_hull and basis_list sizes do not match"
743+ deallocate (energy_above_hull)
744+ allocate (energy_above_hull(size (basis_list,1 )))
745+ energy_above_hull = 0._real32
746+ call distribs_container% update( &
747+ basis_list, deallocate_systems= .false. , &
748+ energy_above_hull_list= energy_above_hull, &
749+ from_host = .true. &
750+ )
751+ write (* ,* ) " Handled error: from_host and energy_above_hull provided"
752+
655753 end subroutine test_update
656754
657755 subroutine test_add (basis , success )
@@ -909,6 +1007,123 @@ subroutine test_get_bin(success)
9091007
9101008 end subroutine test_get_bin
9111009
1010+ subroutine test_read_write_gdfs (basis , success )
1011+ implicit none
1012+ type (basis_type), dimension (:), intent (in ) :: basis
1013+ logical , intent (inout ) :: success
1014+
1015+ type (distribs_container_type) :: distribs_container, distribs_container_read
1016+ character (len= 100 ) :: filename
1017+
1018+ ! Set up a test filename
1019+ filename = ' test_gdfs.dat'
1020+
1021+ ! Create a dummy distribs_container
1022+ call distribs_container% set_history_len(10 )
1023+ call distribs_container% set_width([0.1_real32 , 0.1_real32 , 0.1_real32 ])
1024+ call distribs_container% set_sigma([0.2_real32 , 0.2_real32 , 0.2_real32 ])
1025+ call distribs_container% create([basis], deallocate_systems= .false. )
1026+
1027+ ! Write the GDFs to a file
1028+ call distribs_container% write_gdfs(filename)
1029+
1030+ ! Check if the file exists
1031+ inquire (file= filename, exist= success)
1032+ call assert(success, " GDF file was not created" , success)
1033+
1034+ ! Read the GDFs from the file
1035+ call distribs_container_read% read_gdfs(filename)
1036+
1037+ ! Check if the GDFs were read correctly
1038+ call assert( &
1039+ allocated (distribs_container_read% gdf% df_2body), &
1040+ " 2-body GDF was not read correctly" , &
1041+ success &
1042+ )
1043+ call assert( &
1044+ allocated (distribs_container_read% gdf% df_3body), &
1045+ " 3-body GDF was not read correctly" , &
1046+ success &
1047+ )
1048+ call assert( &
1049+ allocated (distribs_container_read% gdf% df_4body), &
1050+ " 4-body GDF was not read correctly" , &
1051+ success &
1052+ )
1053+
1054+ ! Check if the read width, sigma, and history length match
1055+ call assert( &
1056+ all ( &
1057+ abs ( &
1058+ distribs_container_read% width - &
1059+ distribs_container% width &
1060+ ) .lt. 1.E-6_real32 &
1061+ ), &
1062+ " Width was not read correctly" , &
1063+ success &
1064+ )
1065+ call assert( &
1066+ all ( &
1067+ abs ( &
1068+ distribs_container_read% sigma - &
1069+ distribs_container% sigma &
1070+ ) .lt. 1.E-6_real32 &
1071+ ), &
1072+ " Sigma was not read correctly" , &
1073+ success &
1074+ )
1075+ call assert( &
1076+ distribs_container_read% history_len .eq. distribs_container% history_len, &
1077+ " History length was not read correctly" , &
1078+ success &
1079+ )
1080+ call assert( &
1081+ all ( &
1082+ abs ( 1._real32 - &
1083+ distribs_container_read% history_deltas / &
1084+ distribs_container% history_deltas &
1085+ ) .lt. 1.E-4_real32 &
1086+ ), &
1087+ " History deltas were not read correctly" , &
1088+ success &
1089+ )
1090+ call assert( &
1091+ all ( &
1092+ abs ( &
1093+ distribs_container_read% cutoff_min - &
1094+ distribs_container% cutoff_min &
1095+ ) .lt. 1.E-6_real32 &
1096+ ), &
1097+ " Cutoff min was not read correctly" , &
1098+ success &
1099+ )
1100+ call assert( &
1101+ all ( &
1102+ abs ( &
1103+ distribs_container_read% cutoff_max - &
1104+ distribs_container% cutoff_max &
1105+ ) .lt. 1.E-6_real32 &
1106+ ), &
1107+ " Cutoff max was not read correctly" , &
1108+ success &
1109+ )
1110+ call assert( &
1111+ all ( &
1112+ abs ( &
1113+ distribs_container_read% radius_distance_tol - &
1114+ distribs_container% radius_distance_tol &
1115+ ) .lt. 1.E-6_real32 &
1116+ ), &
1117+ " Radius distance tolerance was not read correctly" , &
1118+ success &
1119+ )
1120+ call assert( &
1121+ all ( distribs_container_read% nbins .eq. distribs_container% nbins ), &
1122+ " Number of bins was not read correctly" , &
1123+ success &
1124+ )
1125+ end subroutine test_read_write_gdfs
1126+
9121127! ###############################################################################
9131128
9141129 subroutine assert (condition , message , success )
0 commit comments