Skip to content

Commit

Permalink
Merge pull request Tudat#52 from tudat-team/feature/new_dependent_var…
Browse files Browse the repository at this point in the history
…iables

Feature/new dependent variables
  • Loading branch information
DominicDirkx authored Jan 24, 2022
2 parents f31e986 + 8bba66f commit a201064
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 18 deletions.
25 changes: 25 additions & 0 deletions include/tudat/simulation/propagation_setup/propagationOutput.h
Original file line number Diff line number Diff line change
Expand Up @@ -1148,6 +1148,31 @@ std::pair< std::function< Eigen::VectorXd( ) >, int > getVectorDependentVariable
break;
}
#endif
case custom_dependent_variable:
{
std::shared_ptr< CustomDependentVariableSaveSettings > customVariableSettings =
std::dynamic_pointer_cast< CustomDependentVariableSaveSettings >( dependentVariableSettings );

if( customVariableSettings == nullptr )
{
std::string errorMessage= "Error, inconsistent inout when creating dependent variable function of type custom_dependent_variable";
throw std::runtime_error( errorMessage );
}
else
{
variableFunction = [=]( )
{
Eigen::VectorXd customVariables = customVariableSettings->customDependentVariableFunction_( );
if( customVariables.rows( ) != customVariableSettings->dependentVariableSize_ )
{
throw std::runtime_error( "Error when retrieving custom dependent variable, actual size is different from pre-defined size" );
}
return customVariables;
};
parameterSize = customVariableSettings->dependentVariableSize_;
}
break;
}
default:
std::string errorMessage =
"Error, did not recognize vector dependent variable type when making variable function: " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -489,30 +489,24 @@ class AccelerationPartialWrtStateSaveSettings: public SingleDependentVariableSav

};

class CustomDependentVariableSaveSettings: public SingleDependentVariableSaveSettings
{
public:

//class CustomDependentVariableSaveSettings: public SingleDependentVariableSaveSettings
//{
//public:

// CustomDependentVariableSaveSettings(
// const std::string& bodyWithProperty,
// const std::function< Eigen::VectorXd( const double ) > customDependentVariableFunction,
// const int dependentVariableSize ):
// SingleDependentVariableSaveSettings(
// custom_dependent_variable, bodyUndergoingAcceleration, bodyExertingAcceleration ),
// accelerationModelType_( accelerationModelType ), derivativeWrtBody_( derivativeWrtBody ),
// thirdBody_( thirdBody ){ }
CustomDependentVariableSaveSettings(
const std::function< Eigen::VectorXd( ) > customDependentVariableFunction,
const int dependentVariableSize ):
SingleDependentVariableSaveSettings(
custom_dependent_variable, "", "" ),
customDependentVariableFunction_( customDependentVariableFunction ), dependentVariableSize_( dependentVariableSize ){ }

// // Type of acceleration that is to be saved.
// basic_astrodynamics::AvailableAcceleration accelerationModelType_;
const std::function< Eigen::VectorXd( ) > customDependentVariableFunction_;

// // String denoting w.r.t. which body the derivative needs to be taken.
// std::string derivativeWrtBody_;
const int dependentVariableSize_;

// // String denoting the third body w.r.t. which the partial needs to be taken (in case of third body acceleration).
// std::string thirdBody_;
};

//};



Expand Down Expand Up @@ -1099,6 +1093,15 @@ inline std::shared_ptr< SingleDependentVariableSaveSettings > atmosphericTempera
local_temperature_dependent_variable, associatedBody, centralBody );
}

inline std::shared_ptr< SingleDependentVariableSaveSettings > customDependentVariable(
const std::function< Eigen::VectorXd( ) > customDependentVariableFunction,
const int dependentVariableSize )
{
return std::make_shared< CustomDependentVariableSaveSettings >(
customDependentVariableFunction, dependentVariableSize );
}





