Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FAQ page + example application update (source) #407

Merged
merged 4 commits into from
Sep 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions FAQ/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
.. _faqIndex:

FAQ
===============

This page will give some answers to frequently asked questions about Tudat. If your question is not anwsered on this page, please open an issue on the Tudat github `page <https://github.com/Tudat/tudat/issues/new>`_.

- *Q: I would like to use Tudat, where should I start?*
A: the :ref:`gettingStarted` page contains a detailed explanation for new users of how to start using Tudat.

- *Q: I have problems with the installation of the Tudat bundle, how can I solve these problems?*
A: the :ref:`troubleshootingInstallation` page contains several solutions to common errors that can occur during installation. If this does not help, a list of issues raised by users can be found `here <https://github.com/Tudat/tudat/issues>`_. If this still does not contain a solution, a new issue can be made on `github <https://github.com/Tudat/tudat/issues/new>`_ so that the developers can help you.

- *Q: I would like to use Tudat, but I don't know how to code in C++. Can I still use it?*
A: To use Tudat, a little knowledge of C++ is necessary. You can learn :literal:`C++` from scratch using `this <http://www.cplusplus.com/doc/tutorial/>`_ page. If you have already used Matlab before, `this <http://runge.math.smu.edu/Courses/Math6370_Spring13/Lec2.pdf>`_ page lists the differences between the two languages. The same page exists for Python users, and can be found `here <https://pdfs.semanticscholar.org/9ad1/030685050e949d1a3d6d92bababcbe075e07.pdf>`_.

- *Q: I am on Windows and I would like to use the command line for git, how can I do this?*
A: A command line tool was developed for Tudat, you can find it in your tudat bundle under external/tools/tudat_shell. Within this tool you can use all the git commands.

- *Q: Some of the unit test on Windows fail due to high RAM usage, how can I solve this?*
A: Turn the COMPILE_HIGH_ACCURACY_ESTIMATION_TESTS off in the Projects tab.

- *Q: I want to add some features to Tudat, can I do this, and if yes, how?*
A: You can always add features to Tudat. If you think that it can also be used by others, you can make a pull request to the tudat repository. The :ref:`devGuideIndex` page contains guides on how to develop extra features for Tudat.

- *Q: How can I find the definition of a specific class/function/variable in Tudat?*
A: In Qt, you can right click on what you would like to inspect and select the "Follow Symbol Under Cursor" option.

- *Q: How can I find the usages of a specific class/function/variable in the whole Tudat bundle?*
A: In Qt, you can right click on what you would like to find the usages of and select the "Find Usages" option.

- *Q: How can I run CMake again from Qt?*
A: In the Project Tree tab in Qt (on the left side of your screen) you can right-click on the top-level TudatBundle icon and select the "Run CMake" option. The output will be shown in the General Messages tab.

- *Q: When running a Tudat propagation application, my application stops running but I don't know why. How can I find out?*
A: The dynamics Simulator class has a function: :literal:`getPropagationTerminationReason`, which allows you to retrieve a pointer to the :literal:`PropagationTerminationDetails`. This object has a function called :literal:`getPropagationTerminationReason`, which returns the reason for termination of the propagation.

- *Q: I have my own custom aerodynamic coefficient file/function that does not work with any of the given options in Tudat, how can I implement this?*
A: Tudat has a :literal:`customAerodynamicCoefficientInterface` which can be used for this purpose (see the class definition for more information on how to use this). You do need to make a :literal:`boost::function` for your coefficients to be able to use it.

- *Q: When making a Pagmo problem with a propagation step in it, the optimization stops after a while due to high RAM usage, how can I fix this?*
A: Put some variables (especially the creation of the :literal:`bodyMap`) in the constructor of the problem. This will make sure that some vectors will not grow unnecesarily large after several generations.

- *Q: I get a CSpice error telling me it cannot load any more kernels when running a optimization application, how can I solve this?*
A: Make sure that you are not loading the Spice kernels in the fitness function, but either in the constructor or somewhere else that will not be called upon by each time the fitness function is called.

- *Q: How can I repress the output of the :literal:`dependentVariableSettings`?*
A: Set the second argument of the class to false/0.

- *Q: When making a Pagmo problem with a propagation step in it, the optimization stops after a while due to high RAM usage, how can I fix this?*
A: Put some variables (especially the creation of the :literal:`bodyMap`) in the constructor of the problem. This will make sure that some vectors will not grow unnecesarily large after several generations.




1 change: 1 addition & 0 deletions index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,6 @@ Tudat has also been used extensively in research projects, a few of them are lis
started/index
installation/index
tutorials/index
FAQ/index
developerGuide/index

