From f7b3b38d0b2e6906dcca48f2b4900dda181a13d1 Mon Sep 17 00:00:00 2001 From: David A Minton Date: Fri, 2 Dec 2022 15:45:08 -0500 Subject: [PATCH] Added file i/o parameters to the encounter history storage --- src/encounter/encounter_io.f90 | 23 ++++++++++++++++------- src/io/io.f90 | 7 ++++--- src/modules/encounter_classes.f90 | 21 +++++++++++---------- src/modules/swiftest_classes.f90 | 7 ++++--- 4 files changed, 35 insertions(+), 23 deletions(-) diff --git a/src/encounter/encounter_io.f90 b/src/encounter/encounter_io.f90 index 4a53e2db6..9ab5947b1 100644 --- a/src/encounter/encounter_io.f90 +++ b/src/encounter/encounter_io.f90 @@ -12,14 +12,23 @@ use netcdf contains - module subroutine encounter_io_dump_storage_list(self, param) + module subroutine encounter_io_dump_storage_list(self, param, system) !! author: David A. Minton !! !! Dumps the time history of an encounter to file. implicit none ! Arguments - class(encounter_storage(*)), intent(inout) :: self !! Encounter storage object - class(swiftest_parameters), intent(inout) :: param !! Current run configuration parameters + class(encounter_storage(*)), intent(inout) :: self !! Encounter storage object + class(swiftest_parameters), intent(inout) :: param !! Current run configuration parameters + class(swiftest_nbody_system), intent(in), optional :: system !! Swiftest nbody system object + ! Internals + + ! Most of this is just temporary test code just to get something working. Eventually this should get cleaned up. + + + + + return end subroutine encounter_io_dump_storage_list @@ -44,13 +53,13 @@ module subroutine encounter_io_initialize_output(self, param) sfill = ieee_value(sfill, IEEE_QUIET_NAN) ! Check if the file exists, and if it does, delete it - inquire(file=param%outfile, exist=fileExists) + inquire(file=self%enc_file, exist=fileExists) if (fileExists) then - open(unit=LUN, file=self%outfile, status="old", err=667, iomsg=errmsg) + open(unit=LUN, file=self%enc_file, status="old", err=667, iomsg=errmsg) close(unit=LUN, status="delete") end if - call check( nf90_create(self%outfile, NF90_NETCDF4, self%ncid), "encounter_io_initialize_output nf90_create" ) + call check( nf90_create(self%enc_file, NF90_NETCDF4, self%ncid), "encounter_io_initialize_output nf90_create" ) call check( nf90_def_dim(self%ncid, ENCID_DIMNAME, NF90_UNLIMITED, self%encid_dimid), "encounter_io_initialize_output nf90_def_dim encid_dimid" ) call check( nf90_def_dim(self%ncid, STR_DIMNAME, NAMELEN, self%str_dimid), "encounter_io_initialize_output nf90_def_dim str_dimid" ) ! Dimension for string variables (aka character arrays) @@ -109,7 +118,7 @@ module subroutine encounter_io_open_file(self, param, readonly) end if write(errmsg,*) "encounter_io_open_file nf90_open ",trim(adjustl(param%outfile)) - call check( nf90_open(self%outfile, mode, self%ncid), errmsg) + call check( nf90_open(self%enc_file, mode, self%ncid), errmsg) call check( nf90_inq_dimid(self%ncid, TIME_DIMNAME, self%time_dimid), "encounter_io_open_file nf90_inq_dimid time_dimid" ) call check( nf90_inq_dimid(self%ncid, ENCID_DIMNAME, self%encid_dimid), "encounter_io_open_file nf90_inq_dimid encid_dimid" ) diff --git a/src/io/io.f90 b/src/io/io.f90 index e8936d018..85a8d42b3 100644 --- a/src/io/io.f90 +++ b/src/io/io.f90 @@ -270,7 +270,7 @@ module subroutine io_dump_system(self, param) end subroutine io_dump_system - module subroutine io_dump_storage(self, param) + module subroutine io_dump_storage(self, param, system) !! author: David A. Minton !! !! Dumps the time history of the simulation to file. Each time it writes a frame to file, it deallocates the system @@ -279,8 +279,9 @@ module subroutine io_dump_storage(self, param) !! cadence is not divisible by the total number of loops). implicit none ! Arguments - class(swiftest_storage(*)), intent(inout) :: self !! Swiftest simulation history storage object - class(swiftest_parameters), intent(inout) :: param !! Current run configuration parameters + class(swiftest_storage(*)), intent(inout) :: self !! Swiftest simulation history storage object + class(swiftest_parameters), intent(inout) :: param !! Current run configuration parameters + class(swiftest_nbody_system), intent(in), optional :: system !! Swiftest nbody system object (Note, only here so that it can be used in the extended type for encounter_storage) ! Internals integer(I4B) :: i integer(I8B) :: iloop_start diff --git a/src/modules/encounter_classes.f90 b/src/modules/encounter_classes.f90 index 49678f388..b3d913f02 100644 --- a/src/modules/encounter_classes.f90 +++ b/src/modules/encounter_classes.f90 @@ -48,12 +48,6 @@ module encounter_classes final :: encounter_util_final_list !! Finalize the encounter list - deallocates all allocatables end type encounter_list - type, extends(swiftest_storage) :: encounter_storage - !! A class that that is used to store simulation history data between file output - contains - procedure :: dump => encounter_io_dump_storage_list - end type encounter_storage - !! NetCDF dimension and variable names for the enounter save object character(*), parameter :: ENCID_DIMNAME = "encounter" !! The index of the encountering pair in the encounter list character(*), parameter :: COLLIDER_DIMNAME = "collider" !! Dimension that defines the colliding bodies (bodies 1 and 2 are at dimension coordinates 1 and 2, respectively) @@ -69,12 +63,18 @@ module encounter_classes integer(I4B) :: encid_varid !! NetCDF ID for the encounter pair index variable integer(I4B) :: nenc_varid !! NetCDF ID for the number of encounters variable integer(I4B) :: level_varid !! NetCDF ID for the recursion level variable - contains procedure :: initialize => encounter_io_initialize_output !! Initialize a set of parameters used to identify a NetCDF output object procedure :: open => encounter_io_open_file !! Opens a NetCDF file end type encounter_io_parameters + type, extends(swiftest_storage) :: encounter_storage + !! A class that that is used to store simulation history data between file output + type(encounter_io_parameters) :: nciu + contains + procedure :: dump => encounter_io_dump_storage_list + end type encounter_storage + type encounter_bounding_box_1D integer(I4B) :: n !! Number of bodies with extents integer(I4B), dimension(:), allocatable :: ind !! Sorted minimum/maximum extent indices (value > n indicates an ending index) @@ -207,10 +207,11 @@ module subroutine encounter_check_sweep_aabb_single_list(self, n, x, v, renc, dt logical, dimension(:), allocatable, intent(out) :: lvdotr !! Logical array indicating which pairs are approaching end subroutine encounter_check_sweep_aabb_single_list - module subroutine encounter_io_dump_storage_list(self, param) + module subroutine encounter_io_dump_storage_list(self, param, system) implicit none - class(encounter_storage(*)), intent(inout) :: self !! Encounter storage object - class(swiftest_parameters), intent(inout) :: param !! Current run configuration parameters + class(encounter_storage(*)), intent(inout) :: self !! Encounter storage object + class(swiftest_parameters), intent(inout) :: param !! Current run configuration parameters + class(swiftest_nbody_system), intent(in), optional :: system !! Swiftest nbody system object end subroutine encounter_io_dump_storage_list module subroutine encounter_io_initialize_output(self, param) diff --git a/src/modules/swiftest_classes.f90 b/src/modules/swiftest_classes.f90 index fe35c647c..fa0bdf865 100644 --- a/src/modules/swiftest_classes.f90 +++ b/src/modules/swiftest_classes.f90 @@ -632,10 +632,11 @@ module subroutine io_dump_system(self, param) class(swiftest_parameters), intent(inout) :: param !! Current run configuration parameters end subroutine io_dump_system - module subroutine io_dump_storage(self, param) + module subroutine io_dump_storage(self, param, system) implicit none - class(swiftest_storage(*)), intent(inout) :: self !! Swiftest simulation history storage object - class(swiftest_parameters), intent(inout) :: param !! Current run configuration parameters + class(swiftest_storage(*)), intent(inout) :: self !! Swiftest simulation history storage object + class(swiftest_parameters), intent(inout) :: param !! Current run configuration parameters + class(swiftest_nbody_system), intent(in), optional :: system !! Swiftest nbody system object end subroutine io_dump_storage module subroutine io_get_args(integrator, param_file_name, display_style)