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: 4aedd74d71fc
Choose a base ref
...
head repository: mockingbirdnest/Principia
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 177fca89274d
Choose a head ref
  • 19 commits
  • 21 files changed
  • 1 contributor

Commits on Apr 27, 2019

  1. Copy the full SHA
    a9f2023 View commit details
  2. Copy the full SHA
    a4cf8d0 View commit details

Commits on Apr 28, 2019

  1. Better names and some locking.

    pleroy committed Apr 28, 2019
    Copy the full SHA
    3d65c53 View commit details
  2. Locking the commander.

    pleroy committed Apr 28, 2019
    Copy the full SHA
    5db9004 View commit details
  3. TryToForgetBefore.

    pleroy committed Apr 28, 2019
    Copy the full SHA
    319e3f4 View commit details
  4. Comments.

    pleroy committed Apr 28, 2019
    Copy the full SHA
    d3382e9 View commit details
  5. New test failing.

    pleroy committed Apr 28, 2019
    Copy the full SHA
    65d813b View commit details

Commits on May 4, 2019

  1. Merge.

    pleroy committed May 4, 2019
    Copy the full SHA
    04057bb View commit details
  2. Fix the test.

    pleroy committed May 4, 2019
    Copy the full SHA
    44399e4 View commit details
  3. Protector object.

    pleroy committed May 4, 2019
    Copy the full SHA
    bb3ff4c View commit details
  4. Cleanup.

    pleroy committed May 4, 2019
    Copy the full SHA
    92d4b77 View commit details
  5. A test for the protector.

    pleroy committed May 4, 2019
    Copy the full SHA
    5dc6d2b View commit details
  6. Fix the clients.

    pleroy committed May 4, 2019
    Copy the full SHA
    37f85a6 View commit details
  7. Commented-out code.

    pleroy committed May 4, 2019
    Copy the full SHA
    c42973f View commit details
  8. Lint.

    pleroy committed May 4, 2019
    Copy the full SHA
    b867dfe View commit details
  9. Fix the mock.

    pleroy committed May 4, 2019
    Copy the full SHA
    ce83fec View commit details
  10. Lint, again.

    pleroy committed May 4, 2019
    Copy the full SHA
    5157c10 View commit details
  11. After egg's review.

    pleroy committed May 4, 2019
    Copy the full SHA
    32fa703 View commit details
  12. Merge pull request #2150 from pleroy/2090

    Quis custodiet ipsos custodes?
    pleroy authored May 4, 2019
    Copy the full SHA
    177fca8 View commit details
