Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Random improvements and cleanups done while investigating #2519 #2541

Merged
merged 5 commits into from
Apr 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions ksp_plugin/interface_part.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,11 @@ void __cdecl principia__PartApplyIntrinsicTorque(
return m.Return();
}

QPRW __cdecl principia__PartGetActualDegreesOfFreedom(
QPRW __cdecl principia__PartGetActualRigidMotion(
Plugin const* const plugin,
PartId const part_id,
Origin const origin) {
journal::Method<journal::PartGetActualDegreesOfFreedom> m(
journal::Method<journal::PartGetActualRigidMotion> m(
{plugin, part_id, origin});
CHECK_NOTNULL(plugin);
RigidMotion<RigidPart, World> const part_motion = plugin->GetPartActualMotion(
Expand Down
1 change: 1 addition & 0 deletions ksp_plugin/pile_up.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ Status PileUp::DeformAndAdvanceTime(Instant const& t) {
}

void PileUp::RecomputeFromParts() {
absl::MutexLock l(lock_.get());
mass_ = Mass();
intrinsic_force_ = Vector<Force, Barycentric>();
intrinsic_torque_ = Bivector<Torque, NonRotatingPileUp>();
Expand Down
4 changes: 2 additions & 2 deletions ksp_plugin/plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -461,8 +461,8 @@ void Plugin::InsertOrKeepLoadedPart(
main_body_frame.ToThisFrameAtTime(previous_time).orthogonal_map() *
Δplanetarium_rotation.Inverse() *
renderer_->WorldToBarycentric(PlanetariumRotation())},
(renderer_->BarycentricToWorld(PlanetariumRotation()) *
Δplanetarium_rotation)(-angular_velocity_of_world_),
(renderer_->BarycentricToWorld(PlanetariumRotation()) *
Δplanetarium_rotation)(-angular_velocity_of_world_),
main_body_degrees_of_freedom.velocity()};
RigidMotion<World, Barycentric> const world_to_barycentric_motion =
main_body_frame.FromThisFrameAtTime(previous_time) *
Expand Down
10 changes: 5 additions & 5 deletions ksp_plugin_adapter/ksp_plugin_adapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ private void UpdateVessel(Vessel vessel, double universal_time) {
// TODO(egg): check that the vessel is moved *after* this. Shouldn't
// we be calling vessel.orbitDriver.updateFromParameters() after
// setting the orbit anyway?
QPRW part_actual_motion = plugin_.PartGetActualDegreesOfFreedom(
QPRW part_actual_motion = plugin_.PartGetActualRigidMotion(
part.flightID,
new Origin{
reference_part_is_at_origin = true,
Expand Down Expand Up @@ -1294,7 +1294,7 @@ private System.Collections.IEnumerator WaitedForFixedUpdate() {
}
foreach (Part part in vessel.parts.Where(PartIsFaithful)) {
QPRW part_actual_motion =
plugin_.PartGetActualDegreesOfFreedom(
plugin_.PartGetActualRigidMotion(
part.flightID,
new Origin{
reference_part_is_at_origin =
Expand Down Expand Up @@ -1541,11 +1541,11 @@ private void JaiFailliAttendre() {
physical_parent,
new Part.ForceHolder {
force = -part.dragVectorDir * part.dragScalar,
pos = (physical_parent != part &&
PhysicsGlobals.ApplyDragToNonPhysicsPartsAtParentCoM)
pos = (physical_parent != part && PhysicsGlobals.
ApplyDragToNonPhysicsPartsAtParentCoM)
? physical_parent.rb.worldCenterOfMass
: part.partTransform.TransformPoint(
part.CoPOffset)});
part.CoPOffset)});
}
}
}
Expand Down
8 changes: 8 additions & 0 deletions mathematica/mathematica.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "astronomy/orbital_elements.hpp"
#include "geometry/grassmann.hpp"
#include "geometry/point.hpp"
#include "geometry/quaternion.hpp"
#include "geometry/r3_element.hpp"
#include "numerics/fixed_arrays.hpp"
#include "physics/degrees_of_freedom.hpp"
Expand All @@ -18,7 +19,9 @@ namespace principia {
namespace mathematica {
namespace internal_mathematica {

using geometry::Bivector;
using geometry::Point;
using geometry::Quaternion;
using geometry::R3Element;
using geometry::Vector;
using numerics::FixedVector;
Expand Down Expand Up @@ -55,9 +58,14 @@ std::string ToMathematica(FixedVector<T, size> const& fixed_vector);
template<typename T>
std::string ToMathematica(R3Element<T> const& r3_element);

std::string ToMathematica(Quaternion const& quaternion);

template<typename D>
std::string ToMathematica(Quantity<D> const& quantity);

template<typename S, typename F>
std::string ToMathematica(Bivector<S, F> const& bivector);

template<typename S, typename F>
std::string ToMathematica(Vector<S, F> const& vector);

Expand Down
13 changes: 12 additions & 1 deletion mathematica/mathematica_body.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ inline std::string Apply(
result += "[";
for (int i = 0; i < arguments.size(); ++i) {
result += arguments[i];
result += (i + 1 == arguments.size() ? "]" : ",");
result += (i + 1 < arguments.size() ? "," : "");
}
result += "]";
return result;
}

Expand Down Expand Up @@ -105,6 +106,11 @@ inline std::string ToMathematica(double const& real) {
}
}

inline std::string ToMathematica(Quaternion const& quaternion) {
return ToMathematica<double, R3Element<double>>(
{quaternion.real_part(), quaternion.imaginary_part()});
}

template<typename T, int size>
std::string ToMathematica(FixedVector<T, size> const & fixed_vector) {
std::vector<std::string> expressions;
Expand Down Expand Up @@ -137,6 +143,11 @@ std::string ToMathematica(Quantity<D> const& quantity) {
{Apply("Quantity", {number, units}), "$MachinePrecision"});
}

template<typename S, typename F>
std::string ToMathematica(Bivector<S, F> const& bivector) {
return ToMathematica(bivector.coordinates());
}

template<typename S, typename F>
std::string ToMathematica(Vector<S, F> const & vector) {
return ToMathematica(vector.coordinates());
Expand Down
4 changes: 2 additions & 2 deletions serialization/journal.proto
Original file line number Diff line number Diff line change
Expand Up @@ -1587,9 +1587,9 @@ message PartApplyIntrinsicTorque {
optional In in = 1;
}

message PartGetActualDegreesOfFreedom {
message PartGetActualRigidMotion {
extend Method {
optional PartGetActualDegreesOfFreedom extension = 5116;
optional PartGetActualRigidMotion extension = 5116;
}
message In {
required fixed64 plugin = 1 [(pointer_to) = "Plugin const",
Expand Down