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

Use Brent's method instead of bisection for computing apsides and nodes #3347

Merged
merged 3 commits into from Apr 22, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 4 additions & 5 deletions physics/apsides_body.hpp
Expand Up @@ -19,7 +19,7 @@ using geometry::Barycentre;
using geometry::Instant;
using geometry::Position;
using geometry::Sign;
using numerics::Bisect;
using numerics::Brent;
using numerics::Hermite3;
using quantities::IsFinite;
using quantities::Length;
Expand Down Expand Up @@ -176,10 +176,9 @@ absl::Status ComputeNodes(
node_time = Barycentre<Instant, Length>({*previous_time, time},
{z, -*previous_z});
} else {
// The normal case, find the intersection with z = 0 using bisection.
// TODO(egg): Bisection on a polynomial seems daft; we should have
// Newton's method.
node_time = Bisect(
// The normal case, find the intersection with z = 0 using Brent's
// method.
node_time = Brent(
[&z_approximation](Instant const& t) {
return z_approximation.Evaluate(t);
},
Expand Down
12 changes: 6 additions & 6 deletions physics/ephemeris_body.hpp
Expand Up @@ -49,7 +49,7 @@ using integrators::ExplicitSecondOrderOrdinaryDifferentialEquation;
using integrators::IntegrationProblem;
using integrators::Integrator;
using integrators::methods::Fine1987RKNG34;
using numerics::Bisect;
using numerics::Brent;
using numerics::DoublePrecision;
using numerics::Hermite3;
using quantities::Abs;
Expand Down Expand Up @@ -721,11 +721,11 @@ void Ephemeris<Frame>::ComputeApsides(not_null<MassiveBody const*> const body1,
CHECK(previous_time);

// The derivative of |squared_distance| changed sign. Find its zero by
// bisection, this is the time of the apsis. Then compute the apsis and
// append it to one of the output trajectories.
Instant const apsis_time = Bisect(evaluate_square_distance_derivative,
*previous_time,
time);
// Brent's method, this is the time of the apsis. Then compute the apsis
// and append it to one of the output trajectories.
Instant const apsis_time = Brent(evaluate_square_distance_derivative,
*previous_time,
time);
DegreesOfFreedom<Frame> const apsis1_degrees_of_freedom =
body1_trajectory->EvaluateDegreesOfFreedomLocked(apsis_time);
DegreesOfFreedom<Frame> const apsis2_degrees_of_freedom =
Expand Down
14 changes: 7 additions & 7 deletions physics/kepler_orbit_body.hpp
Expand Up @@ -29,7 +29,7 @@ using geometry::Sign;
using geometry::Vector;
using geometry::Velocity;
using geometry::Wedge;
using numerics::Bisect;
using numerics::Brent;
using quantities::Abs;
using quantities::ArcCos;
using quantities::ArcCosh;
Expand Down Expand Up @@ -642,9 +642,9 @@ void KeplerOrbit<Frame>::CompleteAnomalies(KeplerianElements<Frame>& elements) {
(eccentric_anomaly - e * Sin(eccentric_anomaly) * Radian);
};
Angle const eccentric_anomaly = e == 0 ? *mean_anomaly
: Bisect(kepler_equation,
*mean_anomaly - e * Radian,
*mean_anomaly + e * Radian);
: Brent(kepler_equation,
*mean_anomaly - e * Radian,
*mean_anomaly + e * Radian);
true_anomaly = 2 * ArcTan(Sqrt(1 + e) * Sin(eccentric_anomaly / 2),
Sqrt(1 - e) * Cos(eccentric_anomaly / 2));
hyperbolic_mean_anomaly = NaN<Angle>;
Expand All @@ -657,9 +657,9 @@ void KeplerOrbit<Frame>::CompleteAnomalies(KeplerianElements<Frame>& elements) {
hyperbolic_eccentric_anomaly);
};
Angle const hyperbolic_eccentric_anomaly =
Bisect(hyperbolic_kepler_equation,
0 * Radian,
*hyperbolic_mean_anomaly / (e - 1));
Brent(hyperbolic_kepler_equation,
0 * Radian,
*hyperbolic_mean_anomaly / (e - 1));
true_anomaly =
2 * ArcTan(Sqrt(e + 1) * Sinh(hyperbolic_eccentric_anomaly / 2),
Sqrt(e - 1) * Cosh(hyperbolic_eccentric_anomaly / 2));
Expand Down