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

Commit

Permalink
Added the storage of nbody_system snapshots between output dumps
Browse files Browse the repository at this point in the history
  • Loading branch information
daminton committed Dec 1, 2022
1 parent 5b1355f commit 864b02d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 21 deletions.
35 changes: 22 additions & 13 deletions src/main/swiftest_driver.f90
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ program swiftest_driver
integer(I8B) :: iout !! Output cadence counter
integer(I8B) :: istart !! Starting index for loop counter
integer(I8B) :: nloops !! Number of steps to take in the simulation
integer(I8B) :: iframe !! System history frame cindex
real(DP) :: old_t_final = 0.0_DP !! Output time at which writing should start, in order to prevent duplicate lines being written for restarts
type(walltimer) :: integration_timer !! Object used for computing elapsed wall time
real(DP) :: tfrac
Expand Down Expand Up @@ -78,12 +79,19 @@ program swiftest_driver
display_unit => param%display_unit)

call nbody_system%initialize(param)

! Set up loop and output cadence variables
t = tstart
iout = istep_out
idump = dump_cadence
nloops = ceiling((tstop - t0) / dt, kind=I8B)
istart = ceiling((tstart - t0) / dt, kind=I8B)
istart = ceiling((tstart - t0) / dt + 1, kind=I8B)
ioutput = int(istart / istep_out, kind=I8B)

! Set up system storage for intermittent file dumps
if (dump_cadence == 0) dump_cadence = nloops
allocate(swiftest_storage(dump_cadence) :: system_history)
idump = dump_cadence

! Prevent duplicate frames from being written if this is a restarted run
if (param%lrestart) then
old_t_final = nbody_system%get_old_t_final(param)
Expand Down Expand Up @@ -119,9 +127,18 @@ program swiftest_driver
if (istep_out > 0) then
iout = iout - 1
if (iout == 0) then
ioutput = int(iloop / istep_out, kind=I8B)
call nbody_system%write_frame(param)

idump = idump - 1
iframe = dump_cadence - idump
system_history%frame(iframe) = nbody_system

if (idump == 0) then
call nbody_system%dump(param)
do iframe = 1_I8B, dump_cadence
ioutput = int((iloop - dump_cadence - 1_I8B + iframe) / istep_out, kind=I8B)
call system_history%frame(iframe)%system%write_frame(param)
end do
idump = dump_cadence
end if

tfrac = (param%t - param%t0) / (param%tstop - param%t0)

Expand All @@ -147,14 +164,6 @@ program swiftest_driver
end if
end if

!> If the loop counter is at the dump cadence value, dump the state of the system to a file in case it needs to be restarted
if (dump_cadence > 0) then
idump = idump - 1
if (idump == 0) then
call nbody_system%dump(param)
idump = dump_cadence
end if
end if
end do
if (display_style == "COMPACT") write(*,*) "SWIFTEST STOP" // trim(adjustl(param%integrator))
end associate
Expand Down
9 changes: 1 addition & 8 deletions src/modules/swiftest_classes.f90
Original file line number Diff line number Diff line change
Expand Up @@ -425,11 +425,10 @@ module swiftest_classes
end type

type, extends(swiftest_base) :: swiftest_storage(nframes)
integer(I4B), len :: nframes
integer(I8B), len :: nframes
!! A class that that is used to store simulation history data between file output
type(storage_frame), dimension(nframes) :: frame
contains
procedure :: initialize => setup_initialize_storage
end type swiftest_storage

abstract interface
Expand Down Expand Up @@ -1046,12 +1045,6 @@ module subroutine setup_initialize_particle_info_system(self, param)
class(swiftest_parameters), intent(inout) :: param !! Current run configuration parameters
end subroutine setup_initialize_particle_info_system

module subroutine setup_initialize_storage(self, param)
implicit none
class(swiftest_storage(*)), intent(inout) :: self !! Swiftest storage object
class(swiftest_parameters), intent(inout) :: param !! Current run configuration parameters
end subroutine setup_initialize_storage

module subroutine setup_initialize_system(self, param)
implicit none
class(swiftest_nbody_system), intent(inout) :: self !! Swiftest system object
Expand Down
2 changes: 2 additions & 0 deletions src/util/util_copy.f90
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@ module subroutine util_copy_store_system(self, system)
class(storage_frame), intent(inout) :: self !! Swiftest storage frame object
class(swiftest_nbody_system), intent(in) :: system !! Swiftest n-body system object

if (allocated(self%system)) deallocate(self%system)
allocate(self%system, source=system)
return

end subroutine util_copy_store_system

Expand Down

0 comments on commit 864b02d

Please sign in to comment.