ModelSpace
Documentation for ModelSpace models and classes.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
/******************************************************************************
* 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.
******************************************************************************/
/*
Aspherical gravity model header file

Author: Alex Reynolds
*/
/*
Metadata for MS GUI:
imdata = {"displayname" : "Aspherical Gravity",
          "exclude" : False,
          "category" : "Dynamics"
}
aliases = {"mu" : "GM",
           "J2" : "J2",
           "J3" : "J3",
           "r_planet" : "Planet Equatorial Radius",
           "body_mass" : "Spacecraft Mass",
           "pos_body__f" : "Position",
           "grav_accel__f" : "EXCLUDE",
           "grav_force__f" : "Gravity Force",
           "grav_mu" : "EXCLUDE",
           "grav_J2" : "EXCLUDE",
           "grav_J3" : "EXCLUDE",
}
*/

#ifndef MODELS_ENVIRONMENT_ASPHERICAL_GRAVITY_MODEL_H
#define MODELS_ENVIRONMENT_ASPHERICAL_GRAVITY_MODEL_H

#include "simulation/Model.h"
#include "frames/Frame.h"
#include "frames/Node.h"
#include "frames/frameutils.h"
#include "constants/planetdefaults.h"

namespace modelspace {

    // Precalculated constants for internal gravity model use
    const double PC_15_2 = 0.5*15.0;        // Precalc of 15/2
    const double PC_3_2 = 0.5*3.0;          // Precalc of 3/2
    const double PC_35_2 = 0.5*35;          // Precalc of 35/2

    /**
     * @brief   Aspherical gravity model with J2 and J3 effects
     * 
     * This model calculates gravity for a planetary body, accounting for effects
     * due to the J2 and J3 perturbations.
    */
    MODEL(AsphericalGravityModel)
    public:
        // TODO: Replace need for mass with direct acceleration calculation when 
        // body accel methods are implemented
        // Model params
        //         NAME                     TYPE                    DEFAULT VALUE
        START_PARAMS
            /** This is the gravitational parameter of our parent planet. Defaults to
             * Earth's gravitational parameter in m^3/s^2 for ease of use */
            SIGNAL(mu,                      double,                 cfspp::earth_wgs84.mu)
            /** This is the J2 parameter of our parent planet. Defaults to
             * Earth's J2 parameter for ease of use */
            SIGNAL(J2,                      double,                 cfspp::earth_wgs84.J2)
            /** This is the J3 parameter of our parent planet. Defaults to
             * Earth's J3 parameter for ease of use */
            SIGNAL(J3,                      double,                 cfspp::earth_wgs84.J3)
            /** This is the radius of our parent planet. Defaults to Earth's radius, in meters for ease of use */
            SIGNAL(r_planet,                double,                 cfspp::earth_wgs84.eq_radius)
            /** This is the mass of the body, which will be multiplied by our force
             *  to get the force calculation */
            SIGNAL(body_mass,               double,                 1.0)
        END_PARAMS

        // Model inputs
        //         NAME                     TYPE                    DEFAULT VALUE
        START_INPUTS
            /** The position of the object body in the reference frame f */
            SIGNAL(pos_body__f,             CartesianVector3,      CartesianVector3({0.0, 0.0, 0.0}))
        END_INPUTS

        // Model outputs
        //         NAME                     TYPE                    DEFAULT VALUE
        START_OUTPUTS
            /** This is the total acceleration due to gravity calculated in the same reference frame as pos_body__f */
            SIGNAL(grav_accel__f,           CartesianVector3,      CartesianVector3({0.0, 0.0, 0.0}))
            /** This is the total force due to gravity calculated in the same reference frame as pos_body__f */
            SIGNAL(grav_force__f,           CartesianVector3,      CartesianVector3({0.0, 0.0, 0.0}))
            /** This is the acceleration due to  point mass gravity calculated in the same reference frame as pos_body__f */
            SIGNAL(grav_mu,                 CartesianVector3,      CartesianVector3({0.0, 0.0, 0.0}))
            /** This is the acceleration due to J2 calculated in the same reference frame as pos_body__f */
            SIGNAL(grav_J2,                 CartesianVector3,      CartesianVector3({0.0, 0.0, 0.0}))
            /** This is the acceleration due to J3 calculated in the same reference frame as pos_body__f */
            SIGNAL(grav_J3,                 CartesianVector3,      CartesianVector3({0.0, 0.0, 0.0}))
        END_OUTPUTS

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

        // Temporary vectors and variables to carry out our calculations
        double r;
        double precalc_j2;
        double precalc_j3;
        CartesianVector3 grav_force__planet;
    };

}

#endif