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

Commits on Aug 22, 2021

  1. Reorder.

    pleroy committed Aug 22, 2021
    Copy the full SHA
    fe847f4 View commit details
  2. ReanimateOneCheckpoint.

    pleroy committed Aug 22, 2021
    Copy the full SHA
    d740d87 View commit details
  3. Fix compilation errors.

    pleroy committed Aug 22, 2021
    Copy the full SHA
    2e162be View commit details

Commits on Aug 23, 2021

  1. Merge pull request #3112 from pleroy/ReanimateOne

    Add a function to reanimate one checkpoint
    pleroy authored Aug 23, 2021
    Copy the full SHA
    be5beb5 View commit details
Showing with 86 additions and 30 deletions.
  1. +5 −0 ksp_plugin/pile_up.cpp
  2. +2 −0 ksp_plugin/pile_up.hpp
  3. +58 −18 ksp_plugin/vessel.cpp
  4. +10 −7 ksp_plugin/vessel.hpp
  5. +8 −4 ksp_plugin_test/vessel_test.cpp
  6. +3 −1 serialization/ksp_plugin.proto
5 changes: 5 additions & 0 deletions ksp_plugin/pile_up.cpp
Original file line number Diff line number Diff line change
@@ -113,6 +113,11 @@ std::list<not_null<Part*>> const& PileUp::parts() const {
return parts_;
}

Ephemeris<Barycentric>::FixedStepParameters const&
PileUp::fixed_step_parameters() const {
return fixed_step_parameters_;
}

