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

Commit

Permalink
Made minor modifications to the NetCDF I/O so that files are only wri…
Browse files Browse the repository at this point in the history
…tten to disk when a dump is called. Setting ISTEP_DUMP > ISTEP_OUT greatly increases the speed of a run
  • Loading branch information
daminton committed Sep 27, 2021
1 parent 195fd1a commit a1e785e
Show file tree
Hide file tree
Showing 15 changed files with 104 additions and 48 deletions.
Binary file modified examples/rmvs_swifter_comparison/1pl_1tp_encounter/cb.swiftest.in
Binary file not shown.
24 changes: 18 additions & 6 deletions examples/rmvs_swifter_comparison/1pl_1tp_encounter/init_cond.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
swiftest_pl = "pl.swiftest.in"
swiftest_tp = "tp.swiftest.in"
swiftest_cb = "cb.swiftest.in"
swiftest_bin = "bin.swiftest.dat"
swiftest_bin = "bin.swiftest.nc"
swiftest_enc = "enc.swiftest.dat"

MU2KG = swiftest.MSun
Expand All @@ -39,8 +39,8 @@
rmax = 1000.0

npl = 1
plid = 2
tpid = 100
plid = 1
tpid = 2

radius = np.double(4.25875607065041e-05)
Gmass = np.double(0.00012002693582795244940133)
Expand All @@ -60,7 +60,7 @@
#Make Swifter files
plfile = open(swifter_pl, 'w')
print(npl+1, f'! Planet input file generated using init_cond.py',file=plfile)
print(1,GMSun,file=plfile)
print(0,GMSun,file=plfile)
print('0.0 0.0 0.0',file=plfile)
print('0.0 0.0 0.0',file=plfile)
print(plid,"{:.23g}".format(Gmass),rhill, file=plfile)
Expand Down Expand Up @@ -106,9 +106,19 @@
sys.stdout = sys.__stdout__

#Now make Swiftest files
NAMELEN = 32
cbname = "Sun"
plname = "Planet"
tpname = "TestParticle"

cbname = cbname.ljust(NAMELEN)
plname = plname.ljust(NAMELEN)
tpname = tpname.ljust(NAMELEN)

cbfile = FortranFile(swiftest_cb, 'w')
Msun = np.double(1.0)
cbfile.write_record(0)
cbfile.write_record(cbname)
cbfile.write_record(np.double(GMSun))
cbfile.write_record(np.double(rmin))
cbfile.write_record(np.double(swiftest.J2Sun))
Expand All @@ -119,6 +129,7 @@
plfile.write_record(npl)

