Class Model_ODE

Inheritance Relationships

Base Type

Class Documentation

class amici::Model_ODE : public amici::Model

The Model class represents an AMICI ODE model.

The model does not contain any data, but represents the state of the model at a specific time t. The states must not always be in sync, but may be updated asynchronously.

Public Functions

Model_ODE() = default

default constructor

Model_ODE(const int nx_rdata, const int nxtrue_rdata, const int nx_solver, const int nxtrue_solver, const int nx_solver_reinit, const int ny, const int nytrue, const int nz, const int nztrue, const int ne, const int nJ, const int nw, const int ndwdx, const int ndwdp, const int ndwdw, const int ndxdotdw, std::vector<int> ndJydy, const int nnz, const int ubw, const int lbw, const SecondOrderMode o2mode, std::vector<realtype> const &p, std::vector<realtype> const &k, std::vector<int> const &plist, std::vector<realtype> const &idlist, std::vector<int> const &z2event, const bool pythonGenerated = false, const int ndxdotdp_explicit = 0, const int ndxdotdx_explicit = 0, const int w_recursion_depth = 0)

Constructor with model dimensions.

Parameters
  • nx_rdata: number of state variables

  • nxtrue_rdata: number of state variables of the non-augmented model

  • nx_solver: number of state variables with conservation laws applied

  • nxtrue_solver: number of state variables of the non-augmented model with conservation laws applied

  • nx_solver_reinit: number of state variables with conservation laws subject to reinitialization

  • ny: number of observables

  • nytrue: number of observables of the non-augmented model

  • nz: number of event observables

  • nztrue: number of event observables of the non-augmented model

  • ne: number of events

  • nJ: number of objective functions

  • nw: number of repeating elements

  • ndwdx: number of nonzero elements in the x derivative of the repeating elements

  • ndwdp: number of nonzero elements in the p derivative of the repeating elements

  • ndwdw: number of nonzero elements in the w derivative of the repeating elements

  • ndxdotdw: number of nonzero elements dxdotdw

  • ndJydy: number of nonzero elements dJydy

  • nnz: number of nonzero elements in Jacobian

  • ubw: upper matrix bandwidth in the Jacobian

  • lbw: lower matrix bandwidth in the Jacobian

  • o2mode: second order sensitivity mode

  • p: parameters

  • k: constants

  • plist: indexes wrt to which sensitivities are to be computed

  • idlist: indexes indicating algebraic components (DAE only)

  • z2event: mapping of event outputs to events

  • pythonGenerated: flag indicating matlab or python wrapping

  • ndxdotdp_explicit: number of nonzero elements dxdotdp_explicit

  • ndxdotdx_explicit: number of nonzero elements dxdotdx_explicit

  • w_recursion_depth: Recursion depth of fw

void fJ(realtype t, realtype cj, const AmiVector &x, const AmiVector &dx, const AmiVector &xdot, SUNMatrix J) override

Dense Jacobian function.

Parameters
  • t: time

  • cj: scaling factor (inverse of timestep, DAE only)

  • x: state

  • dx: time derivative of state (DAE only)

  • xdot: values of residual function (unused)

  • J: dense matrix to which values of the jacobian will be written

void fJ(realtype t, const_N_Vector x, const_N_Vector xdot, SUNMatrix J)

Implementation of fJ at the N_Vector level.

This function provides an interface to the model specific routines for the solver implementation as well as the AmiVector level implementation

Parameters
  • t: timepoint

  • x: Vector with the states

  • xdot: Vector with the right hand side

  • J: Matrix to which the Jacobian will be written

void fJB(const realtype t, realtype cj, const AmiVector &x, const AmiVector &dx, const AmiVector &xB, const AmiVector &dxB, const AmiVector &xBdot, SUNMatrix JB) override

Dense Jacobian function.

Parameters
  • t: time

  • cj: scaling factor (inverse of timestep, DAE only)

  • x: state

  • dx: time derivative of state (DAE only)

  • xB: Vector with the adjoint states

  • dxB: Vector with the adjoint derivative states

  • xBdot: Vector with the adjoint right hand side (unused)

  • JB: dense matrix to which values of the jacobian will be written

void fJB(realtype t, const_N_Vector x, const_N_Vector xB, const_N_Vector xBdot, SUNMatrix JB)

Implementation of fJB at the N_Vector level, this function provides an interface to the model specific routines for the solver implementation.

Parameters
  • t: timepoint

  • x: Vector with the states

  • xB: Vector with the adjoint states

  • xBdot: Vector with the adjoint right hand side

  • JB: Matrix to which the Jacobian will be written

