From 910e8e946e99c6c049d4cba73ca0ac99686d5ec0 Mon Sep 17 00:00:00 2001 From: David A Minton Date: Thu, 1 Dec 2022 16:01:53 -0500 Subject: [PATCH 01/65] Minor formatting tweak --- src/modules/swiftest_classes.f90 | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/modules/swiftest_classes.f90 b/src/modules/swiftest_classes.f90 index 33d5aa79e..a7d3965c5 100644 --- a/src/modules/swiftest_classes.f90 +++ b/src/modules/swiftest_classes.f90 @@ -1793,17 +1793,17 @@ end subroutine util_spill_body module subroutine util_spill_pl(self, discards, lspill_list, ldestructive) implicit none - class(swiftest_pl), intent(inout) :: self !! Swiftest massive body object - class(swiftest_body), intent(inout) :: discards !! Discarded object - logical, dimension(:), intent(in) :: lspill_list !! Logical array of bodies to spill into the discards + class(swiftest_pl), intent(inout) :: self !! Swiftest massive body object + class(swiftest_body), intent(inout) :: discards !! Discarded object + logical, dimension(:), intent(in) :: lspill_list !! Logical array of bodies to spill into the discards logical, intent(in) :: ldestructive !! Logical flag indicating whether or not this operation should alter the keeps array or not end subroutine util_spill_pl module subroutine util_spill_tp(self, discards, lspill_list, ldestructive) implicit none - class(swiftest_tp), intent(inout) :: self !! Swiftest test particle object - class(swiftest_body), intent(inout) :: discards !! Discarded object - logical, dimension(:), intent(in) :: lspill_list !! Logical array of bodies to spill into the discards + class(swiftest_tp), intent(inout) :: self !! Swiftest test particle object + class(swiftest_body), intent(inout) :: discards !! Discarded object + logical, dimension(:), intent(in) :: lspill_list !! Logical array of bodies to spill into the discards logical, intent(in) :: ldestructive !! Logical flag indicating whether or not this operation should alter the keeps array or not end subroutine util_spill_tp From 1dbe3369d48a570fb11cb1beb6dbc330645fbb78 Mon Sep 17 00:00:00 2001 From: David A Minton Date: Thu, 1 Dec 2022 16:11:45 -0500 Subject: [PATCH 02/65] Switched frame counter variables to I4B to simplify the code, as it really doesn't need to be I8B --- src/io/io.f90 | 11 ++++++----- src/main/swiftest_driver.f90 | 22 +++++++++++----------- src/modules/swiftest_classes.f90 | 4 ++-- src/netcdf/netcdf.f90 | 8 ++++---- 4 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/io/io.f90 b/src/io/io.f90 index 7ee5b9cbd..ce17cdadf 100644 --- a/src/io/io.f90 +++ b/src/io/io.f90 @@ -178,7 +178,7 @@ module subroutine io_conservation_report(self, param, lterminal) if (abs(system%Mtot_error) > 100 * epsilon(system%Mtot_error)) then write(*,*) "Severe error! Mass not conserved! Halting!" ! Save the frame of data to the bin file in the slot just after the present one for diagnostics - param%ioutput = param%ioutput + 1_I8B + param%ioutput = param%ioutput + 1 call self%write_frame(param%nciu, param) call param%nciu%close() call util_exit(FAILURE) @@ -282,12 +282,13 @@ module subroutine io_dump_system_storage(self, param) class(swiftest_storage(*)), intent(inout) :: self !! Swiftest simulation history storage object class(swiftest_parameters), intent(inout) :: param !! Current run configuration parameters ! Internals - integer(I8B) :: i, iloop_start + integer(I4B) :: i + integer(I8B) :: iloop_start - iloop_start = param%iloop - param%istep_out * param%dump_cadence + 1_I8B - do i = 1_I8B, param%dump_cadence + iloop_start = param%iloop - int(param%istep_out * param%dump_cadence + 1, kind=I8B) + do i = 1, param%dump_cadence if (allocated(self%frame(i)%system)) then - param%ioutput = int(iloop_start / param%istep_out, kind=I8B) + i + param%ioutput = int(iloop_start / param%istep_out, kind=I4B) + i call self%frame(i)%system%write_frame(param) deallocate(self%frame(i)%system) end if diff --git a/src/main/swiftest_driver.f90 b/src/main/swiftest_driver.f90 index a9af0cc71..b14abec80 100644 --- a/src/main/swiftest_driver.f90 +++ b/src/main/swiftest_driver.f90 @@ -18,16 +18,16 @@ program swiftest_driver use swiftest implicit none - class(swiftest_nbody_system), allocatable :: nbody_system !! Polymorphic object containing the nbody system to be integrated - class(swiftest_parameters), allocatable :: param !! Run configuration parameters - character(len=:), allocatable :: integrator !! Integrator type code (see swiftest_globals for symbolic names) - character(len=:),allocatable :: param_file_name !! Name of the file containing user-defined parameters - character(len=:), allocatable :: display_style !! Style of the output display {"STANDARD", "COMPACT", "PROGRESS"}). Default is "STANDARD" - integer(I8B) :: idump !! Dump cadence counter - integer(I8B) :: iout !! Output cadence counter - integer(I8B) :: istart !! Starting index for loop counter - integer(I8B) :: nloops !! Number of steps to take in the simulation - integer(I8B) :: iframe !! System history frame cindex + class(swiftest_nbody_system), allocatable :: nbody_system !! Polymorphic object containing the nbody system to be integrated + class(swiftest_parameters), allocatable :: param !! Run configuration parameters + character(len=:), allocatable :: integrator !! Integrator type code (see swiftest_globals for symbolic names) + character(len=:),allocatable :: param_file_name !! Name of the file containing user-defined parameters + character(len=:), allocatable :: display_style !! Style of the output display {"STANDARD", "COMPACT", "PROGRESS"}). Default is "STANDARD" + integer(I8B) :: istart !! Starting index for loop counter + integer(I8B) :: nloops !! Number of steps to take in the simulation + integer(I4B) :: iout !! Output cadence counter + integer(I4B) :: idump !! Dump cadence counter + integer(I4B) :: iframe !! System history frame cindex type(walltimer) :: integration_timer !! Object used for computing elapsed wall time real(DP) :: tfrac type(progress_bar) :: pbar !! Object used to print out a progress bar @@ -83,7 +83,7 @@ program swiftest_driver iout = istep_out nloops = ceiling((tstop - t0) / dt, kind=I8B) istart = ceiling((tstart - t0) / dt + 1, kind=I8B) - ioutput = int(istart / istep_out, kind=I8B) + ioutput = int(istart / istep_out, kind=I4B) ! Set up system storage for intermittent file dumps if (dump_cadence == 0) dump_cadence = ceiling(nloops / (1.0_DP * istep_out), kind=I8B) diff --git a/src/modules/swiftest_classes.f90 b/src/modules/swiftest_classes.f90 index a7d3965c5..6f0d10857 100644 --- a/src/modules/swiftest_classes.f90 +++ b/src/modules/swiftest_classes.f90 @@ -41,7 +41,7 @@ module swiftest_classes real(DP) :: tstop = -1.0_DP !! Integration stop time real(DP) :: dt = -1.0_DP !! Time step integer(I8B) :: iloop = 0_I8B !! Main loop counter - integer(I8B) :: ioutput = 0_I8B !! Output counter + integer(I4B) :: ioutput = 0 !! Output counter character(STRMAX) :: incbfile = CB_INFILE !! Name of input file for the central body character(STRMAX) :: inplfile = PL_INFILE !! Name of input file for massive bodies character(STRMAX) :: intpfile = TP_INFILE !! Name of input file for test particles @@ -425,7 +425,7 @@ module swiftest_classes end type type, extends(swiftest_base) :: swiftest_storage(nframes) - integer(I8B), len :: nframes + integer(I4B), len :: nframes !! A class that that is used to store simulation history data between file output type(storage_frame), dimension(nframes) :: frame contains diff --git a/src/netcdf/netcdf.f90 b/src/netcdf/netcdf.f90 index abd03f1d6..4b56715fd 100644 --- a/src/netcdf/netcdf.f90 +++ b/src/netcdf/netcdf.f90 @@ -519,7 +519,7 @@ module function netcdf_read_frame_system(self, iu, param) result(ierr) call pl%setup(npl, param) call tp%setup(ntp, param) - tslot = int(param%ioutput, kind=I4B) + 1 + tslot = param%ioutput + 1 call check( nf90_inquire_dimension(iu%ncid, iu%id_dimid, len=idmax), "netcdf_read_frame_system nf90_inquire_dimension id_dimid" ) allocate(rtemp(idmax)) @@ -791,7 +791,7 @@ module subroutine netcdf_read_hdr_system(self, iu, param) logical, dimension(:), allocatable :: plmask, tpmask, plmmask - tslot = int(param%ioutput, kind=I4B) + 1 + tslot = param%ioutput + 1 call check( nf90_inquire_dimension(iu%ncid, iu%id_dimid, len=idmax), "netcdf_read_frame_system nf90_inquire_dimension id_dimid" ) call check( nf90_get_var(iu%ncid, iu%time_varid, self%t, start=[tslot]), "netcdf_read_hdr_system nf90_getvar time_varid" ) @@ -1185,7 +1185,7 @@ module subroutine netcdf_write_frame_base(self, iu, param) call self%write_particle_info(iu, param) - tslot = int(param%ioutput, kind=I4B) + 1 + tslot = param%ioutput + 1 call check( nf90_set_fill(iu%ncid, nf90_nofill, old_mode), "netcdf_write_frame_base nf90_set_fill" ) select type(self) @@ -1426,7 +1426,7 @@ module subroutine netcdf_write_hdr_system(self, iu, param) ! Internals integer(I4B) :: tslot - tslot = int(param%ioutput, kind=I4B) + 1 + tslot = param%ioutput + 1 call check( nf90_put_var(iu%ncid, iu%time_varid, self%t, start=[tslot]), "netcdf_write_hdr_system nf90_put_var time_varid" ) call check( nf90_put_var(iu%ncid, iu%npl_varid, self%pl%nbody, start=[tslot]), "netcdf_write_hdr_system nf90_put_var npl_varid" ) From 7d48f803cff810660eeaa4a17eaf2211fd11363d Mon Sep 17 00:00:00 2001 From: David A Minton Date: Thu, 1 Dec 2022 16:21:48 -0500 Subject: [PATCH 03/65] Refactored write_particle_info to just write_info to cut down on uneccesary wordiness --- src/discard/discard.f90 | 4 +- src/modules/swiftest_classes.f90 | 10 ++-- src/netcdf/netcdf.f90 | 90 ++++++++++++++++---------------- src/symba/symba_io.f90 | 4 +- src/symba/symba_util.f90 | 2 +- 5 files changed, 55 insertions(+), 55 deletions(-) diff --git a/src/discard/discard.f90 b/src/discard/discard.f90 index 55ad97f65..2019774a8 100644 --- a/src/discard/discard.f90 +++ b/src/discard/discard.f90 @@ -38,8 +38,8 @@ module subroutine discard_system(self, param) call tp%discard(system, param) ltp_discards = (tp_discards%nbody > 0) end if - if (ltp_discards) call tp_discards%write_particle_info(param%nciu, param) - if (lpl_discards) call pl_discards%write_particle_info(param%nciu, param) + if (ltp_discards) call tp_discards%write_info(param%nciu, param) + if (lpl_discards) call pl_discards%write_info(param%nciu, param) if (lpl_discards .and. param%lenergy) call self%conservation_report(param, lterminal=.false.) if (lpl_check) call pl_discards%setup(0,param) if (ltp_check) call tp_discards%setup(0,param) diff --git a/src/modules/swiftest_classes.f90 b/src/modules/swiftest_classes.f90 index 6f0d10857..6a37a4894 100644 --- a/src/modules/swiftest_classes.f90 +++ b/src/modules/swiftest_classes.f90 @@ -151,9 +151,9 @@ module swiftest_classes !! An abstract superclass for a generic Swiftest object contains !! The minimal methods that all systems must have - procedure :: read_in => io_read_in_base !! Read in body initial conditions from a file - procedure :: write_frame => netcdf_write_frame_base !! I/O routine for writing out a single frame of time-series data for all bodies in the system in NetCDF format - procedure :: write_particle_info => netcdf_write_particle_info_base !! Dump contents of particle information metadata to file + procedure :: read_in => io_read_in_base !! Read in body initial conditions from a file + procedure :: write_frame => netcdf_write_frame_base !! I/O routine for writing out a single frame of time-series data for all bodies in the system in NetCDF format + procedure :: write_info => netcdf_write_info_base !! Dump contents of particle information metadata to file end type swiftest_base !******************************************************************************************************************************** @@ -943,12 +943,12 @@ module subroutine netcdf_write_hdr_system(self, iu, param) class(swiftest_parameters), intent(inout) :: param !! Current run configuration parameters end subroutine netcdf_write_hdr_system - module subroutine netcdf_write_particle_info_base(self, iu, param) + module subroutine netcdf_write_info_base(self, iu, param) implicit none class(swiftest_base), intent(in) :: self !! Swiftest particle object class(netcdf_parameters), intent(inout) :: iu !! Parameters used to identify a particular NetCDF dataset class(swiftest_parameters), intent(inout) :: param !! Current run configuration parameters - end subroutine netcdf_write_particle_info_base + end subroutine netcdf_write_info_base module subroutine obl_acc_body(self, system) implicit none diff --git a/src/netcdf/netcdf.f90 b/src/netcdf/netcdf.f90 index 4b56715fd..1dd114f92 100644 --- a/src/netcdf/netcdf.f90 +++ b/src/netcdf/netcdf.f90 @@ -1183,7 +1183,7 @@ module subroutine netcdf_write_frame_base(self, iu, param) real(DP), dimension(NDIM) :: vh !! Temporary variable to store heliocentric velocity values when converting from pseudovelocity in GR-enabled runs real(DP) :: a, e, inc, omega, capom, capm - call self%write_particle_info(iu, param) + call self%write_info(iu, param) tslot = param%ioutput + 1 @@ -1309,7 +1309,7 @@ module subroutine netcdf_write_frame_system(self, iu, param) end subroutine netcdf_write_frame_system - module subroutine netcdf_write_particle_info_base(self, iu, param) + module subroutine netcdf_write_info_base(self, iu, param) !! author: Carlisle A. Wishard, Dana Singh, and David A. Minton !! !! Write all current particle to file @@ -1324,7 +1324,7 @@ module subroutine netcdf_write_particle_info_base(self, iu, param) character(len=NAMELEN) :: charstring ! This string of spaces of length NAMELEN is used to clear out any old data left behind inside the string variables - call check( nf90_set_fill(iu%ncid, nf90_nofill, old_mode), "netcdf_write_particle_info_base nf90_set_fill nf90_nofill" ) + call check( nf90_set_fill(iu%ncid, nf90_nofill, old_mode), "netcdf_write_info_base nf90_set_fill nf90_nofill" ) select type(self) class is (swiftest_body) @@ -1335,36 +1335,36 @@ module subroutine netcdf_write_particle_info_base(self, iu, param) do i = 1, n j = ind(i) idslot = self%id(j) + 1 - call check( nf90_put_var(iu%ncid, iu%id_varid, self%id(j), start=[idslot]), "netcdf_write_particle_info_base nf90_put_var id_varid" ) + call check( nf90_put_var(iu%ncid, iu%id_varid, self%id(j), start=[idslot]), "netcdf_write_info_base nf90_put_var id_varid" ) charstring = trim(adjustl(self%info(j)%name)) - call check( nf90_put_var(iu%ncid, iu%name_varid, charstring, start=[1, idslot], count=[NAMELEN, 1]), "netcdf_write_particle_info_base nf90_put_var name_varid" ) + call check( nf90_put_var(iu%ncid, iu%name_varid, charstring, start=[1, idslot], count=[NAMELEN, 1]), "netcdf_write_info_base nf90_put_var name_varid" ) charstring = trim(adjustl(self%info(j)%particle_type)) - call check( nf90_put_var(iu%ncid, iu%ptype_varid, charstring, start=[1, idslot], count=[NAMELEN, 1]), "netcdf_write_particle_info_base nf90_put_var particle_type_varid" ) + call check( nf90_put_var(iu%ncid, iu%ptype_varid, charstring, start=[1, idslot], count=[NAMELEN, 1]), "netcdf_write_info_base nf90_put_var particle_type_varid" ) charstring = trim(adjustl(self%info(j)%status)) - call check( nf90_put_var(iu%ncid, iu%status_varid, charstring, start=[1, idslot], count=[NAMELEN, 1]), "netcdf_write_particle_info_base nf90_put_var status_varid" ) + call check( nf90_put_var(iu%ncid, iu%status_varid, charstring, start=[1, idslot], count=[NAMELEN, 1]), "netcdf_write_info_base nf90_put_var status_varid" ) if (param%lclose) then charstring = trim(adjustl(self%info(j)%origin_type)) - call check( nf90_put_var(iu%ncid, iu%origin_type_varid, charstring, start=[1, idslot], count=[NAMELEN, 1]), "netcdf_write_particle_info_base nf90_put_var origin_type_varid" ) - call check( nf90_put_var(iu%ncid, iu%origin_time_varid, self%info(j)%origin_time, start=[idslot]), "netcdf_write_particle_info_base nf90_put_var origin_time_varid" ) - call check( nf90_put_var(iu%ncid, iu%origin_xhx_varid, self%info(j)%origin_xh(1), start=[idslot]), "netcdf_write_particle_info_base nf90_put_var origin_xhx_varid" ) - call check( nf90_put_var(iu%ncid, iu%origin_xhy_varid, self%info(j)%origin_xh(2), start=[idslot]), "netcdf_write_particle_info_base nf90_put_var origin_xhy_varid" ) - call check( nf90_put_var(iu%ncid, iu%origin_xhz_varid, self%info(j)%origin_xh(3), start=[idslot]), "netcdf_write_particle_info_base nf90_put_var origin_xhz_varid" ) - call check( nf90_put_var(iu%ncid, iu%origin_vhx_varid, self%info(j)%origin_vh(1), start=[idslot]), "netcdf_write_particle_info_base nf90_put_var origin_vhx_varid" ) - call check( nf90_put_var(iu%ncid, iu%origin_vhy_varid, self%info(j)%origin_vh(2), start=[idslot]), "netcdf_write_particle_info_base nf90_put_var origin_vhy_varid" ) - call check( nf90_put_var(iu%ncid, iu%origin_vhz_varid, self%info(j)%origin_vh(3), start=[idslot]), "netcdf_write_particle_info_base nf90_put_var origin_vhz_varid" ) + call check( nf90_put_var(iu%ncid, iu%origin_type_varid, charstring, start=[1, idslot], count=[NAMELEN, 1]), "netcdf_write_info_base nf90_put_var origin_type_varid" ) + call check( nf90_put_var(iu%ncid, iu%origin_time_varid, self%info(j)%origin_time, start=[idslot]), "netcdf_write_info_base nf90_put_var origin_time_varid" ) + call check( nf90_put_var(iu%ncid, iu%origin_xhx_varid, self%info(j)%origin_xh(1), start=[idslot]), "netcdf_write_info_base nf90_put_var origin_xhx_varid" ) + call check( nf90_put_var(iu%ncid, iu%origin_xhy_varid, self%info(j)%origin_xh(2), start=[idslot]), "netcdf_write_info_base nf90_put_var origin_xhy_varid" ) + call check( nf90_put_var(iu%ncid, iu%origin_xhz_varid, self%info(j)%origin_xh(3), start=[idslot]), "netcdf_write_info_base nf90_put_var origin_xhz_varid" ) + call check( nf90_put_var(iu%ncid, iu%origin_vhx_varid, self%info(j)%origin_vh(1), start=[idslot]), "netcdf_write_info_base nf90_put_var origin_vhx_varid" ) + call check( nf90_put_var(iu%ncid, iu%origin_vhy_varid, self%info(j)%origin_vh(2), start=[idslot]), "netcdf_write_info_base nf90_put_var origin_vhy_varid" ) + call check( nf90_put_var(iu%ncid, iu%origin_vhz_varid, self%info(j)%origin_vh(3), start=[idslot]), "netcdf_write_info_base nf90_put_var origin_vhz_varid" ) - call check( nf90_put_var(iu%ncid, iu%collision_id_varid, self%info(j)%collision_id, start=[idslot]), "netcdf_write_particle_info_base nf90_put_var collision_id_varid" ) - call check( nf90_put_var(iu%ncid, iu%discard_time_varid, self%info(j)%discard_time, start=[idslot]), "netcdf_write_particle_info_base nf90_put_var discard_time_varid" ) - call check( nf90_put_var(iu%ncid, iu%discard_xhx_varid, self%info(j)%discard_xh(1), start=[idslot]), "netcdf_write_particle_info_base nf90_put_var discard_xhx_varid" ) - call check( nf90_put_var(iu%ncid, iu%discard_xhy_varid, self%info(j)%discard_xh(2), start=[idslot]), "netcdf_write_particle_info_base nf90_put_var discard_xhy_varid" ) - call check( nf90_put_var(iu%ncid, iu%discard_xhz_varid, self%info(j)%discard_xh(3), start=[idslot]), "netcdf_write_particle_info_base nf90_put_var discard_xhz_varid" ) - call check( nf90_put_var(iu%ncid, iu%discard_vhx_varid, self%info(j)%discard_vh(1), start=[idslot]), "netcdf_write_particle_info_base nf90_put_var discard_vhx_varid" ) - call check( nf90_put_var(iu%ncid, iu%discard_vhy_varid, self%info(j)%discard_vh(2), start=[idslot]), "netcdf_write_particle_info_base nf90_put_var discard_vhy_varid" ) - call check( nf90_put_var(iu%ncid, iu%discard_vhz_varid, self%info(j)%discard_vh(3), start=[idslot]), "netcdf_write_particle_info_base nf90_put_var discard_vhz_varid" ) + call check( nf90_put_var(iu%ncid, iu%collision_id_varid, self%info(j)%collision_id, start=[idslot]), "netcdf_write_info_base nf90_put_var collision_id_varid" ) + call check( nf90_put_var(iu%ncid, iu%discard_time_varid, self%info(j)%discard_time, start=[idslot]), "netcdf_write_info_base nf90_put_var discard_time_varid" ) + call check( nf90_put_var(iu%ncid, iu%discard_xhx_varid, self%info(j)%discard_xh(1), start=[idslot]), "netcdf_write_info_base nf90_put_var discard_xhx_varid" ) + call check( nf90_put_var(iu%ncid, iu%discard_xhy_varid, self%info(j)%discard_xh(2), start=[idslot]), "netcdf_write_info_base nf90_put_var discard_xhy_varid" ) + call check( nf90_put_var(iu%ncid, iu%discard_xhz_varid, self%info(j)%discard_xh(3), start=[idslot]), "netcdf_write_info_base nf90_put_var discard_xhz_varid" ) + call check( nf90_put_var(iu%ncid, iu%discard_vhx_varid, self%info(j)%discard_vh(1), start=[idslot]), "netcdf_write_info_base nf90_put_var discard_vhx_varid" ) + call check( nf90_put_var(iu%ncid, iu%discard_vhy_varid, self%info(j)%discard_vh(2), start=[idslot]), "netcdf_write_info_base nf90_put_var discard_vhy_varid" ) + call check( nf90_put_var(iu%ncid, iu%discard_vhz_varid, self%info(j)%discard_vh(3), start=[idslot]), "netcdf_write_info_base nf90_put_var discard_vhz_varid" ) end if end do @@ -1372,44 +1372,44 @@ module subroutine netcdf_write_particle_info_base(self, iu, param) class is (swiftest_cb) idslot = self%id + 1 - call check( nf90_put_var(iu%ncid, iu%id_varid, self%id, start=[idslot]), "netcdf_write_particle_info_base nf90_put_var cb id_varid" ) + call check( nf90_put_var(iu%ncid, iu%id_varid, self%id, start=[idslot]), "netcdf_write_info_base nf90_put_var cb id_varid" ) charstring = trim(adjustl(self%info%name)) - call check( nf90_put_var(iu%ncid, iu%name_varid, charstring, start=[1, idslot], count=[NAMELEN, 1]), "netcdf_write_particle_info_base nf90_put_var cb name_varid" ) + call check( nf90_put_var(iu%ncid, iu%name_varid, charstring, start=[1, idslot], count=[NAMELEN, 1]), "netcdf_write_info_base nf90_put_var cb name_varid" ) charstring = trim(adjustl(self%info%particle_type)) - call check( nf90_put_var(iu%ncid, iu%ptype_varid, charstring, start=[1, idslot], count=[NAMELEN, 1]), "netcdf_write_particle_info_base nf90_put_var cb ptype_varid" ) + call check( nf90_put_var(iu%ncid, iu%ptype_varid, charstring, start=[1, idslot], count=[NAMELEN, 1]), "netcdf_write_info_base nf90_put_var cb ptype_varid" ) charstring = trim(adjustl(self%info%status)) - call check( nf90_put_var(iu%ncid, iu%status_varid, charstring, start=[1, idslot], count=[NAMELEN, 1]), "netcdf_write_particle_info_base nf90_put_var cb status_varid" ) + call check( nf90_put_var(iu%ncid, iu%status_varid, charstring, start=[1, idslot], count=[NAMELEN, 1]), "netcdf_write_info_base nf90_put_var cb status_varid" ) if (param%lclose) then charstring = trim(adjustl(self%info%origin_type)) - call check( nf90_put_var(iu%ncid, iu%origin_type_varid, charstring, start=[1, idslot], count=[NAMELEN, 1]), "netcdf_write_particle_info_base nf90_put_var cb origin_type_varid" ) - - call check( nf90_put_var(iu%ncid, iu%origin_time_varid, self%info%origin_time, start=[idslot]), "netcdf_write_particle_info_base nf90_put_var cb origin_time_varid" ) - call check( nf90_put_var(iu%ncid, iu%origin_xhx_varid, self%info%origin_xh(1), start=[idslot]), "netcdf_write_particle_info_base nf90_put_var cb origin_xhx_varid" ) - call check( nf90_put_var(iu%ncid, iu%origin_xhy_varid, self%info%origin_xh(2), start=[idslot]), "netcdf_write_particle_info_base nf90_put_var cb origin_xhy_varid" ) - call check( nf90_put_var(iu%ncid, iu%origin_xhz_varid, self%info%origin_xh(3), start=[idslot]), "netcdf_write_particle_info_base nf90_put_var cb origin_xhz_varid" ) - call check( nf90_put_var(iu%ncid, iu%origin_vhx_varid, self%info%origin_vh(1), start=[idslot]), "netcdf_write_particle_info_base nf90_put_var cb origin_vhx_varid" ) - call check( nf90_put_var(iu%ncid, iu%origin_vhy_varid, self%info%origin_vh(2), start=[idslot]), "netcdf_write_particle_info_base nf90_put_var cb origin_vhy_varid" ) - call check( nf90_put_var(iu%ncid, iu%origin_vhz_varid, self%info%origin_vh(3), start=[idslot]), "netcdf_write_particle_info_base nf90_put_var cb origin_vhz_varid" ) + call check( nf90_put_var(iu%ncid, iu%origin_type_varid, charstring, start=[1, idslot], count=[NAMELEN, 1]), "netcdf_write_info_base nf90_put_var cb origin_type_varid" ) + + call check( nf90_put_var(iu%ncid, iu%origin_time_varid, self%info%origin_time, start=[idslot]), "netcdf_write_info_base nf90_put_var cb origin_time_varid" ) + call check( nf90_put_var(iu%ncid, iu%origin_xhx_varid, self%info%origin_xh(1), start=[idslot]), "netcdf_write_info_base nf90_put_var cb origin_xhx_varid" ) + call check( nf90_put_var(iu%ncid, iu%origin_xhy_varid, self%info%origin_xh(2), start=[idslot]), "netcdf_write_info_base nf90_put_var cb origin_xhy_varid" ) + call check( nf90_put_var(iu%ncid, iu%origin_xhz_varid, self%info%origin_xh(3), start=[idslot]), "netcdf_write_info_base nf90_put_var cb origin_xhz_varid" ) + call check( nf90_put_var(iu%ncid, iu%origin_vhx_varid, self%info%origin_vh(1), start=[idslot]), "netcdf_write_info_base nf90_put_var cb origin_vhx_varid" ) + call check( nf90_put_var(iu%ncid, iu%origin_vhy_varid, self%info%origin_vh(2), start=[idslot]), "netcdf_write_info_base nf90_put_var cb origin_vhy_varid" ) + call check( nf90_put_var(iu%ncid, iu%origin_vhz_varid, self%info%origin_vh(3), start=[idslot]), "netcdf_write_info_base nf90_put_var cb origin_vhz_varid" ) - call check( nf90_put_var(iu%ncid, iu%collision_id_varid, self%info%collision_id, start=[idslot]), "netcdf_write_particle_info_base nf90_put_var cb collision_id_varid" ) - call check( nf90_put_var(iu%ncid, iu%discard_time_varid, self%info%discard_time, start=[idslot]), "netcdf_write_particle_info_base nf90_put_var cb discard_time_varid" ) - call check( nf90_put_var(iu%ncid, iu%discard_xhx_varid, self%info%discard_xh(1), start=[idslot]), "netcdf_write_particle_info_base nf90_put_var cb discard_xhx_varid" ) - call check( nf90_put_var(iu%ncid, iu%discard_xhy_varid, self%info%discard_xh(2), start=[idslot]), "netcdf_write_particle_info_base nf90_put_var cb discard_xhy_varid" ) - call check( nf90_put_var(iu%ncid, iu%discard_xhz_varid, self%info%discard_xh(3), start=[idslot]), "netcdf_write_particle_info_base nf90_put_var cb discard_xhz_varid" ) - call check( nf90_put_var(iu%ncid, iu%discard_vhx_varid, self%info%discard_vh(1), start=[idslot]), "netcdf_write_particle_info_base nf90_put_var cb discard_vhx_varid" ) - call check( nf90_put_var(iu%ncid, iu%discard_vhy_varid, self%info%discard_vh(2), start=[idslot]), "netcdf_write_particle_info_base nf90_put_var cb discard_vhy_varid" ) - call check( nf90_put_var(iu%ncid, iu%discard_vhz_varid, self%info%discard_vh(3), start=[idslot]), "netcdf_write_particle_info_base nf90_put_var cb discard_vhz_varid" ) + call check( nf90_put_var(iu%ncid, iu%collision_id_varid, self%info%collision_id, start=[idslot]), "netcdf_write_info_base nf90_put_var cb collision_id_varid" ) + call check( nf90_put_var(iu%ncid, iu%discard_time_varid, self%info%discard_time, start=[idslot]), "netcdf_write_info_base nf90_put_var cb discard_time_varid" ) + call check( nf90_put_var(iu%ncid, iu%discard_xhx_varid, self%info%discard_xh(1), start=[idslot]), "netcdf_write_info_base nf90_put_var cb discard_xhx_varid" ) + call check( nf90_put_var(iu%ncid, iu%discard_xhy_varid, self%info%discard_xh(2), start=[idslot]), "netcdf_write_info_base nf90_put_var cb discard_xhy_varid" ) + call check( nf90_put_var(iu%ncid, iu%discard_xhz_varid, self%info%discard_xh(3), start=[idslot]), "netcdf_write_info_base nf90_put_var cb discard_xhz_varid" ) + call check( nf90_put_var(iu%ncid, iu%discard_vhx_varid, self%info%discard_vh(1), start=[idslot]), "netcdf_write_info_base nf90_put_var cb discard_vhx_varid" ) + call check( nf90_put_var(iu%ncid, iu%discard_vhy_varid, self%info%discard_vh(2), start=[idslot]), "netcdf_write_info_base nf90_put_var cb discard_vhy_varid" ) + call check( nf90_put_var(iu%ncid, iu%discard_vhz_varid, self%info%discard_vh(3), start=[idslot]), "netcdf_write_info_base nf90_put_var cb discard_vhz_varid" ) end if end select call check( nf90_set_fill(iu%ncid, old_mode, old_mode) ) return - end subroutine netcdf_write_particle_info_base + end subroutine netcdf_write_info_base module subroutine netcdf_write_hdr_system(self, iu, param) diff --git a/src/symba/symba_io.f90 b/src/symba/symba_io.f90 index d5dd06308..38ead96f1 100644 --- a/src/symba/symba_io.f90 +++ b/src/symba/symba_io.f90 @@ -177,12 +177,12 @@ module subroutine symba_io_write_discard(self, param) associate(pl => self%pl, npl => self%pl%nbody, pl_adds => self%pl_adds) - if (self%tp_discards%nbody > 0) call self%tp_discards%write_particle_info(param%nciu, param) + if (self%tp_discards%nbody > 0) call self%tp_discards%write_info(param%nciu, param) select type(pl_discards => self%pl_discards) class is (symba_merger) if (pl_discards%nbody == 0) return - call pl_discards%write_particle_info(param%nciu, param) + call pl_discards%write_info(param%nciu, param) end select end associate diff --git a/src/symba/symba_util.f90 b/src/symba/symba_util.f90 index f0f300bc1..6f53d6bbd 100644 --- a/src/symba/symba_util.f90 +++ b/src/symba/symba_util.f90 @@ -678,7 +678,7 @@ module subroutine symba_util_rearray_pl(self, system, param) end where end select - call pl%write_particle_info(param%nciu, param) + call pl%write_info(param%nciu, param) deallocate(ldump_mask) ! Reindex the new list of bodies From 01762bfcf5e671b302660629a08fcabf3998c4df Mon Sep 17 00:00:00 2001 From: David A Minton Date: Thu, 1 Dec 2022 16:31:11 -0500 Subject: [PATCH 04/65] Refactored some of the storage procedure names to keep the naming scheme somewhat consistent --- src/io/io.f90 | 4 ++-- src/modules/encounter_classes.f90 | 2 +- src/modules/swiftest_classes.f90 | 12 ++++++------ src/util/util_copy.f90 | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/io/io.f90 b/src/io/io.f90 index ce17cdadf..8da42117a 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_system_storage(self, param) + module subroutine io_dump_storage_system(self, param) !! 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 @@ -295,7 +295,7 @@ module subroutine io_dump_system_storage(self, param) end do return - end subroutine io_dump_system_storage + end subroutine io_dump_storage_system module subroutine io_get_args(integrator, param_file_name, display_style) diff --git a/src/modules/encounter_classes.f90 b/src/modules/encounter_classes.f90 index b562def23..580becc40 100644 --- a/src/modules/encounter_classes.f90 +++ b/src/modules/encounter_classes.f90 @@ -38,7 +38,7 @@ module encounter_classes procedure :: dealloc => encounter_util_dealloc_list !! Deallocates all allocatables procedure :: spill => encounter_util_spill_list !! "Spills" bodies from one object to another depending on the results of a mask (uses the PACK intrinsic) procedure :: resize => encounter_util_resize_list !! Checks the current size of the encounter list against the required size and extends it by a factor of 2 more than requested if it is too small. - final :: encounter_util_final_list !! Finalize the encounter list - deallocates all allocatables + final :: encounter_util_final_list !! Finalize the encounter list - deallocates all allocatables end type encounter_list type encounter_bounding_box_1D diff --git a/src/modules/swiftest_classes.f90 b/src/modules/swiftest_classes.f90 index 6a37a4894..07f446946 100644 --- a/src/modules/swiftest_classes.f90 +++ b/src/modules/swiftest_classes.f90 @@ -417,7 +417,7 @@ module swiftest_classes 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 storage_frame + type swiftest_storage_frame_system 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. @@ -427,9 +427,9 @@ module swiftest_classes 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(storage_frame), dimension(nframes) :: frame + type(swiftest_storage_frame_system), dimension(nframes) :: frame contains - procedure :: dump => io_dump_system_storage + procedure :: dump => io_dump_storage_system end type swiftest_storage abstract interface @@ -626,11 +626,11 @@ module subroutine io_dump_system(self, param) end subroutine io_dump_system - module subroutine io_dump_system_storage(self, param) + module subroutine io_dump_storage_system(self, param) implicit none class(swiftest_storage(*)), intent(inout) :: self !! Swiftest simulation history storage object class(swiftest_parameters), intent(inout) :: param !! Current run configuration parameters - end subroutine io_dump_system_storage + end subroutine io_dump_storage_system module subroutine io_get_args(integrator, param_file_name, display_style) implicit none @@ -1245,7 +1245,7 @@ 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_storage_frame_system), 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 diff --git a/src/util/util_copy.f90 b/src/util/util_copy.f90 index 51e210787..cb1117df9 100644 --- a/src/util/util_copy.f90 +++ b/src/util/util_copy.f90 @@ -83,7 +83,7 @@ module subroutine util_copy_store_system(self, system) !! !! 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_storage_frame_system), intent(inout) :: self !! Swiftest storage frame object class(swiftest_nbody_system), intent(in) :: system !! Swiftest n-body system object if (allocated(self%system)) deallocate(self%system) From 5d243fdf0e5e6597ed3031c139ad2c4030a1d2a8 Mon Sep 17 00:00:00 2001 From: David A Minton Date: Thu, 1 Dec 2022 16:39:32 -0500 Subject: [PATCH 05/65] Restructured the driver to simplify the counting variables. Variables now count up instead of down, simplifying the indexing of the storage frames --- src/main/swiftest_driver.f90 | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/src/main/swiftest_driver.f90 b/src/main/swiftest_driver.f90 index b14abec80..75c601024 100644 --- a/src/main/swiftest_driver.f90 +++ b/src/main/swiftest_driver.f90 @@ -27,7 +27,6 @@ program swiftest_driver integer(I8B) :: nloops !! Number of steps to take in the simulation integer(I4B) :: iout !! Output cadence counter integer(I4B) :: idump !! Dump cadence counter - integer(I4B) :: iframe !! System history frame cindex type(walltimer) :: integration_timer !! Object used for computing elapsed wall time real(DP) :: tfrac type(progress_bar) :: pbar !! Object used to print out a progress bar @@ -80,7 +79,6 @@ program swiftest_driver ! Set up loop and output cadence variables t = tstart - iout = istep_out nloops = ceiling((tstop - t0) / dt, kind=I8B) istart = ceiling((tstart - t0) / dt + 1, kind=I8B) ioutput = int(istart / istep_out, kind=I4B) @@ -88,7 +86,6 @@ program swiftest_driver ! Set up system storage for intermittent file dumps if (dump_cadence == 0) dump_cadence = ceiling(nloops / (1.0_DP * istep_out), kind=I8B) allocate(swiftest_storage(dump_cadence) :: system_history) - idump = dump_cadence ! If this is a new run, compute energy initial conditions (if energy tracking is turned on) and write the initial conditions to file. if (param%lrestart) then @@ -109,6 +106,8 @@ program swiftest_driver call nbody_system%compact_output(param,integration_timer) end if + iout = 0 + idump = 0 do iloop = istart, nloops !> Step the system forward in time call integration_timer%start() @@ -123,16 +122,16 @@ program swiftest_driver !> If the loop counter is at the output cadence value, append the data file with a single frame if (istep_out > 0) then - iout = iout - 1 - if (iout == 0) then - idump = idump - 1 - iframe = dump_cadence - idump - system_history%frame(iframe) = nbody_system - - if (idump == 0) then + iout = iout + 1 + if (iout == istep_out) then + iout = 0 + idump = idump + 1 + system_history%frame(idump) = nbody_system + + if (idump == dump_cadence) then + idump = 0 call nbody_system%dump(param) call system_history%dump(param) - idump = dump_cadence end if tfrac = (t - t0) / (tstop - t0) @@ -155,7 +154,6 @@ program swiftest_driver call integration_timer%reset() - iout = istep_out end if end if From 08584c42b474cc19ea2e783f4108399ee081d953 Mon Sep 17 00:00:00 2001 From: David A Minton Date: Thu, 1 Dec 2022 16:52:47 -0500 Subject: [PATCH 06/65] Added encounter storage object using the same pattern as the system storage object. Also got rid of some old pre-NetCDF cruft in encounter_classes --- src/modules/encounter_classes.f90 | 34 +++++++++++++++++++++++-------- src/modules/swiftest_classes.f90 | 7 +++---- 2 files changed, 28 insertions(+), 13 deletions(-) diff --git a/src/modules/encounter_classes.f90 b/src/modules/encounter_classes.f90 index 580becc40..b14fd5da0 100644 --- a/src/modules/encounter_classes.f90 +++ b/src/modules/encounter_classes.f90 @@ -41,6 +41,21 @@ module encounter_classes final :: encounter_util_final_list !! Finalize the encounter list - deallocates all allocatables end type encounter_list + type encounter_storage_frame_list + class(swiftest_nbody_system), allocatable :: system + contains + procedure :: store => encounter_util_copy_store_list !! Stores a snapshot of the nbody system so that later it can be retrieved for saving to file. + generic :: assignment(=) => store + end type + + type :: encounter_storage(nframes) + integer(I4B), len :: nframes + !! A class that that is used to store simulation history data between file output + type(encounter_storage_frame_list), dimension(nframes) :: frame + 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) @@ -173,16 +188,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_write_frame(iu, t, id1, id2, Gmass1, Gmass2, radius1, radius2, xh1, xh2, vh1, vh2) + module subroutine encounter_io_dump_storage_list(self, param) implicit none - integer(I4B), intent(in) :: iu !! Open file unit number - real(DP), intent(in) :: t !! Time of encounter - integer(I4B), intent(in) :: id1, id2 !! ids of the two encountering bodies - real(DP), intent(in) :: Gmass1, Gmass2 !! G*mass of the two encountering bodies - real(DP), intent(in) :: radius1, radius2 !! Radii of the two encountering bodies - real(DP), dimension(:), intent(in) :: xh1, xh2 !! Swiftestcentric position vectors of the two encountering bodies - real(DP), dimension(:), intent(in) :: vh1, vh2 !! Swiftestcentric velocity vectors of the two encountering bodies - end subroutine encounter_io_write_frame + class(encounter_storage(*)), intent(inout) :: self !! Encounter storage object + class(swiftest_parameters), intent(inout) :: param !! Current run configuration parameters + end subroutine encounter_io_dump_storage_list module subroutine encounter_setup_aabb(self, n, n_last) implicit none @@ -210,6 +220,12 @@ module subroutine encounter_util_copy_list(self, source) class(encounter_list), intent(in) :: source !! Source object to copy into end subroutine encounter_util_copy_list + module subroutine encounter_util_copy_store_list(self, system) + implicit none + class(encounter_storage_frame_list), intent(inout) :: self !! Encounter storage object + class(encounter_list), intent(in) :: system !! Swiftest encounter list structure + end subroutine encounter_util_copy_store_list + module subroutine encounter_util_dealloc_aabb(self) implicit none class(encounter_bounding_box_1D), intent(inout) :: self !!Bounding box structure along a single dimension diff --git a/src/modules/swiftest_classes.f90 b/src/modules/swiftest_classes.f90 index 07f446946..54881ae19 100644 --- a/src/modules/swiftest_classes.f90 +++ b/src/modules/swiftest_classes.f90 @@ -424,7 +424,7 @@ module swiftest_classes generic :: assignment(=) => store end type - type, extends(swiftest_base) :: swiftest_storage(nframes) + type :: swiftest_storage(nframes) integer(I4B), len :: nframes !! A class that that is used to store simulation history data between file output type(swiftest_storage_frame_system), dimension(nframes) :: frame @@ -625,7 +625,6 @@ 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_system(self, param) implicit none class(swiftest_storage(*)), intent(inout) :: self !! Swiftest simulation history storage object @@ -1245,8 +1244,8 @@ end subroutine util_copy_particle_info_arr module subroutine util_copy_store_system(self, system) implicit none - class(swiftest_storage_frame_system), intent(inout) :: self !! Swiftest storage frame object - class(swiftest_nbody_system), intent(in) :: system !! Swiftest n-body system object + class(swiftest_storage_frame_system), 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) From c2c781f2e0e34110a3e644c1e89360af261379d7 Mon Sep 17 00:00:00 2001 From: David A Minton Date: Thu, 1 Dec 2022 17:30:01 -0500 Subject: [PATCH 07/65] Restructured the swiftest_storage object to be a general purpose storage tool capabable of storing *any* object you want. I added an extension in the encounter class definitions that will specialized in encounter list storage --- src/CMakeLists.txt | 1 + src/encounter/encounter_io.f90 | 24 ++++++++++++++++++++++++ src/encounter/encounter_util.f90 | 11 +++++------ src/io/io.f90 | 15 +++++++++------ src/main/swiftest_driver.f90 | 2 +- src/modules/encounter_classes.f90 | 17 +---------------- src/modules/swiftest_classes.f90 | 26 +++++++++++++------------- src/util/util_copy.f90 | 14 +++++++------- 8 files changed, 61 insertions(+), 49 deletions(-) create mode 100644 src/encounter/encounter_io.f90 diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 63c89f2b3..668b07c47 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -28,6 +28,7 @@ SET(FAST_MATH_FILES ${SRC}/discard/discard.f90 ${SRC}/drift/drift.f90 ${SRC}/encounter/encounter_check.f90 + ${SRC}/encounter/encounter_io.f90 ${SRC}/encounter/encounter_setup.f90 ${SRC}/encounter/encounter_util.f90 ${SRC}/fraggle/fraggle_generate.f90 diff --git a/src/encounter/encounter_io.f90 b/src/encounter/encounter_io.f90 new file mode 100644 index 000000000..43d89add6 --- /dev/null +++ b/src/encounter/encounter_io.f90 @@ -0,0 +1,24 @@ +!! Copyright 2022 - David Minton, Carlisle Wishard, Jennifer Pouplin, Jake Elliott, & Dana Singh +!! This file is part of Swiftest. +!! Swiftest is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License +!! as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. +!! Swiftest is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty +!! of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. +!! You should have received a copy of the GNU General Public License along with Swiftest. +!! If not, see: https://www.gnu.org/licenses. + +submodule (encounter_classes) s_encounter_io + use swiftest +contains + + module subroutine encounter_io_dump_storage_list(self, param) + !! 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 + end subroutine encounter_io_dump_storage_list + +end submodule s_encounter_io \ No newline at end of file diff --git a/src/encounter/encounter_util.f90 b/src/encounter/encounter_util.f90 index 09cf6107e..76ac0e492 100644 --- a/src/encounter/encounter_util.f90 +++ b/src/encounter/encounter_util.f90 @@ -70,7 +70,6 @@ module subroutine encounter_util_copy_list(self, source) return end subroutine encounter_util_copy_list - module subroutine encounter_util_dealloc_aabb(self) !! author: David A. Minton !! @@ -149,11 +148,11 @@ module subroutine encounter_util_resize_list(self, nnew) implicit none ! Arguments class(encounter_list), intent(inout) :: self !! Swiftest encounter list - integer(I8B), intent(in) :: nnew !! New size of list needed + integer(I8B), intent(in) :: nnew !! New size of list needed ! Internals class(encounter_list), allocatable :: enc_temp - integer(I8B) :: nold - logical :: lmalloc + integer(I8B) :: nold + logical :: lmalloc lmalloc = allocated(self%status) if (lmalloc) then @@ -185,8 +184,8 @@ module subroutine encounter_util_spill_list(self, discards, lspill_list, ldestru ! Arguments class(encounter_list), intent(inout) :: self !! Swiftest encounter list class(encounter_list), intent(inout) :: discards !! Discarded object - logical, dimension(:), intent(in) :: lspill_list !! Logical array of bodies to spill into the discards - logical, intent(in) :: ldestructive !! Logical flag indicating whether or not this operation should alter body by removing the discard list + logical, dimension(:), intent(in) :: lspill_list !! Logical array of bodies to spill into the discards + logical, intent(in) :: ldestructive !! Logical flag indicating whether or not this operation should alter body by removing the discard list ! Internals integer(I8B) :: nenc_old diff --git a/src/io/io.f90 b/src/io/io.f90 index 8da42117a..e8936d018 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_system(self, param) + module subroutine io_dump_storage(self, param) !! 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 @@ -287,15 +287,18 @@ module subroutine io_dump_storage_system(self, param) iloop_start = param%iloop - int(param%istep_out * param%dump_cadence + 1, kind=I8B) do i = 1, param%dump_cadence - if (allocated(self%frame(i)%system)) then - param%ioutput = int(iloop_start / param%istep_out, kind=I4B) + i - call self%frame(i)%system%write_frame(param) - deallocate(self%frame(i)%system) + param%ioutput = int(iloop_start / param%istep_out, kind=I4B) + i + if (allocated(self%frame(i)%item)) then + select type(system => self%frame(i)%item) + class is (swiftest_nbody_system) + call system%write_frame(param) + end select + deallocate(self%frame(i)%item) end if end do return - end subroutine io_dump_storage_system + end subroutine io_dump_storage module subroutine io_get_args(integrator, param_file_name, display_style) diff --git a/src/main/swiftest_driver.f90 b/src/main/swiftest_driver.f90 index 75c601024..3f9a36adc 100644 --- a/src/main/swiftest_driver.f90 +++ b/src/main/swiftest_driver.f90 @@ -38,7 +38,7 @@ program swiftest_driver character(len=64) :: pbarmessage character(*), parameter :: symbacompactfmt = '(";NPLM",ES22.15,$)' - type(swiftest_storage(nframes=:)), allocatable :: system_history + type(swiftest_storage(nframes=:)), allocatable :: system_history call io_get_args(integrator, param_file_name, display_style) diff --git a/src/modules/encounter_classes.f90 b/src/modules/encounter_classes.f90 index b14fd5da0..91ef22d43 100644 --- a/src/modules/encounter_classes.f90 +++ b/src/modules/encounter_classes.f90 @@ -41,17 +41,8 @@ module encounter_classes final :: encounter_util_final_list !! Finalize the encounter list - deallocates all allocatables end type encounter_list - type encounter_storage_frame_list - class(swiftest_nbody_system), allocatable :: system - contains - procedure :: store => encounter_util_copy_store_list !! Stores a snapshot of the nbody system so that later it can be retrieved for saving to file. - generic :: assignment(=) => store - end type - - type :: encounter_storage(nframes) - integer(I4B), len :: nframes + type, extends(swiftest_storage) :: encounter_storage !! A class that that is used to store simulation history data between file output - type(encounter_storage_frame_list), dimension(nframes) :: frame contains procedure :: dump => encounter_io_dump_storage_list end type encounter_storage @@ -220,12 +211,6 @@ module subroutine encounter_util_copy_list(self, source) class(encounter_list), intent(in) :: source !! Source object to copy into end subroutine encounter_util_copy_list - module subroutine encounter_util_copy_store_list(self, system) - implicit none - class(encounter_storage_frame_list), intent(inout) :: self !! Encounter storage object - class(encounter_list), intent(in) :: system !! Swiftest encounter list structure - end subroutine encounter_util_copy_store_list - module subroutine encounter_util_dealloc_aabb(self) implicit none class(encounter_bounding_box_1D), intent(inout) :: self !!Bounding box structure along a single dimension diff --git a/src/modules/swiftest_classes.f90 b/src/modules/swiftest_classes.f90 index 54881ae19..f23a3c76e 100644 --- a/src/modules/swiftest_classes.f90 +++ b/src/modules/swiftest_classes.f90 @@ -417,19 +417,19 @@ module swiftest_classes 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 swiftest_storage_frame_system - class(swiftest_nbody_system), allocatable :: system + type swiftest_storage_frame + class(*), allocatable :: item 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. + procedure :: store => util_copy_store !! Stores a snapshot of the nbody system so that later it can be retrieved for saving to file. generic :: assignment(=) => store end type type :: swiftest_storage(nframes) integer(I4B), len :: nframes - !! A class that that is used to store simulation history data between file output - type(swiftest_storage_frame_system), dimension(nframes) :: frame + !! An abstract class that establishes the pattern for various storage objects + type(swiftest_storage_frame), dimension(nframes) :: frame contains - procedure :: dump => io_dump_storage_system + procedure :: dump => io_dump_storage end type swiftest_storage abstract interface @@ -449,7 +449,6 @@ subroutine abstract_discard_body(self, system, param) class(swiftest_parameters), intent(inout) :: param !! Current run configuration parameters end subroutine abstract_discard_body - subroutine abstract_kick_body(self, system, param, t, dt, lbeg) import swiftest_body, swiftest_nbody_system, swiftest_parameters, DP implicit none @@ -493,6 +492,7 @@ subroutine abstract_step_system(self, param, t, dt) real(DP), intent(in) :: t !! Simulation time real(DP), intent(in) :: dt !! Current stepsize end subroutine abstract_step_system + end interface interface @@ -625,11 +625,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_system(self, param) + module subroutine io_dump_storage(self, param) implicit none class(swiftest_storage(*)), intent(inout) :: self !! Swiftest simulation history storage object class(swiftest_parameters), intent(inout) :: param !! Current run configuration parameters - end subroutine io_dump_storage_system + end subroutine io_dump_storage module subroutine io_get_args(integrator, param_file_name, display_style) implicit none @@ -1242,11 +1242,11 @@ 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) + module subroutine util_copy_store(self, source) implicit none - class(swiftest_storage_frame_system), 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 + class(swiftest_storage_frame), intent(inout) :: self !! Swiftest storage frame object + class(*), intent(in) :: source !! Any object that one wishes to store + end subroutine util_copy_store module subroutine util_dealloc_body(self) implicit none diff --git a/src/util/util_copy.f90 b/src/util/util_copy.f90 index cb1117df9..6674cf431 100644 --- a/src/util/util_copy.f90 +++ b/src/util/util_copy.f90 @@ -78,18 +78,18 @@ 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) + module subroutine util_copy_store(self, source) !! 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(swiftest_storage_frame_system), intent(inout) :: self !! Swiftest storage frame object - class(swiftest_nbody_system), intent(in) :: system !! Swiftest n-body system object + class(swiftest_storage_frame), intent(inout) :: self !! Swiftest storage frame object + class(*), intent(in) :: source !! Swiftest n-body system object - if (allocated(self%system)) deallocate(self%system) - allocate(self%system, source=system) + if (allocated(self%item)) deallocate(self%item) + allocate(self%item, source=source) + return - - end subroutine util_copy_store_system + end subroutine util_copy_store end submodule s_util_copy From 61321de6f5e4deb570509e22756d78bd5ec488fd Mon Sep 17 00:00:00 2001 From: David A Minton Date: Thu, 1 Dec 2022 19:19:41 -0500 Subject: [PATCH 08/65] Added templates for the encounter io netcdf methods --- src/encounter/encounter_io.f90 | 25 +++++++++++++++++++++++++ src/modules/encounter_classes.f90 | 21 ++++++++++++++++++++- src/modules/symba_classes.f90 | 27 ++++++++++++++------------- 3 files changed, 59 insertions(+), 14 deletions(-) diff --git a/src/encounter/encounter_io.f90 b/src/encounter/encounter_io.f90 index 43d89add6..ba00e3634 100644 --- a/src/encounter/encounter_io.f90 +++ b/src/encounter/encounter_io.f90 @@ -21,4 +21,29 @@ module subroutine encounter_io_dump_storage_list(self, param) class(swiftest_parameters), intent(inout) :: param !! Current run configuration parameters end subroutine encounter_io_dump_storage_list + module subroutine encounter_io_initialize_output(self, param) + !! author: David A. Minton + !! + !! Initialize a NetCDF encounter file system and defines all variables. + implicit none + ! Arguments + class(encounter_io_parameters), intent(inout) :: self !! Parameters used to identify a particular NetCDF dataset + class(swiftest_parameters), intent(in) :: param !! Current run configuration parameters + + return + end subroutine encounter_io_initialize_output + + module subroutine encounter_io_open_file(self, param, readonly) + !! author: David A. Minton + !! + !! Opens a NetCDF encounter file and does the variable inquiries to activate variable ids + implicit none + ! Arguments + class(encounter_io_parameters), intent(inout) :: self !! Parameters used to identify a particular NetCDF dataset + class(swiftest_parameters), intent(in) :: param !! Current run configuration parameters + logical, optional, intent(in) :: readonly !! Logical flag indicating that this should be open read only + + return + end subroutine encounter_io_open_file + end submodule s_encounter_io \ No newline at end of file diff --git a/src/modules/encounter_classes.f90 b/src/modules/encounter_classes.f90 index 91ef22d43..f41c350e0 100644 --- a/src/modules/encounter_classes.f90 +++ b/src/modules/encounter_classes.f90 @@ -46,7 +46,13 @@ module encounter_classes contains procedure :: dump => encounter_io_dump_storage_list end type encounter_storage - + + type, extends(netcdf_parameters) :: encounter_io_parameters + 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 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) @@ -185,6 +191,19 @@ module subroutine encounter_io_dump_storage_list(self, param) class(swiftest_parameters), intent(inout) :: param !! Current run configuration parameters end subroutine encounter_io_dump_storage_list + module subroutine encounter_io_initialize_output(self, param) + implicit none + class(encounter_io_parameters), intent(inout) :: self !! Parameters used to identify a particular NetCDF dataset + class(swiftest_parameters), intent(in) :: param + end subroutine encounter_io_initialize_output + + module subroutine encounter_io_open_file(self, param, readonly) + implicit none + class(encounter_io_parameters), intent(inout) :: self !! Parameters used to identify a particular NetCDF dataset + class(swiftest_parameters), intent(in) :: param !! Current run configuration parameters + logical, optional, intent(in) :: readonly !! Logical flag indicating that this should be open read only + end subroutine encounter_io_open_file + module subroutine encounter_setup_aabb(self, n, n_last) implicit none class(encounter_bounding_box), intent(inout) :: self !! Swiftest encounter structure diff --git a/src/modules/symba_classes.f90 b/src/modules/symba_classes.f90 index e016a36b9..42b676c22 100644 --- a/src/modules/symba_classes.f90 +++ b/src/modules/symba_classes.f90 @@ -16,20 +16,20 @@ module symba_classes use swiftest_classes, only : swiftest_parameters, swiftest_base, swiftest_particle_info, netcdf_parameters use helio_classes, only : helio_cb, helio_pl, helio_tp, helio_nbody_system use fraggle_classes, only : fraggle_colliders, fraggle_fragments - use encounter_classes, only : encounter_list + use encounter_classes, only : encounter_list, encounter_storage implicit none public - integer(I4B), private, parameter :: NENMAX = 32767 - integer(I4B), private, parameter :: NTENC = 3 - real(DP), private, parameter :: RHSCALE = 6.5_DP - real(DP), private, parameter :: RSHELL = 0.48075_DP + integer(I4B), private, parameter :: NENMAX = 32767 + integer(I4B), private, parameter :: NTENC = 3 + real(DP), private, parameter :: RHSCALE = 6.5_DP + real(DP), private, parameter :: RSHELL = 0.48075_DP type, extends(swiftest_parameters) :: symba_parameters - real(DP) :: GMTINY = -1.0_DP !! Smallest G*mass that is fully gravitating - real(DP) :: min_GMfrag = -1.0_DP !! Smallest G*mass that can be produced in a fragmentation event - integer(I4B), dimension(:), allocatable :: seed !! Random seeds - logical :: lfragmentation = .false. !! Do fragmentation modeling instead of simple merger. + real(DP) :: GMTINY = -1.0_DP !! Smallest G*mass that is fully gravitating + real(DP) :: min_GMfrag = -1.0_DP !! Smallest G*mass that can be produced in a fragmentation event + integer(I4B), dimension(:), allocatable :: seed !! Random seeds + logical :: lfragmentation = .false. !! Do fragmentation modeling instead of simple merger. contains procedure :: reader => symba_io_param_reader procedure :: writer => symba_io_param_writer @@ -45,7 +45,7 @@ module symba_classes integer(I4B), dimension(:), allocatable :: child !! Index of children particles contains procedure :: dealloc => symba_util_dealloc_kin !! Deallocates all allocatable arrays - final :: symba_util_final_kin !! Finalizes the SyMBA kinship object - deallocates all allocatables + final :: symba_util_final_kin !! Finalizes the SyMBA kinship object - deallocates all allocatables end type symba_kinship !******************************************************************************************************************************** @@ -53,8 +53,8 @@ module symba_classes !******************************************************************************************************************************* !> SyMBA central body particle class type, extends(helio_cb) :: symba_cb - real(DP) :: GM0 = 0.0_DP !! Initial G*mass of the central body - real(DP) :: dGM = 0.0_DP !! Change in G*mass of the central body + real(DP) :: GM0 = 0.0_DP !! Initial G*mass of the central body + real(DP) :: dGM = 0.0_DP !! Change in G*mass of the central body 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 @@ -184,6 +184,7 @@ module symba_classes class(symba_plplenc), allocatable :: plplenc_list !! List of massive body-massive body encounters in a single step class(symba_plplenc), allocatable :: plplcollision_list !! List of massive body-massive body collisions in a single step integer(I4B) :: irec !! System recursion level + type(encounter_storage(nframes=:)), allocatable :: encounter_history contains procedure :: write_discard => symba_io_write_discard !! Write out information about discarded and merged planets and test particles in SyMBA procedure :: initialize => symba_setup_initialize_system !! Performs SyMBA-specific initilization steps @@ -219,7 +220,7 @@ module subroutine symba_collision_encounter_extract_collisions(self, system, par module subroutine symba_collision_make_colliders_pl(self,idx) implicit none class(symba_pl), intent(inout) :: self !! SyMBA massive body object - integer(I4B), dimension(2), intent(in) :: idx !! Array holding the indices of the two bodies involved in the collision + integer(I4B), dimension(2), intent(in) :: idx !! Array holding the indices of the two bodies involved in the collision end subroutine symba_collision_make_colliders_pl module subroutine symba_collision_resolve_fragmentations(self, system, param) From 5bcf737b4c1a7a613847548486e9700c0201a578 Mon Sep 17 00:00:00 2001 From: David A Minton Date: Thu, 1 Dec 2022 19:30:10 -0500 Subject: [PATCH 09/65] Added new SyMBA-only input parameter indicating how to save encounters --- src/encounter/encounter_io.f90 | 2 ++ src/modules/symba_classes.f90 | 1 + src/symba/symba_io.f90 | 10 ++++++++++ 3 files changed, 13 insertions(+) diff --git a/src/encounter/encounter_io.f90 b/src/encounter/encounter_io.f90 index ba00e3634..1e2f97a1a 100644 --- a/src/encounter/encounter_io.f90 +++ b/src/encounter/encounter_io.f90 @@ -21,6 +21,7 @@ module subroutine encounter_io_dump_storage_list(self, param) class(swiftest_parameters), intent(inout) :: param !! Current run configuration parameters end subroutine encounter_io_dump_storage_list + module subroutine encounter_io_initialize_output(self, param) !! author: David A. Minton !! @@ -33,6 +34,7 @@ module subroutine encounter_io_initialize_output(self, param) return end subroutine encounter_io_initialize_output + module subroutine encounter_io_open_file(self, param, readonly) !! author: David A. Minton !! diff --git a/src/modules/symba_classes.f90 b/src/modules/symba_classes.f90 index 42b676c22..988d75d95 100644 --- a/src/modules/symba_classes.f90 +++ b/src/modules/symba_classes.f90 @@ -30,6 +30,7 @@ module symba_classes real(DP) :: min_GMfrag = -1.0_DP !! Smallest G*mass that can be produced in a fragmentation event integer(I4B), dimension(:), allocatable :: seed !! Random seeds logical :: lfragmentation = .false. !! Do fragmentation modeling instead of simple merger. + character(STRMAX) :: encounter_save = "NONE" !! Indicate how encounter and/or fragmentation data should be saved contains procedure :: reader => symba_io_param_reader procedure :: writer => symba_io_param_writer diff --git a/src/symba/symba_io.f90 b/src/symba/symba_io.f90 index 38ead96f1..9cfd8ba9a 100644 --- a/src/symba/symba_io.f90 +++ b/src/symba/symba_io.f90 @@ -63,6 +63,9 @@ module subroutine symba_io_param_reader(self, unit, iotype, v_list, iostat, ioms read(param_value, *) param%GMTINY case ("MIN_GMFRAG") read(param_value, *) param%min_GMfrag + case ("ENCOUNTER_SAVE") + call io_toupper(param_value) + read(param_value, *) param%encounter_save case("SEED") read(param_value, *) nseeds_from_file ! Because the number of seeds can vary between compilers/systems, we need to make sure we can handle cases in which the input file has a different @@ -113,6 +116,13 @@ module subroutine symba_io_param_reader(self, unit, iotype, v_list, iostat, ioms ! All reporting of collision information in SyMBA (including mergers) is now recorded in the Fraggle logfile call io_log_start(param, FRAGGLE_LOG_OUT, "Fraggle logfile") + if ((param%encounter_save /= "NONE") .and. (param%encounter_save /= "ALL") .and. (param%encounter_save /= "FRAGMENTATION")) then + write(iomsg,*) 'Invalid encounter_save parameter: ',trim(adjustl(param%out_type)) + write(iomsg,*) 'Valid options are NONE, ALL, or FRAGMENTATION' + iostat = -1 + return + end if + ! Call the base method (which also prints the contents to screen) call io_param_reader(param, unit, iotype, v_list, iostat, iomsg) end associate From 3154dfae7de9f2e3a98712fb8246b951a1d074c9 Mon Sep 17 00:00:00 2001 From: David A Minton Date: Thu, 1 Dec 2022 20:09:34 -0500 Subject: [PATCH 10/65] Added initialization of NetCDF encounter data file variables --- src/encounter/encounter_io.f90 | 71 +++++++++++++++++++++++++++++++ src/modules/encounter_classes.f90 | 38 +++++++++++++++++ src/modules/swiftest_classes.f90 | 7 +++ src/netcdf/netcdf.f90 | 2 +- 4 files changed, 117 insertions(+), 1 deletion(-) diff --git a/src/encounter/encounter_io.f90 b/src/encounter/encounter_io.f90 index 1e2f97a1a..5530b61e6 100644 --- a/src/encounter/encounter_io.f90 +++ b/src/encounter/encounter_io.f90 @@ -9,6 +9,7 @@ submodule (encounter_classes) s_encounter_io use swiftest + use netcdf contains module subroutine encounter_io_dump_storage_list(self, param) @@ -26,12 +27,70 @@ module subroutine encounter_io_initialize_output(self, param) !! author: David A. Minton !! !! Initialize a NetCDF encounter file system and defines all variables. + use, intrinsic :: ieee_arithmetic implicit none ! Arguments class(encounter_io_parameters), intent(inout) :: self !! Parameters used to identify a particular NetCDF dataset class(swiftest_parameters), intent(in) :: param !! Current run configuration parameters + ! Internals + integer(I4B) :: nvar, varid, vartype + real(DP) :: dfill + real(SP) :: sfill + logical :: fileExists + character(len=STRMAX) :: errmsg + integer(I4B) :: ndims + + dfill = ieee_value(dfill, IEEE_QUIET_NAN) + sfill = ieee_value(sfill, IEEE_QUIET_NAN) + + ! Check if the file exists, and if it does, delete it + inquire(file=param%outfile, exist=fileExists) + if (fileExists) then + open(unit=LUN, file=self%outfile, 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_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) + call check( nf90_def_dim(self%ncid, TIME_DIMNAME, NF90_UNLIMITED, self%time_dimid), "encounter_io_initialize_output nf90_def_dim time_dimid" ) ! 'y' dimension + + select case (param%out_type) + case("NETCDF_FLOAT") + self%out_type = NF90_FLOAT + case("NETCDF_DOUBLE") + self%out_type = NF90_DOUBLE + end select + + call check( nf90_def_var(self%ncid, TIME_DIMNAME, self%out_type, self%time_dimid, self%time_varid), "encounter_io_initialize_output nf90_def_var time_varid" ) + call check( nf90_def_var(self%ncid, ENCID_DIMNAME, NF90_INT, self%encid_dimid, self%encid_varid), "encounter_io_initialize_output nf90_def_var encid_varid" ) + call check( nf90_def_var(self%ncid, NENC_VARNAME, NF90_INT, self%time_dimid, self%nenc_varid), "encounter_io_initialize_output nf90_def_var nenc_varid" ) + call check( nf90_def_var(self%ncid, ID1_VARNAME, NF90_INT, [self%encid_dimid, self%time_dimid], self%id1_varid), "encounter_io_initialize_output nf90_def_var id1_varid" ) + call check( nf90_def_var(self%ncid, ID2_VARNAME, NF90_INT, [self%encid_dimid, self%time_dimid], self%id2_varid), "encounter_io_initialize_output nf90_def_var id2_varid" ) + call check( nf90_def_var(self%ncid, X1X_VARNAME, self%out_type, [self%encid_dimid, self%time_dimid], self%x1x_varid), "encounter_io_initialize_output nf90_def_var x1x_varid" ) + call check( nf90_def_var(self%ncid, X1Y_VARNAME, self%out_type, [self%encid_dimid, self%time_dimid], self%x1y_varid), "encounter_io_initialize_output nf90_def_var x1y_varid" ) + call check( nf90_def_var(self%ncid, X1Z_VARNAME, self%out_type, [self%encid_dimid, self%time_dimid], self%x1z_varid), "encounter_io_initialize_output nf90_def_var x1z_varid" ) + call check( nf90_def_var(self%ncid, X2X_VARNAME, self%out_type, [self%encid_dimid, self%time_dimid], self%x2x_varid), "encounter_io_initialize_output nf90_def_var x2x_varid" ) + call check( nf90_def_var(self%ncid, X2Y_VARNAME, self%out_type, [self%encid_dimid, self%time_dimid], self%x2y_varid), "encounter_io_initialize_output nf90_def_var x2y_varid" ) + call check( nf90_def_var(self%ncid, X2Z_VARNAME, self%out_type, [self%encid_dimid, self%time_dimid], self%x2z_varid), "encounter_io_initialize_output nf90_def_var x2z_varid" ) + call check( nf90_def_var(self%ncid, V1X_VARNAME, self%out_type, [self%encid_dimid, self%time_dimid], self%v1x_varid), "encounter_io_initialize_output nf90_def_var v1x_varid" ) + call check( nf90_def_var(self%ncid, V1Y_VARNAME, self%out_type, [self%encid_dimid, self%time_dimid], self%v1y_varid), "encounter_io_initialize_output nf90_def_var v1y_varid" ) + call check( nf90_def_var(self%ncid, V1Z_VARNAME, self%out_type, [self%encid_dimid, self%time_dimid], self%v1z_varid), "encounter_io_initialize_output nf90_def_var v1z_varid" ) + call check( nf90_def_var(self%ncid, V2X_VARNAME, self%out_type, [self%encid_dimid, self%time_dimid], self%v2x_varid), "encounter_io_initialize_output nf90_def_var v2x_varid" ) + call check( nf90_def_var(self%ncid, V2Y_VARNAME, self%out_type, [self%encid_dimid, self%time_dimid], self%v2y_varid), "encounter_io_initialize_output nf90_def_var v2y_varid" ) + call check( nf90_def_var(self%ncid, V2Z_VARNAME, self%out_type, [self%encid_dimid, self%time_dimid], self%v2z_varid), "encounter_io_initialize_output nf90_def_var v2z_varid" ) + call check( nf90_def_var(self%ncid, LEVEL_VARNAME, NF90_INT, [self%encid_dimid, self%time_dimid], self%level_varid), "encounter_io_initialize_output nf90_def_var level_varid" ) + + + ! Take the file out of define mode + call check( nf90_enddef(self%ncid), "encounter_io_initialize_output nf90_enddef" ) return + + 667 continue + write(*,*) "Error creating encounter output file. " // trim(adjustl(errmsg)) + call util_exit(FAILURE) end subroutine encounter_io_initialize_output @@ -44,6 +103,18 @@ module subroutine encounter_io_open_file(self, param, readonly) class(encounter_io_parameters), intent(inout) :: self !! Parameters used to identify a particular NetCDF dataset class(swiftest_parameters), intent(in) :: param !! Current run configuration parameters logical, optional, intent(in) :: readonly !! Logical flag indicating that this should be open read only + ! Internals + integer(I4B) :: mode, status + character(len=NF90_MAX_NAME) :: str_dim_name + character(len=STRMAX) :: errmsg + + mode = NF90_WRITE + if (present(readonly)) then + if (readonly) mode = NF90_NOWRITE + end if + + write(errmsg,*) "netcdf_open nf90_open ",trim(adjustl(param%outfile)) + call check( nf90_open(self%outfile, mode, self%ncid), errmsg) return end subroutine encounter_io_open_file diff --git a/src/modules/encounter_classes.f90 b/src/modules/encounter_classes.f90 index f41c350e0..144369346 100644 --- a/src/modules/encounter_classes.f90 +++ b/src/modules/encounter_classes.f90 @@ -17,6 +17,24 @@ module encounter_classes public integer(I4B), parameter :: SWEEPDIM = 3 + !! NetCDF dimension and variable names for the enounter save object + character(*), parameter :: ENCID_DIMNAME = "encounter" + character(*), parameter :: NENC_VARNAME = "nenc" + character(*), parameter :: ID1_VARNAME = "id1" + character(*), parameter :: ID2_VARNAME = "id2" + character(*), parameter :: X1X_VARNAME = "x1x" + character(*), parameter :: X1Y_VARNAME = "x1y" + character(*), parameter :: X1Z_VARNAME = "x1z" + character(*), parameter :: X2X_VARNAME = "x2x" + character(*), parameter :: X2Y_VARNAME = "x2y" + character(*), parameter :: X2Z_VARNAME = "x2z" + character(*), parameter :: V1X_VARNAME = "v1x" + character(*), parameter :: V1Y_VARNAME = "v1y" + character(*), parameter :: V1Z_VARNAME = "v1z" + character(*), parameter :: V2X_VARNAME = "v2x" + character(*), parameter :: V2Y_VARNAME = "v2y" + character(*), parameter :: V2Z_VARNAME = "v2z" + character(*), parameter :: LEVEL_VARNAME = "level" type :: encounter_list integer(I8B) :: nenc = 0 !! Total number of encounters @@ -48,6 +66,26 @@ module encounter_classes end type encounter_storage type, extends(netcdf_parameters) :: encounter_io_parameters + character(STRMAX) :: outfile = "encounter.nc" !! Encounter output file name + integer(I4B) :: encid_dimid !! NetCDF ID for the encounter pair index dimension + 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) :: id1_varid !! NetCDF ID for the id1 of the encounter variable + integer(I4B) :: id2_varid !! NetCDF ID for the id2 of the encounter variable + integer(I4B) :: x1x_varid !! NetCDF ID for the body1 x position variable + integer(I4B) :: x1y_varid !! NetCDF ID for the body1 y position variable + integer(I4B) :: x1z_varid !! NetCDF ID for the body1 z position variable + integer(I4B) :: x2x_varid !! NetCDF ID for the body2 x position variable + integer(I4B) :: x2y_varid !! NetCDF ID for the body2 y position variable + integer(I4B) :: x2z_varid !! NetCDF ID for the body2 z position variable + integer(I4B) :: v1x_varid !! NetCDF ID for the body1 x velocity variable + integer(I4B) :: v1y_varid !! NetCDF ID for the body1 y velocity variable + integer(I4B) :: v1z_varid !! NetCDF ID for the body1 z velocity variable + integer(I4B) :: v2x_varid !! NetCDF ID for the body2 x velocity variable + integer(I4B) :: v2y_varid !! NetCDF ID for the body2 y velocity variable + integer(I4B) :: v2z_varid !! NetCDF ID for the body2 z velocity 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 diff --git a/src/modules/swiftest_classes.f90 b/src/modules/swiftest_classes.f90 index f23a3c76e..fe35c647c 100644 --- a/src/modules/swiftest_classes.f90 +++ b/src/modules/swiftest_classes.f90 @@ -496,6 +496,13 @@ end subroutine abstract_step_system end interface interface + + module subroutine check(status, call_identifier) + implicit none + integer, intent (in) :: status !! The status code returned by a NetCDF function + character(len=*), intent(in), optional :: call_identifier + end subroutine check + module subroutine discard_pl(self, system, param) implicit none class(swiftest_pl), intent(inout) :: self !! Swiftest massive body object diff --git a/src/netcdf/netcdf.f90 b/src/netcdf/netcdf.f90 index 1dd114f92..d0098765d 100644 --- a/src/netcdf/netcdf.f90 +++ b/src/netcdf/netcdf.f90 @@ -12,7 +12,7 @@ use netcdf contains - subroutine check(status, call_identifier) + module subroutine check(status, call_identifier) !! author: Carlisle A. Wishard, Dana Singh, and David A. Minton !! !! Checks the status of all NetCDF operations to catch errors From 88489cb62684b39fc4017fd94fa446ee674fa731 Mon Sep 17 00:00:00 2001 From: David A Minton Date: Fri, 2 Dec 2022 08:34:01 -0500 Subject: [PATCH 11/65] Restructured encounter io with new dimension for the collidiers so I can reuse the regular variables from before --- src/encounter/encounter_io.f90 | 46 ++++++++++++++++++++----------- src/modules/encounter_classes.f90 | 43 +++++++---------------------- src/modules/swiftest_globals.f90 | 1 - 3 files changed, 40 insertions(+), 50 deletions(-) diff --git a/src/encounter/encounter_io.f90 b/src/encounter/encounter_io.f90 index 5530b61e6..f858d83cf 100644 --- a/src/encounter/encounter_io.f90 +++ b/src/encounter/encounter_io.f90 @@ -55,6 +55,7 @@ module subroutine encounter_io_initialize_output(self, param) 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) call check( nf90_def_dim(self%ncid, TIME_DIMNAME, NF90_UNLIMITED, self%time_dimid), "encounter_io_initialize_output nf90_def_dim time_dimid" ) ! 'y' dimension + call check( nf90_def_dim(self%ncid, COLLIDER_DIMNAME, COLLIDER_DIM_SIZE, self%collider_dimid), "encounter_io_initialize_output nf90_def_dim time_dimid" ) ! 'y' dimension select case (param%out_type) case("NETCDF_FLOAT") @@ -65,21 +66,16 @@ module subroutine encounter_io_initialize_output(self, param) call check( nf90_def_var(self%ncid, TIME_DIMNAME, self%out_type, self%time_dimid, self%time_varid), "encounter_io_initialize_output nf90_def_var time_varid" ) call check( nf90_def_var(self%ncid, ENCID_DIMNAME, NF90_INT, self%encid_dimid, self%encid_varid), "encounter_io_initialize_output nf90_def_var encid_varid" ) + call check( nf90_def_var(self%ncid, COLLIDER_DIMNAME, NF90_INT, self%collider_dimid, self%encid_varid), "encounter_io_initialize_output nf90_def_var collider_varid" ) call check( nf90_def_var(self%ncid, NENC_VARNAME, NF90_INT, self%time_dimid, self%nenc_varid), "encounter_io_initialize_output nf90_def_var nenc_varid" ) - call check( nf90_def_var(self%ncid, ID1_VARNAME, NF90_INT, [self%encid_dimid, self%time_dimid], self%id1_varid), "encounter_io_initialize_output nf90_def_var id1_varid" ) - call check( nf90_def_var(self%ncid, ID2_VARNAME, NF90_INT, [self%encid_dimid, self%time_dimid], self%id2_varid), "encounter_io_initialize_output nf90_def_var id2_varid" ) - call check( nf90_def_var(self%ncid, X1X_VARNAME, self%out_type, [self%encid_dimid, self%time_dimid], self%x1x_varid), "encounter_io_initialize_output nf90_def_var x1x_varid" ) - call check( nf90_def_var(self%ncid, X1Y_VARNAME, self%out_type, [self%encid_dimid, self%time_dimid], self%x1y_varid), "encounter_io_initialize_output nf90_def_var x1y_varid" ) - call check( nf90_def_var(self%ncid, X1Z_VARNAME, self%out_type, [self%encid_dimid, self%time_dimid], self%x1z_varid), "encounter_io_initialize_output nf90_def_var x1z_varid" ) - call check( nf90_def_var(self%ncid, X2X_VARNAME, self%out_type, [self%encid_dimid, self%time_dimid], self%x2x_varid), "encounter_io_initialize_output nf90_def_var x2x_varid" ) - call check( nf90_def_var(self%ncid, X2Y_VARNAME, self%out_type, [self%encid_dimid, self%time_dimid], self%x2y_varid), "encounter_io_initialize_output nf90_def_var x2y_varid" ) - call check( nf90_def_var(self%ncid, X2Z_VARNAME, self%out_type, [self%encid_dimid, self%time_dimid], self%x2z_varid), "encounter_io_initialize_output nf90_def_var x2z_varid" ) - call check( nf90_def_var(self%ncid, V1X_VARNAME, self%out_type, [self%encid_dimid, self%time_dimid], self%v1x_varid), "encounter_io_initialize_output nf90_def_var v1x_varid" ) - call check( nf90_def_var(self%ncid, V1Y_VARNAME, self%out_type, [self%encid_dimid, self%time_dimid], self%v1y_varid), "encounter_io_initialize_output nf90_def_var v1y_varid" ) - call check( nf90_def_var(self%ncid, V1Z_VARNAME, self%out_type, [self%encid_dimid, self%time_dimid], self%v1z_varid), "encounter_io_initialize_output nf90_def_var v1z_varid" ) - call check( nf90_def_var(self%ncid, V2X_VARNAME, self%out_type, [self%encid_dimid, self%time_dimid], self%v2x_varid), "encounter_io_initialize_output nf90_def_var v2x_varid" ) - call check( nf90_def_var(self%ncid, V2Y_VARNAME, self%out_type, [self%encid_dimid, self%time_dimid], self%v2y_varid), "encounter_io_initialize_output nf90_def_var v2y_varid" ) - call check( nf90_def_var(self%ncid, V2Z_VARNAME, self%out_type, [self%encid_dimid, self%time_dimid], self%v2z_varid), "encounter_io_initialize_output nf90_def_var v2z_varid" ) + call check( nf90_def_var(self%ncid, NAME_VARNAME, NF90_CHAR, [self%str_dimid, self%collider_dimid, self%encid_dimid], self%name_varid), "encounter_io_initialize_output nf90_def_var name_varid" ) + call check( nf90_def_var(self%ncid, ID_DIMNAME, NF90_INT, [self%collider_dimid, self%encid_dimid, self%time_dimid], self%id_varid), "encounter_io_initialize_output nf90_def_var id_varid" ) + call check( nf90_def_var(self%ncid, XHX_VARNAME, self%out_type, [self%collider_dimid, self%encid_dimid, self%time_dimid], self%xhx_varid), "encounter_io_initialize_output nf90_def_var xhx_varid" ) + call check( nf90_def_var(self%ncid, XHY_VARNAME, self%out_type, [self%collider_dimid, self%encid_dimid, self%time_dimid], self%xhy_varid), "encounter_io_initialize_output nf90_def_var xhy_varid" ) + call check( nf90_def_var(self%ncid, XHZ_VARNAME, self%out_type, [self%collider_dimid, self%encid_dimid, self%time_dimid], self%xhz_varid), "encounter_io_initialize_output nf90_def_var xhz_varid" ) + call check( nf90_def_var(self%ncid, VHX_VARNAME, self%out_type, [self%collider_dimid, self%encid_dimid, self%time_dimid], self%vhx_varid), "encounter_io_initialize_output nf90_def_var vhx_varid" ) + call check( nf90_def_var(self%ncid, VHY_VARNAME, self%out_type, [self%collider_dimid, self%encid_dimid, self%time_dimid], self%vhy_varid), "encounter_io_initialize_output nf90_def_var vhy_varid" ) + call check( nf90_def_var(self%ncid, VHZ_VARNAME, self%out_type, [self%collider_dimid, self%encid_dimid, self%time_dimid], self%vhz_varid), "encounter_io_initialize_output nf90_def_var vhz_varid" ) call check( nf90_def_var(self%ncid, LEVEL_VARNAME, NF90_INT, [self%encid_dimid, self%time_dimid], self%level_varid), "encounter_io_initialize_output nf90_def_var level_varid" ) @@ -105,7 +101,6 @@ module subroutine encounter_io_open_file(self, param, readonly) logical, optional, intent(in) :: readonly !! Logical flag indicating that this should be open read only ! Internals integer(I4B) :: mode, status - character(len=NF90_MAX_NAME) :: str_dim_name character(len=STRMAX) :: errmsg mode = NF90_WRITE @@ -113,9 +108,28 @@ module subroutine encounter_io_open_file(self, param, readonly) if (readonly) mode = NF90_NOWRITE end if - write(errmsg,*) "netcdf_open nf90_open ",trim(adjustl(param%outfile)) + 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_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" ) + call check( nf90_inq_dimid(self%ncid, COLLIDER_DIMNAME, self%collider_dimid), "encounter_io_open_file nf90_inq_dimid collider_dimid" ) + call check( nf90_inq_dimid(self%ncid, STR_DIMNAME, self%str_dimid), "encounter_io_open_file nf90_inq_dimid collider_str" ) + + call check( nf90_inq_varid(self%ncid, TIME_DIMNAME, self%time_varid), "encounter_io_open_file nf90_inq_varid time_varid" ) + call check( nf90_inq_varid(self%ncid, ENCID_DIMNAME, self%encid_varid), "encounter_io_open_file nf90_inq_varid encid_varid" ) + call check( nf90_inq_varid(self%ncid, COLLIDER_DIMNAME, self%collider_varid), "encounter_io_open_file nf90_inq_varid collider_varid" ) + call check( nf90_inq_varid(self%ncid, NAME_VARNAME, self%name_varid), "encounter_io_open_file nf90_inq_varid name_varid" ) + call check( nf90_inq_varid(self%ncid, NENC_VARNAME, self%nenc_varid), "encounter_io_open_file nf90_inq_varid nenc_varid" ) + + call check( nf90_inq_varid(self%ncid, XHX_VARNAME, self%xhx_varid), "encounter_io_open_file nf90_inq_varid xhx_varid" ) + call check( nf90_inq_varid(self%ncid, XHY_VARNAME, self%xhy_varid), "encounter_io_open_file nf90_inq_varid xhy_varid" ) + call check( nf90_inq_varid(self%ncid, XHZ_VARNAME, self%xhz_varid), "encounter_io_open_file nf90_inq_varid xhz_varid" ) + call check( nf90_inq_varid(self%ncid, VHX_VARNAME, self%vhx_varid), "encounter_io_open_file nf90_inq_varid vhx_varid" ) + call check( nf90_inq_varid(self%ncid, VHY_VARNAME, self%vhy_varid), "encounter_io_open_file nf90_inq_varid vhy_varid" ) + call check( nf90_inq_varid(self%ncid, VHZ_VARNAME, self%vhz_varid), "encounter_io_open_file nf90_inq_varid vhz_varid" ) + call check( nf90_inq_varid(self%ncid, LEVEL_VARNAME, self%level_varid), "encounter_io_open_file nf90_inq_varid level_varid" ) + return end subroutine encounter_io_open_file diff --git a/src/modules/encounter_classes.f90 b/src/modules/encounter_classes.f90 index 144369346..6f6cfa68f 100644 --- a/src/modules/encounter_classes.f90 +++ b/src/modules/encounter_classes.f90 @@ -17,24 +17,6 @@ module encounter_classes public integer(I4B), parameter :: SWEEPDIM = 3 - !! NetCDF dimension and variable names for the enounter save object - character(*), parameter :: ENCID_DIMNAME = "encounter" - character(*), parameter :: NENC_VARNAME = "nenc" - character(*), parameter :: ID1_VARNAME = "id1" - character(*), parameter :: ID2_VARNAME = "id2" - character(*), parameter :: X1X_VARNAME = "x1x" - character(*), parameter :: X1Y_VARNAME = "x1y" - character(*), parameter :: X1Z_VARNAME = "x1z" - character(*), parameter :: X2X_VARNAME = "x2x" - character(*), parameter :: X2Y_VARNAME = "x2y" - character(*), parameter :: X2Z_VARNAME = "x2z" - character(*), parameter :: V1X_VARNAME = "v1x" - character(*), parameter :: V1Y_VARNAME = "v1y" - character(*), parameter :: V1Z_VARNAME = "v1z" - character(*), parameter :: V2X_VARNAME = "v2x" - character(*), parameter :: V2Y_VARNAME = "v2y" - character(*), parameter :: V2Z_VARNAME = "v2z" - character(*), parameter :: LEVEL_VARNAME = "level" type :: encounter_list integer(I8B) :: nenc = 0 !! Total number of encounters @@ -64,26 +46,21 @@ module encounter_classes 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) + integer(I4B), parameter :: COLLIDER_DIM_SIZE = 2 !! Size of collider dimension + character(*), parameter :: NENC_VARNAME = "nenc" !! Total number of encounters + character(*), parameter :: LEVEL_VARNAME = "level" !! Recursion depth + type, extends(netcdf_parameters) :: encounter_io_parameters character(STRMAX) :: outfile = "encounter.nc" !! Encounter output file name integer(I4B) :: encid_dimid !! NetCDF ID for the encounter pair index dimension + integer(I4B) :: collider_dimid !! NetCDF ID for the collider dimension + integer(I4B) :: collider_varid !! NetCDF ID for the collider variable 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) :: id1_varid !! NetCDF ID for the id1 of the encounter variable - integer(I4B) :: id2_varid !! NetCDF ID for the id2 of the encounter variable - integer(I4B) :: x1x_varid !! NetCDF ID for the body1 x position variable - integer(I4B) :: x1y_varid !! NetCDF ID for the body1 y position variable - integer(I4B) :: x1z_varid !! NetCDF ID for the body1 z position variable - integer(I4B) :: x2x_varid !! NetCDF ID for the body2 x position variable - integer(I4B) :: x2y_varid !! NetCDF ID for the body2 y position variable - integer(I4B) :: x2z_varid !! NetCDF ID for the body2 z position variable - integer(I4B) :: v1x_varid !! NetCDF ID for the body1 x velocity variable - integer(I4B) :: v1y_varid !! NetCDF ID for the body1 y velocity variable - integer(I4B) :: v1z_varid !! NetCDF ID for the body1 z velocity variable - integer(I4B) :: v2x_varid !! NetCDF ID for the body2 x velocity variable - integer(I4B) :: v2y_varid !! NetCDF ID for the body2 y velocity variable - integer(I4B) :: v2z_varid !! NetCDF ID for the body2 z velocity variable integer(I4B) :: level_varid !! NetCDF ID for the recursion level variable contains diff --git a/src/modules/swiftest_globals.f90 b/src/modules/swiftest_globals.f90 index f8e5674e4..feeb0ef1c 100644 --- a/src/modules/swiftest_globals.f90 +++ b/src/modules/swiftest_globals.f90 @@ -207,7 +207,6 @@ module swiftest_globals type :: netcdf_variables 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 From 41e353e7b96dab3bf3acb3b3e15134596c213146 Mon Sep 17 00:00:00 2001 From: David A Minton Date: Fri, 2 Dec 2022 10:29:39 -0500 Subject: [PATCH 12/65] Added template for a new write_frame method for encounter list objects --- src/encounter/encounter_io.f90 | 15 ++++++++++++++- src/modules/encounter_classes.f90 | 32 +++++++++++++++++++------------ 2 files changed, 34 insertions(+), 13 deletions(-) diff --git a/src/encounter/encounter_io.f90 b/src/encounter/encounter_io.f90 index f858d83cf..4a53e2db6 100644 --- a/src/encounter/encounter_io.f90 +++ b/src/encounter/encounter_io.f90 @@ -100,7 +100,7 @@ module subroutine encounter_io_open_file(self, param, readonly) class(swiftest_parameters), intent(in) :: param !! Current run configuration parameters logical, optional, intent(in) :: readonly !! Logical flag indicating that this should be open read only ! Internals - integer(I4B) :: mode, status + integer(I4B) :: mode character(len=STRMAX) :: errmsg mode = NF90_WRITE @@ -133,4 +133,17 @@ module subroutine encounter_io_open_file(self, param, readonly) return end subroutine encounter_io_open_file + module subroutine encounter_io_write_frame(self, iu, param) + !! author: David A. Minton + !! + !! Write a frame of output of an encounter list structure. + implicit none + ! Arguments + class(encounter_list), intent(in) :: self !! Swiftest encounter structure + class(encounter_io_parameters), intent(inout) :: iu !! Parameters used to identify a particular encounter io NetCDF dataset + class(swiftest_parameters), intent(inout) :: param !! Current run configuration parameters + + return + end subroutine encounter_io_write_frame + end submodule s_encounter_io \ No newline at end of file diff --git a/src/modules/encounter_classes.f90 b/src/modules/encounter_classes.f90 index 6f6cfa68f..17bb81d9d 100644 --- a/src/modules/encounter_classes.f90 +++ b/src/modules/encounter_classes.f90 @@ -32,13 +32,14 @@ module encounter_classes real(DP), dimension(:,:), allocatable :: v2 !! the velocity of body 2 in the encounter real(DP), dimension(:), allocatable :: t !! Time of encounter contains - procedure :: setup => encounter_setup_list !! A constructor that sets the number of encounters and allocates and initializes all arrays - procedure :: append => encounter_util_append_list !! Appends elements from one structure to another - procedure :: copy => encounter_util_copy_list !! Copies elements from the source encounter list into self. - procedure :: dealloc => encounter_util_dealloc_list !! Deallocates all allocatables - procedure :: spill => encounter_util_spill_list !! "Spills" bodies from one object to another depending on the results of a mask (uses the PACK intrinsic) - procedure :: resize => encounter_util_resize_list !! Checks the current size of the encounter list against the required size and extends it by a factor of 2 more than requested if it is too small. - final :: encounter_util_final_list !! Finalize the encounter list - deallocates all allocatables + procedure :: setup => encounter_setup_list !! A constructor that sets the number of encounters and allocates and initializes all arrays + procedure :: append => encounter_util_append_list !! Appends elements from one structure to another + procedure :: copy => encounter_util_copy_list !! Copies elements from the source encounter list into self. + procedure :: dealloc => encounter_util_dealloc_list !! Deallocates all allocatables + procedure :: spill => encounter_util_spill_list !! "Spills" bodies from one object to another depending on the results of a mask (uses the PACK intrinsic) + procedure :: resize => encounter_util_resize_list !! Checks the current size of the encounter list against the required size and extends it by a factor of 2 more than requested if it is too small. + procedure :: write_frame => encounter_io_write_frame !! Writes a frame of encounter data to file + final :: encounter_util_final_list !! Finalize the encounter list - deallocates all allocatables end type encounter_list type, extends(swiftest_storage) :: encounter_storage @@ -48,11 +49,11 @@ module encounter_classes 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) - integer(I4B), parameter :: COLLIDER_DIM_SIZE = 2 !! Size of collider dimension - character(*), parameter :: NENC_VARNAME = "nenc" !! Total number of encounters - character(*), parameter :: LEVEL_VARNAME = "level" !! Recursion depth + 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) + integer(I4B), parameter :: COLLIDER_DIM_SIZE = 2 !! Size of collider dimension + character(*), parameter :: NENC_VARNAME = "nenc" !! Total number of encounters + character(*), parameter :: LEVEL_VARNAME = "level" !! Recursion depth type, extends(netcdf_parameters) :: encounter_io_parameters character(STRMAX) :: outfile = "encounter.nc" !! Encounter output file name @@ -219,6 +220,13 @@ module subroutine encounter_io_open_file(self, param, readonly) logical, optional, intent(in) :: readonly !! Logical flag indicating that this should be open read only end subroutine encounter_io_open_file + module subroutine encounter_io_write_frame(self, iu, param) + implicit none + class(encounter_list), intent(in) :: self !! Swiftest encounter structure + class(encounter_io_parameters), intent(inout) :: iu !! Parameters used to identify a particular encounter io NetCDF dataset + class(swiftest_parameters), intent(inout) :: param !! Current run configuration parameters + end subroutine encounter_io_write_frame + module subroutine encounter_setup_aabb(self, n, n_last) implicit none class(encounter_bounding_box), intent(inout) :: self !! Swiftest encounter structure From 49133c6afadfb5bd9beeae9d933f4e520751c174 Mon Sep 17 00:00:00 2001 From: MintoDA1 <51412913+MintoDA1@users.noreply.github.com> Date: Fri, 2 Dec 2022 10:43:34 -0500 Subject: [PATCH 13/65] Updated comment to be more accurate --- src/symba/symba_encounter_check.f90 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/symba/symba_encounter_check.f90 b/src/symba/symba_encounter_check.f90 index 035d7fd3c..f574a9a3e 100644 --- a/src/symba/symba_encounter_check.f90 +++ b/src/symba/symba_encounter_check.f90 @@ -85,7 +85,7 @@ end function symba_encounter_check_pl module function symba_encounter_check(self, param, system, dt, irec) result(lany_encounter) !! author: David A. Minton !! - !! Check for an encounter between test particles and massive bodies in the pltpenc list. + !! Check for an encounter between test particles and massive bodies in the plplenc and pltpenc list. !! Note: This method works for the polymorphic symba_pltpenc and symba_plplenc types. !! !! Adapted from portions of David E. Kaufmann's Swifter routine: symba_step_recur.f90 From c927119872c122a33e6a1f43ce3d1a19cae66184 Mon Sep 17 00:00:00 2001 From: David A Minton Date: Fri, 2 Dec 2022 11:06:12 -0500 Subject: [PATCH 14/65] Fixed problem where encounter checks were using heliocentric instead of barycentric velocities --- src/symba/symba_encounter_check.f90 | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/symba/symba_encounter_check.f90 b/src/symba/symba_encounter_check.f90 index 035d7fd3c..48672142e 100644 --- a/src/symba/symba_encounter_check.f90 +++ b/src/symba/symba_encounter_check.f90 @@ -43,10 +43,10 @@ module function symba_encounter_check_pl(self, param, system, dt, irec) result(l call pl%set_renc(irec) if (nplt == 0) then - call encounter_check_all_plpl(param, npl, pl%xh, pl%vh, pl%renc, dt, nenc, index1, index2, lvdotr) + call encounter_check_all_plpl(param, npl, pl%xh, pl%vb, pl%renc, dt, nenc, index1, index2, lvdotr) else - call encounter_check_all_plplm(param, nplm, nplt, pl%xh(:,1:nplm), pl%vh(:,1:nplm), pl%xh(:,nplm+1:npl), & - pl%vh(:,nplm+1:npl), pl%renc(1:nplm), pl%renc(nplm+1:npl), dt, nenc, index1, index2, lvdotr) + call encounter_check_all_plplm(param, nplm, nplt, pl%xh(:,1:nplm), pl%vb(:,1:nplm), pl%xh(:,nplm+1:npl), & + pl%vb(:,nplm+1:npl), pl%renc(1:nplm), pl%renc(nplm+1:npl), dt, nenc, index1, index2, lvdotr) end if lany_encounter = nenc > 0_I8B @@ -136,7 +136,7 @@ module function symba_encounter_check(self, param, system, dt, irec) result(lany i = self%index1(k) j = self%index2(k) xr(:) = pl%xh(:,j) - pl%xh(:,i) - vr(:) = pl%vh(:,j) - pl%vh(:,i) + vr(:) = pl%vb(:,j) - pl%vb(:,i) rcrit12 = pl%renc(i) + pl%renc(j) call encounter_check_one(xr(1), xr(2), xr(3), vr(1), vr(2), vr(3), rcrit12, dt, lencounter(lidx), self%lvdotr(k)) if (lencounter(lidx)) then @@ -151,7 +151,7 @@ module function symba_encounter_check(self, param, system, dt, irec) result(lany i = self%index1(k) j = self%index2(k) xr(:) = tp%xh(:,j) - pl%xh(:,i) - vr(:) = tp%vh(:,j) - pl%vh(:,i) + vr(:) = tp%vb(:,j) - pl%vb(:,i) call encounter_check_one(xr(1), xr(2), xr(3), vr(1), vr(2), vr(3), pl%renc(i), dt, & lencounter(lidx), self%lvdotr(k)) if (lencounter(lidx)) then @@ -213,7 +213,7 @@ module function symba_encounter_check_tp(self, param, system, dt, irec) result(l associate(tp => self, ntp => self%nbody, pl => system%pl, npl => system%pl%nbody) call pl%set_renc(irec) - call encounter_check_all_pltp(param, npl, ntp, pl%xh, pl%vh, tp%xh, tp%vh, pl%renc, dt, nenc, index1, index2, lvdotr) + call encounter_check_all_pltp(param, npl, ntp, pl%xh, pl%vb, tp%xh, tp%vb, pl%renc, dt, nenc, index1, index2, lvdotr) lany_encounter = nenc > 0 if (lany_encounter) then From 82c93299426345e493675d0b2d98324450868c30 Mon Sep 17 00:00:00 2001 From: David A Minton Date: Fri, 2 Dec 2022 12:27:05 -0500 Subject: [PATCH 15/65] Added a resize method and more operations leading up to saving the encounter list history --- src/encounter/encounter_util.f90 | 38 +++++++++++++++++++++++++++++ src/modules/encounter_classes.f90 | 8 +++++- src/modules/symba_classes.f90 | 1 + src/symba/symba_encounter_check.f90 | 10 ++++++-- src/symba/symba_step.f90 | 1 + 5 files changed, 55 insertions(+), 3 deletions(-) diff --git a/src/encounter/encounter_util.f90 b/src/encounter/encounter_util.f90 index 76ac0e492..8cdc5c94f 100644 --- a/src/encounter/encounter_util.f90 +++ b/src/encounter/encounter_util.f90 @@ -176,6 +176,44 @@ module subroutine encounter_util_resize_list(self, nnew) end subroutine encounter_util_resize_list + module subroutine encounter_util_resize_storage(self, nnew) + !! author: David A. Minton + !! + !! Checks the current size of the encounter storage against the required size and extends it by a factor of 2 more than requested if it is too small. + !! Note: The reason to extend it by a factor of 2 is for performance. When there are many enounters per step, resizing every time you want to add an + !! encounter takes significant computational effort. Resizing by a factor of 2 is a tradeoff between performance (fewer resize calls) and memory managment + !! Memory usage grows by a factor of 2 each time it fills up, but no more. + implicit none + ! Arguments + class(encounter_storage(*)), allocatable, intent(inout) :: self !! Swiftest encounter list + integer(I4B), intent(in) :: nnew !! New size of list needed + ! Internals + type(encounter_storage(nframes=:)), allocatable :: tmp + integer(I4B) :: i, nold + logical :: lmalloc + + + lmalloc = allocated(self) + if (lmalloc) then + nold = self%nframes + else + nold = 0 + end if + + if (nnew > nold) then + allocate(encounter_storage(nnew) :: tmp) + if (lmalloc) then + do i = 1, nold + if (allocated(self%frame(i)%item)) tmp%frame(i) = self%frame(i)%item + end do + deallocate(self) + end if + call move_alloc(tmp,self) + end if + + return + end subroutine encounter_util_resize_storage + module subroutine encounter_util_spill_list(self, discards, lspill_list, ldestructive) !! author: David A. Minton !! diff --git a/src/modules/encounter_classes.f90 b/src/modules/encounter_classes.f90 index 17bb81d9d..10c9cceec 100644 --- a/src/modules/encounter_classes.f90 +++ b/src/modules/encounter_classes.f90 @@ -43,7 +43,7 @@ module encounter_classes end type encounter_list type, extends(swiftest_storage) :: encounter_storage - !! A class that that is used to store simulation history data between file output + !! 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 @@ -279,6 +279,12 @@ module subroutine encounter_util_resize_list(self, nnew) integer(I8B), intent(in) :: nnew !! New size of list needed end subroutine encounter_util_resize_list + module subroutine encounter_util_resize_storage(self, nnew) + implicit none + class(encounter_storage(*)), allocatable, intent(inout) :: self !! Swiftest encounter list + integer(I4B), intent(in) :: nnew !! New size of list needed + end subroutine encounter_util_resize_storage + module subroutine encounter_util_spill_list(self, discards, lspill_list, ldestructive) implicit none class(encounter_list), intent(inout) :: self !! Swiftest encounter list diff --git a/src/modules/symba_classes.f90 b/src/modules/symba_classes.f90 index 988d75d95..f303d6143 100644 --- a/src/modules/symba_classes.f90 +++ b/src/modules/symba_classes.f90 @@ -186,6 +186,7 @@ module symba_classes class(symba_plplenc), allocatable :: plplcollision_list !! List of massive body-massive body collisions in a single step integer(I4B) :: irec !! System recursion level type(encounter_storage(nframes=:)), allocatable :: encounter_history + integer(I4B) :: iframe = 0 !! Encounter history frame number contains procedure :: write_discard => symba_io_write_discard !! Write out information about discarded and merged planets and test particles in SyMBA procedure :: initialize => symba_setup_initialize_system !! Performs SyMBA-specific initilization steps diff --git a/src/symba/symba_encounter_check.f90 b/src/symba/symba_encounter_check.f90 index 26996302f..8983dfa97 100644 --- a/src/symba/symba_encounter_check.f90 +++ b/src/symba/symba_encounter_check.f90 @@ -34,7 +34,7 @@ module function symba_encounter_check_pl(self, param, system, dt, irec) result(l lany_encounter = .false. if (self%nbody == 0) return - associate(pl => self, plplenc_list => system%plplenc_list) + associate(pl => self, plplenc_list => system%plplenc_list, cb => system%cb, iframe => system%iframe, encounter_history => system%encounter_history) npl = pl%nbody nplm = pl%nplm @@ -57,7 +57,7 @@ module function symba_encounter_check_pl(self, param, system, dt, irec) result(l call move_alloc(index2, plplenc_list%index2) end if - if (lany_encounter) then + if (lany_encounter) then do k = 1_I8B, nenc i = plplenc_list%index1(k) j = plplenc_list%index2(k) @@ -65,6 +65,10 @@ module function symba_encounter_check_pl(self, param, system, dt, irec) result(l plplenc_list%id2(k) = pl%id(j) plplenc_list%status(k) = ACTIVE plplenc_list%level(k) = irec + plplenc_list%x1(:,k) = pl%xh(:,i) + plplenc_list%x2(:,k) = pl%xh(:,j) + plplenc_list%v1(:,k) = pl%vb(:,i) - cb%vb(:) + plplenc_list%v2(:,k) = pl%vb(:,j) - cb%vb(:) pl%lencounter(i) = .true. pl%lencounter(j) = .true. pl%levelg(i) = irec @@ -74,6 +78,8 @@ module function symba_encounter_check_pl(self, param, system, dt, irec) result(l pl%nplenc(i) = pl%nplenc(i) + 1 pl%nplenc(j) = pl%nplenc(j) + 1 end do + iframe = iframe + 1 + encounter_history%frame(iframe) = plplenc_list end if end associate diff --git a/src/symba/symba_step.f90 b/src/symba/symba_step.f90 index e24eeec31..d936ebcea 100644 --- a/src/symba/symba_step.f90 +++ b/src/symba/symba_step.f90 @@ -275,6 +275,7 @@ module subroutine symba_step_reset_system(self, param) nenc_old = system%plplenc_list%nenc call system%plplenc_list%setup(0_I8B) call system%plplcollision_list%setup(0_I8B) + system%iframe = 0 if (npl > 0) then pl%lcollision(1:npl) = .false. call pl%reset_kinship([(i, i=1, npl)]) From 538310cf552aa354d3883b0305ae49a4adfeb0a0 Mon Sep 17 00:00:00 2001 From: David A Minton Date: Fri, 2 Dec 2022 14:35:06 -0500 Subject: [PATCH 16/65] updated resizer to double the size each time it needs to grow --- src/encounter/encounter_util.f90 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/encounter/encounter_util.f90 b/src/encounter/encounter_util.f90 index 8cdc5c94f..c2597377a 100644 --- a/src/encounter/encounter_util.f90 +++ b/src/encounter/encounter_util.f90 @@ -201,7 +201,7 @@ module subroutine encounter_util_resize_storage(self, nnew) end if if (nnew > nold) then - allocate(encounter_storage(nnew) :: tmp) + allocate(encounter_storage(2 * nnew) :: tmp) if (lmalloc) then do i = 1, nold if (allocated(self%frame(i)%item)) tmp%frame(i) = self%frame(i)%item From 813c736fb8dca38ec5d85a6d7f9f415210a01ee6 Mon Sep 17 00:00:00 2001 From: David A Minton Date: Fri, 2 Dec 2022 15:06:30 -0500 Subject: [PATCH 17/65] Added mass, radius, and name variables to encounter list. Also added collision time to SyMBAs version of the list. Added methods needed for basic operations on the lists --- src/encounter/encounter_setup.f90 | 26 ++++++++++++++++++++++--- src/encounter/encounter_util.f90 | 30 +++++++++++++++++++++++++---- src/modules/encounter_classes.f90 | 30 +++++++++++++++++------------ src/modules/symba_classes.f90 | 17 ++++++++-------- src/symba/symba_collision.f90 | 2 +- src/symba/symba_encounter_check.f90 | 15 ++++++++++++--- src/symba/symba_setup.f90 | 3 +++ src/symba/symba_step.f90 | 3 ++- src/symba/symba_util.f90 | 26 ++++++++++++++++++++++--- 9 files changed, 117 insertions(+), 35 deletions(-) diff --git a/src/encounter/encounter_setup.f90 b/src/encounter/encounter_setup.f90 index 95b2680a0..c741cf0a7 100644 --- a/src/encounter/encounter_setup.f90 +++ b/src/encounter/encounter_setup.f90 @@ -62,6 +62,8 @@ module subroutine encounter_setup_list(self, n) ! Arguments class(encounter_list), intent(inout) :: self !! Swiftest encounter structure integer(I8B), intent(in) :: n !! Number of encounters to allocate space for + ! Internals + integer(I8B) :: i if (n < 0) return @@ -75,10 +77,16 @@ module subroutine encounter_setup_list(self, n) if (allocated(self%x2)) deallocate(self%x2) if (allocated(self%v1)) deallocate(self%v1) if (allocated(self%v2)) deallocate(self%v2) - if (allocated(self%t)) deallocate(self%t) + if (allocated(self%Gmass1)) deallocate(self%Gmass1) + if (allocated(self%Gmass2)) deallocate(self%Gmass2) + if (allocated(self%radius1)) deallocate(self%radius1) + if (allocated(self%radius2)) deallocate(self%radius2) + if (allocated(self%name1)) deallocate(self%name1) + if (allocated(self%name2)) deallocate(self%name2) self%nenc = n if (n == 0_I8B) return + self%t = 0.0_DP allocate(self%lvdotr(n)) allocate(self%status(n)) @@ -90,7 +98,12 @@ module subroutine encounter_setup_list(self, n) allocate(self%x2(NDIM,n)) allocate(self%v1(NDIM,n)) allocate(self%v2(NDIM,n)) - allocate(self%t(n)) + allocate(self%Gmass1(n)) + allocate(self%Gmass2(n)) + allocate(self%radius1(n)) + allocate(self%radius2(n)) + allocate(self%name1(n)) + allocate(self%name2(n)) self%lvdotr(:) = .false. self%status(:) = INACTIVE @@ -102,7 +115,14 @@ module subroutine encounter_setup_list(self, n) self%x2(:,:) = 0.0_DP self%v1(:,:) = 0.0_DP self%v2(:,:) = 0.0_DP - self%t(:) = 0.0_DP + self%Gmass1(:) = 0.0_DP + self%Gmass2(:) = 0.0_DP + self%radius1(:) = 0.0_DP + self%radius2(:) = 0.0_DP + do i = 1_I8B, n + self%name1(i) = "UNNAMED" + self%name2(i) = "UNNAMED" + end do return end subroutine encounter_setup_list diff --git a/src/encounter/encounter_util.f90 b/src/encounter/encounter_util.f90 index c2597377a..e6d70dd53 100644 --- a/src/encounter/encounter_util.f90 +++ b/src/encounter/encounter_util.f90 @@ -36,7 +36,12 @@ module subroutine encounter_util_append_list(self, source, lsource_mask) call util_append(self%x2, source%x2, nold, nsrc, lsource_mask) call util_append(self%v1, source%v1, nold, nsrc, lsource_mask) call util_append(self%v2, source%v2, nold, nsrc, lsource_mask) - call util_append(self%t, source%t, nold, nsrc, lsource_mask) + call util_append(self%Gmass1, source%Gmass1, nold, nsrc, lsource_mask) + call util_append(self%Gmass2, source%Gmass2, nold, nsrc, lsource_mask) + call util_append(self%radius1, source%radius1, nold, nsrc, lsource_mask) + call util_append(self%radius2, source%radius2, nold, nsrc, lsource_mask) + call util_append(self%name1, source%name1, nold, nsrc, lsource_mask) + call util_append(self%name2, source%name2, nold, nsrc, lsource_mask) self%nenc = nold + count(lsource_mask(1:nsrc)) return @@ -54,6 +59,7 @@ module subroutine encounter_util_copy_list(self, source) associate(n => source%nenc) self%nenc = n + self%t = source%t self%lvdotr(1:n) = source%lvdotr(1:n) self%status(1:n) = source%status(1:n) self%index1(1:n) = source%index1(1:n) @@ -64,7 +70,12 @@ module subroutine encounter_util_copy_list(self, source) self%x2(:,1:n) = source%x2(:,1:n) self%v1(:,1:n) = source%v1(:,1:n) self%v2(:,1:n) = source%v2(:,1:n) - self%t(1:n) = source%t(1:n) + self%Gmass1(1:n) = source%Gmass1(1:n) + self%Gmass2(1:n) = source%Gmass2(1:n) + self%radius1(1:n) = source%radius1(1:n) + self%radius2(1:n) = source%radius2(1:n) + self%name1(1:n) = source%name1(1:n) + self%name2(1:n) = source%name2(1:n) end associate return @@ -104,7 +115,12 @@ module subroutine encounter_util_dealloc_list(self) if (allocated(self%x2)) deallocate(self%x2) if (allocated(self%v1)) deallocate(self%v1) if (allocated(self%v2)) deallocate(self%v2) - if (allocated(self%t)) deallocate(self%t) + if (allocated(self%Gmass1)) deallocate(self%Gmass1) + if (allocated(self%Gmass2)) deallocate(self%Gmass2) + if (allocated(self%radius1)) deallocate(self%radius1) + if (allocated(self%radius2)) deallocate(self%radius2) + if (allocated(self%name1)) deallocate(self%name1) + if (allocated(self%name2)) deallocate(self%name2) return end subroutine encounter_util_dealloc_list @@ -214,6 +230,7 @@ module subroutine encounter_util_resize_storage(self, nnew) return end subroutine encounter_util_resize_storage + module subroutine encounter_util_spill_list(self, discards, lspill_list, ldestructive) !! author: David A. Minton !! @@ -238,7 +255,12 @@ module subroutine encounter_util_spill_list(self, discards, lspill_list, ldestru call util_spill(keeps%x2, discards%x2, lspill_list, ldestructive) call util_spill(keeps%v1, discards%v1, lspill_list, ldestructive) call util_spill(keeps%v2, discards%v2, lspill_list, ldestructive) - call util_spill(keeps%t, discards%t, lspill_list, ldestructive) + call util_spill(keeps%Gmass1, discards%Gmass1, lspill_list, ldestructive) + call util_spill(keeps%Gmass2, discards%Gmass2, lspill_list, ldestructive) + call util_spill(keeps%radius1, discards%radius1, lspill_list, ldestructive) + call util_spill(keeps%radius2, discards%radius2, lspill_list, ldestructive) + call util_spill(keeps%name1, discards%name1, lspill_list, ldestructive) + call util_spill(keeps%name2, discards%name2, lspill_list, ldestructive) nenc_old = keeps%nenc diff --git a/src/modules/encounter_classes.f90 b/src/modules/encounter_classes.f90 index 10c9cceec..b8f26ce23 100644 --- a/src/modules/encounter_classes.f90 +++ b/src/modules/encounter_classes.f90 @@ -19,18 +19,24 @@ module encounter_classes integer(I4B), parameter :: SWEEPDIM = 3 type :: encounter_list - integer(I8B) :: nenc = 0 !! Total number of encounters - logical, dimension(:), allocatable :: lvdotr !! relative vdotr flag - integer(I4B), dimension(:), allocatable :: status !! status of the interaction - integer(I4B), dimension(:), allocatable :: index1 !! position of the first body in the encounter - integer(I4B), dimension(:), allocatable :: index2 !! position of the second body in the encounter - integer(I4B), dimension(:), allocatable :: id1 !! id of the first body in the encounter - integer(I4B), dimension(:), allocatable :: id2 !! id of the second body in the encounter - real(DP), dimension(:,:), allocatable :: x1 !! the position of body 1 in the encounter - real(DP), dimension(:,:), allocatable :: x2 !! the position of body 2 in the encounter - real(DP), dimension(:,:), allocatable :: v1 !! the velocity of body 1 in the encounter - real(DP), dimension(:,:), allocatable :: v2 !! the velocity of body 2 in the encounter - real(DP), dimension(:), allocatable :: t !! Time of encounter + integer(I8B) :: nenc = 0 !! Total number of encounters + real(DP) :: t !! Time of encounter + logical, dimension(:), allocatable :: lvdotr !! relative vdotr flag + integer(I4B), dimension(:), allocatable :: status !! status of the interaction + integer(I4B), dimension(:), allocatable :: index1 !! position of the first body in the encounter + integer(I4B), dimension(:), allocatable :: index2 !! position of the second body in the encounter + integer(I4B), dimension(:), allocatable :: id1 !! id of the first body in the encounter + integer(I4B), dimension(:), allocatable :: id2 !! id of the second body in the encounter + real(DP), dimension(:,:), allocatable :: x1 !! the position of body 1 in the encounter + real(DP), dimension(:,:), allocatable :: x2 !! the position of body 2 in the encounter + real(DP), dimension(:,:), allocatable :: v1 !! the velocity of body 1 in the encounter + real(DP), dimension(:,:), allocatable :: v2 !! the velocity of body 2 in the encounter + real(DP), dimension(:), allocatable :: Gmass1 !! G*mass of body 1 in the encounter + real(DP), dimension(:), allocatable :: Gmass2 !! G*mass of body 2 in the encounter + real(DP), dimension(:), allocatable :: radius1 !! radius of body 1 in the encounter + real(DP), dimension(:), allocatable :: radius2 !! radius of body 2 in the encounter + character(NAMELEN), dimension(:), allocatable :: name1 !! name body 1 in the encounter + character(NAMELEN), dimension(:), allocatable :: name2 !! name of body 2 in the encounter contains procedure :: setup => encounter_setup_list !! A constructor that sets the number of encounters and allocates and initializes all arrays procedure :: append => encounter_util_append_list !! Appends elements from one structure to another diff --git a/src/modules/symba_classes.f90 b/src/modules/symba_classes.f90 index f303d6143..139b221e0 100644 --- a/src/modules/symba_classes.f90 +++ b/src/modules/symba_classes.f90 @@ -142,7 +142,8 @@ module symba_classes !******************************************************************************************************************************* !> SyMBA class for tracking close encounters in a step type, extends(encounter_list) :: symba_encounter - integer(I4B), dimension(:), allocatable :: level !! encounter recursion level + integer(I4B), dimension(:), allocatable :: level !! encounter recursion level + real(DP), dimension(:), allocatable :: tcollision !! Time of collision contains procedure :: collision_check => symba_collision_check_encounter !! Checks if a test particle is going to collide with a massive body procedure :: encounter_check => symba_encounter_check !! Checks if massive bodies are going through close encounters with each other @@ -180,13 +181,13 @@ module symba_classes ! symba_nbody_system class definitions and method interfaces !******************************************************************************************************************************** type, extends(helio_nbody_system) :: symba_nbody_system - class(symba_merger), allocatable :: pl_adds !! List of added bodies in mergers or collisions - class(symba_pltpenc), allocatable :: pltpenc_list !! List of massive body-test particle encounters in a single step - class(symba_plplenc), allocatable :: plplenc_list !! List of massive body-massive body encounters in a single step - class(symba_plplenc), allocatable :: plplcollision_list !! List of massive body-massive body collisions in a single step - integer(I4B) :: irec !! System recursion level - type(encounter_storage(nframes=:)), allocatable :: encounter_history - integer(I4B) :: iframe = 0 !! Encounter history frame number + class(symba_merger), allocatable :: pl_adds !! List of added bodies in mergers or collisions + class(symba_pltpenc), allocatable :: pltpenc_list !! List of massive body-test particle encounters in a single step + class(symba_plplenc), allocatable :: plplenc_list !! List of massive body-massive body encounters in a single step + class(symba_plplenc), allocatable :: plplcollision_list !! List of massive body-massive body collisions in a single step + integer(I4B) :: irec !! System recursion level + type(encounter_storage(nframes=:)), allocatable :: encounter_history !! Stores encounter history for later retrieval and saving to file + integer(I4B) :: ienc_frame = 0 !! Encounter history frame number contains procedure :: write_discard => symba_io_write_discard !! Write out information about discarded and merged planets and test particles in SyMBA procedure :: initialize => symba_setup_initialize_system !! Performs SyMBA-specific initilization steps diff --git a/src/symba/symba_collision.f90 b/src/symba/symba_collision.f90 index e839af1de..04ec18b46 100644 --- a/src/symba/symba_collision.f90 +++ b/src/symba/symba_collision.f90 @@ -339,7 +339,7 @@ module function symba_collision_check_encounter(self, system, param, t, dt, irec i = self%index1(k) j = self%index2(k) if (lcollision(k)) self%status(k) = COLLISION - self%t(k) = t + self%tcollision(k) = t self%x1(:,k) = pl%xh(:,i) + system%cb%xb(:) self%v1(:,k) = pl%vb(:,i) if (isplpl) then diff --git a/src/symba/symba_encounter_check.f90 b/src/symba/symba_encounter_check.f90 index 8983dfa97..1e900a94a 100644 --- a/src/symba/symba_encounter_check.f90 +++ b/src/symba/symba_encounter_check.f90 @@ -34,7 +34,7 @@ module function symba_encounter_check_pl(self, param, system, dt, irec) result(l lany_encounter = .false. if (self%nbody == 0) return - associate(pl => self, plplenc_list => system%plplenc_list, cb => system%cb, iframe => system%iframe, encounter_history => system%encounter_history) + associate(pl => self, plplenc_list => system%plplenc_list, cb => system%cb, ienc_frame => system%ienc_frame, encounter_history => system%encounter_history) npl = pl%nbody nplm = pl%nplm @@ -69,6 +69,15 @@ module function symba_encounter_check_pl(self, param, system, dt, irec) result(l plplenc_list%x2(:,k) = pl%xh(:,j) plplenc_list%v1(:,k) = pl%vb(:,i) - cb%vb(:) plplenc_list%v2(:,k) = pl%vb(:,j) - cb%vb(:) + plplenc_list%Gmass1(k) = pl%Gmass(i) + plplenc_list%Gmass2(k) = pl%Gmass(j) + if (param%lclose) then + plplenc_list%radius1(k) = pl%radius(i) + plplenc_list%radius2(k) = pl%radius(j) + end if + plplenc_list%name1(k) = pl%info(i)%name + plplenc_list%name2(k) = pl%info(j)%name + pl%lencounter(i) = .true. pl%lencounter(j) = .true. pl%levelg(i) = irec @@ -78,8 +87,8 @@ module function symba_encounter_check_pl(self, param, system, dt, irec) result(l pl%nplenc(i) = pl%nplenc(i) + 1 pl%nplenc(j) = pl%nplenc(j) + 1 end do - iframe = iframe + 1 - encounter_history%frame(iframe) = plplenc_list + ienc_frame = ienc_frame + 1 + encounter_history%frame(ienc_frame) = plplenc_list end if end associate diff --git a/src/symba/symba_setup.f90 b/src/symba/symba_setup.f90 index 9187e4457..9a4ace98f 100644 --- a/src/symba/symba_setup.f90 +++ b/src/symba/symba_setup.f90 @@ -120,9 +120,12 @@ module subroutine symba_setup_encounter_list(self, n) if (n <= 0_I8B) return if (allocated(self%level)) deallocate(self%level) + if (allocated(self%tcollision)) deallocate(self%tcollision) allocate(self%level(n)) + allocate(self%tcollision(n)) self%level(:) = -1 + self%tcollision(:) = 0.0_DP return end subroutine symba_setup_encounter_list diff --git a/src/symba/symba_step.f90 b/src/symba/symba_step.f90 index d936ebcea..29011331d 100644 --- a/src/symba/symba_step.f90 +++ b/src/symba/symba_step.f90 @@ -275,7 +275,8 @@ module subroutine symba_step_reset_system(self, param) nenc_old = system%plplenc_list%nenc call system%plplenc_list%setup(0_I8B) call system%plplcollision_list%setup(0_I8B) - system%iframe = 0 + system%ienc_frame = 0 + if (allocated(system%encounter_history)) deallocate(system%encounter_history) if (npl > 0) then pl%lcollision(1:npl) = .false. call pl%reset_kinship([(i, i=1, npl)]) diff --git a/src/symba/symba_util.f90 b/src/symba/symba_util.f90 index 6f53d6bbd..805addee8 100644 --- a/src/symba/symba_util.f90 +++ b/src/symba/symba_util.f90 @@ -183,6 +183,7 @@ module subroutine symba_util_copy_encounter_list(self, source) class is (symba_encounter) associate(n => source%nenc) self%level(1:n) = source%level(1:n) + self%tcollision(1:n) = source%tcollision(1:n) end associate end select @@ -201,6 +202,7 @@ module subroutine symba_util_dealloc_encounter_list(self) class(symba_encounter), intent(inout) :: self !! SyMBA encounter list if (allocated(self%level)) deallocate(self%level) + if (allocated(self%tcollision)) deallocate(self%tcollision) return end subroutine symba_util_dealloc_encounter_list @@ -724,21 +726,33 @@ module subroutine symba_util_rearray_pl(self, system, param) ! This is an encounter we already know about, so save the old information system%plplenc_list%lvdotr(k) = plplenc_old%lvdotr(k) system%plplenc_list%status(k) = plplenc_old%status(k) + system%plplenc_list%Gmass1(k) = plplenc_old%Gmass1(k) + system%plplenc_list%Gmass2(k) = plplenc_old%Gmass2(k) + system%plplenc_list%radius1(k) = plplenc_old%radius1(k) + system%plplenc_list%radius2(k) = plplenc_old%radius2(k) + system%plplenc_list%name1(k) = plplenc_old%name1(k) + system%plplenc_list%name2(k) = plplenc_old%name2(k) system%plplenc_list%x1(:,k) = plplenc_old%x1(:,k) system%plplenc_list%x2(:,k) = plplenc_old%x2(:,k) system%plplenc_list%v1(:,k) = plplenc_old%v1(:,k) system%plplenc_list%v2(:,k) = plplenc_old%v2(:,k) - system%plplenc_list%t(k) = plplenc_old%t(k) + system%plplenc_list%tcollision(k) = plplenc_old%tcollision(k) system%plplenc_list%level(k) = plplenc_old%level(k) else if (((idnew1 == idold2) .and. (idnew2 == idold1))) then ! This is an encounter we already know about, but with the order reversed, so save the old information system%plplenc_list%lvdotr(k) = plplenc_old%lvdotr(k) system%plplenc_list%status(k) = plplenc_old%status(k) + system%plplenc_list%Gmass1(k) = plplenc_old%Gmass2(k) + system%plplenc_list%Gmass2(k) = plplenc_old%Gmass1(k) + system%plplenc_list%radius1(k) = plplenc_old%radius2(k) + system%plplenc_list%radius2(k) = plplenc_old%radius1(k) + system%plplenc_list%name1(k) = plplenc_old%name2(k) + system%plplenc_list%name2(k) = plplenc_old%name1(k) system%plplenc_list%x1(:,k) = plplenc_old%x2(:,k) system%plplenc_list%x2(:,k) = plplenc_old%x1(:,k) system%plplenc_list%v1(:,k) = plplenc_old%v2(:,k) system%plplenc_list%v2(:,k) = plplenc_old%v1(:,k) - system%plplenc_list%t(k) = plplenc_old%t(k) + system%plplenc_list%tcollision(k) = plplenc_old%tcollision(k) system%plplenc_list%level(k) = plplenc_old%level(k) end if system%plplenc_list%index1(k) = findloc(pl%id(1:npl), system%plplenc_list%id1(k), dim=1) @@ -761,7 +775,13 @@ module subroutine symba_util_rearray_pl(self, system, param) system%plplenc_list%id2(1:nencmin) = pack(system%plplenc_list%id2(1:nenc_old), lmask(1:nenc_old)) system%plplenc_list%lvdotr(1:nencmin) = pack(system%plplenc_list%lvdotr(1:nenc_old), lmask(1:nenc_old)) system%plplenc_list%status(1:nencmin) = pack(system%plplenc_list%status(1:nenc_old), lmask(1:nenc_old)) - system%plplenc_list%t(1:nencmin) = pack(system%plplenc_list%t(1:nenc_old), lmask(1:nenc_old)) + system%plplenc_list%Gmass1(1:nencmin) = pack(system%plplenc_list%Gmass1(1:nenc_old), lmask(1:nenc_old)) + system%plplenc_list%Gmass2(1:nencmin) = pack(system%plplenc_list%Gmass2(1:nenc_old), lmask(1:nenc_old)) + system%plplenc_list%radius1(1:nencmin) = pack(system%plplenc_list%radius1(1:nenc_old), lmask(1:nenc_old)) + system%plplenc_list%radius2(1:nencmin) = pack(system%plplenc_list%radius2(1:nenc_old), lmask(1:nenc_old)) + system%plplenc_list%name1(1:nencmin) = pack(system%plplenc_list%name1(1:nenc_old), lmask(1:nenc_old)) + system%plplenc_list%name2(1:nencmin) = pack(system%plplenc_list%name2(1:nenc_old), lmask(1:nenc_old)) + system%plplenc_list%tcollision(1:nencmin) = pack(system%plplenc_list%tcollision(1:nenc_old), lmask(1:nenc_old)) system%plplenc_list%level(1:nencmin) = pack(system%plplenc_list%level(1:nenc_old), lmask(1:nenc_old)) do i = 1, NDIM system%plplenc_list%x1(i, 1:nencmin) = pack(system%plplenc_list%x1(i, 1:nenc_old), lmask(1:nenc_old)) From fee22243f20764647dfdbc38d670b88f1205bc71 Mon Sep 17 00:00:00 2001 From: David A Minton Date: Fri, 2 Dec 2022 15:22:33 -0500 Subject: [PATCH 18/65] Added encounter history file dump operation --- src/symba/symba_step.f90 | 1 + 1 file changed, 1 insertion(+) diff --git a/src/symba/symba_step.f90 b/src/symba/symba_step.f90 index 29011331d..183105b35 100644 --- a/src/symba/symba_step.f90 +++ b/src/symba/symba_step.f90 @@ -38,6 +38,7 @@ module subroutine symba_step_system(self, param, t, dt) lencounter = pl%encounter_check(param, self, dt, 0) .or. tp%encounter_check(param, self, dt, 0) if (lencounter) then call self%interp(param, t, dt) + call self%encounter_history%dump(param) else self%irec = -1 call helio_step_system(self, param, t, dt) From ad01e29972972a9de58503d407073dc8fb55dbe5 Mon Sep 17 00:00:00 2001 From: David Minton Date: Fri, 2 Dec 2022 15:38:57 -0500 Subject: [PATCH 19/65] Added enc_file to the encounter_io_parameters data type --- src/modules/encounter_classes.f90 | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/modules/encounter_classes.f90 b/src/modules/encounter_classes.f90 index b8f26ce23..49678f388 100644 --- a/src/modules/encounter_classes.f90 +++ b/src/modules/encounter_classes.f90 @@ -62,13 +62,13 @@ module encounter_classes character(*), parameter :: LEVEL_VARNAME = "level" !! Recursion depth type, extends(netcdf_parameters) :: encounter_io_parameters - character(STRMAX) :: outfile = "encounter.nc" !! Encounter output file name - integer(I4B) :: encid_dimid !! NetCDF ID for the encounter pair index dimension - integer(I4B) :: collider_dimid !! NetCDF ID for the collider dimension - integer(I4B) :: collider_varid !! NetCDF ID for the collider variable - 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 + character(STRMAX) :: enc_file = "encounter.nc" !! Encounter output file name + integer(I4B) :: encid_dimid !! NetCDF ID for the encounter pair index dimension + integer(I4B) :: collider_dimid !! NetCDF ID for the collider dimension + integer(I4B) :: collider_varid !! NetCDF ID for the collider variable + 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 From f7b3b38d0b2e6906dcca48f2b4900dda181a13d1 Mon Sep 17 00:00:00 2001 From: David A Minton Date: Fri, 2 Dec 2022 15:45:08 -0500 Subject: [PATCH 20/65] 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) From 9bb2bda37383b2709d7556456ec58d5222047fe1 Mon Sep 17 00:00:00 2001 From: David A Minton Date: Fri, 2 Dec 2022 16:12:35 -0500 Subject: [PATCH 21/65] removed the unneeded system variable from the dump implementation --- src/io/io.f90 | 3 +-- src/modules/swiftest_classes.f90 | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/io/io.f90 b/src/io/io.f90 index 85a8d42b3..b0a752863 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, system) + module subroutine io_dump_storage(self, param) !! 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 @@ -281,7 +281,6 @@ module subroutine io_dump_storage(self, param, system) ! Arguments 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/swiftest_classes.f90 b/src/modules/swiftest_classes.f90 index fa0bdf865..8ddaf0c65 100644 --- a/src/modules/swiftest_classes.f90 +++ b/src/modules/swiftest_classes.f90 @@ -632,11 +632,10 @@ 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, system) + module subroutine io_dump_storage(self, param) 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_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) From 8b431a021b79a3ec11c76fdbbbc02954daae0df4 Mon Sep 17 00:00:00 2001 From: David A Minton Date: Fri, 2 Dec 2022 16:16:27 -0500 Subject: [PATCH 22/65] More updates to encounter write methods --- src/encounter/encounter_io.f90 | 28 ++++++++++++++++++++++------ src/modules/encounter_classes.f90 | 4 ++-- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/src/encounter/encounter_io.f90 b/src/encounter/encounter_io.f90 index 9ab5947b1..33915313d 100644 --- a/src/encounter/encounter_io.f90 +++ b/src/encounter/encounter_io.f90 @@ -12,7 +12,7 @@ use netcdf contains - module subroutine encounter_io_dump_storage_list(self, param, system) + module subroutine encounter_io_dump_storage_list(self, param) !! author: David A. Minton !! !! Dumps the time history of an encounter to file. @@ -20,12 +20,21 @@ module subroutine encounter_io_dump_storage_list(self, param, system) ! Arguments 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 + integer(I4B) :: i ! Most of this is just temporary test code just to get something working. Eventually this should get cleaned up. - - + call self%nciu%initialize(param) + do i = 1, self%nframes + if (allocated(self%frame(i)%item)) then + select type(plplenc_list => self%frame(i)%item) + class is (symba_plplenc) + self%nciu%ienc_frame = i + call plplenc_list%write_frame(self%nciu,param) + end select + end if + end do + call self%nciu%close() return @@ -42,12 +51,10 @@ module subroutine encounter_io_initialize_output(self, param) class(encounter_io_parameters), intent(inout) :: self !! Parameters used to identify a particular NetCDF dataset class(swiftest_parameters), intent(in) :: param !! Current run configuration parameters ! Internals - integer(I4B) :: nvar, varid, vartype real(DP) :: dfill real(SP) :: sfill logical :: fileExists character(len=STRMAX) :: errmsg - integer(I4B) :: ndims dfill = ieee_value(dfill, IEEE_QUIET_NAN) sfill = ieee_value(sfill, IEEE_QUIET_NAN) @@ -151,6 +158,15 @@ module subroutine encounter_io_write_frame(self, iu, param) class(encounter_list), intent(in) :: self !! Swiftest encounter structure class(encounter_io_parameters), intent(inout) :: iu !! Parameters used to identify a particular encounter io NetCDF dataset class(swiftest_parameters), intent(inout) :: param !! Current run configuration parameters + ! Internals + integer(I4B) :: i,old_mode, n + + i = iu%ienc_frame + n = int(self%nenc, kind=I4B) + call check( nf90_set_fill(iu%ncid, nf90_nofill, old_mode), "encounter_io_write_frame_base nf90_set_fill" ) + call check( nf90_put_var(iu%ncid, iu%time_varid, self%t, start=[i]), "netcdf_write_hdr_system nf90_put_var time_varid" ) + call check( nf90_put_var(iu%ncid, iu%xhx_varid, self%x1(1, 1), start=[1, 1, i]), "netcdf_write_frame_base nf90_put_var xhx_varid" ) + return end subroutine encounter_io_write_frame diff --git a/src/modules/encounter_classes.f90 b/src/modules/encounter_classes.f90 index b3d913f02..585992384 100644 --- a/src/modules/encounter_classes.f90 +++ b/src/modules/encounter_classes.f90 @@ -63,6 +63,7 @@ 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 + integer(I4B) :: ienc_frame !! Current frame number for the encounter history 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 @@ -207,11 +208,10 @@ 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, system) + module subroutine encounter_io_dump_storage_list(self, param) implicit none 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) From 83f72dc6b2200aba3e908f49eb1d9256801bf662 Mon Sep 17 00:00:00 2001 From: David A Minton Date: Fri, 2 Dec 2022 16:26:27 -0500 Subject: [PATCH 23/65] Added the rest of the write statements --- src/encounter/encounter_io.f90 | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/encounter/encounter_io.f90 b/src/encounter/encounter_io.f90 index 33915313d..39c1c84cd 100644 --- a/src/encounter/encounter_io.f90 +++ b/src/encounter/encounter_io.f90 @@ -93,6 +93,8 @@ module subroutine encounter_io_initialize_output(self, param) call check( nf90_def_var(self%ncid, VHY_VARNAME, self%out_type, [self%collider_dimid, self%encid_dimid, self%time_dimid], self%vhy_varid), "encounter_io_initialize_output nf90_def_var vhy_varid" ) call check( nf90_def_var(self%ncid, VHZ_VARNAME, self%out_type, [self%collider_dimid, self%encid_dimid, self%time_dimid], self%vhz_varid), "encounter_io_initialize_output nf90_def_var vhz_varid" ) call check( nf90_def_var(self%ncid, LEVEL_VARNAME, NF90_INT, [self%encid_dimid, self%time_dimid], self%level_varid), "encounter_io_initialize_output nf90_def_var level_varid" ) + call check( nf90_def_var(self%ncid, GMASS_VARNAME, self%out_type, [self%collider_dimid, self%encid_dimid, self%time_dimid], self%Gmass_varid), "encounter_io_initialize_output nf90_def_var Gmass_varid" ) + call check( nf90_def_var(self%ncid, RADIUS_VARNAME, self%out_type, [self%collider_dimid, self%encid_dimid, self%time_dimid], self%radius_varid), "encounter_io_initialize_output nf90_def_var radius_varid" ) ! Take the file out of define mode @@ -145,6 +147,8 @@ module subroutine encounter_io_open_file(self, param, readonly) call check( nf90_inq_varid(self%ncid, VHY_VARNAME, self%vhy_varid), "encounter_io_open_file nf90_inq_varid vhy_varid" ) call check( nf90_inq_varid(self%ncid, VHZ_VARNAME, self%vhz_varid), "encounter_io_open_file nf90_inq_varid vhz_varid" ) call check( nf90_inq_varid(self%ncid, LEVEL_VARNAME, self%level_varid), "encounter_io_open_file nf90_inq_varid level_varid" ) + call check( nf90_inq_varid(self%ncid, GMASS_VARNAME, self%Gmass_varid), "encounter_io_open_file nf90_inq_varid Gmass_varid" ) + call check( nf90_inq_varid(self%ncid, RADIUS_VARNAME, self%radius_varid), "encounter_io_open_file nf90_inq_varid radius_varid" ) return end subroutine encounter_io_open_file @@ -165,7 +169,24 @@ module subroutine encounter_io_write_frame(self, iu, param) n = int(self%nenc, kind=I4B) call check( nf90_set_fill(iu%ncid, nf90_nofill, old_mode), "encounter_io_write_frame_base nf90_set_fill" ) call check( nf90_put_var(iu%ncid, iu%time_varid, self%t, start=[i]), "netcdf_write_hdr_system nf90_put_var time_varid" ) - call check( nf90_put_var(iu%ncid, iu%xhx_varid, self%x1(1, 1), start=[1, 1, i]), "netcdf_write_frame_base nf90_put_var xhx_varid" ) + call check( nf90_put_var(iu%ncid, iu%xhx_varid, self%x1(1, :), start=[1, 1, i]), "netcdf_write_frame_base nf90_put_var xhx_varid 1" ) + call check( nf90_put_var(iu%ncid, iu%xhy_varid, self%x1(2, :), start=[1, 1, i]), "netcdf_write_frame_base nf90_put_var xhy_varid 1" ) + call check( nf90_put_var(iu%ncid, iu%xhz_varid, self%x1(3, :), start=[1, 1, i]), "netcdf_write_frame_base nf90_put_var xhz_varid 1" ) + call check( nf90_put_var(iu%ncid, iu%xhx_varid, self%x2(1, :), start=[2, 1, i]), "netcdf_write_frame_base nf90_put_var xhx_varid 2" ) + call check( nf90_put_var(iu%ncid, iu%xhy_varid, self%x2(2, :), start=[2, 1, i]), "netcdf_write_frame_base nf90_put_var xhy_varid 2" ) + call check( nf90_put_var(iu%ncid, iu%xhz_varid, self%x2(3, :), start=[2, 1, i]), "netcdf_write_frame_base nf90_put_var xhz_varid 2" ) + call check( nf90_put_var(iu%ncid, iu%vhx_varid, self%v1(1, :), start=[1, 1, i]), "netcdf_write_frame_base nf90_put_var vhx_varid 1" ) + call check( nf90_put_var(iu%ncid, iu%vhy_varid, self%v1(2, :), start=[1, 1, i]), "netcdf_write_frame_base nf90_put_var vhy_varid 1" ) + call check( nf90_put_var(iu%ncid, iu%vhz_varid, self%v1(3, :), start=[1, 1, i]), "netcdf_write_frame_base nf90_put_var vhz_varid 1" ) + call check( nf90_put_var(iu%ncid, iu%vhx_varid, self%v2(1, :), start=[2, 1, i]), "netcdf_write_frame_base nf90_put_var vhx_varid 2" ) + call check( nf90_put_var(iu%ncid, iu%vhy_varid, self%v2(2, :), start=[2, 1, i]), "netcdf_write_frame_base nf90_put_var vhy_varid 2" ) + call check( nf90_put_var(iu%ncid, iu%vhz_varid, self%v2(3, :), start=[2, 1, i]), "netcdf_write_frame_base nf90_put_var vhz_varid 2" ) + call check( nf90_put_var(iu%ncid, iu%name_varid, self%name1(:), start=[1, 1, i]), "netcdf_write_frame_base nf90_put_var name 1" ) + call check( nf90_put_var(iu%ncid, iu%name_varid, self%name2(:), start=[1, 2, i]), "netcdf_write_frame_base nf90_put_var name 2" ) + call check( nf90_put_var(iu%ncid, iu%Gmass_varid, self%Gmass1(:), start=[1, 1, i]), "netcdf_write_frame_base nf90_put_var Gmass 1" ) + call check( nf90_put_var(iu%ncid, iu%Gmass_varid, self%Gmass2(:), start=[2, 1, i]), "netcdf_write_frame_base nf90_put_var Gmass 2" ) + call check( nf90_put_var(iu%ncid, iu%radius_varid, self%radius1(:), start=[1, 1, i]), "netcdf_write_frame_base nf90_put_var radius 1" ) + call check( nf90_put_var(iu%ncid, iu%radius_varid, self%radius2(:), start=[2, 1, i]), "netcdf_write_frame_base nf90_put_var radius 2" ) return From 7f651c44cbb557d82cdb8dcadffa4861a5b7ab36 Mon Sep 17 00:00:00 2001 From: David A Minton Date: Fri, 2 Dec 2022 16:40:57 -0500 Subject: [PATCH 24/65] Moved the resize storage method to symba_nbody_system so that it can be reallocated --- src/encounter/encounter_util.f90 | 39 ---------------------------- src/modules/encounter_classes.f90 | 8 +----- src/modules/symba_classes.f90 | 7 +++++ src/symba/symba_encounter_check.f90 | 1 + src/symba/symba_util.f90 | 40 +++++++++++++++++++++++++++++ 5 files changed, 49 insertions(+), 46 deletions(-) diff --git a/src/encounter/encounter_util.f90 b/src/encounter/encounter_util.f90 index e6d70dd53..cf7dc3a71 100644 --- a/src/encounter/encounter_util.f90 +++ b/src/encounter/encounter_util.f90 @@ -192,45 +192,6 @@ module subroutine encounter_util_resize_list(self, nnew) end subroutine encounter_util_resize_list - module subroutine encounter_util_resize_storage(self, nnew) - !! author: David A. Minton - !! - !! Checks the current size of the encounter storage against the required size and extends it by a factor of 2 more than requested if it is too small. - !! Note: The reason to extend it by a factor of 2 is for performance. When there are many enounters per step, resizing every time you want to add an - !! encounter takes significant computational effort. Resizing by a factor of 2 is a tradeoff between performance (fewer resize calls) and memory managment - !! Memory usage grows by a factor of 2 each time it fills up, but no more. - implicit none - ! Arguments - class(encounter_storage(*)), allocatable, intent(inout) :: self !! Swiftest encounter list - integer(I4B), intent(in) :: nnew !! New size of list needed - ! Internals - type(encounter_storage(nframes=:)), allocatable :: tmp - integer(I4B) :: i, nold - logical :: lmalloc - - - lmalloc = allocated(self) - if (lmalloc) then - nold = self%nframes - else - nold = 0 - end if - - if (nnew > nold) then - allocate(encounter_storage(2 * nnew) :: tmp) - if (lmalloc) then - do i = 1, nold - if (allocated(self%frame(i)%item)) tmp%frame(i) = self%frame(i)%item - end do - deallocate(self) - end if - call move_alloc(tmp,self) - end if - - return - end subroutine encounter_util_resize_storage - - module subroutine encounter_util_spill_list(self, discards, lspill_list, ldestructive) !! author: David A. Minton !! diff --git a/src/modules/encounter_classes.f90 b/src/modules/encounter_classes.f90 index 585992384..1f213f84a 100644 --- a/src/modules/encounter_classes.f90 +++ b/src/modules/encounter_classes.f90 @@ -73,7 +73,7 @@ module encounter_classes !! 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 + procedure :: dump => encounter_io_dump_storage_list !! Dumps contents of encounter history to file end type encounter_storage type encounter_bounding_box_1D @@ -286,12 +286,6 @@ module subroutine encounter_util_resize_list(self, nnew) integer(I8B), intent(in) :: nnew !! New size of list needed end subroutine encounter_util_resize_list - module subroutine encounter_util_resize_storage(self, nnew) - implicit none - class(encounter_storage(*)), allocatable, intent(inout) :: self !! Swiftest encounter list - integer(I4B), intent(in) :: nnew !! New size of list needed - end subroutine encounter_util_resize_storage - module subroutine encounter_util_spill_list(self, discards, lspill_list, ldestructive) implicit none class(encounter_list), intent(inout) :: self !! Swiftest encounter list diff --git a/src/modules/symba_classes.f90 b/src/modules/symba_classes.f90 index 139b221e0..cd97b74bd 100644 --- a/src/modules/symba_classes.f90 +++ b/src/modules/symba_classes.f90 @@ -197,6 +197,7 @@ module symba_classes procedure :: recursive_step => symba_step_recur_system !! Step interacting planets and active test particles ahead in democratic heliocentric coordinates at the current recursion level, if applicable, and descend to the next deeper level if necessary procedure :: reset => symba_step_reset_system !! Resets pl, tp,and encounter structures at the start of a new step procedure :: dealloc => symba_util_dealloc_system !! Deallocates all allocatable arrays + procedure :: resize_storage => symba_util_resize_storage final :: symba_util_final_system !! Finalizes the SyMBA nbody system object - deallocates all allocatables end type symba_nbody_system @@ -700,6 +701,12 @@ module subroutine symba_util_resize_pl(self, nnew) integer(I4B), intent(in) :: nnew !! New size neded end subroutine symba_util_resize_pl + module subroutine symba_util_resize_storage(self, nnew) + implicit none + class(symba_nbody_system), intent(inout) :: self !! SyMBA nbody system object + integer(I4B), intent(in) :: nnew !! New size of list needed + end subroutine symba_util_resize_storage + module subroutine symba_util_resize_tp(self, nnew) implicit none class(symba_tp), intent(inout) :: self !! SyMBA massive body object diff --git a/src/symba/symba_encounter_check.f90 b/src/symba/symba_encounter_check.f90 index 1e900a94a..60febb3fe 100644 --- a/src/symba/symba_encounter_check.f90 +++ b/src/symba/symba_encounter_check.f90 @@ -88,6 +88,7 @@ module function symba_encounter_check_pl(self, param, system, dt, irec) result(l pl%nplenc(j) = pl%nplenc(j) + 1 end do ienc_frame = ienc_frame + 1 + call system%resize_storage(ienc_frame) encounter_history%frame(ienc_frame) = plplenc_list end if diff --git a/src/symba/symba_util.f90 b/src/symba/symba_util.f90 index 805addee8..6b3661abb 100644 --- a/src/symba/symba_util.f90 +++ b/src/symba/symba_util.f90 @@ -900,6 +900,46 @@ module subroutine symba_util_resize_pl(self, nnew) end subroutine symba_util_resize_pl + module subroutine symba_util_resize_storage(self, nnew) + !! author: David A. Minton + !! + !! Checks the current size of the encounter storage against the required size and extends it by a factor of 2 more than requested if it is too small. + !! Note: The reason to extend it by a factor of 2 is for performance. When there are many enounters per step, resizing every time you want to add an + !! encounter takes significant computational effort. Resizing by a factor of 2 is a tradeoff between performance (fewer resize calls) and memory managment + !! Memory usage grows by a factor of 2 each time it fills up, but no more. + implicit none + ! Arguments + class(symba_nbody_system), intent(inout) :: self !! Swiftest encounter list + integer(I4B), intent(in) :: nnew !! New size of list needed + ! Internals + type(encounter_storage(nframes=:)), allocatable :: tmp + integer(I4B) :: i, nold + logical :: lmalloc + + + lmalloc = allocated(self%encounter_history) + if (lmalloc) then + nold = self%encounter_history%nframes + else + nold = 0 + end if + + if (nnew > nold) then + allocate(encounter_storage(2 * nnew) :: tmp) + if (lmalloc) then + do i = 1, nold + if (allocated(self%encounter_history%frame(i)%item)) tmp%frame(i) = self%encounter_history%frame(i)%item + end do + deallocate(self%encounter_history) + end if + call move_alloc(tmp,self%encounter_history) + end if + + return + end subroutine symba_util_resize_storage + + + module subroutine symba_util_resize_tp(self, nnew) !! author: David A. Minton !! From 17e7dcb50fb15dedfb68b5e253e0930e07576ad8 Mon Sep 17 00:00:00 2001 From: David A Minton Date: Fri, 2 Dec 2022 16:54:11 -0500 Subject: [PATCH 25/65] Fixed some NetCDF stuff --- src/encounter/encounter_io.f90 | 36 ++++++++++++++--------------- src/symba/symba_encounter_check.f90 | 4 ++-- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/encounter/encounter_io.f90 b/src/encounter/encounter_io.f90 index 39c1c84cd..8df13d35c 100644 --- a/src/encounter/encounter_io.f90 +++ b/src/encounter/encounter_io.f90 @@ -169,24 +169,24 @@ module subroutine encounter_io_write_frame(self, iu, param) n = int(self%nenc, kind=I4B) call check( nf90_set_fill(iu%ncid, nf90_nofill, old_mode), "encounter_io_write_frame_base nf90_set_fill" ) call check( nf90_put_var(iu%ncid, iu%time_varid, self%t, start=[i]), "netcdf_write_hdr_system nf90_put_var time_varid" ) - call check( nf90_put_var(iu%ncid, iu%xhx_varid, self%x1(1, :), start=[1, 1, i]), "netcdf_write_frame_base nf90_put_var xhx_varid 1" ) - call check( nf90_put_var(iu%ncid, iu%xhy_varid, self%x1(2, :), start=[1, 1, i]), "netcdf_write_frame_base nf90_put_var xhy_varid 1" ) - call check( nf90_put_var(iu%ncid, iu%xhz_varid, self%x1(3, :), start=[1, 1, i]), "netcdf_write_frame_base nf90_put_var xhz_varid 1" ) - call check( nf90_put_var(iu%ncid, iu%xhx_varid, self%x2(1, :), start=[2, 1, i]), "netcdf_write_frame_base nf90_put_var xhx_varid 2" ) - call check( nf90_put_var(iu%ncid, iu%xhy_varid, self%x2(2, :), start=[2, 1, i]), "netcdf_write_frame_base nf90_put_var xhy_varid 2" ) - call check( nf90_put_var(iu%ncid, iu%xhz_varid, self%x2(3, :), start=[2, 1, i]), "netcdf_write_frame_base nf90_put_var xhz_varid 2" ) - call check( nf90_put_var(iu%ncid, iu%vhx_varid, self%v1(1, :), start=[1, 1, i]), "netcdf_write_frame_base nf90_put_var vhx_varid 1" ) - call check( nf90_put_var(iu%ncid, iu%vhy_varid, self%v1(2, :), start=[1, 1, i]), "netcdf_write_frame_base nf90_put_var vhy_varid 1" ) - call check( nf90_put_var(iu%ncid, iu%vhz_varid, self%v1(3, :), start=[1, 1, i]), "netcdf_write_frame_base nf90_put_var vhz_varid 1" ) - call check( nf90_put_var(iu%ncid, iu%vhx_varid, self%v2(1, :), start=[2, 1, i]), "netcdf_write_frame_base nf90_put_var vhx_varid 2" ) - call check( nf90_put_var(iu%ncid, iu%vhy_varid, self%v2(2, :), start=[2, 1, i]), "netcdf_write_frame_base nf90_put_var vhy_varid 2" ) - call check( nf90_put_var(iu%ncid, iu%vhz_varid, self%v2(3, :), start=[2, 1, i]), "netcdf_write_frame_base nf90_put_var vhz_varid 2" ) - call check( nf90_put_var(iu%ncid, iu%name_varid, self%name1(:), start=[1, 1, i]), "netcdf_write_frame_base nf90_put_var name 1" ) - call check( nf90_put_var(iu%ncid, iu%name_varid, self%name2(:), start=[1, 2, i]), "netcdf_write_frame_base nf90_put_var name 2" ) - call check( nf90_put_var(iu%ncid, iu%Gmass_varid, self%Gmass1(:), start=[1, 1, i]), "netcdf_write_frame_base nf90_put_var Gmass 1" ) - call check( nf90_put_var(iu%ncid, iu%Gmass_varid, self%Gmass2(:), start=[2, 1, i]), "netcdf_write_frame_base nf90_put_var Gmass 2" ) - call check( nf90_put_var(iu%ncid, iu%radius_varid, self%radius1(:), start=[1, 1, i]), "netcdf_write_frame_base nf90_put_var radius 1" ) - call check( nf90_put_var(iu%ncid, iu%radius_varid, self%radius2(:), start=[2, 1, i]), "netcdf_write_frame_base nf90_put_var radius 2" ) + call check( nf90_put_var(iu%ncid, iu%xhx_varid, self%x1(1, :), start=[1, 1, i], count=[1,n,1]), "netcdf_write_frame_base nf90_put_var xhx_varid 1" ) + call check( nf90_put_var(iu%ncid, iu%xhy_varid, self%x1(2, :), start=[1, 1, i], count=[1,n,1]), "netcdf_write_frame_base nf90_put_var xhy_varid 1" ) + call check( nf90_put_var(iu%ncid, iu%xhz_varid, self%x1(3, :), start=[1, 1, i], count=[1,n,1]), "netcdf_write_frame_base nf90_put_var xhz_varid 1" ) + call check( nf90_put_var(iu%ncid, iu%xhx_varid, self%x2(1, :), start=[2, 1, i], count=[1,n,1]), "netcdf_write_frame_base nf90_put_var xhx_varid 2" ) + call check( nf90_put_var(iu%ncid, iu%xhy_varid, self%x2(2, :), start=[2, 1, i], count=[1,n,1]), "netcdf_write_frame_base nf90_put_var xhy_varid 2" ) + call check( nf90_put_var(iu%ncid, iu%xhz_varid, self%x2(3, :), start=[2, 1, i], count=[1,n,1]), "netcdf_write_frame_base nf90_put_var xhz_varid 2" ) + call check( nf90_put_var(iu%ncid, iu%vhx_varid, self%v1(1, :), start=[1, 1, i], count=[1,n,1]), "netcdf_write_frame_base nf90_put_var vhx_varid 1" ) + call check( nf90_put_var(iu%ncid, iu%vhy_varid, self%v1(2, :), start=[1, 1, i], count=[1,n,1]), "netcdf_write_frame_base nf90_put_var vhy_varid 1" ) + call check( nf90_put_var(iu%ncid, iu%vhz_varid, self%v1(3, :), start=[1, 1, i], count=[1,n,1]), "netcdf_write_frame_base nf90_put_var vhz_varid 1" ) + call check( nf90_put_var(iu%ncid, iu%vhx_varid, self%v2(1, :), start=[2, 1, i], count=[1,n,1]), "netcdf_write_frame_base nf90_put_var vhx_varid 2" ) + call check( nf90_put_var(iu%ncid, iu%vhy_varid, self%v2(2, :), start=[2, 1, i], count=[1,n,1]), "netcdf_write_frame_base nf90_put_var vhy_varid 2" ) + call check( nf90_put_var(iu%ncid, iu%vhz_varid, self%v2(3, :), start=[2, 1, i], count=[1,n,1]), "netcdf_write_frame_base nf90_put_var vhz_varid 2" ) + call check( nf90_put_var(iu%ncid, iu%name_varid, self%name1(:), start=[1, 1, i], count=[NAMELEN,1,1]), "netcdf_write_frame_base nf90_put_var name 1" ) + call check( nf90_put_var(iu%ncid, iu%name_varid, self%name2(:), start=[1, 2, i], count=[NAMELEN,1,1]), "netcdf_write_frame_base nf90_put_var name 2" ) + call check( nf90_put_var(iu%ncid, iu%Gmass_varid, self%Gmass1(:), start=[1, 1, i], count=[1,n,1]), "netcdf_write_frame_base nf90_put_var Gmass 1" ) + call check( nf90_put_var(iu%ncid, iu%Gmass_varid, self%Gmass2(:), start=[2, 1, i], count=[1,n,1]), "netcdf_write_frame_base nf90_put_var Gmass 2" ) + call check( nf90_put_var(iu%ncid, iu%radius_varid, self%radius1(:), start=[1, 1, i], count=[1,n,1]), "netcdf_write_frame_base nf90_put_var radius 1" ) + call check( nf90_put_var(iu%ncid, iu%radius_varid, self%radius2(:), start=[2, 1, i], count=[1,n,1]), "netcdf_write_frame_base nf90_put_var radius 2" ) return diff --git a/src/symba/symba_encounter_check.f90 b/src/symba/symba_encounter_check.f90 index 60febb3fe..f07119dba 100644 --- a/src/symba/symba_encounter_check.f90 +++ b/src/symba/symba_encounter_check.f90 @@ -34,7 +34,7 @@ module function symba_encounter_check_pl(self, param, system, dt, irec) result(l lany_encounter = .false. if (self%nbody == 0) return - associate(pl => self, plplenc_list => system%plplenc_list, cb => system%cb, ienc_frame => system%ienc_frame, encounter_history => system%encounter_history) + associate(pl => self, plplenc_list => system%plplenc_list, cb => system%cb, ienc_frame => system%ienc_frame) npl = pl%nbody nplm = pl%nplm @@ -89,7 +89,7 @@ module function symba_encounter_check_pl(self, param, system, dt, irec) result(l end do ienc_frame = ienc_frame + 1 call system%resize_storage(ienc_frame) - encounter_history%frame(ienc_frame) = plplenc_list + system%encounter_history%frame(ienc_frame) = plplenc_list end if end associate From 52a595a0af457cfff33a03e6975a49d8587b7479 Mon Sep 17 00:00:00 2001 From: David A Minton Date: Fri, 2 Dec 2022 19:21:30 -0500 Subject: [PATCH 26/65] Fixed a bunch of issues, but the NetCDF file is still not quite there --- src/encounter/encounter_io.f90 | 45 +++++++++++++++++++--------------- src/symba/symba_util.f90 | 2 +- 2 files changed, 26 insertions(+), 21 deletions(-) diff --git a/src/encounter/encounter_io.f90 b/src/encounter/encounter_io.f90 index 8df13d35c..f1a553a97 100644 --- a/src/encounter/encounter_io.f90 +++ b/src/encounter/encounter_io.f90 @@ -55,6 +55,7 @@ module subroutine encounter_io_initialize_output(self, param) real(SP) :: sfill logical :: fileExists character(len=STRMAX) :: errmsg + integer(I4B), dimension(2), parameter :: collider_dimension = [1,2] dfill = ieee_value(dfill, IEEE_QUIET_NAN) sfill = ieee_value(sfill, IEEE_QUIET_NAN) @@ -82,7 +83,7 @@ module subroutine encounter_io_initialize_output(self, param) call check( nf90_def_var(self%ncid, TIME_DIMNAME, self%out_type, self%time_dimid, self%time_varid), "encounter_io_initialize_output nf90_def_var time_varid" ) call check( nf90_def_var(self%ncid, ENCID_DIMNAME, NF90_INT, self%encid_dimid, self%encid_varid), "encounter_io_initialize_output nf90_def_var encid_varid" ) - call check( nf90_def_var(self%ncid, COLLIDER_DIMNAME, NF90_INT, self%collider_dimid, self%encid_varid), "encounter_io_initialize_output nf90_def_var collider_varid" ) + call check( nf90_def_var(self%ncid, COLLIDER_DIMNAME, NF90_INT, self%collider_dimid, self%collider_varid), "encounter_io_initialize_output nf90_def_var collider_varid" ) call check( nf90_def_var(self%ncid, NENC_VARNAME, NF90_INT, self%time_dimid, self%nenc_varid), "encounter_io_initialize_output nf90_def_var nenc_varid" ) call check( nf90_def_var(self%ncid, NAME_VARNAME, NF90_CHAR, [self%str_dimid, self%collider_dimid, self%encid_dimid], self%name_varid), "encounter_io_initialize_output nf90_def_var name_varid" ) call check( nf90_def_var(self%ncid, ID_DIMNAME, NF90_INT, [self%collider_dimid, self%encid_dimid, self%time_dimid], self%id_varid), "encounter_io_initialize_output nf90_def_var id_varid" ) @@ -99,6 +100,7 @@ module subroutine encounter_io_initialize_output(self, param) ! Take the file out of define mode call check( nf90_enddef(self%ncid), "encounter_io_initialize_output nf90_enddef" ) + call check( nf90_put_var(self%ncid, self%collider_varid, collider_dimension, start=[1], count=[2]), "encounter_io_initialize_output nf90_put_var collider_varid" ) return @@ -168,25 +170,28 @@ module subroutine encounter_io_write_frame(self, iu, param) i = iu%ienc_frame n = int(self%nenc, kind=I4B) call check( nf90_set_fill(iu%ncid, nf90_nofill, old_mode), "encounter_io_write_frame_base nf90_set_fill" ) - call check( nf90_put_var(iu%ncid, iu%time_varid, self%t, start=[i]), "netcdf_write_hdr_system nf90_put_var time_varid" ) - call check( nf90_put_var(iu%ncid, iu%xhx_varid, self%x1(1, :), start=[1, 1, i], count=[1,n,1]), "netcdf_write_frame_base nf90_put_var xhx_varid 1" ) - call check( nf90_put_var(iu%ncid, iu%xhy_varid, self%x1(2, :), start=[1, 1, i], count=[1,n,1]), "netcdf_write_frame_base nf90_put_var xhy_varid 1" ) - call check( nf90_put_var(iu%ncid, iu%xhz_varid, self%x1(3, :), start=[1, 1, i], count=[1,n,1]), "netcdf_write_frame_base nf90_put_var xhz_varid 1" ) - call check( nf90_put_var(iu%ncid, iu%xhx_varid, self%x2(1, :), start=[2, 1, i], count=[1,n,1]), "netcdf_write_frame_base nf90_put_var xhx_varid 2" ) - call check( nf90_put_var(iu%ncid, iu%xhy_varid, self%x2(2, :), start=[2, 1, i], count=[1,n,1]), "netcdf_write_frame_base nf90_put_var xhy_varid 2" ) - call check( nf90_put_var(iu%ncid, iu%xhz_varid, self%x2(3, :), start=[2, 1, i], count=[1,n,1]), "netcdf_write_frame_base nf90_put_var xhz_varid 2" ) - call check( nf90_put_var(iu%ncid, iu%vhx_varid, self%v1(1, :), start=[1, 1, i], count=[1,n,1]), "netcdf_write_frame_base nf90_put_var vhx_varid 1" ) - call check( nf90_put_var(iu%ncid, iu%vhy_varid, self%v1(2, :), start=[1, 1, i], count=[1,n,1]), "netcdf_write_frame_base nf90_put_var vhy_varid 1" ) - call check( nf90_put_var(iu%ncid, iu%vhz_varid, self%v1(3, :), start=[1, 1, i], count=[1,n,1]), "netcdf_write_frame_base nf90_put_var vhz_varid 1" ) - call check( nf90_put_var(iu%ncid, iu%vhx_varid, self%v2(1, :), start=[2, 1, i], count=[1,n,1]), "netcdf_write_frame_base nf90_put_var vhx_varid 2" ) - call check( nf90_put_var(iu%ncid, iu%vhy_varid, self%v2(2, :), start=[2, 1, i], count=[1,n,1]), "netcdf_write_frame_base nf90_put_var vhy_varid 2" ) - call check( nf90_put_var(iu%ncid, iu%vhz_varid, self%v2(3, :), start=[2, 1, i], count=[1,n,1]), "netcdf_write_frame_base nf90_put_var vhz_varid 2" ) - call check( nf90_put_var(iu%ncid, iu%name_varid, self%name1(:), start=[1, 1, i], count=[NAMELEN,1,1]), "netcdf_write_frame_base nf90_put_var name 1" ) - call check( nf90_put_var(iu%ncid, iu%name_varid, self%name2(:), start=[1, 2, i], count=[NAMELEN,1,1]), "netcdf_write_frame_base nf90_put_var name 2" ) - call check( nf90_put_var(iu%ncid, iu%Gmass_varid, self%Gmass1(:), start=[1, 1, i], count=[1,n,1]), "netcdf_write_frame_base nf90_put_var Gmass 1" ) - call check( nf90_put_var(iu%ncid, iu%Gmass_varid, self%Gmass2(:), start=[2, 1, i], count=[1,n,1]), "netcdf_write_frame_base nf90_put_var Gmass 2" ) - call check( nf90_put_var(iu%ncid, iu%radius_varid, self%radius1(:), start=[1, 1, i], count=[1,n,1]), "netcdf_write_frame_base nf90_put_var radius 1" ) - call check( nf90_put_var(iu%ncid, iu%radius_varid, self%radius2(:), start=[2, 1, i], count=[1,n,1]), "netcdf_write_frame_base nf90_put_var radius 2" ) + call check( nf90_put_var(iu%ncid, iu%time_varid, self%t, start=[i]), "encounter_io_write_frame nf90_put_var time_varid" ) + call check( nf90_put_var(iu%ncid, iu%encid_varid, [(i, i=1,n)], start=[i], count=[n]), "encounter_io_write_frame nf90_put_var encid_varid" ) + + call check( nf90_put_var(iu%ncid, iu%nenc_varid, self%nenc, start=[i]), "encounter_io_frame nf90_put_var nenc_varid" ) + call check( nf90_put_var(iu%ncid, iu%name_varid, self%name1(1:n), start=[1, 1, i], count=[NAMELEN,1,1]), "netcdf_write_frame_base nf90_put_var name 1" ) + call check( nf90_put_var(iu%ncid, iu%name_varid, self%name2(1:n), start=[1, 2, i], count=[NAMELEN,1,1]), "netcdf_write_frame_base nf90_put_var name 2" ) + call check( nf90_put_var(iu%ncid, iu%xhx_varid, self%x1(1, 1:n), start=[1, 1, i], count=[1,n,1]), "netcdf_write_frame_base nf90_put_var xhx_varid 1" ) + call check( nf90_put_var(iu%ncid, iu%xhy_varid, self%x1(2, 1:n), start=[1, 1, i], count=[1,n,1]), "netcdf_write_frame_base nf90_put_var xhy_varid 1" ) + call check( nf90_put_var(iu%ncid, iu%xhz_varid, self%x1(3, 1:n), start=[1, 1, i], count=[1,n,1]), "netcdf_write_frame_base nf90_put_var xhz_varid 1" ) + call check( nf90_put_var(iu%ncid, iu%xhx_varid, self%x2(1, 1:n), start=[2, 1, i], count=[1,n,1]), "netcdf_write_frame_base nf90_put_var xhx_varid 2" ) + call check( nf90_put_var(iu%ncid, iu%xhy_varid, self%x2(2, 1:n), start=[2, 1, i], count=[1,n,1]), "netcdf_write_frame_base nf90_put_var xhy_varid 2" ) + call check( nf90_put_var(iu%ncid, iu%xhz_varid, self%x2(3, 1:n), start=[2, 1, i], count=[1,n,1]), "netcdf_write_frame_base nf90_put_var xhz_varid 2" ) + call check( nf90_put_var(iu%ncid, iu%vhx_varid, self%v1(1, 1:n), start=[1, 1, i], count=[1,n,1]), "netcdf_write_frame_base nf90_put_var vhx_varid 1" ) + call check( nf90_put_var(iu%ncid, iu%vhy_varid, self%v1(2, 1:n), start=[1, 1, i], count=[1,n,1]), "netcdf_write_frame_base nf90_put_var vhy_varid 1" ) + call check( nf90_put_var(iu%ncid, iu%vhz_varid, self%v1(3, 1:n), start=[1, 1, i], count=[1,n,1]), "netcdf_write_frame_base nf90_put_var vhz_varid 1" ) + call check( nf90_put_var(iu%ncid, iu%vhx_varid, self%v2(1, 1:n), start=[2, 1, i], count=[1,n,1]), "netcdf_write_frame_base nf90_put_var vhx_varid 2" ) + call check( nf90_put_var(iu%ncid, iu%vhy_varid, self%v2(2, 1:n), start=[2, 1, i], count=[1,n,1]), "netcdf_write_frame_base nf90_put_var vhy_varid 2" ) + call check( nf90_put_var(iu%ncid, iu%vhz_varid, self%v2(3, 1:n), start=[2, 1, i], count=[1,n,1]), "netcdf_write_frame_base nf90_put_var vhz_varid 2" ) + call check( nf90_put_var(iu%ncid, iu%Gmass_varid, self%Gmass1(1:n), start=[1, 1, i], count=[1,n,1]), "netcdf_write_frame_base nf90_put_var Gmass 1" ) + call check( nf90_put_var(iu%ncid, iu%Gmass_varid, self%Gmass2(1:n), start=[2, 1, i], count=[1,n,1]), "netcdf_write_frame_base nf90_put_var Gmass 2" ) + call check( nf90_put_var(iu%ncid, iu%radius_varid, self%radius1(1:n), start=[1, 1, i], count=[1,n,1]), "netcdf_write_frame_base nf90_put_var radius 1" ) + call check( nf90_put_var(iu%ncid, iu%radius_varid, self%radius2(1:n), start=[2, 1, i], count=[1,n,1]), "netcdf_write_frame_base nf90_put_var radius 2" ) return diff --git a/src/symba/symba_util.f90 b/src/symba/symba_util.f90 index 6b3661abb..b7cc9c915 100644 --- a/src/symba/symba_util.f90 +++ b/src/symba/symba_util.f90 @@ -925,7 +925,7 @@ module subroutine symba_util_resize_storage(self, nnew) end if if (nnew > nold) then - allocate(encounter_storage(2 * nnew) :: tmp) + allocate(encounter_storage(8 * nnew) :: tmp) if (lmalloc) then do i = 1, nold if (allocated(self%encounter_history%frame(i)%item)) tmp%frame(i) = self%encounter_history%frame(i)%item From d8783a3c56c5d56d04efd06f786c5ad630513a54 Mon Sep 17 00:00:00 2001 From: David A Minton Date: Fri, 2 Dec 2022 20:15:09 -0500 Subject: [PATCH 27/65] More small fixes --- src/encounter/encounter_io.f90 | 47 +++++++++++++++---------------- src/modules/encounter_classes.f90 | 2 -- 2 files changed, 22 insertions(+), 27 deletions(-) diff --git a/src/encounter/encounter_io.f90 b/src/encounter/encounter_io.f90 index f1a553a97..18b64bd3b 100644 --- a/src/encounter/encounter_io.f90 +++ b/src/encounter/encounter_io.f90 @@ -82,8 +82,6 @@ module subroutine encounter_io_initialize_output(self, param) end select call check( nf90_def_var(self%ncid, TIME_DIMNAME, self%out_type, self%time_dimid, self%time_varid), "encounter_io_initialize_output nf90_def_var time_varid" ) - call check( nf90_def_var(self%ncid, ENCID_DIMNAME, NF90_INT, self%encid_dimid, self%encid_varid), "encounter_io_initialize_output nf90_def_var encid_varid" ) - call check( nf90_def_var(self%ncid, COLLIDER_DIMNAME, NF90_INT, self%collider_dimid, self%collider_varid), "encounter_io_initialize_output nf90_def_var collider_varid" ) call check( nf90_def_var(self%ncid, NENC_VARNAME, NF90_INT, self%time_dimid, self%nenc_varid), "encounter_io_initialize_output nf90_def_var nenc_varid" ) call check( nf90_def_var(self%ncid, NAME_VARNAME, NF90_CHAR, [self%str_dimid, self%collider_dimid, self%encid_dimid], self%name_varid), "encounter_io_initialize_output nf90_def_var name_varid" ) call check( nf90_def_var(self%ncid, ID_DIMNAME, NF90_INT, [self%collider_dimid, self%encid_dimid, self%time_dimid], self%id_varid), "encounter_io_initialize_output nf90_def_var id_varid" ) @@ -100,7 +98,6 @@ module subroutine encounter_io_initialize_output(self, param) ! Take the file out of define mode call check( nf90_enddef(self%ncid), "encounter_io_initialize_output nf90_enddef" ) - call check( nf90_put_var(self%ncid, self%collider_varid, collider_dimension, start=[1], count=[2]), "encounter_io_initialize_output nf90_put_var collider_varid" ) return @@ -137,8 +134,6 @@ module subroutine encounter_io_open_file(self, param, readonly) call check( nf90_inq_dimid(self%ncid, STR_DIMNAME, self%str_dimid), "encounter_io_open_file nf90_inq_dimid collider_str" ) call check( nf90_inq_varid(self%ncid, TIME_DIMNAME, self%time_varid), "encounter_io_open_file nf90_inq_varid time_varid" ) - call check( nf90_inq_varid(self%ncid, ENCID_DIMNAME, self%encid_varid), "encounter_io_open_file nf90_inq_varid encid_varid" ) - call check( nf90_inq_varid(self%ncid, COLLIDER_DIMNAME, self%collider_varid), "encounter_io_open_file nf90_inq_varid collider_varid" ) call check( nf90_inq_varid(self%ncid, NAME_VARNAME, self%name_varid), "encounter_io_open_file nf90_inq_varid name_varid" ) call check( nf90_inq_varid(self%ncid, NENC_VARNAME, self%nenc_varid), "encounter_io_open_file nf90_inq_varid nenc_varid" ) @@ -171,28 +166,30 @@ module subroutine encounter_io_write_frame(self, iu, param) n = int(self%nenc, kind=I4B) call check( nf90_set_fill(iu%ncid, nf90_nofill, old_mode), "encounter_io_write_frame_base nf90_set_fill" ) call check( nf90_put_var(iu%ncid, iu%time_varid, self%t, start=[i]), "encounter_io_write_frame nf90_put_var time_varid" ) - call check( nf90_put_var(iu%ncid, iu%encid_varid, [(i, i=1,n)], start=[i], count=[n]), "encounter_io_write_frame nf90_put_var encid_varid" ) call check( nf90_put_var(iu%ncid, iu%nenc_varid, self%nenc, start=[i]), "encounter_io_frame nf90_put_var nenc_varid" ) - call check( nf90_put_var(iu%ncid, iu%name_varid, self%name1(1:n), start=[1, 1, i], count=[NAMELEN,1,1]), "netcdf_write_frame_base nf90_put_var name 1" ) - call check( nf90_put_var(iu%ncid, iu%name_varid, self%name2(1:n), start=[1, 2, i], count=[NAMELEN,1,1]), "netcdf_write_frame_base nf90_put_var name 2" ) - call check( nf90_put_var(iu%ncid, iu%xhx_varid, self%x1(1, 1:n), start=[1, 1, i], count=[1,n,1]), "netcdf_write_frame_base nf90_put_var xhx_varid 1" ) - call check( nf90_put_var(iu%ncid, iu%xhy_varid, self%x1(2, 1:n), start=[1, 1, i], count=[1,n,1]), "netcdf_write_frame_base nf90_put_var xhy_varid 1" ) - call check( nf90_put_var(iu%ncid, iu%xhz_varid, self%x1(3, 1:n), start=[1, 1, i], count=[1,n,1]), "netcdf_write_frame_base nf90_put_var xhz_varid 1" ) - call check( nf90_put_var(iu%ncid, iu%xhx_varid, self%x2(1, 1:n), start=[2, 1, i], count=[1,n,1]), "netcdf_write_frame_base nf90_put_var xhx_varid 2" ) - call check( nf90_put_var(iu%ncid, iu%xhy_varid, self%x2(2, 1:n), start=[2, 1, i], count=[1,n,1]), "netcdf_write_frame_base nf90_put_var xhy_varid 2" ) - call check( nf90_put_var(iu%ncid, iu%xhz_varid, self%x2(3, 1:n), start=[2, 1, i], count=[1,n,1]), "netcdf_write_frame_base nf90_put_var xhz_varid 2" ) - call check( nf90_put_var(iu%ncid, iu%vhx_varid, self%v1(1, 1:n), start=[1, 1, i], count=[1,n,1]), "netcdf_write_frame_base nf90_put_var vhx_varid 1" ) - call check( nf90_put_var(iu%ncid, iu%vhy_varid, self%v1(2, 1:n), start=[1, 1, i], count=[1,n,1]), "netcdf_write_frame_base nf90_put_var vhy_varid 1" ) - call check( nf90_put_var(iu%ncid, iu%vhz_varid, self%v1(3, 1:n), start=[1, 1, i], count=[1,n,1]), "netcdf_write_frame_base nf90_put_var vhz_varid 1" ) - call check( nf90_put_var(iu%ncid, iu%vhx_varid, self%v2(1, 1:n), start=[2, 1, i], count=[1,n,1]), "netcdf_write_frame_base nf90_put_var vhx_varid 2" ) - call check( nf90_put_var(iu%ncid, iu%vhy_varid, self%v2(2, 1:n), start=[2, 1, i], count=[1,n,1]), "netcdf_write_frame_base nf90_put_var vhy_varid 2" ) - call check( nf90_put_var(iu%ncid, iu%vhz_varid, self%v2(3, 1:n), start=[2, 1, i], count=[1,n,1]), "netcdf_write_frame_base nf90_put_var vhz_varid 2" ) - call check( nf90_put_var(iu%ncid, iu%Gmass_varid, self%Gmass1(1:n), start=[1, 1, i], count=[1,n,1]), "netcdf_write_frame_base nf90_put_var Gmass 1" ) - call check( nf90_put_var(iu%ncid, iu%Gmass_varid, self%Gmass2(1:n), start=[2, 1, i], count=[1,n,1]), "netcdf_write_frame_base nf90_put_var Gmass 2" ) - call check( nf90_put_var(iu%ncid, iu%radius_varid, self%radius1(1:n), start=[1, 1, i], count=[1,n,1]), "netcdf_write_frame_base nf90_put_var radius 1" ) - call check( nf90_put_var(iu%ncid, iu%radius_varid, self%radius2(1:n), start=[2, 1, i], count=[1,n,1]), "netcdf_write_frame_base nf90_put_var radius 2" ) - + call check( nf90_put_var(iu%ncid, iu%name_varid, self%name1(1:n), start=[1, 1, i], count=[NAMELEN,1,1]), "netcdf_write_frame nf90_put_var name 1" ) + call check( nf90_put_var(iu%ncid, iu%name_varid, self%name2(1:n), start=[1, 2, i], count=[NAMELEN,1,1]), "netcdf_write_frame nf90_put_var name 2" ) + call check( nf90_put_var(iu%ncid, iu%xhx_varid, self%x1(1, 1:n), start=[1, 1, i], count=[1,n,1]), "netcdf_write_frame nf90_put_var xhx_varid 1" ) + call check( nf90_put_var(iu%ncid, iu%xhy_varid, self%x1(2, 1:n), start=[1, 1, i], count=[1,n,1]), "netcdf_write_frame nf90_put_var xhy_varid 1" ) + call check( nf90_put_var(iu%ncid, iu%xhz_varid, self%x1(3, 1:n), start=[1, 1, i], count=[1,n,1]), "netcdf_write_frame nf90_put_var xhz_varid 1" ) + call check( nf90_put_var(iu%ncid, iu%xhx_varid, self%x2(1, 1:n), start=[2, 1, i], count=[1,n,1]), "netcdf_write_frame nf90_put_var xhx_varid 2" ) + call check( nf90_put_var(iu%ncid, iu%xhy_varid, self%x2(2, 1:n), start=[2, 1, i], count=[1,n,1]), "netcdf_write_frame nf90_put_var xhy_varid 2" ) + call check( nf90_put_var(iu%ncid, iu%xhz_varid, self%x2(3, 1:n), start=[2, 1, i], count=[1,n,1]), "netcdf_write_frame nf90_put_var xhz_varid 2" ) + call check( nf90_put_var(iu%ncid, iu%vhx_varid, self%v1(1, 1:n), start=[1, 1, i], count=[1,n,1]), "netcdf_write_frame nf90_put_var vhx_varid 1" ) + call check( nf90_put_var(iu%ncid, iu%vhy_varid, self%v1(2, 1:n), start=[1, 1, i], count=[1,n,1]), "netcdf_write_frame nf90_put_var vhy_varid 1" ) + call check( nf90_put_var(iu%ncid, iu%vhz_varid, self%v1(3, 1:n), start=[1, 1, i], count=[1,n,1]), "netcdf_write_frame nf90_put_var vhz_varid 1" ) + call check( nf90_put_var(iu%ncid, iu%vhx_varid, self%v2(1, 1:n), start=[2, 1, i], count=[1,n,1]), "netcdf_write_frame nf90_put_var vhx_varid 2" ) + call check( nf90_put_var(iu%ncid, iu%vhy_varid, self%v2(2, 1:n), start=[2, 1, i], count=[1,n,1]), "netcdf_write_frame nf90_put_var vhy_varid 2" ) + call check( nf90_put_var(iu%ncid, iu%vhz_varid, self%v2(3, 1:n), start=[2, 1, i], count=[1,n,1]), "netcdf_write_frame nf90_put_var vhz_varid 2" ) + call check( nf90_put_var(iu%ncid, iu%Gmass_varid, self%Gmass1(1:n), start=[1, 1, i], count=[1,n,1]), "netcdf_write_frame nf90_put_var Gmass 1" ) + call check( nf90_put_var(iu%ncid, iu%Gmass_varid, self%Gmass2(1:n), start=[2, 1, i], count=[1,n,1]), "netcdf_write_frame nf90_put_var Gmass 2" ) + call check( nf90_put_var(iu%ncid, iu%radius_varid, self%radius1(1:n), start=[1, 1, i], count=[1,n,1]), "netcdf_write_frame nf90_put_var radius 1" ) + call check( nf90_put_var(iu%ncid, iu%radius_varid, self%radius2(1:n), start=[2, 1, i], count=[1,n,1]), "netcdf_write_frame nf90_put_var radius 2" ) + select type(self) + class is (symba_encounter) + call check( nf90_put_var(iu%ncid, iu%level_varid, self%level(1:n), start=[1, i], count=[n,1]), "netcdf_write_frame nf90_put_var level" ) + end select return end subroutine encounter_io_write_frame diff --git a/src/modules/encounter_classes.f90 b/src/modules/encounter_classes.f90 index 1f213f84a..5d883162a 100644 --- a/src/modules/encounter_classes.f90 +++ b/src/modules/encounter_classes.f90 @@ -59,8 +59,6 @@ module encounter_classes character(STRMAX) :: enc_file = "encounter.nc" !! Encounter output file name integer(I4B) :: encid_dimid !! NetCDF ID for the encounter pair index dimension integer(I4B) :: collider_dimid !! NetCDF ID for the collider dimension - integer(I4B) :: collider_varid !! NetCDF ID for the collider variable - 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 integer(I4B) :: ienc_frame !! Current frame number for the encounter history From c48f09f40942f2112f39c9a51cbdfbb6f456a844 Mon Sep 17 00:00:00 2001 From: David A Minton Date: Sat, 3 Dec 2022 05:43:06 -0500 Subject: [PATCH 28/65] Moved NetCDF variable and class definitions to swiftest_classes out of swiftest_globals --- src/modules/swiftest_classes.f90 | 153 +++++++++++++++++++++++++++++++ src/modules/swiftest_globals.f90 | 152 ------------------------------ 2 files changed, 153 insertions(+), 152 deletions(-) diff --git a/src/modules/swiftest_classes.f90 b/src/modules/swiftest_classes.f90 index 8ddaf0c65..724a17994 100644 --- a/src/modules/swiftest_classes.f90 +++ b/src/modules/swiftest_classes.f90 @@ -16,6 +16,159 @@ module swiftest_classes implicit none public + !> NetCDF variable names and constants + character(*), parameter :: NETCDF_OUTFILE = 'bin.nc' !! Default output file name + character(*), parameter :: TIME_DIMNAME = "time" !! NetCDF name of the time dimension + character(*), parameter :: ID_DIMNAME = "id" !! NetCDF name of the particle id dimension + character(*), parameter :: STR_DIMNAME = "string32" !! NetCDF name of the character string dimension + character(*), parameter :: PTYPE_VARNAME = "particle_type" !! NetCDF name of the particle type variable + character(*), parameter :: NAME_VARNAME = "name" !! NetCDF name of the particle name variable + character(*), parameter :: NPL_VARNAME = "npl" !! NetCDF name of the number of active massive bodies variable + character(*), parameter :: NTP_VARNAME = "ntp" !! NetCDF name of the number of active test particles variable + character(*), parameter :: NPLM_VARNAME = "nplm" !! NetCDF name of the number of active fully interacting massive bodies variable (SyMBA) + character(*), parameter :: A_VARNAME = "a" !! NetCDF name of the semimajor axis variable + character(*), parameter :: E_VARNAME = "e" !! NetCDF name of the eccentricity variable + character(*), parameter :: INC_VARNAME = "inc" !! NetCDF name of the inclination variable + character(*), parameter :: CAPOM_VARNAME = "capom" !! NetCDF name of the long. asc. node variable + character(*), parameter :: OMEGA_VARNAME = "omega" !! NetCDF name of the arg. periapsis variable + character(*), parameter :: CAPM_VARNAME = "capm" !! NetCDF name of the mean anomaly variable + character(*), parameter :: XHX_VARNAME = "xhx" !! NetCDF name of the heliocentric position x variable + character(*), parameter :: XHY_VARNAME = "xhy" !! NetCDF name of the heliocentric position y variable + character(*), parameter :: XHZ_VARNAME = "xhz" !! NetCDF name of the heliocentric position z variable + character(*), parameter :: VHX_VARNAME = "vhx" !! NetCDF name of the heliocentric velocity x variable + character(*), parameter :: VHY_VARNAME = "vhy" !! NetCDF name of the heliocentric velocity y variable + character(*), parameter :: VHZ_VARNAME = "vhz" !! NetCDF name of the heliocentric velocity z variable + character(*), parameter :: GR_PSEUDO_VHX_VARNAME = "gr_pseudo_vhx" !! NetCDF name of the heliocentric pseudovelocity x variable (used in GR only) + character(*), parameter :: GR_PSEUDO_VHY_VARNAME = "gr_pseudo_vhy" !! NetCDF name of the heliocentric pseudovelocity y variable (used in GR only) + character(*), parameter :: GR_PSEUDO_VHZ_VARNAME = "gr_pseudo_vhz" !! NetCDF name of the heliocentric pseudovelocity z variable (used in GR only) + character(*), parameter :: GMASS_VARNAME = "Gmass" !! NetCDF name of the mass variable + character(*), parameter :: RHILL_VARNAME = "rhill" !! NetCDF name of the hill radius variable + character(*), parameter :: RADIUS_VARNAME = "radius" !! NetCDF name of the radius variable + character(*), parameter :: IP1_VARNAME = "Ip1" !! NetCDF name of the axis 1 principal moment of inertial variable + character(*), parameter :: IP2_VARNAME = "Ip2" !! NetCDF name of the axis 2 principal moment of inertial variable + character(*), parameter :: IP3_VARNAME = "Ip3" !! NetCDF name of the axis 3 principal moment of inertial variable + character(*), parameter :: ROTX_VARNAME = "rotx" !! NetCDF name of the rotation x variable + character(*), parameter :: ROTY_VARNAME = "roty" !! NetCDF name of the rotation y variable + character(*), parameter :: ROTZ_VARNAME = "rotz" !! NetCDF name of the rotation z variable + character(*), parameter :: K2_VARNAME = "k2" !! NetCDF name of the Love number variable + character(*), parameter :: Q_VARNAME = "Q" !! NetCDF name of the energy dissipation variable + character(*), parameter :: KE_ORB_VARNAME = "KE_orb" !! NetCDF name of the system orbital kinetic energy variable + character(*), parameter :: KE_SPIN_VARNAME = "KE_spin" !! NetCDF name of the system spin kinetic energy variable + character(*), parameter :: PE_VARNAME = "PE" !! NetCDF name of the system potential energy variable + character(*), parameter :: L_ORBX_VARNAME = "L_orbx" !! NetCDF name of the orbital angular momentum x variable + character(*), parameter :: L_ORBY_VARNAME = "L_orby" !! NetCDF name of the orbital angular momentum y variable + character(*), parameter :: L_ORBZ_VARNAME = "L_orbz" !! NetCDF name of the orbital angular momentum z variable + character(*), parameter :: L_SPINX_VARNAME = "L_spinx" !! NetCDF name of the spin angular momentum x variable + character(*), parameter :: L_SPINY_VARNAME = "L_spiny" !! NetCDF name of the spin angular momentum y variable + character(*), parameter :: L_SPINZ_VARNAME = "L_spinz" !! NetCDF name of the spin angular momentum z variable + character(*), parameter :: L_ESCAPEX_VARNAME = "L_escapex" !! NetCDF name of the escaped angular momentum x variable + character(*), parameter :: L_ESCAPEY_VARNAME = "L_escapey" !! NetCDF name of the escaped angular momentum y variable + character(*), parameter :: L_ESCAPEZ_VARNAME = "L_escapez" !! NetCDF name of the escaped angular momentum z variable + 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 :: STATUS_VARNAME = "status" !! NetCDF name of the current status of the body variable (includes discard type) + character(*), parameter :: ORIGIN_TYPE_VARNAME = "origin_type" !! NetCDF name of the origin type variable (Initial Conditions, Disruption, etc.) + character(*), parameter :: ORIGIN_TIME_VARNAME = "origin_time" !! NetCDF name of the time of origin variable + character(*), parameter :: COLLISION_ID_VARNAME = "collision_id" !! NetCDF name of the collision id variable + character(*), parameter :: ORIGIN_XHX_VARNAME = "origin_xhx" !! NetCDF name of the heliocentric position of the body at the time of origin x variable + character(*), parameter :: ORIGIN_XHY_VARNAME = "origin_xhy" !! NetCDF name of the heliocentric position of the body at the time of origin y variable + character(*), parameter :: ORIGIN_XHZ_VARNAME = "origin_xhz" !! NetCDF name of the heliocentric position of the body at the time of origin z variable + character(*), parameter :: ORIGIN_VHX_VARNAME = "origin_vhx" !! NetCDF name of the heliocentric velocity of the body at the time of origin x variable + character(*), parameter :: ORIGIN_VHY_VARNAME = "origin_vhy" !! NetCDF name of the heliocentric velocity of the body at the time of origin y variable + character(*), parameter :: ORIGIN_VHZ_VARNAME = "origin_vhz" !! NetCDF name of the heliocentric velocity of the body at the time of origin z variable + character(*), parameter :: DISCARD_TIME_VARNAME = "discard_time" !! NetCDF name of the time of discard variable + character(*), parameter :: DISCARD_XHX_VARNAME = "discard_xhx" !! NetCDF name of the heliocentric position of the body at the time of discard x variable + character(*), parameter :: DISCARD_XHY_VARNAME = "discard_xhy" !! NetCDF name of the heliocentric position of the body at the time of discard y variable + character(*), parameter :: DISCARD_XHZ_VARNAME = "discard_xhz" !! NetCDF name of the heliocentric position of the body at the time of discard z variable + character(*), parameter :: DISCARD_VHX_VARNAME = "discard_vhx" !! NetCDF name of the heliocentric velocity of the body at the time of discard x variable + character(*), parameter :: DISCARD_VHY_VARNAME = "discard_vhy" !! NetCDF name of the heliocentric velocity of the body at the time of discard y variable + character(*), parameter :: DISCARD_VHZ_VARNAME = "discard_vhz" !! NetCDF name of the heliocentric velocity of the body at the time of discard z variable + character(*), parameter :: DISCARD_BODY_ID_VARNAME = "discard_body_id" !! NetCDF name of the id of the other body involved in the discard + character(*), parameter :: J2RP2_VARNAME = "j2rp2" !! NetCDF name of the j2rp2 variable + character(*), parameter :: J4RP4_VARNAME = "j4rp4" !! NetCDF name of the j4pr4 variable + + !! This derived datatype stores the NetCDF ID values for each of the variables included in the NetCDF data file. This is used as the base class defined in swiftest_classes + type :: netcdf_variables + 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) :: 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) :: nplm_varid !! NetCDF ID for the number of active fully interacting massive bodies variable (SyMBA) + 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) :: gr_pseudo_vhx_varid !! NetCDF ID for the heliocentric pseudovelocity x variable (used in GR) + integer(I4B) :: gr_pseudo_vhy_varid !! NetCDF ID for the heliocentric pseudovelocity y variable (used in GR) + integer(I4B) :: gr_pseudo_vhz_varid !! NetCDF ID for the heliocentric psuedovelocity z variable (used in GR) + 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) :: j2rp2_varid !! NetCDF ID for the j2 variable + integer(I4B) :: j4rp4_varid !! NetCDF ID for the j4 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 + integer(I4B) :: status_varid !! NetCDF ID for the status variable + integer(I4B) :: origin_type_varid !! NetCDF ID for the origin type + integer(I4B) :: origin_time_varid !! NetCDF ID for the origin time + integer(I4B) :: collision_id_varid !! Netcdf ID for the origin collision ID + 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 + integer(I4B) :: discard_time_varid !! NetCDF ID for the time of discard variable + integer(I4B) :: discard_xhx_varid !! NetCDF ID for the heliocentric position of the body at the time of discard x variable + integer(I4B) :: discard_xhy_varid !! NetCDF ID for the heliocentric position of the body at the time of discard y variable + integer(I4B) :: discard_xhz_varid !! NetCDF ID for the heliocentric position of the body at the time of discard z variable + integer(I4B) :: discard_vhx_varid !! NetCDF ID for the heliocentric velocity of the body at the time of discard x variable + integer(I4B) :: discard_vhy_varid !! NetCDF ID for the heliocentric velocity of the body at the time of discard y variable + integer(I4B) :: discard_vhz_varid !! NetCDF ID for the heliocentric velocity of the body at the time of discard z variable + integer(I4B) :: discard_body_id_varid !! NetCDF ID for the id of the other body involved in the discard + integer(I4B) :: id_chunk !! Chunk size for the id dimension variables + integer(I4B) :: time_chunk !! Chunk size for the time dimension variables + logical :: lpseudo_vel_exists = .false. !! Logical flag to indicate whether or not the pseudovelocity vectors were present in an old file. + end type netcdf_variables + + type, extends(netcdf_variables) :: netcdf_parameters contains procedure :: close => netcdf_close !! Closes an open NetCDF file diff --git a/src/modules/swiftest_globals.f90 b/src/modules/swiftest_globals.f90 index feeb0ef1c..4c8c21693 100644 --- a/src/modules/swiftest_globals.f90 +++ b/src/modules/swiftest_globals.f90 @@ -131,156 +131,4 @@ module swiftest_globals integer(I4B), parameter :: NDIM2 = 2 * NDIM !! 2x the number of dimensions real(DP), parameter :: VSMALL = 2 * epsilon(1._DP) !! Very small number used to prevent floating underflow - !> NetCDF variable names and constants - character(*), parameter :: NETCDF_OUTFILE = 'bin.nc' !! Default output file name - character(*), parameter :: TIME_DIMNAME = "time" !! NetCDF name of the time dimension - character(*), parameter :: ID_DIMNAME = "id" !! NetCDF name of the particle id dimension - character(*), parameter :: STR_DIMNAME = "string32" !! NetCDF name of the character string dimension - character(*), parameter :: PTYPE_VARNAME = "particle_type" !! NetCDF name of the particle type variable - character(*), parameter :: NAME_VARNAME = "name" !! NetCDF name of the particle name variable - character(*), parameter :: NPL_VARNAME = "npl" !! NetCDF name of the number of active massive bodies variable - character(*), parameter :: NTP_VARNAME = "ntp" !! NetCDF name of the number of active test particles variable - character(*), parameter :: NPLM_VARNAME = "nplm" !! NetCDF name of the number of active fully interacting massive bodies variable (SyMBA) - character(*), parameter :: A_VARNAME = "a" !! NetCDF name of the semimajor axis variable - character(*), parameter :: E_VARNAME = "e" !! NetCDF name of the eccentricity variable - character(*), parameter :: INC_VARNAME = "inc" !! NetCDF name of the inclination variable - character(*), parameter :: CAPOM_VARNAME = "capom" !! NetCDF name of the long. asc. node variable - character(*), parameter :: OMEGA_VARNAME = "omega" !! NetCDF name of the arg. periapsis variable - character(*), parameter :: CAPM_VARNAME = "capm" !! NetCDF name of the mean anomaly variable - character(*), parameter :: XHX_VARNAME = "xhx" !! NetCDF name of the heliocentric position x variable - character(*), parameter :: XHY_VARNAME = "xhy" !! NetCDF name of the heliocentric position y variable - character(*), parameter :: XHZ_VARNAME = "xhz" !! NetCDF name of the heliocentric position z variable - character(*), parameter :: VHX_VARNAME = "vhx" !! NetCDF name of the heliocentric velocity x variable - character(*), parameter :: VHY_VARNAME = "vhy" !! NetCDF name of the heliocentric velocity y variable - character(*), parameter :: VHZ_VARNAME = "vhz" !! NetCDF name of the heliocentric velocity z variable - character(*), parameter :: GR_PSEUDO_VHX_VARNAME = "gr_pseudo_vhx" !! NetCDF name of the heliocentric pseudovelocity x variable (used in GR only) - character(*), parameter :: GR_PSEUDO_VHY_VARNAME = "gr_pseudo_vhy" !! NetCDF name of the heliocentric pseudovelocity y variable (used in GR only) - character(*), parameter :: GR_PSEUDO_VHZ_VARNAME = "gr_pseudo_vhz" !! NetCDF name of the heliocentric pseudovelocity z variable (used in GR only) - character(*), parameter :: GMASS_VARNAME = "Gmass" !! NetCDF name of the mass variable - character(*), parameter :: RHILL_VARNAME = "rhill" !! NetCDF name of the hill radius variable - character(*), parameter :: RADIUS_VARNAME = "radius" !! NetCDF name of the radius variable - character(*), parameter :: IP1_VARNAME = "Ip1" !! NetCDF name of the axis 1 principal moment of inertial variable - character(*), parameter :: IP2_VARNAME = "Ip2" !! NetCDF name of the axis 2 principal moment of inertial variable - character(*), parameter :: IP3_VARNAME = "Ip3" !! NetCDF name of the axis 3 principal moment of inertial variable - character(*), parameter :: ROTX_VARNAME = "rotx" !! NetCDF name of the rotation x variable - character(*), parameter :: ROTY_VARNAME = "roty" !! NetCDF name of the rotation y variable - character(*), parameter :: ROTZ_VARNAME = "rotz" !! NetCDF name of the rotation z variable - character(*), parameter :: K2_VARNAME = "k2" !! NetCDF name of the Love number variable - character(*), parameter :: Q_VARNAME = "Q" !! NetCDF name of the energy dissipation variable - character(*), parameter :: KE_ORB_VARNAME = "KE_orb" !! NetCDF name of the system orbital kinetic energy variable - character(*), parameter :: KE_SPIN_VARNAME = "KE_spin" !! NetCDF name of the system spin kinetic energy variable - character(*), parameter :: PE_VARNAME = "PE" !! NetCDF name of the system potential energy variable - character(*), parameter :: L_ORBX_VARNAME = "L_orbx" !! NetCDF name of the orbital angular momentum x variable - character(*), parameter :: L_ORBY_VARNAME = "L_orby" !! NetCDF name of the orbital angular momentum y variable - character(*), parameter :: L_ORBZ_VARNAME = "L_orbz" !! NetCDF name of the orbital angular momentum z variable - character(*), parameter :: L_SPINX_VARNAME = "L_spinx" !! NetCDF name of the spin angular momentum x variable - character(*), parameter :: L_SPINY_VARNAME = "L_spiny" !! NetCDF name of the spin angular momentum y variable - character(*), parameter :: L_SPINZ_VARNAME = "L_spinz" !! NetCDF name of the spin angular momentum z variable - character(*), parameter :: L_ESCAPEX_VARNAME = "L_escapex" !! NetCDF name of the escaped angular momentum x variable - character(*), parameter :: L_ESCAPEY_VARNAME = "L_escapey" !! NetCDF name of the escaped angular momentum y variable - character(*), parameter :: L_ESCAPEZ_VARNAME = "L_escapez" !! NetCDF name of the escaped angular momentum z variable - 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 :: STATUS_VARNAME = "status" !! NetCDF name of the current status of the body variable (includes discard type) - character(*), parameter :: ORIGIN_TYPE_VARNAME = "origin_type" !! NetCDF name of the origin type variable (Initial Conditions, Disruption, etc.) - character(*), parameter :: ORIGIN_TIME_VARNAME = "origin_time" !! NetCDF name of the time of origin variable - character(*), parameter :: COLLISION_ID_VARNAME = "collision_id" !! NetCDF name of the collision id variable - character(*), parameter :: ORIGIN_XHX_VARNAME = "origin_xhx" !! NetCDF name of the heliocentric position of the body at the time of origin x variable - character(*), parameter :: ORIGIN_XHY_VARNAME = "origin_xhy" !! NetCDF name of the heliocentric position of the body at the time of origin y variable - character(*), parameter :: ORIGIN_XHZ_VARNAME = "origin_xhz" !! NetCDF name of the heliocentric position of the body at the time of origin z variable - character(*), parameter :: ORIGIN_VHX_VARNAME = "origin_vhx" !! NetCDF name of the heliocentric velocity of the body at the time of origin x variable - character(*), parameter :: ORIGIN_VHY_VARNAME = "origin_vhy" !! NetCDF name of the heliocentric velocity of the body at the time of origin y variable - character(*), parameter :: ORIGIN_VHZ_VARNAME = "origin_vhz" !! NetCDF name of the heliocentric velocity of the body at the time of origin z variable - character(*), parameter :: DISCARD_TIME_VARNAME = "discard_time" !! NetCDF name of the time of discard variable - character(*), parameter :: DISCARD_XHX_VARNAME = "discard_xhx" !! NetCDF name of the heliocentric position of the body at the time of discard x variable - character(*), parameter :: DISCARD_XHY_VARNAME = "discard_xhy" !! NetCDF name of the heliocentric position of the body at the time of discard y variable - character(*), parameter :: DISCARD_XHZ_VARNAME = "discard_xhz" !! NetCDF name of the heliocentric position of the body at the time of discard z variable - character(*), parameter :: DISCARD_VHX_VARNAME = "discard_vhx" !! NetCDF name of the heliocentric velocity of the body at the time of discard x variable - character(*), parameter :: DISCARD_VHY_VARNAME = "discard_vhy" !! NetCDF name of the heliocentric velocity of the body at the time of discard y variable - character(*), parameter :: DISCARD_VHZ_VARNAME = "discard_vhz" !! NetCDF name of the heliocentric velocity of the body at the time of discard z variable - character(*), parameter :: DISCARD_BODY_ID_VARNAME = "discard_body_id" !! NetCDF name of the id of the other body involved in the discard - character(*), parameter :: J2RP2_VARNAME = "j2rp2" !! NetCDF name of the j2rp2 variable - character(*), parameter :: J4RP4_VARNAME = "j4rp4" !! NetCDF name of the j4pr4 variable - - !! This derived datatype stores the NetCDF ID values for each of the variables included in the NetCDF data file. This is used as the base class defined in swiftest_classes - type :: netcdf_variables - 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) :: 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) :: nplm_varid !! NetCDF ID for the number of active fully interacting massive bodies variable (SyMBA) - 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) :: gr_pseudo_vhx_varid !! NetCDF ID for the heliocentric pseudovelocity x variable (used in GR) - integer(I4B) :: gr_pseudo_vhy_varid !! NetCDF ID for the heliocentric pseudovelocity y variable (used in GR) - integer(I4B) :: gr_pseudo_vhz_varid !! NetCDF ID for the heliocentric psuedovelocity z variable (used in GR) - 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) :: j2rp2_varid !! NetCDF ID for the j2 variable - integer(I4B) :: j4rp4_varid !! NetCDF ID for the j4 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 - integer(I4B) :: status_varid !! NetCDF ID for the status variable - integer(I4B) :: origin_type_varid !! NetCDF ID for the origin type - integer(I4B) :: origin_time_varid !! NetCDF ID for the origin time - integer(I4B) :: collision_id_varid !! Netcdf ID for the origin collision ID - 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 - integer(I4B) :: discard_time_varid !! NetCDF ID for the time of discard variable - integer(I4B) :: discard_xhx_varid !! NetCDF ID for the heliocentric position of the body at the time of discard x variable - integer(I4B) :: discard_xhy_varid !! NetCDF ID for the heliocentric position of the body at the time of discard y variable - integer(I4B) :: discard_xhz_varid !! NetCDF ID for the heliocentric position of the body at the time of discard z variable - integer(I4B) :: discard_vhx_varid !! NetCDF ID for the heliocentric velocity of the body at the time of discard x variable - integer(I4B) :: discard_vhy_varid !! NetCDF ID for the heliocentric velocity of the body at the time of discard y variable - integer(I4B) :: discard_vhz_varid !! NetCDF ID for the heliocentric velocity of the body at the time of discard z variable - integer(I4B) :: discard_body_id_varid !! NetCDF ID for the id of the other body involved in the discard - integer(I4B) :: id_chunk !! Chunk size for the id dimension variables - integer(I4B) :: time_chunk !! Chunk size for the time dimension variables - logical :: lpseudo_vel_exists = .false. !! Logical flag to indicate whether or not the pseudovelocity vectors were present in an old file. - end type netcdf_variables - end module swiftest_globals From 428dc10e3d3f4279a014a69c62d00df474012265 Mon Sep 17 00:00:00 2001 From: David A Minton Date: Sat, 3 Dec 2022 06:31:38 -0500 Subject: [PATCH 29/65] Restructured NetCDF parameter definition to consolidate all definitions into one place instead --- src/encounter/encounter_io.f90 | 70 +++--- src/modules/encounter_classes.f90 | 24 +- src/modules/swiftest_classes.f90 | 299 +++++++++++++------------ src/netcdf/netcdf.f90 | 358 +++++++++++++++--------------- 4 files changed, 378 insertions(+), 373 deletions(-) diff --git a/src/encounter/encounter_io.f90 b/src/encounter/encounter_io.f90 index 18b64bd3b..badd3685a 100644 --- a/src/encounter/encounter_io.f90 +++ b/src/encounter/encounter_io.f90 @@ -69,10 +69,10 @@ module subroutine encounter_io_initialize_output(self, param) 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) - call check( nf90_def_dim(self%ncid, TIME_DIMNAME, NF90_UNLIMITED, self%time_dimid), "encounter_io_initialize_output nf90_def_dim time_dimid" ) ! 'y' dimension - call check( nf90_def_dim(self%ncid, COLLIDER_DIMNAME, COLLIDER_DIM_SIZE, self%collider_dimid), "encounter_io_initialize_output nf90_def_dim time_dimid" ) ! 'y' dimension + call check( nf90_def_dim(self%ncid, self%encid_dimname, NF90_UNLIMITED, self%encid_dimid), "encounter_io_initialize_output nf90_def_dim encid_dimid" ) + call check( nf90_def_dim(self%ncid, self%str_dimname, NAMELEN, self%str_dimid), "encounter_io_initialize_output nf90_def_dim str_dimid" ) ! Dimension for string variables (aka character arrays) + call check( nf90_def_dim(self%ncid, self%time_dimname, NF90_UNLIMITED, self%time_dimid), "encounter_io_initialize_output nf90_def_dim time_dimid" ) ! 'y' dimension + call check( nf90_def_dim(self%ncid, self%collider_dimname, self%collider_dim_size, self%collider_dimid), "encounter_io_initialize_output nf90_def_dim time_dimid" ) ! 'y' dimension select case (param%out_type) case("NETCDF_FLOAT") @@ -81,19 +81,19 @@ module subroutine encounter_io_initialize_output(self, param) self%out_type = NF90_DOUBLE end select - call check( nf90_def_var(self%ncid, TIME_DIMNAME, self%out_type, self%time_dimid, self%time_varid), "encounter_io_initialize_output nf90_def_var time_varid" ) - call check( nf90_def_var(self%ncid, NENC_VARNAME, NF90_INT, self%time_dimid, self%nenc_varid), "encounter_io_initialize_output nf90_def_var nenc_varid" ) - call check( nf90_def_var(self%ncid, NAME_VARNAME, NF90_CHAR, [self%str_dimid, self%collider_dimid, self%encid_dimid], self%name_varid), "encounter_io_initialize_output nf90_def_var name_varid" ) - call check( nf90_def_var(self%ncid, ID_DIMNAME, NF90_INT, [self%collider_dimid, self%encid_dimid, self%time_dimid], self%id_varid), "encounter_io_initialize_output nf90_def_var id_varid" ) - call check( nf90_def_var(self%ncid, XHX_VARNAME, self%out_type, [self%collider_dimid, self%encid_dimid, self%time_dimid], self%xhx_varid), "encounter_io_initialize_output nf90_def_var xhx_varid" ) - call check( nf90_def_var(self%ncid, XHY_VARNAME, self%out_type, [self%collider_dimid, self%encid_dimid, self%time_dimid], self%xhy_varid), "encounter_io_initialize_output nf90_def_var xhy_varid" ) - call check( nf90_def_var(self%ncid, XHZ_VARNAME, self%out_type, [self%collider_dimid, self%encid_dimid, self%time_dimid], self%xhz_varid), "encounter_io_initialize_output nf90_def_var xhz_varid" ) - call check( nf90_def_var(self%ncid, VHX_VARNAME, self%out_type, [self%collider_dimid, self%encid_dimid, self%time_dimid], self%vhx_varid), "encounter_io_initialize_output nf90_def_var vhx_varid" ) - call check( nf90_def_var(self%ncid, VHY_VARNAME, self%out_type, [self%collider_dimid, self%encid_dimid, self%time_dimid], self%vhy_varid), "encounter_io_initialize_output nf90_def_var vhy_varid" ) - call check( nf90_def_var(self%ncid, VHZ_VARNAME, self%out_type, [self%collider_dimid, self%encid_dimid, self%time_dimid], self%vhz_varid), "encounter_io_initialize_output nf90_def_var vhz_varid" ) - call check( nf90_def_var(self%ncid, LEVEL_VARNAME, NF90_INT, [self%encid_dimid, self%time_dimid], self%level_varid), "encounter_io_initialize_output nf90_def_var level_varid" ) - call check( nf90_def_var(self%ncid, GMASS_VARNAME, self%out_type, [self%collider_dimid, self%encid_dimid, self%time_dimid], self%Gmass_varid), "encounter_io_initialize_output nf90_def_var Gmass_varid" ) - call check( nf90_def_var(self%ncid, RADIUS_VARNAME, self%out_type, [self%collider_dimid, self%encid_dimid, self%time_dimid], self%radius_varid), "encounter_io_initialize_output nf90_def_var radius_varid" ) + call check( nf90_def_var(self%ncid, self%time_dimname, self%out_type, self%time_dimid, self%time_varid), "encounter_io_initialize_output nf90_def_var time_varid" ) + call check( nf90_def_var(self%ncid, self%nenc_varname, NF90_INT, self%time_dimid, self%nenc_varid), "encounter_io_initialize_output nf90_def_var nenc_varid" ) + call check( nf90_def_var(self%ncid, self%name_varname, NF90_CHAR, [self%str_dimid, self%collider_dimid, self%encid_dimid], self%name_varid), "encounter_io_initialize_output nf90_def_var name_varid" ) + call check( nf90_def_var(self%ncid, self%id_dimname, NF90_INT, [self%collider_dimid, self%encid_dimid, self%time_dimid], self%id_varid), "encounter_io_initialize_output nf90_def_var id_varid" ) + call check( nf90_def_var(self%ncid, self%xhx_varname, self%out_type, [self%collider_dimid, self%encid_dimid, self%time_dimid], self%xhx_varid), "encounter_io_initialize_output nf90_def_var xhx_varid" ) + call check( nf90_def_var(self%ncid, self%xhy_varname, self%out_type, [self%collider_dimid, self%encid_dimid, self%time_dimid], self%xhy_varid), "encounter_io_initialize_output nf90_def_var xhy_varid" ) + call check( nf90_def_var(self%ncid, self%xhz_varname, self%out_type, [self%collider_dimid, self%encid_dimid, self%time_dimid], self%xhz_varid), "encounter_io_initialize_output nf90_def_var xhz_varid" ) + call check( nf90_def_var(self%ncid, self%vhx_varname, self%out_type, [self%collider_dimid, self%encid_dimid, self%time_dimid], self%vhx_varid), "encounter_io_initialize_output nf90_def_var vhx_varid" ) + call check( nf90_def_var(self%ncid, self%vhy_varname, self%out_type, [self%collider_dimid, self%encid_dimid, self%time_dimid], self%vhy_varid), "encounter_io_initialize_output nf90_def_var vhy_varid" ) + call check( nf90_def_var(self%ncid, self%vhz_varname, self%out_type, [self%collider_dimid, self%encid_dimid, self%time_dimid], self%vhz_varid), "encounter_io_initialize_output nf90_def_var vhz_varid" ) + call check( nf90_def_var(self%ncid, self%level_varname, NF90_INT, [self%encid_dimid, self%time_dimid], self%level_varid), "encounter_io_initialize_output nf90_def_var level_varid" ) + call check( nf90_def_var(self%ncid, self%gmass_varname, self%out_type, [self%collider_dimid, self%encid_dimid, self%time_dimid], self%Gmass_varid), "encounter_io_initialize_output nf90_def_var Gmass_varid" ) + call check( nf90_def_var(self%ncid, self%radius_varname, self%out_type, [self%collider_dimid, self%encid_dimid, self%time_dimid], self%radius_varid), "encounter_io_initialize_output nf90_def_var radius_varid" ) ! Take the file out of define mode @@ -128,24 +128,24 @@ module subroutine encounter_io_open_file(self, param, readonly) write(errmsg,*) "encounter_io_open_file nf90_open ",trim(adjustl(param%outfile)) 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" ) - call check( nf90_inq_dimid(self%ncid, COLLIDER_DIMNAME, self%collider_dimid), "encounter_io_open_file nf90_inq_dimid collider_dimid" ) - call check( nf90_inq_dimid(self%ncid, STR_DIMNAME, self%str_dimid), "encounter_io_open_file nf90_inq_dimid collider_str" ) - - call check( nf90_inq_varid(self%ncid, TIME_DIMNAME, self%time_varid), "encounter_io_open_file nf90_inq_varid time_varid" ) - call check( nf90_inq_varid(self%ncid, NAME_VARNAME, self%name_varid), "encounter_io_open_file nf90_inq_varid name_varid" ) - call check( nf90_inq_varid(self%ncid, NENC_VARNAME, self%nenc_varid), "encounter_io_open_file nf90_inq_varid nenc_varid" ) - - call check( nf90_inq_varid(self%ncid, XHX_VARNAME, self%xhx_varid), "encounter_io_open_file nf90_inq_varid xhx_varid" ) - call check( nf90_inq_varid(self%ncid, XHY_VARNAME, self%xhy_varid), "encounter_io_open_file nf90_inq_varid xhy_varid" ) - call check( nf90_inq_varid(self%ncid, XHZ_VARNAME, self%xhz_varid), "encounter_io_open_file nf90_inq_varid xhz_varid" ) - call check( nf90_inq_varid(self%ncid, VHX_VARNAME, self%vhx_varid), "encounter_io_open_file nf90_inq_varid vhx_varid" ) - call check( nf90_inq_varid(self%ncid, VHY_VARNAME, self%vhy_varid), "encounter_io_open_file nf90_inq_varid vhy_varid" ) - call check( nf90_inq_varid(self%ncid, VHZ_VARNAME, self%vhz_varid), "encounter_io_open_file nf90_inq_varid vhz_varid" ) - call check( nf90_inq_varid(self%ncid, LEVEL_VARNAME, self%level_varid), "encounter_io_open_file nf90_inq_varid level_varid" ) - call check( nf90_inq_varid(self%ncid, GMASS_VARNAME, self%Gmass_varid), "encounter_io_open_file nf90_inq_varid Gmass_varid" ) - call check( nf90_inq_varid(self%ncid, RADIUS_VARNAME, self%radius_varid), "encounter_io_open_file nf90_inq_varid radius_varid" ) + call check( nf90_inq_dimid(self%ncid, self%time_dimname, self%time_dimid), "encounter_io_open_file nf90_inq_dimid time_dimid" ) + call check( nf90_inq_dimid(self%ncid, self%encid_dimname, self%encid_dimid), "encounter_io_open_file nf90_inq_dimid encid_dimid" ) + call check( nf90_inq_dimid(self%ncid, self%collider_dimname, self%collider_dimid), "encounter_io_open_file nf90_inq_dimid collider_dimid" ) + call check( nf90_inq_dimid(self%ncid, self%str_dimname, self%str_dimid), "encounter_io_open_file nf90_inq_dimid collider_str" ) + + call check( nf90_inq_varid(self%ncid, self%time_dimname, self%time_varid), "encounter_io_open_file nf90_inq_varid time_varid" ) + call check( nf90_inq_varid(self%ncid, self%name_varname, self%name_varid), "encounter_io_open_file nf90_inq_varid name_varid" ) + call check( nf90_inq_varid(self%ncid, self%nenc_varname, self%nenc_varid), "encounter_io_open_file nf90_inq_varid nenc_varid" ) + + call check( nf90_inq_varid(self%ncid, self%xhx_varname, self%xhx_varid), "encounter_io_open_file nf90_inq_varid xhx_varid" ) + call check( nf90_inq_varid(self%ncid, self%xhy_varname, self%xhy_varid), "encounter_io_open_file nf90_inq_varid xhy_varid" ) + call check( nf90_inq_varid(self%ncid, self%xhz_varname, self%xhz_varid), "encounter_io_open_file nf90_inq_varid xhz_varid" ) + call check( nf90_inq_varid(self%ncid, self%vhx_varname, self%vhx_varid), "encounter_io_open_file nf90_inq_varid vhx_varid" ) + call check( nf90_inq_varid(self%ncid, self%vhy_varname, self%vhy_varid), "encounter_io_open_file nf90_inq_varid vhy_varid" ) + call check( nf90_inq_varid(self%ncid, self%vhz_varname, self%vhz_varid), "encounter_io_open_file nf90_inq_varid vhz_varid" ) + call check( nf90_inq_varid(self%ncid, self%level_varname, self%level_varid), "encounter_io_open_file nf90_inq_varid level_varid" ) + call check( nf90_inq_varid(self%ncid, self%gmass_varname, self%Gmass_varid), "encounter_io_open_file nf90_inq_varid Gmass_varid" ) + call check( nf90_inq_varid(self%ncid, self%radius_varname, self%radius_varid), "encounter_io_open_file nf90_inq_varid radius_varid" ) return end subroutine encounter_io_open_file diff --git a/src/modules/encounter_classes.f90 b/src/modules/encounter_classes.f90 index 5d883162a..1bb595b02 100644 --- a/src/modules/encounter_classes.f90 +++ b/src/modules/encounter_classes.f90 @@ -49,19 +49,19 @@ module encounter_classes end type encounter_list !! 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) - integer(I4B), parameter :: COLLIDER_DIM_SIZE = 2 !! Size of collider dimension - character(*), parameter :: NENC_VARNAME = "nenc" !! Total number of encounters - character(*), parameter :: LEVEL_VARNAME = "level" !! Recursion depth - type, extends(netcdf_parameters) :: encounter_io_parameters - character(STRMAX) :: enc_file = "encounter.nc" !! Encounter output file name - integer(I4B) :: encid_dimid !! NetCDF ID for the encounter pair index dimension - integer(I4B) :: collider_dimid !! NetCDF ID for the collider dimension - integer(I4B) :: nenc_varid !! NetCDF ID for the number of encounters variable - integer(I4B) :: level_varid !! NetCDF ID for the recursion level variable - integer(I4B) :: ienc_frame !! Current frame number for the encounter history + integer(I4B) :: COLLIDER_DIM_SIZE = 2 !! Size of collider dimension + integer(I4B) :: ienc_frame !! Current frame number for the encounter history + character(STRMAX) :: enc_file = "encounter.nc" !! Encounter output file name + + character(NAMELEN) :: encid_dimname = "encounter" !! The index of the encountering pair in the encounter list + integer(I4B) :: encid_dimid !! ID for the encounter pair index dimension + character(NAMELEN) :: collider_dimname = "collider" !! Dimension that defines the colliding bodies (bodies 1 and 2 are at dimension coordinates 1 and 2, respectively) + integer(I4B) :: collider_dimid !! ID for the collider dimension + character(NAMELEN) :: nenc_varname = "nenc" !! Total number of encounters + integer(I4B) :: nenc_varid !! ID for the number of encounters variable + character(NAMELEN) :: level_varname = "level" !! Recursion depth + integer(I4B) :: level_varid !! 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 diff --git a/src/modules/swiftest_classes.f90 b/src/modules/swiftest_classes.f90 index 724a17994..5c75908fb 100644 --- a/src/modules/swiftest_classes.f90 +++ b/src/modules/swiftest_classes.f90 @@ -17,155 +17,160 @@ module swiftest_classes public !> NetCDF variable names and constants - character(*), parameter :: NETCDF_OUTFILE = 'bin.nc' !! Default output file name - character(*), parameter :: TIME_DIMNAME = "time" !! NetCDF name of the time dimension - character(*), parameter :: ID_DIMNAME = "id" !! NetCDF name of the particle id dimension - character(*), parameter :: STR_DIMNAME = "string32" !! NetCDF name of the character string dimension - character(*), parameter :: PTYPE_VARNAME = "particle_type" !! NetCDF name of the particle type variable - character(*), parameter :: NAME_VARNAME = "name" !! NetCDF name of the particle name variable - character(*), parameter :: NPL_VARNAME = "npl" !! NetCDF name of the number of active massive bodies variable - character(*), parameter :: NTP_VARNAME = "ntp" !! NetCDF name of the number of active test particles variable - character(*), parameter :: NPLM_VARNAME = "nplm" !! NetCDF name of the number of active fully interacting massive bodies variable (SyMBA) - character(*), parameter :: A_VARNAME = "a" !! NetCDF name of the semimajor axis variable - character(*), parameter :: E_VARNAME = "e" !! NetCDF name of the eccentricity variable - character(*), parameter :: INC_VARNAME = "inc" !! NetCDF name of the inclination variable - character(*), parameter :: CAPOM_VARNAME = "capom" !! NetCDF name of the long. asc. node variable - character(*), parameter :: OMEGA_VARNAME = "omega" !! NetCDF name of the arg. periapsis variable - character(*), parameter :: CAPM_VARNAME = "capm" !! NetCDF name of the mean anomaly variable - character(*), parameter :: XHX_VARNAME = "xhx" !! NetCDF name of the heliocentric position x variable - character(*), parameter :: XHY_VARNAME = "xhy" !! NetCDF name of the heliocentric position y variable - character(*), parameter :: XHZ_VARNAME = "xhz" !! NetCDF name of the heliocentric position z variable - character(*), parameter :: VHX_VARNAME = "vhx" !! NetCDF name of the heliocentric velocity x variable - character(*), parameter :: VHY_VARNAME = "vhy" !! NetCDF name of the heliocentric velocity y variable - character(*), parameter :: VHZ_VARNAME = "vhz" !! NetCDF name of the heliocentric velocity z variable - character(*), parameter :: GR_PSEUDO_VHX_VARNAME = "gr_pseudo_vhx" !! NetCDF name of the heliocentric pseudovelocity x variable (used in GR only) - character(*), parameter :: GR_PSEUDO_VHY_VARNAME = "gr_pseudo_vhy" !! NetCDF name of the heliocentric pseudovelocity y variable (used in GR only) - character(*), parameter :: GR_PSEUDO_VHZ_VARNAME = "gr_pseudo_vhz" !! NetCDF name of the heliocentric pseudovelocity z variable (used in GR only) - character(*), parameter :: GMASS_VARNAME = "Gmass" !! NetCDF name of the mass variable - character(*), parameter :: RHILL_VARNAME = "rhill" !! NetCDF name of the hill radius variable - character(*), parameter :: RADIUS_VARNAME = "radius" !! NetCDF name of the radius variable - character(*), parameter :: IP1_VARNAME = "Ip1" !! NetCDF name of the axis 1 principal moment of inertial variable - character(*), parameter :: IP2_VARNAME = "Ip2" !! NetCDF name of the axis 2 principal moment of inertial variable - character(*), parameter :: IP3_VARNAME = "Ip3" !! NetCDF name of the axis 3 principal moment of inertial variable - character(*), parameter :: ROTX_VARNAME = "rotx" !! NetCDF name of the rotation x variable - character(*), parameter :: ROTY_VARNAME = "roty" !! NetCDF name of the rotation y variable - character(*), parameter :: ROTZ_VARNAME = "rotz" !! NetCDF name of the rotation z variable - character(*), parameter :: K2_VARNAME = "k2" !! NetCDF name of the Love number variable - character(*), parameter :: Q_VARNAME = "Q" !! NetCDF name of the energy dissipation variable - character(*), parameter :: KE_ORB_VARNAME = "KE_orb" !! NetCDF name of the system orbital kinetic energy variable - character(*), parameter :: KE_SPIN_VARNAME = "KE_spin" !! NetCDF name of the system spin kinetic energy variable - character(*), parameter :: PE_VARNAME = "PE" !! NetCDF name of the system potential energy variable - character(*), parameter :: L_ORBX_VARNAME = "L_orbx" !! NetCDF name of the orbital angular momentum x variable - character(*), parameter :: L_ORBY_VARNAME = "L_orby" !! NetCDF name of the orbital angular momentum y variable - character(*), parameter :: L_ORBZ_VARNAME = "L_orbz" !! NetCDF name of the orbital angular momentum z variable - character(*), parameter :: L_SPINX_VARNAME = "L_spinx" !! NetCDF name of the spin angular momentum x variable - character(*), parameter :: L_SPINY_VARNAME = "L_spiny" !! NetCDF name of the spin angular momentum y variable - character(*), parameter :: L_SPINZ_VARNAME = "L_spinz" !! NetCDF name of the spin angular momentum z variable - character(*), parameter :: L_ESCAPEX_VARNAME = "L_escapex" !! NetCDF name of the escaped angular momentum x variable - character(*), parameter :: L_ESCAPEY_VARNAME = "L_escapey" !! NetCDF name of the escaped angular momentum y variable - character(*), parameter :: L_ESCAPEZ_VARNAME = "L_escapez" !! NetCDF name of the escaped angular momentum z variable - 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 :: STATUS_VARNAME = "status" !! NetCDF name of the current status of the body variable (includes discard type) - character(*), parameter :: ORIGIN_TYPE_VARNAME = "origin_type" !! NetCDF name of the origin type variable (Initial Conditions, Disruption, etc.) - character(*), parameter :: ORIGIN_TIME_VARNAME = "origin_time" !! NetCDF name of the time of origin variable - character(*), parameter :: COLLISION_ID_VARNAME = "collision_id" !! NetCDF name of the collision id variable - character(*), parameter :: ORIGIN_XHX_VARNAME = "origin_xhx" !! NetCDF name of the heliocentric position of the body at the time of origin x variable - character(*), parameter :: ORIGIN_XHY_VARNAME = "origin_xhy" !! NetCDF name of the heliocentric position of the body at the time of origin y variable - character(*), parameter :: ORIGIN_XHZ_VARNAME = "origin_xhz" !! NetCDF name of the heliocentric position of the body at the time of origin z variable - character(*), parameter :: ORIGIN_VHX_VARNAME = "origin_vhx" !! NetCDF name of the heliocentric velocity of the body at the time of origin x variable - character(*), parameter :: ORIGIN_VHY_VARNAME = "origin_vhy" !! NetCDF name of the heliocentric velocity of the body at the time of origin y variable - character(*), parameter :: ORIGIN_VHZ_VARNAME = "origin_vhz" !! NetCDF name of the heliocentric velocity of the body at the time of origin z variable - character(*), parameter :: DISCARD_TIME_VARNAME = "discard_time" !! NetCDF name of the time of discard variable - character(*), parameter :: DISCARD_XHX_VARNAME = "discard_xhx" !! NetCDF name of the heliocentric position of the body at the time of discard x variable - character(*), parameter :: DISCARD_XHY_VARNAME = "discard_xhy" !! NetCDF name of the heliocentric position of the body at the time of discard y variable - character(*), parameter :: DISCARD_XHZ_VARNAME = "discard_xhz" !! NetCDF name of the heliocentric position of the body at the time of discard z variable - character(*), parameter :: DISCARD_VHX_VARNAME = "discard_vhx" !! NetCDF name of the heliocentric velocity of the body at the time of discard x variable - character(*), parameter :: DISCARD_VHY_VARNAME = "discard_vhy" !! NetCDF name of the heliocentric velocity of the body at the time of discard y variable - character(*), parameter :: DISCARD_VHZ_VARNAME = "discard_vhz" !! NetCDF name of the heliocentric velocity of the body at the time of discard z variable - character(*), parameter :: DISCARD_BODY_ID_VARNAME = "discard_body_id" !! NetCDF name of the id of the other body involved in the discard - character(*), parameter :: J2RP2_VARNAME = "j2rp2" !! NetCDF name of the j2rp2 variable - character(*), parameter :: J4RP4_VARNAME = "j4rp4" !! NetCDF name of the j4pr4 variable !! This derived datatype stores the NetCDF ID values for each of the variables included in the NetCDF data file. This is used as the base class defined in swiftest_classes type :: netcdf_variables - 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) :: 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) :: nplm_varid !! NetCDF ID for the number of active fully interacting massive bodies variable (SyMBA) - 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) :: gr_pseudo_vhx_varid !! NetCDF ID for the heliocentric pseudovelocity x variable (used in GR) - integer(I4B) :: gr_pseudo_vhy_varid !! NetCDF ID for the heliocentric pseudovelocity y variable (used in GR) - integer(I4B) :: gr_pseudo_vhz_varid !! NetCDF ID for the heliocentric psuedovelocity z variable (used in GR) - 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) :: j2rp2_varid !! NetCDF ID for the j2 variable - integer(I4B) :: j4rp4_varid !! NetCDF ID for the j4 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 - integer(I4B) :: status_varid !! NetCDF ID for the status variable - integer(I4B) :: origin_type_varid !! NetCDF ID for the origin type - integer(I4B) :: origin_time_varid !! NetCDF ID for the origin time - integer(I4B) :: collision_id_varid !! Netcdf ID for the origin collision ID - 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 - integer(I4B) :: discard_time_varid !! NetCDF ID for the time of discard variable - integer(I4B) :: discard_xhx_varid !! NetCDF ID for the heliocentric position of the body at the time of discard x variable - integer(I4B) :: discard_xhy_varid !! NetCDF ID for the heliocentric position of the body at the time of discard y variable - integer(I4B) :: discard_xhz_varid !! NetCDF ID for the heliocentric position of the body at the time of discard z variable - integer(I4B) :: discard_vhx_varid !! NetCDF ID for the heliocentric velocity of the body at the time of discard x variable - integer(I4B) :: discard_vhy_varid !! NetCDF ID for the heliocentric velocity of the body at the time of discard y variable - integer(I4B) :: discard_vhz_varid !! NetCDF ID for the heliocentric velocity of the body at the time of discard z variable - integer(I4B) :: discard_body_id_varid !! NetCDF ID for the id of the other body involved in the discard - integer(I4B) :: id_chunk !! Chunk size for the id dimension variables - integer(I4B) :: time_chunk !! Chunk size for the time dimension variables - logical :: lpseudo_vel_exists = .false. !! Logical flag to indicate whether or not the pseudovelocity vectors were present in an old file. + integer(I4B) :: out_type !! output type (will be assigned either NF90_DOUBLE or NF90_FLOAT, depending on the user parameter) + integer(I4B) :: ncid !! ID for the output file + integer(I4B) :: discard_body_id_varid !! ID for the id of the other body involved in the discard + integer(I4B) :: id_chunk !! Chunk size for the id dimension variables + integer(I4B) :: time_chunk !! Chunk size for the time dimension variables + logical :: lpseudo_vel_exists = .false. !! Logical flag to indicate whether or not the pseudovelocity vectors were present in an old file. + + ! Dimension ids and variable names + integer(I4B) :: time_dimid !! ID for the time dimension + integer(I4B) :: id_dimid !! ID for the particle id dimension + character(NAMELEN) :: str_dimname = "string32" !! name of the character string dimension + integer(I4B) :: str_dimid !! ID for the character string dimension + character(NAMELEN) :: time_dimname = "time" !! name of the time dimension + integer(I4B) :: time_varid !! ID for the time variable + character(NAMELEN) :: id_dimname = "id" !! name of the particle id dimension + integer(I4B) :: id_varid !! ID for the particle name variable + character(NAMELEN) :: space_dimname = "space" !! name of the space dimension + integer(I4B) :: space_varid !! ID for the space variable + + ! Non-dimension ids and variable names + character(NAMELEN) :: ptype_varname = "particle_type" !! name of the particle type variable + integer(I4B) :: ptype_varid !! ID for the particle type variable + character(NAMELEN) :: name_varname = "name" !! name of the particle name variable + integer(I4B) :: name_varid !! ID for the namevariable + character(NAMELEN) :: npl_varname = "npl" !! name of the number of active massive bodies variable + integer(I4B) :: npl_varid !! ID for the number of active massive bodies variable + character(NAMELEN) :: ntp_varname = "ntp" !! name of the number of active test particles variable + integer(I4B) :: ntp_varid !! ID for the number of active test particles variable + character(NAMELEN) :: nplm_varname = "nplm" !! name of the number of active fully interacting massive bodies variable (SyMBA) + integer(I4B) :: nplm_varid !! ID for the number of active fully interacting massive bodies variable (SyMBA) + character(NAMELEN) :: a_varname = "a" !! name of the semimajor axis variable + integer(I4B) :: a_varid !! ID for the semimajor axis variable + character(NAMELEN) :: e_varname = "e" !! name of the eccentricity variable + integer(I4B) :: e_varid !! ID for the eccentricity variable + character(NAMELEN) :: inc_varname = "inc" !! name of the inclination variable + integer(I4B) :: inc_varid !! ID for the inclination variable + character(NAMELEN) :: capom_varname = "capom" !! name of the long. asc. node variable + integer(I4B) :: capom_varid !! ID for the long. asc. node variable + character(NAMELEN) :: omega_varname = "omega" !! name of the arg. periapsis variable + integer(I4B) :: omega_varid !! ID for the arg. periapsis variable + character(NAMELEN) :: capm_varname = "capm" !! name of the mean anomaly variable + integer(I4B) :: capm_varid !! ID for the mean anomaly variable + character(NAMELEN) :: xhx_varname = "xhx" !! name of the heliocentric position x variable + integer(I4B) :: xhx_varid !! ID for the heliocentric position x variable + character(NAMELEN) :: xhy_varname = "xhy" !! name of the heliocentric position y variable + integer(I4B) :: xhy_varid !! ID for the heliocentric position y variable + character(NAMELEN) :: xhz_varname = "xhz" !! name of the heliocentric position z variable + integer(I4B) :: xhz_varid !! ID for the heliocentric position z variable + character(NAMELEN) :: vhx_varname = "vhx" !! name of the heliocentric velocity x variable + integer(I4B) :: vhx_varid !! ID for the heliocentric velocity x variable + character(NAMELEN) :: vhy_varname = "vhy" !! name of the heliocentric velocity y variable + integer(I4B) :: vhy_varid !! ID for the heliocentric velocity y variable + character(NAMELEN) :: vhz_varname = "vhz" !! name of the heliocentric velocity z variable + integer(I4B) :: vhz_varid !! ID for the heliocentric velocity z variable + character(NAMELEN) :: gr_pseudo_vhx_varname = "gr_pseudo_vhx" !! name of the heliocentric pseudovelocity x variable (used in GR only) + integer(I4B) :: gr_pseudo_vhx_varid !! ID for the heliocentric pseudovelocity x variable (used in GR) + character(NAMELEN) :: gr_pseudo_vhy_varname = "gr_pseudo_vhy" !! name of the heliocentric pseudovelocity y variable (used in GR only) + integer(I4B) :: gr_pseudo_vhy_varid !! ID for the heliocentric pseudovelocity y variable (used in GR) + character(NAMELEN) :: gr_pseudo_vhz_varname = "gr_pseudo_vhz" !! name of the heliocentric pseudovelocity z variable (used in GR only) + integer(I4B) :: gr_pseudo_vhz_varid !! ID for the heliocentric psuedovelocity z variable (used in GR) + character(NAMELEN) :: gmass_varname = "Gmass" !! name of the mass variable + integer(I4B) :: Gmass_varid !! ID for the mass variable + character(NAMELEN) :: rhill_varname = "rhill" !! name of the hill radius variable + integer(I4B) :: rhill_varid !! ID for the hill radius variable + character(NAMELEN) :: radius_varname = "radius" !! name of the radius variable + integer(I4B) :: radius_varid !! ID for the radius variable + character(NAMELEN) :: ip1_varname = "Ip1" !! name of the axis 1 principal moment of inertial variable + integer(I4B) :: Ip1_varid !! ID for the axis 1 principal moment of inertia variable + character(NAMELEN) :: ip2_varname = "Ip2" !! name of the axis 2 principal moment of inertial variable + integer(I4B) :: Ip2_varid !! ID for the axis 2 principal moment of inertia variable + character(NAMELEN) :: ip3_varname = "Ip3" !! name of the axis 3 principal moment of inertial variable + integer(I4B) :: Ip3_varid !! ID for the axis 3 principal moment of inertia variable + character(NAMELEN) :: rotx_varname = "rotx" !! name of the rotation x variable + integer(I4B) :: rotx_varid !! ID for the rotation x variable + character(NAMELEN) :: roty_varname = "roty" !! name of the rotation y variable + integer(I4B) :: roty_varid !! ID for the rotation y variable + character(NAMELEN) :: rotz_varname = "rotz" !! name of the rotation z variable + integer(I4B) :: rotz_varid !! ID for the rotation z variable + character(NAMELEN) :: j2rp2_varname = "j2rp2" !! name of the j2rp2 variable + integer(I4B) :: j2rp2_varid !! ID for the j2 variable + character(NAMELEN) :: j4rp4_varname = "j4rp4" !! name of the j4pr4 variable + integer(I4B) :: j4rp4_varid !! ID for the j4 variable + character(NAMELEN) :: k2_varname = "k2" !! name of the Love number variable + integer(I4B) :: k2_varid !! ID for the Love number variable + character(NAMELEN) :: q_varname = "Q" !! name of the energy dissipation variable + integer(I4B) :: Q_varid !! ID for the energy dissipation variable + character(NAMELEN) :: ke_orb_varname = "KE_orb" !! name of the system orbital kinetic energy variable + integer(I4B) :: KE_orb_varid !! ID for the system orbital kinetic energy variable + character(NAMELEN) :: ke_spin_varname = "KE_spin" !! name of the system spin kinetic energy variable + integer(I4B) :: KE_spin_varid !! ID for the system spin kinetic energy variable + character(NAMELEN) :: pe_varname = "PE" !! name of the system potential energy variable + integer(I4B) :: PE_varid !! ID for the system potential energy variable + character(NAMELEN) :: l_orbx_varname = "L_orbx" !! name of the orbital angular momentum x variable + integer(I4B) :: L_orbx_varid !! ID for the system orbital angular momentum x variable + character(NAMELEN) :: l_orby_varname = "L_orby" !! name of the orbital angular momentum y variable + integer(I4B) :: L_orby_varid !! ID for the system orbital angular momentum y variable + character(NAMELEN) :: l_orbz_varname = "L_orbz" !! name of the orbital angular momentum z variable + integer(I4B) :: L_orbz_varid !! ID for the system orbital angular momentum z variable + character(NAMELEN) :: l_spinx_varname = "L_spinx" !! name of the spin angular momentum x variable + integer(I4B) :: L_spinx_varid !! ID for the system spin angular momentum x variable + character(NAMELEN) :: l_spiny_varname = "L_spiny" !! name of the spin angular momentum y variable + integer(I4B) :: L_spiny_varid !! ID for the system spin angular momentum y variable + character(NAMELEN) :: l_spinz_varname = "L_spinz" !! name of the spin angular momentum z variable + integer(I4B) :: L_spinz_varid !! ID for the system spin angular momentum z variable + character(NAMELEN) :: l_escapex_varname = "L_escapex" !! name of the escaped angular momentum x variable + integer(I4B) :: L_escapex_varid !! ID for the escaped angular momentum x variable + character(NAMELEN) :: l_escapey_varname = "L_escapey" !! name of the escaped angular momentum y variable + integer(I4B) :: L_escapey_varid !! ID for the escaped angular momentum x variable + character(NAMELEN) :: l_escapez_varname = "L_escapez" !! name of the escaped angular momentum z variable + integer(I4B) :: L_escapez_varid !! ID for the escaped angular momentum x variable + character(NAMELEN) :: ecollisions_varname = "Ecollisions" !! name of the escaped angular momentum y variable + integer(I4B) :: Ecollisions_varid !! ID for the energy lost in collisions variable + character(NAMELEN) :: euntracked_varname = "Euntracked" !! name of the energy that is untracked due to loss (untracked potential energy due to mergers and body energy for escaped bodies) + integer(I4B) :: Euntracked_varid !! ID for the energy that is untracked due to loss (untracked potential energy due to mergers and body energy for escaped bodies) + character(NAMELEN) :: gmescape_varname = "GMescape" !! name of the G*Mass of bodies that escape the system + integer(I4B) :: GMescape_varid !! ID for the G*Mass of bodies that escape the system + character(NAMELEN) :: status_varname = "status" !! name of the current status of the body variable (includes discard type) + integer(I4B) :: status_varid !! ID for the status variable + character(NAMELEN) :: origin_type_varname = "origin_type" !! name of the origin type variable (Initial Conditions, Disruption, etc.) + integer(I4B) :: origin_type_varid !! ID for the origin type + character(NAMELEN) :: origin_time_varname = "origin_time" !! name of the time of origin variable + integer(I4B) :: origin_time_varid !! ID for the origin time + character(NAMELEN) :: collision_id_varname = "collision_id" !! name of the collision id variable + integer(I4B) :: collision_id_varid !! Netcdf ID for the origin collision ID + character(NAMELEN) :: origin_xhx_varname = "origin_xhx" !! name of the heliocentric position of the body at the time of origin x variable + integer(I4B) :: origin_xhx_varid !! ID for the origin xh x component + character(NAMELEN) :: origin_xhy_varname = "origin_xhy" !! name of the heliocentric position of the body at the time of origin y variable + integer(I4B) :: origin_xhy_varid !! ID for the origin xh y component + character(NAMELEN) :: origin_xhz_varname = "origin_xhz" !! name of the heliocentric position of the body at the time of origin z variable + integer(I4B) :: origin_xhz_varid !! ID for the origin xh z component + character(NAMELEN) :: origin_vhx_varname = "origin_vhx" !! name of the heliocentric velocity of the body at the time of origin x variable + integer(I4B) :: origin_vhx_varid !! ID for the origin xh x component + character(NAMELEN) :: origin_vhy_varname = "origin_vhy" !! name of the heliocentric velocity of the body at the time of origin y variable + integer(I4B) :: origin_vhy_varid !! ID for the origin xh y component + character(NAMELEN) :: origin_vhz_varname = "origin_vhz" !! name of the heliocentric velocity of the body at the time of origin z variable + integer(I4B) :: origin_vhz_varid !! ID for the origin xh z component + character(NAMELEN) :: discard_time_varname = "discard_time" !! name of the time of discard variable + integer(I4B) :: discard_time_varid !! ID for the time of discard variable + character(NAMELEN) :: discard_xhx_varname = "discard_xhx" !! name of the heliocentric position of the body at the time of discard x variable + integer(I4B) :: discard_xhx_varid !! ID for the heliocentric position of the body at the time of discard x variable + character(NAMELEN) :: discard_xhy_varname = "discard_xhy" !! name of the heliocentric position of the body at the time of discard y variable + integer(I4B) :: discard_xhy_varid !! ID for the heliocentric position of the body at the time of discard y variable + character(NAMELEN) :: discard_xhz_varname = "discard_xhz" !! name of the heliocentric position of the body at the time of discard z variable + integer(I4B) :: discard_xhz_varid !! ID for the heliocentric position of the body at the time of discard z variable + character(NAMELEN) :: discard_vhx_varname = "discard_vhx" !! name of the heliocentric velocity of the body at the time of discard x variable + integer(I4B) :: discard_vhx_varid !! ID for the heliocentric velocity of the body at the time of discard x variable + character(NAMELEN) :: discard_vhy_varname = "discard_vhy" !! name of the heliocentric velocity of the body at the time of discard y variable + integer(I4B) :: discard_vhy_varid !! ID for the heliocentric velocity of the body at the time of discard y variable + character(NAMELEN) :: discard_vhz_varname = "discard_vhz" !! name of the heliocentric velocity of the body at the time of discard z variable + integer(I4B) :: discard_vhz_varid !! ID for the heliocentric velocity of the body at the time of discard z variable + character(NAMELEN) :: discard_body_id_varname = "discard_body_id" !! name of the id of the other body involved in the discard end type netcdf_variables @@ -202,7 +207,7 @@ module swiftest_classes 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) :: outfile = BIN_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_stat = 'NEW' !! Open status for output binary file diff --git a/src/netcdf/netcdf.f90 b/src/netcdf/netcdf.f90 index d0098765d..42aa78882 100644 --- a/src/netcdf/netcdf.f90 +++ b/src/netcdf/netcdf.f90 @@ -197,9 +197,9 @@ module subroutine netcdf_initialize_output(self, param) call check( nf90_create(param%outfile, NF90_NETCDF4, self%ncid), "netcdf_initialize_output nf90_create" ) ! Define the NetCDF dimensions with particle name as the record dimension - call check( nf90_def_dim(self%ncid, ID_DIMNAME, NF90_UNLIMITED, self%id_dimid), "netcdf_initialize_output nf90_def_dim id_dimid" ) ! 'x' dimension - call check( nf90_def_dim(self%ncid, STR_DIMNAME, NAMELEN, self%str_dimid), "netcdf_initialize_output nf90_def_dim str_dimid" ) ! Dimension for string variables (aka character arrays) - call check( nf90_def_dim(self%ncid, TIME_DIMNAME, NF90_UNLIMITED, self%time_dimid), "netcdf_initialize_output nf90_def_dim time_dimid" ) ! 'y' dimension + call check( nf90_def_dim(self%ncid, self%id_dimname, NF90_UNLIMITED, self%id_dimid), "netcdf_initialize_output nf90_def_dim id_dimid" ) ! 'x' dimension + call check( nf90_def_dim(self%ncid, self%str_dimname, NAMELEN, self%str_dimid), "netcdf_initialize_output nf90_def_dim str_dimid" ) ! Dimension for string variables (aka character arrays) + call check( nf90_def_dim(self%ncid, self%time_dimname, NF90_UNLIMITED, self%time_dimid), "netcdf_initialize_output nf90_def_dim time_dimid" ) ! 'y' dimension select case (param%out_type) case("NETCDF_FLOAT") @@ -209,107 +209,107 @@ module subroutine netcdf_initialize_output(self, param) end select !! Define the variables - call check( nf90_def_var(self%ncid, TIME_DIMNAME, self%out_type, self%time_dimid, self%time_varid), "netcdf_initialize_output nf90_def_var time_varid" ) - call check( nf90_def_var(self%ncid, ID_DIMNAME, NF90_INT, self%id_dimid, self%id_varid), "netcdf_initialize_output nf90_def_var id_varid" ) - call check( nf90_def_var(self%ncid, NPL_VARNAME, NF90_INT, self%time_dimid, self%npl_varid), "netcdf_initialize_output nf90_def_var npl_varid" ) - call check( nf90_def_var(self%ncid, NTP_VARNAME, NF90_INT, self%time_dimid, self%ntp_varid), "netcdf_initialize_output nf90_def_var ntp_varid" ) - if (param%integrator == SYMBA) call check( nf90_def_var(self%ncid, NPLM_VARNAME, NF90_INT, self%time_dimid, self%nplm_varid), "netcdf_initialize_output nf90_def_var nplm_varid" ) - call check( nf90_def_var(self%ncid, NAME_VARNAME, NF90_CHAR, [self%str_dimid, self%id_dimid], self%name_varid), "netcdf_initialize_output nf90_def_var name_varid" ) - call check( nf90_def_var(self%ncid, PTYPE_VARNAME, NF90_CHAR, [self%str_dimid, self%id_dimid], self%ptype_varid), "netcdf_initialize_output nf90_def_var ptype_varid" ) - call check( nf90_def_var(self%ncid, STATUS_VARNAME, NF90_CHAR, [self%str_dimid, self%id_dimid], self%status_varid), "netcdf_initialize_output nf90_def_var status_varid" ) + call check( nf90_def_var(self%ncid, self%time_dimname, self%out_type, self%time_dimid, self%time_varid), "netcdf_initialize_output nf90_def_var time_varid" ) + call check( nf90_def_var(self%ncid, self%id_dimname, NF90_INT, self%id_dimid, self%id_varid), "netcdf_initialize_output nf90_def_var id_varid" ) + call check( nf90_def_var(self%ncid, self%npl_varname, NF90_INT, self%time_dimid, self%npl_varid), "netcdf_initialize_output nf90_def_var npl_varid" ) + call check( nf90_def_var(self%ncid, self%ntp_varname, NF90_INT, self%time_dimid, self%ntp_varid), "netcdf_initialize_output nf90_def_var ntp_varid" ) + if (param%integrator == SYMBA) call check( nf90_def_var(self%ncid, self%nplm_varname, NF90_INT, self%time_dimid, self%nplm_varid), "netcdf_initialize_output nf90_def_var nplm_varid" ) + call check( nf90_def_var(self%ncid, self%name_varname, NF90_CHAR, [self%str_dimid, self%id_dimid], self%name_varid), "netcdf_initialize_output nf90_def_var name_varid" ) + call check( nf90_def_var(self%ncid, self%ptype_varname, NF90_CHAR, [self%str_dimid, self%id_dimid], self%ptype_varid), "netcdf_initialize_output nf90_def_var ptype_varid" ) + call check( nf90_def_var(self%ncid, self%status_varname, NF90_CHAR, [self%str_dimid, self%id_dimid], self%status_varid), "netcdf_initialize_output nf90_def_var status_varid" ) if ((param%out_form == "XV") .or. (param%out_form == "XVEL")) then - call check( nf90_def_var(self%ncid, XHX_VARNAME, self%out_type, [self%id_dimid, self%time_dimid], self%xhx_varid), "netcdf_initialize_output nf90_def_var xhx_varid" ) - call check( nf90_def_var(self%ncid, XHY_VARNAME, self%out_type, [self%id_dimid, self%time_dimid], self%xhy_varid), "netcdf_initialize_output nf90_def_var xhy_varid" ) - call check( nf90_def_var(self%ncid, XHZ_VARNAME, self%out_type, [self%id_dimid, self%time_dimid], self%xhz_varid), "netcdf_initialize_output nf90_def_var xhz_varid" ) - call check( nf90_def_var(self%ncid, VHX_VARNAME, self%out_type, [self%id_dimid, self%time_dimid], self%vhx_varid), "netcdf_initialize_output nf90_def_var vhx_varid" ) - call check( nf90_def_var(self%ncid, VHY_VARNAME, self%out_type, [self%id_dimid, self%time_dimid], self%vhy_varid), "netcdf_initialize_output nf90_def_var vhy_varid" ) - call check( nf90_def_var(self%ncid, VHZ_VARNAME, self%out_type, [self%id_dimid, self%time_dimid], self%vhz_varid), "netcdf_initialize_output nf90_def_var vhz_varid" ) + call check( nf90_def_var(self%ncid, self%xhx_varname, self%out_type, [self%id_dimid, self%time_dimid], self%xhx_varid), "netcdf_initialize_output nf90_def_var xhx_varid" ) + call check( nf90_def_var(self%ncid, self%xhy_varname, self%out_type, [self%id_dimid, self%time_dimid], self%xhy_varid), "netcdf_initialize_output nf90_def_var xhy_varid" ) + call check( nf90_def_var(self%ncid, self%xhz_varname, self%out_type, [self%id_dimid, self%time_dimid], self%xhz_varid), "netcdf_initialize_output nf90_def_var xhz_varid" ) + call check( nf90_def_var(self%ncid, self%vhx_varname, self%out_type, [self%id_dimid, self%time_dimid], self%vhx_varid), "netcdf_initialize_output nf90_def_var vhx_varid" ) + call check( nf90_def_var(self%ncid, self%vhy_varname, self%out_type, [self%id_dimid, self%time_dimid], self%vhy_varid), "netcdf_initialize_output nf90_def_var vhy_varid" ) + call check( nf90_def_var(self%ncid, self%vhz_varname, self%out_type, [self%id_dimid, self%time_dimid], self%vhz_varid), "netcdf_initialize_output nf90_def_var vhz_varid" ) !! When GR is enabled, we need to save the pseudovelocity vectors in addition to the true heliocentric velocity vectors, otherwise !! we cannnot expect bit-identical runs from restarted runs with GR enabled due to floating point errors during the conversion. if (param%lgr) then - call check( nf90_def_var(self%ncid, GR_PSEUDO_VHX_VARNAME, self%out_type, [self%id_dimid, self%time_dimid], self%gr_pseudo_vhx_varid), "netcdf_initialize_output nf90_def_var gr_psuedo_vhx_varid" ) - call check( nf90_def_var(self%ncid, GR_PSEUDO_VHY_VARNAME, self%out_type, [self%id_dimid, self%time_dimid], self%gr_pseudo_vhy_varid), "netcdf_initialize_output nf90_def_var gr_psuedo_vhy_varid" ) - call check( nf90_def_var(self%ncid, GR_PSEUDO_VHZ_VARNAME, self%out_type, [self%id_dimid, self%time_dimid], self%gr_pseudo_vhz_varid), "netcdf_initialize_output nf90_def_var gr_psuedo_vhz_varid" ) + call check( nf90_def_var(self%ncid, self%gr_pseudo_vhx_varname, self%out_type, [self%id_dimid, self%time_dimid], self%gr_pseudo_vhx_varid), "netcdf_initialize_output nf90_def_var gr_psuedo_vhx_varid" ) + call check( nf90_def_var(self%ncid, self%gr_pseudo_vhy_varname, self%out_type, [self%id_dimid, self%time_dimid], self%gr_pseudo_vhy_varid), "netcdf_initialize_output nf90_def_var gr_psuedo_vhy_varid" ) + call check( nf90_def_var(self%ncid, self%gr_pseudo_vhz_varname, self%out_type, [self%id_dimid, self%time_dimid], self%gr_pseudo_vhz_varid), "netcdf_initialize_output nf90_def_var gr_psuedo_vhz_varid" ) self%lpseudo_vel_exists = .true. end if end if if ((param%out_form == "EL") .or. (param%out_form == "XVEL")) then - call check( nf90_def_var(self%ncid, A_VARNAME, self%out_type, [self%id_dimid, self%time_dimid], self%a_varid), "netcdf_initialize_output nf90_def_var a_varid" ) - call check( nf90_def_var(self%ncid, E_VARNAME, self%out_type, [self%id_dimid, self%time_dimid], self%e_varid), "netcdf_initialize_output nf90_def_var e_varid" ) - call check( nf90_def_var(self%ncid, INC_VARNAME, self%out_type, [self%id_dimid, self%time_dimid], self%inc_varid), "netcdf_initialize_output nf90_def_var inc_varid" ) - call check( nf90_def_var(self%ncid, CAPOM_VARNAME, self%out_type, [self%id_dimid, self%time_dimid], self%capom_varid), "netcdf_initialize_output nf90_def_var capom_varid" ) - call check( nf90_def_var(self%ncid, OMEGA_VARNAME, self%out_type, [self%id_dimid, self%time_dimid], self%omega_varid), "netcdf_initialize_output nf90_def_var omega_varid" ) - call check( nf90_def_var(self%ncid, CAPM_VARNAME, self%out_type, [self%id_dimid, self%time_dimid], self%capm_varid), "netcdf_initialize_output nf90_def_var capm_varid" ) + call check( nf90_def_var(self%ncid, self%a_varname, self%out_type, [self%id_dimid, self%time_dimid], self%a_varid), "netcdf_initialize_output nf90_def_var a_varid" ) + call check( nf90_def_var(self%ncid, self%e_varname, self%out_type, [self%id_dimid, self%time_dimid], self%e_varid), "netcdf_initialize_output nf90_def_var e_varid" ) + call check( nf90_def_var(self%ncid, self%inc_varname, self%out_type, [self%id_dimid, self%time_dimid], self%inc_varid), "netcdf_initialize_output nf90_def_var inc_varid" ) + call check( nf90_def_var(self%ncid, self%capom_varname, self%out_type, [self%id_dimid, self%time_dimid], self%capom_varid), "netcdf_initialize_output nf90_def_var capom_varid" ) + call check( nf90_def_var(self%ncid, self%omega_varname, self%out_type, [self%id_dimid, self%time_dimid], self%omega_varid), "netcdf_initialize_output nf90_def_var omega_varid" ) + call check( nf90_def_var(self%ncid, self%capm_varname, self%out_type, [self%id_dimid, self%time_dimid], self%capm_varid), "netcdf_initialize_output nf90_def_var capm_varid" ) end if - call check( nf90_def_var(self%ncid, GMASS_VARNAME, self%out_type, [self%id_dimid, self%time_dimid], self%Gmass_varid), "netcdf_initialize_output nf90_def_var Gmass_varid" ) + call check( nf90_def_var(self%ncid, self%gmass_varname, self%out_type, [self%id_dimid, self%time_dimid], self%Gmass_varid), "netcdf_initialize_output nf90_def_var Gmass_varid" ) if (param%lrhill_present) then - call check( nf90_def_var(self%ncid, RHILL_VARNAME, self%out_type, [self%id_dimid, self%time_dimid], self%rhill_varid), "netcdf_initialize_output nf90_def_var rhill_varid" ) + call check( nf90_def_var(self%ncid, self%rhill_varname, self%out_type, [self%id_dimid, self%time_dimid], self%rhill_varid), "netcdf_initialize_output nf90_def_var rhill_varid" ) end if if (param%lclose) then - call check( nf90_def_var(self%ncid, RADIUS_VARNAME, self%out_type, [self%id_dimid, self%time_dimid], self%radius_varid), "netcdf_initialize_output nf90_def_var radius_varid" ) + call check( nf90_def_var(self%ncid, self%radius_varname, self%out_type, [self%id_dimid, self%time_dimid], self%radius_varid), "netcdf_initialize_output nf90_def_var radius_varid" ) - call check( nf90_def_var(self%ncid, ORIGIN_TIME_VARNAME, self%out_type, self%id_dimid, self%origin_time_varid), "netcdf_initialize_output nf90_def_var origin_time_varid" ) - call check( nf90_def_var(self%ncid, ORIGIN_TYPE_VARNAME, NF90_CHAR, [self%str_dimid, self%id_dimid], & + call check( nf90_def_var(self%ncid, self%origin_time_varname, self%out_type, self%id_dimid, self%origin_time_varid), "netcdf_initialize_output nf90_def_var origin_time_varid" ) + call check( nf90_def_var(self%ncid, self%origin_type_varname, NF90_CHAR, [self%str_dimid, self%id_dimid], & self%origin_type_varid), "netcdf_initialize_output nf90_create" ) - call check( nf90_def_var(self%ncid, ORIGIN_XHX_VARNAME, self%out_type, self%id_dimid, self%origin_xhx_varid), "netcdf_initialize_output nf90_def_var origin_xhx_varid" ) - call check( nf90_def_var(self%ncid, ORIGIN_XHY_VARNAME, self%out_type, self%id_dimid, self%origin_xhy_varid), "netcdf_initialize_output nf90_def_var origin_xhy_varid" ) - call check( nf90_def_var(self%ncid, ORIGIN_XHZ_VARNAME, self%out_type, self%id_dimid, self%origin_xhz_varid), "netcdf_initialize_output nf90_def_var origin_xhz_varid" ) - call check( nf90_def_var(self%ncid, ORIGIN_VHX_VARNAME, self%out_type, self%id_dimid, self%origin_vhx_varid), "netcdf_initialize_output nf90_def_var origin_vhx_varid" ) - call check( nf90_def_var(self%ncid, ORIGIN_VHY_VARNAME, self%out_type, self%id_dimid, self%origin_vhy_varid), "netcdf_initialize_output nf90_def_var origin_vhy_varid" ) - call check( nf90_def_var(self%ncid, ORIGIN_VHZ_VARNAME, self%out_type, self%id_dimid, self%origin_vhz_varid), "netcdf_initialize_output nf90_def_var origin_vhz_varid" ) - - call check( nf90_def_var(self%ncid, COLLISION_ID_VARNAME, NF90_INT, self%id_dimid, self%collision_id_varid), "netcdf_initialize_output nf90_def_var collision_id_varid" ) - call check( nf90_def_var(self%ncid, DISCARD_TIME_VARNAME, self%out_type, self%id_dimid, self%discard_time_varid), "netcdf_initialize_output nf90_def_var discard_time_varid" ) - call check( nf90_def_var(self%ncid, DISCARD_XHX_VARNAME, self%out_type, self%id_dimid, self%discard_xhx_varid), "netcdf_initialize_output nf90_def_var discard_xhx_varid" ) - call check( nf90_def_var(self%ncid, DISCARD_XHY_VARNAME, self%out_type, self%id_dimid, self%discard_xhy_varid), "netcdf_initialize_output nf90_def_var discard_xhy_varid" ) - call check( nf90_def_var(self%ncid, DISCARD_XHZ_VARNAME, self%out_type, self%id_dimid, self%discard_xhz_varid), "netcdf_initialize_output nf90_def_var discard_xhz_varid" ) - call check( nf90_def_var(self%ncid, DISCARD_VHX_VARNAME, self%out_type, self%id_dimid, self%discard_vhx_varid), "netcdf_initialize_output nf90_def_var discard_vhx_varid" ) - call check( nf90_def_var(self%ncid, DISCARD_VHY_VARNAME, self%out_type, self%id_dimid, self%discard_vhy_varid), "netcdf_initialize_output nf90_def_var discard_vhy_varid" ) - call check( nf90_def_var(self%ncid, DISCARD_VHZ_VARNAME, self%out_type, self%id_dimid, self%discard_vhz_varid), "netcdf_initialize_output nf90_def_var discard_vhz_varid" ) - call check( nf90_def_var(self%ncid, DISCARD_BODY_ID_VARNAME, NF90_INT, self%id_dimid, self%discard_body_id_varid), "netcdf_initialize_output nf90_def_var discard_body_id_varid" ) + call check( nf90_def_var(self%ncid, self%origin_xhx_varname, self%out_type, self%id_dimid, self%origin_xhx_varid), "netcdf_initialize_output nf90_def_var origin_xhx_varid" ) + call check( nf90_def_var(self%ncid, self%origin_xhy_varname, self%out_type, self%id_dimid, self%origin_xhy_varid), "netcdf_initialize_output nf90_def_var origin_xhy_varid" ) + call check( nf90_def_var(self%ncid, self%origin_xhz_varname, self%out_type, self%id_dimid, self%origin_xhz_varid), "netcdf_initialize_output nf90_def_var origin_xhz_varid" ) + call check( nf90_def_var(self%ncid, self%origin_vhx_varname, self%out_type, self%id_dimid, self%origin_vhx_varid), "netcdf_initialize_output nf90_def_var origin_vhx_varid" ) + call check( nf90_def_var(self%ncid, self%origin_vhy_varname, self%out_type, self%id_dimid, self%origin_vhy_varid), "netcdf_initialize_output nf90_def_var origin_vhy_varid" ) + call check( nf90_def_var(self%ncid, self%origin_vhz_varname, self%out_type, self%id_dimid, self%origin_vhz_varid), "netcdf_initialize_output nf90_def_var origin_vhz_varid" ) + + call check( nf90_def_var(self%ncid, self%collision_id_varname, NF90_INT, self%id_dimid, self%collision_id_varid), "netcdf_initialize_output nf90_def_var collision_id_varid" ) + call check( nf90_def_var(self%ncid, self%discard_time_varname, self%out_type, self%id_dimid, self%discard_time_varid), "netcdf_initialize_output nf90_def_var discard_time_varid" ) + call check( nf90_def_var(self%ncid, self%discard_xhx_varname, self%out_type, self%id_dimid, self%discard_xhx_varid), "netcdf_initialize_output nf90_def_var discard_xhx_varid" ) + call check( nf90_def_var(self%ncid, self%discard_xhy_varname, self%out_type, self%id_dimid, self%discard_xhy_varid), "netcdf_initialize_output nf90_def_var discard_xhy_varid" ) + call check( nf90_def_var(self%ncid, self%discard_xhz_varname, self%out_type, self%id_dimid, self%discard_xhz_varid), "netcdf_initialize_output nf90_def_var discard_xhz_varid" ) + call check( nf90_def_var(self%ncid, self%discard_vhx_varname, self%out_type, self%id_dimid, self%discard_vhx_varid), "netcdf_initialize_output nf90_def_var discard_vhx_varid" ) + call check( nf90_def_var(self%ncid, self%discard_vhy_varname, self%out_type, self%id_dimid, self%discard_vhy_varid), "netcdf_initialize_output nf90_def_var discard_vhy_varid" ) + call check( nf90_def_var(self%ncid, self%discard_vhz_varname, self%out_type, self%id_dimid, self%discard_vhz_varid), "netcdf_initialize_output nf90_def_var discard_vhz_varid" ) + call check( nf90_def_var(self%ncid, self%discard_body_id_varname, NF90_INT, self%id_dimid, self%discard_body_id_varid), "netcdf_initialize_output nf90_def_var discard_body_id_varid" ) end if if (param%lrotation) then - call check( nf90_def_var(self%ncid, IP1_VARNAME, self%out_type, [self%id_dimid, self%time_dimid], self%Ip1_varid), "netcdf_initialize_output nf90_def_var Ip1_varid" ) - call check( nf90_def_var(self%ncid, IP2_VARNAME, self%out_type, [self%id_dimid, self%time_dimid], self%Ip2_varid), "netcdf_initialize_output nf90_def_var Ip2_varid" ) - call check( nf90_def_var(self%ncid, IP3_VARNAME, self%out_type, [self%id_dimid, self%time_dimid], self%Ip3_varid), "netcdf_initialize_output nf90_def_var Ip3_varid" ) - call check( nf90_def_var(self%ncid, ROTX_VARNAME, self%out_type, [self%id_dimid, self%time_dimid], self%rotx_varid), "netcdf_initialize_output nf90_def_var rotx_varid" ) - call check( nf90_def_var(self%ncid, ROTY_VARNAME, self%out_type, [self%id_dimid, self%time_dimid], self%roty_varid), "netcdf_initialize_output nf90_def_var roty_varid" ) - call check( nf90_def_var(self%ncid, ROTZ_VARNAME, self%out_type, [self%id_dimid, self%time_dimid], self%rotz_varid), "netcdf_initialize_output nf90_def_var rotz_varid" ) + call check( nf90_def_var(self%ncid, self%ip1_varname, self%out_type, [self%id_dimid, self%time_dimid], self%Ip1_varid), "netcdf_initialize_output nf90_def_var Ip1_varid" ) + call check( nf90_def_var(self%ncid, self%ip2_varname, self%out_type, [self%id_dimid, self%time_dimid], self%Ip2_varid), "netcdf_initialize_output nf90_def_var Ip2_varid" ) + call check( nf90_def_var(self%ncid, self%ip3_varname, self%out_type, [self%id_dimid, self%time_dimid], self%Ip3_varid), "netcdf_initialize_output nf90_def_var Ip3_varid" ) + call check( nf90_def_var(self%ncid, self%rotx_varname, self%out_type, [self%id_dimid, self%time_dimid], self%rotx_varid), "netcdf_initialize_output nf90_def_var rotx_varid" ) + call check( nf90_def_var(self%ncid, self%roty_varname, self%out_type, [self%id_dimid, self%time_dimid], self%roty_varid), "netcdf_initialize_output nf90_def_var roty_varid" ) + call check( nf90_def_var(self%ncid, self%rotz_varname, self%out_type, [self%id_dimid, self%time_dimid], self%rotz_varid), "netcdf_initialize_output nf90_def_var rotz_varid" ) end if ! if (param%ltides) then - ! call check( nf90_def_var(self%ncid, K2_VARNAME, self%out_type, [self%id_dimid, self%time_dimid], self%k2_varid), "netcdf_initialize_output nf90_def_var k2_varid" ) - ! call check( nf90_def_var(self%ncid, Q_VARNAME, self%out_type, [self%id_dimid, self%time_dimid], self%Q_varid), "netcdf_initialize_output nf90_def_var Q_varid" ) + ! call check( nf90_def_var(self%ncid, self%k2_varname, self%out_type, [self%id_dimid, self%time_dimid], self%k2_varid), "netcdf_initialize_output nf90_def_var k2_varid" ) + ! call check( nf90_def_var(self%ncid, self%q_varname, self%out_type, [self%id_dimid, self%time_dimid], self%Q_varid), "netcdf_initialize_output nf90_def_var Q_varid" ) ! end if if (param%lenergy) then - call check( nf90_def_var(self%ncid, KE_ORB_VARNAME, self%out_type, self%time_dimid, self%KE_orb_varid), "netcdf_initialize_output nf90_def_var KE_orb_varid" ) - call check( nf90_def_var(self%ncid, KE_SPIN_VARNAME, self%out_type, self%time_dimid, self%KE_spin_varid), "netcdf_initialize_output nf90_def_var KE_spin_varid" ) - call check( nf90_def_var(self%ncid, PE_VARNAME, self%out_type, self%time_dimid, self%PE_varid), "netcdf_initialize_output nf90_def_var PE_varid" ) - call check( nf90_def_var(self%ncid, L_ORBX_VARNAME, self%out_type, self%time_dimid, self%L_orbx_varid), "netcdf_initialize_output nf90_def_var L_orbx_varid" ) - call check( nf90_def_var(self%ncid, L_ORBY_VARNAME, self%out_type, self%time_dimid, self%L_orby_varid), "netcdf_initialize_output nf90_def_var L_orby_varid" ) - call check( nf90_def_var(self%ncid, L_ORBZ_VARNAME, self%out_type, self%time_dimid, self%L_orbz_varid), "netcdf_initialize_output nf90_def_var L_orbz_varid" ) - call check( nf90_def_var(self%ncid, L_SPINX_VARNAME, self%out_type, self%time_dimid, self%L_spinx_varid), "netcdf_initialize_output nf90_def_var L_spinx_varid" ) - call check( nf90_def_var(self%ncid, L_SPINY_VARNAME, self%out_type, self%time_dimid, self%L_spiny_varid), "netcdf_initialize_output nf90_def_var L_spiny_varid" ) - call check( nf90_def_var(self%ncid, L_SPINZ_VARNAME, self%out_type, self%time_dimid, self%L_spinz_varid), "netcdf_initialize_output nf90_def_var L_spinz_varid" ) - call check( nf90_def_var(self%ncid, L_ESCAPEX_VARNAME, self%out_type, self%time_dimid, self%L_escapex_varid), "netcdf_initialize_output nf90_def_var L_escapex_varid" ) - call check( nf90_def_var(self%ncid, L_ESCAPEY_VARNAME, self%out_type, self%time_dimid, self%L_escapey_varid), "netcdf_initialize_output nf90_def_var L_escapey_varid" ) - call check( nf90_def_var(self%ncid, L_ESCAPEZ_VARNAME, self%out_type, self%time_dimid, self%L_escapez_varid), "netcdf_initialize_output nf90_def_var L_escapez_varid" ) - call check( nf90_def_var(self%ncid, ECOLLISIONS_VARNAME, self%out_type, self%time_dimid, self%Ecollisions_varid), "netcdf_initialize_output nf90_def_var Ecollisions_varid" ) - call check( nf90_def_var(self%ncid, EUNTRACKED_VARNAME, self%out_type, self%time_dimid, self%Euntracked_varid), "netcdf_initialize_output nf90_def_var Euntracked_varid" ) - call check( nf90_def_var(self%ncid, GMESCAPE_VARNAME, self%out_type, self%time_dimid, self%GMescape_varid), "netcdf_initialize_output nf90_def_var GMescape_varid" ) + call check( nf90_def_var(self%ncid, self%ke_orb_varname, self%out_type, self%time_dimid, self%KE_orb_varid), "netcdf_initialize_output nf90_def_var KE_orb_varid" ) + call check( nf90_def_var(self%ncid, self%ke_spin_varname, self%out_type, self%time_dimid, self%KE_spin_varid), "netcdf_initialize_output nf90_def_var KE_spin_varid" ) + call check( nf90_def_var(self%ncid, self%pe_varname, self%out_type, self%time_dimid, self%PE_varid), "netcdf_initialize_output nf90_def_var PE_varid" ) + call check( nf90_def_var(self%ncid, self%l_orbx_varname, self%out_type, self%time_dimid, self%L_orbx_varid), "netcdf_initialize_output nf90_def_var L_orbx_varid" ) + call check( nf90_def_var(self%ncid, self%l_orby_varname, self%out_type, self%time_dimid, self%L_orby_varid), "netcdf_initialize_output nf90_def_var L_orby_varid" ) + call check( nf90_def_var(self%ncid, self%l_orbz_varname, self%out_type, self%time_dimid, self%L_orbz_varid), "netcdf_initialize_output nf90_def_var L_orbz_varid" ) + call check( nf90_def_var(self%ncid, self%l_spinx_varname, self%out_type, self%time_dimid, self%L_spinx_varid), "netcdf_initialize_output nf90_def_var L_spinx_varid" ) + call check( nf90_def_var(self%ncid, self%l_spiny_varname, self%out_type, self%time_dimid, self%L_spiny_varid), "netcdf_initialize_output nf90_def_var L_spiny_varid" ) + call check( nf90_def_var(self%ncid, self%l_spinz_varname, self%out_type, self%time_dimid, self%L_spinz_varid), "netcdf_initialize_output nf90_def_var L_spinz_varid" ) + call check( nf90_def_var(self%ncid, self%l_escapex_varname, self%out_type, self%time_dimid, self%L_escapex_varid), "netcdf_initialize_output nf90_def_var L_escapex_varid" ) + call check( nf90_def_var(self%ncid, self%l_escapey_varname, self%out_type, self%time_dimid, self%L_escapey_varid), "netcdf_initialize_output nf90_def_var L_escapey_varid" ) + call check( nf90_def_var(self%ncid, self%l_escapez_varname, self%out_type, self%time_dimid, self%L_escapez_varid), "netcdf_initialize_output nf90_def_var L_escapez_varid" ) + call check( nf90_def_var(self%ncid, self%ecollisions_varname, self%out_type, self%time_dimid, self%Ecollisions_varid), "netcdf_initialize_output nf90_def_var Ecollisions_varid" ) + call check( nf90_def_var(self%ncid, self%euntracked_varname, self%out_type, self%time_dimid, self%Euntracked_varid), "netcdf_initialize_output nf90_def_var Euntracked_varid" ) + call check( nf90_def_var(self%ncid, self%gmescape_varname, self%out_type, self%time_dimid, self%GMescape_varid), "netcdf_initialize_output nf90_def_var GMescape_varid" ) end if - call check( nf90_def_var(self%ncid, J2RP2_VARNAME, self%out_type, self%time_dimid, self%j2rp2_varid), "netcdf_initialize_output nf90_def_var j2rp2_varid" ) - call check( nf90_def_var(self%ncid, J4RP4_VARNAME, self%out_type, self%time_dimid, self%j4rp4_varid), "netcdf_initialize_output nf90_def_var j4rp4_varid" ) + call check( nf90_def_var(self%ncid, self%j2rp2_varname, self%out_type, self%time_dimid, self%j2rp2_varid), "netcdf_initialize_output nf90_def_var j2rp2_varid" ) + call check( nf90_def_var(self%ncid, self%j4rp4_varname, self%out_type, self%time_dimid, self%j4rp4_varid), "netcdf_initialize_output nf90_def_var j4rp4_varid" ) ! Set fill mode to NaN for all variables @@ -361,8 +361,8 @@ module subroutine netcdf_open(self, param, readonly) write(errmsg,*) "netcdf_open nf90_open ",trim(adjustl(param%outfile)) call check( nf90_open(param%outfile, mode, self%ncid), errmsg) - call check( nf90_inq_dimid(self%ncid, TIME_DIMNAME, self%time_dimid), "netcdf_open nf90_inq_dimid time_dimid" ) - call check( nf90_inq_dimid(self%ncid, ID_DIMNAME, self%id_dimid), "netcdf_open nf90_inq_dimid id_dimid" ) + call check( nf90_inq_dimid(self%ncid, self%time_dimname, self%time_dimid), "netcdf_open nf90_inq_dimid time_dimid" ) + call check( nf90_inq_dimid(self%ncid, self%id_dimname, self%id_dimid), "netcdf_open nf90_inq_dimid id_dimid" ) if (max(self%time_dimid,self%id_dimid) == 2) then self%str_dimid = 3 else if (min(self%time_dimid,self%id_dimid) == 0) then @@ -375,29 +375,29 @@ module subroutine netcdf_open(self, param, readonly) ! Required Variables - call check( nf90_inq_varid(self%ncid, TIME_DIMNAME, self%time_varid), "netcdf_open nf90_inq_varid time_varid" ) - call check( nf90_inq_varid(self%ncid, ID_DIMNAME, self%id_varid), "netcdf_open nf90_inq_varid id_varid" ) - call check( nf90_inq_varid(self%ncid, NAME_VARNAME, self%name_varid), "netcdf_open nf90_inq_varid name_varid" ) - call check( nf90_inq_varid(self%ncid, PTYPE_VARNAME, self%ptype_varid), "netcdf_open nf90_inq_varid ptype_varid" ) - call check( nf90_inq_varid(self%ncid, GMASS_VARNAME, self%Gmass_varid), "netcdf_open nf90_inq_varid Gmass_varid" ) + call check( nf90_inq_varid(self%ncid, self%time_dimname, self%time_varid), "netcdf_open nf90_inq_varid time_varid" ) + call check( nf90_inq_varid(self%ncid, self%id_dimname, self%id_varid), "netcdf_open nf90_inq_varid id_varid" ) + call check( nf90_inq_varid(self%ncid, self%name_varname, self%name_varid), "netcdf_open nf90_inq_varid name_varid" ) + call check( nf90_inq_varid(self%ncid, self%ptype_varname, self%ptype_varid), "netcdf_open nf90_inq_varid ptype_varid" ) + call check( nf90_inq_varid(self%ncid, self%gmass_varname, self%Gmass_varid), "netcdf_open nf90_inq_varid Gmass_varid" ) if ((param%out_form == "XV") .or. (param%out_form == "XVEL")) then - call check( nf90_inq_varid(self%ncid, XHX_VARNAME, self%xhx_varid), "netcdf_open nf90_inq_varid xhx_varid" ) - call check( nf90_inq_varid(self%ncid, XHY_VARNAME, self%xhy_varid), "netcdf_open nf90_inq_varid xhy_varid" ) - call check( nf90_inq_varid(self%ncid, XHZ_VARNAME, self%xhz_varid), "netcdf_open nf90_inq_varid xhz_varid" ) - call check( nf90_inq_varid(self%ncid, VHX_VARNAME, self%vhx_varid), "netcdf_open nf90_inq_varid vhx_varid" ) - call check( nf90_inq_varid(self%ncid, VHY_VARNAME, self%vhy_varid), "netcdf_open nf90_inq_varid vhy_varid" ) - call check( nf90_inq_varid(self%ncid, VHZ_VARNAME, self%vhz_varid), "netcdf_open nf90_inq_varid vhz_varid" ) + call check( nf90_inq_varid(self%ncid, self%xhx_varname, self%xhx_varid), "netcdf_open nf90_inq_varid xhx_varid" ) + call check( nf90_inq_varid(self%ncid, self%xhy_varname, self%xhy_varid), "netcdf_open nf90_inq_varid xhy_varid" ) + call check( nf90_inq_varid(self%ncid, self%xhz_varname, self%xhz_varid), "netcdf_open nf90_inq_varid xhz_varid" ) + call check( nf90_inq_varid(self%ncid, self%vhx_varname, self%vhx_varid), "netcdf_open nf90_inq_varid vhx_varid" ) + call check( nf90_inq_varid(self%ncid, self%vhy_varname, self%vhy_varid), "netcdf_open nf90_inq_varid vhy_varid" ) + call check( nf90_inq_varid(self%ncid, self%vhz_varname, self%vhz_varid), "netcdf_open nf90_inq_varid vhz_varid" ) if (param%lgr) then !! check if pseudovelocity vectors exist in this file. If they are, set the correct flag so we know whe should not do the conversion. - status = nf90_inq_varid(self%ncid, GR_PSEUDO_VHX_VARNAME, self%gr_pseudo_vhx_varid) + status = nf90_inq_varid(self%ncid, self%gr_pseudo_vhx_varname, self%gr_pseudo_vhx_varid) self%lpseudo_vel_exists = (status == nf90_noerr) if (self%lpseudo_vel_exists) then - status = nf90_inq_varid(self%ncid, GR_PSEUDO_VHY_VARNAME, self%gr_pseudo_vhy_varid) + status = nf90_inq_varid(self%ncid, self%gr_pseudo_vhy_varname, self%gr_pseudo_vhy_varid) self%lpseudo_vel_exists = (status == nf90_noerr) if (self%lpseudo_vel_exists) then - status = nf90_inq_varid(self%ncid, GR_PSEUDO_VHZ_VARNAME, self%gr_pseudo_vhz_varid) + status = nf90_inq_varid(self%ncid, self%gr_pseudo_vhz_varname, self%gr_pseudo_vhz_varid) self%lpseudo_vel_exists = (status == nf90_noerr) end if end if @@ -409,85 +409,85 @@ module subroutine netcdf_open(self, param, readonly) end if if ((param%out_form == "EL") .or. (param%out_form == "XVEL")) then - call check( nf90_inq_varid(self%ncid, A_VARNAME, self%a_varid), "netcdf_open nf90_inq_varid a_varid" ) - call check( nf90_inq_varid(self%ncid, E_VARNAME, self%e_varid), "netcdf_open nf90_inq_varid e_varid" ) - call check( nf90_inq_varid(self%ncid, INC_VARNAME, self%inc_varid), "netcdf_open nf90_inq_varid inc_varid" ) - call check( nf90_inq_varid(self%ncid, CAPOM_VARNAME, self%capom_varid), "netcdf_open nf90_inq_varid capom_varid" ) - call check( nf90_inq_varid(self%ncid, OMEGA_VARNAME, self%omega_varid), "netcdf_open nf90_inq_varid omega_varid" ) - call check( nf90_inq_varid(self%ncid, CAPM_VARNAME, self%capm_varid), "netcdf_open nf90_inq_varid capm_varid" ) + call check( nf90_inq_varid(self%ncid, self%a_varname, self%a_varid), "netcdf_open nf90_inq_varid a_varid" ) + call check( nf90_inq_varid(self%ncid, self%e_varname, self%e_varid), "netcdf_open nf90_inq_varid e_varid" ) + call check( nf90_inq_varid(self%ncid, self%inc_varname, self%inc_varid), "netcdf_open nf90_inq_varid inc_varid" ) + call check( nf90_inq_varid(self%ncid, self%capom_varname, self%capom_varid), "netcdf_open nf90_inq_varid capom_varid" ) + call check( nf90_inq_varid(self%ncid, self%omega_varname, self%omega_varid), "netcdf_open nf90_inq_varid omega_varid" ) + call check( nf90_inq_varid(self%ncid, self%capm_varname, self%capm_varid), "netcdf_open nf90_inq_varid capm_varid" ) end if if (param%lclose) then - call check( nf90_inq_varid(self%ncid, RADIUS_VARNAME, self%radius_varid), "netcdf_open nf90_inq_varid radius_varid" ) + call check( nf90_inq_varid(self%ncid, self%radius_varname, self%radius_varid), "netcdf_open nf90_inq_varid radius_varid" ) end if if (param%lrotation) then - call check( nf90_inq_varid(self%ncid, IP1_VARNAME, self%Ip1_varid), "netcdf_open nf90_inq_varid Ip1_varid" ) - call check( nf90_inq_varid(self%ncid, IP2_VARNAME, self%Ip2_varid), "netcdf_open nf90_inq_varid Ip2_varid" ) - call check( nf90_inq_varid(self%ncid, IP3_VARNAME, self%Ip3_varid), "netcdf_open nf90_inq_varid Ip3_varid" ) - call check( nf90_inq_varid(self%ncid, ROTX_VARNAME, self%rotx_varid), "netcdf_open nf90_inq_varid rotx_varid" ) - call check( nf90_inq_varid(self%ncid, ROTY_VARNAME, self%roty_varid), "netcdf_open nf90_inq_varid roty_varid" ) - call check( nf90_inq_varid(self%ncid, ROTZ_VARNAME, self%rotz_varid), "netcdf_open nf90_inq_varid rotz_varid" ) + call check( nf90_inq_varid(self%ncid, self%ip1_varname, self%Ip1_varid), "netcdf_open nf90_inq_varid Ip1_varid" ) + call check( nf90_inq_varid(self%ncid, self%ip2_varname, self%Ip2_varid), "netcdf_open nf90_inq_varid Ip2_varid" ) + call check( nf90_inq_varid(self%ncid, self%ip3_varname, self%Ip3_varid), "netcdf_open nf90_inq_varid Ip3_varid" ) + call check( nf90_inq_varid(self%ncid, self%rotx_varname, self%rotx_varid), "netcdf_open nf90_inq_varid rotx_varid" ) + call check( nf90_inq_varid(self%ncid, self%roty_varname, self%roty_varid), "netcdf_open nf90_inq_varid roty_varid" ) + call check( nf90_inq_varid(self%ncid, self%rotz_varname, self%rotz_varid), "netcdf_open nf90_inq_varid rotz_varid" ) end if ! if (param%ltides) then - ! call check( nf90_inq_varid(self%ncid, K2_VARNAME, self%k2_varid), "netcdf_open nf90_inq_varid k2_varid" ) - ! call check( nf90_inq_varid(self%ncid, Q_VARNAME, self%Q_varid), "netcdf_open nf90_inq_varid Q_varid" ) + ! call check( nf90_inq_varid(self%ncid, self%k2_varname, self%k2_varid), "netcdf_open nf90_inq_varid k2_varid" ) + ! call check( nf90_inq_varid(self%ncid, self%q_varname, self%Q_varid), "netcdf_open nf90_inq_varid Q_varid" ) ! end if ! Optional Variables if (param%lrhill_present) then - status = nf90_inq_varid(self%ncid, RHILL_VARNAME, self%rhill_varid) + status = nf90_inq_varid(self%ncid, self%rhill_varname, self%rhill_varid) if (status /= nf90_noerr) write(*,*) "Warning! RHILL variable not set in input file. Calculating." end if ! Optional variables The User Doesn't Need to Know About - status = nf90_inq_varid(self%ncid, NPL_VARNAME, self%npl_varid) - status = nf90_inq_varid(self%ncid, NTP_VARNAME, self%ntp_varid) - status = nf90_inq_varid(self%ncid, STATUS_VARNAME, self%status_varid) - status = nf90_inq_varid(self%ncid, J2RP2_VARNAME, self%j2rp2_varid) - status = nf90_inq_varid(self%ncid, J4RP4_VARNAME, self%j4rp4_varid) + status = nf90_inq_varid(self%ncid, self%npl_varname, self%npl_varid) + status = nf90_inq_varid(self%ncid, self%ntp_varname, self%ntp_varid) + status = nf90_inq_varid(self%ncid, self%status_varname, self%status_varid) + status = nf90_inq_varid(self%ncid, self%j2rp2_varname, self%j2rp2_varid) + status = nf90_inq_varid(self%ncid, self%j4rp4_varname, self%j4rp4_varid) if (param%integrator == SYMBA) then - status = nf90_inq_varid(self%ncid, NPLM_VARNAME, self%nplm_varid) + status = nf90_inq_varid(self%ncid, self%nplm_varname, self%nplm_varid) end if if (param%lclose) then - status = nf90_inq_varid(self%ncid, ORIGIN_TYPE_VARNAME, self%origin_type_varid) - status = nf90_inq_varid(self%ncid, ORIGIN_TIME_VARNAME, self%origin_time_varid) - status = nf90_inq_varid(self%ncid, ORIGIN_XHX_VARNAME, self%origin_xhx_varid) - status = nf90_inq_varid(self%ncid, ORIGIN_XHY_VARNAME, self%origin_xhy_varid) - status = nf90_inq_varid(self%ncid, ORIGIN_XHZ_VARNAME, self%origin_xhz_varid) - status = nf90_inq_varid(self%ncid, ORIGIN_VHX_VARNAME, self%origin_vhx_varid) - status = nf90_inq_varid(self%ncid, ORIGIN_VHY_VARNAME, self%origin_vhy_varid) - status = nf90_inq_varid(self%ncid, ORIGIN_VHZ_VARNAME, self%origin_vhz_varid) - status = nf90_inq_varid(self%ncid, COLLISION_ID_VARNAME, self%collision_id_varid) - status = nf90_inq_varid(self%ncid, DISCARD_TIME_VARNAME, self%discard_time_varid) - status = nf90_inq_varid(self%ncid, DISCARD_XHX_VARNAME, self%discard_xhx_varid) - status = nf90_inq_varid(self%ncid, DISCARD_XHY_VARNAME, self%discard_xhy_varid) - status = nf90_inq_varid(self%ncid, DISCARD_XHZ_VARNAME, self%discard_xhz_varid) - status = nf90_inq_varid(self%ncid, DISCARD_VHX_VARNAME, self%discard_vhx_varid) - status = nf90_inq_varid(self%ncid, DISCARD_VHY_VARNAME, self%discard_vhy_varid) - status = nf90_inq_varid(self%ncid, DISCARD_VHZ_VARNAME, self%discard_vhz_varid) - status = nf90_inq_varid(self%ncid, DISCARD_BODY_ID_VARNAME, self%discard_body_id_varid) + status = nf90_inq_varid(self%ncid, self%origin_type_varname, self%origin_type_varid) + status = nf90_inq_varid(self%ncid, self%origin_time_varname, self%origin_time_varid) + status = nf90_inq_varid(self%ncid, self%origin_xhx_varname, self%origin_xhx_varid) + status = nf90_inq_varid(self%ncid, self%origin_xhy_varname, self%origin_xhy_varid) + status = nf90_inq_varid(self%ncid, self%origin_xhz_varname, self%origin_xhz_varid) + status = nf90_inq_varid(self%ncid, self%origin_vhx_varname, self%origin_vhx_varid) + status = nf90_inq_varid(self%ncid, self%origin_vhy_varname, self%origin_vhy_varid) + status = nf90_inq_varid(self%ncid, self%origin_vhz_varname, self%origin_vhz_varid) + status = nf90_inq_varid(self%ncid, self%collision_id_varname, self%collision_id_varid) + status = nf90_inq_varid(self%ncid, self%discard_time_varname, self%discard_time_varid) + status = nf90_inq_varid(self%ncid, self%discard_xhx_varname, self%discard_xhx_varid) + status = nf90_inq_varid(self%ncid, self%discard_xhy_varname, self%discard_xhy_varid) + status = nf90_inq_varid(self%ncid, self%discard_xhz_varname, self%discard_xhz_varid) + status = nf90_inq_varid(self%ncid, self%discard_vhx_varname, self%discard_vhx_varid) + status = nf90_inq_varid(self%ncid, self%discard_vhy_varname, self%discard_vhy_varid) + status = nf90_inq_varid(self%ncid, self%discard_vhz_varname, self%discard_vhz_varid) + status = nf90_inq_varid(self%ncid, self%discard_body_id_varname, self%discard_body_id_varid) end if if (param%lenergy) then - status = nf90_inq_varid(self%ncid, KE_ORB_VARNAME, self%KE_orb_varid) - status = nf90_inq_varid(self%ncid, KE_SPIN_VARNAME, self%KE_spin_varid) - status = nf90_inq_varid(self%ncid, PE_VARNAME, self%PE_varid) - status = nf90_inq_varid(self%ncid, L_ORBX_VARNAME, self%L_orbx_varid) - status = nf90_inq_varid(self%ncid, L_ORBY_VARNAME, self%L_orby_varid) - status = nf90_inq_varid(self%ncid, L_ORBZ_VARNAME, self%L_orbz_varid) - status = nf90_inq_varid(self%ncid, L_SPINX_VARNAME, self%L_spinx_varid) - status = nf90_inq_varid(self%ncid, L_SPINY_VARNAME, self%L_spiny_varid) - status = nf90_inq_varid(self%ncid, L_SPINZ_VARNAME, self%L_spinz_varid) - status = nf90_inq_varid(self%ncid, L_ESCAPEX_VARNAME, self%L_escapex_varid) - status = nf90_inq_varid(self%ncid, L_ESCAPEY_VARNAME, self%L_escapey_varid) - status = nf90_inq_varid(self%ncid, L_ESCAPEZ_VARNAME, self%L_escapez_varid) - status = nf90_inq_varid(self%ncid, ECOLLISIONS_VARNAME, self%Ecollisions_varid) - status = nf90_inq_varid(self%ncid, EUNTRACKED_VARNAME, self%Euntracked_varid) - status = nf90_inq_varid(self%ncid, GMESCAPE_VARNAME, self%GMescape_varid) + status = nf90_inq_varid(self%ncid, self%ke_orb_varname, self%KE_orb_varid) + status = nf90_inq_varid(self%ncid, self%ke_spin_varname, self%KE_spin_varid) + status = nf90_inq_varid(self%ncid, self%pe_varname, self%PE_varid) + status = nf90_inq_varid(self%ncid, self%l_orbx_varname, self%L_orbx_varid) + status = nf90_inq_varid(self%ncid, self%l_orby_varname, self%L_orby_varid) + status = nf90_inq_varid(self%ncid, self%l_orbz_varname, self%L_orbz_varid) + status = nf90_inq_varid(self%ncid, self%l_spinx_varname, self%L_spinx_varid) + status = nf90_inq_varid(self%ncid, self%l_spiny_varname, self%L_spiny_varid) + status = nf90_inq_varid(self%ncid, self%l_spinz_varname, self%L_spinz_varid) + status = nf90_inq_varid(self%ncid, self%l_escapex_varname, self%L_escapex_varid) + status = nf90_inq_varid(self%ncid, self%l_escapey_varname, self%L_escapey_varid) + status = nf90_inq_varid(self%ncid, self%l_escapez_varname, self%L_escapez_varid) + status = nf90_inq_varid(self%ncid, self%ecollisions_varname, self%Ecollisions_varid) + status = nf90_inq_varid(self%ncid, self%euntracked_varname, self%Euntracked_varid) + status = nf90_inq_varid(self%ncid, self%gmescape_varname, self%GMescape_varid) end if return @@ -733,14 +733,14 @@ module function netcdf_read_frame_system(self, iu, param) result(ierr) ! if (npl > 0) pl%Q(:) = pack(rtemp, plmask) ! end if - status = nf90_inq_varid(iu%ncid, J2RP2_VARNAME, iu%j2rp2_varid) + status = nf90_inq_varid(iu%ncid, iu%j2rp2_varname, iu%j2rp2_varid) if (status == nf90_noerr) then call check( nf90_get_var(iu%ncid, iu%j2rp2_varid, cb%j2rp2, start=[tslot]), "netcdf_read_frame_system nf90_getvar j2rp2_varid" ) else cb%j2rp2 = 0.0_DP end if - status = nf90_inq_varid(iu%ncid, J4RP4_VARNAME, iu%j4rp4_varid) + status = nf90_inq_varid(iu%ncid, iu%j4rp4_varname, iu%j4rp4_varid) if (status == nf90_noerr) then call check( nf90_get_var(iu%ncid, iu%j4rp4_varid, cb%j4rp4, start=[tslot]), "netcdf_read_frame_system nf90_getvar j4rp4_varid" ) else @@ -813,14 +813,14 @@ module subroutine netcdf_read_hdr_system(self, iu, param) endwhere end select - status = nf90_inq_varid(iu%ncid, NPL_VARNAME, iu%npl_varid) + status = nf90_inq_varid(iu%ncid, iu%npl_varname, iu%npl_varid) if (status == nf90_noerr) then call check( nf90_get_var(iu%ncid, iu%npl_varid, self%pl%nbody, start=[tslot]), "netcdf_read_hdr_system nf90_getvar npl_varid" ) else self%pl%nbody = count(plmask(:)) end if - status = nf90_inq_varid(iu%ncid, NTP_VARNAME, iu%ntp_varid) + status = nf90_inq_varid(iu%ncid, iu%ntp_varname, iu%ntp_varid) if (status == nf90_noerr) then call check( nf90_get_var(iu%ncid, iu%ntp_varid, self%tp%nbody, start=[tslot]), "netcdf_read_hdr_system nf90_getvar ntp_varid" ) else @@ -828,7 +828,7 @@ module subroutine netcdf_read_hdr_system(self, iu, param) end if if (param%integrator == SYMBA) then - status = nf90_inq_varid(iu%ncid, NPLM_VARNAME, iu%nplm_varid) + status = nf90_inq_varid(iu%ncid, iu%nplm_varname, iu%nplm_varid) select type(pl => self%pl) class is (symba_pl) if (status == nf90_noerr) then @@ -840,35 +840,35 @@ module subroutine netcdf_read_hdr_system(self, iu, param) end if if (param%lenergy) then - status = nf90_inq_varid(iu%ncid, KE_ORB_VARNAME, iu%KE_orb_varid) + status = nf90_inq_varid(iu%ncid, iu%ke_orb_varname, iu%KE_orb_varid) if (status == nf90_noerr) call check( nf90_get_var(iu%ncid, iu%KE_orb_varid, self%ke_orbit, start=[tslot]), "netcdf_read_hdr_system nf90_getvar KE_orb_varid" ) - status = nf90_inq_varid(iu%ncid, KE_SPIN_VARNAME, iu%KE_spin_varid) + status = nf90_inq_varid(iu%ncid, iu%ke_spin_varname, iu%KE_spin_varid) if (status == nf90_noerr) call check( nf90_get_var(iu%ncid, iu%KE_spin_varid, self%ke_spin, start=[tslot]), "netcdf_read_hdr_system nf90_getvar KE_spin_varid" ) - status = nf90_inq_varid(iu%ncid, PE_VARNAME, iu%PE_varid) + status = nf90_inq_varid(iu%ncid, iu%pe_varname, iu%PE_varid) if (status == nf90_noerr) call check( nf90_get_var(iu%ncid, iu%PE_varid, self%pe, start=[tslot]), "netcdf_read_hdr_system nf90_getvar PE_varid" ) - status = nf90_inq_varid(iu%ncid, L_ORBX_VARNAME, iu%L_orbx_varid) + status = nf90_inq_varid(iu%ncid, iu%l_orbx_varname, iu%L_orbx_varid) if (status == nf90_noerr) call check( nf90_get_var(iu%ncid, iu%L_orbx_varid, self%Lorbit(1), start=[tslot]), "netcdf_read_hdr_system nf90_getvar L_orbx_varid" ) - status = nf90_inq_varid(iu%ncid, L_ORBY_VARNAME, iu%L_orby_varid) + status = nf90_inq_varid(iu%ncid, iu%l_orby_varname, iu%L_orby_varid) if (status == nf90_noerr) call check( nf90_get_var(iu%ncid, iu%L_orby_varid, self%Lorbit(2), start=[tslot]), "netcdf_read_hdr_system nf90_getvar L_orby_varid" ) - status = nf90_inq_varid(iu%ncid, L_ORBZ_VARNAME, iu%L_orbz_varid) + status = nf90_inq_varid(iu%ncid, iu%l_orbz_varname, iu%L_orbz_varid) if (status == nf90_noerr) call check( nf90_get_var(iu%ncid, iu%L_orbz_varid, self%Lorbit(3), start=[tslot]), "netcdf_read_hdr_system nf90_getvar L_orbz_varid" ) - status = nf90_inq_varid(iu%ncid, L_SPINX_VARNAME, iu%L_spinx_varid) + status = nf90_inq_varid(iu%ncid, iu%l_spinx_varname, iu%L_spinx_varid) if (status == nf90_noerr) call check( nf90_get_var(iu%ncid, iu%L_spinx_varid, self%Lspin(1), start=[tslot]), "netcdf_read_hdr_system nf90_getvar L_spinx_varid" ) - status = nf90_inq_varid(iu%ncid, L_SPINY_VARNAME, iu%L_spiny_varid) + status = nf90_inq_varid(iu%ncid, iu%l_spiny_varname, iu%L_spiny_varid) if (status == nf90_noerr) call check( nf90_get_var(iu%ncid, iu%L_spiny_varid, self%Lspin(2), start=[tslot]), "netcdf_read_hdr_system nf90_getvar L_spiny_varid" ) - status = nf90_inq_varid(iu%ncid, L_SPINZ_VARNAME, iu%L_spinz_varid) + status = nf90_inq_varid(iu%ncid, iu%l_spinz_varname, iu%L_spinz_varid) if (status == nf90_noerr) call check( nf90_get_var(iu%ncid, iu%L_spinz_varid, self%Lspin(3), start=[tslot]), "netcdf_read_hdr_system nf90_getvar L_spinz_varid" ) - status = nf90_inq_varid(iu%ncid, L_ESCAPEX_VARNAME, iu%L_escapex_varid) + status = nf90_inq_varid(iu%ncid, iu%l_escapex_varname, iu%L_escapex_varid) if (status == nf90_noerr) call check( nf90_get_var(iu%ncid, iu%L_escapex_varid, self%Lescape(1), start=[tslot]), "netcdf_read_hdr_system nf90_getvar L_escapex_varid" ) - status = nf90_inq_varid(iu%ncid, L_ESCAPEY_VARNAME, iu%L_escapey_varid) + status = nf90_inq_varid(iu%ncid, iu%l_escapey_varname, iu%L_escapey_varid) if (status == nf90_noerr) call check( nf90_get_var(iu%ncid, iu%L_escapey_varid, self%Lescape(2), start=[tslot]), "netcdf_read_hdr_system nf90_getvar L_escapey_varid" ) - status = nf90_inq_varid(iu%ncid, L_ESCAPEZ_VARNAME, iu%L_escapez_varid) + status = nf90_inq_varid(iu%ncid, iu%l_escapez_varname, iu%L_escapez_varid) if (status == nf90_noerr) call check( nf90_get_var(iu%ncid, iu%L_escapez_varid, self%Lescape(3), start=[tslot]), "netcdf_read_hdr_system nf90_getvar L_escapez_varid" ) - status = nf90_inq_varid(iu%ncid, ECOLLISIONS_VARNAME, iu%Ecollisions_varid) + status = nf90_inq_varid(iu%ncid, iu%ecollisions_varname, iu%Ecollisions_varid) if (status == nf90_noerr) call check( nf90_get_var(iu%ncid, iu%Ecollisions_varid, self%Ecollisions, start=[tslot]), "netcdf_read_hdr_system nf90_getvar Ecollisions_varid" ) - status = nf90_inq_varid(iu%ncid, EUNTRACKED_VARNAME, iu%Euntracked_varid) + status = nf90_inq_varid(iu%ncid, iu%euntracked_varname, iu%Euntracked_varid) if (status == nf90_noerr) call check( nf90_get_var(iu%ncid, iu%Euntracked_varid, self%Euntracked, start=[tslot]), "netcdf_read_hdr_system nf90_getvar Euntracked_varid" ) - status = nf90_inq_varid(iu%ncid, GMESCAPE_VARNAME, iu%GMescape_varid) + status = nf90_inq_varid(iu%ncid, iu%gmescape_varname, iu%GMescape_varid) if (status == nf90_noerr) call check( nf90_get_var(iu%ncid, iu%GMescape_varid, self%GMescape, start=[tslot]), "netcdf_read_hdr_system nf90_getvar GMescape_varid" ) end if @@ -946,7 +946,7 @@ module subroutine netcdf_read_particle_info_system(self, iu, param, plmask, tpma call tp%info(i)%set_value(particle_type=ctemp(tpind(i))) end do - status = nf90_inq_varid(iu%ncid, STATUS_VARNAME, iu%status_varid) + status = nf90_inq_varid(iu%ncid, iu%status_varname, iu%status_varid) if (status == nf90_noerr) then call check( nf90_get_var(iu%ncid, iu%status_varid, ctemp, count=[NAMELEN, idmax]), "netcdf_read_particle_info_system nf90_getvar status_varid") call cb%info%set_value(status=ctemp(1)) @@ -962,7 +962,7 @@ module subroutine netcdf_read_particle_info_system(self, iu, param, plmask, tpma if (param%lclose) then - status = nf90_inq_varid(iu%ncid, ORIGIN_TYPE_VARNAME, iu%origin_type_varid) + status = nf90_inq_varid(iu%ncid, iu%origin_type_varname, iu%origin_type_varid) if (status == nf90_noerr) then call check( nf90_get_var(iu%ncid, iu%origin_type_varid, ctemp, count=[NAMELEN, idmax]), "netcdf_read_particle_info_system nf90_getvar origin_type_varid" ) else @@ -977,7 +977,7 @@ module subroutine netcdf_read_particle_info_system(self, iu, param, plmask, tpma call tp%info(i)%set_value(origin_type=ctemp(tpind(i))) end do - status = nf90_inq_varid(iu%ncid, ORIGIN_TIME_VARNAME, iu%origin_time_varid) + status = nf90_inq_varid(iu%ncid, iu%origin_time_varname, iu%origin_time_varid) if (status == nf90_noerr) then call check( nf90_get_var(iu%ncid, iu%origin_time_varid, rtemp), "netcdf_read_particle_info_system nf90_getvar origin_time_varid" ) else @@ -992,7 +992,7 @@ module subroutine netcdf_read_particle_info_system(self, iu, param, plmask, tpma call tp%info(i)%set_value(origin_time=rtemp(tpind(i))) end do - status = nf90_inq_varid(iu%ncid, ORIGIN_XHX_VARNAME, iu%origin_xhx_varid) + status = nf90_inq_varid(iu%ncid, iu%origin_xhx_varname, iu%origin_xhx_varid) if (status == nf90_noerr) then call check( nf90_get_var(iu%ncid, iu%origin_xhx_varid, rtemp_arr(1,:)), "netcdf_read_particle_info_system nf90_getvar origin_xhx_varid" ) else if ((param%out_form == "XV") .or. (param%out_form == "XVEL")) then @@ -1001,7 +1001,7 @@ module subroutine netcdf_read_particle_info_system(self, iu, param, plmask, tpma rtemp_arr(1,:) = 0._DP end if - status = nf90_inq_varid(iu%ncid, ORIGIN_XHY_VARNAME, iu%origin_xhy_varid) + status = nf90_inq_varid(iu%ncid, iu%origin_xhy_varname, iu%origin_xhy_varid) if (status == nf90_noerr) then call check( nf90_get_var(iu%ncid, iu%origin_xhy_varid, rtemp_arr(2,:)), "netcdf_read_particle_info_system nf90_getvar origin_xhy_varid" ) else if ((param%out_form == "XV") .or. (param%out_form == "XVEL")) then @@ -1010,7 +1010,7 @@ module subroutine netcdf_read_particle_info_system(self, iu, param, plmask, tpma rtemp_arr(2,:) = 0._DP end if - status = nf90_inq_varid(iu%ncid, ORIGIN_XHZ_VARNAME, iu%origin_xhz_varid) + status = nf90_inq_varid(iu%ncid, iu%origin_xhz_varname, iu%origin_xhz_varid) if (status == nf90_noerr) then call check( nf90_get_var(iu%ncid, iu%origin_xhz_varid, rtemp_arr(3,:)), "netcdf_read_particle_info_system nf90_getvar origin_xhz_varid" ) else if ((param%out_form == "XV") .or. (param%out_form == "XVEL")) then @@ -1026,7 +1026,7 @@ module subroutine netcdf_read_particle_info_system(self, iu, param, plmask, tpma call tp%info(i)%set_value(origin_xh=rtemp_arr(:,tpind(i))) end do - status = nf90_inq_varid(iu%ncid, ORIGIN_VHX_VARNAME, iu%origin_vhx_varid) + status = nf90_inq_varid(iu%ncid, iu%origin_vhx_varname, iu%origin_vhx_varid) if (status == nf90_noerr) then call check( nf90_get_var(iu%ncid, iu%origin_vhx_varid, rtemp_arr(1,:)), "netcdf_read_particle_info_system nf90_getvar origin_vhx_varid" ) else if ((param%out_form == "XV") .or. (param%out_form == "XVEL")) then @@ -1035,7 +1035,7 @@ module subroutine netcdf_read_particle_info_system(self, iu, param, plmask, tpma rtemp_arr(1,:) = 0._DP end if - status = nf90_inq_varid(iu%ncid, ORIGIN_VHY_VARNAME, iu%origin_vhy_varid) + status = nf90_inq_varid(iu%ncid, iu%origin_vhy_varname, iu%origin_vhy_varid) if (status == nf90_noerr) then call check( nf90_get_var(iu%ncid, iu%origin_vhy_varid, rtemp_arr(2,:)), "netcdf_read_particle_info_system nf90_getvar origin_vhy_varid" ) else if ((param%out_form == "XV") .or. (param%out_form == "XVEL")) then @@ -1044,7 +1044,7 @@ module subroutine netcdf_read_particle_info_system(self, iu, param, plmask, tpma rtemp_arr(2,:) = 0._DP end if - status = nf90_inq_varid(iu%ncid, ORIGIN_VHZ_VARNAME, iu%origin_vhz_varid) + status = nf90_inq_varid(iu%ncid, iu%origin_vhz_varname, iu%origin_vhz_varid) if (status == nf90_noerr) then call check( nf90_get_var(iu%ncid, iu%origin_vhz_varid, rtemp_arr(3,:)), "netcdf_read_particle_info_system nf90_getvar origin_vhz_varid" ) else if ((param%out_form == "XV") .or. (param%out_form == "XVEL")) then @@ -1060,7 +1060,7 @@ module subroutine netcdf_read_particle_info_system(self, iu, param, plmask, tpma call tp%info(i)%set_value(origin_vh=rtemp_arr(:,tpind(i))) end do - status = nf90_inq_varid(iu%ncid, COLLISION_ID_VARNAME, iu%collision_id_varid) + status = nf90_inq_varid(iu%ncid, iu%collision_id_varname, iu%collision_id_varid) if (status == nf90_noerr) then call check( nf90_get_var(iu%ncid, iu%collision_id_varid, itemp), "netcdf_read_particle_info_system nf90_getvar collision_id_varid" ) else @@ -1074,7 +1074,7 @@ module subroutine netcdf_read_particle_info_system(self, iu, param, plmask, tpma call tp%info(i)%set_value(collision_id=itemp(tpind(i))) end do - status = nf90_inq_varid(iu%ncid, DISCARD_TIME_VARNAME, iu%discard_time_varid) + status = nf90_inq_varid(iu%ncid, iu%discard_time_varname, iu%discard_time_varid) if (status == nf90_noerr) then call check( nf90_get_var(iu%ncid, iu%discard_time_varid, rtemp), "netcdf_read_particle_info_system nf90_getvar discard_time_varid" ) else @@ -1089,21 +1089,21 @@ module subroutine netcdf_read_particle_info_system(self, iu, param, plmask, tpma call tp%info(i)%set_value(discard_time=rtemp(tpind(i))) end do - status = nf90_inq_varid(iu%ncid, DISCARD_XHX_VARNAME, iu%discard_xhx_varid) + status = nf90_inq_varid(iu%ncid, iu%discard_xhx_varname, iu%discard_xhx_varid) if (status == nf90_noerr) then call check( nf90_get_var(iu%ncid, iu%discard_xhx_varid, rtemp_arr(1,:)), "netcdf_read_particle_info_system nf90_getvar discard_xhx_varid" ) else rtemp_arr(1,:) = 0.0_DP end if - status = nf90_inq_varid(iu%ncid, DISCARD_XHY_VARNAME, iu%discard_xhy_varid) + status = nf90_inq_varid(iu%ncid, iu%discard_xhy_varname, iu%discard_xhy_varid) if (status == nf90_noerr) then call check( nf90_get_var(iu%ncid, iu%discard_xhy_varid, rtemp_arr(2,:)), "netcdf_read_particle_info_system nf90_getvar discard_xhy_varid" ) else rtemp_arr(2,:) = 0.0_DP end if - status = nf90_inq_varid(iu%ncid, DISCARD_XHZ_VARNAME, iu%discard_xhz_varid) + status = nf90_inq_varid(iu%ncid, iu%discard_xhz_varname, iu%discard_xhz_varid) if (status == nf90_noerr) then call check( nf90_get_var(iu%ncid, iu%discard_xhz_varid, rtemp_arr(3,:)), "netcdf_read_particle_info_system nf90_getvar discard_xhz_varid" ) else @@ -1117,21 +1117,21 @@ module subroutine netcdf_read_particle_info_system(self, iu, param, plmask, tpma call tp%info(i)%set_value(discard_xh=rtemp_arr(:,tpind(i))) end do - status = nf90_inq_varid(iu%ncid, DISCARD_VHX_VARNAME, iu%discard_vhx_varid) + status = nf90_inq_varid(iu%ncid, iu%discard_vhx_varname, iu%discard_vhx_varid) if (status == nf90_noerr) then call check( nf90_get_var(iu%ncid, iu%discard_vhx_varid, rtemp_arr(1,:)), "netcdf_read_particle_info_system nf90_getvar discard_vhx_varid" ) else rtemp_arr(1,:) = 0.0_DP end if - status = nf90_inq_varid(iu%ncid, DISCARD_VHY_VARNAME, iu%discard_vhy_varid) + status = nf90_inq_varid(iu%ncid, iu%discard_vhy_varname, iu%discard_vhy_varid) if (status == nf90_noerr) then call check( nf90_get_var(iu%ncid, iu%discard_vhy_varid, rtemp_arr(2,:)), "netcdf_read_particle_info_system nf90_getvar discard_vhy_varid" ) else rtemp_arr(2,:) = 0.0_DP end if - status = nf90_inq_varid(iu%ncid, DISCARD_VHZ_VARNAME, iu%discard_vhz_varid) + status = nf90_inq_varid(iu%ncid, iu%discard_vhz_varname, iu%discard_vhz_varid) if (status == nf90_noerr) then call check( nf90_get_var(iu%ncid, iu%discard_vhz_varid, rtemp_arr(3,:)), "netcdf_read_particle_info_system nf90_getvar discard_vhz_varid" ) else From c514868dc0d8b6de40300bca73a706c23bac0aa9 Mon Sep 17 00:00:00 2001 From: David A Minton Date: Sat, 3 Dec 2022 06:37:01 -0500 Subject: [PATCH 30/65] Removed space stuff for new branch --- src/modules/swiftest_classes.f90 | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/modules/swiftest_classes.f90 b/src/modules/swiftest_classes.f90 index 5c75908fb..3c4543886 100644 --- a/src/modules/swiftest_classes.f90 +++ b/src/modules/swiftest_classes.f90 @@ -36,8 +36,6 @@ module swiftest_classes integer(I4B) :: time_varid !! ID for the time variable character(NAMELEN) :: id_dimname = "id" !! name of the particle id dimension integer(I4B) :: id_varid !! ID for the particle name variable - character(NAMELEN) :: space_dimname = "space" !! name of the space dimension - integer(I4B) :: space_varid !! ID for the space variable ! Non-dimension ids and variable names character(NAMELEN) :: ptype_varname = "particle_type" !! name of the particle type variable From d2221e2d249d63ba10fe1e414a8e6b4e89aaf814 Mon Sep 17 00:00:00 2001 From: David A Minton Date: Sat, 3 Dec 2022 06:39:17 -0500 Subject: [PATCH 31/65] Disabled the encounter dumps for testing --- src/symba/symba_step.f90 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/symba/symba_step.f90 b/src/symba/symba_step.f90 index 183105b35..ecf1874f6 100644 --- a/src/symba/symba_step.f90 +++ b/src/symba/symba_step.f90 @@ -38,7 +38,7 @@ module subroutine symba_step_system(self, param, t, dt) lencounter = pl%encounter_check(param, self, dt, 0) .or. tp%encounter_check(param, self, dt, 0) if (lencounter) then call self%interp(param, t, dt) - call self%encounter_history%dump(param) + !call self%encounter_history%dump(param) else self%irec = -1 call helio_step_system(self, param, t, dt) From 6585cd46c7b1b09d60930e22f8ede47a4aa2aa70 Mon Sep 17 00:00:00 2001 From: David A Minton Date: Sat, 3 Dec 2022 06:41:42 -0500 Subject: [PATCH 32/65] Added the SPACE DIMENSION! --- src/modules/swiftest_classes.f90 | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/modules/swiftest_classes.f90 b/src/modules/swiftest_classes.f90 index 3c4543886..5c75908fb 100644 --- a/src/modules/swiftest_classes.f90 +++ b/src/modules/swiftest_classes.f90 @@ -36,6 +36,8 @@ module swiftest_classes integer(I4B) :: time_varid !! ID for the time variable character(NAMELEN) :: id_dimname = "id" !! name of the particle id dimension integer(I4B) :: id_varid !! ID for the particle name variable + character(NAMELEN) :: space_dimname = "space" !! name of the space dimension + integer(I4B) :: space_varid !! ID for the space variable ! Non-dimension ids and variable names character(NAMELEN) :: ptype_varname = "particle_type" !! name of the particle type variable From 2f24f6fb8dd96c3eb8ebfc71f47485b68ec28b0d Mon Sep 17 00:00:00 2001 From: David A Minton Date: Sat, 3 Dec 2022 07:06:38 -0500 Subject: [PATCH 33/65] Refactored NetCDF subroutines and arguments for consistency and clarity --- src/encounter/encounter_io.f90 | 124 ++-- src/modules/encounter_classes.f90 | 4 +- src/modules/swiftest_classes.f90 | 35 +- src/netcdf/netcdf.f90 | 989 ++++++++++++++-------------- src/symba/symba_encounter_check.f90 | 14 +- 5 files changed, 586 insertions(+), 580 deletions(-) diff --git a/src/encounter/encounter_io.f90 b/src/encounter/encounter_io.f90 index badd3685a..e425c0ae1 100644 --- a/src/encounter/encounter_io.f90 +++ b/src/encounter/encounter_io.f90 @@ -67,12 +67,12 @@ module subroutine encounter_io_initialize_output(self, param) close(unit=LUN, status="delete") end if - call check( nf90_create(self%enc_file, NF90_NETCDF4, self%ncid), "encounter_io_initialize_output nf90_create" ) + call check( nf90_create(self%enc_file, NF90_NETCDF4, self%id), "encounter_io_initialize_output nf90_create" ) - call check( nf90_def_dim(self%ncid, self%encid_dimname, NF90_UNLIMITED, self%encid_dimid), "encounter_io_initialize_output nf90_def_dim encid_dimid" ) - call check( nf90_def_dim(self%ncid, self%str_dimname, NAMELEN, self%str_dimid), "encounter_io_initialize_output nf90_def_dim str_dimid" ) ! Dimension for string variables (aka character arrays) - call check( nf90_def_dim(self%ncid, self%time_dimname, NF90_UNLIMITED, self%time_dimid), "encounter_io_initialize_output nf90_def_dim time_dimid" ) ! 'y' dimension - call check( nf90_def_dim(self%ncid, self%collider_dimname, self%collider_dim_size, self%collider_dimid), "encounter_io_initialize_output nf90_def_dim time_dimid" ) ! 'y' dimension + call check( nf90_def_dim(self%id, self%eid_dimname, NF90_UNLIMITED, self%eid_dimid), "encounter_io_initialize_output nf90_def_dim eid_dimid" ) + call check( nf90_def_dim(self%id, self%str_dimname, NAMELEN, self%str_dimid), "encounter_io_initialize_output nf90_def_dim str_dimid" ) ! Dimension for string variables (aka character arrays) + call check( nf90_def_dim(self%id, self%time_dimname, NF90_UNLIMITED, self%time_dimid), "encounter_io_initialize_output nf90_def_dim time_dimid" ) ! 'y' dimension + call check( nf90_def_dim(self%id, self%collider_dimname, self%collider_dim_size, self%collider_dimid), "encounter_io_initialize_output nf90_def_dim time_dimid" ) ! 'y' dimension select case (param%out_type) case("NETCDF_FLOAT") @@ -81,23 +81,23 @@ module subroutine encounter_io_initialize_output(self, param) self%out_type = NF90_DOUBLE end select - call check( nf90_def_var(self%ncid, self%time_dimname, self%out_type, self%time_dimid, self%time_varid), "encounter_io_initialize_output nf90_def_var time_varid" ) - call check( nf90_def_var(self%ncid, self%nenc_varname, NF90_INT, self%time_dimid, self%nenc_varid), "encounter_io_initialize_output nf90_def_var nenc_varid" ) - call check( nf90_def_var(self%ncid, self%name_varname, NF90_CHAR, [self%str_dimid, self%collider_dimid, self%encid_dimid], self%name_varid), "encounter_io_initialize_output nf90_def_var name_varid" ) - call check( nf90_def_var(self%ncid, self%id_dimname, NF90_INT, [self%collider_dimid, self%encid_dimid, self%time_dimid], self%id_varid), "encounter_io_initialize_output nf90_def_var id_varid" ) - call check( nf90_def_var(self%ncid, self%xhx_varname, self%out_type, [self%collider_dimid, self%encid_dimid, self%time_dimid], self%xhx_varid), "encounter_io_initialize_output nf90_def_var xhx_varid" ) - call check( nf90_def_var(self%ncid, self%xhy_varname, self%out_type, [self%collider_dimid, self%encid_dimid, self%time_dimid], self%xhy_varid), "encounter_io_initialize_output nf90_def_var xhy_varid" ) - call check( nf90_def_var(self%ncid, self%xhz_varname, self%out_type, [self%collider_dimid, self%encid_dimid, self%time_dimid], self%xhz_varid), "encounter_io_initialize_output nf90_def_var xhz_varid" ) - call check( nf90_def_var(self%ncid, self%vhx_varname, self%out_type, [self%collider_dimid, self%encid_dimid, self%time_dimid], self%vhx_varid), "encounter_io_initialize_output nf90_def_var vhx_varid" ) - call check( nf90_def_var(self%ncid, self%vhy_varname, self%out_type, [self%collider_dimid, self%encid_dimid, self%time_dimid], self%vhy_varid), "encounter_io_initialize_output nf90_def_var vhy_varid" ) - call check( nf90_def_var(self%ncid, self%vhz_varname, self%out_type, [self%collider_dimid, self%encid_dimid, self%time_dimid], self%vhz_varid), "encounter_io_initialize_output nf90_def_var vhz_varid" ) - call check( nf90_def_var(self%ncid, self%level_varname, NF90_INT, [self%encid_dimid, self%time_dimid], self%level_varid), "encounter_io_initialize_output nf90_def_var level_varid" ) - call check( nf90_def_var(self%ncid, self%gmass_varname, self%out_type, [self%collider_dimid, self%encid_dimid, self%time_dimid], self%Gmass_varid), "encounter_io_initialize_output nf90_def_var Gmass_varid" ) - call check( nf90_def_var(self%ncid, self%radius_varname, self%out_type, [self%collider_dimid, self%encid_dimid, self%time_dimid], self%radius_varid), "encounter_io_initialize_output nf90_def_var radius_varid" ) + call check( nf90_def_var(self%id, self%time_dimname, self%out_type, self%time_dimid, self%time_varid), "encounter_io_initialize_output nf90_def_var time_varid" ) + call check( nf90_def_var(self%id, self%nenc_varname, NF90_INT, self%time_dimid, self%nenc_varid), "encounter_io_initialize_output nf90_def_var nenc_varid" ) + call check( nf90_def_var(self%id, self%name_varname, NF90_CHAR, [self%str_dimid, self%collider_dimid, self%eid_dimid], self%name_varid), "encounter_io_initialize_output nf90_def_var name_varid" ) + call check( nf90_def_var(self%id, self%id_dimname, NF90_INT, [self%collider_dimid, self%eid_dimid, self%time_dimid], self%id_varid), "encounter_io_initialize_output nf90_def_var id_varid" ) + call check( nf90_def_var(self%id, self%xhx_varname, self%out_type, [self%collider_dimid, self%eid_dimid, self%time_dimid], self%xhx_varid), "encounter_io_initialize_output nf90_def_var xhx_varid" ) + call check( nf90_def_var(self%id, self%xhy_varname, self%out_type, [self%collider_dimid, self%eid_dimid, self%time_dimid], self%xhy_varid), "encounter_io_initialize_output nf90_def_var xhy_varid" ) + call check( nf90_def_var(self%id, self%xhz_varname, self%out_type, [self%collider_dimid, self%eid_dimid, self%time_dimid], self%xhz_varid), "encounter_io_initialize_output nf90_def_var xhz_varid" ) + call check( nf90_def_var(self%id, self%vhx_varname, self%out_type, [self%collider_dimid, self%eid_dimid, self%time_dimid], self%vhx_varid), "encounter_io_initialize_output nf90_def_var vhx_varid" ) + call check( nf90_def_var(self%id, self%vhy_varname, self%out_type, [self%collider_dimid, self%eid_dimid, self%time_dimid], self%vhy_varid), "encounter_io_initialize_output nf90_def_var vhy_varid" ) + call check( nf90_def_var(self%id, self%vhz_varname, self%out_type, [self%collider_dimid, self%eid_dimid, self%time_dimid], self%vhz_varid), "encounter_io_initialize_output nf90_def_var vhz_varid" ) + call check( nf90_def_var(self%id, self%level_varname, NF90_INT, [self%eid_dimid, self%time_dimid], self%level_varid), "encounter_io_initialize_output nf90_def_var level_varid" ) + call check( nf90_def_var(self%id, self%gmass_varname, self%out_type, [self%collider_dimid, self%eid_dimid, self%time_dimid], self%Gmass_varid), "encounter_io_initialize_output nf90_def_var Gmass_varid" ) + call check( nf90_def_var(self%id, self%radius_varname, self%out_type, [self%collider_dimid, self%eid_dimid, self%time_dimid], self%radius_varid), "encounter_io_initialize_output nf90_def_var radius_varid" ) ! Take the file out of define mode - call check( nf90_enddef(self%ncid), "encounter_io_initialize_output nf90_enddef" ) + call check( nf90_enddef(self%id), "encounter_io_initialize_output nf90_enddef" ) return @@ -126,26 +126,26 @@ 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%enc_file, mode, self%ncid), errmsg) - - call check( nf90_inq_dimid(self%ncid, self%time_dimname, self%time_dimid), "encounter_io_open_file nf90_inq_dimid time_dimid" ) - call check( nf90_inq_dimid(self%ncid, self%encid_dimname, self%encid_dimid), "encounter_io_open_file nf90_inq_dimid encid_dimid" ) - call check( nf90_inq_dimid(self%ncid, self%collider_dimname, self%collider_dimid), "encounter_io_open_file nf90_inq_dimid collider_dimid" ) - call check( nf90_inq_dimid(self%ncid, self%str_dimname, self%str_dimid), "encounter_io_open_file nf90_inq_dimid collider_str" ) - - call check( nf90_inq_varid(self%ncid, self%time_dimname, self%time_varid), "encounter_io_open_file nf90_inq_varid time_varid" ) - call check( nf90_inq_varid(self%ncid, self%name_varname, self%name_varid), "encounter_io_open_file nf90_inq_varid name_varid" ) - call check( nf90_inq_varid(self%ncid, self%nenc_varname, self%nenc_varid), "encounter_io_open_file nf90_inq_varid nenc_varid" ) - - call check( nf90_inq_varid(self%ncid, self%xhx_varname, self%xhx_varid), "encounter_io_open_file nf90_inq_varid xhx_varid" ) - call check( nf90_inq_varid(self%ncid, self%xhy_varname, self%xhy_varid), "encounter_io_open_file nf90_inq_varid xhy_varid" ) - call check( nf90_inq_varid(self%ncid, self%xhz_varname, self%xhz_varid), "encounter_io_open_file nf90_inq_varid xhz_varid" ) - call check( nf90_inq_varid(self%ncid, self%vhx_varname, self%vhx_varid), "encounter_io_open_file nf90_inq_varid vhx_varid" ) - call check( nf90_inq_varid(self%ncid, self%vhy_varname, self%vhy_varid), "encounter_io_open_file nf90_inq_varid vhy_varid" ) - call check( nf90_inq_varid(self%ncid, self%vhz_varname, self%vhz_varid), "encounter_io_open_file nf90_inq_varid vhz_varid" ) - call check( nf90_inq_varid(self%ncid, self%level_varname, self%level_varid), "encounter_io_open_file nf90_inq_varid level_varid" ) - call check( nf90_inq_varid(self%ncid, self%gmass_varname, self%Gmass_varid), "encounter_io_open_file nf90_inq_varid Gmass_varid" ) - call check( nf90_inq_varid(self%ncid, self%radius_varname, self%radius_varid), "encounter_io_open_file nf90_inq_varid radius_varid" ) + call check( nf90_open(self%enc_file, mode, self%id), errmsg) + + call check( nf90_inq_dimid(self%id, self%time_dimname, self%time_dimid), "encounter_io_open_file nf90_inq_dimid time_dimid" ) + call check( nf90_inq_dimid(self%id, self%eid_dimname, self%eid_dimid), "encounter_io_open_file nf90_inq_dimid eid_dimid" ) + call check( nf90_inq_dimid(self%id, self%collider_dimname, self%collider_dimid), "encounter_io_open_file nf90_inq_dimid collider_dimid" ) + call check( nf90_inq_dimid(self%id, self%str_dimname, self%str_dimid), "encounter_io_open_file nf90_inq_dimid collider_str" ) + + call check( nf90_inq_varid(self%id, self%time_dimname, self%time_varid), "encounter_io_open_file nf90_inq_varid time_varid" ) + call check( nf90_inq_varid(self%id, self%name_varname, self%name_varid), "encounter_io_open_file nf90_inq_varid name_varid" ) + call check( nf90_inq_varid(self%id, self%nenc_varname, self%nenc_varid), "encounter_io_open_file nf90_inq_varid nenc_varid" ) + + call check( nf90_inq_varid(self%id, self%xhx_varname, self%xhx_varid), "encounter_io_open_file nf90_inq_varid xhx_varid" ) + call check( nf90_inq_varid(self%id, self%xhy_varname, self%xhy_varid), "encounter_io_open_file nf90_inq_varid xhy_varid" ) + call check( nf90_inq_varid(self%id, self%xhz_varname, self%xhz_varid), "encounter_io_open_file nf90_inq_varid xhz_varid" ) + call check( nf90_inq_varid(self%id, self%vhx_varname, self%vhx_varid), "encounter_io_open_file nf90_inq_varid vhx_varid" ) + call check( nf90_inq_varid(self%id, self%vhy_varname, self%vhy_varid), "encounter_io_open_file nf90_inq_varid vhy_varid" ) + call check( nf90_inq_varid(self%id, self%vhz_varname, self%vhz_varid), "encounter_io_open_file nf90_inq_varid vhz_varid" ) + call check( nf90_inq_varid(self%id, self%level_varname, self%level_varid), "encounter_io_open_file nf90_inq_varid level_varid" ) + call check( nf90_inq_varid(self%id, self%gmass_varname, self%Gmass_varid), "encounter_io_open_file nf90_inq_varid Gmass_varid" ) + call check( nf90_inq_varid(self%id, self%radius_varname, self%radius_varid), "encounter_io_open_file nf90_inq_varid radius_varid" ) return end subroutine encounter_io_open_file @@ -164,31 +164,31 @@ module subroutine encounter_io_write_frame(self, iu, param) i = iu%ienc_frame n = int(self%nenc, kind=I4B) - call check( nf90_set_fill(iu%ncid, nf90_nofill, old_mode), "encounter_io_write_frame_base nf90_set_fill" ) - call check( nf90_put_var(iu%ncid, iu%time_varid, self%t, start=[i]), "encounter_io_write_frame nf90_put_var time_varid" ) - - call check( nf90_put_var(iu%ncid, iu%nenc_varid, self%nenc, start=[i]), "encounter_io_frame nf90_put_var nenc_varid" ) - call check( nf90_put_var(iu%ncid, iu%name_varid, self%name1(1:n), start=[1, 1, i], count=[NAMELEN,1,1]), "netcdf_write_frame nf90_put_var name 1" ) - call check( nf90_put_var(iu%ncid, iu%name_varid, self%name2(1:n), start=[1, 2, i], count=[NAMELEN,1,1]), "netcdf_write_frame nf90_put_var name 2" ) - call check( nf90_put_var(iu%ncid, iu%xhx_varid, self%x1(1, 1:n), start=[1, 1, i], count=[1,n,1]), "netcdf_write_frame nf90_put_var xhx_varid 1" ) - call check( nf90_put_var(iu%ncid, iu%xhy_varid, self%x1(2, 1:n), start=[1, 1, i], count=[1,n,1]), "netcdf_write_frame nf90_put_var xhy_varid 1" ) - call check( nf90_put_var(iu%ncid, iu%xhz_varid, self%x1(3, 1:n), start=[1, 1, i], count=[1,n,1]), "netcdf_write_frame nf90_put_var xhz_varid 1" ) - call check( nf90_put_var(iu%ncid, iu%xhx_varid, self%x2(1, 1:n), start=[2, 1, i], count=[1,n,1]), "netcdf_write_frame nf90_put_var xhx_varid 2" ) - call check( nf90_put_var(iu%ncid, iu%xhy_varid, self%x2(2, 1:n), start=[2, 1, i], count=[1,n,1]), "netcdf_write_frame nf90_put_var xhy_varid 2" ) - call check( nf90_put_var(iu%ncid, iu%xhz_varid, self%x2(3, 1:n), start=[2, 1, i], count=[1,n,1]), "netcdf_write_frame nf90_put_var xhz_varid 2" ) - call check( nf90_put_var(iu%ncid, iu%vhx_varid, self%v1(1, 1:n), start=[1, 1, i], count=[1,n,1]), "netcdf_write_frame nf90_put_var vhx_varid 1" ) - call check( nf90_put_var(iu%ncid, iu%vhy_varid, self%v1(2, 1:n), start=[1, 1, i], count=[1,n,1]), "netcdf_write_frame nf90_put_var vhy_varid 1" ) - call check( nf90_put_var(iu%ncid, iu%vhz_varid, self%v1(3, 1:n), start=[1, 1, i], count=[1,n,1]), "netcdf_write_frame nf90_put_var vhz_varid 1" ) - call check( nf90_put_var(iu%ncid, iu%vhx_varid, self%v2(1, 1:n), start=[2, 1, i], count=[1,n,1]), "netcdf_write_frame nf90_put_var vhx_varid 2" ) - call check( nf90_put_var(iu%ncid, iu%vhy_varid, self%v2(2, 1:n), start=[2, 1, i], count=[1,n,1]), "netcdf_write_frame nf90_put_var vhy_varid 2" ) - call check( nf90_put_var(iu%ncid, iu%vhz_varid, self%v2(3, 1:n), start=[2, 1, i], count=[1,n,1]), "netcdf_write_frame nf90_put_var vhz_varid 2" ) - call check( nf90_put_var(iu%ncid, iu%Gmass_varid, self%Gmass1(1:n), start=[1, 1, i], count=[1,n,1]), "netcdf_write_frame nf90_put_var Gmass 1" ) - call check( nf90_put_var(iu%ncid, iu%Gmass_varid, self%Gmass2(1:n), start=[2, 1, i], count=[1,n,1]), "netcdf_write_frame nf90_put_var Gmass 2" ) - call check( nf90_put_var(iu%ncid, iu%radius_varid, self%radius1(1:n), start=[1, 1, i], count=[1,n,1]), "netcdf_write_frame nf90_put_var radius 1" ) - call check( nf90_put_var(iu%ncid, iu%radius_varid, self%radius2(1:n), start=[2, 1, i], count=[1,n,1]), "netcdf_write_frame nf90_put_var radius 2" ) + call check( nf90_set_fill(iu%id, nf90_nofill, old_mode), "encounter_io_write_frame_base nf90_set_fill" ) + call check( nf90_put_var(iu%id, iu%time_varid, self%t, start=[i]), "encounter_io_write_frame nf90_put_var time_varid" ) + + call check( nf90_put_var(iu%id, iu%nenc_varid, self%nenc, start=[i]), "encounter_io_frame nf90_put_var nenc_varid" ) + call check( nf90_put_var(iu%id, iu%name_varid, self%name1(1:n), start=[1, 1, i], count=[NAMELEN,1,1]), "netcdf_write_frame nf90_put_var name 1" ) + call check( nf90_put_var(iu%id, iu%name_varid, self%name2(1:n), start=[1, 2, i], count=[NAMELEN,1,1]), "netcdf_write_frame nf90_put_var name 2" ) + call check( nf90_put_var(iu%id, iu%xhx_varid, self%x1(1, 1:n), start=[1, 1, i], count=[1,n,1]), "netcdf_write_frame nf90_put_var xhx_varid 1" ) + call check( nf90_put_var(iu%id, iu%xhy_varid, self%x1(2, 1:n), start=[1, 1, i], count=[1,n,1]), "netcdf_write_frame nf90_put_var xhy_varid 1" ) + call check( nf90_put_var(iu%id, iu%xhz_varid, self%x1(3, 1:n), start=[1, 1, i], count=[1,n,1]), "netcdf_write_frame nf90_put_var xhz_varid 1" ) + call check( nf90_put_var(iu%id, iu%xhx_varid, self%x2(1, 1:n), start=[2, 1, i], count=[1,n,1]), "netcdf_write_frame nf90_put_var xhx_varid 2" ) + call check( nf90_put_var(iu%id, iu%xhy_varid, self%x2(2, 1:n), start=[2, 1, i], count=[1,n,1]), "netcdf_write_frame nf90_put_var xhy_varid 2" ) + call check( nf90_put_var(iu%id, iu%xhz_varid, self%x2(3, 1:n), start=[2, 1, i], count=[1,n,1]), "netcdf_write_frame nf90_put_var xhz_varid 2" ) + call check( nf90_put_var(iu%id, iu%vhx_varid, self%v1(1, 1:n), start=[1, 1, i], count=[1,n,1]), "netcdf_write_frame nf90_put_var vhx_varid 1" ) + call check( nf90_put_var(iu%id, iu%vhy_varid, self%v1(2, 1:n), start=[1, 1, i], count=[1,n,1]), "netcdf_write_frame nf90_put_var vhy_varid 1" ) + call check( nf90_put_var(iu%id, iu%vhz_varid, self%v1(3, 1:n), start=[1, 1, i], count=[1,n,1]), "netcdf_write_frame nf90_put_var vhz_varid 1" ) + call check( nf90_put_var(iu%id, iu%vhx_varid, self%v2(1, 1:n), start=[2, 1, i], count=[1,n,1]), "netcdf_write_frame nf90_put_var vhx_varid 2" ) + call check( nf90_put_var(iu%id, iu%vhy_varid, self%v2(2, 1:n), start=[2, 1, i], count=[1,n,1]), "netcdf_write_frame nf90_put_var vhy_varid 2" ) + call check( nf90_put_var(iu%id, iu%vhz_varid, self%v2(3, 1:n), start=[2, 1, i], count=[1,n,1]), "netcdf_write_frame nf90_put_var vhz_varid 2" ) + call check( nf90_put_var(iu%id, iu%Gmass_varid, self%Gmass1(1:n), start=[1, 1, i], count=[1,n,1]), "netcdf_write_frame nf90_put_var Gmass 1" ) + call check( nf90_put_var(iu%id, iu%Gmass_varid, self%Gmass2(1:n), start=[2, 1, i], count=[1,n,1]), "netcdf_write_frame nf90_put_var Gmass 2" ) + call check( nf90_put_var(iu%id, iu%radius_varid, self%radius1(1:n), start=[1, 1, i], count=[1,n,1]), "netcdf_write_frame nf90_put_var radius 1" ) + call check( nf90_put_var(iu%id, iu%radius_varid, self%radius2(1:n), start=[2, 1, i], count=[1,n,1]), "netcdf_write_frame nf90_put_var radius 2" ) select type(self) class is (symba_encounter) - call check( nf90_put_var(iu%ncid, iu%level_varid, self%level(1:n), start=[1, i], count=[n,1]), "netcdf_write_frame nf90_put_var level" ) + call check( nf90_put_var(iu%id, iu%level_varid, self%level(1:n), start=[1, i], count=[n,1]), "netcdf_write_frame nf90_put_var level" ) end select return diff --git a/src/modules/encounter_classes.f90 b/src/modules/encounter_classes.f90 index 1bb595b02..a7f2d72ac 100644 --- a/src/modules/encounter_classes.f90 +++ b/src/modules/encounter_classes.f90 @@ -54,8 +54,8 @@ module encounter_classes integer(I4B) :: ienc_frame !! Current frame number for the encounter history character(STRMAX) :: enc_file = "encounter.nc" !! Encounter output file name - character(NAMELEN) :: encid_dimname = "encounter" !! The index of the encountering pair in the encounter list - integer(I4B) :: encid_dimid !! ID for the encounter pair index dimension + character(NAMELEN) :: eid_dimname = "encounter" !! The index of the encountering pair in the encounter list + integer(I4B) :: eid_dimid !! ID for the encounter pair index dimension character(NAMELEN) :: collider_dimname = "collider" !! Dimension that defines the colliding bodies (bodies 1 and 2 are at dimension coordinates 1 and 2, respectively) integer(I4B) :: collider_dimid !! ID for the collider dimension character(NAMELEN) :: nenc_varname = "nenc" !! Total number of encounters diff --git a/src/modules/swiftest_classes.f90 b/src/modules/swiftest_classes.f90 index 5c75908fb..f3704a978 100644 --- a/src/modules/swiftest_classes.f90 +++ b/src/modules/swiftest_classes.f90 @@ -21,22 +21,23 @@ module swiftest_classes !! This derived datatype stores the NetCDF ID values for each of the variables included in the NetCDF data file. This is used as the base class defined in swiftest_classes type :: netcdf_variables integer(I4B) :: out_type !! output type (will be assigned either NF90_DOUBLE or NF90_FLOAT, depending on the user parameter) - integer(I4B) :: ncid !! ID for the output file + integer(I4B) :: id !! ID for the output file integer(I4B) :: discard_body_id_varid !! ID for the id of the other body involved in the discard integer(I4B) :: id_chunk !! Chunk size for the id dimension variables integer(I4B) :: time_chunk !! Chunk size for the time dimension variables logical :: lpseudo_vel_exists = .false. !! Logical flag to indicate whether or not the pseudovelocity vectors were present in an old file. ! Dimension ids and variable names - integer(I4B) :: time_dimid !! ID for the time dimension - integer(I4B) :: id_dimid !! ID for the particle id dimension character(NAMELEN) :: str_dimname = "string32" !! name of the character string dimension integer(I4B) :: str_dimid !! ID for the character string dimension character(NAMELEN) :: time_dimname = "time" !! name of the time dimension + integer(I4B) :: time_dimid !! ID for the time dimension integer(I4B) :: time_varid !! ID for the time variable character(NAMELEN) :: id_dimname = "id" !! name of the particle id dimension + integer(I4B) :: id_dimid !! ID for the particle id dimension integer(I4B) :: id_varid !! ID for the particle name variable character(NAMELEN) :: space_dimname = "space" !! name of the space dimension + integer(I4B) :: space_dimid !! ID for the space dimension integer(I4B) :: space_varid !! ID for the space variable ! Non-dimension ids and variable names @@ -1062,55 +1063,55 @@ module subroutine netcdf_sync(self) class(netcdf_parameters), intent(inout) :: self !! Parameters used to identify a particular NetCDF dataset end subroutine netcdf_sync - module function netcdf_read_frame_system(self, iu, param) result(ierr) + module function netcdf_read_frame_system(self, nciu, param) result(ierr) implicit none class(swiftest_nbody_system), intent(inout) :: self !! Swiftest system object - class(netcdf_parameters), intent(inout) :: iu !! Parameters used to for reading a NetCDF dataset to file + class(netcdf_parameters), intent(inout) :: nciu !! Parameters used to for reading a NetCDF dataset to file class(swiftest_parameters), intent(inout) :: param !! Current run configuration parameters integer(I4B) :: ierr !! Error code: returns 0 if the read is successful end function netcdf_read_frame_system - module subroutine netcdf_read_hdr_system(self, iu, param) + module subroutine netcdf_read_hdr_system(self, nciu, param) implicit none class(swiftest_nbody_system), intent(inout) :: self !! Swiftest nbody system object - class(netcdf_parameters), intent(inout) :: iu !! Parameters used to for reading a NetCDF dataset to file + class(netcdf_parameters), intent(inout) :: nciu !! Parameters used to for reading a NetCDF dataset to file class(swiftest_parameters), intent(inout) :: param !! Current run configuration parameters end subroutine netcdf_read_hdr_system - module subroutine netcdf_read_particle_info_system(self, iu, param, plmask, tpmask) + module subroutine netcdf_read_particle_info_system(self, nciu, param, plmask, tpmask) implicit none class(swiftest_nbody_system), intent(inout) :: self !! Swiftest nbody system object - class(netcdf_parameters), intent(inout) :: iu !! Parameters used to identify a particular NetCDF dataset + class(netcdf_parameters), intent(inout) :: nciu !! Parameters used to identify a particular NetCDF dataset class(swiftest_parameters), intent(inout) :: param !! Current run configuration parameters logical, dimension(:), intent(in) :: plmask !! Logical array indicating which index values belong to massive bodies logical, dimension(:), intent(in) :: tpmask !! Logical array indicating which index values belong to test particles end subroutine netcdf_read_particle_info_system - module subroutine netcdf_write_frame_base(self, iu, param) + module subroutine netcdf_write_frame_base(self, nciu, param) implicit none class(swiftest_base), intent(in) :: self !! Swiftest base object - class(netcdf_parameters), intent(inout) :: iu !! Parameters used to for writing a NetCDF dataset to file + class(netcdf_parameters), intent(inout) :: nciu !! Parameters used to for writing a NetCDF dataset to file class(swiftest_parameters), intent(inout) :: param !! Current run configuration parameters end subroutine netcdf_write_frame_base - module subroutine netcdf_write_frame_system(self, iu, param) + module subroutine netcdf_write_frame_system(self, nciu, param) implicit none class(swiftest_nbody_system), intent(inout) :: self !! Swiftest system object - class(netcdf_parameters), intent(inout) :: iu !! Parameters used to for writing a NetCDF dataset to file + class(netcdf_parameters), intent(inout) :: nciu !! Parameters used to for writing a NetCDF dataset to file class(swiftest_parameters), intent(inout) :: param !! Current run configuration parameters end subroutine netcdf_write_frame_system - module subroutine netcdf_write_hdr_system(self, iu, param) + module subroutine netcdf_write_hdr_system(self, nciu, param) implicit none class(swiftest_nbody_system), intent(in) :: self !! Swiftest nbody system object - class(netcdf_parameters), intent(inout) :: iu !! Parameters used to for writing a NetCDF dataset to file + class(netcdf_parameters), intent(inout) :: nciu !! Parameters used to for writing a NetCDF dataset to file class(swiftest_parameters), intent(inout) :: param !! Current run configuration parameters end subroutine netcdf_write_hdr_system - module subroutine netcdf_write_info_base(self, iu, param) + module subroutine netcdf_write_info_base(self, nciu, param) implicit none class(swiftest_base), intent(in) :: self !! Swiftest particle object - class(netcdf_parameters), intent(inout) :: iu !! Parameters used to identify a particular NetCDF dataset + class(netcdf_parameters), intent(inout) :: nciu !! Parameters used to identify a particular NetCDF dataset class(swiftest_parameters), intent(inout) :: param !! Current run configuration parameters end subroutine netcdf_write_info_base diff --git a/src/netcdf/netcdf.f90 b/src/netcdf/netcdf.f90 index 42aa78882..a01482202 100644 --- a/src/netcdf/netcdf.f90 +++ b/src/netcdf/netcdf.f90 @@ -39,7 +39,7 @@ module subroutine netcdf_close(self) ! Arguments class(netcdf_parameters), intent(inout) :: self !! Parameters used to identify a particular NetCDF dataset - call check( nf90_close(self%ncid), "netcdf_close" ) + call check( nf90_close(self%id), "netcdf_close" ) return end subroutine netcdf_close @@ -81,51 +81,51 @@ module function netcdf_get_old_t_final_system(self, param) result(old_t_final) real(DP) :: KE_orb_orig, KE_spin_orig, PE_orig call param%nciu%open(param) - call check( nf90_inquire_dimension(param%nciu%ncid, param%nciu%time_dimid, len=itmax), "netcdf_get_old_t_final_system time_dimid" ) - call check( nf90_inquire_dimension(param%nciu%ncid, param%nciu%id_dimid, len=idmax), "netcdf_get_old_t_final_system id_dimid" ) + call check( nf90_inquire_dimension(param%nciu%id, param%nciu%time_dimid, len=itmax), "netcdf_get_old_t_final_system time_dimid" ) + call check( nf90_inquire_dimension(param%nciu%id, param%nciu%id_dimid, len=idmax), "netcdf_get_old_t_final_system id_dimid" ) allocate(vals(idmax)) - call check( nf90_get_var(param%nciu%ncid, param%nciu%time_varid, val, start=[1], count=[1]), "netcdf_get_old_t_final_system time_varid" ) + call check( nf90_get_var(param%nciu%id, param%nciu%time_varid, val, start=[1], count=[1]), "netcdf_get_old_t_final_system time_varid" ) !old_t_final = val(1) old_t_final = param%t0 ! For NetCDF it is safe to overwrite the final t value on a restart if (param%lenergy) then - call check( nf90_get_var(param%nciu%ncid, param%nciu%KE_orb_varid, val, start=[1], count=[1]), "netcdf_get_old_t_final_system KE_orb_varid" ) + call check( nf90_get_var(param%nciu%id, param%nciu%KE_orb_varid, val, start=[1], count=[1]), "netcdf_get_old_t_final_system KE_orb_varid" ) KE_orb_orig = val(1) - call check( nf90_get_var(param%nciu%ncid, param%nciu%KE_spin_varid, val, start=[1], count=[1]), "netcdf_get_old_t_final_system KE_spin_varid" ) + call check( nf90_get_var(param%nciu%id, param%nciu%KE_spin_varid, val, start=[1], count=[1]), "netcdf_get_old_t_final_system KE_spin_varid" ) KE_spin_orig = val(1) - call check( nf90_get_var(param%nciu%ncid, param%nciu%PE_varid, val, start=[1], count=[1]), "netcdf_get_old_t_final_system PE_varid" ) + call check( nf90_get_var(param%nciu%id, param%nciu%PE_varid, val, start=[1], count=[1]), "netcdf_get_old_t_final_system PE_varid" ) PE_orig = val(1) - call check( nf90_get_var(param%nciu%ncid, param%nciu%Ecollisions_varid, self%Ecollisions, start=[1]), "netcdf_get_old_t_final_system Ecollisions_varid" ) - call check( nf90_get_var(param%nciu%ncid, param%nciu%Euntracked_varid, self%Euntracked, start=[1]), "netcdf_get_old_t_final_system Euntracked_varid" ) + call check( nf90_get_var(param%nciu%id, param%nciu%Ecollisions_varid, self%Ecollisions, start=[1]), "netcdf_get_old_t_final_system Ecollisions_varid" ) + call check( nf90_get_var(param%nciu%id, param%nciu%Euntracked_varid, self%Euntracked, start=[1]), "netcdf_get_old_t_final_system Euntracked_varid" ) self%Eorbit_orig = KE_orb_orig + KE_spin_orig + PE_orig + self%Ecollisions + self%Euntracked - call check( nf90_get_var(param%nciu%ncid, param%nciu%L_orbx_varid, val, start=[1], count=[1]), "netcdf_get_old_t_final_system L_orbx_varid" ) + call check( nf90_get_var(param%nciu%id, param%nciu%L_orbx_varid, val, start=[1], count=[1]), "netcdf_get_old_t_final_system L_orbx_varid" ) self%Lorbit_orig(1) = val(1) - call check( nf90_get_var(param%nciu%ncid, param%nciu%L_orby_varid, val, start=[1], count=[1]), "netcdf_get_old_t_final_system L_orby_varid" ) + call check( nf90_get_var(param%nciu%id, param%nciu%L_orby_varid, val, start=[1], count=[1]), "netcdf_get_old_t_final_system L_orby_varid" ) self%Lorbit_orig(2) = val(1) - call check( nf90_get_var(param%nciu%ncid, param%nciu%L_orbz_varid, val, start=[1], count=[1]), "netcdf_get_old_t_final_system L_orbz_varid" ) + call check( nf90_get_var(param%nciu%id, param%nciu%L_orbz_varid, val, start=[1], count=[1]), "netcdf_get_old_t_final_system L_orbz_varid" ) self%Lorbit_orig(3) = val(1) - call check( nf90_get_var(param%nciu%ncid, param%nciu%L_spinx_varid, val, start=[1], count=[1]), "netcdf_get_old_t_final_system L_spinx_varid" ) + call check( nf90_get_var(param%nciu%id, param%nciu%L_spinx_varid, val, start=[1], count=[1]), "netcdf_get_old_t_final_system L_spinx_varid" ) self%Lspin_orig(1) = val(1) - call check( nf90_get_var(param%nciu%ncid, param%nciu%L_spiny_varid, val, start=[1], count=[1]), "netcdf_get_old_t_final_system L_spiny_varid" ) + call check( nf90_get_var(param%nciu%id, param%nciu%L_spiny_varid, val, start=[1], count=[1]), "netcdf_get_old_t_final_system L_spiny_varid" ) self%Lspin_orig(2) = val(1) - call check( nf90_get_var(param%nciu%ncid, param%nciu%L_spinz_varid, val, start=[1], count=[1]), "netcdf_get_old_t_final_system L_spinz_varid" ) + call check( nf90_get_var(param%nciu%id, param%nciu%L_spinz_varid, val, start=[1], count=[1]), "netcdf_get_old_t_final_system L_spinz_varid" ) self%Lspin_orig(3) = val(1) - call check( nf90_get_var(param%nciu%ncid, param%nciu%L_escapex_varid, self%Lescape(1), start=[1]), "netcdf_get_old_t_final_system L_escapex_varid" ) - call check( nf90_get_var(param%nciu%ncid, param%nciu%L_escapey_varid, self%Lescape(2), start=[1]), "netcdf_get_old_t_final_system L_escapey_varid" ) - call check( nf90_get_var(param%nciu%ncid, param%nciu%L_escapez_varid, self%Lescape(3), start=[1]), "netcdf_get_old_t_final_system L_escapez_varid" ) + call check( nf90_get_var(param%nciu%id, param%nciu%L_escapex_varid, self%Lescape(1), start=[1]), "netcdf_get_old_t_final_system L_escapex_varid" ) + call check( nf90_get_var(param%nciu%id, param%nciu%L_escapey_varid, self%Lescape(2), start=[1]), "netcdf_get_old_t_final_system L_escapey_varid" ) + call check( nf90_get_var(param%nciu%id, param%nciu%L_escapez_varid, self%Lescape(3), start=[1]), "netcdf_get_old_t_final_system L_escapez_varid" ) self%Ltot_orig(:) = self%Lorbit_orig(:) + self%Lspin_orig(:) + self%Lescape(:) - call check( nf90_get_var(param%nciu%ncid, param%nciu%Gmass_varid, vals, start=[1,1], count=[idmax,1]), "netcdf_get_old_t_final_system Gmass_varid" ) - call check( nf90_get_var(param%nciu%ncid, param%nciu%GMescape_varid, self%GMescape, start=[1]), "netcdf_get_old_t_final_system GMescape_varid" ) + call check( nf90_get_var(param%nciu%id, param%nciu%Gmass_varid, vals, start=[1,1], count=[idmax,1]), "netcdf_get_old_t_final_system Gmass_varid" ) + call check( nf90_get_var(param%nciu%id, param%nciu%GMescape_varid, self%GMescape, start=[1]), "netcdf_get_old_t_final_system GMescape_varid" ) self%GMtot_orig = vals(1) + sum(vals(2:idmax), vals(2:idmax) == vals(2:idmax)) + self%GMescape select type(cb => self%cb) @@ -133,23 +133,23 @@ module function netcdf_get_old_t_final_system(self, param) result(old_t_final) cb%GM0 = vals(1) cb%dGM = cb%Gmass - cb%GM0 - call check( nf90_get_var(param%nciu%ncid, param%nciu%radius_varid, val, start=[1,1], count=[1,1]), "netcdf_get_old_t_final_system radius_varid" ) + call check( nf90_get_var(param%nciu%id, param%nciu%radius_varid, val, start=[1,1], count=[1,1]), "netcdf_get_old_t_final_system radius_varid" ) cb%R0 = val(1) if (param%lrotation) then - call check( nf90_get_var(param%nciu%ncid, param%nciu%rotx_varid, val, start=[1,1], count=[1,1]), "netcdf_get_old_t_final_system rotx_varid" ) + call check( nf90_get_var(param%nciu%id, param%nciu%rotx_varid, val, start=[1,1], count=[1,1]), "netcdf_get_old_t_final_system rotx_varid" ) rot0(1) = val(1) - call check( nf90_get_var(param%nciu%ncid, param%nciu%roty_varid, val, start=[1,1], count=[1,1]), "netcdf_get_old_t_final_system roty_varid" ) + call check( nf90_get_var(param%nciu%id, param%nciu%roty_varid, val, start=[1,1], count=[1,1]), "netcdf_get_old_t_final_system roty_varid" ) rot0(2) = val(1) - call check( nf90_get_var(param%nciu%ncid, param%nciu%rotz_varid, val, start=[1,1], count=[1,1]), "netcdf_get_old_t_final_system rotz_varid" ) + call check( nf90_get_var(param%nciu%id, param%nciu%rotz_varid, val, start=[1,1], count=[1,1]), "netcdf_get_old_t_final_system rotz_varid" ) rot0(3) = val(1) - call check( nf90_get_var(param%nciu%ncid, param%nciu%Ip1_varid, val, start=[1,1], count=[1,1]), "netcdf_get_old_t_final_system Ip1_varid" ) + call check( nf90_get_var(param%nciu%id, param%nciu%Ip1_varid, val, start=[1,1], count=[1,1]), "netcdf_get_old_t_final_system Ip1_varid" ) Ip0(1) = val(1) - call check( nf90_get_var(param%nciu%ncid, param%nciu%Ip2_varid, val, start=[1,1], count=[1,1]), "netcdf_get_old_t_final_system Ip2_varid" ) + call check( nf90_get_var(param%nciu%id, param%nciu%Ip2_varid, val, start=[1,1], count=[1,1]), "netcdf_get_old_t_final_system Ip2_varid" ) Ip0(2) = val(1) - call check( nf90_get_var(param%nciu%ncid, param%nciu%Ip3_varid, val, start=[1,1], count=[1,1]), "netcdf_get_old_t_final_system Ip3_varid" ) + call check( nf90_get_var(param%nciu%id, param%nciu%Ip3_varid, val, start=[1,1], count=[1,1]), "netcdf_get_old_t_final_system Ip3_varid" ) Ip0(3) = val(1) cb%L0(:) = Ip0(3) * cb%GM0 * cb%R0**2 * rot0(:) @@ -175,7 +175,7 @@ module subroutine netcdf_initialize_output(self, param) implicit none ! Arguments class(netcdf_parameters), intent(inout) :: self !! Parameters used to identify a particular NetCDF dataset - class(swiftest_parameters), intent(in) :: param !! Current run configuration parameters + class(swiftest_parameters), intent(in) :: param !! Current run configuration parameters ! Internals integer(I4B) :: nvar, varid, vartype real(DP) :: dfill @@ -184,153 +184,163 @@ module subroutine netcdf_initialize_output(self, param) character(len=STRMAX) :: errmsg integer(I4B) :: ndims - dfill = ieee_value(dfill, IEEE_QUIET_NAN) - sfill = ieee_value(sfill, IEEE_QUIET_NAN) + associate(nciu => self) - ! Check if the file exists, and if it does, delete it - inquire(file=param%outfile, exist=fileExists) - if (fileExists) then - open(unit=LUN, file=param%outfile, status="old", err=667, iomsg=errmsg) - close(unit=LUN, status="delete") - end if - - call check( nf90_create(param%outfile, NF90_NETCDF4, self%ncid), "netcdf_initialize_output nf90_create" ) + dfill = ieee_value(dfill, IEEE_QUIET_NAN) + sfill = ieee_value(sfill, IEEE_QUIET_NAN) - ! Define the NetCDF dimensions with particle name as the record dimension - call check( nf90_def_dim(self%ncid, self%id_dimname, NF90_UNLIMITED, self%id_dimid), "netcdf_initialize_output nf90_def_dim id_dimid" ) ! 'x' dimension - call check( nf90_def_dim(self%ncid, self%str_dimname, NAMELEN, self%str_dimid), "netcdf_initialize_output nf90_def_dim str_dimid" ) ! Dimension for string variables (aka character arrays) - call check( nf90_def_dim(self%ncid, self%time_dimname, NF90_UNLIMITED, self%time_dimid), "netcdf_initialize_output nf90_def_dim time_dimid" ) ! 'y' dimension + select case (param%out_type) + case("NETCDF_FLOAT") + nciu%out_type = NF90_FLOAT + case("NETCDF_DOUBLE") + nciu%out_type = NF90_DOUBLE + end select - select case (param%out_type) - case("NETCDF_FLOAT") - self%out_type = NF90_FLOAT - case("NETCDF_DOUBLE") - self%out_type = NF90_DOUBLE - end select + ! Check if the file exists, and if it does, delete it + inquire(file=param%outfile, exist=fileExists) + if (fileExists) then + open(unit=LUN, file=param%outfile, status="old", err=667, iomsg=errmsg) + close(unit=LUN, status="delete") + end if - !! Define the variables - call check( nf90_def_var(self%ncid, self%time_dimname, self%out_type, self%time_dimid, self%time_varid), "netcdf_initialize_output nf90_def_var time_varid" ) - call check( nf90_def_var(self%ncid, self%id_dimname, NF90_INT, self%id_dimid, self%id_varid), "netcdf_initialize_output nf90_def_var id_varid" ) - call check( nf90_def_var(self%ncid, self%npl_varname, NF90_INT, self%time_dimid, self%npl_varid), "netcdf_initialize_output nf90_def_var npl_varid" ) - call check( nf90_def_var(self%ncid, self%ntp_varname, NF90_INT, self%time_dimid, self%ntp_varid), "netcdf_initialize_output nf90_def_var ntp_varid" ) - if (param%integrator == SYMBA) call check( nf90_def_var(self%ncid, self%nplm_varname, NF90_INT, self%time_dimid, self%nplm_varid), "netcdf_initialize_output nf90_def_var nplm_varid" ) - call check( nf90_def_var(self%ncid, self%name_varname, NF90_CHAR, [self%str_dimid, self%id_dimid], self%name_varid), "netcdf_initialize_output nf90_def_var name_varid" ) - call check( nf90_def_var(self%ncid, self%ptype_varname, NF90_CHAR, [self%str_dimid, self%id_dimid], self%ptype_varid), "netcdf_initialize_output nf90_def_var ptype_varid" ) - call check( nf90_def_var(self%ncid, self%status_varname, NF90_CHAR, [self%str_dimid, self%id_dimid], self%status_varid), "netcdf_initialize_output nf90_def_var status_varid" ) + ! Create the file + call check( nf90_create(param%outfile, NF90_NETCDF4, nciu%id), "netcdf_initialize_output nf90_create" ) + + ! Dimensions + call check( nf90_def_dim(nciu%id, nciu%time_dimname, NF90_UNLIMITED, nciu%time_dimid), "netcdf_initialize_output nf90_def_dim time_dimid" ) ! Simulation time dimension + call check( nf90_def_dim(nciu%id, nciu%id_dimname, NF90_UNLIMITED, nciu%id_dimid), "netcdf_initialize_output nf90_def_dim id_dimid" ) ! dimension to store particle id numbers + call check( nf90_def_dim(nciu%id, nciu%space_dimname, 3, nciu%space_dimid), "netcdf_initialize_output nf90_def_dim space_dimid" ) ! 3D space dimension + call check( nf90_def_dim(nciu%id, nciu%str_dimname, NAMELEN, nciu%str_dimid), "netcdf_initialize_output nf90_def_dim str_dimid" ) ! Dimension for string variables (aka character arrays) + + ! Dimension coordinates + call check( nf90_def_var(nciu%id, nciu%time_dimname, nciu%out_type, nciu%time_dimid, nciu%time_varid), "netcdf_initialize_output nf90_def_var time_varid" ) + call check( nf90_def_var(nciu%id, nciu%id_dimname, NF90_INT, nciu%id_dimid, nciu%id_varid), "netcdf_initialize_output nf90_def_var id_varid" ) + call check( nf90_def_var(nciu%id, nciu%space_dimname, NF90_CHAR, nciu%space_dimid, nciu%space_varid), "netcdf_initialize_output nf90_def_var space_varid" ) + + ! Variables + call check( nf90_def_var(nciu%id, nciu%npl_varname, NF90_INT, nciu%time_dimid, nciu%npl_varid), "netcdf_initialize_output nf90_def_var npl_varid" ) + call check( nf90_def_var(nciu%id, nciu%ntp_varname, NF90_INT, nciu%time_dimid, nciu%ntp_varid), "netcdf_initialize_output nf90_def_var ntp_varid" ) + if (param%integrator == SYMBA) call check( nf90_def_var(nciu%id, nciu%nplm_varname, NF90_INT, nciu%time_dimid, nciu%nplm_varid), "netcdf_initialize_output nf90_def_var nplm_varid" ) + call check( nf90_def_var(nciu%id, nciu%name_varname, NF90_CHAR, [nciu%str_dimid, nciu%id_dimid], nciu%name_varid), "netcdf_initialize_output nf90_def_var name_varid" ) + call check( nf90_def_var(nciu%id, nciu%ptype_varname, NF90_CHAR, [nciu%str_dimid, nciu%id_dimid], nciu%ptype_varid), "netcdf_initialize_output nf90_def_var ptype_varid" ) + call check( nf90_def_var(nciu%id, nciu%status_varname, NF90_CHAR, [nciu%str_dimid, nciu%id_dimid], nciu%status_varid), "netcdf_initialize_output nf90_def_var status_varid" ) + + if ((param%out_form == "XV") .or. (param%out_form == "XVEL")) then + call check( nf90_def_var(nciu%id, nciu%xhx_varname, nciu%out_type, [nciu%id_dimid, nciu%time_dimid], nciu%xhx_varid), "netcdf_initialize_output nf90_def_var xhx_varid" ) + call check( nf90_def_var(nciu%id, nciu%xhy_varname, nciu%out_type, [nciu%id_dimid, nciu%time_dimid], nciu%xhy_varid), "netcdf_initialize_output nf90_def_var xhy_varid" ) + call check( nf90_def_var(nciu%id, nciu%xhz_varname, nciu%out_type, [nciu%id_dimid, nciu%time_dimid], nciu%xhz_varid), "netcdf_initialize_output nf90_def_var xhz_varid" ) + call check( nf90_def_var(nciu%id, nciu%vhx_varname, nciu%out_type, [nciu%id_dimid, nciu%time_dimid], nciu%vhx_varid), "netcdf_initialize_output nf90_def_var vhx_varid" ) + call check( nf90_def_var(nciu%id, nciu%vhy_varname, nciu%out_type, [nciu%id_dimid, nciu%time_dimid], nciu%vhy_varid), "netcdf_initialize_output nf90_def_var vhy_varid" ) + call check( nf90_def_var(nciu%id, nciu%vhz_varname, nciu%out_type, [nciu%id_dimid, nciu%time_dimid], nciu%vhz_varid), "netcdf_initialize_output nf90_def_var vhz_varid" ) + + !! When GR is enabled, we need to save the pseudovelocity vectors in addition to the true heliocentric velocity vectors, otherwise + !! we cannnot expect bit-identical runs from restarted runs with GR enabled due to floating point errors during the conversion. + if (param%lgr) then + call check( nf90_def_var(nciu%id, nciu%gr_pseudo_vhx_varname, nciu%out_type, [nciu%id_dimid, nciu%time_dimid], nciu%gr_pseudo_vhx_varid), "netcdf_initialize_output nf90_def_var gr_psuedo_vhx_varid" ) + call check( nf90_def_var(nciu%id, nciu%gr_pseudo_vhy_varname, nciu%out_type, [nciu%id_dimid, nciu%time_dimid], nciu%gr_pseudo_vhy_varid), "netcdf_initialize_output nf90_def_var gr_psuedo_vhy_varid" ) + call check( nf90_def_var(nciu%id, nciu%gr_pseudo_vhz_varname, nciu%out_type, [nciu%id_dimid, nciu%time_dimid], nciu%gr_pseudo_vhz_varid), "netcdf_initialize_output nf90_def_var gr_psuedo_vhz_varid" ) + nciu%lpseudo_vel_exists = .true. + end if - if ((param%out_form == "XV") .or. (param%out_form == "XVEL")) then - call check( nf90_def_var(self%ncid, self%xhx_varname, self%out_type, [self%id_dimid, self%time_dimid], self%xhx_varid), "netcdf_initialize_output nf90_def_var xhx_varid" ) - call check( nf90_def_var(self%ncid, self%xhy_varname, self%out_type, [self%id_dimid, self%time_dimid], self%xhy_varid), "netcdf_initialize_output nf90_def_var xhy_varid" ) - call check( nf90_def_var(self%ncid, self%xhz_varname, self%out_type, [self%id_dimid, self%time_dimid], self%xhz_varid), "netcdf_initialize_output nf90_def_var xhz_varid" ) - call check( nf90_def_var(self%ncid, self%vhx_varname, self%out_type, [self%id_dimid, self%time_dimid], self%vhx_varid), "netcdf_initialize_output nf90_def_var vhx_varid" ) - call check( nf90_def_var(self%ncid, self%vhy_varname, self%out_type, [self%id_dimid, self%time_dimid], self%vhy_varid), "netcdf_initialize_output nf90_def_var vhy_varid" ) - call check( nf90_def_var(self%ncid, self%vhz_varname, self%out_type, [self%id_dimid, self%time_dimid], self%vhz_varid), "netcdf_initialize_output nf90_def_var vhz_varid" ) - - !! When GR is enabled, we need to save the pseudovelocity vectors in addition to the true heliocentric velocity vectors, otherwise - !! we cannnot expect bit-identical runs from restarted runs with GR enabled due to floating point errors during the conversion. - if (param%lgr) then - call check( nf90_def_var(self%ncid, self%gr_pseudo_vhx_varname, self%out_type, [self%id_dimid, self%time_dimid], self%gr_pseudo_vhx_varid), "netcdf_initialize_output nf90_def_var gr_psuedo_vhx_varid" ) - call check( nf90_def_var(self%ncid, self%gr_pseudo_vhy_varname, self%out_type, [self%id_dimid, self%time_dimid], self%gr_pseudo_vhy_varid), "netcdf_initialize_output nf90_def_var gr_psuedo_vhy_varid" ) - call check( nf90_def_var(self%ncid, self%gr_pseudo_vhz_varname, self%out_type, [self%id_dimid, self%time_dimid], self%gr_pseudo_vhz_varid), "netcdf_initialize_output nf90_def_var gr_psuedo_vhz_varid" ) - self%lpseudo_vel_exists = .true. + end if + + if ((param%out_form == "EL") .or. (param%out_form == "XVEL")) then + call check( nf90_def_var(nciu%id, nciu%a_varname, nciu%out_type, [nciu%id_dimid, nciu%time_dimid], nciu%a_varid), "netcdf_initialize_output nf90_def_var a_varid" ) + call check( nf90_def_var(nciu%id, nciu%e_varname, nciu%out_type, [nciu%id_dimid, nciu%time_dimid], nciu%e_varid), "netcdf_initialize_output nf90_def_var e_varid" ) + call check( nf90_def_var(nciu%id, nciu%inc_varname, nciu%out_type, [nciu%id_dimid, nciu%time_dimid], nciu%inc_varid), "netcdf_initialize_output nf90_def_var inc_varid" ) + call check( nf90_def_var(nciu%id, nciu%capom_varname, nciu%out_type, [nciu%id_dimid, nciu%time_dimid], nciu%capom_varid), "netcdf_initialize_output nf90_def_var capom_varid" ) + call check( nf90_def_var(nciu%id, nciu%omega_varname, nciu%out_type, [nciu%id_dimid, nciu%time_dimid], nciu%omega_varid), "netcdf_initialize_output nf90_def_var omega_varid" ) + call check( nf90_def_var(nciu%id, nciu%capm_varname, nciu%out_type, [nciu%id_dimid, nciu%time_dimid], nciu%capm_varid), "netcdf_initialize_output nf90_def_var capm_varid" ) end if - end if - - if ((param%out_form == "EL") .or. (param%out_form == "XVEL")) then - call check( nf90_def_var(self%ncid, self%a_varname, self%out_type, [self%id_dimid, self%time_dimid], self%a_varid), "netcdf_initialize_output nf90_def_var a_varid" ) - call check( nf90_def_var(self%ncid, self%e_varname, self%out_type, [self%id_dimid, self%time_dimid], self%e_varid), "netcdf_initialize_output nf90_def_var e_varid" ) - call check( nf90_def_var(self%ncid, self%inc_varname, self%out_type, [self%id_dimid, self%time_dimid], self%inc_varid), "netcdf_initialize_output nf90_def_var inc_varid" ) - call check( nf90_def_var(self%ncid, self%capom_varname, self%out_type, [self%id_dimid, self%time_dimid], self%capom_varid), "netcdf_initialize_output nf90_def_var capom_varid" ) - call check( nf90_def_var(self%ncid, self%omega_varname, self%out_type, [self%id_dimid, self%time_dimid], self%omega_varid), "netcdf_initialize_output nf90_def_var omega_varid" ) - call check( nf90_def_var(self%ncid, self%capm_varname, self%out_type, [self%id_dimid, self%time_dimid], self%capm_varid), "netcdf_initialize_output nf90_def_var capm_varid" ) - end if + call check( nf90_def_var(nciu%id, nciu%gmass_varname, nciu%out_type, [nciu%id_dimid, nciu%time_dimid], nciu%Gmass_varid), "netcdf_initialize_output nf90_def_var Gmass_varid" ) - call check( nf90_def_var(self%ncid, self%gmass_varname, self%out_type, [self%id_dimid, self%time_dimid], self%Gmass_varid), "netcdf_initialize_output nf90_def_var Gmass_varid" ) + if (param%lrhill_present) then + call check( nf90_def_var(nciu%id, nciu%rhill_varname, nciu%out_type, [nciu%id_dimid, nciu%time_dimid], nciu%rhill_varid), "netcdf_initialize_output nf90_def_var rhill_varid" ) + end if - if (param%lrhill_present) then - call check( nf90_def_var(self%ncid, self%rhill_varname, self%out_type, [self%id_dimid, self%time_dimid], self%rhill_varid), "netcdf_initialize_output nf90_def_var rhill_varid" ) - end if + if (param%lclose) then + call check( nf90_def_var(nciu%id, nciu%radius_varname, nciu%out_type, [nciu%id_dimid, nciu%time_dimid], nciu%radius_varid), "netcdf_initialize_output nf90_def_var radius_varid" ) + + call check( nf90_def_var(nciu%id, nciu%origin_time_varname, nciu%out_type, nciu%id_dimid, nciu%origin_time_varid), "netcdf_initialize_output nf90_def_var origin_time_varid" ) + call check( nf90_def_var(nciu%id, nciu%origin_type_varname, NF90_CHAR, [nciu%str_dimid, nciu%id_dimid], & + nciu%origin_type_varid), "netcdf_initialize_output nf90_create" ) + call check( nf90_def_var(nciu%id, nciu%origin_xhx_varname, nciu%out_type, nciu%id_dimid, nciu%origin_xhx_varid), "netcdf_initialize_output nf90_def_var origin_xhx_varid" ) + call check( nf90_def_var(nciu%id, nciu%origin_xhy_varname, nciu%out_type, nciu%id_dimid, nciu%origin_xhy_varid), "netcdf_initialize_output nf90_def_var origin_xhy_varid" ) + call check( nf90_def_var(nciu%id, nciu%origin_xhz_varname, nciu%out_type, nciu%id_dimid, nciu%origin_xhz_varid), "netcdf_initialize_output nf90_def_var origin_xhz_varid" ) + call check( nf90_def_var(nciu%id, nciu%origin_vhx_varname, nciu%out_type, nciu%id_dimid, nciu%origin_vhx_varid), "netcdf_initialize_output nf90_def_var origin_vhx_varid" ) + call check( nf90_def_var(nciu%id, nciu%origin_vhy_varname, nciu%out_type, nciu%id_dimid, nciu%origin_vhy_varid), "netcdf_initialize_output nf90_def_var origin_vhy_varid" ) + call check( nf90_def_var(nciu%id, nciu%origin_vhz_varname, nciu%out_type, nciu%id_dimid, nciu%origin_vhz_varid), "netcdf_initialize_output nf90_def_var origin_vhz_varid" ) + + call check( nf90_def_var(nciu%id, nciu%collision_id_varname, NF90_INT, nciu%id_dimid, nciu%collision_id_varid), "netcdf_initialize_output nf90_def_var collision_id_varid" ) + call check( nf90_def_var(nciu%id, nciu%discard_time_varname, nciu%out_type, nciu%id_dimid, nciu%discard_time_varid), "netcdf_initialize_output nf90_def_var discard_time_varid" ) + call check( nf90_def_var(nciu%id, nciu%discard_xhx_varname, nciu%out_type, nciu%id_dimid, nciu%discard_xhx_varid), "netcdf_initialize_output nf90_def_var discard_xhx_varid" ) + call check( nf90_def_var(nciu%id, nciu%discard_xhy_varname, nciu%out_type, nciu%id_dimid, nciu%discard_xhy_varid), "netcdf_initialize_output nf90_def_var discard_xhy_varid" ) + call check( nf90_def_var(nciu%id, nciu%discard_xhz_varname, nciu%out_type, nciu%id_dimid, nciu%discard_xhz_varid), "netcdf_initialize_output nf90_def_var discard_xhz_varid" ) + call check( nf90_def_var(nciu%id, nciu%discard_vhx_varname, nciu%out_type, nciu%id_dimid, nciu%discard_vhx_varid), "netcdf_initialize_output nf90_def_var discard_vhx_varid" ) + call check( nf90_def_var(nciu%id, nciu%discard_vhy_varname, nciu%out_type, nciu%id_dimid, nciu%discard_vhy_varid), "netcdf_initialize_output nf90_def_var discard_vhy_varid" ) + call check( nf90_def_var(nciu%id, nciu%discard_vhz_varname, nciu%out_type, nciu%id_dimid, nciu%discard_vhz_varid), "netcdf_initialize_output nf90_def_var discard_vhz_varid" ) + call check( nf90_def_var(nciu%id, nciu%discard_body_id_varname, NF90_INT, nciu%id_dimid, nciu%discard_body_id_varid), "netcdf_initialize_output nf90_def_var discard_body_id_varid" ) + end if - if (param%lclose) then - call check( nf90_def_var(self%ncid, self%radius_varname, self%out_type, [self%id_dimid, self%time_dimid], self%radius_varid), "netcdf_initialize_output nf90_def_var radius_varid" ) - - call check( nf90_def_var(self%ncid, self%origin_time_varname, self%out_type, self%id_dimid, self%origin_time_varid), "netcdf_initialize_output nf90_def_var origin_time_varid" ) - call check( nf90_def_var(self%ncid, self%origin_type_varname, NF90_CHAR, [self%str_dimid, self%id_dimid], & - self%origin_type_varid), "netcdf_initialize_output nf90_create" ) - call check( nf90_def_var(self%ncid, self%origin_xhx_varname, self%out_type, self%id_dimid, self%origin_xhx_varid), "netcdf_initialize_output nf90_def_var origin_xhx_varid" ) - call check( nf90_def_var(self%ncid, self%origin_xhy_varname, self%out_type, self%id_dimid, self%origin_xhy_varid), "netcdf_initialize_output nf90_def_var origin_xhy_varid" ) - call check( nf90_def_var(self%ncid, self%origin_xhz_varname, self%out_type, self%id_dimid, self%origin_xhz_varid), "netcdf_initialize_output nf90_def_var origin_xhz_varid" ) - call check( nf90_def_var(self%ncid, self%origin_vhx_varname, self%out_type, self%id_dimid, self%origin_vhx_varid), "netcdf_initialize_output nf90_def_var origin_vhx_varid" ) - call check( nf90_def_var(self%ncid, self%origin_vhy_varname, self%out_type, self%id_dimid, self%origin_vhy_varid), "netcdf_initialize_output nf90_def_var origin_vhy_varid" ) - call check( nf90_def_var(self%ncid, self%origin_vhz_varname, self%out_type, self%id_dimid, self%origin_vhz_varid), "netcdf_initialize_output nf90_def_var origin_vhz_varid" ) - - call check( nf90_def_var(self%ncid, self%collision_id_varname, NF90_INT, self%id_dimid, self%collision_id_varid), "netcdf_initialize_output nf90_def_var collision_id_varid" ) - call check( nf90_def_var(self%ncid, self%discard_time_varname, self%out_type, self%id_dimid, self%discard_time_varid), "netcdf_initialize_output nf90_def_var discard_time_varid" ) - call check( nf90_def_var(self%ncid, self%discard_xhx_varname, self%out_type, self%id_dimid, self%discard_xhx_varid), "netcdf_initialize_output nf90_def_var discard_xhx_varid" ) - call check( nf90_def_var(self%ncid, self%discard_xhy_varname, self%out_type, self%id_dimid, self%discard_xhy_varid), "netcdf_initialize_output nf90_def_var discard_xhy_varid" ) - call check( nf90_def_var(self%ncid, self%discard_xhz_varname, self%out_type, self%id_dimid, self%discard_xhz_varid), "netcdf_initialize_output nf90_def_var discard_xhz_varid" ) - call check( nf90_def_var(self%ncid, self%discard_vhx_varname, self%out_type, self%id_dimid, self%discard_vhx_varid), "netcdf_initialize_output nf90_def_var discard_vhx_varid" ) - call check( nf90_def_var(self%ncid, self%discard_vhy_varname, self%out_type, self%id_dimid, self%discard_vhy_varid), "netcdf_initialize_output nf90_def_var discard_vhy_varid" ) - call check( nf90_def_var(self%ncid, self%discard_vhz_varname, self%out_type, self%id_dimid, self%discard_vhz_varid), "netcdf_initialize_output nf90_def_var discard_vhz_varid" ) - call check( nf90_def_var(self%ncid, self%discard_body_id_varname, NF90_INT, self%id_dimid, self%discard_body_id_varid), "netcdf_initialize_output nf90_def_var discard_body_id_varid" ) - end if + if (param%lrotation) then + call check( nf90_def_var(nciu%id, nciu%ip1_varname, nciu%out_type, [nciu%id_dimid, nciu%time_dimid], nciu%Ip1_varid), "netcdf_initialize_output nf90_def_var Ip1_varid" ) + call check( nf90_def_var(nciu%id, nciu%ip2_varname, nciu%out_type, [nciu%id_dimid, nciu%time_dimid], nciu%Ip2_varid), "netcdf_initialize_output nf90_def_var Ip2_varid" ) + call check( nf90_def_var(nciu%id, nciu%ip3_varname, nciu%out_type, [nciu%id_dimid, nciu%time_dimid], nciu%Ip3_varid), "netcdf_initialize_output nf90_def_var Ip3_varid" ) + call check( nf90_def_var(nciu%id, nciu%rotx_varname, nciu%out_type, [nciu%id_dimid, nciu%time_dimid], nciu%rotx_varid), "netcdf_initialize_output nf90_def_var rotx_varid" ) + call check( nf90_def_var(nciu%id, nciu%roty_varname, nciu%out_type, [nciu%id_dimid, nciu%time_dimid], nciu%roty_varid), "netcdf_initialize_output nf90_def_var roty_varid" ) + call check( nf90_def_var(nciu%id, nciu%rotz_varname, nciu%out_type, [nciu%id_dimid, nciu%time_dimid], nciu%rotz_varid), "netcdf_initialize_output nf90_def_var rotz_varid" ) + end if - if (param%lrotation) then - call check( nf90_def_var(self%ncid, self%ip1_varname, self%out_type, [self%id_dimid, self%time_dimid], self%Ip1_varid), "netcdf_initialize_output nf90_def_var Ip1_varid" ) - call check( nf90_def_var(self%ncid, self%ip2_varname, self%out_type, [self%id_dimid, self%time_dimid], self%Ip2_varid), "netcdf_initialize_output nf90_def_var Ip2_varid" ) - call check( nf90_def_var(self%ncid, self%ip3_varname, self%out_type, [self%id_dimid, self%time_dimid], self%Ip3_varid), "netcdf_initialize_output nf90_def_var Ip3_varid" ) - call check( nf90_def_var(self%ncid, self%rotx_varname, self%out_type, [self%id_dimid, self%time_dimid], self%rotx_varid), "netcdf_initialize_output nf90_def_var rotx_varid" ) - call check( nf90_def_var(self%ncid, self%roty_varname, self%out_type, [self%id_dimid, self%time_dimid], self%roty_varid), "netcdf_initialize_output nf90_def_var roty_varid" ) - call check( nf90_def_var(self%ncid, self%rotz_varname, self%out_type, [self%id_dimid, self%time_dimid], self%rotz_varid), "netcdf_initialize_output nf90_def_var rotz_varid" ) - end if + ! if (param%ltides) then + ! call check( nf90_def_var(nciu%id, nciu%k2_varname, nciu%out_type, [nciu%id_dimid, nciu%time_dimid], nciu%k2_varid), "netcdf_initialize_output nf90_def_var k2_varid" ) + ! call check( nf90_def_var(nciu%id, nciu%q_varname, nciu%out_type, [nciu%id_dimid, nciu%time_dimid], nciu%Q_varid), "netcdf_initialize_output nf90_def_var Q_varid" ) + ! end if - ! if (param%ltides) then - ! call check( nf90_def_var(self%ncid, self%k2_varname, self%out_type, [self%id_dimid, self%time_dimid], self%k2_varid), "netcdf_initialize_output nf90_def_var k2_varid" ) - ! call check( nf90_def_var(self%ncid, self%q_varname, self%out_type, [self%id_dimid, self%time_dimid], self%Q_varid), "netcdf_initialize_output nf90_def_var Q_varid" ) - ! end if + if (param%lenergy) then + call check( nf90_def_var(nciu%id, nciu%ke_orb_varname, nciu%out_type, nciu%time_dimid, nciu%KE_orb_varid), "netcdf_initialize_output nf90_def_var KE_orb_varid" ) + call check( nf90_def_var(nciu%id, nciu%ke_spin_varname, nciu%out_type, nciu%time_dimid, nciu%KE_spin_varid), "netcdf_initialize_output nf90_def_var KE_spin_varid" ) + call check( nf90_def_var(nciu%id, nciu%pe_varname, nciu%out_type, nciu%time_dimid, nciu%PE_varid), "netcdf_initialize_output nf90_def_var PE_varid" ) + call check( nf90_def_var(nciu%id, nciu%l_orbx_varname, nciu%out_type, nciu%time_dimid, nciu%L_orbx_varid), "netcdf_initialize_output nf90_def_var L_orbx_varid" ) + call check( nf90_def_var(nciu%id, nciu%l_orby_varname, nciu%out_type, nciu%time_dimid, nciu%L_orby_varid), "netcdf_initialize_output nf90_def_var L_orby_varid" ) + call check( nf90_def_var(nciu%id, nciu%l_orbz_varname, nciu%out_type, nciu%time_dimid, nciu%L_orbz_varid), "netcdf_initialize_output nf90_def_var L_orbz_varid" ) + call check( nf90_def_var(nciu%id, nciu%l_spinx_varname, nciu%out_type, nciu%time_dimid, nciu%L_spinx_varid), "netcdf_initialize_output nf90_def_var L_spinx_varid" ) + call check( nf90_def_var(nciu%id, nciu%l_spiny_varname, nciu%out_type, nciu%time_dimid, nciu%L_spiny_varid), "netcdf_initialize_output nf90_def_var L_spiny_varid" ) + call check( nf90_def_var(nciu%id, nciu%l_spinz_varname, nciu%out_type, nciu%time_dimid, nciu%L_spinz_varid), "netcdf_initialize_output nf90_def_var L_spinz_varid" ) + call check( nf90_def_var(nciu%id, nciu%l_escapex_varname, nciu%out_type, nciu%time_dimid, nciu%L_escapex_varid), "netcdf_initialize_output nf90_def_var L_escapex_varid" ) + call check( nf90_def_var(nciu%id, nciu%l_escapey_varname, nciu%out_type, nciu%time_dimid, nciu%L_escapey_varid), "netcdf_initialize_output nf90_def_var L_escapey_varid" ) + call check( nf90_def_var(nciu%id, nciu%l_escapez_varname, nciu%out_type, nciu%time_dimid, nciu%L_escapez_varid), "netcdf_initialize_output nf90_def_var L_escapez_varid" ) + call check( nf90_def_var(nciu%id, nciu%ecollisions_varname, nciu%out_type, nciu%time_dimid, nciu%Ecollisions_varid), "netcdf_initialize_output nf90_def_var Ecollisions_varid" ) + call check( nf90_def_var(nciu%id, nciu%euntracked_varname, nciu%out_type, nciu%time_dimid, nciu%Euntracked_varid), "netcdf_initialize_output nf90_def_var Euntracked_varid" ) + call check( nf90_def_var(nciu%id, nciu%gmescape_varname, nciu%out_type, nciu%time_dimid, nciu%GMescape_varid), "netcdf_initialize_output nf90_def_var GMescape_varid" ) + end if - if (param%lenergy) then - call check( nf90_def_var(self%ncid, self%ke_orb_varname, self%out_type, self%time_dimid, self%KE_orb_varid), "netcdf_initialize_output nf90_def_var KE_orb_varid" ) - call check( nf90_def_var(self%ncid, self%ke_spin_varname, self%out_type, self%time_dimid, self%KE_spin_varid), "netcdf_initialize_output nf90_def_var KE_spin_varid" ) - call check( nf90_def_var(self%ncid, self%pe_varname, self%out_type, self%time_dimid, self%PE_varid), "netcdf_initialize_output nf90_def_var PE_varid" ) - call check( nf90_def_var(self%ncid, self%l_orbx_varname, self%out_type, self%time_dimid, self%L_orbx_varid), "netcdf_initialize_output nf90_def_var L_orbx_varid" ) - call check( nf90_def_var(self%ncid, self%l_orby_varname, self%out_type, self%time_dimid, self%L_orby_varid), "netcdf_initialize_output nf90_def_var L_orby_varid" ) - call check( nf90_def_var(self%ncid, self%l_orbz_varname, self%out_type, self%time_dimid, self%L_orbz_varid), "netcdf_initialize_output nf90_def_var L_orbz_varid" ) - call check( nf90_def_var(self%ncid, self%l_spinx_varname, self%out_type, self%time_dimid, self%L_spinx_varid), "netcdf_initialize_output nf90_def_var L_spinx_varid" ) - call check( nf90_def_var(self%ncid, self%l_spiny_varname, self%out_type, self%time_dimid, self%L_spiny_varid), "netcdf_initialize_output nf90_def_var L_spiny_varid" ) - call check( nf90_def_var(self%ncid, self%l_spinz_varname, self%out_type, self%time_dimid, self%L_spinz_varid), "netcdf_initialize_output nf90_def_var L_spinz_varid" ) - call check( nf90_def_var(self%ncid, self%l_escapex_varname, self%out_type, self%time_dimid, self%L_escapex_varid), "netcdf_initialize_output nf90_def_var L_escapex_varid" ) - call check( nf90_def_var(self%ncid, self%l_escapey_varname, self%out_type, self%time_dimid, self%L_escapey_varid), "netcdf_initialize_output nf90_def_var L_escapey_varid" ) - call check( nf90_def_var(self%ncid, self%l_escapez_varname, self%out_type, self%time_dimid, self%L_escapez_varid), "netcdf_initialize_output nf90_def_var L_escapez_varid" ) - call check( nf90_def_var(self%ncid, self%ecollisions_varname, self%out_type, self%time_dimid, self%Ecollisions_varid), "netcdf_initialize_output nf90_def_var Ecollisions_varid" ) - call check( nf90_def_var(self%ncid, self%euntracked_varname, self%out_type, self%time_dimid, self%Euntracked_varid), "netcdf_initialize_output nf90_def_var Euntracked_varid" ) - call check( nf90_def_var(self%ncid, self%gmescape_varname, self%out_type, self%time_dimid, self%GMescape_varid), "netcdf_initialize_output nf90_def_var GMescape_varid" ) - end if + call check( nf90_def_var(nciu%id, nciu%j2rp2_varname, nciu%out_type, nciu%time_dimid, nciu%j2rp2_varid), "netcdf_initialize_output nf90_def_var j2rp2_varid" ) + call check( nf90_def_var(nciu%id, nciu%j4rp4_varname, nciu%out_type, nciu%time_dimid, nciu%j4rp4_varid), "netcdf_initialize_output nf90_def_var j4rp4_varid" ) + + + ! Set fill mode to NaN for all variables + call check( nf90_inquire(nciu%id, nVariables=nvar), "netcdf_initialize_output nf90_inquire nVariables" ) + do varid = 1, nvar + call check( nf90_inquire_variable(nciu%id, varid, xtype=vartype, ndims=ndims), "netcdf_initialize_output nf90_inquire_variable" ) + select case(vartype) + case(NF90_INT) + call check( nf90_def_var_fill(nciu%id, varid, 0, NF90_FILL_INT), "netcdf_initialize_output nf90_def_var_fill NF90_INT" ) + case(NF90_FLOAT) + call check( nf90_def_var_fill(nciu%id, varid, 0, sfill), "netcdf_initialize_output nf90_def_var_fill NF90_FLOAT" ) + case(NF90_DOUBLE) + call check( nf90_def_var_fill(nciu%id, varid, 0, dfill), "netcdf_initialize_output nf90_def_var_fill NF90_DOUBLE" ) + case(NF90_CHAR) + call check( nf90_def_var_fill(nciu%id, varid, 0, 0), "netcdf_initialize_output nf90_def_var_fill NF90_CHAR" ) + end select + end do - call check( nf90_def_var(self%ncid, self%j2rp2_varname, self%out_type, self%time_dimid, self%j2rp2_varid), "netcdf_initialize_output nf90_def_var j2rp2_varid" ) - call check( nf90_def_var(self%ncid, self%j4rp4_varname, self%out_type, self%time_dimid, self%j4rp4_varid), "netcdf_initialize_output nf90_def_var j4rp4_varid" ) - - - ! Set fill mode to NaN for all variables - call check( nf90_inquire(self%ncid, nVariables=nvar), "netcdf_initialize_output nf90_inquire nVariables" ) - do varid = 1, nvar - call check( nf90_inquire_variable(self%ncid, varid, xtype=vartype, ndims=ndims), "netcdf_initialize_output nf90_inquire_variable" ) - select case(vartype) - case(NF90_INT) - call check( nf90_def_var_fill(self%ncid, varid, 0, NF90_FILL_INT), "netcdf_initialize_output nf90_def_var_fill NF90_INT" ) - case(NF90_FLOAT) - call check( nf90_def_var_fill(self%ncid, varid, 0, sfill), "netcdf_initialize_output nf90_def_var_fill NF90_FLOAT" ) - case(NF90_DOUBLE) - call check( nf90_def_var_fill(self%ncid, varid, 0, dfill), "netcdf_initialize_output nf90_def_var_fill NF90_DOUBLE" ) - case(NF90_CHAR) - call check( nf90_def_var_fill(self%ncid, varid, 0, 0), "netcdf_initialize_output nf90_def_var_fill NF90_CHAR" ) - end select - end do + ! Take the file out of define mode + call check( nf90_enddef(nciu%id), "netcdf_initialize_output nf90_enddef" ) - ! Take the file out of define mode - call check( nf90_enddef(self%ncid), "netcdf_initialize_output nf90_enddef" ) + call check( nf90_put_var(nciu%id, nciu%space_varid, ["x","y","z"], start=[1], count=[3]), "netcdf_initialize_output nf90_put_var space" ) + end associate return 667 continue @@ -350,7 +360,6 @@ module subroutine netcdf_open(self, param, readonly) logical, optional, intent(in) :: readonly !! Logical flag indicating that this should be open read only ! Internals integer(I4B) :: mode, status - character(len=NF90_MAX_NAME) :: str_dim_name character(len=STRMAX) :: errmsg mode = NF90_WRITE @@ -359,45 +368,41 @@ module subroutine netcdf_open(self, param, readonly) end if write(errmsg,*) "netcdf_open nf90_open ",trim(adjustl(param%outfile)) - call check( nf90_open(param%outfile, mode, self%ncid), errmsg) - - call check( nf90_inq_dimid(self%ncid, self%time_dimname, self%time_dimid), "netcdf_open nf90_inq_dimid time_dimid" ) - call check( nf90_inq_dimid(self%ncid, self%id_dimname, self%id_dimid), "netcdf_open nf90_inq_dimid id_dimid" ) - if (max(self%time_dimid,self%id_dimid) == 2) then - self%str_dimid = 3 - else if (min(self%time_dimid,self%id_dimid) == 0) then - self%str_dimid = 1 - else - self%str_dimid = 2 - end if - call check( nf90_inquire_dimension(self%ncid, self%str_dimid, name=str_dim_name), "netcdf_open nf90_inquire_dimension str_dim_name" ) - call check( nf90_inq_dimid(self%ncid, str_dim_name, self%str_dimid), "netcdf_open nf90_inq_dimid str_dimid" ) + call check( nf90_open(param%outfile, mode, self%id), errmsg) - ! Required Variables + ! Dimensions + call check( nf90_inq_dimid(self%id, self%time_dimname, self%time_dimid), "netcdf_open nf90_inq_dimid time_dimid" ) + call check( nf90_inq_dimid(self%id, self%id_dimname, self%id_dimid), "netcdf_open nf90_inq_dimid id_dimid" ) + call check( nf90_inq_dimid(self%id, self%space_dimname, self%space_dimid), "netcdf_open nf90_inq_dimid space_dimid" ) + call check( nf90_inq_dimid(self%id, self%str_dimname, self%str_dimid), "netcdf_open nf90_inq_dimid str_dimid" ) - call check( nf90_inq_varid(self%ncid, self%time_dimname, self%time_varid), "netcdf_open nf90_inq_varid time_varid" ) - call check( nf90_inq_varid(self%ncid, self%id_dimname, self%id_varid), "netcdf_open nf90_inq_varid id_varid" ) - call check( nf90_inq_varid(self%ncid, self%name_varname, self%name_varid), "netcdf_open nf90_inq_varid name_varid" ) - call check( nf90_inq_varid(self%ncid, self%ptype_varname, self%ptype_varid), "netcdf_open nf90_inq_varid ptype_varid" ) - call check( nf90_inq_varid(self%ncid, self%gmass_varname, self%Gmass_varid), "netcdf_open nf90_inq_varid Gmass_varid" ) + ! Dimension coordinates + call check( nf90_inq_varid(self%id, self%time_dimname, self%time_varid), "netcdf_open nf90_inq_varid time_varid" ) + call check( nf90_inq_varid(self%id, self%id_dimname, self%id_varid), "netcdf_open nf90_inq_varid id_varid" ) + call check( nf90_inq_varid(self%id, self%space_dimname, self%space_varid), "netcdf_open nf90_inq_varid space_varid" ) + + ! Required Variables + call check( nf90_inq_varid(self%id, self%name_varname, self%name_varid), "netcdf_open nf90_inq_varid name_varid" ) + call check( nf90_inq_varid(self%id, self%ptype_varname, self%ptype_varid), "netcdf_open nf90_inq_varid ptype_varid" ) + call check( nf90_inq_varid(self%id, self%gmass_varname, self%Gmass_varid), "netcdf_open nf90_inq_varid Gmass_varid" ) if ((param%out_form == "XV") .or. (param%out_form == "XVEL")) then - call check( nf90_inq_varid(self%ncid, self%xhx_varname, self%xhx_varid), "netcdf_open nf90_inq_varid xhx_varid" ) - call check( nf90_inq_varid(self%ncid, self%xhy_varname, self%xhy_varid), "netcdf_open nf90_inq_varid xhy_varid" ) - call check( nf90_inq_varid(self%ncid, self%xhz_varname, self%xhz_varid), "netcdf_open nf90_inq_varid xhz_varid" ) - call check( nf90_inq_varid(self%ncid, self%vhx_varname, self%vhx_varid), "netcdf_open nf90_inq_varid vhx_varid" ) - call check( nf90_inq_varid(self%ncid, self%vhy_varname, self%vhy_varid), "netcdf_open nf90_inq_varid vhy_varid" ) - call check( nf90_inq_varid(self%ncid, self%vhz_varname, self%vhz_varid), "netcdf_open nf90_inq_varid vhz_varid" ) + call check( nf90_inq_varid(self%id, self%xhx_varname, self%xhx_varid), "netcdf_open nf90_inq_varid xhx_varid" ) + call check( nf90_inq_varid(self%id, self%xhy_varname, self%xhy_varid), "netcdf_open nf90_inq_varid xhy_varid" ) + call check( nf90_inq_varid(self%id, self%xhz_varname, self%xhz_varid), "netcdf_open nf90_inq_varid xhz_varid" ) + call check( nf90_inq_varid(self%id, self%vhx_varname, self%vhx_varid), "netcdf_open nf90_inq_varid vhx_varid" ) + call check( nf90_inq_varid(self%id, self%vhy_varname, self%vhy_varid), "netcdf_open nf90_inq_varid vhy_varid" ) + call check( nf90_inq_varid(self%id, self%vhz_varname, self%vhz_varid), "netcdf_open nf90_inq_varid vhz_varid" ) if (param%lgr) then !! check if pseudovelocity vectors exist in this file. If they are, set the correct flag so we know whe should not do the conversion. - status = nf90_inq_varid(self%ncid, self%gr_pseudo_vhx_varname, self%gr_pseudo_vhx_varid) + status = nf90_inq_varid(self%id, self%gr_pseudo_vhx_varname, self%gr_pseudo_vhx_varid) self%lpseudo_vel_exists = (status == nf90_noerr) if (self%lpseudo_vel_exists) then - status = nf90_inq_varid(self%ncid, self%gr_pseudo_vhy_varname, self%gr_pseudo_vhy_varid) + status = nf90_inq_varid(self%id, self%gr_pseudo_vhy_varname, self%gr_pseudo_vhy_varid) self%lpseudo_vel_exists = (status == nf90_noerr) if (self%lpseudo_vel_exists) then - status = nf90_inq_varid(self%ncid, self%gr_pseudo_vhz_varname, self%gr_pseudo_vhz_varid) + status = nf90_inq_varid(self%id, self%gr_pseudo_vhz_varname, self%gr_pseudo_vhz_varid) self%lpseudo_vel_exists = (status == nf90_noerr) end if end if @@ -409,99 +414,99 @@ module subroutine netcdf_open(self, param, readonly) end if if ((param%out_form == "EL") .or. (param%out_form == "XVEL")) then - call check( nf90_inq_varid(self%ncid, self%a_varname, self%a_varid), "netcdf_open nf90_inq_varid a_varid" ) - call check( nf90_inq_varid(self%ncid, self%e_varname, self%e_varid), "netcdf_open nf90_inq_varid e_varid" ) - call check( nf90_inq_varid(self%ncid, self%inc_varname, self%inc_varid), "netcdf_open nf90_inq_varid inc_varid" ) - call check( nf90_inq_varid(self%ncid, self%capom_varname, self%capom_varid), "netcdf_open nf90_inq_varid capom_varid" ) - call check( nf90_inq_varid(self%ncid, self%omega_varname, self%omega_varid), "netcdf_open nf90_inq_varid omega_varid" ) - call check( nf90_inq_varid(self%ncid, self%capm_varname, self%capm_varid), "netcdf_open nf90_inq_varid capm_varid" ) + call check( nf90_inq_varid(self%id, self%a_varname, self%a_varid), "netcdf_open nf90_inq_varid a_varid" ) + call check( nf90_inq_varid(self%id, self%e_varname, self%e_varid), "netcdf_open nf90_inq_varid e_varid" ) + call check( nf90_inq_varid(self%id, self%inc_varname, self%inc_varid), "netcdf_open nf90_inq_varid inc_varid" ) + call check( nf90_inq_varid(self%id, self%capom_varname, self%capom_varid), "netcdf_open nf90_inq_varid capom_varid" ) + call check( nf90_inq_varid(self%id, self%omega_varname, self%omega_varid), "netcdf_open nf90_inq_varid omega_varid" ) + call check( nf90_inq_varid(self%id, self%capm_varname, self%capm_varid), "netcdf_open nf90_inq_varid capm_varid" ) end if if (param%lclose) then - call check( nf90_inq_varid(self%ncid, self%radius_varname, self%radius_varid), "netcdf_open nf90_inq_varid radius_varid" ) + call check( nf90_inq_varid(self%id, self%radius_varname, self%radius_varid), "netcdf_open nf90_inq_varid radius_varid" ) end if if (param%lrotation) then - call check( nf90_inq_varid(self%ncid, self%ip1_varname, self%Ip1_varid), "netcdf_open nf90_inq_varid Ip1_varid" ) - call check( nf90_inq_varid(self%ncid, self%ip2_varname, self%Ip2_varid), "netcdf_open nf90_inq_varid Ip2_varid" ) - call check( nf90_inq_varid(self%ncid, self%ip3_varname, self%Ip3_varid), "netcdf_open nf90_inq_varid Ip3_varid" ) - call check( nf90_inq_varid(self%ncid, self%rotx_varname, self%rotx_varid), "netcdf_open nf90_inq_varid rotx_varid" ) - call check( nf90_inq_varid(self%ncid, self%roty_varname, self%roty_varid), "netcdf_open nf90_inq_varid roty_varid" ) - call check( nf90_inq_varid(self%ncid, self%rotz_varname, self%rotz_varid), "netcdf_open nf90_inq_varid rotz_varid" ) + call check( nf90_inq_varid(self%id, self%ip1_varname, self%Ip1_varid), "netcdf_open nf90_inq_varid Ip1_varid" ) + call check( nf90_inq_varid(self%id, self%ip2_varname, self%Ip2_varid), "netcdf_open nf90_inq_varid Ip2_varid" ) + call check( nf90_inq_varid(self%id, self%ip3_varname, self%Ip3_varid), "netcdf_open nf90_inq_varid Ip3_varid" ) + call check( nf90_inq_varid(self%id, self%rotx_varname, self%rotx_varid), "netcdf_open nf90_inq_varid rotx_varid" ) + call check( nf90_inq_varid(self%id, self%roty_varname, self%roty_varid), "netcdf_open nf90_inq_varid roty_varid" ) + call check( nf90_inq_varid(self%id, self%rotz_varname, self%rotz_varid), "netcdf_open nf90_inq_varid rotz_varid" ) end if ! if (param%ltides) then - ! call check( nf90_inq_varid(self%ncid, self%k2_varname, self%k2_varid), "netcdf_open nf90_inq_varid k2_varid" ) - ! call check( nf90_inq_varid(self%ncid, self%q_varname, self%Q_varid), "netcdf_open nf90_inq_varid Q_varid" ) + ! call check( nf90_inq_varid(self%id, self%k2_varname, self%k2_varid), "netcdf_open nf90_inq_varid k2_varid" ) + ! call check( nf90_inq_varid(self%id, self%q_varname, self%Q_varid), "netcdf_open nf90_inq_varid Q_varid" ) ! end if ! Optional Variables if (param%lrhill_present) then - status = nf90_inq_varid(self%ncid, self%rhill_varname, self%rhill_varid) + status = nf90_inq_varid(self%id, self%rhill_varname, self%rhill_varid) if (status /= nf90_noerr) write(*,*) "Warning! RHILL variable not set in input file. Calculating." end if ! Optional variables The User Doesn't Need to Know About - status = nf90_inq_varid(self%ncid, self%npl_varname, self%npl_varid) - status = nf90_inq_varid(self%ncid, self%ntp_varname, self%ntp_varid) - status = nf90_inq_varid(self%ncid, self%status_varname, self%status_varid) - status = nf90_inq_varid(self%ncid, self%j2rp2_varname, self%j2rp2_varid) - status = nf90_inq_varid(self%ncid, self%j4rp4_varname, self%j4rp4_varid) + status = nf90_inq_varid(self%id, self%npl_varname, self%npl_varid) + status = nf90_inq_varid(self%id, self%ntp_varname, self%ntp_varid) + status = nf90_inq_varid(self%id, self%status_varname, self%status_varid) + status = nf90_inq_varid(self%id, self%j2rp2_varname, self%j2rp2_varid) + status = nf90_inq_varid(self%id, self%j4rp4_varname, self%j4rp4_varid) if (param%integrator == SYMBA) then - status = nf90_inq_varid(self%ncid, self%nplm_varname, self%nplm_varid) + status = nf90_inq_varid(self%id, self%nplm_varname, self%nplm_varid) end if if (param%lclose) then - status = nf90_inq_varid(self%ncid, self%origin_type_varname, self%origin_type_varid) - status = nf90_inq_varid(self%ncid, self%origin_time_varname, self%origin_time_varid) - status = nf90_inq_varid(self%ncid, self%origin_xhx_varname, self%origin_xhx_varid) - status = nf90_inq_varid(self%ncid, self%origin_xhy_varname, self%origin_xhy_varid) - status = nf90_inq_varid(self%ncid, self%origin_xhz_varname, self%origin_xhz_varid) - status = nf90_inq_varid(self%ncid, self%origin_vhx_varname, self%origin_vhx_varid) - status = nf90_inq_varid(self%ncid, self%origin_vhy_varname, self%origin_vhy_varid) - status = nf90_inq_varid(self%ncid, self%origin_vhz_varname, self%origin_vhz_varid) - status = nf90_inq_varid(self%ncid, self%collision_id_varname, self%collision_id_varid) - status = nf90_inq_varid(self%ncid, self%discard_time_varname, self%discard_time_varid) - status = nf90_inq_varid(self%ncid, self%discard_xhx_varname, self%discard_xhx_varid) - status = nf90_inq_varid(self%ncid, self%discard_xhy_varname, self%discard_xhy_varid) - status = nf90_inq_varid(self%ncid, self%discard_xhz_varname, self%discard_xhz_varid) - status = nf90_inq_varid(self%ncid, self%discard_vhx_varname, self%discard_vhx_varid) - status = nf90_inq_varid(self%ncid, self%discard_vhy_varname, self%discard_vhy_varid) - status = nf90_inq_varid(self%ncid, self%discard_vhz_varname, self%discard_vhz_varid) - status = nf90_inq_varid(self%ncid, self%discard_body_id_varname, self%discard_body_id_varid) + status = nf90_inq_varid(self%id, self%origin_type_varname, self%origin_type_varid) + status = nf90_inq_varid(self%id, self%origin_time_varname, self%origin_time_varid) + status = nf90_inq_varid(self%id, self%origin_xhx_varname, self%origin_xhx_varid) + status = nf90_inq_varid(self%id, self%origin_xhy_varname, self%origin_xhy_varid) + status = nf90_inq_varid(self%id, self%origin_xhz_varname, self%origin_xhz_varid) + status = nf90_inq_varid(self%id, self%origin_vhx_varname, self%origin_vhx_varid) + status = nf90_inq_varid(self%id, self%origin_vhy_varname, self%origin_vhy_varid) + status = nf90_inq_varid(self%id, self%origin_vhz_varname, self%origin_vhz_varid) + status = nf90_inq_varid(self%id, self%collision_id_varname, self%collision_id_varid) + status = nf90_inq_varid(self%id, self%discard_time_varname, self%discard_time_varid) + status = nf90_inq_varid(self%id, self%discard_xhx_varname, self%discard_xhx_varid) + status = nf90_inq_varid(self%id, self%discard_xhy_varname, self%discard_xhy_varid) + status = nf90_inq_varid(self%id, self%discard_xhz_varname, self%discard_xhz_varid) + status = nf90_inq_varid(self%id, self%discard_vhx_varname, self%discard_vhx_varid) + status = nf90_inq_varid(self%id, self%discard_vhy_varname, self%discard_vhy_varid) + status = nf90_inq_varid(self%id, self%discard_vhz_varname, self%discard_vhz_varid) + status = nf90_inq_varid(self%id, self%discard_body_id_varname, self%discard_body_id_varid) end if if (param%lenergy) then - status = nf90_inq_varid(self%ncid, self%ke_orb_varname, self%KE_orb_varid) - status = nf90_inq_varid(self%ncid, self%ke_spin_varname, self%KE_spin_varid) - status = nf90_inq_varid(self%ncid, self%pe_varname, self%PE_varid) - status = nf90_inq_varid(self%ncid, self%l_orbx_varname, self%L_orbx_varid) - status = nf90_inq_varid(self%ncid, self%l_orby_varname, self%L_orby_varid) - status = nf90_inq_varid(self%ncid, self%l_orbz_varname, self%L_orbz_varid) - status = nf90_inq_varid(self%ncid, self%l_spinx_varname, self%L_spinx_varid) - status = nf90_inq_varid(self%ncid, self%l_spiny_varname, self%L_spiny_varid) - status = nf90_inq_varid(self%ncid, self%l_spinz_varname, self%L_spinz_varid) - status = nf90_inq_varid(self%ncid, self%l_escapex_varname, self%L_escapex_varid) - status = nf90_inq_varid(self%ncid, self%l_escapey_varname, self%L_escapey_varid) - status = nf90_inq_varid(self%ncid, self%l_escapez_varname, self%L_escapez_varid) - status = nf90_inq_varid(self%ncid, self%ecollisions_varname, self%Ecollisions_varid) - status = nf90_inq_varid(self%ncid, self%euntracked_varname, self%Euntracked_varid) - status = nf90_inq_varid(self%ncid, self%gmescape_varname, self%GMescape_varid) + status = nf90_inq_varid(self%id, self%ke_orb_varname, self%KE_orb_varid) + status = nf90_inq_varid(self%id, self%ke_spin_varname, self%KE_spin_varid) + status = nf90_inq_varid(self%id, self%pe_varname, self%PE_varid) + status = nf90_inq_varid(self%id, self%l_orbx_varname, self%L_orbx_varid) + status = nf90_inq_varid(self%id, self%l_orby_varname, self%L_orby_varid) + status = nf90_inq_varid(self%id, self%l_orbz_varname, self%L_orbz_varid) + status = nf90_inq_varid(self%id, self%l_spinx_varname, self%L_spinx_varid) + status = nf90_inq_varid(self%id, self%l_spiny_varname, self%L_spiny_varid) + status = nf90_inq_varid(self%id, self%l_spinz_varname, self%L_spinz_varid) + status = nf90_inq_varid(self%id, self%l_escapex_varname, self%L_escapex_varid) + status = nf90_inq_varid(self%id, self%l_escapey_varname, self%L_escapey_varid) + status = nf90_inq_varid(self%id, self%l_escapez_varname, self%L_escapez_varid) + status = nf90_inq_varid(self%id, self%ecollisions_varname, self%Ecollisions_varid) + status = nf90_inq_varid(self%id, self%euntracked_varname, self%Euntracked_varid) + status = nf90_inq_varid(self%id, self%gmescape_varname, self%GMescape_varid) end if return end subroutine netcdf_open - module function netcdf_read_frame_system(self, iu, param) result(ierr) + module function netcdf_read_frame_system(self, nciu, param) result(ierr) !! author: The Purdue Swiftest Team - David A. Minton, Carlisle A. Wishard, Jennifer L.L. Pouplin, and Jacob R. Elliott !! !! Read a frame (header plus records for each massive body and active test particle) from an output binary file implicit none ! Arguments class(swiftest_nbody_system), intent(inout) :: self !! Swiftest system object - class(netcdf_parameters), intent(inout) :: iu !! Parameters used to identify a particular NetCDF dataset + class(netcdf_parameters), intent(inout) :: nciu !! Parameters used to identify a particular NetCDF dataset class(swiftest_parameters), intent(inout) :: param !! Current run configuration parameters ! Return integer(I4B) :: ierr !! Error code: returns 0 if the read is successful @@ -511,8 +516,8 @@ module function netcdf_read_frame_system(self, iu, param) result(ierr) integer(I4B), dimension(:), allocatable :: itemp logical, dimension(:), allocatable :: validmask, tpmask, plmask - call iu%open(param, readonly=.true.) - call self%read_hdr(iu, param) + call nciu%open(param, readonly=.true.) + call self%read_hdr(nciu, param) associate(cb => self%cb, pl => self%pl, tp => self%tp, npl => self%pl%nbody, ntp => self%tp%nbody) @@ -521,26 +526,26 @@ module function netcdf_read_frame_system(self, iu, param) result(ierr) tslot = param%ioutput + 1 - call check( nf90_inquire_dimension(iu%ncid, iu%id_dimid, len=idmax), "netcdf_read_frame_system nf90_inquire_dimension id_dimid" ) + call check( nf90_inquire_dimension(nciu%id, nciu%id_dimid, len=idmax), "netcdf_read_frame_system nf90_inquire_dimension id_dimid" ) allocate(rtemp(idmax)) allocate(itemp(idmax)) allocate(validmask(idmax)) allocate(tpmask(idmax)) allocate(plmask(idmax)) - call check( nf90_inquire_dimension(iu%ncid, iu%time_dimid, len=t_max), "netcdf_read_frame_system nf90_inquire_dimension time_dimid" ) - call check( nf90_inquire_dimension(iu%ncid, iu%str_dimid, len=str_max), "netcdf_read_frame_system nf90_inquire_dimension str_dimid" ) + call check( nf90_inquire_dimension(nciu%id, nciu%time_dimid, len=t_max), "netcdf_read_frame_system nf90_inquire_dimension time_dimid" ) + call check( nf90_inquire_dimension(nciu%id, nciu%str_dimid, len=str_max), "netcdf_read_frame_system nf90_inquire_dimension str_dimid" ) ! First filter out only the id slots that contain valid bodies if (param%in_form == "XV") then - call check( nf90_get_var(iu%ncid, iu%xhx_varid, rtemp(:), start=[1, tslot]), "netcdf_read_frame_system filter pass nf90_getvar xhx_varid" ) + call check( nf90_get_var(nciu%id, nciu%xhx_varid, rtemp(:), start=[1, tslot]), "netcdf_read_frame_system filter pass nf90_getvar xhx_varid" ) else - call check( nf90_get_var(iu%ncid, iu%a_varid, rtemp(:), start=[1, tslot]), "netcdf_read_frame_system filter pass nf90_getvar a_varid" ) + call check( nf90_get_var(nciu%id, nciu%a_varid, rtemp(:), start=[1, tslot]), "netcdf_read_frame_system filter pass nf90_getvar a_varid" ) end if validmask(:) = rtemp(:) == rtemp(:) ! Next, filter only bodies that don't have mass (test particles) - call check( nf90_get_var(iu%ncid, iu%Gmass_varid, rtemp(:), start=[1, tslot]), "netcdf_read_frame_system nf90_getvar Gmass_varid" ) + call check( nf90_get_var(nciu%id, nciu%Gmass_varid, rtemp(:), start=[1, tslot]), "netcdf_read_frame_system nf90_getvar Gmass_varid" ) plmask(:) = rtemp(:) == rtemp(:) .and. validmask(:) tpmask(:) = .not. plmask(:) .and. validmask(:) plmask(1) = .false. ! This is the central body @@ -573,80 +578,80 @@ module function netcdf_read_frame_system(self, iu, param) result(ierr) ! Now read in each variable and split the outputs by body type if ((param%in_form == "XV") .or. (param%in_form == "XVEL")) then - call check( nf90_get_var(iu%ncid, iu%xhx_varid, rtemp, start=[1, tslot]), "netcdf_read_frame_system nf90_getvar xhx_varid" ) + call check( nf90_get_var(nciu%id, nciu%xhx_varid, rtemp, start=[1, tslot]), "netcdf_read_frame_system nf90_getvar xhx_varid" ) if (npl > 0) pl%xh(1,:) = pack(rtemp, plmask) if (ntp > 0) tp%xh(1,:) = pack(rtemp, tpmask) - call check( nf90_get_var(iu%ncid, iu%xhy_varid, rtemp, start=[1, tslot]), "netcdf_read_frame_system nf90_getvar xhy_varid" ) + call check( nf90_get_var(nciu%id, nciu%xhy_varid, rtemp, start=[1, tslot]), "netcdf_read_frame_system nf90_getvar xhy_varid" ) if (npl > 0) pl%xh(2,:) = pack(rtemp, plmask) if (ntp > 0) tp%xh(2,:) = pack(rtemp, tpmask) - call check( nf90_get_var(iu%ncid, iu%xhz_varid, rtemp, start=[1, tslot]), "netcdf_read_frame_system nf90_getvar xhz_varid" ) + call check( nf90_get_var(nciu%id, nciu%xhz_varid, rtemp, start=[1, tslot]), "netcdf_read_frame_system nf90_getvar xhz_varid" ) if (npl > 0) pl%xh(3,:) = pack(rtemp, plmask) if (ntp > 0) tp%xh(3,:) = pack(rtemp, tpmask) - if (param%lgr .and. iu%lpseudo_vel_exists) then - call check( nf90_get_var(iu%ncid, iu%gr_pseudo_vhx_varid, rtemp, start=[1, tslot]), "netcdf_read_frame_system nf90_getvar gr_pseudo_vhx_varid" ) + if (param%lgr .and. nciu%lpseudo_vel_exists) then + call check( nf90_get_var(nciu%id, nciu%gr_pseudo_vhx_varid, rtemp, start=[1, tslot]), "netcdf_read_frame_system nf90_getvar gr_pseudo_vhx_varid" ) if (npl > 0) pl%vh(1,:) = pack(rtemp, plmask) if (ntp > 0) tp%vh(1,:) = pack(rtemp, tpmask) - call check( nf90_get_var(iu%ncid, iu%gr_pseudo_vhy_varid, rtemp, start=[1, tslot]), "netcdf_read_frame_system nf90_getvar gr_pseudo_vhy_varid" ) + call check( nf90_get_var(nciu%id, nciu%gr_pseudo_vhy_varid, rtemp, start=[1, tslot]), "netcdf_read_frame_system nf90_getvar gr_pseudo_vhy_varid" ) if (npl > 0) pl%vh(2,:) = pack(rtemp, plmask) if (ntp > 0) tp%vh(2,:) = pack(rtemp, tpmask) - call check( nf90_get_var(iu%ncid, iu%gr_pseudo_vhz_varid, rtemp, start=[1, tslot]), "netcdf_read_frame_system nf90_getvar gr_pseudo_vhz_varid" ) + call check( nf90_get_var(nciu%id, nciu%gr_pseudo_vhz_varid, rtemp, start=[1, tslot]), "netcdf_read_frame_system nf90_getvar gr_pseudo_vhz_varid" ) if (npl > 0) pl%vh(3,:) = pack(rtemp, plmask) if (ntp > 0) tp%vh(3,:) = pack(rtemp, tpmask) else - call check( nf90_get_var(iu%ncid, iu%vhx_varid, rtemp, start=[1, tslot]), "netcdf_read_frame_system nf90_getvar vhx_varid" ) + call check( nf90_get_var(nciu%id, nciu%vhx_varid, rtemp, start=[1, tslot]), "netcdf_read_frame_system nf90_getvar vhx_varid" ) if (npl > 0) pl%vh(1,:) = pack(rtemp, plmask) if (ntp > 0) tp%vh(1,:) = pack(rtemp, tpmask) - call check( nf90_get_var(iu%ncid, iu%vhy_varid, rtemp, start=[1, tslot]), "netcdf_read_frame_system nf90_getvar vhy_varid" ) + call check( nf90_get_var(nciu%id, nciu%vhy_varid, rtemp, start=[1, tslot]), "netcdf_read_frame_system nf90_getvar vhy_varid" ) if (npl > 0) pl%vh(2,:) = pack(rtemp, plmask) if (ntp > 0) tp%vh(2,:) = pack(rtemp, tpmask) - call check( nf90_get_var(iu%ncid, iu%vhz_varid, rtemp, start=[1, tslot]), "netcdf_read_frame_system nf90_getvar vhz_varid" ) + call check( nf90_get_var(nciu%id, nciu%vhz_varid, rtemp, start=[1, tslot]), "netcdf_read_frame_system nf90_getvar vhz_varid" ) if (npl > 0) pl%vh(3,:) = pack(rtemp, plmask) if (ntp > 0) tp%vh(3,:) = pack(rtemp, tpmask) end if end if if ((param%in_form == "EL") .or. (param%in_form == "XVEL")) then - call check( nf90_get_var(iu%ncid, iu%a_varid, rtemp, start=[1, tslot]), "netcdf_read_frame_system nf90_getvar a_varid" ) + call check( nf90_get_var(nciu%id, nciu%a_varid, rtemp, start=[1, tslot]), "netcdf_read_frame_system nf90_getvar a_varid" ) if (.not.allocated(pl%a)) allocate(pl%a(npl)) if (.not.allocated(tp%a)) allocate(tp%a(ntp)) if (npl > 0) pl%a(:) = pack(rtemp, plmask) if (ntp > 0) tp%a(:) = pack(rtemp, tpmask) - call check( nf90_get_var(iu%ncid, iu%e_varid, rtemp, start=[1, tslot]), "netcdf_read_frame_system nf90_getvar e_varid" ) + call check( nf90_get_var(nciu%id, nciu%e_varid, rtemp, start=[1, tslot]), "netcdf_read_frame_system nf90_getvar e_varid" ) if (.not.allocated(pl%e)) allocate(pl%e(npl)) if (.not.allocated(tp%e)) allocate(tp%e(ntp)) if (npl > 0) pl%e(:) = pack(rtemp, plmask) if (ntp > 0) tp%e(:) = pack(rtemp, tpmask) - call check( nf90_get_var(iu%ncid, iu%inc_varid, rtemp, start=[1, tslot]), "netcdf_read_frame_system nf90_getvar inc_varid" ) + call check( nf90_get_var(nciu%id, nciu%inc_varid, rtemp, start=[1, tslot]), "netcdf_read_frame_system nf90_getvar inc_varid" ) rtemp = rtemp * DEG2RAD if (.not.allocated(pl%inc)) allocate(pl%inc(npl)) if (.not.allocated(tp%inc)) allocate(tp%inc(ntp)) if (npl > 0) pl%inc(:) = pack(rtemp, plmask) if (ntp > 0) tp%inc(:) = pack(rtemp, tpmask) - call check( nf90_get_var(iu%ncid, iu%capom_varid, rtemp, start=[1, tslot]), "netcdf_read_frame_system nf90_getvar capom_varid" ) + call check( nf90_get_var(nciu%id, nciu%capom_varid, rtemp, start=[1, tslot]), "netcdf_read_frame_system nf90_getvar capom_varid" ) rtemp = rtemp * DEG2RAD if (.not.allocated(pl%capom)) allocate(pl%capom(npl)) if (.not.allocated(tp%capom)) allocate(tp%capom(ntp)) if (npl > 0) pl%capom(:) = pack(rtemp, plmask) if (ntp > 0) tp%capom(:) = pack(rtemp, tpmask) - call check( nf90_get_var(iu%ncid, iu%omega_varid, rtemp, start=[1, tslot]), "netcdf_read_frame_system nf90_getvar omega_varid" ) + call check( nf90_get_var(nciu%id, nciu%omega_varid, rtemp, start=[1, tslot]), "netcdf_read_frame_system nf90_getvar omega_varid" ) rtemp = rtemp * DEG2RAD if (.not.allocated(pl%omega)) allocate(pl%omega(npl)) if (.not.allocated(tp%omega)) allocate(tp%omega(ntp)) if (npl > 0) pl%omega(:) = pack(rtemp, plmask) if (ntp > 0) tp%omega(:) = pack(rtemp, tpmask) - call check( nf90_get_var(iu%ncid, iu%capm_varid, rtemp, start=[1, tslot]), "netcdf_read_frame_system nf90_getvar capm_varid" ) + call check( nf90_get_var(nciu%id, nciu%capm_varid, rtemp, start=[1, tslot]), "netcdf_read_frame_system nf90_getvar capm_varid" ) rtemp = rtemp * DEG2RAD if (.not.allocated(pl%capm)) allocate(pl%capm(npl)) if (.not.allocated(tp%capm)) allocate(tp%capm(ntp)) @@ -655,7 +660,7 @@ module function netcdf_read_frame_system(self, iu, param) result(ierr) end if - call check( nf90_get_var(iu%ncid, iu%Gmass_varid, rtemp, start=[1, tslot]), "netcdf_read_frame_system nf90_getvar Gmass_varid" ) + call check( nf90_get_var(nciu%id, nciu%Gmass_varid, rtemp, start=[1, tslot]), "netcdf_read_frame_system nf90_getvar Gmass_varid" ) cb%Gmass = rtemp(1) cb%mass = cb%Gmass / param%GU @@ -671,13 +676,13 @@ module function netcdf_read_frame_system(self, iu, param) result(ierr) pl%mass(:) = pl%Gmass(:) / param%GU if (param%lrhill_present) then - call check( nf90_get_var(iu%ncid, iu%rhill_varid, rtemp, start=[1, tslot]), "netcdf_read_frame_system nf90_getvar rhill_varid" ) + call check( nf90_get_var(nciu%id, nciu%rhill_varid, rtemp, start=[1, tslot]), "netcdf_read_frame_system nf90_getvar rhill_varid" ) pl%rhill(:) = pack(rtemp, plmask) end if end if if (param%lclose) then - call check( nf90_get_var(iu%ncid, iu%radius_varid, rtemp, start=[1, tslot]), "netcdf_read_frame_system nf90_getvar radius_varid" ) + call check( nf90_get_var(nciu%id, nciu%radius_varid, rtemp, start=[1, tslot]), "netcdf_read_frame_system nf90_getvar radius_varid" ) cb%radius = rtemp(1) ! Set initial central body radius for SyMBA bookkeeping @@ -692,27 +697,27 @@ module function netcdf_read_frame_system(self, iu, param) result(ierr) end if if (param%lrotation) then - call check( nf90_get_var(iu%ncid, iu%Ip1_varid, rtemp, start=[1, tslot]), "netcdf_read_frame_system nf90_getvar Ip1_varid" ) + call check( nf90_get_var(nciu%id, nciu%Ip1_varid, rtemp, start=[1, tslot]), "netcdf_read_frame_system nf90_getvar Ip1_varid" ) cb%Ip(1) = rtemp(1) if (npl > 0) pl%Ip(1,:) = pack(rtemp, plmask) - call check( nf90_get_var(iu%ncid, iu%Ip2_varid, rtemp, start=[1, tslot]), "netcdf_read_frame_system nf90_getvar Ip2_varid" ) + call check( nf90_get_var(nciu%id, nciu%Ip2_varid, rtemp, start=[1, tslot]), "netcdf_read_frame_system nf90_getvar Ip2_varid" ) cb%Ip(2) = rtemp(1) if (npl > 0) pl%Ip(2,:) = pack(rtemp, plmask) - call check( nf90_get_var(iu%ncid, iu%Ip3_varid, rtemp, start=[1, tslot]), "netcdf_read_frame_system nf90_getvar Ip3_varid" ) + call check( nf90_get_var(nciu%id, nciu%Ip3_varid, rtemp, start=[1, tslot]), "netcdf_read_frame_system nf90_getvar Ip3_varid" ) cb%Ip(3) = rtemp(1) if (npl > 0) pl%Ip(3,:) = pack(rtemp, plmask) - call check( nf90_get_var(iu%ncid, iu%rotx_varid, rtemp, start=[1, tslot]), "netcdf_read_frame_system nf90_getvar rotx_varid" ) + call check( nf90_get_var(nciu%id, nciu%rotx_varid, rtemp, start=[1, tslot]), "netcdf_read_frame_system nf90_getvar rotx_varid" ) cb%rot(1) = rtemp(1) if (npl > 0) pl%rot(1,:) = pack(rtemp, plmask) - call check( nf90_get_var(iu%ncid, iu%roty_varid, rtemp, start=[1, tslot]), "netcdf_read_frame_system nf90_getvar roty_varid" ) + call check( nf90_get_var(nciu%id, nciu%roty_varid, rtemp, start=[1, tslot]), "netcdf_read_frame_system nf90_getvar roty_varid" ) cb%rot(2) = rtemp(1) if (npl > 0) pl%rot(2,:) = pack(rtemp, plmask) - call check( nf90_get_var(iu%ncid, iu%rotz_varid, rtemp, start=[1, tslot]), "netcdf_read_frame_system nf90_getvar rotz_varid" ) + call check( nf90_get_var(nciu%id, nciu%rotz_varid, rtemp, start=[1, tslot]), "netcdf_read_frame_system nf90_getvar rotz_varid" ) cb%rot(3) = rtemp(1) if (npl > 0) pl%rot(3,:) = pack(rtemp, plmask) @@ -724,37 +729,37 @@ module function netcdf_read_frame_system(self, iu, param) result(ierr) end if ! if (param%ltides) then - ! call check( nf90_get_var(iu%ncid, iu%k2_varid, rtemp, start=[1, tslot]), "netcdf_read_frame_system nf90_getvar k2_varid" ) + ! call check( nf90_get_var(nciu%id, nciu%k2_varid, rtemp, start=[1, tslot]), "netcdf_read_frame_system nf90_getvar k2_varid" ) ! cb%k2 = rtemp(1) ! if (npl > 0) pl%k2(:) = pack(rtemp, plmask) - ! call check( nf90_get_var(iu%ncid, iu%Q_varid, rtemp, start=[1, tslot]), "netcdf_read_frame_system nf90_getvar Q_varid" ) + ! call check( nf90_get_var(nciu%id, nciu%Q_varid, rtemp, start=[1, tslot]), "netcdf_read_frame_system nf90_getvar Q_varid" ) ! cb%Q = rtemp(1) ! if (npl > 0) pl%Q(:) = pack(rtemp, plmask) ! end if - status = nf90_inq_varid(iu%ncid, iu%j2rp2_varname, iu%j2rp2_varid) + status = nf90_inq_varid(nciu%id, nciu%j2rp2_varname, nciu%j2rp2_varid) if (status == nf90_noerr) then - call check( nf90_get_var(iu%ncid, iu%j2rp2_varid, cb%j2rp2, start=[tslot]), "netcdf_read_frame_system nf90_getvar j2rp2_varid" ) + call check( nf90_get_var(nciu%id, nciu%j2rp2_varid, cb%j2rp2, start=[tslot]), "netcdf_read_frame_system nf90_getvar j2rp2_varid" ) else cb%j2rp2 = 0.0_DP end if - status = nf90_inq_varid(iu%ncid, iu%j4rp4_varname, iu%j4rp4_varid) + status = nf90_inq_varid(nciu%id, nciu%j4rp4_varname, nciu%j4rp4_varid) if (status == nf90_noerr) then - call check( nf90_get_var(iu%ncid, iu%j4rp4_varid, cb%j4rp4, start=[tslot]), "netcdf_read_frame_system nf90_getvar j4rp4_varid" ) + call check( nf90_get_var(nciu%id, nciu%j4rp4_varid, cb%j4rp4, start=[tslot]), "netcdf_read_frame_system nf90_getvar j4rp4_varid" ) else cb%j4rp4 = 0.0_DP end if - call self%read_particle_info(iu, param, plmask, tpmask) + call self%read_particle_info(nciu, param, plmask, tpmask) if (param%in_form == "EL") then call pl%el2xv(cb) call tp%el2xv(cb) end if ! if this is a GR-enabled run, check to see if we got the pseudovelocities in. Otherwise, we'll need to generate them. - if (param%lgr .and. .not.(iu%lpseudo_vel_exists)) then + if (param%lgr .and. .not.(nciu%lpseudo_vel_exists)) then call pl%set_mu(cb) call tp%set_mu(cb) call pl%v2pv(param) @@ -763,7 +768,7 @@ module function netcdf_read_frame_system(self, iu, param) result(ierr) end associate - call iu%close() + call nciu%close() ierr = 0 return @@ -774,7 +779,7 @@ module function netcdf_read_frame_system(self, iu, param) result(ierr) end function netcdf_read_frame_system - module subroutine netcdf_read_hdr_system(self, iu, param) + module subroutine netcdf_read_hdr_system(self, nciu, param) !! author: David A. Minton !! !! Reads header information (variables that change with time, but not particle id). @@ -783,7 +788,7 @@ module subroutine netcdf_read_hdr_system(self, iu, param) implicit none ! Arguments class(swiftest_nbody_system), intent(inout) :: self !! Swiftest nbody system object - class(netcdf_parameters), intent(inout) :: iu !! Parameters used to for writing a NetCDF dataset to file + class(netcdf_parameters), intent(inout) :: nciu !! Parameters used to for writing a NetCDF dataset to file class(swiftest_parameters), intent(inout) :: param !! Current run configuration parameters ! Internals integer(I4B) :: tslot, status, idmax @@ -792,15 +797,15 @@ module subroutine netcdf_read_hdr_system(self, iu, param) tslot = param%ioutput + 1 - call check( nf90_inquire_dimension(iu%ncid, iu%id_dimid, len=idmax), "netcdf_read_frame_system nf90_inquire_dimension id_dimid" ) - call check( nf90_get_var(iu%ncid, iu%time_varid, self%t, start=[tslot]), "netcdf_read_hdr_system nf90_getvar time_varid" ) + call check( nf90_inquire_dimension(nciu%id, nciu%id_dimid, len=idmax), "netcdf_read_frame_system nf90_inquire_dimension id_dimid" ) + call check( nf90_get_var(nciu%id, nciu%time_varid, self%t, start=[tslot]), "netcdf_read_hdr_system nf90_getvar time_varid" ) allocate(gmtemp(idmax)) allocate(tpmask(idmax)) allocate(plmask(idmax)) allocate(plmmask(idmax)) - call check( nf90_get_var(iu%ncid, iu%Gmass_varid, gmtemp, start=[1,1]), "netcdf_read_frame_system nf90_getvar Gmass_varid" ) + call check( nf90_get_var(nciu%id, nciu%Gmass_varid, gmtemp, start=[1,1]), "netcdf_read_frame_system nf90_getvar Gmass_varid" ) plmask(:) = gmtemp(:) == gmtemp(:) tpmask(:) = .not. plmask(:) @@ -813,26 +818,26 @@ module subroutine netcdf_read_hdr_system(self, iu, param) endwhere end select - status = nf90_inq_varid(iu%ncid, iu%npl_varname, iu%npl_varid) + status = nf90_inq_varid(nciu%id, nciu%npl_varname, nciu%npl_varid) if (status == nf90_noerr) then - call check( nf90_get_var(iu%ncid, iu%npl_varid, self%pl%nbody, start=[tslot]), "netcdf_read_hdr_system nf90_getvar npl_varid" ) + call check( nf90_get_var(nciu%id, nciu%npl_varid, self%pl%nbody, start=[tslot]), "netcdf_read_hdr_system nf90_getvar npl_varid" ) else self%pl%nbody = count(plmask(:)) end if - status = nf90_inq_varid(iu%ncid, iu%ntp_varname, iu%ntp_varid) + status = nf90_inq_varid(nciu%id, nciu%ntp_varname, nciu%ntp_varid) if (status == nf90_noerr) then - call check( nf90_get_var(iu%ncid, iu%ntp_varid, self%tp%nbody, start=[tslot]), "netcdf_read_hdr_system nf90_getvar ntp_varid" ) + call check( nf90_get_var(nciu%id, nciu%ntp_varid, self%tp%nbody, start=[tslot]), "netcdf_read_hdr_system nf90_getvar ntp_varid" ) else self%tp%nbody = count(tpmask(:)) end if if (param%integrator == SYMBA) then - status = nf90_inq_varid(iu%ncid, iu%nplm_varname, iu%nplm_varid) + status = nf90_inq_varid(nciu%id, nciu%nplm_varname, nciu%nplm_varid) select type(pl => self%pl) class is (symba_pl) if (status == nf90_noerr) then - call check( nf90_get_var(iu%ncid, iu%nplm_varid, pl%nplm, start=[tslot]), "netcdf_read_hdr_system nf90_getvar nplm_varid" ) + call check( nf90_get_var(nciu%id, nciu%nplm_varid, pl%nplm, start=[tslot]), "netcdf_read_hdr_system nf90_getvar nplm_varid" ) else pl%nplm = count(plmmask(:)) end if @@ -840,50 +845,50 @@ module subroutine netcdf_read_hdr_system(self, iu, param) end if if (param%lenergy) then - status = nf90_inq_varid(iu%ncid, iu%ke_orb_varname, iu%KE_orb_varid) - if (status == nf90_noerr) call check( nf90_get_var(iu%ncid, iu%KE_orb_varid, self%ke_orbit, start=[tslot]), "netcdf_read_hdr_system nf90_getvar KE_orb_varid" ) - status = nf90_inq_varid(iu%ncid, iu%ke_spin_varname, iu%KE_spin_varid) - if (status == nf90_noerr) call check( nf90_get_var(iu%ncid, iu%KE_spin_varid, self%ke_spin, start=[tslot]), "netcdf_read_hdr_system nf90_getvar KE_spin_varid" ) - status = nf90_inq_varid(iu%ncid, iu%pe_varname, iu%PE_varid) - if (status == nf90_noerr) call check( nf90_get_var(iu%ncid, iu%PE_varid, self%pe, start=[tslot]), "netcdf_read_hdr_system nf90_getvar PE_varid" ) - status = nf90_inq_varid(iu%ncid, iu%l_orbx_varname, iu%L_orbx_varid) - if (status == nf90_noerr) call check( nf90_get_var(iu%ncid, iu%L_orbx_varid, self%Lorbit(1), start=[tslot]), "netcdf_read_hdr_system nf90_getvar L_orbx_varid" ) - status = nf90_inq_varid(iu%ncid, iu%l_orby_varname, iu%L_orby_varid) - if (status == nf90_noerr) call check( nf90_get_var(iu%ncid, iu%L_orby_varid, self%Lorbit(2), start=[tslot]), "netcdf_read_hdr_system nf90_getvar L_orby_varid" ) - status = nf90_inq_varid(iu%ncid, iu%l_orbz_varname, iu%L_orbz_varid) - if (status == nf90_noerr) call check( nf90_get_var(iu%ncid, iu%L_orbz_varid, self%Lorbit(3), start=[tslot]), "netcdf_read_hdr_system nf90_getvar L_orbz_varid" ) - status = nf90_inq_varid(iu%ncid, iu%l_spinx_varname, iu%L_spinx_varid) - if (status == nf90_noerr) call check( nf90_get_var(iu%ncid, iu%L_spinx_varid, self%Lspin(1), start=[tslot]), "netcdf_read_hdr_system nf90_getvar L_spinx_varid" ) - status = nf90_inq_varid(iu%ncid, iu%l_spiny_varname, iu%L_spiny_varid) - if (status == nf90_noerr) call check( nf90_get_var(iu%ncid, iu%L_spiny_varid, self%Lspin(2), start=[tslot]), "netcdf_read_hdr_system nf90_getvar L_spiny_varid" ) - status = nf90_inq_varid(iu%ncid, iu%l_spinz_varname, iu%L_spinz_varid) - if (status == nf90_noerr) call check( nf90_get_var(iu%ncid, iu%L_spinz_varid, self%Lspin(3), start=[tslot]), "netcdf_read_hdr_system nf90_getvar L_spinz_varid" ) - status = nf90_inq_varid(iu%ncid, iu%l_escapex_varname, iu%L_escapex_varid) - if (status == nf90_noerr) call check( nf90_get_var(iu%ncid, iu%L_escapex_varid, self%Lescape(1), start=[tslot]), "netcdf_read_hdr_system nf90_getvar L_escapex_varid" ) - status = nf90_inq_varid(iu%ncid, iu%l_escapey_varname, iu%L_escapey_varid) - if (status == nf90_noerr) call check( nf90_get_var(iu%ncid, iu%L_escapey_varid, self%Lescape(2), start=[tslot]), "netcdf_read_hdr_system nf90_getvar L_escapey_varid" ) - status = nf90_inq_varid(iu%ncid, iu%l_escapez_varname, iu%L_escapez_varid) - if (status == nf90_noerr) call check( nf90_get_var(iu%ncid, iu%L_escapez_varid, self%Lescape(3), start=[tslot]), "netcdf_read_hdr_system nf90_getvar L_escapez_varid" ) - status = nf90_inq_varid(iu%ncid, iu%ecollisions_varname, iu%Ecollisions_varid) - if (status == nf90_noerr) call check( nf90_get_var(iu%ncid, iu%Ecollisions_varid, self%Ecollisions, start=[tslot]), "netcdf_read_hdr_system nf90_getvar Ecollisions_varid" ) - status = nf90_inq_varid(iu%ncid, iu%euntracked_varname, iu%Euntracked_varid) - if (status == nf90_noerr) call check( nf90_get_var(iu%ncid, iu%Euntracked_varid, self%Euntracked, start=[tslot]), "netcdf_read_hdr_system nf90_getvar Euntracked_varid" ) - status = nf90_inq_varid(iu%ncid, iu%gmescape_varname, iu%GMescape_varid) - if (status == nf90_noerr) call check( nf90_get_var(iu%ncid, iu%GMescape_varid, self%GMescape, start=[tslot]), "netcdf_read_hdr_system nf90_getvar GMescape_varid" ) + status = nf90_inq_varid(nciu%id, nciu%ke_orb_varname, nciu%KE_orb_varid) + if (status == nf90_noerr) call check( nf90_get_var(nciu%id, nciu%KE_orb_varid, self%ke_orbit, start=[tslot]), "netcdf_read_hdr_system nf90_getvar KE_orb_varid" ) + status = nf90_inq_varid(nciu%id, nciu%ke_spin_varname, nciu%KE_spin_varid) + if (status == nf90_noerr) call check( nf90_get_var(nciu%id, nciu%KE_spin_varid, self%ke_spin, start=[tslot]), "netcdf_read_hdr_system nf90_getvar KE_spin_varid" ) + status = nf90_inq_varid(nciu%id, nciu%pe_varname, nciu%PE_varid) + if (status == nf90_noerr) call check( nf90_get_var(nciu%id, nciu%PE_varid, self%pe, start=[tslot]), "netcdf_read_hdr_system nf90_getvar PE_varid" ) + status = nf90_inq_varid(nciu%id, nciu%l_orbx_varname, nciu%L_orbx_varid) + if (status == nf90_noerr) call check( nf90_get_var(nciu%id, nciu%L_orbx_varid, self%Lorbit(1), start=[tslot]), "netcdf_read_hdr_system nf90_getvar L_orbx_varid" ) + status = nf90_inq_varid(nciu%id, nciu%l_orby_varname, nciu%L_orby_varid) + if (status == nf90_noerr) call check( nf90_get_var(nciu%id, nciu%L_orby_varid, self%Lorbit(2), start=[tslot]), "netcdf_read_hdr_system nf90_getvar L_orby_varid" ) + status = nf90_inq_varid(nciu%id, nciu%l_orbz_varname, nciu%L_orbz_varid) + if (status == nf90_noerr) call check( nf90_get_var(nciu%id, nciu%L_orbz_varid, self%Lorbit(3), start=[tslot]), "netcdf_read_hdr_system nf90_getvar L_orbz_varid" ) + status = nf90_inq_varid(nciu%id, nciu%l_spinx_varname, nciu%L_spinx_varid) + if (status == nf90_noerr) call check( nf90_get_var(nciu%id, nciu%L_spinx_varid, self%Lspin(1), start=[tslot]), "netcdf_read_hdr_system nf90_getvar L_spinx_varid" ) + status = nf90_inq_varid(nciu%id, nciu%l_spiny_varname, nciu%L_spiny_varid) + if (status == nf90_noerr) call check( nf90_get_var(nciu%id, nciu%L_spiny_varid, self%Lspin(2), start=[tslot]), "netcdf_read_hdr_system nf90_getvar L_spiny_varid" ) + status = nf90_inq_varid(nciu%id, nciu%l_spinz_varname, nciu%L_spinz_varid) + if (status == nf90_noerr) call check( nf90_get_var(nciu%id, nciu%L_spinz_varid, self%Lspin(3), start=[tslot]), "netcdf_read_hdr_system nf90_getvar L_spinz_varid" ) + status = nf90_inq_varid(nciu%id, nciu%l_escapex_varname, nciu%L_escapex_varid) + if (status == nf90_noerr) call check( nf90_get_var(nciu%id, nciu%L_escapex_varid, self%Lescape(1), start=[tslot]), "netcdf_read_hdr_system nf90_getvar L_escapex_varid" ) + status = nf90_inq_varid(nciu%id, nciu%l_escapey_varname, nciu%L_escapey_varid) + if (status == nf90_noerr) call check( nf90_get_var(nciu%id, nciu%L_escapey_varid, self%Lescape(2), start=[tslot]), "netcdf_read_hdr_system nf90_getvar L_escapey_varid" ) + status = nf90_inq_varid(nciu%id, nciu%l_escapez_varname, nciu%L_escapez_varid) + if (status == nf90_noerr) call check( nf90_get_var(nciu%id, nciu%L_escapez_varid, self%Lescape(3), start=[tslot]), "netcdf_read_hdr_system nf90_getvar L_escapez_varid" ) + status = nf90_inq_varid(nciu%id, nciu%ecollisions_varname, nciu%Ecollisions_varid) + if (status == nf90_noerr) call check( nf90_get_var(nciu%id, nciu%Ecollisions_varid, self%Ecollisions, start=[tslot]), "netcdf_read_hdr_system nf90_getvar Ecollisions_varid" ) + status = nf90_inq_varid(nciu%id, nciu%euntracked_varname, nciu%Euntracked_varid) + if (status == nf90_noerr) call check( nf90_get_var(nciu%id, nciu%Euntracked_varid, self%Euntracked, start=[tslot]), "netcdf_read_hdr_system nf90_getvar Euntracked_varid" ) + status = nf90_inq_varid(nciu%id, nciu%gmescape_varname, nciu%GMescape_varid) + if (status == nf90_noerr) call check( nf90_get_var(nciu%id, nciu%GMescape_varid, self%GMescape, start=[tslot]), "netcdf_read_hdr_system nf90_getvar GMescape_varid" ) end if return end subroutine netcdf_read_hdr_system - module subroutine netcdf_read_particle_info_system(self, iu, param, plmask, tpmask) + module subroutine netcdf_read_particle_info_system(self, nciu, param, plmask, tpmask) !! author: Carlisle A. Wishard, Dana Singh, and David A. Minton !! !! Reads particle information metadata from file implicit none ! Arguments class(swiftest_nbody_system), intent(inout) :: self !! Swiftest nbody system object - class(netcdf_parameters), intent(inout) :: iu !! Parameters used to identify a particular NetCDF dataset + class(netcdf_parameters), intent(inout) :: nciu !! Parameters used to identify a particular NetCDF dataset class(swiftest_parameters), intent(inout) :: param !! Current run configuration parameters logical, dimension(:), intent(in) :: plmask !! Logical array indicating which index values belong to massive bodies logical, dimension(:), intent(in) :: tpmask !! Logical array indicating which index values belong to test particles @@ -923,12 +928,12 @@ module subroutine netcdf_read_particle_info_system(self, iu, param, plmask, tpma tpind(:) = pack([(i, i = 1, idmax)], tpmask(:)) end if - call check( nf90_get_var(iu%ncid, iu%id_varid, itemp), "netcdf_read_particle_info_system nf90_getvar id_varid" ) + call check( nf90_get_var(nciu%id, nciu%id_varid, itemp), "netcdf_read_particle_info_system nf90_getvar id_varid" ) cb%id = itemp(1) pl%id(:) = pack(itemp, plmask) tp%id(:) = pack(itemp, tpmask) - call check( nf90_get_var(iu%ncid, iu%name_varid, ctemp, count=[NAMELEN, idmax]), "netcdf_read_particle_info_system nf90_getvar name_varid" ) + call check( nf90_get_var(nciu%id, nciu%name_varid, ctemp, count=[NAMELEN, idmax]), "netcdf_read_particle_info_system nf90_getvar name_varid" ) call cb%info%set_value(name=ctemp(1)) do i = 1, npl call pl%info(i)%set_value(name=ctemp(plind(i))) @@ -937,7 +942,7 @@ module subroutine netcdf_read_particle_info_system(self, iu, param, plmask, tpma call tp%info(i)%set_value(name=ctemp(tpind(i))) end do - call check( nf90_get_var(iu%ncid, iu%ptype_varid, ctemp, count=[NAMELEN, idmax]), "netcdf_read_particle_info_system nf90_getvar ptype_varid" ) + call check( nf90_get_var(nciu%id, nciu%ptype_varid, ctemp, count=[NAMELEN, idmax]), "netcdf_read_particle_info_system nf90_getvar ptype_varid" ) call cb%info%set_value(particle_type=ctemp(1)) do i = 1, npl call pl%info(i)%set_value(particle_type=ctemp(plind(i))) @@ -946,9 +951,9 @@ module subroutine netcdf_read_particle_info_system(self, iu, param, plmask, tpma call tp%info(i)%set_value(particle_type=ctemp(tpind(i))) end do - status = nf90_inq_varid(iu%ncid, iu%status_varname, iu%status_varid) + status = nf90_inq_varid(nciu%id, nciu%status_varname, nciu%status_varid) if (status == nf90_noerr) then - call check( nf90_get_var(iu%ncid, iu%status_varid, ctemp, count=[NAMELEN, idmax]), "netcdf_read_particle_info_system nf90_getvar status_varid") + call check( nf90_get_var(nciu%id, nciu%status_varid, ctemp, count=[NAMELEN, idmax]), "netcdf_read_particle_info_system nf90_getvar status_varid") call cb%info%set_value(status=ctemp(1)) else call cb%info%set_value(status="ACTIVE") @@ -962,9 +967,9 @@ module subroutine netcdf_read_particle_info_system(self, iu, param, plmask, tpma if (param%lclose) then - status = nf90_inq_varid(iu%ncid, iu%origin_type_varname, iu%origin_type_varid) + status = nf90_inq_varid(nciu%id, nciu%origin_type_varname, nciu%origin_type_varid) if (status == nf90_noerr) then - call check( nf90_get_var(iu%ncid, iu%origin_type_varid, ctemp, count=[NAMELEN, idmax]), "netcdf_read_particle_info_system nf90_getvar origin_type_varid" ) + call check( nf90_get_var(nciu%id, nciu%origin_type_varid, ctemp, count=[NAMELEN, idmax]), "netcdf_read_particle_info_system nf90_getvar origin_type_varid" ) else ctemp = "Initial Conditions" end if @@ -977,9 +982,9 @@ module subroutine netcdf_read_particle_info_system(self, iu, param, plmask, tpma call tp%info(i)%set_value(origin_type=ctemp(tpind(i))) end do - status = nf90_inq_varid(iu%ncid, iu%origin_time_varname, iu%origin_time_varid) + status = nf90_inq_varid(nciu%id, nciu%origin_time_varname, nciu%origin_time_varid) if (status == nf90_noerr) then - call check( nf90_get_var(iu%ncid, iu%origin_time_varid, rtemp), "netcdf_read_particle_info_system nf90_getvar origin_time_varid" ) + call check( nf90_get_var(nciu%id, nciu%origin_time_varid, rtemp), "netcdf_read_particle_info_system nf90_getvar origin_time_varid" ) else rtemp = param%t0 end if @@ -992,29 +997,29 @@ module subroutine netcdf_read_particle_info_system(self, iu, param, plmask, tpma call tp%info(i)%set_value(origin_time=rtemp(tpind(i))) end do - status = nf90_inq_varid(iu%ncid, iu%origin_xhx_varname, iu%origin_xhx_varid) + status = nf90_inq_varid(nciu%id, nciu%origin_xhx_varname, nciu%origin_xhx_varid) if (status == nf90_noerr) then - call check( nf90_get_var(iu%ncid, iu%origin_xhx_varid, rtemp_arr(1,:)), "netcdf_read_particle_info_system nf90_getvar origin_xhx_varid" ) + call check( nf90_get_var(nciu%id, nciu%origin_xhx_varid, rtemp_arr(1,:)), "netcdf_read_particle_info_system nf90_getvar origin_xhx_varid" ) else if ((param%out_form == "XV") .or. (param%out_form == "XVEL")) then - call check( nf90_get_var(iu%ncid, iu%xhx_varid, rtemp_arr(1,:)), "netcdf_read_particle_info_system nf90_getvar xhx_varid" ) + call check( nf90_get_var(nciu%id, nciu%xhx_varid, rtemp_arr(1,:)), "netcdf_read_particle_info_system nf90_getvar xhx_varid" ) else rtemp_arr(1,:) = 0._DP end if - status = nf90_inq_varid(iu%ncid, iu%origin_xhy_varname, iu%origin_xhy_varid) + status = nf90_inq_varid(nciu%id, nciu%origin_xhy_varname, nciu%origin_xhy_varid) if (status == nf90_noerr) then - call check( nf90_get_var(iu%ncid, iu%origin_xhy_varid, rtemp_arr(2,:)), "netcdf_read_particle_info_system nf90_getvar origin_xhy_varid" ) + call check( nf90_get_var(nciu%id, nciu%origin_xhy_varid, rtemp_arr(2,:)), "netcdf_read_particle_info_system nf90_getvar origin_xhy_varid" ) else if ((param%out_form == "XV") .or. (param%out_form == "XVEL")) then - call check( nf90_get_var(iu%ncid, iu%xhy_varid, rtemp_arr(2,:)), "netcdf_read_particle_info_system nf90_getvar xhx_varid" ) + call check( nf90_get_var(nciu%id, nciu%xhy_varid, rtemp_arr(2,:)), "netcdf_read_particle_info_system nf90_getvar xhx_varid" ) else rtemp_arr(2,:) = 0._DP end if - status = nf90_inq_varid(iu%ncid, iu%origin_xhz_varname, iu%origin_xhz_varid) + status = nf90_inq_varid(nciu%id, nciu%origin_xhz_varname, nciu%origin_xhz_varid) if (status == nf90_noerr) then - call check( nf90_get_var(iu%ncid, iu%origin_xhz_varid, rtemp_arr(3,:)), "netcdf_read_particle_info_system nf90_getvar origin_xhz_varid" ) + call check( nf90_get_var(nciu%id, nciu%origin_xhz_varid, rtemp_arr(3,:)), "netcdf_read_particle_info_system nf90_getvar origin_xhz_varid" ) else if ((param%out_form == "XV") .or. (param%out_form == "XVEL")) then - call check( nf90_get_var(iu%ncid, iu%xhz_varid, rtemp_arr(3,:)), "netcdf_read_particle_info_system nf90_getvar xhz_varid" ) + call check( nf90_get_var(nciu%id, nciu%xhz_varid, rtemp_arr(3,:)), "netcdf_read_particle_info_system nf90_getvar xhz_varid" ) else rtemp_arr(3,:) = 0._DP end if @@ -1026,29 +1031,29 @@ module subroutine netcdf_read_particle_info_system(self, iu, param, plmask, tpma call tp%info(i)%set_value(origin_xh=rtemp_arr(:,tpind(i))) end do - status = nf90_inq_varid(iu%ncid, iu%origin_vhx_varname, iu%origin_vhx_varid) + status = nf90_inq_varid(nciu%id, nciu%origin_vhx_varname, nciu%origin_vhx_varid) if (status == nf90_noerr) then - call check( nf90_get_var(iu%ncid, iu%origin_vhx_varid, rtemp_arr(1,:)), "netcdf_read_particle_info_system nf90_getvar origin_vhx_varid" ) + call check( nf90_get_var(nciu%id, nciu%origin_vhx_varid, rtemp_arr(1,:)), "netcdf_read_particle_info_system nf90_getvar origin_vhx_varid" ) else if ((param%out_form == "XV") .or. (param%out_form == "XVEL")) then - call check( nf90_get_var(iu%ncid, iu%vhx_varid, rtemp_arr(1,:)), "netcdf_read_particle_info_system nf90_getvar vhx_varid" ) + call check( nf90_get_var(nciu%id, nciu%vhx_varid, rtemp_arr(1,:)), "netcdf_read_particle_info_system nf90_getvar vhx_varid" ) else rtemp_arr(1,:) = 0._DP end if - status = nf90_inq_varid(iu%ncid, iu%origin_vhy_varname, iu%origin_vhy_varid) + status = nf90_inq_varid(nciu%id, nciu%origin_vhy_varname, nciu%origin_vhy_varid) if (status == nf90_noerr) then - call check( nf90_get_var(iu%ncid, iu%origin_vhy_varid, rtemp_arr(2,:)), "netcdf_read_particle_info_system nf90_getvar origin_vhy_varid" ) + call check( nf90_get_var(nciu%id, nciu%origin_vhy_varid, rtemp_arr(2,:)), "netcdf_read_particle_info_system nf90_getvar origin_vhy_varid" ) else if ((param%out_form == "XV") .or. (param%out_form == "XVEL")) then - call check( nf90_get_var(iu%ncid, iu%vhy_varid, rtemp_arr(2,:)), "netcdf_read_particle_info_system nf90_getvar vhy_varid" ) + call check( nf90_get_var(nciu%id, nciu%vhy_varid, rtemp_arr(2,:)), "netcdf_read_particle_info_system nf90_getvar vhy_varid" ) else rtemp_arr(2,:) = 0._DP end if - status = nf90_inq_varid(iu%ncid, iu%origin_vhz_varname, iu%origin_vhz_varid) + status = nf90_inq_varid(nciu%id, nciu%origin_vhz_varname, nciu%origin_vhz_varid) if (status == nf90_noerr) then - call check( nf90_get_var(iu%ncid, iu%origin_vhz_varid, rtemp_arr(3,:)), "netcdf_read_particle_info_system nf90_getvar origin_vhz_varid" ) + call check( nf90_get_var(nciu%id, nciu%origin_vhz_varid, rtemp_arr(3,:)), "netcdf_read_particle_info_system nf90_getvar origin_vhz_varid" ) else if ((param%out_form == "XV") .or. (param%out_form == "XVEL")) then - call check( nf90_get_var(iu%ncid, iu%vhz_varid, rtemp_arr(3,:)), "netcdf_read_particle_info_system nf90_getvar vhz_varid" ) + call check( nf90_get_var(nciu%id, nciu%vhz_varid, rtemp_arr(3,:)), "netcdf_read_particle_info_system nf90_getvar vhz_varid" ) else rtemp_arr(3,:) = 0._DP end if @@ -1060,9 +1065,9 @@ module subroutine netcdf_read_particle_info_system(self, iu, param, plmask, tpma call tp%info(i)%set_value(origin_vh=rtemp_arr(:,tpind(i))) end do - status = nf90_inq_varid(iu%ncid, iu%collision_id_varname, iu%collision_id_varid) + status = nf90_inq_varid(nciu%id, nciu%collision_id_varname, nciu%collision_id_varid) if (status == nf90_noerr) then - call check( nf90_get_var(iu%ncid, iu%collision_id_varid, itemp), "netcdf_read_particle_info_system nf90_getvar collision_id_varid" ) + call check( nf90_get_var(nciu%id, nciu%collision_id_varid, itemp), "netcdf_read_particle_info_system nf90_getvar collision_id_varid" ) else itemp = 0.0_DP end if @@ -1074,9 +1079,9 @@ module subroutine netcdf_read_particle_info_system(self, iu, param, plmask, tpma call tp%info(i)%set_value(collision_id=itemp(tpind(i))) end do - status = nf90_inq_varid(iu%ncid, iu%discard_time_varname, iu%discard_time_varid) + status = nf90_inq_varid(nciu%id, nciu%discard_time_varname, nciu%discard_time_varid) if (status == nf90_noerr) then - call check( nf90_get_var(iu%ncid, iu%discard_time_varid, rtemp), "netcdf_read_particle_info_system nf90_getvar discard_time_varid" ) + call check( nf90_get_var(nciu%id, nciu%discard_time_varid, rtemp), "netcdf_read_particle_info_system nf90_getvar discard_time_varid" ) else rtemp = 0.0_DP end if @@ -1089,23 +1094,23 @@ module subroutine netcdf_read_particle_info_system(self, iu, param, plmask, tpma call tp%info(i)%set_value(discard_time=rtemp(tpind(i))) end do - status = nf90_inq_varid(iu%ncid, iu%discard_xhx_varname, iu%discard_xhx_varid) + status = nf90_inq_varid(nciu%id, nciu%discard_xhx_varname, nciu%discard_xhx_varid) if (status == nf90_noerr) then - call check( nf90_get_var(iu%ncid, iu%discard_xhx_varid, rtemp_arr(1,:)), "netcdf_read_particle_info_system nf90_getvar discard_xhx_varid" ) + call check( nf90_get_var(nciu%id, nciu%discard_xhx_varid, rtemp_arr(1,:)), "netcdf_read_particle_info_system nf90_getvar discard_xhx_varid" ) else rtemp_arr(1,:) = 0.0_DP end if - status = nf90_inq_varid(iu%ncid, iu%discard_xhy_varname, iu%discard_xhy_varid) + status = nf90_inq_varid(nciu%id, nciu%discard_xhy_varname, nciu%discard_xhy_varid) if (status == nf90_noerr) then - call check( nf90_get_var(iu%ncid, iu%discard_xhy_varid, rtemp_arr(2,:)), "netcdf_read_particle_info_system nf90_getvar discard_xhy_varid" ) + call check( nf90_get_var(nciu%id, nciu%discard_xhy_varid, rtemp_arr(2,:)), "netcdf_read_particle_info_system nf90_getvar discard_xhy_varid" ) else rtemp_arr(2,:) = 0.0_DP end if - status = nf90_inq_varid(iu%ncid, iu%discard_xhz_varname, iu%discard_xhz_varid) + status = nf90_inq_varid(nciu%id, nciu%discard_xhz_varname, nciu%discard_xhz_varid) if (status == nf90_noerr) then - call check( nf90_get_var(iu%ncid, iu%discard_xhz_varid, rtemp_arr(3,:)), "netcdf_read_particle_info_system nf90_getvar discard_xhz_varid" ) + call check( nf90_get_var(nciu%id, nciu%discard_xhz_varid, rtemp_arr(3,:)), "netcdf_read_particle_info_system nf90_getvar discard_xhz_varid" ) else rtemp_arr(3,:) = 0.0_DP end if @@ -1117,23 +1122,23 @@ module subroutine netcdf_read_particle_info_system(self, iu, param, plmask, tpma call tp%info(i)%set_value(discard_xh=rtemp_arr(:,tpind(i))) end do - status = nf90_inq_varid(iu%ncid, iu%discard_vhx_varname, iu%discard_vhx_varid) + status = nf90_inq_varid(nciu%id, nciu%discard_vhx_varname, nciu%discard_vhx_varid) if (status == nf90_noerr) then - call check( nf90_get_var(iu%ncid, iu%discard_vhx_varid, rtemp_arr(1,:)), "netcdf_read_particle_info_system nf90_getvar discard_vhx_varid" ) + call check( nf90_get_var(nciu%id, nciu%discard_vhx_varid, rtemp_arr(1,:)), "netcdf_read_particle_info_system nf90_getvar discard_vhx_varid" ) else rtemp_arr(1,:) = 0.0_DP end if - status = nf90_inq_varid(iu%ncid, iu%discard_vhy_varname, iu%discard_vhy_varid) + status = nf90_inq_varid(nciu%id, nciu%discard_vhy_varname, nciu%discard_vhy_varid) if (status == nf90_noerr) then - call check( nf90_get_var(iu%ncid, iu%discard_vhy_varid, rtemp_arr(2,:)), "netcdf_read_particle_info_system nf90_getvar discard_vhy_varid" ) + call check( nf90_get_var(nciu%id, nciu%discard_vhy_varid, rtemp_arr(2,:)), "netcdf_read_particle_info_system nf90_getvar discard_vhy_varid" ) else rtemp_arr(2,:) = 0.0_DP end if - status = nf90_inq_varid(iu%ncid, iu%discard_vhz_varname, iu%discard_vhz_varid) + status = nf90_inq_varid(nciu%id, nciu%discard_vhz_varname, nciu%discard_vhz_varid) if (status == nf90_noerr) then - call check( nf90_get_var(iu%ncid, iu%discard_vhz_varid, rtemp_arr(3,:)), "netcdf_read_particle_info_system nf90_getvar discard_vhz_varid" ) + call check( nf90_get_var(nciu%id, nciu%discard_vhz_varid, rtemp_arr(3,:)), "netcdf_read_particle_info_system nf90_getvar discard_vhz_varid" ) else rtemp_arr(3,:) = 0.0_DP end if @@ -1161,13 +1166,13 @@ module subroutine netcdf_sync(self) ! Arguments class(netcdf_parameters), intent(inout) :: self !! Parameters used to identify a particular NetCDF dataset - call check( nf90_sync(self%ncid), "netcdf_sync nf90_sync" ) + call check( nf90_sync(self%id), "netcdf_sync nf90_sync" ) return end subroutine netcdf_sync - module subroutine netcdf_write_frame_base(self, iu, param) + module subroutine netcdf_write_frame_base(self, nciu, param) !! author: Carlisle A. Wishard, Dana Singh, and David A. Minton !! !! Write a frame of output of either test particle or massive body data to the binary output file @@ -1175,7 +1180,7 @@ module subroutine netcdf_write_frame_base(self, iu, param) implicit none ! Arguments class(swiftest_base), intent(in) :: self !! Swiftest particle object - class(netcdf_parameters), intent(inout) :: iu !! Parameters used to identify a particular NetCDF dataset + class(netcdf_parameters), intent(inout) :: nciu !! Parameters used to identify a particular NetCDF dataset class(swiftest_parameters), intent(inout) :: param !! Current run configuration parameters ! Internals integer(I4B) :: i, j, tslot, idslot, old_mode @@ -1183,11 +1188,11 @@ module subroutine netcdf_write_frame_base(self, iu, param) real(DP), dimension(NDIM) :: vh !! Temporary variable to store heliocentric velocity values when converting from pseudovelocity in GR-enabled runs real(DP) :: a, e, inc, omega, capom, capm - call self%write_info(iu, param) + call self%write_info(nciu, param) tslot = param%ioutput + 1 - call check( nf90_set_fill(iu%ncid, nf90_nofill, old_mode), "netcdf_write_frame_base nf90_set_fill" ) + call check( nf90_set_fill(nciu%id, nf90_nofill, old_mode), "netcdf_write_frame_base nf90_set_fill" ) select type(self) class is (swiftest_body) associate(n => self%nbody) @@ -1203,21 +1208,21 @@ module subroutine netcdf_write_frame_base(self, iu, param) if (param%lgr) call gr_pseudovel2vel(param, self%mu(j), self%xh(:, j), self%vh(:, j), vh(:)) if ((param%out_form == "XV") .or. (param%out_form == "XVEL")) then - call check( nf90_put_var(iu%ncid, iu%xhx_varid, self%xh(1, j), start=[idslot, tslot]), "netcdf_write_frame_base nf90_put_var xhx_varid" ) - call check( nf90_put_var(iu%ncid, iu%xhy_varid, self%xh(2, j), start=[idslot, tslot]), "netcdf_write_frame_base nf90_put_var xhy_varid" ) - call check( nf90_put_var(iu%ncid, iu%xhz_varid, self%xh(3, j), start=[idslot, tslot]), "netcdf_write_frame_base nf90_put_var xhz_varid" ) + call check( nf90_put_var(nciu%id, nciu%xhx_varid, self%xh(1, j), start=[idslot, tslot]), "netcdf_write_frame_base nf90_put_var xhx_varid" ) + call check( nf90_put_var(nciu%id, nciu%xhy_varid, self%xh(2, j), start=[idslot, tslot]), "netcdf_write_frame_base nf90_put_var xhy_varid" ) + call check( nf90_put_var(nciu%id, nciu%xhz_varid, self%xh(3, j), start=[idslot, tslot]), "netcdf_write_frame_base nf90_put_var xhz_varid" ) if (param%lgr) then !! Convert from pseudovelocity to heliocentric without replacing the current value of pseudovelocity - call check( nf90_put_var(iu%ncid, iu%vhx_varid, vh(1), start=[idslot, tslot]), "netcdf_write_frame_base nf90_put_var vhx_varid (gr case)" ) - call check( nf90_put_var(iu%ncid, iu%vhy_varid, vh(2), start=[idslot, tslot]), "netcdf_write_frame_base nf90_put_var vhy_varid (gr case)" ) - call check( nf90_put_var(iu%ncid, iu%vhz_varid, vh(3), start=[idslot, tslot]), "netcdf_write_frame_base nf90_put_var vhz_varid (gr case)" ) - call check( nf90_put_var(iu%ncid, iu%gr_pseudo_vhx_varid, self%vh(1, j), start=[idslot, tslot]), "netcdf_write_frame_base nf90_put_var gr_pseudo_vhx_varid" ) - call check( nf90_put_var(iu%ncid, iu%gr_pseudo_vhy_varid, self%vh(2, j), start=[idslot, tslot]), "netcdf_write_frame_base nf90_put_var gr_pseudo_vhy_varid" ) - call check( nf90_put_var(iu%ncid, iu%gr_pseudo_vhz_varid, self%vh(3, j), start=[idslot, tslot]), "netcdf_write_frame_base nf90_put_var gr_pseudo_vhz_varid" ) + call check( nf90_put_var(nciu%id, nciu%vhx_varid, vh(1), start=[idslot, tslot]), "netcdf_write_frame_base nf90_put_var vhx_varid (gr case)" ) + call check( nf90_put_var(nciu%id, nciu%vhy_varid, vh(2), start=[idslot, tslot]), "netcdf_write_frame_base nf90_put_var vhy_varid (gr case)" ) + call check( nf90_put_var(nciu%id, nciu%vhz_varid, vh(3), start=[idslot, tslot]), "netcdf_write_frame_base nf90_put_var vhz_varid (gr case)" ) + call check( nf90_put_var(nciu%id, nciu%gr_pseudo_vhx_varid, self%vh(1, j), start=[idslot, tslot]), "netcdf_write_frame_base nf90_put_var gr_pseudo_vhx_varid" ) + call check( nf90_put_var(nciu%id, nciu%gr_pseudo_vhy_varid, self%vh(2, j), start=[idslot, tslot]), "netcdf_write_frame_base nf90_put_var gr_pseudo_vhy_varid" ) + call check( nf90_put_var(nciu%id, nciu%gr_pseudo_vhz_varid, self%vh(3, j), start=[idslot, tslot]), "netcdf_write_frame_base nf90_put_var gr_pseudo_vhz_varid" ) else - call check( nf90_put_var(iu%ncid, iu%vhx_varid, self%vh(1, j), start=[idslot, tslot]), "netcdf_write_frame_base nf90_put_var vhx_varid" ) - call check( nf90_put_var(iu%ncid, iu%vhy_varid, self%vh(2, j), start=[idslot, tslot]), "netcdf_write_frame_base nf90_put_var vhy_varid" ) - call check( nf90_put_var(iu%ncid, iu%vhz_varid, self%vh(3, j), start=[idslot, tslot]), "netcdf_write_frame_base nf90_put_var vhz_varid" ) + call check( nf90_put_var(nciu%id, nciu%vhx_varid, self%vh(1, j), start=[idslot, tslot]), "netcdf_write_frame_base nf90_put_var vhx_varid" ) + call check( nf90_put_var(nciu%id, nciu%vhy_varid, self%vh(2, j), start=[idslot, tslot]), "netcdf_write_frame_base nf90_put_var vhy_varid" ) + call check( nf90_put_var(nciu%id, nciu%vhz_varid, self%vh(3, j), start=[idslot, tslot]), "netcdf_write_frame_base nf90_put_var vhz_varid" ) end if end if @@ -1231,32 +1236,32 @@ module subroutine netcdf_write_frame_base(self, iu, param) self%vh(1,j), self%vh(2,j), self%vh(3,j), & a, e, inc, capom, omega, capm) end if - call check( nf90_put_var(iu%ncid, iu%a_varid, a, start=[idslot, tslot]), "netcdf_write_frame_base nf90_put_var a_varid" ) - call check( nf90_put_var(iu%ncid, iu%e_varid, e, start=[idslot, tslot]), "netcdf_write_frame_base nf90_put_var e_varid" ) - call check( nf90_put_var(iu%ncid, iu%inc_varid, inc * RAD2DEG, start=[idslot, tslot]), "netcdf_write_frame_base nf90_put_var inc_varid" ) - call check( nf90_put_var(iu%ncid, iu%capom_varid, capom * RAD2DEG, start=[idslot, tslot]), "netcdf_write_frame_base nf90_put_var capom_varid" ) - call check( nf90_put_var(iu%ncid, iu%omega_varid, omega * RAD2DEG, start=[idslot, tslot]), "netcdf_write_frame_base nf90_put_var omega_varid" ) - call check( nf90_put_var(iu%ncid, iu%capm_varid, capm * RAD2DEG, start=[idslot, tslot]), "netcdf_write_frame_base nf90_put_var capm_varid" ) + call check( nf90_put_var(nciu%id, nciu%a_varid, a, start=[idslot, tslot]), "netcdf_write_frame_base nf90_put_var a_varid" ) + call check( nf90_put_var(nciu%id, nciu%e_varid, e, start=[idslot, tslot]), "netcdf_write_frame_base nf90_put_var e_varid" ) + call check( nf90_put_var(nciu%id, nciu%inc_varid, inc * RAD2DEG, start=[idslot, tslot]), "netcdf_write_frame_base nf90_put_var inc_varid" ) + call check( nf90_put_var(nciu%id, nciu%capom_varid, capom * RAD2DEG, start=[idslot, tslot]), "netcdf_write_frame_base nf90_put_var capom_varid" ) + call check( nf90_put_var(nciu%id, nciu%omega_varid, omega * RAD2DEG, start=[idslot, tslot]), "netcdf_write_frame_base nf90_put_var omega_varid" ) + call check( nf90_put_var(nciu%id, nciu%capm_varid, capm * RAD2DEG, start=[idslot, tslot]), "netcdf_write_frame_base nf90_put_var capm_varid" ) end if select type(self) class is (swiftest_pl) ! Additional output if the passed polymorphic object is a massive body - call check( nf90_put_var(iu%ncid, iu%Gmass_varid, self%Gmass(j), start=[idslot, tslot]), "netcdf_write_frame_base nf90_put_var Gmass_varid" ) + call check( nf90_put_var(nciu%id, nciu%Gmass_varid, self%Gmass(j), start=[idslot, tslot]), "netcdf_write_frame_base nf90_put_var Gmass_varid" ) if (param%lrhill_present) then - call check( nf90_put_var(iu%ncid, iu%rhill_varid, self%rhill(j), start=[idslot, tslot]), "netcdf_write_frame_base nf90_put_var rhill_varid" ) + call check( nf90_put_var(nciu%id, nciu%rhill_varid, self%rhill(j), start=[idslot, tslot]), "netcdf_write_frame_base nf90_put_var rhill_varid" ) end if - if (param%lclose) call check( nf90_put_var(iu%ncid, iu%radius_varid, self%radius(j), start=[idslot, tslot]), "netcdf_write_frame_base nf90_put_var radius_varid" ) + if (param%lclose) call check( nf90_put_var(nciu%id, nciu%radius_varid, self%radius(j), start=[idslot, tslot]), "netcdf_write_frame_base nf90_put_var radius_varid" ) if (param%lrotation) then - call check( nf90_put_var(iu%ncid, iu%Ip1_varid, self%Ip(1, j), start=[idslot, tslot]), "netcdf_write_frame_base nf90_put_var Ip1_varid" ) - call check( nf90_put_var(iu%ncid, iu%Ip2_varid, self%Ip(2, j), start=[idslot, tslot]), "netcdf_write_frame_base nf90_put_var Ip2_varid" ) - call check( nf90_put_var(iu%ncid, iu%Ip3_varid, self%Ip(3, j), start=[idslot, tslot]), "netcdf_write_frame_base nf90_put_var Ip3_varid" ) - call check( nf90_put_var(iu%ncid, iu%rotx_varid, self%rot(1, j), start=[idslot, tslot]), "netcdf_write_frame_base nf90_put_var rotx_varid" ) - call check( nf90_put_var(iu%ncid, iu%roty_varid, self%rot(2, j), start=[idslot, tslot]), "netcdf_write_frame_base nf90_put_var roty_varid" ) - call check( nf90_put_var(iu%ncid, iu%rotz_varid, self%rot(3, j), start=[idslot, tslot]), "netcdf_write_frame_base nf90_put_var rotz_varid" ) + call check( nf90_put_var(nciu%id, nciu%Ip1_varid, self%Ip(1, j), start=[idslot, tslot]), "netcdf_write_frame_base nf90_put_var Ip1_varid" ) + call check( nf90_put_var(nciu%id, nciu%Ip2_varid, self%Ip(2, j), start=[idslot, tslot]), "netcdf_write_frame_base nf90_put_var Ip2_varid" ) + call check( nf90_put_var(nciu%id, nciu%Ip3_varid, self%Ip(3, j), start=[idslot, tslot]), "netcdf_write_frame_base nf90_put_var Ip3_varid" ) + call check( nf90_put_var(nciu%id, nciu%rotx_varid, self%rot(1, j), start=[idslot, tslot]), "netcdf_write_frame_base nf90_put_var rotx_varid" ) + call check( nf90_put_var(nciu%id, nciu%roty_varid, self%rot(2, j), start=[idslot, tslot]), "netcdf_write_frame_base nf90_put_var roty_varid" ) + call check( nf90_put_var(nciu%id, nciu%rotz_varid, self%rot(3, j), start=[idslot, tslot]), "netcdf_write_frame_base nf90_put_var rotz_varid" ) end if ! if (param%ltides) then - ! call check( nf90_put_var(iu%ncid, iu%k2_varid, self%k2(j), start=[idslot, tslot]), "netcdf_write_frame_base nf90_put_var k2_varid" ) - ! call check( nf90_put_var(iu%ncid, iu%Q_varid, self%Q(j), start=[idslot, tslot]), "netcdf_write_frame_base nf90_put_var Q_varid" ) + ! call check( nf90_put_var(nciu%id, nciu%k2_varid, self%k2(j), start=[idslot, tslot]), "netcdf_write_frame_base nf90_put_var k2_varid" ) + ! call check( nf90_put_var(nciu%id, nciu%Q_varid, self%Q(j), start=[idslot, tslot]), "netcdf_write_frame_base nf90_put_var Q_varid" ) ! end if end select @@ -1264,59 +1269,59 @@ module subroutine netcdf_write_frame_base(self, iu, param) end associate class is (swiftest_cb) idslot = self%id + 1 - call check( nf90_put_var(iu%ncid, iu%id_varid, self%id, start=[idslot]), "netcdf_write_frame_base nf90_put_var cb id_varid" ) + call check( nf90_put_var(nciu%id, nciu%id_varid, self%id, start=[idslot]), "netcdf_write_frame_base nf90_put_var cb id_varid" ) - call check( nf90_put_var(iu%ncid, iu%Gmass_varid, self%Gmass, start=[idslot, tslot]), "netcdf_write_frame_base nf90_put_var cb Gmass_varid" ) - if (param%lclose) call check( nf90_put_var(iu%ncid, iu%radius_varid, self%radius, start=[idslot, tslot]), "netcdf_write_frame_base nf90_put_var cb radius_varid" ) - call check( nf90_put_var(iu%ncid, iu%j2rp2_varid, self%j2rp2, start=[tslot]), "netcdf_write_frame_base nf90_put_var cb j2rp2_varid" ) - call check( nf90_put_var(iu%ncid, iu%j4rp4_varid, self%j4rp4, start=[tslot]), "netcdf_write_frame_base nf90_put_var cb j4rp4_varid" ) + call check( nf90_put_var(nciu%id, nciu%Gmass_varid, self%Gmass, start=[idslot, tslot]), "netcdf_write_frame_base nf90_put_var cb Gmass_varid" ) + if (param%lclose) call check( nf90_put_var(nciu%id, nciu%radius_varid, self%radius, start=[idslot, tslot]), "netcdf_write_frame_base nf90_put_var cb radius_varid" ) + call check( nf90_put_var(nciu%id, nciu%j2rp2_varid, self%j2rp2, start=[tslot]), "netcdf_write_frame_base nf90_put_var cb j2rp2_varid" ) + call check( nf90_put_var(nciu%id, nciu%j4rp4_varid, self%j4rp4, start=[tslot]), "netcdf_write_frame_base nf90_put_var cb j4rp4_varid" ) if (param%lrotation) then - call check( nf90_put_var(iu%ncid, iu%Ip1_varid, self%Ip(1), start=[idslot, tslot]), "netcdf_write_frame_base nf90_put_var cb Ip1_varid" ) - call check( nf90_put_var(iu%ncid, iu%Ip2_varid, self%Ip(2), start=[idslot, tslot]), "netcdf_write_frame_base nf90_put_var cb Ip2_varid" ) - call check( nf90_put_var(iu%ncid, iu%Ip3_varid, self%Ip(3), start=[idslot, tslot]), "netcdf_write_frame_base nf90_put_var cb Ip3_varid" ) - call check( nf90_put_var(iu%ncid, iu%rotx_varid, self%rot(1), start=[idslot, tslot]), "netcdf_write_frame_base nf90_put_var cb rotx_varid" ) - call check( nf90_put_var(iu%ncid, iu%roty_varid, self%rot(2), start=[idslot, tslot]), "netcdf_write_frame_base nf90_put_var cb roty_varid" ) - call check( nf90_put_var(iu%ncid, iu%rotz_varid, self%rot(3), start=[idslot, tslot]), "netcdf_write_frame_base nf90_put_var cb rotz_varid" ) + call check( nf90_put_var(nciu%id, nciu%Ip1_varid, self%Ip(1), start=[idslot, tslot]), "netcdf_write_frame_base nf90_put_var cb Ip1_varid" ) + call check( nf90_put_var(nciu%id, nciu%Ip2_varid, self%Ip(2), start=[idslot, tslot]), "netcdf_write_frame_base nf90_put_var cb Ip2_varid" ) + call check( nf90_put_var(nciu%id, nciu%Ip3_varid, self%Ip(3), start=[idslot, tslot]), "netcdf_write_frame_base nf90_put_var cb Ip3_varid" ) + call check( nf90_put_var(nciu%id, nciu%rotx_varid, self%rot(1), start=[idslot, tslot]), "netcdf_write_frame_base nf90_put_var cb rotx_varid" ) + call check( nf90_put_var(nciu%id, nciu%roty_varid, self%rot(2), start=[idslot, tslot]), "netcdf_write_frame_base nf90_put_var cb roty_varid" ) + call check( nf90_put_var(nciu%id, nciu%rotz_varid, self%rot(3), start=[idslot, tslot]), "netcdf_write_frame_base nf90_put_var cb rotz_varid" ) end if ! if (param%ltides) then - ! call check( nf90_put_var(iu%ncid, iu%k2_varid, self%k2, start=[idslot, tslot]), "netcdf_write_frame_base nf90_put_var cb k2_varid" ) - ! call check( nf90_put_var(iu%ncid, iu%Q_varid, self%Q, start=[idslot, tslot]), "netcdf_write_frame_base nf90_put_var cb Q_varid" ) + ! call check( nf90_put_var(nciu%id, nciu%k2_varid, self%k2, start=[idslot, tslot]), "netcdf_write_frame_base nf90_put_var cb k2_varid" ) + ! call check( nf90_put_var(nciu%id, nciu%Q_varid, self%Q, start=[idslot, tslot]), "netcdf_write_frame_base nf90_put_var cb Q_varid" ) ! end if end select - call check( nf90_set_fill(iu%ncid, old_mode, old_mode), "netcdf_write_frame_base nf90_set_fill old_mode" ) + call check( nf90_set_fill(nciu%id, old_mode, old_mode), "netcdf_write_frame_base nf90_set_fill old_mode" ) return end subroutine netcdf_write_frame_base - module subroutine netcdf_write_frame_system(self, iu, param) + module subroutine netcdf_write_frame_system(self, nciu, param) !! author: The Purdue Swiftest Team - David A. Minton, Carlisle A. Wishard, Jennifer L.L. Pouplin, and Jacob R. Elliott !! !! Write a frame (header plus records for each massive body and active test particle) to a output binary file implicit none ! Arguments class(swiftest_nbody_system), intent(inout) :: self !! Swiftest system object - class(netcdf_parameters), intent(inout) :: iu !! Parameters used to identify a particular NetCDF dataset + class(netcdf_parameters), intent(inout) :: nciu !! Parameters used to identify a particular NetCDF dataset class(swiftest_parameters), intent(inout) :: param !! Current run configuration parameters - call self%write_hdr(iu, param) - call self%cb%write_frame(iu, param) - call self%pl%write_frame(iu, param) - call self%tp%write_frame(iu, param) + call self%write_hdr(nciu, param) + call self%cb%write_frame(nciu, param) + call self%pl%write_frame(nciu, param) + call self%tp%write_frame(nciu, param) return end subroutine netcdf_write_frame_system - module subroutine netcdf_write_info_base(self, iu, param) + module subroutine netcdf_write_info_base(self, nciu, param) !! author: Carlisle A. Wishard, Dana Singh, and David A. Minton !! !! Write all current particle to file implicit none ! Arguments class(swiftest_base), intent(in) :: self !! Swiftest particle object - class(netcdf_parameters), intent(inout) :: iu !! Parameters used to identify a particular NetCDF dataset + class(netcdf_parameters), intent(inout) :: nciu !! Parameters used to identify a particular NetCDF dataset class(swiftest_parameters), intent(inout) :: param !! Current run configuration parameters ! Internals integer(I4B) :: i, j, idslot, old_mode @@ -1324,7 +1329,7 @@ module subroutine netcdf_write_info_base(self, iu, param) character(len=NAMELEN) :: charstring ! This string of spaces of length NAMELEN is used to clear out any old data left behind inside the string variables - call check( nf90_set_fill(iu%ncid, nf90_nofill, old_mode), "netcdf_write_info_base nf90_set_fill nf90_nofill" ) + call check( nf90_set_fill(nciu%id, nf90_nofill, old_mode), "netcdf_write_info_base nf90_set_fill nf90_nofill" ) select type(self) class is (swiftest_body) @@ -1335,36 +1340,36 @@ module subroutine netcdf_write_info_base(self, iu, param) do i = 1, n j = ind(i) idslot = self%id(j) + 1 - call check( nf90_put_var(iu%ncid, iu%id_varid, self%id(j), start=[idslot]), "netcdf_write_info_base nf90_put_var id_varid" ) + call check( nf90_put_var(nciu%id, nciu%id_varid, self%id(j), start=[idslot]), "netcdf_write_info_base nf90_put_var id_varid" ) charstring = trim(adjustl(self%info(j)%name)) - call check( nf90_put_var(iu%ncid, iu%name_varid, charstring, start=[1, idslot], count=[NAMELEN, 1]), "netcdf_write_info_base nf90_put_var name_varid" ) + call check( nf90_put_var(nciu%id, nciu%name_varid, charstring, start=[1, idslot], count=[NAMELEN, 1]), "netcdf_write_info_base nf90_put_var name_varid" ) charstring = trim(adjustl(self%info(j)%particle_type)) - call check( nf90_put_var(iu%ncid, iu%ptype_varid, charstring, start=[1, idslot], count=[NAMELEN, 1]), "netcdf_write_info_base nf90_put_var particle_type_varid" ) + call check( nf90_put_var(nciu%id, nciu%ptype_varid, charstring, start=[1, idslot], count=[NAMELEN, 1]), "netcdf_write_info_base nf90_put_var particle_type_varid" ) charstring = trim(adjustl(self%info(j)%status)) - call check( nf90_put_var(iu%ncid, iu%status_varid, charstring, start=[1, idslot], count=[NAMELEN, 1]), "netcdf_write_info_base nf90_put_var status_varid" ) + call check( nf90_put_var(nciu%id, nciu%status_varid, charstring, start=[1, idslot], count=[NAMELEN, 1]), "netcdf_write_info_base nf90_put_var status_varid" ) if (param%lclose) then charstring = trim(adjustl(self%info(j)%origin_type)) - call check( nf90_put_var(iu%ncid, iu%origin_type_varid, charstring, start=[1, idslot], count=[NAMELEN, 1]), "netcdf_write_info_base nf90_put_var origin_type_varid" ) - call check( nf90_put_var(iu%ncid, iu%origin_time_varid, self%info(j)%origin_time, start=[idslot]), "netcdf_write_info_base nf90_put_var origin_time_varid" ) - call check( nf90_put_var(iu%ncid, iu%origin_xhx_varid, self%info(j)%origin_xh(1), start=[idslot]), "netcdf_write_info_base nf90_put_var origin_xhx_varid" ) - call check( nf90_put_var(iu%ncid, iu%origin_xhy_varid, self%info(j)%origin_xh(2), start=[idslot]), "netcdf_write_info_base nf90_put_var origin_xhy_varid" ) - call check( nf90_put_var(iu%ncid, iu%origin_xhz_varid, self%info(j)%origin_xh(3), start=[idslot]), "netcdf_write_info_base nf90_put_var origin_xhz_varid" ) - call check( nf90_put_var(iu%ncid, iu%origin_vhx_varid, self%info(j)%origin_vh(1), start=[idslot]), "netcdf_write_info_base nf90_put_var origin_vhx_varid" ) - call check( nf90_put_var(iu%ncid, iu%origin_vhy_varid, self%info(j)%origin_vh(2), start=[idslot]), "netcdf_write_info_base nf90_put_var origin_vhy_varid" ) - call check( nf90_put_var(iu%ncid, iu%origin_vhz_varid, self%info(j)%origin_vh(3), start=[idslot]), "netcdf_write_info_base nf90_put_var origin_vhz_varid" ) + call check( nf90_put_var(nciu%id, nciu%origin_type_varid, charstring, start=[1, idslot], count=[NAMELEN, 1]), "netcdf_write_info_base nf90_put_var origin_type_varid" ) + call check( nf90_put_var(nciu%id, nciu%origin_time_varid, self%info(j)%origin_time, start=[idslot]), "netcdf_write_info_base nf90_put_var origin_time_varid" ) + call check( nf90_put_var(nciu%id, nciu%origin_xhx_varid, self%info(j)%origin_xh(1), start=[idslot]), "netcdf_write_info_base nf90_put_var origin_xhx_varid" ) + call check( nf90_put_var(nciu%id, nciu%origin_xhy_varid, self%info(j)%origin_xh(2), start=[idslot]), "netcdf_write_info_base nf90_put_var origin_xhy_varid" ) + call check( nf90_put_var(nciu%id, nciu%origin_xhz_varid, self%info(j)%origin_xh(3), start=[idslot]), "netcdf_write_info_base nf90_put_var origin_xhz_varid" ) + call check( nf90_put_var(nciu%id, nciu%origin_vhx_varid, self%info(j)%origin_vh(1), start=[idslot]), "netcdf_write_info_base nf90_put_var origin_vhx_varid" ) + call check( nf90_put_var(nciu%id, nciu%origin_vhy_varid, self%info(j)%origin_vh(2), start=[idslot]), "netcdf_write_info_base nf90_put_var origin_vhy_varid" ) + call check( nf90_put_var(nciu%id, nciu%origin_vhz_varid, self%info(j)%origin_vh(3), start=[idslot]), "netcdf_write_info_base nf90_put_var origin_vhz_varid" ) - call check( nf90_put_var(iu%ncid, iu%collision_id_varid, self%info(j)%collision_id, start=[idslot]), "netcdf_write_info_base nf90_put_var collision_id_varid" ) - call check( nf90_put_var(iu%ncid, iu%discard_time_varid, self%info(j)%discard_time, start=[idslot]), "netcdf_write_info_base nf90_put_var discard_time_varid" ) - call check( nf90_put_var(iu%ncid, iu%discard_xhx_varid, self%info(j)%discard_xh(1), start=[idslot]), "netcdf_write_info_base nf90_put_var discard_xhx_varid" ) - call check( nf90_put_var(iu%ncid, iu%discard_xhy_varid, self%info(j)%discard_xh(2), start=[idslot]), "netcdf_write_info_base nf90_put_var discard_xhy_varid" ) - call check( nf90_put_var(iu%ncid, iu%discard_xhz_varid, self%info(j)%discard_xh(3), start=[idslot]), "netcdf_write_info_base nf90_put_var discard_xhz_varid" ) - call check( nf90_put_var(iu%ncid, iu%discard_vhx_varid, self%info(j)%discard_vh(1), start=[idslot]), "netcdf_write_info_base nf90_put_var discard_vhx_varid" ) - call check( nf90_put_var(iu%ncid, iu%discard_vhy_varid, self%info(j)%discard_vh(2), start=[idslot]), "netcdf_write_info_base nf90_put_var discard_vhy_varid" ) - call check( nf90_put_var(iu%ncid, iu%discard_vhz_varid, self%info(j)%discard_vh(3), start=[idslot]), "netcdf_write_info_base nf90_put_var discard_vhz_varid" ) + call check( nf90_put_var(nciu%id, nciu%collision_id_varid, self%info(j)%collision_id, start=[idslot]), "netcdf_write_info_base nf90_put_var collision_id_varid" ) + call check( nf90_put_var(nciu%id, nciu%discard_time_varid, self%info(j)%discard_time, start=[idslot]), "netcdf_write_info_base nf90_put_var discard_time_varid" ) + call check( nf90_put_var(nciu%id, nciu%discard_xhx_varid, self%info(j)%discard_xh(1), start=[idslot]), "netcdf_write_info_base nf90_put_var discard_xhx_varid" ) + call check( nf90_put_var(nciu%id, nciu%discard_xhy_varid, self%info(j)%discard_xh(2), start=[idslot]), "netcdf_write_info_base nf90_put_var discard_xhy_varid" ) + call check( nf90_put_var(nciu%id, nciu%discard_xhz_varid, self%info(j)%discard_xh(3), start=[idslot]), "netcdf_write_info_base nf90_put_var discard_xhz_varid" ) + call check( nf90_put_var(nciu%id, nciu%discard_vhx_varid, self%info(j)%discard_vh(1), start=[idslot]), "netcdf_write_info_base nf90_put_var discard_vhx_varid" ) + call check( nf90_put_var(nciu%id, nciu%discard_vhy_varid, self%info(j)%discard_vh(2), start=[idslot]), "netcdf_write_info_base nf90_put_var discard_vhy_varid" ) + call check( nf90_put_var(nciu%id, nciu%discard_vhz_varid, self%info(j)%discard_vh(3), start=[idslot]), "netcdf_write_info_base nf90_put_var discard_vhz_varid" ) end if end do @@ -1372,47 +1377,47 @@ module subroutine netcdf_write_info_base(self, iu, param) class is (swiftest_cb) idslot = self%id + 1 - call check( nf90_put_var(iu%ncid, iu%id_varid, self%id, start=[idslot]), "netcdf_write_info_base nf90_put_var cb id_varid" ) + call check( nf90_put_var(nciu%id, nciu%id_varid, self%id, start=[idslot]), "netcdf_write_info_base nf90_put_var cb id_varid" ) charstring = trim(adjustl(self%info%name)) - call check( nf90_put_var(iu%ncid, iu%name_varid, charstring, start=[1, idslot], count=[NAMELEN, 1]), "netcdf_write_info_base nf90_put_var cb name_varid" ) + call check( nf90_put_var(nciu%id, nciu%name_varid, charstring, start=[1, idslot], count=[NAMELEN, 1]), "netcdf_write_info_base nf90_put_var cb name_varid" ) charstring = trim(adjustl(self%info%particle_type)) - call check( nf90_put_var(iu%ncid, iu%ptype_varid, charstring, start=[1, idslot], count=[NAMELEN, 1]), "netcdf_write_info_base nf90_put_var cb ptype_varid" ) + call check( nf90_put_var(nciu%id, nciu%ptype_varid, charstring, start=[1, idslot], count=[NAMELEN, 1]), "netcdf_write_info_base nf90_put_var cb ptype_varid" ) charstring = trim(adjustl(self%info%status)) - call check( nf90_put_var(iu%ncid, iu%status_varid, charstring, start=[1, idslot], count=[NAMELEN, 1]), "netcdf_write_info_base nf90_put_var cb status_varid" ) + call check( nf90_put_var(nciu%id, nciu%status_varid, charstring, start=[1, idslot], count=[NAMELEN, 1]), "netcdf_write_info_base nf90_put_var cb status_varid" ) if (param%lclose) then charstring = trim(adjustl(self%info%origin_type)) - call check( nf90_put_var(iu%ncid, iu%origin_type_varid, charstring, start=[1, idslot], count=[NAMELEN, 1]), "netcdf_write_info_base nf90_put_var cb origin_type_varid" ) - - call check( nf90_put_var(iu%ncid, iu%origin_time_varid, self%info%origin_time, start=[idslot]), "netcdf_write_info_base nf90_put_var cb origin_time_varid" ) - call check( nf90_put_var(iu%ncid, iu%origin_xhx_varid, self%info%origin_xh(1), start=[idslot]), "netcdf_write_info_base nf90_put_var cb origin_xhx_varid" ) - call check( nf90_put_var(iu%ncid, iu%origin_xhy_varid, self%info%origin_xh(2), start=[idslot]), "netcdf_write_info_base nf90_put_var cb origin_xhy_varid" ) - call check( nf90_put_var(iu%ncid, iu%origin_xhz_varid, self%info%origin_xh(3), start=[idslot]), "netcdf_write_info_base nf90_put_var cb origin_xhz_varid" ) - call check( nf90_put_var(iu%ncid, iu%origin_vhx_varid, self%info%origin_vh(1), start=[idslot]), "netcdf_write_info_base nf90_put_var cb origin_vhx_varid" ) - call check( nf90_put_var(iu%ncid, iu%origin_vhy_varid, self%info%origin_vh(2), start=[idslot]), "netcdf_write_info_base nf90_put_var cb origin_vhy_varid" ) - call check( nf90_put_var(iu%ncid, iu%origin_vhz_varid, self%info%origin_vh(3), start=[idslot]), "netcdf_write_info_base nf90_put_var cb origin_vhz_varid" ) + call check( nf90_put_var(nciu%id, nciu%origin_type_varid, charstring, start=[1, idslot], count=[NAMELEN, 1]), "netcdf_write_info_base nf90_put_var cb origin_type_varid" ) + + call check( nf90_put_var(nciu%id, nciu%origin_time_varid, self%info%origin_time, start=[idslot]), "netcdf_write_info_base nf90_put_var cb origin_time_varid" ) + call check( nf90_put_var(nciu%id, nciu%origin_xhx_varid, self%info%origin_xh(1), start=[idslot]), "netcdf_write_info_base nf90_put_var cb origin_xhx_varid" ) + call check( nf90_put_var(nciu%id, nciu%origin_xhy_varid, self%info%origin_xh(2), start=[idslot]), "netcdf_write_info_base nf90_put_var cb origin_xhy_varid" ) + call check( nf90_put_var(nciu%id, nciu%origin_xhz_varid, self%info%origin_xh(3), start=[idslot]), "netcdf_write_info_base nf90_put_var cb origin_xhz_varid" ) + call check( nf90_put_var(nciu%id, nciu%origin_vhx_varid, self%info%origin_vh(1), start=[idslot]), "netcdf_write_info_base nf90_put_var cb origin_vhx_varid" ) + call check( nf90_put_var(nciu%id, nciu%origin_vhy_varid, self%info%origin_vh(2), start=[idslot]), "netcdf_write_info_base nf90_put_var cb origin_vhy_varid" ) + call check( nf90_put_var(nciu%id, nciu%origin_vhz_varid, self%info%origin_vh(3), start=[idslot]), "netcdf_write_info_base nf90_put_var cb origin_vhz_varid" ) - call check( nf90_put_var(iu%ncid, iu%collision_id_varid, self%info%collision_id, start=[idslot]), "netcdf_write_info_base nf90_put_var cb collision_id_varid" ) - call check( nf90_put_var(iu%ncid, iu%discard_time_varid, self%info%discard_time, start=[idslot]), "netcdf_write_info_base nf90_put_var cb discard_time_varid" ) - call check( nf90_put_var(iu%ncid, iu%discard_xhx_varid, self%info%discard_xh(1), start=[idslot]), "netcdf_write_info_base nf90_put_var cb discard_xhx_varid" ) - call check( nf90_put_var(iu%ncid, iu%discard_xhy_varid, self%info%discard_xh(2), start=[idslot]), "netcdf_write_info_base nf90_put_var cb discard_xhy_varid" ) - call check( nf90_put_var(iu%ncid, iu%discard_xhz_varid, self%info%discard_xh(3), start=[idslot]), "netcdf_write_info_base nf90_put_var cb discard_xhz_varid" ) - call check( nf90_put_var(iu%ncid, iu%discard_vhx_varid, self%info%discard_vh(1), start=[idslot]), "netcdf_write_info_base nf90_put_var cb discard_vhx_varid" ) - call check( nf90_put_var(iu%ncid, iu%discard_vhy_varid, self%info%discard_vh(2), start=[idslot]), "netcdf_write_info_base nf90_put_var cb discard_vhy_varid" ) - call check( nf90_put_var(iu%ncid, iu%discard_vhz_varid, self%info%discard_vh(3), start=[idslot]), "netcdf_write_info_base nf90_put_var cb discard_vhz_varid" ) + call check( nf90_put_var(nciu%id, nciu%collision_id_varid, self%info%collision_id, start=[idslot]), "netcdf_write_info_base nf90_put_var cb collision_id_varid" ) + call check( nf90_put_var(nciu%id, nciu%discard_time_varid, self%info%discard_time, start=[idslot]), "netcdf_write_info_base nf90_put_var cb discard_time_varid" ) + call check( nf90_put_var(nciu%id, nciu%discard_xhx_varid, self%info%discard_xh(1), start=[idslot]), "netcdf_write_info_base nf90_put_var cb discard_xhx_varid" ) + call check( nf90_put_var(nciu%id, nciu%discard_xhy_varid, self%info%discard_xh(2), start=[idslot]), "netcdf_write_info_base nf90_put_var cb discard_xhy_varid" ) + call check( nf90_put_var(nciu%id, nciu%discard_xhz_varid, self%info%discard_xh(3), start=[idslot]), "netcdf_write_info_base nf90_put_var cb discard_xhz_varid" ) + call check( nf90_put_var(nciu%id, nciu%discard_vhx_varid, self%info%discard_vh(1), start=[idslot]), "netcdf_write_info_base nf90_put_var cb discard_vhx_varid" ) + call check( nf90_put_var(nciu%id, nciu%discard_vhy_varid, self%info%discard_vh(2), start=[idslot]), "netcdf_write_info_base nf90_put_var cb discard_vhy_varid" ) + call check( nf90_put_var(nciu%id, nciu%discard_vhz_varid, self%info%discard_vh(3), start=[idslot]), "netcdf_write_info_base nf90_put_var cb discard_vhz_varid" ) end if end select - call check( nf90_set_fill(iu%ncid, old_mode, old_mode) ) + call check( nf90_set_fill(nciu%id, old_mode, old_mode) ) return end subroutine netcdf_write_info_base - module subroutine netcdf_write_hdr_system(self, iu, param) + module subroutine netcdf_write_hdr_system(self, nciu, param) !! author: David A. Minton !! !! Writes header information (variables that change with time, but not particle id). @@ -1421,37 +1426,37 @@ module subroutine netcdf_write_hdr_system(self, iu, param) implicit none ! Arguments class(swiftest_nbody_system), intent(in) :: self !! Swiftest nbody system object - class(netcdf_parameters), intent(inout) :: iu !! Parameters used to for writing a NetCDF dataset to file + class(netcdf_parameters), intent(inout) :: nciu !! Parameters used to for writing a NetCDF dataset to file class(swiftest_parameters), intent(inout) :: param !! Current run configuration parameters ! Internals integer(I4B) :: tslot tslot = param%ioutput + 1 - call check( nf90_put_var(iu%ncid, iu%time_varid, self%t, start=[tslot]), "netcdf_write_hdr_system nf90_put_var time_varid" ) - call check( nf90_put_var(iu%ncid, iu%npl_varid, self%pl%nbody, start=[tslot]), "netcdf_write_hdr_system nf90_put_var npl_varid" ) - call check( nf90_put_var(iu%ncid, iu%ntp_varid, self%tp%nbody, start=[tslot]), "netcdf_write_hdr_system nf90_put_var ntp_varid" ) + call check( nf90_put_var(nciu%id, nciu%time_varid, self%t, start=[tslot]), "netcdf_write_hdr_system nf90_put_var time_varid" ) + call check( nf90_put_var(nciu%id, nciu%npl_varid, self%pl%nbody, start=[tslot]), "netcdf_write_hdr_system nf90_put_var npl_varid" ) + call check( nf90_put_var(nciu%id, nciu%ntp_varid, self%tp%nbody, start=[tslot]), "netcdf_write_hdr_system nf90_put_var ntp_varid" ) select type(pl => self%pl) class is (symba_pl) - call check( nf90_put_var(iu%ncid, iu%nplm_varid, pl%nplm, start=[tslot]), "netcdf_write_hdr_system nf90_put_var nplm_varid" ) + call check( nf90_put_var(nciu%id, nciu%nplm_varid, pl%nplm, start=[tslot]), "netcdf_write_hdr_system nf90_put_var nplm_varid" ) end select if (param%lenergy) then - call check( nf90_put_var(iu%ncid, iu%KE_orb_varid, self%ke_orbit, start=[tslot]), "netcdf_write_hdr_system nf90_put_var KE_orb_varid" ) - call check( nf90_put_var(iu%ncid, iu%KE_spin_varid, self%ke_spin, start=[tslot]), "netcdf_write_hdr_system nf90_put_var KE_spin_varid" ) - call check( nf90_put_var(iu%ncid, iu%PE_varid, self%pe, start=[tslot]), "netcdf_write_hdr_system nf90_put_var PE_varid" ) - call check( nf90_put_var(iu%ncid, iu%L_orbx_varid, self%Lorbit(1), start=[tslot]), "netcdf_write_hdr_system nf90_put_var L_orbx_varid" ) - call check( nf90_put_var(iu%ncid, iu%L_orby_varid, self%Lorbit(2), start=[tslot]), "netcdf_write_hdr_system nf90_put_var L_orby_varid" ) - call check( nf90_put_var(iu%ncid, iu%L_orbz_varid, self%Lorbit(3), start=[tslot]), "netcdf_write_hdr_system nf90_put_var L_orbz_varid" ) - call check( nf90_put_var(iu%ncid, iu%L_spinx_varid, self%Lspin(1), start=[tslot]), "netcdf_write_hdr_system nf90_put_var L_spinx_varid" ) - call check( nf90_put_var(iu%ncid, iu%L_spiny_varid, self%Lspin(2), start=[tslot]), "netcdf_write_hdr_system nf90_put_var L_spiny_varid" ) - call check( nf90_put_var(iu%ncid, iu%L_spinz_varid, self%Lspin(3), start=[tslot]), "netcdf_write_hdr_system nf90_put_var L_spinz_varid" ) - call check( nf90_put_var(iu%ncid, iu%L_escapex_varid, self%Lescape(1), start=[tslot]), "netcdf_write_hdr_system nf90_put_var L_escapex_varid" ) - call check( nf90_put_var(iu%ncid, iu%L_escapey_varid, self%Lescape(2), start=[tslot]), "netcdf_write_hdr_system nf90_put_var L_escapey_varid" ) - call check( nf90_put_var(iu%ncid, iu%L_escapez_varid, self%Lescape(3), start=[tslot]), "netcdf_write_hdr_system nf90_put_var L_escapez_varid" ) - call check( nf90_put_var(iu%ncid, iu%Ecollisions_varid, self%Ecollisions, start=[tslot]), "netcdf_write_hdr_system nf90_put_var Ecollisions_varid" ) - call check( nf90_put_var(iu%ncid, iu%Euntracked_varid, self%Euntracked, start=[tslot]), "netcdf_write_hdr_system nf90_put_var Euntracked_varid" ) - call check( nf90_put_var(iu%ncid, iu%GMescape_varid, self%GMescape, start=[tslot]), "netcdf_write_hdr_system nf90_put_var GMescape_varid" ) + call check( nf90_put_var(nciu%id, nciu%KE_orb_varid, self%ke_orbit, start=[tslot]), "netcdf_write_hdr_system nf90_put_var KE_orb_varid" ) + call check( nf90_put_var(nciu%id, nciu%KE_spin_varid, self%ke_spin, start=[tslot]), "netcdf_write_hdr_system nf90_put_var KE_spin_varid" ) + call check( nf90_put_var(nciu%id, nciu%PE_varid, self%pe, start=[tslot]), "netcdf_write_hdr_system nf90_put_var PE_varid" ) + call check( nf90_put_var(nciu%id, nciu%L_orbx_varid, self%Lorbit(1), start=[tslot]), "netcdf_write_hdr_system nf90_put_var L_orbx_varid" ) + call check( nf90_put_var(nciu%id, nciu%L_orby_varid, self%Lorbit(2), start=[tslot]), "netcdf_write_hdr_system nf90_put_var L_orby_varid" ) + call check( nf90_put_var(nciu%id, nciu%L_orbz_varid, self%Lorbit(3), start=[tslot]), "netcdf_write_hdr_system nf90_put_var L_orbz_varid" ) + call check( nf90_put_var(nciu%id, nciu%L_spinx_varid, self%Lspin(1), start=[tslot]), "netcdf_write_hdr_system nf90_put_var L_spinx_varid" ) + call check( nf90_put_var(nciu%id, nciu%L_spiny_varid, self%Lspin(2), start=[tslot]), "netcdf_write_hdr_system nf90_put_var L_spiny_varid" ) + call check( nf90_put_var(nciu%id, nciu%L_spinz_varid, self%Lspin(3), start=[tslot]), "netcdf_write_hdr_system nf90_put_var L_spinz_varid" ) + call check( nf90_put_var(nciu%id, nciu%L_escapex_varid, self%Lescape(1), start=[tslot]), "netcdf_write_hdr_system nf90_put_var L_escapex_varid" ) + call check( nf90_put_var(nciu%id, nciu%L_escapey_varid, self%Lescape(2), start=[tslot]), "netcdf_write_hdr_system nf90_put_var L_escapey_varid" ) + call check( nf90_put_var(nciu%id, nciu%L_escapez_varid, self%Lescape(3), start=[tslot]), "netcdf_write_hdr_system nf90_put_var L_escapez_varid" ) + call check( nf90_put_var(nciu%id, nciu%Ecollisions_varid, self%Ecollisions, start=[tslot]), "netcdf_write_hdr_system nf90_put_var Ecollisions_varid" ) + call check( nf90_put_var(nciu%id, nciu%Euntracked_varid, self%Euntracked, start=[tslot]), "netcdf_write_hdr_system nf90_put_var Euntracked_varid" ) + call check( nf90_put_var(nciu%id, nciu%GMescape_varid, self%GMescape, start=[tslot]), "netcdf_write_hdr_system nf90_put_var GMescape_varid" ) end if return diff --git a/src/symba/symba_encounter_check.f90 b/src/symba/symba_encounter_check.f90 index f07119dba..1cfa81c88 100644 --- a/src/symba/symba_encounter_check.f90 +++ b/src/symba/symba_encounter_check.f90 @@ -119,7 +119,7 @@ module function symba_encounter_check(self, param, system, dt, irec) result(lany logical :: isplpl real(DP) :: rlim2, rji2, rcrit12 logical, dimension(:), allocatable :: lencmask, lencounter - integer(I4B), dimension(:), allocatable :: encidx + integer(I4B), dimension(:), allocatable :: eidx lany_encounter = .false. if (self%nenc == 0) return @@ -142,13 +142,13 @@ module function symba_encounter_check(self, param, system, dt, irec) result(lany call pl%set_renc(irec) - allocate(encidx(nenc_enc)) + allocate(eidx(nenc_enc)) allocate(lencounter(nenc_enc)) - encidx(:) = pack([(k, k = 1, self%nenc)], lencmask(:)) + eidx(:) = pack([(k, k = 1, self%nenc)], lencmask(:)) lencounter(:) = .false. if (isplpl) then do concurrent(lidx = 1:nenc_enc) - k = encidx(lidx) + k = eidx(lidx) i = self%index1(k) j = self%index2(k) xr(:) = pl%xh(:,j) - pl%xh(:,i) @@ -163,7 +163,7 @@ module function symba_encounter_check(self, param, system, dt, irec) result(lany end do else do concurrent(lidx = 1:nenc_enc) - k = encidx(lidx) + k = eidx(lidx) i = self%index1(k) j = self%index2(k) xr(:) = tp%xh(:,j) - pl%xh(:,i) @@ -180,9 +180,9 @@ module function symba_encounter_check(self, param, system, dt, irec) result(lany lany_encounter = any(lencounter(:)) if (lany_encounter) then nenc_enc = count(lencounter(:)) - encidx(1:nenc_enc) = pack(encidx(:), lencounter(:)) + eidx(1:nenc_enc) = pack(eidx(:), lencounter(:)) do lidx = 1, nenc_enc - k = encidx(lidx) + k = eidx(lidx) i = self%index1(k) j = self%index2(k) pl%levelg(i) = irec From d4ff657f433e68e26a7705ce5d03ae961e7bb772 Mon Sep 17 00:00:00 2001 From: David A Minton Date: Sat, 3 Dec 2022 07:09:44 -0500 Subject: [PATCH 34/65] Continued to refactor netcdf --- src/netcdf/netcdf.f90 | 234 +++++++++++++++++++++--------------------- 1 file changed, 119 insertions(+), 115 deletions(-) diff --git a/src/netcdf/netcdf.f90 b/src/netcdf/netcdf.f90 index a01482202..dca6d7dbf 100644 --- a/src/netcdf/netcdf.f90 +++ b/src/netcdf/netcdf.f90 @@ -367,133 +367,137 @@ module subroutine netcdf_open(self, param, readonly) if (readonly) mode = NF90_NOWRITE end if - write(errmsg,*) "netcdf_open nf90_open ",trim(adjustl(param%outfile)) - call check( nf90_open(param%outfile, mode, self%id), errmsg) - - ! Dimensions - call check( nf90_inq_dimid(self%id, self%time_dimname, self%time_dimid), "netcdf_open nf90_inq_dimid time_dimid" ) - call check( nf90_inq_dimid(self%id, self%id_dimname, self%id_dimid), "netcdf_open nf90_inq_dimid id_dimid" ) - call check( nf90_inq_dimid(self%id, self%space_dimname, self%space_dimid), "netcdf_open nf90_inq_dimid space_dimid" ) - call check( nf90_inq_dimid(self%id, self%str_dimname, self%str_dimid), "netcdf_open nf90_inq_dimid str_dimid" ) - - ! Dimension coordinates - call check( nf90_inq_varid(self%id, self%time_dimname, self%time_varid), "netcdf_open nf90_inq_varid time_varid" ) - call check( nf90_inq_varid(self%id, self%id_dimname, self%id_varid), "netcdf_open nf90_inq_varid id_varid" ) - call check( nf90_inq_varid(self%id, self%space_dimname, self%space_varid), "netcdf_open nf90_inq_varid space_varid" ) - - ! Required Variables - call check( nf90_inq_varid(self%id, self%name_varname, self%name_varid), "netcdf_open nf90_inq_varid name_varid" ) - call check( nf90_inq_varid(self%id, self%ptype_varname, self%ptype_varid), "netcdf_open nf90_inq_varid ptype_varid" ) - call check( nf90_inq_varid(self%id, self%gmass_varname, self%Gmass_varid), "netcdf_open nf90_inq_varid Gmass_varid" ) - - if ((param%out_form == "XV") .or. (param%out_form == "XVEL")) then - call check( nf90_inq_varid(self%id, self%xhx_varname, self%xhx_varid), "netcdf_open nf90_inq_varid xhx_varid" ) - call check( nf90_inq_varid(self%id, self%xhy_varname, self%xhy_varid), "netcdf_open nf90_inq_varid xhy_varid" ) - call check( nf90_inq_varid(self%id, self%xhz_varname, self%xhz_varid), "netcdf_open nf90_inq_varid xhz_varid" ) - call check( nf90_inq_varid(self%id, self%vhx_varname, self%vhx_varid), "netcdf_open nf90_inq_varid vhx_varid" ) - call check( nf90_inq_varid(self%id, self%vhy_varname, self%vhy_varid), "netcdf_open nf90_inq_varid vhy_varid" ) - call check( nf90_inq_varid(self%id, self%vhz_varname, self%vhz_varid), "netcdf_open nf90_inq_varid vhz_varid" ) - - if (param%lgr) then - !! check if pseudovelocity vectors exist in this file. If they are, set the correct flag so we know whe should not do the conversion. - status = nf90_inq_varid(self%id, self%gr_pseudo_vhx_varname, self%gr_pseudo_vhx_varid) - self%lpseudo_vel_exists = (status == nf90_noerr) - if (self%lpseudo_vel_exists) then - status = nf90_inq_varid(self%id, self%gr_pseudo_vhy_varname, self%gr_pseudo_vhy_varid) - self%lpseudo_vel_exists = (status == nf90_noerr) - if (self%lpseudo_vel_exists) then - status = nf90_inq_varid(self%id, self%gr_pseudo_vhz_varname, self%gr_pseudo_vhz_varid) - self%lpseudo_vel_exists = (status == nf90_noerr) + associate(nciu => self) + + write(errmsg,*) "netcdf_open nf90_open ",trim(adjustl(param%outfile)) + call check( nf90_open(param%outfile, mode, nciu%id), errmsg) + + ! Dimensions + call check( nf90_inq_dimid(nciu%id, nciu%time_dimname, nciu%time_dimid), "netcdf_open nf90_inq_dimid time_dimid" ) + call check( nf90_inq_dimid(nciu%id, nciu%id_dimname, nciu%id_dimid), "netcdf_open nf90_inq_dimid id_dimid" ) + call check( nf90_inq_dimid(nciu%id, nciu%space_dimname, nciu%space_dimid), "netcdf_open nf90_inq_dimid space_dimid" ) + call check( nf90_inq_dimid(nciu%id, nciu%str_dimname, nciu%str_dimid), "netcdf_open nf90_inq_dimid str_dimid" ) + + ! Dimension coordinates + call check( nf90_inq_varid(nciu%id, nciu%time_dimname, nciu%time_varid), "netcdf_open nf90_inq_varid time_varid" ) + call check( nf90_inq_varid(nciu%id, nciu%id_dimname, nciu%id_varid), "netcdf_open nf90_inq_varid id_varid" ) + call check( nf90_inq_varid(nciu%id, nciu%space_dimname, nciu%space_varid), "netcdf_open nf90_inq_varid space_varid" ) + + ! Required Variables + call check( nf90_inq_varid(nciu%id, nciu%name_varname, nciu%name_varid), "netcdf_open nf90_inq_varid name_varid" ) + call check( nf90_inq_varid(nciu%id, nciu%ptype_varname, nciu%ptype_varid), "netcdf_open nf90_inq_varid ptype_varid" ) + call check( nf90_inq_varid(nciu%id, nciu%gmass_varname, nciu%Gmass_varid), "netcdf_open nf90_inq_varid Gmass_varid" ) + + if ((param%out_form == "XV") .or. (param%out_form == "XVEL")) then + call check( nf90_inq_varid(nciu%id, nciu%xhx_varname, nciu%xhx_varid), "netcdf_open nf90_inq_varid xhx_varid" ) + call check( nf90_inq_varid(nciu%id, nciu%xhy_varname, nciu%xhy_varid), "netcdf_open nf90_inq_varid xhy_varid" ) + call check( nf90_inq_varid(nciu%id, nciu%xhz_varname, nciu%xhz_varid), "netcdf_open nf90_inq_varid xhz_varid" ) + call check( nf90_inq_varid(nciu%id, nciu%vhx_varname, nciu%vhx_varid), "netcdf_open nf90_inq_varid vhx_varid" ) + call check( nf90_inq_varid(nciu%id, nciu%vhy_varname, nciu%vhy_varid), "netcdf_open nf90_inq_varid vhy_varid" ) + call check( nf90_inq_varid(nciu%id, nciu%vhz_varname, nciu%vhz_varid), "netcdf_open nf90_inq_varid vhz_varid" ) + + if (param%lgr) then + !! check if pseudovelocity vectors exist in this file. If they are, set the correct flag so we know whe should not do the conversion. + status = nf90_inq_varid(nciu%id, nciu%gr_pseudo_vhx_varname, nciu%gr_pseudo_vhx_varid) + nciu%lpseudo_vel_exists = (status == nf90_noerr) + if (nciu%lpseudo_vel_exists) then + status = nf90_inq_varid(nciu%id, nciu%gr_pseudo_vhy_varname, nciu%gr_pseudo_vhy_varid) + nciu%lpseudo_vel_exists = (status == nf90_noerr) + if (nciu%lpseudo_vel_exists) then + status = nf90_inq_varid(nciu%id, nciu%gr_pseudo_vhz_varname, nciu%gr_pseudo_vhz_varid) + nciu%lpseudo_vel_exists = (status == nf90_noerr) + end if end if + if (.not.nciu%lpseudo_vel_exists) then + write(*,*) "Warning! Pseudovelocity not found in input file for GR enabled run. If this is a restarted run, bit-identical trajectories are not guarunteed!" + end if + end if - if (.not.self%lpseudo_vel_exists) then - write(*,*) "Warning! Pseudovelocity not found in input file for GR enabled run. If this is a restarted run, bit-identical trajectories are not guarunteed!" - end if + end if + if ((param%out_form == "EL") .or. (param%out_form == "XVEL")) then + call check( nf90_inq_varid(nciu%id, nciu%a_varname, nciu%a_varid), "netcdf_open nf90_inq_varid a_varid" ) + call check( nf90_inq_varid(nciu%id, nciu%e_varname, nciu%e_varid), "netcdf_open nf90_inq_varid e_varid" ) + call check( nf90_inq_varid(nciu%id, nciu%inc_varname, nciu%inc_varid), "netcdf_open nf90_inq_varid inc_varid" ) + call check( nf90_inq_varid(nciu%id, nciu%capom_varname, nciu%capom_varid), "netcdf_open nf90_inq_varid capom_varid" ) + call check( nf90_inq_varid(nciu%id, nciu%omega_varname, nciu%omega_varid), "netcdf_open nf90_inq_varid omega_varid" ) + call check( nf90_inq_varid(nciu%id, nciu%capm_varname, nciu%capm_varid), "netcdf_open nf90_inq_varid capm_varid" ) end if - end if - if ((param%out_form == "EL") .or. (param%out_form == "XVEL")) then - call check( nf90_inq_varid(self%id, self%a_varname, self%a_varid), "netcdf_open nf90_inq_varid a_varid" ) - call check( nf90_inq_varid(self%id, self%e_varname, self%e_varid), "netcdf_open nf90_inq_varid e_varid" ) - call check( nf90_inq_varid(self%id, self%inc_varname, self%inc_varid), "netcdf_open nf90_inq_varid inc_varid" ) - call check( nf90_inq_varid(self%id, self%capom_varname, self%capom_varid), "netcdf_open nf90_inq_varid capom_varid" ) - call check( nf90_inq_varid(self%id, self%omega_varname, self%omega_varid), "netcdf_open nf90_inq_varid omega_varid" ) - call check( nf90_inq_varid(self%id, self%capm_varname, self%capm_varid), "netcdf_open nf90_inq_varid capm_varid" ) - end if + if (param%lclose) then + call check( nf90_inq_varid(nciu%id, nciu%radius_varname, nciu%radius_varid), "netcdf_open nf90_inq_varid radius_varid" ) + end if - if (param%lclose) then - call check( nf90_inq_varid(self%id, self%radius_varname, self%radius_varid), "netcdf_open nf90_inq_varid radius_varid" ) - end if - - if (param%lrotation) then - call check( nf90_inq_varid(self%id, self%ip1_varname, self%Ip1_varid), "netcdf_open nf90_inq_varid Ip1_varid" ) - call check( nf90_inq_varid(self%id, self%ip2_varname, self%Ip2_varid), "netcdf_open nf90_inq_varid Ip2_varid" ) - call check( nf90_inq_varid(self%id, self%ip3_varname, self%Ip3_varid), "netcdf_open nf90_inq_varid Ip3_varid" ) - call check( nf90_inq_varid(self%id, self%rotx_varname, self%rotx_varid), "netcdf_open nf90_inq_varid rotx_varid" ) - call check( nf90_inq_varid(self%id, self%roty_varname, self%roty_varid), "netcdf_open nf90_inq_varid roty_varid" ) - call check( nf90_inq_varid(self%id, self%rotz_varname, self%rotz_varid), "netcdf_open nf90_inq_varid rotz_varid" ) - end if + if (param%lrotation) then + call check( nf90_inq_varid(nciu%id, nciu%ip1_varname, nciu%Ip1_varid), "netcdf_open nf90_inq_varid Ip1_varid" ) + call check( nf90_inq_varid(nciu%id, nciu%ip2_varname, nciu%Ip2_varid), "netcdf_open nf90_inq_varid Ip2_varid" ) + call check( nf90_inq_varid(nciu%id, nciu%ip3_varname, nciu%Ip3_varid), "netcdf_open nf90_inq_varid Ip3_varid" ) + call check( nf90_inq_varid(nciu%id, nciu%rotx_varname, nciu%rotx_varid), "netcdf_open nf90_inq_varid rotx_varid" ) + call check( nf90_inq_varid(nciu%id, nciu%roty_varname, nciu%roty_varid), "netcdf_open nf90_inq_varid roty_varid" ) + call check( nf90_inq_varid(nciu%id, nciu%rotz_varname, nciu%rotz_varid), "netcdf_open nf90_inq_varid rotz_varid" ) + end if - ! if (param%ltides) then - ! call check( nf90_inq_varid(self%id, self%k2_varname, self%k2_varid), "netcdf_open nf90_inq_varid k2_varid" ) - ! call check( nf90_inq_varid(self%id, self%q_varname, self%Q_varid), "netcdf_open nf90_inq_varid Q_varid" ) - ! end if + ! if (param%ltides) then + ! call check( nf90_inq_varid(nciu%id, nciu%k2_varname, nciu%k2_varid), "netcdf_open nf90_inq_varid k2_varid" ) + ! call check( nf90_inq_varid(nciu%id, nciu%q_varname, nciu%Q_varid), "netcdf_open nf90_inq_varid Q_varid" ) + ! end if - ! Optional Variables - if (param%lrhill_present) then - status = nf90_inq_varid(self%id, self%rhill_varname, self%rhill_varid) - if (status /= nf90_noerr) write(*,*) "Warning! RHILL variable not set in input file. Calculating." - end if + ! Optional Variables + if (param%lrhill_present) then + status = nf90_inq_varid(nciu%id, nciu%rhill_varname, nciu%rhill_varid) + if (status /= nf90_noerr) write(*,*) "Warning! RHILL variable not set in input file. Calculating." + end if - ! Optional variables The User Doesn't Need to Know About - status = nf90_inq_varid(self%id, self%npl_varname, self%npl_varid) - status = nf90_inq_varid(self%id, self%ntp_varname, self%ntp_varid) - status = nf90_inq_varid(self%id, self%status_varname, self%status_varid) - status = nf90_inq_varid(self%id, self%j2rp2_varname, self%j2rp2_varid) - status = nf90_inq_varid(self%id, self%j4rp4_varname, self%j4rp4_varid) + ! Optional variables The User Doesn't Need to Know About + status = nf90_inq_varid(nciu%id, nciu%npl_varname, nciu%npl_varid) + status = nf90_inq_varid(nciu%id, nciu%ntp_varname, nciu%ntp_varid) + status = nf90_inq_varid(nciu%id, nciu%status_varname, nciu%status_varid) + status = nf90_inq_varid(nciu%id, nciu%j2rp2_varname, nciu%j2rp2_varid) + status = nf90_inq_varid(nciu%id, nciu%j4rp4_varname, nciu%j4rp4_varid) - if (param%integrator == SYMBA) then - status = nf90_inq_varid(self%id, self%nplm_varname, self%nplm_varid) - end if + if (param%integrator == SYMBA) then + status = nf90_inq_varid(nciu%id, nciu%nplm_varname, nciu%nplm_varid) + end if - if (param%lclose) then - status = nf90_inq_varid(self%id, self%origin_type_varname, self%origin_type_varid) - status = nf90_inq_varid(self%id, self%origin_time_varname, self%origin_time_varid) - status = nf90_inq_varid(self%id, self%origin_xhx_varname, self%origin_xhx_varid) - status = nf90_inq_varid(self%id, self%origin_xhy_varname, self%origin_xhy_varid) - status = nf90_inq_varid(self%id, self%origin_xhz_varname, self%origin_xhz_varid) - status = nf90_inq_varid(self%id, self%origin_vhx_varname, self%origin_vhx_varid) - status = nf90_inq_varid(self%id, self%origin_vhy_varname, self%origin_vhy_varid) - status = nf90_inq_varid(self%id, self%origin_vhz_varname, self%origin_vhz_varid) - status = nf90_inq_varid(self%id, self%collision_id_varname, self%collision_id_varid) - status = nf90_inq_varid(self%id, self%discard_time_varname, self%discard_time_varid) - status = nf90_inq_varid(self%id, self%discard_xhx_varname, self%discard_xhx_varid) - status = nf90_inq_varid(self%id, self%discard_xhy_varname, self%discard_xhy_varid) - status = nf90_inq_varid(self%id, self%discard_xhz_varname, self%discard_xhz_varid) - status = nf90_inq_varid(self%id, self%discard_vhx_varname, self%discard_vhx_varid) - status = nf90_inq_varid(self%id, self%discard_vhy_varname, self%discard_vhy_varid) - status = nf90_inq_varid(self%id, self%discard_vhz_varname, self%discard_vhz_varid) - status = nf90_inq_varid(self%id, self%discard_body_id_varname, self%discard_body_id_varid) - end if + if (param%lclose) then + status = nf90_inq_varid(nciu%id, nciu%origin_type_varname, nciu%origin_type_varid) + status = nf90_inq_varid(nciu%id, nciu%origin_time_varname, nciu%origin_time_varid) + status = nf90_inq_varid(nciu%id, nciu%origin_xhx_varname, nciu%origin_xhx_varid) + status = nf90_inq_varid(nciu%id, nciu%origin_xhy_varname, nciu%origin_xhy_varid) + status = nf90_inq_varid(nciu%id, nciu%origin_xhz_varname, nciu%origin_xhz_varid) + status = nf90_inq_varid(nciu%id, nciu%origin_vhx_varname, nciu%origin_vhx_varid) + status = nf90_inq_varid(nciu%id, nciu%origin_vhy_varname, nciu%origin_vhy_varid) + status = nf90_inq_varid(nciu%id, nciu%origin_vhz_varname, nciu%origin_vhz_varid) + status = nf90_inq_varid(nciu%id, nciu%collision_id_varname, nciu%collision_id_varid) + status = nf90_inq_varid(nciu%id, nciu%discard_time_varname, nciu%discard_time_varid) + status = nf90_inq_varid(nciu%id, nciu%discard_xhx_varname, nciu%discard_xhx_varid) + status = nf90_inq_varid(nciu%id, nciu%discard_xhy_varname, nciu%discard_xhy_varid) + status = nf90_inq_varid(nciu%id, nciu%discard_xhz_varname, nciu%discard_xhz_varid) + status = nf90_inq_varid(nciu%id, nciu%discard_vhx_varname, nciu%discard_vhx_varid) + status = nf90_inq_varid(nciu%id, nciu%discard_vhy_varname, nciu%discard_vhy_varid) + status = nf90_inq_varid(nciu%id, nciu%discard_vhz_varname, nciu%discard_vhz_varid) + status = nf90_inq_varid(nciu%id, nciu%discard_body_id_varname, nciu%discard_body_id_varid) + end if - if (param%lenergy) then - status = nf90_inq_varid(self%id, self%ke_orb_varname, self%KE_orb_varid) - status = nf90_inq_varid(self%id, self%ke_spin_varname, self%KE_spin_varid) - status = nf90_inq_varid(self%id, self%pe_varname, self%PE_varid) - status = nf90_inq_varid(self%id, self%l_orbx_varname, self%L_orbx_varid) - status = nf90_inq_varid(self%id, self%l_orby_varname, self%L_orby_varid) - status = nf90_inq_varid(self%id, self%l_orbz_varname, self%L_orbz_varid) - status = nf90_inq_varid(self%id, self%l_spinx_varname, self%L_spinx_varid) - status = nf90_inq_varid(self%id, self%l_spiny_varname, self%L_spiny_varid) - status = nf90_inq_varid(self%id, self%l_spinz_varname, self%L_spinz_varid) - status = nf90_inq_varid(self%id, self%l_escapex_varname, self%L_escapex_varid) - status = nf90_inq_varid(self%id, self%l_escapey_varname, self%L_escapey_varid) - status = nf90_inq_varid(self%id, self%l_escapez_varname, self%L_escapez_varid) - status = nf90_inq_varid(self%id, self%ecollisions_varname, self%Ecollisions_varid) - status = nf90_inq_varid(self%id, self%euntracked_varname, self%Euntracked_varid) - status = nf90_inq_varid(self%id, self%gmescape_varname, self%GMescape_varid) - end if + if (param%lenergy) then + status = nf90_inq_varid(nciu%id, nciu%ke_orb_varname, nciu%KE_orb_varid) + status = nf90_inq_varid(nciu%id, nciu%ke_spin_varname, nciu%KE_spin_varid) + status = nf90_inq_varid(nciu%id, nciu%pe_varname, nciu%PE_varid) + status = nf90_inq_varid(nciu%id, nciu%l_orbx_varname, nciu%L_orbx_varid) + status = nf90_inq_varid(nciu%id, nciu%l_orby_varname, nciu%L_orby_varid) + status = nf90_inq_varid(nciu%id, nciu%l_orbz_varname, nciu%L_orbz_varid) + status = nf90_inq_varid(nciu%id, nciu%l_spinx_varname, nciu%L_spinx_varid) + status = nf90_inq_varid(nciu%id, nciu%l_spiny_varname, nciu%L_spiny_varid) + status = nf90_inq_varid(nciu%id, nciu%l_spinz_varname, nciu%L_spinz_varid) + status = nf90_inq_varid(nciu%id, nciu%l_escapex_varname, nciu%L_escapex_varid) + status = nf90_inq_varid(nciu%id, nciu%l_escapey_varname, nciu%L_escapey_varid) + status = nf90_inq_varid(nciu%id, nciu%l_escapez_varname, nciu%L_escapez_varid) + status = nf90_inq_varid(nciu%id, nciu%ecollisions_varname, nciu%Ecollisions_varid) + status = nf90_inq_varid(nciu%id, nciu%euntracked_varname, nciu%Euntracked_varid) + status = nf90_inq_varid(nciu%id, nciu%gmescape_varname, nciu%GMescape_varid) + end if + + end associate return end subroutine netcdf_open From c8145640030038b07b6d040664cc339b0c28e6e0 Mon Sep 17 00:00:00 2001 From: David A Minton Date: Sat, 3 Dec 2022 10:00:08 -0500 Subject: [PATCH 35/65] Added space dimension to initial conditions generator --- python/swiftest/swiftest/init_cond.py | 27 ++++++++++++-------- python/swiftest/swiftest/io.py | 36 ++++++++++++++++++++++++--- 2 files changed, 49 insertions(+), 14 deletions(-) diff --git a/python/swiftest/swiftest/init_cond.py b/python/swiftest/swiftest/init_cond.py index 1d43fb599..27763ef14 100644 --- a/python/swiftest/swiftest/init_cond.py +++ b/python/swiftest/swiftest/init_cond.py @@ -325,8 +325,9 @@ def vec2xr(param: Dict, if rotz is None: rotz = np.full_like(v1, 0.0) - dims = ['time', 'id', 'vec'] + dims = ['id', 'vec'] infodims = ['id', 'vec'] + space_var = np.array(["x","y","z"]) # The central body is always given id 0 if GMpl is not None: @@ -360,16 +361,19 @@ def vec2xr(param: Dict, vec = np.vstack([v1,v2,v3,v4,v5,v6]) if iscb: + particle_type[icb] = "Central Body" lab_cb = clab.copy() vec_cb = np.vstack([GMpl[icb],Rpl[icb],J2[icb],J4[icb]]) if param['ROTATION']: vec_cb = np.vstack([vec_cb, Ip1[icb], Ip2[icb], Ip3[icb], rotx[icb], roty[icb], rotz[icb]]) - particle_type[icb] = "Central Body" - vec_cb = np.expand_dims(vec_cb.T,axis=0) # Make way for the time dimension! - ds_cb = xr.DataArray(vec_cb, dims=dims, coords={'time': [t], 'id': idvals[icb], 'vec': lab_cb}).to_dataset(dim='vec') + + ds_cb = xr.DataArray(vec_cb.T, dims=dims, coords={'id': idvals[icb], 'vec': lab_cb}) + ds_cb = ds_cb.expand_dims({"time":1}).assign_coords({"time": [t]}).to_dataset(dim='vec') else: ds_cb = None + if ispl: + particle_type[ipl] = np.repeat("Massive Body",idvals[ipl].size) lab_pl = plab.copy() vec_pl = np.vstack([vec[:,ipl], GMpl[ipl]]) if param['CHK_CLOSE']: @@ -378,16 +382,18 @@ def vec2xr(param: Dict, vec_pl = np.vstack([vec_pl, rhill[ipl]]) if param['ROTATION']: vec_pl = np.vstack([vec_pl, Ip1[ipl], Ip2[ipl], Ip3[ipl], rotx[ipl], roty[ipl], rotz[ipl]]) - particle_type[ipl] = np.repeat("Massive Body",idvals[ipl].size) - vec_pl = np.expand_dims(vec_pl.T,axis=0) # Make way for the time dimension! - ds_pl = xr.DataArray(vec_pl, dims=dims, coords={'time': [t], 'id': idvals[ipl], 'vec': lab_pl}).to_dataset(dim='vec') + + ds_pl = xr.DataArray(vec_pl.T, dims=dims, coords={'id': idvals[ipl], 'vec': lab_pl}) + ds_pl = ds_pl.expand_dims({"time":1}).assign_coords({"time": [t]}).to_dataset(dim='vec') else: ds_pl = None + if istp: - lab_tp = tlab.copy() - vec_tp = np.expand_dims(vec[:,itp].T,axis=0) # Make way for the time dimension! - ds_tp = xr.DataArray(vec_tp, dims=dims, coords={'time': [t], 'id': idvals[itp], 'vec': lab_tp}).to_dataset(dim='vec') particle_type[itp] = np.repeat("Test Particle",idvals[itp].size) + lab_tp = tlab.copy() + vec_tp = vec[:,itp] + ds_tp = xr.DataArray(vec_tp.T, dims=dims, coords={'id': idvals[itp], 'vec': lab_tp}) + ds_tp = ds_tp.expand_dims({"time":1}).assign_coords({"time": [t]}).to_dataset(dim='vec') else: ds_tp = None @@ -398,5 +404,6 @@ def vec2xr(param: Dict, else: ds = ds[0] ds = xr.merge([ds_info,ds]) + ds["space"] = xr.DataArray(space_var,dims=["space"],coords={"space":space_var}) return ds \ No newline at end of file diff --git a/python/swiftest/swiftest/io.py b/python/swiftest/swiftest/io.py index 92eeec73e..01983bad6 100644 --- a/python/swiftest/swiftest/io.py +++ b/python/swiftest/swiftest/io.py @@ -56,6 +56,7 @@ # This defines Xarray Dataset variables that are strings, which must be processed due to quirks in how NetCDF-Fortran # handles strings differently than Python's Xarray. string_varnames = ["name", "particle_type", "status", "origin_type"] +char_varnames = ["space"] int_varnames = ["id", "ntp", "npl", "nplm", "discard_body_id", "collision_id"] def bool2yesno(boolval): @@ -805,7 +806,7 @@ def swifter2xr(param, verbose=True): ------- xarray dataset """ - dims = ['time', 'id', 'vec'] + dims = ['time', 'id','vec'] pl = [] tp = [] with FortranFile(param['BIN_OUT'], 'r') as f: @@ -889,7 +890,7 @@ def string_converter(da): Parameters ---------- da : xarray dataset - + Returns ------- da : xarray dataset with the strings cleaned up @@ -900,6 +901,24 @@ def string_converter(da): da = xstrip(da) return da +def char_converter(da): + """ + Converts a string to a unicode string + + Parameters + ---------- + da : xarray dataset + + Returns + ------- + da : xarray dataset with the strings cleaned up + """ + if da.dtype == np.dtype(object): + da = da.astype(' Date: Sat, 3 Dec 2022 10:00:54 -0500 Subject: [PATCH 36/65] Added space dimension to netcdf procedures --- src/netcdf/netcdf.f90 | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/netcdf/netcdf.f90 b/src/netcdf/netcdf.f90 index dca6d7dbf..aac5a8a4c 100644 --- a/src/netcdf/netcdf.f90 +++ b/src/netcdf/netcdf.f90 @@ -208,14 +208,14 @@ module subroutine netcdf_initialize_output(self, param) ! Dimensions call check( nf90_def_dim(nciu%id, nciu%time_dimname, NF90_UNLIMITED, nciu%time_dimid), "netcdf_initialize_output nf90_def_dim time_dimid" ) ! Simulation time dimension - call check( nf90_def_dim(nciu%id, nciu%id_dimname, NF90_UNLIMITED, nciu%id_dimid), "netcdf_initialize_output nf90_def_dim id_dimid" ) ! dimension to store particle id numbers call check( nf90_def_dim(nciu%id, nciu%space_dimname, 3, nciu%space_dimid), "netcdf_initialize_output nf90_def_dim space_dimid" ) ! 3D space dimension + call check( nf90_def_dim(nciu%id, nciu%id_dimname, NF90_UNLIMITED, nciu%id_dimid), "netcdf_initialize_output nf90_def_dim id_dimid" ) ! dimension to store particle id numbers call check( nf90_def_dim(nciu%id, nciu%str_dimname, NAMELEN, nciu%str_dimid), "netcdf_initialize_output nf90_def_dim str_dimid" ) ! Dimension for string variables (aka character arrays) ! Dimension coordinates call check( nf90_def_var(nciu%id, nciu%time_dimname, nciu%out_type, nciu%time_dimid, nciu%time_varid), "netcdf_initialize_output nf90_def_var time_varid" ) - call check( nf90_def_var(nciu%id, nciu%id_dimname, NF90_INT, nciu%id_dimid, nciu%id_varid), "netcdf_initialize_output nf90_def_var id_varid" ) call check( nf90_def_var(nciu%id, nciu%space_dimname, NF90_CHAR, nciu%space_dimid, nciu%space_varid), "netcdf_initialize_output nf90_def_var space_varid" ) + call check( nf90_def_var(nciu%id, nciu%id_dimname, NF90_INT, nciu%id_dimid, nciu%id_varid), "netcdf_initialize_output nf90_def_var id_varid" ) ! Variables call check( nf90_def_var(nciu%id, nciu%npl_varname, NF90_INT, nciu%time_dimid, nciu%npl_varid), "netcdf_initialize_output nf90_def_var npl_varid" ) @@ -374,14 +374,14 @@ module subroutine netcdf_open(self, param, readonly) ! Dimensions call check( nf90_inq_dimid(nciu%id, nciu%time_dimname, nciu%time_dimid), "netcdf_open nf90_inq_dimid time_dimid" ) - call check( nf90_inq_dimid(nciu%id, nciu%id_dimname, nciu%id_dimid), "netcdf_open nf90_inq_dimid id_dimid" ) call check( nf90_inq_dimid(nciu%id, nciu%space_dimname, nciu%space_dimid), "netcdf_open nf90_inq_dimid space_dimid" ) + call check( nf90_inq_dimid(nciu%id, nciu%id_dimname, nciu%id_dimid), "netcdf_open nf90_inq_dimid id_dimid" ) call check( nf90_inq_dimid(nciu%id, nciu%str_dimname, nciu%str_dimid), "netcdf_open nf90_inq_dimid str_dimid" ) ! Dimension coordinates call check( nf90_inq_varid(nciu%id, nciu%time_dimname, nciu%time_varid), "netcdf_open nf90_inq_varid time_varid" ) - call check( nf90_inq_varid(nciu%id, nciu%id_dimname, nciu%id_varid), "netcdf_open nf90_inq_varid id_varid" ) call check( nf90_inq_varid(nciu%id, nciu%space_dimname, nciu%space_varid), "netcdf_open nf90_inq_varid space_varid" ) + call check( nf90_inq_varid(nciu%id, nciu%id_dimname, nciu%id_varid), "netcdf_open nf90_inq_varid id_varid" ) ! Required Variables call check( nf90_inq_varid(nciu%id, nciu%name_varname, nciu%name_varid), "netcdf_open nf90_inq_varid name_varid" ) From 1d4d18a792cf18356fc4cd626fca616ad350040c Mon Sep 17 00:00:00 2001 From: David A Minton Date: Sat, 3 Dec 2022 10:07:52 -0500 Subject: [PATCH 37/65] Cleaned up space coordinate dimension file stuff --- python/swiftest/swiftest/init_cond.py | 4 ++-- src/modules/swiftest_classes.f90 | 1 + src/netcdf/netcdf.f90 | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/python/swiftest/swiftest/init_cond.py b/python/swiftest/swiftest/init_cond.py index 27763ef14..b0dabe922 100644 --- a/python/swiftest/swiftest/init_cond.py +++ b/python/swiftest/swiftest/init_cond.py @@ -327,7 +327,7 @@ def vec2xr(param: Dict, dims = ['id', 'vec'] infodims = ['id', 'vec'] - space_var = np.array(["x","y","z"]) + space_coords = np.array(["x","y","z"]) # The central body is always given id 0 if GMpl is not None: @@ -404,6 +404,6 @@ def vec2xr(param: Dict, else: ds = ds[0] ds = xr.merge([ds_info,ds]) - ds["space"] = xr.DataArray(space_var,dims=["space"],coords={"space":space_var}) + ds["space"] = xr.DataArray(space_coords,dims=["space"],coords={"space":space_coords}) return ds \ No newline at end of file diff --git a/src/modules/swiftest_classes.f90 b/src/modules/swiftest_classes.f90 index f3704a978..61e0ac846 100644 --- a/src/modules/swiftest_classes.f90 +++ b/src/modules/swiftest_classes.f90 @@ -39,6 +39,7 @@ module swiftest_classes character(NAMELEN) :: space_dimname = "space" !! name of the space dimension integer(I4B) :: space_dimid !! ID for the space dimension integer(I4B) :: space_varid !! ID for the space variable + character(len=1),dimension(3) :: space_coords = ["x","y","z"] !! The space dimension coordinate labels ! Non-dimension ids and variable names character(NAMELEN) :: ptype_varname = "particle_type" !! name of the particle type variable diff --git a/src/netcdf/netcdf.f90 b/src/netcdf/netcdf.f90 index aac5a8a4c..1459cf02b 100644 --- a/src/netcdf/netcdf.f90 +++ b/src/netcdf/netcdf.f90 @@ -338,7 +338,7 @@ module subroutine netcdf_initialize_output(self, param) ! Take the file out of define mode call check( nf90_enddef(nciu%id), "netcdf_initialize_output nf90_enddef" ) - call check( nf90_put_var(nciu%id, nciu%space_varid, ["x","y","z"], start=[1], count=[3]), "netcdf_initialize_output nf90_put_var space" ) + call check( nf90_put_var(nciu%id, nciu%space_varid, nciu%space_coords, start=[1], count=[3]), "netcdf_initialize_output nf90_put_var space" ) end associate return From 968d3951cd8c776a9ffed8f62ff5eeb45682f88f Mon Sep 17 00:00:00 2001 From: David A Minton Date: Sat, 3 Dec 2022 10:39:47 -0500 Subject: [PATCH 38/65] Did some more to try to get dimensions into the order I want --- examples/Basic_Simulation/initial_conditions.py | 4 ++-- python/swiftest/swiftest/init_cond.py | 6 ++++++ python/swiftest/swiftest/io.py | 15 ++++++++++++++- python/swiftest/swiftest/simulation_class.py | 1 + 4 files changed, 23 insertions(+), 3 deletions(-) diff --git a/examples/Basic_Simulation/initial_conditions.py b/examples/Basic_Simulation/initial_conditions.py index 4d7fe7ae5..a577c6658 100644 --- a/examples/Basic_Simulation/initial_conditions.py +++ b/examples/Basic_Simulation/initial_conditions.py @@ -23,7 +23,7 @@ from numpy.random import default_rng # Initialize the simulation object as a variable -sim = swiftest.Simulation(tstart=0.0, tstop=1.0e3, dt=0.01, tstep_out=1.0e0, dump_cadence=0, fragmentation=True, minimum_fragment_mass = 2.5e-11, mtiny=2.5e-8) +sim = swiftest.Simulation(fragmentation=True, minimum_fragment_mass = 2.5e-11, mtiny=2.5e-8) # Add the modern planets and the Sun using the JPL Horizons Database sim.add_solar_system_body(["Sun","Mercury","Venus","Earth","Mars","Jupiter","Saturn","Uranus","Neptune","Pluto"]) @@ -67,4 +67,4 @@ sim.get_parameter() # Run the simulation -sim.run() +sim.run(tstart=0.0, tstop=1.0e2, dt=0.01, tstep_out=1.0e0, dump_cadence=0, ) diff --git a/python/swiftest/swiftest/init_cond.py b/python/swiftest/swiftest/init_cond.py index b0dabe922..fb7ae2fbd 100644 --- a/python/swiftest/swiftest/init_cond.py +++ b/python/swiftest/swiftest/init_cond.py @@ -406,4 +406,10 @@ def vec2xr(param: Dict, ds = xr.merge([ds_info,ds]) ds["space"] = xr.DataArray(space_coords,dims=["space"],coords={"space":space_coords}) + # Re-order dimension coordinates so that they are in the same order as the Fortran side + idx = ds.indexes + dim_order = ["time", "space", "id"] + idx = {index_name: idx[index_name] for index_name in dim_order} + ds = ds.reindex(idx) + return ds \ No newline at end of file diff --git a/python/swiftest/swiftest/io.py b/python/swiftest/swiftest/io.py index 01983bad6..caa36926a 100644 --- a/python/swiftest/swiftest/io.py +++ b/python/swiftest/swiftest/io.py @@ -193,7 +193,19 @@ def read_swiftest_param(param_file_name, param, verbose=True): print(f"{param_file_name} not found.") return param - +def reorder_dims(ds): + + # Re-order dimension coordinates so that they are in the same order as the Fortran side + idx = ds.indexes + if "id" in idx: + dim_order = ["time", "space", "id"] + elif "name" in idx: + dim_order = ["time", "space", "name"] + else: + dim_order = idx + idx = {index_name: idx[index_name] for index_name in dim_order} + ds = ds.reindex(idx) + return ds def read_swifter_param(param_file_name, verbose=True): """ Reads in a Swifter param.in file and saves it as a dictionary @@ -1134,6 +1146,7 @@ def swiftest_xr2infile(ds, param, in_type="NETCDF_DOUBLE", infile_name=None,fram frame = unclean_string_values(frame) if verbose: print(f"Writing initial conditions to file {infile_name}") + frame = reorder_dims(frame) frame.to_netcdf(path=infile_name) return frame diff --git a/python/swiftest/swiftest/simulation_class.py b/python/swiftest/swiftest/simulation_class.py index aad511e92..9e1279a79 100644 --- a/python/swiftest/swiftest/simulation_class.py +++ b/python/swiftest/swiftest/simulation_class.py @@ -2549,6 +2549,7 @@ def get_nvals(ds): self.data = get_nvals(self.data) self.data = self.data.sortby("id") + self.data = io.reorder_dims(self.data) return dsnew From 6e22638e1c2b6ff6b6dfbfe44f0039dda5060455 Mon Sep 17 00:00:00 2001 From: David A Minton Date: Sat, 3 Dec 2022 10:54:58 -0500 Subject: [PATCH 39/65] Experimenting with saving the vector position and velocity data rather than by component --- src/modules/swiftest_classes.f90 | 4 ++++ src/netcdf/netcdf.f90 | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/src/modules/swiftest_classes.f90 b/src/modules/swiftest_classes.f90 index 61e0ac846..d136cd7f6 100644 --- a/src/modules/swiftest_classes.f90 +++ b/src/modules/swiftest_classes.f90 @@ -64,6 +64,10 @@ module swiftest_classes integer(I4B) :: omega_varid !! ID for the arg. periapsis variable character(NAMELEN) :: capm_varname = "capm" !! name of the mean anomaly variable integer(I4B) :: capm_varid !! ID for the mean anomaly variable + character(NAMELEN) :: rh_varname = "rh" !! name of the heliocentric position vector variable + integer(I4B) :: rh_varid !! ID for the heliocentric position vector variable + character(NAMELEN) :: vh_varname = "vh" !! name of the heliocentric velocity vector variable + integer(I4B) :: vh_varid !! ID for the heliocentric velocity vector variable character(NAMELEN) :: xhx_varname = "xhx" !! name of the heliocentric position x variable integer(I4B) :: xhx_varid !! ID for the heliocentric position x variable character(NAMELEN) :: xhy_varname = "xhy" !! name of the heliocentric position y variable diff --git a/src/netcdf/netcdf.f90 b/src/netcdf/netcdf.f90 index 1459cf02b..818fa3302 100644 --- a/src/netcdf/netcdf.f90 +++ b/src/netcdf/netcdf.f90 @@ -226,6 +226,8 @@ module subroutine netcdf_initialize_output(self, param) call check( nf90_def_var(nciu%id, nciu%status_varname, NF90_CHAR, [nciu%str_dimid, nciu%id_dimid], nciu%status_varid), "netcdf_initialize_output nf90_def_var status_varid" ) if ((param%out_form == "XV") .or. (param%out_form == "XVEL")) then + call check( nf90_def_var(nciu%id, nciu%rh_varname, nciu%out_type, [nciu%space_dimid, nciu%id_dimid, nciu%time_dimid], nciu%rh_varid), "netcdf_initialize_output nf90_def_var rh_varid" ) + call check( nf90_def_var(nciu%id, nciu%vh_varname, nciu%out_type, [nciu%space_dimid, nciu%id_dimid, nciu%time_dimid], nciu%vh_varid), "netcdf_initialize_output nf90_def_var vh_varid" ) call check( nf90_def_var(nciu%id, nciu%xhx_varname, nciu%out_type, [nciu%id_dimid, nciu%time_dimid], nciu%xhx_varid), "netcdf_initialize_output nf90_def_var xhx_varid" ) call check( nf90_def_var(nciu%id, nciu%xhy_varname, nciu%out_type, [nciu%id_dimid, nciu%time_dimid], nciu%xhy_varid), "netcdf_initialize_output nf90_def_var xhy_varid" ) call check( nf90_def_var(nciu%id, nciu%xhz_varname, nciu%out_type, [nciu%id_dimid, nciu%time_dimid], nciu%xhz_varid), "netcdf_initialize_output nf90_def_var xhz_varid" ) @@ -389,6 +391,8 @@ module subroutine netcdf_open(self, param, readonly) call check( nf90_inq_varid(nciu%id, nciu%gmass_varname, nciu%Gmass_varid), "netcdf_open nf90_inq_varid Gmass_varid" ) if ((param%out_form == "XV") .or. (param%out_form == "XVEL")) then + status = nf90_inq_varid(nciu%id, nciu%rh_varname, nciu%rh_varid) + status = nf90_inq_varid(nciu%id, nciu%vh_varname, nciu%vh_varid) call check( nf90_inq_varid(nciu%id, nciu%xhx_varname, nciu%xhx_varid), "netcdf_open nf90_inq_varid xhx_varid" ) call check( nf90_inq_varid(nciu%id, nciu%xhy_varname, nciu%xhy_varid), "netcdf_open nf90_inq_varid xhy_varid" ) call check( nf90_inq_varid(nciu%id, nciu%xhz_varname, nciu%xhz_varid), "netcdf_open nf90_inq_varid xhz_varid" ) @@ -1212,6 +1216,8 @@ module subroutine netcdf_write_frame_base(self, nciu, param) if (param%lgr) call gr_pseudovel2vel(param, self%mu(j), self%xh(:, j), self%vh(:, j), vh(:)) if ((param%out_form == "XV") .or. (param%out_form == "XVEL")) then + call check( nf90_put_var(nciu%id, nciu%rh_varid, self%xh(:, j), start=[1,idslot, tslot], count=[3,1,1]), "netcdf_write_frame_base nf90_put_var rh_varid" ) + call check( nf90_put_var(nciu%id, nciu%vh_varid, self%vh(:, j), start=[1,idslot, tslot], count=[3,1,1]), "netcdf_write_frame_base nf90_put_var vh_varid" ) call check( nf90_put_var(nciu%id, nciu%xhx_varid, self%xh(1, j), start=[idslot, tslot]), "netcdf_write_frame_base nf90_put_var xhx_varid" ) call check( nf90_put_var(nciu%id, nciu%xhy_varid, self%xh(2, j), start=[idslot, tslot]), "netcdf_write_frame_base nf90_put_var xhy_varid" ) call check( nf90_put_var(nciu%id, nciu%xhz_varid, self%xh(3, j), start=[idslot, tslot]), "netcdf_write_frame_base nf90_put_var xhz_varid" ) From 4f1d1aef068331ae490b7f828d7e08b0b7152ea0 Mon Sep 17 00:00:00 2001 From: David A Minton Date: Sat, 3 Dec 2022 12:17:30 -0500 Subject: [PATCH 40/65] Converted NetCDF vector component variables to vector variables --- python/swiftest/swiftest/io.py | 4 +- src/modules/swiftest_classes.f90 | 100 ++++++++----------------------- 2 files changed, 26 insertions(+), 78 deletions(-) diff --git a/python/swiftest/swiftest/io.py b/python/swiftest/swiftest/io.py index caa36926a..7a67f9a8a 100644 --- a/python/swiftest/swiftest/io.py +++ b/python/swiftest/swiftest/io.py @@ -198,9 +198,9 @@ def reorder_dims(ds): # Re-order dimension coordinates so that they are in the same order as the Fortran side idx = ds.indexes if "id" in idx: - dim_order = ["time", "space", "id"] + dim_order = ["time", "id", "space"] elif "name" in idx: - dim_order = ["time", "space", "name"] + dim_order = ["time", "name", "space"] else: dim_order = idx idx = {index_name: idx[index_name] for index_name in dim_order} diff --git a/src/modules/swiftest_classes.f90 b/src/modules/swiftest_classes.f90 index d136cd7f6..302d09eea 100644 --- a/src/modules/swiftest_classes.f90 +++ b/src/modules/swiftest_classes.f90 @@ -21,7 +21,7 @@ module swiftest_classes !! This derived datatype stores the NetCDF ID values for each of the variables included in the NetCDF data file. This is used as the base class defined in swiftest_classes type :: netcdf_variables integer(I4B) :: out_type !! output type (will be assigned either NF90_DOUBLE or NF90_FLOAT, depending on the user parameter) - integer(I4B) :: id !! ID for the output file + integer(I4B) :: id !! ID for the output file integer(I4B) :: discard_body_id_varid !! ID for the id of the other body involved in the discard integer(I4B) :: id_chunk !! Chunk size for the id dimension variables integer(I4B) :: time_chunk !! Chunk size for the time dimension variables @@ -68,42 +68,18 @@ module swiftest_classes integer(I4B) :: rh_varid !! ID for the heliocentric position vector variable character(NAMELEN) :: vh_varname = "vh" !! name of the heliocentric velocity vector variable integer(I4B) :: vh_varid !! ID for the heliocentric velocity vector variable - character(NAMELEN) :: xhx_varname = "xhx" !! name of the heliocentric position x variable - integer(I4B) :: xhx_varid !! ID for the heliocentric position x variable - character(NAMELEN) :: xhy_varname = "xhy" !! name of the heliocentric position y variable - integer(I4B) :: xhy_varid !! ID for the heliocentric position y variable - character(NAMELEN) :: xhz_varname = "xhz" !! name of the heliocentric position z variable - integer(I4B) :: xhz_varid !! ID for the heliocentric position z variable - character(NAMELEN) :: vhx_varname = "vhx" !! name of the heliocentric velocity x variable - integer(I4B) :: vhx_varid !! ID for the heliocentric velocity x variable - character(NAMELEN) :: vhy_varname = "vhy" !! name of the heliocentric velocity y variable - integer(I4B) :: vhy_varid !! ID for the heliocentric velocity y variable - character(NAMELEN) :: vhz_varname = "vhz" !! name of the heliocentric velocity z variable - integer(I4B) :: vhz_varid !! ID for the heliocentric velocity z variable - character(NAMELEN) :: gr_pseudo_vhx_varname = "gr_pseudo_vhx" !! name of the heliocentric pseudovelocity x variable (used in GR only) - integer(I4B) :: gr_pseudo_vhx_varid !! ID for the heliocentric pseudovelocity x variable (used in GR) - character(NAMELEN) :: gr_pseudo_vhy_varname = "gr_pseudo_vhy" !! name of the heliocentric pseudovelocity y variable (used in GR only) - integer(I4B) :: gr_pseudo_vhy_varid !! ID for the heliocentric pseudovelocity y variable (used in GR) - character(NAMELEN) :: gr_pseudo_vhz_varname = "gr_pseudo_vhz" !! name of the heliocentric pseudovelocity z variable (used in GR only) - integer(I4B) :: gr_pseudo_vhz_varid !! ID for the heliocentric psuedovelocity z variable (used in GR) + character(NAMELEN) :: gr_pseudo_vh_varname = "gr_pseudo_vh" !! name of the heliocentric pseudovelocity vector variable (used in GR only) + integer(I4B) :: gr_pseudo_vh_varid !! ID for the heliocentric pseudovelocity vector variable (used in GR) character(NAMELEN) :: gmass_varname = "Gmass" !! name of the mass variable integer(I4B) :: Gmass_varid !! ID for the mass variable character(NAMELEN) :: rhill_varname = "rhill" !! name of the hill radius variable integer(I4B) :: rhill_varid !! ID for the hill radius variable character(NAMELEN) :: radius_varname = "radius" !! name of the radius variable integer(I4B) :: radius_varid !! ID for the radius variable - character(NAMELEN) :: ip1_varname = "Ip1" !! name of the axis 1 principal moment of inertial variable - integer(I4B) :: Ip1_varid !! ID for the axis 1 principal moment of inertia variable - character(NAMELEN) :: ip2_varname = "Ip2" !! name of the axis 2 principal moment of inertial variable - integer(I4B) :: Ip2_varid !! ID for the axis 2 principal moment of inertia variable - character(NAMELEN) :: ip3_varname = "Ip3" !! name of the axis 3 principal moment of inertial variable - integer(I4B) :: Ip3_varid !! ID for the axis 3 principal moment of inertia variable - character(NAMELEN) :: rotx_varname = "rotx" !! name of the rotation x variable - integer(I4B) :: rotx_varid !! ID for the rotation x variable - character(NAMELEN) :: roty_varname = "roty" !! name of the rotation y variable - integer(I4B) :: roty_varid !! ID for the rotation y variable - character(NAMELEN) :: rotz_varname = "rotz" !! name of the rotation z variable - integer(I4B) :: rotz_varid !! ID for the rotation z variable + character(NAMELEN) :: Ip_varname = "Ip" !! name of the principal moment of inertial variable + integer(I4B) :: Ip_varid !! ID for the axis principal moment of inertia variable + character(NAMELEN) :: rot_varname = "rot" !! name of the rotation vector variable + integer(I4B) :: rot_varid !! ID for the rotation vector variable character(NAMELEN) :: j2rp2_varname = "j2rp2" !! name of the j2rp2 variable integer(I4B) :: j2rp2_varid !! ID for the j2 variable character(NAMELEN) :: j4rp4_varname = "j4rp4" !! name of the j4pr4 variable @@ -118,29 +94,17 @@ module swiftest_classes integer(I4B) :: KE_spin_varid !! ID for the system spin kinetic energy variable character(NAMELEN) :: pe_varname = "PE" !! name of the system potential energy variable integer(I4B) :: PE_varid !! ID for the system potential energy variable - character(NAMELEN) :: l_orbx_varname = "L_orbx" !! name of the orbital angular momentum x variable - integer(I4B) :: L_orbx_varid !! ID for the system orbital angular momentum x variable - character(NAMELEN) :: l_orby_varname = "L_orby" !! name of the orbital angular momentum y variable - integer(I4B) :: L_orby_varid !! ID for the system orbital angular momentum y variable - character(NAMELEN) :: l_orbz_varname = "L_orbz" !! name of the orbital angular momentum z variable - integer(I4B) :: L_orbz_varid !! ID for the system orbital angular momentum z variable - character(NAMELEN) :: l_spinx_varname = "L_spinx" !! name of the spin angular momentum x variable - integer(I4B) :: L_spinx_varid !! ID for the system spin angular momentum x variable - character(NAMELEN) :: l_spiny_varname = "L_spiny" !! name of the spin angular momentum y variable - integer(I4B) :: L_spiny_varid !! ID for the system spin angular momentum y variable - character(NAMELEN) :: l_spinz_varname = "L_spinz" !! name of the spin angular momentum z variable - integer(I4B) :: L_spinz_varid !! ID for the system spin angular momentum z variable - character(NAMELEN) :: l_escapex_varname = "L_escapex" !! name of the escaped angular momentum x variable - integer(I4B) :: L_escapex_varid !! ID for the escaped angular momentum x variable - character(NAMELEN) :: l_escapey_varname = "L_escapey" !! name of the escaped angular momentum y variable - integer(I4B) :: L_escapey_varid !! ID for the escaped angular momentum x variable - character(NAMELEN) :: l_escapez_varname = "L_escapez" !! name of the escaped angular momentum z variable - integer(I4B) :: L_escapez_varid !! ID for the escaped angular momentum x variable - character(NAMELEN) :: ecollisions_varname = "Ecollisions" !! name of the escaped angular momentum y variable + character(NAMELEN) :: L_orb_varname = "L_orb" !! name of the orbital angular momentum vector variable + integer(I4B) :: L_orb_varid !! ID for the system orbital angular momentum vector variable + character(NAMELEN) :: L_spin_varname = "L_spin" !! name of the spin angular momentum vector variable + integer(I4B) :: L_spin_varid !! ID for the system spin angular momentum vector variable + character(NAMELEN) :: L_escape_varname = "L_escape" !! name of the escaped angular momentum vector variable + integer(I4B) :: L_escape_varid !! ID for the escaped angular momentum vector variable + character(NAMELEN) :: Ecollisions_varname = "Ecollisions" !! name of the escaped angular momentum y variable integer(I4B) :: Ecollisions_varid !! ID for the energy lost in collisions variable - character(NAMELEN) :: euntracked_varname = "Euntracked" !! name of the energy that is untracked due to loss (untracked potential energy due to mergers and body energy for escaped bodies) + character(NAMELEN) :: Euntracked_varname = "Euntracked" !! name of the energy that is untracked due to loss (untracked potential energy due to mergers and body energy for escaped bodies) integer(I4B) :: Euntracked_varid !! ID for the energy that is untracked due to loss (untracked potential energy due to mergers and body energy for escaped bodies) - character(NAMELEN) :: gmescape_varname = "GMescape" !! name of the G*Mass of bodies that escape the system + character(NAMELEN) :: GMescape_varname = "GMescape" !! name of the G*Mass of bodies that escape the system integer(I4B) :: GMescape_varid !! ID for the G*Mass of bodies that escape the system character(NAMELEN) :: status_varname = "status" !! name of the current status of the body variable (includes discard type) integer(I4B) :: status_varid !! ID for the status variable @@ -150,32 +114,16 @@ module swiftest_classes integer(I4B) :: origin_time_varid !! ID for the origin time character(NAMELEN) :: collision_id_varname = "collision_id" !! name of the collision id variable integer(I4B) :: collision_id_varid !! Netcdf ID for the origin collision ID - character(NAMELEN) :: origin_xhx_varname = "origin_xhx" !! name of the heliocentric position of the body at the time of origin x variable - integer(I4B) :: origin_xhx_varid !! ID for the origin xh x component - character(NAMELEN) :: origin_xhy_varname = "origin_xhy" !! name of the heliocentric position of the body at the time of origin y variable - integer(I4B) :: origin_xhy_varid !! ID for the origin xh y component - character(NAMELEN) :: origin_xhz_varname = "origin_xhz" !! name of the heliocentric position of the body at the time of origin z variable - integer(I4B) :: origin_xhz_varid !! ID for the origin xh z component - character(NAMELEN) :: origin_vhx_varname = "origin_vhx" !! name of the heliocentric velocity of the body at the time of origin x variable - integer(I4B) :: origin_vhx_varid !! ID for the origin xh x component - character(NAMELEN) :: origin_vhy_varname = "origin_vhy" !! name of the heliocentric velocity of the body at the time of origin y variable - integer(I4B) :: origin_vhy_varid !! ID for the origin xh y component - character(NAMELEN) :: origin_vhz_varname = "origin_vhz" !! name of the heliocentric velocity of the body at the time of origin z variable - integer(I4B) :: origin_vhz_varid !! ID for the origin xh z component + character(NAMELEN) :: origin_rh_varname = "origin_rh" !! name of the heliocentric position vector of the body at the time of origin variable + integer(I4B) :: origin_rh_varid !! ID for the origin position vector variable + character(NAMELEN) :: origin_vh_varname = "origin_vh" !! name of the heliocentric velocity vector of the body at the time of origin variable + integer(I4B) :: origin_vh_varid !! ID for the origin velocity vector component character(NAMELEN) :: discard_time_varname = "discard_time" !! name of the time of discard variable integer(I4B) :: discard_time_varid !! ID for the time of discard variable - character(NAMELEN) :: discard_xhx_varname = "discard_xhx" !! name of the heliocentric position of the body at the time of discard x variable - integer(I4B) :: discard_xhx_varid !! ID for the heliocentric position of the body at the time of discard x variable - character(NAMELEN) :: discard_xhy_varname = "discard_xhy" !! name of the heliocentric position of the body at the time of discard y variable - integer(I4B) :: discard_xhy_varid !! ID for the heliocentric position of the body at the time of discard y variable - character(NAMELEN) :: discard_xhz_varname = "discard_xhz" !! name of the heliocentric position of the body at the time of discard z variable - integer(I4B) :: discard_xhz_varid !! ID for the heliocentric position of the body at the time of discard z variable - character(NAMELEN) :: discard_vhx_varname = "discard_vhx" !! name of the heliocentric velocity of the body at the time of discard x variable - integer(I4B) :: discard_vhx_varid !! ID for the heliocentric velocity of the body at the time of discard x variable - character(NAMELEN) :: discard_vhy_varname = "discard_vhy" !! name of the heliocentric velocity of the body at the time of discard y variable - integer(I4B) :: discard_vhy_varid !! ID for the heliocentric velocity of the body at the time of discard y variable - character(NAMELEN) :: discard_vhz_varname = "discard_vhz" !! name of the heliocentric velocity of the body at the time of discard z variable - integer(I4B) :: discard_vhz_varid !! ID for the heliocentric velocity of the body at the time of discard z variable + character(NAMELEN) :: discard_rh_varname = "discard_rh" !! name of the heliocentric position vector of the body at the time of discard variable + integer(I4B) :: discard_rh_varid !! ID for the heliocentric position vector of the body at the time of discard variable + character(NAMELEN) :: discard_vh_varname = "discard_vh" !! name of the heliocentric velocity vector of the body at the time of discard variable + integer(I4B) :: discard_vh_varid !! ID for the heliocentric velocity vector of the body at the time of discard variable character(NAMELEN) :: discard_body_id_varname = "discard_body_id" !! name of the id of the other body involved in the discard end type netcdf_variables From 013178900a92946143f52e3aac8c30bf3a169592 Mon Sep 17 00:00:00 2001 From: David A Minton Date: Sat, 3 Dec 2022 15:51:00 -0500 Subject: [PATCH 41/65] Major refactoring! Changed all NetCDF component variables to vectors in the SPACE DIMENSION. Also refactored xh to rh, as that's has been bugging me for years. --- src/discard/discard.f90 | 16 +- src/drift/drift.f90 | 2 +- src/encounter/encounter_io.f90 | 104 +++--- src/fraggle/fraggle_io.f90 | 4 +- src/fraggle/fraggle_util.f90 | 2 +- src/gr/gr.f90 | 22 +- src/helio/helio_drift.f90 | 26 +- src/helio/helio_gr.f90 | 8 +- src/helio/helio_kick.f90 | 4 +- src/io/io.f90 | 2 +- src/kick/kick.f90 | 10 +- src/modules/swiftest_classes.f90 | 32 +- src/netcdf/netcdf.f90 | 517 ++++++++-------------------- src/obl/obl.f90 | 10 +- src/orbel/orbel.f90 | 4 +- src/rmvs/rmvs_discard.f90 | 2 +- src/rmvs/rmvs_encounter_check.f90 | 2 +- src/rmvs/rmvs_kick.f90 | 12 +- src/rmvs/rmvs_step.f90 | 30 +- src/setup/setup.f90 | 14 +- src/setup/symba_collision.f90 | 36 +- src/symba/symba_collision.f90 | 36 +- src/symba/symba_discard.f90 | 10 +- src/symba/symba_encounter_check.f90 | 14 +- src/symba/symba_kick.f90 | 14 +- src/symba/symba_util.f90 | 6 +- src/tides/tides_getacch_pl.f90 | 4 +- src/util/util_append.f90 | 2 +- src/util/util_coord.f90 | 24 +- src/util/util_copy.f90 | 4 +- src/util/util_dealloc.f90 | 2 +- src/util/util_fill.f90 | 2 +- src/util/util_peri.f90 | 4 +- src/util/util_rescale.f90 | 2 +- src/util/util_resize.f90 | 2 +- src/util/util_set.f90 | 20 +- src/util/util_sort.f90 | 4 +- src/util/util_spill.f90 | 2 +- src/whm/whm_coord.f90 | 14 +- src/whm/whm_gr.f90 | 4 +- src/whm/whm_kick.f90 | 8 +- src/whm/whm_util.f90 | 2 +- 42 files changed, 404 insertions(+), 635 deletions(-) diff --git a/src/discard/discard.f90 b/src/discard/discard.f90 index 2019774a8..41ece554b 100644 --- a/src/discard/discard.f90 +++ b/src/discard/discard.f90 @@ -131,7 +131,7 @@ subroutine discard_cb_tp(tp, system, param) rmaxu2 = param%rmaxu**2 do i = 1, ntp if (tp%status(i) == ACTIVE) then - rh2 = dot_product(tp%xh(:, i), tp%xh(:, i)) + rh2 = dot_product(tp%rh(:, i), tp%rh(:, i)) if ((param%rmax >= 0.0_DP) .and. (rh2 > rmax2)) then tp%status(i) = DISCARDED_RMAX write(idstr, *) tp%id(i) @@ -140,7 +140,7 @@ subroutine discard_cb_tp(tp, system, param) " too far from the central body at t = " // trim(adjustl(timestr)) tp%ldiscard(i) = .true. tp%lmask(i) = .false. - call tp%info(i)%set_value(status="DISCARDED_RMAX", discard_time=system%t, discard_xh=tp%xh(:,i), & + call tp%info(i)%set_value(status="DISCARDED_RMAX", discard_time=system%t, discard_rh=tp%rh(:,i), & discard_vh=tp%vh(:,i)) else if ((param%rmin >= 0.0_DP) .and. (rh2 < rmin2)) then tp%status(i) = DISCARDED_RMIN @@ -150,7 +150,7 @@ subroutine discard_cb_tp(tp, system, param) " too close to the central body at t = " // trim(adjustl(timestr)) tp%ldiscard(i) = .true. tp%lmask(i) = .false. - call tp%info(i)%set_value(status="DISCARDED_RMIN", discard_time=system%t, discard_xh=tp%xh(:,i), & + call tp%info(i)%set_value(status="DISCARDED_RMIN", discard_time=system%t, discard_rh=tp%rh(:,i), & discard_vh=tp%vh(:,i), discard_body_id=cb%id) else if (param%rmaxu >= 0.0_DP) then rb2 = dot_product(tp%xb(:, i), tp%xb(:, i)) @@ -164,7 +164,7 @@ subroutine discard_cb_tp(tp, system, param) " is unbound and too far from barycenter at t = " // trim(adjustl(timestr)) tp%ldiscard(i) = .true. tp%lmask(i) = .false. - call tp%info(i)%set_value(status="DISCARDED_RMAXU", discard_time=system%t, discard_xh=tp%xh(:,i), & + call tp%info(i)%set_value(status="DISCARDED_RMAXU", discard_time=system%t, discard_rh=tp%rh(:,i), & discard_vh=tp%vh(:,i)) end if end if @@ -201,7 +201,7 @@ subroutine discard_peri_tp(tp, system, param) if (tp%isperi(i) == 0) then ih = 1 do j = 1, npl - dx(:) = tp%xh(:, i) - pl%xh(:, j) + dx(:) = tp%rh(:, i) - pl%rh(:, j) r2 = dot_product(dx(:), dx(:)) if (r2 <= (pl%rhill(j))**2) ih = 0 end do @@ -215,7 +215,7 @@ subroutine discard_peri_tp(tp, system, param) write(*, *) "Particle " // trim(adjustl(tp%info(i)%name)) // " (" // trim(adjustl(idstr)) // ")" // & " perihelion distance too small at t = " // trim(adjustl(timestr)) tp%ldiscard(i) = .true. - call tp%info(i)%set_value(status="DISCARDED_PERI", discard_time=system%t, discard_xh=tp%xh(:,i), & + call tp%info(i)%set_value(status="DISCARDED_PERI", discard_time=system%t, discard_rh=tp%rh(:,i), & discard_vh=tp%vh(:,i), discard_body_id=pl%id(j)) end if end if @@ -250,7 +250,7 @@ subroutine discard_pl_tp(tp, system, param) do i = 1, ntp if (tp%status(i) == ACTIVE) then do j = 1, npl - dx(:) = tp%xh(:, i) - pl%xh(:, j) + dx(:) = tp%rh(:, i) - pl%rh(:, j) dv(:) = tp%vh(:, i) - pl%vh(:, j) radius = pl%radius(j) call discard_pl_close(dx(:), dv(:), dt, radius**2, isp, r2min) @@ -265,7 +265,7 @@ subroutine discard_pl_tp(tp, system, param) // " too close to massive body " // trim(adjustl(pl%info(j)%name)) // " (" // trim(adjustl(idstrj)) // ")" & // " at t = " // trim(adjustl(timestr)) tp%ldiscard(i) = .true. - call tp%info(i)%set_value(status="DISCARDED_PLR", discard_time=system%t, discard_xh=tp%xh(:,i), & + call tp%info(i)%set_value(status="DISCARDED_PLR", discard_time=system%t, discard_rh=tp%rh(:,i), & discard_vh=tp%vh(:,i), discard_body_id=pl%id(j)) exit end if diff --git a/src/drift/drift.f90 b/src/drift/drift.f90 index b2e3c1b9a..7c7c2bdba 100644 --- a/src/drift/drift.f90 +++ b/src/drift/drift.f90 @@ -39,7 +39,7 @@ module subroutine drift_body(self, system, param, dt) associate(n => self%nbody) allocate(iflag(n)) iflag(:) = 0 - call drift_all(self%mu, self%xh, self%vh, self%nbody, param, dt, self%lmask, iflag) + call drift_all(self%mu, self%rh, self%vh, self%nbody, param, dt, self%lmask, iflag) if (any(iflag(1:n) /= 0)) then where(iflag(1:n) /= 0) self%status(1:n) = DISCARDED_DRIFTERR do i = 1, n diff --git a/src/encounter/encounter_io.f90 b/src/encounter/encounter_io.f90 index e425c0ae1..d28ecd1f5 100644 --- a/src/encounter/encounter_io.f90 +++ b/src/encounter/encounter_io.f90 @@ -81,19 +81,15 @@ module subroutine encounter_io_initialize_output(self, param) self%out_type = NF90_DOUBLE end select - call check( nf90_def_var(self%id, self%time_dimname, self%out_type, self%time_dimid, self%time_varid), "encounter_io_initialize_output nf90_def_var time_varid" ) - call check( nf90_def_var(self%id, self%nenc_varname, NF90_INT, self%time_dimid, self%nenc_varid), "encounter_io_initialize_output nf90_def_var nenc_varid" ) - call check( nf90_def_var(self%id, self%name_varname, NF90_CHAR, [self%str_dimid, self%collider_dimid, self%eid_dimid], self%name_varid), "encounter_io_initialize_output nf90_def_var name_varid" ) - call check( nf90_def_var(self%id, self%id_dimname, NF90_INT, [self%collider_dimid, self%eid_dimid, self%time_dimid], self%id_varid), "encounter_io_initialize_output nf90_def_var id_varid" ) - call check( nf90_def_var(self%id, self%xhx_varname, self%out_type, [self%collider_dimid, self%eid_dimid, self%time_dimid], self%xhx_varid), "encounter_io_initialize_output nf90_def_var xhx_varid" ) - call check( nf90_def_var(self%id, self%xhy_varname, self%out_type, [self%collider_dimid, self%eid_dimid, self%time_dimid], self%xhy_varid), "encounter_io_initialize_output nf90_def_var xhy_varid" ) - call check( nf90_def_var(self%id, self%xhz_varname, self%out_type, [self%collider_dimid, self%eid_dimid, self%time_dimid], self%xhz_varid), "encounter_io_initialize_output nf90_def_var xhz_varid" ) - call check( nf90_def_var(self%id, self%vhx_varname, self%out_type, [self%collider_dimid, self%eid_dimid, self%time_dimid], self%vhx_varid), "encounter_io_initialize_output nf90_def_var vhx_varid" ) - call check( nf90_def_var(self%id, self%vhy_varname, self%out_type, [self%collider_dimid, self%eid_dimid, self%time_dimid], self%vhy_varid), "encounter_io_initialize_output nf90_def_var vhy_varid" ) - call check( nf90_def_var(self%id, self%vhz_varname, self%out_type, [self%collider_dimid, self%eid_dimid, self%time_dimid], self%vhz_varid), "encounter_io_initialize_output nf90_def_var vhz_varid" ) - call check( nf90_def_var(self%id, self%level_varname, NF90_INT, [self%eid_dimid, self%time_dimid], self%level_varid), "encounter_io_initialize_output nf90_def_var level_varid" ) - call check( nf90_def_var(self%id, self%gmass_varname, self%out_type, [self%collider_dimid, self%eid_dimid, self%time_dimid], self%Gmass_varid), "encounter_io_initialize_output nf90_def_var Gmass_varid" ) - call check( nf90_def_var(self%id, self%radius_varname, self%out_type, [self%collider_dimid, self%eid_dimid, self%time_dimid], self%radius_varid), "encounter_io_initialize_output nf90_def_var radius_varid" ) + ! call check( nf90_def_var(self%id, self%time_dimname, self%out_type, self%time_dimid, self%time_varid), "encounter_io_initialize_output nf90_def_var time_varid" ) + ! call check( nf90_def_var(self%id, self%nenc_varname, NF90_INT, self%time_dimid, self%nenc_varid), "encounter_io_initialize_output nf90_def_var nenc_varid" ) + ! call check( nf90_def_var(self%id, self%name_varname, NF90_CHAR, [self%str_dimid, self%collider_dimid, self%eid_dimid], self%name_varid), "encounter_io_initialize_output nf90_def_var name_varid" ) + ! call check( nf90_def_var(self%id, self%id_dimname, NF90_INT, [self%collider_dimid, self%eid_dimid, self%time_dimid], self%id_varid), "encounter_io_initialize_output nf90_def_var id_varid" ) + ! call check( nf90_def_var(self%id, self%rh_varname, self%out_type, [self%collider_dimid, self%eid_dimid, self%time_dimid], self%rh_varid), "encounter_io_initialize_output nf90_def_var rh_varid" ) + ! call check( nf90_def_var(self%id, self%vh_varname, self%out_type, [self%collider_dimid, self%eid_dimid, self%time_dimid], self%vh_varid), "encounter_io_initialize_output nf90_def_var vh_varid" ) + ! call check( nf90_def_var(self%id, self%level_varname, NF90_INT, [self%eid_dimid, self%time_dimid], self%level_varid), "encounter_io_initialize_output nf90_def_var level_varid" ) + ! call check( nf90_def_var(self%id, self%gmass_varname, self%out_type, [self%collider_dimid, self%eid_dimid, self%time_dimid], self%Gmass_varid), "encounter_io_initialize_output nf90_def_var Gmass_varid" ) + ! call check( nf90_def_var(self%id, self%radius_varname, self%out_type, [self%collider_dimid, self%eid_dimid, self%time_dimid], self%radius_varid), "encounter_io_initialize_output nf90_def_var radius_varid" ) ! Take the file out of define mode @@ -128,24 +124,24 @@ module subroutine encounter_io_open_file(self, param, readonly) write(errmsg,*) "encounter_io_open_file nf90_open ",trim(adjustl(param%outfile)) call check( nf90_open(self%enc_file, mode, self%id), errmsg) - call check( nf90_inq_dimid(self%id, self%time_dimname, self%time_dimid), "encounter_io_open_file nf90_inq_dimid time_dimid" ) - call check( nf90_inq_dimid(self%id, self%eid_dimname, self%eid_dimid), "encounter_io_open_file nf90_inq_dimid eid_dimid" ) - call check( nf90_inq_dimid(self%id, self%collider_dimname, self%collider_dimid), "encounter_io_open_file nf90_inq_dimid collider_dimid" ) - call check( nf90_inq_dimid(self%id, self%str_dimname, self%str_dimid), "encounter_io_open_file nf90_inq_dimid collider_str" ) - - call check( nf90_inq_varid(self%id, self%time_dimname, self%time_varid), "encounter_io_open_file nf90_inq_varid time_varid" ) - call check( nf90_inq_varid(self%id, self%name_varname, self%name_varid), "encounter_io_open_file nf90_inq_varid name_varid" ) - call check( nf90_inq_varid(self%id, self%nenc_varname, self%nenc_varid), "encounter_io_open_file nf90_inq_varid nenc_varid" ) - - call check( nf90_inq_varid(self%id, self%xhx_varname, self%xhx_varid), "encounter_io_open_file nf90_inq_varid xhx_varid" ) - call check( nf90_inq_varid(self%id, self%xhy_varname, self%xhy_varid), "encounter_io_open_file nf90_inq_varid xhy_varid" ) - call check( nf90_inq_varid(self%id, self%xhz_varname, self%xhz_varid), "encounter_io_open_file nf90_inq_varid xhz_varid" ) - call check( nf90_inq_varid(self%id, self%vhx_varname, self%vhx_varid), "encounter_io_open_file nf90_inq_varid vhx_varid" ) - call check( nf90_inq_varid(self%id, self%vhy_varname, self%vhy_varid), "encounter_io_open_file nf90_inq_varid vhy_varid" ) - call check( nf90_inq_varid(self%id, self%vhz_varname, self%vhz_varid), "encounter_io_open_file nf90_inq_varid vhz_varid" ) - call check( nf90_inq_varid(self%id, self%level_varname, self%level_varid), "encounter_io_open_file nf90_inq_varid level_varid" ) - call check( nf90_inq_varid(self%id, self%gmass_varname, self%Gmass_varid), "encounter_io_open_file nf90_inq_varid Gmass_varid" ) - call check( nf90_inq_varid(self%id, self%radius_varname, self%radius_varid), "encounter_io_open_file nf90_inq_varid radius_varid" ) + ! call check( nf90_inq_dimid(self%id, self%time_dimname, self%time_dimid), "encounter_io_open_file nf90_inq_dimid time_dimid" ) + ! call check( nf90_inq_dimid(self%id, self%eid_dimname, self%eid_dimid), "encounter_io_open_file nf90_inq_dimid eid_dimid" ) + ! call check( nf90_inq_dimid(self%id, self%collider_dimname, self%collider_dimid), "encounter_io_open_file nf90_inq_dimid collider_dimid" ) + ! call check( nf90_inq_dimid(self%id, self%str_dimname, self%str_dimid), "encounter_io_open_file nf90_inq_dimid collider_str" ) + + ! call check( nf90_inq_varid(self%id, self%time_dimname, self%time_varid), "encounter_io_open_file nf90_inq_varid time_varid" ) + ! call check( nf90_inq_varid(self%id, self%name_varname, self%name_varid), "encounter_io_open_file nf90_inq_varid name_varid" ) + ! call check( nf90_inq_varid(self%id, self%nenc_varname, self%nenc_varid), "encounter_io_open_file nf90_inq_varid nenc_varid" ) + + ! call check( nf90_inq_varid(self%id, self%xhx_varname, self%xhx_varid), "encounter_io_open_file nf90_inq_varid xhx_varid" ) + ! call check( nf90_inq_varid(self%id, self%xhy_varname, self%xhy_varid), "encounter_io_open_file nf90_inq_varid xhy_varid" ) + ! call check( nf90_inq_varid(self%id, self%xhz_varname, self%xhz_varid), "encounter_io_open_file nf90_inq_varid xhz_varid" ) + ! call check( nf90_inq_varid(self%id, self%vhx_varname, self%vhx_varid), "encounter_io_open_file nf90_inq_varid vhx_varid" ) + ! call check( nf90_inq_varid(self%id, self%vhy_varname, self%vhy_varid), "encounter_io_open_file nf90_inq_varid vhy_varid" ) + ! call check( nf90_inq_varid(self%id, self%vhz_varname, self%vhz_varid), "encounter_io_open_file nf90_inq_varid vhz_varid" ) + ! call check( nf90_inq_varid(self%id, self%level_varname, self%level_varid), "encounter_io_open_file nf90_inq_varid level_varid" ) + ! call check( nf90_inq_varid(self%id, self%gmass_varname, self%Gmass_varid), "encounter_io_open_file nf90_inq_varid Gmass_varid" ) + ! call check( nf90_inq_varid(self%id, self%radius_varname, self%radius_varid), "encounter_io_open_file nf90_inq_varid radius_varid" ) return end subroutine encounter_io_open_file @@ -167,29 +163,29 @@ module subroutine encounter_io_write_frame(self, iu, param) call check( nf90_set_fill(iu%id, nf90_nofill, old_mode), "encounter_io_write_frame_base nf90_set_fill" ) call check( nf90_put_var(iu%id, iu%time_varid, self%t, start=[i]), "encounter_io_write_frame nf90_put_var time_varid" ) - call check( nf90_put_var(iu%id, iu%nenc_varid, self%nenc, start=[i]), "encounter_io_frame nf90_put_var nenc_varid" ) - call check( nf90_put_var(iu%id, iu%name_varid, self%name1(1:n), start=[1, 1, i], count=[NAMELEN,1,1]), "netcdf_write_frame nf90_put_var name 1" ) - call check( nf90_put_var(iu%id, iu%name_varid, self%name2(1:n), start=[1, 2, i], count=[NAMELEN,1,1]), "netcdf_write_frame nf90_put_var name 2" ) - call check( nf90_put_var(iu%id, iu%xhx_varid, self%x1(1, 1:n), start=[1, 1, i], count=[1,n,1]), "netcdf_write_frame nf90_put_var xhx_varid 1" ) - call check( nf90_put_var(iu%id, iu%xhy_varid, self%x1(2, 1:n), start=[1, 1, i], count=[1,n,1]), "netcdf_write_frame nf90_put_var xhy_varid 1" ) - call check( nf90_put_var(iu%id, iu%xhz_varid, self%x1(3, 1:n), start=[1, 1, i], count=[1,n,1]), "netcdf_write_frame nf90_put_var xhz_varid 1" ) - call check( nf90_put_var(iu%id, iu%xhx_varid, self%x2(1, 1:n), start=[2, 1, i], count=[1,n,1]), "netcdf_write_frame nf90_put_var xhx_varid 2" ) - call check( nf90_put_var(iu%id, iu%xhy_varid, self%x2(2, 1:n), start=[2, 1, i], count=[1,n,1]), "netcdf_write_frame nf90_put_var xhy_varid 2" ) - call check( nf90_put_var(iu%id, iu%xhz_varid, self%x2(3, 1:n), start=[2, 1, i], count=[1,n,1]), "netcdf_write_frame nf90_put_var xhz_varid 2" ) - call check( nf90_put_var(iu%id, iu%vhx_varid, self%v1(1, 1:n), start=[1, 1, i], count=[1,n,1]), "netcdf_write_frame nf90_put_var vhx_varid 1" ) - call check( nf90_put_var(iu%id, iu%vhy_varid, self%v1(2, 1:n), start=[1, 1, i], count=[1,n,1]), "netcdf_write_frame nf90_put_var vhy_varid 1" ) - call check( nf90_put_var(iu%id, iu%vhz_varid, self%v1(3, 1:n), start=[1, 1, i], count=[1,n,1]), "netcdf_write_frame nf90_put_var vhz_varid 1" ) - call check( nf90_put_var(iu%id, iu%vhx_varid, self%v2(1, 1:n), start=[2, 1, i], count=[1,n,1]), "netcdf_write_frame nf90_put_var vhx_varid 2" ) - call check( nf90_put_var(iu%id, iu%vhy_varid, self%v2(2, 1:n), start=[2, 1, i], count=[1,n,1]), "netcdf_write_frame nf90_put_var vhy_varid 2" ) - call check( nf90_put_var(iu%id, iu%vhz_varid, self%v2(3, 1:n), start=[2, 1, i], count=[1,n,1]), "netcdf_write_frame nf90_put_var vhz_varid 2" ) - call check( nf90_put_var(iu%id, iu%Gmass_varid, self%Gmass1(1:n), start=[1, 1, i], count=[1,n,1]), "netcdf_write_frame nf90_put_var Gmass 1" ) - call check( nf90_put_var(iu%id, iu%Gmass_varid, self%Gmass2(1:n), start=[2, 1, i], count=[1,n,1]), "netcdf_write_frame nf90_put_var Gmass 2" ) - call check( nf90_put_var(iu%id, iu%radius_varid, self%radius1(1:n), start=[1, 1, i], count=[1,n,1]), "netcdf_write_frame nf90_put_var radius 1" ) - call check( nf90_put_var(iu%id, iu%radius_varid, self%radius2(1:n), start=[2, 1, i], count=[1,n,1]), "netcdf_write_frame nf90_put_var radius 2" ) - select type(self) - class is (symba_encounter) - call check( nf90_put_var(iu%id, iu%level_varid, self%level(1:n), start=[1, i], count=[n,1]), "netcdf_write_frame nf90_put_var level" ) - end select + ! call check( nf90_put_var(iu%id, iu%nenc_varid, self%nenc, start=[i]), "encounter_io_frame nf90_put_var nenc_varid" ) + ! call check( nf90_put_var(iu%id, iu%name_varid, self%name1(1:n), start=[1, 1, i], count=[NAMELEN,1,1]), "netcdf_write_frame nf90_put_var name 1" ) + ! call check( nf90_put_var(iu%id, iu%name_varid, self%name2(1:n), start=[1, 2, i], count=[NAMELEN,1,1]), "netcdf_write_frame nf90_put_var name 2" ) + ! call check( nf90_put_var(iu%id, iu%xhx_varid, self%x1(1, 1:n), start=[1, 1, i], count=[1,n,1]), "netcdf_write_frame nf90_put_var xhx_varid 1" ) + ! call check( nf90_put_var(iu%id, iu%xhy_varid, self%x1(2, 1:n), start=[1, 1, i], count=[1,n,1]), "netcdf_write_frame nf90_put_var xhy_varid 1" ) + ! call check( nf90_put_var(iu%id, iu%xhz_varid, self%x1(3, 1:n), start=[1, 1, i], count=[1,n,1]), "netcdf_write_frame nf90_put_var xhz_varid 1" ) + ! call check( nf90_put_var(iu%id, iu%xhx_varid, self%x2(1, 1:n), start=[2, 1, i], count=[1,n,1]), "netcdf_write_frame nf90_put_var xhx_varid 2" ) + ! call check( nf90_put_var(iu%id, iu%xhy_varid, self%x2(2, 1:n), start=[2, 1, i], count=[1,n,1]), "netcdf_write_frame nf90_put_var xhy_varid 2" ) + ! call check( nf90_put_var(iu%id, iu%xhz_varid, self%x2(3, 1:n), start=[2, 1, i], count=[1,n,1]), "netcdf_write_frame nf90_put_var xhz_varid 2" ) + ! call check( nf90_put_var(iu%id, iu%vhx_varid, self%v1(1, 1:n), start=[1, 1, i], count=[1,n,1]), "netcdf_write_frame nf90_put_var vhx_varid 1" ) + ! call check( nf90_put_var(iu%id, iu%vhy_varid, self%v1(2, 1:n), start=[1, 1, i], count=[1,n,1]), "netcdf_write_frame nf90_put_var vhy_varid 1" ) + ! call check( nf90_put_var(iu%id, iu%vhz_varid, self%v1(3, 1:n), start=[1, 1, i], count=[1,n,1]), "netcdf_write_frame nf90_put_var vhz_varid 1" ) + ! call check( nf90_put_var(iu%id, iu%vhx_varid, self%v2(1, 1:n), start=[2, 1, i], count=[1,n,1]), "netcdf_write_frame nf90_put_var vhx_varid 2" ) + ! call check( nf90_put_var(iu%id, iu%vhy_varid, self%v2(2, 1:n), start=[2, 1, i], count=[1,n,1]), "netcdf_write_frame nf90_put_var vhy_varid 2" ) + ! call check( nf90_put_var(iu%id, iu%vhz_varid, self%v2(3, 1:n), start=[2, 1, i], count=[1,n,1]), "netcdf_write_frame nf90_put_var vhz_varid 2" ) + ! call check( nf90_put_var(iu%id, iu%Gmass_varid, self%Gmass1(1:n), start=[1, 1, i], count=[1,n,1]), "netcdf_write_frame nf90_put_var Gmass 1" ) + ! call check( nf90_put_var(iu%id, iu%Gmass_varid, self%Gmass2(1:n), start=[2, 1, i], count=[1,n,1]), "netcdf_write_frame nf90_put_var Gmass 2" ) + ! call check( nf90_put_var(iu%id, iu%radius_varid, self%radius1(1:n), start=[1, 1, i], count=[1,n,1]), "netcdf_write_frame nf90_put_var radius 1" ) + ! call check( nf90_put_var(iu%id, iu%radius_varid, self%radius2(1:n), start=[2, 1, i], count=[1,n,1]), "netcdf_write_frame nf90_put_var radius 2" ) + ! select type(self) + ! class is (symba_encounter) + ! call check( nf90_put_var(iu%id, iu%level_varid, self%level(1:n), start=[1, i], count=[n,1]), "netcdf_write_frame nf90_put_var level" ) + ! end select return end subroutine encounter_io_write_frame diff --git a/src/fraggle/fraggle_io.f90 b/src/fraggle/fraggle_io.f90 index b1a60a25b..87d2d7d11 100644 --- a/src/fraggle/fraggle_io.f90 +++ b/src/fraggle/fraggle_io.f90 @@ -108,9 +108,9 @@ module subroutine fraggle_io_log_pl(pl, param) do i = 1, pl%nbody write(LUN, *) i, pl%vb(:,i) end do - write(LUN, *) "xh" + write(LUN, *) "rh" do i = 1, pl%nbody - write(LUN, *) i, pl%xh(:,i) + write(LUN, *) i, pl%rh(:,i) end do write(LUN, *) "vh" do i = 1, pl%nbody diff --git a/src/fraggle/fraggle_util.f90 b/src/fraggle/fraggle_util.f90 index e03e30eb5..5c0803912 100644 --- a/src/fraggle/fraggle_util.f90 +++ b/src/fraggle/fraggle_util.f90 @@ -37,7 +37,7 @@ module subroutine fraggle_util_add_fragments_to_system(frag, colliders, system, do concurrent (i = 1:nfrag) pl%xb(:,npl_before+i) = frag%xb(:,i) pl%vb(:,npl_before+i) = frag%vb(:,i) - pl%xh(:,npl_before+i) = frag%xb(:,i) - cb%xb(:) + pl%rh(:,npl_before+i) = frag%xb(:,i) - cb%xb(:) pl%vh(:,npl_before+i) = frag%vb(:,i) - cb%vb(:) end do if (param%lrotation) then diff --git a/src/gr/gr.f90 b/src/gr/gr.f90 index 8b32c7654..0d7fb7aaa 100644 --- a/src/gr/gr.f90 +++ b/src/gr/gr.f90 @@ -34,11 +34,11 @@ pure module subroutine gr_kick_getaccb_ns_body(self, system, param) associate(n => self%nbody, cb => system%cb, inv_c2 => param%inv_c2) if (n == 0) return do i = 1, n - rmag = norm2(self%xh(:,i)) + rmag = norm2(self%rh(:,i)) vmag2 = dot_product(self%vh(:,i), self%vh(:,i)) - rdotv = dot_product(self%xh(:,i), self%vh(:,i)) + rdotv = dot_product(self%rh(:,i), self%vh(:,i)) self%agr(:, i) = self%mu * inv_c2 / rmag**3 * ((4 * self%mu(i) / rmag - vmag2) & - * self%xh(:,i) + 4 * rdotv * self%vh(:,i)) + * self%rh(:,i) + 4 * rdotv * self%vh(:,i)) end do select type(self) @@ -113,7 +113,7 @@ pure module subroutine gr_p4_pos_kick(param, x, v, dt) end subroutine gr_p4_pos_kick - pure module subroutine gr_pseudovel2vel(param, mu, xh, pv, vh) + pure module subroutine gr_pseudovel2vel(param, mu, rh, pv, vh) !! author: David A. Minton !! !! Converts the relativistic pseudovelocity back into a veliocentric velocity @@ -128,7 +128,7 @@ pure module subroutine gr_pseudovel2vel(param, mu, xh, pv, vh) ! Arguments class(swiftest_parameters), intent(in) :: param !! Current run configuration parameters real(DP), intent(in) :: mu !! G * (Mcb + m), G = gravitational constant, Mcb = mass of central body, m = mass of body - real(DP), dimension(:), intent(in) :: xh !! Heliocentric position vector + real(DP), dimension(:), intent(in) :: rh !! Heliocentric position vector real(DP), dimension(:), intent(in) :: pv !! Pseudovelocity velocity vector - see Saha & Tremain (1994), eq. (32) real(DP), dimension(:), intent(out) :: vh !! Heliocentric velocity vector ! Internals @@ -136,7 +136,7 @@ pure module subroutine gr_pseudovel2vel(param, mu, xh, pv, vh) associate(inv_c2 => param%inv_c2) vmag2 = dot_product(pv(:), pv(:)) - rmag = norm2(xh(:)) + rmag = norm2(rh(:)) grterm = 1.0_DP - inv_c2 * (0.5_DP * vmag2 + 3 * mu / rmag) vh(:) = pv(:) * grterm end associate @@ -161,7 +161,7 @@ pure module subroutine gr_pv2vh_body(self, param) if (n == 0) return allocate(vh, mold = self%vh) do i = 1, n - call gr_pseudovel2vel(param, self%mu(i), self%xh(:, i), self%vh(:, i), vh(:, i)) + call gr_pseudovel2vel(param, self%mu(i), self%rh(:, i), self%vh(:, i), vh(:, i)) end do call move_alloc(vh, self%vh) end associate @@ -170,7 +170,7 @@ pure module subroutine gr_pv2vh_body(self, param) end subroutine gr_pv2vh_body - pure module subroutine gr_vel2pseudovel(param, mu, xh, vh, pv) + pure module subroutine gr_vel2pseudovel(param, mu, rh, vh, pv) !! author: David A. Minton !! !! Converts the heliocentric velocity into a pseudovelocity with relativistic corrections. @@ -186,7 +186,7 @@ pure module subroutine gr_vel2pseudovel(param, mu, xh, vh, pv) ! Arguments class(swiftest_parameters), intent(in) :: param !! Current run configuration parameters real(DP), intent(in) :: mu !! G * (Mcb + m), G = gravitational constant, Mcb = mass of central body, m = mass of body - real(DP), dimension(:), intent(in) :: xh !! Heliocentric position vector + real(DP), dimension(:), intent(in) :: rh !! Heliocentric position vector real(DP), dimension(:), intent(in) :: vh !! Heliocentric velocity vector real(DP), dimension(:), intent(out) :: pv !! Pseudovelocity vector - see Saha & Tremain (1994), eq. (32) ! Internals @@ -199,7 +199,7 @@ pure module subroutine gr_vel2pseudovel(param, mu, xh, vh, pv) associate(inv_c2 => param%inv_c2) pv(1:NDIM) = vh(1:NDIM) ! Initial guess - rterm = 3 * mu / norm2(xh(:)) + rterm = 3 * mu / norm2(rh(:)) v2 = dot_product(vh(:), vh(:)) do n = 1, MAXITER pv2 = dot_product(pv(:), pv(:)) @@ -263,7 +263,7 @@ pure module subroutine gr_vh2pv_body(self, param) if (n == 0) return allocate(pv, mold = self%vh) do i = 1, n - call gr_vel2pseudovel(param, self%mu(i), self%xh(:, i), self%vh(:, i), pv(:, i)) + call gr_vel2pseudovel(param, self%mu(i), self%rh(:, i), self%vh(:, i), pv(:, i)) end do call move_alloc(pv, self%vh) end associate diff --git a/src/helio/helio_drift.f90 b/src/helio/helio_drift.f90 index 1076532c0..06e98e0fa 100644 --- a/src/helio/helio_drift.f90 +++ b/src/helio/helio_drift.f90 @@ -36,7 +36,7 @@ module subroutine helio_drift_body(self, system, param, dt) iflag(:) = 0 allocate(mu(n)) mu(:) = system%cb%Gmass - call drift_all(mu, self%xh, self%vb, self%nbody, param, dt, self%lmask, iflag) + call drift_all(mu, self%rh, self%vb, self%nbody, param, dt, self%lmask, iflag) if (any(iflag(1:n) /= 0)) then where(iflag(1:n) /= 0) self%status(1:n) = DISCARDED_DRIFTERR do i = 1, n @@ -84,29 +84,29 @@ module subroutine helio_drift_tp(self, system, param, dt) end subroutine helio_drift_tp - pure elemental subroutine helio_drift_linear_one(xhx, xhy, xhz, ptx, pty, ptz, dt) + pure elemental subroutine helio_drift_linear_one(rhx, rhy, rhz, ptx, pty, ptz, dt) !! author: David A. Minton !! !! Calculate the linear drift for a single body implicit none - real(DP), intent(inout) :: xhx, xhy, xhz + real(DP), intent(inout) :: rhx, rhy, rhz real(DP), intent(in) :: ptx, pty, ptz, dt - xhx = xhx + ptx * dt - xhy = xhy + pty * dt - xhz = xhz + ptz * dt + rhx = rhx + ptx * dt + rhy = rhy + pty * dt + rhz = rhz + ptz * dt return end subroutine helio_drift_linear_one - subroutine helio_drift_linear_all(xh, pt, dt, n, lmask) + subroutine helio_drift_linear_all(rh, pt, dt, n, lmask) !! author: David A. Minton !! !! Loop through all the bodies and calculate the linear drift implicit none ! Arguments - real(DP), dimension(:,:), intent(inout) :: xh + real(DP), dimension(:,:), intent(inout) :: rh real(DP), dimension(:), intent(in) :: pt real(DP), intent(in) :: dt integer(I4B), intent(in) :: n @@ -115,7 +115,7 @@ subroutine helio_drift_linear_all(xh, pt, dt, n, lmask) integer(I4B) :: i do i = 1, n - if (lmask(i)) call helio_drift_linear_one(xh(1,i), xh(2,i), xh(3,i), pt(1), pt(2), pt(3), dt) + if (lmask(i)) call helio_drift_linear_one(rh(1,i), rh(2,i), rh(3,i), pt(1), pt(2), pt(3), dt) end do return @@ -146,7 +146,7 @@ module subroutine helio_drift_linear_pl(self, cb, dt, lbeg) pt(2) = sum(pl%Gmass(1:npl) * pl%vb(2,1:npl), self%lmask(1:npl)) pt(3) = sum(pl%Gmass(1:npl) * pl%vb(3,1:npl), self%lmask(1:npl)) pt(:) = pt(:) / cb%Gmass - call helio_drift_linear_all(pl%xh(:,:), pt(:), dt, npl, pl%lmask(:)) + call helio_drift_linear_all(pl%rh(:,:), pt(:), dt, npl, pl%lmask(:)) if (lbeg) then cb%ptbeg = pt(:) @@ -186,9 +186,9 @@ module subroutine helio_drift_linear_tp(self, cb, dt, lbeg) pt(:) = cb%ptend end if where (self%lmask(1:ntp)) - tp%xh(1, 1:ntp) = tp%xh(1, 1:ntp) + pt(1) * dt - tp%xh(2, 1:ntp) = tp%xh(2, 1:ntp) + pt(2) * dt - tp%xh(3, 1:ntp) = tp%xh(3, 1:ntp) + pt(3) * dt + tp%rh(1, 1:ntp) = tp%rh(1, 1:ntp) + pt(1) * dt + tp%rh(2, 1:ntp) = tp%rh(2, 1:ntp) + pt(2) * dt + tp%rh(3, 1:ntp) = tp%rh(3, 1:ntp) + pt(3) * dt end where end associate diff --git a/src/helio/helio_gr.f90 b/src/helio/helio_gr.f90 index 5ffbf60b2..13209ce1a 100644 --- a/src/helio/helio_gr.f90 +++ b/src/helio/helio_gr.f90 @@ -26,7 +26,7 @@ pure module subroutine helio_gr_kick_getacch_pl(self, param) if (self%nbody == 0) return associate(pl => self, npl => self%nbody) - call gr_kick_getacch(pl%mu, pl%xh, pl%lmask, npl, param%inv_c2, pl%agr) + call gr_kick_getacch(pl%mu, pl%rh, pl%lmask, npl, param%inv_c2, pl%agr) pl%ah(:,1:npl) = pl%ah(:,1:npl) + pl%agr(:,1:npl) end associate @@ -49,7 +49,7 @@ pure module subroutine helio_gr_kick_getacch_tp(self, param) if (self%nbody == 0) return associate(tp => self, ntp => self%nbody) - call gr_kick_getacch(tp%mu, tp%xh, tp%lmask, ntp, param%inv_c2, tp%agr) + call gr_kick_getacch(tp%mu, tp%rh, tp%lmask, ntp, param%inv_c2, tp%agr) tp%ah(:,1:ntp) = tp%ah(:,1:ntp) + tp%agr(:,1:ntp) end associate @@ -77,7 +77,7 @@ pure module subroutine helio_gr_p4_pl(self, system, param, dt) associate(pl => self, npl => self%nbody) do concurrent(i = 1:npl, pl%lmask(i)) - call gr_p4_pos_kick(param, pl%xh(:, i), pl%vb(:, i), dt) + call gr_p4_pos_kick(param, pl%rh(:, i), pl%vb(:, i), dt) end do end associate @@ -105,7 +105,7 @@ pure module subroutine helio_gr_p4_tp(self, system, param, dt) associate(tp => self, ntp => self%nbody) do concurrent(i = 1:ntp, tp%lmask(i)) - call gr_p4_pos_kick(param, tp%xh(:, i), tp%vb(:, i), dt) + call gr_p4_pos_kick(param, tp%rh(:, i), tp%vb(:, i), dt) end do end associate diff --git a/src/helio/helio_kick.f90 b/src/helio/helio_kick.f90 index 067a6195c..b5161b405 100644 --- a/src/helio/helio_kick.f90 +++ b/src/helio/helio_kick.f90 @@ -112,9 +112,9 @@ module subroutine helio_kick_vb_pl(self, system, param, t, dt, lbeg) pl%ah(:, 1:npl) = 0.0_DP call pl%accel(system, param, t, lbeg) if (lbeg) then - call pl%set_beg_end(xbeg = pl%xh) + call pl%set_beg_end(xbeg = pl%rh) else - call pl%set_beg_end(xend = pl%xh) + call pl%set_beg_end(xend = pl%rh) end if do concurrent(i = 1:npl, pl%lmask(i)) pl%vb(1, i) = pl%vb(1, i) + pl%ah(1, i) * dt diff --git a/src/io/io.f90 b/src/io/io.f90 index b0a752863..e0b381aec 100644 --- a/src/io/io.f90 +++ b/src/io/io.f90 @@ -1381,7 +1381,7 @@ module function io_read_frame_body(self, iu, param) result(ierr) select case(param%in_form) case ("XV") - read(iu, *, err = 667, iomsg = errmsg) self%xh(1, i), self%xh(2, i), self%xh(3, i) + read(iu, *, err = 667, iomsg = errmsg) self%rh(1, i), self%rh(2, i), self%rh(3, i) read(iu, *, err = 667, iomsg = errmsg) self%vh(1, i), self%vh(2, i), self%vh(3, i) case ("EL") read(iu, *, err = 667, iomsg = errmsg) self%a(i), self%e(i), self%inc(i) diff --git a/src/kick/kick.f90 b/src/kick/kick.f90 index dd0682bf0..40b238fec 100644 --- a/src/kick/kick.f90 +++ b/src/kick/kick.f90 @@ -43,15 +43,15 @@ module subroutine kick_getacch_int_pl(self, param) if (param%lflatten_interactions) then if (param%lclose) then - call kick_getacch_int_all_flat_pl(self%nbody, self%nplpl, self%k_plpl, self%xh, self%Gmass, self%radius, self%ah) + call kick_getacch_int_all_flat_pl(self%nbody, self%nplpl, self%k_plpl, self%rh, self%Gmass, self%radius, self%ah) else - call kick_getacch_int_all_flat_pl(self%nbody, self%nplpl, self%k_plpl, self%xh, self%Gmass, acc=self%ah) + call kick_getacch_int_all_flat_pl(self%nbody, self%nplpl, self%k_plpl, self%rh, self%Gmass, acc=self%ah) end if else if (param%lclose) then - call kick_getacch_int_all_triangular_pl(self%nbody, self%nbody, self%xh, self%Gmass, self%radius, self%ah) + call kick_getacch_int_all_triangular_pl(self%nbody, self%nbody, self%rh, self%Gmass, self%radius, self%ah) else - call kick_getacch_int_all_triangular_pl(self%nbody, self%nbody, self%xh, self%Gmass, acc=self%ah) + call kick_getacch_int_all_triangular_pl(self%nbody, self%nbody, self%rh, self%Gmass, acc=self%ah) end if end if @@ -80,7 +80,7 @@ module subroutine kick_getacch_int_tp(self, param, GMpl, xhp, npl) if ((self%nbody == 0) .or. (npl == 0)) return - call kick_getacch_int_all_tp(self%nbody, npl, self%xh, xhp, GMpl, self%lmask, self%ah) + call kick_getacch_int_all_tp(self%nbody, npl, self%rh, xhp, GMpl, self%lmask, self%ah) return end subroutine kick_getacch_int_tp diff --git a/src/modules/swiftest_classes.f90 b/src/modules/swiftest_classes.f90 index 302d09eea..73ad063e6 100644 --- a/src/modules/swiftest_classes.f90 +++ b/src/modules/swiftest_classes.f90 @@ -244,11 +244,11 @@ module swiftest_classes 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 integer(I4B) :: collision_id !! The ID of the collision that formed the particle - real(DP), dimension(NDIM) :: origin_xh !! The heliocentric distance vector at the time of the particle's formation + real(DP), dimension(NDIM) :: origin_rh !! 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 real(DP) :: discard_time !! The time of the particle's discard character(len=NAMELEN) :: status !! Particle status description: Active, Merged, Fragmented, etc. - real(DP), dimension(NDIM) :: discard_xh !! The heliocentric distance vector at the time of the particle's discard + real(DP), dimension(NDIM) :: discard_rh !! The heliocentric distance vector at the time of the particle's discard real(DP), dimension(NDIM) :: discard_vh !! The heliocentric velocity vector at the time of the particle's discard integer(I4B) :: discard_body_id !! The id of the other body involved in the discard (0 if no other body involved) contains @@ -314,7 +314,7 @@ module swiftest_classes logical, dimension(:), allocatable :: ldiscard !! Body should be discarded logical, dimension(:), allocatable :: lmask !! Logical mask used to select a subset of bodies when performing certain operations (drift, kick, accel, etc.) real(DP), dimension(:), allocatable :: mu !! G * (Mcb + [m]) - real(DP), dimension(:,:), allocatable :: xh !! Swiftestcentric position + real(DP), dimension(:,:), allocatable :: rh !! Swiftestcentric position real(DP), dimension(:,:), allocatable :: vh !! Swiftestcentric velocity real(DP), dimension(:,:), allocatable :: xb !! Barycentric position real(DP), dimension(:,:), allocatable :: vb !! Barycentric velocity @@ -396,7 +396,7 @@ module swiftest_classes procedure :: b2h => util_coord_b2h_pl !! Convert massive bodies from barycentric to heliocentric coordinates (position and velocity) procedure :: vh2vb => util_coord_vh2vb_pl !! Convert massive bodies from heliocentric to barycentric coordinates (velocity only) procedure :: vb2vh => util_coord_vb2vh_pl !! Convert massive bodies from barycentric to heliocentric coordinates (velocity only) - procedure :: xh2xb => util_coord_xh2xb_pl !! Convert massive bodies from heliocentric to barycentric coordinates (position only) + procedure :: xh2xb => util_coord_rh2xb_pl !! Convert massive bodies from heliocentric to barycentric coordinates (position only) procedure :: dealloc => util_dealloc_pl !! Deallocates all allocatable arrays procedure :: fill => util_fill_pl !! "Fills" bodies from one object into another depending on the results of a mask (uses the UNPACK intrinsic) procedure :: resize => util_resize_pl !! Checks the current size of a Swiftest body against the requested size and resizes it if it is too small. @@ -436,7 +436,7 @@ module swiftest_classes procedure :: b2h => util_coord_b2h_tp !! Convert test particles from barycentric to heliocentric coordinates (position and velocity) procedure :: vb2vh => util_coord_vb2vh_tp !! Convert test particles from barycentric to heliocentric coordinates (velocity only) procedure :: vh2vb => util_coord_vh2vb_tp !! Convert test particles from heliocentric to barycentric coordinates (velocity only) - procedure :: xh2xb => util_coord_xh2xb_tp !! Convert test particles from heliocentric to barycentric coordinates (position only) + procedure :: xh2xb => util_coord_rh2xb_tp !! Convert test particles from heliocentric to barycentric coordinates (position only) procedure :: dealloc => util_dealloc_tp !! Deallocates all allocatable arrays procedure :: fill => util_fill_tp !! "Fills" bodies from one object into another depending on the results of a mask (uses the UNPACK intrinsic) procedure :: get_peri => util_peri_tp !! Determine system pericenter passages for test particles @@ -688,11 +688,11 @@ pure module subroutine gr_p4_pos_kick(param, x, v, dt) real(DP), intent(in) :: dt !! Step size end subroutine gr_p4_pos_kick - pure module subroutine gr_pseudovel2vel(param, mu, xh, pv, vh) + pure module subroutine gr_pseudovel2vel(param, mu, rh, pv, vh) implicit none class(swiftest_parameters), intent(in) :: param !! Current run configuration parameters real(DP), intent(in) :: mu !! G * (Mcb + m), G = gravitational constant, Mcb = mass of central body, m = mass of body - real(DP), dimension(:), intent(in) :: xh !! Swiftestcentric position vector + real(DP), dimension(:), intent(in) :: rh !! Swiftestcentric position vector real(DP), dimension(:), intent(in) :: pv !! Pseudovelocity velocity vector - see Saha & Tremain (1994), eq. (32) real(DP), dimension(:), intent(out) :: vh !! Swiftestcentric velocity vector end subroutine gr_pseudovel2vel @@ -703,11 +703,11 @@ pure module subroutine gr_pv2vh_body(self, param) class(swiftest_parameters), intent(in) :: param !! Current run configuration parameters end subroutine gr_pv2vh_body - pure module subroutine gr_vel2pseudovel(param, mu, xh, vh, pv) + pure module subroutine gr_vel2pseudovel(param, mu, rh, vh, pv) implicit none class(swiftest_parameters), intent(in) :: param !! Current run configuration parameters real(DP), intent(in) :: mu !! G * (Mcb + m), G = gravitational constant, Mcb = mass of central body, m = mass of body - real(DP), dimension(:), intent(in) :: xh !! Swiftestcentric position vector + real(DP), dimension(:), intent(in) :: rh !! Swiftestcentric position vector real(DP), dimension(:), intent(in) :: vh !! Swiftestcentric velocity vector real(DP), dimension(:), intent(out) :: pv !! Pseudovelocity vector - see Saha & Tremain (1994), eq. (32) end subroutine gr_vel2pseudovel @@ -1336,17 +1336,17 @@ module subroutine util_coord_vh2vb_tp(self, vbcb) real(DP), dimension(:), intent(in) :: vbcb !! Barycentric velocity of the central body end subroutine util_coord_vh2vb_tp - module subroutine util_coord_xh2xb_pl(self, cb) + module subroutine util_coord_rh2xb_pl(self, cb) implicit none class(swiftest_pl), intent(inout) :: self !! Swiftest massive body object class(swiftest_cb), intent(inout) :: cb !! Swiftest central body object - end subroutine util_coord_xh2xb_pl + end subroutine util_coord_rh2xb_pl - module subroutine util_coord_xh2xb_tp(self, cb) + module subroutine util_coord_rh2xb_tp(self, cb) implicit none class(swiftest_tp), intent(inout) :: self !! Swiftest test particle object class(swiftest_cb), intent(in) :: cb !! Swiftest central body object - end subroutine util_coord_xh2xb_tp + end subroutine util_coord_rh2xb_tp module subroutine util_copy_particle_info(self, source) implicit none @@ -1618,7 +1618,7 @@ module subroutine util_set_mu_tp(self, cb) end subroutine util_set_mu_tp module subroutine util_set_particle_info(self, name, particle_type, status, origin_type, origin_time, collision_id, & - origin_xh, origin_vh, discard_time, discard_xh, discard_vh, discard_body_id) + origin_rh, origin_vh, discard_time, discard_rh, discard_vh, discard_body_id) implicit none class(swiftest_particle_info), intent(inout) :: self character(len=*), intent(in), optional :: name !! Non-unique name @@ -1627,10 +1627,10 @@ module subroutine util_set_particle_info(self, name, particle_type, status, orig character(len=*), intent(in), optional :: origin_type !! String containing a description of the origin of the particle (e.g. Initial Conditions, Supercatastrophic, Disruption, etc.) real(DP), intent(in), optional :: origin_time !! The time of the particle's formation integer(I4B), intent(in), optional :: collision_id !! The ID fo the collision that formed the particle - real(DP), dimension(:), intent(in), optional :: origin_xh !! The heliocentric distance vector at the time of the particle's formation + real(DP), dimension(:), intent(in), optional :: origin_rh !! The heliocentric distance vector at the time of the particle's formation real(DP), dimension(:), intent(in), optional :: origin_vh !! The heliocentric velocity vector at the time of the particle's formation real(DP), intent(in), optional :: discard_time !! The time of the particle's discard - real(DP), dimension(:), intent(in), optional :: discard_xh !! The heliocentric distance vector at the time of the particle's discard + real(DP), dimension(:), intent(in), optional :: discard_rh !! The heliocentric distance vector at the time of the particle's discard real(DP), dimension(:), intent(in), optional :: discard_vh !! The heliocentric velocity vector at the time of the particle's discard integer(I4B), intent(in), optional :: discard_body_id !! The id of the other body involved in the discard (0 if no other body involved) end subroutine util_set_particle_info diff --git a/src/netcdf/netcdf.f90 b/src/netcdf/netcdf.f90 index 818fa3302..fd3bf2ec5 100644 --- a/src/netcdf/netcdf.f90 +++ b/src/netcdf/netcdf.f90 @@ -76,51 +76,37 @@ module function netcdf_get_old_t_final_system(self, param) result(old_t_final) ! Internals integer(I4B) :: itmax, idmax real(DP), dimension(:), allocatable :: vals - real(DP), dimension(1) :: val - real(DP), dimension(NDIM) :: rot0, Ip0, Lnow + real(DP), dimension(1) :: rtemp + real(DP), dimension(NDIM) :: vectemp, rot0, Ip0, Lnow real(DP) :: KE_orb_orig, KE_spin_orig, PE_orig call param%nciu%open(param) call check( nf90_inquire_dimension(param%nciu%id, param%nciu%time_dimid, len=itmax), "netcdf_get_old_t_final_system time_dimid" ) call check( nf90_inquire_dimension(param%nciu%id, param%nciu%id_dimid, len=idmax), "netcdf_get_old_t_final_system id_dimid" ) allocate(vals(idmax)) - call check( nf90_get_var(param%nciu%id, param%nciu%time_varid, val, start=[1], count=[1]), "netcdf_get_old_t_final_system time_varid" ) + call check( nf90_get_var(param%nciu%id, param%nciu%time_varid, rtemp, start=[1], count=[1]), "netcdf_get_old_t_final_system time_varid" ) - !old_t_final = val(1) + !old_t_final = rtemp(1) old_t_final = param%t0 ! For NetCDF it is safe to overwrite the final t value on a restart if (param%lenergy) then - call check( nf90_get_var(param%nciu%id, param%nciu%KE_orb_varid, val, start=[1], count=[1]), "netcdf_get_old_t_final_system KE_orb_varid" ) - KE_orb_orig = val(1) + call check( nf90_get_var(param%nciu%id, param%nciu%KE_orb_varid, rtemp, start=[1], count=[1]), "netcdf_get_old_t_final_system KE_orb_varid" ) + KE_orb_orig = rtemp(1) - call check( nf90_get_var(param%nciu%id, param%nciu%KE_spin_varid, val, start=[1], count=[1]), "netcdf_get_old_t_final_system KE_spin_varid" ) - KE_spin_orig = val(1) + call check( nf90_get_var(param%nciu%id, param%nciu%KE_spin_varid, rtemp, start=[1], count=[1]), "netcdf_get_old_t_final_system KE_spin_varid" ) + KE_spin_orig = rtemp(1) - call check( nf90_get_var(param%nciu%id, param%nciu%PE_varid, val, start=[1], count=[1]), "netcdf_get_old_t_final_system PE_varid" ) - PE_orig = val(1) + call check( nf90_get_var(param%nciu%id, param%nciu%PE_varid, rtemp, start=[1], count=[1]), "netcdf_get_old_t_final_system PE_varid" ) + PE_orig = rtemp(1) call check( nf90_get_var(param%nciu%id, param%nciu%Ecollisions_varid, self%Ecollisions, start=[1]), "netcdf_get_old_t_final_system Ecollisions_varid" ) call check( nf90_get_var(param%nciu%id, param%nciu%Euntracked_varid, self%Euntracked, start=[1]), "netcdf_get_old_t_final_system Euntracked_varid" ) self%Eorbit_orig = KE_orb_orig + KE_spin_orig + PE_orig + self%Ecollisions + self%Euntracked - call check( nf90_get_var(param%nciu%id, param%nciu%L_orbx_varid, val, start=[1], count=[1]), "netcdf_get_old_t_final_system L_orbx_varid" ) - self%Lorbit_orig(1) = val(1) - call check( nf90_get_var(param%nciu%id, param%nciu%L_orby_varid, val, start=[1], count=[1]), "netcdf_get_old_t_final_system L_orby_varid" ) - self%Lorbit_orig(2) = val(1) - call check( nf90_get_var(param%nciu%id, param%nciu%L_orbz_varid, val, start=[1], count=[1]), "netcdf_get_old_t_final_system L_orbz_varid" ) - self%Lorbit_orig(3) = val(1) - - call check( nf90_get_var(param%nciu%id, param%nciu%L_spinx_varid, val, start=[1], count=[1]), "netcdf_get_old_t_final_system L_spinx_varid" ) - self%Lspin_orig(1) = val(1) - call check( nf90_get_var(param%nciu%id, param%nciu%L_spiny_varid, val, start=[1], count=[1]), "netcdf_get_old_t_final_system L_spiny_varid" ) - self%Lspin_orig(2) = val(1) - call check( nf90_get_var(param%nciu%id, param%nciu%L_spinz_varid, val, start=[1], count=[1]), "netcdf_get_old_t_final_system L_spinz_varid" ) - self%Lspin_orig(3) = val(1) - - call check( nf90_get_var(param%nciu%id, param%nciu%L_escapex_varid, self%Lescape(1), start=[1]), "netcdf_get_old_t_final_system L_escapex_varid" ) - call check( nf90_get_var(param%nciu%id, param%nciu%L_escapey_varid, self%Lescape(2), start=[1]), "netcdf_get_old_t_final_system L_escapey_varid" ) - call check( nf90_get_var(param%nciu%id, param%nciu%L_escapez_varid, self%Lescape(3), start=[1]), "netcdf_get_old_t_final_system L_escapez_varid" ) + call check( nf90_get_var(param%nciu%id, param%nciu%L_orb_varid, self%Lorbit_orig(:), start=[1,1], count=[NDIM,1]), "netcdf_get_old_t_final_system L_orb_varid" ) + call check( nf90_get_var(param%nciu%id, param%nciu%L_spin_varid, self%Lspin_orig(:), start=[1,1], count=[NDIM,1]), "netcdf_get_old_t_final_system L_spin_varid" ) + call check( nf90_get_var(param%nciu%id, param%nciu%L_escape_varid, self%Lescape(:), start=[1,1], count=[NDIM,1]), "netcdf_get_old_t_final_system L_escape_varid" ) self%Ltot_orig(:) = self%Lorbit_orig(:) + self%Lspin_orig(:) + self%Lescape(:) @@ -133,24 +119,13 @@ module function netcdf_get_old_t_final_system(self, param) result(old_t_final) cb%GM0 = vals(1) cb%dGM = cb%Gmass - cb%GM0 - call check( nf90_get_var(param%nciu%id, param%nciu%radius_varid, val, start=[1,1], count=[1,1]), "netcdf_get_old_t_final_system radius_varid" ) - cb%R0 = val(1) + call check( nf90_get_var(param%nciu%id, param%nciu%radius_varid, rtemp, start=[1,1], count=[1,1]), "netcdf_get_old_t_final_system radius_varid" ) + cb%R0 = rtemp(1) if (param%lrotation) then - call check( nf90_get_var(param%nciu%id, param%nciu%rotx_varid, val, start=[1,1], count=[1,1]), "netcdf_get_old_t_final_system rotx_varid" ) - rot0(1) = val(1) - call check( nf90_get_var(param%nciu%id, param%nciu%roty_varid, val, start=[1,1], count=[1,1]), "netcdf_get_old_t_final_system roty_varid" ) - rot0(2) = val(1) - call check( nf90_get_var(param%nciu%id, param%nciu%rotz_varid, val, start=[1,1], count=[1,1]), "netcdf_get_old_t_final_system rotz_varid" ) - rot0(3) = val(1) - - call check( nf90_get_var(param%nciu%id, param%nciu%Ip1_varid, val, start=[1,1], count=[1,1]), "netcdf_get_old_t_final_system Ip1_varid" ) - Ip0(1) = val(1) - call check( nf90_get_var(param%nciu%id, param%nciu%Ip2_varid, val, start=[1,1], count=[1,1]), "netcdf_get_old_t_final_system Ip2_varid" ) - Ip0(2) = val(1) - call check( nf90_get_var(param%nciu%id, param%nciu%Ip3_varid, val, start=[1,1], count=[1,1]), "netcdf_get_old_t_final_system Ip3_varid" ) - Ip0(3) = val(1) + call check( nf90_get_var(param%nciu%id, param%nciu%rot_varid, rot0, start=[1,1,1], count=[NDIM,1,1]), "netcdf_get_old_t_final_system rot_varid" ) + call check( nf90_get_var(param%nciu%id, param%nciu%Ip_varid, Ip0, start=[1,1,1], count=[NDIM,1,1]), "netcdf_get_old_t_final_system Ip_varid" ) cb%L0(:) = Ip0(3) * cb%GM0 * cb%R0**2 * rot0(:) @@ -208,7 +183,7 @@ module subroutine netcdf_initialize_output(self, param) ! Dimensions call check( nf90_def_dim(nciu%id, nciu%time_dimname, NF90_UNLIMITED, nciu%time_dimid), "netcdf_initialize_output nf90_def_dim time_dimid" ) ! Simulation time dimension - call check( nf90_def_dim(nciu%id, nciu%space_dimname, 3, nciu%space_dimid), "netcdf_initialize_output nf90_def_dim space_dimid" ) ! 3D space dimension + call check( nf90_def_dim(nciu%id, nciu%space_dimname, NDIM, nciu%space_dimid), "netcdf_initialize_output nf90_def_dim space_dimid" ) ! 3D space dimension call check( nf90_def_dim(nciu%id, nciu%id_dimname, NF90_UNLIMITED, nciu%id_dimid), "netcdf_initialize_output nf90_def_dim id_dimid" ) ! dimension to store particle id numbers call check( nf90_def_dim(nciu%id, nciu%str_dimname, NAMELEN, nciu%str_dimid), "netcdf_initialize_output nf90_def_dim str_dimid" ) ! Dimension for string variables (aka character arrays) @@ -228,19 +203,11 @@ module subroutine netcdf_initialize_output(self, param) if ((param%out_form == "XV") .or. (param%out_form == "XVEL")) then call check( nf90_def_var(nciu%id, nciu%rh_varname, nciu%out_type, [nciu%space_dimid, nciu%id_dimid, nciu%time_dimid], nciu%rh_varid), "netcdf_initialize_output nf90_def_var rh_varid" ) call check( nf90_def_var(nciu%id, nciu%vh_varname, nciu%out_type, [nciu%space_dimid, nciu%id_dimid, nciu%time_dimid], nciu%vh_varid), "netcdf_initialize_output nf90_def_var vh_varid" ) - call check( nf90_def_var(nciu%id, nciu%xhx_varname, nciu%out_type, [nciu%id_dimid, nciu%time_dimid], nciu%xhx_varid), "netcdf_initialize_output nf90_def_var xhx_varid" ) - call check( nf90_def_var(nciu%id, nciu%xhy_varname, nciu%out_type, [nciu%id_dimid, nciu%time_dimid], nciu%xhy_varid), "netcdf_initialize_output nf90_def_var xhy_varid" ) - call check( nf90_def_var(nciu%id, nciu%xhz_varname, nciu%out_type, [nciu%id_dimid, nciu%time_dimid], nciu%xhz_varid), "netcdf_initialize_output nf90_def_var xhz_varid" ) - call check( nf90_def_var(nciu%id, nciu%vhx_varname, nciu%out_type, [nciu%id_dimid, nciu%time_dimid], nciu%vhx_varid), "netcdf_initialize_output nf90_def_var vhx_varid" ) - call check( nf90_def_var(nciu%id, nciu%vhy_varname, nciu%out_type, [nciu%id_dimid, nciu%time_dimid], nciu%vhy_varid), "netcdf_initialize_output nf90_def_var vhy_varid" ) - call check( nf90_def_var(nciu%id, nciu%vhz_varname, nciu%out_type, [nciu%id_dimid, nciu%time_dimid], nciu%vhz_varid), "netcdf_initialize_output nf90_def_var vhz_varid" ) !! When GR is enabled, we need to save the pseudovelocity vectors in addition to the true heliocentric velocity vectors, otherwise !! we cannnot expect bit-identical runs from restarted runs with GR enabled due to floating point errors during the conversion. if (param%lgr) then - call check( nf90_def_var(nciu%id, nciu%gr_pseudo_vhx_varname, nciu%out_type, [nciu%id_dimid, nciu%time_dimid], nciu%gr_pseudo_vhx_varid), "netcdf_initialize_output nf90_def_var gr_psuedo_vhx_varid" ) - call check( nf90_def_var(nciu%id, nciu%gr_pseudo_vhy_varname, nciu%out_type, [nciu%id_dimid, nciu%time_dimid], nciu%gr_pseudo_vhy_varid), "netcdf_initialize_output nf90_def_var gr_psuedo_vhy_varid" ) - call check( nf90_def_var(nciu%id, nciu%gr_pseudo_vhz_varname, nciu%out_type, [nciu%id_dimid, nciu%time_dimid], nciu%gr_pseudo_vhz_varid), "netcdf_initialize_output nf90_def_var gr_psuedo_vhz_varid" ) + call check( nf90_def_var(nciu%id, nciu%gr_pseudo_vh_varname, nciu%out_type, [nciu%space_dimid, nciu%id_dimid, nciu%time_dimid], nciu%gr_pseudo_vh_varid), "netcdf_initialize_output nf90_def_var gr_psuedo_vh_varid" ) nciu%lpseudo_vel_exists = .true. end if @@ -267,31 +234,19 @@ module subroutine netcdf_initialize_output(self, param) call check( nf90_def_var(nciu%id, nciu%origin_time_varname, nciu%out_type, nciu%id_dimid, nciu%origin_time_varid), "netcdf_initialize_output nf90_def_var origin_time_varid" ) call check( nf90_def_var(nciu%id, nciu%origin_type_varname, NF90_CHAR, [nciu%str_dimid, nciu%id_dimid], & nciu%origin_type_varid), "netcdf_initialize_output nf90_create" ) - call check( nf90_def_var(nciu%id, nciu%origin_xhx_varname, nciu%out_type, nciu%id_dimid, nciu%origin_xhx_varid), "netcdf_initialize_output nf90_def_var origin_xhx_varid" ) - call check( nf90_def_var(nciu%id, nciu%origin_xhy_varname, nciu%out_type, nciu%id_dimid, nciu%origin_xhy_varid), "netcdf_initialize_output nf90_def_var origin_xhy_varid" ) - call check( nf90_def_var(nciu%id, nciu%origin_xhz_varname, nciu%out_type, nciu%id_dimid, nciu%origin_xhz_varid), "netcdf_initialize_output nf90_def_var origin_xhz_varid" ) - call check( nf90_def_var(nciu%id, nciu%origin_vhx_varname, nciu%out_type, nciu%id_dimid, nciu%origin_vhx_varid), "netcdf_initialize_output nf90_def_var origin_vhx_varid" ) - call check( nf90_def_var(nciu%id, nciu%origin_vhy_varname, nciu%out_type, nciu%id_dimid, nciu%origin_vhy_varid), "netcdf_initialize_output nf90_def_var origin_vhy_varid" ) - call check( nf90_def_var(nciu%id, nciu%origin_vhz_varname, nciu%out_type, nciu%id_dimid, nciu%origin_vhz_varid), "netcdf_initialize_output nf90_def_var origin_vhz_varid" ) + call check( nf90_def_var(nciu%id, nciu%origin_rh_varname, nciu%out_type, [nciu%space_dimid, nciu%id_dimid], nciu%origin_rh_varid), "netcdf_initialize_output nf90_def_var origin_rh_varid" ) + call check( nf90_def_var(nciu%id, nciu%origin_vh_varname, nciu%out_type, [nciu%space_dimid, nciu%id_dimid], nciu%origin_vh_varid), "netcdf_initialize_output nf90_def_var origin_vh_varid" ) call check( nf90_def_var(nciu%id, nciu%collision_id_varname, NF90_INT, nciu%id_dimid, nciu%collision_id_varid), "netcdf_initialize_output nf90_def_var collision_id_varid" ) call check( nf90_def_var(nciu%id, nciu%discard_time_varname, nciu%out_type, nciu%id_dimid, nciu%discard_time_varid), "netcdf_initialize_output nf90_def_var discard_time_varid" ) - call check( nf90_def_var(nciu%id, nciu%discard_xhx_varname, nciu%out_type, nciu%id_dimid, nciu%discard_xhx_varid), "netcdf_initialize_output nf90_def_var discard_xhx_varid" ) - call check( nf90_def_var(nciu%id, nciu%discard_xhy_varname, nciu%out_type, nciu%id_dimid, nciu%discard_xhy_varid), "netcdf_initialize_output nf90_def_var discard_xhy_varid" ) - call check( nf90_def_var(nciu%id, nciu%discard_xhz_varname, nciu%out_type, nciu%id_dimid, nciu%discard_xhz_varid), "netcdf_initialize_output nf90_def_var discard_xhz_varid" ) - call check( nf90_def_var(nciu%id, nciu%discard_vhx_varname, nciu%out_type, nciu%id_dimid, nciu%discard_vhx_varid), "netcdf_initialize_output nf90_def_var discard_vhx_varid" ) - call check( nf90_def_var(nciu%id, nciu%discard_vhy_varname, nciu%out_type, nciu%id_dimid, nciu%discard_vhy_varid), "netcdf_initialize_output nf90_def_var discard_vhy_varid" ) - call check( nf90_def_var(nciu%id, nciu%discard_vhz_varname, nciu%out_type, nciu%id_dimid, nciu%discard_vhz_varid), "netcdf_initialize_output nf90_def_var discard_vhz_varid" ) + call check( nf90_def_var(nciu%id, nciu%discard_rh_varname, nciu%out_type, [nciu%space_dimid, nciu%id_dimid], nciu%discard_rh_varid), "netcdf_initialize_output nf90_def_var discard_rh_varid" ) + call check( nf90_def_var(nciu%id, nciu%discard_vh_varname, nciu%out_type, [nciu%space_dimid, nciu%id_dimid], nciu%discard_vh_varid), "netcdf_initialize_output nf90_def_var discard_vh_varid" ) call check( nf90_def_var(nciu%id, nciu%discard_body_id_varname, NF90_INT, nciu%id_dimid, nciu%discard_body_id_varid), "netcdf_initialize_output nf90_def_var discard_body_id_varid" ) end if if (param%lrotation) then - call check( nf90_def_var(nciu%id, nciu%ip1_varname, nciu%out_type, [nciu%id_dimid, nciu%time_dimid], nciu%Ip1_varid), "netcdf_initialize_output nf90_def_var Ip1_varid" ) - call check( nf90_def_var(nciu%id, nciu%ip2_varname, nciu%out_type, [nciu%id_dimid, nciu%time_dimid], nciu%Ip2_varid), "netcdf_initialize_output nf90_def_var Ip2_varid" ) - call check( nf90_def_var(nciu%id, nciu%ip3_varname, nciu%out_type, [nciu%id_dimid, nciu%time_dimid], nciu%Ip3_varid), "netcdf_initialize_output nf90_def_var Ip3_varid" ) - call check( nf90_def_var(nciu%id, nciu%rotx_varname, nciu%out_type, [nciu%id_dimid, nciu%time_dimid], nciu%rotx_varid), "netcdf_initialize_output nf90_def_var rotx_varid" ) - call check( nf90_def_var(nciu%id, nciu%roty_varname, nciu%out_type, [nciu%id_dimid, nciu%time_dimid], nciu%roty_varid), "netcdf_initialize_output nf90_def_var roty_varid" ) - call check( nf90_def_var(nciu%id, nciu%rotz_varname, nciu%out_type, [nciu%id_dimid, nciu%time_dimid], nciu%rotz_varid), "netcdf_initialize_output nf90_def_var rotz_varid" ) + call check( nf90_def_var(nciu%id, nciu%Ip_varname, nciu%out_type, [nciu%space_dimid, nciu%id_dimid, nciu%time_dimid], nciu%Ip_varid), "netcdf_initialize_output nf90_def_var Ip_varid" ) + call check( nf90_def_var(nciu%id, nciu%rot_varname, nciu%out_type, [nciu%space_dimid, nciu%id_dimid, nciu%time_dimid], nciu%rot_varid), "netcdf_initialize_output nf90_def_var rot_varid" ) end if ! if (param%ltides) then @@ -303,18 +258,12 @@ module subroutine netcdf_initialize_output(self, param) call check( nf90_def_var(nciu%id, nciu%ke_orb_varname, nciu%out_type, nciu%time_dimid, nciu%KE_orb_varid), "netcdf_initialize_output nf90_def_var KE_orb_varid" ) call check( nf90_def_var(nciu%id, nciu%ke_spin_varname, nciu%out_type, nciu%time_dimid, nciu%KE_spin_varid), "netcdf_initialize_output nf90_def_var KE_spin_varid" ) call check( nf90_def_var(nciu%id, nciu%pe_varname, nciu%out_type, nciu%time_dimid, nciu%PE_varid), "netcdf_initialize_output nf90_def_var PE_varid" ) - call check( nf90_def_var(nciu%id, nciu%l_orbx_varname, nciu%out_type, nciu%time_dimid, nciu%L_orbx_varid), "netcdf_initialize_output nf90_def_var L_orbx_varid" ) - call check( nf90_def_var(nciu%id, nciu%l_orby_varname, nciu%out_type, nciu%time_dimid, nciu%L_orby_varid), "netcdf_initialize_output nf90_def_var L_orby_varid" ) - call check( nf90_def_var(nciu%id, nciu%l_orbz_varname, nciu%out_type, nciu%time_dimid, nciu%L_orbz_varid), "netcdf_initialize_output nf90_def_var L_orbz_varid" ) - call check( nf90_def_var(nciu%id, nciu%l_spinx_varname, nciu%out_type, nciu%time_dimid, nciu%L_spinx_varid), "netcdf_initialize_output nf90_def_var L_spinx_varid" ) - call check( nf90_def_var(nciu%id, nciu%l_spiny_varname, nciu%out_type, nciu%time_dimid, nciu%L_spiny_varid), "netcdf_initialize_output nf90_def_var L_spiny_varid" ) - call check( nf90_def_var(nciu%id, nciu%l_spinz_varname, nciu%out_type, nciu%time_dimid, nciu%L_spinz_varid), "netcdf_initialize_output nf90_def_var L_spinz_varid" ) - call check( nf90_def_var(nciu%id, nciu%l_escapex_varname, nciu%out_type, nciu%time_dimid, nciu%L_escapex_varid), "netcdf_initialize_output nf90_def_var L_escapex_varid" ) - call check( nf90_def_var(nciu%id, nciu%l_escapey_varname, nciu%out_type, nciu%time_dimid, nciu%L_escapey_varid), "netcdf_initialize_output nf90_def_var L_escapey_varid" ) - call check( nf90_def_var(nciu%id, nciu%l_escapez_varname, nciu%out_type, nciu%time_dimid, nciu%L_escapez_varid), "netcdf_initialize_output nf90_def_var L_escapez_varid" ) - call check( nf90_def_var(nciu%id, nciu%ecollisions_varname, nciu%out_type, nciu%time_dimid, nciu%Ecollisions_varid), "netcdf_initialize_output nf90_def_var Ecollisions_varid" ) - call check( nf90_def_var(nciu%id, nciu%euntracked_varname, nciu%out_type, nciu%time_dimid, nciu%Euntracked_varid), "netcdf_initialize_output nf90_def_var Euntracked_varid" ) - call check( nf90_def_var(nciu%id, nciu%gmescape_varname, nciu%out_type, nciu%time_dimid, nciu%GMescape_varid), "netcdf_initialize_output nf90_def_var GMescape_varid" ) + call check( nf90_def_var(nciu%id, nciu%L_orb_varname, nciu%out_type, [nciu%space_dimid, nciu%time_dimid], nciu%L_orb_varid), "netcdf_initialize_output nf90_def_var L_orb_varid" ) + call check( nf90_def_var(nciu%id, nciu%L_spin_varname, nciu%out_type, [nciu%space_dimid, nciu%time_dimid], nciu%L_spin_varid), "netcdf_initialize_output nf90_def_var L_spin_varid" ) + call check( nf90_def_var(nciu%id, nciu%L_escape_varname, nciu%out_type, [nciu%space_dimid, nciu%time_dimid], nciu%L_escape_varid), "netcdf_initialize_output nf90_def_var L_escape_varid" ) + call check( nf90_def_var(nciu%id, nciu%Ecollisions_varname, nciu%out_type, nciu%time_dimid, nciu%Ecollisions_varid), "netcdf_initialize_output nf90_def_var Ecollisions_varid" ) + call check( nf90_def_var(nciu%id, nciu%Euntracked_varname, nciu%out_type, nciu%time_dimid, nciu%Euntracked_varid), "netcdf_initialize_output nf90_def_var Euntracked_varid" ) + call check( nf90_def_var(nciu%id, nciu%GMescape_varname, nciu%out_type, nciu%time_dimid, nciu%GMescape_varid), "netcdf_initialize_output nf90_def_var GMescape_varid" ) end if call check( nf90_def_var(nciu%id, nciu%j2rp2_varname, nciu%out_type, nciu%time_dimid, nciu%j2rp2_varid), "netcdf_initialize_output nf90_def_var j2rp2_varid" ) @@ -340,7 +289,7 @@ module subroutine netcdf_initialize_output(self, param) ! Take the file out of define mode call check( nf90_enddef(nciu%id), "netcdf_initialize_output nf90_enddef" ) - call check( nf90_put_var(nciu%id, nciu%space_varid, nciu%space_coords, start=[1], count=[3]), "netcdf_initialize_output nf90_put_var space" ) + call check( nf90_put_var(nciu%id, nciu%space_varid, nciu%space_coords, start=[1], count=[NDIM]), "netcdf_initialize_output nf90_put_var space" ) end associate return @@ -391,27 +340,13 @@ module subroutine netcdf_open(self, param, readonly) call check( nf90_inq_varid(nciu%id, nciu%gmass_varname, nciu%Gmass_varid), "netcdf_open nf90_inq_varid Gmass_varid" ) if ((param%out_form == "XV") .or. (param%out_form == "XVEL")) then - status = nf90_inq_varid(nciu%id, nciu%rh_varname, nciu%rh_varid) - status = nf90_inq_varid(nciu%id, nciu%vh_varname, nciu%vh_varid) - call check( nf90_inq_varid(nciu%id, nciu%xhx_varname, nciu%xhx_varid), "netcdf_open nf90_inq_varid xhx_varid" ) - call check( nf90_inq_varid(nciu%id, nciu%xhy_varname, nciu%xhy_varid), "netcdf_open nf90_inq_varid xhy_varid" ) - call check( nf90_inq_varid(nciu%id, nciu%xhz_varname, nciu%xhz_varid), "netcdf_open nf90_inq_varid xhz_varid" ) - call check( nf90_inq_varid(nciu%id, nciu%vhx_varname, nciu%vhx_varid), "netcdf_open nf90_inq_varid vhx_varid" ) - call check( nf90_inq_varid(nciu%id, nciu%vhy_varname, nciu%vhy_varid), "netcdf_open nf90_inq_varid vhy_varid" ) - call check( nf90_inq_varid(nciu%id, nciu%vhz_varname, nciu%vhz_varid), "netcdf_open nf90_inq_varid vhz_varid" ) + call check( nf90_inq_varid(nciu%id, nciu%rh_varname, nciu%rh_varid), "netcdf_open nf90_inq_varid rh_varid" ) + call check( nf90_inq_varid(nciu%id, nciu%vh_varname, nciu%vh_varid), "netcdf_open nf90_inq_varid vh_varid" ) if (param%lgr) then !! check if pseudovelocity vectors exist in this file. If they are, set the correct flag so we know whe should not do the conversion. - status = nf90_inq_varid(nciu%id, nciu%gr_pseudo_vhx_varname, nciu%gr_pseudo_vhx_varid) + status = nf90_inq_varid(nciu%id, nciu%gr_pseudo_vh_varname, nciu%gr_pseudo_vh_varid) nciu%lpseudo_vel_exists = (status == nf90_noerr) - if (nciu%lpseudo_vel_exists) then - status = nf90_inq_varid(nciu%id, nciu%gr_pseudo_vhy_varname, nciu%gr_pseudo_vhy_varid) - nciu%lpseudo_vel_exists = (status == nf90_noerr) - if (nciu%lpseudo_vel_exists) then - status = nf90_inq_varid(nciu%id, nciu%gr_pseudo_vhz_varname, nciu%gr_pseudo_vhz_varid) - nciu%lpseudo_vel_exists = (status == nf90_noerr) - end if - end if if (.not.nciu%lpseudo_vel_exists) then write(*,*) "Warning! Pseudovelocity not found in input file for GR enabled run. If this is a restarted run, bit-identical trajectories are not guarunteed!" end if @@ -433,12 +368,8 @@ module subroutine netcdf_open(self, param, readonly) end if if (param%lrotation) then - call check( nf90_inq_varid(nciu%id, nciu%ip1_varname, nciu%Ip1_varid), "netcdf_open nf90_inq_varid Ip1_varid" ) - call check( nf90_inq_varid(nciu%id, nciu%ip2_varname, nciu%Ip2_varid), "netcdf_open nf90_inq_varid Ip2_varid" ) - call check( nf90_inq_varid(nciu%id, nciu%ip3_varname, nciu%Ip3_varid), "netcdf_open nf90_inq_varid Ip3_varid" ) - call check( nf90_inq_varid(nciu%id, nciu%rotx_varname, nciu%rotx_varid), "netcdf_open nf90_inq_varid rotx_varid" ) - call check( nf90_inq_varid(nciu%id, nciu%roty_varname, nciu%roty_varid), "netcdf_open nf90_inq_varid roty_varid" ) - call check( nf90_inq_varid(nciu%id, nciu%rotz_varname, nciu%rotz_varid), "netcdf_open nf90_inq_varid rotz_varid" ) + call check( nf90_inq_varid(nciu%id, nciu%Ip_varname, nciu%Ip_varid), "netcdf_open nf90_inq_varid Ip_varid" ) + call check( nf90_inq_varid(nciu%id, nciu%rot_varname, nciu%rot_varid), "netcdf_open nf90_inq_varid rot_varid" ) end if ! if (param%ltides) then @@ -466,20 +397,12 @@ module subroutine netcdf_open(self, param, readonly) if (param%lclose) then status = nf90_inq_varid(nciu%id, nciu%origin_type_varname, nciu%origin_type_varid) status = nf90_inq_varid(nciu%id, nciu%origin_time_varname, nciu%origin_time_varid) - status = nf90_inq_varid(nciu%id, nciu%origin_xhx_varname, nciu%origin_xhx_varid) - status = nf90_inq_varid(nciu%id, nciu%origin_xhy_varname, nciu%origin_xhy_varid) - status = nf90_inq_varid(nciu%id, nciu%origin_xhz_varname, nciu%origin_xhz_varid) - status = nf90_inq_varid(nciu%id, nciu%origin_vhx_varname, nciu%origin_vhx_varid) - status = nf90_inq_varid(nciu%id, nciu%origin_vhy_varname, nciu%origin_vhy_varid) - status = nf90_inq_varid(nciu%id, nciu%origin_vhz_varname, nciu%origin_vhz_varid) + status = nf90_inq_varid(nciu%id, nciu%origin_rh_varname, nciu%origin_rh_varid) + status = nf90_inq_varid(nciu%id, nciu%origin_vh_varname, nciu%origin_vh_varid) status = nf90_inq_varid(nciu%id, nciu%collision_id_varname, nciu%collision_id_varid) status = nf90_inq_varid(nciu%id, nciu%discard_time_varname, nciu%discard_time_varid) - status = nf90_inq_varid(nciu%id, nciu%discard_xhx_varname, nciu%discard_xhx_varid) - status = nf90_inq_varid(nciu%id, nciu%discard_xhy_varname, nciu%discard_xhy_varid) - status = nf90_inq_varid(nciu%id, nciu%discard_xhz_varname, nciu%discard_xhz_varid) - status = nf90_inq_varid(nciu%id, nciu%discard_vhx_varname, nciu%discard_vhx_varid) - status = nf90_inq_varid(nciu%id, nciu%discard_vhy_varname, nciu%discard_vhy_varid) - status = nf90_inq_varid(nciu%id, nciu%discard_vhz_varname, nciu%discard_vhz_varid) + status = nf90_inq_varid(nciu%id, nciu%discard_rh_varname, nciu%discard_rh_varid) + status = nf90_inq_varid(nciu%id, nciu%discard_vh_varname, nciu%discard_vh_varid) status = nf90_inq_varid(nciu%id, nciu%discard_body_id_varname, nciu%discard_body_id_varid) end if @@ -487,18 +410,12 @@ module subroutine netcdf_open(self, param, readonly) status = nf90_inq_varid(nciu%id, nciu%ke_orb_varname, nciu%KE_orb_varid) status = nf90_inq_varid(nciu%id, nciu%ke_spin_varname, nciu%KE_spin_varid) status = nf90_inq_varid(nciu%id, nciu%pe_varname, nciu%PE_varid) - status = nf90_inq_varid(nciu%id, nciu%l_orbx_varname, nciu%L_orbx_varid) - status = nf90_inq_varid(nciu%id, nciu%l_orby_varname, nciu%L_orby_varid) - status = nf90_inq_varid(nciu%id, nciu%l_orbz_varname, nciu%L_orbz_varid) - status = nf90_inq_varid(nciu%id, nciu%l_spinx_varname, nciu%L_spinx_varid) - status = nf90_inq_varid(nciu%id, nciu%l_spiny_varname, nciu%L_spiny_varid) - status = nf90_inq_varid(nciu%id, nciu%l_spinz_varname, nciu%L_spinz_varid) - status = nf90_inq_varid(nciu%id, nciu%l_escapex_varname, nciu%L_escapex_varid) - status = nf90_inq_varid(nciu%id, nciu%l_escapey_varname, nciu%L_escapey_varid) - status = nf90_inq_varid(nciu%id, nciu%l_escapez_varname, nciu%L_escapez_varid) - status = nf90_inq_varid(nciu%id, nciu%ecollisions_varname, nciu%Ecollisions_varid) - status = nf90_inq_varid(nciu%id, nciu%euntracked_varname, nciu%Euntracked_varid) - status = nf90_inq_varid(nciu%id, nciu%gmescape_varname, nciu%GMescape_varid) + status = nf90_inq_varid(nciu%id, nciu%L_orb_varname, nciu%L_orb_varid) + status = nf90_inq_varid(nciu%id, nciu%L_spin_varname, nciu%L_spin_varid) + status = nf90_inq_varid(nciu%id, nciu%L_escape_varname, nciu%L_escape_varid) + status = nf90_inq_varid(nciu%id, nciu%Ecollisions_varname, nciu%Ecollisions_varid) + status = nf90_inq_varid(nciu%id, nciu%Euntracked_varname, nciu%Euntracked_varid) + status = nf90_inq_varid(nciu%id, nciu%GMescape_varname, nciu%GMescape_varid) end if end associate @@ -519,8 +436,9 @@ module function netcdf_read_frame_system(self, nciu, param) result(ierr) ! Return integer(I4B) :: ierr !! Error code: returns 0 if the read is successful ! Internals - integer(I4B) :: tslot, idmax, npl_check, ntp_check, nplm_check, t_max, str_max, status + integer(I4B) :: i, tslot, idmax, npl_check, ntp_check, nplm_check, t_max, str_max, status real(DP), dimension(:), allocatable :: rtemp + real(DP), dimension(:,:), allocatable :: vectemp integer(I4B), dimension(:), allocatable :: itemp logical, dimension(:), allocatable :: validmask, tpmask, plmask @@ -536,6 +454,7 @@ module function netcdf_read_frame_system(self, nciu, param) result(ierr) call check( nf90_inquire_dimension(nciu%id, nciu%id_dimid, len=idmax), "netcdf_read_frame_system nf90_inquire_dimension id_dimid" ) allocate(rtemp(idmax)) + allocate(vectemp(NDIM,idmax)) allocate(itemp(idmax)) allocate(validmask(idmax)) allocate(tpmask(idmax)) @@ -545,16 +464,16 @@ module function netcdf_read_frame_system(self, nciu, param) result(ierr) ! First filter out only the id slots that contain valid bodies if (param%in_form == "XV") then - call check( nf90_get_var(nciu%id, nciu%xhx_varid, rtemp(:), start=[1, tslot]), "netcdf_read_frame_system filter pass nf90_getvar xhx_varid" ) + call check( nf90_get_var(nciu%id, nciu%rh_varid, vectemp(:,:), start=[1, 1, tslot]), "netcdf_read_frame_system filter pass nf90_getvar rh_varid" ) + validmask(:) = vectemp(1,:) == vectemp(1,:) else call check( nf90_get_var(nciu%id, nciu%a_varid, rtemp(:), start=[1, tslot]), "netcdf_read_frame_system filter pass nf90_getvar a_varid" ) + validmask(:) = rtemp(:) == rtemp(:) end if - validmask(:) = rtemp(:) == rtemp(:) - ! Next, filter only bodies that don't have mass (test particles) - call check( nf90_get_var(nciu%id, nciu%Gmass_varid, rtemp(:), start=[1, tslot]), "netcdf_read_frame_system nf90_getvar Gmass_varid" ) - plmask(:) = rtemp(:) == rtemp(:) .and. validmask(:) + call check( nf90_get_var(nciu%id, nciu%Gmass_varid, vectemp(:,:), start=[1, 1, tslot]), "netcdf_read_frame_system nf90_getvar Gmass_varid" ) + plmask(:) = vectemp(1,:) == vectemp(1,:) .and. validmask(:) tpmask(:) = .not. plmask(:) .and. validmask(:) plmask(1) = .false. ! This is the central body @@ -586,80 +505,62 @@ module function netcdf_read_frame_system(self, nciu, param) result(ierr) ! Now read in each variable and split the outputs by body type if ((param%in_form == "XV") .or. (param%in_form == "XVEL")) then - call check( nf90_get_var(nciu%id, nciu%xhx_varid, rtemp, start=[1, tslot]), "netcdf_read_frame_system nf90_getvar xhx_varid" ) - if (npl > 0) pl%xh(1,:) = pack(rtemp, plmask) - if (ntp > 0) tp%xh(1,:) = pack(rtemp, tpmask) - - call check( nf90_get_var(nciu%id, nciu%xhy_varid, rtemp, start=[1, tslot]), "netcdf_read_frame_system nf90_getvar xhy_varid" ) - if (npl > 0) pl%xh(2,:) = pack(rtemp, plmask) - if (ntp > 0) tp%xh(2,:) = pack(rtemp, tpmask) - - call check( nf90_get_var(nciu%id, nciu%xhz_varid, rtemp, start=[1, tslot]), "netcdf_read_frame_system nf90_getvar xhz_varid" ) - if (npl > 0) pl%xh(3,:) = pack(rtemp, plmask) - if (ntp > 0) tp%xh(3,:) = pack(rtemp, tpmask) + call check( nf90_get_var(nciu%id, nciu%rh_varid, vectemp, start=[1, 1, tslot], count=[NDIM,idmax,1]), "netcdf_read_frame_system nf90_getvar rh_varid" ) + do i = 1, NDIM + if (npl > 0) pl%rh(i,:) = pack(vectemp(i,:), plmask(:)) + if (ntp > 0) tp%rh(i,:) = pack(vectemp(i,:), tpmask(:)) + end do if (param%lgr .and. nciu%lpseudo_vel_exists) then - call check( nf90_get_var(nciu%id, nciu%gr_pseudo_vhx_varid, rtemp, start=[1, tslot]), "netcdf_read_frame_system nf90_getvar gr_pseudo_vhx_varid" ) - if (npl > 0) pl%vh(1,:) = pack(rtemp, plmask) - if (ntp > 0) tp%vh(1,:) = pack(rtemp, tpmask) - - call check( nf90_get_var(nciu%id, nciu%gr_pseudo_vhy_varid, rtemp, start=[1, tslot]), "netcdf_read_frame_system nf90_getvar gr_pseudo_vhy_varid" ) - if (npl > 0) pl%vh(2,:) = pack(rtemp, plmask) - if (ntp > 0) tp%vh(2,:) = pack(rtemp, tpmask) - - call check( nf90_get_var(nciu%id, nciu%gr_pseudo_vhz_varid, rtemp, start=[1, tslot]), "netcdf_read_frame_system nf90_getvar gr_pseudo_vhz_varid" ) - if (npl > 0) pl%vh(3,:) = pack(rtemp, plmask) - if (ntp > 0) tp%vh(3,:) = pack(rtemp, tpmask) + call check( nf90_get_var(nciu%id, nciu%gr_pseudo_vh_varid, vectemp, start=[1, 1, tslot], count=[NDIM,idmax,1]), "netcdf_read_frame_system nf90_getvar gr_pseudo_vh_varid" ) + do i = 1, NDIM + if (npl > 0) pl%vh(i,:) = pack(vectemp(i,:), plmask(:)) + if (ntp > 0) tp%vh(i,:) = pack(vectemp(i,:), tpmask(:)) + end do else - call check( nf90_get_var(nciu%id, nciu%vhx_varid, rtemp, start=[1, tslot]), "netcdf_read_frame_system nf90_getvar vhx_varid" ) - if (npl > 0) pl%vh(1,:) = pack(rtemp, plmask) - if (ntp > 0) tp%vh(1,:) = pack(rtemp, tpmask) - - call check( nf90_get_var(nciu%id, nciu%vhy_varid, rtemp, start=[1, tslot]), "netcdf_read_frame_system nf90_getvar vhy_varid" ) - if (npl > 0) pl%vh(2,:) = pack(rtemp, plmask) - if (ntp > 0) tp%vh(2,:) = pack(rtemp, tpmask) - - call check( nf90_get_var(nciu%id, nciu%vhz_varid, rtemp, start=[1, tslot]), "netcdf_read_frame_system nf90_getvar vhz_varid" ) - if (npl > 0) pl%vh(3,:) = pack(rtemp, plmask) - if (ntp > 0) tp%vh(3,:) = pack(rtemp, tpmask) + call check( nf90_get_var(nciu%id, nciu%vh_varid, rtemp, start=[1, 1, tslot], count=[NDIM,idmax,1]), "netcdf_read_frame_system nf90_getvar vhx_varid" ) + do i = 1, NDIM + if (npl > 0) pl%vh(i,:) = pack(vectemp(i,:), plmask(:)) + if (ntp > 0) tp%vh(i,:) = pack(vectemp(i,:), tpmask(:)) + end do end if end if if ((param%in_form == "EL") .or. (param%in_form == "XVEL")) then - call check( nf90_get_var(nciu%id, nciu%a_varid, rtemp, start=[1, tslot]), "netcdf_read_frame_system nf90_getvar a_varid" ) + call check( nf90_get_var(nciu%id, nciu%a_varid, rtemp, start=[1, tslot], count=[idmax,1]), "netcdf_read_frame_system nf90_getvar a_varid" ) if (.not.allocated(pl%a)) allocate(pl%a(npl)) if (.not.allocated(tp%a)) allocate(tp%a(ntp)) if (npl > 0) pl%a(:) = pack(rtemp, plmask) if (ntp > 0) tp%a(:) = pack(rtemp, tpmask) - call check( nf90_get_var(nciu%id, nciu%e_varid, rtemp, start=[1, tslot]), "netcdf_read_frame_system nf90_getvar e_varid" ) + call check( nf90_get_var(nciu%id, nciu%e_varid, rtemp, start=[1, tslot], count=[idmax,1]), "netcdf_read_frame_system nf90_getvar e_varid" ) if (.not.allocated(pl%e)) allocate(pl%e(npl)) if (.not.allocated(tp%e)) allocate(tp%e(ntp)) if (npl > 0) pl%e(:) = pack(rtemp, plmask) if (ntp > 0) tp%e(:) = pack(rtemp, tpmask) - call check( nf90_get_var(nciu%id, nciu%inc_varid, rtemp, start=[1, tslot]), "netcdf_read_frame_system nf90_getvar inc_varid" ) + call check( nf90_get_var(nciu%id, nciu%inc_varid, rtemp, start=[1, tslot], count=[idmax,1]), "netcdf_read_frame_system nf90_getvar inc_varid" ) rtemp = rtemp * DEG2RAD if (.not.allocated(pl%inc)) allocate(pl%inc(npl)) if (.not.allocated(tp%inc)) allocate(tp%inc(ntp)) if (npl > 0) pl%inc(:) = pack(rtemp, plmask) if (ntp > 0) tp%inc(:) = pack(rtemp, tpmask) - call check( nf90_get_var(nciu%id, nciu%capom_varid, rtemp, start=[1, tslot]), "netcdf_read_frame_system nf90_getvar capom_varid" ) + call check( nf90_get_var(nciu%id, nciu%capom_varid, rtemp, start=[1, tslot], count=[idmax,1]), "netcdf_read_frame_system nf90_getvar capom_varid" ) rtemp = rtemp * DEG2RAD if (.not.allocated(pl%capom)) allocate(pl%capom(npl)) if (.not.allocated(tp%capom)) allocate(tp%capom(ntp)) if (npl > 0) pl%capom(:) = pack(rtemp, plmask) if (ntp > 0) tp%capom(:) = pack(rtemp, tpmask) - call check( nf90_get_var(nciu%id, nciu%omega_varid, rtemp, start=[1, tslot]), "netcdf_read_frame_system nf90_getvar omega_varid" ) + call check( nf90_get_var(nciu%id, nciu%omega_varid, rtemp, start=[1, tslot], count=[idmax,1]), "netcdf_read_frame_system nf90_getvar omega_varid" ) rtemp = rtemp * DEG2RAD if (.not.allocated(pl%omega)) allocate(pl%omega(npl)) if (.not.allocated(tp%omega)) allocate(tp%omega(ntp)) if (npl > 0) pl%omega(:) = pack(rtemp, plmask) if (ntp > 0) tp%omega(:) = pack(rtemp, tpmask) - call check( nf90_get_var(nciu%id, nciu%capm_varid, rtemp, start=[1, tslot]), "netcdf_read_frame_system nf90_getvar capm_varid" ) + call check( nf90_get_var(nciu%id, nciu%capm_varid, rtemp, start=[1, tslot], count=[idmax,1]), "netcdf_read_frame_system nf90_getvar capm_varid" ) rtemp = rtemp * DEG2RAD if (.not.allocated(pl%capm)) allocate(pl%capm(npl)) if (.not.allocated(tp%capm)) allocate(tp%capm(ntp)) @@ -668,7 +569,7 @@ module function netcdf_read_frame_system(self, nciu, param) result(ierr) end if - call check( nf90_get_var(nciu%id, nciu%Gmass_varid, rtemp, start=[1, tslot]), "netcdf_read_frame_system nf90_getvar Gmass_varid" ) + call check( nf90_get_var(nciu%id, nciu%Gmass_varid, rtemp, start=[1, tslot], count=[idmax,1]), "netcdf_read_frame_system nf90_getvar Gmass_varid" ) cb%Gmass = rtemp(1) cb%mass = cb%Gmass / param%GU @@ -684,13 +585,13 @@ module function netcdf_read_frame_system(self, nciu, param) result(ierr) pl%mass(:) = pl%Gmass(:) / param%GU if (param%lrhill_present) then - call check( nf90_get_var(nciu%id, nciu%rhill_varid, rtemp, start=[1, tslot]), "netcdf_read_frame_system nf90_getvar rhill_varid" ) + call check( nf90_get_var(nciu%id, nciu%rhill_varid, rtemp, start=[1, tslot], count=[idmax,1]), "netcdf_read_frame_system nf90_getvar rhill_varid" ) pl%rhill(:) = pack(rtemp, plmask) end if end if if (param%lclose) then - call check( nf90_get_var(nciu%id, nciu%radius_varid, rtemp, start=[1, tslot]), "netcdf_read_frame_system nf90_getvar radius_varid" ) + call check( nf90_get_var(nciu%id, nciu%radius_varid, rtemp, start=[1, tslot], count=[idmax,1]), "netcdf_read_frame_system nf90_getvar radius_varid" ) cb%radius = rtemp(1) ! Set initial central body radius for SyMBA bookkeeping @@ -705,29 +606,17 @@ module function netcdf_read_frame_system(self, nciu, param) result(ierr) end if if (param%lrotation) then - call check( nf90_get_var(nciu%id, nciu%Ip1_varid, rtemp, start=[1, tslot]), "netcdf_read_frame_system nf90_getvar Ip1_varid" ) - cb%Ip(1) = rtemp(1) - if (npl > 0) pl%Ip(1,:) = pack(rtemp, plmask) - - call check( nf90_get_var(nciu%id, nciu%Ip2_varid, rtemp, start=[1, tslot]), "netcdf_read_frame_system nf90_getvar Ip2_varid" ) - cb%Ip(2) = rtemp(1) - if (npl > 0) pl%Ip(2,:) = pack(rtemp, plmask) - - call check( nf90_get_var(nciu%id, nciu%Ip3_varid, rtemp, start=[1, tslot]), "netcdf_read_frame_system nf90_getvar Ip3_varid" ) - cb%Ip(3) = rtemp(1) - if (npl > 0) pl%Ip(3,:) = pack(rtemp, plmask) - - call check( nf90_get_var(nciu%id, nciu%rotx_varid, rtemp, start=[1, tslot]), "netcdf_read_frame_system nf90_getvar rotx_varid" ) - cb%rot(1) = rtemp(1) - if (npl > 0) pl%rot(1,:) = pack(rtemp, plmask) - - call check( nf90_get_var(nciu%id, nciu%roty_varid, rtemp, start=[1, tslot]), "netcdf_read_frame_system nf90_getvar roty_varid" ) - cb%rot(2) = rtemp(1) - if (npl > 0) pl%rot(2,:) = pack(rtemp, plmask) + call check( nf90_get_var(nciu%id, nciu%Ip_varid, vectemp, start=[1, 1, tslot], count=[NDIM,idmax,1]), "netcdf_read_frame_system nf90_getvar Ip_varid" ) + cb%Ip(:) = vectemp(:,1) + do i = 1, NDIM + if (npl > 0) pl%Ip(i,:) = pack(vectemp(i,:), plmask(:)) + end do - call check( nf90_get_var(nciu%id, nciu%rotz_varid, rtemp, start=[1, tslot]), "netcdf_read_frame_system nf90_getvar rotz_varid" ) - cb%rot(3) = rtemp(1) - if (npl > 0) pl%rot(3,:) = pack(rtemp, plmask) + call check( nf90_get_var(nciu%id, nciu%rot_varid, vectemp, start=[1, 1, tslot], count=[NDIM,idmax,1]), "netcdf_read_frame_system nf90_getvar rot_varid" ) + cb%rot(:) = vectemp(:,1) + do i = 1, NDIM + if (npl > 0) pl%rot(i,:) = pack(vectemp(i,:), plmask(:)) + end do ! Set initial central body angular momentum for Helio bookkeeping select type(cb) @@ -813,7 +702,7 @@ module subroutine netcdf_read_hdr_system(self, nciu, param) allocate(plmask(idmax)) allocate(plmmask(idmax)) - call check( nf90_get_var(nciu%id, nciu%Gmass_varid, gmtemp, start=[1,1]), "netcdf_read_frame_system nf90_getvar Gmass_varid" ) + call check( nf90_get_var(nciu%id, nciu%Gmass_varid, gmtemp, start=[1,1], count=[idmax,1]), "netcdf_read_frame_system nf90_getvar Gmass_varid" ) plmask(:) = gmtemp(:) == gmtemp(:) tpmask(:) = .not. plmask(:) @@ -859,29 +748,17 @@ module subroutine netcdf_read_hdr_system(self, nciu, param) if (status == nf90_noerr) call check( nf90_get_var(nciu%id, nciu%KE_spin_varid, self%ke_spin, start=[tslot]), "netcdf_read_hdr_system nf90_getvar KE_spin_varid" ) status = nf90_inq_varid(nciu%id, nciu%pe_varname, nciu%PE_varid) if (status == nf90_noerr) call check( nf90_get_var(nciu%id, nciu%PE_varid, self%pe, start=[tslot]), "netcdf_read_hdr_system nf90_getvar PE_varid" ) - status = nf90_inq_varid(nciu%id, nciu%l_orbx_varname, nciu%L_orbx_varid) - if (status == nf90_noerr) call check( nf90_get_var(nciu%id, nciu%L_orbx_varid, self%Lorbit(1), start=[tslot]), "netcdf_read_hdr_system nf90_getvar L_orbx_varid" ) - status = nf90_inq_varid(nciu%id, nciu%l_orby_varname, nciu%L_orby_varid) - if (status == nf90_noerr) call check( nf90_get_var(nciu%id, nciu%L_orby_varid, self%Lorbit(2), start=[tslot]), "netcdf_read_hdr_system nf90_getvar L_orby_varid" ) - status = nf90_inq_varid(nciu%id, nciu%l_orbz_varname, nciu%L_orbz_varid) - if (status == nf90_noerr) call check( nf90_get_var(nciu%id, nciu%L_orbz_varid, self%Lorbit(3), start=[tslot]), "netcdf_read_hdr_system nf90_getvar L_orbz_varid" ) - status = nf90_inq_varid(nciu%id, nciu%l_spinx_varname, nciu%L_spinx_varid) - if (status == nf90_noerr) call check( nf90_get_var(nciu%id, nciu%L_spinx_varid, self%Lspin(1), start=[tslot]), "netcdf_read_hdr_system nf90_getvar L_spinx_varid" ) - status = nf90_inq_varid(nciu%id, nciu%l_spiny_varname, nciu%L_spiny_varid) - if (status == nf90_noerr) call check( nf90_get_var(nciu%id, nciu%L_spiny_varid, self%Lspin(2), start=[tslot]), "netcdf_read_hdr_system nf90_getvar L_spiny_varid" ) - status = nf90_inq_varid(nciu%id, nciu%l_spinz_varname, nciu%L_spinz_varid) - if (status == nf90_noerr) call check( nf90_get_var(nciu%id, nciu%L_spinz_varid, self%Lspin(3), start=[tslot]), "netcdf_read_hdr_system nf90_getvar L_spinz_varid" ) - status = nf90_inq_varid(nciu%id, nciu%l_escapex_varname, nciu%L_escapex_varid) - if (status == nf90_noerr) call check( nf90_get_var(nciu%id, nciu%L_escapex_varid, self%Lescape(1), start=[tslot]), "netcdf_read_hdr_system nf90_getvar L_escapex_varid" ) - status = nf90_inq_varid(nciu%id, nciu%l_escapey_varname, nciu%L_escapey_varid) - if (status == nf90_noerr) call check( nf90_get_var(nciu%id, nciu%L_escapey_varid, self%Lescape(2), start=[tslot]), "netcdf_read_hdr_system nf90_getvar L_escapey_varid" ) - status = nf90_inq_varid(nciu%id, nciu%l_escapez_varname, nciu%L_escapez_varid) - if (status == nf90_noerr) call check( nf90_get_var(nciu%id, nciu%L_escapez_varid, self%Lescape(3), start=[tslot]), "netcdf_read_hdr_system nf90_getvar L_escapez_varid" ) - status = nf90_inq_varid(nciu%id, nciu%ecollisions_varname, nciu%Ecollisions_varid) + status = nf90_inq_varid(nciu%id, nciu%L_orb_varname, nciu%L_orb_varid) + if (status == nf90_noerr) call check( nf90_get_var(nciu%id, nciu%L_orb_varid, self%Lorbit(:), start=[1,tslot], count=[NDIM,1]), "netcdf_read_hdr_system nf90_getvar L_orb_varid" ) + status = nf90_inq_varid(nciu%id, nciu%L_spin_varname, nciu%L_spin_varid) + if (status == nf90_noerr) call check( nf90_get_var(nciu%id, nciu%L_spin_varid, self%Lspin(:), start=[1,tslot], count=[NDIM,1]), "netcdf_read_hdr_system nf90_getvar L_spin_varid" ) + status = nf90_inq_varid(nciu%id, nciu%L_escape_varname, nciu%L_escape_varid) + if (status == nf90_noerr) call check( nf90_get_var(nciu%id, nciu%L_escape_varid, self%Lescape(:), start=[1, tslot], count=[NDIM,1]), "netcdf_read_hdr_system nf90_getvar L_escape_varid" ) + status = nf90_inq_varid(nciu%id, nciu%Ecollisions_varname, nciu%Ecollisions_varid) if (status == nf90_noerr) call check( nf90_get_var(nciu%id, nciu%Ecollisions_varid, self%Ecollisions, start=[tslot]), "netcdf_read_hdr_system nf90_getvar Ecollisions_varid" ) - status = nf90_inq_varid(nciu%id, nciu%euntracked_varname, nciu%Euntracked_varid) + status = nf90_inq_varid(nciu%id, nciu%Euntracked_varname, nciu%Euntracked_varid) if (status == nf90_noerr) call check( nf90_get_var(nciu%id, nciu%Euntracked_varid, self%Euntracked, start=[tslot]), "netcdf_read_hdr_system nf90_getvar Euntracked_varid" ) - status = nf90_inq_varid(nciu%id, nciu%gmescape_varname, nciu%GMescape_varid) + status = nf90_inq_varid(nciu%id, nciu%GMescape_varname, nciu%GMescape_varid) if (status == nf90_noerr) call check( nf90_get_var(nciu%id, nciu%GMescape_varid, self%GMescape, start=[tslot]), "netcdf_read_hdr_system nf90_getvar GMescape_varid" ) end if @@ -903,7 +780,7 @@ module subroutine netcdf_read_particle_info_system(self, nciu, param, plmask, tp ! Internals integer(I4B) :: i, idmax, status real(DP), dimension(:), allocatable :: rtemp - real(DP), dimension(:,:), allocatable :: rtemp_arr + real(DP), dimension(:,:), allocatable :: vectemp integer(I4B), dimension(:), allocatable :: itemp character(len=NAMELEN), dimension(:), allocatable :: ctemp integer(I4B), dimension(:), allocatable :: plind, tpind @@ -911,7 +788,7 @@ module subroutine netcdf_read_particle_info_system(self, nciu, param, plmask, tp ! This string of spaces of length NAMELEN is used to clear out any old data left behind inside the string variables idmax = size(plmask) allocate(rtemp(idmax)) - allocate(rtemp_arr(NDIM,idmax)) + allocate(vectemp(NDIM,idmax)) allocate(itemp(idmax)) allocate(ctemp(idmax)) @@ -1005,72 +882,36 @@ module subroutine netcdf_read_particle_info_system(self, nciu, param, plmask, tp call tp%info(i)%set_value(origin_time=rtemp(tpind(i))) end do - status = nf90_inq_varid(nciu%id, nciu%origin_xhx_varname, nciu%origin_xhx_varid) - if (status == nf90_noerr) then - call check( nf90_get_var(nciu%id, nciu%origin_xhx_varid, rtemp_arr(1,:)), "netcdf_read_particle_info_system nf90_getvar origin_xhx_varid" ) - else if ((param%out_form == "XV") .or. (param%out_form == "XVEL")) then - call check( nf90_get_var(nciu%id, nciu%xhx_varid, rtemp_arr(1,:)), "netcdf_read_particle_info_system nf90_getvar xhx_varid" ) - else - rtemp_arr(1,:) = 0._DP - end if - - status = nf90_inq_varid(nciu%id, nciu%origin_xhy_varname, nciu%origin_xhy_varid) + status = nf90_inq_varid(nciu%id, nciu%origin_rh_varname, nciu%origin_rh_varid) if (status == nf90_noerr) then - call check( nf90_get_var(nciu%id, nciu%origin_xhy_varid, rtemp_arr(2,:)), "netcdf_read_particle_info_system nf90_getvar origin_xhy_varid" ) + call check( nf90_get_var(nciu%id, nciu%origin_rh_varid, vectemp(:,:)), "netcdf_read_particle_info_system nf90_getvar origin_rh_varid" ) else if ((param%out_form == "XV") .or. (param%out_form == "XVEL")) then - call check( nf90_get_var(nciu%id, nciu%xhy_varid, rtemp_arr(2,:)), "netcdf_read_particle_info_system nf90_getvar xhx_varid" ) + call check( nf90_get_var(nciu%id, nciu%rh_varid, vectemp(:,:)), "netcdf_read_particle_info_system nf90_getvar rh_varid" ) else - rtemp_arr(2,:) = 0._DP - end if - - status = nf90_inq_varid(nciu%id, nciu%origin_xhz_varname, nciu%origin_xhz_varid) - if (status == nf90_noerr) then - call check( nf90_get_var(nciu%id, nciu%origin_xhz_varid, rtemp_arr(3,:)), "netcdf_read_particle_info_system nf90_getvar origin_xhz_varid" ) - else if ((param%out_form == "XV") .or. (param%out_form == "XVEL")) then - call check( nf90_get_var(nciu%id, nciu%xhz_varid, rtemp_arr(3,:)), "netcdf_read_particle_info_system nf90_getvar xhz_varid" ) - else - rtemp_arr(3,:) = 0._DP + vectemp(:,:) = 0._DP end if do i = 1, npl - call pl%info(i)%set_value(origin_xh=rtemp_arr(:,plind(i))) + call pl%info(i)%set_value(origin_rh=vectemp(:,plind(i))) end do do i = 1, ntp - call tp%info(i)%set_value(origin_xh=rtemp_arr(:,tpind(i))) + call tp%info(i)%set_value(origin_rh=vectemp(:,tpind(i))) end do - status = nf90_inq_varid(nciu%id, nciu%origin_vhx_varname, nciu%origin_vhx_varid) + status = nf90_inq_varid(nciu%id, nciu%origin_vh_varname, nciu%origin_vh_varid) if (status == nf90_noerr) then - call check( nf90_get_var(nciu%id, nciu%origin_vhx_varid, rtemp_arr(1,:)), "netcdf_read_particle_info_system nf90_getvar origin_vhx_varid" ) + call check( nf90_get_var(nciu%id, nciu%origin_vh_varid, vectemp(:,:)), "netcdf_read_particle_info_system nf90_getvar origin_vh_varid" ) else if ((param%out_form == "XV") .or. (param%out_form == "XVEL")) then - call check( nf90_get_var(nciu%id, nciu%vhx_varid, rtemp_arr(1,:)), "netcdf_read_particle_info_system nf90_getvar vhx_varid" ) + call check( nf90_get_var(nciu%id, nciu%vh_varid, vectemp(:,:)), "netcdf_read_particle_info_system nf90_getvar vh_varid" ) else - rtemp_arr(1,:) = 0._DP + vectemp(:,:) = 0._DP end if - status = nf90_inq_varid(nciu%id, nciu%origin_vhy_varname, nciu%origin_vhy_varid) - if (status == nf90_noerr) then - call check( nf90_get_var(nciu%id, nciu%origin_vhy_varid, rtemp_arr(2,:)), "netcdf_read_particle_info_system nf90_getvar origin_vhy_varid" ) - else if ((param%out_form == "XV") .or. (param%out_form == "XVEL")) then - call check( nf90_get_var(nciu%id, nciu%vhy_varid, rtemp_arr(2,:)), "netcdf_read_particle_info_system nf90_getvar vhy_varid" ) - else - rtemp_arr(2,:) = 0._DP - end if - - status = nf90_inq_varid(nciu%id, nciu%origin_vhz_varname, nciu%origin_vhz_varid) - if (status == nf90_noerr) then - call check( nf90_get_var(nciu%id, nciu%origin_vhz_varid, rtemp_arr(3,:)), "netcdf_read_particle_info_system nf90_getvar origin_vhz_varid" ) - else if ((param%out_form == "XV") .or. (param%out_form == "XVEL")) then - call check( nf90_get_var(nciu%id, nciu%vhz_varid, rtemp_arr(3,:)), "netcdf_read_particle_info_system nf90_getvar vhz_varid" ) - else - rtemp_arr(3,:) = 0._DP - end if - do i = 1, npl - call pl%info(i)%set_value(origin_vh=rtemp_arr(:,plind(i))) + call pl%info(i)%set_value(origin_vh=vectemp(:,plind(i))) end do do i = 1, ntp - call tp%info(i)%set_value(origin_vh=rtemp_arr(:,tpind(i))) + call tp%info(i)%set_value(origin_vh=vectemp(:,tpind(i))) end do status = nf90_inq_varid(nciu%id, nciu%collision_id_varname, nciu%collision_id_varid) @@ -1102,60 +943,32 @@ module subroutine netcdf_read_particle_info_system(self, nciu, param, plmask, tp call tp%info(i)%set_value(discard_time=rtemp(tpind(i))) end do - status = nf90_inq_varid(nciu%id, nciu%discard_xhx_varname, nciu%discard_xhx_varid) + status = nf90_inq_varid(nciu%id, nciu%discard_rh_varname, nciu%discard_rh_varid) if (status == nf90_noerr) then - call check( nf90_get_var(nciu%id, nciu%discard_xhx_varid, rtemp_arr(1,:)), "netcdf_read_particle_info_system nf90_getvar discard_xhx_varid" ) + call check( nf90_get_var(nciu%id, nciu%discard_rh_varid, vectemp(:,:)), "netcdf_read_particle_info_system nf90_getvar discard_rh_varid" ) else - rtemp_arr(1,:) = 0.0_DP - end if - - status = nf90_inq_varid(nciu%id, nciu%discard_xhy_varname, nciu%discard_xhy_varid) - if (status == nf90_noerr) then - call check( nf90_get_var(nciu%id, nciu%discard_xhy_varid, rtemp_arr(2,:)), "netcdf_read_particle_info_system nf90_getvar discard_xhy_varid" ) - else - rtemp_arr(2,:) = 0.0_DP - end if - - status = nf90_inq_varid(nciu%id, nciu%discard_xhz_varname, nciu%discard_xhz_varid) - if (status == nf90_noerr) then - call check( nf90_get_var(nciu%id, nciu%discard_xhz_varid, rtemp_arr(3,:)), "netcdf_read_particle_info_system nf90_getvar discard_xhz_varid" ) - else - rtemp_arr(3,:) = 0.0_DP + vectemp(:,:) = 0.0_DP end if do i = 1, npl - call pl%info(i)%set_value(discard_xh=rtemp_arr(:,plind(i))) + call pl%info(i)%set_value(discard_rh=vectemp(:,plind(i))) end do do i = 1, ntp - call tp%info(i)%set_value(discard_xh=rtemp_arr(:,tpind(i))) + call tp%info(i)%set_value(discard_rh=vectemp(:,tpind(i))) end do - status = nf90_inq_varid(nciu%id, nciu%discard_vhx_varname, nciu%discard_vhx_varid) - if (status == nf90_noerr) then - call check( nf90_get_var(nciu%id, nciu%discard_vhx_varid, rtemp_arr(1,:)), "netcdf_read_particle_info_system nf90_getvar discard_vhx_varid" ) - else - rtemp_arr(1,:) = 0.0_DP - end if - - status = nf90_inq_varid(nciu%id, nciu%discard_vhy_varname, nciu%discard_vhy_varid) - if (status == nf90_noerr) then - call check( nf90_get_var(nciu%id, nciu%discard_vhy_varid, rtemp_arr(2,:)), "netcdf_read_particle_info_system nf90_getvar discard_vhy_varid" ) - else - rtemp_arr(2,:) = 0.0_DP - end if - - status = nf90_inq_varid(nciu%id, nciu%discard_vhz_varname, nciu%discard_vhz_varid) + status = nf90_inq_varid(nciu%id, nciu%discard_vh_varname, nciu%discard_vh_varid) if (status == nf90_noerr) then - call check( nf90_get_var(nciu%id, nciu%discard_vhz_varid, rtemp_arr(3,:)), "netcdf_read_particle_info_system nf90_getvar discard_vhz_varid" ) + call check( nf90_get_var(nciu%id, nciu%discard_vh_varid, vectemp(:,:)), "netcdf_read_particle_info_system nf90_getvar discard_vh_varid" ) else - rtemp_arr(3,:) = 0.0_DP + vectemp(:,:) = 0.0_DP end if do i = 1, npl - call pl%info(i)%set_value(discard_vh=rtemp_arr(:,plind(i))) + call pl%info(i)%set_value(discard_vh=vectemp(:,plind(i))) end do do i = 1, ntp - call tp%info(i)%set_value(discard_vh=rtemp_arr(:,tpind(i))) + call tp%info(i)%set_value(discard_vh=vectemp(:,tpind(i))) end do end if @@ -1213,36 +1026,26 @@ module subroutine netcdf_write_frame_base(self, nciu, param) idslot = self%id(j) + 1 !! Convert from pseudovelocity to heliocentric without replacing the current value of pseudovelocity - if (param%lgr) call gr_pseudovel2vel(param, self%mu(j), self%xh(:, j), self%vh(:, j), vh(:)) + if (param%lgr) call gr_pseudovel2vel(param, self%mu(j), self%rh(:, j), self%vh(:, j), vh(:)) if ((param%out_form == "XV") .or. (param%out_form == "XVEL")) then - call check( nf90_put_var(nciu%id, nciu%rh_varid, self%xh(:, j), start=[1,idslot, tslot], count=[3,1,1]), "netcdf_write_frame_base nf90_put_var rh_varid" ) - call check( nf90_put_var(nciu%id, nciu%vh_varid, self%vh(:, j), start=[1,idslot, tslot], count=[3,1,1]), "netcdf_write_frame_base nf90_put_var vh_varid" ) - call check( nf90_put_var(nciu%id, nciu%xhx_varid, self%xh(1, j), start=[idslot, tslot]), "netcdf_write_frame_base nf90_put_var xhx_varid" ) - call check( nf90_put_var(nciu%id, nciu%xhy_varid, self%xh(2, j), start=[idslot, tslot]), "netcdf_write_frame_base nf90_put_var xhy_varid" ) - call check( nf90_put_var(nciu%id, nciu%xhz_varid, self%xh(3, j), start=[idslot, tslot]), "netcdf_write_frame_base nf90_put_var xhz_varid" ) + call check( nf90_put_var(nciu%id, nciu%rh_varid, self%rh(:, j), start=[1,idslot, tslot], count=[NDIM,1,1]), "netcdf_write_frame_base nf90_put_var rh_varid" ) if (param%lgr) then !! Convert from pseudovelocity to heliocentric without replacing the current value of pseudovelocity - call check( nf90_put_var(nciu%id, nciu%vhx_varid, vh(1), start=[idslot, tslot]), "netcdf_write_frame_base nf90_put_var vhx_varid (gr case)" ) - call check( nf90_put_var(nciu%id, nciu%vhy_varid, vh(2), start=[idslot, tslot]), "netcdf_write_frame_base nf90_put_var vhy_varid (gr case)" ) - call check( nf90_put_var(nciu%id, nciu%vhz_varid, vh(3), start=[idslot, tslot]), "netcdf_write_frame_base nf90_put_var vhz_varid (gr case)" ) - call check( nf90_put_var(nciu%id, nciu%gr_pseudo_vhx_varid, self%vh(1, j), start=[idslot, tslot]), "netcdf_write_frame_base nf90_put_var gr_pseudo_vhx_varid" ) - call check( nf90_put_var(nciu%id, nciu%gr_pseudo_vhy_varid, self%vh(2, j), start=[idslot, tslot]), "netcdf_write_frame_base nf90_put_var gr_pseudo_vhy_varid" ) - call check( nf90_put_var(nciu%id, nciu%gr_pseudo_vhz_varid, self%vh(3, j), start=[idslot, tslot]), "netcdf_write_frame_base nf90_put_var gr_pseudo_vhz_varid" ) + call check( nf90_put_var(nciu%id, nciu%vh_varid, vh(:), start=[1,idslot, tslot], count=[NDIM,1,1]), "netcdf_write_frame_base nf90_put_var vh_varid" ) + call check( nf90_put_var(nciu%id, nciu%gr_pseudo_vh_varid, self%vh(:, j), start=[1,idslot, tslot],count=[NDIM,1,1]), "netcdf_write_frame_base nf90_put_var gr_pseudo_vhx_varid" ) else - call check( nf90_put_var(nciu%id, nciu%vhx_varid, self%vh(1, j), start=[idslot, tslot]), "netcdf_write_frame_base nf90_put_var vhx_varid" ) - call check( nf90_put_var(nciu%id, nciu%vhy_varid, self%vh(2, j), start=[idslot, tslot]), "netcdf_write_frame_base nf90_put_var vhy_varid" ) - call check( nf90_put_var(nciu%id, nciu%vhz_varid, self%vh(3, j), start=[idslot, tslot]), "netcdf_write_frame_base nf90_put_var vhz_varid" ) + call check( nf90_put_var(nciu%id, nciu%vh_varid, self%vh(:, j), start=[1,idslot, tslot], count=[NDIM,1,1]), "netcdf_write_frame_base nf90_put_var vh_varid" ) end if end if if ((param%out_form == "EL") .or. (param%out_form == "XVEL")) then if (param%lgr) then !! For GR-enabled runs, use the true value of velocity computed above - call orbel_xv2el(self%mu(j), self%xh(1,j), self%xh(2,j), self%xh(3,j), & + call orbel_xv2el(self%mu(j), self%rh(1,j), self%rh(2,j), self%rh(3,j), & vh(1), vh(2), vh(3), & a, e, inc, capom, omega, capm) else !! For non-GR runs just convert from the velocity we have - call orbel_xv2el(self%mu(j), self%xh(1,j), self%xh(2,j), self%xh(3,j), & + call orbel_xv2el(self%mu(j), self%rh(1,j), self%rh(2,j), self%rh(3,j), & self%vh(1,j), self%vh(2,j), self%vh(3,j), & a, e, inc, capom, omega, capm) end if @@ -1262,12 +1065,8 @@ module subroutine netcdf_write_frame_base(self, nciu, param) end if if (param%lclose) call check( nf90_put_var(nciu%id, nciu%radius_varid, self%radius(j), start=[idslot, tslot]), "netcdf_write_frame_base nf90_put_var radius_varid" ) if (param%lrotation) then - call check( nf90_put_var(nciu%id, nciu%Ip1_varid, self%Ip(1, j), start=[idslot, tslot]), "netcdf_write_frame_base nf90_put_var Ip1_varid" ) - call check( nf90_put_var(nciu%id, nciu%Ip2_varid, self%Ip(2, j), start=[idslot, tslot]), "netcdf_write_frame_base nf90_put_var Ip2_varid" ) - call check( nf90_put_var(nciu%id, nciu%Ip3_varid, self%Ip(3, j), start=[idslot, tslot]), "netcdf_write_frame_base nf90_put_var Ip3_varid" ) - call check( nf90_put_var(nciu%id, nciu%rotx_varid, self%rot(1, j), start=[idslot, tslot]), "netcdf_write_frame_base nf90_put_var rotx_varid" ) - call check( nf90_put_var(nciu%id, nciu%roty_varid, self%rot(2, j), start=[idslot, tslot]), "netcdf_write_frame_base nf90_put_var roty_varid" ) - call check( nf90_put_var(nciu%id, nciu%rotz_varid, self%rot(3, j), start=[idslot, tslot]), "netcdf_write_frame_base nf90_put_var rotz_varid" ) + call check( nf90_put_var(nciu%id, nciu%Ip_varid, self%Ip(:, j), start=[1,idslot, tslot], count=[NDIM,1,1]), "netcdf_write_frame_base nf90_put_var Ip_varid" ) + call check( nf90_put_var(nciu%id, nciu%rot_varid, self%rot(:, j), start=[1,idslot, tslot], count=[NDIM,1,1]), "netcdf_write_frame_base nf90_put_var rotx_varid" ) end if ! if (param%ltides) then ! call check( nf90_put_var(nciu%id, nciu%k2_varid, self%k2(j), start=[idslot, tslot]), "netcdf_write_frame_base nf90_put_var k2_varid" ) @@ -1286,12 +1085,8 @@ module subroutine netcdf_write_frame_base(self, nciu, param) call check( nf90_put_var(nciu%id, nciu%j2rp2_varid, self%j2rp2, start=[tslot]), "netcdf_write_frame_base nf90_put_var cb j2rp2_varid" ) call check( nf90_put_var(nciu%id, nciu%j4rp4_varid, self%j4rp4, start=[tslot]), "netcdf_write_frame_base nf90_put_var cb j4rp4_varid" ) if (param%lrotation) then - call check( nf90_put_var(nciu%id, nciu%Ip1_varid, self%Ip(1), start=[idslot, tslot]), "netcdf_write_frame_base nf90_put_var cb Ip1_varid" ) - call check( nf90_put_var(nciu%id, nciu%Ip2_varid, self%Ip(2), start=[idslot, tslot]), "netcdf_write_frame_base nf90_put_var cb Ip2_varid" ) - call check( nf90_put_var(nciu%id, nciu%Ip3_varid, self%Ip(3), start=[idslot, tslot]), "netcdf_write_frame_base nf90_put_var cb Ip3_varid" ) - call check( nf90_put_var(nciu%id, nciu%rotx_varid, self%rot(1), start=[idslot, tslot]), "netcdf_write_frame_base nf90_put_var cb rotx_varid" ) - call check( nf90_put_var(nciu%id, nciu%roty_varid, self%rot(2), start=[idslot, tslot]), "netcdf_write_frame_base nf90_put_var cb roty_varid" ) - call check( nf90_put_var(nciu%id, nciu%rotz_varid, self%rot(3), start=[idslot, tslot]), "netcdf_write_frame_base nf90_put_var cb rotz_varid" ) + call check( nf90_put_var(nciu%id, nciu%Ip_varid, self%Ip(:), start=[1, idslot, tslot], count=[NDIM,1,1]), "netcdf_write_frame_base nf90_put_var cb Ip_varid" ) + call check( nf90_put_var(nciu%id, nciu%rot_varid, self%rot(:), start=[1, idslot, tslot], count=[NDIM,1,1]), "netcdf_write_frame_base nf90_put_var cb rot_varid" ) end if ! if (param%ltides) then ! call check( nf90_put_var(nciu%id, nciu%k2_varid, self%k2, start=[idslot, tslot]), "netcdf_write_frame_base nf90_put_var cb k2_varid" ) @@ -1365,21 +1160,13 @@ module subroutine netcdf_write_info_base(self, nciu, param) charstring = trim(adjustl(self%info(j)%origin_type)) call check( nf90_put_var(nciu%id, nciu%origin_type_varid, charstring, start=[1, idslot], count=[NAMELEN, 1]), "netcdf_write_info_base nf90_put_var origin_type_varid" ) call check( nf90_put_var(nciu%id, nciu%origin_time_varid, self%info(j)%origin_time, start=[idslot]), "netcdf_write_info_base nf90_put_var origin_time_varid" ) - call check( nf90_put_var(nciu%id, nciu%origin_xhx_varid, self%info(j)%origin_xh(1), start=[idslot]), "netcdf_write_info_base nf90_put_var origin_xhx_varid" ) - call check( nf90_put_var(nciu%id, nciu%origin_xhy_varid, self%info(j)%origin_xh(2), start=[idslot]), "netcdf_write_info_base nf90_put_var origin_xhy_varid" ) - call check( nf90_put_var(nciu%id, nciu%origin_xhz_varid, self%info(j)%origin_xh(3), start=[idslot]), "netcdf_write_info_base nf90_put_var origin_xhz_varid" ) - call check( nf90_put_var(nciu%id, nciu%origin_vhx_varid, self%info(j)%origin_vh(1), start=[idslot]), "netcdf_write_info_base nf90_put_var origin_vhx_varid" ) - call check( nf90_put_var(nciu%id, nciu%origin_vhy_varid, self%info(j)%origin_vh(2), start=[idslot]), "netcdf_write_info_base nf90_put_var origin_vhy_varid" ) - call check( nf90_put_var(nciu%id, nciu%origin_vhz_varid, self%info(j)%origin_vh(3), start=[idslot]), "netcdf_write_info_base nf90_put_var origin_vhz_varid" ) + call check( nf90_put_var(nciu%id, nciu%origin_rh_varid, self%info(j)%origin_rh(:), start=[1,idslot], count=[NDIM,1]), "netcdf_write_info_base nf90_put_var origin_rh_varid" ) + call check( nf90_put_var(nciu%id, nciu%origin_vh_varid, self%info(j)%origin_vh(:), start=[1,idslot], count=[NDIM,1]), "netcdf_write_info_base nf90_put_var origin_vh_varid" ) call check( nf90_put_var(nciu%id, nciu%collision_id_varid, self%info(j)%collision_id, start=[idslot]), "netcdf_write_info_base nf90_put_var collision_id_varid" ) call check( nf90_put_var(nciu%id, nciu%discard_time_varid, self%info(j)%discard_time, start=[idslot]), "netcdf_write_info_base nf90_put_var discard_time_varid" ) - call check( nf90_put_var(nciu%id, nciu%discard_xhx_varid, self%info(j)%discard_xh(1), start=[idslot]), "netcdf_write_info_base nf90_put_var discard_xhx_varid" ) - call check( nf90_put_var(nciu%id, nciu%discard_xhy_varid, self%info(j)%discard_xh(2), start=[idslot]), "netcdf_write_info_base nf90_put_var discard_xhy_varid" ) - call check( nf90_put_var(nciu%id, nciu%discard_xhz_varid, self%info(j)%discard_xh(3), start=[idslot]), "netcdf_write_info_base nf90_put_var discard_xhz_varid" ) - call check( nf90_put_var(nciu%id, nciu%discard_vhx_varid, self%info(j)%discard_vh(1), start=[idslot]), "netcdf_write_info_base nf90_put_var discard_vhx_varid" ) - call check( nf90_put_var(nciu%id, nciu%discard_vhy_varid, self%info(j)%discard_vh(2), start=[idslot]), "netcdf_write_info_base nf90_put_var discard_vhy_varid" ) - call check( nf90_put_var(nciu%id, nciu%discard_vhz_varid, self%info(j)%discard_vh(3), start=[idslot]), "netcdf_write_info_base nf90_put_var discard_vhz_varid" ) + call check( nf90_put_var(nciu%id, nciu%discard_rh_varid, self%info(j)%discard_rh(:), start=[1,idslot], count=[NDIM,1]), "netcdf_write_info_base nf90_put_var discard_rh_varid" ) + call check( nf90_put_var(nciu%id, nciu%discard_vh_varid, self%info(j)%discard_vh(:), start=[1,idslot], count=[NDIM,1]), "netcdf_write_info_base nf90_put_var discard_vh_varid" ) end if end do @@ -1403,21 +1190,13 @@ module subroutine netcdf_write_info_base(self, nciu, param) call check( nf90_put_var(nciu%id, nciu%origin_type_varid, charstring, start=[1, idslot], count=[NAMELEN, 1]), "netcdf_write_info_base nf90_put_var cb origin_type_varid" ) call check( nf90_put_var(nciu%id, nciu%origin_time_varid, self%info%origin_time, start=[idslot]), "netcdf_write_info_base nf90_put_var cb origin_time_varid" ) - call check( nf90_put_var(nciu%id, nciu%origin_xhx_varid, self%info%origin_xh(1), start=[idslot]), "netcdf_write_info_base nf90_put_var cb origin_xhx_varid" ) - call check( nf90_put_var(nciu%id, nciu%origin_xhy_varid, self%info%origin_xh(2), start=[idslot]), "netcdf_write_info_base nf90_put_var cb origin_xhy_varid" ) - call check( nf90_put_var(nciu%id, nciu%origin_xhz_varid, self%info%origin_xh(3), start=[idslot]), "netcdf_write_info_base nf90_put_var cb origin_xhz_varid" ) - call check( nf90_put_var(nciu%id, nciu%origin_vhx_varid, self%info%origin_vh(1), start=[idslot]), "netcdf_write_info_base nf90_put_var cb origin_vhx_varid" ) - call check( nf90_put_var(nciu%id, nciu%origin_vhy_varid, self%info%origin_vh(2), start=[idslot]), "netcdf_write_info_base nf90_put_var cb origin_vhy_varid" ) - call check( nf90_put_var(nciu%id, nciu%origin_vhz_varid, self%info%origin_vh(3), start=[idslot]), "netcdf_write_info_base nf90_put_var cb origin_vhz_varid" ) + call check( nf90_put_var(nciu%id, nciu%origin_rh_varid, self%info%origin_rh(:), start=[1, idslot], count=[NDIM,1]), "netcdf_write_info_base nf90_put_var cb origin_rh_varid" ) + call check( nf90_put_var(nciu%id, nciu%origin_vh_varid, self%info%origin_vh(:), start=[1, idslot], count=[NDIM,1]), "netcdf_write_info_base nf90_put_var cb origin_vh_varid" ) call check( nf90_put_var(nciu%id, nciu%collision_id_varid, self%info%collision_id, start=[idslot]), "netcdf_write_info_base nf90_put_var cb collision_id_varid" ) call check( nf90_put_var(nciu%id, nciu%discard_time_varid, self%info%discard_time, start=[idslot]), "netcdf_write_info_base nf90_put_var cb discard_time_varid" ) - call check( nf90_put_var(nciu%id, nciu%discard_xhx_varid, self%info%discard_xh(1), start=[idslot]), "netcdf_write_info_base nf90_put_var cb discard_xhx_varid" ) - call check( nf90_put_var(nciu%id, nciu%discard_xhy_varid, self%info%discard_xh(2), start=[idslot]), "netcdf_write_info_base nf90_put_var cb discard_xhy_varid" ) - call check( nf90_put_var(nciu%id, nciu%discard_xhz_varid, self%info%discard_xh(3), start=[idslot]), "netcdf_write_info_base nf90_put_var cb discard_xhz_varid" ) - call check( nf90_put_var(nciu%id, nciu%discard_vhx_varid, self%info%discard_vh(1), start=[idslot]), "netcdf_write_info_base nf90_put_var cb discard_vhx_varid" ) - call check( nf90_put_var(nciu%id, nciu%discard_vhy_varid, self%info%discard_vh(2), start=[idslot]), "netcdf_write_info_base nf90_put_var cb discard_vhy_varid" ) - call check( nf90_put_var(nciu%id, nciu%discard_vhz_varid, self%info%discard_vh(3), start=[idslot]), "netcdf_write_info_base nf90_put_var cb discard_vhz_varid" ) + call check( nf90_put_var(nciu%id, nciu%discard_rh_varid, self%info%discard_rh(:), start=[1, idslot], count=[NDIM,1]), "netcdf_write_info_base nf90_put_var cb discard_rh_varid" ) + call check( nf90_put_var(nciu%id, nciu%discard_vh_varid, self%info%discard_vh(:), start=[1, idslot], count=[NDIM,1]), "netcdf_write_info_base nf90_put_var cb discard_vh_varid" ) end if end select @@ -1455,15 +1234,9 @@ module subroutine netcdf_write_hdr_system(self, nciu, param) call check( nf90_put_var(nciu%id, nciu%KE_orb_varid, self%ke_orbit, start=[tslot]), "netcdf_write_hdr_system nf90_put_var KE_orb_varid" ) call check( nf90_put_var(nciu%id, nciu%KE_spin_varid, self%ke_spin, start=[tslot]), "netcdf_write_hdr_system nf90_put_var KE_spin_varid" ) call check( nf90_put_var(nciu%id, nciu%PE_varid, self%pe, start=[tslot]), "netcdf_write_hdr_system nf90_put_var PE_varid" ) - call check( nf90_put_var(nciu%id, nciu%L_orbx_varid, self%Lorbit(1), start=[tslot]), "netcdf_write_hdr_system nf90_put_var L_orbx_varid" ) - call check( nf90_put_var(nciu%id, nciu%L_orby_varid, self%Lorbit(2), start=[tslot]), "netcdf_write_hdr_system nf90_put_var L_orby_varid" ) - call check( nf90_put_var(nciu%id, nciu%L_orbz_varid, self%Lorbit(3), start=[tslot]), "netcdf_write_hdr_system nf90_put_var L_orbz_varid" ) - call check( nf90_put_var(nciu%id, nciu%L_spinx_varid, self%Lspin(1), start=[tslot]), "netcdf_write_hdr_system nf90_put_var L_spinx_varid" ) - call check( nf90_put_var(nciu%id, nciu%L_spiny_varid, self%Lspin(2), start=[tslot]), "netcdf_write_hdr_system nf90_put_var L_spiny_varid" ) - call check( nf90_put_var(nciu%id, nciu%L_spinz_varid, self%Lspin(3), start=[tslot]), "netcdf_write_hdr_system nf90_put_var L_spinz_varid" ) - call check( nf90_put_var(nciu%id, nciu%L_escapex_varid, self%Lescape(1), start=[tslot]), "netcdf_write_hdr_system nf90_put_var L_escapex_varid" ) - call check( nf90_put_var(nciu%id, nciu%L_escapey_varid, self%Lescape(2), start=[tslot]), "netcdf_write_hdr_system nf90_put_var L_escapey_varid" ) - call check( nf90_put_var(nciu%id, nciu%L_escapez_varid, self%Lescape(3), start=[tslot]), "netcdf_write_hdr_system nf90_put_var L_escapez_varid" ) + call check( nf90_put_var(nciu%id, nciu%L_orb_varid, self%Lorbit(:), start=[1,tslot], count=[NDIM,1]), "netcdf_write_hdr_system nf90_put_var L_orb_varid" ) + call check( nf90_put_var(nciu%id, nciu%L_spin_varid, self%Lspin(:), start=[1,tslot], count=[NDIM,1]), "netcdf_write_hdr_system nf90_put_var L_spin_varid" ) + call check( nf90_put_var(nciu%id, nciu%L_escape_varid, self%Lescape(:), start=[1,tslot], count=[NDIM,1]), "netcdf_write_hdr_system nf90_put_var L_escape_varid" ) call check( nf90_put_var(nciu%id, nciu%Ecollisions_varid, self%Ecollisions, start=[tslot]), "netcdf_write_hdr_system nf90_put_var Ecollisions_varid" ) call check( nf90_put_var(nciu%id, nciu%Euntracked_varid, self%Euntracked, start=[tslot]), "netcdf_write_hdr_system nf90_put_var Euntracked_varid" ) call check( nf90_put_var(nciu%id, nciu%GMescape_varid, self%GMescape, start=[tslot]), "netcdf_write_hdr_system nf90_put_var GMescape_varid" ) diff --git a/src/obl/obl.f90 b/src/obl/obl.f90 index 9ae30a5e4..be964c3e5 100644 --- a/src/obl/obl.f90 +++ b/src/obl/obl.f90 @@ -31,17 +31,17 @@ module subroutine obl_acc_body(self, system) associate(n => self%nbody, cb => system%cb) self%aobl(:,:) = 0.0_DP do concurrent(i = 1:n, self%lmask(i)) - r2 = dot_product(self%xh(:, i), self%xh(:, i)) + r2 = dot_product(self%rh(:, i), self%rh(:, i)) irh = 1.0_DP / sqrt(r2) rinv2 = irh**2 t0 = -cb%Gmass * rinv2 * rinv2 * irh t1 = 1.5_DP * cb%j2rp2 - t2 = self%xh(3, i) * self%xh(3, i) * rinv2 + t2 = self%rh(3, i) * self%rh(3, i) * rinv2 t3 = 1.875_DP * cb%j4rp4 * rinv2 fac1 = t0 * (t1 - t3 - (5 * t1 - (14.0_DP - 21.0_DP * t2) * t3) * t2) fac2 = 2 * t0 * (t1 - (2.0_DP - (14.0_DP * t2 / 3.0_DP)) * t3) - self%aobl(:, i) = fac1 * self%xh(:, i) - self%aobl(3, i) = fac2 * self%xh(3, i) + self%aobl(3, i) + self%aobl(:, i) = fac1 * self%rh(:, i) + self%aobl(3, i) = fac2 * self%rh(3, i) + self%aobl(3, i) end do end associate return @@ -137,7 +137,7 @@ module subroutine obl_pot_system(self) associate(system => self, pl => self%pl, npl => self%pl%nbody, cb => self%cb) if (.not. any(pl%lmask(1:npl))) return do concurrent (i = 1:npl, pl%lmask(i)) - oblpot_arr(i) = obl_pot_one(cb%Gmass, pl%Gmass(i), cb%j2rp2, cb%j4rp4, pl%xh(3,i), 1.0_DP / norm2(pl%xh(:,i))) + oblpot_arr(i) = obl_pot_one(cb%Gmass, pl%Gmass(i), cb%j2rp2, cb%j4rp4, pl%rh(3,i), 1.0_DP / norm2(pl%rh(:,i))) end do system%oblpot = sum(oblpot_arr, pl%lmask(1:npl)) end associate diff --git a/src/orbel/orbel.f90 b/src/orbel/orbel.f90 index 5e7c4a989..014fe9bae 100644 --- a/src/orbel/orbel.f90 +++ b/src/orbel/orbel.f90 @@ -28,7 +28,7 @@ module subroutine orbel_el2xv_vec(self, cb) call self%set_mu(cb) do concurrent (i = 1:self%nbody) call orbel_el2xv(self%mu(i), self%a(i), self%e(i), self%inc(i), self%capom(i), & - self%omega(i), self%capm(i), self%xh(:, i), self%vh(:, i)) + self%omega(i), self%capm(i), self%rh(:, i), self%vh(:, i)) end do return end subroutine orbel_el2xv_vec @@ -885,7 +885,7 @@ module subroutine orbel_xv2el_vec(self, cb) if (allocated(self%omega)) deallocate(self%omega); allocate(self%omega(self%nbody)) if (allocated(self%capm)) deallocate(self%capm); allocate(self%capm(self%nbody)) do concurrent (i = 1:self%nbody) - call orbel_xv2el(self%mu(i), self%xh(1,i), self%xh(2,i), self%xh(3,i), & + call orbel_xv2el(self%mu(i), self%rh(1,i), self%rh(2,i), self%rh(3,i), & self%vh(1,i), self%vh(2,i), self%vh(3,i), & self%a(i), self%e(i), self%inc(i), & self%capom(i), self%omega(i), self%capm(i)) diff --git a/src/rmvs/rmvs_discard.f90 b/src/rmvs/rmvs_discard.f90 index 60be2f6b0..1b3a58ddc 100644 --- a/src/rmvs/rmvs_discard.f90 +++ b/src/rmvs/rmvs_discard.f90 @@ -43,7 +43,7 @@ module subroutine rmvs_discard_tp(self, system, param) // " (" // trim(adjustl(idstrj)) // ") is too small at t = " // trim(adjustl(timestr)) tp%ldiscard(i) = .true. tp%lmask(i) = .false. - call tp%info(i)%set_value(status="DISCARDED_PLQ", discard_time=t, discard_xh=tp%xh(:,i), & + call tp%info(i)%set_value(status="DISCARDED_PLQ", discard_time=t, discard_rh=tp%rh(:,i), & discard_vh=tp%vh(:,i), discard_body_id=pl%id(iplperP)) end if end if diff --git a/src/rmvs/rmvs_encounter_check.f90 b/src/rmvs/rmvs_encounter_check.f90 index cf6b73624..860bcacfb 100644 --- a/src/rmvs/rmvs_encounter_check.f90 +++ b/src/rmvs/rmvs_encounter_check.f90 @@ -42,7 +42,7 @@ module function rmvs_encounter_check_tp(self, param, system, dt) result(lencount class is (rmvs_pl) associate(tp => self, ntp => self%nbody, npl => pl%nbody) tp%plencP(1:ntp) = 0 - call encounter_check_all_pltp(param, npl, ntp, pl%xbeg, pl%vbeg, tp%xh, tp%vh, pl%renc, dt, & + call encounter_check_all_pltp(param, npl, ntp, pl%xbeg, pl%vbeg, tp%rh, tp%vh, pl%renc, dt, & nenc, index1, index2, lvdotr) lencounter = (nenc > 0_I8B) diff --git a/src/rmvs/rmvs_kick.f90 b/src/rmvs/rmvs_kick.f90 index 91e63a62e..bb43aba94 100644 --- a/src/rmvs/rmvs_kick.f90 +++ b/src/rmvs/rmvs_kick.f90 @@ -42,11 +42,11 @@ module subroutine rmvs_kick_getacch_tp(self, system, param, t, lbeg) class is (rmvs_pl) select type (cb => system%cb) class is (rmvs_cb) - associate(xpc => pl%xh, xpct => self%xh, apct => self%ah, system_planetocen => system) + associate(xpc => pl%rh, xpct => self%rh, apct => self%ah, system_planetocen => system) system_planetocen%lbeg = lbeg ! Save the original heliocentric position for later - allocate(xh_original, source=tp%xh) + allocate(xh_original, source=tp%rh) ! Temporarily turn off the heliocentric-dependent acceleration terms during an inner encounter using a copy of the parameter list with all of the heliocentric-specific acceleration terms turned off allocate(param_planetocen, source=param) @@ -60,17 +60,17 @@ module subroutine rmvs_kick_getacch_tp(self, system, param, t, lbeg) ! Now compute any heliocentric values of acceleration if (tp%lfirst) then do concurrent(i = 1:ntp, tp%lmask(i)) - tp%xheliocentric(:,i) = tp%xh(:,i) + cb%inner(inner_index - 1)%x(:,1) + tp%xheliocentric(:,i) = tp%rh(:,i) + cb%inner(inner_index - 1)%x(:,1) end do else do concurrent(i = 1:ntp, tp%lmask(i)) - tp%xheliocentric(:,i) = tp%xh(:,i) + cb%inner(inner_index )%x(:,1) + tp%xheliocentric(:,i) = tp%rh(:,i) + cb%inner(inner_index )%x(:,1) end do end if ! Swap the planetocentric and heliocentric position vectors and central body masses do concurrent(i = 1:ntp, tp%lmask(i)) - tp%xh(:, i) = tp%xheliocentric(:, i) + tp%rh(:, i) = tp%xheliocentric(:, i) end do GMcb_original = cb%Gmass cb%Gmass = tp%cb_heliocentric%Gmass @@ -81,7 +81,7 @@ module subroutine rmvs_kick_getacch_tp(self, system, param, t, lbeg) if (param%lgr) call tp%accel_gr(param) ! Put everything back the way we found it - call move_alloc(xh_original, tp%xh) + call move_alloc(xh_original, tp%rh) cb%Gmass = GMcb_original end associate diff --git a/src/rmvs/rmvs_step.f90 b/src/rmvs/rmvs_step.f90 index 7c39614e1..132139e33 100644 --- a/src/rmvs/rmvs_step.f90 +++ b/src/rmvs/rmvs_step.f90 @@ -38,7 +38,7 @@ module subroutine rmvs_step_system(self, param, t, dt) select type(tp => self%tp) class is (rmvs_tp) associate(system => self, ntp => tp%nbody, npl => pl%nbody) - allocate(xbeg, source=pl%xh) + allocate(xbeg, source=pl%rh) allocate(vbeg, source=pl%vh) call pl%set_beg_end(xbeg = xbeg, vbeg = vbeg) ! ****** Check for close encounters ***** ! @@ -49,7 +49,7 @@ module subroutine rmvs_step_system(self, param, t, dt) pl%outer(0)%x(:, 1:npl) = xbeg(:, 1:npl) pl%outer(0)%v(:, 1:npl) = vbeg(:, 1:npl) call pl%step(system, param, t, dt) - pl%outer(NTENC)%x(:, 1:npl) = pl%xh(:, 1:npl) + pl%outer(NTENC)%x(:, 1:npl) = pl%rh(:, 1:npl) pl%outer(NTENC)%v(:, 1:npl) = pl%vh(:, 1:npl) call rmvs_interp_out(cb, pl, dt) call rmvs_step_out(cb, pl, tp, system, param, t, dt) @@ -96,7 +96,7 @@ subroutine rmvs_interp_out(cb, pl, dt) dntenc = real(NTENC, kind=DP) associate (npl => pl%nbody) - allocate(xtmp, mold = pl%xh) + allocate(xtmp, mold = pl%rh) allocate(vtmp, mold = pl%vh) allocate(GMcb(npl)) allocate(dto(npl)) @@ -247,7 +247,7 @@ subroutine rmvs_interp_in(cb, pl, system, param, dt, outer_index) pl%inner(NTPHENC)%x(:, 1:npl) = pl%outer(outer_index)%x(:, 1:npl) pl%inner(NTPHENC)%v(:, 1:npl) = pl%outer(outer_index)%v(:, 1:npl) - allocate(xtmp,mold=pl%xh) + allocate(xtmp,mold=pl%rh) allocate(vtmp,mold=pl%vh) allocate(GMcb(npl)) allocate(dti(npl)) @@ -258,9 +258,9 @@ subroutine rmvs_interp_in(cb, pl, system, param, dt, outer_index) vtmp(:, 1:npl) = pl%inner(0)%v(:, 1:npl) if ((param%loblatecb) .or. (param%ltides)) then - allocate(xh_original, source=pl%xh) + allocate(xh_original, source=pl%rh) allocate(ah_original, source=pl%ah) - pl%xh(:, 1:npl) = xtmp(:, 1:npl) ! Temporarily replace heliocentric position with inner substep values to calculate the oblateness terms + pl%rh(:, 1:npl) = xtmp(:, 1:npl) ! Temporarily replace heliocentric position with inner substep values to calculate the oblateness terms end if if (param%loblatecb) then call pl%accel_obl(system) @@ -317,7 +317,7 @@ subroutine rmvs_interp_in(cb, pl, system, param, dt, outer_index) pl%inner(inner_index)%v(:, 1:npl) = pl%inner(inner_index)%v(:, 1:npl) + frac * vtmp(:, 1:npl) if (param%loblatecb) then - pl%xh(:,1:npl) = pl%inner(inner_index)%x(:, 1:npl) + pl%rh(:,1:npl) = pl%inner(inner_index)%x(:, 1:npl) call pl%accel_obl(system) pl%inner(inner_index)%aobl(:, 1:npl) = pl%aobl(:, 1:npl) end if @@ -329,7 +329,7 @@ subroutine rmvs_interp_in(cb, pl, system, param, dt, outer_index) end do if (param%loblatecb) then ! Calculate the final value of oblateness accelerations at the final inner substep - pl%xh(:, 1:npl) = pl%inner(NTPHENC)%x(:, 1:npl) + pl%rh(:, 1:npl) = pl%inner(NTPHENC)%x(:, 1:npl) call pl%accel_obl(system) pl%inner(NTPHENC)%aobl(:, 1:npl) = pl%aobl(:, 1:npl) end if @@ -339,7 +339,7 @@ subroutine rmvs_interp_in(cb, pl, system, param, dt, outer_index) ! pl%inner(NTPHENC)%atide(:, 1:npl) = pl%atide(:, 1:npl) ! end if ! Put the planet positions and accelerations back into place - if (allocated(xh_original)) call move_alloc(xh_original, pl%xh) + if (allocated(xh_original)) call move_alloc(xh_original, pl%rh) if (allocated(ah_original)) call move_alloc(ah_original, pl%ah) end associate return @@ -388,7 +388,7 @@ subroutine rmvs_step_in(cb, pl, tp, param, outer_time, dto) ! now step the encountering test particles fully through the inner encounter lfirsttp = .true. do inner_index = 1, NTPHENC ! Integrate over the encounter region, using the "substitute" planetocentric systems at each level - plenci%xh(:, 1:npl) = plenci%inner(inner_index - 1)%x(:, 1:npl) + plenci%rh(:, 1:npl) = plenci%inner(inner_index - 1)%x(:, 1:npl) call plenci%set_beg_end(xbeg = plenci%inner(inner_index - 1)%x, & xend = plenci%inner(inner_index)%x) @@ -403,7 +403,7 @@ subroutine rmvs_step_in(cb, pl, tp, param, outer_time, dto) call tpenci%step(planetocen_system, param, inner_time, dti) do j = 1, pl%nenc(i) - tpenci%xheliocentric(:, j) = tpenci%xh(:, j) + pl%inner(inner_index)%x(:,i) + tpenci%xheliocentric(:, j) = tpenci%rh(:, j) + pl%inner(inner_index)%x(:,i) end do inner_time = outer_time + j * dti call rmvs_peri_tp(tpenci, pl, inner_time, dti, .false., inner_index, i, param) @@ -464,8 +464,8 @@ subroutine rmvs_make_planetocentric(param, cb, pl, tp) ! Grab all the encountering test particles and convert them to a planetocentric frame tpenci%id(1:nenci) = pack(tp%id(1:ntp), encmask(1:ntp)) do j = 1, NDIM - tpenci%xheliocentric(j, 1:nenci) = pack(tp%xh(j,1:ntp), encmask(:)) - tpenci%xh(j, 1:nenci) = tpenci%xheliocentric(j, 1:nenci) - pl%inner(0)%x(j, i) + tpenci%xheliocentric(j, 1:nenci) = pack(tp%rh(j,1:ntp), encmask(:)) + tpenci%rh(j, 1:nenci) = tpenci%xheliocentric(j, 1:nenci) - pl%inner(0)%x(j, i) tpenci%vh(j, 1:nenci) = pack(tp%vh(j, 1:ntp), encmask(1:ntp)) - pl%inner(0)%v(j, i) end do tpenci%lperi(1:nenci) = pack(tp%lperi(1:ntp), encmask(1:ntp)) @@ -538,7 +538,7 @@ subroutine rmvs_peri_tp(tp, pl, t, dt, lfirst, inner_index, ipleP, param) rhill2 = pl%rhill(ipleP)**2 mu = pl%Gmass(ipleP) - associate(nenc => tp%nbody, xpc => tp%xh, vpc => tp%vh) + associate(nenc => tp%nbody, xpc => tp%rh, vpc => tp%vh) if (lfirst) then do i = 1, nenc if (tp%lmask(i)) then @@ -625,7 +625,7 @@ subroutine rmvs_end_planetocentric(pl, tp) tp%status(tpind(1:nenci)) = tpenci%status(1:nenci) tp%lmask(tpind(1:nenci)) = tpenci%lmask(1:nenci) do j = 1, NDIM - tp%xh(j, tpind(1:nenci)) = tpenci%xh(j,1:nenci) + pl%inner(NTPHENC)%x(j, i) + tp%rh(j, tpind(1:nenci)) = tpenci%rh(j,1:nenci) + pl%inner(NTPHENC)%x(j, i) tp%vh(j, tpind(1:nenci)) = tpenci%vh(j,1:nenci) + pl%inner(NTPHENC)%v(j, i) end do tp%lperi(tpind(1:nenci)) = tpenci%lperi(1:nenci) diff --git a/src/setup/setup.f90 b/src/setup/setup.f90 index 655d15b58..26aed237c 100644 --- a/src/setup/setup.f90 +++ b/src/setup/setup.f90 @@ -113,14 +113,14 @@ module subroutine setup_initialize_particle_info_system(self, param) associate(cb => self%cb, pl => self%pl, npl => self%pl%nbody, tp => self%tp, ntp => self%tp%nbody) call cb%info%set_value(particle_type=CB_TYPE_NAME, status="ACTIVE", origin_type="Initial conditions", & - origin_time=param%t0, origin_xh=[0.0_DP, 0.0_DP, 0.0_DP], origin_vh=[0.0_DP, 0.0_DP, 0.0_DP]) + origin_time=param%t0, origin_rh=[0.0_DP, 0.0_DP, 0.0_DP], origin_vh=[0.0_DP, 0.0_DP, 0.0_DP]) do i = 1, self%pl%nbody call pl%info(i)%set_value(particle_type=PL_TYPE_NAME, status="ACTIVE", origin_type="Initial conditions", & - origin_time=param%t0, origin_xh=self%pl%xh(:,i), origin_vh=self%pl%vh(:,i)) + origin_time=param%t0, origin_rh=self%pl%rh(:,i), origin_vh=self%pl%vh(:,i)) end do do i = 1, self%tp%nbody call tp%info(i)%set_value(particle_type=TP_TYPE_NAME, status="ACTIVE", origin_type="Initial conditions", & - origin_time=param%t0, origin_xh=self%tp%xh(:,i), origin_vh=self%tp%vh(:,i)) + origin_time=param%t0, origin_rh=self%tp%rh(:,i), origin_vh=self%tp%vh(:,i)) end do end associate @@ -193,7 +193,7 @@ module subroutine setup_body(self, n, param) allocate(self%ldiscard(n)) allocate(self%lmask(n)) allocate(self%mu(n)) - allocate(self%xh(NDIM, n)) + allocate(self%rh(NDIM, n)) allocate(self%vh(NDIM, n)) allocate(self%xb(NDIM, n)) allocate(self%vb(NDIM, n)) @@ -210,10 +210,10 @@ module subroutine setup_body(self, n, param) origin_type = "UNKNOWN", & collision_id = 0, & origin_time = -huge(1.0_DP), & - origin_xh = [0.0_DP, 0.0_DP, 0.0_DP], & + origin_rh = [0.0_DP, 0.0_DP, 0.0_DP], & origin_vh = [0.0_DP, 0.0_DP, 0.0_DP], & discard_time = -huge(1.0_DP), & - discard_xh = [0.0_DP, 0.0_DP, 0.0_DP], & + discard_rh = [0.0_DP, 0.0_DP, 0.0_DP], & discard_vh = [0.0_DP, 0.0_DP, 0.0_DP], & discard_body_id = -1 & ) @@ -223,7 +223,7 @@ module subroutine setup_body(self, n, param) self%ldiscard(:) = .false. self%lmask(:) = .false. self%mu(:) = 0.0_DP - self%xh(:,:) = 0.0_DP + self%rh(:,:) = 0.0_DP self%vh(:,:) = 0.0_DP self%xb(:,:) = 0.0_DP self%vb(:,:) = 0.0_DP diff --git a/src/setup/symba_collision.f90 b/src/setup/symba_collision.f90 index e839af1de..c4d04ee75 100644 --- a/src/setup/symba_collision.f90 +++ b/src/setup/symba_collision.f90 @@ -314,7 +314,7 @@ module function symba_collision_check_encounter(self, system, param, t, dt, irec do concurrent(k = 1:nenc, lmask(k)) i = self%index1(k) j = self%index2(k) - xr(:) = pl%xh(:, i) - pl%xh(:, j) + xr(:) = pl%rh(:, i) - pl%rh(:, j) vr(:) = pl%vb(:, i) - pl%vb(:, j) rlim = pl%radius(i) + pl%radius(j) Gmtot = pl%Gmass(i) + pl%Gmass(j) @@ -325,7 +325,7 @@ module function symba_collision_check_encounter(self, system, param, t, dt, irec do concurrent(k = 1:nenc, lmask(k)) i = self%index1(k) j = self%index2(k) - xr(:) = pl%xh(:, i) - tp%xh(:, j) + xr(:) = pl%rh(:, i) - tp%rh(:, j) vr(:) = pl%vb(:, i) - tp%vb(:, j) lcollision(k) = symba_collision_check_one(xr(1), xr(2), xr(3), vr(1), vr(2), vr(3), & pl%Gmass(i), pl%radius(i), dt, self%lvdotr(k)) @@ -340,10 +340,10 @@ module function symba_collision_check_encounter(self, system, param, t, dt, irec j = self%index2(k) if (lcollision(k)) self%status(k) = COLLISION self%t(k) = t - self%x1(:,k) = pl%xh(:,i) + system%cb%xb(:) + self%x1(:,k) = pl%rh(:,i) + system%cb%xb(:) self%v1(:,k) = pl%vb(:,i) if (isplpl) then - self%x2(:,k) = pl%xh(:,j) + system%cb%xb(:) + self%x2(:,k) = pl%rh(:,j) + system%cb%xb(:) self%v2(:,k) = pl%vb(:,j) if (lcollision(k)) then ! Check to see if either of these bodies has been involved with a collision before, and if so, make this a collisional colliders%idx @@ -352,11 +352,11 @@ module function symba_collision_check_encounter(self, system, param, t, dt, irec ! Set the collision flag for these to bodies to true in case they become involved in another collision later in the step pl%lcollision([i, j]) = .true. pl%status([i, j]) = COLLISION - call pl%info(i)%set_value(status="COLLISION", discard_time=t, discard_xh=pl%xh(:,i), discard_vh=pl%vh(:,i)) - call pl%info(j)%set_value(status="COLLISION", discard_time=t, discard_xh=pl%xh(:,j), discard_vh=pl%vh(:,j)) + call pl%info(i)%set_value(status="COLLISION", discard_time=t, discard_rh=pl%rh(:,i), discard_vh=pl%vh(:,i)) + call pl%info(j)%set_value(status="COLLISION", discard_time=t, discard_rh=pl%rh(:,j), discard_vh=pl%vh(:,j)) end if else - self%x2(:,k) = tp%xh(:,j) + system%cb%xb(:) + self%x2(:,k) = tp%rh(:,j) + system%cb%xb(:) self%v2(:,k) = tp%vb(:,j) if (lcollision(k)) then tp%status(j) = DISCARDED_PLR @@ -364,7 +364,7 @@ module function symba_collision_check_encounter(self, system, param, t, dt, irec write(idstri, *) pl%id(i) write(idstrj, *) tp%id(j) write(timestr, *) t - call tp%info(j)%set_value(status="DISCARDED_PLR", discard_time=t, discard_xh=tp%xh(:,j), discard_vh=tp%vh(:,j)) + call tp%info(j)%set_value(status="DISCARDED_PLR", discard_time=t, discard_rh=tp%rh(:,j), discard_vh=tp%vh(:,j)) write(message, *) "Particle " // trim(adjustl(tp%info(j)%name)) // " (" // trim(adjustl(idstrj)) // ")" & // " collided with massive body " // trim(adjustl(pl%info(i)%name)) // " (" // trim(adjustl(idstri)) // ")" & // " at t = " // trim(adjustl(timestr)) @@ -508,7 +508,7 @@ function symba_collision_consolidate_colliders(pl, cb, param, idx_parent, collid ! Find the barycenter of each body along with its children, if it has any do j = 1, 2 - colliders%xb(:, j) = pl%xh(:, idx_parent(j)) + cb%xb(:) + colliders%xb(:, j) = pl%rh(:, idx_parent(j)) + cb%xb(:) colliders%vb(:, j) = pl%vb(:, idx_parent(j)) ! Assume principal axis rotation about axis corresponding to highest moment of inertia (3rd Ip) if (param%lrotation) then @@ -521,7 +521,7 @@ function symba_collision_consolidate_colliders(pl, cb, param, idx_parent, collid idx_child = parent_child_index_array(j)%idx(i + 1) if (.not. pl%lcollision(idx_child)) cycle mchild = pl%mass(idx_child) - xchild(:) = pl%xh(:, idx_child) + cb%xb(:) + xchild(:) = pl%rh(:, idx_child) + cb%xb(:) vchild(:) = pl%vb(:, idx_child) volchild = (4.0_DP / 3.0_DP) * PI * pl%radius(idx_child)**3 volume(j) = volume(j) + volchild @@ -747,7 +747,7 @@ subroutine symba_collision_mergeaddsub(system, param, colliders, frag, status) call pl%vb2vh(cb) call pl%xh2xb(cb) do i = 1, nfrag - plnew%xh(:,i) = frag%xb(:, i) - cb%xb(:) + plnew%rh(:,i) = frag%xb(:, i) - cb%xb(:) plnew%vh(:,i) = frag%vb(:, i) - cb%vb(:) end do plnew%mass(1:nfrag) = frag%mass(1:nfrag) @@ -762,7 +762,7 @@ subroutine symba_collision_mergeaddsub(system, param, colliders, frag, status) do i = 1, nfrag write(newname, FRAGFMT) frag%id(i) call plnew%info(i)%set_value(origin_type="Disruption", origin_time=system%t, name=newname, & - origin_xh=plnew%xh(:,i), & + origin_rh=plnew%rh(:,i), & origin_vh=plnew%vh(:,i), collision_id=param%maxid_collision) end do do i = 1, ncolliders @@ -772,14 +772,14 @@ subroutine symba_collision_mergeaddsub(system, param, colliders, frag, status) iother = ibiggest end if call pl%info(colliders%idx(i))%set_value(status="Disruption", discard_time=system%t, & - discard_xh=pl%xh(:,i), discard_vh=pl%vh(:,i), discard_body_id=iother) + discard_rh=pl%rh(:,i), discard_vh=pl%vh(:,i), discard_body_id=iother) end do case(SUPERCATASTROPHIC) plnew%status(1:nfrag) = NEW_PARTICLE do i = 1, nfrag write(newname, FRAGFMT) frag%id(i) call plnew%info(i)%set_value(origin_type="Supercatastrophic", origin_time=system%t, name=newname, & - origin_xh=plnew%xh(:,i), origin_vh=plnew%vh(:,i), & + origin_rh=plnew%rh(:,i), origin_vh=plnew%vh(:,i), & collision_id=param%maxid_collision) end do do i = 1, ncolliders @@ -789,7 +789,7 @@ subroutine symba_collision_mergeaddsub(system, param, colliders, frag, status) iother = ibiggest end if call pl%info(colliders%idx(i))%set_value(status="Supercatastrophic", discard_time=system%t, & - discard_xh=pl%xh(:,i), discard_vh=pl%vh(:,i), & + discard_rh=pl%rh(:,i), discard_vh=pl%vh(:,i), & discard_body_id=iother) end do case(HIT_AND_RUN_DISRUPT) @@ -798,14 +798,14 @@ subroutine symba_collision_mergeaddsub(system, param, colliders, frag, status) do i = 2, nfrag write(newname, FRAGFMT) frag%id(i) call plnew%info(i)%set_value(origin_type="Hit and run fragment", origin_time=system%t, name=newname, & - origin_xh=plnew%xh(:,i), origin_vh=plnew%vh(:,i), & + origin_rh=plnew%rh(:,i), origin_vh=plnew%vh(:,i), & collision_id=param%maxid_collision) end do do i = 1, ncolliders if (colliders%idx(i) == ibiggest) cycle iother = ibiggest call pl%info(colliders%idx(i))%set_value(status="Hit and run fragmention", discard_time=system%t, & - discard_xh=pl%xh(:,i), discard_vh=pl%vh(:,i), & + discard_rh=pl%rh(:,i), discard_vh=pl%vh(:,i), & discard_body_id=iother) end do case(MERGED) @@ -815,7 +815,7 @@ subroutine symba_collision_mergeaddsub(system, param, colliders, frag, status) if (colliders%idx(i) == ibiggest) cycle iother = ibiggest - call pl%info(colliders%idx(i))%set_value(status="MERGED", discard_time=system%t, discard_xh=pl%xh(:,i), & + call pl%info(colliders%idx(i))%set_value(status="MERGED", discard_time=system%t, discard_rh=pl%rh(:,i), & discard_vh=pl%vh(:,i), discard_body_id=iother) end do end select diff --git a/src/symba/symba_collision.f90 b/src/symba/symba_collision.f90 index 04ec18b46..06c474078 100644 --- a/src/symba/symba_collision.f90 +++ b/src/symba/symba_collision.f90 @@ -314,7 +314,7 @@ module function symba_collision_check_encounter(self, system, param, t, dt, irec do concurrent(k = 1:nenc, lmask(k)) i = self%index1(k) j = self%index2(k) - xr(:) = pl%xh(:, i) - pl%xh(:, j) + xr(:) = pl%rh(:, i) - pl%rh(:, j) vr(:) = pl%vb(:, i) - pl%vb(:, j) rlim = pl%radius(i) + pl%radius(j) Gmtot = pl%Gmass(i) + pl%Gmass(j) @@ -325,7 +325,7 @@ module function symba_collision_check_encounter(self, system, param, t, dt, irec do concurrent(k = 1:nenc, lmask(k)) i = self%index1(k) j = self%index2(k) - xr(:) = pl%xh(:, i) - tp%xh(:, j) + xr(:) = pl%rh(:, i) - tp%rh(:, j) vr(:) = pl%vb(:, i) - tp%vb(:, j) lcollision(k) = symba_collision_check_one(xr(1), xr(2), xr(3), vr(1), vr(2), vr(3), & pl%Gmass(i), pl%radius(i), dt, self%lvdotr(k)) @@ -340,10 +340,10 @@ module function symba_collision_check_encounter(self, system, param, t, dt, irec j = self%index2(k) if (lcollision(k)) self%status(k) = COLLISION self%tcollision(k) = t - self%x1(:,k) = pl%xh(:,i) + system%cb%xb(:) + self%x1(:,k) = pl%rh(:,i) + system%cb%xb(:) self%v1(:,k) = pl%vb(:,i) if (isplpl) then - self%x2(:,k) = pl%xh(:,j) + system%cb%xb(:) + self%x2(:,k) = pl%rh(:,j) + system%cb%xb(:) self%v2(:,k) = pl%vb(:,j) if (lcollision(k)) then ! Check to see if either of these bodies has been involved with a collision before, and if so, make this a collisional colliders%idx @@ -352,11 +352,11 @@ module function symba_collision_check_encounter(self, system, param, t, dt, irec ! Set the collision flag for these to bodies to true in case they become involved in another collision later in the step pl%lcollision([i, j]) = .true. pl%status([i, j]) = COLLISION - call pl%info(i)%set_value(status="COLLISION", discard_time=t, discard_xh=pl%xh(:,i), discard_vh=pl%vh(:,i)) - call pl%info(j)%set_value(status="COLLISION", discard_time=t, discard_xh=pl%xh(:,j), discard_vh=pl%vh(:,j)) + call pl%info(i)%set_value(status="COLLISION", discard_time=t, discard_rh=pl%rh(:,i), discard_vh=pl%vh(:,i)) + call pl%info(j)%set_value(status="COLLISION", discard_time=t, discard_rh=pl%rh(:,j), discard_vh=pl%vh(:,j)) end if else - self%x2(:,k) = tp%xh(:,j) + system%cb%xb(:) + self%x2(:,k) = tp%rh(:,j) + system%cb%xb(:) self%v2(:,k) = tp%vb(:,j) if (lcollision(k)) then tp%status(j) = DISCARDED_PLR @@ -364,7 +364,7 @@ module function symba_collision_check_encounter(self, system, param, t, dt, irec write(idstri, *) pl%id(i) write(idstrj, *) tp%id(j) write(timestr, *) t - call tp%info(j)%set_value(status="DISCARDED_PLR", discard_time=t, discard_xh=tp%xh(:,j), discard_vh=tp%vh(:,j)) + call tp%info(j)%set_value(status="DISCARDED_PLR", discard_time=t, discard_rh=tp%rh(:,j), discard_vh=tp%vh(:,j)) write(message, *) "Particle " // trim(adjustl(tp%info(j)%name)) // " (" // trim(adjustl(idstrj)) // ")" & // " collided with massive body " // trim(adjustl(pl%info(i)%name)) // " (" // trim(adjustl(idstri)) // ")" & // " at t = " // trim(adjustl(timestr)) @@ -508,7 +508,7 @@ function symba_collision_consolidate_colliders(pl, cb, param, idx_parent, collid ! Find the barycenter of each body along with its children, if it has any do j = 1, 2 - colliders%xb(:, j) = pl%xh(:, idx_parent(j)) + cb%xb(:) + colliders%xb(:, j) = pl%rh(:, idx_parent(j)) + cb%xb(:) colliders%vb(:, j) = pl%vb(:, idx_parent(j)) ! Assume principal axis rotation about axis corresponding to highest moment of inertia (3rd Ip) if (param%lrotation) then @@ -521,7 +521,7 @@ function symba_collision_consolidate_colliders(pl, cb, param, idx_parent, collid idx_child = parent_child_index_array(j)%idx(i + 1) if (.not. pl%lcollision(idx_child)) cycle mchild = pl%mass(idx_child) - xchild(:) = pl%xh(:, idx_child) + cb%xb(:) + xchild(:) = pl%rh(:, idx_child) + cb%xb(:) vchild(:) = pl%vb(:, idx_child) volchild = (4.0_DP / 3.0_DP) * PI * pl%radius(idx_child)**3 volume(j) = volume(j) + volchild @@ -747,7 +747,7 @@ subroutine symba_collision_mergeaddsub(system, param, colliders, frag, status) call pl%vb2vh(cb) call pl%xh2xb(cb) do i = 1, nfrag - plnew%xh(:,i) = frag%xb(:, i) - cb%xb(:) + plnew%rh(:,i) = frag%xb(:, i) - cb%xb(:) plnew%vh(:,i) = frag%vb(:, i) - cb%vb(:) end do plnew%mass(1:nfrag) = frag%mass(1:nfrag) @@ -762,7 +762,7 @@ subroutine symba_collision_mergeaddsub(system, param, colliders, frag, status) do i = 1, nfrag write(newname, FRAGFMT) frag%id(i) call plnew%info(i)%set_value(origin_type="Disruption", origin_time=system%t, name=newname, & - origin_xh=plnew%xh(:,i), & + origin_rh=plnew%rh(:,i), & origin_vh=plnew%vh(:,i), collision_id=param%maxid_collision) end do do i = 1, ncolliders @@ -772,14 +772,14 @@ subroutine symba_collision_mergeaddsub(system, param, colliders, frag, status) iother = ibiggest end if call pl%info(colliders%idx(i))%set_value(status="Disruption", discard_time=system%t, & - discard_xh=pl%xh(:,i), discard_vh=pl%vh(:,i), discard_body_id=iother) + discard_rh=pl%rh(:,i), discard_vh=pl%vh(:,i), discard_body_id=iother) end do case(SUPERCATASTROPHIC) plnew%status(1:nfrag) = NEW_PARTICLE do i = 1, nfrag write(newname, FRAGFMT) frag%id(i) call plnew%info(i)%set_value(origin_type="Supercatastrophic", origin_time=system%t, name=newname, & - origin_xh=plnew%xh(:,i), origin_vh=plnew%vh(:,i), & + origin_rh=plnew%rh(:,i), origin_vh=plnew%vh(:,i), & collision_id=param%maxid_collision) end do do i = 1, ncolliders @@ -789,7 +789,7 @@ subroutine symba_collision_mergeaddsub(system, param, colliders, frag, status) iother = ibiggest end if call pl%info(colliders%idx(i))%set_value(status="Supercatastrophic", discard_time=system%t, & - discard_xh=pl%xh(:,i), discard_vh=pl%vh(:,i), & + discard_rh=pl%rh(:,i), discard_vh=pl%vh(:,i), & discard_body_id=iother) end do case(HIT_AND_RUN_DISRUPT) @@ -798,14 +798,14 @@ subroutine symba_collision_mergeaddsub(system, param, colliders, frag, status) do i = 2, nfrag write(newname, FRAGFMT) frag%id(i) call plnew%info(i)%set_value(origin_type="Hit and run fragment", origin_time=system%t, name=newname, & - origin_xh=plnew%xh(:,i), origin_vh=plnew%vh(:,i), & + origin_rh=plnew%rh(:,i), origin_vh=plnew%vh(:,i), & collision_id=param%maxid_collision) end do do i = 1, ncolliders if (colliders%idx(i) == ibiggest) cycle iother = ibiggest call pl%info(colliders%idx(i))%set_value(status="Hit and run fragmention", discard_time=system%t, & - discard_xh=pl%xh(:,i), discard_vh=pl%vh(:,i), & + discard_rh=pl%rh(:,i), discard_vh=pl%vh(:,i), & discard_body_id=iother) end do case(MERGED) @@ -815,7 +815,7 @@ subroutine symba_collision_mergeaddsub(system, param, colliders, frag, status) if (colliders%idx(i) == ibiggest) cycle iother = ibiggest - call pl%info(colliders%idx(i))%set_value(status="MERGED", discard_time=system%t, discard_xh=pl%xh(:,i), & + call pl%info(colliders%idx(i))%set_value(status="MERGED", discard_time=system%t, discard_rh=pl%rh(:,i), & discard_vh=pl%vh(:,i), discard_body_id=iother) end do end select diff --git a/src/symba/symba_discard.f90 b/src/symba/symba_discard.f90 index 76bcbaf41..a380487f7 100644 --- a/src/symba/symba_discard.f90 +++ b/src/symba/symba_discard.f90 @@ -38,7 +38,7 @@ subroutine symba_discard_cb_pl(pl, system, param) rmaxu2 = param%rmaxu**2 do i = 1, npl if (pl%status(i) == ACTIVE) then - rh2 = dot_product(pl%xh(:,i), pl%xh(:,i)) + rh2 = dot_product(pl%rh(:,i), pl%rh(:,i)) if ((param%rmax >= 0.0_DP) .and. (rh2 > rmax2)) then pl%ldiscard(i) = .true. pl%lcollision(i) = .false. @@ -54,7 +54,7 @@ subroutine symba_discard_cb_pl(pl, system, param) call io_log_one_message(FRAGGLE_LOG_OUT, "***********************************************************" // & "***********************************************************") call io_log_one_message(FRAGGLE_LOG_OUT, "") - call pl%info(i)%set_value(status="DISCARDED_RMAX", discard_time=system%t, discard_xh=pl%xh(:,i), & + call pl%info(i)%set_value(status="DISCARDED_RMAX", discard_time=system%t, discard_rh=pl%rh(:,i), & discard_vh=pl%vh(:,i)) else if ((param%rmin >= 0.0_DP) .and. (rh2 < rmin2)) then pl%ldiscard(i) = .true. @@ -71,7 +71,7 @@ subroutine symba_discard_cb_pl(pl, system, param) call io_log_one_message(FRAGGLE_LOG_OUT, "************************************************************" // & "************************************************************") call io_log_one_message(FRAGGLE_LOG_OUT, "") - call pl%info(i)%set_value(status="DISCARDED_RMIN", discard_time=system%t, discard_xh=pl%xh(:,i), & + call pl%info(i)%set_value(status="DISCARDED_RMIN", discard_time=system%t, discard_rh=pl%rh(:,i), & discard_vh=pl%vh(:,i), discard_body_id=cb%id) else if (param%rmaxu >= 0.0_DP) then rb2 = dot_product(pl%xb(:,i), pl%xb(:,i)) @@ -92,7 +92,7 @@ subroutine symba_discard_cb_pl(pl, system, param) call io_log_one_message(FRAGGLE_LOG_OUT, "************************************************************" // & "************************************************************") call io_log_one_message(FRAGGLE_LOG_OUT, "") - call pl%info(i)%set_value(status="DISCARDED_RMAXU", discard_time=system%t, discard_xh=pl%xh(:,i), & + call pl%info(i)%set_value(status="DISCARDED_RMAXU", discard_time=system%t, discard_rh=pl%rh(:,i), & discard_vh=pl%vh(:,i)) end if end if @@ -330,7 +330,7 @@ subroutine symba_discard_peri_pl(pl, system, param) write(*, *) trim(adjustl(pl%info(i)%name)) // " (" // trim(adjustl(idstr)) // & ") perihelion distance too small at t = " // trim(adjustl(timestr)) call pl%info(i)%set_value(status="DISCARDED_PERI", discard_time=system%t, & - discard_xh=pl%xh(:,i), discard_vh=pl%vh(:,i), discard_body_id=system%cb%id) + discard_rh=pl%rh(:,i), discard_vh=pl%vh(:,i), discard_body_id=system%cb%id) end if end if end if diff --git a/src/symba/symba_encounter_check.f90 b/src/symba/symba_encounter_check.f90 index 1cfa81c88..b955d4998 100644 --- a/src/symba/symba_encounter_check.f90 +++ b/src/symba/symba_encounter_check.f90 @@ -43,9 +43,9 @@ module function symba_encounter_check_pl(self, param, system, dt, irec) result(l call pl%set_renc(irec) if (nplt == 0) then - call encounter_check_all_plpl(param, npl, pl%xh, pl%vb, pl%renc, dt, nenc, index1, index2, lvdotr) + call encounter_check_all_plpl(param, npl, pl%rh, pl%vb, pl%renc, dt, nenc, index1, index2, lvdotr) else - call encounter_check_all_plplm(param, nplm, nplt, pl%xh(:,1:nplm), pl%vb(:,1:nplm), pl%xh(:,nplm+1:npl), & + call encounter_check_all_plplm(param, nplm, nplt, pl%rh(:,1:nplm), pl%vb(:,1:nplm), pl%rh(:,nplm+1:npl), & pl%vb(:,nplm+1:npl), pl%renc(1:nplm), pl%renc(nplm+1:npl), dt, nenc, index1, index2, lvdotr) end if @@ -65,8 +65,8 @@ module function symba_encounter_check_pl(self, param, system, dt, irec) result(l plplenc_list%id2(k) = pl%id(j) plplenc_list%status(k) = ACTIVE plplenc_list%level(k) = irec - plplenc_list%x1(:,k) = pl%xh(:,i) - plplenc_list%x2(:,k) = pl%xh(:,j) + plplenc_list%x1(:,k) = pl%rh(:,i) + plplenc_list%x2(:,k) = pl%rh(:,j) plplenc_list%v1(:,k) = pl%vb(:,i) - cb%vb(:) plplenc_list%v2(:,k) = pl%vb(:,j) - cb%vb(:) plplenc_list%Gmass1(k) = pl%Gmass(i) @@ -151,7 +151,7 @@ module function symba_encounter_check(self, param, system, dt, irec) result(lany k = eidx(lidx) i = self%index1(k) j = self%index2(k) - xr(:) = pl%xh(:,j) - pl%xh(:,i) + xr(:) = pl%rh(:,j) - pl%rh(:,i) vr(:) = pl%vb(:,j) - pl%vb(:,i) rcrit12 = pl%renc(i) + pl%renc(j) call encounter_check_one(xr(1), xr(2), xr(3), vr(1), vr(2), vr(3), rcrit12, dt, lencounter(lidx), self%lvdotr(k)) @@ -166,7 +166,7 @@ module function symba_encounter_check(self, param, system, dt, irec) result(lany k = eidx(lidx) i = self%index1(k) j = self%index2(k) - xr(:) = tp%xh(:,j) - pl%xh(:,i) + xr(:) = tp%rh(:,j) - pl%rh(:,i) vr(:) = tp%vb(:,j) - pl%vb(:,i) call encounter_check_one(xr(1), xr(2), xr(3), vr(1), vr(2), vr(3), pl%renc(i), dt, & lencounter(lidx), self%lvdotr(k)) @@ -229,7 +229,7 @@ module function symba_encounter_check_tp(self, param, system, dt, irec) result(l associate(tp => self, ntp => self%nbody, pl => system%pl, npl => system%pl%nbody) call pl%set_renc(irec) - call encounter_check_all_pltp(param, npl, ntp, pl%xh, pl%vb, tp%xh, tp%vb, pl%renc, dt, nenc, index1, index2, lvdotr) + call encounter_check_all_pltp(param, npl, ntp, pl%rh, pl%vb, tp%rh, tp%vb, pl%renc, dt, nenc, index1, index2, lvdotr) lany_encounter = nenc > 0 if (lany_encounter) then diff --git a/src/symba/symba_kick.f90 b/src/symba/symba_kick.f90 index 476fd1697..114160f9a 100644 --- a/src/symba/symba_kick.f90 +++ b/src/symba/symba_kick.f90 @@ -42,9 +42,9 @@ module subroutine symba_kick_getacch_int_pl(self, param) end if if (param%lflatten_interactions) then - call kick_getacch_int_all_flat_pl(self%nbody, self%nplplm, self%k_plpl, self%xh, self%Gmass, self%radius, self%ah) + call kick_getacch_int_all_flat_pl(self%nbody, self%nplplm, self%k_plpl, self%rh, self%Gmass, self%radius, self%ah) else - call kick_getacch_int_all_triangular_pl(self%nbody, self%nplm, self%xh, self%Gmass, self%radius, self%ah) + call kick_getacch_int_all_triangular_pl(self%nbody, self%nplm, self%rh, self%Gmass, self%radius, self%ah) end if if (param%ladaptive_interactions .and. self%nplplm > 0) then @@ -87,7 +87,7 @@ module subroutine symba_kick_getacch_pl(self, system, param, t, lbeg) allocate(k_plpl_enc(2,nplplenc)) k_plpl_enc(1,1:nplplenc) = plplenc_list%index1(1:nplplenc) k_plpl_enc(2,1:nplplenc) = plplenc_list%index2(1:nplplenc) - call kick_getacch_int_all_flat_pl(npl, nplplenc, k_plpl_enc, pl%xh, pl%Gmass, pl%radius, ah_enc) + call kick_getacch_int_all_flat_pl(npl, nplplenc, k_plpl_enc, pl%rh, pl%Gmass, pl%radius, ah_enc) pl%ah(:,1:npl) = pl%ah(:,1:npl) - ah_enc(:,1:npl) end if @@ -129,9 +129,9 @@ module subroutine symba_kick_getacch_tp(self, system, param, t, lbeg) j = pltpenc_list%index2(k) if (tp%lmask(j)) then if (lbeg) then - dx(:) = tp%xh(:,j) - pl%xbeg(:,i) + dx(:) = tp%rh(:,j) - pl%xbeg(:,i) else - dx(:) = tp%xh(:,j) - pl%xend(:,i) + dx(:) = tp%rh(:,j) - pl%xend(:,i) end if rjj = dot_product(dx(:), dx(:)) fac = pl%Gmass(i) / (rjj * sqrt(rjj)) @@ -232,11 +232,11 @@ module subroutine symba_kick_encounter(self, system, dt, irec, sgn) if (isplpl) then ri = ((pl%rhill(i) + pl%rhill(j))**2) * (RHSCALE**2) * (RSHELL**(2*irecl)) rim1 = ri * (RSHELL**2) - dx(:) = pl%xh(:,j) - pl%xh(:,i) + dx(:) = pl%rh(:,j) - pl%rh(:,i) else ri = ((pl%rhill(i))**2) * (RHSCALE**2) * (RSHELL**(2*irecl)) rim1 = ri * (RSHELL**2) - dx(:) = tp%xh(:,j) - pl%xh(:,i) + dx(:) = tp%rh(:,j) - pl%rh(:,i) end if r2 = dot_product(dx(:), dx(:)) if (r2 < rim1) then diff --git a/src/symba/symba_util.f90 b/src/symba/symba_util.f90 index b7cc9c915..621287433 100644 --- a/src/symba/symba_util.f90 +++ b/src/symba/symba_util.f90 @@ -534,7 +534,7 @@ module subroutine symba_util_peri_pl(self, system, param) if (param%qmin_coord == "HELIO") then do i = 1, npl if (pl%status(i) == ACTIVE) then - vdotr = dot_product(pl%xh(:,i), pl%vh(:,i)) + vdotr = dot_product(pl%rh(:,i), pl%vh(:,i)) if (vdotr > 0.0_DP) then pl%isperi(i) = 1 else @@ -558,11 +558,11 @@ module subroutine symba_util_peri_pl(self, system, param) if (param%qmin_coord == "HELIO") then do i = 1, npl if (pl%status(i) == ACTIVE) then - vdotr = dot_product(pl%xh(:,i), pl%vh(:,i)) + vdotr = dot_product(pl%rh(:,i), pl%vh(:,i)) if (pl%isperi(i) == -1) then if (vdotr >= 0.0_DP) then pl%isperi(i) = 0 - CALL orbel_xv2aeq(pl%mu(i), pl%xh(1,i), pl%xh(2,i), pl%xh(3,i), pl%vh(1,i), pl%vh(2,i), pl%vh(3,i), & + CALL orbel_xv2aeq(pl%mu(i), pl%rh(1,i), pl%rh(2,i), pl%rh(3,i), pl%vh(1,i), pl%vh(2,i), pl%vh(3,i), & pl%atp(i), e, pl%peri(i)) end if else diff --git a/src/tides/tides_getacch_pl.f90 b/src/tides/tides_getacch_pl.f90 index 4feb76221..c37e84b88 100644 --- a/src/tides/tides_getacch_pl.f90 +++ b/src/tides/tides_getacch_pl.f90 @@ -29,9 +29,9 @@ module subroutine tides_kick_getacch_pl(self, system) pl%atide(:,:) = 0.0_DP cb%atide(:) = 0.0_DP do i = 1, npl - rmag = norm2(pl%xh(:,i)) + rmag = norm2(pl%rh(:,i)) vmag = norm2(pl%vh(:,i)) - r_unit(:) = pl%xh(:,i) / rmag + r_unit(:) = pl%rh(:,i) / rmag v_unit(:) = pl%vh(:,i) / vmag h_unit(:) = r_unit(:) .cross. v_unit(:) theta_unit(:) = h_unit(:) .cross. r_unit(:) diff --git a/src/util/util_append.f90 b/src/util/util_append.f90 index d59704374..a02b28f2b 100644 --- a/src/util/util_append.f90 +++ b/src/util/util_append.f90 @@ -209,7 +209,7 @@ module subroutine util_append_body(self, source, lsource_mask) call util_append(self%ldiscard, source%ldiscard, nold, nsrc, lsource_mask) call util_append(self%lmask, source%lmask, nold, nsrc, lsource_mask) call util_append(self%mu, source%mu, nold, nsrc, lsource_mask) - call util_append(self%xh, source%xh, nold, nsrc, lsource_mask) + call util_append(self%rh, source%rh, nold, nsrc, lsource_mask) call util_append(self%vh, source%vh, nold, nsrc, lsource_mask) call util_append(self%xb, source%xb, nold, nsrc, lsource_mask) call util_append(self%vb, source%vb, nold, nsrc, lsource_mask) diff --git a/src/util/util_coord.f90 b/src/util/util_coord.f90 index 21b57844d..98a5549ac 100644 --- a/src/util/util_coord.f90 +++ b/src/util/util_coord.f90 @@ -35,14 +35,14 @@ module subroutine util_coord_h2b_pl(self, cb) do i = 1, npl if (pl%status(i) == INACTIVE) cycle Gmtot = Gmtot + pl%Gmass(i) - xtmp(:) = xtmp(:) + pl%Gmass(i) * pl%xh(:,i) + xtmp(:) = xtmp(:) + pl%Gmass(i) * pl%rh(:,i) vtmp(:) = vtmp(:) + pl%Gmass(i) * pl%vh(:,i) end do cb%xb(:) = -xtmp(:) / Gmtot cb%vb(:) = -vtmp(:) / Gmtot do i = 1, npl if (pl%status(i) == INACTIVE) cycle - pl%xb(:,i) = pl%xh(:,i) + cb%xb(:) + pl%xb(:,i) = pl%rh(:,i) + cb%xb(:) pl%vb(:,i) = pl%vh(:,i) + cb%vb(:) end do end associate @@ -68,7 +68,7 @@ module subroutine util_coord_h2b_tp(self, cb) if (self%nbody == 0) return associate(tp => self, ntp => self%nbody) do concurrent (i = 1:ntp, tp%status(i) /= INACTIVE) - tp%xb(:, i) = tp%xh(:, i) + cb%xb(:) + tp%xb(:, i) = tp%rh(:, i) + cb%xb(:) tp%vb(:, i) = tp%vh(:, i) + cb%vb(:) end do end associate @@ -95,7 +95,7 @@ module subroutine util_coord_b2h_pl(self, cb) associate(pl => self, npl => self%nbody) do concurrent (i = 1:npl, pl%status(i) /= INACTIVE) - pl%xh(:, i) = pl%xb(:, i) - cb%xb(:) + pl%rh(:, i) = pl%xb(:, i) - cb%xb(:) pl%vh(:, i) = pl%vb(:, i) - cb%vb(:) end do end associate @@ -122,7 +122,7 @@ module subroutine util_coord_b2h_tp(self, cb) associate(tp => self, ntp => self%nbody) do concurrent(i = 1:ntp, tp%status(i) /= INACTIVE) - tp%xh(:, i) = tp%xb(:, i) - cb%xb(:) + tp%rh(:, i) = tp%xb(:, i) - cb%xb(:) tp%vh(:, i) = tp%vb(:, i) - cb%vb(:) end do end associate @@ -246,7 +246,7 @@ module subroutine util_coord_vh2vb_tp(self, vbcb) end subroutine util_coord_vh2vb_tp - module subroutine util_coord_xh2xb_pl(self, cb) + module subroutine util_coord_rh2xb_pl(self, cb) !! author: David A. Minton !! !! Convert position vectors of massive bodies from heliocentric to barycentric coordinates (position only) @@ -269,20 +269,20 @@ module subroutine util_coord_xh2xb_pl(self, cb) do i = 1, npl if (pl%status(i) == INACTIVE) cycle Gmtot = Gmtot + pl%Gmass(i) - xtmp(:) = xtmp(:) + pl%Gmass(i) * pl%xh(:,i) + xtmp(:) = xtmp(:) + pl%Gmass(i) * pl%rh(:,i) end do cb%xb(:) = -xtmp(:) / Gmtot do i = 1, npl if (pl%status(i) == INACTIVE) cycle - pl%xb(:,i) = pl%xh(:,i) + cb%xb(:) + pl%xb(:,i) = pl%rh(:,i) + cb%xb(:) end do end associate return - end subroutine util_coord_xh2xb_pl + end subroutine util_coord_rh2xb_pl - module subroutine util_coord_xh2xb_tp(self, cb) + module subroutine util_coord_rh2xb_tp(self, cb) !! author: David A. Minton !! !! Convert test particles from heliocentric to barycentric coordinates (position only) @@ -299,11 +299,11 @@ module subroutine util_coord_xh2xb_tp(self, cb) if (self%nbody == 0) return associate(tp => self, ntp => self%nbody) do concurrent (i = 1:ntp, tp%status(i) /= INACTIVE) - tp%xb(:, i) = tp%xh(:, i) + cb%xb(:) + tp%xb(:, i) = tp%rh(:, i) + cb%xb(:) end do end associate return - end subroutine util_coord_xh2xb_tp + end subroutine util_coord_rh2xb_tp end submodule s_util_coord \ No newline at end of file diff --git a/src/util/util_copy.f90 b/src/util/util_copy.f90 index 6674cf431..bef861d07 100644 --- a/src/util/util_copy.f90 +++ b/src/util/util_copy.f90 @@ -26,10 +26,10 @@ module subroutine util_copy_particle_info(self, source) origin_type = source%origin_type, & origin_time = source%origin_time, & collision_id = source%collision_id, & - origin_xh = source%origin_xh(:), & + origin_rh = source%origin_rh(:), & origin_vh = source%origin_vh(:), & discard_time = source%discard_time, & - discard_xh = source%discard_xh(:), & + discard_rh = source%discard_rh(:), & discard_vh = source%discard_vh(:), & discard_body_id = source%discard_body_id & ) diff --git a/src/util/util_dealloc.f90 b/src/util/util_dealloc.f90 index 107a7c478..b3fb38fd9 100644 --- a/src/util/util_dealloc.f90 +++ b/src/util/util_dealloc.f90 @@ -25,7 +25,7 @@ module subroutine util_dealloc_body(self) if (allocated(self%ldiscard)) deallocate(self%ldiscard) if (allocated(self%lmask)) deallocate(self%lmask) if (allocated(self%mu)) deallocate(self%mu) - if (allocated(self%xh)) deallocate(self%xh) + if (allocated(self%rh)) deallocate(self%rh) if (allocated(self%vh)) deallocate(self%vh) if (allocated(self%xb)) deallocate(self%xb) if (allocated(self%vb)) deallocate(self%vb) diff --git a/src/util/util_fill.f90 b/src/util/util_fill.f90 index deb78f4ee..9b542d19c 100644 --- a/src/util/util_fill.f90 +++ b/src/util/util_fill.f90 @@ -160,7 +160,7 @@ module subroutine util_fill_body(self, inserts, lfill_list) call util_fill(keeps%ldiscard, inserts%ldiscard, lfill_list) call util_fill(keeps%lmask, inserts%lmask, lfill_list) call util_fill(keeps%mu, inserts%mu, lfill_list) - call util_fill(keeps%xh, inserts%xh, lfill_list) + call util_fill(keeps%rh, inserts%rh, lfill_list) call util_fill(keeps%vh, inserts%vh, lfill_list) call util_fill(keeps%xb, inserts%xb, lfill_list) call util_fill(keeps%vb, inserts%vb, lfill_list) diff --git a/src/util/util_peri.f90 b/src/util/util_peri.f90 index bed29c58a..badd0e328 100644 --- a/src/util/util_peri.f90 +++ b/src/util/util_peri.f90 @@ -34,11 +34,11 @@ module subroutine util_peri_tp(self, system, param) allocate(vdotr(ntp)) if (param%qmin_coord == "HELIO") then do i = 1, ntp - vdotr(i) = dot_product(tp%xh(:, i), tp%vh(:, i)) + vdotr(i) = dot_product(tp%rh(:, i), tp%vh(:, i)) if (tp%isperi(i) == -1) then if (vdotr(i) >= 0.0_DP) then tp%isperi(i) = 0 - call orbel_xv2aeq(tp%mu(i), tp%xh(1,i), tp%xh(2,i), tp%xh(3,i), tp%vh(1,i), tp%vh(2,i), tp%vh(3,i), & + call orbel_xv2aeq(tp%mu(i), tp%rh(1,i), tp%rh(2,i), tp%rh(3,i), tp%vh(1,i), tp%vh(2,i), tp%vh(3,i), & tp%atp(i), e, tp%peri(i)) end if else diff --git a/src/util/util_rescale.f90 b/src/util/util_rescale.f90 index 482089859..deb3e0e1e 100644 --- a/src/util/util_rescale.f90 +++ b/src/util/util_rescale.f90 @@ -48,7 +48,7 @@ module subroutine util_rescale_system(self, param, mscale, dscale, tscale) pl%mass(1:npl) = pl%mass(1:npl) / mscale pl%Gmass(1:npl) = param%GU * pl%mass(1:npl) pl%radius(1:npl) = pl%radius(1:npl) / dscale - pl%xh(:,1:npl) = pl%xh(:,1:npl) / dscale + pl%rh(:,1:npl) = pl%rh(:,1:npl) / dscale pl%vh(:,1:npl) = pl%vh(:,1:npl) / vscale pl%xb(:,1:npl) = pl%xb(:,1:npl) / dscale pl%vb(:,1:npl) = pl%vb(:,1:npl) / vscale diff --git a/src/util/util_resize.f90 b/src/util/util_resize.f90 index 01cf544ac..eee6b0e4c 100644 --- a/src/util/util_resize.f90 +++ b/src/util/util_resize.f90 @@ -297,7 +297,7 @@ module subroutine util_resize_body(self, nnew) call util_resize(self%ldiscard, nnew) call util_resize(self%lmask, nnew) call util_resize(self%mu, nnew) - call util_resize(self%xh, nnew) + call util_resize(self%rh, nnew) call util_resize(self%vh, nnew) call util_resize(self%xb, nnew) call util_resize(self%vb, nnew) diff --git a/src/util/util_set.f90 b/src/util/util_set.f90 index 1a67efcbe..05e4b41f9 100644 --- a/src/util/util_set.f90 +++ b/src/util/util_set.f90 @@ -53,7 +53,7 @@ module subroutine util_set_ir3h(self) if (self%nbody > 0) then do i = 1, self%nbody - r2 = dot_product(self%xh(:, i), self%xh(:, i)) + r2 = dot_product(self%rh(:, i), self%rh(:, i)) irh = 1.0_DP / sqrt(r2) self%ir3h(i) = irh / r2 end do @@ -107,8 +107,8 @@ module subroutine util_set_mu_tp(self, cb) return end subroutine util_set_mu_tp - module subroutine util_set_particle_info(self, name, particle_type, status, origin_type, origin_time, collision_id, origin_xh,& - origin_vh, discard_time, discard_xh, discard_vh, discard_body_id) + module subroutine util_set_particle_info(self, name, particle_type, status, origin_type, origin_time, collision_id, origin_rh,& + origin_vh, discard_time, discard_rh, discard_vh, discard_body_id) !! author: David A. Minton !! !! Sets one or more values of the particle information metadata object @@ -121,10 +121,10 @@ module subroutine util_set_particle_info(self, name, particle_type, status, orig character(len=*), intent(in), optional :: origin_type !! String containing a description of the origin of the particle (e.g. Initial Conditions, Supercatastrophic, Disruption, etc.) real(DP), intent(in), optional :: origin_time !! The time of the particle's formation integer(I4B), intent(in), optional :: collision_id !! The ID fo the collision that formed the particle - real(DP), dimension(:), intent(in), optional :: origin_xh !! The heliocentric distance vector at the time of the particle's formation + real(DP), dimension(:), intent(in), optional :: origin_rh !! The heliocentric distance vector at the time of the particle's formation real(DP), dimension(:), intent(in), optional :: origin_vh !! The heliocentric velocity vector at the time of the particle's formation real(DP), intent(in), optional :: discard_time !! The time of the particle's discard - real(DP), dimension(:), intent(in), optional :: discard_xh !! The heliocentric distance vector at the time of the particle's discard + real(DP), dimension(:), intent(in), optional :: discard_rh !! The heliocentric distance vector at the time of the particle's discard real(DP), dimension(:), intent(in), optional :: discard_vh !! The heliocentric velocity vector at the time of the particle's discard integer(I4B), intent(in), optional :: discard_body_id !! The id of the other body involved in the discard (0 if no other body involved) ! Internals @@ -152,8 +152,8 @@ module subroutine util_set_particle_info(self, name, particle_type, status, orig if (present(collision_id)) then self%collision_id = collision_id end if - if (present(origin_xh)) then - self%origin_xh(:) = origin_xh(:) + if (present(origin_rh)) then + self%origin_rh(:) = origin_rh(:) end if if (present(origin_vh)) then self%origin_vh(:) = origin_vh(:) @@ -161,8 +161,8 @@ module subroutine util_set_particle_info(self, name, particle_type, status, orig if (present(discard_time)) then self%discard_time = discard_time end if - if (present(discard_xh)) then - self%discard_xh(:) = discard_xh(:) + if (present(discard_rh)) then + self%discard_rh(:) = discard_rh(:) end if if (present(discard_vh)) then self%discard_vh(:) = discard_vh(:) @@ -242,7 +242,7 @@ module subroutine util_set_rhill_approximate(self,cb) if (self%nbody == 0) return - rh(1:self%nbody) = .mag. self%xh(:,1:self%nbody) + rh(1:self%nbody) = .mag. self%rh(:,1:self%nbody) self%rhill(1:self%nbody) = rh(1:self%nbody) * (self%Gmass(1:self%nbody) / cb%Gmass / 3)**THIRD return diff --git a/src/util/util_sort.f90 b/src/util/util_sort.f90 index dde5d7dfe..b1500afab 100644 --- a/src/util/util_sort.f90 +++ b/src/util/util_sort.f90 @@ -51,7 +51,7 @@ module subroutine util_sort_body(self, sortby, ascending) call util_sort(direction * body%capom(1:n), ind) case("mu") call util_sort(direction * body%mu(1:n), ind) - case("lfirst", "nbody", "ldiscard", "xh", "vh", "xb", "vb", "ah", "aobl", "atide", "agr") + case("lfirst", "nbody", "ldiscard", "rh", "vh", "xb", "vb", "ah", "aobl", "atide", "agr") write(*,*) 'Cannot sort by ' // trim(adjustl(sortby)) // '. Component not sortable!' case default write(*,*) 'Cannot sort by ' // trim(adjustl(sortby)) // '. Component not found!' @@ -760,7 +760,7 @@ module subroutine util_sort_rearrange_body(self, ind) call util_sort_rearrange(self%info, ind, n) call util_sort_rearrange(self%status, ind, n) call util_sort_rearrange(self%ldiscard, ind, n) - call util_sort_rearrange(self%xh, ind, n) + call util_sort_rearrange(self%rh, ind, n) call util_sort_rearrange(self%vh, ind, n) call util_sort_rearrange(self%xb, ind, n) call util_sort_rearrange(self%vb, ind, n) diff --git a/src/util/util_spill.f90 b/src/util/util_spill.f90 index 63d7fe1d9..9b9208252 100644 --- a/src/util/util_spill.f90 +++ b/src/util/util_spill.f90 @@ -339,7 +339,7 @@ module subroutine util_spill_body(self, discards, lspill_list, ldestructive) call util_spill(keeps%lmask, discards%lmask, lspill_list, ldestructive) call util_spill(keeps%ldiscard, discards%ldiscard, lspill_list, ldestructive) call util_spill(keeps%mu, discards%mu, lspill_list, ldestructive) - call util_spill(keeps%xh, discards%xh, lspill_list, ldestructive) + call util_spill(keeps%rh, discards%rh, lspill_list, ldestructive) call util_spill(keeps%vh, discards%vh, lspill_list, ldestructive) call util_spill(keeps%xb, discards%xb, lspill_list, ldestructive) call util_spill(keeps%vb, discards%vb, lspill_list, ldestructive) diff --git a/src/whm/whm_coord.f90 b/src/whm/whm_coord.f90 index 2b888a279..4af8b56a9 100644 --- a/src/whm/whm_coord.f90 +++ b/src/whm/whm_coord.f90 @@ -31,18 +31,18 @@ module subroutine whm_coord_h2j_pl(self, cb) if (self%nbody == 0) return - associate(npl => self%nbody, GMpl => self%Gmass, eta => self%eta, xh => self%xh, vh => self%vh, & + associate(npl => self%nbody, GMpl => self%Gmass, eta => self%eta, rh => self%rh, vh => self%vh, & xj => self%xj, vj => self%vj) - xj(:, 1) = xh(:, 1) + xj(:, 1) = rh(:, 1) vj(:, 1) = vh(:, 1) sumx(:) = 0.0_DP sumv(:) = 0.0_DP do i = 2, npl - sumx(:) = sumx(:) + GMpl(i - 1) * xh(:, i - 1) + sumx(:) = sumx(:) + GMpl(i - 1) * rh(:, i - 1) sumv(:) = sumv(:) + GMpl(i - 1) * vh(:, i - 1) cap(:) = sumx(:) / eta(i - 1) capv(:) = sumv(:) / eta(i - 1) - xj(:, i) = xh(:, i) - cap(:) + xj(:, i) = rh(:, i) - cap(:) vj(:, i) = vh(:, i) - capv(:) end do end associate @@ -72,16 +72,16 @@ module subroutine whm_coord_j2h_pl(self, cb) if (self%nbody == 0) return - associate(npl => self%nbody, GMpl => self%Gmass, eta => self%eta, xh => self%xh, vh => self%vh, & + associate(npl => self%nbody, GMpl => self%Gmass, eta => self%eta, rh => self%rh, vh => self%vh, & xj => self%xj, vj => self%vj) - xh(:, 1) = xj(:, 1) + rh(:, 1) = xj(:, 1) vh(:, 1) = vj(:, 1) sumx(:) = 0.0_DP sumv(:) = 0.0_DP do i = 2, npl sumx(:) = sumx(:) + GMpl(i - 1) * xj(:, i - 1) / eta(i - 1) sumv(:) = sumv(:) + GMpl(i - 1) * vj(:, i - 1) / eta(i - 1) - xh(:, i) = xj(:, i) + sumx(:) + rh(:, i) = xj(:, i) + sumx(:) vh(:, i) = vj(:, i) + sumv(:) end do end associate diff --git a/src/whm/whm_gr.f90 b/src/whm/whm_gr.f90 index 02dc7d4a4..01bd6f285 100644 --- a/src/whm/whm_gr.f90 +++ b/src/whm/whm_gr.f90 @@ -62,7 +62,7 @@ pure module subroutine whm_gr_kick_getacch_tp(self, param) if (self%nbody == 0) return associate(tp => self, ntp => self%nbody, inv_c2 => param%inv_c2) - call gr_kick_getacch(tp%mu, tp%xh, tp%lmask, ntp, param%inv_c2, tp%agr) + call gr_kick_getacch(tp%mu, tp%rh, tp%lmask, ntp, param%inv_c2, tp%agr) tp%ah(:,1:ntp) = tp%ah(:,1:ntp) + tp%agr(:,1:ntp) end associate @@ -116,7 +116,7 @@ pure module subroutine whm_gr_p4_tp(self, system, param, dt) associate(tp => self, ntp => self%nbody) if (ntp == 0) return do concurrent(i = 1:ntp, tp%lmask(i)) - call gr_p4_pos_kick(param, tp%xh(:, i), tp%vh(:, i), dt) + call gr_p4_pos_kick(param, tp%rh(:, i), tp%vh(:, i), dt) end do end associate diff --git a/src/whm/whm_kick.f90 b/src/whm/whm_kick.f90 index 54a6ef621..d782c89f4 100644 --- a/src/whm/whm_kick.f90 +++ b/src/whm/whm_kick.f90 @@ -34,7 +34,7 @@ module subroutine whm_kick_getacch_pl(self, system, param, t, lbeg) associate(cb => system%cb, pl => self, npl => self%nbody) call pl%set_ir3() - ah0(:) = whm_kick_getacch_ah0(pl%Gmass(2:npl), pl%xh(:,2:npl), npl-1) + ah0(:) = whm_kick_getacch_ah0(pl%Gmass(2:npl), pl%rh(:,2:npl), npl-1) do i = 1, npl pl%ah(:, i) = pl%ah(:, i) + ah0(:) end do @@ -158,7 +158,7 @@ pure subroutine whm_kick_getacch_ah1(cb, pl) associate(npl => pl%nbody) do concurrent (i = 2:npl, pl%lmask(i)) ah1j(:) = pl%xj(:, i) * pl%ir3j(i) - ah1h(:) = pl%xh(:, i) * pl%ir3h(i) + ah1h(:) = pl%rh(:, i) * pl%ir3h(i) pl%ah(:, i) = pl%ah(:, i) + cb%Gmass * (ah1j(:) - ah1h(:)) end do end associate @@ -227,11 +227,11 @@ module subroutine whm_kick_vh_pl(self, system, param, t, dt, lbeg) call pl%accel(system, param, t, lbeg) pl%lfirst = .false. end if - call pl%set_beg_end(xbeg = pl%xh) + call pl%set_beg_end(xbeg = pl%rh) else pl%ah(:, 1:npl) = 0.0_DP call pl%accel(system, param, t, lbeg) - call pl%set_beg_end(xend = pl%xh) + call pl%set_beg_end(xend = pl%rh) end if do concurrent(i = 1:npl, pl%lmask(i)) pl%vh(:, i) = pl%vh(:, i) + pl%ah(:, i) * dt diff --git a/src/whm/whm_util.f90 b/src/whm/whm_util.f90 index 2143cf0e9..9c6efdd41 100644 --- a/src/whm/whm_util.f90 +++ b/src/whm/whm_util.f90 @@ -171,7 +171,7 @@ module subroutine whm_util_set_ir3j(self) if (self%nbody > 0) then do i = 1, self%nbody - r2 = dot_product(self%xh(:, i), self%xh(:, i)) + r2 = dot_product(self%rh(:, i), self%rh(:, i)) ir = 1.0_DP / sqrt(r2) self%ir3h(i) = ir / r2 r2 = dot_product(self%xj(:, i), self%xj(:, i)) From 2afdbec23831233241949d459f68221252d75bed Mon Sep 17 00:00:00 2001 From: David A Minton Date: Sat, 3 Dec 2022 15:58:37 -0500 Subject: [PATCH 42/65] Started the process of converting Python code to the SPACE DIMENSION. Still a ways to go. --- python/swiftest/swiftest/init_cond.py | 7 +- python/swiftest/swiftest/io.py | 54 +++++++------- python/swiftest/swiftest/simulation_class.py | 74 +++++++++----------- 3 files changed, 64 insertions(+), 71 deletions(-) diff --git a/python/swiftest/swiftest/init_cond.py b/python/swiftest/swiftest/init_cond.py index fb7ae2fbd..147a954ce 100644 --- a/python/swiftest/swiftest/init_cond.py +++ b/python/swiftest/swiftest/init_cond.py @@ -192,6 +192,9 @@ def solar_system_horizons(plname: str, v4 = pldata[plname].vectors()['vx'][0] * VCONV v5 = pldata[plname].vectors()['vy'][0] * VCONV v6 = pldata[plname].vectors()['vz'][0] * VCONV + + rh = pldata[plname].vectors()[['x','y','z']][0] * DCONV + vh = pldata[plname].vectors()[['vx','vy','vz']][0] * VCONV elif param['IN_FORM'] == 'EL': v1 = pldata[plname].elements()['a'][0] * DCONV v2 = pldata[plname].elements()['e'][0] @@ -276,13 +279,13 @@ def vec2xr(param: Dict, namevals : v1 : array of floats - xh + rh v2 : array of floats yh v3 : array of floats zh v4 : array of floats - vhxh + vhrh v5 : array of floats vhyh v6 : array of floats diff --git a/python/swiftest/swiftest/io.py b/python/swiftest/swiftest/io.py index 7a67f9a8a..dc2899d16 100644 --- a/python/swiftest/swiftest/io.py +++ b/python/swiftest/swiftest/io.py @@ -529,9 +529,9 @@ def swifter_stream(f, param): tlab = [] if param['OUT_FORM'] == 'XV' or param['OUT_FORM'] == 'XVEL': - tlab.append('xhx') - tlab.append('xhy') - tlab.append('xhz') + tlab.append('rhx') + tlab.append('rhy') + tlab.append('rhz') tlab.append('vhx') tlab.append('vhy') tlab.append('vhz') @@ -577,9 +577,9 @@ def make_swiftest_labels(param): """ tlab = [] if param['OUT_FORM'] == 'XV' or param['OUT_FORM'] == 'XVEL': - tlab.append('xhx') - tlab.append('xhy') - tlab.append('xhz') + tlab.append('rhx') + tlab.append('rhy') + tlab.append('rhz') tlab.append('vhx') tlab.append('vhy') tlab.append('vhz') @@ -619,16 +619,16 @@ def make_swiftest_labels(param): infolab_float = [ "origin_time", - "origin_xhx", - "origin_xhy", - "origin_xhz", + "origin_rhx", + "origin_rhy", + "origin_rhz", "origin_vhx", "origin_vhy", "origin_vhz", "discard_time", - "discard_xhx", - "discard_xhy", - "discard_xhz", + "discard_rhx", + "discard_rhy", + "discard_rhz", "discard_vhx", "discard_vhy", "discard_vhz", @@ -1013,7 +1013,7 @@ def swiftest_particle_stream(f): ID of massive bodie origin_type : string The origin type for the body (Initial conditions, disruption, supercatastrophic, hit and run, etc) - origin_xh : float array + origin_rh : float array The origin heliocentric position vector origin_vh : float array The origin heliocentric velocity vector @@ -1043,7 +1043,7 @@ def swiftest_particle_2xr(param): ------- infoxr : xarray dataset """ - veclab = ['time_origin', 'xhx_origin', 'py_origin', 'pz_origin', 'vhx_origin', 'vhy_origin', 'vhz_origin'] + veclab = ['time_origin', 'rhx_origin', 'py_origin', 'pz_origin', 'vhx_origin', 'vhy_origin', 'vhz_origin'] id_list = [] origin_type_list = [] origin_vec_list = [] @@ -1100,7 +1100,7 @@ def select_active_from_frame(ds, param, framenum=-1): # Select only the active particles at this time step # Remove the inactive particles if param['OUT_FORM'] == 'XV' or param['OUT_FORM'] == 'XVEL': - iactive = iframe[count_dim].where((~np.isnan(iframe['Gmass'])) | (~np.isnan(iframe['xhx'])), drop=True)[count_dim] + iactive = iframe[count_dim].where((~np.isnan(iframe['Gmass'])) | (~np.isnan(iframe['rhx'])), drop=True)[count_dim] else: iactive = iframe[count_dim].where((~np.isnan(iframe['Gmass'])) | (~np.isnan(iframe['a'])), drop = True)[count_dim] if count_dim == "id": @@ -1197,7 +1197,7 @@ def swiftest_xr2infile(ds, param, in_type="NETCDF_DOUBLE", infile_name=None,fram if param['CHK_CLOSE']: print(pli['radius'].values[0], file=plfile) if param['IN_FORM'] == 'XV': - print(pli['xhx'].values[0], pli['xhy'].values[0], pli['xhz'].values[0], file=plfile) + print(pli['rhx'].values[0], pli['rhy'].values[0], pli['rhz'].values[0], file=plfile) print(pli['vhx'].values[0], pli['vhy'].values[0], pli['vhz'].values[0], file=plfile) elif param['IN_FORM'] == 'EL': print(pli['a'].values[0], pli['e'].values[0], pli['inc'].values[0], file=plfile) @@ -1216,7 +1216,7 @@ def swiftest_xr2infile(ds, param, in_type="NETCDF_DOUBLE", infile_name=None,fram tpi = tp.sel(id=i) print(tpi['name'].values[0], file=tpfile) if param['IN_FORM'] == 'XV': - print(tpi['xhx'].values[0], tpi['xhy'].values[0], tpi['xhz'].values[0], file=tpfile) + print(tpi['rhx'].values[0], tpi['rhy'].values[0], tpi['rhz'].values[0], file=tpfile) print(tpi['vhx'].values[0], tpi['vhy'].values[0], tpi['vhz'].values[0], file=tpfile) elif param['IN_FORM'] == 'EL': print(tpi['a'].values[0], tpi['e'].values[0], tpi['inc'].values[0], file=tpfile) @@ -1280,7 +1280,7 @@ def swifter_xr2infile(ds, param, framenum=-1): print(i.values, pli['Gmass'].values, file=plfile) if param['CHK_CLOSE']: print(pli['radius'].values, file=plfile) - print(pli['xhx'].values, pli['xhy'].values, pli['xhz'].values, file=plfile) + print(pli['rhx'].values, pli['rhy'].values, pli['rhz'].values, file=plfile) print(pli['vhx'].values, pli['vhy'].values, pli['vhz'].values, file=plfile) plfile.close() @@ -1290,7 +1290,7 @@ def swifter_xr2infile(ds, param, framenum=-1): for i in tp.id: tpi = tp.sel(id=i) print(i.values, file=tpfile) - print(tpi['xhx'].values, tpi['xhy'].values, tpi['xhz'].values, file=tpfile) + print(tpi['rhx'].values, tpi['rhy'].values, tpi['rhz'].values, file=tpfile) print(tpi['vhx'].values, tpi['vhy'].values, tpi['vhz'].values, file=tpfile) tpfile.close() else: @@ -1461,10 +1461,10 @@ def swift2swifter(swift_param, plname="", tpname="", conversion_questions={}): print(plrad, file=plnew) line = plold.readline() i_list = [i for i in re.split(' +|\t',line) if i.strip()] - xh = real2float(i_list[0]) + rh = real2float(i_list[0]) yh = real2float(i_list[1]) zh = real2float(i_list[2]) - print(xh, yh, zh, file=plnew) + print(rh, yh, zh, file=plnew) line = plold.readline() i_list = [i for i in re.split(' +|\t',line) if i.strip()] vhx = real2float(i_list[0]) @@ -1500,10 +1500,10 @@ def swift2swifter(swift_param, plname="", tpname="", conversion_questions={}): print(npl + n + 1, file=tpnew) line = tpold.readline() i_list = [i for i in re.split(' +|\t',line) if i.strip()] - xh = real2float(i_list[0]) + rh = real2float(i_list[0]) yh = real2float(i_list[1]) zh = real2float(i_list[2]) - print(xh, yh, zh, file=tpnew) + print(rh, yh, zh, file=tpnew) line = tpold.readline() i_list = [i for i in re.split(' +|\t',line) if i.strip()] vhx = real2float(i_list[0]) @@ -1589,10 +1589,10 @@ def swifter2swiftest(swifter_param, plname="", tpname="", cbname="", conversion_ print(plrad, file=plnew) line = plold.readline() i_list = [i for i in re.split(' +|\t',line) if i.strip()] - xh = real2float(i_list[0]) + rh = real2float(i_list[0]) yh = real2float(i_list[1]) zh = real2float(i_list[2]) - print(xh, yh, zh, file=plnew) + print(rh, yh, zh, file=plnew) line = plold.readline() i_list = [i for i in re.split(' +|\t',line) if i.strip()] vhx = real2float(i_list[0]) @@ -1633,10 +1633,10 @@ def swifter2swiftest(swifter_param, plname="", tpname="", cbname="", conversion_ print(name, file=tpnew) line = tpold.readline() i_list = [i for i in re.split(' +|\t',line) if i.strip()] - xh = real2float(i_list[0]) + rh = real2float(i_list[0]) yh = real2float(i_list[1]) zh = real2float(i_list[2]) - print(xh, yh, zh, file=tpnew) + print(rh, yh, zh, file=tpnew) line = tpold.readline() i_list = [i for i in re.split(' +|\t',line) if i.strip()] vhx = real2float(i_list[0]) diff --git a/python/swiftest/swiftest/simulation_class.py b/python/swiftest/swiftest/simulation_class.py index 9e1279a79..9e4840f78 100644 --- a/python/swiftest/swiftest/simulation_class.py +++ b/python/swiftest/swiftest/simulation_class.py @@ -2273,13 +2273,13 @@ def _get_instance_var(self, arg_list: str | List[str], valid_arg: Dict, verbose: def add_body(self, name: str | List[str] | npt.NDArray[np.str_] | None=None, idvals: int | list[int] | npt.NDArray[np.int_] | None=None, - v1: float | List[float] | npt.NDArray[np.float_] | None = None, - v2: float | List[float] | npt.NDArray[np.float_] | None = None, - v3: float | List[float] | npt.NDArray[np.float_] | None = None, - v4: float | List[float] | npt.NDArray[np.float_] | None = None, - v5: float | List[float] | npt.NDArray[np.float_] | None = None, - v6: float | List[float] | npt.NDArray[np.float_] | None = None, - xh: List[float] | List[npt.NDArray[np.float_]] | npt.NDArray[np.float_] | None = None, + a: float | List[float] | npt.NDArray[np.float_] | None = None, + e: float | List[float] | npt.NDArray[np.float_] | None = None, + inc: float | List[float] | npt.NDArray[np.float_] | None = None, + capom: float | List[float] | npt.NDArray[np.float_] | None = None, + omega: float | List[float] | npt.NDArray[np.float_] | None = None, + capm: float | List[float] | npt.NDArray[np.float_] | None = None, + rh: List[float] | List[npt.NDArray[np.float_]] | npt.NDArray[np.float_] | None = None, vh: List[float] | List[npt.NDArray[np.float_]] | npt.NDArray[np.float_] | None = None, mass: float | List[float] | npt.NDArray[np.float_] | None=None, Gmass: float | List[float] | npt.NDArray[np.float_] | None=None, @@ -2308,19 +2308,19 @@ def add_body(self, idvals : int or array-like of int, optional Unique id values. If not passed, an id will be assigned in ascending order starting from the pre-existing Dataset ids. - v1 : float or array-like of float, optional - xhx for param['IN_FORM'] == "XV"; a for param['IN_FORM'] == "EL" - v2 : float or array-like of float, optional - xhy for param['IN_FORM'] == "XV"; e for param['IN_FORM'] == "EL" - v3 : float or array-like of float, optional - xhz for param['IN_FORM'] == "XV"; inc for param['IN_FORM'] == "EL" - v4 : float or array-like of float, optional - vhx for param['IN_FORM'] == "XV"; capom for param['IN_FORM'] == "EL" - v5 : float or array-like of float, optional - vhy for param['IN_FORM'] == "XV"; omega for param['IN_FORM'] == "EL" - v6 : float or array-like of float, optional - vhz for param['IN_FORM'] == "XV"; capm for param['IN_FORM'] == "EL" - xh : (n,3) array-like of float, optional + a : float or array-like of float, optional + semimajor axis for param['IN_FORM'] == "EL" + e : float or array-like of float, optional + eccentricity for param['IN_FORM'] == "EL" + inc : float or array-like of float, optional + inclination for param['IN_FORM'] == "EL" + capom : float or array-like of float, optional + longitude of periapsis for param['IN_FORM'] == "EL" + omega : float or array-like of float, optional + argument of periapsis for param['IN_FORM'] == "EL" + capm : float or array-like of float, optional + mean anomaly for param['IN_FORM'] == "EL" + rh : (n,3) array-like of float, optional Position vector array. This can be used instead of passing v1, v2, and v3 sepearately for "XV" input format vh : (n,3) array-like of float, optional Velocity vector array. This can be used instead of passing v4, v5, and v6 sepearately for "XV" input format @@ -2332,10 +2332,6 @@ def add_body(self, Radius values if these are massive bodies rhill : float or array-like of float, optional Hill's radius values if these are massive bodies - Ip<1,2,3> : float or array-like of float, optional - Principal axes moments of inertia if these are massive bodies with rotation enabled - rot: float or array-like of float, optional - Rotation rate vector components if these are massive bodies with rotation enabled rot: (3) or (n,3) array-like of float, optional Rotation rate vectors if these are massive bodies with rotation enabled. This can be used instead of passing rotx, roty, and rotz separately @@ -2404,27 +2400,21 @@ def input_to_array_3d(val,n=None): nbodies = None name,nbodies = input_to_array(name,"s",nbodies) - v1,nbodies = input_to_array(v1,"f",nbodies) - v2,nbodies = input_to_array(v2,"f",nbodies) - v3,nbodies = input_to_array(v3,"f",nbodies) - v4,nbodies = input_to_array(v4,"f",nbodies) - v5,nbodies = input_to_array(v5,"f",nbodies) - v6,nbodies = input_to_array(v6,"f",nbodies) + a,nbodies = input_to_array(a,"f",nbodies) + e,nbodies = input_to_array(e,"f",nbodies) + inc,nbodies = input_to_array(inc,"f",nbodies) + capom,nbodies = input_to_array(capm,"f",nbodies) + omega,nbodies = input_to_array(omega,"f",nbodies) + capm,nbodies = input_to_array(capm,"f",nbodies) idvals,nbodies = input_to_array(idvals,"i",nbodies) mass,nbodies = input_to_array(mass,"f",nbodies) Gmass,nbodies = input_to_array(Gmass,"f",nbodies) rhill,nbodies = input_to_array(rhill,"f",nbodies) radius,nbodies = input_to_array(radius,"f",nbodies) - Ip1,nbodies = input_to_array(Ip1,"f",nbodies) - Ip2,nbodies = input_to_array(Ip2,"f",nbodies) - Ip3,nbodies = input_to_array(Ip3,"f",nbodies) - rotx,nbodies = input_to_array(rotx,"f",nbodies) - roty,nbodies = input_to_array(roty,"f",nbodies) - rotz,nbodies = input_to_array(rotz,"f",nbodies) J2,nbodies = input_to_array(J2,"f",nbodies) J4,nbodies = input_to_array(J4,"f",nbodies) - xh,nbodies = input_to_array_3d(xh,nbodies) + rh,nbodies = input_to_array_3d(rh,nbodies) vh,nbodies = input_to_array_3d(vh,nbodies) rot,nbodies = input_to_array_3d(rot,nbodies) Ip,nbodies = input_to_array_3d(Ip,nbodies) @@ -2447,13 +2437,13 @@ def input_to_array_3d(val,n=None): t = self.param['TSTART'] - if xh is not None: + if rh is not None: if v1 is not None or v2 is not None or v3 is not None: - raise ValueError("Cannot use xh and v1,v2,v3 inputs simultaneously!") + raise ValueError("Cannot use rh and v1,v2,v3 inputs simultaneously!") else: - v1 = xh.T[0] - v2 = xh.T[1] - v3 = xh.T[2] + v1 = rh.T[0] + v2 = rh.T[1] + v3 = rh.T[2] if vh is not None: if v4 is not None or v5 is not None or v6 is not None: From d1167535c88997bf78599db3e20f91543aeaee45 Mon Sep 17 00:00:00 2001 From: David A Minton Date: Sat, 3 Dec 2022 16:49:45 -0500 Subject: [PATCH 43/65] Converted init.solar_system_horizons function to the SPACE DIMENSION --- python/swiftest/swiftest/init_cond.py | 92 +++++++++++---------------- 1 file changed, 37 insertions(+), 55 deletions(-) diff --git a/python/swiftest/swiftest/init_cond.py b/python/swiftest/swiftest/init_cond.py index 147a954ce..693c206d9 100644 --- a/python/swiftest/swiftest/init_cond.py +++ b/python/swiftest/swiftest/init_cond.py @@ -135,38 +135,37 @@ def solar_system_horizons(plname: str, solarpole = SkyCoord(ra=286.13 * u.degree, dec=63.87 * u.degree) solarrot = planetrot['Sun'] * param['TU2S'] rotcb = solarpole.cartesian * solarrot + rotcb = np.array([rotcb.x.value, rotcb.y.value, rotcb.z.value]) Ipsun = np.array([0.0, 0.0, planetIpz['Sun']]) param_tmp = param param_tmp['OUT_FORM'] = 'XVEL' + rh = None + vh = None + a = None + e = None + inc = None + capom = None + omega = None + capm = None + Ip = None + rot = None + rhill = None + GMpl = None + Rpl = None + J2 = None + J4 = None + if plname == "Sun" : # Create central body print("Creating the Sun as a central body") - v1 = None - v2 = None - v3 = None - v4 = None - v5 = None - v6 = None - rhill = None GMpl = GMcb Rpl = Rcb J2 = J2RP2 J4 = J4RP4 if param['ROTATION']: - Ip1 = Ipsun[0] - Ip2 = Ipsun[1] - Ip3 = Ipsun[2] - rotx = rotcb.x.value - roty = rotcb.y.value - rotz = rotcb.z.value - else: - Ip1 = None - Ip2 = None - Ip3 = None - rotx = None - roty = None - rotz = None + Ip = Ipsun + rot = rotcb else: # Fetch solar system ephemerides from Horizons print(f"Fetching ephemerides data for {plname} from JPL/Horizons") @@ -177,44 +176,38 @@ def solar_system_horizons(plname: str, ephemerides_end_date = tend.isoformat() ephemerides_step = '1d' - J2 = None - J4 = None - pldata = {} pldata[plname] = Horizons(id=idval, location='@sun', epochs={'start': ephemerides_start_date, 'stop': ephemerides_end_date, 'step': ephemerides_step}) if param['IN_FORM'] == 'XV': - v1 = pldata[plname].vectors()['x'][0] * DCONV - v2 = pldata[plname].vectors()['y'][0] * DCONV - v3 = pldata[plname].vectors()['z'][0] * DCONV - v4 = pldata[plname].vectors()['vx'][0] * VCONV - v5 = pldata[plname].vectors()['vy'][0] * VCONV - v6 = pldata[plname].vectors()['vz'][0] * VCONV + rx = pldata[plname].vectors()['x'][0] * DCONV + ry = pldata[plname].vectors()['y'][0] * DCONV + rz = pldata[plname].vectors()['z'][0] * DCONV + vx = pldata[plname].vectors()['vx'][0] * VCONV + vy = pldata[plname].vectors()['vy'][0] * VCONV + vz = pldata[plname].vectors()['vz'][0] * VCONV - rh = pldata[plname].vectors()[['x','y','z']][0] * DCONV - vh = pldata[plname].vectors()[['vx','vy','vz']][0] * VCONV + rh = np.array([rx,ry,rz]) + vh = np.array([vx,vy,vz]) elif param['IN_FORM'] == 'EL': - v1 = pldata[plname].elements()['a'][0] * DCONV - v2 = pldata[plname].elements()['e'][0] - v3 = pldata[plname].elements()['incl'][0] - v4 = pldata[plname].elements()['Omega'][0] - v5 = pldata[plname].elements()['w'][0] - v6 = pldata[plname].elements()['M'][0] + a = pldata[plname].elements()['a'][0] * DCONV + e = pldata[plname].elements()['e'][0] + inc = pldata[plname].elements()['incl'][0] + capom = pldata[plname].elements()['Omega'][0] + omega = pldata[plname].elements()['w'][0] + capm = pldata[plname].elements()['M'][0] if ispl: GMpl = GMcb / MSun_over_Mpl[plname] if param['CHK_CLOSE']: Rpl = planetradius[plname] * DCONV - else: - Rpl = None # Generate planet value vectors if (param['RHILL_PRESENT']): rhill = pldata[plname].elements()['a'][0] * DCONV * (3 * MSun_over_Mpl[plname]) ** (-THIRDLONG) - else: - rhill = None + if (param['ROTATION']): RA = pldata[plname].ephemerides()['NPole_RA'][0] DEC = pldata[plname].ephemerides()['NPole_DEC'][0] @@ -222,20 +215,9 @@ def solar_system_horizons(plname: str, rotpole = SkyCoord(ra=RA * u.degree, dec=DEC * u.degree) rotrate = planetrot[plname] * param['TU2S'] rot = rotpole.cartesian * rotrate + rot = np.array([rot.x.value, rot.y.value, rot.z.value]) Ip = np.array([0.0, 0.0, planetIpz[plname]]) - Ip1 = Ip[0] - Ip2 = Ip[1] - Ip3 = Ip[2] - rotx = rot.x.value - roty = rot.y.value - rotz = rot.z.value - else: - Ip1 = None - Ip2 = None - Ip3 = None - rotx = None - roty = None - rotz = None + else: GMpl = None @@ -244,7 +226,7 @@ def solar_system_horizons(plname: str, else: plid = idval - return plname,v1,v2,v3,v4,v5,v6,idval,GMpl,Rpl,rhill,Ip1,Ip2,Ip3,rotx,roty,rotz,J2,J4 + return plname,idval,a,e,inc,capom,omega,capm,rh,vh,GMpl,Rpl,rhill,Ip,rot,J2,J4 def vec2xr(param: Dict, namevals: npt.NDArray[np.str_], From 68b176afcede7e6a36789ba12532bd334d0479ad Mon Sep 17 00:00:00 2001 From: David A Minton Date: Sat, 3 Dec 2022 19:36:38 -0500 Subject: [PATCH 44/65] Continued my quest to bring the Python code into THE SPACE DIMENSION --- python/swiftest/swiftest/init_cond.py | 164 +++++++++---------- python/swiftest/swiftest/simulation_class.py | 91 +++------- 2 files changed, 102 insertions(+), 153 deletions(-) diff --git a/python/swiftest/swiftest/init_cond.py b/python/swiftest/swiftest/init_cond.py index 693c206d9..d2e6bd51f 100644 --- a/python/swiftest/swiftest/init_cond.py +++ b/python/swiftest/swiftest/init_cond.py @@ -141,25 +141,25 @@ def solar_system_horizons(plname: str, param_tmp = param param_tmp['OUT_FORM'] = 'XVEL' - rh = None - vh = None + rh = np.full(3,np.nan) + vh = np.full(3,np.nan) a = None e = None inc = None capom = None omega = None capm = None - Ip = None - rot = None + Ip = np.full(3,np.nan) + rot = np.full(3,np.nan) rhill = None - GMpl = None + Gmass = None Rpl = None J2 = None J4 = None if plname == "Sun" : # Create central body print("Creating the Sun as a central body") - GMpl = GMcb + Gmass = GMcb Rpl = Rcb J2 = J2RP2 J4 = J4RP4 @@ -200,7 +200,7 @@ def solar_system_horizons(plname: str, capm = pldata[plname].elements()['M'][0] if ispl: - GMpl = GMcb / MSun_over_Mpl[plname] + Gmass = GMcb / MSun_over_Mpl[plname] if param['CHK_CLOSE']: Rpl = planetradius[plname] * DCONV @@ -219,33 +219,31 @@ def solar_system_horizons(plname: str, Ip = np.array([0.0, 0.0, planetIpz[plname]]) else: - GMpl = None + Gmass = None if idval is None: plid = planetid[plname] else: plid = idval - return plname,idval,a,e,inc,capom,omega,capm,rh,vh,GMpl,Rpl,rhill,Ip,rot,J2,J4 + return plname,idval,a,e,inc,capom,omega,capm,rh,vh,Gmass,Rpl,rhill,Ip,rot,J2,J4 def vec2xr(param: Dict, - namevals: npt.NDArray[np.str_], - v1: npt.NDArray[np.float_], - v2: npt.NDArray[np.float_], - v3: npt.NDArray[np.float_], - v4: npt.NDArray[np.float_], - v5: npt.NDArray[np.float_], - v6: npt.NDArray[np.float_], - idvals: npt.NDArray[np.int_], - GMpl: npt.NDArray[np.float_] | None=None, - Rpl: npt.NDArray[np.float_] | None=None, + name: npt.NDArray[np.str_] | None=None, + id: npt.NDArray[np.int_] | None=None, + a: npt.NDArray[np.float_] | None=None, + e: npt.NDArray[np.float_] | None=None, + inc: npt.NDArray[np.float_] | None=None, + capom: npt.NDArray[np.float_] | None=None, + omega: npt.NDArray[np.float_] | None=None, + capm: npt.NDArray[np.float_] | None=None, + rh: npt.NDArray[np.int_] | None=None, + vh: npt.NDArray[np.int_] | None=None, + Gmass: npt.NDArray[np.float_] | None=None, + radius: npt.NDArray[np.float_] | None=None, rhill: npt.NDArray[np.float_] | None=None, - Ip1: npt.NDArray[np.float_] | None=None, - Ip2: npt.NDArray[np.float_] | None=None, - Ip3: npt.NDArray[np.float_] | None=None, - rotx: npt.NDArray[np.float_] | None=None, - roty: npt.NDArray[np.float_] | None=None, - rotz: npt.NDArray[np.float_] | None=None, + Ip: npt.NDArray[np.float_] | None=None, + rot: npt.NDArray[np.float_] | None=None, J2: npt.NDArray[np.float_] | None=None, J4: npt.NDArray[np.float_] | None=None, t: float=0.0): @@ -256,76 +254,66 @@ def vec2xr(param: Dict, ---------- param : dict Swiftest paramuration parameters. - idvals : integer - Array of body index values. - namevals : - - v1 : array of floats - rh - v2 : array of floats - yh - v3 : array of floats - zh - v4 : array of floats - vhrh - v5 : array of floats - vhyh - v6 : array of floats - vhzh - GMpl : array of floats - G*mass - Rpl : array of floats - radius - rhill : array of floats - Hill Radius - Ip1 : array of floats - Principal axes moments of inertia - Ip2 : array of floats - Principal axes moments of inertia - Ip3 : array of floats - Principal axes moments of inertia - rox : array of floats - Rotation rate vector - roty : array of floats - Rotation rate vector - rotz : array of floats - Rotation rate vector + name : str or array-like of str, optional + Name or names of Bodies. If none passed, name will be "Body" + id : int or array-like of int, optional + Unique id values. If not passed, an id will be assigned in ascending order starting from the pre-existing + Dataset ids. + a : float or array-like of float, optional + semimajor axis for param['IN_FORM'] == "EL" + e : float or array-like of float, optional + eccentricity for param['IN_FORM'] == "EL" + inc : float or array-like of float, optional + inclination for param['IN_FORM'] == "EL" + capom : float or array-like of float, optional + longitude of periapsis for param['IN_FORM'] == "EL" + omega : float or array-like of float, optional + argument of periapsis for param['IN_FORM'] == "EL" + capm : float or array-like of float, optional + mean anomaly for param['IN_FORM'] == "EL" + rh : (n,3) array-like of float, optional + Position vector array. This can be used instead of passing v1, v2, and v3 sepearately for "XV" input format + vh : (n,3) array-like of float, optional + Velocity vector array. This can be used instead of passing v4, v5, and v6 sepearately for "XV" input format + Gmass : float or array-like of float, optional + G*mass values if these are massive bodies (only one of mass or Gmass can be passed) + radius : float or array-like of float, optional + Radius values if these are massive bodies + rhill : float or array-like of float, optional + Hill's radius values if these are massive bodies + rot: (n,3) array-like of float, optional + Rotation rate vectors if these are massive bodies with rotation enabled. This can be used instead of passing + rotx, roty, and rotz separately + Ip: (n,3) array-like of flaot, optional + Principal axes moments of inertia vectors if these are massive bodies with rotation enabled. This can be used + instead of passing Ip1, Ip2, and Ip3 separately t : array of floats Time at start of simulation Returns ------- ds : xarray dataset """ + if param['ROTATION']: - if Ip1 is None: - Ip1 = np.full_like(v1, 0.4) - if Ip2 is None: - Ip2 = np.full_like(v1, 0.4) - if Ip3 is None: - Ip3 = np.full_like(v1, 0.4) - if rotx is None: - rotx = np.full_like(v1, 0.0) - if roty is None: - roty = np.full_like(v1, 0.0) - if rotz is None: - rotz = np.full_like(v1, 0.0) - + if Ip is None: + Ip = np.full_like(rot, 0.4) + dims = ['id', 'vec'] infodims = ['id', 'vec'] space_coords = np.array(["x","y","z"]) # The central body is always given id 0 - if GMpl is not None: - icb = (~np.isnan(GMpl)) & (idvals == 0) - ipl = (~np.isnan(GMpl)) & (idvals != 0) - itp = (np.isnan(GMpl)) & (idvals != 0) + if Gmass is not None: + icb = (~np.isnan(Gmass)) & (id == 0) + ipl = (~np.isnan(Gmass)) & (id != 0) + itp = (np.isnan(Gmass)) & (id != 0) iscb = any(icb) ispl = any(ipl) istp = any(itp) else: - icb = np.full_like(idvals,False) - ipl = np.full_like(idvals,False) - itp = idvals != 0 + icb = np.full_like(id,False) + ipl = np.full_like(id,False) + itp = id != 0 iscb = False ispl = False istp = any(itp) @@ -342,25 +330,25 @@ def vec2xr(param: Dict, param['OUT_FORM'] = param['IN_FORM'] clab, plab, tlab, infolab_float, infolab_int, infolab_str = swiftest.io.make_swiftest_labels(param) param['OUT_FORM'] = old_out_form - particle_type = np.empty_like(namevals) + particle_type = np.empty_like(name) vec = np.vstack([v1,v2,v3,v4,v5,v6]) if iscb: particle_type[icb] = "Central Body" lab_cb = clab.copy() - vec_cb = np.vstack([GMpl[icb],Rpl[icb],J2[icb],J4[icb]]) + vec_cb = np.vstack([Gmass[icb],Rpl[icb],J2[icb],J4[icb]]) if param['ROTATION']: vec_cb = np.vstack([vec_cb, Ip1[icb], Ip2[icb], Ip3[icb], rotx[icb], roty[icb], rotz[icb]]) - ds_cb = xr.DataArray(vec_cb.T, dims=dims, coords={'id': idvals[icb], 'vec': lab_cb}) + ds_cb = xr.DataArray(vec_cb.T, dims=dims, coords={'id': id[icb], 'vec': lab_cb}) ds_cb = ds_cb.expand_dims({"time":1}).assign_coords({"time": [t]}).to_dataset(dim='vec') else: ds_cb = None if ispl: - particle_type[ipl] = np.repeat("Massive Body",idvals[ipl].size) + particle_type[ipl] = np.repeat("Massive Body",id[ipl].size) lab_pl = plab.copy() - vec_pl = np.vstack([vec[:,ipl], GMpl[ipl]]) + vec_pl = np.vstack([vec[:,ipl], Gmass[ipl]]) if param['CHK_CLOSE']: vec_pl = np.vstack([vec_pl, Rpl[ipl]]) if param['RHILL_PRESENT']: @@ -368,21 +356,21 @@ def vec2xr(param: Dict, if param['ROTATION']: vec_pl = np.vstack([vec_pl, Ip1[ipl], Ip2[ipl], Ip3[ipl], rotx[ipl], roty[ipl], rotz[ipl]]) - ds_pl = xr.DataArray(vec_pl.T, dims=dims, coords={'id': idvals[ipl], 'vec': lab_pl}) + ds_pl = xr.DataArray(vec_pl.T, dims=dims, coords={'id': id[ipl], 'vec': lab_pl}) ds_pl = ds_pl.expand_dims({"time":1}).assign_coords({"time": [t]}).to_dataset(dim='vec') else: ds_pl = None if istp: - particle_type[itp] = np.repeat("Test Particle",idvals[itp].size) + particle_type[itp] = np.repeat("Test Particle",id[itp].size) lab_tp = tlab.copy() vec_tp = vec[:,itp] - ds_tp = xr.DataArray(vec_tp.T, dims=dims, coords={'id': idvals[itp], 'vec': lab_tp}) + ds_tp = xr.DataArray(vec_tp.T, dims=dims, coords={'id': id[itp], 'vec': lab_tp}) ds_tp = ds_tp.expand_dims({"time":1}).assign_coords({"time": [t]}).to_dataset(dim='vec') else: ds_tp = None - ds_info = xr.DataArray(np.vstack([namevals,particle_type]).T, dims=infodims, coords={'id': idvals, 'vec' : ["name", "particle_type"]}).to_dataset(dim='vec') + ds_info = xr.DataArray(np.vstack([name,particle_type]).T, dims=infodims, coords={'id': id, 'vec' : ["name", "particle_type"]}).to_dataset(dim='vec') ds = [d for d in [ds_cb, ds_pl, ds_tp] if d is not None] if len(ds) > 1: ds = xr.combine_by_coords(ds) diff --git a/python/swiftest/swiftest/simulation_class.py b/python/swiftest/swiftest/simulation_class.py index 9e4840f78..ac2136e5e 100644 --- a/python/swiftest/swiftest/simulation_class.py +++ b/python/swiftest/swiftest/simulation_class.py @@ -2085,61 +2085,28 @@ def add_solar_system_body(self, #Convert the list receieved from the solar_system_horizons output and turn it into arguments to vec2xr if len(body_list) == 1: - name,v1,v2,v3,v4,v5,v6,ephemeris_id,Gmass,radius,rhill,Ip1,Ip2,Ip3,rotx,roty,rotz,J2,J4 = tuple(np.hsplit(np.array(body_list[0]),19)) + values = list(np.hsplit(np.array(body_list[0]),17)) else: - name,v1,v2,v3,v4,v5,v6,ephemeris_id,Gmass,radius,rhill,Ip1,Ip2,Ip3,rotx,roty,rotz,J2,J4 = tuple(np.squeeze(np.hsplit(np.array(body_list),19))) - - ephemeris_id = ephemeris_id.astype(int) - v1 = v1.astype(np.float64) - v2 = v2.astype(np.float64) - v3 = v3.astype(np.float64) - v4 = v4.astype(np.float64) - v5 = v5.astype(np.float64) - v6 = v6.astype(np.float64) - rhill = rhill.astype(np.float64) - J2 = J2.astype(np.float64) - J4 = J4.astype(np.float64) - - Gmass = Gmass.astype(np.float64) - radius = radius.astype(np.float64) - Ip1 = Ip1.astype(np.float64) - Ip2 = Ip2.astype(np.float64) - Ip3 = Ip3.astype(np.float64) - rotx = rotx.astype(np.float64) - roty = roty.astype(np.float64) - rotz = rotz.astype(np.float64) - - - if all(np.isnan(Gmass)): - Gmass = None - if all(np.isnan(radius)): - radius = None - if all(np.isnan(rhill)): - rhill = None - if all(np.isnan(Ip1)): - Ip1 = None - if all(np.isnan(Ip2)): - Ip2 = None - if all(np.isnan(Ip3)): - Ip3 = None - if all(np.isnan(rotx)): - rotx = None - if all(np.isnan(roty)): - roty = None - if all(np.isnan(rotz)): - rotz = None - if all(np.isnan(J2)): - J2 = None - if all(np.isnan(J4)): - J4 = None - - t = self.param['TSTART'] - - dsnew = init_cond.vec2xr(self.param,name,v1,v2,v3,v4,v5,v6,ephemeris_id, - GMpl=Gmass, Rpl=radius, rhill=rhill, - Ip1=Ip1, Ip2=Ip2, Ip3=Ip3, - rotx=rotx, roty=roty, rotz=rotz, - J2=J2, J4=J4, t=t) + values = list(np.squeeze(np.hsplit(np.array(body_list),17))) + keys = ["name","id","a","e","inc","capom","omega","capm","rh","vh","Gmass","radius","rhill","Ip","rot","J2","J4"] + kwargs = dict(zip(keys,values)) + scalar_floats = ["a","e","inc","capom","omega","capm","Gmass","radius","rhill","J2","J4"] + vector_floats = ["rh","vh","Ip","rot"] + scalar_ints = ["id"] + + for k in scalar_ints: + kwargs[k] = kwargs[k].astype(int) + for k in scalar_floats: + kwargs[k] = kwargs[k].astype(np.float64) + if all(np.isnan(kwargs[k])): + kwargs[k] = None + for k in vector_floats: + kwargs[k] = kwargs[k][0].astype(np.float64) + if all(np.isnan(kwargs[k])): + kwargs[k] = None + kwargs['t'] = self.param['TSTART'] + + dsnew = init_cond.vec2xr(self.param,**kwargs) dsnew = self._combine_and_fix_dsnew(dsnew) if dsnew['npl'] > 0 or dsnew['ntp'] > 0: @@ -2272,7 +2239,7 @@ def _get_instance_var(self, arg_list: str | List[str], valid_arg: Dict, verbose: def add_body(self, name: str | List[str] | npt.NDArray[np.str_] | None=None, - idvals: int | list[int] | npt.NDArray[np.int_] | None=None, + id: int | list[int] | npt.NDArray[np.int_] | None=None, a: float | List[float] | npt.NDArray[np.float_] | None = None, e: float | List[float] | npt.NDArray[np.float_] | None = None, inc: float | List[float] | npt.NDArray[np.float_] | None = None, @@ -2285,14 +2252,8 @@ def add_body(self, Gmass: float | List[float] | npt.NDArray[np.float_] | None=None, radius: float | List[float] | npt.NDArray[np.float_] | None=None, rhill: float | List[float] | npt.NDArray[np.float_] | None=None, - Ip1: float | List[float] | npt.NDArray[np.float_] | None=None, - Ip2: float | List[float] | npt.NDArray[np.float_] | None=None, - Ip3: float | List[float] | npt.NDArray[np.float_] | None=None, - Ip: List[float] | npt.NDArray[np.float_] | None=None, - rotx: float | List[float] | npt.NDArray[np.float_] | None=None, - roty: float | List[float] | npt.NDArray[np.float_] | None=None, - rotz: float | List[float] | npt.NDArray[np.float_] | None=None, rot: List[float] | List[npt.NDArray[np.float_]] | npt.NDArray[np.float_] | None=None, + Ip: List[float] | npt.NDArray[np.float_] | None=None, J2: float | List[float] | npt.NDArray[np.float_] | None=None, J4: float | List[float] | npt.NDArray[np.float_] | None=None): """ @@ -2305,7 +2266,7 @@ def add_body(self, ---------- name : str or array-like of str, optional Name or names of Bodies. If none passed, name will be "Body" - idvals : int or array-like of int, optional + id : int or array-like of int, optional Unique id values. If not passed, an id will be assigned in ascending order starting from the pre-existing Dataset ids. a : float or array-like of float, optional @@ -2403,10 +2364,10 @@ def input_to_array_3d(val,n=None): a,nbodies = input_to_array(a,"f",nbodies) e,nbodies = input_to_array(e,"f",nbodies) inc,nbodies = input_to_array(inc,"f",nbodies) - capom,nbodies = input_to_array(capm,"f",nbodies) + capom,nbodies = input_to_array(capom,"f",nbodies) omega,nbodies = input_to_array(omega,"f",nbodies) capm,nbodies = input_to_array(capm,"f",nbodies) - idvals,nbodies = input_to_array(idvals,"i",nbodies) + idvals,nbodies = input_to_array(id,"i",nbodies) mass,nbodies = input_to_array(mass,"f",nbodies) Gmass,nbodies = input_to_array(Gmass,"f",nbodies) rhill,nbodies = input_to_array(rhill,"f",nbodies) From 8042a7cc7ea6ac9bf4a526c640c5b59a9a694c65 Mon Sep 17 00:00:00 2001 From: David A Minton Date: Sun, 4 Dec 2022 00:03:13 -0500 Subject: [PATCH 45/65] Greatly simplified the vec2xr function and now it works in THE SPACE DIMENSION --- python/swiftest/swiftest/init_cond.py | 196 ++++++------------- python/swiftest/swiftest/simulation_class.py | 29 +-- 2 files changed, 79 insertions(+), 146 deletions(-) diff --git a/python/swiftest/swiftest/init_cond.py b/python/swiftest/swiftest/init_cond.py index d2e6bd51f..f93a89a8f 100644 --- a/python/swiftest/swiftest/init_cond.py +++ b/python/swiftest/swiftest/init_cond.py @@ -24,10 +24,10 @@ List, Any ) -def solar_system_horizons(plname: str, +def solar_system_horizons(name: str, param: Dict, ephemerides_start_date: str, - idval: int | None = None): + id: int | None = None): """ Initializes a Swiftest dataset containing the major planets of the Solar System at a particular data from JPL/Horizons @@ -56,14 +56,14 @@ def solar_system_horizons(plname: str, 'Pluto': '9' } - if plname in planetid: + if name in planetid: ispl = True - idval = planetid[plname] + id = planetid[name] else: ispl = False - print(f"\nMassive body {plname} not found or not yet supported") + print(f"\nMassive body {name} not found or not yet supported") print("This will be created as a massless test particle") - if idval is None: + if id is None: print("ID value required for this input type") return @@ -157,7 +157,7 @@ def solar_system_horizons(plname: str, J2 = None J4 = None - if plname == "Sun" : # Create central body + if name == "Sun" : # Create central body print("Creating the Sun as a central body") Gmass = GMcb Rpl = Rcb @@ -167,7 +167,7 @@ def solar_system_horizons(plname: str, Ip = Ipsun rot = rotcb else: # Fetch solar system ephemerides from Horizons - print(f"Fetching ephemerides data for {plname} from JPL/Horizons") + print(f"Fetching ephemerides data for {name} from JPL/Horizons") # Horizons date time internal variables tstart = datetime.date.fromisoformat(ephemerides_start_date) @@ -177,76 +177,56 @@ def solar_system_horizons(plname: str, ephemerides_step = '1d' pldata = {} - pldata[plname] = Horizons(id=idval, location='@sun', + pldata[name] = Horizons(id=id, location='@sun', epochs={'start': ephemerides_start_date, 'stop': ephemerides_end_date, 'step': ephemerides_step}) if param['IN_FORM'] == 'XV': - rx = pldata[plname].vectors()['x'][0] * DCONV - ry = pldata[plname].vectors()['y'][0] * DCONV - rz = pldata[plname].vectors()['z'][0] * DCONV - vx = pldata[plname].vectors()['vx'][0] * VCONV - vy = pldata[plname].vectors()['vy'][0] * VCONV - vz = pldata[plname].vectors()['vz'][0] * VCONV + rx = pldata[name].vectors()['x'][0] * DCONV + ry = pldata[name].vectors()['y'][0] * DCONV + rz = pldata[name].vectors()['z'][0] * DCONV + vx = pldata[name].vectors()['vx'][0] * VCONV + vy = pldata[name].vectors()['vy'][0] * VCONV + vz = pldata[name].vectors()['vz'][0] * VCONV rh = np.array([rx,ry,rz]) vh = np.array([vx,vy,vz]) elif param['IN_FORM'] == 'EL': - a = pldata[plname].elements()['a'][0] * DCONV - e = pldata[plname].elements()['e'][0] - inc = pldata[plname].elements()['incl'][0] - capom = pldata[plname].elements()['Omega'][0] - omega = pldata[plname].elements()['w'][0] - capm = pldata[plname].elements()['M'][0] + a = pldata[name].elements()['a'][0] * DCONV + e = pldata[name].elements()['e'][0] + inc = pldata[name].elements()['incl'][0] + capom = pldata[name].elements()['Omega'][0] + omega = pldata[name].elements()['w'][0] + capm = pldata[name].elements()['M'][0] if ispl: - Gmass = GMcb / MSun_over_Mpl[plname] + Gmass = GMcb / MSun_over_Mpl[name] if param['CHK_CLOSE']: - Rpl = planetradius[plname] * DCONV + Rpl = planetradius[name] * DCONV # Generate planet value vectors if (param['RHILL_PRESENT']): - rhill = pldata[plname].elements()['a'][0] * DCONV * (3 * MSun_over_Mpl[plname]) ** (-THIRDLONG) + rhill = pldata[name].elements()['a'][0] * DCONV * (3 * MSun_over_Mpl[name]) ** (-THIRDLONG) if (param['ROTATION']): - RA = pldata[plname].ephemerides()['NPole_RA'][0] - DEC = pldata[plname].ephemerides()['NPole_DEC'][0] + RA = pldata[name].ephemerides()['NPole_RA'][0] + DEC = pldata[name].ephemerides()['NPole_DEC'][0] rotpole = SkyCoord(ra=RA * u.degree, dec=DEC * u.degree) - rotrate = planetrot[plname] * param['TU2S'] + rotrate = planetrot[name] * param['TU2S'] rot = rotpole.cartesian * rotrate rot = np.array([rot.x.value, rot.y.value, rot.z.value]) - Ip = np.array([0.0, 0.0, planetIpz[plname]]) + Ip = np.array([0.0, 0.0, planetIpz[name]]) else: Gmass = None - if idval is None: - plid = planetid[plname] - else: - plid = idval + if id is None: + id = planetid[name] - return plname,idval,a,e,inc,capom,omega,capm,rh,vh,Gmass,Rpl,rhill,Ip,rot,J2,J4 + return id,name,a,e,inc,capom,omega,capm,rh,vh,Gmass,Rpl,rhill,Ip,rot,J2,J4 -def vec2xr(param: Dict, - name: npt.NDArray[np.str_] | None=None, - id: npt.NDArray[np.int_] | None=None, - a: npt.NDArray[np.float_] | None=None, - e: npt.NDArray[np.float_] | None=None, - inc: npt.NDArray[np.float_] | None=None, - capom: npt.NDArray[np.float_] | None=None, - omega: npt.NDArray[np.float_] | None=None, - capm: npt.NDArray[np.float_] | None=None, - rh: npt.NDArray[np.int_] | None=None, - vh: npt.NDArray[np.int_] | None=None, - Gmass: npt.NDArray[np.float_] | None=None, - radius: npt.NDArray[np.float_] | None=None, - rhill: npt.NDArray[np.float_] | None=None, - Ip: npt.NDArray[np.float_] | None=None, - rot: npt.NDArray[np.float_] | None=None, - J2: npt.NDArray[np.float_] | None=None, - J4: npt.NDArray[np.float_] | None=None, - t: float=0.0): +def vec2xr(param: Dict, **kwargs: Any): """ Converts and stores the variables of all bodies in an xarray dataset. @@ -255,7 +235,7 @@ def vec2xr(param: Dict, param : dict Swiftest paramuration parameters. name : str or array-like of str, optional - Name or names of Bodies. If none passed, name will be "Body" + Name or names of Bodies. If none passed, name will be "Body" id : int or array-like of int, optional Unique id values. If not passed, an id will be assigned in ascending order starting from the pre-existing Dataset ids. @@ -283,9 +263,8 @@ def vec2xr(param: Dict, Hill's radius values if these are massive bodies rot: (n,3) array-like of float, optional Rotation rate vectors if these are massive bodies with rotation enabled. This can be used instead of passing - rotx, roty, and rotz separately - Ip: (n,3) array-like of flaot, optional - Principal axes moments of inertia vectors if these are massive bodies with rotation enabled. This can be used + Ip: (n,3) array-like of flaot, optional + Principal axes moments of inertia vectors if these are massive bodies with rotation enabled. This can be used instead of passing Ip1, Ip2, and Ip3 separately t : array of floats Time at start of simulation @@ -294,94 +273,45 @@ def vec2xr(param: Dict, ds : xarray dataset """ - if param['ROTATION']: - if Ip is None: - Ip = np.full_like(rot, 0.4) - - dims = ['id', 'vec'] - infodims = ['id', 'vec'] - space_coords = np.array(["x","y","z"]) - # The central body is always given id 0 - if Gmass is not None: - icb = (~np.isnan(Gmass)) & (id == 0) - ipl = (~np.isnan(Gmass)) & (id != 0) - itp = (np.isnan(Gmass)) & (id != 0) - iscb = any(icb) - ispl = any(ipl) - istp = any(itp) - else: - icb = np.full_like(id,False) - ipl = np.full_like(id,False) - itp = id != 0 - iscb = False - ispl = False - istp = any(itp) - if ispl and param['CHK_CLOSE'] and Rpl is None: - print("Massive bodies need a radius value.") - return None - if ispl and rhill is None and param['RHILL_PRESENT']: - print("rhill is required.") - return None - - # Be sure we use the correct input format - old_out_form = param['OUT_FORM'] - param['OUT_FORM'] = param['IN_FORM'] - clab, plab, tlab, infolab_float, infolab_int, infolab_str = swiftest.io.make_swiftest_labels(param) - param['OUT_FORM'] = old_out_form - particle_type = np.empty_like(name) - vec = np.vstack([v1,v2,v3,v4,v5,v6]) + kwargs = {k:kwargs[k] for k,v in kwargs.items() if v is not None} - if iscb: - particle_type[icb] = "Central Body" - lab_cb = clab.copy() - vec_cb = np.vstack([Gmass[icb],Rpl[icb],J2[icb],J4[icb]]) - if param['ROTATION']: - vec_cb = np.vstack([vec_cb, Ip1[icb], Ip2[icb], Ip3[icb], rotx[icb], roty[icb], rotz[icb]]) + if param['ROTATION']: + if "rot" not in kwargs: + warnings.warn("Rotation vectors must be given when rotation is enabled",stacklevel=2) + return + if "Ip" not in kwargs: + kwargs['Ip'] = np.full_like(rot, 0.4) - ds_cb = xr.DataArray(vec_cb.T, dims=dims, coords={'id': id[icb], 'vec': lab_cb}) - ds_cb = ds_cb.expand_dims({"time":1}).assign_coords({"time": [t]}).to_dataset(dim='vec') - else: - ds_cb = None + if "t" not in kwargs: + kwargs["t"] = np.array([0.0]) - if ispl: - particle_type[ipl] = np.repeat("Massive Body",id[ipl].size) - lab_pl = plab.copy() - vec_pl = np.vstack([vec[:,ipl], Gmass[ipl]]) - if param['CHK_CLOSE']: - vec_pl = np.vstack([vec_pl, Rpl[ipl]]) - if param['RHILL_PRESENT']: - vec_pl = np.vstack([vec_pl, rhill[ipl]]) - if param['ROTATION']: - vec_pl = np.vstack([vec_pl, Ip1[ipl], Ip2[ipl], Ip3[ipl], rotx[ipl], roty[ipl], rotz[ipl]]) + scalar_dims = ['id'] + vector_dims = ['id','space'] + time_dims =['time'] + space_coords = np.array(["x","y","z"]) - ds_pl = xr.DataArray(vec_pl.T, dims=dims, coords={'id': id[ipl], 'vec': lab_pl}) - ds_pl = ds_pl.expand_dims({"time":1}).assign_coords({"time": [t]}).to_dataset(dim='vec') - else: - ds_pl = None - if istp: - particle_type[itp] = np.repeat("Test Particle",id[itp].size) - lab_tp = tlab.copy() - vec_tp = vec[:,itp] - ds_tp = xr.DataArray(vec_tp.T, dims=dims, coords={'id': id[itp], 'vec': lab_tp}) - ds_tp = ds_tp.expand_dims({"time":1}).assign_coords({"time": [t]}).to_dataset(dim='vec') - else: - ds_tp = None + vector_vars = ["rh","vh","Ip","rot"] + scalar_vars = ["name","a","e","inc","capom","omega","capm","Gmass","radius","rhill","J2","J4"] + time_vars = ["rh","vh","Ip","rot","a","e","inc","capom","omega","capm","Gmass","radius","rhill","J2","J4"] - ds_info = xr.DataArray(np.vstack([name,particle_type]).T, dims=infodims, coords={'id': id, 'vec' : ["name", "particle_type"]}).to_dataset(dim='vec') - ds = [d for d in [ds_cb, ds_pl, ds_tp] if d is not None] - if len(ds) > 1: - ds = xr.combine_by_coords(ds) - else: - ds = ds[0] - ds = xr.merge([ds_info,ds]) - ds["space"] = xr.DataArray(space_coords,dims=["space"],coords={"space":space_coords}) + data_vars = {k:(scalar_dims,v) for k,v in kwargs.items() if k in scalar_vars} + data_vars.update({k:(vector_dims,v) for k,v in kwargs.items() if k in vector_vars}) + ds = xr.Dataset(data_vars=data_vars, + coords={ + "id":(["id"],kwargs['id']), + "space":(["space"],space_coords), + } + ) + time_vars = [v for v in time_vars if v in ds] + for v in time_vars: + ds[v] = ds[v].expand_dims({"time":1}).assign_coords({"time": kwargs['t']}) # Re-order dimension coordinates so that they are in the same order as the Fortran side idx = ds.indexes - dim_order = ["time", "space", "id"] + dim_order = ["time", "id", "space"] idx = {index_name: idx[index_name] for index_name in dim_order} ds = ds.reindex(idx) diff --git a/python/swiftest/swiftest/simulation_class.py b/python/swiftest/swiftest/simulation_class.py index ac2136e5e..446ee0e3d 100644 --- a/python/swiftest/swiftest/simulation_class.py +++ b/python/swiftest/swiftest/simulation_class.py @@ -2081,30 +2081,33 @@ def add_solar_system_body(self, body_list = [] for i,n in enumerate(name): - body_list.append(init_cond.solar_system_horizons(n, self.param, date, idval=ephemeris_id[i])) + body_list.append(init_cond.solar_system_horizons(n, self.param, date, id=ephemeris_id[i])) #Convert the list receieved from the solar_system_horizons output and turn it into arguments to vec2xr if len(body_list) == 1: values = list(np.hsplit(np.array(body_list[0]),17)) else: values = list(np.squeeze(np.hsplit(np.array(body_list),17))) - keys = ["name","id","a","e","inc","capom","omega","capm","rh","vh","Gmass","radius","rhill","Ip","rot","J2","J4"] + keys = ["id","name","a","e","inc","capom","omega","capm","rh","vh","Gmass","radius","rhill","Ip","rot","J2","J4"] kwargs = dict(zip(keys,values)) scalar_floats = ["a","e","inc","capom","omega","capm","Gmass","radius","rhill","J2","J4"] vector_floats = ["rh","vh","Ip","rot"] scalar_ints = ["id"] - for k in scalar_ints: - kwargs[k] = kwargs[k].astype(int) - for k in scalar_floats: - kwargs[k] = kwargs[k].astype(np.float64) - if all(np.isnan(kwargs[k])): - kwargs[k] = None - for k in vector_floats: - kwargs[k] = kwargs[k][0].astype(np.float64) - if all(np.isnan(kwargs[k])): - kwargs[k] = None - kwargs['t'] = self.param['TSTART'] + for k,v in kwargs.items(): + if k in scalar_ints: + kwargs[k] = v.astype(int) + elif k in scalar_floats: + kwargs[k] = v.astype(np.float64) + if all(np.isnan(kwargs[k])): + kwargs[k] = None + elif k in vector_floats: + kwargs[k] = np.vstack(v) + kwargs[k] = kwargs[k].astype(np.float64) + if np.all(np.isnan(kwargs[k])): + kwargs[k] = None + + kwargs['t'] = np.array([self.param['TSTART']]) dsnew = init_cond.vec2xr(self.param,**kwargs) From a527bc3b4f29ac8e88b619a3bf10b825c2ccc277 Mon Sep 17 00:00:00 2001 From: David A Minton Date: Sun, 4 Dec 2022 08:14:07 -0500 Subject: [PATCH 46/65] Cleaned up most of the add_body and add_solar_system_bodies methods for compatibility in THE SPACE DIMENSION. --- .../Basic_Simulation/initial_conditions.py | 14 ++--- python/swiftest/swiftest/init_cond.py | 39 +++++------- python/swiftest/swiftest/simulation_class.py | 59 ++++--------------- 3 files changed, 33 insertions(+), 79 deletions(-) diff --git a/examples/Basic_Simulation/initial_conditions.py b/examples/Basic_Simulation/initial_conditions.py index a577c6658..c69a5d26a 100644 --- a/examples/Basic_Simulation/initial_conditions.py +++ b/examples/Basic_Simulation/initial_conditions.py @@ -42,14 +42,10 @@ GM_pl = (np.array([6e23, 8e23, 1e24, 3e24, 5e24]) / sim.param['MU2KG']) * sim.GU R_pl = np.full(npl, (3 * (GM_pl / sim.GU) / (4 * np.pi * density_pl)) ** (1.0 / 3.0)) Rh_pl = a_pl * ((GM_pl) / (3 * sim.GU)) ** (1.0 / 3.0) -Ip1_pl = [0.4, 0.4, 0.4, 0.4, 0.4] -Ip2_pl = [0.4, 0.4, 0.4, 0.4, 0.4] -Ip3_pl = [0.4, 0.4, 0.4, 0.4, 0.4] -rotx_pl = [0.0, 0.0, 0.0, 0.0, 0.0] -roty_pl = [0.0, 0.0, 0.0, 0.0, 0.0] -rotz_pl = [0.0, 0.0, 0.0, 0.0, 0.0] +Ip_pl = np.full((npl,3),0.4,) +rot_pl = np.zeros((npl,3)) -sim.add_body(name=name_pl, v1=a_pl, v2=e_pl, v3=inc_pl, v4=capom_pl, v5=omega_pl, v6=capm_pl, Gmass=GM_pl, radius=R_pl, rhill=Rh_pl, Ip1=Ip1_pl, Ip2=Ip2_pl, Ip3=Ip3_pl, rotx=rotx_pl, roty=roty_pl, rotz=rotz_pl) +sim.add_body(name=name_pl, a=a_pl, e=e_pl, inc=inc_pl, capom=capom_pl, omega=omega_pl, capm=capm_pl, Gmass=GM_pl, radius=R_pl, rhill=Rh_pl, Ip=Ip_pl, rot=rot_pl) # Add 10 user-defined test particles ntp = 10 @@ -62,9 +58,9 @@ omega_tp = default_rng().uniform(0.0, 360.0, ntp) capm_tp = default_rng().uniform(0.0, 360.0, ntp) -sim.add_body(name=name_tp, v1=a_tp, v2=e_tp, v3=inc_tp, v4=capom_tp, v5=omega_tp, v6=capm_tp) +sim.add_body(name=name_tp, a=a_tp, e=e_tp, inc=inc_tp, capom=capom_tp, omega=omega_tp, capm=capm_tp) # Display the run configuration parameters sim.get_parameter() # Run the simulation -sim.run(tstart=0.0, tstop=1.0e2, dt=0.01, tstep_out=1.0e0, dump_cadence=0, ) +#sim.run(tstart=0.0, tstop=1.0e2, dt=0.01, tstep_out=1.0e0, dump_cadence=0, ) diff --git a/python/swiftest/swiftest/init_cond.py b/python/swiftest/swiftest/init_cond.py index f93a89a8f..b24eff0d8 100644 --- a/python/swiftest/swiftest/init_cond.py +++ b/python/swiftest/swiftest/init_cond.py @@ -266,36 +266,35 @@ def vec2xr(param: Dict, **kwargs: Any): Ip: (n,3) array-like of flaot, optional Principal axes moments of inertia vectors if these are massive bodies with rotation enabled. This can be used instead of passing Ip1, Ip2, and Ip3 separately - t : array of floats + time : array of floats Time at start of simulation Returns ------- ds : xarray dataset """ + scalar_dims = ['id'] + vector_dims = ['id','space'] + space_coords = np.array(["x","y","z"]) + vector_vars = ["rh","vh","Ip","rot"] + scalar_vars = ["name","a","e","inc","capom","omega","capm","Gmass","radius","rhill","J2","J4"] + time_vars = ["rh","vh","Ip","rot","a","e","inc","capom","omega","capm","Gmass","radius","rhill","J2","J4"] - + # Check for valid keyword arguments kwargs = {k:kwargs[k] for k,v in kwargs.items() if v is not None} - if param['ROTATION']: - if "rot" not in kwargs: - warnings.warn("Rotation vectors must be given when rotation is enabled",stacklevel=2) + if "rot" not in kwargs and "Gmass" in kwargs: + warnings.warn("Rotation vectors must be given when rotation is enabled for massive bodies",stacklevel=2) return - if "Ip" not in kwargs: + if "Ip" not in kwargs and "rot" in kwargs: kwargs['Ip'] = np.full_like(rot, 0.4) - if "t" not in kwargs: - kwargs["t"] = np.array([0.0]) - - scalar_dims = ['id'] - vector_dims = ['id','space'] - time_dims =['time'] - space_coords = np.array(["x","y","z"]) + if "time" not in kwargs: + kwargs["time"] = np.array([0.0]) + valid_arguments = vector_vars + scalar_vars + ['time','id'] - vector_vars = ["rh","vh","Ip","rot"] - scalar_vars = ["name","a","e","inc","capom","omega","capm","Gmass","radius","rhill","J2","J4"] - time_vars = ["rh","vh","Ip","rot","a","e","inc","capom","omega","capm","Gmass","radius","rhill","J2","J4"] + kwargs = {k:v for k,v in kwargs.items() if k in valid_arguments} data_vars = {k:(scalar_dims,v) for k,v in kwargs.items() if k in scalar_vars} data_vars.update({k:(vector_dims,v) for k,v in kwargs.items() if k in vector_vars}) @@ -307,12 +306,6 @@ def vec2xr(param: Dict, **kwargs: Any): ) time_vars = [v for v in time_vars if v in ds] for v in time_vars: - ds[v] = ds[v].expand_dims({"time":1}).assign_coords({"time": kwargs['t']}) - - # Re-order dimension coordinates so that they are in the same order as the Fortran side - idx = ds.indexes - dim_order = ["time", "id", "space"] - idx = {index_name: idx[index_name] for index_name in dim_order} - ds = ds.reindex(idx) + ds[v] = ds[v].expand_dims({"time":1}).assign_coords({"time": kwargs['time']}) return ds \ No newline at end of file diff --git a/python/swiftest/swiftest/simulation_class.py b/python/swiftest/swiftest/simulation_class.py index 446ee0e3d..8394c5e44 100644 --- a/python/swiftest/swiftest/simulation_class.py +++ b/python/swiftest/swiftest/simulation_class.py @@ -2085,9 +2085,9 @@ def add_solar_system_body(self, #Convert the list receieved from the solar_system_horizons output and turn it into arguments to vec2xr if len(body_list) == 1: - values = list(np.hsplit(np.array(body_list[0]),17)) + values = list(np.hsplit(np.array(body_list[0],dtype=np.dtype(object)),17)) else: - values = list(np.squeeze(np.hsplit(np.array(body_list),17))) + values = list(np.squeeze(np.hsplit(np.array(body_list,np.dtype(object)),17))) keys = ["id","name","a","e","inc","capom","omega","capm","rh","vh","Gmass","radius","rhill","Ip","rot","J2","J4"] kwargs = dict(zip(keys,values)) scalar_floats = ["a","e","inc","capom","omega","capm","Gmass","radius","rhill","J2","J4"] @@ -2107,7 +2107,7 @@ def add_solar_system_body(self, if np.all(np.isnan(kwargs[k])): kwargs[k] = None - kwargs['t'] = np.array([self.param['TSTART']]) + kwargs['time'] = np.array([self.param['TSTART']]) dsnew = init_cond.vec2xr(self.param,**kwargs) @@ -2370,7 +2370,7 @@ def input_to_array_3d(val,n=None): capom,nbodies = input_to_array(capom,"f",nbodies) omega,nbodies = input_to_array(omega,"f",nbodies) capm,nbodies = input_to_array(capm,"f",nbodies) - idvals,nbodies = input_to_array(id,"i",nbodies) + id,nbodies = input_to_array(id,"i",nbodies) mass,nbodies = input_to_array(mass,"f",nbodies) Gmass,nbodies = input_to_array(Gmass,"f",nbodies) rhill,nbodies = input_to_array(rhill,"f",nbodies) @@ -2388,50 +2388,18 @@ def input_to_array_3d(val,n=None): else: maxid = self.data.id.max().values[()] - if idvals is None: - idvals = np.arange(start=maxid+1,stop=maxid+1+nbodies,dtype=int) + if id is None: + id = np.arange(start=maxid+1,stop=maxid+1+nbodies,dtype=int) if name is None: - name=np.char.mod(f"Body%d",idvals) + name=np.char.mod(f"Body%d",id) if len(self.data) > 0: - dup_id = np.in1d(idvals, self.data.id) + dup_id = np.in1d(id, self.data.id) if any(dup_id): - raise ValueError(f"Duplicate ids detected: ", *idvals[dup_id]) + raise ValueError(f"Duplicate ids detected: ", *id[dup_id]) - t = self.param['TSTART'] - - if rh is not None: - if v1 is not None or v2 is not None or v3 is not None: - raise ValueError("Cannot use rh and v1,v2,v3 inputs simultaneously!") - else: - v1 = rh.T[0] - v2 = rh.T[1] - v3 = rh.T[2] - - if vh is not None: - if v4 is not None or v5 is not None or v6 is not None: - raise ValueError("Cannot use vh and v4,v5,v6 inputs simultaneously!") - else: - v4 = vh.T[0] - v5 = vh.T[1] - v6 = vh.T[2] - - if rot is not None: - if rotx is not None or roty is not None or rotz is not None: - raise ValueError("Cannot use rot and rotx,roty,rotz inputs simultaneously!") - else: - rotx = rot.T[0] - roty = rot.T[1] - rotz = rot.T[2] - - if Ip is not None: - if Ip1 is not None or Ip2 is not None or Ip3 is not None: - raise ValueError("Cannot use Ip and Ip1,Ip2,Ip3 inputs simultaneously!") - else: - Ip1 = Ip.T[0] - Ip2 = Ip.T[1] - Ip3 = Ip.T[2] + time = [self.param['TSTART']] if mass is not None: if Gmass is not None: @@ -2439,11 +2407,8 @@ def input_to_array_3d(val,n=None): else: Gmass = self.param['GU'] * mass - dsnew = init_cond.vec2xr(self.param, name, v1, v2, v3, v4, v5, v6, idvals, - GMpl=Gmass, Rpl=radius, rhill=rhill, - Ip1=Ip1, Ip2=Ip2, Ip3=Ip3, - rotx=rotx, roty=roty, rotz=rotz, - J2=J2, J4=J4,t=t) + dsnew = init_cond.vec2xr(self.param, name=name, a=a, e=e, inc=inc, capom=capom, omega=omega, capm=capm, id=id, + Gmass=Gmass, radius=radius, rhill=rhill, Ip=Ip, rh=rh, vh=vh,rot=rot, J2=J2, J4=J4, time=time) dsnew = self._combine_and_fix_dsnew(dsnew) self.save(verbose=False) From 63877ff147eaefa1fcde0a703c7a1fff392552d8 Mon Sep 17 00:00:00 2001 From: David A Minton Date: Sun, 4 Dec 2022 10:29:15 -0500 Subject: [PATCH 47/65] Fixed issues getting particle types when they aren't in the input file --- .../Basic_Simulation/initial_conditions.py | 2 +- src/netcdf/netcdf.f90 | 78 ++++++++++++------- 2 files changed, 53 insertions(+), 27 deletions(-) diff --git a/examples/Basic_Simulation/initial_conditions.py b/examples/Basic_Simulation/initial_conditions.py index c69a5d26a..824cccfb9 100644 --- a/examples/Basic_Simulation/initial_conditions.py +++ b/examples/Basic_Simulation/initial_conditions.py @@ -63,4 +63,4 @@ sim.get_parameter() # Run the simulation -#sim.run(tstart=0.0, tstop=1.0e2, dt=0.01, tstep_out=1.0e0, dump_cadence=0, ) +sim.run(tstart=0.0, tstop=1.0e2, dt=0.01, tstep_out=1.0e0, dump_cadence=0, ) diff --git a/src/netcdf/netcdf.f90 b/src/netcdf/netcdf.f90 index fd3bf2ec5..b5c44b00e 100644 --- a/src/netcdf/netcdf.f90 +++ b/src/netcdf/netcdf.f90 @@ -336,7 +336,6 @@ module subroutine netcdf_open(self, param, readonly) ! Required Variables call check( nf90_inq_varid(nciu%id, nciu%name_varname, nciu%name_varid), "netcdf_open nf90_inq_varid name_varid" ) - call check( nf90_inq_varid(nciu%id, nciu%ptype_varname, nciu%ptype_varid), "netcdf_open nf90_inq_varid ptype_varid" ) call check( nf90_inq_varid(nciu%id, nciu%gmass_varname, nciu%Gmass_varid), "netcdf_open nf90_inq_varid Gmass_varid" ) if ((param%out_form == "XV") .or. (param%out_form == "XVEL")) then @@ -389,6 +388,7 @@ module subroutine netcdf_open(self, param, readonly) status = nf90_inq_varid(nciu%id, nciu%status_varname, nciu%status_varid) status = nf90_inq_varid(nciu%id, nciu%j2rp2_varname, nciu%j2rp2_varid) status = nf90_inq_varid(nciu%id, nciu%j4rp4_varname, nciu%j4rp4_varid) + status = nf90_inq_varid(nciu%id, nciu%ptype_varname, nciu%ptype_varid) if (param%integrator == SYMBA) then status = nf90_inq_varid(nciu%id, nciu%nplm_varname, nciu%nplm_varid) @@ -472,8 +472,8 @@ module function netcdf_read_frame_system(self, nciu, param) result(ierr) end if ! Next, filter only bodies that don't have mass (test particles) - call check( nf90_get_var(nciu%id, nciu%Gmass_varid, vectemp(:,:), start=[1, 1, tslot]), "netcdf_read_frame_system nf90_getvar Gmass_varid" ) - plmask(:) = vectemp(1,:) == vectemp(1,:) .and. validmask(:) + call check( nf90_get_var(nciu%id, nciu%Gmass_varid, rtemp(:), start=[1, tslot]), "netcdf_read_frame_system nf90_getvar tp finder Gmass_varid" ) + plmask(:) = rtemp(:) == rtemp(:) .and. validmask(:) tpmask(:) = .not. plmask(:) .and. validmask(:) plmask(1) = .false. ! This is the central body @@ -694,7 +694,7 @@ module subroutine netcdf_read_hdr_system(self, nciu, param) tslot = param%ioutput + 1 - call check( nf90_inquire_dimension(nciu%id, nciu%id_dimid, len=idmax), "netcdf_read_frame_system nf90_inquire_dimension id_dimid" ) + call check( nf90_inquire_dimension(nciu%id, nciu%id_dimid, len=idmax), "netcdf_read_hdr_system nf90_inquire_dimension id_dimid" ) call check( nf90_get_var(nciu%id, nciu%time_varid, self%t, start=[tslot]), "netcdf_read_hdr_system nf90_getvar time_varid" ) allocate(gmtemp(idmax)) @@ -702,7 +702,7 @@ module subroutine netcdf_read_hdr_system(self, nciu, param) allocate(plmask(idmax)) allocate(plmmask(idmax)) - call check( nf90_get_var(nciu%id, nciu%Gmass_varid, gmtemp, start=[1,1], count=[idmax,1]), "netcdf_read_frame_system nf90_getvar Gmass_varid" ) + call check( nf90_get_var(nciu%id, nciu%Gmass_varid, gmtemp, start=[1,1], count=[idmax,1]), "netcdf_read_hdr_system nf90_getvar Gmass_varid" ) plmask(:) = gmtemp(:) == gmtemp(:) tpmask(:) = .not. plmask(:) @@ -827,14 +827,40 @@ module subroutine netcdf_read_particle_info_system(self, nciu, param, plmask, tp call tp%info(i)%set_value(name=ctemp(tpind(i))) end do - call check( nf90_get_var(nciu%id, nciu%ptype_varid, ctemp, count=[NAMELEN, idmax]), "netcdf_read_particle_info_system nf90_getvar ptype_varid" ) - call cb%info%set_value(particle_type=ctemp(1)) - do i = 1, npl - call pl%info(i)%set_value(particle_type=ctemp(plind(i))) - end do - do i = 1, ntp - call tp%info(i)%set_value(particle_type=ctemp(tpind(i))) - end do + status = nf90_get_var(nciu%id, nciu%ptype_varid, ctemp, count=[NAMELEN, idmax]) + if (status /= nf90_noerr) then ! Set default particle types + call cb%info%set_value(particle_type=CB_TYPE_NAME) + + ! Handle semi-interacting bodies in SyMBA + select type(pl) + class is (symba_pl) + select type (param) + class is (symba_parameters) + do i = 1, npl + if (pl%Gmass(i) < param%GMTINY) then + call pl%info(i)%set_value(particle_type=PL_TINY_TYPE_NAME) + else + call pl%info(i)%set_value(particle_type=PL_TYPE_NAME) + end if + end do + end select + class default ! Non-SyMBA massive bodies + do i = 1, npl + call pl%info(i)%set_value(particle_type=PL_TYPE_NAME) + end do + end select + do i = 1, ntp + call tp%info(i)%set_value(particle_type=TP_TYPE_NAME) + end do + else ! Use particle types defined in input file + call cb%info%set_value(particle_type=ctemp(1)) + do i = 1, npl + call pl%info(i)%set_value(particle_type=ctemp(plind(i))) + end do + do i = 1, ntp + call tp%info(i)%set_value(particle_type=ctemp(tpind(i))) + end do + end if status = nf90_inq_varid(nciu%id, nciu%status_varname, nciu%status_varid) if (status == nf90_noerr) then @@ -1049,28 +1075,28 @@ module subroutine netcdf_write_frame_base(self, nciu, param) self%vh(1,j), self%vh(2,j), self%vh(3,j), & a, e, inc, capom, omega, capm) end if - call check( nf90_put_var(nciu%id, nciu%a_varid, a, start=[idslot, tslot]), "netcdf_write_frame_base nf90_put_var a_varid" ) - call check( nf90_put_var(nciu%id, nciu%e_varid, e, start=[idslot, tslot]), "netcdf_write_frame_base nf90_put_var e_varid" ) - call check( nf90_put_var(nciu%id, nciu%inc_varid, inc * RAD2DEG, start=[idslot, tslot]), "netcdf_write_frame_base nf90_put_var inc_varid" ) - call check( nf90_put_var(nciu%id, nciu%capom_varid, capom * RAD2DEG, start=[idslot, tslot]), "netcdf_write_frame_base nf90_put_var capom_varid" ) - call check( nf90_put_var(nciu%id, nciu%omega_varid, omega * RAD2DEG, start=[idslot, tslot]), "netcdf_write_frame_base nf90_put_var omega_varid" ) - call check( nf90_put_var(nciu%id, nciu%capm_varid, capm * RAD2DEG, start=[idslot, tslot]), "netcdf_write_frame_base nf90_put_var capm_varid" ) + call check( nf90_put_var(nciu%id, nciu%a_varid, a, start=[idslot, tslot]), "netcdf_write_frame_base nf90_put_var body a_varid" ) + call check( nf90_put_var(nciu%id, nciu%e_varid, e, start=[idslot, tslot]), "netcdf_write_frame_base nf90_put_var body e_varid" ) + call check( nf90_put_var(nciu%id, nciu%inc_varid, inc * RAD2DEG, start=[idslot, tslot]), "netcdf_write_frame_base nf90_put_var body inc_varid" ) + call check( nf90_put_var(nciu%id, nciu%capom_varid, capom * RAD2DEG, start=[idslot, tslot]), "netcdf_write_frame_base nf90_put_var body capom_varid" ) + call check( nf90_put_var(nciu%id, nciu%omega_varid, omega * RAD2DEG, start=[idslot, tslot]), "netcdf_write_frame_base nf90_put_var body omega_varid" ) + call check( nf90_put_var(nciu%id, nciu%capm_varid, capm * RAD2DEG, start=[idslot, tslot]), "netcdf_write_frame_base nf90_put_var body capm_varid" ) end if select type(self) class is (swiftest_pl) ! Additional output if the passed polymorphic object is a massive body - call check( nf90_put_var(nciu%id, nciu%Gmass_varid, self%Gmass(j), start=[idslot, tslot]), "netcdf_write_frame_base nf90_put_var Gmass_varid" ) + call check( nf90_put_var(nciu%id, nciu%Gmass_varid, self%Gmass(j), start=[idslot, tslot]), "netcdf_write_frame_base nf90_put_var body Gmass_varid" ) if (param%lrhill_present) then - call check( nf90_put_var(nciu%id, nciu%rhill_varid, self%rhill(j), start=[idslot, tslot]), "netcdf_write_frame_base nf90_put_var rhill_varid" ) + call check( nf90_put_var(nciu%id, nciu%rhill_varid, self%rhill(j), start=[idslot, tslot]), "netcdf_write_frame_base nf90_put_var body rhill_varid" ) end if - if (param%lclose) call check( nf90_put_var(nciu%id, nciu%radius_varid, self%radius(j), start=[idslot, tslot]), "netcdf_write_frame_base nf90_put_var radius_varid" ) + if (param%lclose) call check( nf90_put_var(nciu%id, nciu%radius_varid, self%radius(j), start=[idslot, tslot]), "netcdf_write_frame_base nf90_put_var body radius_varid" ) if (param%lrotation) then - call check( nf90_put_var(nciu%id, nciu%Ip_varid, self%Ip(:, j), start=[1,idslot, tslot], count=[NDIM,1,1]), "netcdf_write_frame_base nf90_put_var Ip_varid" ) - call check( nf90_put_var(nciu%id, nciu%rot_varid, self%rot(:, j), start=[1,idslot, tslot], count=[NDIM,1,1]), "netcdf_write_frame_base nf90_put_var rotx_varid" ) + call check( nf90_put_var(nciu%id, nciu%Ip_varid, self%Ip(:, j), start=[1,idslot, tslot], count=[NDIM,1,1]), "netcdf_write_frame_base nf90_put_var body Ip_varid" ) + call check( nf90_put_var(nciu%id, nciu%rot_varid, self%rot(:, j), start=[1,idslot, tslot], count=[NDIM,1,1]), "netcdf_write_frame_base nf90_put_var body rotx_varid" ) end if ! if (param%ltides) then - ! call check( nf90_put_var(nciu%id, nciu%k2_varid, self%k2(j), start=[idslot, tslot]), "netcdf_write_frame_base nf90_put_var k2_varid" ) - ! call check( nf90_put_var(nciu%id, nciu%Q_varid, self%Q(j), start=[idslot, tslot]), "netcdf_write_frame_base nf90_put_var Q_varid" ) + ! call check( nf90_put_var(nciu%id, nciu%k2_varid, self%k2(j), start=[idslot, tslot]), "netcdf_write_frame_base nf90_put_var body k2_varid" ) + ! call check( nf90_put_var(nciu%id, nciu%Q_varid, self%Q(j), start=[idslot, tslot]), "netcdf_write_frame_base nf90_put_var body Q_varid" ) ! end if end select From 8a066632443c70da9bd261d62ce1db74a59f33a5 Mon Sep 17 00:00:00 2001 From: David A Minton Date: Sun, 4 Dec 2022 10:55:10 -0500 Subject: [PATCH 48/65] Created new .ic instance variable to keep a copy of the initial conditions that won't get altered by the running simulation --- python/swiftest/swiftest/simulation_class.py | 35 ++++++++++++++------ 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/python/swiftest/swiftest/simulation_class.py b/python/swiftest/swiftest/simulation_class.py index 8394c5e44..167d86e3b 100644 --- a/python/swiftest/swiftest/simulation_class.py +++ b/python/swiftest/swiftest/simulation_class.py @@ -302,6 +302,7 @@ def __init__(self,read_param: bool = False, read_old_output_file: bool = False, self.param = {} self.data = xr.Dataset() + self.ic = xr.Dataset() # Set the location of the parameter input file, choosing the default if it isn't specified. param_file = kwargs.pop("param_file",Path.cwd() / "simdata" / "param.in") @@ -322,8 +323,8 @@ def __init__(self,read_param: bool = False, read_old_output_file: bool = False, # If the user asks to read in an old parameter file or output file, override any default parameters with values from the file # If the file doesn't exist, flag it for now so we know to create it + param_file_found = False if read_param or read_old_output_file: - if self.read_param(read_init_cond = not read_old_output_file): # We will add the parameter file to the kwarg list. This will keep the set_parameter method from # overriding everything with defaults when there are no arguments passed to Simulation() @@ -347,7 +348,7 @@ def __init__(self,read_param: bool = False, read_old_output_file: bool = False, if read_old_output_file: binpath = os.path.join(self.sim_dir, self.param['BIN_OUT']) if os.path.exists(binpath): - self.bin2xr() + self.read_output_file() else: warnings.warn(f"BIN_OUT file {binpath} not found.",stacklevel=2) return @@ -470,7 +471,7 @@ def run(self,**kwargs): self._run_swiftest_driver() # Read in new data - self.bin2xr() + self.read_output_file() return @@ -2051,7 +2052,8 @@ def add_solar_system_body(self, >*Note.* Currently only the JPL Horizons ephemeris is implemented, so this is ignored. Returns ------- - data : Xarray dataset with body or bodies added. + None + initial conditions data stored as an Xarray Dataset in the init_cond instance variable """ if type(name) is str: @@ -2115,7 +2117,9 @@ def add_solar_system_body(self, if dsnew['npl'] > 0 or dsnew['ntp'] > 0: self.save(verbose=False) - return dsnew + self.ic = self.data.copy(deep=True) + + return def set_ephemeris_date(self, @@ -2412,8 +2416,9 @@ def input_to_array_3d(val,n=None): dsnew = self._combine_and_fix_dsnew(dsnew) self.save(verbose=False) + self.ic = self.data.copy(deep=True) - return dsnew + return def _combine_and_fix_dsnew(self,dsnew): """ @@ -2517,6 +2522,7 @@ def read_param(self, param_tmp = self.param.copy() param_tmp['BIN_OUT'] = init_cond_file self.data = io.swiftest2xr(param_tmp, verbose=self.verbose) + self.ic = self.data.copy(deep=True) else: warnings.warn(f"Initial conditions file file {init_cond_file} not found.", stacklevel=2) else: @@ -2641,12 +2647,14 @@ def convert(self, param_file, newcodename="Swiftest", plname="pl.swiftest.in", t warnings.warn(f"Conversion from {self.codename} to {newcodename} is not supported.",stacklevel=2) return oldparam - def bin2xr(self): + def read_output_file(self,read_init_cond : bool = True): """ - Converts simulation output files from a flat binary file to a xarray dataset. + Reads in simulation data from an output file and stores it as an Xarray Dataset in the `data` instance variable. Parameters ---------- + read_init_cond : bool + Read in an initial conditions file along with the output file. Default is True Returns ------- @@ -2661,6 +2669,13 @@ def bin2xr(self): if self.codename == "Swiftest": self.data = io.swiftest2xr(param_tmp, verbose=self.verbose) if self.verbose: print('Swiftest simulation data stored as xarray DataSet .data') + if read_init_cond: + if "NETCDF" in param['IN_TYPE']: + param_tmp['BIN_OUT'] = os.path.join(self.sim_dir, self.param['NC_IN']) + self.ic = io.swiftest2xr(param_tmp, verbose=self.verbose) + else: + self.ic = self.data.isel(time=0) + elif self.codename == "Swifter": self.data = io.swifter2xr(param_tmp, verbose=self.verbose) if self.verbose: print('Swifter simulation data stored as xarray DataSet .data') @@ -2684,11 +2699,11 @@ def follow(self, codestyle="Swifter"): fol : xarray dataset """ if self.data is None: - self.bin2xr() + self.read_output_file() if codestyle == "Swift": try: with open('follow.in', 'r') as f: - line = f.readline() # Parameter file (ignored because bin2xr already takes care of it + line = f.readline() # Parameter file (ignored because read_output_file already takes care of it line = f.readline() # PL file (ignored) line = f.readline() # TP file (ignored) line = f.readline() # ifol From 01d8a1c55ee8061ceedf7e288e563ca18c4fbe56 Mon Sep 17 00:00:00 2001 From: David A Minton Date: Sun, 4 Dec 2022 10:55:40 -0500 Subject: [PATCH 49/65] Updated Basic_Simulation initial conditions generators --- .../Basic_Simulation/initial_conditions.ipynb | 1485 +---------------- .../Basic_Simulation/initial_conditions.py | 2 +- 2 files changed, 24 insertions(+), 1463 deletions(-) diff --git a/examples/Basic_Simulation/initial_conditions.ipynb b/examples/Basic_Simulation/initial_conditions.ipynb index 17b85582f..f6a872061 100644 --- a/examples/Basic_Simulation/initial_conditions.ipynb +++ b/examples/Basic_Simulation/initial_conditions.ipynb @@ -2,18 +2,10 @@ "cells": [ { "cell_type": "code", - "execution_count": 1, + "execution_count": null, "id": "2c4f59ea-1251-49f6-af1e-5695d7e25500", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "env: OMP_NUM_THREADS=4\n" - ] - } - ], + "outputs": [], "source": [ "import swiftest\n", "import numpy as np\n", @@ -23,468 +15,21 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": null, "id": "6054c7ab-c748-4b39-9fee-d8b27326f497", "metadata": {}, "outputs": [], "source": [ "# Initialize the simulation object as a variable\n", - "sim = swiftest.Simulation(tstart=0.0, tstop=1.0e3, dt=0.01, tstep_out=1.0e0, dump_cadence=2, fragmentation=True, minimum_fragment_mass = 2.5e-11, mtiny=2.5e-8)" + "sim = swiftest.Simulation(fragmentation=True, minimum_fragment_mass = 2.5e-11, mtiny=2.5e-8)" ] }, { "cell_type": "code", - "execution_count": 3, + "execution_count": null, "id": "1c122676-bacb-447c-bc37-5ef8019be0d0", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Creating the Sun as a central body\n", - "Fetching ephemerides data for Mercury from JPL/Horizons\n", - "Fetching ephemerides data for Venus from JPL/Horizons\n", - "Fetching ephemerides data for Earth from JPL/Horizons\n", - "Fetching ephemerides data for Mars from JPL/Horizons\n", - "Fetching ephemerides data for Jupiter from JPL/Horizons\n", - "Fetching ephemerides data for Saturn from JPL/Horizons\n", - "Fetching ephemerides data for Uranus from JPL/Horizons\n", - "Fetching ephemerides data for Neptune from JPL/Horizons\n", - "Fetching ephemerides data for Pluto from JPL/Horizons\n" - ] - }, - { - "data": { - "text/html": [ - "
\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "
<xarray.Dataset>\n",
-       "Dimensions:        (name: 10, time: 1)\n",
-       "Coordinates:\n",
-       "  * name           (name) <U32 'Sun' 'Mercury' 'Venus' ... 'Neptune' 'Pluto'\n",
-       "  * time           (time) float64 0.0\n",
-       "Data variables: (12/21)\n",
-       "    particle_type  (name) <U32 'Central Body' 'Massive Body' ... 'Massive Body'\n",
-       "    id             (name) int64 0 1 2 3 4 5 6 7 8 9\n",
-       "    a              (time, name) float64 nan 0.3871 0.7233 ... 19.24 30.04 39.37\n",
-       "    e              (time, name) float64 nan 0.2056 0.006718 ... 0.008956 0.2487\n",
-       "    inc            (time, name) float64 nan 7.003 3.394 ... 0.773 1.771 17.17\n",
-       "    capom          (time, name) float64 nan 48.3 76.6 ... 74.01 131.8 110.3\n",
-       "    ...             ...\n",
-       "    rotz           (time, name) float64 82.25 34.36 8.703 ... 2.33e+03 -38.57\n",
-       "    j2rp2          (time, name) float64 4.754e-12 nan nan nan ... nan nan nan\n",
-       "    j4rp4          (time, name) float64 -2.247e-18 nan nan nan ... nan nan nan\n",
-       "    ntp            (time) int64 0\n",
-       "    npl            (time) int64 9\n",
-       "    nplm           (time) int64 8
" - ], - "text/plain": [ - "\n", - "Dimensions: (name: 10, time: 1)\n", - "Coordinates:\n", - " * name (name) \n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "
<xarray.Dataset>\n",
-       "Dimensions:        (name: 5, time: 1)\n",
-       "Coordinates:\n",
-       "  * name           (name) <U14 'MassiveBody_01' ... 'MassiveBody_05'\n",
-       "  * time           (time) float64 0.0\n",
-       "Data variables: (12/19)\n",
-       "    particle_type  (name) <U14 'Massive Body' 'Massive Body' ... 'Massive Body'\n",
-       "    id             (name) int64 10 11 12 13 14\n",
-       "    a              (time, name) float64 1.469 0.4169 1.369 0.6314 0.4806\n",
-       "    e              (time, name) float64 0.1092 0.03191 0.03574 0.03611 0.2767\n",
-       "    inc            (time, name) float64 0.2741 70.11 62.39 31.73 47.9\n",
-       "    capom          (time, name) float64 123.3 146.2 205.2 41.36 298.9\n",
-       "    ...             ...\n",
-       "    rotx           (time, name) float64 0.0 0.0 0.0 0.0 0.0\n",
-       "    roty           (time, name) float64 0.0 0.0 0.0 0.0 0.0\n",
-       "    rotz           (time, name) float64 0.0 0.0 0.0 0.0 0.0\n",
-       "    ntp            (time) int64 0\n",
-       "    npl            (time) int64 4\n",
-       "    nplm           (time) int64 4
" - ], - "text/plain": [ - "\n", - "Dimensions: (name: 5, time: 1)\n", - "Coordinates:\n", - " * name (name) \n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "
<xarray.Dataset>\n",
-       "Dimensions:        (name: 10, time: 1)\n",
-       "Coordinates:\n",
-       "  * name           (name) <U15 'TestParticle_01' ... 'TestParticle_10'\n",
-       "  * time           (time) float64 0.0\n",
-       "Data variables:\n",
-       "    particle_type  (name) <U15 'Test Particle' ... 'Test Particle'\n",
-       "    id             (name) int64 15 16 17 18 19 20 21 22 23 24\n",
-       "    a              (time, name) float64 0.7527 1.445 0.8756 ... 1.341 0.9409\n",
-       "    e              (time, name) float64 0.267 0.0711 0.04515 ... 0.1502 0.06409\n",
-       "    inc            (time, name) float64 58.34 7.109 33.64 ... 52.18 26.94 7.888\n",
-       "    capom          (time, name) float64 130.7 145.3 68.94 ... 131.8 140.6 81.53\n",
-       "    omega          (time, name) float64 144.5 215.6 104.4 ... 288.9 84.92 180.3\n",
-       "    capm           (time, name) float64 55.73 338.2 71.69 ... 239.2 311.4 187.1\n",
-       "    ntp            int64 10\n",
-       "    npl            int64 0\n",
-       "    nplm           int64 0
" - ], - "text/plain": [ - "\n", - "Dimensions: (name: 10, time: 1)\n", - "Coordinates:\n", - " * name (name) 2\u001b[0m \u001b[43msim\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mrun\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n", - "File \u001b[0;32m~/git_debug/swiftest/python/swiftest/swiftest/simulation_class.py:474\u001b[0m, in \u001b[0;36mSimulation.run\u001b[0;34m(self, **kwargs)\u001b[0m\n\u001b[1;32m 471\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_run_swiftest_driver()\n\u001b[1;32m 473\u001b[0m \u001b[38;5;66;03m# Read in new data\u001b[39;00m\n\u001b[0;32m--> 474\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mbin2xr\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 476\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m\n", - "File \u001b[0;32m~/git_debug/swiftest/python/swiftest/swiftest/simulation_class.py:2743\u001b[0m, in \u001b[0;36mSimulation.bin2xr\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 2741\u001b[0m param_tmp[\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mBIN_OUT\u001b[39m\u001b[38;5;124m'\u001b[39m] \u001b[38;5;241m=\u001b[39m os\u001b[38;5;241m.\u001b[39mpath\u001b[38;5;241m.\u001b[39mjoin(\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39msim_dir, \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mparam[\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mBIN_OUT\u001b[39m\u001b[38;5;124m'\u001b[39m])\n\u001b[1;32m 2742\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mcodename \u001b[38;5;241m==\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mSwiftest\u001b[39m\u001b[38;5;124m\"\u001b[39m:\n\u001b[0;32m-> 2743\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mdata \u001b[38;5;241m=\u001b[39m \u001b[43mio\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mswiftest2xr\u001b[49m\u001b[43m(\u001b[49m\u001b[43mparam_tmp\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mverbose\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mverbose\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 2744\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mverbose: \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mSwiftest simulation data stored as xarray DataSet .data\u001b[39m\u001b[38;5;124m'\u001b[39m)\n\u001b[1;32m 2745\u001b[0m \u001b[38;5;28;01melif\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mcodename \u001b[38;5;241m==\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mSwifter\u001b[39m\u001b[38;5;124m\"\u001b[39m:\n", - "File \u001b[0;32m~/git_debug/swiftest/python/swiftest/swiftest/io.py:854\u001b[0m, in \u001b[0;36mswiftest2xr\u001b[0;34m(param, verbose)\u001b[0m\n\u001b[1;32m 852\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m ((param[\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mOUT_TYPE\u001b[39m\u001b[38;5;124m'\u001b[39m] \u001b[38;5;241m==\u001b[39m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mNETCDF_DOUBLE\u001b[39m\u001b[38;5;124m'\u001b[39m) \u001b[38;5;129;01mor\u001b[39;00m (param[\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mOUT_TYPE\u001b[39m\u001b[38;5;124m'\u001b[39m] \u001b[38;5;241m==\u001b[39m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mNETCDF_FLOAT\u001b[39m\u001b[38;5;124m'\u001b[39m)):\n\u001b[1;32m 853\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m verbose: \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;124m'\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124mCreating Dataset from NetCDF file\u001b[39m\u001b[38;5;124m'\u001b[39m)\n\u001b[0;32m--> 854\u001b[0m ds \u001b[38;5;241m=\u001b[39m \u001b[43mxr\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mopen_dataset\u001b[49m\u001b[43m(\u001b[49m\u001b[43mparam\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mBIN_OUT\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mmask_and_scale\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43;01mFalse\u001b[39;49;00m\u001b[43m)\u001b[49m\n\u001b[1;32m 855\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m param[\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mOUT_TYPE\u001b[39m\u001b[38;5;124m'\u001b[39m] \u001b[38;5;241m==\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mNETCDF_DOUBLE\u001b[39m\u001b[38;5;124m\"\u001b[39m:\n\u001b[1;32m 856\u001b[0m ds \u001b[38;5;241m=\u001b[39m fix_types(ds,ftype\u001b[38;5;241m=\u001b[39mnp\u001b[38;5;241m.\u001b[39mfloat64)\n", - "File \u001b[0;32m~/.conda/envs/cent7/2020.11-py38/debug_env/lib/python3.8/site-packages/xarray/backends/api.py:495\u001b[0m, in \u001b[0;36mopen_dataset\u001b[0;34m(filename_or_obj, engine, chunks, cache, decode_cf, mask_and_scale, decode_times, decode_timedelta, use_cftime, concat_characters, decode_coords, drop_variables, backend_kwargs, *args, **kwargs)\u001b[0m\n\u001b[1;32m 483\u001b[0m decoders \u001b[38;5;241m=\u001b[39m _resolve_decoders_kwargs(\n\u001b[1;32m 484\u001b[0m decode_cf,\n\u001b[1;32m 485\u001b[0m open_backend_dataset_parameters\u001b[38;5;241m=\u001b[39mbackend\u001b[38;5;241m.\u001b[39mopen_dataset_parameters,\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 491\u001b[0m decode_coords\u001b[38;5;241m=\u001b[39mdecode_coords,\n\u001b[1;32m 492\u001b[0m )\n\u001b[1;32m 494\u001b[0m overwrite_encoded_chunks \u001b[38;5;241m=\u001b[39m kwargs\u001b[38;5;241m.\u001b[39mpop(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124moverwrite_encoded_chunks\u001b[39m\u001b[38;5;124m\"\u001b[39m, \u001b[38;5;28;01mNone\u001b[39;00m)\n\u001b[0;32m--> 495\u001b[0m backend_ds \u001b[38;5;241m=\u001b[39m \u001b[43mbackend\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mopen_dataset\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m 496\u001b[0m \u001b[43m \u001b[49m\u001b[43mfilename_or_obj\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 497\u001b[0m \u001b[43m \u001b[49m\u001b[43mdrop_variables\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mdrop_variables\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 498\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mdecoders\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 499\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 500\u001b[0m \u001b[43m\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 501\u001b[0m ds \u001b[38;5;241m=\u001b[39m _dataset_from_backend_dataset(\n\u001b[1;32m 502\u001b[0m backend_ds,\n\u001b[1;32m 503\u001b[0m filename_or_obj,\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 510\u001b[0m \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs,\n\u001b[1;32m 511\u001b[0m )\n\u001b[1;32m 512\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m ds\n", - "File \u001b[0;32m~/.conda/envs/cent7/2020.11-py38/debug_env/lib/python3.8/site-packages/xarray/backends/h5netcdf_.py:386\u001b[0m, in \u001b[0;36mH5netcdfBackendEntrypoint.open_dataset\u001b[0;34m(self, filename_or_obj, mask_and_scale, decode_times, concat_characters, decode_coords, drop_variables, use_cftime, decode_timedelta, format, group, lock, invalid_netcdf, phony_dims, decode_vlen_strings)\u001b[0m\n\u001b[1;32m 374\u001b[0m store \u001b[38;5;241m=\u001b[39m H5NetCDFStore\u001b[38;5;241m.\u001b[39mopen(\n\u001b[1;32m 375\u001b[0m filename_or_obj,\n\u001b[1;32m 376\u001b[0m \u001b[38;5;28mformat\u001b[39m\u001b[38;5;241m=\u001b[39m\u001b[38;5;28mformat\u001b[39m,\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 381\u001b[0m decode_vlen_strings\u001b[38;5;241m=\u001b[39mdecode_vlen_strings,\n\u001b[1;32m 382\u001b[0m )\n\u001b[1;32m 384\u001b[0m store_entrypoint \u001b[38;5;241m=\u001b[39m StoreBackendEntrypoint()\n\u001b[0;32m--> 386\u001b[0m ds \u001b[38;5;241m=\u001b[39m \u001b[43mstore_entrypoint\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mopen_dataset\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m 387\u001b[0m \u001b[43m \u001b[49m\u001b[43mstore\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 388\u001b[0m \u001b[43m \u001b[49m\u001b[43mmask_and_scale\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mmask_and_scale\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 389\u001b[0m \u001b[43m \u001b[49m\u001b[43mdecode_times\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mdecode_times\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 390\u001b[0m \u001b[43m \u001b[49m\u001b[43mconcat_characters\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mconcat_characters\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 391\u001b[0m \u001b[43m \u001b[49m\u001b[43mdecode_coords\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mdecode_coords\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 392\u001b[0m \u001b[43m \u001b[49m\u001b[43mdrop_variables\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mdrop_variables\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 393\u001b[0m \u001b[43m \u001b[49m\u001b[43muse_cftime\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43muse_cftime\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 394\u001b[0m \u001b[43m \u001b[49m\u001b[43mdecode_timedelta\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mdecode_timedelta\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 395\u001b[0m \u001b[43m\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 396\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m ds\n", - "File \u001b[0;32m~/.conda/envs/cent7/2020.11-py38/debug_env/lib/python3.8/site-packages/xarray/backends/store.py:24\u001b[0m, in \u001b[0;36mStoreBackendEntrypoint.open_dataset\u001b[0;34m(self, store, mask_and_scale, decode_times, concat_characters, decode_coords, drop_variables, use_cftime, decode_timedelta)\u001b[0m\n\u001b[1;32m 12\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mopen_dataset\u001b[39m(\n\u001b[1;32m 13\u001b[0m \u001b[38;5;28mself\u001b[39m,\n\u001b[1;32m 14\u001b[0m store,\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 22\u001b[0m decode_timedelta\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mNone\u001b[39;00m,\n\u001b[1;32m 23\u001b[0m ):\n\u001b[0;32m---> 24\u001b[0m \u001b[38;5;28mvars\u001b[39m, attrs \u001b[38;5;241m=\u001b[39m \u001b[43mstore\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mload\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 25\u001b[0m encoding \u001b[38;5;241m=\u001b[39m store\u001b[38;5;241m.\u001b[39mget_encoding()\n\u001b[1;32m 27\u001b[0m \u001b[38;5;28mvars\u001b[39m, attrs, coord_names \u001b[38;5;241m=\u001b[39m conventions\u001b[38;5;241m.\u001b[39mdecode_cf_variables(\n\u001b[1;32m 28\u001b[0m \u001b[38;5;28mvars\u001b[39m,\n\u001b[1;32m 29\u001b[0m attrs,\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 36\u001b[0m decode_timedelta\u001b[38;5;241m=\u001b[39mdecode_timedelta,\n\u001b[1;32m 37\u001b[0m )\n", - "File \u001b[0;32m~/.conda/envs/cent7/2020.11-py38/debug_env/lib/python3.8/site-packages/xarray/backends/common.py:123\u001b[0m, in \u001b[0;36mAbstractDataStore.load\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 101\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mload\u001b[39m(\u001b[38;5;28mself\u001b[39m):\n\u001b[1;32m 102\u001b[0m \u001b[38;5;124;03m\"\"\"\u001b[39;00m\n\u001b[1;32m 103\u001b[0m \u001b[38;5;124;03m This loads the variables and attributes simultaneously.\u001b[39;00m\n\u001b[1;32m 104\u001b[0m \u001b[38;5;124;03m A centralized loading function makes it easier to create\u001b[39;00m\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 120\u001b[0m \u001b[38;5;124;03m are requested, so care should be taken to make sure its fast.\u001b[39;00m\n\u001b[1;32m 121\u001b[0m \u001b[38;5;124;03m \"\"\"\u001b[39;00m\n\u001b[1;32m 122\u001b[0m variables \u001b[38;5;241m=\u001b[39m FrozenDict(\n\u001b[0;32m--> 123\u001b[0m (_decode_variable_name(k), v) \u001b[38;5;28;01mfor\u001b[39;00m k, v \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mget_variables\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\u001b[38;5;241m.\u001b[39mitems()\n\u001b[1;32m 124\u001b[0m )\n\u001b[1;32m 125\u001b[0m attributes \u001b[38;5;241m=\u001b[39m FrozenDict(\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mget_attrs())\n\u001b[1;32m 126\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m variables, attributes\n", - "File \u001b[0;32m~/.conda/envs/cent7/2020.11-py38/debug_env/lib/python3.8/site-packages/xarray/backends/h5netcdf_.py:229\u001b[0m, in \u001b[0;36mH5NetCDFStore.get_variables\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 228\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mget_variables\u001b[39m(\u001b[38;5;28mself\u001b[39m):\n\u001b[0;32m--> 229\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mFrozenDict\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m 230\u001b[0m \u001b[43m \u001b[49m\u001b[43m(\u001b[49m\u001b[43mk\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mopen_store_variable\u001b[49m\u001b[43m(\u001b[49m\u001b[43mk\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mv\u001b[49m\u001b[43m)\u001b[49m\u001b[43m)\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43;01mfor\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[43mk\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mv\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;129;43;01min\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mds\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mvariables\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mitems\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 231\u001b[0m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m\n", - "File \u001b[0;32m~/.conda/envs/cent7/2020.11-py38/debug_env/lib/python3.8/site-packages/xarray/core/utils.py:476\u001b[0m, in \u001b[0;36mFrozenDict\u001b[0;34m(*args, **kwargs)\u001b[0m\n\u001b[1;32m 475\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mFrozenDict\u001b[39m(\u001b[38;5;241m*\u001b[39margs, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m Frozen:\n\u001b[0;32m--> 476\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m Frozen(\u001b[38;5;28;43mdict\u001b[39;49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43margs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m)\n", - "File \u001b[0;32m~/.conda/envs/cent7/2020.11-py38/debug_env/lib/python3.8/site-packages/xarray/backends/h5netcdf_.py:230\u001b[0m, in \u001b[0;36m\u001b[0;34m(.0)\u001b[0m\n\u001b[1;32m 228\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mget_variables\u001b[39m(\u001b[38;5;28mself\u001b[39m):\n\u001b[1;32m 229\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m FrozenDict(\n\u001b[0;32m--> 230\u001b[0m (k, \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mopen_store_variable\u001b[49m\u001b[43m(\u001b[49m\u001b[43mk\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mv\u001b[49m\u001b[43m)\u001b[49m) \u001b[38;5;28;01mfor\u001b[39;00m k, v \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mds\u001b[38;5;241m.\u001b[39mvariables\u001b[38;5;241m.\u001b[39mitems()\n\u001b[1;32m 231\u001b[0m )\n", - "File \u001b[0;32m~/.conda/envs/cent7/2020.11-py38/debug_env/lib/python3.8/site-packages/xarray/backends/h5netcdf_.py:195\u001b[0m, in \u001b[0;36mH5NetCDFStore.open_store_variable\u001b[0;34m(self, name, var)\u001b[0m\n\u001b[1;32m 192\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;21;01mh5py\u001b[39;00m\n\u001b[1;32m 194\u001b[0m dimensions \u001b[38;5;241m=\u001b[39m var\u001b[38;5;241m.\u001b[39mdimensions\n\u001b[0;32m--> 195\u001b[0m data \u001b[38;5;241m=\u001b[39m indexing\u001b[38;5;241m.\u001b[39mLazilyIndexedArray(\u001b[43mH5NetCDFArrayWrapper\u001b[49m\u001b[43m(\u001b[49m\u001b[43mname\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[43m)\u001b[49m)\n\u001b[1;32m 196\u001b[0m attrs \u001b[38;5;241m=\u001b[39m _read_attributes(var)\n\u001b[1;32m 198\u001b[0m \u001b[38;5;66;03m# netCDF4 specific encoding\u001b[39;00m\n", - "File \u001b[0;32m~/.conda/envs/cent7/2020.11-py38/debug_env/lib/python3.8/site-packages/xarray/backends/netCDF4_.py:56\u001b[0m, in \u001b[0;36mBaseNetCDF4Array.__init__\u001b[0;34m(self, variable_name, datastore)\u001b[0m\n\u001b[1;32m 53\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mvariable_name \u001b[38;5;241m=\u001b[39m variable_name\n\u001b[1;32m 55\u001b[0m array \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mget_array()\n\u001b[0;32m---> 56\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mshape \u001b[38;5;241m=\u001b[39m \u001b[43marray\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mshape\u001b[49m\n\u001b[1;32m 58\u001b[0m dtype \u001b[38;5;241m=\u001b[39m array\u001b[38;5;241m.\u001b[39mdtype\n\u001b[1;32m 59\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m dtype \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;28mstr\u001b[39m:\n\u001b[1;32m 60\u001b[0m \u001b[38;5;66;03m# use object dtype because that's the only way in numpy to\u001b[39;00m\n\u001b[1;32m 61\u001b[0m \u001b[38;5;66;03m# represent variable length strings; it also prevents automatic\u001b[39;00m\n\u001b[1;32m 62\u001b[0m \u001b[38;5;66;03m# string concatenation via conventions.decode_cf_variable\u001b[39;00m\n", - "File \u001b[0;32m~/.conda/envs/cent7/2020.11-py38/debug_env/lib/python3.8/site-packages/h5netcdf/core.py:259\u001b[0m, in \u001b[0;36mBaseVariable.shape\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 257\u001b[0m \u001b[38;5;124;03m\"\"\"Return current sizes of all variable dimensions.\"\"\"\u001b[39;00m\n\u001b[1;32m 258\u001b[0m \u001b[38;5;66;03m# return actual dimensions sizes, this is in line with netcdf4-python\u001b[39;00m\n\u001b[0;32m--> 259\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mtuple\u001b[39m([\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_parent\u001b[38;5;241m.\u001b[39m_all_dimensions[d]\u001b[38;5;241m.\u001b[39msize \u001b[38;5;28;01mfor\u001b[39;00m d \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mdimensions])\n", - "File \u001b[0;32m~/.conda/envs/cent7/2020.11-py38/debug_env/lib/python3.8/site-packages/h5netcdf/core.py:259\u001b[0m, in \u001b[0;36m\u001b[0;34m(.0)\u001b[0m\n\u001b[1;32m 257\u001b[0m \u001b[38;5;124;03m\"\"\"Return current sizes of all variable dimensions.\"\"\"\u001b[39;00m\n\u001b[1;32m 258\u001b[0m \u001b[38;5;66;03m# return actual dimensions sizes, this is in line with netcdf4-python\u001b[39;00m\n\u001b[0;32m--> 259\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mtuple\u001b[39m([\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_parent\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_all_dimensions\u001b[49m\u001b[43m[\u001b[49m\u001b[43md\u001b[49m\u001b[43m]\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43msize\u001b[49m \u001b[38;5;28;01mfor\u001b[39;00m d \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mdimensions])\n", - "File \u001b[0;32m~/.conda/envs/cent7/2020.11-py38/debug_env/lib/python3.8/site-packages/h5netcdf/dimensions.py:115\u001b[0m, in \u001b[0;36mDimension.size\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 113\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m reflist \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[1;32m 114\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m ref, axis \u001b[38;5;129;01min\u001b[39;00m reflist:\n\u001b[0;32m--> 115\u001b[0m var \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_parent\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_h5group\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43m/\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m[\u001b[49m\u001b[43mref\u001b[49m\u001b[43m]\u001b[49m\n\u001b[1;32m 116\u001b[0m size \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mmax\u001b[39m(var\u001b[38;5;241m.\u001b[39mshape[axis], size)\n\u001b[1;32m 117\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m size\n", - "File \u001b[0;32mh5py/_objects.pyx:54\u001b[0m, in \u001b[0;36mh5py._objects.with_phil.wrapper\u001b[0;34m()\u001b[0m\n", - "File \u001b[0;32mh5py/_objects.pyx:55\u001b[0m, in \u001b[0;36mh5py._objects.with_phil.wrapper\u001b[0;34m()\u001b[0m\n", - "File \u001b[0;32m~/.conda/envs/cent7/2020.11-py38/debug_env/lib/python3.8/site-packages/h5py/_hl/group.py:337\u001b[0m, in \u001b[0;36mGroup.__getitem__\u001b[0;34m(self, name)\u001b[0m\n\u001b[1;32m 335\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m Group(oid)\n\u001b[1;32m 336\u001b[0m \u001b[38;5;28;01melif\u001b[39;00m otype \u001b[38;5;241m==\u001b[39m h5i\u001b[38;5;241m.\u001b[39mDATASET:\n\u001b[0;32m--> 337\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mdataset\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mDataset\u001b[49m\u001b[43m(\u001b[49m\u001b[43moid\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mreadonly\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43m(\u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mfile\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mmode\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m==\u001b[39;49m\u001b[43m \u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mr\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m)\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 338\u001b[0m \u001b[38;5;28;01melif\u001b[39;00m otype \u001b[38;5;241m==\u001b[39m h5i\u001b[38;5;241m.\u001b[39mDATATYPE:\n\u001b[1;32m 339\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m datatype\u001b[38;5;241m.\u001b[39mDatatype(oid)\n", - "File \u001b[0;32mh5py/_objects.pyx:54\u001b[0m, in \u001b[0;36mh5py._objects.with_phil.wrapper\u001b[0;34m()\u001b[0m\n", - "File \u001b[0;32mh5py/_objects.pyx:55\u001b[0m, in \u001b[0;36mh5py._objects.with_phil.wrapper\u001b[0;34m()\u001b[0m\n", - "File \u001b[0;32m~/.conda/envs/cent7/2020.11-py38/debug_env/lib/python3.8/site-packages/h5py/_hl/dataset.py:622\u001b[0m, in \u001b[0;36mDataset.__init__\u001b[0;34m(self, bind, readonly)\u001b[0m\n\u001b[1;32m 619\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mValueError\u001b[39;00m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;132;01m%s\u001b[39;00m\u001b[38;5;124m is not a DatasetID\u001b[39m\u001b[38;5;124m\"\u001b[39m \u001b[38;5;241m%\u001b[39m bind)\n\u001b[1;32m 620\u001b[0m \u001b[38;5;28msuper\u001b[39m()\u001b[38;5;241m.\u001b[39m\u001b[38;5;21m__init__\u001b[39m(bind)\n\u001b[0;32m--> 622\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_dcpl \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mid\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mget_create_plist\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 623\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_dxpl \u001b[38;5;241m=\u001b[39m h5p\u001b[38;5;241m.\u001b[39mcreate(h5p\u001b[38;5;241m.\u001b[39mDATASET_XFER)\n\u001b[1;32m 624\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_filters \u001b[38;5;241m=\u001b[39m filters\u001b[38;5;241m.\u001b[39mget_filters(\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_dcpl)\n", - "\u001b[0;31mKeyboardInterrupt\u001b[0m: " - ] - } - ], + "outputs": [], "source": [ "# Run the simulation\n", - "sim.run()" + "sim.run(tstart=0.0, tstop=1.0e3, dt=0.01, tstep_out=1.0e0, dump_cadence=0)" ] }, { diff --git a/examples/Basic_Simulation/initial_conditions.py b/examples/Basic_Simulation/initial_conditions.py index 824cccfb9..7e0218a03 100644 --- a/examples/Basic_Simulation/initial_conditions.py +++ b/examples/Basic_Simulation/initial_conditions.py @@ -63,4 +63,4 @@ sim.get_parameter() # Run the simulation -sim.run(tstart=0.0, tstop=1.0e2, dt=0.01, tstep_out=1.0e0, dump_cadence=0, ) +sim.run(tstart=0.0, tstop=1.0e3, dt=0.01, tstep_out=1.0e0, dump_cadence=0) From a1b6ca6b9e9aa10901bdcf0a12464e1be3e42b1e Mon Sep 17 00:00:00 2001 From: David A Minton Date: Sun, 4 Dec 2022 10:59:05 -0500 Subject: [PATCH 50/65] Removed the encounter list stuff that I won't actually use --- src/symba/symba_encounter_check.f90 | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/src/symba/symba_encounter_check.f90 b/src/symba/symba_encounter_check.f90 index b955d4998..e58da2129 100644 --- a/src/symba/symba_encounter_check.f90 +++ b/src/symba/symba_encounter_check.f90 @@ -69,15 +69,6 @@ module function symba_encounter_check_pl(self, param, system, dt, irec) result(l plplenc_list%x2(:,k) = pl%rh(:,j) plplenc_list%v1(:,k) = pl%vb(:,i) - cb%vb(:) plplenc_list%v2(:,k) = pl%vb(:,j) - cb%vb(:) - plplenc_list%Gmass1(k) = pl%Gmass(i) - plplenc_list%Gmass2(k) = pl%Gmass(j) - if (param%lclose) then - plplenc_list%radius1(k) = pl%radius(i) - plplenc_list%radius2(k) = pl%radius(j) - end if - plplenc_list%name1(k) = pl%info(i)%name - plplenc_list%name2(k) = pl%info(j)%name - pl%lencounter(i) = .true. pl%lencounter(j) = .true. pl%levelg(i) = irec @@ -87,9 +78,6 @@ module function symba_encounter_check_pl(self, param, system, dt, irec) result(l pl%nplenc(i) = pl%nplenc(i) + 1 pl%nplenc(j) = pl%nplenc(j) + 1 end do - ienc_frame = ienc_frame + 1 - call system%resize_storage(ienc_frame) - system%encounter_history%frame(ienc_frame) = plplenc_list end if end associate From 5a0e0e797329438fc2681abe2c5616b02dc309cc Mon Sep 17 00:00:00 2001 From: David A Minton Date: Sun, 4 Dec 2022 11:00:54 -0500 Subject: [PATCH 51/65] Added missing self --- python/swiftest/swiftest/simulation_class.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python/swiftest/swiftest/simulation_class.py b/python/swiftest/swiftest/simulation_class.py index 167d86e3b..5b9aef212 100644 --- a/python/swiftest/swiftest/simulation_class.py +++ b/python/swiftest/swiftest/simulation_class.py @@ -312,7 +312,7 @@ def __init__(self,read_param: bool = False, read_old_output_file: bool = False, # then using the arguments passed via **kwargs. #-------------------------- - # Lowest Priority: Defaults + # Lowest Priority: Defaults: #-------------------------- # Quietly set all parameters to their defaults. self.set_parameter(verbose=False,param_file=param_file) @@ -2670,7 +2670,7 @@ def read_output_file(self,read_init_cond : bool = True): self.data = io.swiftest2xr(param_tmp, verbose=self.verbose) if self.verbose: print('Swiftest simulation data stored as xarray DataSet .data') if read_init_cond: - if "NETCDF" in param['IN_TYPE']: + if "NETCDF" in self.param['IN_TYPE']: param_tmp['BIN_OUT'] = os.path.join(self.sim_dir, self.param['NC_IN']) self.ic = io.swiftest2xr(param_tmp, verbose=self.verbose) else: From 0d71424a445c838de54741fa094c3aed464ac667 Mon Sep 17 00:00:00 2001 From: David A Minton Date: Sun, 4 Dec 2022 11:03:02 -0500 Subject: [PATCH 52/65] Minor fixes to initial conditions generator --- .../Basic_Simulation/initial_conditions.ipynb | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/examples/Basic_Simulation/initial_conditions.ipynb b/examples/Basic_Simulation/initial_conditions.ipynb index f6a872061..60581d22a 100644 --- a/examples/Basic_Simulation/initial_conditions.ipynb +++ b/examples/Basic_Simulation/initial_conditions.ipynb @@ -123,7 +123,7 @@ "outputs": [], "source": [ "# Display the run configuration parameters\n", - "sim.get_parameter()" + "p = sim.get_parameter()" ] }, { @@ -143,6 +143,26 @@ "id": "02a8911d-3b2c-415c-9290-bf1519a3f5c6", "metadata": {}, "outputs": [], + "source": [ + "sim.ic" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "5f8d1ac3-5ad0-4b8a-ad9d-1b63486920aa", + "metadata": {}, + "outputs": [], + "source": [ + "sim.data" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "fb93805d-377b-47d6-a565-c26acd2a7cbc", + "metadata": {}, + "outputs": [], "source": [] } ], From 9f0294f87eb23c86dea21243b63de78dadf5d25e Mon Sep 17 00:00:00 2001 From: David A Minton Date: Sun, 4 Dec 2022 11:04:26 -0500 Subject: [PATCH 53/65] Changed argument from xh to rh --- examples/Fragmentation/Fragmentation_Movie.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/Fragmentation/Fragmentation_Movie.py b/examples/Fragmentation/Fragmentation_Movie.py index 4759594d5..24fc40e30 100644 --- a/examples/Fragmentation/Fragmentation_Movie.py +++ b/examples/Fragmentation/Fragmentation_Movie.py @@ -188,13 +188,13 @@ def data_stream(self, frame=0): if run_new: sim = swiftest.Simulation(param_file=param_file, rotation=True, init_cond_format = "XV", compute_conservation_values=True) sim.add_solar_system_body("Sun") - sim.add_body(Gmass=body_Gmass[style], radius=body_radius[style], xh=pos_vectors[style], vh=vel_vectors[style], rot=rot_vectors[style]) + sim.add_body(Gmass=body_Gmass[style], radius=body_radius[style], rh=pos_vectors[style], vh=vel_vectors[style], rot=rot_vectors[style]) # Set fragmentation parameters minimum_fragment_gmass = 0.2 * body_Gmass[style][1] # Make the minimum fragment mass a fraction of the smallest body gmtiny = 0.99 * body_Gmass[style][1] # Make GMTINY just smaller than the smallest original body. This will prevent runaway collisional cascades sim.set_parameter(fragmentation = True, gmtiny=gmtiny, minimum_fragment_gmass=minimum_fragment_gmass, verbose=False) - sim.run(dt=1e-8, tstop=2.e-5) + sim.run(dt=2e-5, tstop=2.e-5) else: sim = swiftest.Simulation(param_file=param_file, read_old_output_file=True) From c509479c2bbb84707903b225b8d15330429ec8b9 Mon Sep 17 00:00:00 2001 From: David A Minton Date: Sun, 4 Dec 2022 11:13:59 -0500 Subject: [PATCH 54/65] Added new simdir argument to make it easier to create individual simulations in specific directories without having to change the name of every file --- python/swiftest/swiftest/simulation_class.py | 28 +++++++++++--------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/python/swiftest/swiftest/simulation_class.py b/python/swiftest/swiftest/simulation_class.py index 5b9aef212..f4c99f5d8 100644 --- a/python/swiftest/swiftest/simulation_class.py +++ b/python/swiftest/swiftest/simulation_class.py @@ -41,7 +41,7 @@ class Simulation: This is a class that defines the basic Swift/Swifter/Swiftest simulation object """ - def __init__(self,read_param: bool = False, read_old_output_file: bool = False, **kwargs: Any): + def __init__(self,read_param: bool = False, read_old_output_file: bool = False, simdir: os.PathLike | str = "simdata",**kwargs: Any): """ Parameters @@ -66,6 +66,9 @@ def __init__(self,read_param: bool = False, read_old_output_file: bool = False, read_old_output_file : bool, default False If true, read in a pre-existing binary input file given by the argument `output_file_name` if it exists. Parameter input file equivalent: None + simdir : PathLike, default `"simdir"` + Directory where simulation data will be stored, including the parameter file, initial conditions file, output file, + dump files, and log files. **kwargs : See list of valid parameters and their defaults below @@ -308,6 +311,8 @@ def __init__(self,read_param: bool = False, read_old_output_file: bool = False, param_file = kwargs.pop("param_file",Path.cwd() / "simdata" / "param.in") self.verbose = kwargs.pop("verbose",True) + self.simdir = simdir + # Parameters are set in reverse priority order. First the defaults, then values from a pre-existing input file, # then using the arguments passed via **kwargs. @@ -346,7 +351,7 @@ def __init__(self,read_param: bool = False, read_old_output_file: bool = False, # Read in an old simulation file if requested if read_old_output_file: - binpath = os.path.join(self.sim_dir, self.param['BIN_OUT']) + binpath = os.path.join(self.simdir, self.param['BIN_OUT']) if os.path.exists(binpath): self.read_output_file() else: @@ -365,7 +370,7 @@ def _run_swiftest_driver(self): with open(driver_script, 'w') as f: f.write(f"#{self._shell_full} -l\n") f.write(f"source ~/.{self._shell}rc\n") - f.write(f"cd {self.sim_dir}\n") + f.write(f"cd {self.simdir}\n") f.write(f"{str(self.driver_executable)} {self.integrator} {str(self.param_file)} compact\n") cmd = f"{env['SHELL']} -l {driver_script}" @@ -767,14 +772,13 @@ def set_parameter(self, verbose: bool = True, **kwargs): # Extract the simulation directory and create it if it doesn't exist if param_file is not None: self.param_file = Path.cwd() / param_file - self.sim_dir = self.param_file.parent - if self.sim_dir.exists(): - if not self.sim_dir.is_dir(): - msg = f"Cannot create the {self.sim_dir} directory: File exists." + if self.simdir.exists(): + if not self.simdir.is_dir(): + msg = f"Cannot create the {self.simdir} directory: File exists." msg += "\nDelete the file or change the location of param_file" warnings.warn(msg,stacklevel=2) else: - self.sim_dir.mkdir(parents=True, exist_ok=False) + self.simdir.mkdir(parents=True, exist_ok=False) # If no arguments (other than, possibly, verbose) are requested, use defaults if len(kwargs) == 0: @@ -2517,7 +2521,7 @@ def read_param(self, self.param = io.read_swiftest_param(param_file, self.param, verbose=verbose) if read_init_cond: if "NETCDF" in self.param['IN_TYPE']: - init_cond_file = self.sim_dir / self.param['NC_IN'] + init_cond_file = self.simdir / self.param['NC_IN'] if os.path.exists(init_cond_file): param_tmp = self.param.copy() param_tmp['BIN_OUT'] = init_cond_file @@ -2665,13 +2669,13 @@ def read_output_file(self,read_init_cond : bool = True): # This is done to handle cases where the method is called from a different working directory than the simulation # results param_tmp = self.param.copy() - param_tmp['BIN_OUT'] = os.path.join(self.sim_dir, self.param['BIN_OUT']) + param_tmp['BIN_OUT'] = os.path.join(self.simdir, self.param['BIN_OUT']) if self.codename == "Swiftest": self.data = io.swiftest2xr(param_tmp, verbose=self.verbose) if self.verbose: print('Swiftest simulation data stored as xarray DataSet .data') if read_init_cond: if "NETCDF" in self.param['IN_TYPE']: - param_tmp['BIN_OUT'] = os.path.join(self.sim_dir, self.param['NC_IN']) + param_tmp['BIN_OUT'] = os.path.join(self.simdir, self.param['NC_IN']) self.ic = io.swiftest2xr(param_tmp, verbose=self.verbose) else: self.ic = self.data.isel(time=0) @@ -2764,7 +2768,7 @@ def save(self, param = self.param if codename == "Swiftest": - infile_name = Path(self.sim_dir) / param['NC_IN'] + infile_name = Path(self.simdir) / param['NC_IN'] io.swiftest_xr2infile(ds=self.data, param=param, in_type=self.param['IN_TYPE'], infile_name=infile_name, framenum=framenum, verbose=verbose) self.write_param(param_file=param_file,**kwargs) elif codename == "Swifter": From 0d00f4b722a1fb59c59385799d923a09ba0b84d5 Mon Sep 17 00:00:00 2001 From: David A Minton Date: Sun, 4 Dec 2022 11:24:56 -0500 Subject: [PATCH 55/65] Fixed bug that prevented parameter file from being saved in new simdir directory --- .../whm_gr_test/swiftest_relativity.ipynb | 893 +----------------- python/swiftest/swiftest/simulation_class.py | 24 +- 2 files changed, 23 insertions(+), 894 deletions(-) diff --git a/examples/whm_gr_test/swiftest_relativity.ipynb b/examples/whm_gr_test/swiftest_relativity.ipynb index 0e5f26360..4d44ca569 100644 --- a/examples/whm_gr_test/swiftest_relativity.ipynb +++ b/examples/whm_gr_test/swiftest_relativity.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": 1, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -10,906 +10,33 @@ "from astroquery.jplhorizons import Horizons\n", "import datetime\n", "import numpy as np\n", - "import matplotlib.pyplot as plt" + "import matplotlib.pyplot as plt\n", + "import os" ] }, { "cell_type": "code", - "execution_count": 2, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Creating the Sun as a central body\n", - "Fetching ephemerides data for Mercury from JPL/Horizons\n", - "Fetching ephemerides data for Venus from JPL/Horizons\n", - "Fetching ephemerides data for Earth from JPL/Horizons\n", - "Fetching ephemerides data for Mars from JPL/Horizons\n", - "Fetching ephemerides data for Jupiter from JPL/Horizons\n", - "Fetching ephemerides data for Saturn from JPL/Horizons\n", - "Fetching ephemerides data for Uranus from JPL/Horizons\n", - "Fetching ephemerides data for Neptune from JPL/Horizons\n" - ] - }, - { - "data": { - "text/html": [ - "
\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "
<xarray.Dataset>\n",
-       "Dimensions:        (name: 9, time: 1)\n",
-       "Coordinates:\n",
-       "  * name           (name) <U32 'Sun' 'Mercury' 'Venus' ... 'Uranus' 'Neptune'\n",
-       "  * time           (time) float64 0.0\n",
-       "Data variables: (12/15)\n",
-       "    particle_type  (name) <U32 'Central Body' 'Massive Body' ... 'Massive Body'\n",
-       "    id             (name) int64 0 1 2 3 4 5 6 7 8\n",
-       "    a              (time, name) float64 nan 0.3871 0.7233 ... 9.532 19.24 30.04\n",
-       "    e              (time, name) float64 nan 0.2056 0.006718 ... 0.04796 0.008956\n",
-       "    inc            (time, name) float64 nan 7.003 3.394 ... 2.488 0.773 1.771\n",
-       "    capom          (time, name) float64 nan 48.3 76.6 ... 113.6 74.01 131.8\n",
-       "    ...             ...\n",
-       "    radius         (time, name) float64 0.00465 1.631e-05 ... 0.0001646\n",
-       "    j2rp2          (time, name) float64 4.754e-12 nan nan nan ... nan nan nan\n",
-       "    j4rp4          (time, name) float64 -2.247e-18 nan nan nan ... nan nan nan\n",
-       "    ntp            (time) int64 0\n",
-       "    npl            (time) int64 8\n",
-       "    nplm           (time) int64 8
" - ], - "text/plain": [ - "\n", - "Dimensions: (name: 9, time: 1)\n", - "Coordinates:\n", - " * name (name) \n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "
<xarray.Dataset>\n",
-       "Dimensions:        (name: 9, time: 1)\n",
-       "Coordinates:\n",
-       "  * name           (name) <U32 'Sun' 'Mercury' 'Venus' ... 'Uranus' 'Neptune'\n",
-       "  * time           (time) float64 0.0\n",
-       "Data variables: (12/15)\n",
-       "    particle_type  (name) <U32 'Central Body' 'Massive Body' ... 'Massive Body'\n",
-       "    id             (name) int64 0 1 2 3 4 5 6 7 8\n",
-       "    a              (time, name) float64 nan 0.3871 0.7233 ... 9.532 19.24 30.04\n",
-       "    e              (time, name) float64 nan 0.2056 0.006718 ... 0.04796 0.008956\n",
-       "    inc            (time, name) float64 nan 7.003 3.394 ... 2.488 0.773 1.771\n",
-       "    capom          (time, name) float64 nan 48.3 76.6 ... 113.6 74.01 131.8\n",
-       "    ...             ...\n",
-       "    radius         (time, name) float64 0.00465 1.631e-05 ... 0.0001646\n",
-       "    j2rp2          (time, name) float64 4.754e-12 nan nan nan ... nan nan nan\n",
-       "    j4rp4          (time, name) float64 -2.247e-18 nan nan nan ... nan nan nan\n",
-       "    ntp            (time) int64 0\n",
-       "    npl            (time) int64 8\n",
-       "    nplm           (time) int64 8
" - ], - "text/plain": [ - "\n", - "Dimensions: (name: 9, time: 1)\n", - "Coordinates:\n", - " * name (name) Date: Sun, 4 Dec 2022 11:25:56 -0500 Subject: [PATCH 56/65] Updated whm_gr_test notebook --- examples/whm_gr_test/swiftest_relativity.ipynb | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/examples/whm_gr_test/swiftest_relativity.ipynb b/examples/whm_gr_test/swiftest_relativity.ipynb index 4d44ca569..ea91ed5a2 100644 --- a/examples/whm_gr_test/swiftest_relativity.ipynb +++ b/examples/whm_gr_test/swiftest_relativity.ipynb @@ -40,9 +40,7 @@ "metadata": {}, "outputs": [], "source": [ - "%%capture\n", - "tstep_out = 10.0\n", - "sim_gr.run(tstop=1000.0, dt=0.005, tstep_out=tstep_out, integrator=\"whm\",general_relativity=True)" + "run_args = {\"tstop\":1000.0, \"dt\":0.005, \"tstep_out\":10.0,\"integrator\":\"whm\"}" ] }, { @@ -51,8 +49,16 @@ "metadata": {}, "outputs": [], "source": [ - "%%capture\n", - "sim_nogr.run(tstop=1000.0, dt=0.005, tstep_out=tstep_out, integrator=\"whm\",general_relativity=False)" + "sim_gr.run(**run_args,general_relativity=True)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "sim_nogr.run(**run_args,general_relativity=False)" ] }, { From e2282dad1eed59b8ce343dd5d17b47d5dbf38b88 Mon Sep 17 00:00:00 2001 From: David A Minton Date: Sun, 4 Dec 2022 11:35:40 -0500 Subject: [PATCH 57/65] More updates to notebook. WHM seems to have a problem where relativity isn't working. Will need to fix later --- examples/whm_gr_test/swiftest_relativity.ipynb | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/examples/whm_gr_test/swiftest_relativity.ipynb b/examples/whm_gr_test/swiftest_relativity.ipynb index ea91ed5a2..477963283 100644 --- a/examples/whm_gr_test/swiftest_relativity.ipynb +++ b/examples/whm_gr_test/swiftest_relativity.ipynb @@ -40,7 +40,7 @@ "metadata": {}, "outputs": [], "source": [ - "run_args = {\"tstop\":1000.0, \"dt\":0.005, \"tstep_out\":10.0,\"integrator\":\"whm\"}" + "run_args = {\"tstop\":1000.0, \"dt\":0.005, \"tstep_out\":10.0, \"dump_cadence\": 0,\"integrator\":\"whm\"}" ] }, { @@ -117,8 +117,8 @@ "metadata": {}, "outputs": [], "source": [ - "dvarpi_gr = np.diff(varpisim_gr) * 3600 * 100 / tstep_out\n", - "dvarpi_nogr = np.diff(varpisim_nogr) * 3600 * 100 / tstep_out\n", + "dvarpi_gr = np.diff(varpisim_gr) * 3600 * 100 / run_args['tstep_out']\n", + "dvarpi_nogr = np.diff(varpisim_nogr) * 3600 * 100 / run_args['tstep_out']\n", "dvarpi_obs = np.diff(varpi_obs) / np.diff(t) * 3600 * 100" ] }, @@ -150,7 +150,9 @@ "execution_count": null, "metadata": {}, "outputs": [], - "source": [] + "source": [ + "sim_nogr.param" + ] }, { "cell_type": "code", From d7357dacc9a496e9e2cada6c98dc8ad9d3c6cee1 Mon Sep 17 00:00:00 2001 From: David A Minton Date: Sun, 4 Dec 2022 11:37:39 -0500 Subject: [PATCH 58/65] Updates to helio_gr_test notebook --- .../helio_gr_test/swiftest_relativity.ipynb | 26 ++++++++++++------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/examples/helio_gr_test/swiftest_relativity.ipynb b/examples/helio_gr_test/swiftest_relativity.ipynb index 4b6d13106..e7ae73b23 100644 --- a/examples/helio_gr_test/swiftest_relativity.ipynb +++ b/examples/helio_gr_test/swiftest_relativity.ipynb @@ -19,7 +19,7 @@ "metadata": {}, "outputs": [], "source": [ - "sim_gr = swiftest.Simulation(param_file=\"grsim/param.gr.in\", output_file_name=\"bin.gr.nc\")\n", + "sim_gr = swiftest.Simulation(simdir=\"gr\")\n", "sim_gr.add_solar_system_body([\"Sun\",\"Mercury\",\"Venus\",\"Earth\",\"Mars\",\"Jupiter\",\"Saturn\",\"Uranus\",\"Neptune\"])" ] }, @@ -29,7 +29,7 @@ "metadata": {}, "outputs": [], "source": [ - "sim_nogr = swiftest.Simulation(param_file=\"nogrsim/param.nogr.in\", output_file_name=\"bin.nogr.nc\")\n", + "sim_nogr = swiftest.Simulation(simdir=\"nogr\")\n", "sim_nogr.add_solar_system_body([\"Sun\",\"Mercury\",\"Venus\",\"Earth\",\"Mars\",\"Jupiter\",\"Saturn\",\"Uranus\",\"Neptune\"])" ] }, @@ -39,8 +39,7 @@ "metadata": {}, "outputs": [], "source": [ - "tstep_out = 10.0\n", - "sim_gr.run(tstop=1000.0, dt=0.005, tstep_out=tstep_out, integrator=\"helio\",general_relativity=True)" + "run_args = {\"tstop\":1000.0, \"dt\":0.005, \"tstep_out\":10.0, \"dump_cadence\": 0,\"integrator\":\"helio\"}" ] }, { @@ -49,7 +48,16 @@ "metadata": {}, "outputs": [], "source": [ - "sim_nogr.run(tstop=1000.0, dt=0.005, tstep_out=tstep_out, integrator=\"helio\",general_relativity=False)" + "sim_gr.run(**run_args,general_relativity=True)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "sim_nogr.run(**run_args,general_relativity=False)" ] }, { @@ -108,8 +116,8 @@ "metadata": {}, "outputs": [], "source": [ - "dvarpi_gr = np.diff(varpisim_gr) * 3600 * 100 / tstep_out\n", - "dvarpi_nogr = np.diff(varpisim_nogr) * 3600 * 100 / tstep_out\n", + "dvarpi_gr = np.diff(varpisim_gr) * 3600 * 100 / run_args['tstep_out']\n", + "dvarpi_nogr = np.diff(varpisim_nogr) * 3600 * 100 / run_args['tstep_out']\n", "dvarpi_obs = np.diff(varpi_obs) / np.diff(t) * 3600 * 100" ] }, @@ -146,9 +154,9 @@ ], "metadata": { "kernelspec": { - "display_name": "swiftest", + "display_name": "Python (My debug_env Kernel)", "language": "python", - "name": "swiftest" + "name": "debug_env" }, "language_info": { "codemirror_mode": { From 6bd8a9d0d536ade373f954628efc5d19f3852eb2 Mon Sep 17 00:00:00 2001 From: David A Minton Date: Sun, 4 Dec 2022 15:47:09 -0500 Subject: [PATCH 59/65] Fixed some wonkiness with the name of the integrator that as a side effect turned off GR --- src/io/io.f90 | 48 ++++++++++++++++---------------- src/main/swiftest_driver.f90 | 7 +++-- src/modules/swiftest_classes.f90 | 4 +-- 3 files changed, 30 insertions(+), 29 deletions(-) diff --git a/src/io/io.f90 b/src/io/io.f90 index e0b381aec..81aca06d1 100644 --- a/src/io/io.f90 +++ b/src/io/io.f90 @@ -497,8 +497,9 @@ module subroutine io_param_reader(self, unit, iotype, v_list, iostat, iomsg) logical :: dt_set = .false. !! Is the step size set in the input file? integer(I4B) :: ilength, ifirst, ilast, i !! Variables used to parse input file character(STRMAX) :: line !! Line of the input file - character (len=:), allocatable :: line_trim,param_name, param_value !! Strings used to parse the param file + character(len=:), allocatable :: line_trim,param_name, param_value !! Strings used to parse the param file character(*),parameter :: linefmt = '(A)' !! Format code for simple text string + character(len=:), allocatable :: integrator ! Parse the file line by line, extracting tokens then matching them up with known parameters if possible @@ -762,30 +763,29 @@ module subroutine io_param_reader(self, unit, iotype, v_list, iostat, iomsg) ! Calculate the G for the system units param%GU = GC / (param%DU2M**3 / (param%MU2KG * param%TU2S**2)) - associate(integrator => v_list(1)) - if ((integrator == RMVS) .or. (integrator == SYMBA)) then - if (.not.param%lclose) then - write(iomsg,*) 'This integrator requires CHK_CLOSE to be enabled.' - iostat = -1 - return - end if + integrator = v_list(1) + if ((integrator == RMVS) .or. (integrator == SYMBA)) then + if (.not.param%lclose) then + write(iomsg,*) 'This integrator requires CHK_CLOSE to be enabled.' + iostat = -1 + return end if - - ! Determine if the GR flag is set correctly for this integrator - select case(integrator) - case(WHM, RMVS, HELIO, SYMBA) - case default - if (param%lgr) write(iomsg, *) 'GR is not yet implemented for this integrator. This parameter will be ignored.' - param%lgr = .false. - end select + end if + + ! Determine if the GR flag is set correctly for this integrator + select case(integrator) + case(WHM, RMVS, HELIO, SYMBA) + case default + if (param%lgr) write(iomsg, *) 'GR is not yet implemented for this integrator. This parameter will be ignored.' + param%lgr = .false. + end select - if (param%lgr) then - ! Calculate the inverse speed of light in the system units - param%inv_c2 = einsteinC * param%TU2S / param%DU2M - param%inv_c2 = (param%inv_c2)**(-2) - end if + if (param%lgr) then + ! Calculate the inverse speed of light in the system units + param%inv_c2 = einsteinC * param%TU2S / param%DU2M + param%inv_c2 = (param%inv_c2)**(-2) + end if - end associate select case(trim(adjustl(param%interaction_loops))) case("ADAPTIVE") @@ -1444,8 +1444,8 @@ module subroutine io_read_in_param(self, param_file_name) character(STRMAX) :: errmsg !! Error message in UDIO procedure ! Read in name of parameter file - write(self%display_unit, *) 'Parameter input file is ', trim(adjustl(param_file_name)) - self%param_file_name = param_file_name + self%param_file_name = trim(adjustl(param_file_name)) + write(self%display_unit, *) 'Parameter input file is ' // self%param_file_name !! todo: Currently this procedure does not work in user-defined derived-type input mode !! as the newline characters are ignored in the input file when compiled in ifort. diff --git a/src/main/swiftest_driver.f90 b/src/main/swiftest_driver.f90 index 3f9a36adc..846915444 100644 --- a/src/main/swiftest_driver.f90 +++ b/src/main/swiftest_driver.f90 @@ -49,7 +49,7 @@ program swiftest_driver case default allocate(swiftest_parameters :: param) end select - param%integrator = integrator + param%integrator = trim(adjustl(integrator)) call param%set_display(display_style) !> Define the maximum number of threads @@ -93,6 +93,7 @@ program swiftest_driver else if (param%lenergy) call nbody_system%conservation_report(param, lterminal=.false.) ! This will save the initial values of energy and momentum call nbody_system%write_frame(param) + call nbody_system%dump(param) end if write(display_unit, *) " *************** Main Loop *************** " @@ -102,7 +103,7 @@ program swiftest_driver write(pbarmessage,fmt=pbarfmt) t0, tstop call pbar%update(1,message=pbarmessage) else if (display_style == "COMPACT") then - write(*,*) "SWIFTEST START " // trim(adjustl(param%integrator)) + write(*,*) "SWIFTEST START " // param%integrator call nbody_system%compact_output(param,integration_timer) end if @@ -160,7 +161,7 @@ program swiftest_driver end do ! Dump any remaining history if it exists call system_history%dump(param) - if (display_style == "COMPACT") write(*,*) "SWIFTEST STOP" // trim(adjustl(param%integrator)) + if (display_style == "COMPACT") write(*,*) "SWIFTEST STOP" // param%integrator end associate call util_exit(SUCCESS) diff --git a/src/modules/swiftest_classes.f90 b/src/modules/swiftest_classes.f90 index 73ad063e6..b516a60a2 100644 --- a/src/modules/swiftest_classes.f90 +++ b/src/modules/swiftest_classes.f90 @@ -144,8 +144,8 @@ module swiftest_classes !> User defined parameters that are read in from the parameters input file. !> Each paramter is initialized to a default values. type :: swiftest_parameters - character(STRMAX) :: integrator = UNKNOWN_INTEGRATOR !! Symbolic name of the nbody integrator used - character(STRMAX) :: param_file_name = "param.in" !! The default name of the parameter input file + character(len=:), allocatable :: integrator !! Symbolic name of the nbody integrator used + character(len=:), allocatable :: param_file_name !! The name of the parameter file integer(I4B) :: maxid = -1 !! The current maximum particle id number integer(I4B) :: maxid_collision = 0 !! The current maximum collision id number real(DP) :: t0 = 0.0_DP !! Integration reference time From 30b00fca32cc7b2058eb2cde4ef407b8e106b3c1 Mon Sep 17 00:00:00 2001 From: David A Minton Date: Sun, 4 Dec 2022 16:01:31 -0500 Subject: [PATCH 60/65] More changes to relativity examples --- examples/helio_gr_test/grsim/param.gr.in | 35 ---- examples/helio_gr_test/nogrsim/param.nogr.in | 35 ---- .../helio_gr_test/swiftest_relativity.ipynb | 176 ------------------ examples/helio_gr_test/swiftest_relativity.py | 60 ------ examples/whm_gr_test/swiftest_relativity.py | 4 +- 5 files changed, 2 insertions(+), 308 deletions(-) delete mode 100644 examples/helio_gr_test/grsim/param.gr.in delete mode 100644 examples/helio_gr_test/nogrsim/param.nogr.in delete mode 100644 examples/helio_gr_test/swiftest_relativity.ipynb delete mode 100644 examples/helio_gr_test/swiftest_relativity.py diff --git a/examples/helio_gr_test/grsim/param.gr.in b/examples/helio_gr_test/grsim/param.gr.in deleted file mode 100644 index 0616db203..000000000 --- a/examples/helio_gr_test/grsim/param.gr.in +++ /dev/null @@ -1,35 +0,0 @@ -! VERSION Swiftest input file -T0 0.0 -TSTART 0.0 -TSTOP 1000.0 -DT 0.005 -ISTEP_OUT 2000 -ISTEP_DUMP 2000 -NC_IN init_cond.nc -IN_TYPE NETCDF_DOUBLE -IN_FORM EL -BIN_OUT bin.gr.nc -OUT_FORM XVEL -OUT_TYPE NETCDF_DOUBLE -OUT_STAT REPLACE -CHK_QMIN 0.004650467260962157 -CHK_RMIN 0.004650467260962157 -CHK_RMAX 10000.0 -CHK_EJECT 10000.0 -CHK_QMIN_COORD HELIO -CHK_QMIN_RANGE 0.004650467260962157 10000.0 -MU2KG 1.988409870698051e+30 -TU2S 31557600.0 -DU2M 149597870700.0 -FRAGMENTATION NO -RESTART NO -CHK_CLOSE YES -GR YES -ROTATION NO -ENERGY NO -EXTRA_FORCE NO -BIG_DISCARD NO -RHILL_PRESENT NO -INTERACTION_LOOPS TRIANGULAR -ENCOUNTER_CHECK TRIANGULAR -TIDES NO diff --git a/examples/helio_gr_test/nogrsim/param.nogr.in b/examples/helio_gr_test/nogrsim/param.nogr.in deleted file mode 100644 index 9e2ab0b22..000000000 --- a/examples/helio_gr_test/nogrsim/param.nogr.in +++ /dev/null @@ -1,35 +0,0 @@ -! VERSION Swiftest input file -T0 0.0 -TSTART 0.0 -TSTOP 1000.0 -DT 0.005 -ISTEP_OUT 2000 -ISTEP_DUMP 2000 -NC_IN init_cond.nc -IN_TYPE NETCDF_DOUBLE -IN_FORM EL -BIN_OUT bin.nogr.nc -OUT_FORM XVEL -OUT_TYPE NETCDF_DOUBLE -OUT_STAT REPLACE -CHK_QMIN 0.004650467260962157 -CHK_RMIN 0.004650467260962157 -CHK_RMAX 10000.0 -CHK_EJECT 10000.0 -CHK_QMIN_COORD HELIO -CHK_QMIN_RANGE 0.004650467260962157 10000.0 -MU2KG 1.988409870698051e+30 -TU2S 31557600.0 -DU2M 149597870700.0 -FRAGMENTATION NO -RESTART NO -CHK_CLOSE YES -GR NO -ROTATION NO -ENERGY NO -EXTRA_FORCE NO -BIG_DISCARD NO -RHILL_PRESENT NO -INTERACTION_LOOPS TRIANGULAR -ENCOUNTER_CHECK TRIANGULAR -TIDES NO diff --git a/examples/helio_gr_test/swiftest_relativity.ipynb b/examples/helio_gr_test/swiftest_relativity.ipynb deleted file mode 100644 index e7ae73b23..000000000 --- a/examples/helio_gr_test/swiftest_relativity.ipynb +++ /dev/null @@ -1,176 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "import swiftest\n", - "from astroquery.jplhorizons import Horizons\n", - "import datetime\n", - "import numpy as np\n", - "import matplotlib.pyplot as plt" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "sim_gr = swiftest.Simulation(simdir=\"gr\")\n", - "sim_gr.add_solar_system_body([\"Sun\",\"Mercury\",\"Venus\",\"Earth\",\"Mars\",\"Jupiter\",\"Saturn\",\"Uranus\",\"Neptune\"])" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "sim_nogr = swiftest.Simulation(simdir=\"nogr\")\n", - "sim_nogr.add_solar_system_body([\"Sun\",\"Mercury\",\"Venus\",\"Earth\",\"Mars\",\"Jupiter\",\"Saturn\",\"Uranus\",\"Neptune\"])" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "run_args = {\"tstop\":1000.0, \"dt\":0.005, \"tstep_out\":10.0, \"dump_cadence\": 0,\"integrator\":\"helio\"}" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "sim_gr.run(**run_args,general_relativity=True)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "sim_nogr.run(**run_args,general_relativity=False)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Get the start and end date of the simulation so we can compare with the real solar system\n", - "start_date = sim_gr.ephemeris_date\n", - "tstop_d = sim_gr.param['TSTOP'] * sim_gr.param['TU2S'] / swiftest.JD2S\n", - "\n", - "stop_date = (datetime.datetime.fromisoformat(start_date) + datetime.timedelta(days=tstop_d)).isoformat()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "#Get the ephemerides of Mercury for the same timeframe as the simulation\n", - "obj = Horizons(id='1', location='@sun',\n", - " epochs={'start':start_date, 'stop':stop_date,\n", - " 'step':'10y'})\n", - "el = obj.elements()\n", - "t = (el['datetime_jd']-el['datetime_jd'][0]) / 365.25\n", - "varpi_obs = el['w'] + el['Omega']" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Compute the longitude of the periapsis\n", - "sim_gr.data['varpi'] = np.mod(sim_gr.data['omega'] + sim_gr.data['capom'],360)\n", - "sim_nogr.data['varpi'] = np.mod(sim_nogr.data['omega'] + sim_nogr.data['capom'],360)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "varpisim_gr= sim_gr.data['varpi'].sel(name=\"Mercury\")\n", - "varpisim_nogr= sim_nogr.data['varpi'].sel(name=\"Mercury\")\n", - "tsim = sim_gr.data['time']" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "dvarpi_gr = np.diff(varpisim_gr) * 3600 * 100 / run_args['tstep_out']\n", - "dvarpi_nogr = np.diff(varpisim_nogr) * 3600 * 100 / run_args['tstep_out']\n", - "dvarpi_obs = np.diff(varpi_obs) / np.diff(t) * 3600 * 100" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "fig, ax = plt.subplots()\n", - "\n", - "ax.plot(t, varpi_obs, label=\"JPL Horizons\",linewidth=2.5)\n", - "ax.plot(tsim, varpisim_gr, label=\"Swiftest helio GR\",linewidth=1.5)\n", - "ax.plot(tsim, varpisim_nogr, label=\"Swiftest helio No GR\",linewidth=1.5)\n", - "ax.set_xlabel('Time (y)')\n", - "ax.set_ylabel('Mercury $\\\\varpi$ (deg)')\n", - "ax.legend()\n", - "plt.savefig(\"helio_gr_mercury_precession.png\",dpi=300)\n", - "print('Mean precession rate for Mercury long. peri. (arcsec/100 y)')\n", - "print(f'JPL Horizons : {np.mean(dvarpi_obs)}')\n", - "print(f'Swiftest No GR : {np.mean(dvarpi_nogr)}')\n", - "print(f'Swiftest GR : {np.mean(dvarpi_gr)}')\n", - "print(f'Obs - Swiftest GR : {np.mean(dvarpi_obs - dvarpi_gr)}')\n", - "print(f'Obs - Swiftest No GR : {np.mean(dvarpi_obs - dvarpi_nogr)}')" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python (My debug_env Kernel)", - "language": "python", - "name": "debug_env" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.8.5" - } - }, - "nbformat": 4, - "nbformat_minor": 4 -} diff --git a/examples/helio_gr_test/swiftest_relativity.py b/examples/helio_gr_test/swiftest_relativity.py deleted file mode 100644 index a5f4e4371..000000000 --- a/examples/helio_gr_test/swiftest_relativity.py +++ /dev/null @@ -1,60 +0,0 @@ -#!/usr/bin/env python -import swiftest -from astroquery.jplhorizons import Horizons -import datetime -import numpy as np -import matplotlib.pyplot as plt - -sim_gr = swiftest.Simulation(param_file="param.gr.in", output_file_name="bin.gr.nc") -sim_gr.add_solar_system_body(["Sun","Mercury","Venus","Earth","Mars","Jupiter","Saturn","Uranus","Neptune"]) - -sim_nogr = swiftest.Simulation(param_file="param.nogr.in", output_file_name="bin.nogr.nc") -sim_nogr.add_solar_system_body(["Sun","Mercury","Venus","Earth","Mars","Jupiter","Saturn","Uranus","Neptune"]) - -tstep_out = 10.0 -sim_gr.run(tstop=1000.0, dt=0.005, tstep_out=tstep_out, integrator="helio",general_relativity=True) -sim_nogr.run(tstop=1000.0, dt=0.005, tstep_out=tstep_out, integrator="helio",general_relativity=False) - -# Get the start and end date of the simulation so we can compare with the real solar system -start_date = sim_gr.ephemeris_date -tstop_d = sim_gr.param['TSTOP'] * sim_gr.param['TU2S'] / swiftest.JD2S - -stop_date = (datetime.datetime.fromisoformat(start_date) + datetime.timedelta(days=tstop_d)).isoformat() - -#Get the ephemerides of Mercury for the same timeframe as the simulation -obj = Horizons(id='1', location='@sun', - epochs={'start':start_date, 'stop':stop_date, - 'step':'10y'}) -el = obj.elements() -t = (el['datetime_jd']-el['datetime_jd'][0]) / 365.25 -varpi_obs = el['w'] + el['Omega'] - -# Compute the longitude of the periapsis -sim_gr.data['varpi'] = np.mod(sim_gr.data['omega'] + sim_gr.data['capom'],360) -sim_nogr.data['varpi'] = np.mod(sim_nogr.data['omega'] + sim_nogr.data['capom'],360) - -varpisim_gr= sim_gr.data['varpi'].sel(name="Mercury") -varpisim_nogr= sim_nogr.data['varpi'].sel(name="Mercury") -tsim = sim_gr.data['time'] - -dvarpi_gr = np.diff(varpisim_gr) * 3600 * 100 / tstep_out -dvarpi_nogr = np.diff(varpisim_nogr) * 3600 * 100 / tstep_out -dvarpi_obs = np.diff(varpi_obs) / np.diff(t) * 3600 * 100 - - -fig, ax = plt.subplots() - -ax.plot(t, varpi_obs, label="JPL Horizons",linewidth=2.5) -ax.plot(tsim, varpisim_gr, label="Swiftest Helio GR",linewidth=1.5) -ax.plot(tsim, varpisim_nogr, label="Swiftest Helio No GR",linewidth=1.5) -ax.set_xlabel('Time (y)') -ax.set_ylabel('Mercury $\\varpi$ (deg)') -ax.legend() -plt.savefig("helio_gr_mercury_precession.png",dpi=300) - -print('Mean precession rate for Mercury long. peri. (arcsec/100 y)') -print(f'JPL Horizons : {np.mean(dvarpi_obs)}') -print(f'Swiftest No GR : {np.mean(dvarpi_nogr)}') -print(f'Swiftest GR : {np.mean(dvarpi_gr)}') -print(f'Obs - Swiftest GR : {np.mean(dvarpi_obs - dvarpi_gr)}') -print(f'Obs - Swiftest No GR : {np.mean(dvarpi_obs - dvarpi_nogr)}') diff --git a/examples/whm_gr_test/swiftest_relativity.py b/examples/whm_gr_test/swiftest_relativity.py index a4ea53c3b..d4b777fa1 100644 --- a/examples/whm_gr_test/swiftest_relativity.py +++ b/examples/whm_gr_test/swiftest_relativity.py @@ -5,10 +5,10 @@ import numpy as np import matplotlib.pyplot as plt -sim_gr = swiftest.Simulation(param_file="param.gr.in", output_file_name="bin.gr.nc") +sim_gr = swiftest.Simulation(simdir="gr") sim_gr.add_solar_system_body(["Sun","Mercury","Venus","Earth","Mars","Jupiter","Saturn","Uranus","Neptune"]) -sim_nogr = swiftest.Simulation(param_file="param.nogr.in", output_file_name="bin.nogr.nc") +sim_nogr = swiftest.Simulation(simdir="nogr") sim_nogr.add_solar_system_body(["Sun","Mercury","Venus","Earth","Mars","Jupiter","Saturn","Uranus","Neptune"]) tstep_out = 10.0 From 3b3b58e2f8c369b52af220148040a31c711972a1 Mon Sep 17 00:00:00 2001 From: David A Minton Date: Sun, 4 Dec 2022 16:01:52 -0500 Subject: [PATCH 61/65] Renamed gr test python script and notebook --- examples/helio_gr_test/helio_gr_test.ipynb | 176 +++++++++++++++++++++ examples/helio_gr_test/helio_gr_test.py | 60 +++++++ 2 files changed, 236 insertions(+) create mode 100644 examples/helio_gr_test/helio_gr_test.ipynb create mode 100644 examples/helio_gr_test/helio_gr_test.py diff --git a/examples/helio_gr_test/helio_gr_test.ipynb b/examples/helio_gr_test/helio_gr_test.ipynb new file mode 100644 index 000000000..e7ae73b23 --- /dev/null +++ b/examples/helio_gr_test/helio_gr_test.ipynb @@ -0,0 +1,176 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "import swiftest\n", + "from astroquery.jplhorizons import Horizons\n", + "import datetime\n", + "import numpy as np\n", + "import matplotlib.pyplot as plt" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "sim_gr = swiftest.Simulation(simdir=\"gr\")\n", + "sim_gr.add_solar_system_body([\"Sun\",\"Mercury\",\"Venus\",\"Earth\",\"Mars\",\"Jupiter\",\"Saturn\",\"Uranus\",\"Neptune\"])" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "sim_nogr = swiftest.Simulation(simdir=\"nogr\")\n", + "sim_nogr.add_solar_system_body([\"Sun\",\"Mercury\",\"Venus\",\"Earth\",\"Mars\",\"Jupiter\",\"Saturn\",\"Uranus\",\"Neptune\"])" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "run_args = {\"tstop\":1000.0, \"dt\":0.005, \"tstep_out\":10.0, \"dump_cadence\": 0,\"integrator\":\"helio\"}" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "sim_gr.run(**run_args,general_relativity=True)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "sim_nogr.run(**run_args,general_relativity=False)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# Get the start and end date of the simulation so we can compare with the real solar system\n", + "start_date = sim_gr.ephemeris_date\n", + "tstop_d = sim_gr.param['TSTOP'] * sim_gr.param['TU2S'] / swiftest.JD2S\n", + "\n", + "stop_date = (datetime.datetime.fromisoformat(start_date) + datetime.timedelta(days=tstop_d)).isoformat()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "#Get the ephemerides of Mercury for the same timeframe as the simulation\n", + "obj = Horizons(id='1', location='@sun',\n", + " epochs={'start':start_date, 'stop':stop_date,\n", + " 'step':'10y'})\n", + "el = obj.elements()\n", + "t = (el['datetime_jd']-el['datetime_jd'][0]) / 365.25\n", + "varpi_obs = el['w'] + el['Omega']" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# Compute the longitude of the periapsis\n", + "sim_gr.data['varpi'] = np.mod(sim_gr.data['omega'] + sim_gr.data['capom'],360)\n", + "sim_nogr.data['varpi'] = np.mod(sim_nogr.data['omega'] + sim_nogr.data['capom'],360)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "varpisim_gr= sim_gr.data['varpi'].sel(name=\"Mercury\")\n", + "varpisim_nogr= sim_nogr.data['varpi'].sel(name=\"Mercury\")\n", + "tsim = sim_gr.data['time']" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "dvarpi_gr = np.diff(varpisim_gr) * 3600 * 100 / run_args['tstep_out']\n", + "dvarpi_nogr = np.diff(varpisim_nogr) * 3600 * 100 / run_args['tstep_out']\n", + "dvarpi_obs = np.diff(varpi_obs) / np.diff(t) * 3600 * 100" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "fig, ax = plt.subplots()\n", + "\n", + "ax.plot(t, varpi_obs, label=\"JPL Horizons\",linewidth=2.5)\n", + "ax.plot(tsim, varpisim_gr, label=\"Swiftest helio GR\",linewidth=1.5)\n", + "ax.plot(tsim, varpisim_nogr, label=\"Swiftest helio No GR\",linewidth=1.5)\n", + "ax.set_xlabel('Time (y)')\n", + "ax.set_ylabel('Mercury $\\\\varpi$ (deg)')\n", + "ax.legend()\n", + "plt.savefig(\"helio_gr_mercury_precession.png\",dpi=300)\n", + "print('Mean precession rate for Mercury long. peri. (arcsec/100 y)')\n", + "print(f'JPL Horizons : {np.mean(dvarpi_obs)}')\n", + "print(f'Swiftest No GR : {np.mean(dvarpi_nogr)}')\n", + "print(f'Swiftest GR : {np.mean(dvarpi_gr)}')\n", + "print(f'Obs - Swiftest GR : {np.mean(dvarpi_obs - dvarpi_gr)}')\n", + "print(f'Obs - Swiftest No GR : {np.mean(dvarpi_obs - dvarpi_nogr)}')" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python (My debug_env Kernel)", + "language": "python", + "name": "debug_env" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.8.5" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} diff --git a/examples/helio_gr_test/helio_gr_test.py b/examples/helio_gr_test/helio_gr_test.py new file mode 100644 index 000000000..8d78a861b --- /dev/null +++ b/examples/helio_gr_test/helio_gr_test.py @@ -0,0 +1,60 @@ +#!/usr/bin/env python +import swiftest +from astroquery.jplhorizons import Horizons +import datetime +import numpy as np +import matplotlib.pyplot as plt + +sim_gr = swiftest.Simulation(simdir="gr") +sim_gr.add_solar_system_body(["Sun","Mercury","Venus","Earth","Mars","Jupiter","Saturn","Uranus","Neptune"]) + +sim_nogr = swiftest.Simulation(simdir="nogr") +sim_nogr.add_solar_system_body(["Sun","Mercury","Venus","Earth","Mars","Jupiter","Saturn","Uranus","Neptune"]) + +run_args = {"tstop":1000.0, "dt":0.005, "tstep_out":10.0, "dump_cadence": 0,"integrator":"helio"} + +sim_gr.run(**run_args,general_relativity=True) +sim_nogr.run(**run_args,general_relativity=False) + +# Get the start and end date of the simulation so we can compare with the real solar system +start_date = sim_gr.ephemeris_date +tstop_d = sim_gr.param['TSTOP'] * sim_gr.param['TU2S'] / swiftest.JD2S + +stop_date = (datetime.datetime.fromisoformat(start_date) + datetime.timedelta(days=tstop_d)).isoformat() + +#Get the ephemerides of Mercury for the same timeframe as the simulation +obj = Horizons(id='1', location='@sun', + epochs={'start':start_date, 'stop':stop_date, + 'step':'10y'}) +el = obj.elements() +t = (el['datetime_jd']-el['datetime_jd'][0]) / 365.25 +varpi_obs = el['w'] + el['Omega'] + +# Compute the longitude of the periapsis +sim_gr.data['varpi'] = np.mod(sim_gr.data['omega'] + sim_gr.data['capom'],360) +sim_nogr.data['varpi'] = np.mod(sim_nogr.data['omega'] + sim_nogr.data['capom'],360) + +varpisim_gr= sim_gr.data['varpi'].sel(name="Mercury") +varpisim_nogr= sim_nogr.data['varpi'].sel(name="Mercury") +tsim = sim_gr.data['time'] + +dvarpi_gr = np.diff(varpisim_gr) * 3600 * 100 / run_args['tstep_out'] +dvarpi_nogr = np.diff(varpisim_nogr) * 3600 * 100 / run_args['tstep_out'] +dvarpi_obs = np.diff(varpi_obs) / np.diff(t) * 3600 * 100 + +fig, ax = plt.subplots() + +ax.plot(t, varpi_obs, label="JPL Horizons",linewidth=2.5) +ax.plot(tsim, varpisim_gr, label="Swiftest Helio GR",linewidth=1.5) +ax.plot(tsim, varpisim_nogr, label="Swiftest Helio No GR",linewidth=1.5) +ax.set_xlabel('Time (y)') +ax.set_ylabel('Mercury $\\varpi$ (deg)') +ax.legend() +plt.savefig("helio_gr_mercury_precession.png",dpi=300) + +print('Mean precession rate for Mercury long. peri. (arcsec/100 y)') +print(f'JPL Horizons : {np.mean(dvarpi_obs)}') +print(f'Swiftest No GR : {np.mean(dvarpi_nogr)}') +print(f'Swiftest GR : {np.mean(dvarpi_gr)}') +print(f'Obs - Swiftest GR : {np.mean(dvarpi_obs - dvarpi_gr)}') +print(f'Obs - Swiftest No GR : {np.mean(dvarpi_obs - dvarpi_nogr)}') From cfcb505138a92e13f4511ebc3a626e20159acdb9 Mon Sep 17 00:00:00 2001 From: David A Minton Date: Sun, 4 Dec 2022 16:57:27 -0500 Subject: [PATCH 62/65] Added extended set of orbital elements to output --- src/modules/swiftest_classes.f90 | 19 ++++++++++++++++--- src/netcdf/netcdf.f90 | 22 +++++++++++++++++++--- src/orbel/orbel.f90 | 26 ++++++++++++++++++++++---- 3 files changed, 57 insertions(+), 10 deletions(-) diff --git a/src/modules/swiftest_classes.f90 b/src/modules/swiftest_classes.f90 index b516a60a2..a09aca917 100644 --- a/src/modules/swiftest_classes.f90 +++ b/src/modules/swiftest_classes.f90 @@ -60,10 +60,18 @@ module swiftest_classes integer(I4B) :: inc_varid !! ID for the inclination variable character(NAMELEN) :: capom_varname = "capom" !! name of the long. asc. node variable integer(I4B) :: capom_varid !! ID for the long. asc. node variable - character(NAMELEN) :: omega_varname = "omega" !! name of the arg. periapsis variable - integer(I4B) :: omega_varid !! ID for the arg. periapsis variable + character(NAMELEN) :: omega_varname = "omega" !! name of the arg. of periapsis variable + integer(I4B) :: omega_varid !! ID for the arg. of periapsis variable character(NAMELEN) :: capm_varname = "capm" !! name of the mean anomaly variable integer(I4B) :: capm_varid !! ID for the mean anomaly variable + character(NAMELEN) :: varpi_varname = "varpi" !! name of the long. of periapsis variable + integer(I4B) :: varpi_varid !! ID for the long. of periapsis variable + character(NAMELEN) :: lam_varname = "lam" !! name of the mean longitude variable + integer(I4B) :: lam_varid !! ID for the mean longitude variable + character(NAMELEN) :: f_varname = "f" !! name of the true anomaly variable + integer(I4B) :: f_varid !! ID for the true anomaly variable + character(NAMELEN) :: cape_varname = "cape" !! name of the eccentric anomaly variable + integer(I4B) :: cape_varid !! ID for the eccentric anomaly variable character(NAMELEN) :: rh_varname = "rh" !! name of the heliocentric position vector variable integer(I4B) :: rh_varid !! ID for the heliocentric position vector variable character(NAMELEN) :: vh_varname = "vh" !! name of the heliocentric velocity vector variable @@ -1127,7 +1135,7 @@ pure module subroutine orbel_xv2aqt(mu, px, py, pz, vx, vy, vz, a, q, capm, tper real(DP), intent(out) :: tperi !! time of pericenter passage end subroutine orbel_xv2aqt - pure module subroutine orbel_xv2el(mu, px, py, pz, vx, vy, vz, a, e, inc, capom, omega, capm) + pure module subroutine orbel_xv2el(mu, px, py, pz, vx, vy, vz, a, e, inc, capom, omega, capm, varpi, lam, f, cape, capf) implicit none real(DP), intent(in) :: mu !! Gravitational constant real(DP), intent(in) :: px,py,pz !! Position vector @@ -1138,6 +1146,11 @@ pure module subroutine orbel_xv2el(mu, px, py, pz, vx, vy, vz, a, e, inc, capom, real(DP), intent(out) :: capom !! longitude of ascending node real(DP), intent(out) :: omega !! argument of periapsis real(DP), intent(out) :: capm !! mean anomaly + real(DP), intent(out) :: varpi !! longitude of periapsis + real(DP), intent(out) :: lam !! mean longitude + real(DP), intent(out) :: f !! true anomaly + real(DP), intent(out) :: cape !! eccentric anomaly (eccentric orbits) + real(DP), intent(out) :: capf !! hyperbolic anomaly (hyperbolic orbits) end subroutine orbel_xv2el module subroutine orbel_xv2el_vec(self, cb) diff --git a/src/netcdf/netcdf.f90 b/src/netcdf/netcdf.f90 index b5c44b00e..20cccc8e5 100644 --- a/src/netcdf/netcdf.f90 +++ b/src/netcdf/netcdf.f90 @@ -220,6 +220,10 @@ module subroutine netcdf_initialize_output(self, param) call check( nf90_def_var(nciu%id, nciu%capom_varname, nciu%out_type, [nciu%id_dimid, nciu%time_dimid], nciu%capom_varid), "netcdf_initialize_output nf90_def_var capom_varid" ) call check( nf90_def_var(nciu%id, nciu%omega_varname, nciu%out_type, [nciu%id_dimid, nciu%time_dimid], nciu%omega_varid), "netcdf_initialize_output nf90_def_var omega_varid" ) call check( nf90_def_var(nciu%id, nciu%capm_varname, nciu%out_type, [nciu%id_dimid, nciu%time_dimid], nciu%capm_varid), "netcdf_initialize_output nf90_def_var capm_varid" ) + call check( nf90_def_var(nciu%id, nciu%varpi_varname, nciu%out_type, [nciu%id_dimid, nciu%time_dimid], nciu%varpi_varid), "netcdf_initialize_output nf90_def_var varpi_varid" ) + call check( nf90_def_var(nciu%id, nciu%lam_varname, nciu%out_type, [nciu%id_dimid, nciu%time_dimid], nciu%lam_varid), "netcdf_initialize_output nf90_def_var lam_varid" ) + call check( nf90_def_var(nciu%id, nciu%f_varname, nciu%out_type, [nciu%id_dimid, nciu%time_dimid], nciu%f_varid), "netcdf_initialize_output nf90_def_var f_varid" ) + call check( nf90_def_var(nciu%id, nciu%cape_varname, nciu%out_type, [nciu%id_dimid, nciu%time_dimid], nciu%cape_varid), "netcdf_initialize_output nf90_def_var cape_varid" ) end if call check( nf90_def_var(nciu%id, nciu%gmass_varname, nciu%out_type, [nciu%id_dimid, nciu%time_dimid], nciu%Gmass_varid), "netcdf_initialize_output nf90_def_var Gmass_varid" ) @@ -389,6 +393,10 @@ module subroutine netcdf_open(self, param, readonly) status = nf90_inq_varid(nciu%id, nciu%j2rp2_varname, nciu%j2rp2_varid) status = nf90_inq_varid(nciu%id, nciu%j4rp4_varname, nciu%j4rp4_varid) status = nf90_inq_varid(nciu%id, nciu%ptype_varname, nciu%ptype_varid) + status = nf90_inq_varid(nciu%id, nciu%varpi_varname, nciu%varpi_varid) + status = nf90_inq_varid(nciu%id, nciu%lam_varname, nciu%lam_varid) + status = nf90_inq_varid(nciu%id, nciu%f_varname, nciu%f_varid) + status = nf90_inq_varid(nciu%id, nciu%cape_varname, nciu%cape_varid) if (param%integrator == SYMBA) then status = nf90_inq_varid(nciu%id, nciu%nplm_varname, nciu%nplm_varid) @@ -1033,7 +1041,7 @@ module subroutine netcdf_write_frame_base(self, nciu, param) integer(I4B) :: i, j, tslot, idslot, old_mode integer(I4B), dimension(:), allocatable :: ind real(DP), dimension(NDIM) :: vh !! Temporary variable to store heliocentric velocity values when converting from pseudovelocity in GR-enabled runs - real(DP) :: a, e, inc, omega, capom, capm + real(DP) :: a, e, inc, omega, capom, capm, varpi, lam, f, cape, capf call self%write_info(nciu, param) @@ -1069,11 +1077,11 @@ module subroutine netcdf_write_frame_base(self, nciu, param) if (param%lgr) then !! For GR-enabled runs, use the true value of velocity computed above call orbel_xv2el(self%mu(j), self%rh(1,j), self%rh(2,j), self%rh(3,j), & vh(1), vh(2), vh(3), & - a, e, inc, capom, omega, capm) + a, e, inc, capom, omega, capm, varpi, lam, f, cape, capf) else !! For non-GR runs just convert from the velocity we have call orbel_xv2el(self%mu(j), self%rh(1,j), self%rh(2,j), self%rh(3,j), & self%vh(1,j), self%vh(2,j), self%vh(3,j), & - a, e, inc, capom, omega, capm) + a, e, inc, capom, omega, capm, varpi, lam, f, cape, capf) end if call check( nf90_put_var(nciu%id, nciu%a_varid, a, start=[idslot, tslot]), "netcdf_write_frame_base nf90_put_var body a_varid" ) call check( nf90_put_var(nciu%id, nciu%e_varid, e, start=[idslot, tslot]), "netcdf_write_frame_base nf90_put_var body e_varid" ) @@ -1081,6 +1089,14 @@ module subroutine netcdf_write_frame_base(self, nciu, param) call check( nf90_put_var(nciu%id, nciu%capom_varid, capom * RAD2DEG, start=[idslot, tslot]), "netcdf_write_frame_base nf90_put_var body capom_varid" ) call check( nf90_put_var(nciu%id, nciu%omega_varid, omega * RAD2DEG, start=[idslot, tslot]), "netcdf_write_frame_base nf90_put_var body omega_varid" ) call check( nf90_put_var(nciu%id, nciu%capm_varid, capm * RAD2DEG, start=[idslot, tslot]), "netcdf_write_frame_base nf90_put_var body capm_varid" ) + call check( nf90_put_var(nciu%id, nciu%varpi_varid, varpi * RAD2DEG, start=[idslot, tslot]), "netcdf_write_frame_base nf90_put_var body varpi_varid" ) + call check( nf90_put_var(nciu%id, nciu%lam_varid, lam * RAD2DEG, start=[idslot, tslot]), "netcdf_write_frame_base nf90_put_var body lam_varid" ) + call check( nf90_put_var(nciu%id, nciu%f_varid, f * RAD2DEG, start=[idslot, tslot]), "netcdf_write_frame_base nf90_put_var body f_varid" ) + if (e < 1.0_DP) then + call check( nf90_put_var(nciu%id, nciu%cape_varid, cape * RAD2DEG, start=[idslot, tslot]), "netcdf_write_frame_base nf90_put_var body cape_varid" ) + else if (e > 1.0_DP) then + call check( nf90_put_var(nciu%id, nciu%cape_varid, capf * RAD2DEG, start=[idslot, tslot]), "netcdf_write_frame_base nf90_put_var body (capf) cape_varid" ) + end if end if select type(self) diff --git a/src/orbel/orbel.f90 b/src/orbel/orbel.f90 index 014fe9bae..9e7a571eb 100644 --- a/src/orbel/orbel.f90 +++ b/src/orbel/orbel.f90 @@ -874,6 +874,7 @@ module subroutine orbel_xv2el_vec(self, cb) class(swiftest_cb), intent(inout) :: cb !! Swiftest central body object ! internals integer(I4B) :: i + real(DP) :: varpi, lam, f, cape, capf if (self%nbody == 0) return @@ -887,15 +888,16 @@ module subroutine orbel_xv2el_vec(self, cb) do concurrent (i = 1:self%nbody) call orbel_xv2el(self%mu(i), self%rh(1,i), self%rh(2,i), self%rh(3,i), & self%vh(1,i), self%vh(2,i), self%vh(3,i), & - self%a(i), self%e(i), self%inc(i), & - self%capom(i), self%omega(i), self%capm(i)) + self%a(i), self%e(i), self%inc(i), & + self%capom(i), self%omega(i), self%capm(i), & + varpi, lam, f, cape, capf) end do return end subroutine orbel_xv2el_vec - pure module subroutine orbel_xv2el(mu, px, py, pz, vx, vy, vz, a, e, inc, capom, omega, capm) + pure module subroutine orbel_xv2el(mu, px, py, pz, vx, vy, vz, a, e, inc, capom, omega, capm, varpi, lam, f, cape, capf) !! author: David A. Minton !! !! Compute osculating orbital elements from relative Cartesian position and velocity @@ -921,9 +923,14 @@ pure module subroutine orbel_xv2el(mu, px, py, pz, vx, vy, vz, a, e, inc, capom, real(DP), intent(out) :: capom !! longitude of ascending node real(DP), intent(out) :: omega !! argument of periapsis real(DP), intent(out) :: capm !! mean anomaly + real(DP), intent(out) :: varpi !! longitude of periapsis + real(DP), intent(out) :: lam !! mean longitude + real(DP), intent(out) :: f !! true anomaly + real(DP), intent(out) :: cape !! eccentric anomaly (eccentric orbits) + real(DP), intent(out) :: capf !! hyperbolic anomaly (hyperbolic orbits) ! Internals integer(I4B) :: iorbit_type - real(DP) :: r, v2, h2, h, rdotv, energy, fac, u, w, cw, sw, face, cape, tmpf, capf + real(DP) :: r, v2, h2, h, rdotv, energy, fac, u, w, cw, sw, face, tmpf, sf, cf, rdot real(DP), dimension(NDIM) :: hvec, x, v a = 0.0_DP @@ -1023,6 +1030,17 @@ pure module subroutine orbel_xv2el(mu, px, py, pz, vx, vy, vz, a, e, inc, capom, end select omega = u - w if (omega < 0.0_DP) omega = omega + TWOPI + varpi = mod(omega + capom, TWOPI) + lam = mod(capm + varpi, TWOPI) + if (e > VSMALL) then + cf = 1.0_DP / e * (a * (1.0_DP - e**2)/r - 1.0_DP) + rdot = sign(sqrt(v2 - (h / r)**2),rdotv) + sf = a * (1.0_DP - e**2) / (h * e) * rdot + f = atan2(sf,cf) + else + f = u + end if + return end subroutine orbel_xv2el From eb344152c11a6e0cd7b7427d584ada53aa9224e1 Mon Sep 17 00:00:00 2001 From: David A Minton Date: Sun, 4 Dec 2022 17:00:54 -0500 Subject: [PATCH 63/65] Fixed it so true anomaly is put on the range 0..2pi --- src/orbel/orbel.f90 | 1 + 1 file changed, 1 insertion(+) diff --git a/src/orbel/orbel.f90 b/src/orbel/orbel.f90 index 9e7a571eb..0a4416160 100644 --- a/src/orbel/orbel.f90 +++ b/src/orbel/orbel.f90 @@ -1037,6 +1037,7 @@ pure module subroutine orbel_xv2el(mu, px, py, pz, vx, vy, vz, a, e, inc, capom, rdot = sign(sqrt(v2 - (h / r)**2),rdotv) sf = a * (1.0_DP - e**2) / (h * e) * rdot f = atan2(sf,cf) + if (f < 0.0_DP) f = f + TWOPI else f = u end if From d972a21154da1984101cbc187da415d096473bbb Mon Sep 17 00:00:00 2001 From: David A Minton Date: Sun, 4 Dec 2022 17:02:29 -0500 Subject: [PATCH 64/65] Fixed up helio_gr_test scripts and notebooks --- examples/helio_gr_test/helio_gr_test.ipynb | 18 ------------------ examples/helio_gr_test/helio_gr_test.py | 4 ---- python/swiftest/swiftest/io.py | 1 - 3 files changed, 23 deletions(-) diff --git a/examples/helio_gr_test/helio_gr_test.ipynb b/examples/helio_gr_test/helio_gr_test.ipynb index e7ae73b23..c6b0c67ea 100644 --- a/examples/helio_gr_test/helio_gr_test.ipynb +++ b/examples/helio_gr_test/helio_gr_test.ipynb @@ -88,17 +88,6 @@ "varpi_obs = el['w'] + el['Omega']" ] }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Compute the longitude of the periapsis\n", - "sim_gr.data['varpi'] = np.mod(sim_gr.data['omega'] + sim_gr.data['capom'],360)\n", - "sim_nogr.data['varpi'] = np.mod(sim_nogr.data['omega'] + sim_nogr.data['capom'],360)" - ] - }, { "cell_type": "code", "execution_count": null, @@ -143,13 +132,6 @@ "print(f'Obs - Swiftest GR : {np.mean(dvarpi_obs - dvarpi_gr)}')\n", "print(f'Obs - Swiftest No GR : {np.mean(dvarpi_obs - dvarpi_nogr)}')" ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] } ], "metadata": { diff --git a/examples/helio_gr_test/helio_gr_test.py b/examples/helio_gr_test/helio_gr_test.py index 8d78a861b..0d9339dbe 100644 --- a/examples/helio_gr_test/helio_gr_test.py +++ b/examples/helio_gr_test/helio_gr_test.py @@ -30,10 +30,6 @@ t = (el['datetime_jd']-el['datetime_jd'][0]) / 365.25 varpi_obs = el['w'] + el['Omega'] -# Compute the longitude of the periapsis -sim_gr.data['varpi'] = np.mod(sim_gr.data['omega'] + sim_gr.data['capom'],360) -sim_nogr.data['varpi'] = np.mod(sim_nogr.data['omega'] + sim_nogr.data['capom'],360) - varpisim_gr= sim_gr.data['varpi'].sel(name="Mercury") varpisim_nogr= sim_nogr.data['varpi'].sel(name="Mercury") tsim = sim_gr.data['time'] diff --git a/python/swiftest/swiftest/io.py b/python/swiftest/swiftest/io.py index dc2899d16..dbcb7430d 100644 --- a/python/swiftest/swiftest/io.py +++ b/python/swiftest/swiftest/io.py @@ -847,7 +847,6 @@ def swifter2xr(param, verbose=True): if verbose: print(f"Successfully converted {ds.sizes['time']} output frames.") return ds - def swiftest2xr(param, verbose=True): """ Converts a Swiftest binary data file into an xarray DataSet. From eadc6a6b3c2c377961048082c35a6775fd8b17ea Mon Sep 17 00:00:00 2001 From: David A Minton Date: Sun, 4 Dec 2022 17:05:33 -0500 Subject: [PATCH 65/65] updated whm_gr_test --- ...est_relativity.ipynb => whm_gr_test.ipynb} | 34 ++----------------- ...{swiftest_relativity.py => whm_gr_test.py} | 16 ++++----- 2 files changed, 9 insertions(+), 41 deletions(-) rename examples/whm_gr_test/{swiftest_relativity.ipynb => whm_gr_test.ipynb} (84%) rename examples/whm_gr_test/{swiftest_relativity.py => whm_gr_test.py} (78%) diff --git a/examples/whm_gr_test/swiftest_relativity.ipynb b/examples/whm_gr_test/whm_gr_test.ipynb similarity index 84% rename from examples/whm_gr_test/swiftest_relativity.ipynb rename to examples/whm_gr_test/whm_gr_test.ipynb index 477963283..a3dac65b2 100644 --- a/examples/whm_gr_test/swiftest_relativity.ipynb +++ b/examples/whm_gr_test/whm_gr_test.ipynb @@ -10,8 +10,7 @@ "from astroquery.jplhorizons import Horizons\n", "import datetime\n", "import numpy as np\n", - "import matplotlib.pyplot as plt\n", - "import os" + "import matplotlib.pyplot as plt" ] }, { @@ -89,17 +88,6 @@ "varpi_obs = el['w'] + el['Omega']" ] }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Compute the longitude of the periapsis\n", - "sim_gr.data['varpi'] = np.mod(sim_gr.data['omega'] + sim_gr.data['capom'],360)\n", - "sim_nogr.data['varpi'] = np.mod(sim_nogr.data['omega'] + sim_nogr.data['capom'],360)" - ] - }, { "cell_type": "code", "execution_count": null, @@ -131,8 +119,8 @@ "fig, ax = plt.subplots()\n", "\n", "ax.plot(t, varpi_obs, label=\"JPL Horizons\",linewidth=2.5)\n", - "ax.plot(tsim, varpisim_gr, label=\"Swiftest whm GR\",linewidth=1.5)\n", - "ax.plot(tsim, varpisim_nogr, label=\"Swiftest whm No GR\",linewidth=1.5)\n", + "ax.plot(tsim, varpisim_gr, label=\"Swiftest WHM GR\",linewidth=1.5)\n", + "ax.plot(tsim, varpisim_nogr, label=\"Swiftest WHM No GR\",linewidth=1.5)\n", "ax.set_xlabel('Time (y)')\n", "ax.set_ylabel('Mercury $\\\\varpi$ (deg)')\n", "ax.legend()\n", @@ -144,22 +132,6 @@ "print(f'Obs - Swiftest GR : {np.mean(dvarpi_obs - dvarpi_gr)}')\n", "print(f'Obs - Swiftest No GR : {np.mean(dvarpi_obs - dvarpi_nogr)}')" ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "sim_nogr.param" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] } ], "metadata": { diff --git a/examples/whm_gr_test/swiftest_relativity.py b/examples/whm_gr_test/whm_gr_test.py similarity index 78% rename from examples/whm_gr_test/swiftest_relativity.py rename to examples/whm_gr_test/whm_gr_test.py index d4b777fa1..2061e251b 100644 --- a/examples/whm_gr_test/swiftest_relativity.py +++ b/examples/whm_gr_test/whm_gr_test.py @@ -11,9 +11,10 @@ sim_nogr = swiftest.Simulation(simdir="nogr") sim_nogr.add_solar_system_body(["Sun","Mercury","Venus","Earth","Mars","Jupiter","Saturn","Uranus","Neptune"]) -tstep_out = 10.0 -sim_gr.run(tstop=1000.0, dt=0.005, tstep_out=tstep_out, integrator="whm",general_relativity=True) -sim_nogr.run(tstop=1000.0, dt=0.005, tstep_out=tstep_out, integrator="whm",general_relativity=False) +run_args = {"tstop":1000.0, "dt":0.005, "tstep_out":10.0, "dump_cadence": 0,"integrator":"whm"} + +sim_gr.run(**run_args,general_relativity=True) +sim_nogr.run(**run_args,general_relativity=False) # Get the start and end date of the simulation so we can compare with the real solar system start_date = sim_gr.ephemeris_date @@ -29,19 +30,14 @@ t = (el['datetime_jd']-el['datetime_jd'][0]) / 365.25 varpi_obs = el['w'] + el['Omega'] -# Compute the longitude of the periapsis -sim_gr.data['varpi'] = np.mod(sim_gr.data['omega'] + sim_gr.data['capom'],360) -sim_nogr.data['varpi'] = np.mod(sim_nogr.data['omega'] + sim_nogr.data['capom'],360) - varpisim_gr= sim_gr.data['varpi'].sel(name="Mercury") varpisim_nogr= sim_nogr.data['varpi'].sel(name="Mercury") tsim = sim_gr.data['time'] -dvarpi_gr = np.diff(varpisim_gr) * 3600 * 100 / tstep_out -dvarpi_nogr = np.diff(varpisim_nogr) * 3600 * 100 / tstep_out +dvarpi_gr = np.diff(varpisim_gr) * 3600 * 100 / run_args['tstep_out'] +dvarpi_nogr = np.diff(varpisim_nogr) * 3600 * 100 / run_args['tstep_out'] dvarpi_obs = np.diff(varpi_obs) / np.diff(t) * 3600 * 100 - fig, ax = plt.subplots() ax.plot(t, varpi_obs, label="JPL Horizons",linewidth=2.5)