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

Commit

Permalink
Fixed a bunch of issues and now SyMBA info stuff is going into the Ne…
Browse files Browse the repository at this point in the history
…tCDF files properly
  • Loading branch information
daminton committed Aug 27, 2021
1 parent a634afd commit 00b40c5
Show file tree
Hide file tree
Showing 7 changed files with 191 additions and 77 deletions.
2 changes: 1 addition & 1 deletion src/fragmentation/fragmentation.f90
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ subroutine construct_temporary_system(tmpsys, tmpparam)
end where
lexclude(npl+1:(npl + nfrag)) = .true.
allocate(tmpparam, source=param)
call setup_construct_system(tmpsys, param)
call setup_construct_system(tmpsys, tmpparam)
call tmpsys%tp%setup(0, param)
deallocate(tmpsys%cb)
allocate(tmpsys%cb, source=cb)
Expand Down
21 changes: 10 additions & 11 deletions src/io/io.f90
Original file line number Diff line number Diff line change
Expand Up @@ -1811,7 +1811,6 @@ module subroutine io_write_frame_system(self, param)
character(len=STRMAX) :: errmsg
integer(I4B) :: iu = BINUNIT !! Unit number for the output file to write frame to
logical :: fileExists
type(netcdf_parameters) :: nciu

if (.not.lfirst .and. param%lenergy) call self%conservation_report(param, lterminal=.true.)

Expand Down Expand Up @@ -1861,17 +1860,17 @@ module subroutine io_write_frame_system(self, param)

select case(param%out_stat)
case('APPEND')
call nciu%open(param)
call param%nciu%open(param)
case('NEW', 'REPLACE', 'UNKNOWN')
call nciu%initialize(param)
call nciu%close(param)
call nciu%open(param)
call param%nciu%initialize(param)
call param%nciu%close(param)
call param%nciu%open(param)
end select
lfirst = .false.
else
call nciu%open(param)
call param%nciu%open(param)
end if
call self%write_hdr(nciu, param)
call self%write_hdr(param%nciu, param)
end if

if (param%lgr) then
Expand All @@ -1892,10 +1891,10 @@ module subroutine io_write_frame_system(self, param)

close(iu, err = 667, iomsg = errmsg)
else if ((param%out_type == NETCDF_FLOAT_TYPE) .or. (param%out_type == NETCDF_DOUBLE_TYPE)) then
call cb%write_frame(nciu, param)
call pl%write_frame(nciu, param)
call tp%write_frame(nciu, param)
call nciu%close(param)
call cb%write_frame(param%nciu, param)
call pl%write_frame(param%nciu, param)
call tp%write_frame(param%nciu, param)
call param%nciu%close(param)
end if

return
Expand Down
118 changes: 61 additions & 57 deletions src/modules/swiftest_classes.f90
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,64 @@ module swiftest_classes
implicit none
public


