Tudat/Astrodynamics/BasicAstrodynamics/UnitTests/unitTestAccelerationModel.cpp
//! Test whether AnotherDerivedAccelerationModel (acceleration data type=Eigen::Vector2f) functions
//! correctly.
Test whether AnotherDerivedAccelerationModel (acceleration data type=Eigen::Vector2f) functions
correctly.
Test whether AnotherDerivedAccelerationModel ( acceleration data type = Eigen :: Vector2f ) functions correctly .
BOOST_AUTO_TEST_CASE( test_derived2fAccelerationModel )
{
    typedef TestBody< 2, float > TestBody2f;
    typedef std::shared_ptr< TestBody2f > TestBody2fPointer;
    typedef AccelerationModel< Eigen::Vector2f > AccelerationModel2f;
    typedef std::shared_ptr< AccelerationModel2f > AccelerationModel2fPointer;
    typedef AnotherDerivedAccelerationModel< Eigen::Vector2f, Eigen::Vector2f,
            Eigen::Vector2f, float > AnotherDerivedAccelerationModel2f;
    TestBody2fPointer body = std::make_shared< TestBody2f >(
                ( Eigen::VectorXf( 4 ) << -0.3f, 4.5f, 0.1f, 0.2f ).finished( ), -2.3f );
    AccelerationModel2fPointer accelerationModel2f
            = std::make_shared< AnotherDerivedAccelerationModel2f >(
                std::bind( &TestBody2f::getCurrentPosition, body ),
                std::bind( &TestBody2f::getCurrentVelocity, body ),
                std::bind( &TestBody2f::getCurrentTime, body ) );
    std::vector< Eigen::Vector2f > computedAccelerations( 3 );
    computedAccelerations.at( 0 ) = accelerationModel2f->getAcceleration( );
    body->setCurrentTimeAndState(
                0.33f, ( Eigen::VectorXf( 4 ) << 1.34f, 2.65f, -0.23f, 0.1f ).finished( ) );
    accelerationModel2f->updateMembers( );
    computedAccelerations.at( 1 ) = accelerationModel2f->getAcceleration( );
    body->setCurrentTimeAndState(
                -10.3f, ( Eigen::VectorXf( 4 ) << -98.99f, 1.53f, 1.23f, -0.11f ).finished( ) );
    computedAccelerations.at( 2 ) = updateAndGetAcceleration( accelerationModel2f );
    std::vector< Eigen::Vector2f > expectedAccelerations;
    expectedAccelerations.push_back( 0.5 * Eigen::Vector2f( -0.3f, 4.5f )
                                     / ( 3.2 * ( -2.3f + 3.4 ) * -2.3f )
                                     + Eigen::Vector2f( 0.1f, 0.2f ) / -2.3f );
    expectedAccelerations.push_back( 0.5 * Eigen::Vector2f( 1.34f, 2.65f )
                                     / ( 3.2 * ( 0.33f + 3.4 ) * 0.33f )
                                     + Eigen::Vector2f( -0.23f, 0.1f ) / 0.33f );
    expectedAccelerations.push_back( 0.5 * Eigen::Vector2f( -98.99f, 1.53f )
                                     / ( 3.2 * ( -10.3f + 3.4 ) * -10.3f )
                                     + Eigen::Vector2f( 1.23f, -0.11f ) / -10.3f );
    for ( unsigned int i = 0; i < computedAccelerations.size( ); i++ )
    {
        TUDAT_CHECK_MATRIX_BASE( computedAccelerations.at( i ), expectedAccelerations.at( i ) )
                BOOST_CHECK_CLOSE_FRACTION( computedAccelerations.at( i ).coeff( row, col ),
                                   expectedAccelerations.at( i ).coeff( row, col ), 5.0e-7 );
    }
}
BOOST_AUTO_TEST_CASE ( test_derived2fAccelerationModel ) { typedef TestBody < 2 , float > TestBody2f ; typedef std :: shared_ptr < TestBody2f > TestBody2fPointer ; typedef AccelerationModel < Eigen :: Vector2f > AccelerationModel2f ; typedef std :: shared_ptr < AccelerationModel2f > AccelerationModel2fPointer ; typedef AnotherDerivedAccelerationModel < Eigen :: Vector2f , Eigen :: Vector2f , Eigen :: Vector2f , float > AnotherDerivedAccelerationModel2f ; TestBody2fPointer body = std :: make_shared < TestBody2f > ( ( Eigen :: VectorXf ( 4 ) << -0.3f , 4.5f , 0.1f , 0.2f ) . finished ( ) , -2.3f ) ; AccelerationModel2fPointer accelerationModel2f = std :: make_shared < AnotherDerivedAccelerationModel2f > ( std :: bind ( & TestBody2f :: getCurrentPosition , body ) , std :: bind ( & TestBody2f :: getCurrentVelocity , body ) , std :: bind ( & TestBody2f :: getCurrentTime , body ) ) ; std :: vector < Eigen :: Vector2f > computedAccelerations ( 3 ) ; computedAccelerations . at ( 0 ) = accelerationModel2f -> getAcceleration ( ) ; body -> setCurrentTimeAndState ( 0.33f , ( Eigen :: VectorXf ( 4 ) << 1.34f , 2.65f , -0.23f , 0.1f ) . finished ( ) ) ; accelerationModel2f -> updateMembers ( ) ; computedAccelerations . at ( 1 ) = accelerationModel2f -> getAcceleration ( ) ; body -> setCurrentTimeAndState ( -10.3f , ( Eigen :: VectorXf ( 4 ) << -98.99f , 1.53f , 1.23f , -0.11f ) . finished ( ) ) ; computedAccelerations . at ( 2 ) = updateAndGetAcceleration ( accelerationModel2f ) ; std :: vector < Eigen :: Vector2f > expectedAccelerations ; expectedAccelerations . push_back ( 0.5 * Eigen :: Vector2f ( -0.3f , 4.5f ) / ( 3.2 * ( -2.3f + 3.4 ) * -2.3f ) + Eigen :: Vector2f ( 0.1f , 0.2f ) / -2.3f ) ; expectedAccelerations . push_back ( 0.5 * Eigen :: Vector2f ( 1.34f , 2.65f ) / ( 3.2 * ( 0.33f + 3.4 ) * 0.33f ) + Eigen :: Vector2f ( -0.23f , 0.1f ) / 0.33f ) ; expectedAccelerations . push_back ( 0.5 * Eigen :: Vector2f ( -98.99f , 1.53f ) / ( 3.2 * ( -10.3f + 3.4 ) * -10.3f ) + Eigen :: Vector2f ( 1.23f , -0.11f ) / -10.3f ) ; for ( unsigned int i = 0 ; i < computedAccelerations . size ( ) ; i ++ ) { TUDAT_CHECK_MATRIX_BASE ( computedAccelerations . at ( i ) , expectedAccelerations . at ( i ) ) BOOST_CHECK_CLOSE_FRACTION ( computedAccelerations . at ( i ) . coeff ( row , col ) , expectedAccelerations . at ( i ) . coeff ( row , col ) , 5.0e-7 ) ; } }
Test whether AnotherDerivedAccelerationModel (acceleration data type=Eigen::Vector2f) functions
correctly.
Test whether AnotherDerivedAccelerationModel ( acceleration data type = Eigen :: Vector2f ) functions correctly .
// NOTE: For this test, it is imperative that the float values are given with the "f" // suffix, to ensure that their precision is indeed of float-type. // Shortcuts. // Create body with initial state and time. // Create acceleration model using AnotherDerivedAccelerationModel class, and pass pointers to // functions in body. // Declare container of computed accelerations. // Get acceleration vector before members are updated. // Update time and state. // Update acceleration model members. // Get acceleration vector, now after members have been updated. // Update time and state. // Update and get acceleration with single function. // Set expected accelerations. // Check that the acceleration vectors before and after the update match expected values.