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

Commits on Oct 28, 2021

  1. Part compiles.

    pleroy committed Oct 28, 2021
    Copy the full SHA
    734134c View commit details
  2. Copy the full SHA
    b97ffeb View commit details

Commits on Oct 29, 2021

  1. Part and PileUp tests passing.

    pleroy committed Oct 29, 2021
    Copy the full SHA
    e098baa View commit details
  2. Copy the full SHA
    4b3a07a View commit details
  3. Copy the full SHA
    8d0541e View commit details

Commits on Oct 30, 2021

  1. Copy the full SHA
    5b41ed4 View commit details
  2. Copy the full SHA
    f264b7c View commit details
  3. After egg's review.

    pleroy committed Oct 30, 2021
    Copy the full SHA
    99c2a6c View commit details
  4. Merge pull request #3180 from pleroy/Part

    Convert Part and its test to DiscreteTraject0ry
    pleroy authored Oct 30, 2021

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    c103882 View commit details
Showing with 72 additions and 75 deletions.
  1. +46 −47 ksp_plugin/part.cpp
  2. +18 −16 ksp_plugin/part.hpp
  3. +6 −6 ksp_plugin/pile_up.cpp
  4. +2 −6 ksp_plugin_test/part_test.cpp
93 changes: 46 additions & 47 deletions ksp_plugin/part.cpp
Original file line number Diff line number Diff line change
@@ -161,56 +161,51 @@ RigidMotion<RigidPart, Barycentric> const& Part::rigid_motion() const {
return rigid_motion_;
}

