#include <rungeKutta.h>
|
static int | RKfunction (double, const double y[], double f[], void *) |
| function to be integrated (internal use) More...
|
|
static int | jacobian (double, const double y[], double *, double dfdt[], void *) |
| compute jacobian (internal use) More...
|
|
|
static std::vector< double, CIVITA_ALLOCATOR< double > > | stockVars |
| vector of variables that are integrated via Runge-Kutta. These variables label the columns of the Godley table More...
|
|
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 More...
|
|
Definition at line 45 of file rungeKutta.h.
◆ ~RungeKutta()
virtual minsky::RungeKutta::~RungeKutta |
( |
| ) |
|
|
virtualdefault |
◆ CLASSDESC_ACCESS()
minsky::RungeKutta::CLASSDESC_ACCESS |
( |
RungeKutta |
| ) |
|
|
private |
◆ evalEquations() [1/2]
void minsky::RungeKutta::evalEquations |
( |
double |
result[], |
|
|
double |
t, |
|
|
const double |
vars[] |
|
) |
| |
|
protected |
Definition at line 248 of file rungeKutta.cc.
References minsky::Minsky::displayErrorItem(), and pyminsky::minsky.
Referenced by minsky::VariableBase::onMouseMotion().
251 const double reverseFactor=
reverse? -1: 1;
255 for (
size_t i=0; i<equations.size(); ++i)
256 equations[i]->eval(flow.data(), flow.size(), vars);
259 for (
size_t i=0; i<
stockVars.size(); ++i) result[i]=0;
263 for (vector<Integral>::iterator i=integrals.begin(); i<integrals.end(); ++i)
265 if (i->input().idx()<0)
269 throw error(
"integral not wired");
272 assert(i->input().size()==i->stock->size());
273 for (
size_t j=0; j<i->input().size(); ++j)
274 result[i->stock->idx()+j] = reverseFactor *
275 (i->input().isFlowVar()? flow[i->input().idx()+j] : vars[i->input().idx()+j]);
void displayErrorItem(const Item &op) const
indicate operation item has error, if visible, otherwise contining group
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...
bool reverse
reverse direction of simulation
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
void eval(double *sv, const double *fv) const
evaluate Godley tables on sv (of type double[]) and current value of fv (of type double[]), storing result in output variable (of fv). sv is assume to be of size stockVars and fv is assumed to be of size flowVars.
Minsky & minsky()
global minsky object
◆ evalEquations() [2/2]
void minsky::RungeKutta::evalEquations |
( |
| ) |
|
|
inline |
Definition at line 70 of file rungeKutta.h.
71 for (
auto& eq: equations)
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 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
◆ evalJacobian()
void minsky::RungeKutta::evalJacobian |
( |
Matrix & |
jac, |
|
|
double |
t, |
|
|
const double |
vars[] |
|
) |
| |
|
protected |
Definition at line 216 of file rungeKutta.cc.
219 const double reverseFactor=
reverse? -1: 1;
223 for (
size_t i=0; i<equations.size(); ++i)
224 equations[i]->eval(flow.data(), flow.size(), sv);
227 for (
size_t j=0; j<
stockVars.size(); ++j)
231 for (
size_t i=0; i<equations.size(); ++i)
232 equations[i]->deriv(df.data(), df.size(), ds.data(), sv, flow.data());
235 for (vector<Integral>::iterator i=integrals.begin();
236 i!=integrals.end(); ++i)
238 assert(i->stock->idx()>=0 && i->input().idx()>=0);
240 i->input().isFlowVar()? df[i->input().idx()]: ds[i->input().idx()];
242 for (
size_t i=0; i<
stockVars.size(); i++)
243 jac(i,j)=reverseFactor*d[i];
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...
bool reverse
reverse direction of simulation
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
void eval(double *sv, const double *fv) const
evaluate Godley tables on sv (of type double[]) and current value of fv (of type double[]), storing result in output variable (of fv). sv is assume to be of size stockVars and fv is assumed to be of size flowVars.
◆ jacobian()
int minsky::RungeKutta::jacobian |
( |
double |
t, |
|
|
const double |
y[], |
|
|
double * |
dfdy, |
|
|
double |
dfdt[], |
|
|
void * |
params |
|
) |
| |
|
staticprotected |
compute jacobian (internal use)
Definition at line 65 of file rungeKutta.cc.
67 if (params==NULL)
return GSL_EBADFUNC;
71 ((RungeKutta*)params)->evalJacobian(jac,
t,y);
73 catch (std::exception& e)
75 ((RungeKutta*)params)->threadErrMsg=
e.what();
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...
◆ resetIfFlagged()
virtual bool minsky::RungeKutta::resetIfFlagged |
( |
| ) |
|
|
inlinevirtual |
checks whether a reset is required, and resets the simulation if so
- Returns
- whether simulation was reset
Reimplemented in minsky::Minsky.
Definition at line 65 of file rungeKutta.h.
◆ RKfunction()
int minsky::RungeKutta::RKfunction |
( |
double |
t, |
|
|
const double |
y[], |
|
|
double |
f[], |
|
|
void * |
params |
|
) |
| |
|
staticprotected |
function to be integrated (internal use)
checks if any GUI events are waiting, and proces an event if so TODO - make this a virtual method of RungeKutta?
Definition at line 50 of file rungeKutta.cc.
References f.
52 if (params==NULL)
return GSL_EBADFUNC;
55 ((RungeKutta*)params)->evalEquations(
f,
t,y);
57 catch (std::exception& e)
59 ((RungeKutta*)params)->threadErrMsg=
e.what();
◆ rkreset()
void minsky::RungeKutta::rkreset |
( |
| ) |
|
◆ rkstep()
void minsky::RungeKutta::rkstep |
( |
| ) |
|
step the equations (by n steps, default 1) evaluate the flow equations without stepping.
- Exceptions
-
ecolab::error | if equations are illdefined |
Definition at line 130 of file rungeKutta.cc.
References minsky::doOneEvent().
139 RKThreadRunning=
true;
142 boost::thread rkThread([&]() {
148 gsl_odeiv2_driver_set_nmax(ode->driver,
nSteps);
151 err=gsl_odeiv2_driver_apply(ode->driver, &tp, numeric_limits<double>::max(),
152 stockVarsCopy.data());
156 vector<double> d(stockVarsCopy.size());
160 for (
size_t j=0; j<d.size(); ++j)
161 stockVarsCopy[j]+=d[j];
166 catch (
const std::exception& ex)
169 threadErrMsg=ex.what();
173 threadErrMsg=
"Unknown exception thrown on ODE solver thread";
175 RKThreadRunning=
false;
178 while (RKThreadRunning)
186 if (!threadErrMsg.empty())
188 auto msg=std::move(threadErrMsg);
189 threadErrMsg.clear();
191 throw runtime_error(msg);
199 case GSL_SUCCESS:
case GSL_EMAXITER:
break;
201 throw error(
"unspecified error GSL_FAILURE returned");
203 gsl_odeiv2_driver_reset(ode->driver);
204 throw error(
"Invalid arithmetic operation detected");
206 throw error(
"gsl error: %s",gsl_strerror(err));
void doOneEvent(bool idleTasksOnly)
checks if any GUI events are waiting, and proces an event if so
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...
bool reverse
reverse direction of simulation
virtual bool resetIfFlagged()
checks whether a reset is required, and resets the simulation if so
bool running
controls whether simulation is running
◆ RKdata
◆ evalGodley
◆ reverse
bool minsky::RungeKutta::reverse =false |
reverse direction of simulation
Definition at line 59 of file rungeKutta.h.
◆ running
bool minsky::RungeKutta::running =false |
controls whether simulation is running
Definition at line 58 of file rungeKutta.h.
double minsky::RungeKutta::t {0} |
The documentation for this class was generated from the following files: