Tudat/Astrodynamics/OrbitDetermination/AccelerationPartials/sphericalHarmonicAccelerationPartial.cpp
//! Function to create a function returning a partial w.r.t. a vector parameter.
Function to create a function returning a partial w.r.t. a vector parameter.
Function to create a function returning a partial w . r . t . a vector parameter .
std::pair< std::function< void( Eigen::MatrixXd& ) >, int > SphericalHarmonicsGravityPartial::getParameterPartialFunction(
        std::shared_ptr< estimatable_parameters::EstimatableParameter< Eigen::VectorXd > > parameter )
{
    using namespace tudat::estimatable_parameters;
    std::function< void( Eigen::MatrixXd& ) > partialFunction;
    int numberOfRows = 0;
    if( parameter->getParameterName( ).second.first == acceleratingBody_ )
    {
        if( estimatable_parameters::isParameterRotationMatrixProperty( parameter->getParameterName( ).first ) )
        {
            if( rotationMatrixPartials_.count( std::make_pair( parameter->getParameterName( ).first,
                                                               parameter->getSecondaryIdentifier( ) ) ) != 0 )
            {
                partialFunction = std::bind(
                            &SphericalHarmonicsGravityPartial::wrtRotationModelParameter,
                            this, std::placeholders::_1, parameter->getParameterName( ).first, parameter->getSecondaryIdentifier( ) );
                numberOfRows = parameter->getParameterSize( );
            }
            else
            {
                std::string errorMessage = "Error, not taking partial of sh acceleration wrt rotational parameter" +
                        std::to_string( parameter->getParameterName( ).first ) + " of " +
                        parameter->getParameterName( ).second.first;
                throw std::runtime_error( errorMessage );
            }
        }
        else if( estimatable_parameters::isParameterTidalProperty( parameter->getParameterName( ).first ) )
        {
            std::shared_ptr< estimatable_parameters::TidalLoveNumber< Eigen::VectorXd > > tidalLoveNumber =
                    std::dynamic_pointer_cast< estimatable_parameters::TidalLoveNumber< Eigen::VectorXd >  >( parameter );
            if( tidalLoveNumber == nullptr )
            {
                throw std::runtime_error( "Error when getting tidal Love number vector parameter, object is nullptr" );
            }
            int degree = tidalLoveNumber->getDegree( );
            std::vector< int > orders = tidalLoveNumber->getOrders( );
            int sumOrders = tidalLoveNumber->getSumOrders( );
            std::pair< int, std::pair< int, int > > currentTidalPartialOutput;
            for( unsigned int i = 0; i < tidalLoveNumberPartialInterfaces_.size( ); i++ )
            {
                currentTidalPartialOutput = tidalLoveNumberPartialInterfaces_.at( i )->setParameterPartialFunction(
                            parameter, maximumDegree_, maximumOrder_ );
                if( numberOfRows != 0 && currentTidalPartialOutput.first > 0 )
                {
                    throw std::runtime_error( "Error when getting vector tidal parameter partial, inconsistent output" +
                                              std::to_string( numberOfRows ) + ", " +
                                              std::to_string( currentTidalPartialOutput.first ) );
                }
                else
                {
                    if( currentTidalPartialOutput.first > 0 )
                    {
                        std::function< std::vector< Eigen::Matrix< double, 2, Eigen::Dynamic > >( ) > coefficientPartialFunction =
                                std::bind( &orbit_determination::TidalLoveNumberPartialInterface::getCurrentVectorParameterPartial,
                                             tidalLoveNumberPartialInterfaces_.at( i ), parameter, currentTidalPartialOutput.second );
                        partialFunction = std::bind(
                                    &SphericalHarmonicsGravityPartial::wrtTidalModelParameter, this, coefficientPartialFunction,
                                    degree, orders, sumOrders, parameter->getParameterSize( ), std::placeholders::_1 );
                        numberOfRows = currentTidalPartialOutput.first;
                    }
                }
            }
        }
        else
        {
            switch( parameter->getParameterName( ).first )
            {
            case spherical_harmonics_cosine_coefficient_block:
            {
                std::shared_ptr< SphericalHarmonicsCosineCoefficients > coefficientsParameter =
                        std::dynamic_pointer_cast< SphericalHarmonicsCosineCoefficients >( parameter );
                partialFunction = std::bind( &SphericalHarmonicsGravityPartial::wrtCosineCoefficientBlock, this,
                                               coefficientsParameter->getBlockIndices( ), std::placeholders::_1 );
                numberOfRows = coefficientsParameter->getParameterSize( );
                break;
            }
            case spherical_harmonics_sine_coefficient_block:
            {
                std::shared_ptr< SphericalHarmonicsSineCoefficients > coefficientsParameter =
                        std::dynamic_pointer_cast< SphericalHarmonicsSineCoefficients >( parameter );
                partialFunction = std::bind( &SphericalHarmonicsGravityPartial::wrtSineCoefficientBlock, this,
                                               coefficientsParameter->getBlockIndices( ), std::placeholders::_1 );
                numberOfRows = coefficientsParameter->getParameterSize( );
                break;
            }
            default:
                break;
            }
        }
    }
    return std::make_pair( partialFunction, numberOfRows );
}
std :: pair < std :: function < void ( Eigen :: MatrixXd & ) > , int > SphericalHarmonicsGravityPartial :: getParameterPartialFunction ( std :: shared_ptr < estimatable_parameters :: EstimatableParameter < Eigen :: VectorXd > > parameter ) { using namespace tudat :: estimatable_parameters ; std :: function < void ( Eigen :: MatrixXd & ) > partialFunction ; int numberOfRows = 0 ; if ( parameter -> getParameterName ( ) . second . first == acceleratingBody_ ) { if ( estimatable_parameters :: isParameterRotationMatrixProperty ( parameter -> getParameterName ( ) . first ) ) { if ( rotationMatrixPartials_ . count ( std :: make_pair ( parameter -> getParameterName ( ) . first , parameter -> getSecondaryIdentifier ( ) ) ) != 0 ) { partialFunction = std :: bind ( & SphericalHarmonicsGravityPartial :: wrtRotationModelParameter , this , std :: placeholders :: _1 , parameter -> getParameterName ( ) . first , parameter -> getSecondaryIdentifier ( ) ) ; numberOfRows = parameter -> getParameterSize ( ) ; } else { std :: string errorMessage = " " + std :: to_string ( parameter -> getParameterName ( ) . first ) + " " + parameter -> getParameterName ( ) . second . first ; throw std :: runtime_error ( errorMessage ) ; } } else if ( estimatable_parameters :: isParameterTidalProperty ( parameter -> getParameterName ( ) . first ) ) { std :: shared_ptr < estimatable_parameters :: TidalLoveNumber < Eigen :: VectorXd > > tidalLoveNumber = std :: dynamic_pointer_cast < estimatable_parameters :: TidalLoveNumber < Eigen :: VectorXd > > ( parameter ) ; if ( tidalLoveNumber == nullptr ) { throw std :: runtime_error ( " " ) ; } int degree = tidalLoveNumber -> getDegree ( ) ; std :: vector < int > orders = tidalLoveNumber -> getOrders ( ) ; int sumOrders = tidalLoveNumber -> getSumOrders ( ) ; std :: pair < int , std :: pair < int , int > > currentTidalPartialOutput ; for ( unsigned int i = 0 ; i < tidalLoveNumberPartialInterfaces_ . size ( ) ; i ++ ) { currentTidalPartialOutput = tidalLoveNumberPartialInterfaces_ . at ( i ) -> setParameterPartialFunction ( parameter , maximumDegree_ , maximumOrder_ ) ; if ( numberOfRows != 0 && currentTidalPartialOutput . first > 0 ) { throw std :: runtime_error ( " " + std :: to_string ( numberOfRows ) + " " + std :: to_string ( currentTidalPartialOutput . first ) ) ; } else { if ( currentTidalPartialOutput . first > 0 ) { std :: function < std :: vector < Eigen :: Matrix < double , 2 , Eigen :: Dynamic > > ( ) > coefficientPartialFunction = std :: bind ( & orbit_determination :: TidalLoveNumberPartialInterface :: getCurrentVectorParameterPartial , tidalLoveNumberPartialInterfaces_ . at ( i ) , parameter , currentTidalPartialOutput . second ) ; partialFunction = std :: bind ( & SphericalHarmonicsGravityPartial :: wrtTidalModelParameter , this , coefficientPartialFunction , degree , orders , sumOrders , parameter -> getParameterSize ( ) , std :: placeholders :: _1 ) ; numberOfRows = currentTidalPartialOutput . first ; } } } } else { switch ( parameter -> getParameterName ( ) . first ) { case spherical_harmonics_cosine_coefficient_block : { std :: shared_ptr < SphericalHarmonicsCosineCoefficients > coefficientsParameter = std :: dynamic_pointer_cast < SphericalHarmonicsCosineCoefficients > ( parameter ) ; partialFunction = std :: bind ( & SphericalHarmonicsGravityPartial :: wrtCosineCoefficientBlock , this , coefficientsParameter -> getBlockIndices ( ) , std :: placeholders :: _1 ) ; numberOfRows = coefficientsParameter -> getParameterSize ( ) ; break ; } case spherical_harmonics_sine_coefficient_block : { std :: shared_ptr < SphericalHarmonicsSineCoefficients > coefficientsParameter = std :: dynamic_pointer_cast < SphericalHarmonicsSineCoefficients > ( parameter ) ; partialFunction = std :: bind ( & SphericalHarmonicsGravityPartial :: wrtSineCoefficientBlock , this , coefficientsParameter -> getBlockIndices ( ) , std :: placeholders :: _1 ) ; numberOfRows = coefficientsParameter -> getParameterSize ( ) ; break ; } default : break ; } } } return std :: make_pair ( partialFunction , numberOfRows ) ; }
Function to create a function returning a partial w.r.t.
Function to create a function returning a partial w . r . t .
// Declare return variables, default number of rows = 0 (i.e. no dependency) // Check properties of body exerting acceleration. // Check if partial is a rotational property of body exerting acceleration. // Check if required rotation matrix partial exists. // Get partial function. // Check if partial is a tidal property of body exerting acceleration. // Check input consistency // Get degree and order(s) of tidal variations // Check dependency on current partial object // If tidal dependency esists, set partial function // Check non-rotational parameters. // Cast parameter object to required type. // Cast parameter object to required type. // Return partial function and partial size.