Skip to content
This repository was archived by the owner on Aug 28, 2024. It is now read-only.

Commit

Permalink
More cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
daminton committed Dec 18, 2022
1 parent ad14dde commit a41f331
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 34 deletions.
2 changes: 1 addition & 1 deletion src/collision/collision_util.f90
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
20 changes: 10 additions & 10 deletions src/encounter/encounter_util.f90
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand All @@ -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)
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/modules/collision_classes.f90
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 11 additions & 4 deletions src/modules/encounter_classes.f90
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
23 changes: 15 additions & 8 deletions src/modules/swiftest_classes.f90
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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

!********************************************************************************************************************************
Expand Down Expand Up @@ -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]
Expand Down
20 changes: 10 additions & 10 deletions src/util/util_index.f90
Original file line number Diff line number Diff line change
Expand Up @@ -78,28 +78,28 @@ 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

! 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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit a41f331

Please sign in to comment.