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

Commit

Permalink
Added module interface for orbel_xv2el in anticipation of incorporati…
Browse files Browse the repository at this point in the history
…ng it into the Python code
  • Loading branch information
daminton committed Aug 19, 2021
1 parent bf22091 commit 2a1e81d
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 4 deletions.
13 changes: 13 additions & 0 deletions src/modules/swiftest_classes.f90
Original file line number Diff line number Diff line change
Expand Up @@ -775,6 +775,19 @@ module pure subroutine orbel_xv2aqt(mu, x, v, a, q, capm, tperi)
real(DP), intent(out) :: tperi !! time of pericenter passage
end subroutine orbel_xv2aqt

module pure subroutine orbel_xv2el(mu, x, v, a, e, inc, capom, omega, capm)
implicit none
real(DP), intent(in) :: mu !! Gravitational constant
real(DP), dimension(:), intent(in) :: x !! Position vector
real(DP), dimension(:), intent(in) :: v !! Velocity vector
real(DP), intent(out) :: a !! semimajor axis
real(DP), intent(out) :: e !! eccentricity
real(DP), intent(out) :: inc !! inclination
real(DP), intent(out) :: capom !! longitude of ascending node
real(DP), intent(out) :: omega !! argument of periapsis
real(DP), intent(out) :: capm !! mean anomaly
end subroutine orbel_xv2el

module subroutine orbel_xv2el_vec(self, cb)
implicit none
class(swiftest_body), intent(inout) :: self !! Swiftest body object
Expand Down
16 changes: 12 additions & 4 deletions src/orbel/orbel.f90
Original file line number Diff line number Diff line change
Expand Up @@ -890,7 +890,7 @@ module subroutine orbel_xv2el_vec(self, cb)
end do
end subroutine orbel_xv2el_vec

pure subroutine orbel_xv2el(mu, x, v, a, e, inc, capom, omega, capm)
module pure subroutine orbel_xv2el(mu, x, v, a, e, inc, capom, omega, capm)
!! author: David A. Minton
!!
!! Compute osculating orbital elements from relative Cartesian position and velocity
Expand All @@ -906,9 +906,17 @@ pure subroutine orbel_xv2el(mu, x, v, a, e, inc, capom, omega, capm)
!! Adapted from David E. Kaufmann's Swifter routine: orbel_xv2el.f90
!! Adapted from Martin Duncan's Swift routine orbel_xv2el.f
implicit none
real(DP), intent(in) :: mu
real(DP), dimension(:), intent(in) :: x, v
real(DP), intent(out) :: a, e, inc, capom, omega, capm
! Arguments
real(DP), intent(in) :: mu !! Gravitational constant
real(DP), dimension(:), intent(in) :: x !! Position vector
real(DP), dimension(:), intent(in) :: v !! Velocity vector
real(DP), intent(out) :: a !! semimajor axis
real(DP), intent(out) :: e !! eccentricity
real(DP), intent(out) :: inc !! inclination
real(DP), intent(out) :: capom !! longitude of ascending node
real(DP), intent(out) :: omega !! argument of periapsis
real(DP), intent(out) :: capm !! mean anomaly
! Internals
integer(I4B) :: iorbit_type
real(DP) :: r, v2, h2, h, rdotv, energy, fac, u, w, cw, sw, face, cape, tmpf, capf
real(DP), dimension(NDIM) :: hvec
Expand Down
32 changes: 32 additions & 0 deletions src/python/orbel.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
module orbel
use swiftest
private
public :: xv2el
contains
pure elemental subroutine xv2el(mu, px, py, pz, vx, vy, vz, a, e, inc, capom, omega, capm)
use module_interfaces, only : orbel_xv2el
implicit none
! Arguments
real*8, intent(in) :: mu, px, py, pz, vx, vy, vz
real*8, intent(out) :: a, e, inc, capom, omega, capm
!$f2py intent(in) mu
!$f2py intent(in) px
!$f2py intent(in) py
!$f2py intent(in) pz
!$f2py intent(in) vx
!$f2py intent(in) vy
!$f2py intent(in) vz
!$f2py intent(out) a
!$f2py intent(out) e
!$f2py intent(out) inc
!$f2py intent(out) capom
!$f2py intent(out) omega
!$f2py intent(out) capm
! Internals
real*8, dimension(3) :: x, v
x = [px, py, pz]
v = [vx, vy, vz]
call orbel_xv2el(x, v, mu, a, e, inc, capom, omega, capm)
return
end subroutine xv2el
end module orbel

0 comments on commit 2a1e81d

Please sign in to comment.