{# NEST dynamics template This template defines a C++ function of the form: int modelName_dynamics (double t, N_Vector y, N_Vector f, void* pnode) if using the CVODE/IDA solvers, or int modelName_dynamics (double t, const double y[], double f[], void* pnode) if using the GSL ODE solvers. The function computes the derivatives of all states defined in the system. Template variables are: - ODEmethod: the current used solver method; can be "cvode" "ida" or "gsl" - modelName: the name of the current system - localVars: list of strings with the name of all local variables appearing in the system - parameterDefs - the parameter equations of the form "name = params->name" which retrieve parameter values from the params structure and assign it to local variables - ratePrevEqDefs - a list of equations that retrieve the state values computed at the previous time step and assign them to local variables - eqOrderDefs - topologically sorted list of strings with external, assignment, reaction, pool equations in C++ syntax - rateOrderDefs - list of strings with the rate equatins in C++ syntax #} {% if ((ODEmethod == "cvode") or (ODEmethod == "ida") ) %} extern "C" int {{modelName}}_dynamics (double t, N_Vector y, N_Vector f, void* pnode) {% else %} extern "C" int {{modelName}}_dynamics (double t, const double y[], double f[], void* pnode) {% endif %} { {% if (not (dynamics.localVars == [])) %} double {{dynamics.localVars | join(", ")}}; {% endif %} // S is shorthand for the type that describes the model state typedef {{modelName}}::State_ S; // cast the node ptr to an object of the proper type assert(pnode); const {{modelName}} & node = *(reinterpret_cast<{{modelName}}*>(pnode)); {{modelName}} & vnode = *(reinterpret_cast<{{modelName}}*>(pnode)); // params is a reference to the model parameters const struct {{modelName}}::Parameters_ *params; params = &(node.P_); // state is a reference to the model state struct {{modelName}}::State_ *state; state = &(vnode.S_); // y[] must be the state vector supplied by the integrator, // not the state vector in the node, node.S_.y[]. {% for parameterDef in dynamics.parameterDefs %} {{parameterDef}} {% endfor %} {% for eq in dynamics.ratePrevEqDefs %} {{eq}} {% endfor %} {% for eq in dynamics.eqOrderDefs %} {{eq}} {% endfor %} {% for eq in dynamics.rateEqDefs %} {{eq}} {% endfor %} {% if ((ODEmethod == "cvode") or (ODEmethod == "ida") ) %} return 0; {% else %} return GSL_SUCCESS; {% endif %} }