Skip to content
Snippets Groups Projects
Commit 429c94a2 authored by Dmitri Naumov's avatar Dmitri Naumov
Browse files

[MaL] ODE: Add MappedVector/Matrix template alias.

parent 8f82fd28
No related branches found
No related tags found
No related merge requests found
...@@ -28,8 +28,7 @@ class OdeSolver ...@@ -28,8 +28,7 @@ class OdeSolver
{ {
public: public:
using Arr = std::array<double, NumEquations>; using Arr = std::array<double, NumEquations>;
using ConstArrRef = using ConstArrRef = MappedConstVector<NumEquations>;
Eigen::Map<const Eigen::Matrix<double, NumEquations, 1>>;
using Function = MathLib::Function<NumEquations, FunctionArguments...>; using Function = MathLib::Function<NumEquations, FunctionArguments...>;
using JacobianFunction = using JacobianFunction =
MathLib::JacobianFunction<NumEquations, FunctionArguments...>; MathLib::JacobianFunction<NumEquations, FunctionArguments...>;
......
...@@ -44,10 +44,7 @@ struct Handles<N, FunctionArgument> : public MathLib::FunctionHandles ...@@ -44,10 +44,7 @@ struct Handles<N, FunctionArgument> : public MathLib::FunctionHandles
// consider omission of data pointer and switch to std::function or // consider omission of data pointer and switch to std::function or
// alike // alike
if (f) if (f)
return f(t, return f(t, MappedConstVector<N>{y}, MappedVector<N>{ydot}, _data);
Eigen::Map<const Eigen::Matrix<double, N, 1>>{y},
Eigen::Map<Eigen::Matrix<double, N, 1>>{ydot},
_data);
return true; return true;
} }
...@@ -56,9 +53,9 @@ struct Handles<N, FunctionArgument> : public MathLib::FunctionHandles ...@@ -56,9 +53,9 @@ struct Handles<N, FunctionArgument> : public MathLib::FunctionHandles
{ {
if (df) if (df)
return df(t, return df(t,
Eigen::Map<const Eigen::Matrix<double, N, 1>>{y}, MappedConstVector<N>{y},
Eigen::Map<Eigen::Matrix<double, N, 1>>{ydot}, MappedVector<N>{ydot},
Eigen::Map<Eigen::Matrix<double, N, N>>{jac /*, order*/}, MappedMatrix<N, N>{jac /*, order*/},
_data); _data);
return true; return true;
} }
...@@ -85,9 +82,7 @@ struct Handles<N> : public MathLib::FunctionHandles ...@@ -85,9 +82,7 @@ struct Handles<N> : public MathLib::FunctionHandles
{ {
// auto ydot_ = Eigen::Map<Eigen::Matrix<double, N, 1>>{y}; // auto ydot_ = Eigen::Map<Eigen::Matrix<double, N, 1>>{y};
// auto ydot_ = Eigen::Map<Eigen::Matrix<double, N, 1>>{ydot}; // auto ydot_ = Eigen::Map<Eigen::Matrix<double, N, 1>>{ydot};
return f(t, return f(t, MappedConstVector<N>{y}, MappedVector<N>{ydot});
Eigen::Map<const Eigen::Matrix<double, N, 1>>{y},
Eigen::Map<Eigen::Matrix<double, N, 1>>{ydot});
} }
return true; return true;
} }
...@@ -97,9 +92,9 @@ struct Handles<N> : public MathLib::FunctionHandles ...@@ -97,9 +92,9 @@ struct Handles<N> : public MathLib::FunctionHandles
{ {
if (df) if (df)
return df(t, return df(t,
Eigen::Map<const Eigen::Matrix<double, N, 1>>{y}, MappedConstVector<N>{y},
Eigen::Map<Eigen::Matrix<double, N, 1>>{ydot}, MappedVector<N>{ydot},
Eigen::Map<Eigen::Matrix<double, N, N>>{jac /*, order*/}); MappedMatrix<N, N>{jac /*, order*/});
return true; return true;
} }
......
...@@ -14,19 +14,30 @@ ...@@ -14,19 +14,30 @@
namespace MathLib namespace MathLib
{ {
template <int M, int N>
using MappedMatrix = Eigen::Map<Eigen::Matrix<double, M, N>>;
template <int M, int N>
using MappedConstMatrix = Eigen::Map<const Eigen::Matrix<double, M, N>>;
template <int N>
using MappedVector = MappedMatrix<N, 1>;
template <int N>
using MappedConstVector = MappedConstMatrix<N, 1>;
template <unsigned N, typename... FunctionArguments> template <unsigned N, typename... FunctionArguments>
using Function = bool (*)(const double t, using Function = bool (*)(const double t,
Eigen::Map<const Eigen::Matrix<double, N, 1>> const y, MappedConstVector<N> const y,
Eigen::Map<Eigen::Matrix<double, N, 1>> ydot, MappedVector<N> ydot,
FunctionArguments&... arg); FunctionArguments&... arg);
template <unsigned N, typename... FunctionArguments> template <unsigned N, typename... FunctionArguments>
using JacobianFunction = using JacobianFunction = bool (*)(const double t,
bool (*)(const double t, MappedConstVector<N> const y,
Eigen::Map<const Eigen::Matrix<double, N, 1>> const y, MappedVector<N> ydot,
Eigen::Map<Eigen::Matrix<double, N, 1>> ydot, MappedMatrix<N, N> jac,
Eigen::Map<Eigen::Matrix<double, N, N>> jac, FunctionArguments&... arg);
FunctionArguments&... arg);
// This is an internal detail // This is an internal detail
class FunctionHandles class FunctionHandles
......
...@@ -16,8 +16,8 @@ ...@@ -16,8 +16,8 @@
#include <cstdio> #include <cstdio>
bool f(const double, bool f(const double,
Eigen::Map<const Eigen::Matrix<double, 1, 1>> const y, MathLib::MappedConstVector<1> const y,
Eigen::Map<Eigen::Matrix<double, 1, 1>> ydot) MathLib::MappedVector<1> ydot)
{ {
if (y[0] <= 0.0) return false; if (y[0] <= 0.0) return false;
...@@ -26,9 +26,9 @@ bool f(const double, ...@@ -26,9 +26,9 @@ bool f(const double,
} }
bool df(const double /*t*/, bool df(const double /*t*/,
Eigen::Map<const Eigen::Matrix<double, 1, 1>> const y, MathLib::MappedConstVector<1> const y,
Eigen::Map<Eigen::Matrix<double, 1, 1>> /*ydot*/, MathLib::MappedVector<1> /*ydot*/,
Eigen::Map<Eigen::Matrix<double, 1, 1>> jac) MathLib::MappedMatrix<1, 1> jac)
{ {
if (y[0] <= 0.0) return false; if (y[0] <= 0.0) return false;
...@@ -42,8 +42,8 @@ struct ExtraData ...@@ -42,8 +42,8 @@ struct ExtraData
}; };
bool f_extra(const double, bool f_extra(const double,
Eigen::Map<const Eigen::Matrix<double, 1, 1>> const y, MathLib::MappedConstVector<1> const y,
Eigen::Map<Eigen::Matrix<double, 1, 1>> ydot, MathLib::MappedVector<1> ydot,
ExtraData& data) ExtraData& data)
{ {
if (y[0] <= 0.0) return false; if (y[0] <= 0.0) return false;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment