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

Commit

Permalink
added in the framework to support a collision_id variable
Browse files Browse the repository at this point in the history
  • Loading branch information
cwishard committed Sep 29, 2021
1 parent ef0bbba commit 4cee753
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 20 deletions.
2 changes: 2 additions & 0 deletions src/io/io.f90
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ module subroutine io_dump_particle_info(self, iu)
write(iu, err = 667, iomsg = errmsg) self%particle_type
write(iu, err = 667, iomsg = errmsg) self%origin_type
write(iu, err = 667, iomsg = errmsg) self%origin_time
write(iu, err = 667, iomsg = errmsg) self%collision_id
write(iu, err = 667, iomsg = errmsg) self%origin_xh(:)
write(iu, err = 667, iomsg = errmsg) self%origin_vh(:)

Expand Down Expand Up @@ -1725,6 +1726,7 @@ module subroutine io_read_in_particle_info(self, iu)
read(iu, err = 667, iomsg = errmsg) self%particle_type
read(iu, err = 667, iomsg = errmsg) self%origin_type
read(iu, err = 667, iomsg = errmsg) self%origin_time
read(iu, err = 667, iomsg = errmsg) self%collision_id
read(iu, err = 667, iomsg = errmsg) self%origin_xh(:)
read(iu, err = 667, iomsg = errmsg) self%origin_vh(:)

Expand Down
5 changes: 4 additions & 1 deletion src/modules/swiftest_classes.f90
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ module swiftest_classes
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
Expand Down Expand Up @@ -178,6 +179,7 @@ module swiftest_classes
character(len=NAMELEN) :: particle_type !! String containing a description of the particle type (e.g. Central Body, Massive Body, Test Particle)
character(len=NAMELEN) :: origin_type !! String containing a description of the origin of the particle (e.g. Initial Conditions, Supercatastrophic, Disruption, etc.)
real(DP) :: origin_time !! The time of the particle's formation
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_vh !! The heliocentric velocity vector at the time of the particle's formation
real(DP) :: discard_time !! The time of the particle's discard
Expand Down Expand Up @@ -1643,14 +1645,15 @@ module subroutine util_set_mu_tp(self, cb)
class(swiftest_cb), intent(inout) :: cb !! Swiftest central body object
end subroutine util_set_mu_tp

module subroutine util_set_particle_info(self, name, particle_type, status, origin_type, origin_time, 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_xh, origin_vh, discard_time, discard_xh, discard_vh, discard_body_id)
implicit none
class(swiftest_particle_info), intent(inout) :: self
character(len=*), intent(in), optional :: name !! Non-unique name
character(len=*), intent(in), optional :: particle_type !! String containing a description of the particle type (e.g. Central Body, Massive Body, Test Particle)
character(len=*), intent(in), optional :: status !! Particle status description: Active, Merged, Fragmented, etc.
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_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
Expand Down
1 change: 1 addition & 0 deletions src/modules/swiftest_globals.f90
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ module swiftest_globals
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
Expand Down
34 changes: 19 additions & 15 deletions src/netcdf/netcdf.f90
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,8 @@ module subroutine netcdf_initialize_output(self, param)

