Spherical harmonic gravity acceleration, and optionally its gradient , with Pines' formulation (see the module documentation). Includes the central (point mass) term.
The coefficients are unnormalized, as stored by the toolkit's
geopotential_model_pines (cnm(n,m), snm(n,m), for n>=1, m>=0;
degree 1 is ignored, as in the toolkit's gravpot).
All vectors are in the body-fixed frame of the coefficients.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| real(kind=wp), | intent(in), | dimension(3) | :: | r |
position vector [km] |
|
| integer, | intent(in) | :: | nmax |
degree to use (>=0) |
||
| integer, | intent(in) | :: | mmax |
order to use (0 to |
||
| real(kind=wp), | intent(in) | :: | re |
body reference radius [km] |
||
| real(kind=wp), | intent(in) | :: | mu |
body gravitational parameter [km^3/s^2] |
||
| real(kind=wp), | intent(in), | dimension(:,0:) | :: | cnm |
unnormalized C coefficients |
|
| real(kind=wp), | intent(in), | dimension(:,0:) | :: | snm |
unnormalized S coefficients |
|
| real(kind=wp), | intent(out), | dimension(3) | :: | acc |
acceleration [km/s^2] |
|
| real(kind=wp), | intent(out), | optional, | dimension(3,3) | :: | grad |
gravity gradient [1/s^2] |
pure subroutine pines_gravity(r,nmax,mmax,re,mu,cnm,snm,acc,grad) implicit none real(wp),dimension(3),intent(in) :: r !! position vector [km] integer,intent(in) :: nmax !! degree to use (>=0) integer,intent(in) :: mmax !! order to use (0 to `nmax`) real(wp),intent(in) :: re !! body reference radius [km] real(wp),intent(in) :: mu !! body gravitational parameter [km^3/s^2] real(wp),dimension(:,0:),intent(in) :: cnm !! unnormalized C coefficients `cnm(n,m)` real(wp),dimension(:,0:),intent(in) :: snm !! unnormalized S coefficients `snm(n,m)` real(wp),dimension(3),intent(out) :: acc !! acceleration [km/s^2] real(wp),dimension(3,3),intent(out),optional :: grad !! gravity gradient \( \partial \mathbf{a}/\partial \mathbf{r} \) [1/s^2] real(wp),dimension(0:nmax,0:nmax+2) :: a !! derived Legendre functions A(n,m) = d^m P_n / du^m real(wp),dimension(0:nmax) :: rm, im !! real and imaginary parts of (s + i t)^m real(wp),dimension(3) :: shat !! direction cosines (s,t,u) real(wp),dimension(3) :: g !! dU/dshat real(wp),dimension(3) :: gr !! d2U/dshat dr real(wp),dimension(3,3) :: gss !! d2U/dshat2 real(wp),dimension(3) :: bn_g !! gradient of B_n w.r.t. shat real(wp),dimension(3,3) :: bn_h !! Hessian of B_n w.r.t. shat real(wp),dimension(3,3) :: p !! projection I - shat*shat^T real(wp),dimension(3) :: pg, pgr real(wp) :: rmag, rinv, s, t, u real(wp) :: ur, urr !! dU/dr, d2U/dr2 real(wp) :: rho, rho1, rho2 !! rho_n and its first and second derivatives w.r.t. r real(wp) :: bn !! B_n = sum_m A(n,m) D(n,m) real(wp) :: c, sn !! C(n,m), S(n,m) real(wp) :: d, ds, dt, dss, dst !! D(n,m) = C r_m + S i_m, and its derivatives w.r.t. s and t real(wp) :: sg !! shat . g integer :: n, m, mtop, i, j logical :: need_grad need_grad = present(grad) rmag = norm2(r) rinv = one / rmag shat = r * rinv s = shat(1) t = shat(2) u = shat(3) ! derived Legendre functions A(n,m) (zero for m > n): a = zero a(0,0) = one if (nmax >= 1) then a(1,0) = u a(1,1) = one end if do n = 2, nmax a(n,0) = (real(2*n-1,wp)*u*a(n-1,0) - real(n-1,wp)*a(n-2,0)) / real(n,wp) do m = 1, n ! from P'_n - P'_{n-2} = (2n-1) P_{n-1}, differentiated m-1 times: a(n,m) = real(2*n-1,wp)*a(n-1,m-1) + a(n-2,m) end do end do ! (s + i t)^m: rm(0) = one im(0) = zero do m = 1, nmax rm(m) = s*rm(m-1) - t*im(m-1) im(m) = s*im(m-1) + t*rm(m-1) end do ! accumulate U_r, U_rr, g, g_r, G_ss: ur = zero urr = zero g = zero gr = zero gss = zero rho = mu * rinv ! rho_0 do n = 0, nmax if (n == 1) then ! degree 1 is zero (center of mass at the origin) rho = rho * re * rinv cycle end if rho1 = -real(n+1,wp) * rho * rinv rho2 = real((n+1)*(n+2),wp) * rho * rinv * rinv bn = zero bn_g = zero bn_h = zero if (n == 0) then bn = one ! the central term (C00 = 1) else mtop = min(n, mmax) do m = 0, mtop c = cnm(n,m) sn = snm(n,m) d = c*rm(m) + sn*im(m) if (m >= 1) then ds = real(m,wp) * (c*rm(m-1) + sn*im(m-1)) dt = real(m,wp) * (sn*rm(m-1) - c*im(m-1)) else ds = zero dt = zero end if bn = bn + a(n,m)*d bn_g(1) = bn_g(1) + a(n,m)*ds bn_g(2) = bn_g(2) + a(n,m)*dt bn_g(3) = bn_g(3) + a(n,m+1)*d if (need_grad) then if (m >= 2) then dss = real(m*(m-1),wp) * (c*rm(m-2) + sn*im(m-2)) dst = real(m*(m-1),wp) * (sn*rm(m-2) - c*im(m-2)) else dss = zero dst = zero end if bn_h(1,1) = bn_h(1,1) + a(n,m)*dss bn_h(1,2) = bn_h(1,2) + a(n,m)*dst bn_h(2,2) = bn_h(2,2) - a(n,m)*dss ! (D_tt = -D_ss) bn_h(1,3) = bn_h(1,3) + a(n,m+1)*ds bn_h(2,3) = bn_h(2,3) + a(n,m+1)*dt bn_h(3,3) = bn_h(3,3) + a(n,m+2)*d end if end do end if ur = ur + rho1*bn urr = urr + rho2*bn g = g + rho*bn_g gr = gr + rho1*bn_g if (need_grad) gss = gss + rho*bn_h rho = rho * re * rinv ! rho_{n+1} end do ! acceleration: sg = dot_product(shat, g) pg = g - sg*shat acc = ur*shat + rinv*pg if (need_grad) then gss(2,1) = gss(1,2) gss(3,1) = gss(1,3) gss(3,2) = gss(2,3) p = -outer(shat,shat) do i = 1, 3 p(i,i) = p(i,i) + one end do pgr = gr - dot_product(shat,gr)*shat grad = urr*outer(shat,shat) & + rinv*(outer(pgr,shat) + outer(shat,pgr)) & + (ur*rinv)*p & + (rinv*rinv)*( matmul(p,matmul(gss,p)) - (outer(pg,shat) + outer(shat,pg)) - sg*p ) ! symmetrize (it is symmetric analytically): do j = 1, 3 do i = j+1, 3 grad(i,j) = 0.5_wp*(grad(i,j) + grad(j,i)) grad(j,i) = grad(i,j) end do end do end if end subroutine pines_gravity