ballistic_derivs Subroutine

public subroutine ballistic_derivs(me, t, x, xdot)

Equations of motion for a ballistic segment.

Note

In this example, all the segments have the same equations of motion!

Arguments

Type IntentOptional Attributes Name
class(ddeabm_class), intent(inout) :: me
real(kind=wp), intent(in) :: t

time [sec from epoch]

real(kind=wp), intent(in), dimension(:) :: x

state [r,v] in inertial frame (moon-centered) (and, for stm_mode, the 6x6 state transition matrix , column by column)

real(kind=wp), intent(out), dimension(:) :: xdot

derivative of state ()


Calls

proc~~ballistic_derivs~~CallsGraph proc~ballistic_derivs ballistic_derivs get_acc get_acc proc~ballistic_derivs->get_acc get_r get_r proc~ballistic_derivs->get_r icrf_to_iau_moon icrf_to_iau_moon proc~ballistic_derivs->icrf_to_iau_moon j2000_to_frame j2000_to_frame proc~ballistic_derivs->j2000_to_frame proc~pines_gravity pines_gravity proc~ballistic_derivs->proc~pines_gravity proc~pointmass_gravity_gradient pointmass_gravity_gradient proc~ballistic_derivs->proc~pointmass_gravity_gradient proc~third_body_gravity_gradient third_body_gravity_gradient proc~ballistic_derivs->proc~third_body_gravity_gradient third_body_gravity third_body_gravity proc~ballistic_derivs->third_body_gravity proc~outer outer proc~pines_gravity->proc~outer proc~point_gradient point_gradient proc~pointmass_gravity_gradient->proc~point_gradient proc~third_body_gravity_gradient->proc~point_gradient proc~point_gradient->proc~outer

Called by

proc~~ballistic_derivs~~CalledByGraph proc~ballistic_derivs ballistic_derivs proc~propagate_segment_stm segment%propagate_segment_stm proc~propagate_segment_stm->proc~ballistic_derivs proc~compute_jacobian_stm mission_type%compute_jacobian_stm proc~compute_jacobian_stm->proc~propagate_segment_stm proc~equilibrate equilibrate proc~equilibrate->proc~compute_jacobian_stm proc~equilibrate_scales mission_type%equilibrate_scales proc~equilibrate_scales->proc~compute_jacobian_stm proc~eclipse_optimize eclipse_optimize proc~eclipse_optimize->proc~equilibrate proc~initialize_the_mission mission_type%initialize_the_mission proc~initialize_the_mission->proc~equilibrate_scales interface~eclipse_optimize my_solver_type%eclipse_optimize interface~eclipse_optimize->proc~eclipse_optimize proc~initialize_the_solver my_solver_type%initialize_the_solver proc~initialize_the_solver->proc~initialize_the_mission proc~halo_solver_main halo_solver_main proc~halo_solver_main->interface~eclipse_optimize proc~halo_solver_main->proc~initialize_the_solver

