1010#include < cmath>
1111#include < functional>
1212#include < memory>
13+ #include < chrono>
1314
1415namespace amici {
1516
@@ -47,6 +48,9 @@ namespace amici {
4748 */
4849class Solver {
4950 public:
51+ /* * Type of what is passed to Sundials solvers as user_data */
52+ using user_data_type = std::pair<Model *, Solver const *>;
53+
5054 Solver () = default ;
5155
5256 /* *
@@ -468,6 +472,30 @@ class Solver {
468472 */
469473 void setMaxSteps (long int maxsteps);
470474
475+ /* *
476+ * @brief Returns the maximum time allowed for integration
477+ * @return Time in seconds
478+ */
479+ double getMaxTime () const ;
480+
481+ /* *
482+ * @brief Set the maximum time allowed for integration
483+ * @param maxtime Time in seconds
484+ */
485+ void setMaxTime (double maxtime);
486+
487+ /* *
488+ * @brief Start timer for tracking integration time
489+ */
490+ void startTimer () const ;
491+
492+ /* *
493+ * @brief Check whether maximum integration time was exceeded
494+ * @return True if the maximum integration time was exceeded,
495+ * false otherwise.
496+ */
497+ bool timeExceeded () const ;
498+
471499 /* *
472500 * @brief returns the maximum number of solver steps for the backward
473501 * problem
@@ -1113,21 +1141,16 @@ class Solver {
11131141 virtual void setErrHandlerFn () const = 0;
11141142
11151143 /* *
1116- * @brief Attaches the user data instance (here this is a Model) to the
1117- * forward problem
1118- *
1119- * @param model Model instance
1144+ * @brief Attaches the user data to the forward problem
11201145 */
1121- virtual void setUserData (Model *model ) const = 0;
1146+ virtual void setUserData () const = 0;
11221147
11231148 /* *
1124- * @brief attaches the user data instance (here this is a Model) to the
1125- * backward problem
1149+ * @brief attaches the user data to the backward problem
11261150 *
11271151 * @param which identifier of the backwards problem
1128- * @param model Model instance
11291152 */
1130- virtual void setUserDataB (int which, Model *model ) const = 0;
1153+ virtual void setUserDataB (int which) const = 0;
11311154
11321155 /* *
11331156 * @brief specifies the maximum number of steps for the forward
@@ -1519,6 +1542,9 @@ class Solver {
15191542 mutable std::vector<std::unique_ptr<void , std::function<void (void *)>>>
15201543 solver_memory_B_;
15211544
1545+ /* * Sundials user_data */
1546+ mutable user_data_type user_data;
1547+
15221548 /* * internal sensitivity method flag used to select the sensitivity solution
15231549 * method. Only applies for Forward Sensitivities. */
15241550 InternalSensitivityMethod ism_ {InternalSensitivityMethod::simultaneous};
@@ -1540,6 +1566,12 @@ class Solver {
15401566 /* * maximum number of allowed integration steps */
15411567 long int maxsteps_ {10000 };
15421568
1569+ /* * Maximum wall-time for integration in seconds */
1570+ std::chrono::duration<double , std::ratio<1 >> maxtime_ {std::chrono::duration<double >::max ()};
1571+
1572+ /* * Time at which solver timer was started */
1573+ mutable std::chrono::time_point<std::chrono::system_clock> starttime_;
1574+
15431575 /* * linear solver for the forward problem */
15441576 mutable std::unique_ptr<SUNLinSolWrapper> linear_solver_;
15451577
0 commit comments