plfile.write_record(plid)
plfile.write_record(plname)
plfile.write_record(p_pl[0])
plfile.write_record(p_pl[1])
plfile.write_record(p_pl[2])
Expand All @@ -133,6 +144,7 @@
ntp = 1
tpfile.write_record(ntp)
tpfile.write_record(tpid)
tpfile.write_record(tpname)
tpfile.write_record(p_tp[0])
tpfile.write_record(p_tp[1])
tpfile.write_record(p_tp[2])
Expand All @@ -154,8 +166,8 @@
print(f'ISTEP_OUT {iout:d}')
print(f'ISTEP_DUMP {iout:d}')
print(f'BIN_OUT {swiftest_bin}')
print(f'OUT_TYPE REAL8')
print(f'OUT_FORM XV')
print(f'OUT_TYPE NETCDF_DOUBLE')
print(f'OUT_FORM XVEL')
print(f'OUT_STAT REPLACE')
print(f'RHILL_PRESENT yes')
print(f'CHK_CLOSE yes')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ PL_IN pl.swiftest.in
TP_IN tp.swiftest.in
IN_TYPE REAL8
ISTEP_OUT 1
ISTEP_DUMP 1
BIN_OUT bin.swiftest.dat
OUT_TYPE REAL8
OUT_FORM XV
ISTEP_DUMP 10
BIN_OUT bin.swiftest.nc
OUT_TYPE NETCDF_DOUBLE
OUT_FORM XVEL
OUT_STAT REPLACE
RHILL_PRESENT yes
CHK_CLOSE yes
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
2 ! Planet input file generated using init_cond.py
1 39.476926408897625196
0 39.476926408897625196
0.0 0.0 0.0
0.0 0.0 0.0
2 0.00012002693582795244940133 0.010044724833237892
1 0.00012002693582795244940133 0.010044724833237892
4.25875607065041e-05
1.0 0.0 0.0
0.0 6.283185307179586 0.0
Binary file modified examples/rmvs_swifter_comparison/1pl_1tp_encounter/pl.swiftest.in
Binary file not shown.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
1
100
2
1.01 0.0 0.0
0.0 6.252003053624663 0.0
Binary file modified examples/rmvs_swifter_comparison/1pl_1tp_encounter/tp.swiftest.in
Binary file not shown.
15 changes: 6 additions & 9 deletions src/io/io.f90
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,11 @@ module subroutine io_conservation_report(self, param, lterminal)
if (abs(Merror) > 100 * epsilon(Merror)) then
write(*,*) "Severe error! Mass not conserved! Halting!"
call pl%xv2el(cb)
call param%nciu%open(param)
!call param%nciu%open(param)
call self%write_hdr(param%nciu, param)
call cb%write_frame(param%nciu, param)
call pl%write_frame(param%nciu, param)
call param%nciu%close(param)
call param%nciu%close()
call util_exit(FAILURE)
end if
end if
Expand Down Expand Up @@ -202,9 +202,7 @@ module subroutine io_dump_particle_info_base(self, param, idx)
close(unit = LUN, err = 667, iomsg = errmsg)
!else if ((param%out_type == NETCDF_FLOAT_TYPE) .or. (param%out_type == NETCDF_DOUBLE_TYPE)) then
if ((param%out_type == NETCDF_FLOAT_TYPE) .or. (param%out_type == NETCDF_DOUBLE_TYPE)) then
call param%nciu%open(param)
call self%write_particle_info(param%nciu)
call param%nciu%close(param)
end if

return
Expand Down Expand Up @@ -307,7 +305,9 @@ module subroutine io_dump_system(self, param)
call self%cb%write_frame(dump_param%nciu, dump_param)
call self%pl%write_frame(dump_param%nciu, dump_param)
call self%tp%write_frame(dump_param%nciu, dump_param)
call dump_param%nciu%close(dump_param)
call dump_param%nciu%close()
! Syncrhonize the disk and memory buffer of the NetCDF file (e.g. commit the frame files stored in memory to disk)
call param%nciu%sync()
end if

idx = idx + 1
Expand Down Expand Up @@ -1856,9 +1856,7 @@ module subroutine io_write_discard(self, param)

! Record the discarded body metadata information to file
if ((param%out_type == NETCDF_FLOAT_TYPE) .or. (param%out_type == NETCDF_DOUBLE_TYPE)) then
call param%nciu%open(param)
call tp_discards%write_particle_info(param%nciu)
call param%nciu%close(param)
end if

if (param%discard_out == "") return
Expand Down Expand Up @@ -2176,7 +2174,7 @@ module subroutine io_write_frame_system(self, param)

lfirst = .false.
else
call param%nciu%open(param)
!call param%nciu%open(param)
end if
end if

Expand All @@ -2202,7 +2200,6 @@ module subroutine io_write_frame_system(self, param)
call cb%write_frame(param%nciu, param)
call pl%write_frame(param%nciu, param)
call tp%write_frame(param%nciu, param)
call param%nciu%close(param)
end if

return
Expand Down
19 changes: 11 additions & 8 deletions src/kick/kick.f90
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,18 @@ module subroutine kick_getacch_int_pl(self, param)
character(len=STRMAX) :: tstr, nstr, cstr, mstr, lstyle
character(len=1) :: schar