call check( nf90_def_var(self%ncid, STATUS_VARNAME, NF90_CHAR, [self%str_dimid, self%id_dimid], self%status_varid) )
call check( nf90_def_var(self%ncid, ORIGIN_TYPE_VARNAME, NF90_CHAR, [self%str_dimid, self%id_dimid], self%origin_type_varid) )
call check( nf90_def_var(self%ncid, ORIGIN_TIME_VARNAME, self%out_type, self%id_dimid, self%origin_time_varid) )
call check( nf90_def_var(self%ncid, ORIGIN_TIME_VARNAME, self%out_type, self%id_dimid, self%collision_id_varid) )
call check( nf90_def_var(self%ncid, COLLISION_ID_VARNAME, self%out_type, self%id_dimid, self%origin_time_varid) )
call check( nf90_def_var(self%ncid, ORIGIN_XHX_VARNAME, self%out_type, self%id_dimid, self%origin_xhx_varid) )
call check( nf90_def_var(self%ncid, ORIGIN_XHY_VARNAME, self%out_type, self%id_dimid, self%origin_xhy_varid) )
call check( nf90_def_var(self%ncid, ORIGIN_XHZ_VARNAME, self%out_type, self%id_dimid, self%origin_xhz_varid) )
Expand Down Expand Up @@ -280,6 +281,7 @@ module subroutine netcdf_open(self, param)
call check( nf90_inq_varid(self%ncid, STATUS_VARNAME, self%status_varid))
call check( nf90_inq_varid(self%ncid, ORIGIN_TYPE_VARNAME, self%origin_type_varid))
call check( nf90_inq_varid(self%ncid, ORIGIN_TIME_VARNAME, self%origin_time_varid))
call check( nf90_inq_varid(self%ncid, COLLISION_ID_VARNAME, self%collision_id_varid))
call check( nf90_inq_varid(self%ncid, ORIGIN_XHX_VARNAME, self%origin_xhx_varid))
call check( nf90_inq_varid(self%ncid, ORIGIN_XHY_VARNAME, self%origin_xhy_varid))
call check( nf90_inq_varid(self%ncid, ORIGIN_XHZ_VARNAME, self%origin_xhz_varid))
Expand Down Expand Up @@ -561,13 +563,14 @@ module subroutine netcdf_read_particle_info_base(self, iu, ind)
strlen = len(trim(adjustl(self%info(i)%origin_type)))
call check( nf90_get_var(iu%ncid, iu%origin_type_varid, self%info(i)%origin_type, start=[1, idslot], count=[strlen, 1]) )

call check( nf90_get_var(iu%ncid, iu%origin_time_varid, self%info(i)%origin_time, start=[idslot]) )
call check( nf90_get_var(iu%ncid, iu%origin_xhx_varid, self%info(i)%origin_xh(1), start=[idslot]) )
call check( nf90_get_var(iu%ncid, iu%origin_xhy_varid, self%info(i)%origin_xh(2), start=[idslot]) )
call check( nf90_get_var(iu%ncid, iu%origin_xhz_varid, self%info(i)%origin_xh(3), start=[idslot]) )
call check( nf90_get_var(iu%ncid, iu%origin_vhx_varid, self%info(i)%origin_vh(1), start=[idslot]) )
call check( nf90_get_var(iu%ncid, iu%origin_vhy_varid, self%info(i)%origin_vh(2), start=[idslot]) )
call check( nf90_get_var(iu%ncid, iu%origin_vhz_varid, self%info(i)%origin_vh(3), start=[idslot]) )
call check( nf90_get_var(iu%ncid, iu%collision_id_varid, self%info(i)%collision_id, start=[idslot]) )
call check( nf90_get_var(iu%ncid, iu%origin_time_varid, self%info(i)%origin_time, start=[idslot]) )
call check( nf90_get_var(iu%ncid, iu%origin_xhx_varid, self%info(i)%origin_xh(1), start=[idslot]) )
call check( nf90_get_var(iu%ncid, iu%origin_xhy_varid, self%info(i)%origin_xh(2), start=[idslot]) )
call check( nf90_get_var(iu%ncid, iu%origin_xhz_varid, self%info(i)%origin_xh(3), start=[idslot]) )
call check( nf90_get_var(iu%ncid, iu%origin_vhx_varid, self%info(i)%origin_vh(1), start=[idslot]) )
call check( nf90_get_var(iu%ncid, iu%origin_vhy_varid, self%info(i)%origin_vh(2), start=[idslot]) )
call check( nf90_get_var(iu%ncid, iu%origin_vhz_varid, self%info(i)%origin_vh(3), start=[idslot]) )

call check( nf90_get_var(iu%ncid, iu%discard_time_varid, self%info(i)%discard_time, start=[idslot]) )
call check( nf90_get_var(iu%ncid, iu%discard_xhx_varid, self%info(i)%discard_xh(1), start=[idslot]) )
Expand Down Expand Up @@ -805,13 +808,14 @@ module subroutine netcdf_write_particle_info_base(self, iu)
call check( nf90_put_var(iu%ncid, iu%origin_type_varid, emptystr, start=[1, idslot], count=[NAMELEN, 1]) )
call check( nf90_put_var(iu%ncid, iu%origin_type_varid, charstring, start=[1, idslot], count=[strlen, 1]) )

