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

Commit

Permalink
Fixed up resizing methods
Browse files Browse the repository at this point in the history
  • Loading branch information
daminton committed Dec 5, 2022
1 parent f707a46 commit 4dfa484
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ SET(FAST_MATH_FILES
${SRC}/util/util_minimize_bfgs.f90
${SRC}/util/util_peri.f90
${SRC}/util/util_rescale.f90
${SRC}/util/util_reset.f90
${SRC}/util/util_resize.f90
${SRC}/util/util_set.f90
${SRC}/util/util_solve.f90
Expand Down
9 changes: 7 additions & 2 deletions src/modules/swiftest_classes.f90
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,8 @@ module swiftest_classes
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
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
end type swiftest_storage

abstract interface
Expand Down Expand Up @@ -1526,13 +1527,17 @@ module subroutine util_peri_tp(self, system, param)
class(swiftest_parameters), intent(in) :: param !! Current run configuration parameters
end subroutine util_peri_tp


module subroutine util_rescale_system(self, param, mscale, dscale, tscale)
implicit none
class(swiftest_nbody_system), intent(inout) :: self !! Swiftest nbody system object
class(swiftest_parameters), intent(inout) :: param !! Current run configuration parameters. Returns with new values of the scale vactors and GU
real(DP), intent(in) :: mscale, dscale, tscale !! Scale factors for mass, distance, and time units, respectively.
end subroutine util_rescale_system

module subroutine util_reset_storage(self)
implicit none
class(swiftest_storage(*)), intent(inout) :: self !! Swiftest storage object
end subroutine util_reset_storage
end interface


Expand Down
1 change: 1 addition & 0 deletions src/setup/setup.f90
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ module subroutine setup_construct_system(system, param)
allocate(symba_pltpenc :: system%pltpenc_list)
allocate(symba_plplenc :: system%plplenc_list)
allocate(symba_plplenc :: system%plplcollision_list)
allocate(symba_encounter_storage :: system%encounter_history)
end select
case (RINGMOONS)
write(*,*) 'RINGMOONS-SyMBA integrator not yet enabled'
Expand Down
2 changes: 2 additions & 0 deletions src/symba/symba_step.f90
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,8 @@ module subroutine symba_step_reset_system(self, param)
tp%lfirst = param%lfirstkick
pl%lfirst = param%lfirstkick

call system%encounter_history%reset()

end associate
end select
end select
Expand Down
11 changes: 9 additions & 2 deletions src/symba/symba_util.f90
Original file line number Diff line number Diff line change
Expand Up @@ -919,26 +919,32 @@ module subroutine symba_util_resize_storage(self, nnew)
integer(I4B), intent(in) :: nnew !! New size of list needed
! Internals
type(symba_encounter_storage(nframes=:)), allocatable :: tmp
integer(I4B) :: i, nold
integer(I4B) :: i, nold, nbig, iframe_old = 0
logical :: lmalloc


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

if (nnew > nold) then
allocate(symba_encounter_storage(8 * nnew) :: tmp)
nbig = nold
do while (nbig < nnew)
nbig = nbig * 2
end do
allocate(symba_encounter_storage(nbig) :: 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)
self%encounter_history%iframe = iframe_old
end if

return
Expand Down Expand Up @@ -1383,6 +1389,7 @@ 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)
self%encounter_history%frame(self%encounter_history%iframe) = snapshot
end select
end select
Expand Down
32 changes: 32 additions & 0 deletions src/util/util_reset.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
!! Copyright 2022 - David Minton, Carlisle Wishard, Jennifer Pouplin, Jake Elliott, & Dana Singh
!! This file is part of Swiftest.
!! Swiftest is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License
!! as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
!! Swiftest is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
!! of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
!! You should have received a copy of the GNU General Public License along with Swiftest.
!! If not, see: https://www.gnu.org/licenses.

submodule (swiftest_classes) s_util_reset
use swiftest
contains

module subroutine util_reset_storage(self)
!! author: David A. Minton
!!
!! Resets a storage object by deallocating all items and resetting the frame counter to 0
implicit none
! Arguments
class(swiftest_storage(*)), intent(inout) :: self !! Swiftest storage object
! Internals
integer(I4B) :: i

do i = 1, self%nframes
if (allocated(self%frame(i)%item)) deallocate(self%frame(i)%item)
end do
self%iframe = 0

return
end subroutine util_reset_storage

end submodule s_util_reset

0 comments on commit 4dfa484

Please sign in to comment.