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

Commit

Permalink
Added plpl encounter check adapted from Fragmentation branch
Browse files Browse the repository at this point in the history
  • Loading branch information
daminton committed Jul 24, 2021
1 parent 2ef9364 commit 4f30c8e
Show file tree
Hide file tree
Showing 10 changed files with 277 additions and 96 deletions.
99 changes: 83 additions & 16 deletions examples/helio_swifter_comparison/swiftest_vs_swifter.ipynb

Large diffs are not rendered by default.

21 changes: 4 additions & 17 deletions src/eucl/eucl.f90
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ module subroutine eucl_dist_index_plpl(self)
npl = int(self%nbody, kind=I8B)
associate(nplpl => self%nplpl)
nplpl = (npl * (npl - 1) / 2) ! number of entries in a strict lower triangle, nplm x npl, minus first column
if (allocated(self%k_eucl)) deallocate(self%k_eucl) ! Reset the index array if it's been set previously
allocate(self%k_eucl(2, nplpl))
if (allocated(self%k_plpl)) deallocate(self%k_plpl) ! Reset the index array if it's been set previously
allocate(self%k_plpl(2, nplpl))
do i = 1, npl
counter = (i - 1_I8B) * npl - i * (i - 1_I8B) / 2_I8B + 1_I8B
do j = i + 1_I8B, npl
self%k_eucl(1, counter) = i
self%k_eucl(2, counter) = j
self%k_plpl(1, counter) = i
self%k_plpl(2, counter) = j
counter = counter + 1_I8B
end do
end do
Expand All @@ -34,17 +34,4 @@ module subroutine eucl_dist_index_plpl(self)

end subroutine eucl_dist_index_plpl

module subroutine eucl_dist_index_pltp(self, pl)
!! author: Jacob R. Elliott and David A. Minton
!!
!! Turns i,j indices into k index for use in the Euclidean distance matrix
!!
!! Reference:
!!
!! Mélodie Angeletti, Jean-Marie Bonny, Jonas Koko. Parallel Euclidean distance matrix computation on big datasets *.
!! 2019. hal-0204751 implicit none
class(swiftest_tp), intent(inout) :: self !! Swiftest test particle object
class(swiftest_pl), intent(inout) :: pl !! Swiftest massive body object
end subroutine eucl_dist_index_pltp

end submodule s_eucl
2 changes: 1 addition & 1 deletion src/kick/kick.f90
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ module pure subroutine kick_getacch_int_pl(self)

associate(pl => self, npl => self%nbody, nplpl => self%nplpl)
do k = 1, nplpl
associate(i => pl%k_eucl(1, k), j => pl%k_eucl(2, k))
associate(i => pl%k_plpl(1, k), j => pl%k_plpl(2, k))
dx(:) = pl%xh(:, j) - pl%xh(:, i)
rji2 = dot_product(dx(:), dx(:))
irij3 = 1.0_DP / (rji2 * sqrt(rji2))
Expand Down
26 changes: 13 additions & 13 deletions src/modules/rmvs_classes.f90
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ module rmvs_classes
!! RMVS test particle class
type, public, extends(whm_tp) :: rmvs_tp
!! Note to developers: If you add componenets to this class, be sure to update methods and subroutines that traverse the
!! component list, such as rmvs_setup_tp and rmvs_spill_tp
!! component list, such as rmvs_setup_tp and rmvs_util_spill_tp
! encounter steps)
logical, dimension(:), allocatable :: lperi !! planetocentric pericenter passage flag (persistent for a full rmvs time step) over a full RMVS time step)
integer(I4B), dimension(:), allocatable :: plperP !! index of planet associated with pericenter distance peri (persistent over a full RMVS time step)
Expand All @@ -70,11 +70,11 @@ module rmvs_classes
private
procedure, public :: discard => rmvs_discard_tp !! Check to see if test particles should be discarded based on pericenter passage distances with respect to planets encountered
procedure, public :: encounter_check => rmvs_encounter_check_tp !! Checks if any test particles are undergoing a close encounter with a massive body
procedure, public :: fill => rmvs_fill_tp !! "Fills" bodies from one object into another depending on the results of a mask (uses the MERGE intrinsic)
procedure, public :: fill => rmvs_util_fill_tp !! "Fills" bodies from one object into another depending on the results of a mask (uses the MERGE intrinsic)
procedure, public :: accel => rmvs_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, public :: setup => rmvs_setup_tp !! Constructor method - Allocates space for number of particles
procedure, public :: spill => rmvs_spill_tp !! "Spills" bodies from one object to another depending on the results of a mask (uses the PACK intrinsic)
procedure, public :: 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 @@ -92,9 +92,9 @@ module rmvs_classes
logical :: lplanetocentric = .false. !! Flag that indicates that the object is a planetocentric set of masive bodies used for close encounter calculations
contains
private
procedure, public :: fill => rmvs_fill_pl !! "Fills" bodies from one object into another depending on the results of a mask (uses the MERGE intrinsic)
procedure, public :: fill => rmvs_util_fill_pl !! "Fills" bodies from one object into another depending on the results of a mask (uses the MERGE intrinsic)
procedure, public :: setup => rmvs_setup_pl !! Constructor method - Allocates space for number of particles
procedure, public :: spill => rmvs_spill_pl !! "Spills" bodies from one object to another depending on the results of a mask (uses the PACK intrinsic)
procedure, public :: 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 @@ -120,21 +120,21 @@ 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_fill_pl(self, inserts, lfill_list)
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_fill_pl
end subroutine rmvs_util_fill_pl

