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

Commits on Mar 29, 2020

  1. Replay.

    pleroy committed Mar 29, 2020
    Copy the full SHA
    7f3603c View commit details

Commits on Mar 30, 2020

  1. Constexpr vs. const.

    pleroy committed Mar 30, 2020
    Copy the full SHA
    2d8740d View commit details
  2. Merge.

    pleroy committed Mar 30, 2020
    Copy the full SHA
    a3a2c44 View commit details
  3. Log messages during replay.

    pleroy committed Mar 30, 2020
    Copy the full SHA
    7b632b4 View commit details

Commits on Mar 31, 2020

  1. Don't insert psychohistory points before the fork time. Also record t…

    …he version in the journal.
    pleroy committed Mar 31, 2020
    Copy the full SHA
    760e9df View commit details
  2. Cleanup.

    pleroy committed Mar 31, 2020
    Copy the full SHA
    f6a01f1 View commit details

Commits on Apr 1, 2020

  1. After egg's review.

    pleroy committed Apr 1, 2020
    Copy the full SHA
    c85d4e1 View commit details
  2. Merge pull request #2516 from pleroy/2507

    Skip the points of the parts's psychohistory that are before the vessel's psychohistory fork
    pleroy authored Apr 1, 2020
    Copy the full SHA
    4098b8a View commit details
Showing with 78 additions and 31 deletions.
  1. +1 −0 journal/journal.vcxproj
  2. +3 −0 journal/journal.vcxproj.filters
  3. +7 −22 journal/player_test.cpp
  4. +16 −1 journal/recorder.cpp
  5. +18 −1 journal/recorder_test.cpp
  6. +3 −2 ksp_plugin/pile_up.cpp
  7. +27 −3 ksp_plugin/vessel.cpp
  8. +2 −1 ksp_plugin/vessel.hpp
  9. +1 −1 physics/discrete_trajectory.hpp
1 change: 1 addition & 0 deletions journal/journal.vcxproj
Original file line number Diff line number Diff line change
@@ -27,6 +27,7 @@
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\base\status.cpp" />
<ClCompile Include="..\base\version.generated.cc" />
<ClCompile Include="..\physics\protector.cpp" />
<ClCompile Include="player.cpp" />
<ClCompile Include="player.generated.cc">
3 changes: 3 additions & 0 deletions journal/journal.vcxproj.filters
Original file line number Diff line number Diff line change
@@ -64,5 +64,8 @@
<ClCompile Include="..\physics\protector.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\base\version.generated.cc">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
</Project>
29 changes: 7 additions & 22 deletions journal/player_test.cpp
Original file line number Diff line number Diff line change
@@ -77,18 +77,19 @@ TEST_F(PlayerTest, PlayTiny) {
while (player.Play(count)) {
++count;
}
EXPECT_EQ(2, count);
EXPECT_EQ(3, count);
}

TEST_F(PlayerTest, DISABLED_SECULAR_Benchmarks) {
benchmark::RunSpecifiedBenchmarks();
}

