WarpTwin
Documentation for WarpTwin models and classes.
Loading...
Searching...
No Matches
CR3BPDynamicsModel.h
/******************************************************************************
* Copyright (c) ATTX INC 2025. All Rights Reserved.
*
* This software and associated documentation (the "Software") are the 
* proprietary and confidential information of ATTX INC. The Software is 
* furnished under a license agreement between ATTX and the user organization 
* and may be used or copied only in accordance with the terms of the agreement.
* Refer to 'license/attx_license.adoc' for standard license terms.
*
* EXPORT CONTROL NOTICE: THIS SOFTWARE MAY INCLUDE CONTENT CONTROLLED UNDER THE
* INTERNATIONAL TRAFFIC IN ARMS REGULATIONS (ITAR) OR THE EXPORT ADMINISTRATION 
* REGULATIONS (EAR99). No part of the Software may be used, reproduced, or 
* transmitted in any form or by any means, for any purpose, without the express 
* written permission of ATTX INC.
******************************************************************************/
/*
Circular restricted three body dynamics header file

Author: Alex Reynolds
*/
/*
Metadata for MS GUI:
imdata = {"displayname" : "Three Body Dynamics",
          "exclude" : False,
          "category" : "Dynamics"
}
aliases = {"mu_primary" : "GM Primary",
           "mu_secondary" : "GM Secondary",
           "orbit_radius" : "Orbit Radius",
           "use_canonical" : "EXCLUDE",
           "pos_synodic" : "Position",
           "vel_synodic" : "Velocity",
           "accel_synodic" : "Acceleration"
}
*/

#ifndef MODELS_ACTUATORS_CR3BP_DYNAMICS_MODEL_H
#define MODELS_ACTUATORS_CR3BP_DYNAMICS_MODEL_H

#include "core/mathmacros.h"
#include "simulation/Model.h"
#include "cr3bputils/CR3BPDynamics.h"
#include "constants/planetdefaults.h"

namespace warptwin {

    /**
     * @brief   Simplified dynamics model representing motion in the circular restricted 3 body problem
     * 
     * This model calculates the expected acceleration experienced by a 
     * body acting under three-body dynamics using the circular restricted
     * three body assumptions. 
     * 
     * Note the synodic frame definition is consistent with the definitions
     * in this same directory, which is as follows:
     * - Frame centered at the system barycenter
     * - Frame +x directed from the major body to the minor body
     * - Frame +z aligned to the minor body's angular momentum vector
     * - Frame +y completes the RH frame along the definition of minor planet travel
     * 
     * Key assumptions:
     * - The model outputs acceleration, not force, and so to apply it to a
     *   WarpTwin frame requires conversion or a body with unit mass
    */
    MODEL(CR3BPDynamicsModel)
    public:
        // Model params
        //         NAME                     TYPE                    DEFAULT VALUE
        START_PARAMS
            /** The gravitational parameter of the primary body of the system.
                Defaults to the gravitational parameter of the Earth in m^3/s^2 */
            SIGNAL(mu_primary,              double,                 warpos::earth_wgs84.mu)
            /** The gravitational parameter of the secondary body of the system.
                Defaults to the gravitational parameter of the Moon in m^3/s^2 */
            SIGNAL(mu_secondary,            double,                 warpos::moon_nasa.mu)
            /** The distance the secondary body maintains from the primary body in the CR3BP */
            SIGNAL(orbit_radius,            double,                 384800000)
            /** Flag to indicate whether model should use ND canonical units (true) or standard units (false) */
            SIGNAL(use_canonical,           int,                    true)
        END_PARAMS

        // Model inputs
        //         NAME                     TYPE                    DEFAULT VALUE
        START_INPUTS
            /** The position of the spacecraft in the rotating three body "synodic" frame.
                Default is in meters */
            SIGNAL(pos_synodic,             CartesianVector3,       CartesianVector3({0.0, 0.0, 0.0}))
            /** The velocity of the spacecraft in the rotating three body "synodic" frame.
                Default is in meters/second */
            SIGNAL(vel_synodic,             CartesianVector3,       CartesianVector3({0.0, 0.0, 0.0}))
        END_INPUTS

        // Model outputs
        //         NAME                     TYPE                    DEFAULT VALUE
        START_OUTPUTS
            /** The acceleration of the spacecraft in the rotating three body "synodic" frame.
                Default is in meters/s^2 */
            SIGNAL(accel_synodic,           CartesianVector3,       CartesianVector3({0.0, 0.0, 0.0}))
        END_OUTPUTS

    protected:
        int16 start();
        int16 execute();

        // CR3BP conversions
        double _mu_star;
        double _l_star;
        double _t_star;

        CartesianVector3 _internal_pos;
        CartesianVector3 _internal_vel;

        std::array<double, 6> _input_states;
        std::array<double, 6> _rates;
        CR3BPDynamics _dynamics;
        CartesianVector3 _tmp;
    };
}

#endif