OGS 6.2.0-97-g4a610c866
FunctionHandles.h
Go to the documentation of this file.
1 
10 #pragma once
11 
12 #include "ODESolverTypes.h"
13 
14 namespace MathLib
15 {
16 namespace ODE
17 {
18 namespace detail
19 {
22 
31 {
32 public:
35  virtual bool call(const double t, double const* const y,
36  double* const ydot) = 0;
37 
41  virtual bool callJacobian(const double t,
42  double const* const y,
43  double* const ydot,
44  double* const jac) = 0;
45 
47  virtual bool hasJacobian() const = 0;
48 
50  virtual unsigned getNumberOfEquations() const = 0;
51 
52  virtual ~FunctionHandles() = default;
53 };
54 
56 template <unsigned N>
57 struct FunctionHandlesImpl final : public FunctionHandles
58 {
60  {
61  }
62 
71  bool call(const double t, const double* const y,
72  double* const ydot) override
73  {
74  if (f)
75  {
76  MappedVector<N> ydot_mapped{ydot};
77  return f(t, MappedConstVector<N>{y}, ydot_mapped);
78  }
79  return false;
80  }
81 
88  bool callJacobian(const double t, const double* const y, double* const ydot,
89  double* const jac) override
90  {
91  if (df)
92  {
93  MappedMatrix<N, N> jac_mapped{jac};
94  return df(t,
97  jac_mapped);
98  }
99  return false;
100  }
101 
102  bool hasJacobian() const override { return df != nullptr; }
103  unsigned getNumberOfEquations() const override { return N; }
106 };
107 
109 
110 } // namespace detail
111 } // namespace ODE
112 } // namespace MathLib
bool hasJacobian() const override
Tells whether a Jacobian function has been set.
std::function< bool(const double t, MappedConstVector< N > const &y, MappedConstVector< N > const &ydot, MappedMatrix< N, N > &jac)> JacobianFunction
virtual bool callJacobian(const double t, double const *const y, double *const ydot, double *const jac)=0
Function handles for an ODE system of N equations.
MappedConstMatrix< N, 1 > MappedConstVector
virtual bool call(const double t, double const *const y, double *const ydot)=0
unsigned getNumberOfEquations() const override
Returns the number of equations in the ODE system.
bool callJacobian(const double t, const double *const y, double *const ydot, double *const jac) override
std::function< bool(const double t, MappedConstVector< N > const &y, MappedVector< N > &ydot)> Function
FunctionHandlesImpl(Function< N > &f, JacobianFunction< N > &df)
virtual unsigned getNumberOfEquations() const =0
Returns the number of equations in the ODE system.
bool call(const double t, const double *const y, double *const ydot) override
virtual bool hasJacobian() const =0
Tells whether a Jacobian function has been set.
Eigen::Map< Eigen::Matrix< double, N, M, Eigen::ColMajor > > MappedMatrix
MappedMatrix< N, 1 > MappedVector