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

Commit

Permalink
Cleaned up a bunch of lingering problems left over from transferring …
Browse files Browse the repository at this point in the history
…a bunch of symba body variables to swiftest
  • Loading branch information
daminton committed Dec 23, 2022
1 parent 10b8f2d commit ebcef5e
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 66 deletions.
2 changes: 1 addition & 1 deletion src/swiftest/swiftest_module.f90
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ module swiftest
class(encounter_list), allocatable :: plpl_encounter !! List of massive body-massive body encounters in a single step
class(collision_list_plpl), allocatable :: plpl_collision !! List of massive body-massive body collisions in a single step
class(collision_list_plpl), allocatable :: pltp_collision !! List of massive body-massive body collisions in a single step
class(collision_merge), allocatable :: collider !! Collision system object
class(collision_merge), allocatable :: collider !! Collision system object
class(encounter_storage(nframes=:)), allocatable :: encounter_history !! Stores encounter history for later retrieval and saving to file
class(collision_storage(nframes=:)), allocatable :: collision_history !! Stores encounter history for later retrieval and saving to file

Expand Down
46 changes: 25 additions & 21 deletions src/swiftest/swiftest_util.f90
Original file line number Diff line number Diff line change
Expand Up @@ -328,9 +328,7 @@ module subroutine swiftest_util_append_tp(self, source, lsource_mask)
select type(source)
class is (swiftest_tp)
associate(nold => self%nbody, nsrc => source%nbody)
call swiftest_util_append(self%isperi, source%isperi, nold, nsrc, lsource_mask)
call swiftest_util_append(self%peri, source%peri, nold, nsrc, lsource_mask)
call swiftest_util_append(self%atp, source%atp, nold, nsrc, lsource_mask)
call swiftest_util_append(self%nplenc, source%nplenc, nold, nsrc, lsource_mask)

call swiftest_util_append_body(self, source, lsource_mask)
end associate
Expand Down Expand Up @@ -806,9 +804,6 @@ module subroutine swiftest_util_dealloc_tp(self)
class(swiftest_tp), intent(inout) :: self !! Swiftest test particle object

if (allocated(self%nplenc)) deallocate(self%nplenc)
if (allocated(self%isperi)) deallocate(self%isperi)
if (allocated(self%peri)) deallocate(self%peri)
if (allocated(self%atp)) deallocate(self%atp)
if (allocated(self%k_pltp)) deallocate(self%k_pltp)

call swiftest_util_dealloc_body(self)
Expand Down Expand Up @@ -1903,6 +1898,7 @@ module subroutine swiftest_util_reset_kinship_pl(self, idx)
! Internals
integer(I4B) :: i, j


self%kin(idx(:))%parent = idx(:)
self%kin(idx(:))%nchild = 0
do j = 1, size(idx(:))
Expand Down Expand Up @@ -2777,6 +2773,9 @@ module subroutine swiftest_util_setup_body(self, n, param)
allocate(self%ah(NDIM, n))
allocate(self%ir3h(n))
allocate(self%aobl(NDIM, n))
allocate(self%isperi(n))
allocate(self%peri(n))
allocate(self%atp(n))
if (param%lclose) then
allocate(self%lcollision(n))
allocate(self%lencounter(n))
Expand Down Expand Up @@ -2813,6 +2812,9 @@ module subroutine swiftest_util_setup_body(self, n, param)
self%ah(:,:) = 0.0_DP
self%ir3h(:) = 0.0_DP
self%aobl(:,:) = 0.0_DP
self%isperi(:) = 1
self%peri(:) = 0.0_DP
self%atp(:) = 0.0_DP

if (param%ltides) then
allocate(self%atide(NDIM, n))
Expand All @@ -2837,6 +2839,8 @@ module subroutine swiftest_util_setup_pl(self, n, param)
class(swiftest_pl), intent(inout) :: self !! Swiftest massive body object
integer(I4B), intent(in) :: n !! Number of particles to allocate space for
class(swiftest_parameters), intent(in) :: param !! Current run configuration parameter
! Internals
integer(I4B) :: i

!> Call allocation method for parent class
!> The parent class here is the abstract swiftest_body class, so we can't use the type-bound procedure
Expand All @@ -2860,12 +2864,13 @@ module subroutine swiftest_util_setup_pl(self, n, param)
allocate(self%ntpenc(n))
allocate(self%radius(n))
allocate(self%density(n))
allocate(self%kin(n))

