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

Commits on Jan 1, 2020

  1. Copy the full SHA
    fd94cf5 View commit details
  2. Copy the full SHA
    445885d View commit details
  3. alphabet

    eggrobin committed Jan 1, 2020
    Copy the full SHA
    18c2caa View commit details
  4. NON_ROTATING_PILE_UP

    eggrobin committed Jan 1, 2020
    Copy the full SHA
    a0e3dd7 View commit details
  5. lint

    eggrobin committed Jan 1, 2020
    Copy the full SHA
    d693ae1 View commit details
  6. Merge pull request #2428 from eggrobin/angular-momentum-accounting

    Rename RigidPileUp to make room for a rotating RigidPileUp
    eggrobin authored Jan 1, 2020
    Copy the full SHA
    bcf0f70 View commit details
Showing with 70 additions and 64 deletions.
  1. +0 −11 ksp_plugin/frames.hpp
  2. +34 −33 ksp_plugin/pile_up.cpp
  3. +21 −5 ksp_plugin/pile_up.hpp
  4. +13 −13 ksp_plugin_test/pile_up_test.cpp
  5. +1 −1 physics/massive_body_body.hpp
  6. +1 −1 serialization/geometry.proto
11 changes: 0 additions & 11 deletions ksp_plugin/frames.hpp
Original file line number Diff line number Diff line change
@@ -129,16 +129,6 @@ using MainBodyCentred = Frame<serialization::Frame::PluginTag,
Handedness::Right,
serialization::Frame::MAIN_BODY_CENTRED>;

// The |PileUp| is seen as a rigid body; the degrees of freedom of the parts in
// the frame of that body can be set, however their motion is not integrated;
// this is simply applied as an offset from the rigid body motion of the
// |PileUp|. The origin of |RigidPileUp| is the centre of mass of the pile up.
// Its axes are those of Barycentric.
using RigidPileUp = Frame<serialization::Frame::PluginTag,
NonInertial,
Handedness::Right,
serialization::Frame::RIGID_PILE_UP>;

