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

Commit

Permalink
Getting the collision ouput data cleaned up.
Browse files Browse the repository at this point in the history
  • Loading branch information
daminton committed Dec 10, 2022
1 parent 05359b1 commit 8eeae19
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 39 deletions.
2 changes: 1 addition & 1 deletion examples/Fragmentation/Fragmentation_Movie.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ def data_stream(self, frame=0):
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, collision_save="TRAJECTORY", gmtiny=gmtiny, minimum_fragment_gmass=minimum_fragment_gmass, verbose=False)
sim.run(dt=1e-4, tstop=1.0e-3, istep_out=1, dump_cadence=0)
sim.run(dt=1e-4, tstop=1.0e-3, istep_out=1, dump_cadence=1)

print("Generating animation")
anim = AnimatedScatter(sim,movie_filename,movie_titles[style],style,nskip=1)
4 changes: 2 additions & 2 deletions python/swiftest/swiftest/simulation_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -2958,8 +2958,8 @@ def clean(self):
]
glob_files = [self.simdir.glob("**/dump_param?.in")] \
+ [self.simdir.glob("**/dump_bin?.nc")] \
+ [self.simdir.glob("**/enc*.nc")] \
+ [self.simdir.glob("**/frag*.nc")]
+ [self.simdir.glob("**/encounter_*.nc")] \
+ [self.simdir.glob("**/collision_*.nc")]

for f in old_files:
if f.exists():
Expand Down
11 changes: 5 additions & 6 deletions src/encounter/encounter_io.f90
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ module subroutine encounter_io_initialize(self, param)
logical :: fileExists
character(len=STRMAX) :: errmsg
integer(I4B) :: ndims, i
character(len=NAMELEN) :: charstring

associate(nc => self)
dfill = ieee_value(dfill, IEEE_QUIET_NAN)
Expand Down Expand Up @@ -153,7 +152,7 @@ module subroutine encounter_io_write_frame(self, nc, param)
class(swiftest_parameters), intent(inout) :: param !! Current run configuration parameters
! Internals
integer(I4B) :: i, tslot, idslot, old_mode, npl, ntp
character(len=NAMELEN) :: charstring
character(len=:), allocatable :: charstring

tslot = param%ioutput
associate(pl => self%pl, tp => self%tp)
Expand All @@ -179,9 +178,9 @@ module subroutine encounter_io_write_frame(self, nc, param)
end if

charstring = trim(adjustl(pl%info(i)%name))
call check( nf90_put_var(nc%id, nc%name_varid, charstring, start=[1, idslot], count=[NAMELEN, 1]), "encounter_io_write_frame nf90_put_var pl name_varid" )
call check( nf90_put_var(nc%id, nc%name_varid, charstring, start=[1, idslot], count=[len(charstring), 1]), "encounter_io_write_frame nf90_put_var pl name_varid" )
charstring = trim(adjustl(pl%info(i)%particle_type))
call check( nf90_put_var(nc%id, nc%ptype_varid, charstring, start=[1, idslot], count=[NAMELEN, 1]), "encounter_io_write_frame nf90_put_var pl particle_type_varid" )
call check( nf90_put_var(nc%id, nc%ptype_varid, charstring, start=[1, idslot], count=[len(charstring), 1]), "encounter_io_write_frame nf90_put_var pl particle_type_varid" )
end do

ntp = tp%nbody
Expand All @@ -192,9 +191,9 @@ module subroutine encounter_io_write_frame(self, nc, param)
call check( nf90_put_var(nc%id, nc%vh_varid, tp%vh(:,i), start=[1,idslot,tslot], count=[NDIM,1,1]), "encounter_io_write_frame nf90_put_var tp vh_varid" )