1 change: 1 addition & 0 deletions astronomy/astronomy.vcxproj
Original file line number Diff line number Diff line change
@@ -79,6 +79,7 @@
<ClCompile Include="..\base\bundle.cpp" />
<ClCompile Include="..\base\status.cpp" />
<ClCompile Include="..\numerics\cbrt.cpp" />
<ClCompile Include="..\physics\protector.cpp" />
<ClCompile Include="date_time_test.cpp" />
<ClCompile Include="ksp_fingerprint_test.cpp" />
<ClCompile Include="ksp_resonance_test.cpp" />
3 changes: 3 additions & 0 deletions astronomy/astronomy.vcxproj.filters
Original file line number Diff line number Diff line change
@@ -266,5 +266,8 @@
<ClCompile Include="standard_product_3_test.cpp">
<Filter>Test Files</Filter>
</ClCompile>
<ClCompile Include="..\physics\protector.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
</Project>
1 change: 1 addition & 0 deletions journal/journal.vcxproj
Original file line number Diff line number Diff line change
@@ -19,6 +19,7 @@
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\base\status.cpp" />
<ClCompile Include="..\physics\protector.cpp" />
<ClCompile Include="player.cpp" />
<ClCompile Include="player.generated.cc">
<ExcludedFromBuild>true</ExcludedFromBuild>
3 changes: 3 additions & 0 deletions journal/journal.vcxproj.filters
Original file line number Diff line number Diff line change
@@ -61,5 +61,8 @@
<ClCompile Include="..\base\status.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\physics\protector.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
</Project>
1 change: 1 addition & 0 deletions ksp_physics/ksp_physics.vcxproj
Original file line number Diff line number Diff line change
@@ -12,6 +12,7 @@
<ItemGroup>
<ClCompile Include="..\base\status.cpp" />
<ClCompile Include="..\base\version.generated.cc" />
<ClCompile Include="..\physics\protector.cpp" />
<ClCompile Include="ksp_physics_lib.cpp" />
</ItemGroup>
</Project>
3 changes: 3 additions & 0 deletions ksp_physics/ksp_physics.vcxproj.filters
Original file line number Diff line number Diff line change
@@ -20,6 +20,9 @@
<ClCompile Include="..\base\version.generated.cc">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\physics\protector.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="ksp_physics_lib.hpp">
2 changes: 1 addition & 1 deletion ksp_plugin/plugin.cpp
Original file line number Diff line number Diff line change
@@ -784,7 +784,7 @@ void Plugin::WaitForVesselToCatchUp(PileUpFuture& pile_up_future,
void Plugin::ForgetAllHistoriesBefore(Instant const& t) const {
CHECK(!initializing_);
CHECK_LT(t, current_time_);
ephemeris_->ForgetBefore(t);
ephemeris_->EventuallyForgetBefore(t);
for (auto const& pair : vessels_) {
not_null<std::unique_ptr<Vessel>> const& vessel = pair.second;
vessel->ForgetBefore(t);
9 changes: 6 additions & 3 deletions ksp_plugin_test/plugin_test.cpp
Original file line number Diff line number Diff line change
@@ -760,7 +760,9 @@ TEST_F(PluginTest, ForgetAllHistoriesBeforeWithFlightPlan) {
.WillRepeatedly(ReturnRef(
SymmetricLinearMultistepIntegrator<QuinlanTremaine1990Order12,
Position<Barycentric>>()));
EXPECT_CALL(plugin_->mock_ephemeris(), ForgetBefore(_)).Times(2);
EXPECT_CALL(plugin_->mock_ephemeris(), EventuallyForgetBefore(_))
.Times(2)
.WillRepeatedly(Return(true));
EXPECT_CALL(*mock_dynamic_frame, ToThisFrameAtTime(_))
.WillRepeatedly(Return(
RigidMotion<Barycentric, Navigation>(
@@ -886,8 +888,9 @@ TEST_F(PluginTest, ForgetAllHistoriesBeforeAfterPredictionFork) {

Instant const initial_time = ParseTT(initial_time_);
Instant const& time = initial_time + 1 * Second;
EXPECT_CALL(plugin_->mock_ephemeris(), ForgetBefore(HistoryTime(time, 5)))
.Times(1);
EXPECT_CALL(plugin_->mock_ephemeris(),
EventuallyForgetBefore(HistoryTime(time, 5)))
.WillOnce(Return(true));
plugin_->AdvanceTime(time, Angle());
VesselSet collided_vessels;
plugin_->CatchUpLaggingVessels(collided_vessels);
1 change: 1 addition & 0 deletions mathematica/mathematica.vcxproj
Original file line number Diff line number Diff line change
@@ -10,6 +10,7 @@
<ClCompile Include="..\base\bundle.cpp" />
<ClCompile Include="..\base\status.cpp" />
<ClCompile Include="..\numerics\cbrt.cpp" />
<ClCompile Include="..\physics\protector.cpp" />
<ClCompile Include="integrator_plots.cpp" />
<ClCompile Include="local_error_analysis.cpp" />
<ClCompile Include="retrobop_dynamical_stability.cpp" />
3 changes: 3 additions & 0 deletions mathematica/mathematica.vcxproj.filters
Original file line number Diff line number Diff line change
@@ -35,6 +35,9 @@
<ClCompile Include="..\numerics\cbrt.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\physics\protector.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="mathematica.hpp">
8 changes: 4 additions & 4 deletions mathematica/retrobop_dynamical_stability.cpp
Original file line number Diff line number Diff line change
@@ -473,21 +473,21 @@ void AnalyseGlobalError() {
if (reference_ephemeris != nullptr) {
bundle.Add([&reference_ephemeris = *reference_ephemeris, t]() {
reference_ephemeris.Prolong(t);
reference_ephemeris.ForgetBefore(t);
reference_ephemeris.EventuallyForgetBefore(t);
return Status::OK;
});
}
if (refined_ephemeris != nullptr) {
bundle.Add([&refined_ephemeris = *refined_ephemeris, t]() {
refined_ephemeris.Prolong(t);
refined_ephemeris.ForgetBefore(t);
refined_ephemeris.EventuallyForgetBefore(t);
return Status::OK;
});
}
for (auto const& ephemeris : perturbed_ephemerides) {
bundle.Add([ephemeris = ephemeris.get(), t]() {
ephemeris->Prolong(t);
ephemeris->ForgetBefore(t);
ephemeris->EventuallyForgetBefore(t);
return Status::OK;
});
}
@@ -593,7 +593,7 @@ void StatisticallyAnalyseStability() {
Position<Barycentric>>(),
step / 2));
ephemeris->Prolong(t);
ephemeris->ForgetBefore(t);
ephemeris->EventuallyForgetBefore(t);
refined.Prolong(t);
Length numerical_error;
Celestial most_erroneous_moon;
1 change: 0 additions & 1 deletion physics/continuous_trajectory.hpp
Original file line number Diff line number Diff line change
@@ -89,7 +89,6 @@ class ContinuousTrajectory : public Trajectory<Frame> {

// End of the implementation of the interface.

// Serializes the current state of this object.
void WriteToMessage(not_null<serialization::ContinuousTrajectory*> message)
const EXCLUDES(lock_);
static not_null<std::unique_ptr<ContinuousTrajectory>> ReadFromMessage(
54 changes: 39 additions & 15 deletions physics/ephemeris.hpp
Original file line number Diff line number Diff line change
@@ -22,6 +22,7 @@
#include "physics/geopotential.hpp"
#include "physics/massive_body.hpp"
#include "physics/oblate_body.hpp"
#include "physics/protector.hpp"
#include "serialization/ksp_plugin.pb.h"
#include "serialization/numerics.pb.h"
#include "serialization/physics.pb.h"
@@ -39,8 +40,8 @@ using geometry::Vector;
using integrators::AdaptiveStepSizeIntegrator;
using integrators::ExplicitSecondOrderOrdinaryDifferentialEquation;
using integrators::FixedStepSizeIntegrator;
using integrators::Integrator;
using integrators::IntegrationProblem;
using integrators::Integrator;
using integrators::SpecialSecondOrderDifferentialEquation;
using quantities::Acceleration;
using quantities::Length;
@@ -61,11 +62,10 @@ class Ephemeris {
// The |length_| and |speed_integration_tolerance|s are used to compute the
// |tolerance_to_error_ratio| for step size control. The number of steps is
// limited to |max_steps|.
ODEAdaptiveStepParameters(
AdaptiveStepSizeIntegrator<ODE> const& integrator,
std::int64_t max_steps,
Length const& length_integration_tolerance,
Speed const& speed_integration_tolerance);
ODEAdaptiveStepParameters(AdaptiveStepSizeIntegrator<ODE> const& integrator,
std::int64_t max_steps,
Length const& length_integration_tolerance,
Speed const& speed_integration_tolerance);

AdaptiveStepSizeIntegrator<ODE> const& integrator() const;
std::int64_t max_steps() const;
@@ -185,13 +185,11 @@ class Ephemeris {

virtual Status last_severe_integration_status() const;

// Calls |ForgetBefore| on all trajectories. On return |t_min() == t|. This
// function is thread-hostile in the sense that it can cause |t_min()| to
// increase, so if it is called is parallel with code that iterates over the
// trajectories of the ephemeris, it can cause trouble.
// TODO(phl): Consider eliminating this function and truncating on
// serialization/deserialization.
virtual void ForgetBefore(Instant const& t) EXCLUDES(lock_);
// If the time |t| is not protected by a |Guard|, calls |ForgetBefore| on all
// trajectories and returns true, after which |t_min() == t|. If the time |t|
// is protected by a |Guard|, returns false; the actual action is delayed
// until the destruction of the |Guard|.
virtual bool EventuallyForgetBefore(Instant const& t) EXCLUDES(lock_);

// Prolongs the ephemeris up to at least |t|. After the call, |t_max() >= t|.
virtual void Prolong(Instant const& t) EXCLUDES(lock_);
@@ -286,6 +284,24 @@ class Ephemeris {
static not_null<std::unique_ptr<Ephemeris>> ReadFromMessage(
serialization::Ephemeris const& message) EXCLUDES(lock_);

// A |Guard| is an RAII object that protects a critical section against
// changes to |t_min| due to calls to |EventuallyForgetBefore|.
class Guard final {
public:
explicit Guard(not_null<Ephemeris<Frame> const*> ephemeris);
~Guard();

// Move only.
Guard(Guard&&) = default;
Guard& operator=(Guard&&) = default;
Guard(Guard const&) = delete;
Guard& operator=(Guard const&) = delete;

private:
not_null<Ephemeris<Frame> const*> const ephemeris_;
Instant t_min_;
};

protected:
// For mocking purposes, leaves everything uninitialized and uses the given
// |integrator|.
@@ -311,6 +327,8 @@ class Ephemeris {
// |instance_| is being integrated.
Instant instance_time() const EXCLUDES(lock_);

Instant t_min_locked() const REQUIRES_SHARED(lock_);

// Computes the accelerations between one body, |body1| (with index |b1| in
// the |positions| and |accelerations| arrays) and the bodies |bodies2| (with
// indices [b2_begin, b2_end[ in the |bodies2|, |positions| and
@@ -407,14 +425,20 @@ class Ephemeris {

not_null<
std::unique_ptr<Checkpointer<serialization::Ephemeris>>> checkpointer_;
not_null<std::unique_ptr<Protector>> protector_;

// The fields above this line are fixed at construction and therefore not
// protected. Note that |ContinuousTrajectory| is thread-safe.
// protected. Note that |ContinuousTrajectory| is thread-safe. |lock_| is
// also used to protect sections where the trajectories are not mutually
// consistent (e.g., during ForgetBefore, Prolong, etc.).
mutable absl::Mutex lock_;

std::unique_ptr<typename Integrator<NewtonianMotionEquation>::Instance>
instance_ GUARDED_BY(lock_);

Status last_severe_integration_status_;
Status last_severe_integration_status_ GUARDED_BY(lock_);

friend class Guard;
};

} // namespace internal_ephemeris
Loading