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

Commit

Permalink
Save intermediate param files to be able to restart from any position…
Browse files Browse the repository at this point in the history
… in an old run (stop gap until a better system for saving random seeds is developed)
  • Loading branch information
daminton committed Jan 6, 2023
1 parent 9ac43be commit 6a3e4b5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
8 changes: 7 additions & 1 deletion python/swiftest/swiftest/simulation_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -2953,10 +2953,16 @@ def clean(self):
self.simdir / "collisions.log",
self.simdir / "collisions.nc",
self.simdir / "encounters.nc",
self.simdir / "param.restart.in",
]

glob_files = [self.simdir.glob("**/param.*.in")]

for f in old_files:
if f.exists():
os.remove(f)

for g in glob_files:
for f in g:
if f.exists():
os.remove(f)
return
7 changes: 6 additions & 1 deletion src/swiftest/swiftest_io.f90
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ module subroutine swiftest_io_dump_system(self, param)
class(swiftest_parameters), allocatable :: param_restart !! Local parameters variable used to parameters change input file names
!! to dump file-specific values without changing the user-defined values
character(len=:), allocatable :: param_file_name
character(len=STRMAX) :: time_text

! Dump the encounter history if necessary
if (param%lenc_save_trajectory .or. param%lenc_save_closest .and. allocated(self%encounter_history)) call self%encounter_history%dump(param)
Expand All @@ -248,13 +249,16 @@ module subroutine swiftest_io_dump_system(self, param)
call param%system_history%dump(param)

allocate(param_restart, source=param)
param_file_name = trim(adjustl(PARAM_RESTART_FILE))
param_restart%in_form = "XV"
param_restart%out_stat = 'APPEND'
param_restart%in_type = "NETCDF_DOUBLE"
param_restart%nc_in = param%outfile
param_restart%lrestart = .true.
param_restart%tstart = self%t
param_file_name = trim(adjustl(PARAM_RESTART_FILE))
call param_restart%dump(param_file_name)
write(time_text,'(I0.20)') param%iloop
param_file_name = "param." // trim(adjustl(time_text)) // ".in"
call param_restart%dump(param_file_name)

return
Expand Down Expand Up @@ -2293,6 +2297,7 @@ module subroutine swiftest_io_param_writer(self, unit, iotype, v_list, iostat, i
call io_param_writer_one("COLLISION_MODEL",param%collision_model, unit)
if (param%collision_model == "FRAGGLE" ) then
nseeds = size(param%seed)
call random_seed(get = param%seed)
call io_param_writer_one("SEED", [nseeds, param%seed(:)], unit)
end if

Expand Down

0 comments on commit 6a3e4b5

Please sign in to comment.