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

Commits on May 30, 2020

  1. Copy the full SHA
    e645874 View commit details
  2. Copy the full SHA
    48ef0f3 View commit details
  3. Cleanup.

    pleroy committed May 30, 2020
    Copy the full SHA
    fd56c41 View commit details
  4. Lint.

    pleroy committed May 30, 2020
    Copy the full SHA
    fb8f8f9 View commit details
  5. Merge pull request #2596 from pleroy/2593

    A better syntax for the selectors of RigidMotion and AcceleratedRigidMotion
    pleroy authored May 30, 2020
    Copy the full SHA
    043a626 View commit details
2 changes: 1 addition & 1 deletion geometry/frame.hpp
Original file line number Diff line number Diff line change
@@ -37,7 +37,7 @@ enum class Handedness {
// or:
// using MyFrame = Frame<enum class MyFrameTag, Inertial>;
//
// By default, the frame is non-inertial and right-handed.
// By default, the frame is arbitrary and right-handed.
//
// A non-serializable frame misses the ReadFromMessage method but has a
// WriteToMessage method which fails at execution. The reason is that
1 change: 0 additions & 1 deletion geometry/named_quantities.hpp
Original file line number Diff line number Diff line change
@@ -13,7 +13,6 @@
namespace principia {
namespace geometry {


// A trait to treat types that have a norm uniformly (using Abs for quantities
// or double, and Norm for multivectors).
template<typename T,
2 changes: 1 addition & 1 deletion ksp_plugin/interface_part.cpp
Original file line number Diff line number Diff line change
@@ -92,7 +92,7 @@ QPRW __cdecl principia__PartGetActualRigidMotion(
Rotation<RigidPart, World> const part_orientation =
part_motion.orthogonal_map().AsRotation();
AngularVelocity<World> const part_angular_velocity =
part_motion.Inverse().angular_velocity_of_to_frame();
part_motion.angular_velocity_of<RigidPart>();
return m.Return(
{ToQP(part_dof),
ToWXYZ(part_orientation.quaternion()),
5 changes: 3 additions & 2 deletions ksp_plugin/pile_up.cpp
Original file line number Diff line number Diff line change
@@ -158,7 +158,7 @@ void PileUp::RecomputeFromParts() {
Identity<Barycentric, NonRotatingPileUp>()(part->intrinsic_torque());

AngularVelocity<NonRotatingPileUp> const part_angular_velocity =
part_motion.Inverse().angular_velocity_of_to_frame();
part_motion.angular_velocity_of<RigidPart>();
InertiaTensor<NonRotatingPileUp> part_inertia_tensor =
part_motion.orthogonal_map()(part->inertia_tensor());
if (part->is_solid_rocket_motor()) {
@@ -469,7 +469,8 @@ void PileUp::DeformPileUpIfNeeded(Instant const& t) {
apparent_pile_up_motion.Inverse() *
apparent_system.LinearMotion().Inverse() * apparent_part_motion;
auto const part_proper_ω =
part_motion_in_principal_axes.angular_velocity_of_to_frame().Norm();
part_motion_in_principal_axes.angular_velocity_of<PileUpPrincipalAxes>()
.Norm();
if (part_proper_ω < reference_part_proper_ω) {
reference_part_proper_ω = part_proper_ω;
reference_part = part;
2 changes: 1 addition & 1 deletion physics/barycentric_rotating_dynamic_frame_body.hpp
Original file line number Diff line number Diff line change
@@ -154,7 +154,7 @@ BarycentricRotatingDynamicFrame<InertialFrame, ThisFrame>::MotionOfThisFrame(
Vector<Acceleration, InertialFrame> const r̈ =
secondary_acceleration - primary_acceleration;
AngularVelocity<InertialFrame> const& ω =
to_this_frame.angular_velocity_of_to_frame();
to_this_frame.angular_velocity_of<ThisFrame>();
Variation<AngularVelocity<InertialFrame>> const
angular_acceleration_of_to_frame =
(Wedge(r, r̈) * Radian - 2 * ω * InnerProduct(r, ṙ)) / r.Norm²();
2 changes: 1 addition & 1 deletion physics/body_centred_body_direction_dynamic_frame_body.hpp
Original file line number Diff line number Diff line change
@@ -177,7 +177,7 @@ MotionOfThisFrame(Instant const& t) const {
Vector<Acceleration, InertialFrame> const r̈ =
secondary_acceleration - primary_acceleration;
AngularVelocity<InertialFrame> const& ω =
to_this_frame.angular_velocity_of_to_frame();
to_this_frame.angular_velocity_of<ThisFrame>();
Variation<AngularVelocity<InertialFrame>> const
angular_acceleration_of_to_frame =
(Wedge(r, r̈) * Radian - 2 * ω * InnerProduct(r, ṙ)) / r.Norm²();
8 changes: 5 additions & 3 deletions physics/dynamic_frame_body.hpp
Original file line number Diff line number Diff line change
@@ -55,9 +55,10 @@ DynamicFrame<InertialFrame, ThisFrame>::GeometricAcceleration(
// Beware, we want the angular velocity of ThisFrame as seen in the
// InertialFrame, but pushed to ThisFrame. Otherwise the sign is wrong.
AngularVelocity<ThisFrame> const Ω = to_this_frame.orthogonal_map()(
to_this_frame.angular_velocity_of_to_frame());
to_this_frame.angular_velocity_of<ThisFrame>());
Variation<AngularVelocity<ThisFrame>> const dΩ_over_dt =
to_this_frame.orthogonal_map()(motion.angular_acceleration_of_to_frame());
to_this_frame.orthogonal_map()(
motion.angular_acceleration_of<ThisFrame>());
Displacement<ThisFrame> const r =
degrees_of_freedom.position() - ThisFrame::origin;

@@ -67,7 +68,8 @@ DynamicFrame<InertialFrame, ThisFrame>::GeometricAcceleration(
from_this_frame.rigid_transformation()(
degrees_of_freedom.position())));
Vector<Acceleration, ThisFrame> const linear_acceleration =
-to_this_frame.orthogonal_map()(motion.acceleration_of_to_frame_origin());
-to_this_frame.orthogonal_map()(
motion.acceleration_of_origin_of<ThisFrame>());
Vector<Acceleration, ThisFrame> const coriolis_acceleration_at_point =
-2 * Ω * degrees_of_freedom.velocity() / Radian;
Vector<Acceleration, ThisFrame> const centrifugal_acceleration_at_point =
2 changes: 1 addition & 1 deletion physics/mechanical_system.hpp
Original file line number Diff line number Diff line change
@@ -84,7 +84,7 @@ class MechanicalSystem {
// ⎛ ∑x² ∑xy ∑xy ⎞
// ⎜ ∑yx ∑y² ∑yz ⎟
// ⎝ ∑zx ∑zy ∑z² ⎠
// whereas the latter (obtained from the former by |Anticommutator()| has the
// whereas the latter (obtained from the former by |Anticommutator()|) has the
// coordinates
// ⎛ ∑(y² + z²) -∑xy -∑xy ⎞
// ⎜ -∑yx ∑(x² + z²) -∑yz ⎟
2 changes: 1 addition & 1 deletion physics/mechanical_system_body.hpp
Original file line number Diff line number Diff line change
@@ -31,7 +31,7 @@ void MechanicalSystem<InertialFrame, SystemFrame>::AddRigidBody(
sum_of_inertia_tensors_ += inertia_tensor_in_inertial_axes;
sum_of_intrinsic_angular_momenta_ +=
Anticommutator(inertia_tensor_in_inertial_axes,
motion.Inverse().angular_velocity_of_to_frame());
motion.angular_velocity_of<BodyFrame>());
}

template<typename InertialFrame, typename SystemFrame>
56 changes: 46 additions & 10 deletions physics/rigid_motion.hpp
Original file line number Diff line number Diff line change
@@ -28,19 +28,43 @@ using geometry::RigidTransformation;
using geometry::Vector;
using geometry::Velocity;
using quantities::Acceleration;
using quantities::AngularAcceleration;
using quantities::Length;
using quantities::Variation;
using quantities::si::Radian;

// A trait to determine if Frame is FromFrame or ToFrame and return the other
// one as the |type| member.
template<typename Frame, typename FromFrame, typename ToFrame>
struct other_frame;

template<typename Frame>
struct other_frame<Frame, Frame, Frame> {
using type = Frame;
};

template<typename FromFrame, typename ToFrame>
struct other_frame<FromFrame, FromFrame, ToFrame> {
using type = ToFrame;
};

template<typename FromFrame, typename ToFrame>
struct other_frame<ToFrame, FromFrame, ToFrame> {
using type = FromFrame;
};

// The instantaneous motion of |ToFrame| with respect to |FromFrame|.
// This is the derivative of a |RigidTransformation<FromFrame, ToFrame>|.
// In order to invert, the |RigidTransformation| is needed, and we need its
// linear part anyway, so we store it (and we forward its action on positions).
template<typename FromFrame, typename ToFrame>
class RigidMotion final {
template<typename T>
using other_frame_t = typename other_frame<T, FromFrame, ToFrame>::type;

public:
RigidMotion(
RigidTransformation<FromFrame, ToFrame> rigid_transformation,
RigidTransformation<FromFrame, ToFrame> const& rigid_transformation,
AngularVelocity<FromFrame> const& angular_velocity_of_to_frame,
Velocity<FromFrame> const& velocity_of_to_frame_origin);

@@ -55,8 +79,11 @@ class RigidMotion final {
RigidTransformation<FromFrame, ToFrame> const& rigid_transformation() const;
// Returns |rigid_transformation().linear_map()|.
OrthogonalMap<FromFrame, ToFrame> const& orthogonal_map() const;
AngularVelocity<FromFrame> const& angular_velocity_of_to_frame() const;
Velocity<FromFrame> const& velocity_of_to_frame_origin() const;

template<typename F>
AngularVelocity<other_frame_t<F>> angular_velocity_of() const;
template<typename F>
Velocity<other_frame_t<F>> velocity_of_origin_of() const;

DegreesOfFreedom<ToFrame> operator()(
DegreesOfFreedom<FromFrame> const& degrees_of_freedom) const;
@@ -93,6 +120,9 @@ class RigidMotion final {
// d/dt rigid_transformation⁻¹(ToFrame::origin).
Velocity<FromFrame> velocity_of_to_frame_origin_;

template<typename, typename>
friend class RigidMotion;

template<typename From, typename Through, typename To>
friend RigidMotion<From, To> operator*(
RigidMotion<Through, To> const& left,
@@ -108,23 +138,29 @@ RigidMotion<FromFrame, ToFrame> operator*(
// second derivative (angular and linear accelerations).
template<typename FromFrame, typename ToFrame>
class AcceleratedRigidMotion final {
template<typename T>
using other_frame_t = typename other_frame<T, FromFrame, ToFrame>::type;

public:
AcceleratedRigidMotion(
RigidMotion<FromFrame, ToFrame> rigid_motion,
Variation<AngularVelocity<FromFrame>> const&
RigidMotion<FromFrame, ToFrame> const& rigid_motion,
Bivector<AngularAcceleration, FromFrame> const&
angular_acceleration_of_to_frame,
Vector<Acceleration, FromFrame> const& acceleration_of_to_frame_origin);

RigidMotion<FromFrame, ToFrame> const& rigid_motion() const;
Variation<AngularVelocity<FromFrame>> const&
angular_acceleration_of_to_frame() const;
Vector<Acceleration, FromFrame> const& acceleration_of_to_frame_origin()
const;

template<typename F>
Bivector<AngularAcceleration, other_frame_t<F>>
angular_acceleration_of() const;
template<typename F>
Vector<Acceleration, other_frame_t<F>> acceleration_of_origin_of() const;

private:
RigidMotion<FromFrame, ToFrame> const rigid_motion_;
// d/dt rigid_motion_.angular_velocity_of_to_frame().
Variation<AngularVelocity<FromFrame>> const angular_acceleration_of_to_frame_;
Bivector<AngularAcceleration, FromFrame> const
angular_acceleration_of_to_frame_;
// d/dt rigid_motion_.velocity_of_to_frame_origin().
Vector<Acceleration, FromFrame> const acceleration_of_to_frame_origin_;
};
89 changes: 66 additions & 23 deletions physics/rigid_motion_body.hpp
Original file line number Diff line number Diff line change
@@ -16,10 +16,10 @@ using geometry::LinearMap;

template<typename FromFrame, typename ToFrame>
RigidMotion<FromFrame, ToFrame>::RigidMotion(
RigidTransformation<FromFrame, ToFrame> rigid_transformation,
RigidTransformation<FromFrame, ToFrame> const& rigid_transformation,
AngularVelocity<FromFrame> const& angular_velocity_of_to_frame,
Velocity<FromFrame> const& velocity_of_to_frame_origin)
: rigid_transformation_(std::move(rigid_transformation)),
: rigid_transformation_(rigid_transformation),
angular_velocity_of_to_frame_(angular_velocity_of_to_frame),
velocity_of_to_frame_origin_(velocity_of_to_frame_origin) {}

@@ -48,15 +48,34 @@ RigidMotion<FromFrame, ToFrame>::orthogonal_map() const {
}

template<typename FromFrame, typename ToFrame>
AngularVelocity<FromFrame> const&
RigidMotion<FromFrame, ToFrame>::angular_velocity_of_to_frame() const {
return angular_velocity_of_to_frame_;
template<typename F>
AngularVelocity<
typename RigidMotion<FromFrame, ToFrame>::template other_frame_t<F>>
RigidMotion<FromFrame, ToFrame>::angular_velocity_of() const {
if constexpr (std::is_same_v<F, ToFrame>) {
return angular_velocity_of_to_frame_;
} else if constexpr (std::is_same_v<F, FromFrame>) {
return Inverse().angular_velocity_of_to_frame_;
} else {
static_assert(std::disjunction_v<std::is_same_v<F, ToFrame>,
std::is_same_v<F, FromFrame>>,
"Nonsensical frame");
}
}

template<typename FromFrame, typename ToFrame>
Velocity<FromFrame> const&
RigidMotion<FromFrame, ToFrame>::velocity_of_to_frame_origin() const {
return velocity_of_to_frame_origin_;
template<typename F>
Velocity<typename RigidMotion<FromFrame, ToFrame>::template other_frame_t<F>>
RigidMotion<FromFrame, ToFrame>::velocity_of_origin_of() const {
if constexpr (std::is_same_v<F, ToFrame>) {
return velocity_of_to_frame_origin_;
} else if constexpr (std::is_same_v<F, FromFrame>) {
return Inverse().velocity_of_to_frame_origin_;
} else {
static_assert(std::disjunction_v<std::is_same_v<F, ToFrame>,
std::is_same_v<F, FromFrame>>,
"Nonsensical frame");
}
}

template<typename FromFrame, typename ToFrame>
@@ -154,8 +173,8 @@ std::ostream& operator<<(std::ostream& out,
RigidMotion<FromFrame, ToFrame> const& rigid_motion) {
return out << "{transformation: " << rigid_motion.rigid_transformation()
<< ", angular velocity: "
<< rigid_motion.angular_velocity_of_to_frame()
<< ", velocity: " << rigid_motion.velocity_of_to_frame_origin()
<< rigid_motion.angular_velocity_of<ToFrame>()
<< ", velocity: " << rigid_motion.velocity_of_origin_of<ToFrame>()
<< "}";
}

@@ -165,19 +184,19 @@ std::ostream& operator<<(std::ostream& out,
accelerated_rigid_motion) {
return out << "{motion: " << accelerated_rigid_motion.rigid_motion()
<< ", angular acceleration: "
<< accelerated_rigid_motion.angular_acceleration_of_to_frame()
<< accelerated_rigid_motion.angular_acceleration_of<ToFrame>()
<< ", acceleration: "
<< accelerated_rigid_motion.acceleration_of_to_frame_origin()
<< accelerated_rigid_motion.acceleration_of_origin_of<ToFrame>()
<< "}";
}

template<typename FromFrame, typename ToFrame>
AcceleratedRigidMotion<FromFrame, ToFrame>::AcceleratedRigidMotion(
RigidMotion<FromFrame, ToFrame> rigid_motion,
Variation<AngularVelocity<FromFrame>> const&
RigidMotion<FromFrame, ToFrame> const& rigid_motion,
Bivector<AngularAcceleration, FromFrame> const&
angular_acceleration_of_to_frame,
Vector<Acceleration, FromFrame> const& acceleration_of_to_frame_origin)
: rigid_motion_(std::move(rigid_motion)),
: rigid_motion_(rigid_motion),
angular_acceleration_of_to_frame_(angular_acceleration_of_to_frame),
acceleration_of_to_frame_origin_(acceleration_of_to_frame_origin) {}

@@ -186,17 +205,41 @@ RigidMotion<FromFrame, ToFrame> const&
AcceleratedRigidMotion<FromFrame, ToFrame>::rigid_motion() const {
return rigid_motion_;
}

template<typename FromFrame, typename ToFrame>
Variation<AngularVelocity<FromFrame>> const&
AcceleratedRigidMotion<FromFrame, ToFrame>::angular_acceleration_of_to_frame()
const {
return angular_acceleration_of_to_frame_;
template<typename F>
Bivector<AngularAcceleration,
typename AcceleratedRigidMotion<FromFrame, ToFrame>::
template other_frame_t<F>>
AcceleratedRigidMotion<FromFrame, ToFrame>::angular_acceleration_of() const {
if constexpr (std::is_same_v<F, ToFrame>) {
return angular_acceleration_of_to_frame_;
} else if constexpr (std::is_same_v<F, FromFrame>) {
static_assert(!std::is_same_v<F, FromFrame>,
"Time to implement AcceleratedRigidMotion::Inverse");
} else {
static_assert(std::disjunction_v<std::is_same_v<F, ToFrame>,
std::is_same_v<F, FromFrame>>,
"Nonsensical frame");
}
}

template<typename FromFrame, typename ToFrame>
Vector<Acceleration, FromFrame> const&
AcceleratedRigidMotion<FromFrame, ToFrame>::acceleration_of_to_frame_origin()
const {
return acceleration_of_to_frame_origin_;
template<typename F>
Vector<Acceleration,
typename AcceleratedRigidMotion<FromFrame, ToFrame>::
template other_frame_t<F>>
AcceleratedRigidMotion<FromFrame, ToFrame>::acceleration_of_origin_of() const {
if constexpr (std::is_same_v<F, ToFrame>) {
return acceleration_of_to_frame_origin_;
} else if constexpr (std::is_same_v<F, FromFrame>) {
static_assert(!std::is_same_v<F, FromFrame>,
"Time to implement AcceleratedRigidMotion::Inverse");
} else {
static_assert(std::disjunction_v<std::is_same_v<F, ToFrame>,
std::is_same_v<F, FromFrame>>,
"Nonsensical frame");
}
}

} // namespace internal_rigid_motion
4 changes: 2 additions & 2 deletions physics/rigid_motion_test.cpp
Original file line number Diff line number Diff line change
@@ -222,13 +222,13 @@ TEST_F(RigidMotionTest, GroupoidInverse) {
}

TEST_F(RigidMotionTest, SecondConstructor) {
auto const terrestrial_to_selenocentric1 =
RigidMotion<Terrestrial, Selenocentric> const terrestrial_to_selenocentric1 =
geocentric_to_selenocentric_ * geocentric_to_terrestrial_.Inverse();
DegreesOfFreedom<Selenocentric> const terrestrial_dof_in_selenocentric =
terrestrial_to_selenocentric1({Terrestrial::origin,
Terrestrial::unmoving});
AngularVelocity<Selenocentric> const terrestrial_rotation_in_selenocentric =
terrestrial_to_selenocentric1.Inverse().angular_velocity_of_to_frame();
terrestrial_to_selenocentric1.angular_velocity_of<Terrestrial>();

RigidMotion<Terrestrial, Selenocentric> const terrestrial_to_selenocentric2(
terrestrial_to_selenocentric1.rigid_transformation(),