Tudat/SimulationSetup/UnitTests/unitTestAccelerationModelSetup.cpp
//! Test setup of aerodynamic accelerations (non-constant coefficients)
Test setup of aerodynamic accelerations (non-constant coefficients)
Test setup of aerodynamic accelerations ( non - constant coefficients )
BOOST_AUTO_TEST_CASE( test_aerodynamicAccelerationModelSetupWithCoefficientIndependentVariables )
{
    using namespace tudat::simulation_setup;
    using namespace tudat;
    spice_interface::loadStandardSpiceKernels( );
    std::map< std::string, std::shared_ptr< BodySettings > > bodySettings;
    bodySettings[ "Earth" ] = getDefaultSingleBodySettings( "Earth", 0.0, 86400.0 );
    bodySettings[ "Vehicle" ] = std::make_shared< BodySettings >( );
    NamedBodyMap bodyMap = createBodies( bodySettings );
    setGlobalFrameBodyEphemerides( bodyMap, "SSB", "ECLIPJ2000" );
    bodyMap[ "Vehicle" ]->setAerodynamicCoefficientInterface(
                getApolloCoefficientInterface( ) );
    SelectedAccelerationMap accelerationSettingsMap;
    accelerationSettingsMap[ "Vehicle" ][ "Earth" ].push_back(
                std::make_shared< AccelerationSettings >( aerodynamic ) );
    std::map< std::string, std::string > centralBodies;
    centralBodies[ "Vehicle" ] = "Earth";
    AccelerationMap accelerationsMap = createAccelerationModelsMap(
                bodyMap, accelerationSettingsMap, centralBodies );
    std::shared_ptr< AccelerationModel3d > aerodynamicAcceleration = accelerationsMap[ "Vehicle" ][ "Earth" ][ 0 ];
    std::shared_ptr< aerodynamics::FlightConditions > vehicleFlightConditions =
            bodyMap[ "Vehicle" ]->getFlightConditions( );
    std::shared_ptr< aerodynamics::AerodynamicCoefficientInterface > coefficientInterface =
            bodyMap[ "Vehicle" ]->getAerodynamicCoefficientInterface( );
    double angleOfAttack = 1.232;
    double angleOfSideslip = -0.00322;
    double bankAngle = 2.323432;
    vehicleFlightConditions->getAerodynamicAngleCalculator( )->setOrientationAngleFunctions(
                [ & ]( ){ return angleOfAttack; },
                [ & ]( ){ return angleOfSideslip; },
                [ & ]( ){ return bankAngle; } );
    double testTime = 0.5E7;
    bodyMap[ "Earth" ]->setCurrentRotationalStateToLocalFrameFromEphemeris( testTime );
    bodyMap[ "Earth" ]->setState( Eigen::Vector6d::Zero( ) );
    double bodyMass = 500.0;
    bodyMap[ "Vehicle" ]->setBodyMassFunction( [ & ]( const double ){ return bodyMass; } );
    bodyMap[ "Vehicle" ]->updateMass( testTime );
    for( unsigned int i = 0; i < 4; i++ )
    {
        Eigen::Vector6d vehicleBodyFixedState =
                ( Eigen::Vector6d( ) << -1656517.23153109, -5790058.28764025, -2440584.88186829,
                  6526.30784888051, -2661.34558272018, 2377.09572383163 ).finished( );
        if( i > 0 )
        {
            vehicleBodyFixedState.segment( 3, 3 ) += ( Eigen::Vector3d( ) << -3234.2, 2456.2, 33.245 ).finished( );
        }
        Eigen::Vector6d vehicleInertialState =
                ephemerides::transformStateToFrameFromRotations(
                    vehicleBodyFixedState,
                    bodyMap[ "Earth" ]->getRotationalEphemeris( )->getRotationToBaseFrame( testTime ),
                bodyMap[ "Earth" ]->getRotationalEphemeris( )->getDerivativeOfRotationToBaseFrame( testTime ) );
        bodyMap[ "Vehicle" ]->setState( vehicleInertialState );
        if( i > 1 )
        {
            angleOfAttack -= 0.6465;
        }
        if( i > 2  )
        {
            angleOfSideslip += 0.00123;
        }
        vehicleFlightConditions->getAerodynamicAngleCalculator( )->setOrientationAngleFunctions(
                    [ & ]( ){ return angleOfAttack; },
                    [ & ]( ){ return angleOfSideslip; },
                    [ & ]( ){ return bankAngle; } );
        vehicleFlightConditions->resetCurrentTime( TUDAT_NAN );
        vehicleFlightConditions->updateConditions( testTime );
        double velocity = vehicleBodyFixedState.segment( 3, 3 ).norm( );
        double speedOfSound = bodyMap[ "Earth" ]->getAtmosphereModel( )->getSpeedOfSound(
                    vehicleFlightConditions->getCurrentAltitude( ), 0.0, 0.0, 0.0 );
        double machNumber = velocity / speedOfSound;
        Eigen::Vector3d automaticCoefficients = coefficientInterface->getCurrentForceCoefficients( );
        coefficientInterface->updateFullCurrentCoefficients(
                   { machNumber, angleOfAttack, angleOfSideslip } );
        Eigen::Vector3d manualCoefficients = coefficientInterface->getCurrentForceCoefficients( );
        TUDAT_CHECK_MATRIX_CLOSE_FRACTION(
                    automaticCoefficients, manualCoefficients, ( 5.0 *  std::numeric_limits< double >::epsilon( ) ) );
    }
}
BOOST_AUTO_TEST_CASE ( test_aerodynamicAccelerationModelSetupWithCoefficientIndependentVariables ) { using namespace tudat :: simulation_setup ; using namespace tudat ; spice_interface :: loadStandardSpiceKernels ( ) ; std :: map < std :: string , std :: shared_ptr < BodySettings > > bodySettings ; bodySettings [ " " ] = getDefaultSingleBodySettings ( " " , 0.0 , 86400.0 ) ; bodySettings [ " " ] = std :: make_shared < BodySettings > ( ) ; NamedBodyMap bodyMap = createBodies ( bodySettings ) ; setGlobalFrameBodyEphemerides ( bodyMap , " " , " " ) ; bodyMap [ " " ] -> setAerodynamicCoefficientInterface ( getApolloCoefficientInterface ( ) ) ; SelectedAccelerationMap accelerationSettingsMap ; accelerationSettingsMap [ " " ] [ " " ] . push_back ( std :: make_shared < AccelerationSettings > ( aerodynamic ) ) ; std :: map < std :: string , std :: string > centralBodies ; centralBodies [ " " ] = " " ; AccelerationMap accelerationsMap = createAccelerationModelsMap ( bodyMap , accelerationSettingsMap , centralBodies ) ; std :: shared_ptr < AccelerationModel3d > aerodynamicAcceleration = accelerationsMap [ " " ] [ " " ] [ 0 ] ; std :: shared_ptr < aerodynamics :: FlightConditions > vehicleFlightConditions = bodyMap [ " " ] -> getFlightConditions ( ) ; std :: shared_ptr < aerodynamics :: AerodynamicCoefficientInterface > coefficientInterface = bodyMap [ " " ] -> getAerodynamicCoefficientInterface ( ) ; double angleOfAttack = 1.232 ; double angleOfSideslip = -0.00322 ; double bankAngle = 2.323432 ; vehicleFlightConditions -> getAerodynamicAngleCalculator ( ) -> setOrientationAngleFunctions ( [ & ] ( ) { return angleOfAttack ; } , [ & ] ( ) { return angleOfSideslip ; } , [ & ] ( ) { return bankAngle ; } ) ; double testTime = 0.5E7 ; bodyMap [ " " ] -> setCurrentRotationalStateToLocalFrameFromEphemeris ( testTime ) ; bodyMap [ " " ] -> setState ( Eigen :: Vector6d :: Zero ( ) ) ; double bodyMass = 500.0 ; bodyMap [ " " ] -> setBodyMassFunction ( [ & ] ( const double ) { return bodyMass ; } ) ; bodyMap [ " " ] -> updateMass ( testTime ) ; for ( unsigned int i = 0 ; i < 4 ; i ++ ) { Eigen :: Vector6d vehicleBodyFixedState = ( Eigen :: Vector6d ( ) << -1656517.23153109 , -5790058.28764025 , -2440584.88186829 , 6526.30784888051 , -2661.34558272018 , 2377.09572383163 ) . finished ( ) ; if ( i > 0 ) { vehicleBodyFixedState . segment ( 3 , 3 ) += ( Eigen :: Vector3d ( ) << -3234.2 , 2456.2 , 33.245 ) . finished ( ) ; } Eigen :: Vector6d vehicleInertialState = ephemerides :: transformStateToFrameFromRotations ( vehicleBodyFixedState , bodyMap [ " " ] -> getRotationalEphemeris ( ) -> getRotationToBaseFrame ( testTime ) , bodyMap [ " " ] -> getRotationalEphemeris ( ) -> getDerivativeOfRotationToBaseFrame ( testTime ) ) ; bodyMap [ " " ] -> setState ( vehicleInertialState ) ; if ( i > 1 ) { angleOfAttack -= 0.6465 ; } if ( i > 2 ) { angleOfSideslip += 0.00123 ; } vehicleFlightConditions -> getAerodynamicAngleCalculator ( ) -> setOrientationAngleFunctions ( [ & ] ( ) { return angleOfAttack ; } , [ & ] ( ) { return angleOfSideslip ; } , [ & ] ( ) { return bankAngle ; } ) ; vehicleFlightConditions -> resetCurrentTime ( TUDAT_NAN ) ; vehicleFlightConditions -> updateConditions ( testTime ) ; double velocity = vehicleBodyFixedState . segment ( 3 , 3 ) . norm ( ) ; double speedOfSound = bodyMap [ " " ] -> getAtmosphereModel ( ) -> getSpeedOfSound ( vehicleFlightConditions -> getCurrentAltitude ( ) , 0.0 , 0.0 , 0.0 ) ; double machNumber = velocity / speedOfSound ; Eigen :: Vector3d automaticCoefficients = coefficientInterface -> getCurrentForceCoefficients ( ) ; coefficientInterface -> updateFullCurrentCoefficients ( { machNumber , angleOfAttack , angleOfSideslip } ) ; Eigen :: Vector3d manualCoefficients = coefficientInterface -> getCurrentForceCoefficients ( ) ; TUDAT_CHECK_MATRIX_CLOSE_FRACTION ( automaticCoefficients , manualCoefficients , ( 5.0 * std :: numeric_limits < double > :: epsilon ( ) ) ) ; } }
Test setup of aerodynamic accelerations (non-constant coefficients)
Test setup of aerodynamic accelerations ( non - constant coefficients )
// Load Spice kernels // Get settings for Earth. // Create body objects. // Create vehicle aerodynamic coefficients // Define settings for accelerations: point // Define origin of integration // Create accelerations // Retrieve flight conditions and orientation angles // Define orientation angles. // Update environment to current time. // Set vehicle mass // Test aerodynamic coefficients for various cases of independent variables. // Define body-fixed vehicle state. // Define vehicle inertial state. // Define orientation angles. // Update flight conditions // Calculate Mach number // Get manual and automatic coefficients and compare.