From b7afb0de6e41da2a7e78074e069c065de3907963 Mon Sep 17 00:00:00 2001 From: David A Minton Date: Thu, 1 Dec 2022 08:54:39 -0500 Subject: [PATCH] Created new storage class and= operator overloading to enable storage of system snapshots for later dumping --- src/io/io.f90 | 2 +- src/main/swiftest_driver.f90 | 1 + src/modules/swiftest_classes.f90 | 29 ++++++++++++++++++----------- src/util/util_copy.f90 | 11 +++++++++++ 4 files changed, 31 insertions(+), 12 deletions(-) diff --git a/src/io/io.f90 b/src/io/io.f90 index de4c547e9..91f20ed23 100644 --- a/src/io/io.f90 +++ b/src/io/io.f90 @@ -526,7 +526,7 @@ module subroutine io_param_reader(self, unit, iotype, v_list, iostat, iomsg) case ("OUT_STAT") call io_toupper(param_value) param%out_stat = param_value - case ("ISTEP_DUMP") + case ("DUMP_CADENCE") read(param_value, *, err = 667, iomsg = iomsg) param%istep_dump case ("CHK_CLOSE") call io_toupper(param_value) diff --git a/src/main/swiftest_driver.f90 b/src/main/swiftest_driver.f90 index 8f02b74f8..037592432 100644 --- a/src/main/swiftest_driver.f90 +++ b/src/main/swiftest_driver.f90 @@ -40,6 +40,7 @@ program swiftest_driver character(len=64) :: pbarmessage character(*), parameter :: symbacompactfmt = '(";NPLM",ES22.15,$)' + type(swiftest_storage(nframes=:)), allocatable :: system_history call io_get_args(integrator, param_file_name, display_style) diff --git a/src/modules/swiftest_classes.f90 b/src/modules/swiftest_classes.f90 index 086b00676..50f1c33ee 100644 --- a/src/modules/swiftest_classes.f90 +++ b/src/modules/swiftest_classes.f90 @@ -46,14 +46,14 @@ module swiftest_classes character(STRMAX) :: inplfile = PL_INFILE !! Name of input file for massive bodies character(STRMAX) :: intpfile = TP_INFILE !! Name of input file for test particles character(STRMAX) :: in_netcdf = NC_INFILE !! Name of system input file for NetCDF input - character(STRMAX) :: in_type = "ASCII" !! Data representation type of input data files - character(STRMAX) :: in_form = "XV" !! Format of input data files ("EL" or "XV") - integer(I4B) :: istep_out = -1 !! Number of time steps between binary outputs + character(STRMAX) :: in_type = "ASCII" !! Data representation type of input data files + character(STRMAX) :: in_form = "XV" !! Format of input data files ("EL" or "XV") + integer(I4B) :: istep_out = -1 !! Number of time steps between saved outputs character(STRMAX) :: outfile = NETCDF_OUTFILE !! Name of output binary file - character(STRMAX) :: out_type = "NETCDF_DOUBLE" !! Binary format of output file - character(STRMAX) :: out_form = "XVEL" !! Data to write to output file + character(STRMAX) :: out_type = "NETCDF_DOUBLE" !! Binary format of output file + character(STRMAX) :: out_form = "XVEL" !! Data to write to output file character(STRMAX) :: out_stat = 'NEW' !! Open status for output binary file - integer(I4B) :: istep_dump = -1 !! Number of time steps between dumps + integer(I4B) :: dump_cadence = 1 !! Number of output steps between dumping simulation data to file real(DP) :: rmin = -1.0_DP !! Minimum heliocentric radius for test particle real(DP) :: rmax = -1.0_DP !! Maximum heliocentric radius for test particle real(DP) :: rmaxu = -1.0_DP !! Maximum unbound heliocentric radius for test particle @@ -413,24 +413,25 @@ module swiftest_classes procedure :: get_energy_and_momentum => util_get_energy_momentum_system !! Calculates the total system energy and momentum procedure :: rescale => util_rescale_system !! Rescales the system into a new set of units procedure :: validate_ids => util_valid_id_system !! Validate the numerical ids passed to the system and save the maximum value - generic :: write_frame => write_frame_system, write_frame_netcdf !! Generic method call for reading a frame of output data + generic :: write_frame => write_frame_system, write_frame_netcdf !! Generic method call for reading a frame of output data end type swiftest_nbody_system - type system_storage_frame + type storage_frame class(swiftest_nbody_system), allocatable :: system + contains + procedure :: store => util_copy_store_system !! Stores a snapshot of the nbody system so that later it can be retrieved for saving to file. + generic :: assignment(=) => store end type type, extends(swiftest_base) :: swiftest_storage(nframes) integer(I4B), len :: nframes !! A class that that is used to store simulation history data between file output - type(system_storage_frame), dimension(nframes) :: frame + type(storage_frame), dimension(nframes) :: frame contains procedure :: initialize => setup_initialize_storage end type swiftest_storage - abstract interface - subroutine abstract_accel(self, system, param, t, lbeg) import swiftest_body, swiftest_nbody_system, swiftest_parameters, DP class(swiftest_body), intent(inout) :: self !! Swiftest body data structure @@ -1240,6 +1241,12 @@ module subroutine util_copy_particle_info_arr(source, dest, idx) integer(I4B), dimension(:), intent(in), optional :: idx !! Optional array of indices to draw the source object end subroutine util_copy_particle_info_arr + module subroutine util_copy_store_system(self, system) + implicit none + class(storage_frame), intent(inout) :: self !! Swiftest storage frame object + class(swiftest_nbody_system), intent(in) :: system !! Swiftest n-body system object + end subroutine util_copy_store_system + module subroutine util_dealloc_body(self) implicit none class(swiftest_body), intent(inout) :: self diff --git a/src/util/util_copy.f90 b/src/util/util_copy.f90 index 2266396fb..fed2f0604 100644 --- a/src/util/util_copy.f90 +++ b/src/util/util_copy.f90 @@ -78,5 +78,16 @@ module subroutine util_copy_particle_info_arr(source, dest, idx) end subroutine util_copy_particle_info_arr + module subroutine util_copy_store_system(self, system) + !! author: David A. Minton + !! + !! Stores a snapshot of the nbody system so that later it can be retrieved for saving to file. + implicit none + class(storage_frame), intent(inout) :: self !! Swiftest storage frame object + class(swiftest_nbody_system), intent(in) :: system !! Swiftest n-body system object + + allocate(self%system, source=system) + + end subroutine util_copy_store_system end submodule s_util_copy