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

Commit

Permalink
Added RMVS sorting methods and cleaned up some comment typos and form…
Browse files Browse the repository at this point in the history
…atting
  • Loading branch information
daminton committed Jul 28, 2021
1 parent 2536428 commit 952ffc8
Show file tree
Hide file tree
Showing 7 changed files with 208 additions and 38 deletions.
84 changes: 57 additions & 27 deletions src/modules/rmvs_classes.f90
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,15 @@ module rmvs_classes
integer(I4B) :: ipleP !! index value of encountering planet
logical :: lplanetocentric = .false. !! Flag that indicates that the object is a planetocentric set of masive bodies used for close encounter calculations
contains
procedure :: discard => rmvs_discard_tp !! Check to see if test particles should be discarded based on pericenter passage distances with respect to planets encountered
procedure :: encounter_check => rmvs_encounter_check_tp !! Checks if any test particles are undergoing a close encounter with a massive body
procedure :: fill => rmvs_util_fill_tp !! "Fills" bodies from one object into another depending on the results of a mask (uses the MERGE intrinsic)
procedure :: accel => rmvs_kick_getacch_tp !! Calculates either the standard or modified version of the acceleration depending if the
!! if the test particle is undergoing a close encounter or not
procedure :: setup => rmvs_setup_tp !! Constructor method - Allocates space for number of particles
procedure :: spill => rmvs_util_spill_tp !! "Spills" bodies from one object to another depending on the results of a mask (uses the PACK intrinsic)
procedure :: discard => rmvs_discard_tp !! Check to see if test particles should be discarded based on pericenter passage distances with respect to planets encountered
procedure :: encounter_check => rmvs_encounter_check_tp !! Checks if any test particles are undergoing a close encounter with a massive body
procedure :: accel => rmvs_kick_getacch_tp !! Calculates either the standard or modified version of the acceleration depending if the
!! if the test particle is undergoing a close encounter or not
procedure :: setup => rmvs_setup_tp !! Constructor method - Allocates space for number of particles
procedure :: fill => rmvs_util_fill_tp !! "Fills" bodies from one object into another depending on the results of a mask (uses the MERGE intrinsic)
procedure :: sort => rmvs_util_sort_tp !! Sorts body arrays by a sortable componen
procedure :: rearrange => rmvs_util_sort_rearrange_tp !! Rearranges the order of array elements of body based on an input index array. Used in sorting methods
procedure :: spill => rmvs_util_spill_tp !! "Spills" bodies from one object to another depending on the results of a mask (uses the PACK intrinsic)
end type rmvs_tp

!********************************************************************************************************************************
Expand All @@ -89,9 +91,11 @@ module rmvs_classes
class(rmvs_nbody_system), dimension(:), allocatable :: planetocentric !! Planetocentric version of the massive body objects (one for each massive body)
logical :: lplanetocentric = .false. !! Flag that indicates that the object is a planetocentric set of masive bodies used for close encounter calculations
contains
procedure :: fill => rmvs_util_fill_pl !! "Fills" bodies from one object into another depending on the results of a mask (uses the MERGE intrinsic)
procedure :: setup => rmvs_setup_pl !! Constructor method - Allocates space for number of particles
procedure :: spill => rmvs_util_spill_pl !! "Spills" bodies from one object to another depending on the results of a mask (uses the PACK intrinsic)
procedure :: setup => rmvs_setup_pl !! Constructor method - Allocates space for number of particles
procedure :: sort => rmvs_util_sort_pl !! Sorts body arrays by a sortable componen
procedure :: rearrange => rmvs_util_sort_rearrange_pl !! Rearranges the order of array elements of body based on an input index array. Used in sorting methods
procedure :: fill => rmvs_util_fill_pl !! "Fills" bodies from one object into another depending on the results of a mask (uses the MERGE intrinsic)
procedure :: spill => rmvs_util_spill_pl !! "Spills" bodies from one object to another depending on the results of a mask (uses the PACK intrinsic)
end type rmvs_pl

interface
Expand All @@ -117,22 +121,6 @@ module function rmvs_encounter_check_tp(self, system, dt) result(lencounter)
logical :: lencounter !! Returns true if there is at least one close encounter
end function rmvs_encounter_check_tp

module subroutine rmvs_util_fill_pl(self, inserts, lfill_list)
use swiftest_classes, only : swiftest_body
implicit none
class(rmvs_pl), intent(inout) :: self !! RMVS massive body object
class(swiftest_body), intent(inout) :: inserts !! Inserted object
logical, dimension(:), intent(in) :: lfill_list !! Logical array of bodies to merge into the keeps
end subroutine rmvs_util_fill_pl

