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

Commit

Permalink
Browse files Browse the repository at this point in the history
Reformatted code to pull use statements out of individual subroutines in the submodules due to complains from ifort. Also cleaned up some cruft
  • Loading branch information
daminton committed Apr 1, 2021
1 parent 0fcf102 commit 893407a
Show file tree
Hide file tree
Showing 53 changed files with 719 additions and 826 deletions.
78 changes: 49 additions & 29 deletions src/discard/discard.f90
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
submodule (swiftest_classes) s_discard
use swiftest
contains
module procedure discard_system
module subroutine discard_system(self, config)
!! author: David A. Minton
!!
!! Check to see if particles should be discarded based on their positions relative to the massive bodies
!!
!! Adapted from David E. Kaufmann's Swifter routine: discard.f90
!! Adapted from Hal Levison's Swift routine discard.f
use swiftest
implicit none
logical, dimension(:), allocatable :: lspill_list
class(swiftest_nbody_system), intent(inout) :: self !! Swiftest system object
class(swiftest_configuration), intent(in) :: config !! Input collection of configuration parameters

real(DP) :: msys
if (self%tp%nbody == 0) return
select type(self)
class is (whm_nbody_system)
associate(cb => self%cb, pl => self%pl, tp => self%tp, t => config%t, dt => config%dt, &
msys => self%msys, discards => self%tp_discards, &
ntp => self%tp%nbody)
ntp => self%tp%nbody, ldiscard => self%tp%ldiscard)
if ((config%rmin >= 0.0_DP) .or. (config%rmax >= 0.0_DP) .or. &
(config%rmaxu >= 0.0_DP) .or. ((config%qmin >= 0.0_DP) .and. (config%qmin_coord == "BARY"))) then
call pl%h2b(cb)
Expand All @@ -27,29 +27,34 @@
if (ntp > 0) call tp%discard_sun(cb, config, t, msys)
end if
if (config%qmin >= 0.0_DP .and. ntp > 0) call tp%discard_peri(cb, pl, config, t, msys)
if (config%lclose .and. ntp > 0) call tp%discard_pl(cb, pl, config, t, dt)
if (config%lclose .and. ntp > 0) call tp%discard_pl(pl, t, dt)

if (any(tp%ldiscard(1:ntp))) then
! Spill the discards to the spill list
allocate(lspill_list, source = tp%ldiscard)
call tp%spill(discards, lspill_list)
call tp%spill(discards, ldiscard)
call self%write_discard(config, discards)
deallocate(lspill_list)
end if
end associate
end select
return
end procedure discard_system
end subroutine discard_system

module procedure discard_sun_tp
module subroutine discard_sun_tp(self, cb, config, t, msys)
!! author: David A. Minton
!!
!! Check to see if test particles should be discarded based on their positions relative to the Sun
!! or because they are unbound from the system
!!
!! Adapted from David E. Kaufmann's Swifter routine: discard_sun.f90
!! Adapted from Hal Levison's Swift routine discard_sun.f
use swiftest
implicit none
! Arguments
class(swiftest_tp), intent(inout) :: self !! Swiftest test particle object
class(swiftest_cb), intent(inout) :: cb !! Swiftest central body object
class(swiftest_configuration), intent(in) :: config !! configuration parameters
real(DP), intent(in) :: t !! Current simulation tim
real(DP), intent(in) :: msys !! Total system mass
! Internals
integer(I4B) :: i
real(DP) :: energy, vb2, rb2, rh2, rmin2, rmax2, rmaxu2

Expand Down Expand Up @@ -83,23 +88,29 @@
end associate

return

end procedure discard_sun_tp
end subroutine discard_sun_tp

