3#include <kinsol/kinsol.h>
4#include <nvector/nvector_serial.h>
5#include <sunmatrix/sunmatrix_dense.h>
6#include <sunlinsol/sunlinsol_dense.h>
7#include <sunmatrix/sunmatrix_band.h>
8#include <sunlinsol/sunlinsol_band.h>
9#include <sundials/sundials_types.h>
62 const std::vector<double> &_scales_v,
63 const std::vector<double> &_scales_f,
64 const std::vector<double> &_constraints,
67 const double ftol = 1E-5,
68 const double stol = 1E-5) :
75 rv = SUNContext_Create(NULL, &
sun);
83 J = SUNBandMatrix(
nvar, mu, ml,
sun);
85 for(
size_t k=0; k<
nvar; k++) {
86 NV_Ith_S(
scales_v, k) = _scales_v[k];
87 NV_Ith_S(
scales_f, k) = _scales_f[k];
95 rv = KINSetScaledStepTol(
kmem, stol);
96 rv = KINSetFuncNormTol(
kmem, ftol);
98 rv = KINSetNumMaxIters(
kmem, 5000);
109int solve(
int (*Func)(N_Vector, N_Vector,
void*),
110 std::vector<double> &y) {
114 for(
size_t k=0; k<
nvar; k++)
115 NV_Ith_S(
vars, k) = y[k];
128 for(
size_t k=0; k<
nvar; k++)
129 y[k] = NV_Ith_S(
vars,k);
148 SUNContext_Free(&
sun);
solver_kinsol(void *_user_data, const size_t _nvar, const std::vector< double > &_scales_v, const std::vector< double > &_scales_f, const std::vector< double > &_constraints, const int mu, const int ml, const double ftol=1E-5, const double stol=1E-5)
int solve(int(*Func)(N_Vector, N_Vector, void *), std::vector< double > &y)
N_Vector scales_v
scales for variables being solved: f(v)
size_t nvar
number of variables being solved
N_Vector vars
variables being solved
SUNContext sun
sundials object
void * user_data
pointer to user data/functions
SUNLinearSolver LS
linear solver
int rv
function return value
int exact_or_modified_newton
1 or 0, respectively
int solver_type
KIN_NONE, KIN_LINESEARCH, KIN_FP, KIN_PICARD.
N_Vector constraints
constraints on the scalars (e.g., >0 etc.)
SUNMatrix J
Jacobian matrix.
N_Vector scales_f
scales for functions being solved: f(v)