Skip to content

Commit

Permalink
Some more fixes to Windows and macOS build issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
Sean Cowan committed Nov 8, 2024
1 parent 2f5c249 commit 34f5412
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 42 deletions.
15 changes: 4 additions & 11 deletions benchmark/leg_sims_flanagan_benchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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();
Expand Down
30 changes: 6 additions & 24 deletions benchmark/leg_sims_flanagan_hf_benchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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
Expand All @@ -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<std::array<double, 3>, 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<std::array<double, 3>, 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);
Expand All @@ -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();
Expand Down
6 changes: 3 additions & 3 deletions src/leg/sims_flanagan_hf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<double, 3> 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);
}
Expand Down
4 changes: 2 additions & 2 deletions test/leg_sims_flanagan_hf_helpers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<double> &throttles, double cut) : m_cut(cut), m_throttles(throttles)
sf_hf_test_object(std::vector<double> &throttles, double cut) : m_throttles(throttles), m_cut(cut)
{
for (double m_throttle : m_throttles) {
m_thrusts.push_back(m_throttle * m_max_thrust);
Expand Down Expand Up @@ -169,9 +169,9 @@ struct sf_hf_test_object {
std::array<double, 7> m_fwd_final_state{};
std::array<double, 7> m_bck_final_state{};
std::array<double, 7> m_mc_manual{};
std::vector<double> m_thrusts;
std::array<std::array<double, 3>, 2> m_rvs{{{1, 0.1, -0.1}, {0.2, 1, -0.2}}};
double m_ms = 1;
std::vector<double> m_thrusts;
std::vector<double> m_throttles = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
std::array<std::array<double, 3>, 2> m_rvf{{{1.2, -0.1, 0.1}, {-0.2, 1.023, -0.44}}};
double m_mf = m_ms * 13 / 15;
Expand Down
4 changes: 2 additions & 2 deletions test/leg_sims_flanagan_hf_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 34f5412

Please sign in to comment.