type :: netcdf_parameters
integer(I4B) :: out_type !! NetCDF output type (will be assigned either NF90_DOUBLE or NF90_FLOAT, depending on the user parameter)
integer(I4B) :: ncid !! NetCDF ID for the output file
integer(I4B) :: dimids(3) !! Dimensions of the NetCDF file
integer(I4B) :: time_dimid !! NetCDF ID for the time dimension
integer(I4B) :: id_dimid !! NetCDF ID for the particle id dimension
integer(I4B) :: str_dimid !! NetCDF ID for the character string dimension
integer(I4B) :: time_varid !! NetCDF ID for the time variable
integer(I4B) :: id_varid !! NetCDF ID for the particle name variable
integer(I4B) :: name_varid !! NetCDF ID for the namevariable
integer(I4B) :: ptype_varid !! NetCDF ID for the particle type variable
integer(I4B) :: npl_varid !! NetCDF ID for the number of active massive bodies variable
integer(I4B) :: ntp_varid !! NetCDF ID for the number of active test particles variable
integer(I4B) :: a_varid !! NetCDF ID for the semimajor axis variable
integer(I4B) :: e_varid !! NetCDF ID for the eccentricity variable
integer(I4B) :: inc_varid !! NetCDF ID for the inclination variable
integer(I4B) :: capom_varid !! NetCDF ID for the long. asc. node variable
integer(I4B) :: omega_varid !! NetCDF ID for the arg. periapsis variable
integer(I4B) :: capm_varid !! NetCDF ID for the mean anomaly variable
integer(I4B) :: xhx_varid !! NetCDF ID for the heliocentric position x variable
integer(I4B) :: xhy_varid !! NetCDF ID for the heliocentric position y variable
integer(I4B) :: xhz_varid !! NetCDF ID for the heliocentric position z variable
integer(I4B) :: vhx_varid !! NetCDF ID for the heliocentric velocity x variable
integer(I4B) :: vhy_varid !! NetCDF ID for the heliocentric velocity y variable
integer(I4B) :: vhz_varid !! NetCDF ID for the heliocentric velocity z variable
integer(I4B) :: Gmass_varid !! NetCDF ID for the mass variable
integer(I4B) :: rhill_varid !! NetCDF ID for the hill radius variable
integer(I4B) :: radius_varid !! NetCDF ID for the radius variable
integer(I4B) :: Ip1_varid !! NetCDF ID for the axis 1 principal moment of inertia variable
integer(I4B) :: Ip2_varid !! NetCDF ID for the axis 2 principal moment of inertia variable
integer(I4B) :: Ip3_varid !! NetCDF ID for the axis 3 principal moment of inertia variable
integer(I4B) :: rotx_varid !! NetCDF ID for the rotation x variable
integer(I4B) :: roty_varid !! NetCDF ID for the rotation y variable
integer(I4B) :: rotz_varid !! NetCDF ID for the rotation z variable
integer(I4B) :: k2_varid !! NetCDF ID for the Love number variable
integer(I4B) :: Q_varid !! NetCDF ID for the energy dissipation variable
integer(I4B) :: KE_orb_varid !! NetCDF ID for the system orbital kinetic energy variable
integer(I4B) :: KE_spin_varid !! NetCDF ID for the system spin kinetic energy variable
integer(I4B) :: PE_varid !! NetCDF ID for the system potential energy variable
integer(I4B) :: L_orbx_varid !! NetCDF ID for the system orbital angular momentum x variable
integer(I4B) :: L_orby_varid !! NetCDF ID for the system orbital angular momentum y variable
integer(I4B) :: L_orbz_varid !! NetCDF ID for the system orbital angular momentum z variable
integer(I4B) :: L_spinx_varid !! NetCDF ID for the system spin angular momentum x variable
integer(I4B) :: L_spiny_varid !! NetCDF ID for the system spin angular momentum y variable
integer(I4B) :: L_spinz_varid !! NetCDF ID for the system spin angular momentum z variable
integer(I4B) :: L_escapex_varid !! NetCDF ID for the escaped angular momentum x variable
integer(I4B) :: L_escapey_varid !! NetCDF ID for the escaped angular momentum x variable
integer(I4B) :: L_escapez_varid !! NetCDF ID for the escaped angular momentum x variable
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
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
procedure :: open => netcdf_open !! Opens a NetCDF file
end type netcdf_parameters

!********************************************************************************************************************************
! swiftest_parameters class definitions
!********************************************************************************************************************************
Expand Down Expand Up @@ -77,69 +135,15 @@ module swiftest_classes
logical :: lgr = .false. !! Turn on GR
logical :: lyarkovsky = .false. !! Turn on Yarkovsky effect
logical :: lyorp = .false. !! Turn on YORP effect

class(netcdf_parameters), allocatable :: nciu !! Object containing NetCDF parameters
contains
procedure :: reader => io_param_reader
procedure :: writer => io_param_writer
procedure :: dump => io_dump_param
procedure :: read_in => io_read_in_param
end type swiftest_parameters

