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

Commit

Permalink
Consolidated NetCDF and particle info into main Swiftest class. Info …
Browse files Browse the repository at this point in the history
…still gets corrupted after some amount of time.
  • Loading branch information
daminton committed Aug 28, 2021
1 parent b92eb1f commit 4c2152f
Show file tree
Hide file tree
Showing 17 changed files with 310 additions and 1,046 deletions.
6 changes: 3 additions & 3 deletions examples/symba_mars_disk/param.in
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
!Parameter file for the SyMBA-RINGMOONS test
T0 0.0
TSTOP 6000.0
TSTOP 60000.0
DT 600.0
CB_IN cb.in
PL_IN mars.in
TP_IN tp.in
IN_TYPE ASCII
ISTEP_OUT 1
ISTEP_DUMP 1
ISTEP_OUT 10
ISTEP_DUMP 10
!BIN_OUT bin.dat
!OUT_TYPE REAL8
BIN_OUT bin.nc
Expand Down
453 changes: 35 additions & 418 deletions examples/symba_mars_disk/testnetcdf.ipynb

Large diffs are not rendered by default.

10 changes: 9 additions & 1 deletion src/io/io.f90
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ module subroutine io_dump_particle_info(self, iu)

write(iu, err = 667, iomsg = errmsg) self%name
write(iu, err = 667, iomsg = errmsg) self%particle_type
write(iu, err = 667, iomsg = errmsg) self%origin_type
write(iu, err = 667, iomsg = errmsg) self%origin_time
write(iu, err = 667, iomsg = errmsg) self%origin_xh(:)
write(iu, err = 667, iomsg = errmsg) self%origin_vh(:)

return

Expand Down Expand Up @@ -1416,6 +1420,10 @@ module subroutine io_read_in_particle_info(self, iu)

read(iu, err = 667, iomsg = errmsg) self%name
read(iu, err = 667, iomsg = errmsg) self%particle_type
read(iu, err = 667, iomsg = errmsg) self%origin_type
read(iu, err = 667, iomsg = errmsg) self%origin_time
read(iu, err = 667, iomsg = errmsg) self%origin_xh(:)
read(iu, err = 667, iomsg = errmsg) self%origin_vh(:)

return

Expand All @@ -1438,7 +1446,7 @@ module subroutine io_read_particle_info_system(self, param)
integer(I4B) :: i, id, idx
logical :: lmatch
character(STRMAX) :: errmsg
class(swiftest_particle_info), allocatable :: tmpinfo
type(swiftest_particle_info), allocatable :: tmpinfo

open(unit = LUN, file = param%particle_out, status = 'OLD', form = 'UNFORMATTED', err = 667, iomsg = errmsg)

Expand Down
37 changes: 25 additions & 12 deletions src/modules/swiftest_classes.f90
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,15 @@ module swiftest_classes
integer(I4B) :: Ecollisions_varid !! NetCDF ID for the energy lost in collisions variable
integer(I4B) :: Euntracked_varid !! NetCDF ID for the energy that is untracked due to loss (untracked potential energy due to mergers and body energy for escaped bodies)
integer(I4B) :: GMescape_varid !! NetCDF ID for the G*Mass of bodies that escape the system
logical :: ltrack_origin = .false. !! Indicate whether to track particle origin (SyMBA with Fragmentation)
integer(I4B) :: origin_type_varid !! NetCDF ID for the origin type
integer(I4B) :: origin_time_varid !! NetCDF ID for the origin type
integer(I4B) :: origin_xhx_varid !! NetCDF ID for the origin xh x component
integer(I4B) :: origin_xhy_varid !! NetCDF ID for the origin xh y component
integer(I4B) :: origin_xhz_varid !! NetCDF ID for the origin xh z component
integer(I4B) :: origin_vhx_varid !! NetCDF ID for the origin xh x component
integer(I4B) :: origin_vhy_varid !! NetCDF ID for the origin xh y component
integer(I4B) :: origin_vhz_varid !! NetCDF ID for the origin xh z component
contains
procedure :: close => netcdf_close !! Closes an open NetCDF file
procedure :: initialize => netcdf_initialize_output !! Initialize a set of parameters used to identify a NetCDF output object
Expand Down Expand Up @@ -136,7 +145,7 @@ module swiftest_classes
logical :: lyarkovsky = .false. !! Turn on Yarkovsky effect
logical :: lyorp = .false. !! Turn on YORP effect