module subroutine rmvs_util_fill_tp(self, inserts, lfill_list)
use swiftest_classes, only : swiftest_body
implicit none
class(rmvs_tp), intent(inout) :: self !! RMVS massive body object
class(swiftest_body), intent(inout) :: inserts !! Inserted object
logical, dimension(:), intent(in) :: lfill_list !! Logical array of bodies to merge into the keeps
end subroutine rmvs_util_fill_tp

module subroutine rmvs_kick_getacch_tp(self, system, param, t, lbeg)
use swiftest_classes, only : swiftest_nbody_system, swiftest_parameters
implicit none
Expand Down Expand Up @@ -162,10 +150,52 @@ module subroutine rmvs_setup_tp(self,n)
integer, intent(in) :: n !! Number of test particles to allocate
end subroutine rmvs_setup_tp

module subroutine rmvs_util_fill_pl(self, inserts, lfill_list)
use swiftest_classes, only : swiftest_body
implicit none
class(rmvs_pl), intent(inout) :: self !! RMVS massive body object
class(swiftest_body), intent(inout) :: inserts !! Inserted object
logical, dimension(:), intent(in) :: lfill_list !! Logical array of bodies to merge into the keeps
end subroutine rmvs_util_fill_pl

module subroutine rmvs_util_fill_tp(self, inserts, lfill_list)
use swiftest_classes, only : swiftest_body
implicit none
class(rmvs_tp), intent(inout) :: self !! RMVS massive body object
class(swiftest_body), intent(inout) :: inserts !! Inserted object
logical, dimension(:), intent(in) :: lfill_list !! Logical array of bodies to merge into the keeps
end subroutine rmvs_util_fill_tp

module subroutine rmvs_util_sort_pl(self, sortby, ascending)
implicit none
class(rmvs_pl), intent(inout) :: self !! RMVS massive body object
character(*), intent(in) :: sortby !! Sorting attribute
logical, intent(in) :: ascending !! Logical flag indicating whether or not the sorting should be in ascending or descending order
end subroutine rmvs_util_sort_pl

module subroutine rmvs_util_sort_tp(self, sortby, ascending)
implicit none
class(rmvs_tp), intent(inout) :: self !! RMVS test particle object
character(*), intent(in) :: sortby !! Sorting attribute
logical, intent(in) :: ascending !! Logical flag indicating whether or not the sorting should be in ascending or descending order
end subroutine rmvs_util_sort_tp

module subroutine rmvs_util_sort_rearrange_pl(self, ind)
implicit none
class(rmvs_pl), intent(inout) :: self !! RMVS massive body object
integer(I4B), dimension(:), intent(in) :: ind !! Index array used to restructure the body (should contain all 1:n index values in the desired order)
end subroutine rmvs_util_sort_rearrange_pl

module subroutine rmvs_util_sort_rearrange_tp(self, ind)
implicit none
class(rmvs_tp), intent(inout) :: self !! RMVS test particle object
integer(I4B), dimension(:), intent(in) :: ind !! Index array used to restructure the body (should contain all 1:n index values in the desired order)
end subroutine rmvs_util_sort_rearrange_tp

module subroutine rmvs_util_spill_pl(self, discards, lspill_list)
use swiftest_classes, only : swiftest_body
implicit none
class(rmvs_pl), intent(inout) :: self !! RMVS massive body object
class(rmvs_pl), intent(inout) :: self !! RMVS massive body object
class(swiftest_body), intent(inout) :: discards !! Discarded object
logical, dimension(:), intent(in) :: lspill_list !! Logical array of bodies to spill into the discards
end subroutine rmvs_util_spill_pl
Expand Down
4 changes: 2 additions & 2 deletions src/modules/symba_classes.f90
Original file line number Diff line number Diff line change
Expand Up @@ -316,13 +316,13 @@ end subroutine symba_setup_pl

module subroutine symba_setup_pltpenc(self,n)
implicit none
class(symba_pltpenc), intent(inout) :: self !! Symba pl-tp encounter structure
class(symba_pltpenc), intent(inout) :: self !! SyMBA pl-tp encounter structure
integer, intent(in) :: n !! Number of encounters to allocate space for
end subroutine symba_setup_pltpenc