type :: netcdf_parameters
integer(I4B) :: out_type !! NetCDF output type (will be assigned either NF90_DOUBLE or NF90_FLOAT, depending on the user parameter)
integer(I4B) :: ncid !! NetCDF ID for the output file
integer(I4B) :: dimids(3) !! Dimensions of the NetCDF file
integer(I4B) :: time_dimid !! NetCDF ID for the time dimension
integer(I4B) :: id_dimid !! NetCDF ID for the particle id dimension
integer(I4B) :: str_dimid !! NetCDF ID for the character string dimension
integer(I4B) :: time_varid !! NetCDF ID for the time variable
integer(I4B) :: id_varid !! NetCDF ID for the particle name variable
integer(I4B) :: name_varid !! NetCDF ID for the namevariable
integer(I4B) :: ptype_varid !! NetCDF ID for the particle type variable
integer(I4B) :: npl_varid !! NetCDF ID for the number of active massive bodies variable
integer(I4B) :: ntp_varid !! NetCDF ID for the number of active test particles variable
integer(I4B) :: a_varid !! NetCDF ID for the semimajor axis variable
integer(I4B) :: e_varid !! NetCDF ID for the eccentricity variable
integer(I4B) :: inc_varid !! NetCDF ID for the inclination variable
integer(I4B) :: capom_varid !! NetCDF ID for the long. asc. node variable
integer(I4B) :: omega_varid !! NetCDF ID for the arg. periapsis variable
integer(I4B) :: capm_varid !! NetCDF ID for the mean anomaly variable
integer(I4B) :: xhx_varid !! NetCDF ID for the heliocentric position x variable
integer(I4B) :: xhy_varid !! NetCDF ID for the heliocentric position y variable
integer(I4B) :: xhz_varid !! NetCDF ID for the heliocentric position z variable
integer(I4B) :: vhx_varid !! NetCDF ID for the heliocentric velocity x variable
integer(I4B) :: vhy_varid !! NetCDF ID for the heliocentric velocity y variable
integer(I4B) :: vhz_varid !! NetCDF ID for the heliocentric velocity z variable
integer(I4B) :: Gmass_varid !! NetCDF ID for the mass variable
integer(I4B) :: rhill_varid !! NetCDF ID for the hill radius variable
integer(I4B) :: radius_varid !! NetCDF ID for the radius variable
integer(I4B) :: Ip1_varid !! NetCDF ID for the axis 1 principal moment of inertia variable
integer(I4B) :: Ip2_varid !! NetCDF ID for the axis 2 principal moment of inertia variable
integer(I4B) :: Ip3_varid !! NetCDF ID for the axis 3 principal moment of inertia variable
integer(I4B) :: rotx_varid !! NetCDF ID for the rotation x variable
integer(I4B) :: roty_varid !! NetCDF ID for the rotation y variable
integer(I4B) :: rotz_varid !! NetCDF ID for the rotation z variable
integer(I4B) :: k2_varid !! NetCDF ID for the Love number variable
integer(I4B) :: Q_varid !! NetCDF ID for the energy dissipation variable
integer(I4B) :: KE_orb_varid !! NetCDF ID for the system orbital kinetic energy variable
integer(I4B) :: KE_spin_varid !! NetCDF ID for the system spin kinetic energy variable
integer(I4B) :: PE_varid !! NetCDF ID for the system potential energy variable
integer(I4B) :: L_orbx_varid !! NetCDF ID for the system orbital angular momentum x variable
integer(I4B) :: L_orby_varid !! NetCDF ID for the system orbital angular momentum y variable
integer(I4B) :: L_orbz_varid !! NetCDF ID for the system orbital angular momentum z variable
integer(I4B) :: L_spinx_varid !! NetCDF ID for the system spin angular momentum x variable
integer(I4B) :: L_spiny_varid !! NetCDF ID for the system spin angular momentum y variable
integer(I4B) :: L_spinz_varid !! NetCDF ID for the system spin angular momentum z variable
integer(I4B) :: L_escapex_varid !! NetCDF ID for the escaped angular momentum x variable
integer(I4B) :: L_escapey_varid !! NetCDF ID for the escaped angular momentum x variable
integer(I4B) :: L_escapez_varid !! NetCDF ID for the escaped angular momentum x variable
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
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
procedure :: open => netcdf_open !! Opens a NetCDF file
end type netcdf_parameters

!********************************************************************************************************************************
! swiftest_swiftest_particle_info class definitions and method interfaces
Expand Down Expand Up @@ -986,7 +990,7 @@ end subroutine setup_body
module subroutine setup_construct_system(system, param)
implicit none
class(swiftest_nbody_system), allocatable, intent(inout) :: system !! Swiftest 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_construct_system

module subroutine setup_encounter(self, n)
Expand Down
21 changes: 19 additions & 2 deletions src/modules/symba_classes.f90
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ module symba_classes
real(DP) :: R0 = 0.0_DP !! Initial radius of the central body
real(DP) :: dR = 0.0_DP !! Change in the radius of the central body
contains
procedure :: write_frame_netcdf => symba_netcdf_write_frame_cb !! I/O routine for writing out a single frame of time-series data for all bodies in the system in NetCDF format
end type symba_cb

