Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F121994487
kite_model_test.cpp
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Tue, Jul 15, 05:59
Size
4 KB
Mime Type
text/x-c
Expires
Thu, Jul 17, 05:59 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
27422134
Attached To
R1517 test_package
kite_model_test.cpp
View Options
#define BOOST_TEST_MODULE kite_model_test
#include <boost/test/included/unit_test.hpp>
#include "integrator.h"
#include "kite.h"
using namespace casadi;
BOOST_AUTO_TEST_SUITE( kite_model_suite_test )
BOOST_AUTO_TEST_CASE( ode_solver_test )
{
std::string kite_config_file = "umx_radian.yaml";
KiteProperties kite_props = kite_utils::LoadProperties(kite_config_file);
AlgorithmProperties algo_props;
algo_props.Integrator = RK4;
/** SCALING */
//kite_props.Tether.length = kite_props.Tether.length / 3;
KiteDynamics kite(kite_props, algo_props);
Function ode = kite.getNumericDynamics();
/** compare three ode solvers */
Dict opts;
opts["tf"] = 1.0;
opts["poly_order"] = 10;
opts["tol"] = 1e-10;
opts["method"] = IntType::RK4;
ODESolver rk4_solver(ode, opts);
opts["method"] = IntType::CVODES;
ODESolver cvodes_solver(ode, opts);
opts["method"] = IntType::CHEBYCHEV;
ODESolver chebychev_solver(ode, opts);
//kite_props.Tether.length = kite_props.Tether.length / 3;
//std::cout << "New tether length : " << kite_props.Tether.length << "\n";
KiteDynamics kite2(kite_props, algo_props);
Function ode2 = kite.getNumericDynamics();
double tf = 1.0;
casadi::DMDict props;
props["scale"] = 1;
props["P"] = casadi::DM::diag(casadi::DM({0.1, 1/3.0, 1/3.0, 1/2.0, 1/5.0, 1/2.0, 1/3.0, 1/3.0, 1/3.0, 1.0, 1.0, 1.0, 1.0}));
props["R"] = casadi::DM::diag(casadi::DM({1/0.15, 1/0.2618, 1/0.2618}));
PSODESolver<9,1,13,3>ps_solver(ode2, tf, props);
/** solve a problem */
DM rk4_sol, cheb_sol, cv_sol, ps_sol;
//DM init_state = DM::vertcat({0.318732, 0.182552, 0.254833, 1.85435, -0.142882, -0.168359,
// -0.229383, -0.0500282, -0.746832, 0.189409, -0.836349, -0.48178, 0.180367});
//DM control = DM::vertcat({0.3, kmath::deg2rad(5), -kmath::deg2rad(2)});
DM init_state = DM::vertcat({6.9339, -0.6144, 1.6105, -0.0007, -1.2395, -1.9020,
-1.2460, 2.5256, -0.2083, -0.8945, -0.3079, -0.2095, -0.2471});
DM control = DM::vertcat({0.15, 0.139623, -0.072583});
std::chrono::time_point<std::chrono::system_clock> start = kite_utils::get_time();
rk4_sol = rk4_solver.solve(init_state, control, tf);
std::chrono::time_point<std::chrono::system_clock> rk4_stop = kite_utils::get_time();
cv_sol = cvodes_solver.solve(init_state, control, tf);
std::chrono::time_point<std::chrono::system_clock> cv_stop = kite_utils::get_time();
cheb_sol = chebychev_solver.solve(init_state, control, tf);
std::chrono::time_point<std::chrono::system_clock> cheb_stop = kite_utils::get_time();
ps_sol = ps_solver.solve(init_state, control);
std::chrono::time_point<std::chrono::system_clock> ps_stop = kite_utils::get_time();
auto rk4_duration = std::chrono::duration_cast<std::chrono::microseconds>(rk4_stop - start);
auto cv_duration = std::chrono::duration_cast<std::chrono::microseconds>(cv_stop - rk4_stop);
auto cheb_duration = std::chrono::duration_cast<std::chrono::microseconds>(cheb_stop - cv_stop);
auto ps_duration = std::chrono::duration_cast<std::chrono::microseconds>(ps_stop - cheb_stop);
std::cout << "RK4 solve time: " << std::setprecision(6)
<< static_cast<double>(rk4_duration.count()) * 1e-6 << " [seconds]" << "\n";
std::cout << "CVODES solve time: " << std::setprecision(6)
<< static_cast<double>(cv_duration.count()) * 1e-6 << " [seconds]" << "\n";
std::cout << "CHEB solve time: " << std::setprecision(6)
<< static_cast<double>(cheb_duration.count()) * 1e-6 << " [seconds]" << "\n";
std::cout << "PS solve time: " << std::setprecision(6)
<< static_cast<double>(ps_duration.count()) * 1e-6 << " [seconds]" << "\n";
std::cout << "RK4: " << rk4_sol << "\n";
std::cout << "CVODES: " << cv_sol << "\n";
std::cout << "CHEB: " << cheb_sol << "\n";
std::cout << "PS:" << ps_sol << "\n";
BOOST_CHECK(true);
}
BOOST_AUTO_TEST_SUITE_END()
Event Timeline
Log In to Comment