# 3.5. Apollo Capsule Entry¶

The example described on this page is that of Apollo on a reentry trajectory towards the surface of Earth. To have a clearer overview of the application, you should check out the example at Un-guided Capsule Entry, which is identical to this one but without the use of JSON files. The code for this tutorial is located in your Tudat Bundle at:

tudatBundle/tudatExampleApplications/satellitePropagatorExamples/SatellitePropagatorExamples/apolloCapsuleEntryJSON.cpp


The Apollo capsule entry cannot be simulated using exclusively JSON input files and the json_interface application. Some of the Tudat features that this application uses cannot be provided using JSON files, and thus a custom JSON-based application, in which part of the settings are read from a JSON file and others specified manually using C++ code, has to be written.

The Tudat features that this application uses that are not supported by the JSON interface are:

This functionality has to be implemented in the C++ application. However, as for any JSON-based application, the first step is to generate the input file. This file is located in your Tudat Bundle at:

tudatBundle/tudatExampleApplications/satellitePropagatorExamples/SatellitePropagatorExamples/apolloCapsuleEntry.json


A few remarks about the contents of this file can be made:

• The key spice.preloadEphemeris has to be set to false because the key finalEpoch is not defined, so it is not possible to interpolate the ephemeris of celestial bodies.
• For the body Apollo, only the mass is specified; the aerodynamic settings (including coefficients and reference area) will be loaded manually in the C++ application.
• Since the key file of the export settings is mandatory, a placeholder empty string is provided for export[ 0 ].file and export[ 1 ].file, which will be then redefined in the C++ application.
• The variable representing Apollo’s altitude w.r.t. Earth is used twice: as termination condition and as dependent variable to be exported to an output file. Rather than repeating it twice, the key export[ 1 ].variables[ 1 ] has been set to reference the termination’s variable by using the special string "\${termination.variable}".

Then, in the C++ app, as explained in Writing Custom JSON-based Applications, a derived class of JsonSimulationManager has been created, providing custom implementations for the virtual methods resetBodies, resetExportSettings and resetPropagatorSettings:

class ApolloJsonSimulationManager : public tudat::json_interface::JsonSimulationManager< >
{
public:

// Inherit constructor.
using JsonSimulationManager< >::JsonSimulationManager;

protected:

virtual void resetBodies( )
{
...
}

virtual void resetExportSettings( )
{
...
}

virtual void resetPropagatorSettings( )
{
...
}

};


For the resetBodies method, we first call the default implementation of the base class, and then we create Apollo’s aerodynamic coefficients interface manually, using a function defined in tudat::unit_tests:

virtual void resetBodies( )
{
// First, call the original resetBodies, which uses the information in the JSON file
JsonSimulationManager::resetBodies( );

// Then, create vehicle's aerodynamic coefficients interface
getBody( "Apollo" )->setAerodynamicCoefficientInterface( tudat::unit_tests::getApolloCoefficientInterface( ) );
}


Note that we use the method getBody( const std::string& bodyName ) of JsonSimulationManager, which retrieves the body named bodyName from the body map. If we want to create a new body manually, we use the method addBody( const std::string& bodyName ) (note that, if the body already exists, it will be reset to a body created with the empty constructor).

For the resetExportSettings method, we first call the default implementation of the base class, and then modify the output files paths using the function tudat_applications::getOutputPath( ):

virtual void resetExportSettings( )
{
// First, call the original resetExportSettings, which uses the information in the JSON file
JsonSimulationManager::resetExportSettings( );

// Then, replace the output file paths (empty strings placeholders had been specified in the JSON file)
const std::string outputDirectory = tudat_applications::getOutputPath( ) + "ApolloCapsuleExampleJSON/";
getExportSettings( 0 )->setOutputFile( outputDirectory + "apolloPropagationHistory.dat" );
getExportSettings( 1 )->setOutputFile( outputDirectory + "apolloDependentVariableHistory.dat" );
}


In this case, we use the method getExportSettings( unsigned int index ), which returns the ExportSettings object created from the key export[ index ] in the JSON file.

Finally, we also override the method resetPropagatorSettings:

  1 2 3 4 5 6 7 8 9 10 virtual void resetPropagatorSettings( ) { // First, call the original resetPropagatorSettings, which uses the information in the JSON file JsonSimulationManager::resetPropagatorSettings( ); // Define constant 30 degree angle of attack double constantAngleOfAttack = 30.0 * tudat::mathematical_constants::PI / 180.0; getBody( "Apollo" )->getFlightConditions( )->getAerodynamicAngleCalculator( )-> setOrientationAngleFunctions( [ = ]( ){ return constantAngleOfAttack; } ); } 

After calling the original implementation in line 4, we define an angle of attack for Apollo. This is done by modifying Apollo’s flight conditions. This can only be done once the flight conditions have been created, i.e. after JsonSimulationManager::resetPropagatorSettings( ) has been called, since this method will create the acceleration aerodynamic models based on the body map created previously.

Now, we can write our main function, which uses the custom class ApolloJsonSimulationManager:

int main( )
{
const std::string cppFilePath( __FILE__ );
const std::string cppFolder = cppFilePath.substr( 0, cppFilePath.find_last_of("/\\") + 1 );

ApolloJsonSimulationManager jsonSimulationManager( cppFolder + "apolloCapsuleEntry.json" );

tudatBundle/tudatExampleApplications/satellitePropagatorExamples/SatellitePropagatorExamples/SimulationOutput/ApolloCapsuleExampleJSON