Minsky
rungeKutta.h
Go to the documentation of this file.
1 /*
2  @copyright Steve Keen 2021
3  @author Russell Standish
4  This file is part of Minsky.
5 
6  Minsky is free software: you can redistribute it and/or modify it
7  under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  Minsky is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with Minsky. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #ifndef RUNGEKUTTA_H
21 #define RUNGEKUTTA_H
22 #include "simulation.h"
23 #include "evalOp.h"
24 #include "evalGodley.h"
25 #include "integral.h"
26 
27 namespace minsky
28 {
29  struct RKdata; // an internal structure for holding Runge-Kutta data
30  class Matrix; // convenience class for accessing matrix elements from a data array
31 
34  {
35  protected:
36  std::shared_ptr<RKdata> ode;
38  std::vector<Integral> integrals;
40  std::string threadErrMsg;
42  volatile bool RKThreadRunning=false;
43  };
44 
45  class RungeKutta: public Simulation, public classdesc::Exclude<RungeKuttaExclude>, public ValueVector
46  {
48  protected:
49  void evalEquations(double result[], double, const double vars[]);
50  void evalJacobian(Matrix&, double, const double vars[]);
52  static int RKfunction(double, const double y[], double f[], void*);
54  static int jacobian(double, const double y[], double*, double dfdt[], void*);
55  friend struct RKdata;
56  public:
57  double t{0};
58  bool running=false;
59  bool reverse=false;
61 
62  virtual ~RungeKutta()=default;
65  virtual bool resetIfFlagged() {return false;}
66  void rkreset();
67  void rkstep();
68  void evalEquations() {
71  for (auto& eq: equations)
73  }
74 
75  };
76 }
77 #include "rungeKutta.cd"
78 #endif
void rkstep()
step the equations (by n steps, default 1) evaluate the flow equations without stepping.
Definition: rungeKutta.cc:130
components excluded from reflection
Definition: rungeKutta.h:33
function f
Definition: canvas.m:1
static int RKfunction(double, const double y[], double f[], void *)
function to be integrated (internal use)
Definition: rungeKutta.cc:50
std::vector< Integral > integrals
Definition: rungeKutta.h:38
void rkreset()
reset the simulation
Definition: rungeKutta.cc:122
EvalGodley evalGodley
Definition: rungeKutta.h:60
convenience class for accessing matrix elements from a data array
Definition: matrix.h:26
static std::vector< double, CIVITA_ALLOCATOR< double > > stockVars
vector of variables that are integrated via Runge-Kutta. These variables label the columns of the God...
static int jacobian(double, const double y[], double *, double dfdt[], void *)
compute jacobian (internal use)
Definition: rungeKutta.cc:65
CLASSDESC_ACCESS(RungeKutta)
std::shared_ptr< RKdata > ode
Definition: rungeKutta.h:36
Creation and access to the minskyTCL_obj object, which has code to record whenever Minsky&#39;s state cha...
Definition: constMap.h:22
EvalOpVector equations
Definition: rungeKutta.h:37
std::string threadErrMsg
used to report a thrown exception on the simulation thread
Definition: rungeKutta.h:40
bool reverse
reverse direction of simulation
Definition: rungeKutta.h:59
static std::vector< double, CIVITA_ALLOCATOR< double > > flowVars
variables defined as a simple function of the stock variables, also known as lhs variables. These variables appear in the body of the Godley table
volatile bool RKThreadRunning
flag indicates that RK engine is computing a step
Definition: rungeKutta.h:42
double t
time
Definition: rungeKutta.h:57
void evalJacobian(Matrix &, double, const double vars[])
Definition: rungeKutta.cc:216
virtual bool resetIfFlagged()
checks whether a reset is required, and resets the simulation if so
Definition: rungeKutta.h:65
void evalEquations()
Definition: rungeKutta.h:70
virtual ~RungeKutta()=default
bool running
controls whether simulation is running
Definition: rungeKutta.h:58