26#if defined (HAVE_CONFIG_H)
58static bool user_jac_ignore_ml_mu;
61lsode_f (
const F77_INT& neq,
const double&
time,
double *,
double *deriv,
70 tmp_deriv = (*user_fcn) (*tmp_x,
time);
76 for (
F77_INT i = 0; i < neq; i++)
77 deriv[i] = tmp_deriv.
elem (i);
84lsode_j (
const F77_INT& neq,
const double&
time,
double *,
86 double *pd,
const F77_INT& nrowpd)
94 tmp_jac = (*user_jac) (*tmp_x,
time);
96 if (user_jac_ignore_ml_mu)
97 for (
F77_INT j = 0; j < neq; j++)
98 for (
F77_INT i = 0; i < neq; i++)
99 pd[nrowpd * j + i] = tmp_jac (i, j);
102 for (
F77_INT i = 0, j = mu; i <= ml; j == 0 ? i++ : j--)
104 for (
F77_INT k = i, l = j; k < neq && l < neq; k++, l++)
105 pd[nrowpd * l + k + mu - l] = tmp_jac (k, l);
118 || LSODE_options::m_reset)
122 m_initialized =
true;
132 user_jac_ignore_ml_mu =
true;
136 m_iwork(0) = lower_jacobian_subdiagonals ();
138 m_iwork(1) = upper_jacobian_subdiagonals ();
140 if (integration_method () ==
"stiff")
146 if (jacobian_type () ==
"banded")
149 user_jac_ignore_ml_mu =
false;
156 if (jacobian_type () ==
"full")
158 else if (jacobian_type () ==
"banded")
160 else if (jacobian_type () ==
"diagonal")
165 (*current_liboctave_error_handler)
166 (
"lsode: internal error, wrong jacobian type");
173 m_lrw = 22 + n * (9 + n);
187 for (
F77_INT i = 4; i < 9; i++)
192 for (
F77_INT i = 4; i < 9; i++)
199 if (maxord > 0 && maxord <= max_maxord)
201 m_iwork(4) = octave::to_f77_int (maxord);
207 (*current_liboctave_error_handler)
208 (
"lsode: invalid value for maximum order");
243 (*current_liboctave_error_handler)
244 (
"lsode: inconsistent sizes for state and derivative vectors");
254 m_rel_tol = relative_tolerance ();
255 m_abs_tol = absolute_tolerance ();
257 F77_INT abs_tol_len = octave::to_f77_int (m_abs_tol.
numel ());
259 if (abs_tol_len == 1)
261 else if (abs_tol_len == n)
266 (*current_liboctave_error_handler)
267 (
"lsode: inconsistent sizes for state and absolute tolerance vectors");
273 double iss = initial_step_size ();
280 double maxss = maximum_step_size ();
287 double minss = minimum_step_size ();
294 F77_INT sl = octave::to_f77_int (step_limit ());
301 LSODE_options::m_reset =
false;
306 double *pabs_tol = m_abs_tol.
rwdata ();
309 double *prwork = m_rwork.
rwdata ();
314 pabs_tol, m_itask, tmp_istate, m_iopt, prwork,
315 m_lrw, piwork, m_liw, lsode_j, m_method_flag));
341 (*current_liboctave_error_handler)
342 (
"unrecognized value of istate (= %" OCTAVE_IDX_TYPE_FORMAT
") "
355 std::ostringstream buf;
357 std::string t_curr = buf.str ();
362 retval =
"prior to initial integration step";
366 retval =
"successful exit";
370 retval =
"prior to continuation call with modified parameters";
374 retval =
"excess work on this call (t = " + t_curr +
375 "; perhaps wrong integration method)";
379 retval =
"excess accuracy requested (tolerances too small)";
383 retval =
"invalid input detected (see printed message)";
387 retval =
"repeated error test failures (t = " + t_curr +
388 "; check all inputs)";
392 retval =
"repeated convergence failures (t = " + t_curr +
393 "; perhaps bad Jacobian supplied or wrong choice of integration method or tolerances)";
397 retval =
"error weight became zero during problem. (t = " + t_curr +
398 "; solution component i vanished, and atol or atol(i) == 0)";
402 retval =
"return requested in user-supplied function (t = "
407 retval =
"unknown error state";
422 if (n_out > 0 && n > 0)
426 for (
F77_INT i = 0; i < n; i++)
436 for (
F77_INT i = 0; i < n; i++)
437 retval.
elem (j, i) = x_next.
elem (i);
452 if (n_out > 0 && n > 0)
456 for (
F77_INT i = 0; i < n; i++)
465 double next_crit = tcrit.
elem (0);
467 while (i_out < n_out)
469 bool do_restart =
false;
471 next_out = tout.
elem (i_out);
473 next_crit = tcrit.
elem (i_crit);
475 bool save_output =
false;
478 if (next_crit == next_out)
487 else if (next_crit < next_out)
520 for (
F77_INT i = 0; i < n; i++)
521 retval.
elem (i_out-1, i) = x_next.
elem (i);
F77_INT(* lsode_jac_ptr)(const F77_INT &, const double &, double *, const F77_INT &, const F77_INT &, double *, const F77_INT &)
F77_INT(* lsode_fcn_ptr)(const F77_INT &, const double &, double *, double *, F77_INT &)
F77_RET_T F77_FUNC(dlsode, DLSODE)(lsode_fcn_ptr
N Dimensional Array with copy-on-write semantics.
T & elem(octave_idx_type n)
Size of the specified dimension.
void resize(const dim_vector &dv, const T &rfv)
Size of the specified dimension.
bool isempty() const
Size of the specified dimension.
T * rwdata()
Size of the specified dimension.
octave_idx_type numel() const
Number of elements in the array.
std::string error_message() const
ColumnVector do_integrate(double t)
void resize(octave_idx_type nr, octave_idx_type nc, double rfv=0)
ColumnVector(* ODERHSFunc)(const ColumnVector &, double)
Matrix(* ODEJacFunc)(const ColumnVector &, double)
ODERHSFunc function() const
ODEJacFunc jacobian_function() const
virtual void force_restart()
octave_idx_type size() const
void set_stop_time(double tt)
Vector representing the dimensions (size) of an Array.
subroutine dlsode(f, neq, y, t, tout, itol, rtol, atol, itask, istate, iopt, rwork, lrw, iwork, liw, jac, mf)
#define F77_XFCN(f, F, args)
octave_f77_int_type F77_INT
F77_RET_T(F77_CONST_CHAR_ARG_DECL, F77_CONST_CHAR_ARG_DECL, F77_CONST_CHAR_ARG_DECL, const F77_INT &, const F77_INT &, const F77_INT &, F77_INT &, F77_INT &, F77_DBLE *, const F77_INT &, F77_DBLE *, const F77_INT &, F77_DBLE *, F77_DBLE *, F77_DBLE *, const F77_INT &, F77_DBLE *, const F77_INT &, F77_DBLE *, const F77_INT &, F77_DBLE *, F77_INT *, F77_INT &F77_CHAR_ARG_LEN_DECL F77_CHAR_ARG_LEN_DECL F77_CHAR_ARG_LEN_DECL)
F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE const F77_INT F77_INT & ierr