module procedure discard_peri_tp
module subroutine discard_peri_tp(self, cb, pl, config, t, msys)
!! author: David A. Minton
!!
!! Check to see if a test particle should be discarded because its perihelion distance becomes too small
!!
!! Adapted from David E. Kaufmann's Swifter routine: discard_peri.f90
!! Adapted from Hal Levison's Swift routine discard_peri.f
use swiftest
implicit none
! Arguments
class(swiftest_tp), intent(inout) :: self !! Swiftest test particle object
class(swiftest_cb), intent(inout) :: cb !! Swiftest central body object
class(swiftest_pl), intent(inout) :: pl !! Swiftest massive body object
class(swiftest_configuration), intent(in) :: config !! configuration parameters
real(DP), intent(in) :: t !! Current simulation tim
real(DP), intent(in) :: msys !! Total system mass
! Internals
logical, save :: lfirst = .true.
integer(I4B) :: i, j, ih, ntp, npl
integer(I4B) :: i, j, ih
real(DP) :: r2
real(DP), dimension(NDIM) :: dx


associate(tp => self, ntp => self%nbody, npl => pl%nbody, qmin_coord => config%qmin_coord)
if (lfirst) then
call util_hills(npl, pl)
Expand Down Expand Up @@ -132,19 +143,23 @@
end associate
return

end procedure discard_peri_tp
end subroutine discard_peri_tp

module procedure discard_pl_tp
module subroutine discard_pl_tp(self, pl, t, dt)
!! author: David A. Minton
!!
!! Check to see if test particles should be discarded based on their positions relative to the massive bodies
!!
!! Adapted from David E. Kaufmann's Swifter routine: discard_pl.f90
!! Adapted from Hal Levison's Swift routine discard_pl.f
use swiftest
implicit none

integer(I4B) :: i, j, isp, ntp, npl
! Arguments
class(swiftest_tp), intent(inout) :: self !! Swiftest test particle object
class(swiftest_pl), intent(inout) :: pl !! Swiftest massive body object
real(DP), intent(in) :: t !! Current simulation tim
real(DP), intent(in) :: dt !! Stepsize
! Internals
integer(I4B) :: i, j, isp
real(DP) :: r2min, radius
real(DP), dimension(NDIM) :: dx, dv

Expand All @@ -170,19 +185,25 @@
end associate
return

end procedure discard_pl_tp
end subroutine discard_pl_tp

module procedure discard_pl_close
module subroutine discard_pl_close(dx, dv, dt, r2crit, iflag, r2min)
!! author: David A. Minton
!!
!! Check to see if a test particle and massive body are having, or will have within the next time step, an encounter such
!! that the separation distance r is less than some critical radius rcrit (or r**2 < rcrit**2 = r2crit)
!!
!! Adapted from David E. Kaufmann's Swifter routine: discard_pl_close.f90
!! Adapted from Hal Levison's Swift routine discard_pl_close.f
use swiftest
implicit none
! Arguments
real(DP), dimension(:), intent(in) :: dx, dv
real(DP), intent(in) :: dt, r2crit
integer(I4B), intent(out) :: iflag
real(DP), intent(out) :: r2min
! Internals
real(DP) :: r2, v2, vdotr, tmin

r2 = dot_product(dx(:), dx(:))
if (r2 <= r2crit) then
iflag = 1
Expand All @@ -208,7 +229,6 @@
end if

return

end procedure discard_pl_close
end subroutine discard_pl_close

end submodule s_discard
12 changes: 1 addition & 11 deletions src/driftkick/drift.f90
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
submodule (swiftest_classes) drift_implementation