Source Code

    subroutine ballistic_derivs(me,t,x,xdot)

    implicit none

    class(ddeabm_class),intent(inout) :: me
    real(wp),intent(in)               :: t    !! time [sec from epoch]
    real(wp),dimension(:),intent(in)  :: x    !! state [r,v] in inertial frame (moon-centered)
                                              !! (and, for `stm_mode`, the 6x6 state transition matrix
                                              !! \( \Phi \), column by column)
    real(wp),dimension(:),intent(out) :: xdot !! derivative of state (\( dx/dt \))

    real(wp),dimension(3) :: r,rb,v
    reaL(wp),dimension(3) :: r_earth_wrt_moon,r_sun_wrt_moon,r_jupiter_wrt_moon
    real(wp),dimension(3,3) :: rotmat
    real(wp),dimension(3) :: a_geopot  !! central body acc
    real(wp),dimension(3) :: a_earth
    real(wp),dimension(3) :: a_sun
    real(wp),dimension(3) :: a_jupiter
    real(wp),dimension(3) :: a_third_body  !! total third-body acc
    real(wp) :: et !! ephemeris time of `t`
    logical :: status_ok
    logical :: stm  !! if the STM derivatives are to be computed
    real(wp),dimension(3,3) :: ggrad  !! gravity gradient d(acc)/dr [inertial]
    real(wp),dimension(3,3) :: hb     !! central body gravity gradient [body-fixed frame]
    real(wp),dimension(6,6) :: phi, phidot

    select type (me)

    class is (segment)

        ! get state:
        r = x(1:3)
        v = x(4:6)
        stm = me%stm_mode .and. me%compute_stm .and. size(x)==n_eoms_stm
        ggrad = zero

        ! compute ephemeris time [sec]:
        et = (me%data%et_ref + me%t_offset) + t  ! (t is local while integrating, see t_offset)

        if (me%pointmass_central_body) then
            ! pointmass moon gravity model
            a_geopot = -mu_moon / norm2(r)**3 * r
            if (stm) ggrad = pointmass_gravity_gradient(r,mu_moon)
        else
            ! geopotential gravity:
            ! first get the rotation matrix from inertial to body-fixed Moon frame
            select case (grav_frame)
            case (1); rotmat = icrf_to_iau_moon(et) ! iau_moon
            case (2); rotmat = me%moon_pa%j2000_to_frame(et) ! moon_pa (splined)
            case default; error stop 'invalid grav_frame in ballistic_derivs'
            end select
            rb = matmul(rotmat,r)           ! r in body-fixed frame
            if (me%stm_mode) then
                ! Pines, with the gradient (the same coefficients as the toolkit's model)
                if (stm) then
                    call pines_gravity(rb,grav_n,grav_m,me%grav%re,me%grav%mu,&
                                       me%grav%cnm,me%grav%snm,a_geopot,hb)
                    ggrad = matmul(transpose(rotmat),matmul(hb,rotmat))  ! gradient in the inertial frame
                else
                    call pines_gravity(rb,grav_n,grav_m,me%grav%re,me%grav%mu,&
                                       me%grav%cnm,me%grav%snm,a_geopot)
                end if
            else
                call me%grav%get_acc(rb,grav_n,grav_m,a_geopot)  ! get the acc due to the geopotential
            end if
            a_geopot = matmul(transpose(rotmat),a_geopot)    ! convert acc back to inertial frame
        end if

        ! third-body state vectors (wrt the central body, which is the moon in this case):
        ! [inertial frame]
        a_third_body  = zero
        if (me%include_pointmass_earth) then
            call me%eph%get_r(et,body_earth,body_moon,r_earth_wrt_moon,status_ok)
            call me%third_body_gravity(r,r_earth_wrt_moon,mu_earth,a_earth)
            a_third_body = a_third_body + a_earth
            if (stm) ggrad = ggrad + third_body_gravity_gradient(r,r_earth_wrt_moon,mu_earth)
        end if
        if (me%include_pointmass_sun) then
            call me%eph%get_r(et,body_sun,body_moon,r_sun_wrt_moon,status_ok)
            call me%third_body_gravity(r,r_sun_wrt_moon,mu_sun,a_sun)
            a_third_body = a_third_body + a_sun
            if (stm) ggrad = ggrad + third_body_gravity_gradient(r,r_sun_wrt_moon,mu_sun)
        end if
        if (me%include_pointmass_jupiter) then
            call me%eph%get_r(et,body_jupiter,body_moon,r_jupiter_wrt_moon,status_ok)
            call me%third_body_gravity(r,r_jupiter_wrt_moon,mu_jupiter, a_jupiter)
            a_third_body = a_third_body + a_jupiter
            if (stm) ggrad = ggrad + third_body_gravity_gradient(r,r_jupiter_wrt_moon,mu_jupiter)
        end if

        !total derivative vector:
        xdot(1:3) = v
        xdot(4:6) = a_geopot + a_third_body

        if (size(x) > n_eoms) then
            if (stm) then
                ! variational equations: dPhi/dt = [0 I; G 0] Phi
                phi = reshape(x(n_eoms+1:n_eoms_stm), [6,6])
                phidot(1:3,:) = phi(4:6,:)
                phidot(4:6,:) = matmul(ggrad, phi(1:3,:))
                xdot(n_eoms+1:n_eoms_stm) = reshape(phidot, [n_eoms*n_eoms])
            else
                xdot(n_eoms+1:) = zero  ! the STM is not being computed
            end if
        end if

    class default

        error stop 'invalid class in ballistic_derivs'

    end select

    end subroutine ballistic_derivs