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

Commit

Permalink
More progress. Everything is connected. Just needs to be tested and b…
Browse files Browse the repository at this point in the history
…ugs fixed
  • Loading branch information
daminton committed Dec 10, 2022
1 parent 7972bcc commit ec08c01
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/encounter/encounter_io.f90
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ module subroutine encounter_io_dump(self, param)

do i = 1, self%nframes
if (allocated(self%frame(i)%item)) then
param%ioutput = self%tslot(i)

select type(snapshot => self%frame(i)%item)
class is (fraggle_collision_snapshot)
param%ioutput = i
call snapshot%write_frame(self%nc,param)
call snapshot%encounter_snapshot%write_frame(self%nc,param)
class is (encounter_snapshot)
param%ioutput = self%tslot(i)
call snapshot%write_frame(self%nc,param)
end select
else
Expand Down
57 changes: 53 additions & 4 deletions src/symba/symba_util.f90
Original file line number Diff line number Diff line change
Expand Up @@ -869,7 +869,56 @@ module subroutine symba_util_resize_pl(self, nnew)
end subroutine symba_util_resize_pl


subroutine symba_util_save_storage(system, snapshot, t)
subroutine symba_util_save_collision(system, snapshot)
!! 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
type(symba_nbody_system), intent(inout) :: system !! SyMBA nbody system object
class(encounter_snapshot), intent(in) :: snapshot !! Encounter snapshot object
! Internals
type(encounter_storage(nframes=:)), allocatable :: tmp
integer(I4B) :: i, nnew, nold, nbig

! Advance the snapshot frame counter
system%collision_history%iframe = system%collision_history%iframe + 1

! Check to make sure the current encounter_history object is big enough. If not, grow it by a factor of 2
nnew = system%encounter_history%iframe
nold = system%encounter_history%nframes

if (nnew > nold) then
nbig = nold
do while (nbig < nnew)
nbig = nbig * 2
end do
allocate(encounter_storage(nbig) :: tmp)
tmp%tvals(1:nold) = system%encounter_history%tvals(1:nold)
tmp%tvals(nold+1:nbig) = huge(1.0_DP)
tmp%tslot(1:nold) = system%encounter_history%tslot(1:nold)
tmp%tslot(nold+1:nbig) = 0
tmp%iframe = system%encounter_history%iframe
call move_alloc(system%encounter_history%nc, tmp%nc)

do i = 1, nold
if (allocated(system%encounter_history%frame(i)%item)) call move_alloc(system%encounter_history%frame(i)%item, tmp%frame(i)%item)
end do
deallocate(system%encounter_history)
call move_alloc(tmp,system%encounter_history)
nnew = nbig
end if

system%collision_history%frame(nnew) = snapshot

return
end subroutine symba_util_save_collision


subroutine symba_util_save_encounter(system, snapshot, t)
!! 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.
Expand Down Expand Up @@ -925,7 +974,7 @@ subroutine symba_util_save_storage(system, snapshot, t)
end do

return
end subroutine symba_util_save_storage
end subroutine symba_util_save_encounter


module subroutine symba_util_resize_tp(self, nnew)
Expand Down Expand Up @@ -1323,7 +1372,7 @@ module subroutine symba_util_take_collision_snapshot(self, param, t, stage)
allocate(fraggle_collision_snapshot :: snapshot)
allocate(snapshot%colliders, source=self%colliders)
allocate(snapshot%fragments, source=self%fragments)
!call symba_util_save_storage(self,snapshot,t)
call symba_util_save_collision(self,snapshot)
end select

return
Expand Down Expand Up @@ -1430,7 +1479,7 @@ module subroutine symba_util_take_encounter_snapshot(self, param, t)
end select

! Save the snapshot
call symba_util_save_storage(self,snapshot,t)
call symba_util_save_encounter(self,snapshot,t)
end select
end select
end associate
Expand Down

0 comments on commit ec08c01

Please sign in to comment.