Automatic Differentiation
 
Loading...
Searching...
No Matches

◆ kinsol_solve()

template<typename F1 , typename... Args>
Eigen::VectorXd stan::math::kinsol_solve ( const F1 &  f,
const Eigen::VectorXd &  x,
const double  scaling_step_tol,
const double  function_tolerance,
const int64_t  max_num_steps,
const bool  custom_jacobian,
const int  steps_eval_jacobian,
const int  global_line_search,
std::ostream *const  msgs,
const Args &...  args 
)

Return the solution to the specified algebraic system, given an initial guess.

Invokes the Kinsol solver from Sundials.

Template Parameters
Ftype of equation system function.
Ttype of initial guess vector.
Parameters
[in]fFunctor that evaluated the system of equations.
[in]xVector of starting values.
[in]yParameter vector for the equation system. The function is overloaded to treat y as a vector of doubles or of a a template type T.
[in]datContinuous data vector for the equation system.
[in]dat_intInteger data vector for the equation system.
[in,out]msgsThe print stream for warning messages.
[in]scaling_step_tolScaled-step stopping tolerance. If a Newton step is smaller than the scaling step tolerance, the code breaks, assuming the solver is no longer making significant progress (i.e. is stuck)
[in]function_tolerancedetermines whether roots are acceptable.
[in]max_num_stepsMaximum number of function evaluations.
[in]custom_jacobianIf 0, use Kinsol's default to compute the jacobian for the Newton step, namely Quotient Difference (finite difference). If 1, use reverse-mode AD, unless the user specifies their own method.
[in]J_fA functor that computes the Jacobian for the Newton step. Defaults to reverse-mode AD.
[in]steps_eval_jacobianMaximum number of steps before the Jacobian gets recomputed. Note that Kinsol's default is 10. If equal to 1, the algorithm computes exact Newton steps.
[in]global_line_searchdoes the solver use a global line search? If equal to KIN_NONE, no, if KIN_LINESEARCH, yes.
[in,out]msgsthe print stream for warning messages
argsExtra arguments passed unmodified through to DAE right hand side
Exceptions
<code>std::invalid_argument</code>if Kinsol returns a negative flag when setting up the solver.
<code>std::domain_error</code>if Kinsol fails to solve equation in max_num_steps iterations.
<code>std::runtime_error</code>if Kinsol returns a negative flag that is not due to hitting max_num_steps.

Definition at line 61 of file kinsol_solve.hpp.