Skip to content

Commit

Permalink
Merge pull request #1 from magnific0/rkf56
Browse files Browse the repository at this point in the history
Add test case from Fehlberg1968.
  • Loading branch information
Reneh107 committed Mar 22, 2016
2 parents 1c86d85 + bbca5e6 commit e6ebe68
Showing 1 changed file with 47 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@
#include <boost/test/unit_test.hpp>
#include <iostream>

#include <math.h>

#include "Tudat/Mathematics/NumericalIntegrators/rungeKuttaVariableStepSizeIntegrator.h"
#include "Tudat/Mathematics/NumericalIntegrators/rungeKuttaCoefficients.h"
#include "Tudat/Mathematics/NumericalIntegrators/UnitTests/numericalIntegratorTestFunctions.h"
Expand All @@ -86,8 +88,53 @@ namespace unit_tests

BOOST_AUTO_TEST_SUITE( test_runge_kutta_fehlberg_56_integrator )

Eigen::Vector2d FehlbergLogirithmicTestDifferentialEquation( double x, Eigen::Vector2d state){
Eigen::Vector2d stateDerivative;
stateDerivative( 0 ) = -2*x*state(0)*log(state(1));
stateDerivative( 1 ) = 2*x*state(1)*log(state(0));
return stateDerivative;
}

using numerical_integrator_test_functions::computeNonAutonomousModelStateDerivative;

//! Test Compare with Runge Kutta 78
BOOST_AUTO_TEST_CASE( test_RungeKuttaFehlberg56_Integrator_Fehlberg_Benchmark )
{
tudat::numerical_integrators::RungeKuttaCoefficients coeff56 =
tudat::numerical_integrators::RungeKuttaCoefficients::get(
tudat::numerical_integrators::RungeKuttaCoefficients::rungeKuttaFehlberg56) ;

// Integrator settings
double minimumStepSize = std::numeric_limits<double>::epsilon() ;
double maximumStepSize = std::numeric_limits<double>::infinity() ;
double initialStepSize = 1E-16;
double relativeTolerance = 1E-16;
double absoluteTolerance = 1E-16;

// Initial conditions
double initialTime = 0.0;
double finalTime = 5.0;
Eigen::Vector2d initialState(exp(1.0), 1.0);

// Setup integrator
tudat::numerical_integrators::RungeKuttaVariableStepSizeIntegratorXd integrator56(
coeff56, boost::bind(FehlbergLogirithmicTestDifferentialEquation,_1,_2),
initialTime , initialState, minimumStepSize,
maximumStepSize, relativeTolerance, absoluteTolerance );

double finalTimeSquared = finalTime * finalTime;

Eigen::Vector2d numSol = integrator56.integrateTo(finalTime, initialStepSize);
Eigen::Vector2d anaSol(exp(cos(finalTimeSquared)), exp(sin(finalTimeSquared)));

Eigen::Vector2d computedDifference = numSol - anaSol;
std::cout << computedDifference << std::endl;
// std::cout << solution56 << std::endl;
// BOOST_CHECK_SMALL( std::fabs(Difference(0)) , 1E-14 ) ;

}


//! Test Compare with Runge Kutta 78
BOOST_AUTO_TEST_CASE( test_RungeKuttaFehlberg56_Integrator_Compare78 )
{
Expand Down

0 comments on commit e6ebe68

Please sign in to comment.