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

Commit

Permalink
Fixed indexing issue in the shgrav acceleration calculation and fixed…
Browse files Browse the repository at this point in the history
… some issues when recording discards
  • Loading branch information
daminton committed Feb 27, 2024
1 parent 2793724 commit c42fdf4
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 13 deletions.
3 changes: 1 addition & 2 deletions examples/spherical_harmonics_cb/spherical_harmonics_cb.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,10 @@
capm_tp = rng.uniform(0.0, 360.0, ntp)

sim.add_body(name=name_tp, a=a_tp, e=e_tp, inc=inc_tp, capom=capom_tp, omega=omega_tp, capm=capm_tp)
sim.set_parameter(tstart=0.0, tstop=5.0e2, dt=0.01, istep_out=100, dump_cadence=0, compute_conservation_values=True, mtiny=mtiny)
sim.set_parameter(tstart=0.0, tstop=1.0, dt=0.01, istep_out=1, dump_cadence=0, compute_conservation_values=True, mtiny=mtiny)

# Display the run configuration parameters.
sim.get_parameter()
sim.save()

# Run the simulation. Arguments may be defined here or thorugh the swiftest.Simulation() method.
sim.run()
4 changes: 2 additions & 2 deletions src/shgrav/shgrav_accel.f90
Original file line number Diff line number Diff line change
Expand Up @@ -158,14 +158,14 @@ module subroutine shgrav_acc(body, nbody_system)
class is (swiftest_pl)
do i = 1, body%nbody
if (body%lmask(i)) then
call shgrav_g_acc_one(cb%Gmass, cb%radius, cb%rotphase, body%rh(:,i), cb%c_lm, body%aobl, &
call shgrav_g_acc_one(cb%Gmass, cb%radius, cb%rotphase, body%rh(:,i), cb%c_lm, body%aobl(:,i), &
GMpl=body%Gmass(i), aoblcb=cb%aobl)
end if
end do
class is (swiftest_tp)
do i = 1, body%nbody
if (body%lmask(i)) then
call shgrav_g_acc_one(cb%Gmass, cb%radius, cb%rotphase, body%rh(:,i), cb%c_lm, body%aobl)
call shgrav_g_acc_one(cb%Gmass, cb%radius, cb%rotphase, body%rh(:,i), cb%c_lm, body%aobl(:,i))
end if
end do
end select
Expand Down
21 changes: 14 additions & 7 deletions src/swiftest/swiftest_discard.f90
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,18 @@ module subroutine swiftest_discard_system(self, param)
end if

if (ltp_discards.or.lpl_discards) then
! Advance the collision id number and save it
collider%maxid_collision = collider%maxid_collision + 1
collider%collision_id = collider%maxid_collision
collider%impactors%regime = COLLRESOLVE_REGIME_MERGE
write(idstr,*) collider%collision_id
call swiftest_io_log_one_message(COLLISION_LOG_OUT, "collision_id " // trim(adjustl(idstr)))

if (ltp_discards) then
allocate(ldiscard, source=tp%ldiscard(:))
do i = 1, ntp
if (ldiscard(i)) call tp%info(i)%set_value(collision_id=collider%collision_id)
end do
allocate(tpsub, mold=tp)
call tp%spill(tpsub, ldiscard, ldestructive=.true.)
nsub = tpsub%nbody
Expand All @@ -70,6 +80,9 @@ module subroutine swiftest_discard_system(self, param)
! simply used to trigger a snapshot.
if (param%lenergy) call self%conservation_report(param, lterminal=.false.)
allocate(ldiscard, source=pl%ldiscard(:))
do i = 1, npl
if (ldiscard(i)) call pl%info(i)%set_value(collision_id=collider%collision_id)
end do
allocate(plsub, mold=pl)
call pl%spill(plsub, ldiscard, ldestructive=.false.)
nsub = plsub%nbody
Expand All @@ -86,13 +99,7 @@ module subroutine swiftest_discard_system(self, param)
end select
call pl_discards%setup(0,param)
end if
! Advance the collision id number and save it
collider%maxid_collision = max(collider%maxid_collision, maxval(nbody_system%pl%info(:)%collision_id))
collider%maxid_collision = collider%maxid_collision + 1
collider%collision_id = collider%maxid_collision
collider%impactors%regime = COLLRESOLVE_REGIME_MERGE
write(idstr,*) collider%collision_id
call swiftest_io_log_one_message(COLLISION_LOG_OUT, "collision_id " // trim(adjustl(idstr)))


call collision_history%take_snapshot(param,nbody_system, t, "particle")
end if
Expand Down
3 changes: 1 addition & 2 deletions src/swiftest/swiftest_obl.f90
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,6 @@ module subroutine swiftest_non_spherical_cb_acc_pl(self, nbody_system)
end associate

return

end subroutine swiftest_non_spherical_cb_acc_pl


Expand Down Expand Up @@ -289,8 +288,8 @@ module subroutine swiftest_non_spherical_cb_acc_tp(self, nbody_system)
end do

end associate
return

return
end subroutine swiftest_non_spherical_cb_acc_tp


Expand Down

0 comments on commit c42fdf4

Please sign in to comment.