From f4623b455421f5acc043e8d7b6723e7d5281c08f Mon Sep 17 00:00:00 2001 From: Francesco Biscani Date: Tue, 8 Aug 2023 09:42:32 +0200 Subject: [PATCH 1/2] Move the exposition of the VSOP2013 functions into the model submodule. --- doc/notebooks/vsop2013.ipynb | 12 ++++++------ heyoka/core.cpp | 25 ------------------------- heyoka/expose_models.cpp | 24 ++++++++++++++++++++++++ 3 files changed, 30 insertions(+), 31 deletions(-) diff --git a/doc/notebooks/vsop2013.ipynb b/doc/notebooks/vsop2013.ipynb index 18af7bd0..14be61be 100644 --- a/doc/notebooks/vsop2013.ipynb +++ b/doc/notebooks/vsop2013.ipynb @@ -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", @@ -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))))" ] }, { @@ -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)))" ] }, { @@ -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", diff --git a/heyoka/core.cpp b/heyoka/core.cpp index ab84c184..0014a745 100644 --- a/heyoka/core.cpp +++ b/heyoka/core.cpp @@ -10,14 +10,12 @@ #include #include -#include #include #include #include #include #include #include -#include #include #include @@ -46,7 +44,6 @@ #endif -#include #include #include #include @@ -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) { @@ -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. diff --git a/heyoka/expose_models.cpp b/heyoka/expose_models.cpp index f88b1a0e..45d0830c 100644 --- a/heyoka/expose_models.cpp +++ b/heyoka/expose_models.cpp @@ -9,6 +9,7 @@ #include #include +#include #include #include #include @@ -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()), 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 From b540a1869de8923f3bda1cf1854eab0a3fd06095 Mon Sep 17 00:00:00 2001 From: Francesco Biscani Date: Tue, 8 Aug 2023 09:46:40 +0200 Subject: [PATCH 2/2] Update changelog. --- doc/breaking_changes.rst | 3 +++ doc/changelog.rst | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/doc/breaking_changes.rst b/doc/breaking_changes.rst index 4e409dd1..dd2dc364 100644 --- a/doc/breaking_changes.rst +++ b/doc/breaking_changes.rst @@ -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. diff --git a/doc/changelog.rst b/doc/changelog.rst index aa9b2059..ac5fec85 100644 --- a/doc/changelog.rst +++ b/doc/changelog.rst @@ -40,6 +40,10 @@ New Changes ~~~~~~~ +- **BREAKING**: the VSOP2013 functions have been moved from the + main module to the new ``model`` submodule + (`#130 `__). + This is a :ref:`breaking change `. - The custom NumPy memory manager that prevents memory leaks with ``real`` arrays is now disabled by default (`#129 `__).