charstring = trim(adjustl(tp%info(i)%name))
call check( nf90_put_var(nc%id, nc%name_varid, charstring, start=[1, idslot], count=[NAMELEN, 1]), "encounter_io_write_frame nf90_put_var tp name_varid" )
call check( nf90_put_var(nc%id, nc%name_varid, charstring, start=[1, idslot], count=[len(charstring), 1]), "encounter_io_write_frame nf90_put_var tp name_varid" )
charstring = trim(adjustl(tp%info(i)%particle_type))
call check( nf90_put_var(nc%id, nc%ptype_varid, charstring, start=[1, idslot], count=[NAMELEN, 1]), "encounter_io_write_frame nf90_put_var tp particle_type_varid" )
call check( nf90_put_var(nc%id, nc%ptype_varid, charstring, start=[1, idslot], count=[len(charstring), 1]), "encounter_io_write_frame nf90_put_var tp particle_type_varid" )
end do

call check( nf90_set_fill(nc%id, old_mode, old_mode) )
Expand Down
11 changes: 6 additions & 5 deletions src/fraggle/fraggle_io.f90
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ module subroutine fraggle_io_initialize_output(self, param)
! Dimension coordinates
call check( nf90_def_var(nc%id, nc%space_dimname, NF90_CHAR, nc%space_dimid, nc%space_varid), "fraggle_io_initialize nf90_def_var space_varid" )
call check( nf90_def_var(nc%id, nc%id_dimname, NF90_INT, nc%id_dimid, nc%id_varid), "fraggle_io_initialize nf90_def_var id_varid" )
call check( nf90_def_var(nc%id, nc%stage_dimname, NF90_CHAR, nc%stage_dimid, nc%stage_varid), "fraggle_io_initialize nf90_def_var stage_varid" )
call check( nf90_def_var(nc%id, nc%stage_dimname, NF90_CHAR, [nc%str_dimid, nc%stage_dimid], nc%stage_varid), "fraggle_io_initialize nf90_def_var stage_varid" )

