From 864170334da99e6334785e9cbc2e7cd72832e1cf Mon Sep 17 00:00:00 2001 From: Dario Izzo Date: Tue, 29 Aug 2023 10:44:51 +0200 Subject: [PATCH] udpla::keplerian interface --- include/kep3/core_astro/convert_anomalies.hpp | 8 +- include/kep3/planets/keplerian.hpp | 73 +++++++++++++++++++ 2 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 include/kep3/planets/keplerian.hpp diff --git a/include/kep3/core_astro/convert_anomalies.hpp b/include/kep3/core_astro/convert_anomalies.hpp index c3892804..c845a985 100644 --- a/include/kep3/core_astro/convert_anomalies.hpp +++ b/include/kep3/core_astro/convert_anomalies.hpp @@ -26,13 +26,19 @@ inline double m2e(double M, double ecc) { // (tests indicated that any higher order expansion does not really improve) double IG = M; const int digits = std::numeric_limits::digits; + std::uintmax_t max_iter = 100u; double sol = boost::math::tools::halley_iterate( [M, ecc](double E) { return std::make_tuple(kepE(E, M, ecc), d_kepE(E, ecc), dd_kepE(E, ecc)); }, IG, IG - boost::math::constants::pi(), - IG + boost::math::constants::pi(), digits); + IG + boost::math::constants::pi(), digits, max_iter); + if (max_iter == 100u) { + throw std::domain_error( + "Maximum number of iterations exceeded when solving Kepler's " + "equation for the eccentric anomaly in m2e."); + } return sol; } // eccentric to mean (only ellipses) e<1 diff --git a/include/kep3/planets/keplerian.hpp b/include/kep3/planets/keplerian.hpp new file mode 100644 index 00000000..bfecada0 --- /dev/null +++ b/include/kep3/planets/keplerian.hpp @@ -0,0 +1,73 @@ + +// Copyright 2023, 2024 Dario Izzo (dario.izzo@gmail.com), Francesco Biscani +// (bluescarni@gmail.com) +// +// This file is part of the kep3 library. +// +// This Source Code Form is subject to the terms of the Mozilla +// Public License v. 2.0. If a copy of the MPL was not distributed +// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. + +#ifndef kep3_UDPLA_KEPLERIAN_H +#define kep3_UDPLA_KEPLERIAN_H + +#include +#include + +#include +#include +#include + + +namespace kep3::udpla { + +class kep3_DLL_PUBLIC keplerian { + + static const std::array default_elements; + + kep3::epoch m_ref_epoch; + std::array m_elem; + std::string m_name; + double m_mu_central_body; + double m_mu_self; + double m_radius; + double m_safe_radius; + + friend class boost::serialization::access; + template void serialize(Archive &ar, unsigned) { + ar &m_ref_epoch; + ar &m_elem; + ar &m_name; + ar &m_mu_central_body; + ar &m_mu_self; + ar &m_radius; + ar &m_safe_radius; + } + +public: + // NOTE: in here elem is a,e,i,W,w,M (Mean anomaly, not true anomaly) + // NOTE: added_param contains mu_self, radius and safe_radius + explicit keplerian(const epoch &ref_epoch = kep3::epoch(0), + const std::array &elem = default_elements, + double mu_central_body = 1., std::string name = "Unknown", + std::array added_params = {-1., -1., -1.}); + + // Mandatory UDPLA methods + static std::array, 2> eph(const epoch &); + + // Optional UDPLA methods + [[nodiscard]] std::string get_name() const; + [[nodiscard]] double get_mu_central_body() const; + [[nodiscard]] double get_mu_self() const; + [[nodiscard]] double get_radius() const; + [[nodiscard]] double get_safe_radius() const; + [[nodiscard]] std::string get_extra_info() const; + + // Other methods + [[nodiscard]] std::string get_ref_epoch() const; + [[nodiscard]] std::string get_elem() const; +}; +} // namespace kep3::udpla +kep3_S11N_PLANET_EXPORT_KEY(kep3::udpla::keplerian); + +#endif // kep3_EPOCH_H \ No newline at end of file