module subroutine rmvs_fill_tp(self, inserts, lfill_list)
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_fill_tp
end subroutine rmvs_util_fill_tp

module subroutine rmvs_getacch_tp(self, system, param, t, lbeg)
use swiftest_classes, only : swiftest_nbody_system, swiftest_parameters
Expand Down Expand Up @@ -165,21 +165,21 @@ 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_spill_pl(self, discards, lspill_list)
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(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_spill_pl
end subroutine rmvs_util_spill_pl

module subroutine rmvs_spill_tp(self, discards, lspill_list)
module subroutine rmvs_util_spill_tp(self, discards, lspill_list)
use swiftest_classes, only : swiftest_body
implicit none
class(rmvs_tp), intent(inout) :: self !! RMVS test particle 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_spill_tp
end subroutine rmvs_util_spill_tp

module subroutine rmvs_step_system(self, param, t, dt)
use swiftest_classes, only : swiftest_parameters
Expand Down
17 changes: 5 additions & 12 deletions src/modules/swiftest_classes.f90
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module swiftest_classes
private
public :: discard_pl, discard_system, discard_tp
public :: drift_all, drift_body, drift_one
public :: eucl_dist_index_plpl, eucl_dist_index_pltp
public :: eucl_dist_index_plpl
public :: gr_getaccb_ns_body, gr_p4_pos_kick, gr_pseudovel2vel, gr_vel2pseudovel
public :: io_dump_param, io_dump_swiftest, io_dump_system, io_get_args, io_get_token, io_param_reader, io_param_writer, io_read_body_in, &
io_read_cb_in, io_read_param_in, io_read_frame_body, io_read_frame_cb, io_read_frame_system, &
Expand Down Expand Up @@ -162,8 +162,6 @@ module swiftest_classes
real(DP), dimension(:), allocatable :: omega !! Argument of pericenter
real(DP), dimension(:), allocatable :: capm !! Mean anomaly
real(DP), dimension(:), allocatable :: mu !! G * (Mcb + [m])
integer(I4B), dimension(:,:), allocatable :: k_eucl !! Index array used to convert flattened the body-body comparison upper triangular matrix
integer(I8B) :: nplpl !! Number of body-body comparisons in the flattened upper triangular matrix
!! Note to developers: If you add components to this class, be sure to update methods and subroutines that traverse the
!! component list, such as setup_body and util_spill
contains
Expand Down Expand Up @@ -209,7 +207,9 @@ module swiftest_classes
real(DP), dimension(:,:), allocatable :: rot !! Body rotation vector in inertial coordinate frame (units rad / TU)
real(DP), dimension(:), allocatable :: k2 !! Tidal Love number
real(DP), dimension(:), allocatable :: Q !! Tidal quality factor
real(DP), dimension(:), allocatable :: tlag !! Tidal phase lag
real(DP), dimension(:), allocatable :: tlag !! Tidal phase lag
integer(I4B), dimension(:,:), allocatable :: k_plpl !! Index array used to convert flattened the body-body comparison upper triangular matrix
integer(I8B) :: nplpl !! Number of body-body comparisons in the flattened upper triangular matrix
!! Note to developers: If you add components to this class, be sure to update methods and subroutines that traverse the
!! component list, such as setup_pl and util_spill_pl
contains
Expand Down Expand Up @@ -247,7 +247,6 @@ module swiftest_classes
! Test particle-specific concrete methods
! These are concrete because they are the same implemenation for all integrators
procedure, public :: discard => discard_tp !! Check to see if test particles should be discarded based on their positions relative to the massive bodies
procedure, public :: eucl_index => eucl_dist_index_pltp !! Sets up the (i, j) -> k indexing used for the single-loop blocking Euclidean distance matrix
procedure, public :: accel_int => kick_getacch_int_tp !! Compute direct cross (third) term heliocentric accelerations of test particles by massive bodies
procedure, public :: accel_obl => obl_acc_tp !! Compute the barycentric accelerations of bodies due to the oblateness of the central body
procedure, public :: setup => setup_tp !! A base constructor that sets the number of bodies and
Expand Down Expand Up @@ -388,7 +387,7 @@ module pure subroutine drift_all(mu, x, v, n, param, dt, mask, iflag)
real(DP), dimension(:), intent(in) :: mu !! Vector of gravitational constants
real(DP), dimension(:,:), intent(inout) :: x, v !! Position and velocity vectors
integer(I4B), intent(in) :: n !! number of bodies
class(swiftest_parameters), intent(in) :: param !! Current run configuration parameters
class(swiftest_parameters), intent(in) :: param !! Current run configuration parameters
real(DP), intent(in) :: dt !! Stepsize
logical, dimension(:), intent(in) :: mask !! Logical mask of size self%nbody that determines which bodies to drift.
integer(I4B), dimension(:), intent(out) :: iflag !! Vector of error flags. 0 means no problem
Expand Down Expand Up @@ -416,12 +415,6 @@ module subroutine eucl_dist_index_plpl(self)
class(swiftest_pl), intent(inout) :: self !! Swiftest massive body object
end subroutine

module subroutine eucl_dist_index_pltp(self, pl)
implicit none
class(swiftest_tp), intent(inout) :: self !! Swiftest test particle object
class(swiftest_pl), intent(inout) :: pl !! Swiftest massive body object
end subroutine

module pure subroutine gr_getaccb_ns_body(self, system, param)
implicit none
class(swiftest_body), intent(inout) :: self !! Swiftest generic body object
Expand Down
26 changes: 24 additions & 2 deletions src/modules/symba_classes.f90
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,9 @@ module symba_classes
integer(I4B), dimension(:), allocatable :: index1 !! position of the planet in encounter
integer(I4B), dimension(:), allocatable :: index2 !! position of the test particle in encounter
contains
procedure, public :: setup => symba_setup_pltpenc !! A constructor that sets the number of encounters and allocates and initializes all arrays
procedure, public :: setup => symba_setup_pltpenc !! A constructor that sets the number of encounters and allocates and initializes all arrays
procedure, public :: copy => symba_util_copy_pltpenc !! Copies all elements of one pltpenc list to another
procedure, public :: resize => symba_util_resize_pltpenc !! Checks the current size of the pltpenc_list against the required size and extends it by a factor of 2 more than requested if it is too small
end type symba_pltpenc

!********************************************************************************************************************************
Expand All @@ -134,7 +136,8 @@ module symba_classes
real(DP), dimension(:,:), allocatable :: vb1 !! the barycentric velocity of parent 1 in encounter
real(DP), dimension(:,:), allocatable :: vb2 !! the barycentric velocity of parent 2 in encounter
contains
procedure, public :: setup => symba_setup_plplenc !! A constructor that sets the number of encounters and allocates and initializes all arrays
procedure, public :: setup => symba_setup_plplenc !! A constructor that sets the number of encounters and allocates and initializes all arrays
procedure, public :: copy => symba_util_copy_plplenc !! Copies all elements of one plplenc list to another
end type symba_plplenc

!********************************************************************************************************************************
Expand Down Expand Up @@ -306,5 +309,24 @@ module subroutine symba_step_reset_system(self)
implicit none
class(symba_nbody_system), intent(inout) :: self !! SyMBA nbody system object
end subroutine symba_step_reset_system

module subroutine symba_util_copy_pltpenc(self, source)
implicit none
class(symba_pltpenc), intent(inout) :: self !! SyMBA pl-tp encounter list
class(symba_pltpenc), intent(in) :: source !! Source object to copy into
end subroutine symba_util_copy_pltpenc

module subroutine symba_util_copy_plplenc(self, source)
implicit none
class(symba_plplenc), intent(inout) :: self !! SyMBA pl-pl encounter list
class(symba_pltpenc), intent(in) :: source !! Source object to copy into
end subroutine symba_util_copy_plplenc

module subroutine symba_util_resize_pltpenc(self, nrequested)
implicit none
class(symba_pltpenc), intent(inout) :: self !! SyMBA pl-tp encounter list
integer(I4B), intent(in) :: nrequested !! New size of list needed
end subroutine symba_util_resize_pltpenc

end interface
end module symba_classes
20 changes: 10 additions & 10 deletions src/rmvs/rmvs_spill_and_fill.f90 → src/rmvs/rmvs_util.f90
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
submodule(rmvs_classes) s_rmvs_spill_and_fill
submodule(rmvs_classes) s_rmvs_util
use swiftest
contains
module subroutine rmvs_spill_pl(self, discards, lspill_list)
module subroutine rmvs_util_spill_pl(self, discards, lspill_list)
!! author: David A. Minton
!!
!! Move spilled (discarded) RMVS test particle structure from active list to discard list
Expand Down Expand Up @@ -31,9 +31,9 @@ module subroutine rmvs_spill_pl(self, discards, lspill_list)

return

end subroutine rmvs_spill_pl
end subroutine rmvs_util_spill_pl

module subroutine rmvs_fill_pl(self, inserts, lfill_list)
module subroutine rmvs_util_fill_pl(self, inserts, lfill_list)
!! author: David A. Minton
!!
!! Insert new RMVS massive body structure into an old one.
Expand Down Expand Up @@ -62,9 +62,9 @@ module subroutine rmvs_fill_pl(self, inserts, lfill_list)

return

end subroutine rmvs_fill_pl
end subroutine rmvs_util_fill_pl

module subroutine rmvs_spill_tp(self, discards, lspill_list)
module subroutine rmvs_util_spill_tp(self, discards, lspill_list)
!! author: David A. Minton
!!
!! Move spilled (discarded) RMVS test particle structure from active list to discard list
Expand Down Expand Up @@ -98,9 +98,9 @@ module subroutine rmvs_spill_tp(self, discards, lspill_list)

return

end subroutine rmvs_spill_tp
end subroutine rmvs_util_spill_tp

module subroutine rmvs_fill_tp(self, inserts, lfill_list)
module subroutine rmvs_util_fill_tp(self, inserts, lfill_list)
!! author: David A. Minton
!!
!! Insert new RMVS test particle structure into an old one.
Expand Down Expand Up @@ -133,6 +133,6 @@ module subroutine rmvs_fill_tp(self, inserts, lfill_list)

return

end subroutine rmvs_fill_tp
end subroutine rmvs_util_fill_tp

end submodule s_rmvs_spill_and_fill
end submodule s_rmvs_util
Loading

0 comments on commit 4f30c8e

Please sign in to comment.