! Variables
call check( nf90_def_var(nc%id, nc%time_dimname, nc%out_type, &
Expand Down Expand Up @@ -134,7 +134,8 @@ module subroutine fraggle_io_initialize_output(self, param)

! Add in the space and stage dimension coordinates
call check( nf90_put_var(nc%id, nc%space_varid, nc%space_coords, start=[1], count=[NDIM]), "fraggle_io_initialize nf90_put_var space" )
call check( nf90_put_var(nc%id, nc%stage_varid, nc%stage_coords, start=[1], count=[2]), "fraggle_io_initialize nf90_put_var stage" )
call check( nf90_put_var(nc%id, nc%stage_varid, nc%stage_coords(1), start=[1,1], count=[len(nc%stage_coords(1)),1]), "fraggle_io_initialize nf90_put_var stage 1" )
call check( nf90_put_var(nc%id, nc%stage_varid, nc%stage_coords(2), start=[1,2], count=[len(nc%stage_coords(2)),1]), "fraggle_io_initialize nf90_put_var stage 2" )

! Pre-fill id slots with ids
call check( nf90_put_var(nc%id, nc%id_varid, [(-1,i=1,param%maxid)], start=[1], count=[param%maxid]), "fraggle_io_initialize nf90_put_varid_varid" )
Expand All @@ -160,7 +161,7 @@ module subroutine fraggle_io_write_frame(self, nc, param)
class(swiftest_parameters), intent(inout) :: param !! Current run configuration parameters
! Internals
integer(I4B) :: i, eslot, idslot, old_mode, npl
character(len=NAMELEN) :: charstring
character(len=:), allocatable :: charstring

eslot = param%ioutput
associate(pl => self%colliders%pl, colliders => self%colliders, fragments => self%fragments)
Expand All @@ -178,9 +179,9 @@ module subroutine fraggle_io_write_frame(self, nc, param)
idslot = pl%id(i)
call check( nf90_put_var(nc%id, nc%id_varid, pl%id(i), start=[ idslot ]), "fraggle_io_write_frame nf90_put_var id_varid" )
charstring = trim(adjustl(pl%info(i)%name))
call check( nf90_put_var(nc%id, nc%name_varid, charstring, start=[1, idslot], count=[NAMELEN, 1]), "fraggle_io_write_frame nf90_put_var name_varid" )
call check( nf90_put_var(nc%id, nc%name_varid, charstring, start=[1, idslot], count=[len(charstring), 1]), "fraggle_io_write_frame nf90_put_var name_varid" )
charstring = trim(adjustl(pl%info(i)%particle_type))
call check( nf90_put_var(nc%id, nc%ptype_varid, charstring, start=[1, idslot, eslot], count=[NAMELEN, 1, 1]), "fraggle_io_write_frame nf90_put_var particle_type_varid" )
call check( nf90_put_var(nc%id, nc%ptype_varid, charstring, start=[1, idslot, eslot], count=[len(charstring), 1, 1]), "fraggle_io_write_frame nf90_put_var particle_type_varid" )

call check( nf90_put_var(nc%id, nc%rh_varid, pl%rh(:,i), start=[1, idslot, 1, eslot], count=[NDIM,1,1,1]), "fraggle_io_write_frame nf90_put_var rh_varid" )
call check( nf90_put_var(nc%id, nc%vh_varid, pl%vh(:,i), start=[1, idslot, 1, eslot], count=[NDIM,1,1,1]), "fraggle_io_write_frame nf90_put_var vh_varid" )
Expand Down
2 changes: 1 addition & 1 deletion src/modules/fraggle_classes.f90
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ module fraggle_classes
integer(I4B) :: stage_dimid !! ID for the stage dimension
integer(I4B) :: stage_varid !! ID for the stage variable
character(NAMELEN) :: stage_dimname = "stage" !! name of the stage dimension (before/after)
character(len=6), dimension(2) :: stage_coords = ["before", "after "] !! The stage coordinate labels
character(len=6), dimension(2) :: stage_coords = ["before", "after"] !! The stage coordinate labels

character(NAMELEN) :: event_dimname = "collision" !! Name of collision event dimension
integer(I4B) :: event_dimid !! ID for the collision event dimension
Expand Down
14 changes: 7 additions & 7 deletions src/netcdf/netcdf.f90
Original file line number Diff line number Diff line change
Expand Up @@ -1163,7 +1163,7 @@ module subroutine netcdf_write_info_base(self, nc, param)
! Internals
integer(I4B) :: i, j, idslot, old_mode
integer(I4B), dimension(:), allocatable :: ind
character(len=NAMELEN) :: charstring
character(len=:), allocatable :: 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(nc%id, nf90_nofill, old_mode), "netcdf_write_info_base nf90_set_fill nf90_nofill" )
Expand All @@ -1180,14 +1180,14 @@ module subroutine netcdf_write_info_base(self, nc, param)
call check( nf90_put_var(nc%id, nc%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(nc%id, nc%name_varid, charstring, start=[1, idslot], count=[NAMELEN, 1]), "netcdf_write_info_base nf90_put_var name_varid" )
call check( nf90_put_var(nc%id, nc%name_varid, charstring, start=[1, idslot], count=[len(charstring), 1]), "netcdf_write_info_base nf90_put_var name_varid" )

charstring = trim(adjustl(self%info(j)%particle_type))
call check( nf90_put_var(nc%id, nc%ptype_varid, charstring, start=[1, idslot], count=[NAMELEN, 1]), "netcdf_write_info_base nf90_put_var particle_type_varid" )
call check( nf90_put_var(nc%id, nc%ptype_varid, charstring, start=[1, idslot], count=[len(charstring), 1]), "netcdf_write_info_base nf90_put_var particle_type_varid" )

if (param%lclose) then
charstring = trim(adjustl(self%info(j)%origin_type))
call check( nf90_put_var(nc%id, nc%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(nc%id, nc%origin_type_varid, charstring, start=[1, idslot], count=[len(charstring), 1]), "netcdf_write_info_base nf90_put_var origin_type_varid" )
call check( nf90_put_var(nc%id, nc%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(nc%id, nc%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(nc%id, nc%origin_vh_varid, self%info(j)%origin_vh(:), start=[1,idslot], count=[NDIM,1]), "netcdf_write_info_base nf90_put_var origin_vh_varid" )
Expand All @@ -1206,14 +1206,14 @@ module subroutine netcdf_write_info_base(self, nc, param)
call check( nf90_put_var(nc%id, nc%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(nc%id, nc%name_varid, charstring, start=[1, idslot], count=[NAMELEN, 1]), "netcdf_write_info_base nf90_put_var cb name_varid" )
call check( nf90_put_var(nc%id, nc%name_varid, charstring, start=[1, idslot], count=[len(charstring), 1]), "netcdf_write_info_base nf90_put_var cb name_varid" )

charstring = trim(adjustl(self%info%particle_type))
call check( nf90_put_var(nc%id, nc%ptype_varid, charstring, start=[1, idslot], count=[NAMELEN, 1]), "netcdf_write_info_base nf90_put_var cb ptype_varid" )
call check( nf90_put_var(nc%id, nc%ptype_varid, charstring, start=[1, idslot], count=[len(charstring), 1]), "netcdf_write_info_base nf90_put_var cb ptype_varid" )

if (param%lclose) then
charstring = trim(adjustl(self%info%origin_type))
call check( nf90_put_var(nc%id, nc%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(nc%id, nc%origin_type_varid, charstring, start=[1, idslot], count=[len(charstring), 1]), "netcdf_write_info_base nf90_put_var cb origin_type_varid" )

call check( nf90_put_var(nc%id, nc%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(nc%id, nc%origin_rh_varid, self%info%origin_rh(:), start=[1, idslot], count=[NDIM,1]), "netcdf_write_info_base nf90_put_var cb origin_rh_varid" )
Expand Down
37 changes: 20 additions & 17 deletions src/symba/symba_io.f90
Original file line number Diff line number Diff line change
Expand Up @@ -21,27 +21,30 @@ module subroutine symba_io_dump_encounter(self, param)
class(symba_nbody_system), intent(inout) :: self !! SyMBA nbody system object
class(symba_parameters), intent(inout) :: param !! Current run configuration parameters

if (self%encounter_history%iframe == 0) return ! No enounters in this interval

associate(encounter_history => self%encounter_history, nce => self%encounter_history%nc, eframe => self%encounter_history%iframe,&
collision_history => self%collision_history, ncc => self%collision_history%nc, cframe => self%collision_history%iframe)

! Create and save the output files for this encounter and fragmentation
nce%file_number = nce%file_number + 1
nce%time_dimsize = maxval(encounter_history%tslot(:))
write(nce%file_name, '("encounter_",I0.6,".nc")') nce%file_number
call nce%initialize(param)
call encounter_history%dump(param)
call nce%close()
call encounter_history%reset()

ncc%file_number = ncc%file_number + 1
write(ncc%file_name, '("collision_",I0.6,".nc")') ncc%file_number
ncc%time_dimsize = maxval(collision_history%tslot(:))
call ncc%initialize(param)
call collision_history%dump(param)
call ncc%close()
call collision_history%reset()
if (encounter_history%iframe > 0) then
! Create and save the output files for this encounter and fragmentation
nce%file_number = nce%file_number + 1
nce%time_dimsize = maxval(encounter_history%tslot(:))
write(nce%file_name, '("encounter_",I0.6,".nc")') nce%file_number
call nce%initialize(param)
call encounter_history%dump(param)
call nce%close()
call encounter_history%reset()
end if

if (collision_history%iframe > 0) then
ncc%file_number = ncc%file_number + 1
write(ncc%file_name, '("collision_",I0.6,".nc")') ncc%file_number
ncc%time_dimsize = maxval(collision_history%tslot(:))
call ncc%initialize(param)
call collision_history%dump(param)
call ncc%close()
call collision_history%reset()
end if
end associate

return
Expand Down

0 comments on commit 8eeae19

Please sign in to comment.