8 #include <gtest/gtest.h> 9 #include "../system/TestNonlinearSystem.h" 13 using std::shared_ptr;
18 std::random_device rd;
19 std::mt19937 eng(rd());
20 std::uniform_real_distribution<> distr(min, max);
26 TEST(IntegrationTest, derivativeTest)
34 for (
size_t i = 0;
i < nTests; ++
i)
36 shared_ptr<SecondOrderSystem> oscillator;
41 while (w_n * w_n - zeta * zeta <= 0)
47 oscillator->checkParameters();
58 stateEulerCT << 1.0, 0.0;
60 stateEulerOdeInt << 1.0, 0.0;
62 stateRK4CT << 1.0, 0.0;
64 stateRK4OdeInt << 1.0, 0.0;
67 double startTime = 0.0;
68 size_t numSteps = 100000;
72 integratorEulerOdeint.
integrate_n_steps(stateEulerOdeInt, startTime, numSteps, dt);
75 std::cout <<
"ODEINT Euler took: " << t.
getElapsedTime() <<
" s for integration" << std::endl;
81 std::cout <<
"CT Euler took: " << t.
getElapsedTime() <<
" s for integration" << std::endl;
87 std::cout <<
"ODEINT RK4 took: " << t.
getElapsedTime() <<
" s for integration" << std::endl;
93 std::cout <<
"CT RK4 took: " << t.
getElapsedTime() <<
" s for integration" << std::endl;
95 ASSERT_LT((stateRK4CT - stateRK4OdeInt).array().abs().maxCoeff(), 1e-12);
96 ASSERT_LT((stateEulerCT - stateEulerOdeInt).array().abs().maxCoeff(), 1e-12);
A timer ("stop watch") to record elapsed time based on the system clock.
Definition: Timer.h:19
void integrate_n_steps(StateVector< STATE_DIM, SCALAR > &state, const SCALAR &startTime, size_t numSteps, SCALAR dt, StateVectorArray< STATE_DIM, SCALAR > &stateTrajectory, tpl::TimeArray< SCALAR > &timeTrajectory)
Equidistant integration based on number of time steps and step length.
Definition: Integrator-impl.h:50
SCALAR getElapsedTime() const
Get the elapsed time between calls to start() and stop()
Definition: Timer.h:40
Definition: Integrator.h:32
double uniformRandomNumber(double min, double max)
Definition: IntegratorComparison.h:16
void stop()
Trigger stop.
Definition: Timer.h:34
clear all close all load ct GNMSLog0 mat reformat t
void start()
Trigger start.
Definition: Timer.h:29
tpl::SecondOrderSystem< double > SecondOrderSystem
harmonic oscillator (double)
Definition: SecondOrderSystem.h:220
const size_t state_dim
Definition: SymplecticIntegrationTest.cpp:14
static const size_t STATE_DIM
Definition: TestNonlinearSystem.h:21
Definition: StateVector.h:12
Standard Integrator.
Definition: Integrator.h:62
Definition: Integrator.h:33
Definition: Integrator.h:39
TEST(IntegrationTest, derivativeTest)
Definition: IntegratorComparison.h:26
Definition: Integrator.h:40
void reset()
Resets the clock.
Definition: Timer.h:49