WarpTwin
Documentation for WarpTwin models and classes.
Loading...
Searching...
No Matches
MSISAtmosphereModel.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.
******************************************************************************/
/*
MSIS Atmosphere Model header file

Author: Alex Reynolds
*/
/*
Metadata for MS GUI:
imdata = {"exclude" : True}
*/

#ifndef MODELS_ENVIRONMENT_MSIS_ATMOSPHERE_MODEL
#define MODELS_ENVIRONMENT_MSIS_ATMOSPHERE_MODEL

#include "simulation/Model.h"
#include "msis/nrlmsise-00.h"

namespace warptwin {

    /**
     * @brief High fidelity atmosphere model utilizing the NRL MSIS implementation
     * 
     * The MSIS atmosphere model is derived from the c-based MSIS
     * implementation posted at 
     * https://git.smce.nasa.gov/ccmc-share/modelwebarchive/-/tree/main/MSIS/NRLMSIS00/nrlmsis00_c_version
     * 
     * It runs in the start step model call and generally takes
     * detic latitude, longitude, and altitude wrt Earth as inputs
     * and outputs density, temperature, and ideal gas pressure.
    */
    MODEL(MSISAtmosphereModel)
    public:
        // Model params
        //         NAME                     TYPE                    DEFAULT VALUE
        START_PARAMS
            /** 81 day average, centered on input time, of F10.7 solar activity index */
            SIGNAL(solar_flux_81d_avg,      double,                 150.0)
            /** Daily F10.7 solar activity for previous day */
            SIGNAL(solar_flux_day,          double,                 150.0)
            /** Daily Ap geomagnetic activity index */
            SIGNAL(daily_ap,                double,                 10.0)
            /** Our R value for ideal gas pressure calculation. Default is
             * for air */
            SIGNAL(R_idealgas_kJ_kg_K,      double,                 286.0)
        END_PARAMS

        // Model inputs
        //         NAME                     TYPE                    DEFAULT VALUE
        START_INPUTS
            /** The detic latitude to query, in radians */
            SIGNAL(lat_rad,                 double,                 0.0)
            /** The longitude to query, in radians */
            SIGNAL(lon_rad,                 double,                 0.0)
            /** The detic altitude above ground level to query, in meters */
            SIGNAL(alt_m,                   double,                 0.0)
            /** The day of the year (1 to 366) */
            SIGNAL(day,                     int,                    1)
            /** The universal time, in seconds, in the current day. Up to 86400.0 */
            SIGNAL(utsec,                   double,                 0.0)
        END_INPUTS

        // Model outputs
        //         NAME                     TYPE                    DEFAULT VALUE
        START_OUTPUTS
            /** The total atmospheric mass density in kg/m^3 */
            SIGNAL(density_kg_m3,           double,                 0.0)
            /** The temperature at the query point in degrees K */
            SIGNAL(temperature_K,           double,                 0.0)
            /** The ideal gas P=rho*R*T atmospheric pressure at the query point
             * in N/m^2. Derived from MSIS -- applicability will vary due
             * to ideal gas assumption. */
            SIGNAL(pressure_ideal_N_m2,     double,                 0.0)
        END_OUTPUTS 
        
        /// @brief Set delayed output on MSIS model
        /// @param num_steps The number of steps to delay until starting calculation
        void delayCalcSteps(unsigned int num_steps) {_start_run = num_steps;}
    protected:
        int16 start() override;
        int16 execute() override;

        /// @brief   Function to check range of input values
        /// @return  Error code corresponding to success/failure
        int _msisCheckInputs();

        // Flag, input, output MSIS parameters specified per nrlmsise-00.h.
        // Used to interact with the actual MSIS model.
        nrlmsise_flags _flags;
        nrlmsise_input _input;
        nrlmsise_output _output;

        unsigned int _step_counter = 0;
        unsigned int _start_run = 0;
    };
}

#endif