module subroutine symba_setup_plplenc(self,n)
implicit none
class(symba_plplenc), intent(inout) :: self !! Symba pl-tp encounter structure
class(symba_plplenc), intent(inout) :: self !! SyMBA pl-tp encounter structure
integer, intent(in) :: n !! Number of encounters to allocate space for
end subroutine symba_setup_plplenc

Expand Down
130 changes: 130 additions & 0 deletions src/rmvs/rmvs_util.f90
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,136 @@ module subroutine rmvs_util_fill_tp(self, inserts, lfill_list)
return
end subroutine rmvs_util_fill_tp

module subroutine rmvs_util_sort_pl(self, sortby, ascending)
!! author: David A. Minton
!!
!! Sort a RMVS massive body object in-place.
!! sortby is a string indicating which array component to sort.
implicit none
! Arguments
class(rmvs_pl), intent(inout) :: self !! RMVS massive body object
character(*), intent(in) :: sortby !! Sorting attribute
logical, intent(in) :: ascending !! Logical flag indicating whether or not the sorting should be in ascending or descending order
! Internals
integer(I4B), dimension(self%nbody) :: ind
integer(I4B) :: direction

if (ascending) then
direction = 1
else
direction = -1
end if

associate(pl => self, npl => self%nbody)
select case(sortby)
case("nenc")
call util_sort(direction * pl%nenc(1:npl), ind(1:npl))
case("tpenc1P")
call util_sort(direction * pl%tpenc1P(1:npl), ind(1:npl))
case("plind")
call util_sort(direction * pl%plind(1:npl), ind(1:npl))
case("outer", "inner", "planetocentric", "lplanetocentric")
write(*,*) 'Cannot sort by ' // trim(adjustl(sortby)) // '. Component not sortable!'
case default ! Look for components in the parent class
call whm_util_sort_pl(pl, sortby, ascending)
return
end select

call pl%rearrange(ind)

end associate
return
end subroutine rmvs_util_sort_pl

module subroutine rmvs_util_sort_tp(self, sortby, ascending)
!! author: David A. Minton
!!
!! Sort a RMVS test particle object in-place.
!! sortby is a string indicating which array component to sort.
implicit none
! Arguments
class(rmvs_tp), intent(inout) :: self !! RMVS test particle object
character(*), intent(in) :: sortby !! Sorting attribute
logical, intent(in) :: ascending !! Logical flag indicating whether or not the sorting should be in ascending or descending order
! Internals
integer(I4B), dimension(self%nbody) :: ind
integer(I4B) :: direction

if (ascending) then
direction = 1
else
direction = -1
end if

associate(tp => self, ntp => self%nbody)
select case(sortby)
case("plperP")
call util_sort(direction * tp%plperP(1:ntp), ind(1:ntp))
case("plencP")
call util_sort(direction * tp%plencP(1:ntp), ind(1:ntp))
case("lperi", "cb_heliocentric", "xheliocentric", "index", "ipleP", "lplanetocentric")
write(*,*) 'Cannot sort by ' // trim(adjustl(sortby)) // '. Component not sortable!'
case default ! Look for components in the parent class (*NOTE whm_tp does not need its own sort method, so we go straight to the swiftest_tp method)
call util_sort_tp(tp, sortby, ascending)
return
end select

call tp%rearrange(ind)

end associate
return
end subroutine rmvs_util_sort_tp

module subroutine rmvs_util_sort_rearrange_pl(self, ind)
!! author: David A. Minton
!!
!! Rearrange RMVS massive body structure in-place from an index list.
!! This is a helper utility used to make polymorphic sorting work on Swiftest structures.
implicit none
! Arguments
class(rmvs_pl), intent(inout) :: self !! RMVS massive body object
integer(I4B), dimension(:), intent(in) :: ind !! Index array used to restructure the body (should contain all 1:n index values in the desired order)
! Internals
class(rmvs_pl), allocatable :: pl_sorted !! Temporary holder for sorted body
integer(I4B) :: i

associate(pl => self, npl => self%nbody)
call util_sort_rearrange_pl(pl,ind)
allocate(pl_sorted, source=self)
pl%eta(1:npl) = pl_sorted%eta(ind(1:npl))
pl%xj(:,1:npl) = pl_sorted%xj(:,ind(1:npl))
pl%vj(:,1:npl) = pl_sorted%vj(:,ind(1:npl))
pl%muj(1:npl) = pl_sorted%muj(ind(1:npl))
pl%ir3j(1:npl) = pl_sorted%ir3j(ind(1:npl))
deallocate(pl_sorted)
end associate
return
end subroutine rmvs_util_sort_rearrange_pl