self%nplenc(:) = 0
self%ntpenc(:) = 0
self%radius(:) = 0.0_DP
self%density(:) = 1.0_DP

call self%reset_kinship([(i, i=1, n)])
end if

if (param%lmtiny_pl) then
Expand Down Expand Up @@ -2909,14 +2914,9 @@ module subroutine swiftest_util_setup_tp(self, n, param)
call swiftest_util_setup_body(self, n, param)
if (n == 0) return

allocate(self%isperi(n))
allocate(self%peri(n))
allocate(self%atp(n))
allocate(self%nplenc(n))

self%isperi(:) = 0
self%peri(:) = 0.0_DP
self%atp(:) = 0.0_DP
self%npltp = 0_I8B
self%nplenc(:) = 0

return
Expand Down Expand Up @@ -2986,7 +2986,11 @@ module subroutine swiftest_util_sort_body(self, sortby, ascending)
call swiftest_util_sort(direction * body%capom(1:n), ind)
case("mu")
call swiftest_util_sort(direction * body%mu(1:n), ind)
case("lfirst", "nbody", "ldiscard", "rh", "vh", "rb", "vb", "ah", "aobl", "atide", "agr")
case("peri")
call swiftest_util_sort(direction * body%peri(1:n), ind)
case("atp")
call swiftest_util_sort(direction * body%atp(1:n), ind)
case("info", "lfirst", "nbody", "ldiscard", "lcollision", "lencounter", "rh", "vh", "rb", "vb", "ah", "aobl", "atide", "agr","isperi")
write(*,*) 'Cannot sort by ' // trim(adjustl(sortby)) // '. Component not sortable!'
case default
write(*,*) 'Cannot sort by ' // trim(adjustl(sortby)) // '. Component not found!'
Expand Down Expand Up @@ -3625,7 +3629,11 @@ module subroutine swiftest_util_sort_pl(self, sortby, ascending)
call swiftest_util_sort(direction * pl%Q(1:npl), ind)
case("tlag")
call swiftest_util_sort(direction * pl%tlag(1:npl), ind)
case("rbeg", "rend", "vbeg", "Ip", "rot", "k_plpl", "nplpl")
case("nplenc")
call swiftest_util_sort(direction * pl%nplenc(1:npl), ind)
case("ntpenc")
call swiftest_util_sort(direction * pl%ntpenc(1:npl), ind)
case("lmtiny", "nplm", "nplplm", "kin", "rbeg", "rend", "vbeg", "Ip", "rot", "k_plpl", "nplpl")
write(*,*) 'Cannot sort by ' // trim(adjustl(sortby)) // '. Component not sortable!'
case default ! Look for components in the parent class
call swiftest_util_sort_body(pl, sortby, ascending)
Expand Down Expand Up @@ -3664,12 +3672,8 @@ module subroutine swiftest_util_sort_tp(self, sortby, ascending)

associate(tp => self, ntp => self%nbody)
select case(sortby)
case("peri")
call swiftest_util_sort(direction * tp%peri(1:ntp), ind)
case("atp")
call swiftest_util_sort(direction * tp%atp(1:ntp), ind)
case("isperi")
write(*,*) 'Cannot sort by ' // trim(adjustl(sortby)) // '. Component not sortable!'
case("nplenc")
call swiftest_util_sort(direction * tp%nplenc(1:ntp), ind)
case default ! Look for components in the parent class
call swiftest_util_sort_body(tp, sortby, ascending)
return
Expand Down
46 changes: 2 additions & 44 deletions src/symba/symba_util.f90
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,6 @@ module subroutine symba_util_dealloc_pl(self)

if (allocated(self%levelg)) deallocate(self%levelg)
if (allocated(self%levelm)) deallocate(self%levelm)
if (allocated(self%isperi)) deallocate(self%isperi)
if (allocated(self%peri)) deallocate(self%peri)
if (allocated(self%atp)) deallocate(self%atp)

call self%helio_pl%dealloc()

