8 #include <gtest/gtest.h> 11 using std::shared_ptr;
16 std::random_device rd;
17 std::mt19937 eng(rd());
18 std::uniform_real_distribution<> distr(min, max);
24 TEST(SystemDiscretizerTest, IntegratorComparison)
31 for (
size_t i = 1;
i < nTests; ++
i)
37 while (w_n * w_n - zeta * zeta <= 0)
46 oscillator1->checkParameters();
47 oscillator2->checkParameters();
50 std::shared_ptr<ConstantController<state_dim, control_dim>> constantController(
52 oscillator1->setController(constantController);
56 double startTime = 0.0;
70 integratedStateEuler << 1.0, 0.0;
71 integratedStateRK4 << 1.0, 0.0;
72 propagatedStateEuler << 1.0, 0.0;
73 propagatedStateRK4 << 1.0, 0.0;
75 for (
size_t j = 0; j < nStages; j++)
81 constantController->setControl(ctrl);
82 integratorEuler.
integrate_n_steps(integratedStateEuler, startTime, K_sim, dt / (
double)K_sim);
83 integratorRK4.
integrate_n_steps(integratedStateRK4, startTime, K_sim, dt / (
double)K_sim);
90 ASSERT_LT((propagatedStateEuler - integratedStateEuler).array().abs().maxCoeff(), 1e-12);
91 ASSERT_LT((propagatedStateRK4 - integratedStateRK4).array().abs().maxCoeff(), 1e-12);
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
Definition: Integrator.h:32
A constant controller.
Definition: ConstantController.h:20
virtual void propagateControlledDynamics(const StateVector< STATE_DIM, SCALAR > &state, const time_t n, const ControlVector< CONTROL_DIM, SCALAR > &control, StateVector< STATE_DIM, SCALAR > &stateNext) override
propagate discrete-time dynamics by performing a numerical forward integration of the continuous-time...
Definition: SystemDiscretizer-impl.h:121
Discretize a general, continuous-time non-linear dynamic system using forward integration.
Definition: SystemDiscretizer.h:44
tpl::SecondOrderSystem< double > SecondOrderSystem
harmonic oscillator (double)
Definition: SecondOrderSystem.h:220
double uniformRandomNumber(double min, double max)
Definition: SystemDiscretizerTest.h:14
const size_t state_dim
Definition: SymplecticIntegrationTest.cpp:14
Definition: StateVector.h:12
Standard Integrator.
Definition: Integrator.h:62
Definition: Integrator.h:33
const size_t control_dim
Definition: SymplecticIntegrationTest.cpp:17
TEST(SystemDiscretizerTest, IntegratorComparison)
Definition: SystemDiscretizerTest.h:24