void fJSparse(realtype t, realtype cj, const AmiVector &x, const AmiVector &dx, const AmiVector &xdot, SUNMatrix J) override

Sparse Jacobian function.

Parameters
  • t: time

  • cj: scaling factor (inverse of timestep, DAE only)

  • x: state

  • dx: time derivative of state (DAE only)

  • xdot: values of residual function (unused)

  • J: sparse matrix to which values of the Jacobian will be written

void fJSparse(realtype t, const_N_Vector x, SUNMatrix J)

Implementation of fJSparse at the N_Vector level, this function provides an interface to the model specific routines for the solver implementation as well as the AmiVector level implementation.

Parameters
  • t: timepoint

  • x: Vector with the states

  • J: Matrix to which the Jacobian will be written

void fJSparseB(const realtype t, realtype cj, const AmiVector &x, const AmiVector &dx, const AmiVector &xB, const AmiVector &dxB, const AmiVector &xBdot, SUNMatrix JB) override

Sparse Jacobian function.

Parameters
  • t: time

  • cj: scaling factor (inverse of timestep, DAE only)

  • x: state

  • dx: time derivative of state (DAE only)

  • xB: Vector with the adjoint states

  • dxB: Vector with the adjoint derivative states

  • xBdot: Vector with the adjoint right hand side (unused)

  • JB: dense matrix to which values of the jacobian will be written

void fJSparseB(realtype t, const_N_Vector x, const_N_Vector xB, const_N_Vector xBdot, SUNMatrix JB)

Implementation of fJSparseB at the N_Vector level, this function provides an interface to the model specific routines for the solver implementation.

Parameters
  • t: timepoint

  • x: Vector with the states

  • xB: Vector with the adjoint states

  • xBdot: Vector with the adjoint right hand side

  • JB: Matrix to which the Jacobian will be written

void fJDiag(realtype t, N_Vector JDiag, const_N_Vector x)

Implementation of fJDiag at the N_Vector level, this function provides an interface to the model specific routines for the solver implementation.

Parameters
  • t: timepoint

  • JDiag: Vector to which the Jacobian diagonal will be written

  • x: Vector with the states

void fJDiag(realtype t, AmiVector &JDiag, realtype cj, const AmiVector &x, const AmiVector &dx) override

Diagonal of the Jacobian (for preconditioning)

Parameters
  • t: timepoint

  • JDiag: Vector to which the Jacobian diagonal will be written

  • cj: scaling factor, inverse of the step size

  • x: Vector with the states

  • dx: Vector with the derivative states

void fJv(realtype t, const AmiVector &x, const AmiVector &dx, const AmiVector &xdot, const AmiVector &v, AmiVector &nJv, realtype cj) override

Jacobian multiply function.

Parameters
  • t: time

  • x: state

  • dx: time derivative of state (DAE only)

  • xdot: values of residual function (unused)

  • v: multiplication vector (unused)

  • nJv: array to which result of multiplication will be written

  • cj: scaling factor (inverse of timestep, DAE only)

void fJv(const_N_Vector v, N_Vector Jv, realtype t, const_N_Vector x)

Implementation of fJv at the N_Vector level.

Parameters
  • t: timepoint

  • x: Vector with the states

  • v: Vector with which the Jacobian is multiplied

  • Jv: Vector to which the Jacobian vector product will be written

void fJvB(const_N_Vector vB, N_Vector JvB, realtype t, const_N_Vector x, const_N_Vector xB)

Implementation of fJvB at the N_Vector level.

Parameters
  • t: timepoint

  • x: Vector with the states

  • xB: Vector with the adjoint states

  • vB: Vector with which the Jacobian is multiplied

  • JvB: Vector to which the Jacobian vector product will be written

void froot(realtype t, const AmiVector &x, const AmiVector &dx, gsl::span<realtype> root) override

Root function.

Parameters
  • t: time

  • x: state

  • dx: time derivative of state (DAE only)

  • root: array to which values of the root function will be written

void froot(realtype t, const_N_Vector x, gsl::span<realtype> root)

Implementation of froot at the N_Vector level This function provides an interface to the model specific routines for the solver implementation as well as the AmiVector level implementation.

Parameters
  • t: timepoint

  • x: Vector with the states

  • root: array with root function values

void fxdot(realtype t, const AmiVector &x, const AmiVector &dx, AmiVector &xdot) override

Residual function.

Parameters
  • t: time

  • x: state

  • dx: time derivative of state (DAE only)

  • xdot: array to which values of the residual function will be written

void fxdot(realtype t, const_N_Vector x, N_Vector xdot)

Implementation of fxdot at the N_Vector level, this function provides an interface to the model specific routines for the solver implementation as well as the AmiVector level implementation.

