Tudat/SimulationSetup/UnitTests/unitTestAccelerationModelSetup.cpp
//! Test set up of spherical harmonic gravitational accelerations.
Test set up of spherical harmonic gravitational accelerations.
Test set up of spherical harmonic gravitational accelerations .
BOOST_AUTO_TEST_CASE( test_shGravityModelSetup )
{
    NamedBodyMap bodyMap;
    bodyMap[ "Earth" ] = std::make_shared< Body >( );
    bodyMap[ "Vehicle" ] = std::make_shared< Body >( );
    Eigen::Vector6d dummyEarthState =
            ( Eigen::Vector6d ( ) << 1.1E11, 0.5E11, 0.01E11, 0.0, 0.0, 0.0
              ).finished( );
    bodyMap[ "Earth" ]->setState( dummyEarthState );
    bodyMap[ "Vehicle" ]->setState(
                ( Eigen::Vector6d ( ) << 7.0e6, 8.0e6, 9.0e6, 0.0, 0.0, 0.0
                  ).finished( ) + dummyEarthState );
    double gravitationalParameter = 3.986004418e14;
    double planetaryRadius = 6378137.0;
    Eigen::MatrixXd cosineCoefficients =
            ( Eigen::MatrixXd( 6, 6 ) <<
              1.0, 0.0, 0.0, 0.0, 0.0, 0.0,
              0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
              -4.841651437908150e-4, -2.066155090741760e-10, 2.439383573283130e-6, 0.0, 0.0, 0.0,
              9.571612070934730e-7, 2.030462010478640e-6, 9.047878948095281e-7,
              7.213217571215680e-7, 0.0, 0.0, 5.399658666389910e-7, -5.361573893888670e-7,
              3.505016239626490e-7, 9.908567666723210e-7, -1.885196330230330e-7, 0.0,
              6.867029137366810e-8, -6.292119230425290e-8, 6.520780431761640e-7,
              -4.518471523288430e-7, -2.953287611756290e-7, 1.748117954960020e-7
              ).finished( );
    Eigen::MatrixXd sineCoefficients =
            ( Eigen::MatrixXd( 6, 6 ) <<
              0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
              0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
              0.0, 1.384413891379790e-9, -1.400273703859340e-6, 0.0, 0.0, 0.0,
              0.0, 2.482004158568720e-7, -6.190054751776180e-7, 1.414349261929410e-6, 0.0, 0.0,
              0.0, -4.735673465180860e-7, 6.624800262758290e-7, -2.009567235674520e-7,
              3.088038821491940e-7, 0.0, 0.0, -9.436980733957690e-8, -3.233531925405220e-7,
              -2.149554083060460e-7, 4.980705501023510e-8, -6.693799351801650e-7
              ).finished( );
    bodyMap[ "Earth" ]->setGravityFieldModel(
                std::make_shared< gravitation::SphericalHarmonicsGravityField >(
                    gravitationalParameter, planetaryRadius, cosineCoefficients,
                    sineCoefficients, "IAU_Earth" ) );
    bodyMap[ "Earth" ]->setRotationalEphemeris(
                std::make_shared< ephemerides::SpiceRotationalEphemeris >(
                    "ECLIPJ2000", "IAU_Earth" ) );
    SelectedAccelerationMap accelerationSettingsMap;
    accelerationSettingsMap[ "Vehicle" ][ "Earth" ].push_back(
                std::make_shared< SphericalHarmonicAccelerationSettings >( 5, 5 ) );
    std::map< std::string, std::string > centralBodies;
    centralBodies[ "Vehicle" ] = "Earth";
    AccelerationMap accelerationsMap = createAccelerationModelsMap(
                bodyMap, accelerationSettingsMap, centralBodies );
    std::shared_ptr< basic_astrodynamics::AccelerationModel< Eigen::Vector3d > >
            directAcceleration = accelerationsMap[ "Vehicle" ][ "Earth" ][ 0 ];
    std::shared_ptr< basic_astrodynamics::AccelerationModel< Eigen::Vector3d > >
            manualAcceleration =
            std::make_shared< gravitation::SphericalHarmonicsGravitationalAccelerationModel >(
                std::bind( &Body::getPosition, bodyMap[ "Vehicle" ] ),
            gravitationalParameter,
            planetaryRadius, cosineCoefficients, sineCoefficients,
            std::bind( &Body::getPosition, bodyMap[ "Earth" ] ) );
    TUDAT_CHECK_MATRIX_CLOSE_FRACTION(
                ( basic_astrodynamics::updateAndGetAcceleration( manualAcceleration ) ),
                ( basic_astrodynamics::updateAndGetAcceleration( directAcceleration ) ),
                std::numeric_limits< double >::epsilon( ) );
    bodyMap[ "Vehicle" ]->setGravityFieldModel( std::make_shared< gravitation::GravityFieldModel >(
                                                    0.1 * gravitationalParameter ) );
    accelerationsMap = createAccelerationModelsMap(
                bodyMap, accelerationSettingsMap, centralBodies );
    directAcceleration = accelerationsMap[ "Vehicle" ][ "Earth" ][ 0 ];
    manualAcceleration =
            std::make_shared< gravitation::SphericalHarmonicsGravitationalAccelerationModel >(
                std::bind( &Body::getPosition, bodyMap[ "Vehicle" ] ),
            gravitationalParameter * 1.1,
            planetaryRadius, cosineCoefficients, sineCoefficients,
            std::bind( &Body::getPosition, bodyMap[ "Earth" ] ) );
    TUDAT_CHECK_MATRIX_CLOSE_FRACTION(
                ( basic_astrodynamics::updateAndGetAcceleration( manualAcceleration ) ),
                ( basic_astrodynamics::updateAndGetAcceleration( directAcceleration ) ),
                std::numeric_limits< double >::epsilon( ) );
}
BOOST_AUTO_TEST_CASE ( test_shGravityModelSetup ) { NamedBodyMap bodyMap ; bodyMap [ " " ] = std :: make_shared < Body > ( ) ; bodyMap [ " " ] = std :: make_shared < Body > ( ) ; Eigen :: Vector6d dummyEarthState = ( Eigen :: Vector6d ( ) << 1.1E11 , 0.5E11 , 0.01E11 , 0.0 , 0.0 , 0.0 ) . finished ( ) ; bodyMap [ " " ] -> setState ( dummyEarthState ) ; bodyMap [ " " ] -> setState ( ( Eigen :: Vector6d ( ) << 7.0e6 , 8.0e6 , 9.0e6 , 0.0 , 0.0 , 0.0 ) . finished ( ) + dummyEarthState ) ; double gravitationalParameter = 3.986004418e14 ; double planetaryRadius = 6378137.0 ; Eigen :: MatrixXd cosineCoefficients = ( Eigen :: MatrixXd ( 6 , 6 ) << 1.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , -4.841651437908150e-4 , -2.066155090741760e-10 , 2.439383573283130e-6 , 0.0 , 0.0 , 0.0 , 9.571612070934730e-7 , 2.030462010478640e-6 , 9.047878948095281e-7 , 7.213217571215680e-7 , 0.0 , 0.0 , 5.399658666389910e-7 , -5.361573893888670e-7 , 3.505016239626490e-7 , 9.908567666723210e-7 , -1.885196330230330e-7 , 0.0 , 6.867029137366810e-8 , -6.292119230425290e-8 , 6.520780431761640e-7 , -4.518471523288430e-7 , -2.953287611756290e-7 , 1.748117954960020e-7 ) . finished ( ) ; Eigen :: MatrixXd sineCoefficients = ( Eigen :: MatrixXd ( 6 , 6 ) << 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 1.384413891379790e-9 , -1.400273703859340e-6 , 0.0 , 0.0 , 0.0 , 0.0 , 2.482004158568720e-7 , -6.190054751776180e-7 , 1.414349261929410e-6 , 0.0 , 0.0 , 0.0 , -4.735673465180860e-7 , 6.624800262758290e-7 , -2.009567235674520e-7 , 3.088038821491940e-7 , 0.0 , 0.0 , -9.436980733957690e-8 , -3.233531925405220e-7 , -2.149554083060460e-7 , 4.980705501023510e-8 , -6.693799351801650e-7 ) . finished ( ) ; bodyMap [ " " ] -> setGravityFieldModel ( std :: make_shared < gravitation :: SphericalHarmonicsGravityField > ( gravitationalParameter , planetaryRadius , cosineCoefficients , sineCoefficients , " " ) ) ; bodyMap [ " " ] -> setRotationalEphemeris ( std :: make_shared < ephemerides :: SpiceRotationalEphemeris > ( " " , " " ) ) ; SelectedAccelerationMap accelerationSettingsMap ; accelerationSettingsMap [ " " ] [ " " ] . push_back ( std :: make_shared < SphericalHarmonicAccelerationSettings > ( 5 , 5 ) ) ; std :: map < std :: string , std :: string > centralBodies ; centralBodies [ " " ] = " " ; AccelerationMap accelerationsMap = createAccelerationModelsMap ( bodyMap , accelerationSettingsMap , centralBodies ) ; std :: shared_ptr < basic_astrodynamics :: AccelerationModel < Eigen :: Vector3d > > directAcceleration = accelerationsMap [ " " ] [ " " ] [ 0 ] ; std :: shared_ptr < basic_astrodynamics :: AccelerationModel < Eigen :: Vector3d > > manualAcceleration = std :: make_shared < gravitation :: SphericalHarmonicsGravitationalAccelerationModel > ( std :: bind ( & Body :: getPosition , bodyMap [ " " ] ) , gravitationalParameter , planetaryRadius , cosineCoefficients , sineCoefficients , std :: bind ( & Body :: getPosition , bodyMap [ " " ] ) ) ; TUDAT_CHECK_MATRIX_CLOSE_FRACTION ( ( basic_astrodynamics :: updateAndGetAcceleration ( manualAcceleration ) ) , ( basic_astrodynamics :: updateAndGetAcceleration ( directAcceleration ) ) , std :: numeric_limits < double > :: epsilon ( ) ) ; bodyMap [ " " ] -> setGravityFieldModel ( std :: make_shared < gravitation :: GravityFieldModel > ( 0.1 * gravitationalParameter ) ) ; accelerationsMap = createAccelerationModelsMap ( bodyMap , accelerationSettingsMap , centralBodies ) ; directAcceleration = accelerationsMap [ " " ] [ " " ] [ 0 ] ; manualAcceleration = std :: make_shared < gravitation :: SphericalHarmonicsGravitationalAccelerationModel > ( std :: bind ( & Body :: getPosition , bodyMap [ " " ] ) , gravitationalParameter * 1.1 , planetaryRadius , cosineCoefficients , sineCoefficients , std :: bind ( & Body :: getPosition , bodyMap [ " " ] ) ) ; TUDAT_CHECK_MATRIX_CLOSE_FRACTION ( ( basic_astrodynamics :: updateAndGetAcceleration ( manualAcceleration ) ) , ( basic_astrodynamics :: updateAndGetAcceleration ( directAcceleration ) ) , std :: numeric_limits < double > :: epsilon ( ) ) ; }
Test set up of spherical harmonic gravitational accelerations.
Test set up of spherical harmonic gravitational accelerations .
// Create body map // Set constant state for Earth and Vehicle // Define Earth gravity field. // Define settings for acceleration model (spherical harmonic due to Earth up to degree and // order 5. // Set accelerations to be calculated w.r.t. the Earth. // Create and retrieve acceleration. // Manually create acceleration model. // Test equivalence of two acceleration models. // Set (unrealistically) a gravity field model on the Vehicle, to test its // influence on acceleration. // Recreate and retrieve acceleration. // Manually create acceleration. // Test equivalence of two acceleration models.