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

Move the VSOP2013 functions into the model submodule #130

Merged
merged 2 commits into from
Aug 8, 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
3 changes: 3 additions & 0 deletions doc/breaking_changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ Breaking changes
1.0.0
-----

- The VSOP2013 functions have been moved into the
``model`` submodule. The semantics of the functions
have not changed.
- The ``make_nbody_sys()`` function has been replaced by
the ``model.nbody()`` function, with identical semantics.

Expand Down
4 changes: 4 additions & 0 deletions doc/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ New
Changes
~~~~~~~

- **BREAKING**: the VSOP2013 functions have been moved from the
main module to the new ``model`` submodule
(`#130 <https://github.com/bluescarni/heyoka.py/pull/130>`__).
This is a :ref:`breaking change <bchanges_1_0_0>`.
- The custom NumPy memory manager that prevents memory leaks
with ``real`` arrays is now disabled by default
(`#129 <https://github.com/bluescarni/heyoka.py/pull/129>`__).
Expand Down
12 changes: 6 additions & 6 deletions doc/notebooks/vsop2013.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"API overview\n",
"-------\n",
"\n",
"heyoka.py provides three functions to generate the analytical formulae for the VSOP2013 theory.\n",
"heyoka.py provides three functions to generate the analytical formulae for the VSOP2013 theory. These functions are available in the ``model`` submodule.\n",
"\n",
"The first one, ``vsop2013_elliptic()``, returns the formulae for the heliocentric elliptic orbital elements for a given planet. The 6 elliptic orbital elements are, in order:\n",
"\n",
Expand Down Expand Up @@ -56,7 +56,7 @@
"import heyoka as hy\n",
"\n",
"for thr in [1e-7, 1e-9, 1e-11]:\n",
" print(\"Size of Mars' semi-major axis solution @ {}: {}\".format(thr, len(hy.vsop2013_elliptic(4, 1, thresh = thr))))"
" print(\"Size of Mars' semi-major axis solution @ {}: {}\".format(thr, len(hy.model.vsop2013_elliptic(4, 1, thresh = thr))))"
]
},
{
Expand Down Expand Up @@ -98,9 +98,9 @@
}
],
"source": [
"print(\"Mars' semi-major axis solution, threshold = 6e-5, default time expression:\\n{}\\n\".format(hy.vsop2013_elliptic(4, 1, thresh = 6e-5)))\n",
"print(\"Mars' semi-major axis solution, threshold = 6e-5, time represented by variable 'x':\\n{}\\n\".format(hy.vsop2013_elliptic(4, 1, time=hy.expression(\"x\"), thresh = 6e-5)))\n",
"print(\"Mars' semi-major axis solution, threshold = 6e-5, time rescaled by a factor of 100:\\n{}\".format(hy.vsop2013_elliptic(4, 1, time=hy.time / 100., thresh = 6e-5)))"
"print(\"Mars' semi-major axis solution, threshold = 6e-5, default time expression:\\n{}\\n\".format(hy.model.vsop2013_elliptic(4, 1, thresh = 6e-5)))\n",
"print(\"Mars' semi-major axis solution, threshold = 6e-5, time represented by variable 'x':\\n{}\\n\".format(hy.model.vsop2013_elliptic(4, 1, time=hy.expression(\"x\"), thresh = 6e-5)))\n",
"print(\"Mars' semi-major axis solution, threshold = 6e-5, time rescaled by a factor of 100:\\n{}\".format(hy.model.vsop2013_elliptic(4, 1, time=hy.time / 100., thresh = 6e-5)))"
]
},
{
Expand Down Expand Up @@ -161,7 +161,7 @@
" # position of Venus (planet index 2) in the ICRF. Replace the\n",
" # default time variable with the \"tm\" symbolic variable and set\n",
" # a custom threshold level.\n",
" venus_x, venus_y, venus_z = hy.vsop2013_cartesian_icrf(2, time=tm, thresh=thr)[:3]\n",
" venus_x, venus_y, venus_z = hy.model.vsop2013_cartesian_icrf(2, time=tm, thresh=thr)[:3]\n",
"\n",
" # Compile the function for the evaluation of venus_x/y/z.\n",
" venus_cf = hy.make_cfunc([venus_x, venus_y, venus_z])\n",
Expand Down
25 changes: 0 additions & 25 deletions heyoka/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,12 @@

#include <cassert>
#include <cstddef>
#include <cstdint>
#include <exception>
#include <initializer_list>
#include <iostream>
#include <optional>
#include <sstream>
#include <type_traits>
#include <utility>
#include <vector>

#include <oneapi/tbb/global_control.h>
Expand Down Expand Up @@ -46,7 +44,6 @@

#endif

#include <heyoka/celmec/vsop2013.hpp>
#include <heyoka/exceptions.hpp>
#include <heyoka/expression.hpp>
#include <heyoka/llvm_state.hpp>
Expand Down Expand Up @@ -107,7 +104,6 @@ PyObject *import_numpy(PyObject *m)
PYBIND11_MODULE(core, m)
{
using namespace pybind11::literals;
namespace kw = hey::kw;

// Import the NumPy API bits.
if (heypy::detail::import_numpy(m.ptr()) == nullptr) {
Expand Down Expand Up @@ -304,27 +300,6 @@ PYBIND11_MODULE(core, m)
// Setup the sympy integration bits.
heypy::setup_sympy(m);

// Expose the vsop2013 functions.
m.def(
"vsop2013_elliptic",
[](std::uint32_t pl_idx, std::uint32_t var_idx, hey::expression t_expr, double thresh) {
return hey::vsop2013_elliptic(pl_idx, var_idx, kw::time = std::move(t_expr), kw::thresh = thresh);
},
"pl_idx"_a, "var_idx"_a = 0, "time"_a = hey::time, "thresh"_a.noconvert() = 1e-9);
m.def(
"vsop2013_cartesian",
[](std::uint32_t pl_idx, hey::expression t_expr, double thresh) {
return hey::vsop2013_cartesian(pl_idx, kw::time = std::move(t_expr), kw::thresh = thresh);
},
"pl_idx"_a, "time"_a = hey::time, "thresh"_a.noconvert() = 1e-9);
m.def(
"vsop2013_cartesian_icrf",
[](std::uint32_t pl_idx, hey::expression t_expr, double thresh) {
return hey::vsop2013_cartesian_icrf(pl_idx, kw::time = std::move(t_expr), kw::thresh = thresh);
},
"pl_idx"_a, "time"_a = hey::time, "thresh"_a.noconvert() = 1e-9);
m.def("get_vsop2013_mus", &hey::get_vsop2013_mus);

// Expose the helpers to get/set the number of threads in use by heyoka.py.
// NOTE: these are not thread-safe themselves. Should they be? If not, their
// thread unsafety must be highlighted in the docs.
Expand Down
24 changes: 24 additions & 0 deletions heyoka/expose_models.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <heyoka/config.hpp>

#include <algorithm>
#include <cstdint>
#include <iterator>
#include <optional>
#include <string>
Expand Down Expand Up @@ -319,6 +320,29 @@ void expose_models(py::module_ &m)
"Gconst"_a.noconvert() = 1., "masses"_a.noconvert() = py::list{},
"positions"_a = py::array{py::dtype(get_dtype<double>()), py::array::ShapeContainer{0, 3}},
"omega"_a.noconvert() = py::list{});

// VSOP2013.
m.def(
"_model_vsop2013_elliptic",
[](std::uint32_t pl_idx, std::uint32_t var_idx, hy::expression t_expr, double thresh) {
return hy::model::vsop2013_elliptic(pl_idx, var_idx, hy::kw::time = std::move(t_expr),
hy::kw::thresh = thresh);
},
"pl_idx"_a, "var_idx"_a = 0, "time"_a = hy::time, "thresh"_a.noconvert() = 1e-9);
m.def(
"_model_vsop2013_cartesian",
[](std::uint32_t pl_idx, hy::expression t_expr, double thresh) {
return hy::model::vsop2013_cartesian(pl_idx, hy::kw::time = std::move(t_expr), hy::kw::thresh = thresh);
},
"pl_idx"_a, "time"_a = hy::time, "thresh"_a.noconvert() = 1e-9);
m.def(
"_model_vsop2013_cartesian_icrf",
[](std::uint32_t pl_idx, hy::expression t_expr, double thresh) {
return hy::model::vsop2013_cartesian_icrf(pl_idx, hy::kw::time = std::move(t_expr),
hy::kw::thresh = thresh);
},
"pl_idx"_a, "time"_a = hy::time, "thresh"_a.noconvert() = 1e-9);
m.def("_model_get_vsop2013_mus", &hy::model::get_vsop2013_mus);
}

} // namespace heyoka_py