Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: mockingbirdnest/Principia
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 10e95710cd1b
Choose a base ref
...
head repository: mockingbirdnest/Principia
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: d682ca43aa56
Choose a head ref
  • 9 commits
  • 17 files changed
  • 1 contributor

Commits on Dec 8, 2018

  1. Copy the full SHA
    e1e5afe View commit details
  2. Copy the full SHA
    768890f View commit details
  3. Compatibility value.

    pleroy committed Dec 8, 2018
    Copy the full SHA
    81449f9 View commit details
  4. Copy the full SHA
    55f7b0c View commit details
  5. Fix the tests.

    pleroy committed Dec 8, 2018
    Copy the full SHA
    acadab5 View commit details
  6. Fix 2 failures.

    pleroy committed Dec 8, 2018
    Copy the full SHA
    5fdbfe8 View commit details
  7. All the tests pass.

    pleroy committed Dec 8, 2018
    Copy the full SHA
    2cd7821 View commit details
  8. After egg's review.

    pleroy committed Dec 8, 2018
    Copy the full SHA
    643a3bf View commit details
  9. Merge pull request #2022 from pleroy/2021

    Remove unused initial_direction from C#
    pleroy authored Dec 8, 2018
    Copy the full SHA
    d682ca4 View commit details
1 change: 1 addition & 0 deletions journal/profiles.hpp
Original file line number Diff line number Diff line change
@@ -22,6 +22,7 @@ using interface::Burn;
using interface::ConfigurationAccuracyParameters;
using interface::ConfigurationAdaptiveStepParameters;
using interface::ConfigurationFixedStepParameters;
using interface::FlightPlanAdaptiveStepParameters;
using interface::KeplerianElements;
using interface::Iterator;
using interface::NavigationFrameParameters;
26 changes: 17 additions & 9 deletions ksp_plugin/flight_plan.cpp
Original file line number Diff line number Diff line change
@@ -7,6 +7,7 @@
#include "integrators/embedded_explicit_generalized_runge_kutta_nyström_integrator.hpp"
#include "integrators/embedded_explicit_runge_kutta_nyström_integrator.hpp"
#include "integrators/methods.hpp"
#include "ksp_plugin/integrators.hpp"
#include "testing_utilities/make_not_null.hpp"

