Skip to content

Commit

Permalink
New tutorial on learning mascons, doc additions.
Browse files Browse the repository at this point in the history
  • Loading branch information
bluescarni committed Jun 16, 2024
1 parent f5c09f4 commit 008f72d
Show file tree
Hide file tree
Showing 7 changed files with 502 additions and 2 deletions.
1 change: 1 addition & 0 deletions doc/api_model.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ Functions
cart2geo
nrlmsise00_tn
jb08_tn
fixed_centres
1 change: 1 addition & 0 deletions doc/examples_astro.rst
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,4 @@ Celestial mechanics and astrodynamics
notebooks/tides_spokes
notebooks/lagrangian_propagator
notebooks/gg_stab
notebooks/learning_mascons
458 changes: 458 additions & 0 deletions doc/notebooks/learning_mascons.ipynb

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions heyoka/_test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ def test_rotating(self):

def test_fixed_centres(self):
from . import model, make_vars, expression as ex, sqrt
from numpy import single

x, y, z, vx, vy, vz = make_vars("x", "y", "z", "vx", "vy", "vz")

Expand Down Expand Up @@ -140,6 +141,15 @@ def test_fixed_centres(self):
in str(cm.exception)
)

# Run also a small test with single-precision values.
dyn = model.fixed_centres(
Gconst=single(1.5), masses=[single(1.1)], positions=[[1.0, 2.0, 3.0]]
)

self.assertEqual(dyn[0][0], x)
self.assertEqual(dyn[0][1], ex("vx"))
self.assertTrue("1.10000002" in repr(dyn))

def test_nbody(self):
from . import model, expression, sqrt, make_vars

Expand Down
27 changes: 27 additions & 0 deletions heyoka/docstrings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -678,4 +678,31 @@ std::string var_args_all()
)";
}

std::string fixed_centres()
{
return R"(fixed_centres(Gconst: expression | str | numpy.single | float | numpy.longdouble = 1., masses: list[expression | str | numpy.single | float | numpy.longdouble] = [], positions: collections.abc.Iterable = numpy.empty((0, 3), dtype=float)) -> list[tuple[expression, expression]]
Produces the expression for the dynamics of a fixed-centres problem.
In the fixed-centres problem, a number of massive particles are fixed in space, which each mass generating
a Newtonian gravitational field.
Several checks are run on the input arguments:
- *positions* must be convertible into an ``N x 3`` array, with each row containing
the position vector of a mass,
- the number of elements in *masses* must be the same as the number of three-dimensional
position vectors in *positions*.
:param Gconst: the gravitational constant.
:param masses: the list of mass values (one for each particle).
:param positions: the positions of the particles.
:returns: the dynamics of the Newtonian fixed centres problem.
:raises ValueError: if one or more input arguments are malformed, as explained above.
)";
}

} // namespace heyoka_py::docstrings
1 change: 1 addition & 0 deletions heyoka/docstrings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ std::string hamiltonian();
std::string cart2geo();
std::string nrlmsise00_tn();
std::string jb08_tn();
std::string fixed_centres();

// var_ode_sys() and related.
std::string var_args();
Expand Down
6 changes: 4 additions & 2 deletions heyoka/expose_models.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@

#include "common_utils.hpp"
#include "custom_casters.hpp"
#include "docstrings.hpp"
#include "dtypes.hpp"
#include "expose_models.hpp"

Expand Down Expand Up @@ -207,7 +208,7 @@ void expose_models(py::module_ &m)

// A variant containing either an expression or a numerical/string
// type from which an expression can be constructed.
using vex_t = std::variant<hy::expression, std::string, double, long double
using vex_t = std::variant<hy::expression, std::string, float, double, long double
#if defined(HEYOKA_HAVE_REAL128)
,
mppp::real128
Expand Down Expand Up @@ -276,7 +277,8 @@ void expose_models(py::module_ &m)
return detail::fixed_centres_impl(hy::model::fixed_centres, Gconst, masses, positions);
},
"Gconst"_a.noconvert() = 1., "masses"_a.noconvert() = py::list{},
"positions"_a = py::array{py::dtype(get_dtype<double>()), py::array::ShapeContainer{0, 3}});
"positions"_a = py::array{py::dtype(get_dtype<double>()), py::array::ShapeContainer{0, 3}},
docstrings::fixed_centres().c_str());
m.def(
"_model_fixed_centres_energy",
[](const vex_t &Gconst, const std::vector<vex_t> &masses, const py::iterable &positions) {
Expand Down

0 comments on commit 008f72d

Please sign in to comment.