16#include "wuzp/trafo/internal/apply_units.hpp"
17#include "wuzp/trafo/internal/pull_back.hpp"
18#include "wuzp/trafo/internal/push_forward.hpp"
24 int DimensionFromV_,
int DimensionToV_,
typename... UnitsT_>
32template <
template <
typename,
int,
int>
typename ValuesT_,
typename FromT_,
typename ToT_,
typename QuantitiesT_>
34 template <
typename... UnitsT_>
36 Jacobian<ValuesT_, typename QuantitiesT_::ValueT, FromT_, ToT_, Cols<QuantitiesT_>::value, Rows<QuantitiesT_>::value, UnitsT_...>;
37 using type =
typename ApplyUnits<typename QuantitiesT_::UnitsT, WithUnits>::type;
40template <
template <
typename,
int,
int>
typename ValuesT_,
typename FromT_,
typename ToT_,
typename QuantitiesT_>
41auto makeJacobian(QuantitiesT_ quantities) {
42 return typename JacobianOf<ValuesT_, FromT_, ToT_, QuantitiesT_>::type{std::move(quantities)};
47template <
template <
typename,
int,
int>
typename ValuesT_,
typename LhsT_,
typename RhsT_>
48auto composeJacobians(
const LhsT_& lhs,
const RhsT_& rhs) {
49 return makeJacobian<ValuesT_, typename RhsT_::From, typename LhsT_::To>(
innerProduct(lhs.getQuantities(), rhs.getQuantities()));
83 int DimensionFromV_,
int DimensionToV_,
typename... UnitsT_>
86 :
public PassiveTransformation<Jacobian<ValuesT_, ValueT_, FromT_, ToT_, DimensionFromV_, DimensionToV_, UnitsT_...>, FromT_, ToT_> {
89 using ValuesT = ValuesT_<ValueT_, DimensionToV_, DimensionFromV_>;
94 template <
typename... Args>
96 explicit Jacobian(Args&&... args) : quantities_{std::forward<Args>(args)...} {}
106 template <
typename ObjectT_>
108 static_assert(std::is_same_v<typename GetCoordinateSystem<ObjectT_>::type, ToT_>,
"Coordinate systems do not match.");
109 return internal::pullBack<FromT_, ToT_>(quantities_,
object);
118 static_assert(DimensionFromV_ == DimensionToV_,
119 "Only a square Jacobian, between coordinate systems of the same dimension, has an inverse.");
120 return internal::makeJacobian<ValuesT_, ToT_, FromT_>(quantities_.inverse());
132 auto pseudoInverse()
const {
return internal::makeJacobian<ValuesT_, ToT_, FromT_>(quantities_.pseudoInverse()); }
136 template <
template <
typename,
int,
int>
typename ValuesOtherT_,
typename ValueOtherT_,
typename FromOtherT_,
typename ToOtherT_,
137 int DimensionFromOtherV_,
int DimensionToOtherV_,
typename... UnitsOtherT_>
141 static_assert(internal::SameFrames<
Jacobian, std::remove_cvref_t<
decltype(other)>>::value);
142 return quantities_.isApprox(other.
getQuantities(), precision);
154template <
template <
typename,
int,
int>
typename ValuesT_,
typename ValueT_,
typename FromT_,
typename ToT_,
int DimensionFromV_,
155 int DimensionToV_,
typename... UnitsT_,
typename QuantitiesOtherT_,
typename CoordinateSystemOtherT_>
160 return internal::pushForward<FromT_, ToT_>(jacobian.
getQuantities(),
object);
164template <
template <
typename,
int,
int>
typename ValuesT_,
typename ValueT_,
typename FromT_,
typename ToT_,
int DimensionFromV_,
165 int DimensionToV_,
typename... UnitsT_,
typename QuantitiesOtherT_,
typename CoordinateSystemOtherT_>
170 return internal::pushForward<FromT_, ToT_>(jacobian.
getQuantities(),
object);
176template <
template <
typename,
int,
int>
typename ValuesT_,
typename ValueT_,
typename FromT_,
typename ToT_,
int DimensionFromV_,
177 int DimensionToV_,
typename... UnitsT_,
typename QuantitiesOtherT_,
typename CoordinateSystemOtherT_>
181 "A Jacobian maps vectors, not points: the change of coordinates whose derivative it is maps the points.");
184template <
template <
typename,
int,
int>
typename ValuesT_,
typename ValueT_,
typename FromT_,
typename ToT_,
int DimensionFromV_,
185 int DimensionToV_,
typename... UnitsT_,
typename IndicesOtherT_,
typename QuantitiesOtherT_,
typename CoordinateSystemOtherT_,
186 typename AbsoluteOtherT_>
188 Tensor<IndicesOtherT_, QuantitiesOtherT_, CoordinateSystemOtherT_, AbsoluteOtherT_>> {
190 "A Jacobian pushes forward vectors and tensors with two upper indices. Use pullback() for covectors and tensors with two "
195template <
template <
typename,
int,
int>
typename ValuesLhsT_,
typename ValueLhsT_,
typename FromLhsT_,
typename ToLhsT_,
196 int DimensionFromLhsV_,
int DimensionToLhsV_,
typename... UnitsLhsT_,
template <
typename,
int,
int>
typename ValuesRhsT_,
197 typename ValueRhsT_,
typename FromRhsT_,
typename ToRhsT_,
int DimensionFromRhsV_,
int DimensionToRhsV_,
typename... UnitsRhsT_>
199 Jacobian<ValuesRhsT_, ValueRhsT_, FromRhsT_, ToRhsT_, DimensionFromRhsV_, DimensionToRhsV_, UnitsRhsT_...>> {
203 return internal::composeJacobians<ValuesLhsT_>(lhs, rhs);
210template <
template <
typename,
int,
int>
typename ValuesLhsT_,
typename ValueLhsT_,
typename FromLhsT_,
typename ToLhsT_,
211 int DimensionFromLhsV_,
int DimensionToLhsV_,
typename... UnitsLhsT_,
typename RhsT_>
212 requires internal::IsChangeOfBasis<RhsT_>::value
217 return internal::composeJacobians<ValuesLhsT_>(lhs, rhs);
221template <
typename LhsT_,
template <
typename,
int,
int>
typename ValuesRhsT_,
typename ValueRhsT_,
typename FromRhsT_,
typename ToRhsT_,
222 int DimensionFromRhsV_,
int DimensionToRhsV_,
typename... UnitsRhsT_>
223 requires internal::IsChangeOfBasis<LhsT_>::value
225 Jacobian<ValuesRhsT_, ValueRhsT_, FromRhsT_, ToRhsT_, DimensionFromRhsV_, DimensionToRhsV_, UnitsRhsT_...>> {
229 return internal::composeJacobians<ValuesRhsT_>(lhs, rhs);
233template <
template <
typename,
int,
int>
typename ValuesLhsT_,
typename ValueLhsT_,
typename FromLhsT_,
typename ToLhsT_,
234 int DimensionFromLhsV_,
int DimensionToLhsV_,
typename... UnitsLhsT_,
template <
typename,
int,
int>
typename ValuesRhsT_,
235 typename ValueRhsT_,
typename FromRhsT_,
typename ToRhsT_,
int DimensionFromRhsV_,
int DimensionToRhsV_,
typename... UnitsRhsT_>
238 static_assert(internal::SameFrames<std::remove_cvref_t<
decltype(lhs)>, std::remove_cvref_t<
decltype(rhs)>>::value);
242template <
template <
typename,
int,
int>
typename ValuesLhsT_,
typename ValueLhsT_,
typename FromLhsT_,
typename ToLhsT_,
243 int DimensionFromLhsV_,
int DimensionToLhsV_,
typename... UnitsLhsT_,
template <
typename,
int,
int>
typename ValuesRhsT_,
244 typename ValueRhsT_,
typename FromRhsT_,
typename ToRhsT_,
int DimensionFromRhsV_,
int DimensionToRhsV_,
typename... UnitsRhsT_>
247 return !(lhs == rhs);
250template <
template <
typename,
int,
int>
typename ValuesT_,
typename ValueT_,
typename FromT_,
typename ToT_,
int DimensionFromV_,
251 int DimensionToV_,
typename... UnitsT_>
The Jacobian J = d(To)/d(From) of a change of coordinates from the coordinate system From to the coor...
Quantities< ValuesT, UnitsT > QuantitiesT
Jacobian(Args &&... args)
auto pseudoInverse() const
The pseudo-inverse J^+, from To to From, of a Jacobian of full rank (see Quantities::pseudoInverse())...
ValuesT_< typename QuantitiesT_::ValueT, DimensionToV_, DimensionFromV_ > ValuesT
bool isApprox(const Jacobian< ValuesOtherT_, ValueOtherT_, FromOtherT_, ToOtherT_, DimensionFromOtherV_, DimensionToOtherV_, UnitsOtherT_... > &other, const ValueT precision=Precision< ValueT >::value()) const
Whether both Jacobians, which must transform between the same coordinate systems, are approximately e...
auto inverse() const
The inverse Jacobian, from To to From, the Jacobian of the inverse change of coordinates,...
const QuantitiesT & getQuantities() const
The matrix J, whose element J_ij is the derivative of the coordinate x_i of To with respect to the co...
typename QuantitiesT_::ValueT ValueT
auto pullback(const ObjectT_ &object) const
The pullback of a covector w in To, w J, e.g. of a force into joint torques, or of a tensor M in To w...
TypeMatrix< DimensionToV_, DimensionFromV_, UnitsT_... > UnitsT
Container to store quantities.
A tensor of rank 0, 1 or 2, whose components are quantities, expressed in a coordinate system,...
Any coordinate system: a specialization of CoordinateSystem, including the intermediate ones of trans...
The alias template ValueMatrix<ValueT_, RowsV_, ColsV_> of any value matrix backend,...
Whether constructing a Class from the arguments copies or moves it, i.e. whether they are a single Cl...
internal::AbsoluteImpl< true > Absolute
bool operator!=(const Quantities< ValuesLhsT_, UnitsLhsT_ > &lhs, const Quantities< ValuesRhsT_, UnitsRhsT_ > &rhs)
std::ostream & operator<<(std::ostream &lhs, const Quantities< ValuesT_, UnitsT_ > &rhs)
auto innerProduct(const Quantities< ValuesLhsT_, UnitsLhsT_ > &lhs, const Quantities< ValuesRhsT_, UnitsRhsT_ > &rhs)
internal::AbsoluteImpl< false > Relative
bool operator==(const Quantities< ValuesLhsT_, UnitsLhsT_ > &lhs, const Quantities< ValuesRhsT_, UnitsRhsT_ > &rhs)
typename CreateTypeMatrix< RowsV_, ColsV_, Types... >::type TypeMatrix
A matrix storing types at compile-time.
wuzp::CompositionTraits< Jacobian< ValuesLhsT_, ValueLhsT_, FromLhsT_, ToLhsT_, DimensionFromLhsV_, DimensionToLhsV_, UnitsLhsT_... >, Jacobian< ValuesRhsT_, ValueRhsT_, FromRhsT_, ToRhsT_, DimensionFromRhsV_, DimensionToRhsV_, UnitsRhsT_... > >::compose static auto compose(const Jacobian< ValuesLhsT_, ValueLhsT_, FromLhsT_, ToLhsT_, DimensionFromLhsV_, DimensionToLhsV_, UnitsLhsT_... > &lhs, const Jacobian< ValuesRhsT_, ValueRhsT_, FromRhsT_, ToRhsT_, DimensionFromRhsV_, DimensionToRhsV_, UnitsRhsT_... > &rhs)
static auto compose(const Jacobian< ValuesLhsT_, ValueLhsT_, FromLhsT_, ToLhsT_, DimensionFromLhsV_, DimensionToLhsV_, UnitsLhsT_... > &lhs, const RhsT_ &rhs)
static auto compose(const LhsT_ &lhs, const Jacobian< ValuesRhsT_, ValueRhsT_, FromRhsT_, ToRhsT_, DimensionFromRhsV_, DimensionToRhsV_, UnitsRhsT_... > &rhs)
The composition lhs * rhs of two transformations, which applies rhs first, then lhs: (lhs * rhs)....
False for every type, so that a static_assert on it fails only when the template that names it is ins...
The indices of a tensor, in their order, e.g. Indices<Up, Down> for a linear map T^i_j,...
static constexpr ValueT_ value()
An upper, or contravariant, index, e.g. of a vector v^i, whose components transform like the coordina...