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

Commit

Permalink
Added file i/o parameters to the encounter history storage
Browse files Browse the repository at this point in the history
  • Loading branch information
daminton committed Dec 2, 2022
1 parent ad01e29 commit f7b3b38
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 23 deletions.
23 changes: 16 additions & 7 deletions src/encounter/encounter_io.f90
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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)
Expand Down Expand Up @@ -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" )
Expand Down
7 changes: 4 additions & 3 deletions src/io/io.f90
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
21 changes: 11 additions & 10 deletions src/modules/encounter_classes.f90
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
7 changes: 4 additions & 3 deletions src/modules/swiftest_classes.f90
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit f7b3b38

Please sign in to comment.