diff --git a/benchmark/leg_sims_flanagan_benchmark.cpp b/benchmark/leg_sims_flanagan_benchmark.cpp index e9b1365..db32dd8 100644 --- a/benchmark/leg_sims_flanagan_benchmark.cpp +++ b/benchmark/leg_sims_flanagan_benchmark.cpp @@ -32,7 +32,7 @@ using std::chrono::high_resolution_clock; using std::chrono::microseconds; // NOLINTNEXTLINE(bugprone-easily-swappable-parameters) -void perform_convergence_benchmark(uint N, uint nseg) +void perform_convergence_benchmark(unsigned N, unsigned nseg) { // // Engines @@ -56,10 +56,9 @@ void perform_convergence_benchmark(uint N, uint nseg) // auto rvf = jupiter.eph(1000); int count_n = 0; int count_a = 0; - for (uint i(0); i < N; ++i) { + for (decltype(N) i = 0; i < N; ++i) { auto rvs = earth.eph(ts_random(rng_engine)); auto rvf = jupiter.eph(ts_random(rng_engine)); - // double tof_ic = kep3::pi / 2; double tof_ic = tof_random(rng_engine); double mu = 1; rvs[0][0] /= kep3::AU; @@ -100,7 +99,6 @@ void perform_convergence_benchmark(uint N, uint nseg) uda.set_ftol_abs(0); uda.set_maxeval(1000); pagmo::algorithm algo{uda}; - // algo.set_verbosity(5u); // We solve first a pop_a = algo.evolve(pop_a); @@ -123,7 +121,7 @@ void perform_convergence_benchmark(uint N, uint nseg) } // NOLINTNEXTLINE(bugprone-easily-swappable-parameters) -void perform_speed_benchmark(uint N, uint nseg, uint pop_size) +void perform_speed_benchmark(unsigned N, unsigned nseg, unsigned pop_size) { // // Engines @@ -143,14 +141,11 @@ void perform_speed_benchmark(uint N, uint nseg, uint pop_size) kep3::udpla::vsop2013 udpla_jupiter("jupiter", 1e-2); kep3::planet earth{udpla_earth}; kep3::planet jupiter{udpla_jupiter}; - // auto rvs = earth.eph(1000); - // auto rvf = jupiter.eph(1000); double count_n = 0; double count_a = 0; - for (uint i(0); i < N; ++i) { + for (decltype(N) i = 0; i < N; ++i) { auto rvs = earth.eph(ts_random(rng_engine)); auto rvf = jupiter.eph(ts_random(rng_engine)); - // double tof_ic = kep3::pi / 2; double tof_ic = tof_random(rng_engine); double mu = 1; rvs[0][0] /= kep3::AU; @@ -168,7 +163,6 @@ void perform_speed_benchmark(uint N, uint nseg, uint pop_size) = {{{lp.get_r1()[0], lp.get_r1()[1], lp.get_r1()[2]}, {lp.get_v1()[0][0] + dv_pert_random(rng_engine), lp.get_v1()[0][1] + dv_pert_random(rng_engine), lp.get_v1()[0][2] + dv_pert_random(rng_engine)}}}; - // double mass = 1; double mass = mass_random(rng_engine); double max_thrust = 1; double isp = 1; @@ -189,7 +183,6 @@ void perform_speed_benchmark(uint N, uint nseg, uint pop_size) uda.set_ftol_abs(0); uda.set_maxeval(1000); pagmo::algorithm algo{uda}; - // algo.set_verbosity(5u); // First we time the analytical gradients auto start = high_resolution_clock::now(); diff --git a/benchmark/leg_sims_flanagan_hf_benchmark.cpp b/benchmark/leg_sims_flanagan_hf_benchmark.cpp index 652a561..e075a07 100644 --- a/benchmark/leg_sims_flanagan_hf_benchmark.cpp +++ b/benchmark/leg_sims_flanagan_hf_benchmark.cpp @@ -33,7 +33,7 @@ using std::chrono::high_resolution_clock; using std::chrono::microseconds; // NOLINTNEXTLINE(bugprone-easily-swappable-parameters) -void perform_convergence_benchmark(uint N, uint nseg) +void perform_convergence_benchmark(unsigned N, unsigned nseg) { // // Engines @@ -53,16 +53,13 @@ void perform_convergence_benchmark(uint N, uint nseg) kep3::udpla::vsop2013 udpla_jupiter("jupiter", 1e-2); kep3::planet earth{udpla_earth}; kep3::planet jupiter{udpla_jupiter}; - // auto rvs = earth.eph(1000); - // auto rvf = jupiter.eph(1000); int count_n = 0; int count_a = 0; auto bench_udp_a = sf_hf_bench_udp(); auto bench_udp_n = sf_hf_bench_udp(); - for (uint i(0); i < N; ++i) { + for (decltype(N) i = 0; i < N; ++i) { auto rvs = earth.eph(ts_random(rng_engine)); auto rvf = jupiter.eph(ts_random(rng_engine)); - // double tof_ic = kep3::pi / 2; double tof_ic = tof_random(rng_engine); double mu = 1; rvs[0][0] /= kep3::AU; @@ -103,7 +100,6 @@ void perform_convergence_benchmark(uint N, uint nseg) uda.set_ftol_abs(0); uda.set_maxeval(1000); pagmo::algorithm algo{uda}; - // algo.set_verbosity(5u); // We solve first a pop_a = algo.evolve(pop_a); @@ -126,7 +122,7 @@ void perform_convergence_benchmark(uint N, uint nseg) } // NOLINTNEXTLINE(bugprone-easily-swappable-parameters) -void perform_speed_benchmark(uint N, uint nseg, uint pop_size) +void perform_speed_benchmark(unsigned N, unsigned nseg, unsigned pop_size) { // // Engines @@ -146,39 +142,26 @@ void perform_speed_benchmark(uint N, uint nseg, uint pop_size) kep3::udpla::vsop2013 udpla_jupiter("jupiter", 1e-2); kep3::planet earth{udpla_earth}; kep3::planet jupiter{udpla_jupiter}; - // auto rvs = earth.eph(1000); - // auto rvf = jupiter.eph(1000); double count_n = 0; double count_a = 0; auto bench_udp_a = sf_hf_bench_udp(); auto bench_udp_n = sf_hf_bench_udp(); - for (uint i(0); i < N; ++i) { + for (decltype(N) i = 0; i < N; ++i) { auto rvs = earth.eph(ts_random(rng_engine)); auto rvf = jupiter.eph(ts_random(rng_engine)); - // double tof_ic = kep3::pi / 2; - double tof_ic = tof_random(rng_engine); - double mu = 1; rvs[0][0] /= kep3::AU; rvs[0][1] /= kep3::AU; rvs[0][2] /= kep3::AU; rvf[0][0] /= kep3::AU; rvf[0][1] /= kep3::AU; rvf[0][2] /= kep3::AU; - const kep3::lambert_problem lp{rvs[0], rvf[0], tof_ic, mu}; // Create HF legs - std::array, 2> rvs_udp_ic = {{{lp.get_r0()[0], lp.get_r0()[1], lp.get_r0()[2]}, - {lp.get_v0()[0][0], lp.get_v0()[0][1], lp.get_v0()[0][2]}}}; - std::array, 2> rvf_udp_ic - = {{{lp.get_r1()[0], lp.get_r1()[1], lp.get_r1()[2]}, - {lp.get_v1()[0][0] + dv_pert_random(rng_engine), lp.get_v1()[0][1] + dv_pert_random(rng_engine), - lp.get_v1()[0][2] + dv_pert_random(rng_engine)}}}; - // double mass = 1; double mass = mass_random(rng_engine); double max_thrust = 1; double isp = 1; - bench_udp_a.set_leg(rvs_udp_ic, mass, rvf_udp_ic, max_thrust, isp, nseg, true); - bench_udp_n.set_leg(rvs_udp_ic, mass, rvf_udp_ic, max_thrust, isp, nseg, false); + bench_udp_a.set_leg(rvs, mass, rvf, max_thrust, isp, nseg, true); + bench_udp_n.set_leg(rvs, mass, rvf, max_thrust, isp, nseg, false); pagmo::problem prob_a{bench_udp_a}; pagmo::problem prob_n{bench_udp_n}; prob_a.set_c_tol(1e-8); @@ -194,7 +177,6 @@ void perform_speed_benchmark(uint N, uint nseg, uint pop_size) uda.set_ftol_abs(0); uda.set_maxeval(1000); pagmo::algorithm algo{uda}; - // algo.set_verbosity(5u); // First we time the analytical gradients auto start = high_resolution_clock::now(); diff --git a/src/leg/sims_flanagan_hf.cpp b/src/leg/sims_flanagan_hf.cpp index bc9a34d..ed49154 100644 --- a/src/leg/sims_flanagan_hf.cpp +++ b/src/leg/sims_flanagan_hf.cpp @@ -622,17 +622,17 @@ sims_flanagan_hf::compute_all_gradients() const if (m_nseg_fwd > 0) { x0_per_seg[0] = m_rvms; } - for (auto i = 1; i < m_nseg_fwd; ++i) { + for (decltype(m_nseg_fwd) i = 1; i < m_nseg_fwd; ++i) { x0_per_seg[i] = xf_per_seg[i - 1]; } if (m_nseg_bck > 0) { x0_per_seg[m_nseg - 1] = m_rvmf; } - for (auto i = 1; i < m_nseg_bck; ++i) { + for (decltype(m_nseg_bck) i = 1; i < m_nseg_bck; ++i) { x0_per_seg[(m_nseg - 1) - i] = xf_per_seg[(m_nseg - 1) - (i - 1)]; } - for (auto i = 0; i < dxdtof_per_seg.size(); ++i) { + for (decltype(dxdtof_per_seg.size()) i = 0; i < dxdtof_per_seg.size(); ++i) { std::array current_throttles = {m_throttles[i * 3], m_throttles[i * 3 + 1], m_throttles[i * 3 + 2]}; dxdtof_per_seg[i] = get_state_derivative(x0_per_seg[i], current_throttles); } diff --git a/test/leg_sims_flanagan_hf_helpers.hpp b/test/leg_sims_flanagan_hf_helpers.hpp index 7cbf749..376db15 100644 --- a/test/leg_sims_flanagan_hf_helpers.hpp +++ b/test/leg_sims_flanagan_hf_helpers.hpp @@ -58,7 +58,7 @@ struct sf_hf_test_object { explicit sf_hf_test_object(double cut) : m_cut(cut) {} - sf_hf_test_object(std::vector &throttles, double cut) : m_cut(cut), m_throttles(throttles) + sf_hf_test_object(std::vector &throttles, double cut) : m_throttles(throttles), m_cut(cut) { for (double m_throttle : m_throttles) { m_thrusts.push_back(m_throttle * m_max_thrust); @@ -169,9 +169,9 @@ struct sf_hf_test_object { std::array m_fwd_final_state{}; std::array m_bck_final_state{}; std::array m_mc_manual{}; - std::vector m_thrusts; std::array, 2> m_rvs{{{1, 0.1, -0.1}, {0.2, 1, -0.2}}}; double m_ms = 1; + std::vector m_thrusts; std::vector m_throttles = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; std::array, 2> m_rvf{{{1.2, -0.1, 0.1}, {-0.2, 1.023, -0.44}}}; double m_mf = m_ms * 13 / 15; diff --git a/test/leg_sims_flanagan_hf_test.cpp b/test/leg_sims_flanagan_hf_test.cpp index a3eca0a..5c06c9d 100644 --- a/test/leg_sims_flanagan_hf_test.cpp +++ b/test/leg_sims_flanagan_hf_test.cpp @@ -319,7 +319,7 @@ TEST_CASE("compute_state_history") // Get state history kep3::leg::sims_flanagan_hf sf{}; auto mc = sf.compute_mismatch_constraints(); - uint grid_points_per_segment = 4; + unsigned grid_points_per_segment = 4; auto state_history = sf.get_state_history(grid_points_per_segment); // Get fwd final state @@ -358,7 +358,7 @@ TEST_CASE("compute_state_history_2") // Get state history auto mc = sf.compute_mismatch_constraints(); - uint grid_points_per_segment = 4; + unsigned grid_points_per_segment = 4; auto state_history = sf.get_state_history(grid_points_per_segment); // Get fwd final state