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

Commit

Permalink
Fixed issue where failed fragmentation generation still advanced the …
Browse files Browse the repository at this point in the history
…maxid counter ahead as if it succeeded, leading to gaps in the ids of bodies. Also changed the way names are saved to the info variable.
  • Loading branch information
daminton committed Sep 4, 2021
1 parent b12a40a commit aa1bcd1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 14 deletions.
23 changes: 15 additions & 8 deletions src/io/io.f90
Original file line number Diff line number Diff line change
Expand Up @@ -1022,12 +1022,14 @@ module subroutine io_read_in_cb(self, param)
integer(I4B) :: iu = LUN
character(len=STRMAX) :: errmsg
integer(I4B) :: ierr, idold
character(len=NAMELEN) :: name

if (param%in_type == 'ASCII') then
self%id = 0
param%maxid = 0
open(unit = iu, file = param%incbfile, status = 'old', form = 'FORMATTED', err = 667, iomsg = errmsg)
read(iu, *, err = 667, iomsg = errmsg) self%info%name
read(iu, *, err = 667, iomsg = errmsg) name
call self%info%set_value(name=name)
read(iu, *, err = 667, iomsg = errmsg) self%Gmass
self%mass = real(self%Gmass / param%GU, kind=DP)
read(iu, *, err = 667, iomsg = errmsg) self%radius
Expand Down Expand Up @@ -1133,6 +1135,7 @@ module function io_read_frame_body(self, iu, param) result(ierr)
integer(I4B) :: ierr !! Error code: returns 0 if the read is successful
! Internals
character(len=STRMAX) :: errmsg
character(len=NAMELEN), dimension(self%nbody) :: name
integer(I4B) :: i
real(QP) :: val

Expand All @@ -1157,9 +1160,10 @@ module function io_read_frame_body(self, iu, param) result(ierr)
select case(param%in_type)
case (REAL4_TYPE, REAL8_TYPE)
read(iu, err = 667, iomsg = errmsg) self%id(:)
associate(name => self%info%name)
read(iu, err = 667, iomsg = errmsg) name(:)
end associate
read(iu, err = 667, iomsg = errmsg) name(:)
do i = 1, n
call self%info(i)%set_value(name=name(i))
end do

select case (param%in_form)
case (XV)
Expand Down Expand Up @@ -1205,10 +1209,11 @@ module function io_read_frame_body(self, iu, param) result(ierr)
select type(self)
class is (swiftest_pl)
if (param%lrhill_present) then
read(iu, *, err = 667, iomsg = errmsg) self%info(i)%name, val, self%rhill(i)
read(iu, *, err = 667, iomsg = errmsg) name(i), val, self%rhill(i)
else
read(iu, *, err = 667, iomsg = errmsg) self%info(i)%name, val
read(iu, *, err = 667, iomsg = errmsg) name(i), val
end if
call self%info(i)%set_value(name=name(i))
self%Gmass(i) = real(val, kind=DP)
self%mass(i) = real(val / param%GU, kind=DP)
read(iu, *, err = 667, iomsg = errmsg) self%radius(i)
Expand Down Expand Up @@ -1280,10 +1285,12 @@ module function io_read_frame_cb(self, iu, param) result(ierr)
! Result
integer(I4B) :: ierr !! Error code: returns 0 if the read is successful
! Internals
character(len=STRMAX) :: errmsg
character(len=STRMAX) :: errmsg
character(len=NAMELEN) :: name

read(iu, err = 667, iomsg = errmsg) self%id
read(iu, err = 667, iomsg = errmsg) self%info%name
read(iu, err = 667, iomsg = errmsg) name
call self%info%set_value(name=name)
read(iu, err = 667, iomsg = errmsg) self%Gmass
self%mass = self%Gmass / param%GU
read(iu, err = 667, iomsg = errmsg) self%radius
Expand Down
12 changes: 6 additions & 6 deletions src/symba/symba_collision.f90
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ module function symba_collision_casedisruption(system, param, colliders, frag)
! Collisional fragments will be uniformly distributed around the pre-impact barycenter
call frag%setup(nfrag, param)
call frag%set_mass_dist(colliders)
frag%id(1:nfrag) = [(i, i = param%maxid + 1, param%maxid + nfrag)]
param%maxid = frag%id(nfrag)

! Generate the position and velocity distributions of the fragments
call frag%generate_fragments(colliders, system, param, lfailure)
Expand All @@ -63,6 +61,8 @@ module function symba_collision_casedisruption(system, param, colliders, frag)
case(COLLRESOLVE_REGIME_SUPERCATASTROPHIC)
status = SUPERCATASTROPHIC
end select
frag%id(1:nfrag) = [(i, i = param%maxid + 1, param%maxid + nfrag)]
param%maxid = frag%id(nfrag)
call symba_collision_mergeaddsub(system, param, colliders, frag, status)
end if

Expand Down Expand Up @@ -110,10 +110,6 @@ module function symba_collision_casehitandrun(system, param, colliders, frag) r
lpure = .false.
call frag%setup(nfrag, param)
call frag%set_mass_dist(colliders)
ibiggest = colliders%idx(maxloc(system%pl%Gmass(colliders%idx(:)), dim=1))
frag%id(1) = system%pl%id(ibiggest)
frag%id(2:nfrag) = [(i, i = param%maxid + 1, param%maxid + nfrag - 1)]
param%maxid = frag%id(nfrag)

! Generate the position and velocity distributions of the fragments
call frag%generate_fragments(colliders, system, param, lpure)
Expand All @@ -135,6 +131,10 @@ module function symba_collision_casehitandrun(system, param, colliders, frag) r
pl%lcollision(colliders%idx(:)) = .false.
end select
else
ibiggest = colliders%idx(maxloc(system%pl%Gmass(colliders%idx(:)), dim=1))
frag%id(1) = system%pl%id(ibiggest)
frag%id(2:nfrag) = [(i, i = param%maxid + 1, param%maxid + nfrag - 1)]
param%maxid = frag%id(nfrag)
status = HIT_AND_RUN_DISRUPT
call symba_collision_mergeaddsub(system, param, colliders, frag, status)
end if
Expand Down

0 comments on commit aa1bcd1

Please sign in to comment.