Program Listing for File model_ode.h

Return to documentation for file (include/amici/model_ode.h)

#ifndef AMICI_MODEL_ODE_H
#define AMICI_MODEL_ODE_H

#include "amici/model.h"

#include <nvector/nvector_serial.h>

#include <sundials/sundials_matrix.h>
#include <sunmatrix/sunmatrix_band.h>
#include <sunmatrix/sunmatrix_dense.h>
#include <sunmatrix/sunmatrix_sparse.h>

#include <utility>
#include <vector>

namespace amici {

class CVodeSolver;

class Model_ODE : public Model {
  public:
    Model_ODE() = default;

    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)
        : Model(nx_rdata, nxtrue_rdata, nx_solver, nxtrue_solver,
                nx_solver_reinit, ny, nytrue, nz, nztrue, ne, nJ, nw, ndwdx,
                ndwdp, ndwdw, ndxdotdw, std::move(ndJydy), nnz, ubw, lbw,
                o2mode, p, k, plist, idlist, z2event, pythonGenerated,
                ndxdotdp_explicit, ndxdotdx_explicit, w_recursion_depth) {}

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

    void fJ(realtype t, N_Vector x, N_Vector xdot, SUNMatrix J);

    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;

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

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

    void fJSparse(realtype t, N_Vector x, SUNMatrix J);

    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;

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

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

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

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

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

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

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

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

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

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

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

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

    void fxBdot_ss(const realtype t, const AmiVector &xB,
                   const AmiVector & /*dxB*/, AmiVector &xBdot) override;

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

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

    void fJSparseB_ss(SUNMatrix JB) override;

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

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

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

    std::unique_ptr<Solver> getSolver() override;

  protected:

    virtual 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);

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

    virtual void fJSparse_colptrs(SUNMatrixWrapper &JSparse);

    virtual void fJSparse_rowvals(SUNMatrixWrapper &JSparse);

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

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

    virtual 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);

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

    virtual void fdxdotdp_explicit_colptrs(SUNMatrixWrapper &dxdotdp);

    virtual void fdxdotdp_explicit_rowvals(SUNMatrixWrapper &dxdotdp);

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

    virtual void fdxdotdx_explicit_colptrs(SUNMatrixWrapper &dxdotdx);

    virtual void fdxdotdx_explicit_rowvals(SUNMatrixWrapper &dxdotdx);

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

    virtual void fdxdotdw_colptrs(SUNMatrixWrapper &dxdotdw);

    virtual void fdxdotdw_rowvals(SUNMatrixWrapper &dxdotdw);

    void fdxdotdw(realtype t, const N_Vector x);

    void fdxdotdp(realtype t, const N_Vector x);

    void fdxdotdp(realtype t, const AmiVector &x, const AmiVector &dx) override;
};
} // namespace amici

#endif // MODEL_H