Skip to content

Commit

Permalink
udpla::keplerian interface
Browse files Browse the repository at this point in the history
  • Loading branch information
darioizzo committed Aug 29, 2023
1 parent 5585613 commit 8641703
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 1 deletion.
8 changes: 7 additions & 1 deletion include/kep3/core_astro/convert_anomalies.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<double>::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<double>(),
IG + boost::math::constants::pi<double>(), digits);
IG + boost::math::constants::pi<double>(), 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
Expand Down
73 changes: 73 additions & 0 deletions include/kep3/planets/keplerian.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@

// Copyright 2023, 2024 Dario Izzo ([email protected]), Francesco Biscani
// ([email protected])
//
// 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 <array>
#include <utility>

#include <kep3/detail/visibility.hpp>
#include <kep3/epoch.hpp>
#include <kep3/planet.hpp>


namespace kep3::udpla {

class kep3_DLL_PUBLIC keplerian {

static const std::array<double, 6> default_elements;

kep3::epoch m_ref_epoch;
std::array<double, 6> 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 <typename Archive> 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<double, 6> &elem = default_elements,
double mu_central_body = 1., std::string name = "Unknown",
std::array<double, 3> added_params = {-1., -1., -1.});

// Mandatory UDPLA methods
static std::array<std::array<double, 3>, 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

0 comments on commit 8641703

Please sign in to comment.