if (param%ladaptive_interactions) then
if (lfirst) then
write(itimer%loopname, *) "kick_getacch_int_pl"
write(itimer%looptype, *) "INTERACTION"
call itimer%time_this_loop(param, self, self%nplpl)
lfirst = .false.
if (self%nplpl > 0) then
if (lfirst) then
write(itimer%loopname, *) "kick_getacch_int_pl"
write(itimer%looptype, *) "INTERACTION"
call itimer%time_this_loop(param, self, self%nplpl)
lfirst = .false.
else
if (itimer%check(param, self%nplpl)) call itimer%time_this_loop(param, self, self%nplpl)
end if
else
if (itimer%check(param, self%nplpl)) call itimer%time_this_loop(param, self, self%nplpl)
param%lflatten_interactions = .false.
end if
end if

Expand All @@ -37,7 +40,7 @@ module subroutine kick_getacch_int_pl(self, param)
call kick_getacch_int_all_triangular_pl(self%nbody, self%nbody, self%xh, self%Gmass, self%radius, self%ah)
end if

if (param%ladaptive_interactions) then
if (param%ladaptive_interactions .and. self%nplpl > 0) then
if (itimer%is_on) call itimer%adapt(param, self, self%nplpl)
end if

Expand Down
2 changes: 2 additions & 0 deletions src/main/swiftest_driver.f90
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ program swiftest_driver
end do
end associate

call nbody_system%finalize(param)

call util_exit(SUCCESS)

stop
Expand Down
16 changes: 14 additions & 2 deletions src/modules/swiftest_classes.f90
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ module swiftest_classes
procedure :: close => netcdf_close !! Closes an open NetCDF file
procedure :: initialize => netcdf_initialize_output !! Initialize a set of parameters used to identify a NetCDF output object
procedure :: open => netcdf_open !! Opens a NetCDF file
procedure :: sync => netcdf_sync !! Syncrhonize the disk and memory buffer of the NetCDF file (e.g. commit the frame files stored in memory to disk)
end type netcdf_parameters