class(netcdf_parameters), allocatable :: nciu !! Object containing NetCDF parameters
type(netcdf_parameters) :: nciu !! Object containing NetCDF parameters
contains
procedure :: reader => io_param_reader
procedure :: writer => io_param_writer
Expand All @@ -153,6 +162,10 @@ module swiftest_classes
type :: swiftest_particle_info
character(len=NAMELEN) :: name !! Non-unique name
character(len=NAMELEN) :: particle_type !! String containing a description of the particle type (e.g. Central Body, Massive Body, Test Particle)
character(len=NAMELEN) :: origin_type !! String containing a description of the origin of the particle (e.g. Initial Conditions, Supercatastrophic, Disruption, etc.)
real(DP) :: origin_time !! The time of the particle's formation
real(DP), dimension(NDIM) :: origin_xh !! The heliocentric distance vector at the time of the particle's formation
real(DP), dimension(NDIM) :: origin_vh !! The heliocentric velocity vector at the time of the particle's formation
contains
procedure :: dump => io_dump_particle_info !! Dumps contents of particle information to file
procedure :: read_in => io_read_in_particle_info !! Read in a particle information object from an open file
Expand All @@ -176,7 +189,7 @@ module swiftest_classes
!********************************************************************************************************************************
!> A concrete lass for the central body in a Swiftest simulation
type, abstract, extends(swiftest_base) :: swiftest_cb
class(swiftest_particle_info), allocatable :: info !! Particle metadata information
type(swiftest_particle_info) :: info !! Particle metadata information
integer(I4B) :: id = 0 !! External identifier (unique)
real(DP) :: mass = 0.0_DP !! Central body mass (units MU)
real(DP) :: Gmass = 0.0_DP !! Central mass gravitational term G * mass (units GU * MU)
Expand Down Expand Up @@ -215,7 +228,7 @@ module swiftest_classes
!! Superclass that defines the generic elements of a Swiftest particle
logical :: lfirst = .true. !! Run the current step as a first
integer(I4B) :: nbody = 0 !! Number of bodies
class(swiftest_particle_info), dimension(:), allocatable :: info !! Particle metadata information
type(swiftest_particle_info), dimension(:), allocatable :: info !! Particle metadata information
integer(I4B), dimension(:), allocatable :: id !! External identifier (unique)
integer(I4B), dimension(:), allocatable :: status !! An integrator-specific status indicator
logical, dimension(:), allocatable :: ldiscard !! Body should be discarded
Expand Down Expand Up @@ -1002,7 +1015,7 @@ end subroutine setup_encounter
module subroutine setup_initialize_particle_info_system(self, param)
implicit none
class(swiftest_nbody_system), intent(inout) :: self !! Swiftest nbody system object
class(swiftest_parameters), intent(in) :: param !! Current run configuration parameters
class(swiftest_parameters), intent(inout) :: param !! Current run configuration parameters
end subroutine setup_initialize_particle_info_system

module subroutine setup_initialize_system(self, param)
Expand Down Expand Up @@ -1084,8 +1097,8 @@ end subroutine util_append_arr_I4B

module subroutine util_append_arr_info(arr, source, nold, nsrc, lsource_mask)
implicit none
class(swiftest_particle_info), dimension(:), allocatable, intent(inout) :: arr !! Destination array
class(swiftest_particle_info), dimension(:), allocatable, intent(in) :: source !! Array to append
type(swiftest_particle_info), dimension(:), allocatable, intent(inout) :: arr !! Destination array
type(swiftest_particle_info), dimension(:), allocatable, intent(in) :: source !! Array to append
integer(I4B), intent(in) :: nold, nsrc !! Extend of the old array and the source array, respectively
logical, dimension(:), intent(in) :: lsource_mask !! Logical mask indicating which elements to append to
end subroutine util_append_arr_info
Expand Down Expand Up @@ -1253,8 +1266,8 @@ end subroutine util_fill_arr_I4B