DiscreteTrajectory<Barycentric>::Iterator Part::history_begin() {
// Make sure that we skip the point of the prehistory.
auto it = history_->Fork();
return ++it;
DiscreteTraject0ry<Barycentric>::iterator Part::history_begin() {
return history_->begin();
}

DiscreteTrajectory<Barycentric>::Iterator Part::history_end() {
DiscreteTraject0ry<Barycentric>::iterator Part::history_end() {
return history_->end();
}

DiscreteTrajectory<Barycentric>::Iterator Part::psychohistory_begin() {
if (psychohistory_ == nullptr) {
psychohistory_ = history_->NewForkAtLast();
DiscreteTraject0ry<Barycentric>::iterator Part::psychohistory_begin() {
if (psychohistory_ == trajectory_.segments().end()) {
psychohistory_ = trajectory_.NewSegment();
}
// TODO(phl): This used to say:
// Make sure that we skip the fork, which may be the point of the prehistory.
auto it = psychohistory_->Fork();
return ++it;
return psychohistory_->begin();
}

DiscreteTrajectory<Barycentric>::Iterator Part::psychohistory_end() {
if (psychohistory_ == nullptr) {
psychohistory_ = history_->NewForkAtLast();
DiscreteTraject0ry<Barycentric>::iterator Part::psychohistory_end() {
if (psychohistory_ == trajectory_.segments().end()) {
psychohistory_ = trajectory_.NewSegment();
}
return psychohistory_->end();
}

void Part::AppendToHistory(
Instant const& time,
DegreesOfFreedom<Barycentric> const& degrees_of_freedom) {
if (psychohistory_ != nullptr) {
history_->DeleteFork(psychohistory_);
if (psychohistory_ != trajectory_.segments().end()) {
trajectory_.DeleteSegments(psychohistory_);
}
history_->Append(time, degrees_of_freedom);
trajectory_.Append(time, degrees_of_freedom);
}

void Part::AppendToPsychohistory(
Instant const& time,
DegreesOfFreedom<Barycentric> const& degrees_of_freedom) {
if (psychohistory_ == nullptr) {
psychohistory_ = history_->NewForkAtLast();
if (psychohistory_ == trajectory_.segments().end()) {
psychohistory_ = trajectory_.NewSegment();
}
psychohistory_->Append(time, degrees_of_freedom);
trajectory_.Append(time, degrees_of_freedom);
}

void Part::ClearHistory() {
if (psychohistory_ != nullptr) {
history_->DeleteFork(psychohistory_);
}
prehistory_->DeleteFork(history_);
history_ = prehistory_->NewForkAtLast();
trajectory_.clear();
psychohistory_ = trajectory_.segments().end();
}

void Part::set_containing_pile_up(
@@ -252,9 +247,9 @@ void Part::WriteToMessage(not_null<serialization::Part*> const message,
serialization_index_for_pile_up(containing_pile_up_.get()));
}
rigid_motion_.WriteToMessage(message->mutable_rigid_motion());
prehistory_->WriteToMessage(message->mutable_prehistory(),
/*forks=*/{history_, psychohistory_},
/*exact=*/{});
trajectory_.WriteToMessage(message->mutable_prehistory(),
/*tracked=*/{history_, psychohistory_},
/*exact=*/{});
}

not_null<std::unique_ptr<Part>> Part::ReadFromMessage(
@@ -267,11 +262,14 @@ not_null<std::unique_ptr<Part>> Part::ReadFromMessage(
is_pre_fréchet || (message.has_pre_frenet_inertia_tensor() &&
!message.has_intrinsic_torque());
bool const is_pre_galileo = !message.has_centre_of_mass();
LOG_IF(WARNING, is_pre_galileo) << "Reading pre-"
<< (is_pre_cesàro ? u8"Cesàro"
: is_pre_fréchet ? u8"Fréchet"
: is_pre_frenet ? "Frenet"
: "Galileo") << " Part";
bool const is_pre_ζήνων = message.prehistory().segment_size() == 0;
LOG_IF(WARNING, is_pre_ζήνων)
<< "Reading pre-"
<< (is_pre_cesàro ? u8"Cesàro"
: is_pre_fréchet ? u8"Fréchet"
: is_pre_frenet ? "Frenet"
: is_pre_galileo ? "Galileo"
: u8"Ζήνων") << " Part";

std::unique_ptr<Part> part;
if (is_pre_fréchet) {
@@ -324,25 +322,29 @@ not_null<std::unique_ptr<Part>> Part::ReadFromMessage(
}

if (is_pre_cesàro) {
auto tail = DiscreteTrajectory<Barycentric>::ReadFromMessage(
auto tail = DiscreteTraject0ry<Barycentric>::ReadFromMessage(
message.prehistory(),
/*forks=*/{});
// The |prehistory_| and |history_| have been created by the constructor
// above. Construct the various trajectories from the |tail|.
for (auto it = tail->begin(); it != tail->end();) {
/*tracked=*/{});
// The |history_| has been created by the constructor above. Construct the
// various trajectories from the |tail|.
for (auto it = tail.begin(); it != tail.end();) {
auto const& [time, degrees_of_freedom] = *it;
++it;
if (it == tail->end() && !message.tail_is_authoritative()) {
if (it == tail.end() && !message.tail_is_authoritative()) {
part->AppendToPsychohistory(time, degrees_of_freedom);
} else {
part->AppendToHistory(time, degrees_of_freedom);
}
}
} else if (is_pre_ζήνων) {
auto prehistory = DiscreteTraject0ry<Barycentric>::ReadFromMessage(
message.prehistory(),
/*tracked=*/{&part->history_, &part->psychohistory_});
part->trajectory_ = prehistory.DetachSegments(part->history_);
} else {
part->history_ = nullptr;
part->prehistory_ = DiscreteTrajectory<Barycentric>::ReadFromMessage(
part->trajectory_ = DiscreteTraject0ry<Barycentric>::ReadFromMessage(
message.prehistory(),
/*forks=*/{&part->history_, &part->psychohistory_});
/*tracked=*/{&part->history_, &part->psychohistory_});
}
return std::move(part);
}
@@ -378,13 +380,10 @@ Part::Part(PartId const part_id,
mass_(mass),
inertia_tensor_(inertia_tensor),
rigid_motion_(std::move(rigid_motion)),
prehistory_(make_not_null_unique<DiscreteTrajectory<Barycentric>>()),
history_(trajectory_.segments().begin()),
psychohistory_(trajectory_.segments().end()),
subset_node_(make_not_null_unique<Subset<Part>::Node>()),
deletion_callback_(std::move(deletion_callback)) {
prehistory_->Append(astronomy::InfinitePast,
{Barycentric::origin, Barycentric::unmoving});
history_ = prehistory_->NewForkAtLast();
}
deletion_callback_(std::move(deletion_callback)) {}

RigidMotion<RigidPart, EccentricPart> Part::MakeRigidToEccentricMotion(
Position<EccentricPart> const& centre_of_mass) {
34 changes: 18 additions & 16 deletions ksp_plugin/part.hpp
Original file line number Diff line number Diff line change
@@ -15,6 +15,8 @@
#include "geometry/grassmann.hpp"
#include "geometry/named_quantities.hpp"
#include "physics/degrees_of_freedom.hpp"
#include "physics/discrete_traject0ry.hpp"
#include "physics/discrete_trajectory_segment_iterator.hpp"
#include "physics/rigid_motion.hpp"
#include "quantities/named_quantities.hpp"
#include "quantities/quantities.hpp"
@@ -34,7 +36,8 @@ using geometry::Position;
using geometry::Vector;
using geometry::Velocity;
using physics::DegreesOfFreedom;
using physics::DiscreteTrajectory;
using physics::DiscreteTraject0ry;
using physics::DiscreteTrajectorySegmentIterator;
using physics::RigidMotion;
using quantities::Force;
using quantities::Mass;
@@ -113,10 +116,10 @@ class Part final {
// Return iterators to the beginning and end of the history and psychohistory
// of the part, respectively. Either trajectory may be empty, but they are
// not both empty.
DiscreteTrajectory<Barycentric>::Iterator history_begin();
DiscreteTrajectory<Barycentric>::Iterator history_end();
DiscreteTrajectory<Barycentric>::Iterator psychohistory_begin();
DiscreteTrajectory<Barycentric>::Iterator psychohistory_end();
DiscreteTraject0ry<Barycentric>::iterator history_begin();
DiscreteTraject0ry<Barycentric>::iterator history_end();
DiscreteTraject0ry<Barycentric>::iterator psychohistory_begin();
DiscreteTraject0ry<Barycentric>::iterator psychohistory_end();

// Appends a point to the history or psychohistory of this part. These
// temporarily hold the trajectory of the part and are constructed by
@@ -195,18 +198,17 @@ class Part final {

// See the comments in pile_up.hpp for an explanation of the terminology.

// The |prehistory_| always has a single point at time -∞. It sole purpose is
// to make it convenient to hook the |psychohistory_| even if there is no
// point in the |history_| (it's not possible to fork-at-last an empty root
// trajectory, but it works for a non-root).
not_null<std::unique_ptr<DiscreteTrajectory<Barycentric>>> prehistory_;
// The |history_| is nearly always not null, except in some transient
// situations. It's a fork of the |prehistory_|.
DiscreteTrajectory<Barycentric>* history_ = nullptr;
// The trajectory of the part, composed of (at most) two segments, the
// history and the psychohistory.
DiscreteTraject0ry<Barycentric> trajectory_;

// The |history_| is nearly always present, except in some transient
// situations.
DiscreteTrajectorySegmentIterator<Barycentric> history_;

// The |psychohistory_| is destroyed by |AppendToHistory| and is recreated
// as needed by |AppendToPsychohistory| or by |tail|. That's because
// |NewForkAtLast| is relatively expensive so we only call it when necessary.
DiscreteTrajectory<Barycentric>* psychohistory_ = nullptr;
// as needed by |AppendToPsychohistory|.
DiscreteTrajectorySegmentIterator<Barycentric> psychohistory_;

// We will use union-find algorithms on |Part|s.
not_null<std::unique_ptr<Subset<Part>::Node>> const subset_node_;
12 changes: 6 additions & 6 deletions ksp_plugin/pile_up.cpp
Original file line number Diff line number Diff line change
@@ -220,13 +220,13 @@ not_null<std::unique_ptr<PileUp>> PileUp::ReadFromMessage(
bool const is_pre_frobenius = message.rigid_pile_up().empty() ||
!message.has_angular_momentum();
bool const is_pre_ζήνων = message.history().segment_size() == 0;
LOG_IF(WARNING, is_pre_frobenius)
LOG_IF(WARNING, is_pre_ζήνων)
<< "Reading pre-"
<< (is_pre_cartan ? "Cartan"
: is_pre_cesàro ? u8"Cesàro"
: is_pre_frege ? "Frege"
: is_pre_ζήνων ? "Frobenius"
: u8"pre-Ζήνων") << " PileUp";
<< (is_pre_cartan ? "Cartan"
: is_pre_cesàro ? u8"Cesàro"
: is_pre_frege ? "Frege"
: is_pre_frobenius ? "Frobenius"
: u8"Ζήνων") << " PileUp";

std::unique_ptr<PileUp> pile_up;
if (is_pre_cesàro) {
8 changes: 2 additions & 6 deletions ksp_plugin_test/part_test.cpp
Original file line number Diff line number Diff line change
@@ -137,12 +137,8 @@ TEST_F(PartTest, Serialization) {
.quantity()
.magnitude(),
AlmostEquals(-5, 2));
EXPECT_EQ(1, message.prehistory().zfp().timeline_size());
EXPECT_EQ(1, message.prehistory().children_size());
EXPECT_EQ(1, message.prehistory().children(0).trajectories_size());
EXPECT_EQ(
1,
message.prehistory().children(0).trajectories(0).zfp().timeline_size());
EXPECT_EQ(1, message.prehistory().segment_size());
EXPECT_EQ(1, message.prehistory().segment(0).zfp().timeline_size());

auto const p = Part::ReadFromMessage(message, /*deletion_callback=*/nullptr);
EXPECT_EQ(part_.inertia_tensor(), p->inertia_tensor());