module subroutine rmvs_util_sort_rearrange_tp(self, ind)
!! author: David A. Minton
!!
!! Rearrange RMVS test particle object in-place from an index list.
!! This is a helper utility used to make polymorphic sorting work on Swiftest structures.
implicit none
! Arguments
class(rmvs_tp), intent(inout) :: self !! RMVS test particle object
integer(I4B), dimension(:), intent(in) :: ind !! Index array used to restructure the body (should contain all 1:n index values in the desired order)
! Internals
class(rmvs_tp), allocatable :: tp_sorted !! Temporary holder for sorted body

associate(tp => self, ntp => self%nbody)
call util_sort_rearrange_tp(tp,ind)
allocate(tp_sorted, source=self)
tp%lperi(1:ntp) = tp_sorted%lperi(ind(1:ntp))
tp%plperP(1:ntp) = tp_sorted%plperP(ind(1:ntp))
tp%plencP(1:ntp) = tp_sorted%plencP(ind(1:ntp))
tp%xheliocentric(:,1:ntp) = tp_sorted%xheliocentric(:,ind(1:ntp))
deallocate(tp_sorted)
end associate
return
end subroutine rmvs_util_sort_rearrange_tp

module subroutine rmvs_util_spill_pl(self, discards, lspill_list)
!! author: David A. Minton
!!
Expand Down
4 changes: 2 additions & 2 deletions src/symba/symba_setup.f90
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ module subroutine symba_setup_pltpenc(self, n)
!!
implicit none
! Arguments
class(symba_pltpenc), intent(inout) :: self !! Symba pl-tp encounter structure
class(symba_pltpenc), intent(inout) :: self !! SyMBA pl-tp encounter structure
integer, intent(in) :: n !! Number of encounters to allocate space for

self%nenc = n
Expand Down Expand Up @@ -80,7 +80,7 @@ module subroutine symba_setup_plplenc(self,n)
!
implicit none
! Arguments
class(symba_plplenc), intent(inout) :: self !! Symba pl-tp encounter structure
class(symba_plplenc), intent(inout) :: self !! SyMBA pl-tp encounter structure
integer, intent(in) :: n !! Number of encounters to allocate space for

call symba_setup_pltpenc(self, n)
Expand Down
10 changes: 6 additions & 4 deletions src/symba/symba_util.f90
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,9 @@ module subroutine symba_util_sort_pl(self, sortby, ascending)
call util_sort(direction * pl%peri(1:npl), ind(1:npl))
case("atp")
call util_sort(direction * pl%atp(1:npl), ind(1:npl))
case default
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 util_sort_pl(pl, sortby, ascending)
return
end select
Expand Down Expand Up @@ -138,7 +140,7 @@ module subroutine symba_util_sort_tp(self, sortby, ascending)
call util_sort(direction * tp%levelg(1:ntp), ind(1:ntp))
case("levelm")
call util_sort(direction * tp%levelm(1:ntp), ind(1:ntp))
case default
case default ! Look for components in the parent class
call util_sort_tp(tp, sortby, ascending)
return
end select
Expand All @@ -156,7 +158,7 @@ module subroutine symba_util_sort_rearrange_pl(self, ind)
!! This is a helper utility used to make polymorphic sorting work on Swiftest structures.
implicit none
! Arguments
class(symba_pl), intent(inout) :: self !! Symba massive body object
class(symba_pl), intent(inout) :: self !! SyMBA massive body object
integer(I4B), dimension(:), intent(in) :: ind !! Index array used to restructure the body (should contain all 1:n index values in the desired order)
! Internals
class(symba_pl), allocatable :: pl_sorted !! Temporary holder for sorted body
Expand Down Expand Up @@ -193,7 +195,7 @@ module subroutine symba_util_sort_rearrange_tp(self, ind)
!! This is a helper utility used to make polymorphic sorting work on Swiftest structures.
implicit none
! Arguments
class(symba_tp), intent(inout) :: self !! Symba massive body object
class(symba_tp), intent(inout) :: self !! SyMBA test particle object
integer(I4B), dimension(:), intent(in) :: ind !! Index array used to restructure the body (should contain all 1:n index values in the desired order)
! Internals
class(symba_tp), allocatable :: tp_sorted !! Temporary holder for sorted body
Expand Down
Loading

0 comments on commit 952ffc8

Please sign in to comment.