Parameters
  • t: timepoint

  • x: Vector with the states

  • xdot: Vector with the right hand side

void fxBdot(realtype t, N_Vector x, N_Vector xB, N_Vector xBdot)

Implementation of fxBdot at the N_Vector level.

Parameters
  • t: timepoint

  • x: Vector with the states

  • xB: Vector with the adjoint states

  • xBdot: Vector with the adjoint right hand side

void fqBdot(realtype t, const_N_Vector x, const_N_Vector xB, N_Vector qBdot)

Implementation of fqBdot at the N_Vector level.

Parameters
  • t: timepoint

  • x: Vector with the states

  • xB: Vector with the adjoint states

  • qBdot: Vector with the adjoint quadrature right hand side

void fxBdot_ss(const realtype t, const AmiVector &xB, const AmiVector&, AmiVector &xBdot) override

Residual function backward when running in steady state mode.

Parameters
  • t: time

  • xB: adjoint state

  • dxB: time derivative of state (DAE only)

  • xBdot: array to which values of the residual function will be written

void fxBdot_ss(realtype t, const_N_Vector xB, N_Vector xBdot) const

Implementation of fxBdot for steady state at the N_Vector level.

Parameters
  • t: timepoint

  • xB: Vector with the states

  • xBdot: Vector with the adjoint right hand side

void fqBdot_ss(realtype t, N_Vector xB, N_Vector qBdot) const

Implementation of fqBdot for steady state case at the N_Vector level.

Parameters
  • t: timepoint

  • xB: Vector with the adjoint states

  • qBdot: Vector with the adjoint quadrature right hand side

void fJSparseB_ss(SUNMatrix JB) override

Sparse Jacobian function backward, steady state case.

Parameters
  • JB: sparse matrix to which values of the Jacobian will be written

void writeSteadystateJB(const realtype t, realtype cj, const AmiVector &x, const AmiVector &dx, const AmiVector &xB, const AmiVector &dxB, const AmiVector &xBdot) override

Computes the sparse backward Jacobian for steadystate integration and writes it to the model member.

Parameters
  • t: timepoint

  • cj: scalar in Jacobian

  • x: Vector with the states

  • dx: Vector with the derivative states

  • xB: Vector with the adjoint states

  • dxB: Vector with the adjoint derivative states

  • xBdot: Vector with the adjoint state right hand side

void fsxdot(realtype t, const AmiVector &x, const AmiVector &dx, int ip, const AmiVector &sx, const AmiVector &sdx, AmiVector &sxdot) override

Sensitivity Residual function.

Parameters
  • t: time

  • x: state

  • dx: time derivative of state (DAE only)

  • ip: parameter index

  • sx: sensitivity state

  • sdx: time derivative of sensitivity state (DAE only)

  • sxdot: array to which values of the sensitivity residual function will be written

void fsxdot(realtype t, const_N_Vector x, int ip, const_N_Vector sx, N_Vector sxdot)

Implementation of fsxdot at the N_Vector level.

Parameters
  • t: timepoint

  • x: Vector with the states

  • ip: parameter index

  • sx: Vector with the state sensitivities

  • sxdot: Vector with the sensitivity right hand side

std::unique_ptr<Solver> getSolver() override

Retrieves the solver object.

Return

The Solver instance

Protected Functions

void fJSparse(SUNMatrixContent_Sparse JSparse, realtype t, const realtype *x, const realtype *p, const realtype *k, const realtype *h, const realtype *w, const realtype *dwdx)

Model specific implementation for fJSparse (Matlab)

Parameters
  • JSparse: Matrix to which the Jacobian will be written

  • t: timepoint

  • x: Vector with the states

  • p: parameter vector

  • k: constants vector

  • h: Heaviside vector

  • w: vector with helper variables

  • dwdx: derivative of w wrt x

void fJSparse(realtype *JSparse, realtype t, const realtype *x, const realtype *p, const realtype *k, const realtype *h, const realtype *w, const realtype *dwdx)

Model specific implementation for fJSparse, data only (Py)

Parameters
  • JSparse: Matrix to which the Jacobian will be written

  • t: timepoint

  • x: Vector with the states

  • p: parameter vector

  • k: constants vector

  • h: Heaviside vector

  • w: vector with helper variables

  • dwdx: derivative of w wrt x

void fJSparse_colptrs(SUNMatrixWrapper &JSparse)

Model specific implementation for fJSparse, column pointers.

Parameters
  • JSparse: sparse matrix to which colptrs will be written

void fJSparse_rowvals(SUNMatrixWrapper &JSparse)

Model specific implementation for fJSparse, row values.

Parameters
  • JSparse: sparse matrix to which rowvals will be written

