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

Commit

Permalink
Now only save encounters at unique time slots
Browse files Browse the repository at this point in the history
  • Loading branch information
daminton committed Dec 6, 2022
1 parent 6ae67f0 commit f046b6a
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 10 deletions.
6 changes: 3 additions & 3 deletions src/modules/swiftest_classes.f90
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions src/modules/symba_classes.f90
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion src/symba/symba_io.f90
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)

Expand Down
19 changes: 15 additions & 4 deletions src/symba/symba_util.f90
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit f046b6a

Please sign in to comment.