Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates for latest heyoka changes #135

Merged
merged 4 commits into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions doc/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ Changelog
New
~~~

- Add model for the circular restricted three-body problem
(`#135 <https://github.com/bluescarni/heyoka.py/pull/135>`__).
- The LLVM SLP vectorizer can now be enabled
(`#134 <https://github.com/bluescarni/heyoka.py/pull/134>`__).
This feature is opt-in due to the fact that enabling it
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
"where $f_h$ is the perturbative acceleration acting on the satellite along the $\\hat{\\mathbf e}_h$ direction.\n",
"\n",
"## The Equations of Motion\n",
"We consider the dynamics of both the Chief and the Deputy expressed in terms of their position and velocity in $\\mathcal F_i$ and subject to the J2 term only (the expression of additional terms for the Earth gravitational potential can be found [here](https://space.stackexchange.com/questions/22266/j2-long-period-perturbations-in-the-inclination):\n",
"We consider the dynamics of both the Chief and the Deputy expressed in terms of their position and velocity in $\\mathcal F_i$ and subject to the J2 term only:\n",
"\n",
"$$\n",
"\\left\\{\n",
Expand Down
18 changes: 18 additions & 0 deletions heyoka/_test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,3 +252,21 @@ def test_pendulum(self):
)
),
)

def test_cr3bp(self):
from . import model, make_vars

x, px, y = make_vars("x", "px", "y")

dyn = model.cr3bp()
self.assertEqual(dyn[0][0], x)
self.assertEqual(dyn[0][1], px + y)

dyn = model.cr3bp(mu=1.0 / 2**4)
self.assertTrue("0.06250000000" in str(dyn[3][1]))

jac = model.cr3bp_jacobi()
self.assertTrue("0.00100000" in str(jac))

jac = model.cr3bp_jacobi(mu=1.0 / 2**4)
self.assertTrue("0.06250000000" in str(jac))
3 changes: 2 additions & 1 deletion heyoka/expose_expression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <heyoka/config.hpp>

#include <cstdint>
#include <functional>
#include <iterator>
#include <optional>
#include <sstream>
Expand Down Expand Up @@ -201,7 +202,7 @@ void expose_expression(py::module_ &m)
.def("__copy__", copy_wrapper<hey::expression>)
.def("__deepcopy__", deepcopy_wrapper<hey::expression>, "memo"_a)
// Hashing.
.def("__hash__", [](const heyoka::expression &e) { return heyoka::hash(e); })
.def("__hash__", [](const heyoka::expression &e) { return std::hash<heyoka::expression>{}(e); })
// Pickle support.
.def(py::pickle(&pickle_getstate_wrapper<hey::expression>, &pickle_setstate_wrapper<hey::expression>));

Expand Down
19 changes: 19 additions & 0 deletions heyoka/expose_models.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,17 @@ auto mascon_impl(const Op &op, const V &Gconst, const std::vector<V> &masses, co
hy::kw::omega = omega_vec);
}

// Common logic to expose cr3bp helpers.
template <typename Op, typename V>
auto cr3bp_impl(const Op &op, const V &mu)
{
namespace hy = heyoka;

const auto muval = ex_from_variant(mu);

return op(hy::kw::mu = muval);
}

} // namespace

} // namespace detail
Expand Down Expand Up @@ -343,6 +354,14 @@ void expose_models(py::module_ &m)
},
"pl_idx"_a, "time"_a = hy::time, "thresh"_a.noconvert() = 1e-9);
m.def("_model_get_vsop2013_mus", &hy::model::get_vsop2013_mus);

// CR3BP.
m.def(
"_model_cr3bp", [](const vex_t &mu) { return detail::cr3bp_impl(hy::model::cr3bp, mu); },
"mu"_a.noconvert() = 1e-3);
m.def(
"_model_cr3bp_jacobi", [](const vex_t &mu) { return detail::cr3bp_impl(hy::model::cr3bp_jacobi, mu); },
"mu"_a.noconvert() = 1e-3);
}

} // namespace heyoka_py