module subroutine util_fill_arr_info(keeps, inserts, lfill_list)
implicit none
class(swiftest_particle_info), dimension(:), allocatable, intent(inout) :: keeps !! Array of values to keep
class(swiftest_particle_info), dimension(:), allocatable, intent(in) :: inserts !! Array of values to insert into keep
type(swiftest_particle_info), dimension(:), allocatable, intent(inout) :: keeps !! Array of values to keep
type(swiftest_particle_info), dimension(:), allocatable, intent(in) :: inserts !! Array of values to insert into keep
logical, dimension(:), intent(in) :: lfill_list !! Logical array of bodies to merge into the keeps
end subroutine util_fill_arr_info

Expand Down Expand Up @@ -1322,7 +1335,7 @@ end subroutine util_resize_arr_I4B

module subroutine util_resize_arr_info(arr, nnew)
implicit none
class(swiftest_particle_info), dimension(:), allocatable, intent(inout) :: arr !! Array to resize
type(swiftest_particle_info), dimension(:), allocatable, intent(inout) :: arr !! Array to resize
integer(I4B), intent(in) :: nnew !! New size
end subroutine util_resize_arr_info

Expand Down Expand Up @@ -1506,7 +1519,7 @@ end subroutine util_sort_rearrange_arr_I4B

module subroutine util_sort_rearrange_arr_info(arr, ind, n)
implicit none
class(swiftest_particle_info), dimension(:), allocatable, intent(inout) :: arr !! Destination array
type(swiftest_particle_info), dimension(:), allocatable, intent(inout) :: arr !! Destination array
integer(I4B), dimension(:), intent(in) :: ind !! Index to rearrange against
integer(I4B), intent(in) :: n !! Number of elements in arr and ind to rearrange
end subroutine util_sort_rearrange_arr_info
Expand Down Expand Up @@ -1603,8 +1616,8 @@ end subroutine util_spill_arr_I8B

module subroutine util_spill_arr_info(keeps, discards, lspill_list, ldestructive)
implicit none
class(swiftest_particle_info), dimension(:), allocatable, intent(inout) :: keeps !! Array of values to keep
class(swiftest_particle_info), dimension(:), allocatable, intent(inout) :: discards !! Array of discards
type(swiftest_particle_info), dimension(:), allocatable, intent(inout) :: keeps !! Array of values to keep
type(swiftest_particle_info), dimension(:), allocatable, intent(inout) :: discards !! Array of discards
logical, dimension(:), intent(in) :: lspill_list !! Logical array of bodies to spill into the discardss
logical, intent(in) :: ldestructive !! Logical flag indicating whether or not this operation should alter the keeps array or not
end subroutine util_spill_arr_info
Expand Down
10 changes: 10 additions & 0 deletions src/modules/swiftest_globals.f90
Original file line number Diff line number Diff line change
Expand Up @@ -181,4 +181,14 @@ module swiftest_globals
character(*), parameter :: ECOLLISIONS_VARNAME = "Ecollisions" !! NetCDF name of the escaped angular momentum y variable
character(*), parameter :: EUNTRACKED_VARNAME = "Euntracked" !! NetCDF name of the energy that is untracked due to loss (untracked potential energy due to mergers and body energy for escaped bodies)
character(*), parameter :: GMESCAPE_VARNAME = "GMescape" !! NetCDF name of the G*Mass of bodies that escape the system
character(*), parameter :: ORIGIN_TYPE_VARNAME = "origin_type"
character(*), parameter :: ORIGIN_TIME_VARNAME = "origin_time"
character(*), parameter :: ORIGIN_XHX_VARNAME = "origin_xhx"
character(*), parameter :: ORIGIN_XHY_VARNAME = "origin_xhy"
character(*), parameter :: ORIGIN_XHZ_VARNAME = "origin_xhz"
character(*), parameter :: ORIGIN_VHX_VARNAME = "origin_vhx"
character(*), parameter :: ORIGIN_VHY_VARNAME = "origin_vhy"
character(*), parameter :: ORIGIN_VHZ_VARNAME = "origin_vhz"
character(*), parameter :: PL_TINY_TYPE_NAME = "Semi-Interacting Massive Body"

end module swiftest_globals
Loading

0 comments on commit 4c2152f

Please sign in to comment.