use swiftest
!> Integration control parameters:
real(DP), parameter :: E2MAX = 0.36_DP
real(DP), parameter :: DM2MAX = 0.16_DP
Expand All @@ -16,7 +16,6 @@ module pure subroutine drift_one(mu, x, v, dt, iflag)
!!
!! Adapted from David E. Kaufmann's Swifter routine routine drift_one.f90
!! Adapted from Hal Levison and Martin Duncan's Swift routine drift_one.f
use swiftest_globals
implicit none
! Arguments
real(DP), intent(in) :: mu !! G * (Mcb + m), G = gravitational constant, Mcb = mass of central body, m = mass of body to drift
Expand Down Expand Up @@ -46,7 +45,6 @@ pure subroutine drift_dan(mu, x0, v0, dt0, iflag)
!!
!! Adapted from David E. Kaufmann's Swifter routine: drift_dan.f90
!! Adapted from Hal Levison and Martin Duncan's Swift routine drift_dan.f
use swiftest
implicit none
integer(I4B), intent(out) :: iflag
real(DP), intent(in) :: mu, dt0
Expand Down Expand Up @@ -118,7 +116,6 @@ pure subroutine drift_kepmd(dm, es, ec, x, s, c)
!!
!! Adapted from David E. Kaufmann's Swifter routine: drift_kepmd.f90
!! Adapted from Martin Duncan's Swift routine drift_kepmd.f
use swiftest
implicit none
real(DP), intent(in) :: dm, es, ec
real(DP), intent(out) :: x, s, c
Expand Down Expand Up @@ -155,7 +152,6 @@ pure subroutine drift_kepu(dt,r0,mu,alpha,u,fp,c1,c2,c3,iflag)
!!
!! Adapted from David E. Kaufmann's Swifter routine: drift_kepu.f90
!! Adapted from Hal Levison's Swift routine drift_kepu.f
use swiftest
implicit none
integer(I4B), intent(out) :: iflag
real(DP), intent(in) :: dt, r0, mu, alpha, u
Expand Down Expand Up @@ -183,7 +179,6 @@ pure subroutine drift_kepu_fchk(dt, r0, mu, alpha, u, s, f)
!!
!! Adapted from David E. Kaufmann's Swifter routine: drift_kepu_fchk.f90
!! Adapted from Martin Duncan's Swift routine drift_kepu_fchk.f
use swiftest
implicit none
real(DP), intent(in) :: dt, r0, mu, alpha, u, s
real(DP), intent(out) :: f
Expand All @@ -206,7 +201,6 @@ pure subroutine drift_kepu_guess(dt, r0, mu, alpha, u, s)
!!
!! Adapted from David E. Kaufmann's Swifter routine: drift_kepu_guess.f90
!! Adapted from Hal Levison and Martin Duncan's Swift routine drift_kepu_guess.f
use swiftest
implicit none
real(DP), intent(in) :: dt, r0, mu, alpha, u
real(DP), intent(out) :: s
Expand Down Expand Up @@ -245,7 +239,6 @@ pure subroutine drift_kepu_lag(s, dt, r0, mu, alpha, u, fp, c1, c2, c3, iflag)
!!
!! Adapted from David E. Kaufmann's Swifter routine: drift_kepu_lag.f90
!! Adapted from Hal Levison's Swift routine drift_kepu_lag.f
use swiftest
implicit none
integer(I4B), intent(out) :: iflag
real(DP), intent(in) :: dt, r0, mu, alpha, u
Expand Down Expand Up @@ -290,7 +283,6 @@ pure subroutine drift_kepu_new(s, dt, r0, mu, alpha, u, fp, c1, c2, c3, iflag)
!!
!! Adapted from David E. Kaufmann's Swifter routine: drift_kepu_new.f90
!! Adapted from Hal Levison's Swift routine drift_kepu_new.f
use swiftest
implicit none
integer(I4B), intent(out) :: iflag
real(DP), intent(in) :: dt, r0, mu, alpha, u
Expand Down Expand Up @@ -332,7 +324,6 @@ pure subroutine drift_kepu_p3solve(dt, r0, mu, alpha, u, s, iflag)
!!
!! Adapted from David E. Kaufmann's Swifter routine: drift_kepu_p3solve.f90
!! Adapted from Martin Duncan's Swift routine drift_kepu_p3solve.f
use swiftest
implicit none
integer(I4B), intent(out) :: iflag
real(DP), intent(in) :: dt, r0, mu, alpha, u
Expand Down Expand Up @@ -376,7 +367,6 @@ pure subroutine drift_kepu_stumpff(x, c0, c1, c2, c3)
!!
!! Adapted from David E. Kaufmann's Swifter routine: drift_kepu_stumpff.f90
!! Adapted from Hal Levison's Swift routine drift_kepu_stumpff.f
use swiftest
implicit none
real(DP), intent(inout) :: x
real(DP), intent(out) :: c0, c1, c2, c3
Expand Down
50 changes: 28 additions & 22 deletions src/driftkick/kick.f90
Original file line number Diff line number Diff line change
@@ -1,36 +1,42 @@
submodule(swiftest_classes) s_kick
contains
module procedure kick_vh_body
!! author: David A. Minton
!!
!! Kick heliocentric velocities of bodies
!!
!! Adapted from Martin Duncan and Hal Levison's Swift routine kickvh.f and kickvh_tp.f
!! Adapted from David E. Kaufmann's Swifter routine whm_kickvh.f90 and whm_kickvh_tp.f90
use swiftest
implicit none
integer(I4B) :: i

