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

Commits on Aug 19, 2021

  1. Remove zfp flag.

    pleroy committed Aug 19, 2021
    Copy the full SHA
    a694d0c View commit details
  2. Merge pull request #3102 from pleroy/Zfp

    Remove the zfp flag and fix a typo
    pleroy authored Aug 19, 2021
    Copy the full SHA
    5cfb589 View commit details
Showing with 60 additions and 69 deletions.
  1. +60 −69 physics/discrete_trajectory_body.hpp
129 changes: 60 additions & 69 deletions physics/discrete_trajectory_body.hpp
Original file line number Diff line number Diff line change
@@ -500,77 +500,68 @@ void DiscreteTrajectory<Frame>::WriteSubTreeToMessage(
std::vector<DiscreteTrajectory<Frame>*>& forks) const {
Forkable<DiscreteTrajectory, Iterator, DiscreteTrajectoryTraits<Frame>>::
WriteSubTreeToMessage(message, forks);
if (Flags::IsPresent("zfp", "off")) {
for (auto const& [instant, degrees_of_freedom] : timeline_) {
auto const instantaneous_degrees_of_freedom = message->add_timeline();
instant.WriteToMessage(
instantaneous_degrees_of_freedom->mutable_instant());
degrees_of_freedom.WriteToMessage(
instantaneous_degrees_of_freedom->mutable_degrees_of_freedom());
}
} else {
int const timeline_size = timeline_.size();
auto* const zfp = message->mutable_zfp();
zfp->set_timeline_size(timeline_size);

// The timeline data is made dimensionless and stored in separate arrays per
// coordinate. We expect strong correlations within a coordinate over time,
// but not between coordinates.
std::vector<double> t;
std::vector<double> qx;
std::vector<double> qy;
std::vector<double> qz;
std::vector<double> px;
std::vector<double> py;
std::vector<double> pz;
t.reserve(timeline_size);
qx.reserve(timeline_size);
qy.reserve(timeline_size);
qz.reserve(timeline_size);
px.reserve(timeline_size);
py.reserve(timeline_size);
pz.reserve(timeline_size);
std::optional<Instant> previous_instant;
Time max_Δt;
std::string* const zfp_timeline = zfp->mutable_timeline();
for (auto const& [instant, degrees_of_freedom] : timeline_) {
auto const q = degrees_of_freedom.position() - Frame::origin;
auto const p = degrees_of_freedom.velocity();
t.push_back((instant - Instant{}) / Second);
qx.push_back(q.coordinates().x / Metre);
qy.push_back(q.coordinates().y / Metre);
qz.push_back(q.coordinates().z / Metre);
px.push_back(p.coordinates().x / (Metre / Second));
py.push_back(p.coordinates().y / (Metre / Second));
pz.push_back(p.coordinates().z / (Metre / Second));
if (previous_instant.has_value()) {
max_Δt = std::max(max_Δt, instant - *previous_instant);
}
previous_instant = instant;
}

// Times are exact.
ZfpCompressor time_compressor(0);
// Lengths are approximated to the downsampling tolerance if downsampling is
// enabled, otherwise they are exact.
Length const length_tolerance =
downsampling_.has_value() ? downsampling_->tolerance() : Length();
ZfpCompressor length_compressor(length_tolerance / Metre);
// Speeds are approximated based on the length tolerance and the maximum
// step in the timeline.
ZfpCompressor const speed_compressor((length_tolerance / max_Δt) /
(Metre / Second));

ZfpCompressor::WriteVersion(message);
time_compressor.WriteToMessageMultidimensional<2>(t, zfp_timeline);
length_compressor.WriteToMessageMultidimensional<2>(qx, zfp_timeline);
length_compressor.WriteToMessageMultidimensional<2>(qy, zfp_timeline);
length_compressor.WriteToMessageMultidimensional<2>(qz, zfp_timeline);
speed_compressor.WriteToMessageMultidimensional<2>(px, zfp_timeline);
speed_compressor.WriteToMessageMultidimensional<2>(py, zfp_timeline);
speed_compressor.WriteToMessageMultidimensional<2>(pz, zfp_timeline);
int const timeline_size = timeline_.size();
auto* const zfp = message->mutable_zfp();
zfp->set_timeline_size(timeline_size);

// The timeline data is made dimensionless and stored in separate arrays per
// coordinate. We expect strong correlations within a coordinate over time,
// but not between coordinates.
std::vector<double> t;
std::vector<double> qx;
std::vector<double> qy;
std::vector<double> qz;
std::vector<double> px;
std::vector<double> py;
std::vector<double> pz;
t.reserve(timeline_size);
qx.reserve(timeline_size);
qy.reserve(timeline_size);
qz.reserve(timeline_size);
px.reserve(timeline_size);
py.reserve(timeline_size);
pz.reserve(timeline_size);
std::optional<Instant> previous_instant;
Time max_Δt;
std::string* const zfp_timeline = zfp->mutable_timeline();
for (auto const& [instant, degrees_of_freedom] : timeline_) {
auto const q = degrees_of_freedom.position() - Frame::origin;
auto const p = degrees_of_freedom.velocity();
t.push_back((instant - Instant{}) / Second);
qx.push_back(q.coordinates().x / Metre);
qy.push_back(q.coordinates().y / Metre);
qz.push_back(q.coordinates().z / Metre);
px.push_back(p.coordinates().x / (Metre / Second));
py.push_back(p.coordinates().y / (Metre / Second));
pz.push_back(p.coordinates().z / (Metre / Second));
if (previous_instant.has_value()) {
max_Δt = std::max(max_Δt, instant - *previous_instant);
}
previous_instant = instant;
}

// Times are exact.
ZfpCompressor time_compressor(0);
// Lengths are approximated to the downsampling tolerance if downsampling is
// enabled, otherwise they are exact.
Length const length_tolerance =
downsampling_.has_value() ? downsampling_->tolerance() : Length();
ZfpCompressor length_compressor(length_tolerance / Metre);
// Speeds are approximated based on the length tolerance and the maximum
// step in the timeline.
ZfpCompressor const speed_compressor((length_tolerance / max_Δt) /
(Metre / Second));

ZfpCompressor::WriteVersion(message);
time_compressor.WriteToMessageMultidimensional<2>(t, zfp_timeline);
length_compressor.WriteToMessageMultidimensional<2>(qx, zfp_timeline);
length_compressor.WriteToMessageMultidimensional<2>(qy, zfp_timeline);
length_compressor.WriteToMessageMultidimensional<2>(qz, zfp_timeline);
speed_compressor.WriteToMessageMultidimensional<2>(px, zfp_timeline);
speed_compressor.WriteToMessageMultidimensional<2>(py, zfp_timeline);
speed_compressor.WriteToMessageMultidimensional<2>(pz, zfp_timeline);

if (downsampling_.has_value()) {
downsampling_->WriteToMessage(message->mutable_downsampling());
}
@@ -582,7 +573,7 @@ void DiscreteTrajectory<Frame>::FillSubTreeFromMessage(
std::vector<DiscreteTrajectory<Frame>**> const& forks) {
bool const is_pre_frobenius = !message.has_zfp();
LOG_IF(WARNING, is_pre_frobenius)
<< "Reading pre-Frobenius PolynomialInMonomialBasis";
<< "Reading pre-Frobenius DiscreteTrajectory";
if (is_pre_frobenius) {
for (auto const& instantaneous_dof : message.timeline()) {
Append(Instant::ReadFromMessage(instantaneous_dof.instant()),