!********************************************************************************************************************************
Expand Down Expand Up @@ -432,6 +433,7 @@ module swiftest_classes
procedure :: read_particle_info => io_read_particle_info_system !! Read in particle metadata from file
procedure :: write_discard => io_write_discard !! Write out information about discarded test particles
procedure :: obl_pot => obl_pot_system !! Compute the contribution to the total gravitational potential due solely to the oblateness of the central body
procedure :: finalize => setup_finalize_system !! Runs any finalization subroutines when ending the simulation.
procedure :: initialize => setup_initialize_system !! Initialize the system from input files
procedure :: init_particle_info => setup_initialize_particle_info_system !! Initialize the system from input files
procedure :: step_spin => tides_step_spin_system !! Steps the spins of the massive & central bodies due to tides.
Expand Down Expand Up @@ -998,10 +1000,9 @@ module pure subroutine kick_getacch_int_one_tp(rji2, xr, yr, zr, Gmpl, ax, ay, a
real(DP), intent(inout) :: ax, ay, az !! Acceleration vector components of test particle
end subroutine kick_getacch_int_one_tp

module subroutine netcdf_close(self, param)
module subroutine netcdf_close(self)
implicit none
class(netcdf_parameters), intent(inout) :: self !! Parameters used to identify a particular NetCDF dataset
class(swiftest_parameters), intent(in) :: param !! Current run configuration parameters
end subroutine netcdf_close

module function netcdf_get_old_t_final_system(self, param) result(old_t_final)
Expand All @@ -1023,6 +1024,11 @@ module subroutine netcdf_open(self, param)
class(swiftest_parameters), intent(in) :: param !! Current run configuration parameters
end subroutine netcdf_open

module subroutine netcdf_sync(self)
implicit none
class(netcdf_parameters), intent(inout) :: self !! Parameters used to identify a particular NetCDF dataset
end subroutine netcdf_sync

module function netcdf_read_frame_base(self, iu, param) result(ierr)
implicit none
class(swiftest_base), intent(inout) :: self !! Swiftest base object
Expand Down Expand Up @@ -1157,6 +1163,12 @@ module subroutine setup_encounter(self, n)
integer(I4B), intent(in) :: n !! Number of encounters to allocate space for
end subroutine setup_encounter

module subroutine setup_finalize_system(self, param)
implicit none
class(swiftest_nbody_system), intent(inout) :: self !! Swiftest system object
class(swiftest_parameters), intent(inout) :: param !! Current run configuration parameters
end subroutine setup_finalize_system

module subroutine setup_initialize_particle_info_system(self, param)
implicit none
class(swiftest_nbody_system), intent(inout) :: self !! Swiftest nbody system object
Expand Down
23 changes: 17 additions & 6 deletions src/netcdf/netcdf.f90
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,13 @@ subroutine check(status)
return
end subroutine check

module subroutine netcdf_close(self, param)
module subroutine netcdf_close(self)
!! author: Carlisle A. Wishard, Dana Singh, and David A. Minton
!!
!! Closes a NetCDF file
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

call check( nf90_close(self%ncid) )

Expand Down Expand Up @@ -446,7 +445,7 @@ module function netcdf_read_frame_system(self, iu, param) result(ierr)
call self%cb%read_in(param)
call self%pl%read_in(param)
call self%tp%read_in(param)
call iu%close(param)
call iu%close()

ierr = 0
return
Expand Down Expand Up @@ -500,6 +499,21 @@ module subroutine netcdf_read_hdr_system(self, iu, param)
return
end subroutine netcdf_read_hdr_system


module subroutine netcdf_sync(self)
!! author: David A. Minton
!!
!! Syncrhonize the disk and memory buffer of the NetCDF file (e.g. commit the frame files stored in memory to disk)
!!
implicit none
! Arguments
class(netcdf_parameters), intent(inout) :: self !! Parameters used to identify a particular NetCDF dataset

call check( nf90_sync(self%ncid) )

return
end subroutine netcdf_sync

module subroutine netcdf_write_frame_base(self, iu, param)
!! author: Carlisle A. Wishard, Dana Singh, and David A. Minton
!!
Expand Down Expand Up @@ -610,13 +624,10 @@ module subroutine netcdf_write_frame_system(self, iu, param)
class(netcdf_parameters), intent(inout) :: iu !! Parameters used to identify a particular NetCDF dataset
class(swiftest_parameters), intent(in) :: param !! Current run configuration parameters

call iu%open(param)

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 iu%close(param)

return
end subroutine netcdf_write_frame_system
Expand Down
21 changes: 21 additions & 0 deletions src/setup/setup.f90
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,27 @@ module subroutine setup_encounter(self, n)
end subroutine setup_encounter


module subroutine setup_finalize_system(self, param)
!! author: David A. Minton
!!
!! Runs any finalization subroutines when ending the simulation.
!!
implicit none
! Arguments
class(swiftest_nbody_system), intent(inout) :: self !! Swiftest system object
class(swiftest_parameters), intent(inout) :: param !! Current run configuration parameters
integer(I4B) :: ierr

associate(system => self)
if ((param%out_type == NETCDF_FLOAT_TYPE) .or. (param%out_type == NETCDF_DOUBLE_TYPE)) then
call param%nciu%close()
end if
end associate

return
end subroutine setup_finalize_system


module subroutine setup_initialize_particle_info_system(self, param)
!! author: David A. Minton
!!
Expand Down
2 changes: 0 additions & 2 deletions src/symba/symba_io.f90
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,7 @@ module subroutine symba_io_write_discard(self, param)

! Record the discarded body metadata information to file
if ((param%out_type == NETCDF_FLOAT_TYPE) .or. (param%out_type == NETCDF_DOUBLE_TYPE)) then
call param%nciu%open(param)
call pl_discards%write_particle_info(param%nciu)
call param%nciu%close(param)
end if

if (param%discard_out == "") return
Expand Down

0 comments on commit a1e785e

Please sign in to comment.