void PileUp::SetPartApparentRigidMotion(
not_null<Part*> const part,
RigidMotion<RigidPart, Apparent> const& rigid_motion) {
2 changes: 2 additions & 0 deletions ksp_plugin/pile_up.hpp
Original file line number Diff line number Diff line change
@@ -106,6 +106,8 @@ class PileUp {
PileUp& operator=(PileUp&& pile_up) = default;

std::list<not_null<Part*>> const& parts() const;
Ephemeris<Barycentric>::FixedStepParameters const& fixed_step_parameters()
const;

// Set the rigid motion for the given |part|. This rigid motion is *apparent*
// in the sense that it was reported by the game but we know better since we
76 changes: 58 additions & 18 deletions ksp_plugin/vessel.cpp
Original file line number Diff line number Diff line change
@@ -581,21 +581,46 @@ void Vessel::FillContainingPileUpsFromMessage(
}
}

void Vessel::MakeAsynchronous() {
synchronous_ = false;
}

void Vessel::MakeSynchronous() {
synchronous_ = true;
}

Vessel::Vessel()
: body_(),
prediction_adaptive_step_parameters_(DefaultPredictionParameters()),
parent_(testing_utilities::make_not_null<Celestial const*>()),
ephemeris_(testing_utilities::make_not_null<Ephemeris<Barycentric>*>()),
checkpointer_(make_not_null_unique<Checkpointer<serialization::Vessel>>(
/*reader=*/nullptr,
/*writer=*/nullptr)),
history_(make_not_null_unique<DiscreteTrajectory<Barycentric>>()),
prognosticator_(nullptr, 20ms) {}

Checkpointer<serialization::Vessel>::Writer Vessel::MakeCheckpointerWriter() {
return [this](not_null<serialization::Vessel::Checkpoint*> const message) {
if (backstory_ == history_.get()) {
history_->WriteToMessage(message->mutable_segment(),
history_->WriteToMessage(message->mutable_non_collapsible_segment(),
/*excluded=*/{psychohistory_},
/*tracked=*/{},
/*exact=*/{psychohistory_->Fork()});
} else {
auto backstory = backstory_->DetachFork();
backstory->WriteToMessage(message->mutable_segment(),
backstory->WriteToMessage(message->mutable_non_collapsible_segment(),
/*excluded=*/{psychohistory_},
/*tracked=*/{},
/*exact=*/{psychohistory_->Fork()});
history_->AttachFork(std::move(backstory));
}

// Here the containing pile-up is the one for the collapsible segment.
ForSomePart([message](Part& first_part) {
first_part.containing_pile_up()->fixed_step_parameters().WriteToMessage(
message->mutable_collapsible_fixed_step_parameters());
});
};
}

@@ -605,25 +630,40 @@ Checkpointer<serialization::Vessel>::Reader Vessel::MakeCheckpointerReader() {
};
}

void Vessel::MakeAsynchronous() {
synchronous_ = false;
}
absl::Status Vessel::ReanimateOneCheckpoint(
serialization::Vessel::Checkpoint const& message) {
// Restore the non-collapsible segment that was fully saved.
auto non_collapsible_segment =
DiscreteTrajectory<Barycentric>::ReadFromMessage(
message.non_collapsible_segment(),
/*tracked=*/{});
auto const collapsible_fixed_step_parameters =
Ephemeris<Barycentric>::FixedStepParameters::ReadFromMessage(
message.collapsible_fixed_step_parameters());
CHECK(!non_collapsible_segment->Empty());

// Construct a new collapsible segment at the end of the non-collapsible
// segment and integrate it until the start time of the history.
Instant const& t_initial = non_collapsible_segment->back().time;
Instant const& t_final = history_->begin()->time;
auto const collapsible_segment = non_collapsible_segment->NewForkAtLast();
auto fixed_instance =
ephemeris_->NewInstance({collapsible_segment},
Ephemeris<Barycentric>::NoIntrinsicAccelerations,
collapsible_fixed_step_parameters);
auto const status = ephemeris_->FlowWithFixedStep(t_final, *fixed_instance);
RETURN_IF_ERROR(status);

// Attach the existing |history_| at the end of the collapsible segment and
// make the whole enchilada the new |history_|. If integration reached the
// start of the existing |history_|, attaching will drop the duplicated point.
// If not, we'll have very close points near the stich.
non_collapsible_segment->AttachFork(std::move(history_));
history_ = std::move(non_collapsible_segment);

void Vessel::MakeSynchronous() {
synchronous_ = true;
return absl::OkStatus();
}

Vessel::Vessel()
: body_(),
prediction_adaptive_step_parameters_(DefaultPredictionParameters()),
parent_(testing_utilities::make_not_null<Celestial const*>()),
ephemeris_(testing_utilities::make_not_null<Ephemeris<Barycentric>*>()),
checkpointer_(make_not_null_unique<Checkpointer<serialization::Vessel>>(
/*reader=*/nullptr,
/*writer=*/nullptr)),
history_(make_not_null_unique<DiscreteTrajectory<Barycentric>>()),
prognosticator_(nullptr, 20ms) {}

absl::StatusOr<std::unique_ptr<DiscreteTrajectory<Barycentric>>>
Vessel::FlowPrognostication(
PrognosticatorParameters prognosticator_parameters) {
17 changes: 10 additions & 7 deletions ksp_plugin/vessel.hpp
Original file line number Diff line number Diff line change
@@ -215,13 +215,6 @@ class Vessel {
PileUp::PileUpForSerializationIndex const&
pile_up_for_serialization_index);

// Return functions that can be passed to a |Checkpointer| to write this
// vessel to a checkpoint or read it back.
Checkpointer<serialization::Vessel>::Writer
MakeCheckpointerWriter();
Checkpointer<serialization::Vessel>::Reader
MakeCheckpointerReader();

static void MakeAsynchronous();
static void MakeSynchronous();

@@ -241,6 +234,16 @@ class Vessel {
using TrajectoryIterator =
DiscreteTrajectory<Barycentric>::Iterator (Part::*)();

// Return functions that can be passed to a |Checkpointer| to write this
// vessel to a checkpoint or read it back.
Checkpointer<serialization::Vessel>::Writer
MakeCheckpointerWriter();
Checkpointer<serialization::Vessel>::Reader
MakeCheckpointerReader();

absl::Status ReanimateOneCheckpoint(
serialization::Vessel::Checkpoint const& message);

// Runs the integrator to compute the |prognostication_| based on the given
// parameters.
absl::StatusOr<std::unique_ptr<DiscreteTrajectory<Barycentric>>>
12 changes: 8 additions & 4 deletions ksp_plugin_test/vessel_test.cpp
Original file line number Diff line number Diff line change
@@ -612,11 +612,15 @@ TEST_F(VesselTest, Checkpointing) {
WriteCheckpointToMessage(&message);
CHECK_EQ(2, message.checkpoint_size());
CHECK_EQ(0, message.checkpoint(0).time().scalar().magnitude());
CHECK_EQ(0, message.checkpoint(0).segment().children_size());
CHECK_EQ(1, message.checkpoint(0).segment().zfp().timeline_size());
CHECK_EQ(0, message.checkpoint(0).non_collapsible_segment().children_size());
CHECK_EQ(
1,
message.checkpoint(0).non_collapsible_segment().zfp().timeline_size());
CHECK_EQ(25, message.checkpoint(1).time().scalar().magnitude());
CHECK_EQ(0, message.checkpoint(1).segment().children_size());
CHECK_EQ(16, message.checkpoint(1).segment().zfp().timeline_size());
CHECK_EQ(0, message.checkpoint(1).non_collapsible_segment().children_size());
CHECK_EQ(
16,
message.checkpoint(1).non_collapsible_segment().zfp().timeline_size());
}

TEST_F(VesselTest, SerializationSuccess) {
4 changes: 3 additions & 1 deletion serialization/ksp_plugin.proto
Original file line number Diff line number Diff line change
@@ -163,7 +163,9 @@ message Renderer {
message Vessel {
message Checkpoint {
required Point time = 1;
required DiscreteTrajectory segment = 2;
required DiscreteTrajectory non_collapsible_segment = 2;
required Ephemeris.FixedStepParameters
collapsible_fixed_step_parameters = 3;
}
required string guid = 13;
required string name = 19;