namespace principia {
@@ -181,16 +182,28 @@ FlightPlan::adaptive_step_parameters() const {
return adaptive_step_parameters_;
}

Ephemeris<Barycentric>::GeneralizedAdaptiveStepParameters const&
FlightPlan::generalized_adaptive_step_parameters() const {
return generalized_adaptive_step_parameters_;
}

bool FlightPlan::SetAdaptiveStepParameters(
Ephemeris<Barycentric>::AdaptiveStepParameters const&
adaptive_step_parameters) {
adaptive_step_parameters,
Ephemeris<Barycentric>::GeneralizedAdaptiveStepParameters const&
generalized_adaptive_step_parameters) {
auto const original_adaptive_step_parameters = adaptive_step_parameters_;
auto const original_generalized_adaptive_step_parameters =
generalized_adaptive_step_parameters_;
adaptive_step_parameters_ = adaptive_step_parameters;
generalized_adaptive_step_parameters_ = generalized_adaptive_step_parameters;
if (RecomputeSegments()) {
return true;
} else {
// If the recomputation fails, leave this place as clean as we found it.
adaptive_step_parameters_ = original_adaptive_step_parameters;
generalized_adaptive_step_parameters_ =
original_generalized_adaptive_step_parameters;
CHECK(RecomputeSegments());
return false;
}
@@ -245,19 +258,14 @@ std::unique_ptr<FlightPlan> FlightPlan::ReadFromMessage(
Ephemeris<Barycentric>::AdaptiveStepParameters::ReadFromMessage(
message.adaptive_step_parameters()));

bool const is_pre_εὔδοξος =
bool const is_pre_erdős =
!message.has_generalized_adaptive_step_parameters();
std::unique_ptr<Ephemeris<Barycentric>::GeneralizedAdaptiveStepParameters>
generalized_adaptive_step_parameters;
if (is_pre_εὔδοξος) {
if (is_pre_erdős) {
generalized_adaptive_step_parameters = std::make_unique<
Ephemeris<Barycentric>::GeneralizedAdaptiveStepParameters>(
EmbeddedExplicitGeneralizedRungeKuttaNyströmIntegrator<
Fine1987RKNG34,
Position<Barycentric>>(),
/*max_steps=*/1,
/*length_integration_tolerance=*/1 * Metre,
/*speed_integration_tolerance=*/1 * Metre / Second);
DefaultBurnParameters());
} else {
generalized_adaptive_step_parameters = std::make_unique<
Ephemeris<Barycentric>::GeneralizedAdaptiveStepParameters>(
6 changes: 5 additions & 1 deletion ksp_plugin/flight_plan.hpp
Original file line number Diff line number Diff line change
@@ -82,13 +82,17 @@ class FlightPlan {

virtual Ephemeris<Barycentric>::AdaptiveStepParameters const&
adaptive_step_parameters() const;
virtual Ephemeris<Barycentric>::GeneralizedAdaptiveStepParameters const&
generalized_adaptive_step_parameters() const;

// Sets the parameters used to compute the trajectories. The trajectories are
// recomputed. Returns false (and doesn't change this object) if the
// parameters would make it impossible to recompute the trajectories.
virtual bool SetAdaptiveStepParameters(
Ephemeris<Barycentric>::AdaptiveStepParameters const&
adaptive_step_parameters);
adaptive_step_parameters,
Ephemeris<Barycentric>::GeneralizedAdaptiveStepParameters const&
generalized_adaptive_step_parameters);

// Returns the number of trajectory segments in this object.
virtual int number_of_segments() const;
12 changes: 12 additions & 0 deletions ksp_plugin/interface.hpp
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@

#include <typeindex>
#include <type_traits>
#include <utility>

#include "base/not_null.hpp"
#include "base/macros.hpp"
@@ -74,6 +75,8 @@ void CDECL principia__InitGoogleLogging();
bool operator==(AdaptiveStepParameters const& left,
AdaptiveStepParameters const& right);
bool operator==(Burn const& left, Burn const& right);
bool operator==(FlightPlanAdaptiveStepParameters const& left,
FlightPlanAdaptiveStepParameters const& right);
bool operator==(NavigationFrameParameters const& left,
NavigationFrameParameters const& right);
bool operator==(NavigationManoeuvre const& left,
@@ -90,6 +93,10 @@ bool operator==(XYZ const& left, XYZ const& right);
physics::Ephemeris<Barycentric>::AdaptiveStepParameters
FromAdaptiveStepParameters(
AdaptiveStepParameters const& adaptive_step_parameters);
std::pair<physics::Ephemeris<Barycentric>::AdaptiveStepParameters,
physics::Ephemeris<Barycentric>::GeneralizedAdaptiveStepParameters>
FromFlightPlanAdaptiveStepParameters(FlightPlanAdaptiveStepParameters const&
flight_plan_adaptive_step_parameters);

template<typename T>
T FromQP(QP const& qp);
@@ -114,6 +121,11 @@ FromXYZ<Velocity<Frenet<NavigationFrame>>>(XYZ const& xyz);
AdaptiveStepParameters ToAdaptiveStepParameters(
physics::Ephemeris<Barycentric>::AdaptiveStepParameters const&
adaptive_step_parameters);
FlightPlanAdaptiveStepParameters ToFlightPlanAdaptiveStepParameters(
physics::Ephemeris<Barycentric>::AdaptiveStepParameters const&
adaptive_step_parameters,
physics::Ephemeris<Barycentric>::GeneralizedAdaptiveStepParameters const&
generalized_adaptive_step_parameters);

KeplerianElements ToKeplerianElements(
physics::KeplerianElements<Barycentric> const& keplerian_elements);
77 changes: 75 additions & 2 deletions ksp_plugin/interface_body.hpp
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@

#include <cmath>
#include <limits>
#include <utility>

namespace principia {
namespace interface {
@@ -123,6 +124,18 @@ inline bool operator==(Burn const& left, Burn const& right) {
left.delta_v == right.delta_v;
}

inline bool operator==(FlightPlanAdaptiveStepParameters const& left,
FlightPlanAdaptiveStepParameters const& right) {
return left.integrator_kind == right.integrator_kind &&
left.generalized_integrator_kind ==
right.generalized_integrator_kind &&
left.max_steps == right.max_steps &&
NaNIndependentEq(left.length_integration_tolerance,
right.length_integration_tolerance) &&
NaNIndependentEq(left.speed_integration_tolerance,
right.speed_integration_tolerance);
}

inline bool operator==(NavigationFrameParameters const& left,
NavigationFrameParameters const& right) {
return left.extension == right.extension &&
@@ -144,8 +157,7 @@ inline bool operator==(NavigationManoeuvre const& left,
NaNIndependentEq(left.time_of_half_delta_v,
right.time_of_half_delta_v) &&
NaNIndependentEq(left.time_to_half_delta_v,
right.time_to_half_delta_v) &&
left.inertial_direction == right.inertial_direction;
right.time_to_half_delta_v);
}

inline bool operator==(NavigationManoeuvreFrenetTrihedron const& left,
@@ -197,6 +209,49 @@ FromAdaptiveStepParameters(
adaptive_step_parameters.speed_integration_tolerance * (Metre / Second));
}

inline std::pair<
physics::Ephemeris<Barycentric>::AdaptiveStepParameters,
physics::Ephemeris<Barycentric>::GeneralizedAdaptiveStepParameters>
FromFlightPlanAdaptiveStepParameters(FlightPlanAdaptiveStepParameters const&
flight_plan_adaptive_step_parameters) {
serialization::AdaptiveStepSizeIntegrator message1;
CHECK(serialization::AdaptiveStepSizeIntegrator::Kind_IsValid(
flight_plan_adaptive_step_parameters.integrator_kind));
message1.set_kind(
static_cast<serialization::AdaptiveStepSizeIntegrator::Kind>(
flight_plan_adaptive_step_parameters.integrator_kind));

serialization::AdaptiveStepSizeIntegrator message2;
CHECK(serialization::AdaptiveStepSizeIntegrator::Kind_IsValid(
flight_plan_adaptive_step_parameters.generalized_integrator_kind));
message2.set_kind(
static_cast<serialization::AdaptiveStepSizeIntegrator::Kind>(
flight_plan_adaptive_step_parameters.generalized_integrator_kind));

auto const max_steps = flight_plan_adaptive_step_parameters.max_steps;
auto const length_integration_tolerance =
flight_plan_adaptive_step_parameters.length_integration_tolerance * Metre;
auto const speed_integration_tolerance =
flight_plan_adaptive_step_parameters.speed_integration_tolerance *
(Metre / Second);

auto const adaptive_step_parameters =
Ephemeris<Barycentric>::AdaptiveStepParameters(
AdaptiveStepSizeIntegrator<Ephemeris<Barycentric>::
NewtonianMotionEquation>::ReadFromMessage(message1),
max_steps,
length_integration_tolerance,
speed_integration_tolerance);
auto const generalized_adaptive_step_parameters =
Ephemeris<Barycentric>::GeneralizedAdaptiveStepParameters(
AdaptiveStepSizeIntegrator<Ephemeris<Barycentric>::
GeneralizedNewtonianMotionEquation>::ReadFromMessage(message2),
max_steps,
length_integration_tolerance,
speed_integration_tolerance);
return {adaptive_step_parameters, generalized_adaptive_step_parameters};
}

template<>
inline DegreesOfFreedom<World> FromQP(QP const& qp) {
return QPConverter<DegreesOfFreedom<World>>::FromQP(qp);
@@ -239,6 +294,24 @@ inline AdaptiveStepParameters ToAdaptiveStepParameters(
(Metre / Second)};
}

inline FlightPlanAdaptiveStepParameters ToFlightPlanAdaptiveStepParameters(
physics::Ephemeris<Barycentric>::AdaptiveStepParameters const&
adaptive_step_parameters,
physics::Ephemeris<Barycentric>::GeneralizedAdaptiveStepParameters const&
generalized_adaptive_step_parameters) {
serialization::AdaptiveStepSizeIntegrator message1;
adaptive_step_parameters.integrator().WriteToMessage(&message1);
serialization::AdaptiveStepSizeIntegrator message2;
generalized_adaptive_step_parameters.integrator().WriteToMessage(&message2);
// TODO(phl): Should we CHECK that the fields are consistent?
return {message1.kind(),
message2.kind(),
adaptive_step_parameters.max_steps(),
adaptive_step_parameters.length_integration_tolerance() / Metre,
adaptive_step_parameters.speed_integration_tolerance() /
(Metre / Second)};
}

inline KeplerianElements ToKeplerianElements(
physics::KeplerianElements<Barycentric> const& keplerian_elements) {
return {*keplerian_elements.eccentricity,
27 changes: 13 additions & 14 deletions ksp_plugin/interface_flight_plan.cpp
Original file line number Diff line number Diff line change
@@ -165,12 +165,6 @@ NavigationManoeuvre ToInterfaceNavigationManoeuvre(
result.final_time = ToGameTime(plugin, manœuvre.final_time());
result.time_of_half_delta_v = ToGameTime(plugin, manœuvre.time_of_half_Δv());
result.time_to_half_delta_v = manœuvre.time_to_half_Δv() / Second;
Vector<double, Barycentric> const barycentric_inertial_direction =
manœuvre.InertialDirection();
Vector<double, World> const world_inertial_direction =
plugin.renderer().BarycentricToWorld(plugin.PlanetariumRotation())(
barycentric_inertial_direction);
result.inertial_direction = ToXYZ(world_inertial_direction);
return result;
}

@@ -216,14 +210,17 @@ bool principia__FlightPlanExists(
return m.Return(plugin->GetVessel(vessel_guid)->has_flight_plan());
}

AdaptiveStepParameters principia__FlightPlanGetAdaptiveStepParameters(
FlightPlanAdaptiveStepParameters
principia__FlightPlanGetAdaptiveStepParameters(
Plugin const* const plugin,
char const* const vessel_guid) {
journal::Method<journal::FlightPlanGetAdaptiveStepParameters> m(
{plugin, vessel_guid});
CHECK_NOTNULL(plugin);
return m.Return(ToAdaptiveStepParameters(
GetFlightPlan(*plugin, vessel_guid).adaptive_step_parameters()));
auto const& flight_plan = GetFlightPlan(*plugin, vessel_guid);
return m.Return(ToFlightPlanAdaptiveStepParameters(
flight_plan.adaptive_step_parameters(),
flight_plan.generalized_adaptive_step_parameters()));
}

double principia__FlightPlanGetActualFinalTime(Plugin const* const plugin,
@@ -462,14 +459,16 @@ bool principia__FlightPlanReplaceLast(Plugin const* const plugin,
bool principia__FlightPlanSetAdaptiveStepParameters(
Plugin const* const plugin,
char const* const vessel_guid,
AdaptiveStepParameters const adaptive_step_parameters) {
FlightPlanAdaptiveStepParameters const
flight_plan_adaptive_step_parameters) {
journal::Method<journal::FlightPlanSetAdaptiveStepParameters> m(
{plugin, vessel_guid, adaptive_step_parameters});
{plugin, vessel_guid, flight_plan_adaptive_step_parameters});
CHECK_NOTNULL(plugin);
auto const parameters = FromFlightPlanAdaptiveStepParameters(
flight_plan_adaptive_step_parameters);
return m.Return(
GetFlightPlan(*plugin, vessel_guid).
SetAdaptiveStepParameters(
FromAdaptiveStepParameters(adaptive_step_parameters)));
GetFlightPlan(*plugin, vessel_guid).
SetAdaptiveStepParameters(parameters.first, parameters.second));
}

bool principia__FlightPlanSetDesiredFinalTime(Plugin const* const plugin,
38 changes: 10 additions & 28 deletions ksp_plugin/plugin.cpp
Original file line number Diff line number Diff line change
@@ -108,7 +108,6 @@ Plugin::Plugin(std::string const& game_epoch,
Angle const& planetarium_rotation)
: history_parameters_(DefaultHistoryParameters()),
psychohistory_parameters_(DefaultPsychohistoryParameters()),
prediction_parameters_(DefaultPredictionParameters()),
vessel_thread_pool_(
/*pool_size=*/2 * std::thread::hardware_concurrency()),
planetarium_rotation_(planetarium_rotation),
@@ -374,12 +373,13 @@ void Plugin::InsertOrKeepVessel(GUID const& vessel_guid,
auto it = vessels_.find(vessel_guid);
if (it == vessels_.end()) {
std::tie(it, inserted) =
vessels_.emplace(vessel_guid,
make_not_null_unique<Vessel>(vessel_guid,
vessel_name,
parent,
ephemeris_.get(),
prediction_parameters_));
vessels_.emplace(
vessel_guid,
make_not_null_unique<Vessel>(vessel_guid,
vessel_name,
parent,
ephemeris_.get(),
DefaultPredictionParameters()));
} else {
inserted = false;
}
@@ -855,7 +855,7 @@ void Plugin::CreateFlightPlan(GUID const& vessel_guid,
FindOrDie(vessels_, vessel_guid)->CreateFlightPlan(
final_time,
initial_mass,
prediction_parameters_,
DefaultPredictionParameters(),
DefaultBurnParameters());
}

@@ -940,16 +940,6 @@ void Plugin::ComputeAndRenderNodes(
PlanetariumRotation());
}

void Plugin::SetPredictionAdaptiveStepParameters(
Ephemeris<Barycentric>::AdaptiveStepParameters const&
prediction_adaptive_step_parameters) {
prediction_parameters_ = prediction_adaptive_step_parameters;
for (auto const& pair : vessels_) {
not_null<std::unique_ptr<Vessel>> const& vessel = pair.second;
vessel->set_prediction_adaptive_step_parameters(prediction_parameters_);
}
}

bool Plugin::HasCelestial(Index const index) const {
return Contains(celestials_, index);
}
@@ -1252,8 +1242,6 @@ void Plugin::WriteToMessage(
history_parameters_.WriteToMessage(message->mutable_history_parameters());
psychohistory_parameters_.WriteToMessage(
message->mutable_psychohistory_parameters());
prediction_parameters_.WriteToMessage(
message->mutable_prediction_parameters());

planetarium_rotation_.WriteToMessage(message->mutable_planetarium_rotation());
game_epoch_.WriteToMessage(message->mutable_game_epoch());
@@ -1277,13 +1265,9 @@ not_null<std::unique_ptr<Plugin>> Plugin::ReadFromMessage(
auto const psychohistory_parameters =
Ephemeris<Barycentric>::AdaptiveStepParameters::ReadFromMessage(
message.psychohistory_parameters());
auto const prediction_parameters =
Ephemeris<Barycentric>::AdaptiveStepParameters::ReadFromMessage(
message.prediction_parameters());
not_null<std::unique_ptr<Plugin>> plugin =
std::unique_ptr<Plugin>(new Plugin(history_parameters,
psychohistory_parameters,
prediction_parameters));
psychohistory_parameters));

plugin->ephemeris_ =
Ephemeris<Barycentric>::ReadFromMessage(message.ephemeris());
@@ -1396,11 +1380,9 @@ not_null<std::unique_ptr<Plugin>> Plugin::ReadFromMessage(
Plugin::Plugin(
Ephemeris<Barycentric>::FixedStepParameters const& history_parameters,
Ephemeris<Barycentric>::AdaptiveStepParameters const&
psychohistory_parameters,
Ephemeris<Barycentric>::AdaptiveStepParameters const& prediction_parameters)
psychohistory_parameters)
: history_parameters_(history_parameters),
psychohistory_parameters_(psychohistory_parameters),
prediction_parameters_(prediction_parameters),
vessel_thread_pool_(
/*pool_size=*/2 * std::thread::hardware_concurrency()) {}

Loading