From 6a3e4b57de66e24e316b49a0809f2cce7aa008d5 Mon Sep 17 00:00:00 2001 From: David A Minton Date: Fri, 6 Jan 2023 15:03:03 -0500 Subject: [PATCH] Save intermediate param files to be able to restart from any position in an old run (stop gap until a better system for saving random seeds is developed) --- python/swiftest/swiftest/simulation_class.py | 8 +++++++- src/swiftest/swiftest_io.f90 | 7 ++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/python/swiftest/swiftest/simulation_class.py b/python/swiftest/swiftest/simulation_class.py index 30fe46108..b2904e128 100644 --- a/python/swiftest/swiftest/simulation_class.py +++ b/python/swiftest/swiftest/simulation_class.py @@ -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 diff --git a/src/swiftest/swiftest_io.f90 b/src/swiftest/swiftest_io.f90 index 4fe297197..4587e8552 100644 --- a/src/swiftest/swiftest_io.f90 +++ b/src/swiftest/swiftest_io.f90 @@ -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) @@ -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 @@ -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