Skip to content

Commit

Permalink
Start enabling some compact mode testing.
Browse files Browse the repository at this point in the history
  • Loading branch information
bluescarni committed Jul 4, 2024
1 parent e25e2dd commit 741dbe2
Show file tree
Hide file tree
Showing 2 changed files with 157 additions and 145 deletions.
6 changes: 6 additions & 0 deletions src/model/sgp4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,12 @@ void sgp4_propagator<T>::operator()(out_3d out, in_2d<T> tms)
const typename cfunc<T>::in_2d init_span(m_impl->m_init_buffer.data(), n_init_rows,
boost::numeric_cast<std::size_t>(n_sats));

// NOTE: here we are unconditionally enabling parallel operations, even though in principle with very
// few satellites or n_evals we could have some unnecessary overhead. Coming up with a cost model for when
// to enable parallel operations is not easy, as I do not see a reliable way of estimating the propagation
// cost in the presence of derivatives. Probably it does not matter too much as a single sgp4 propagation
// without derivatives is most likely already in the ~1000 flops range.

// The functor to be run in the parallel loop below.
auto par_iter = [out, tms, init_span](cfunc<T> &cf, const auto &range) {
for (auto i = range.begin(); i != range.end(); ++i) {
Expand Down
296 changes: 151 additions & 145 deletions test/model_sgp4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

#include <heyoka/detail/debug.hpp>
#include <heyoka/expression.hpp>
#include <heyoka/kw.hpp>
#include <heyoka/model/sgp4.hpp>

#include "catch.hpp"
Expand Down Expand Up @@ -126,65 +127,68 @@ TEST_CASE("propagator")

using md_input_t = mdspan<const double, extents<std::size_t, 9, std::dynamic_extent>>;

std::vector<double> ins = {revday2radmin(13.75091047972192),
revday2radmin(15.50103472202482),
0.0024963,
0.0007417,
deg2rad(90.2039),
deg2rad(51.6439),
deg2rad(55.5633),
deg2rad(211.2001),
deg2rad(320.5956),
deg2rad(17.6667),
deg2rad(91.4738),
deg2rad(85.6398),
0.75863e-3,
.38792e-4,
2460486.5,
2458826.5,
0.6478633000000116,
0.6933954099999937};

prop_t prop{md_input_t{ins.data(), 9, 2}};

auto tm = std::array{1440., 0.};
prop_t::in_1d<double> tm_in{tm.data(), 2};

std::vector<double> outs(12u);
prop_t::out_2d out{outs.data(), 6, 2};

prop(out, tm_in);

REQUIRE(out(0, 0) == approximately(3134.2015620939, 10000.));
REQUIRE(out(1, 0) == approximately(4604.963663328277, 10000.));
REQUIRE(out(2, 0) == approximately(-4791.661126560278, 10000.));
REQUIRE(out(3, 0) == approximately(2.732034613044249, 10000.));
REQUIRE(out(4, 0) == approximately(3.952589777415254, 10000.));
REQUIRE(out(5, 0) == approximately(5.588906721377138, 10000.));
REQUIRE(out(0, 1) == approximately(3469.947984145807, 10000.));
REQUIRE(out(1, 1) == approximately(-2690.388430131083, 10000.));
REQUIRE(out(2, 1) == approximately(5175.831924199492, 10000.));
REQUIRE(out(3, 1) == approximately(5.810229142351453, 10000.));
REQUIRE(out(4, 1) == approximately(4.802261184784617, 10000.));
REQUIRE(out(5, 1) == approximately(-1.388280333072693, 10000.));

auto dates = std::array<prop_t::date, 2>{{{2460486.5 + 1, 0.6478633000000116}, {2458826.5, 0.6933954099999937}}};
prop_t::in_1d<prop_t::date> date_in{dates.data(), 2};

prop(out, date_in);

REQUIRE(out(0, 0) == approximately(3134.2015620939, 10000.));
REQUIRE(out(1, 0) == approximately(4604.963663328277, 10000.));
REQUIRE(out(2, 0) == approximately(-4791.661126560278, 10000.));
REQUIRE(out(3, 0) == approximately(2.732034613044249, 10000.));
REQUIRE(out(4, 0) == approximately(3.952589777415254, 10000.));
REQUIRE(out(5, 0) == approximately(5.588906721377138, 10000.));
REQUIRE(out(0, 1) == approximately(3469.947984145807, 10000.));
REQUIRE(out(1, 1) == approximately(-2690.388430131083, 10000.));
REQUIRE(out(2, 1) == approximately(5175.831924199492, 10000.));
REQUIRE(out(3, 1) == approximately(5.810229142351453, 10000.));
REQUIRE(out(4, 1) == approximately(4.802261184784617, 10000.));
REQUIRE(out(5, 1) == approximately(-1.388280333072693, 10000.));
const std::vector<double> ins = {revday2radmin(13.75091047972192),
revday2radmin(15.50103472202482),
0.0024963,
0.0007417,
deg2rad(90.2039),
deg2rad(51.6439),
deg2rad(55.5633),
deg2rad(211.2001),
deg2rad(320.5956),
deg2rad(17.6667),
deg2rad(91.4738),
deg2rad(85.6398),
0.75863e-3,
.38792e-4,
2460486.5,
2458826.5,
0.6478633000000116,
0.6933954099999937};

const auto tm = std::array{1440., 0.};
const prop_t::in_1d<double> tm_in{tm.data(), 2};

for (auto cm : {false, true}) {
prop_t prop{md_input_t{ins.data(), 9, 2}, kw::compact_mode = cm};

std::vector<double> outs(12u);
prop_t::out_2d out{outs.data(), 6, 2};

prop(out, tm_in);

REQUIRE(out(0, 0) == approximately(3134.2015620939, 10000.));
REQUIRE(out(1, 0) == approximately(4604.963663328277, 10000.));
REQUIRE(out(2, 0) == approximately(-4791.661126560278, 10000.));
REQUIRE(out(3, 0) == approximately(2.732034613044249, 10000.));
REQUIRE(out(4, 0) == approximately(3.952589777415254, 10000.));
REQUIRE(out(5, 0) == approximately(5.588906721377138, 10000.));
REQUIRE(out(0, 1) == approximately(3469.947984145807, 10000.));
REQUIRE(out(1, 1) == approximately(-2690.388430131083, 10000.));
REQUIRE(out(2, 1) == approximately(5175.831924199492, 10000.));
REQUIRE(out(3, 1) == approximately(5.810229142351453, 10000.));
REQUIRE(out(4, 1) == approximately(4.802261184784617, 10000.));
REQUIRE(out(5, 1) == approximately(-1.388280333072693, 10000.));

auto dates
= std::array<prop_t::date, 2>{{{2460486.5 + 1, 0.6478633000000116}, {2458826.5, 0.6933954099999937}}};
prop_t::in_1d<prop_t::date> date_in{dates.data(), 2};

prop(out, date_in);

REQUIRE(out(0, 0) == approximately(3134.2015620939, 10000.));
REQUIRE(out(1, 0) == approximately(4604.963663328277, 10000.));
REQUIRE(out(2, 0) == approximately(-4791.661126560278, 10000.));
REQUIRE(out(3, 0) == approximately(2.732034613044249, 10000.));
REQUIRE(out(4, 0) == approximately(3.952589777415254, 10000.));
REQUIRE(out(5, 0) == approximately(5.588906721377138, 10000.));
REQUIRE(out(0, 1) == approximately(3469.947984145807, 10000.));
REQUIRE(out(1, 1) == approximately(-2690.388430131083, 10000.));
REQUIRE(out(2, 1) == approximately(5175.831924199492, 10000.));
REQUIRE(out(3, 1) == approximately(5.810229142351453, 10000.));
REQUIRE(out(4, 1) == approximately(4.802261184784617, 10000.));
REQUIRE(out(5, 1) == approximately(-1.388280333072693, 10000.));
}
}

TEST_CASE("propagator batch")
Expand All @@ -195,90 +199,92 @@ TEST_CASE("propagator batch")

using md_input_t = mdspan<const double, extents<std::size_t, 9, std::dynamic_extent>>;

std::vector<double> ins = {revday2radmin(13.75091047972192),
revday2radmin(15.50103472202482),
0.0024963,
0.0007417,
deg2rad(90.2039),
deg2rad(51.6439),
deg2rad(55.5633),
deg2rad(211.2001),
deg2rad(320.5956),
deg2rad(17.6667),
deg2rad(91.4738),
deg2rad(85.6398),
0.75863e-3,
.38792e-4,
2460486.5,
2458826.5,
0.6478633000000116,
0.6933954099999937};

prop_t prop{md_input_t{ins.data(), 9, 2}};

auto tm = std::array{1440., 0., 0., 1440.};
prop_t::in_2d<double> tm_in{tm.data(), 2, 2};

std::vector<double> outs(24u);
prop_t::out_3d out{outs.data(), 2, 6, 2};

prop(out, tm_in);

REQUIRE(out(0, 0, 0) == approximately(3134.2015620939, 10000.));
REQUIRE(out(0, 1, 0) == approximately(4604.963663328277, 10000.));
REQUIRE(out(0, 2, 0) == approximately(-4791.661126560278, 10000.));
REQUIRE(out(0, 3, 0) == approximately(2.732034613044249, 10000.));
REQUIRE(out(0, 4, 0) == approximately(3.952589777415254, 10000.));
REQUIRE(out(0, 5, 0) == approximately(5.588906721377138, 10000.));
REQUIRE(out(0, 0, 1) == approximately(3469.947984145807, 10000.));
REQUIRE(out(0, 1, 1) == approximately(-2690.388430131083, 10000.));
REQUIRE(out(0, 2, 1) == approximately(5175.831924199492, 10000.));
REQUIRE(out(0, 3, 1) == approximately(5.810229142351453, 10000.));
REQUIRE(out(0, 4, 1) == approximately(4.802261184784617, 10000.));
REQUIRE(out(0, 5, 1) == approximately(-1.388280333072693, 10000.));
REQUIRE(out(1, 0, 0) == approximately(2561.223660636298, 10000.));
REQUIRE(out(1, 1, 0) == approximately(3698.797144057697, 10000.));
REQUIRE(out(1, 2, 0) == approximately(5818.772215708888, 10000.));
REQUIRE(out(1, 3, 0) == approximately(-3.276142513618007, 10000.));
REQUIRE(out(1, 4, 0) == approximately(-4.806489082829041, 10000.));
REQUIRE(out(1, 5, 0) == approximately(4.511134501638151, 10000.));
REQUIRE(out(1, 0, 1) == approximately(-3591.82683131782, 10000.));
REQUIRE(out(1, 1, 1) == approximately(2723.666407193435, 10000.));
REQUIRE(out(1, 2, 1) == approximately(-5090.448264983512, 10000.));
REQUIRE(out(1, 3, 1) == approximately(-5.927709516654264, 10000.));
REQUIRE(out(1, 4, 1) == approximately(-4.496384419253211, 10000.));
REQUIRE(out(1, 5, 1) == approximately(1.785277174529374, 10000.));

auto dates = std::array<prop_t::date, 4>{{{2460486.5 + 1, 0.6478633000000116},
{2458826.5, 0.6933954099999937},
{2460486.5, 0.6478633000000116},
{2458826.5 + 1, 0.6933954099999937}}};
prop_t::in_2d<prop_t::date> date_in{dates.data(), 2, 2};

prop(out, date_in);

REQUIRE(out(0, 0, 0) == approximately(3134.2015620939, 10000.));
REQUIRE(out(0, 1, 0) == approximately(4604.963663328277, 10000.));
REQUIRE(out(0, 2, 0) == approximately(-4791.661126560278, 10000.));
REQUIRE(out(0, 3, 0) == approximately(2.732034613044249, 10000.));
REQUIRE(out(0, 4, 0) == approximately(3.952589777415254, 10000.));
REQUIRE(out(0, 5, 0) == approximately(5.588906721377138, 10000.));
REQUIRE(out(0, 0, 1) == approximately(3469.947984145807, 10000.));
REQUIRE(out(0, 1, 1) == approximately(-2690.388430131083, 10000.));
REQUIRE(out(0, 2, 1) == approximately(5175.831924199492, 10000.));
REQUIRE(out(0, 3, 1) == approximately(5.810229142351453, 10000.));
REQUIRE(out(0, 4, 1) == approximately(4.802261184784617, 10000.));
REQUIRE(out(0, 5, 1) == approximately(-1.388280333072693, 10000.));
REQUIRE(out(1, 0, 0) == approximately(2561.223660636298, 10000.));
REQUIRE(out(1, 1, 0) == approximately(3698.797144057697, 10000.));
REQUIRE(out(1, 2, 0) == approximately(5818.772215708888, 10000.));
REQUIRE(out(1, 3, 0) == approximately(-3.276142513618007, 10000.));
REQUIRE(out(1, 4, 0) == approximately(-4.806489082829041, 10000.));
REQUIRE(out(1, 5, 0) == approximately(4.511134501638151, 10000.));
REQUIRE(out(1, 0, 1) == approximately(-3591.82683131782, 10000.));
REQUIRE(out(1, 1, 1) == approximately(2723.666407193435, 10000.));
REQUIRE(out(1, 2, 1) == approximately(-5090.448264983512, 10000.));
REQUIRE(out(1, 3, 1) == approximately(-5.927709516654264, 10000.));
REQUIRE(out(1, 4, 1) == approximately(-4.496384419253211, 10000.));
REQUIRE(out(1, 5, 1) == approximately(1.785277174529374, 10000.));
const std::vector<double> ins = {revday2radmin(13.75091047972192),
revday2radmin(15.50103472202482),
0.0024963,
0.0007417,
deg2rad(90.2039),
deg2rad(51.6439),
deg2rad(55.5633),
deg2rad(211.2001),
deg2rad(320.5956),
deg2rad(17.6667),
deg2rad(91.4738),
deg2rad(85.6398),
0.75863e-3,
.38792e-4,
2460486.5,
2458826.5,
0.6478633000000116,
0.6933954099999937};

const auto tm = std::array{1440., 0., 0., 1440.};
const prop_t::in_2d<double> tm_in{tm.data(), 2, 2};

for (auto cm : {false, true}) {
prop_t prop{md_input_t{ins.data(), 9, 2}, kw::compact_mode = cm};

std::vector<double> outs(24u);
prop_t::out_3d out{outs.data(), 2, 6, 2};

prop(out, tm_in);

REQUIRE(out(0, 0, 0) == approximately(3134.2015620939, 10000.));
REQUIRE(out(0, 1, 0) == approximately(4604.963663328277, 10000.));
REQUIRE(out(0, 2, 0) == approximately(-4791.661126560278, 10000.));
REQUIRE(out(0, 3, 0) == approximately(2.732034613044249, 10000.));
REQUIRE(out(0, 4, 0) == approximately(3.952589777415254, 10000.));
REQUIRE(out(0, 5, 0) == approximately(5.588906721377138, 10000.));
REQUIRE(out(0, 0, 1) == approximately(3469.947984145807, 10000.));
REQUIRE(out(0, 1, 1) == approximately(-2690.388430131083, 10000.));
REQUIRE(out(0, 2, 1) == approximately(5175.831924199492, 10000.));
REQUIRE(out(0, 3, 1) == approximately(5.810229142351453, 10000.));
REQUIRE(out(0, 4, 1) == approximately(4.802261184784617, 10000.));
REQUIRE(out(0, 5, 1) == approximately(-1.388280333072693, 10000.));
REQUIRE(out(1, 0, 0) == approximately(2561.223660636298, 10000.));
REQUIRE(out(1, 1, 0) == approximately(3698.797144057697, 10000.));
REQUIRE(out(1, 2, 0) == approximately(5818.772215708888, 10000.));
REQUIRE(out(1, 3, 0) == approximately(-3.276142513618007, 10000.));
REQUIRE(out(1, 4, 0) == approximately(-4.806489082829041, 10000.));
REQUIRE(out(1, 5, 0) == approximately(4.511134501638151, 10000.));
REQUIRE(out(1, 0, 1) == approximately(-3591.82683131782, 10000.));
REQUIRE(out(1, 1, 1) == approximately(2723.666407193435, 10000.));
REQUIRE(out(1, 2, 1) == approximately(-5090.448264983512, 10000.));
REQUIRE(out(1, 3, 1) == approximately(-5.927709516654264, 10000.));
REQUIRE(out(1, 4, 1) == approximately(-4.496384419253211, 10000.));
REQUIRE(out(1, 5, 1) == approximately(1.785277174529374, 10000.));

auto dates = std::array<prop_t::date, 4>{{{2460486.5 + 1, 0.6478633000000116},
{2458826.5, 0.6933954099999937},
{2460486.5, 0.6478633000000116},
{2458826.5 + 1, 0.6933954099999937}}};
prop_t::in_2d<prop_t::date> date_in{dates.data(), 2, 2};

prop(out, date_in);

REQUIRE(out(0, 0, 0) == approximately(3134.2015620939, 10000.));
REQUIRE(out(0, 1, 0) == approximately(4604.963663328277, 10000.));
REQUIRE(out(0, 2, 0) == approximately(-4791.661126560278, 10000.));
REQUIRE(out(0, 3, 0) == approximately(2.732034613044249, 10000.));
REQUIRE(out(0, 4, 0) == approximately(3.952589777415254, 10000.));
REQUIRE(out(0, 5, 0) == approximately(5.588906721377138, 10000.));
REQUIRE(out(0, 0, 1) == approximately(3469.947984145807, 10000.));
REQUIRE(out(0, 1, 1) == approximately(-2690.388430131083, 10000.));
REQUIRE(out(0, 2, 1) == approximately(5175.831924199492, 10000.));
REQUIRE(out(0, 3, 1) == approximately(5.810229142351453, 10000.));
REQUIRE(out(0, 4, 1) == approximately(4.802261184784617, 10000.));
REQUIRE(out(0, 5, 1) == approximately(-1.388280333072693, 10000.));
REQUIRE(out(1, 0, 0) == approximately(2561.223660636298, 10000.));
REQUIRE(out(1, 1, 0) == approximately(3698.797144057697, 10000.));
REQUIRE(out(1, 2, 0) == approximately(5818.772215708888, 10000.));
REQUIRE(out(1, 3, 0) == approximately(-3.276142513618007, 10000.));
REQUIRE(out(1, 4, 0) == approximately(-4.806489082829041, 10000.));
REQUIRE(out(1, 5, 0) == approximately(4.511134501638151, 10000.));
REQUIRE(out(1, 0, 1) == approximately(-3591.82683131782, 10000.));
REQUIRE(out(1, 1, 1) == approximately(2723.666407193435, 10000.));
REQUIRE(out(1, 2, 1) == approximately(-5090.448264983512, 10000.));
REQUIRE(out(1, 3, 1) == approximately(-5.927709516654264, 10000.));
REQUIRE(out(1, 4, 1) == approximately(-4.496384419253211, 10000.));
REQUIRE(out(1, 5, 1) == approximately(1.785277174529374, 10000.));
}
}

0 comments on commit 741dbe2

Please sign in to comment.