diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 63c89f2b3..7f45ddd5a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -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 diff --git a/src/modules/swiftest_classes.f90 b/src/modules/swiftest_classes.f90 index 977aa2b15..276750eb6 100644 --- a/src/modules/swiftest_classes.f90 +++ b/src/modules/swiftest_classes.f90 @@ -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 @@ -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 diff --git a/src/setup/setup.f90 b/src/setup/setup.f90 index 26aed237c..fe9b20572 100644 --- a/src/setup/setup.f90 +++ b/src/setup/setup.f90 @@ -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' diff --git a/src/symba/symba_step.f90 b/src/symba/symba_step.f90 index f5616510d..e55a001ac 100644 --- a/src/symba/symba_step.f90 +++ b/src/symba/symba_step.f90 @@ -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 diff --git a/src/symba/symba_util.f90 b/src/symba/symba_util.f90 index f3eaa5ef6..919b11acb 100644 --- a/src/symba/symba_util.f90 +++ b/src/symba/symba_util.f90 @@ -919,19 +919,24 @@ 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 @@ -939,6 +944,7 @@ module subroutine symba_util_resize_storage(self, nnew) deallocate(self%encounter_history) end if call move_alloc(tmp,self%encounter_history) + self%encounter_history%iframe = iframe_old end if return @@ -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 diff --git a/src/util/util_reset.f90 b/src/util/util_reset.f90 new file mode 100644 index 000000000..569846a68 --- /dev/null +++ b/src/util/util_reset.f90 @@ -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 \ No newline at end of file