call check( nf90_put_var(iu%ncid, iu%origin_time_varid, self%info(j)%origin_time, start=[idslot]) )
call check( nf90_put_var(iu%ncid, iu%origin_xhx_varid, self%info(j)%origin_xh(1), start=[idslot]) )
call check( nf90_put_var(iu%ncid, iu%origin_xhy_varid, self%info(j)%origin_xh(2), start=[idslot]) )
call check( nf90_put_var(iu%ncid, iu%origin_xhz_varid, self%info(j)%origin_xh(3), start=[idslot]) )
call check( nf90_put_var(iu%ncid, iu%origin_vhx_varid, self%info(j)%origin_vh(1), start=[idslot]) )
call check( nf90_put_var(iu%ncid, iu%origin_vhy_varid, self%info(j)%origin_vh(2), start=[idslot]) )
call check( nf90_put_var(iu%ncid, iu%origin_vhz_varid, self%info(j)%origin_vh(3), start=[idslot]) )
call check( nf90_put_var(iu%ncid, iu%collision_id_varid, self%info(j)%collision_id, start=[idslot]) )
call check( nf90_put_var(iu%ncid, iu%origin_time_varid, self%info(j)%origin_time, start=[idslot]) )
call check( nf90_put_var(iu%ncid, iu%origin_xhx_varid, self%info(j)%origin_xh(1), start=[idslot]) )
call check( nf90_put_var(iu%ncid, iu%origin_xhy_varid, self%info(j)%origin_xh(2), start=[idslot]) )
call check( nf90_put_var(iu%ncid, iu%origin_xhz_varid, self%info(j)%origin_xh(3), start=[idslot]) )
call check( nf90_put_var(iu%ncid, iu%origin_vhx_varid, self%info(j)%origin_vh(1), start=[idslot]) )
call check( nf90_put_var(iu%ncid, iu%origin_vhy_varid, self%info(j)%origin_vh(2), start=[idslot]) )
call check( nf90_put_var(iu%ncid, iu%origin_vhz_varid, self%info(j)%origin_vh(3), start=[idslot]) )

call check( nf90_put_var(iu%ncid, iu%discard_time_varid, self%info(j)%discard_time, start=[idslot]) )
call check( nf90_put_var(iu%ncid, iu%discard_xhx_varid, self%info(j)%discard_xh(1), start=[idslot]) )
Expand Down
7 changes: 4 additions & 3 deletions src/setup/setup.f90
Original file line number Diff line number Diff line change
Expand Up @@ -161,12 +161,12 @@ 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])
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], collision_id=0)
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))
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), collision_id=0)
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))
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), collision_id=0)
end do

end associate
Expand Down Expand Up @@ -277,6 +277,7 @@ module subroutine setup_body(self, n, param)
particle_type = "UNKNOWN", &
status = "INACTIVE", &
origin_type = "UNKNOWN", &
collision_id = 0, &
origin_time = -huge(1.0_DP), &
origin_xh = [0.0_DP, 0.0_DP, 0.0_DP], &
origin_vh = [0.0_DP, 0.0_DP, 0.0_DP], &
Expand Down
1 change: 1 addition & 0 deletions src/util/util_copy.f90
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ module subroutine util_copy_particle_info(self, source)
status = source%status, &
origin_type = source%origin_type, &
origin_time = source%origin_time, &
collision_id = source%collision_id, &
origin_xh = source%origin_xh(:), &
origin_vh = source%origin_vh(:), &
discard_time = source%discard_time, &
Expand Down
6 changes: 5 additions & 1 deletion src/util/util_set.f90
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ 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, 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_xh, origin_vh, discard_time, discard_xh, discard_vh, discard_body_id)
!! author: David A. Minton
!!
!! Sets one or more values of the particle information metadata object
Expand All @@ -110,6 +110,7 @@ module subroutine util_set_particle_info(self, name, particle_type, status, orig
character(len=*), intent(in), optional :: status !! Particle status description: ACTIVE, MERGED, FRAGMENTED, etc.
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_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
Expand Down Expand Up @@ -138,6 +139,9 @@ module subroutine util_set_particle_info(self, name, particle_type, status, orig
if (present(origin_time)) then
self%origin_time = origin_time
end if
if (present(collision_id)) then
self%collision_id = collision_id
end if
if (present(origin_xh)) then
self%origin_xh(:) = origin_xh(:)
end if
Expand Down

0 comments on commit 4cee753

Please sign in to comment.