C API Documentation
Integrator.h
Go to the documentation of this file.
1 // == PREAMBLE ================================================
2 
3 // * Licensed under the Apache License, Version 2.0; see README
4 
5 // == FILEDOC =================================================
6 
14 # ifndef RR_INTEGRATOR_H_
15 # define RR_INTEGRATOR_H_
16 
17 // == INCLUDES ================================================
18 
19 # include "rrLogger.h"
20 # include "rrOSSpecifics.h"
21 # include "Dictionary.h"
22 # include "rrException.h"
23 # include "Solver.h"
24 
25 # include "tr1proxy/rr_memory.h"
26 # include "tr1proxy/rr_unordered_map.h"
27 # include <stdexcept>
28 
29 // == CODE ====================================================
30 
31 namespace rr {
32 
33  class Integrator;
34 
35  class ExecutableModel;
36 
37  /*-------------------------------------------------------------------------------------------
38  IntegratorListener listens for integrator events.
39  ---------------------------------------------------------------------------------------------*/
41  public:
42 
46  virtual uint onTimeStep(Integrator *integrator, ExecutableModel *model, double time) = 0;
47 
51  virtual uint onEvent(Integrator *integrator, ExecutableModel *model, double time) = 0;
52 
53  virtual ~IntegratorListener() {};
54  };
55 
56  typedef cxx11_ns::shared_ptr<IntegratorListener> IntegratorListenerPtr;
57 
58  /*-------------------------------------------------------------------------------------------
59  Integrator is an abstract base class that provides an interface to specific integrator
60  class implementations.
61  ---------------------------------------------------------------------------------------------*/
62  class RR_DECLSPEC Integrator : public Solver {
63  public:
69  using Solver::setValue;
70 
71  enum IntegrationMethod {
72  Deterministic,
73  Stochastic,
74  Hybrid,
75  Other
76  };
77 
78  virtual ~Integrator() {};
79 
80  virtual IntegrationMethod getIntegrationMethod() const = 0;
81 
87  virtual void syncWithModel(ExecutableModel *m);
88 
89  virtual void loadConfigSettings();
90 
91  virtual void loadSBMLSettings(const std::string &filename);
92 
93  virtual double integrate(double t0, double hstep) = 0;
94 
95  virtual void restart(double t0) = 0;
96 
105  virtual void tweakTolerances();
106 
111  virtual void setIndividualTolerance(string sid, double value);
112 
113 
118  virtual void setConcentrationTolerance(const Variant &value);
119 
124  virtual std::vector<double> getConcentrationTolerance();
125 
126 
127  /* CARRYOVER METHODS */
128  virtual void setListener(IntegratorListenerPtr) = 0;
129 
130  virtual IntegratorListenerPtr getListener() = 0;
131 
132  std::string toString() const;
133 
138  virtual std::string toRepr() const;
139  /* !-- END OF CARRYOVER METHODS */
140  };
141 
142 
143  class IntegratorException : public std::runtime_error {
144  public:
145  explicit IntegratorException(const std::string &what) :
146  std::runtime_error(what) {
147  Log(rr::Logger::LOG_ERROR) << __FUNC__ << "what: " << what;
148  }
149 
150  explicit IntegratorException(const std::string &what, const std::string &where) :
151  std::runtime_error(what + "; In " + where) {
152  Log(rr::Logger::LOG_ERROR) << __FUNC__ << "what: " << what << ", where: " << where;
153  }
154  };
155 
161  class RR_DECLSPEC IntegratorRegistrar {
162  protected:
163  typedef Integrator *(*IntegratorCtor)(ExecutableModel *model);
164 
165  public:
166  virtual ~IntegratorRegistrar();
167 
172  virtual std::string getName() const = 0;
173 
178  virtual std::string getDescription() const = 0;
179 
184  virtual std::string getHint() const = 0;
185 
190  virtual Integrator *construct(ExecutableModel *model) const = 0;
191  };
192 
200  class RR_DECLSPEC IntegratorFactory {
201  public:
202  virtual ~IntegratorFactory();
203 
209  Integrator *New(std::string name, ExecutableModel *m) const;
210 
218 
224 
225  // ** Indexing *********************************************************
226 
227  std::size_t size() const;
228 
229  std::string name(std::size_t n) const;
230 
231  std::string hint(std::size_t n) const;
232 
233  std::string description(std::size_t n) const;
234 
235  private:
240  IntegratorFactory() {}
241 
242  typedef std::vector<IntegratorRegistrar *> IntegratorRegistrars;
243  IntegratorRegistrars mRegisteredIntegrators;
244  };
245 
246 }
247 
248 # endif /* RR_INTEGRATOR_H_ */
Contains the base class for RoadRunner solvers.
Base class for all code generation systems; allows compiling and evaluating the model.
Definition: rrExecutableModel.h:118
Definition: Integrator.h:143
Constructs new integrators.
Definition: Integrator.h:200
Integrator * New(std::string name, ExecutableModel *m) const
Constructs a new integrator given the name (e.g. cvode, gillespie)
static IntegratorFactory & getInstance()
Returns the singleton instance of the integrator factory.
void registerSolver(IntegratorRegistrar *i)
Registers a new integrator with the factory so that it can be constructed.
Definition: Integrator.h:62
virtual void setIndividualTolerance(string sid, double value)
Set tolerance for floating species or variables that have a rate rule, will only be used in CVODEInte...
virtual void syncWithModel(ExecutableModel *m)
Called whenever a new model is loaded to allow integrator to reset internal state.
virtual std::string toRepr() const
Return string representation a la Python repr method.
virtual std::vector< double > getConcentrationTolerance()
Get tolerance based on concentration of species, will only be used in CVODEIntegrator.
virtual void setConcentrationTolerance(const Variant &value)
Set tolerance based on concentration of species, will only be used in CVODEIntegrator.
virtual void tweakTolerances()
Fix tolerances for SBML tests.
std::string toString() const
Return a string representation of the solver.
Definition: Integrator.h:40
virtual uint onEvent(Integrator *integrator, ExecutableModel *model, double time)=0
virtual uint onTimeStep(Integrator *integrator, ExecutableModel *model, double time)=0
Handles constructing an integrator and contains meta information about it.
Definition: Integrator.h:161
virtual std::string getHint() const =0
Gets the hint associated with this integrator type.
virtual std::string getName() const =0
Gets the name associated with this integrator type.
virtual Integrator * construct(ExecutableModel *model) const =0
Constructs a new integrator of a given type.
virtual std::string getDescription() const =0
Gets the description associated with this integrator type.
@ LOG_ERROR
A critical error. The application might not be able to continue running successfully.
Definition: rrLogger.h:65
Base class for all integrators and steady state solvers.
Definition: Solver.h:37
Definition: Variant.h:75