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

Commit

Permalink
Added new sorting methods for swiftest bodies
Browse files Browse the repository at this point in the history
  • Loading branch information
daminton committed Jul 27, 2021
1 parent 81ecfaf commit 9939662
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/modules/swiftest_classes.f90
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module swiftest_classes
public :: user_kick_getacch_body
public :: util_coord_b2h_pl, util_coord_b2h_tp, util_coord_h2b_pl, util_coord_h2b_tp, util_exit, util_fill_body, util_fill_pl, util_fill_tp, &
util_peri_tp, util_reverse_status, util_set_beg_end_pl, util_set_ir3h, util_set_msys, util_set_mu_pl, &
util_set_mu_tp, util_set_rhill, util_set_rhill_approximate, util_sort, util_spill_body, util_spill_pl, util_spill_tp, util_valid, util_version
util_set_mu_tp, util_set_rhill, util_set_rhill_approximate, util_sort, util_sort_body, util_sort_pl, util_spill_body, util_spill_pl, util_spill_tp, util_valid, util_version

!********************************************************************************************************************************
! swiftest_parameters class definitions
Expand Down Expand Up @@ -186,6 +186,7 @@ module swiftest_classes
procedure, public :: accel_user => user_kick_getacch_body !! Add user-supplied heliocentric accelerations to planets
procedure, public :: fill => util_fill_body !! "Fills" bodies from one object into another depending on the results of a mask (uses the MERGE intrinsic)
procedure, public :: spill => util_spill_body !! "Spills" bodies from one object to another depending on the results of a mask (uses the PACK intrinsic)
procedure, public :: sort => util_sort_body !! Sorts a body by an attribute (base method only allows for sorting by id. Override to add other capabilities)
procedure, public :: reverse_status => util_reverse_status !! Reverses the active/inactive status of all particles in a structure
end type swiftest_body

Expand Down Expand Up @@ -228,6 +229,7 @@ module swiftest_classes
procedure, public :: b2h => util_coord_b2h_pl !! Convert massive bodies from barycentric to heliocentric coordinates (position and velocity)
procedure, public :: fill => util_fill_pl !! "Fills" bodies from one object into another depending on the results of a mask (uses the MERGE intrinsic)
procedure, public :: set_beg_end => util_set_beg_end_pl !! Sets the beginning and ending positions and velocities of planets.
procedure, public :: sort => util_sort_pl !! Sorts a body by an attribute (adds ability to sort by mass)
procedure, public :: spill => util_spill_pl !! "Spills" bodies from one object to another depending on the results of a mask (uses the PACK intrinsic)
end type swiftest_pl

Expand Down Expand Up @@ -877,9 +879,23 @@ module subroutine util_sort_index_dp(arr,ind)
real(DP), dimension(:), intent(in) :: arr
integer(I4B), dimension(:), intent(out) :: ind
end subroutine util_sort_index_dp
end interface
end interface util_sort

interface
module subroutine util_sort_body(self, sortby, reverse)
implicit none
class(swiftest_body), intent(inout) :: self !! Swiftest body object
character(*), optional, intent(in) :: sortby !! Sorting attribute
logical, optional, intent(in) :: reverse !! Logical flag indicating whether or not the sorting should be in reverse (descending order)
end subroutine util_sort_body

module subroutine util_sort_pl(self, sortby, reverse)
implicit none
class(swiftest_pl), intent(inout) :: self !! Swiftest body object
character(*), optional, intent(in) :: sortby !! Sorting attribute
logical, optional, intent(in) :: reverse !! Logical flag indicating whether or not the sorting should be in reverse (descending order)
end subroutine util_sort_pl

module subroutine util_spill_body(self, discards, lspill_list)
implicit none
class(swiftest_body), intent(inout) :: self !! Swiftest body object
Expand Down
23 changes: 23 additions & 0 deletions src/util/util_sort.f90
Original file line number Diff line number Diff line change
@@ -1,6 +1,29 @@
submodule (swiftest_classes) s_util_sort
use swiftest
contains
module subroutine util_sort_body(self, sortby, reverse)
!! author: David A. Minton
!!
!! Sort a Swiftest body structure in-place.
!! sortby is a string. The only valid input the body class takes is "id," which is also the default value.
!! Sort order is ascending order by default. Set reverse=.true. to sort in descending order.
implicit none
class(swiftest_body), intent(inout) :: self !! Swiftest body object
character(*), optional, intent(in) :: sortby !! Sorting attribute
logical, optional, intent(in) :: reverse !! Logical flag indicating whether or not the sorting should be in reverse (descending order)
end subroutine util_sort_body

module subroutine util_sort_pl(self, sortby, reverse)
!! author: David A. Minton
!!
!! sortby is a string. The only valid input the body class takes is "id," which is also the default value.
!! Sort order is ascending order by default. Set reverse=.true. to sort in descending order.
implicit none
class(swiftest_pl), intent(inout) :: self !! Swiftest body object
character(*), optional, intent(in) :: sortby !! Sorting attribute
logical, optional, intent(in) :: reverse !! Logical flag indicating whether or not the sorting should be in reverse (descending order)
end subroutine util_sort_pl

module subroutine util_sort_dp(arr)
!! author: David A. Minton
!!
Expand Down

0 comments on commit 9939662

Please sign in to comment.