void froot(realtype *root, realtype t, const realtype *x, const realtype *p, const realtype *k, const realtype *h)

Model specific implementation for froot.

Parameters
  • root: values of the trigger function

  • t: timepoint

  • x: Vector with the states

  • p: parameter vector

  • k: constants vector

  • h: Heaviside vector

void fxdot(realtype *xdot, realtype t, const realtype *x, const realtype *p, const realtype *k, const realtype *h, const realtype *w) = 0

Model specific implementation for fxdot.

Parameters
  • xdot: residual function

  • t: timepoint

  • x: Vector with the states

  • p: parameter vector

  • k: constants vector

  • h: Heaviside vector

  • w: vector with helper variables

void fdxdotdp(realtype *dxdotdp, realtype t, const realtype *x, const realtype *p, const realtype *k, const realtype *h, int ip, const realtype *w, const realtype *dwdp)

Model specific implementation of fdxdotdp, with w chainrule (Matlab)

Parameters
  • dxdotdp: partial derivative xdot wrt p

  • t: timepoint

  • x: Vector with the states

  • p: parameter vector

  • k: constants vector

  • h: Heaviside vector

  • ip: parameter index

  • w: vector with helper variables

  • dwdp: derivative of w wrt p

void fdxdotdp_explicit(realtype *dxdotdp_explicit, realtype t, const realtype *x, const realtype *p, const realtype *k, const realtype *h, const realtype *w)

Model specific implementation of fdxdotdp_explicit, no w chainrule (Py)

Parameters
  • dxdotdp_explicit: partial derivative xdot wrt p

  • t: timepoint

  • x: Vector with the states

  • p: parameter vector

  • k: constants vector

  • h: Heaviside vector

  • w: vector with helper variables

void fdxdotdp_explicit_colptrs(SUNMatrixWrapper &dxdotdp)

Model specific implementation of fdxdotdp_explicit, colptrs part.

Parameters
  • dxdotdp: sparse matrix to which colptrs will be written

void fdxdotdp_explicit_rowvals(SUNMatrixWrapper &dxdotdp)

Model specific implementation of fdxdotdp_explicit, rowvals part.

Parameters
  • dxdotdp: sparse matrix to which rowvals will be written

void fdxdotdx_explicit(realtype *dxdotdx_explicit, realtype t, const realtype *x, const realtype *p, const realtype *k, const realtype *h, const realtype *w)

Model specific implementation of fdxdotdx_explicit, no w chainrule (Py)

Parameters
  • dxdotdx_explicit: partial derivative xdot wrt x

  • t: timepoint

  • x: Vector with the states

  • p: parameter vector

  • k: constants vector

  • h: heavyside vector

  • w: vector with helper variables

void fdxdotdx_explicit_colptrs(SUNMatrixWrapper &dxdotdx)

Model specific implementation of fdxdotdx_explicit, colptrs part.

Parameters
  • dxdotdx: sparse matrix to which colptrs will be written

void fdxdotdx_explicit_rowvals(SUNMatrixWrapper &dxdotdx)

Model specific implementation of fdxdotdx_explicit, rowvals part.

Parameters
  • dxdotdx: sparse matrix to which rowvals will be written

void fdxdotdw(realtype *dxdotdw, realtype t, const realtype *x, const realtype *p, const realtype *k, const realtype *h, const realtype *w)

Model specific implementation of fdxdotdw, data part.

Parameters
  • dxdotdw: partial derivative xdot wrt w

  • t: timepoint

  • x: Vector with the states

  • p: parameter vector

  • k: constants vector

  • h: Heaviside vector

  • w: vector with helper variables

void fdxdotdw_colptrs(SUNMatrixWrapper &dxdotdw)

Model specific implementation of fdxdotdw, colptrs part.

Parameters
  • dxdotdw: sparse matrix to which colptrs will be written

void fdxdotdw_rowvals(SUNMatrixWrapper &dxdotdw)

Model specific implementation of fdxdotdw, rowvals part.

Parameters
  • dxdotdw: sparse matrix to which rowvals will be written

void fdxdotdw(realtype t, const_N_Vector x)

Sensitivity of dx/dt wrt model parameters w.

Parameters
  • t: timepoint

  • x: Vector with the states

void fdxdotdp(realtype t, const_N_Vector x)

Explicit sensitivity of dx/dt wrt model parameters p

Parameters
  • t: timepoint

  • x: Vector with the states

void fdxdotdp(realtype t, const AmiVector &x, const AmiVector &dx) override

Model specific sparse implementation of explicit parameter derivative of right hand side.

Parameters
  • t: time

  • x: state

  • dx: time derivative of state (DAE only)