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

Commit

Permalink
Restructured the loop counter with new definitions for t and tstart
Browse files Browse the repository at this point in the history
  • Loading branch information
daminton committed Dec 1, 2022
1 parent 13acd7e commit b7d8357
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 14 deletions.
9 changes: 4 additions & 5 deletions src/io/io.f90
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ module subroutine io_dump_system(self, param)
dump_param%in_netcdf = trim(adjustl(DUMP_NC_FILE(idx)))
dump_param%nciu%id_chunk = self%pl%nbody + self%tp%nbody
dump_param%nciu%time_chunk = 1
dump_param%T0 = param%t
dump_param%tstart = param%t

call dump_param%dump(param_file_name)

Expand Down Expand Up @@ -461,7 +461,6 @@ module subroutine io_param_reader(self, unit, iotype, v_list, iostat, iomsg)
integer, intent(out) :: iostat !! IO status code
character(len=*), intent(inout) :: iomsg !! Message to pass if iostat /= 0
! Internals
logical :: t0_set = .false. !! Is the initial time set in the input file?
logical :: tstart_set = .false. !! Is the final time set in the input file?
logical :: tstop_set = .false. !! Is the final time set in the input file?
logical :: dt_set = .false. !! Is the step size set in the input file?
Expand Down Expand Up @@ -489,9 +488,8 @@ module subroutine io_param_reader(self, unit, iotype, v_list, iostat, iomsg)
select case (param_name)
case ("T0")
read(param_value, *, err = 667, iomsg = iomsg) param%t0
t0_set = .true.
case ("TSTART")
read(param_value, *, err = 667, iomsg = iomsg) param%t0
read(param_value, *, err = 667, iomsg = iomsg) param%tstart
tstart_set = .true.
case ("TSTOP")
read(param_value, *, err = 667, iomsg = iomsg) param%tstop
Expand Down Expand Up @@ -652,7 +650,7 @@ module subroutine io_param_reader(self, unit, iotype, v_list, iostat, iomsg)
iostat = 0

! Do basic sanity checks on the input values
if ((.not. t0_set) .or. (.not. tstop_set) .or. (.not. dt_set)) then
if ((.not. tstart_set) .or. (.not. tstop_set) .or. (.not. dt_set)) then
write(iomsg,*) 'Valid simulation time not set'
iostat = -1
return
Expand Down Expand Up @@ -863,6 +861,7 @@ module subroutine io_param_writer(self, unit, iotype, v_list, iostat, iomsg)

associate(param => self)
call io_param_writer_one("T0", param%t0, unit)
call io_param_writer_one("TSTART", param%tstart, unit)
call io_param_writer_one("TSTOP", param%tstop, unit)
call io_param_writer_one("DT", param%dt, unit)
call io_param_writer_one("IN_TYPE", param%in_type, unit)
Expand Down
15 changes: 7 additions & 8 deletions src/main/swiftest_driver.f90
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@ program swiftest_driver
character(len=:), allocatable :: integrator !! Integrator type code (see swiftest_globals for symbolic names)
character(len=:),allocatable :: param_file_name !! Name of the file containing user-defined parameters
character(len=:), allocatable :: display_style !! Style of the output display {"STANDARD", "COMPACT", "PROGRESS"}). Default is "STANDARD"
integer(I4B) :: ierr !! I/O error code
integer(I8B) :: idump !! Dump cadence counter
integer(I8B) :: iout !! Output cadence counter
integer(I8B) :: ioutput_t0 !! The output frame counter at time 0
integer(I8B) :: istart !! Starting index for loop counter
integer(I8B) :: nloops !! Number of steps to take in the simulation
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
Expand Down Expand Up @@ -68,6 +67,7 @@ program swiftest_driver

associate(t => param%t, &
t0 => param%t0, &
tstart => param%tstart, &
dt => param%dt, &
tstop => param%tstop, &
iloop => param%iloop, &
Expand All @@ -78,13 +78,12 @@ program swiftest_driver
display_unit => param%display_unit)

call nbody_system%initialize(param)
t = t0
iloop = 0
t = tstart
iout = istep_out
idump = dump_cadence
nloops = ceiling((tstop - t0) / dt, kind=I8B)
ioutput_t0 = int(t0 / dt / istep_out, kind=I8B)
ioutput = ioutput_t0
istart = ceiling((tstart - t0) / dt, kind=I8B)
ioutput = int(istart / istep_out, kind=I8B)
! 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 All @@ -104,7 +103,7 @@ program swiftest_driver
write(*,*) "SWIFTEST START " // trim(adjustl(param%integrator))
call nbody_system%compact_output(param,integration_timer)
end if
do iloop = 1, nloops
do iloop = istart, nloops
!> Step the system forward in time
call integration_timer%start()
call nbody_system%step(param, t, dt)
Expand All @@ -120,7 +119,7 @@ program swiftest_driver
if (istep_out > 0) then
iout = iout - 1
if (iout == 0) then
ioutput = ioutput_t0 + iloop / istep_out
ioutput = int(iloop / istep_out, kind=I8B)
call nbody_system%write_frame(param)


Expand Down
3 changes: 2 additions & 1 deletion src/modules/swiftest_classes.f90
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ module swiftest_classes
character(STRMAX) :: param_file_name = "param.in" !! The default name of the parameter input file
integer(I4B) :: maxid = -1 !! The current maximum particle id number
integer(I4B) :: maxid_collision = 0 !! The current maximum collision id number
real(DP) :: t0 = -1.0_DP !! Integration start time
real(DP) :: t0 = 0.0_DP !! Integration reference time
real(DP) :: t = -1.0_DP !! Integration current time
real(DP) :: tstart = -1.0_DP !! Integration start time
real(DP) :: tstop = -1.0_DP !! Integration stop time
real(DP) :: dt = -1.0_DP !! Time step
integer(I8B) :: iloop = 0_I8B !! Main loop counter
Expand Down

0 comments on commit b7d8357

Please sign in to comment.