!********************************************************************************************************************************
Expand Down Expand Up @@ -119,7 +120,6 @@ module symba_classes
procedure :: rearrange => symba_util_sort_rearrange_pl !! Rearranges the order of array elements of body based on an input index array. Used in sorting methods
procedure :: spill => symba_util_spill_pl !! "Spills" bodies from one object to another depending on the results of a mask (uses the PACK intrinsic)
procedure :: write_frame_netcdf => symba_netcdf_write_frame_pl !! I/O routine for writing out a single frame of time-series data for all bodies in the system in NetCDF format
generic :: write_frame => write_frame_netcdf
end type symba_pl

type, extends(symba_pl) :: symba_merger
Expand Down Expand Up @@ -149,6 +149,7 @@ module symba_classes
procedure :: sort => symba_util_sort_tp !! Sorts body arrays by a sortable componen
procedure :: rearrange => symba_util_sort_rearrange_tp !! Rearranges the order of array elements of body based on an input index array. Used in sorting methods
procedure :: spill => symba_util_spill_tp !! "Spills" bodies from one object to another depending on the results of a mask (uses the PACK intrinsic)
procedure :: write_frame_netcdf => symba_netcdf_write_frame_tp !! I/O routine for writing out a single frame of time-series data for all bodies in the system in NetCDF format
end type symba_tp

!********************************************************************************************************************************
Expand Down Expand Up @@ -472,14 +473,30 @@ module subroutine symba_netcdf_open(self, param)
class(swiftest_parameters), intent(in) :: param !! Current run configuration parameters
end subroutine symba_netcdf_open

module subroutine symba_netcdf_write_frame_cb(self, iu, param)
use swiftest_classes, only : swiftest_parameters, netcdf_parameters
implicit none
class(symba_cb), intent(in) :: self !! Symba central body object
class(netcdf_parameters), intent(inout) :: iu !! Parameters used to identify a particular NetCDF dataset
class(swiftest_parameters), intent(in) :: param !! Current run configuration parameters
end subroutine symba_netcdf_write_frame_cb

module subroutine symba_netcdf_write_frame_pl(self, iu, param)
use swiftest_classes, only : swiftest_parameters, netcdf_parameters
implicit none
class(symba_pl), intent(in) :: self !! Swiftest particle object
class(symba_pl), intent(in) :: self !! Symba massive body object
class(netcdf_parameters), intent(inout) :: iu !! Parameters used to identify a particular NetCDF dataset
class(swiftest_parameters), intent(in) :: param !! Current run configuration parameters
end subroutine symba_netcdf_write_frame_pl

module subroutine symba_netcdf_write_frame_tp(self, iu, param)
use swiftest_classes, only : swiftest_parameters, netcdf_parameters
implicit none
class(symba_tp), intent(in) :: self !! SyMBA test particle object
class(netcdf_parameters), intent(inout) :: iu !! Parameters used to identify a particular NetCDF dataset
class(swiftest_parameters), intent(in) :: param !! Current run configuration parameters
end subroutine symba_netcdf_write_frame_tp

module subroutine symba_setup_initialize_particle_info_system(self, param)
use swiftest_classes, only : swiftest_parameters
implicit none
Expand Down
8 changes: 5 additions & 3 deletions src/setup/setup.f90
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module subroutine setup_construct_system(system, param)
implicit none
! Arguments
class(swiftest_nbody_system), allocatable, intent(inout) :: system !! Swiftest system object
class(swiftest_parameters), intent(in) :: param !! Swiftest parameters
class(swiftest_parameters), intent(inout) :: param !! Swiftest parameters

select case(param%integrator)
case (BS)
Expand Down Expand Up @@ -69,9 +69,11 @@ module subroutine setup_construct_system(system, param)

select type(system)
class is (symba_nbody_system)
allocate(symba_particle_info :: system%cb%info)
if (.not.allocated(system%cb%info)) allocate(symba_particle_info :: system%cb%info)
if (.not.allocated(param%nciu)) allocate(symba_netcdf_parameters :: param%nciu)
class default
allocate(swiftest_particle_info :: system%cb%info)
if (.not.allocated(system%cb%info)) allocate(swiftest_particle_info :: system%cb%info)
if (.not.allocated(param%nciu)) allocate(netcdf_parameters :: param%nciu)
end select

return
Expand Down
Loading

0 comments on commit 00b40c5

Please sign in to comment.