From f046b6aa41fcacafbb4a00db20160e7ca001b063 Mon Sep 17 00:00:00 2001 From: David A Minton Date: Tue, 6 Dec 2022 13:34:21 -0500 Subject: [PATCH] Now only save encounters at unique time slots --- src/modules/swiftest_classes.f90 | 6 +++--- src/modules/symba_classes.f90 | 6 ++++-- src/symba/symba_io.f90 | 5 ++++- src/symba/symba_util.f90 | 19 +++++++++++++++---- 4 files changed, 26 insertions(+), 10 deletions(-) diff --git a/src/modules/swiftest_classes.f90 b/src/modules/swiftest_classes.f90 index cfb8ad604..a3e109bb5 100644 --- a/src/modules/swiftest_classes.f90 +++ b/src/modules/swiftest_classes.f90 @@ -544,9 +544,9 @@ module swiftest_classes type :: swiftest_storage(nframes) !! An class that establishes the pattern for various storage objects - integer(I4B), len :: nframes = 32768 !! Total number of frames that can be stored - type(swiftest_storage_frame), dimension(nframes) :: frame !! Array of stored frames - integer(I4B) :: iframe = 0 !! The current frame number + integer(I4B), len :: nframes = 2048 !! Total number of frames that can be stored + type(swiftest_storage_frame), dimension(nframes) :: frame !! Array of stored frames + integer(I4B) :: iframe = 0 !! The current frame number contains procedure :: dump => io_dump_storage !! Dumps storage object contents to file procedure :: reset => util_reset_storage !! Resets a storage object by deallocating all items and resetting the frame counter to 0 diff --git a/src/modules/symba_classes.f90 b/src/modules/symba_classes.f90 index c715e70da..68b94c373 100644 --- a/src/modules/symba_classes.f90 +++ b/src/modules/symba_classes.f90 @@ -182,7 +182,7 @@ module symba_classes !! NetCDF dimension and variable names for the enounter save object type, extends(netcdf_parameters) :: symba_io_encounter_parameters - integer(I4B) :: COLLIDER_DIM_SIZE = 2 !! Size of collider dimension + integer(I4B) :: COLLIDER_DIM_SIZE = 2 !! Size of collider dimension integer(I4B) :: ienc_frame = 1 !! Current frame number for the encounter history character(STRMAX) :: enc_file = "encounter.nc" !! Encounter output file name @@ -194,7 +194,8 @@ module symba_classes type, extends(swiftest_storage) :: symba_encounter_storage !! A class that that is used to store simulation history data between file output - type(symba_io_encounter_parameters) :: nc + type(symba_io_encounter_parameters) :: nc !! NetCDF parameter object + real(DP), dimension(nframes) :: tvals !! Stored time values for snapshots contains procedure :: dump => symba_io_encounter_dump !! Dumps contents of encounter history to file final :: symba_util_final_encounter_storage @@ -229,6 +230,7 @@ module symba_classes type, extends(symba_nbody_system) :: symba_encounter_snapshot + integer(I4B) :: tslot !! The index for the time array in the final NetCDF file contains procedure :: write_encounter_frame => symba_io_encounter_write_frame !! Writes a frame of encounter data to file generic :: write_frame => write_encounter_frame diff --git a/src/symba/symba_io.f90 b/src/symba/symba_io.f90 index 34885acc3..ae330898a 100644 --- a/src/symba/symba_io.f90 +++ b/src/symba/symba_io.f90 @@ -148,7 +148,7 @@ module subroutine symba_io_encounter_write_frame(self, nc, param) integer(I4B) :: i, tslot, idslot, old_mode, n character(len=NAMELEN) :: charstring - tslot = nc%ienc_frame + tslot = self%tslot call check( nf90_set_fill(nc%id, nf90_nofill, old_mode), "symba_io_encounter_write_frame nf90_set_fill" ) select type(pl => self%pl) class is (symba_pl) @@ -368,6 +368,9 @@ module subroutine symba_io_start_encounter(self, param, t) if (.not. allocated(self%encounter_history)) allocate(symba_encounter_storage :: self%encounter_history) call self%encounter_history%reset() + ! Empty out the time slot array for the next pass + self%encounter_history%tvals(:) = -huge(1.0_DP) + ! Take the snapshot at the start of the encounter call self%snapshot(param, t) diff --git a/src/symba/symba_util.f90 b/src/symba/symba_util.f90 index 672ab1aed..65cd64989 100644 --- a/src/symba/symba_util.f90 +++ b/src/symba/symba_util.f90 @@ -1257,10 +1257,10 @@ module subroutine symba_util_spill_encounter_list(self, discards, lspill_list, l !! Note: Because the symba_plplenc currently does not contain any additional variable components, this method can recieve it as an input as well. implicit none ! Arguments - class(symba_encounter), intent(inout) :: self !! SyMBA pl-tp encounter list - class(encounter_list), intent(inout) :: discards !! Discarded object - logical, dimension(:), intent(in) :: lspill_list !! Logical array of bodies to spill into the discards - logical, intent(in) :: ldestructive !! Logical flag indicating whether or not this operation should alter body by removing the discard list + class(symba_encounter), intent(inout) :: self !! SyMBA pl-tp encounter list + class(encounter_list), intent(inout) :: discards !! Discarded object + logical, dimension(:), intent(in) :: lspill_list !! Logical array of bodies to spill into the discards + logical, intent(in) :: ldestructive !! Logical flag indicating whether or not this operation should alter body by removing the discard list associate(keeps => self) select type(discards) @@ -1397,8 +1397,19 @@ module subroutine symba_util_take_encounter_snapshot(self, param, t) ! Save the snapshot self%encounter_history%iframe = self%encounter_history%iframe + 1 call self%resize_storage(self%encounter_history%iframe) + + ! Find out which time slot this belongs in by searching for an existing slot + ! with the same value of time or the first available one + do i = 1, self%encounter_history%nframes + if (t >= self%encounter_history%tvals(i)) then + snapshot%tslot = i + self%encounter_history%tvals(i) = t + exit + end if + end do self%encounter_history%frame(self%encounter_history%iframe) = snapshot + end select end select end associate