5 changes: 1 addition & 4 deletions started/index.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
.. TUDAT_Documentation documentation master file, created by
sphinx-quickstart on Mon Jul 3 06:08:42 2017.
You can adapt this file completely to your liking, but it should at least
contain the root `toctree` directive.
.. _gettingStarted:

Getting Started
===============
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
114 changes: 70 additions & 44 deletions tutorials/applicationWalkthroughs/interplanetaryTrajectory.rst
Original file line number Diff line number Diff line change
Expand Up @@ -161,51 +161,77 @@ The calculation of the final values of the trajectory is done in the same manner

Application Output
~~~~~~~~~~~~~~~~~~

The output of this application should look as follows:
All the output of the trajectory is handled as follows:

.. code-block:: cpp

Starting C:\tudatBundle.git\tudatExampleApplications\satellitePropagatorExamples\bin\applications\application_InterplanetaryTrajectoryDesign.exe...

Cassini Mission:

Total Delta V needed: 5635.96

Time of Earth departure: -6.82397e+007. Delta V needed at Earth: 2754.84

Time of Venus visit: -5.45624e+007. Delta V needed at Venus: 881.223

Time of second Venus visit: -1.57355e+007. Delta V needed at Venus: 1513.75

Time of Earth visit: -1.10052e+007. Delta V needed at Earth: 2.43109

Time of Jupiter visit: 7.74997e+007. Delta V needed at Jupiter: 10.4798

Time of Saturn capture: 4.70819e+008. Delta V needed at Saturn: 473.235

Messenger Mission:

Total Delta V: 8646.21

Time of Earth departure: 1.0123e+008. Delta V needed at Earth: 1408.99

Time of 1st DSM: 1.09338e+008. Delta V needed for 1st DSM: 911.2

Time of second Earth visit: 1.3579e+008. Delta V needed at Earth: 0

Time of 2nd DSM: 1.37277e+008. Delta V needed for 2nd DSM: 1.37516

Time of Venus visit: 1.51201e+008. Delta V needed at Venus: 0

Time of 3d DSM: 1.72658e+008. Delta V needed for 3d DSM: 266.056

Time of second Venus visit: 1.77054e+008. Delta V needed at Venus: 0

Time of 4th DSM: 1.82001e+008. Delta V needed for 4th DSM: 1425.24

Time of Mercury capture: 1.92651e+008. Delta V needed at Mercury: 4633.35

C:/tudatBundle.git/tudatExampleApplications/satellitePropagatorExamples/bin/applications/application_InterplanetaryTrajectoryDesign.exe exited with code 0

// Define vectors to calculate intermediate points
std::vector < Eigen::Vector3d > interPositionVectorMessenger;
std::vector < double > interTimeVectorMessenger;

// Calculate intermediate points and write to file
std::string outputFileTraj = tudat_applications::getOutputPath( )+"messengerTrajectory.dat";
Messenger.intermediatePoints( 1000.0 , interPositionVectorMessenger, interTimeVectorMessenger );
writeTrajectoryToFile( interPositionVectorMessenger, interTimeVectorMessenger, outputFileTraj );

// Define vectors to calculate intermediate points
std::vector < Eigen::Vector3d > manPositionVectorMessenger;
std::vector < double > manTimeVectorMessenger;
std::vector < double > manDeltaVVectorMessenger;

// Calculate maneuvers and write to file
std::string outputFileMan = tudat_applications::getOutputPath( )+"messengerManeuvers.dat";
Messenger.maneuvers( manPositionVectorMessenger, manTimeVectorMessenger, manDeltaVVectorMessenger );
writeTrajectoryToFile( manPositionVectorMessenger, manTimeVectorMessenger, outputFileMan );

// Calculate trajectories of the planets and output to file
std::vector < Eigen::Vector3d > positionVectorEarth;
std::vector < double > timeVectorEarth;
std::vector < Eigen::Vector3d > positionVectorVenus;
std::vector < double > timeVectorVenus;
std::vector < Eigen::Vector3d > positionVectorMercury;
std::vector < double > timeVectorMercury;

// Earth
returnSingleRevolutionPlanetTrajectory(
boost::make_shared< ephemerides::ApproximatePlanetPositions >(
ephemerides::ApproximatePlanetPositionsBase::BodiesWithEphemerisData::earthMoonBarycenter ),
sunGravitationalParameter,
1171.64503236,
1000.0,
positionVectorEarth,
timeVectorEarth);

// Venus
returnSingleRevolutionPlanetTrajectory(
boost::make_shared< ephemerides::ApproximatePlanetPositions >(
ephemerides::ApproximatePlanetPositionsBase::BodiesWithEphemerisData::venus ),
sunGravitationalParameter,
1171.64503236,
1000.0,
positionVectorVenus,
timeVectorVenus);