Expand Down
2 changes: 2 additions & 0 deletions src/simulation/propagation_setup/createEnvironmentUpdater.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -822,6 +822,8 @@ std::vector< std::string > > createEnvironmentUpdaterSettingsForDependentVariabl
case radiation_pressure_coefficient_dependent_variable:
variablesToUpdate[ radiation_pressure_interface_update ].push_back( dependentVariableSaveSettings->associatedBody_ );
break;
case custom_dependent_variable:
break;
default:
throw std::runtime_error( "Error when getting environment updates for dependent variables, parameter " +
std::to_string( dependentVariableSaveSettings->dependentVariableType_ ) + " not found." );
Expand Down
13 changes: 13 additions & 0 deletions src/simulation/propagation_setup/propagationOutput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,19 @@ int getDependentVariableSize(
case radiation_pressure_coefficient_dependent_variable:
variableSize = 1;
break;
case custom_dependent_variable:
if( std::dynamic_pointer_cast< CustomDependentVariableSaveSettings >(
dependentVariableSettings ) == nullptr )
{
std::string errorMessage = "Error, input for custom dependent variable parameter size ";
throw std::runtime_error( errorMessage );
}
else
{
variableSize = 3 * std::dynamic_pointer_cast< CustomDependentVariableSaveSettings >(
dependentVariableSettings )->dependentVariableSize_;
}
break;
default:
std::string errorMessage = "Error, did not recognize dependent variable size of type: " +
std::to_string( dependentVariableSettings->dependentVariableType_ );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,9 @@ std::string getDependentVariableName( const std::shared_ptr< SingleDependentVari
case radiation_pressure_coefficient_dependent_variable:
variableName = "Radiation pressure coefficient ";
break;
case custom_dependent_variable:
variableName = "Custom dependent variable ";
break;
default:
std::string errorMessage = "Error, dependent variable " +
std::to_string( propagationDependentVariables ) +
Expand Down
18 changes: 18 additions & 0 deletions tests/src/astro/propagators/unitTestDependentVariableOutput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,15 @@ BOOST_AUTO_TEST_CASE( testSphericalHarmonicDependentVariableOutput )
}
}

Eigen::VectorXd getCustomDependentVariable(
const SystemOfBodies& bodies )
{
Eigen::Vector6d sunState = bodies.at( "Sun" )->getState( );
Eigen::Vector6d moonState = bodies.at( "Moon" )->getState( );
return sunState.cwiseQuotient( moonState );

}

BOOST_AUTO_TEST_CASE( testDependentVariableEnvironmentUpdate )
{
std::string kernelsPath = paths::getSpiceKernelPath( );
Expand Down Expand Up @@ -716,6 +725,10 @@ BOOST_AUTO_TEST_CASE( testDependentVariableEnvironmentUpdate )
dependentVariables.push_back(
std::make_shared< BodyAerodynamicAngleVariableSaveSettings >(
"Moon", reference_frames::flight_path_angle, "Earth" ) );
dependentVariables.push_back(
std::make_shared< CustomDependentVariableSaveSettings >(
[=]( ){ return getCustomDependentVariable( bodies ); }, 6 ) );


std::shared_ptr< TranslationalStatePropagatorSettings< double > > propagatorSettings =
std::make_shared< TranslationalStatePropagatorSettings< double > >
Expand Down Expand Up @@ -780,6 +793,11 @@ BOOST_AUTO_TEST_CASE( testDependentVariableEnvironmentUpdate )
BOOST_CHECK_SMALL(
std::fabs( variableIterator->second( 6 ) - moonRelativeSphericalState(
orbital_element_conversions::flightPathIndex ) ), 1.0E-14 );

Eigen::Vector6d sunState = bodies.at( "Sun" )->getStateInBaseFrameFromEphemeris( variableIterator->first );
Eigen::Vector6d moonState = bodies.at( "Moon" )->getStateInBaseFrameFromEphemeris(variableIterator->first );
Eigen::Vector6d customDependentVariable = sunState.cwiseQuotient( moonState );
TUDAT_CHECK_MATRIX_CLOSE_FRACTION( customDependentVariable, ( variableIterator->second.segment( 7, 6 ) ), 1.0E-14 );
}
}

Expand Down

0 comments on commit a201064

Please sign in to comment.