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

Commits on Feb 13, 2019

  1. Add intrinsic forces even if a collision is detected. Detect collisio…

    …ns substantially below mean_radius.
    pleroy committed Feb 13, 2019
    Copy the full SHA
    6899a08 View commit details
  2. Link failures.

    pleroy committed Feb 13, 2019
    Copy the full SHA
    17b995b View commit details

Commits on Feb 15, 2019

  1. Copy the full SHA
    1ec936f View commit details
  2. Merge pull request #2075 from pleroy/2072

    Add intrinsic forces even if a collision is detected
    pleroy authored Feb 15, 2019
    Copy the full SHA
    4b72f80 View commit details
68 changes: 36 additions & 32 deletions physics/ephemeris_body.hpp
Original file line number Diff line number Diff line change
@@ -68,6 +68,11 @@ using ::std::placeholders::_3;
constexpr Length pre_ἐρατοσθένης_default_ephemeris_fitting_tolerance =
1 * Milli(Metre);
constexpr Time max_time_between_checkpoints = 180 * Day;
// Below this threshold detect a collision to prevent the integrator and the
// downsampling from going postal.
constexpr double mean_radius_tolerance = 0.9;

Status const CollisionDetected(Error::OUT_OF_RANGE, "Collision detected");

template<typename Frame>
template<typename ODE>
@@ -404,24 +409,23 @@ Ephemeris<Frame>::NewInstance(
FixedStepParameters const& parameters) {
IntegrationProblem<NewtonianMotionEquation> problem;

problem.equation.compute_acceleration = [this, intrinsic_accelerations](
Instant const& t,
std::vector<Position<Frame>> const& positions,
std::vector<Vector<Acceleration, Frame>>& accelerations) {
if (ComputeMasslessBodiesGravitationalAccelerations(t,
problem.equation.compute_acceleration =
[this, intrinsic_accelerations](
Instant const& t,
std::vector<Position<Frame>> const& positions,
std::vector<Vector<Acceleration, Frame>>& accelerations) {
bool const ok =
ComputeMasslessBodiesGravitationalAccelerations(t,
positions,
accelerations)) {
// Add the intrinsic accelerations.
for (int i = 0; i < intrinsic_accelerations.size(); ++i) {
auto const intrinsic_acceleration = intrinsic_accelerations[i];
if (intrinsic_acceleration != nullptr) {
accelerations[i] += intrinsic_acceleration(t);
}
accelerations);
// Add the intrinsic accelerations.
for (int i = 0; i < intrinsic_accelerations.size(); ++i) {
auto const intrinsic_acceleration = intrinsic_accelerations[i];
if (intrinsic_acceleration != nullptr) {
accelerations[i] += intrinsic_acceleration(t);
}
return Status::OK;
} else {
return Status(Error::OUT_OF_RANGE, "Collision detected");
}
return ok ? Status::OK : CollisionDetected;
};

CHECK(!trajectories.empty());
@@ -460,16 +464,14 @@ Status Ephemeris<Frame>::FlowWithAdaptiveStep(
Instant const& t,
std::vector<Position<Frame>> const& positions,
std::vector<Vector<Acceleration, Frame>>& accelerations) {
if (ComputeMasslessBodiesGravitationalAccelerations(t,
bool const ok =
ComputeMasslessBodiesGravitationalAccelerations(t,
positions,
accelerations)) {
if (intrinsic_acceleration != nullptr) {
accelerations[0] += intrinsic_acceleration(t);
}
return Status::OK;
} else {
return Status(Error::OUT_OF_RANGE, "Collision detected");
accelerations);
if (intrinsic_acceleration != nullptr) {
accelerations[0] += intrinsic_acceleration(t);
}
return ok ? Status::OK : CollisionDetected;
};

return FlowODEWithAdaptiveStep<NewtonianMotionEquation>(
@@ -495,15 +497,15 @@ Status Ephemeris<Frame>::FlowWithAdaptiveStep(
std::vector<Position<Frame>> const& positions,
std::vector<Velocity<Frame>> const& velocities,
std::vector<Vector<Acceleration, Frame>>& accelerations) {
if (ComputeMasslessBodiesGravitationalAccelerations(t,
bool const ok =
ComputeMasslessBodiesGravitationalAccelerations(t,
positions,
accelerations)) {
accelerations);
if (intrinsic_acceleration != nullptr) {
accelerations[0] +=
intrinsic_acceleration(t, {positions[0], velocities[0]});
return Status::OK;
} else {
return Status(Error::OUT_OF_RANGE, "Collision detected");
}
return ok ? Status::OK : CollisionDetected;
};

return FlowODEWithAdaptiveStep<GeneralizedNewtonianMotionEquation>(
@@ -982,7 +984,8 @@ ComputeGravitationalAccelerationByMassiveBodyOnMasslessBodies(
std::vector<Vector<Acceleration, Frame>>& accelerations) const {
GravitationalParameter const& μ1 = body1.gravitational_parameter();
Position<Frame> const position1 = trajectories_[b1]->EvaluatePosition(t);
Length const body1_mean_radius = body1.mean_radius();
Length const body1_collision_radius =
mean_radius_tolerance * body1.mean_radius();
bool ok = true;

for (std::size_t b2 = 0; b2 < positions.size(); ++b2) {
@@ -991,7 +994,7 @@ ComputeGravitationalAccelerationByMassiveBodyOnMasslessBodies(

Square<Length> const Δq² = Δq.Norm²();
Length const Δq_norm = Sqrt(Δq²);
ok &= Δq_norm > body1_mean_radius;
ok &= Δq_norm > body1_collision_radius;

Exponentiation<Length, -3> const one_over_Δq³ = Δq_norm / (Δq² * Δq²);

@@ -1163,8 +1166,9 @@ Status Ephemeris<Frame>::FlowODEWithAdaptiveStep(
auto status = instance->Solve(t_final);

// We probably don't care if the vessel gets too close to the singularity, as
// we only use this integrator for the future. So we swallow the error.
// TODO(phl): Is this the right thing to do long term?
// we only use this integrator for the future. So we swallow the error. Note
// that a collision in the prediction or the flight plan (for which this path
// is used) should not cause the vessel to be deleted.
if (status.error() == Error::OUT_OF_RANGE) {
status = Status::OK;
}
4 changes: 2 additions & 2 deletions physics/ephemeris_test.cpp
Original file line number Diff line number Diff line change
@@ -778,8 +778,8 @@ TEST_P(EphemerisTest, ComputeGravitationalAccelerationMasslessBody) {
// An apple located a bit above the pole collides with the ground.
TEST_P(EphemerisTest, CollisionDetection) {
Time const short_duration = 1 * Second;
// A naïve computation would have 1.428 s.
Time const long_duration = 1.431 * Second;
// A naïve computation would have 360.4 s.
Time const long_duration = 354.8 * Second;
std::vector<not_null<std::unique_ptr<MassiveBody const>>> bodies;
std::vector<DegreesOfFreedom<ICRS>> initial_state;

1 change: 1 addition & 0 deletions testing_utilities/testing_utilities.vcxproj
Original file line number Diff line number Diff line change
@@ -34,6 +34,7 @@
<ClInclude Include="vanishes_before_body.hpp" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\base\status.cpp" />
<ClCompile Include="..\numerics\cbrt.cpp" />
<ClCompile Include="algebra_test.cpp" />
<ClCompile Include="almost_equals_test.cpp" />
3 changes: 3 additions & 0 deletions testing_utilities/testing_utilities.vcxproj.filters
Original file line number Diff line number Diff line change
@@ -115,5 +115,8 @@
<ClCompile Include="..\numerics\cbrt.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\base\status.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
</Project>
1 change: 1 addition & 0 deletions tools/tools.vcxproj
Original file line number Diff line number Diff line change
@@ -7,6 +7,7 @@
</PropertyGroup>
<Import Project="$(SolutionDir)principia.props" />
<ItemGroup>
<ClCompile Include="..\base\status.cpp" />
<ClCompile Include="..\numerics\cbrt.cpp" />
<ClCompile Include="generate_configuration.cpp" />
<ClCompile Include="generate_kopernicus.cpp" />
3 changes: 3 additions & 0 deletions tools/tools.vcxproj.filters
Original file line number Diff line number Diff line change
@@ -27,6 +27,9 @@
<ClCompile Include="generate_kopernicus.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\base\status.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="generate_configuration.hpp">