// Mercury
returnSingleRevolutionPlanetTrajectory(
boost::make_shared< ephemerides::ApproximatePlanetPositions >(
ephemerides::ApproximatePlanetPositionsBase::BodiesWithEphemerisData::mercury ),
sunGravitationalParameter,
1171.64503236,
1000.0,
positionVectorMercury,
timeVectorMercury);

std::string outputFilePlanetE = tudat_applications::getOutputPath( )+"earthTrajectory.dat";
writeTrajectoryToFile( positionVectorEarth, timeVectorEarth, outputFilePlanetE );

std::string outputFilePlanetV = tudat_applications::getOutputPath( )+"venusTrajectory.dat";
writeTrajectoryToFile( positionVectorVenus, timeVectorVenus, outputFilePlanetV );

std::string outputFilePlanetM = tudat_applications::getOutputPath( )+"mercuryTrajectory.dat";
writeTrajectoryToFile( positionVectorMercury, timeVectorMercury, outputFilePlanetM );

These lines of code use several functions that can produce output from the calculated trajectory. First, intermediate points are calculated along the trajectory using :literal:`intermediatePoints`. The produced position and time vector are then passed to :literal:`writeTrajectoryToFile` to produce a file that can be read by an external plotting program. The same is done afterwards, but instead of producing some intermediate positions, now only the manuevers are produced. These are then also written to a file. Finally, for every planet the trajectory is outputted to a file to be able to see where the trajectory encounters the planet. The final figure is shown below.

.. figure:: images/interpTrajFig.png

150 changes: 104 additions & 46 deletions tutorials/applicationWalkthroughs/mgaTrans.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ The gravity assist are done in the following order: Eart, Venus, Earth, Earth, J
std::vector< std::vector< double > > bounds( 2, std::vector< double >( numberOfParameters, 0.0 ) );

// Define search bounds: first parameter is start date, following parameters are leg durations
bounds[ 0 ][ 0 ] = 2458849.5;
bounds[ 1 ][ 0 ] = 2458849.5 + 20 * 365;
bounds[ 0 ][ 0 ] = 7304.5; //MJD2000
bounds[ 1 ][ 0 ] = 7304.5 + 10 * 365; //MJD2000
bounds[ 0 ][ 1 ] = 200;
bounds[ 1 ][ 1 ] = 500;
bounds[ 0 ][ 2 ] = 50;
Expand Down Expand Up @@ -55,67 +55,125 @@ This vector, plus the bounds, can then be passed to the UDP, as is done in the f

where :literal:`MultipleGravityAssist( bounds, flybySequence, true )` is the UDP. The true statement enables the UDP to also use the trip time as an objective for the optimalization.

This UDP contains an empty constructor, and a constructor that initializes the bounds, and the problem:
This UDP contains an empty constructor, and a constructor that initializes the problem. The first part of the constructor initializes the leg types of the trajectory:

.. code-block:: cpp

MultipleGravityAssist::MultipleGravityAssist( std::vector< std::vector< double > > &bounds,
std::vector< int > flybySequence,
const bool useTripTime ) :
problemBounds_( bounds ), useTripTime_( useTripTime ) {
// Specify required parameters
// Specify the number of legs and type of legs.
numberOfLegs_ = flybySequence.size( );
legTypeVector_.resize( numberOfLegs_ );
legTypeVector_[ 0 ] = mga_Departure;
legTypeVector_[ numberOfLegs_ - 1 ] = capture;

for(int i = 1; i < numberOfLegs_ - 1; i++){
legTypeVector_[ i ] = mga_Swingby;
}

mgaObject_.type = total_DV_orbit_insertion;
mgaObject_.sequence = flybySequence;
mgaObject_.rev_flag.resize( flybySequence.size( ) );

for( unsigned int i = 0; i < flybySequence.size( ); i++ )
{
mgaObject_.rev_flag[ i ] = 0;
}
The trajectory starts with a departure from Earth, and ends with a capture at Jupiter. All the legs between the departure and capture are swing-by legs. This application will not go into detail on the trajectory design setup, if this is not understood the reader is referred to the :ref:`interplanetaryTrajectoryDesign` application walkthrough.

mgaObject_.Isp = 300.0;
mgaObject_.mass = 8000.0;
mgaObject_.DVlaunch = 0.0;
After the trajectory is setup, the parameters for the selected order of planets is intialized using a large switch statement:

mgaObject_.rp = 76.0E3;
mgaObject_.e = 0.9;
}
.. code-block:: cpp


