From a41f331fdc95722983bf283490a61493f6ad231a Mon Sep 17 00:00:00 2001 From: David A Minton Date: Sat, 17 Dec 2022 20:13:02 -0500 Subject: [PATCH] More cleanup --- src/collision/collision_util.f90 | 2 +- src/encounter/encounter_util.f90 | 20 ++++++++++---------- src/modules/collision_classes.f90 | 2 +- src/modules/encounter_classes.f90 | 15 +++++++++++---- src/modules/swiftest_classes.f90 | 23 +++++++++++++++-------- src/util/util_index.f90 | 20 ++++++++++---------- 6 files changed, 48 insertions(+), 34 deletions(-) diff --git a/src/collision/collision_util.f90 b/src/collision/collision_util.f90 index 5e81b7b00..844bb8cca 100644 --- a/src/collision/collision_util.f90 +++ b/src/collision/collision_util.f90 @@ -310,7 +310,7 @@ module subroutine collision_util_index_map(self) integer(I4B), dimension(:), allocatable :: idvals real(DP), dimension(:), allocatable :: tvals - call encounter_util_get_vals_storage(self, idvals, tvals) + call self%get_index_values(idvals, tvals) ! Consolidate ids to only unique values call util_unique(idvals,self%idvals,self%idmap) diff --git a/src/encounter/encounter_util.f90 b/src/encounter/encounter_util.f90 index e6a786be2..4c472c4b3 100644 --- a/src/encounter/encounter_util.f90 +++ b/src/encounter/encounter_util.f90 @@ -203,19 +203,19 @@ module subroutine encounter_util_get_idvalues_snapshot(self, idvals) end subroutine encounter_util_get_idvalues_snapshot - subroutine encounter_util_get_vals_storage(storage, idvals, tvals) + module subroutine encounter_util_get_vals_storage(self, idvals, tvals) !! author: David A. Minton !! - !! Gets the id values in a storage object, regardless of whether it is encounter of collision + !! Gets the id values in a self object, regardless of whether it is encounter of collision ! Argument - class(swiftest_storage(*)), intent(in) :: storage !! Swiftest storage object - integer(I4B), dimension(:), allocatable, intent(out) :: idvals !! Array of all id values in all snapshots - real(DP), dimension(:), allocatable, intent(out) :: tvals !! Array of all time values in all snapshots + class(encounter_storage(*)), intent(in) :: self !! Encounter storages object + integer(I4B), dimension(:), allocatable, intent(out) :: idvals !! Array of all id values in all snapshots + real(DP), dimension(:), allocatable, intent(out) :: tvals !! Array of all time values in all snapshots ! Internals integer(I4B) :: i, n, nlo, nhi, ntotal integer(I4B), dimension(:), allocatable :: itmp - associate(nsnaps => storage%iframe) + associate(nsnaps => self%iframe) allocate(tvals(nsnaps)) @@ -224,8 +224,8 @@ subroutine encounter_util_get_vals_storage(storage, idvals, tvals) ! First pass to get total number of ids ntotal = 0 do i = 1, nsnaps - if (allocated(storage%frame(i)%item)) then - select type(snapshot => storage%frame(i)%item) + if (allocated(self%frame(i)%item)) then + select type(snapshot => self%frame(i)%item) class is (encounter_snapshot) tvals(i) = snapshot%t call snapshot%get_idvals(itmp) @@ -241,8 +241,8 @@ subroutine encounter_util_get_vals_storage(storage, idvals, tvals) nlo = 1 ! Second pass to store all ids get all of the ids stored do i = 1, nsnaps - if (allocated(storage%frame(i)%item)) then - select type(snapshot => storage%frame(i)%item) + if (allocated(self%frame(i)%item)) then + select type(snapshot => self%frame(i)%item) class is (encounter_snapshot) tvals(i) = snapshot%t call snapshot%get_idvals(itmp) diff --git a/src/modules/collision_classes.f90 b/src/modules/collision_classes.f90 index dccda9c88..791542ffd 100644 --- a/src/modules/collision_classes.f90 +++ b/src/modules/collision_classes.f90 @@ -161,7 +161,7 @@ end subroutine abstract_set_mass_dist end type collision_snapshot !> A class that that is used to store simulation history data between file output - type, extends(swiftest_storage) :: collision_storage + type, extends(encounter_storage) :: collision_storage contains procedure :: dump => collision_io_dump !! Dumps contents of encounter history to file procedure :: take_snapshot => collision_util_snapshot !! Take a minimal snapshot of the system through an encounter diff --git a/src/modules/encounter_classes.f90 b/src/modules/encounter_classes.f90 index e3aa2f9fe..164d97450 100644 --- a/src/modules/encounter_classes.f90 +++ b/src/modules/encounter_classes.f90 @@ -58,10 +58,11 @@ module encounter_classes !> A class that that is used to store simulation history data between file output type, extends(swiftest_storage) :: encounter_storage contains - procedure :: dump => encounter_io_dump !! Dumps contents of encounter history to file - procedure :: make_index_map => encounter_util_index_map !! Maps body id values to storage index values so we don't have to use unlimited dimensions for id - procedure :: take_snapshot => encounter_util_snapshot !! Take a minimal snapshot of the system through an encounter - final :: encounter_util_final_storage + procedure :: dump => encounter_io_dump !! Dumps contents of encounter history to file + procedure :: get_index_values => encounter_util_get_vals_storage !! Gets the unique values of the indices of a storage object (i.e. body id or time value) + procedure :: make_index_map => encounter_util_index_map !! Maps body id values to storage index values so we don't have to use unlimited dimensions for id + procedure :: take_snapshot => encounter_util_snapshot !! Take a minimal snapshot of the system through an encounter + final :: encounter_util_final_storage end type encounter_storage !> NetCDF dimension and variable names for the enounter save object @@ -288,6 +289,12 @@ module subroutine encounter_util_get_idvalues_snapshot(self, idvals) integer(I4B), dimension(:), allocatable, intent(out) :: idvals !! Array of all id values saved in this snapshot end subroutine encounter_util_get_idvalues_snapshot + module subroutine encounter_util_get_vals_storage(self, idvals, tvals) + class(encounter_storage(*)), intent(in) :: self !! Encounter storages object + integer(I4B), dimension(:), allocatable, intent(out) :: idvals !! Array of all id values in all snapshots + real(DP), dimension(:), allocatable, intent(out) :: tvals !! Array of all time values in all snapshots + end subroutine encounter_util_get_vals_storage + module subroutine encounter_util_index_map(self) implicit none class(encounter_storage(*)), intent(inout) :: self !! Encounter storage object diff --git a/src/modules/swiftest_classes.f90 b/src/modules/swiftest_classes.f90 index cf2ae97f4..972e3751f 100644 --- a/src/modules/swiftest_classes.f90 +++ b/src/modules/swiftest_classes.f90 @@ -146,9 +146,9 @@ module swiftest_classes type swiftest_storage_frame class(*), allocatable :: item contains - procedure :: store => util_copy_store !! Stores a snapshot of the nbody system so that later it can be retrieved for saving to file. - generic :: assignment(=) => store - final :: util_final_storage_frame + procedure :: store => util_copy_store !! Stores a snapshot of the nbody system so that later it can be retrieved for saving to file. + generic :: assignment(=) => store + final :: util_final_storage_frame end type type :: swiftest_storage(nframes) @@ -164,11 +164,12 @@ module swiftest_classes integer(I4B), dimension(:), allocatable :: tmap !! The t value -> index map class(netcdf_parameters), allocatable :: nc !! NetCDF object attached to this storage object contains - procedure :: dump => io_dump_storage !! Dumps storage object contents to file - procedure :: make_index_map => util_index_map_storage !! Maps body id values to storage index values so we don't have to use unlimited dimensions for id - procedure :: reset => util_reset_storage !! Resets a storage object by deallocating all items and resetting the frame counter to 0 - procedure :: take_snapshot => util_snapshot_system !! Takes a snapshot of the system for later file storage - final :: util_final_storage + procedure :: dump => io_dump_storage !! Dumps storage object contents to file + procedure :: get_index_values => util_get_vals_storage !! Gets the unique values of the indices of a storage object (i.e. body id or time value) + procedure :: make_index_map => util_index_map_storage !! Maps body id values to storage index values so we don't have to use unlimited dimensions for id + procedure :: reset => util_reset_storage !! Resets a storage object by deallocating all items and resetting the frame counter to 0 + procedure :: take_snapshot => util_snapshot_system !! Takes a snapshot of the system for later file storage + final :: util_final_storage end type swiftest_storage !******************************************************************************************************************************** @@ -1507,6 +1508,12 @@ module subroutine util_flatten_eucl_pltp(self, pl, param) class(swiftest_parameters), intent(inout) :: param !! Current run configuration parameters end subroutine + module subroutine util_get_vals_storage(self, idvals, tvals) + class(swiftest_storage(*)), intent(in) :: self !! Swiftest storage object + integer(I4B), dimension(:), allocatable, intent(out) :: idvals !! Array of all id values in all snapshots + real(DP), dimension(:), allocatable, intent(out) :: tvals !! Array of all time values in all snapshots + end subroutine util_get_vals_storage + module subroutine util_index_array(ind_arr, n) implicit none integer(I4B), dimension(:), allocatable, intent(inout) :: ind_arr !! Index array. Input is a pre-existing index array where n /= size(ind_arr). Output is a new index array ind_arr = [1, 2, ... n] diff --git a/src/util/util_index.f90 b/src/util/util_index.f90 index 0fbd40319..e268b3789 100644 --- a/src/util/util_index.f90 +++ b/src/util/util_index.f90 @@ -78,19 +78,19 @@ module subroutine util_get_idvalues_system(self, idvals) end subroutine util_get_idvalues_system - subroutine util_get_vals_storage(storage, idvals, tvals) + module subroutine util_get_vals_storage(self, idvals, tvals) !! author: David A. Minton !! !! Gets the id values in a storage object, regardless of whether it is encounter of collision ! Argument - class(swiftest_storage(*)), intent(in) :: storage !! Swiftest storage object - integer(I4B), dimension(:), allocatable, intent(out) :: idvals !! Array of all id values in all snapshots - real(DP), dimension(:), allocatable, intent(out) :: tvals !! Array of all time values in all snapshots + class(swiftest_storage(*)), intent(in) :: self !! Swiftest storage object + integer(I4B), dimension(:), allocatable, intent(out) :: idvals !! Array of all id values in all snapshots + real(DP), dimension(:), allocatable, intent(out) :: tvals !! Array of all time values in all snapshots ! Internals integer(I4B) :: i, n, nlo, nhi, ntotal integer(I4B), dimension(:), allocatable :: itmp - associate(nsnaps => storage%iframe) + associate(nsnaps => self%iframe) allocate(tvals(nsnaps)) tvals(:) = 0.0_DP @@ -98,8 +98,8 @@ subroutine util_get_vals_storage(storage, idvals, tvals) ! First pass to get total number of ids ntotal = 0 do i = 1, nsnaps - if (allocated(storage%frame(i)%item)) then - select type(snapshot => storage%frame(i)%item) + if (allocated(self%frame(i)%item)) then + select type(snapshot => self%frame(i)%item) class is (swiftest_nbody_system) tvals(i) = snapshot%t call snapshot%get_idvals(itmp) @@ -115,8 +115,8 @@ subroutine util_get_vals_storage(storage, idvals, tvals) nlo = 1 ! Second pass to store all ids get all of the ids stored do i = 1, nsnaps - if (allocated(storage%frame(i)%item)) then - select type(snapshot => storage%frame(i)%item) + if (allocated(self%frame(i)%item)) then + select type(snapshot => self%frame(i)%item) class is (swiftest_nbody_system) tvals(i) = snapshot%t call snapshot%get_idvals(itmp) @@ -146,7 +146,7 @@ module subroutine util_index_map_storage(self) integer(I4B), dimension(:), allocatable :: idvals real(DP), dimension(:), allocatable :: tvals - call util_get_vals_storage(self, idvals, tvals) + call self%get_index_values(idvals, tvals) call util_unique(idvals,self%idvals,self%idmap) self%nid = size(self%idvals)