associate(n => self%nbody, vh => self%vh, ah => self%ah, status => self%status)
if (n == 0) return
do concurrent(i = 1:n, status(i) == ACTIVE)
vh(:, i) = vh(:, i) + ah(:, i) * dt
end do
end associate
contains
module subroutine kick_vh_body(self, dt)
!! author: David A. Minton
!!
!! Kick heliocentric velocities of bodies
!!
!! Adapted from Martin Duncan and Hal Levison's Swift routine kickvh.f and kickvh_tp.f
!! Adapted from David E. Kaufmann's Swifter routine whm_kickvh.f90 and whm_kickvh_tp.f90
implicit none
! Arguments
class(swiftest_body), intent(inout) :: self !! Swiftest generic body object
real(DP), intent(in) :: dt !! Stepsize
! Internals
integer(I4B) :: i

return
associate(n => self%nbody, vh => self%vh, ah => self%ah, status => self%status)
if (n == 0) return
do concurrent(i = 1:n, status(i) == ACTIVE)
vh(:, i) = vh(:, i) + ah(:, i) * dt
end do
end associate

end procedure kick_vh_body
return
end subroutine kick_vh_body

module procedure kick_vb_body
module subroutine kick_vb_body(self, dt)
!! author: David A. Minton
!!
!! Kick barycentric velocities of bodies
!!
!! Adapted from Martin Duncan and Hal Levison's Swift routine kickvh.f and kickvh_tp.f
!! Adapted from David E. Kaufmann's Swifter routine helio_kickvb.f90 and helio_kickvb_tp.f90
use swiftest
implicit none
! Arguments
class(swiftest_body), intent(inout) :: self !! Swiftest generic body object
real(DP), intent(in) :: dt !! Stepsize
! Internals
integer(I4B) :: i

associate(n => self%nbody, vb => self%vb, ah => self%ah, status => self%status)
Expand All @@ -42,5 +48,5 @@

return

end procedure kick_vb_body
end subroutine kick_vb_body
end submodule s_kick
4 changes: 1 addition & 3 deletions src/eucl/eucl.f90
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
submodule (swiftest_classes) s_eucl
use swiftest
contains

module procedure eucl_dist_index_plpl
!! author: Jacob R. Elliott and David A. Minton
!!
Expand All @@ -10,7 +10,6 @@
!!
!! Mélodie Angeletti, Jean-Marie Bonny, Jonas Koko. Parallel Euclidean distance matrix computation on big datasets *.
!! 2019. hal-0204751
use swiftest
implicit none

integer(I4B) :: i, j, k, kp, p
Expand Down Expand Up @@ -41,7 +40,6 @@
!! author: Jacob R. Elliott and David A. Minton
!!
!! Efficient parallel loop-blocking algrorithm for evaluating the Euclidean distance matrix for planet-planet
use swiftest
implicit none
integer(I4B) :: k, i, j
real(DP), dimension(NDIM) :: dx
Expand Down
3 changes: 1 addition & 2 deletions src/gr/gr.f90
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
submodule(swiftest_classes) s_gr
use swiftest
contains

module procedure gr_getaccb_ns_body
!! author: David A. Minton
!!
!! Add relativistic correction acceleration for non-symplectic integrators
!! Based on Quinn, Tremaine, & Duncan 1998
!!
!! Adapted from David A. Minton's Swifter routine routine gr_getaccb_ns.f90
use swiftest
implicit none

real(DP), dimension(NDIM) :: xh, vh
Expand Down
Loading

0 comments on commit 893407a

Please sign in to comment.