// Create the ephemeris, gravitational parameter, and minimum pericentre vector.
ephemerisVector_.resize( numberOfLegs_ );
gravitationalParameterVector_.resize( numberOfLegs_ );
minimumPericenterRadii_.resize( numberOfLegs_ );
for(int i = 0; i < numberOfLegs_; i++)
{
switch(flybySequence[ i ])
{
case( 1 ):
ephemerisVector_[ i ] = boost::make_shared< ephemerides::ApproximatePlanetPositions >
( ephemerides::ApproximatePlanetPositionsBase::BodiesWithEphemerisData::mercury );
gravitationalParameterVector_[ i ] = 2.2032E13;
minimumPericenterRadii_[ i ] = 2639.7E3;
break;
case( 2 ):
ephemerisVector_[ i ] = boost::make_shared< ephemerides::ApproximatePlanetPositions >
( ephemerides::ApproximatePlanetPositionsBase::BodiesWithEphemerisData::venus );
gravitationalParameterVector_[ i ] = 3.24859E14;
minimumPericenterRadii_[ i ] = 6251.8E3;
break;
...
...
...
case( 8 ):
ephemerisVector_[ i ] = boost::make_shared< ephemerides::ApproximatePlanetPositions >
( ephemerides::ApproximatePlanetPositionsBase::BodiesWithEphemerisData::neptune );
gravitationalParameterVector_[ i ] = 6.836529E15;
minimumPericenterRadii_[ i ] = 25000.0E3;
break;
case( 9 ):
ephemerisVector_[ i ] = boost::make_shared< ephemerides::ApproximatePlanetPositions >
( ephemerides::ApproximatePlanetPositionsBase::BodiesWithEphemerisData::pluto );
gravitationalParameterVector_[ i ] = 8.71E11;
minimumPericenterRadii_[ i ] = 1395.0E3;
break;
default:
std::cerr<<"Planet in flyby sequence is not defined.";
}
}

Where :literal:`mgaObject` is an object of type :literal:`mgaproblem`, which is defined in the AstroToolbox folder.
// Create departure and capture variables.
semiMajorAxes_.resize( 2 );
eccentricities_.resize( 2 );
semiMajorAxes_ << std::numeric_limits< double >::infinity( ), 1.0895e8 / 0.02;
eccentricities_ << 0., 0.98;

Now, the fitness function needs to be set up:

.. code-block:: cpp

//! Get bounds
std::pair<std::vector<double>, std::vector<double> > MultipleGravityAssist::get_bounds() const {
//! Implementation of the fitness function (return delta-v)
std::vector<double> MultipleGravityAssist::fitness( const std::vector<double> &xv ) const
{
// Sun gravitational parameter
const double sunGravitationalParameter = 1.32712428e20;

return { problemBounds_[0], problemBounds_[1] };
}
// Create variable vector.
Eigen::VectorXd variableVector ( numberOfLegs_ + 1 );

double TOF = 0;
for(int i = 0; i < numberOfLegs_ ; i++){
variableVector[ i ] = xv[ i ];
if( i > 0 ){
TOF += xv[i];
}
}
variableVector[ numberOfLegs_ ] = 1;//dummy
variableVector *= physical_constants::JULIAN_DAY;

// Create the trajectory problem.
Trajectory mgaTraj( numberOfLegs_, legTypeVector_, ephemerisVector_,
gravitationalParameterVector_, variableVector, sunGravitationalParameter,
minimumPericenterRadii_, semiMajorAxes_, eccentricities_ );

// Start the deltaV vector.
double resultingDeltaV;
mgaTraj.calculateTrajectory( resultingDeltaV );

if (std::isnan(resultingDeltaV))
{
resultingDeltaV = 1.0E10;
}

if ( useTripTime_ ){
return { resultingDeltaV, TOF };
}
else {
return { resultingDeltaV };
}

}

//! Implementation of the fitness function (return delta-v)
std::vector<double> MultipleGravityAssist::fitness( const std::vector<double> &xv ) const{

std::vector<double> rp;
std::vector<double> DV;
double obj_funct;
int result = MGA( xv, mgaObject_, rp, DV, obj_funct );
if( !useTripTime_ )
{
return { obj_funct };
}
else
{
double tof = 0.0;
for( unsigned int i = 1; i < problemBounds_.at( 0 ).size( ); i++ )
{
tof += xv[ i ];
}
return { obj_funct, tof };

}
}

The code above implements the two necessary methods: :literal:`get_bounds()` and :literal:`fitness( const std::vector<double> &xv )`. The :literal:`get_bounds()` function is implemented in the same way as previous examples. The :literal:`fitness( const std::vector<double> &xv )` method is relatively simple, however it uses an external function called :literal:`MGA`, which calculates the delta-v for the proposed gravity assist trajectory.
The :literal:`fitness( const std::vector<double> &xv )` method is made in a similar way as the previous examples. The decision variables are the departure time and the time-of-flight, thus they need to be entered into the trajectory design code to be able to calculate the delta V. A check is also made, that if the final Delta V was not able to be calculated, it will give a large penalty.

Selecting the Algorithm
~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down
Loading