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

Commits on May 10, 2020

  1. More Mathematica support.

    pleroy committed May 10, 2020
    Copy the full SHA
    e3bc66a View commit details

Commits on May 12, 2020

  1. Copy the full SHA
    16bdc86 View commit details

Commits on May 16, 2020

  1. Merge pull request #2567 from pleroy/2519y

    Mathematica logging of the inertia tensor
    pleroy authored May 16, 2020
    Copy the full SHA
    bb4d49c View commit details
Showing with 74 additions and 0 deletions.
  1. +15 −0 mathematica/mathematica.hpp
  2. +19 −0 mathematica/mathematica_body.hpp
  3. +40 −0 mathematica/mathematica_test.cpp
15 changes: 15 additions & 0 deletions mathematica/mathematica.hpp
Original file line number Diff line number Diff line change
@@ -15,6 +15,8 @@
#include "geometry/point.hpp"
#include "geometry/quaternion.hpp"
#include "geometry/r3_element.hpp"
#include "geometry/r3x3_matrix.hpp"
#include "geometry/symmetric_bilinear_form.hpp"
#include "numerics/fixed_arrays.hpp"
#include "physics/degrees_of_freedom.hpp"
#include "quantities/elementary_functions.hpp"
@@ -31,6 +33,8 @@ using geometry::Bivector;
using geometry::Point;
using geometry::Quaternion;
using geometry::R3Element;
using geometry::R3x3Matrix;
using geometry::SymmetricBilinearForm;
using geometry::Vector;
using numerics::FixedVector;
using physics::DegreesOfFreedom;
@@ -135,6 +139,10 @@ template<typename T, typename OptionalExpressIn = std::nullopt_t>
std::string ToMathematica(R3Element<T> const& r3_element,
OptionalExpressIn express_in = std::nullopt);

template<typename T, typename OptionalExpressIn = std::nullopt_t>
std::string ToMathematica(R3x3Matrix<T> const& r3x3_matrix,
OptionalExpressIn express_in = std::nullopt);

template<typename OptionalExpressIn = std::nullopt_t>
std::string ToMathematica(Quaternion const& quaternion,
OptionalExpressIn express_in = std::nullopt);
@@ -159,6 +167,13 @@ template<typename V, typename OptionalExpressIn = std::nullopt_t>
std::string ToMathematica(Point<V> const& point,
OptionalExpressIn express_in = std::nullopt);

template<typename S,
typename F,
template<typename, typename> typename M,
typename OptionalExpressIn = std::nullopt_t>
std::string ToMathematica(SymmetricBilinearForm<S, F, M> const& form,
OptionalExpressIn express_in = std::nullopt);

template<typename F, typename OptionalExpressIn = std::nullopt_t>
std::string ToMathematica(DegreesOfFreedom<F> const& degrees_of_freedom,
OptionalExpressIn express_in = std::nullopt);
19 changes: 19 additions & 0 deletions mathematica/mathematica_body.hpp
Original file line number Diff line number Diff line change
@@ -191,6 +191,16 @@ std::string ToMathematica(R3Element<T> const& r3_element,
return Apply("List", expressions);
}

template<typename T, typename OptionalExpressIn>
std::string ToMathematica(R3x3Matrix<T> const& r3x3_matrix,
OptionalExpressIn express_in) {
std::vector<R3Element<T>> rows;
rows.push_back(r3x3_matrix.row_x());
rows.push_back(r3x3_matrix.row_y());
rows.push_back(r3x3_matrix.row_z());
return ToMathematica(rows, express_in);
}

template<typename D, typename... Qs>
std::string ToMathematica(Quantity<D> const& quantity,
ExpressIn<Qs...> express_in) {
@@ -225,6 +235,15 @@ std::string ToMathematica(Point<V> const & point,
return ToMathematica(point - Point<V>(), express_in);
}

template<typename S,
typename F,
template<typename, typename> typename M,
typename OptionalExpressIn>
std::string ToMathematica(SymmetricBilinearForm<S, F, M> const& form,
OptionalExpressIn express_in) {
return ToMathematica(form.coordinates(), express_in);
}

template<typename F, typename OptionalExpressIn>
std::string ToMathematica(DegreesOfFreedom<F> const& degrees_of_freedom,
OptionalExpressIn express_in) {
40 changes: 40 additions & 0 deletions mathematica/mathematica_test.cpp
Original file line number Diff line number Diff line change
@@ -11,6 +11,8 @@
#include "geometry/point.hpp"
#include "geometry/quaternion.hpp"
#include "geometry/r3_element.hpp"
#include "geometry/r3x3_matrix.hpp"
#include "geometry/symmetric_bilinear_form.hpp"
#include "gtest/gtest.h"
#include "numerics/fixed_arrays.hpp"
#include "physics/degrees_of_freedom.hpp"
@@ -29,6 +31,8 @@ using geometry::Instant;
using geometry::Point;
using geometry::Quaternion;
using geometry::R3Element;
using geometry::R3x3Matrix;
using geometry::SymmetricBilinearForm;
using geometry::Vector;
using geometry::Velocity;
using numerics::FixedVector;
@@ -101,6 +105,25 @@ TEST_F(MathematicaTest, ToMathematica) {
"SetPrecision[-4.00000000000000000*^+00,$MachinePrecision]]",
ToMathematica(R3Element<double>(2.0, 3.0, -4.0)));
}
{
EXPECT_EQ(
"List["
"List["
"SetPrecision[+1.00000000000000000*^+00,$MachinePrecision],"
"SetPrecision[+2.00000000000000000*^+00,$MachinePrecision],"
"SetPrecision[+3.00000000000000000*^+00,$MachinePrecision]],"
"List["
"SetPrecision[+4.00000000000000000*^+00,$MachinePrecision],"
"SetPrecision[+5.00000000000000000*^+00,$MachinePrecision],"
"SetPrecision[+6.00000000000000000*^+00,$MachinePrecision]],"
"List["
"SetPrecision[+7.00000000000000000*^+00,$MachinePrecision],"
"SetPrecision[+8.00000000000000000*^+00,$MachinePrecision],"
"SetPrecision[+9.00000000000000000*^+00,$MachinePrecision]]]",
ToMathematica(R3x3Matrix<double>({1.0, 2.0, 3.0},
{4.0, 5.0, 6.0},
{7.0, 8.0, 9.0})));
}
{
EXPECT_EQ(
"Quaternion["
@@ -142,6 +165,23 @@ TEST_F(MathematicaTest, ToMathematica) {
ToMathematica(Point<Vector<double, F>>() +
Vector<double, F>({2.0, 3.0, -4.0})));
}
{
EXPECT_EQ(
"List["
"List["
"SetPrecision[+0.00000000000000000*^+00,$MachinePrecision],"
"SetPrecision[+0.00000000000000000*^+00,$MachinePrecision],"
"SetPrecision[+0.00000000000000000*^+00,$MachinePrecision]],"
"List["
"SetPrecision[+0.00000000000000000*^+00,$MachinePrecision],"
"SetPrecision[+0.00000000000000000*^+00,$MachinePrecision],"
"SetPrecision[+0.00000000000000000*^+00,$MachinePrecision]],"
"List["
"SetPrecision[+0.00000000000000000*^+00,$MachinePrecision],"
"SetPrecision[+0.00000000000000000*^+00,$MachinePrecision],"
"SetPrecision[+0.00000000000000000*^+00,$MachinePrecision]]]",
ToMathematica(SymmetricBilinearForm<double, F, Vector>()));
}
{
EXPECT_EQ(
"List["