Expand Down Expand Up @@ -121,18 +118,9 @@ module subroutine symba_util_fill_pl(self, inserts, lfill_list)
associate(keeps => self)
select type(inserts)
class is (symba_pl)
call swiftest_util_fill(keeps%lcollision, inserts%lcollision, lfill_list)
call swiftest_util_fill(keeps%lencounter, inserts%lencounter, lfill_list)
call swiftest_util_fill(keeps%lmtiny, inserts%lmtiny, lfill_list)
call swiftest_util_fill(keeps%nplenc, inserts%nplenc, lfill_list)
call swiftest_util_fill(keeps%ntpenc, inserts%ntpenc, lfill_list)
call swiftest_util_fill(keeps%levelg, inserts%levelg, lfill_list)
call swiftest_util_fill(keeps%levelm, inserts%levelm, lfill_list)
call swiftest_util_fill(keeps%isperi, inserts%isperi, lfill_list)
call swiftest_util_fill(keeps%peri, inserts%peri, lfill_list)
call swiftest_util_fill(keeps%atp, inserts%atp, lfill_list)
call swiftest_util_fill(keeps%kin, inserts%kin, lfill_list)


call swiftest_util_fill_pl(keeps, inserts, lfill_list) ! Note: helio_pl does not have its own fill method, so we skip back to the base class
class default
write(*,*) "Invalid object passed to the fill method. Source must be of class symba_pl or its descendents!"
Expand Down Expand Up @@ -221,9 +209,6 @@ module subroutine symba_util_resize_pl(self, nnew)

call swiftest_util_resize(self%levelg, nnew)
call swiftest_util_resize(self%levelm, nnew)
call swiftest_util_resize(self%isperi, nnew)
call swiftest_util_resize(self%peri, nnew)
call swiftest_util_resize(self%atp, nnew)

call swiftest_util_resize_pl(self, nnew)

Expand Down Expand Up @@ -315,18 +300,9 @@ module subroutine symba_util_setup_pl(self, n, param)

allocate(self%levelg(n))
allocate(self%levelm(n))
allocate(self%isperi(n))
allocate(self%peri(n))
allocate(self%atp(n))
allocate(self%kin(n))


self%levelg(:) = -1
self%levelm(:) = -1
self%isperi(:) = 0
self%peri(:) = 0.0_DP
self%atp(:) = 0.0_DP
call self%reset_kinship([(i, i=1, n)])
return
end subroutine symba_util_setup_pl

Expand Down Expand Up @@ -381,20 +357,11 @@ module subroutine symba_util_sort_pl(self, sortby, ascending)

associate(pl => self, npl => self%nbody)
select case(sortby)
case("nplenc")
call swiftest_util_sort(direction * pl%nplenc(1:npl), ind)
case("ntpenc")
call swiftest_util_sort(direction * pl%ntpenc(1:npl), ind)
case("levelg")
call swiftest_util_sort(direction * pl%levelg(1:npl), ind)
case("levelm")
call swiftest_util_sort(direction * pl%levelm(1:npl), ind)
case("peri")
call swiftest_util_sort(direction * pl%peri(1:npl), ind)
case("atp")
call swiftest_util_sort(direction * pl%atp(1:npl), ind)
case("lcollision", "lencounter", "lmtiny", "nplm", "nplplm", "kin", "info")
write(*,*) 'Cannot sort by ' // trim(adjustl(sortby)) // '. Component not sortable!'

case default ! Look for components in the parent class
call swiftest_util_sort_pl(pl, sortby, ascending)
return
Expand Down Expand Up @@ -508,17 +475,8 @@ module subroutine symba_util_spill_pl(self, discards, lspill_list, ldestructive)
associate(keeps => self)
select type(discards)
class is (symba_pl)
call swiftest_util_spill(keeps%lcollision, discards%lcollision, lspill_list, ldestructive)
call swiftest_util_spill(keeps%lencounter, discards%lencounter, lspill_list, ldestructive)
call swiftest_util_spill(keeps%lmtiny, discards%lmtiny, lspill_list, ldestructive)
call swiftest_util_spill(keeps%nplenc, discards%nplenc, lspill_list, ldestructive)
call swiftest_util_spill(keeps%ntpenc, discards%ntpenc, lspill_list, ldestructive)
call swiftest_util_spill(keeps%levelg, discards%levelg, lspill_list, ldestructive)
call swiftest_util_spill(keeps%levelm, discards%levelm, lspill_list, ldestructive)
call swiftest_util_spill(keeps%isperi, discards%isperi, lspill_list, ldestructive)
call swiftest_util_spill(keeps%peri, discards%peri, lspill_list, ldestructive)
call swiftest_util_spill(keeps%atp, discards%atp, lspill_list, ldestructive)
call swiftest_util_spill(keeps%kin, discards%kin, lspill_list, ldestructive)

call swiftest_util_spill_pl(keeps, discards, lspill_list, ldestructive)
class default
Expand Down

0 comments on commit ebcef5e

Please sign in to comment.