// Convenient instances of types from |physics| for the above frames.
using NavigationFrame = DynamicFrame<Barycentric, Navigation>;
using NavigationManœuvre = Manœuvre<Barycentric, Navigation>;
@@ -163,7 +153,6 @@ using internal_frames::Navigation;
using internal_frames::NavigationFrame;
using internal_frames::NavigationManœuvre;
using internal_frames::RigidPart;
using internal_frames::RigidPileUp;
using internal_frames::World;
using internal_frames::WorldSun;
using internal_frames::sun_looking_glass;
67 changes: 34 additions & 33 deletions ksp_plugin/pile_up.cpp
Original file line number Diff line number Diff line change
@@ -58,11 +58,11 @@ PileUp::PileUp(
DegreesOfFreedom<Barycentric> const barycentre = RecomputeFromParts(parts_);
history_->Append(t, barycentre);

RigidMotion<Barycentric, RigidPileUp> const barycentric_to_pile_up{
RigidTransformation<Barycentric, RigidPileUp>{
RigidMotion<Barycentric, NonRotatingPileUp> const barycentric_to_pile_up{
RigidTransformation<Barycentric, NonRotatingPileUp>{
barycentre.position(),
RigidPileUp::origin,
Identity<Barycentric, RigidPileUp>().Forget()},
NonRotatingPileUp::origin,
Identity<Barycentric, NonRotatingPileUp>().Forget()},
Barycentric::nonrotating,
barycentre.velocity()};
for (not_null<Part*> const part : parts_) {
@@ -210,8 +210,8 @@ not_null<std::unique_ptr<PileUp>> PileUp::ReadFromMessage(
serialization::Pair const& degrees_of_freedom = pair.second;
pile_up->actual_part_rigid_motion_.emplace(
part_id_to_part(part_id),
RigidMotion<RigidPart, RigidPileUp>::MakeNonRotatingMotion(
DegreesOfFreedom<RigidPileUp>::ReadFromMessage(
RigidMotion<RigidPart, NonRotatingPileUp>::MakeNonRotatingMotion(
DegreesOfFreedom<NonRotatingPileUp>::ReadFromMessage(
degrees_of_freedom)));
}
for (auto const& pair : message.apparent_part_degrees_of_freedom()) {
@@ -228,8 +228,9 @@ not_null<std::unique_ptr<PileUp>> PileUp::ReadFromMessage(
std::uint32_t const part_id = pair.first;
serialization::RigidMotion const& rigid_motion = pair.second;
pile_up->actual_part_rigid_motion_.emplace(
part_id_to_part(part_id),
RigidMotion<RigidPart, RigidPileUp>::ReadFromMessage(rigid_motion));
part_id_to_part(part_id),
RigidMotion<RigidPart, NonRotatingPileUp>::ReadFromMessage(
rigid_motion));
}
for (auto const& pair : message.apparent_part_rigid_motion()) {
std::uint32_t const part_id = pair.first;
@@ -289,12 +290,12 @@ void PileUp::DeformPileUpIfNeeded() {

// A motion that maps the apparent centre of mass of the parts to the actual
// centre of mass of the pile-up.
RigidTransformation<ApparentBubble, RigidPileUp> const
RigidTransformation<ApparentBubble, NonRotatingPileUp> const
apparent_bubble_to_pile_up_transformation(
apparent_centre_of_mass.position(),
RigidPileUp::origin,
Identity<ApparentBubble, RigidPileUp>().Forget());
RigidMotion<ApparentBubble, RigidPileUp> const
NonRotatingPileUp::origin,
Identity<ApparentBubble, NonRotatingPileUp>().Forget());
RigidMotion<ApparentBubble, NonRotatingPileUp> const
apparent_bubble_to_pile_up_motion(
apparent_bubble_to_pile_up_transformation,
ApparentBubble::nonrotating,
@@ -393,11 +394,11 @@ void PileUp::NudgeParts() const {
auto const actual_centre_of_mass =
psychohistory_->back().degrees_of_freedom;

RigidMotion<Barycentric, RigidPileUp> const barycentric_to_pile_up{
RigidTransformation<Barycentric, RigidPileUp>{
RigidMotion<Barycentric, NonRotatingPileUp> const barycentric_to_pile_up{
RigidTransformation<Barycentric, NonRotatingPileUp>{
actual_centre_of_mass.position(),
RigidPileUp::origin,
Identity<Barycentric, RigidPileUp>().Forget()},
NonRotatingPileUp::origin,
Identity<Barycentric, NonRotatingPileUp>().Forget()},
Barycentric::nonrotating,
actual_centre_of_mass.velocity()};
auto const pile_up_to_barycentric = barycentric_to_pile_up.Inverse();
@@ -411,16 +412,16 @@ void PileUp::NudgeParts() const {
template<PileUp::AppendToPartTrajectory append_to_part_trajectory>
void PileUp::AppendToPart(DiscreteTrajectory<Barycentric>::Iterator it) const {
auto const& pile_up_dof = it->degrees_of_freedom;
RigidMotion<Barycentric, RigidPileUp> const barycentric_to_pile_up(
RigidTransformation<Barycentric, RigidPileUp>(
RigidMotion<Barycentric, NonRotatingPileUp> const barycentric_to_pile_up(
RigidTransformation<Barycentric, NonRotatingPileUp>(
pile_up_dof.position(),
RigidPileUp::origin,
Identity<Barycentric, RigidPileUp>().Forget()),
NonRotatingPileUp::origin,
Identity<Barycentric, NonRotatingPileUp>().Forget()),
Barycentric::nonrotating,
pile_up_dof.velocity());
auto const pile_up_to_barycentric = barycentric_to_pile_up.Inverse();
for (not_null<Part*> const part : parts_) {
DegreesOfFreedom<RigidPileUp> const actual_part_degrees_of_freedom =
DegreesOfFreedom<NonRotatingPileUp> const actual_part_degrees_of_freedom =
FindOrDie(actual_part_rigid_motion_, part)({RigidPart::origin,
RigidPart::unmoving});
(static_cast<Part*>(part)->*append_to_part_trajectory)(
@@ -447,39 +448,39 @@ DegreesOfFreedom<Barycentric> PileUp::RecomputeFromParts(
DegreesOfFreedom<Barycentric> const pile_up_barycentre = calculator.Get();

// Then compute the inertia tensor and the angular momentum of the pile-up.
InertiaTensor<RigidPileUp> pile_up_inertia_tensor;
Bivector<AngularMomentum, RigidPileUp> pile_up_angular_momentum;
RigidMotion<RigidPileUp, Barycentric> const pile_up_to_barycentric(
RigidTransformation<RigidPileUp, Barycentric>(
RigidPileUp::origin,
InertiaTensor<NonRotatingPileUp> pile_up_inertia_tensor;
Bivector<AngularMomentum, NonRotatingPileUp> pile_up_angular_momentum;
RigidMotion<NonRotatingPileUp, Barycentric> const pile_up_to_barycentric(
RigidTransformation<NonRotatingPileUp, Barycentric>(
NonRotatingPileUp::origin,
pile_up_barycentre.position(),
Identity<RigidPileUp, Barycentric>().Forget()),
Identity<NonRotatingPileUp, Barycentric>().Forget()),
Barycentric::nonrotating,
pile_up_barycentre.velocity());
RigidMotion<Barycentric, RigidPileUp> const barycentric_to_pile_up =
RigidMotion<Barycentric, NonRotatingPileUp> const barycentric_to_pile_up =
pile_up_to_barycentric.Inverse();
for (not_null<Part*> const part : parts) {
RigidMotion<RigidPart, Barycentric> const& part_to_barycentric =
part->rigid_motion();
RigidMotion<RigidPart, RigidPileUp> const part_to_pile_up =
RigidMotion<RigidPart, NonRotatingPileUp> const part_to_pile_up =
barycentric_to_pile_up * part_to_barycentric;

// NOTE(phl): The following call reads like the tensor "transforms" the
// rigid motion. Improve this API.
InertiaTensor<RigidPileUp> const& part_inertia_tensor =
InertiaTensor<NonRotatingPileUp> const& part_inertia_tensor =
part->inertia_tensor().Transform(
part_to_pile_up.rigid_transformation());
pile_up_inertia_tensor += part_inertia_tensor;

Bivector<AngularMomentum, RigidPileUp> const part_angular_momentum =
Bivector<AngularMomentum, NonRotatingPileUp> const part_angular_momentum =
Anticommutator(
part_inertia_tensor,
part_to_pile_up.Inverse().angular_velocity_of_to_frame());
DegreesOfFreedom<RigidPileUp> const part_degrees_of_freedom =
DegreesOfFreedom<NonRotatingPileUp> const part_degrees_of_freedom =
part_to_pile_up({RigidPart::origin, RigidPart::unmoving});
pile_up_angular_momentum +=
part_angular_momentum +
Wedge(part_degrees_of_freedom.position() - RigidPileUp::origin,
Wedge(part_degrees_of_freedom.position() - NonRotatingPileUp::origin,
part->inertia_tensor().mass() *
part_degrees_of_freedom.velocity()) *
Radian;
26 changes: 21 additions & 5 deletions ksp_plugin/pile_up.hpp
Original file line number Diff line number Diff line change
@@ -31,6 +31,7 @@ using base::not_null;
using base::Status;
using geometry::Bivector;
using geometry::Frame;
using geometry::Handedness;
using geometry::Instant;
using geometry::NonInertial;
using geometry::Vector;
@@ -46,6 +47,19 @@ using quantities::AngularMomentum;
using quantities::Force;
using quantities::Mass;

// The origin of |NonRotatingPileUp| is the centre of mass of the pile up.
// Its axes are those of |Barycentric|. It is used to describe the rotational
// motion of the pile up (being a nonrotating frame) without running into
// numerical issues from having a faraway origin like that of |Barycentric|.
// This also makes the quantities more conceptually convenient: the angular
// momentum and inertia tensor with respect to the centre of mass are easier to
// reason with than the same quantities with respect to the barycentre of the
// solar system.
using NonRotatingPileUp = Frame<serialization::Frame::PluginTag,
NonInertial,
Handedness::Right,
serialization::Frame::NON_ROTATING_PILE_UP>;

// A |PileUp| handles a connected component of the graph of |Parts| under
// physical contact. It advances the history and psychohistory of its component
// |Parts|, modeling them as a massless body at their centre of mass.
@@ -117,7 +131,7 @@ class PileUp {
not_null<Ephemeris<Barycentric>*> ephemeris,
std::function<void()> deletion_callback);

// Update the degrees of freedom (in |RigidPileUp|) of all the parts by
// Update the degrees of freedom (in |NonRotatingPileUp|) of all the parts by
// translating the *apparent* degrees of freedom so that their centre of mass
// matches that computed by integration.
// |SetPartApparentDegreesOfFreedom| must have been called for each part in
@@ -136,7 +150,7 @@ class PileUp {

// Adjusts the degrees of freedom of all parts in this pile up based on the
// degrees of freedom of the pile-up computed by |AdvanceTime| and on the
// |RigidPileUp| degrees of freedom of the parts, as set by
// |NonRotatingPileUp| degrees of freedom of the parts, as set by
// |DeformPileUpIfNeeded|.
void NudgeParts() const;

@@ -157,8 +171,8 @@ class PileUp {
Ephemeris<Barycentric>::FixedStepParameters fixed_step_parameters_;

// Recomputed by the parts subset on every change. Not serialized.
Bivector<AngularMomentum, RigidPileUp> angular_momentum_;
InertiaTensor<RigidPileUp> inertia_tensor_;
Bivector<AngularMomentum, NonRotatingPileUp> angular_momentum_;
InertiaTensor<NonRotatingPileUp> inertia_tensor_;
Vector<Force, Barycentric> intrinsic_force_;

// The |history_| is the past trajectory of the pile-up. It is normally
@@ -185,7 +199,9 @@ class PileUp {
Ephemeris<Barycentric>::NewtonianMotionEquation>::Instance>
fixed_instance_;

PartTo<RigidMotion<RigidPart, RigidPileUp>> actual_part_rigid_motion_;
// TODO(phl): Use |RigidPileUp|, a reference frame whose axes are the
// principal axes of the pile up.
PartTo<RigidMotion<RigidPart, NonRotatingPileUp>> actual_part_rigid_motion_;
PartTo<RigidMotion<RigidPart, ApparentBubble>> apparent_part_rigid_motion_;

// Called in the destructor.
26 changes: 13 additions & 13 deletions ksp_plugin_test/pile_up_test.cpp
Original file line number Diff line number Diff line change
@@ -95,7 +95,7 @@ class TestablePileUp : public PileUp {
return psychohistory_;
}

PartTo<RigidMotion<RigidPart, RigidPileUp>> const&
PartTo<RigidMotion<RigidPart, NonRotatingPileUp>> const&
actual_part_rigid_motion() const {
return actual_part_rigid_motion_;
}
@@ -142,24 +142,24 @@ class PileUpTest : public testing::Test {
EXPECT_THAT(
pile_up.actual_part_rigid_motion().at(&p1_)({RigidPart::origin,
RigidPart::unmoving}),
Componentwise(AlmostEquals(RigidPileUp::origin +
Displacement<RigidPileUp>(
Componentwise(AlmostEquals(NonRotatingPileUp::origin +
Displacement<NonRotatingPileUp>(
{-10.0 / 3.0 * Metre,
-2.0 * Metre,
-2.0 / 3.0 * Metre}), 1),
AlmostEquals(Velocity<RigidPileUp>(
AlmostEquals(Velocity<NonRotatingPileUp>(
{-100.0 / 3.0 * Metre / Second,
-20.0 * Metre / Second,
-20.0 / 3.0 * Metre / Second}), 7)));
EXPECT_THAT(
pile_up.actual_part_rigid_motion().at(&p2_)({RigidPart::origin,
RigidPart::unmoving}),
Componentwise(AlmostEquals(RigidPileUp::origin +
Displacement<RigidPileUp>(
Componentwise(AlmostEquals(NonRotatingPileUp::origin +
Displacement<NonRotatingPileUp>(
{5.0 / 3.0 * Metre,
1.0 * Metre,
1.0 / 3.0 * Metre}), 3),
AlmostEquals(Velocity<RigidPileUp>(
AlmostEquals(Velocity<NonRotatingPileUp>(
{50.0 / 3.0 * Metre / Second,
10.0 * Metre / Second,
10.0 / 3.0 * Metre / Second}), 17)));
@@ -219,24 +219,24 @@ class PileUpTest : public testing::Test {
EXPECT_THAT(
pile_up.actual_part_rigid_motion().at(&p1_)({RigidPart::origin,
RigidPart::unmoving}),
Componentwise(AlmostEquals(RigidPileUp::origin +
Displacement<RigidPileUp>(
Componentwise(AlmostEquals(NonRotatingPileUp::origin +
Displacement<NonRotatingPileUp>(
{-34.0 / 9.0 * Metre,
-2.0 / 3.0 * Metre,
8.0 / 9.0 * Metre}), 1),
AlmostEquals(Velocity<RigidPileUp>(
AlmostEquals(Velocity<NonRotatingPileUp>(
{-340.0 / 9.0 * Metre / Second,
-20.0 / 3.0 * Metre / Second,
80.0 / 9.0 * Metre / Second}), 8)));
EXPECT_THAT(
pile_up.actual_part_rigid_motion().at(&p2_)({RigidPart::origin,
RigidPart::unmoving}),
Componentwise(AlmostEquals(RigidPileUp::origin +
Displacement<RigidPileUp>(
Componentwise(AlmostEquals(NonRotatingPileUp::origin +
Displacement<NonRotatingPileUp>(
{17.0 / 9.0 * Metre,
1.0 / 3.0 * Metre,
-4.0 / 9.0 * Metre}), 0),
AlmostEquals(Velocity<RigidPileUp>(
AlmostEquals(Velocity<NonRotatingPileUp>(
{170.0 / 9.0 * Metre / Second,
10.0 / 3.0 * Metre / Second,
-40.0 / 9.0 * Metre / Second}), 8)));
2 changes: 1 addition & 1 deletion physics/massive_body_body.hpp
Original file line number Diff line number Diff line change
@@ -163,7 +163,7 @@ inline not_null<std::unique_ptr<MassiveBody>> MassiveBody::ReadFromMessage(
ROTATING_BODY_TAG_VALUE_CASE(MAIN_BODY_CENTRED);
ROTATING_BODY_TAG_VALUE_CASE(NAVBALL);
ROTATING_BODY_TAG_VALUE_CASE(NAVIGATION);
ROTATING_BODY_TAG_VALUE_CASE(RIGID_PILE_UP);
ROTATING_BODY_TAG_VALUE_CASE(NON_ROTATING_PILE_UP);
ROTATING_BODY_TAG_VALUE_CASE(WORLD);
ROTATING_BODY_TAG_VALUE_CASE(WORLD_SUN);
}
2 changes: 1 addition & 1 deletion serialization/geometry.proto
Original file line number Diff line number Diff line change
@@ -163,9 +163,9 @@ message Frame {
MAIN_BODY_CENTRED = 15;
NAVBALL = 10;
NAVIGATION = 4;
NON_ROTATING_PILE_UP = 11;
// PRE_BOREL_BARYCENTRIC = 3;
RIGID_PART = 16;
RIGID_PILE_UP = 11;
WORLD = 5;
WORLD_SUN = 6;
}