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

Commit

Permalink
Moved the resize storage method to symba_nbody_system so that it can …
Browse files Browse the repository at this point in the history
…be reallocated
  • Loading branch information
daminton committed Dec 2, 2022
1 parent 83f72dc commit 7f651c4
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 46 deletions.
39 changes: 0 additions & 39 deletions src/encounter/encounter_util.f90
Original file line number Diff line number Diff line change
Expand Up @@ -192,45 +192,6 @@ module subroutine encounter_util_resize_list(self, nnew)
end subroutine encounter_util_resize_list


module subroutine encounter_util_resize_storage(self, nnew)
!! author: David A. Minton
!!
!! Checks the current size of the encounter storage against the required size and extends it by a factor of 2 more than requested if it is too small.
!! Note: The reason to extend it by a factor of 2 is for performance. When there are many enounters per step, resizing every time you want to add an
!! encounter takes significant computational effort. Resizing by a factor of 2 is a tradeoff between performance (fewer resize calls) and memory managment
!! Memory usage grows by a factor of 2 each time it fills up, but no more.
implicit none
! Arguments
class(encounter_storage(*)), allocatable, intent(inout) :: self !! Swiftest encounter list
integer(I4B), intent(in) :: nnew !! New size of list needed
! Internals
type(encounter_storage(nframes=:)), allocatable :: tmp
integer(I4B) :: i, nold
logical :: lmalloc


lmalloc = allocated(self)
if (lmalloc) then
nold = self%nframes
else
nold = 0
end if

if (nnew > nold) then
allocate(encounter_storage(2 * nnew) :: tmp)
if (lmalloc) then
do i = 1, nold
if (allocated(self%frame(i)%item)) tmp%frame(i) = self%frame(i)%item
end do
deallocate(self)
end if
call move_alloc(tmp,self)
end if

return
end subroutine encounter_util_resize_storage


module subroutine encounter_util_spill_list(self, discards, lspill_list, ldestructive)
!! author: David A. Minton
!!
Expand Down
8 changes: 1 addition & 7 deletions src/modules/encounter_classes.f90
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ module encounter_classes
!! A class that that is used to store simulation history data between file output
type(encounter_io_parameters) :: nciu
contains
procedure :: dump => encounter_io_dump_storage_list
procedure :: dump => encounter_io_dump_storage_list !! Dumps contents of encounter history to file
end type encounter_storage

type encounter_bounding_box_1D
Expand Down Expand Up @@ -286,12 +286,6 @@ module subroutine encounter_util_resize_list(self, nnew)
integer(I8B), intent(in) :: nnew !! New size of list needed
end subroutine encounter_util_resize_list

module subroutine encounter_util_resize_storage(self, nnew)
implicit none
class(encounter_storage(*)), allocatable, intent(inout) :: self !! Swiftest encounter list
integer(I4B), intent(in) :: nnew !! New size of list needed
end subroutine encounter_util_resize_storage

module subroutine encounter_util_spill_list(self, discards, lspill_list, ldestructive)
implicit none
class(encounter_list), intent(inout) :: self !! Swiftest encounter list
Expand Down
7 changes: 7 additions & 0 deletions src/modules/symba_classes.f90
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ module symba_classes
procedure :: recursive_step => symba_step_recur_system !! Step interacting planets and active test particles ahead in democratic heliocentric coordinates at the current recursion level, if applicable, and descend to the next deeper level if necessary
procedure :: reset => symba_step_reset_system !! Resets pl, tp,and encounter structures at the start of a new step
procedure :: dealloc => symba_util_dealloc_system !! Deallocates all allocatable arrays
procedure :: resize_storage => symba_util_resize_storage
final :: symba_util_final_system !! Finalizes the SyMBA nbody system object - deallocates all allocatables
end type symba_nbody_system

Expand Down Expand Up @@ -700,6 +701,12 @@ module subroutine symba_util_resize_pl(self, nnew)
integer(I4B), intent(in) :: nnew !! New size neded
end subroutine symba_util_resize_pl

module subroutine symba_util_resize_storage(self, nnew)
implicit none
class(symba_nbody_system), intent(inout) :: self !! SyMBA nbody system object
integer(I4B), intent(in) :: nnew !! New size of list needed
end subroutine symba_util_resize_storage

module subroutine symba_util_resize_tp(self, nnew)
implicit none
class(symba_tp), intent(inout) :: self !! SyMBA massive body object
Expand Down
1 change: 1 addition & 0 deletions src/symba/symba_encounter_check.f90
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ module function symba_encounter_check_pl(self, param, system, dt, irec) result(l
pl%nplenc(j) = pl%nplenc(j) + 1
end do
ienc_frame = ienc_frame + 1
call system%resize_storage(ienc_frame)
encounter_history%frame(ienc_frame) = plplenc_list
end if

Expand Down
40 changes: 40 additions & 0 deletions src/symba/symba_util.f90
Original file line number Diff line number Diff line change
Expand Up @@ -900,6 +900,46 @@ module subroutine symba_util_resize_pl(self, nnew)
end subroutine symba_util_resize_pl


module subroutine symba_util_resize_storage(self, nnew)
!! author: David A. Minton
!!
!! Checks the current size of the encounter storage against the required size and extends it by a factor of 2 more than requested if it is too small.
!! Note: The reason to extend it by a factor of 2 is for performance. When there are many enounters per step, resizing every time you want to add an
!! encounter takes significant computational effort. Resizing by a factor of 2 is a tradeoff between performance (fewer resize calls) and memory managment
!! Memory usage grows by a factor of 2 each time it fills up, but no more.
implicit none
! Arguments
class(symba_nbody_system), intent(inout) :: self !! Swiftest encounter list
integer(I4B), intent(in) :: nnew !! New size of list needed
! Internals
type(encounter_storage(nframes=:)), allocatable :: tmp
integer(I4B) :: i, nold
logical :: lmalloc


lmalloc = allocated(self%encounter_history)
if (lmalloc) then
nold = self%encounter_history%nframes
else
nold = 0
end if

if (nnew > nold) then
allocate(encounter_storage(2 * nnew) :: tmp)
if (lmalloc) then
do i = 1, nold
if (allocated(self%encounter_history%frame(i)%item)) tmp%frame(i) = self%encounter_history%frame(i)%item
end do
deallocate(self%encounter_history)
end if
call move_alloc(tmp,self%encounter_history)
end if

return
end subroutine symba_util_resize_storage



module subroutine symba_util_resize_tp(self, nnew)
!! author: David A. Minton
!!
Expand Down

0 comments on commit 7f651c4

Please sign in to comment.