TEST_F(PlayerTest, DISABLED_SECULAR_Debug) {
google::LogToStderr();
// An example of how journaling may be used for debugging. You must set
// |path| and fill the |method_in| and |method_out_return| protocol buffers.
std::string path =
R"(C:\Program Files\Kerbal Space Program\1.7.2\glog\Principia\JOURNAL.20191015-230004)"; // NOLINT
R"(P:\Public Mockingbird\Principia\Crashes\2507\JOURNAL.20200328-214524)"; // NOLINT
Player player(path);
int count = 0;
while (player.Play(count)) {
@@ -106,33 +107,17 @@ TEST_F(PlayerTest, DISABLED_SECULAR_Debug) {
serialization::Method method_in;
{
auto* extension = method_in.MutableExtension(
serialization::FlightPlanReplace::extension);
serialization::CatchUpLaggingVessels::extension);
auto* in = extension->mutable_in();
in->set_plugin(1204843840);
in->set_vessel_guid("6615e657-7c13-4428-bb17-4d9009b4a458");
auto* const burn = in->mutable_burn();
burn->set_thrust_in_kilonewtons(250.00010393791362);
burn->set_specific_impulse_in_seconds_g0(350);
auto* const frame = burn->mutable_frame();
frame->set_extension(6000);
frame->set_centre_index(1);
frame->set_primary_index(0);
frame->set_secondary_index(0);
burn->set_initial_time(3894.6399999993528);
auto* const delta_v = burn->mutable_delta_v();
delta_v->set_x(0);
delta_v->set_y(0);
delta_v->set_z(0);
burn->set_is_inertially_fixed(true);
in->set_index(0);
in->set_plugin(2014156823824);
}
serialization::Method method_out_return;
{
auto* extension = method_out_return.MutableExtension(
serialization::FlightPlanReplace::extension);
serialization::CatchUpLaggingVessels::extension);
}
LOG(ERROR) << "Running unpaired method:\n" << method_in.DebugString();
CHECK(RunIfAppropriate<FlightPlanReplace>(
CHECK(RunIfAppropriate<CatchUpLaggingVessels>(
method_in, method_out_return, player));
#endif
}
17 changes: 16 additions & 1 deletion journal/recorder.cpp
Original file line number Diff line number Diff line change
@@ -5,8 +5,10 @@

#include "base/array.hpp"
#include "base/hexadecimal.hpp"
#include "glog/logging.h"
#include "base/serialization.hpp"
#include "base/version.hpp"
#include "glog/logging.h"
#include "journal/profiles.hpp"

namespace principia {

@@ -34,6 +36,19 @@ void Recorder::WriteAtDestruction(serialization::Method const& method) {
void Recorder::Activate(base::not_null<Recorder*> const recorder) {
CHECK(active_recorder_ == nullptr);
active_recorder_ = recorder;

// When the recorder gets activated, pretend that we got a GetVersion call.
// This will record the version at the beginning of the journal, which is
// useful for forensics.
serialization::Method method;
not_null<serialization::GetVersion*> const get_version =
method.MutableExtension(serialization::GetVersion::extension);
active_recorder_->WriteAtConstruction(method);
not_null<serialization::GetVersion::Out*> const out =
get_version->mutable_out();
out->set_build_date(base::BuildDate);
out->set_version(base::Version);
active_recorder_->WriteAtDestruction(method);
}

void Recorder::Deactivate() {
19 changes: 18 additions & 1 deletion journal/recorder_test.cpp
Original file line number Diff line number Diff line change
@@ -8,6 +8,7 @@

#include "base/array.hpp"
#include "base/hexadecimal.hpp"
#include "base/version.hpp"
#include "gtest/gtest.h"
#include "journal/method.hpp"
#include "journal/profiles.hpp"
@@ -85,8 +86,24 @@ TEST_F(RecorderTest, Recording) {

std::vector<serialization::Method> const methods =
ReadAll(test_name_ + ".journal.hex");
EXPECT_EQ(4, methods.size());
EXPECT_EQ(6, methods.size());
auto it = methods.begin();
{
EXPECT_TRUE(it->HasExtension(serialization::GetVersion::extension));
auto const& extension =
it->GetExtension(serialization::GetVersion::extension);
EXPECT_FALSE(extension.has_out());
}
++it;
{
EXPECT_TRUE(it->HasExtension(serialization::GetVersion::extension));
auto const& extension =
it->GetExtension(serialization::GetVersion::extension);
EXPECT_TRUE(extension.has_out());
EXPECT_EQ(base::BuildDate, extension.out().build_date());
EXPECT_EQ(base::Version, extension.out().version());
}
++it;
{
EXPECT_TRUE(it->HasExtension(serialization::DeletePlugin::extension));
auto const& extension =
5 changes: 3 additions & 2 deletions ksp_plugin/pile_up.cpp
Original file line number Diff line number Diff line change
@@ -533,8 +533,9 @@ Status PileUp::AdvanceTime(Instant const& t) {

CHECK_NOTNULL(psychohistory_);

// Append the |history_| authoritatively to the parts' tails and the
// |psychohistory_| non-authoritatively.
// Append the |history_| to the parts' history and the |psychohistory_| to the
// parts' psychohistory. Drop the history of the pile-up, we won't need it
// anymore.
auto const history_end = history_->end();
auto const psychohistory_end = psychohistory_->end();
auto it = history_last;
30 changes: 27 additions & 3 deletions ksp_plugin/vessel.cpp
Original file line number Diff line number Diff line change
@@ -241,6 +241,20 @@ void Vessel::AdvanceTime() {
&Part::history_end,
*history_);
psychohistory_ = history_->NewForkAtLast();

// The reason why we may want to skip the start of the psychohistory is
// subtle. Say that we have a vessel A with points at t₀, t₀ + 10 s,
// t₀ + 20 s in its history. Say that a vessel B is created at t₀ + 23 s,
// maybe because of an undocking or a staging, and (some) of the parts of A
// are transfered to B. Now time moves a bit and at t₀ = 24 s we want to
// attach the psychohistory of these parts (their centre of mass, really) to
// vessel B. Most of the time the psychohistory will have a *single* point at
// t₀ + 24 s and everything will be fine. However, because the psychohistory
// is integrated using an adaptive step, it is possible that it would have
// multiple points, say one at t₀ + 21 s and one at t₀ + 24 s. In this case
// trying to insert the point at t₀ + 21 s would put us before the last point
// of the history of B and would fail a check. Therefore, we just ignore that
// point. See #2507.
AppendToVesselTrajectory(&Part::psychohistory_begin,
&Part::psychohistory_end,
*psychohistory_);
@@ -588,12 +602,20 @@ void Vessel::AppendToVesselTrajectory(
ends.push_back((*part.*part_trajectory_end)());
}

Instant fork_time;
if (!trajectory.is_root()) {
fork_time = trajectory.Fork()->time;
}

// Loop over the times of the trajectory.
for (;;) {
auto const& it0 = its[0];
bool const at_end_of_part_trajectory = it0 == ends[0];
Instant const first_time = at_end_of_part_trajectory ? Instant()
: it0->time;
bool const after_fork_time = !at_end_of_part_trajectory &&
(trajectory.is_root() ||
first_time > fork_time);

// Loop over the parts at a given time.
BarycentreCalculator<DegreesOfFreedom<Barycentric>, Mass> calculator;
@@ -614,9 +636,11 @@ void Vessel::AppendToVesselTrajectory(
}

// Append the parts' barycentre to the trajectory.
DegreesOfFreedom<Barycentric> const vessel_degrees_of_freedom =
calculator.Get();
trajectory.Append(first_time, vessel_degrees_of_freedom);
if (after_fork_time) {
DegreesOfFreedom<Barycentric> const vessel_degrees_of_freedom =
calculator.Get();
trajectory.Append(first_time, vessel_degrees_of_freedom);
}
}
}

3 changes: 2 additions & 1 deletion ksp_plugin/vessel.hpp
Original file line number Diff line number Diff line change
@@ -223,7 +223,8 @@ class Vessel {
Status const& status);

// Appends to |trajectory| the centre of mass of the trajectories of the parts
// denoted by |part_trajectory_begin| and |part_trajectory_end|.
// denoted by |part_trajectory_begin| and |part_trajectory_end|. Only the
// points that are strictly after the fork time of the trajectory are used.
void AppendToVesselTrajectory(TrajectoryIterator part_trajectory_begin,
TrajectoryIterator part_trajectory_end,
DiscreteTrajectory<Barycentric>& trajectory);
2 changes: 1 addition & 1 deletion physics/discrete_trajectory.hpp
Original file line number Diff line number Diff line change
@@ -65,10 +65,10 @@ using geometry::Instant;
using geometry::Position;
using geometry::Vector;
using geometry::Velocity;
using internal_forkable::DiscreteTrajectoryIterator;
using quantities::Acceleration;
using quantities::Length;
using quantities::Speed;
using internal_forkable::DiscreteTrajectoryIterator;
using numerics::Hermite3;

template<typename Frame>