WarpTwin
Documentation for WarpTwin models and classes.
Loading...
Searching...
No Matches
DipoleMagneticFieldModel.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.
******************************************************************************/
/*
Dipole magnetic field model header file

Author: James Tabony
*/
/*
Metadata for MS GUI:
imdata = {"exclude" : True}
*/

#ifndef MODELS_ENVIRONMENT_DIPOLE_MAGNETIC_FIELD_MODEL_H 
#define MODELS_ENVIRONMENT_DIPOLE_MAGNETIC_FIELD_MODEL_H

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

namespace warptwin {

    /**
     * @brief   Simplified magnetic field model which treats Earth as a dipole magnet
     * 
     * This model calculates the magnetic field vector represented in the
     * PCI frame and object frame using a simple dipole model. The equations
     * and parameters used for this model come from "Fundamentals of
     * Spacecraft Attitude Determination and Control" by Markley and
     * Crassidis, chapter 11 section 1.1, equation 11.5
     * 
     * Note: Crassidis defines the equations from the magnetic south pole,
     * I define my equations from the magnetic north pole.
     * 
     * Author: James Tabony
     * Email: james.tabony@attx.tech
     * 
    */
    MODEL(DipoleMagneticFieldModel)
    public:
        // Model params
        //         NAME                     TYPE                    DEFAULT VALUE
        START_PARAMS
            /** The colatitude of the IGRF magnetic north pole as referenced in the global
             *  latitude/longitude map. Defaults to global north pole (radians) */
            SIGNAL(mag_north_colat,         double,                 0.0)
            /** The longitude of the IGRF magnetic north pole as referenced in the global
             *  latitude/longitude map. Defaults to globak north pole (radians) */
            SIGNAL(mag_north_lon,           double,                 0.0)
            /** Planet magnetic field magnitude at planet equitorial distance. Defaults to Earth. (nT ~ nanoTesla) */
            SIGNAL(dipole_magnitude,        double,                 30034)
            /** Planet equitorial distance, specific to the magnetic field model. Defaults to Earth. (meters) */
            SIGNAL(r_planet_equitorial,     double,                 warpos::earth_wgs84.eq_radius)
            /** Planet rotating frame pointer. */
            SIGNAL(planet_frame_rotating,   Frame*,                nullptr)
        END_PARAMS

        // Model inputs
        //         NAME                     TYPE                    DEFAULT VALUE
        START_INPUTS
            /** Position of the object frame with respect to the planet rotating frame,
             *  resolved/expressed in the planet rotating frame coordinates. (meters) */
            SIGNAL(pos_obj_planet__PCR,     CartesianVector3,      CartesianVector3({0.0, 0.0, 0.0}))
        END_INPUTS

        // Model outputs
        //         NAME                     TYPE                    DEFAULT VALUE
        START_OUTPUTS
            /** The magnetic field vector local to the object, represented in the planet centered
             *  rotating frame, PCR. (nT ~ nanoTesla) */
            SIGNAL(mag_field_obj__PCR,      CartesianVector3,      CartesianVector3({0.0, 0.0, 0.0}))
        END_OUTPUTS

    protected:
        // Execute in protected
        int16 start() override;
        int16 execute() override;

        // Internal variable for error handling
        int _err;

        // Temporary vectors and variables to carry out our calculations
        CartesianVector3 _mag_dipole__PCR; // Magnetic dipole vector in planet centered rotating coordinates
        CartesianVector3 _mag_field__PCR;  // Magnetic field vector in planet centered rotating coordinates

        // Internal variables for scaling factora
        double _scaling_factor;

    };

}

#endif