cvode.h 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795
  1. /*
  2. * -----------------------------------------------------------------
  3. * $Revision: 4378 $
  4. * $Date: 2015-02-19 10:55:14 -0800 (Thu, 19 Feb 2015) $
  5. * -----------------------------------------------------------------
  6. * Programmer(s): Scott D. Cohen, Alan C. Hindmarsh, Radu Serban
  7. * and Dan Shumaker @ LLNL
  8. * -----------------------------------------------------------------
  9. * LLNS Copyright Start
  10. * Copyright (c) 2014, Lawrence Livermore National Security
  11. * This work was performed under the auspices of the U.S. Department
  12. * of Energy by Lawrence Livermore National Laboratory in part under
  13. * Contract W-7405-Eng-48 and in part under Contract DE-AC52-07NA27344.
  14. * Produced at the Lawrence Livermore National Laboratory.
  15. * All rights reserved.
  16. * For details, see the LICENSE file.
  17. * LLNS Copyright End
  18. * -----------------------------------------------------------------
  19. * This is the interface file for the main CVODE integrator.
  20. * -----------------------------------------------------------------
  21. *
  22. * CVODE is used to solve numerically the ordinary initial value
  23. * problem:
  24. *
  25. * y' = f(t,y),
  26. * y(t0) = y0,
  27. *
  28. * where t0, y0 in R^N, and f: R x R^N -> R^N are given.
  29. *
  30. * -----------------------------------------------------------------
  31. */
  32. #ifndef _CVODE_H
  33. #define _CVODE_H
  34. #include <stdio.h>
  35. #include <sundials/sundials_nvector.h>
  36. #ifdef __cplusplus /* wrapper to enable C++ usage */
  37. extern "C" {
  38. #endif
  39. /*
  40. * =================================================================
  41. * C V O D E C O N S T A N T S
  42. * =================================================================
  43. */
  44. /*
  45. * -----------------------------------------------------------------
  46. * Enumerations for inputs to CVodeCreate and CVode.
  47. * -----------------------------------------------------------------
  48. * Symbolic constants for the lmm and iter parameters to CVodeCreate
  49. * and the input parameter itask to CVode, are given below.
  50. *
  51. * lmm: The user of the CVODE package specifies whether to use the
  52. * CV_ADAMS (Adams-Moulton) or CV_BDF (Backward Differentiation
  53. * Formula) linear multistep method. The BDF method is
  54. * recommended for stiff problems, and the CV_ADAMS method is
  55. * recommended for nonstiff problems.
  56. *
  57. * iter: At each internal time step, a nonlinear equation must
  58. * be solved. The user can specify either CV_FUNCTIONAL
  59. * iteration, which does not require linear algebra, or a
  60. * CV_NEWTON iteration, which requires the solution of linear
  61. * systems. In the CV_NEWTON case, the user also specifies a
  62. * CVODE linear solver. CV_NEWTON is recommended in case of
  63. * stiff problems.
  64. *
  65. * itask: The itask input parameter to CVode indicates the job
  66. * of the solver for the next user step. The CV_NORMAL
  67. * itask is to have the solver take internal steps until
  68. * it has reached or just passed the user specified tout
  69. * parameter. The solver then interpolates in order to
  70. * return an approximate value of y(tout). The CV_ONE_STEP
  71. * option tells the solver to just take one internal step
  72. * and return the solution at the point reached by that step.
  73. * -----------------------------------------------------------------
  74. */
  75. /* lmm */
  76. #define CV_ADAMS 1
  77. #define CV_BDF 2
  78. /* iter */
  79. #define CV_FUNCTIONAL 1
  80. #define CV_NEWTON 2
  81. /* itask */
  82. #define CV_NORMAL 1
  83. #define CV_ONE_STEP 2
  84. /*
  85. * ----------------------------------------
  86. * CVODE return flags
  87. * ----------------------------------------
  88. */
  89. #define CV_SUCCESS 0
  90. #define CV_TSTOP_RETURN 1
  91. #define CV_ROOT_RETURN 2
  92. #define CV_WARNING 99
  93. #define CV_TOO_MUCH_WORK -1
  94. #define CV_TOO_MUCH_ACC -2
  95. #define CV_ERR_FAILURE -3
  96. #define CV_CONV_FAILURE -4
  97. #define CV_LINIT_FAIL -5
  98. #define CV_LSETUP_FAIL -6
  99. #define CV_LSOLVE_FAIL -7
  100. #define CV_RHSFUNC_FAIL -8
  101. #define CV_FIRST_RHSFUNC_ERR -9
  102. #define CV_REPTD_RHSFUNC_ERR -10
  103. #define CV_UNREC_RHSFUNC_ERR -11
  104. #define CV_RTFUNC_FAIL -12
  105. #define CV_MEM_FAIL -20
  106. #define CV_MEM_NULL -21
  107. #define CV_ILL_INPUT -22
  108. #define CV_NO_MALLOC -23
  109. #define CV_BAD_K -24
  110. #define CV_BAD_T -25
  111. #define CV_BAD_DKY -26
  112. #define CV_TOO_CLOSE -27
  113. /*
  114. * =================================================================
  115. * F U N C T I O N T Y P E S
  116. * =================================================================
  117. */
  118. /*
  119. * -----------------------------------------------------------------
  120. * Type : CVRhsFn
  121. * -----------------------------------------------------------------
  122. * The f function which defines the right hand side of the ODE
  123. * system y' = f(t,y) must have type CVRhsFn.
  124. * f takes as input the independent variable value t, and the
  125. * dependent variable vector y. It stores the result of f(t,y)
  126. * in the vector ydot. The y and ydot arguments are of type
  127. * N_Vector.
  128. * (Allocation of memory for ydot is handled within CVODE)
  129. * The user_data parameter is the same as the user_data
  130. * parameter set by the user through the CVodeSetUserData routine.
  131. * This user-supplied pointer is passed to the user's f function
  132. * every time it is called.
  133. *
  134. * A CVRhsFn should return 0 if successful, a negative value if
  135. * an unrecoverable error occured, and a positive value if a
  136. * recoverable error (e.g. invalid y values) occured.
  137. * If an unrecoverable occured, the integration is halted.
  138. * If a recoverable error occured, then (in most cases) CVODE
  139. * will try to correct and retry.
  140. * -----------------------------------------------------------------
  141. */
  142. typedef int (*CVRhsFn)(realtype t, N_Vector y,
  143. N_Vector ydot, void *user_data);
  144. /*
  145. * -----------------------------------------------------------------
  146. * Type : CVRootFn
  147. * -----------------------------------------------------------------
  148. * A function g, which defines a set of functions g_i(t,y) whose
  149. * roots are sought during the integration, must have type CVRootFn.
  150. * The function g takes as input the independent variable value
  151. * t, and the dependent variable vector y. It stores the nrtfn
  152. * values g_i(t,y) in the realtype array gout.
  153. * (Allocation of memory for gout is handled within CVODE.)
  154. * The user_data parameter is the same as that passed by the user
  155. * to the CVodeSetUserData routine. This user-supplied pointer is
  156. * passed to the user's g function every time it is called.
  157. *
  158. * A CVRootFn should return 0 if successful or a non-zero value
  159. * if an error occured (in which case the integration will be halted).
  160. * -----------------------------------------------------------------
  161. */
  162. typedef int (*CVRootFn)(realtype t, N_Vector y, realtype *gout, void *user_data);
  163. /*
  164. * -----------------------------------------------------------------
  165. * Type : CVEwtFn
  166. * -----------------------------------------------------------------
  167. * A function e, which sets the error weight vector ewt, must have
  168. * type CVEwtFn.
  169. * The function e takes as input the current dependent variable y.
  170. * It must set the vector of error weights used in the WRMS norm:
  171. *
  172. * ||y||_WRMS = sqrt [ 1/N * sum ( ewt_i * y_i)^2 ]
  173. *
  174. * Typically, the vector ewt has components:
  175. *
  176. * ewt_i = 1 / (reltol * |y_i| + abstol_i)
  177. *
  178. * The user_data parameter is the same as that passed by the user
  179. * to the CVodeSetUserData routine. This user-supplied pointer is
  180. * passed to the user's e function every time it is called.
  181. * A CVEwtFn e must return 0 if the error weight vector has been
  182. * successfuly set and a non-zero value otherwise.
  183. * -----------------------------------------------------------------
  184. */
  185. typedef int (*CVEwtFn)(N_Vector y, N_Vector ewt, void *user_data);
  186. /*
  187. * -----------------------------------------------------------------
  188. * Type : CVErrHandlerFn
  189. * -----------------------------------------------------------------
  190. * A function eh, which handles error messages, must have type
  191. * CVErrHandlerFn.
  192. * The function eh takes as input the error code, the name of the
  193. * module reporting the error, the error message, and a pointer to
  194. * user data, the same as that passed to CVodeSetUserData.
  195. *
  196. * All error codes are negative, except CV_WARNING which indicates
  197. * a warning (the solver continues).
  198. *
  199. * A CVErrHandlerFn has no return value.
  200. * -----------------------------------------------------------------
  201. */
  202. typedef void (*CVErrHandlerFn)(int error_code,
  203. const char *module, const char *function,
  204. char *msg, void *user_data);
  205. /*
  206. * =================================================================
  207. * U S E R - C A L L A B L E R O U T I N E S
  208. * =================================================================
  209. */
  210. /*
  211. * -----------------------------------------------------------------
  212. * Function : CVodeCreate
  213. * -----------------------------------------------------------------
  214. * CVodeCreate creates an internal memory block for a problem to
  215. * be solved by CVODE.
  216. *
  217. * lmm is the type of linear multistep method to be used.
  218. * The legal values are CV_ADAMS and CV_BDF (see previous
  219. * description).
  220. *
  221. * iter is the type of iteration used to solve the nonlinear
  222. * system that arises during each internal time step.
  223. * The legal values are CV_FUNCTIONAL and CV_NEWTON.
  224. *
  225. * If successful, CVodeCreate returns a pointer to initialized
  226. * problem memory. This pointer should be passed to CVodeInit.
  227. * If an initialization error occurs, CVodeCreate prints an error
  228. * message to standard err and returns NULL.
  229. * -----------------------------------------------------------------
  230. */
  231. SUNDIALS_EXPORT void *CVodeCreate(int lmm, int iter);
  232. /*
  233. * -----------------------------------------------------------------
  234. * Integrator optional input specification functions
  235. * -----------------------------------------------------------------
  236. * The following functions can be called to set optional inputs
  237. * to values other than the defaults given below:
  238. *
  239. * Function | Optional input / [ default value ]
  240. * -----------------------------------------------------------------
  241. * |
  242. * CVodeSetErrHandlerFn | user-provided ErrHandler function.
  243. * | [internal]
  244. * |
  245. * CVodeSetErrFile | the file pointer for an error file
  246. * | where all CVODE warning and error
  247. * | messages will be written if the default
  248. * | internal error handling function is used.
  249. * | This parameter can be stdout (standard
  250. * | output), stderr (standard error), or a
  251. * | file pointer (corresponding to a user
  252. * | error file opened for writing) returned
  253. * | by fopen.
  254. * | If not called, then all messages will
  255. * | be written to the standard error stream.
  256. * | [stderr]
  257. * |
  258. * CVodeSetUserData | a pointer to user data that will be
  259. * | passed to the user's f function every
  260. * | time f is called.
  261. * | [NULL]
  262. * |
  263. * CVodeSetMaxOrd | maximum lmm order to be used by the
  264. * | solver.
  265. * | [12 for Adams , 5 for BDF]
  266. * |
  267. * CVodeSetMaxNumSteps | maximum number of internal steps to be
  268. * | taken by the solver in its attempt to
  269. * | reach tout.
  270. * | [500]
  271. * |
  272. * CVodeSetMaxHnilWarns | maximum number of warning messages
  273. * | issued by the solver that t+h==t on the
  274. * | next internal step. A value of -1 means
  275. * | no such messages are issued.
  276. * | [10]
  277. * |
  278. * CVodeSetStabLimDet | flag to turn on/off stability limit
  279. * | detection (TRUE = on, FALSE = off).
  280. * | When BDF is used and order is 3 or
  281. * | greater, CVsldet is called to detect
  282. * | stability limit. If limit is detected,
  283. * | the order is reduced.
  284. * | [FALSE]
  285. * |
  286. * CVodeSetInitStep | initial step size.
  287. * | [estimated by CVODE]
  288. * |
  289. * CVodeSetMinStep | minimum absolute value of step size
  290. * | allowed.
  291. * | [0.0]
  292. * |
  293. * CVodeSetMaxStep | maximum absolute value of step size
  294. * | allowed.
  295. * | [infinity]
  296. * |
  297. * CVodeSetStopTime | the independent variable value past
  298. * | which the solution is not to proceed.
  299. * | [infinity]
  300. * |
  301. * CVodeSetMaxErrTestFails | Maximum number of error test failures
  302. * | in attempting one step.
  303. * | [7]
  304. * |
  305. * CVodeSetMaxNonlinIters | Maximum number of nonlinear solver
  306. * | iterations at one solution.
  307. * | [3]
  308. * |
  309. * CVodeSetMaxConvFails | Maximum number of convergence failures
  310. * | allowed in attempting one step.
  311. * | [10]
  312. * |
  313. * CVodeSetNonlinConvCoef | Coefficient in the nonlinear
  314. * | convergence test.
  315. * | [0.1]
  316. * |
  317. * -----------------------------------------------------------------
  318. * |
  319. * CVodeSetIterType | Changes the current nonlinear iteration
  320. * | type.
  321. * | [set by CVodecreate]
  322. * |
  323. * -----------------------------------------------------------------
  324. * |
  325. * CVodeSetRootDirection | Specifies the direction of zero
  326. * | crossings to be monitored
  327. * | [both directions]
  328. * |
  329. * CVodeSetNoInactiveRootWarn | disable warning about possible
  330. * | g==0 at beginning of integration
  331. * |
  332. * -----------------------------------------------------------------
  333. * -----------------------------------------------------------------
  334. * Return flag:
  335. * CV_SUCCESS if successful
  336. * CV_MEM_NULL if the cvode memory is NULL
  337. * CV_ILL_INPUT if an argument has an illegal value
  338. * -----------------------------------------------------------------
  339. */
  340. SUNDIALS_EXPORT int CVodeSetErrHandlerFn(void *cvode_mem, CVErrHandlerFn ehfun, void *eh_data);
  341. SUNDIALS_EXPORT int CVodeSetErrFile(void *cvode_mem, FILE *errfp);
  342. SUNDIALS_EXPORT int CVodeSetUserData(void *cvode_mem, void *user_data);
  343. SUNDIALS_EXPORT int CVodeSetMaxOrd(void *cvode_mem, int maxord);
  344. SUNDIALS_EXPORT int CVodeSetMaxNumSteps(void *cvode_mem, long int mxsteps);
  345. SUNDIALS_EXPORT int CVodeSetMaxHnilWarns(void *cvode_mem, int mxhnil);
  346. SUNDIALS_EXPORT int CVodeSetStabLimDet(void *cvode_mem, booleantype stldet);
  347. SUNDIALS_EXPORT int CVodeSetInitStep(void *cvode_mem, realtype hin);
  348. SUNDIALS_EXPORT int CVodeSetMinStep(void *cvode_mem, realtype hmin);
  349. SUNDIALS_EXPORT int CVodeSetMaxStep(void *cvode_mem, realtype hmax);
  350. SUNDIALS_EXPORT int CVodeSetStopTime(void *cvode_mem, realtype tstop);
  351. SUNDIALS_EXPORT int CVodeSetMaxErrTestFails(void *cvode_mem, int maxnef);
  352. SUNDIALS_EXPORT int CVodeSetMaxNonlinIters(void *cvode_mem, int maxcor);
  353. SUNDIALS_EXPORT int CVodeSetMaxConvFails(void *cvode_mem, int maxncf);
  354. SUNDIALS_EXPORT int CVodeSetNonlinConvCoef(void *cvode_mem, realtype nlscoef);
  355. SUNDIALS_EXPORT int CVodeSetIterType(void *cvode_mem, int iter);
  356. SUNDIALS_EXPORT int CVodeSetRootDirection(void *cvode_mem, int *rootdir);
  357. SUNDIALS_EXPORT int CVodeSetNoInactiveRootWarn(void *cvode_mem);
  358. /*
  359. * -----------------------------------------------------------------
  360. * Function : CVodeInit
  361. * -----------------------------------------------------------------
  362. * CVodeInit allocates and initializes memory for a problem to
  363. * to be solved by CVODE.
  364. *
  365. * cvode_mem is pointer to CVODE memory returned by CVodeCreate.
  366. *
  367. * f is the name of the C function defining the right-hand
  368. * side function in y' = f(t,y).
  369. *
  370. * t0 is the initial value of t.
  371. *
  372. * y0 is the initial condition vector y(t0).
  373. *
  374. * Return flag:
  375. * CV_SUCCESS if successful
  376. * CV_MEM_NULL if the cvode memory was NULL
  377. * CV_MEM_FAIL if a memory allocation failed
  378. * CV_ILL_INPUT f an argument has an illegal value.
  379. * -----------------------------------------------------------------
  380. */
  381. SUNDIALS_EXPORT int CVodeInit(void *cvode_mem, CVRhsFn f, realtype t0, N_Vector y0);
  382. /*
  383. * -----------------------------------------------------------------
  384. * Function : CVodeReInit
  385. * -----------------------------------------------------------------
  386. * CVodeReInit re-initializes CVode for the solution of a problem,
  387. * where a prior call to CVodeInit has been made with the same
  388. * problem size N. CVodeReInit performs the same input checking
  389. * and initializations that CVodeInit does.
  390. * But it does no memory allocation, assuming that the existing
  391. * internal memory is sufficient for the new problem.
  392. *
  393. * The use of CVodeReInit requires that the maximum method order,
  394. * maxord, is no larger for the new problem than for the problem
  395. * specified in the last call to CVodeInit. This condition is
  396. * automatically fulfilled if the multistep method parameter lmm
  397. * is unchanged (or changed from CV_ADAMS to CV_BDF) and the default
  398. * value for maxord is specified.
  399. *
  400. * All of the arguments to CVodeReInit have names and meanings
  401. * identical to those of CVodeInit.
  402. *
  403. * The return value of CVodeReInit is equal to CV_SUCCESS = 0 if
  404. * there were no errors; otherwise it is a negative int equal to:
  405. * CV_MEM_NULL indicating cvode_mem was NULL (i.e.,
  406. * CVodeCreate has not been called).
  407. * CV_NO_MALLOC indicating that cvode_mem has not been
  408. * allocated (i.e., CVodeInit has not been
  409. * called).
  410. * CV_ILL_INPUT indicating an input argument was illegal
  411. * (including an attempt to increase maxord).
  412. * In case of an error return, an error message is also printed.
  413. * -----------------------------------------------------------------
  414. */
  415. SUNDIALS_EXPORT int CVodeReInit(void *cvode_mem, realtype t0, N_Vector y0);
  416. /*
  417. * -----------------------------------------------------------------
  418. * Functions : CVodeSStolerances
  419. * CVodeSVtolerances
  420. * CVodeWFtolerances
  421. * -----------------------------------------------------------------
  422. *
  423. * These functions specify the integration tolerances. One of them
  424. * MUST be called before the first call to CVode.
  425. *
  426. * CVodeSStolerances specifies scalar relative and absolute tolerances.
  427. * CVodeSVtolerances specifies scalar relative tolerance and a vector
  428. * absolute tolerance (a potentially different absolute tolerance
  429. * for each vector component).
  430. * CVodeWFtolerances specifies a user-provides function (of type CVEwtFn)
  431. * which will be called to set the error weight vector.
  432. *
  433. * The tolerances reltol and abstol define a vector of error weights,
  434. * ewt, with components
  435. * ewt[i] = 1/(reltol*abs(y[i]) + abstol) (in the SS case), or
  436. * ewt[i] = 1/(reltol*abs(y[i]) + abstol[i]) (in the SV case).
  437. * This vector is used in all error and convergence tests, which
  438. * use a weighted RMS norm on all error-like vectors v:
  439. * WRMSnorm(v) = sqrt( (1/N) sum(i=1..N) (v[i]*ewt[i])^2 ),
  440. * where N is the problem dimension.
  441. *
  442. * The return value of these functions is equal to CV_SUCCESS = 0 if
  443. * there were no errors; otherwise it is a negative int equal to:
  444. * CV_MEM_NULL indicating cvode_mem was NULL (i.e.,
  445. * CVodeCreate has not been called).
  446. * CV_NO_MALLOC indicating that cvode_mem has not been
  447. * allocated (i.e., CVodeInit has not been
  448. * called).
  449. * CV_ILL_INPUT indicating an input argument was illegal
  450. * (e.g. a negative tolerance)
  451. * In case of an error return, an error message is also printed.
  452. * -----------------------------------------------------------------
  453. */
  454. SUNDIALS_EXPORT int CVodeSStolerances(void *cvode_mem, realtype reltol, realtype abstol);
  455. SUNDIALS_EXPORT int CVodeSVtolerances(void *cvode_mem, realtype reltol, N_Vector abstol);
  456. SUNDIALS_EXPORT int CVodeWFtolerances(void *cvode_mem, CVEwtFn efun);
  457. /*
  458. * -----------------------------------------------------------------
  459. * Function : CVodeRootInit
  460. * -----------------------------------------------------------------
  461. * CVodeRootInit initializes a rootfinding problem to be solved
  462. * during the integration of the ODE system. It must be called
  463. * after CVodeCreate, and before CVode. The arguments are:
  464. *
  465. * cvode_mem = pointer to CVODE memory returned by CVodeCreate.
  466. *
  467. * nrtfn = number of functions g_i, an int >= 0.
  468. *
  469. * g = name of user-supplied function, of type CVRootFn,
  470. * defining the functions g_i whose roots are sought.
  471. *
  472. * If a new problem is to be solved with a call to CVodeReInit,
  473. * where the new problem has no root functions but the prior one
  474. * did, then call CVodeRootInit with nrtfn = 0.
  475. *
  476. * The return value of CVodeRootInit is CV_SUCCESS = 0 if there were
  477. * no errors; otherwise it is a negative int equal to:
  478. * CV_MEM_NULL indicating cvode_mem was NULL, or
  479. * CV_MEM_FAIL indicating a memory allocation failed.
  480. * (including an attempt to increase maxord).
  481. * CV_ILL_INPUT indicating nrtfn > 0 but g = NULL.
  482. * In case of an error return, an error message is also printed.
  483. * -----------------------------------------------------------------
  484. */
  485. SUNDIALS_EXPORT int CVodeRootInit(void *cvode_mem, int nrtfn, CVRootFn g);
  486. /*
  487. * -----------------------------------------------------------------
  488. * Function : CVode
  489. * -----------------------------------------------------------------
  490. * CVode integrates the ODE over an interval in t.
  491. * If itask is CV_NORMAL, then the solver integrates from its
  492. * current internal t value to a point at or beyond tout, then
  493. * interpolates to t = tout and returns y(tout) in the user-
  494. * allocated vector yout. If itask is CV_ONE_STEP, then the solver
  495. * takes one internal time step and returns in yout the value of
  496. * y at the new internal time. In this case, tout is used only
  497. * during the first call to CVode to determine the direction of
  498. * integration and the rough scale of the t variable. If tstop is
  499. * enabled (through a call to CVodeSetStopTime), then CVode returns
  500. * the solution at tstop. Once the integrator returns at a tstop
  501. * time, any future testing for tstop is disabled (and can be
  502. * reenabled only though a new call to CVodeSetStopTime).
  503. * The time reached by the solver is placed in (*tret). The
  504. * user is responsible for allocating the memory for this value.
  505. *
  506. * cvode_mem is the pointer to CVODE memory returned by
  507. * CVodeCreate.
  508. *
  509. * tout is the next time at which a computed solution is desired.
  510. *
  511. * yout is the computed solution vector. In CV_NORMAL mode with no
  512. * errors and no roots found, yout=y(tout).
  513. *
  514. * tret is a pointer to a real location. CVode sets (*tret) to
  515. * the time reached by the solver and returns
  516. * yout=y(*tret).
  517. *
  518. * itask is CV_NORMAL or CV_ONE_STEP. These two modes are described above.
  519. *
  520. * Here is a brief description of each return value:
  521. *
  522. * CV_SUCCESS: CVode succeeded and no roots were found.
  523. *
  524. * CV_ROOT_RETURN: CVode succeeded, and found one or more roots.
  525. * If nrtfn > 1, call CVodeGetRootInfo to see
  526. * which g_i were found to have a root at (*tret).
  527. *
  528. * CV_TSTOP_RETURN: CVode succeeded and returned at tstop.
  529. *
  530. * CV_MEM_NULL: The cvode_mem argument was NULL.
  531. *
  532. * CV_NO_MALLOC: cvode_mem was not allocated.
  533. *
  534. * CV_ILL_INPUT: One of the inputs to CVode is illegal. This
  535. * includes the situation when a component of the
  536. * error weight vectors becomes < 0 during
  537. * internal time-stepping. It also includes the
  538. * situation where a root of one of the root
  539. * functions was found both at t0 and very near t0.
  540. * The ILL_INPUT flag will also be returned if the
  541. * linear solver routine CV--- (called by the user
  542. * after calling CVodeCreate) failed to set one of
  543. * the linear solver-related fields in cvode_mem or
  544. * if the linear solver's init routine failed. In
  545. * any case, the user should see the printed
  546. * error message for more details.
  547. *
  548. * CV_TOO_MUCH_WORK: The solver took mxstep internal steps but
  549. * could not reach tout. The default value for
  550. * mxstep is MXSTEP_DEFAULT = 500.
  551. *
  552. * CV_TOO_MUCH_ACC: The solver could not satisfy the accuracy
  553. * demanded by the user for some internal step.
  554. *
  555. * CV_ERR_FAILURE: Error test failures occurred too many times
  556. * (= MXNEF = 7) during one internal time step or
  557. * occurred with |h| = hmin.
  558. *
  559. * CV_CONV_FAILURE: Convergence test failures occurred too many
  560. * times (= MXNCF = 10) during one internal time
  561. * step or occurred with |h| = hmin.
  562. *
  563. * CV_LINIT_FAIL: The linear solver's initialization function
  564. * failed.
  565. *
  566. * CV_LSETUP_FAIL: The linear solver's setup routine failed in an
  567. * unrecoverable manner.
  568. *
  569. * CV_LSOLVE_FAIL: The linear solver's solve routine failed in an
  570. * unrecoverable manner.
  571. * -----------------------------------------------------------------
  572. */
  573. SUNDIALS_EXPORT int CVode(void *cvode_mem, realtype tout, N_Vector yout,
  574. realtype *tret, int itask);
  575. /*
  576. * -----------------------------------------------------------------
  577. * Function : CVodeGetDky
  578. * -----------------------------------------------------------------
  579. * CVodeGetDky computes the kth derivative of the y function at
  580. * time t, where tn-hu <= t <= tn, tn denotes the current
  581. * internal time reached, and hu is the last internal step size
  582. * successfully used by the solver. The user may request
  583. * k=0, 1, ..., qu, where qu is the order last used. The
  584. * derivative vector is returned in dky. This vector must be
  585. * allocated by the caller. It is only legal to call this
  586. * function after a successful return from CVode.
  587. *
  588. * cvode_mem is the pointer to CVODE memory returned by
  589. * CVodeCreate.
  590. *
  591. * t is the time at which the kth derivative of y is evaluated.
  592. * The legal range for t is [tn-hu,tn] as described above.
  593. *
  594. * k is the order of the derivative of y to be computed. The
  595. * legal range for k is [0,qu] as described above.
  596. *
  597. * dky is the output derivative vector [((d/dy)^k)y](t).
  598. *
  599. * The return value for CVodeGetDky is one of:
  600. *
  601. * CV_SUCCESS: CVodeGetDky succeeded.
  602. *
  603. * CV_BAD_K: k is not in the range 0, 1, ..., qu.
  604. *
  605. * CV_BAD_T: t is not in the interval [tn-hu,tn].
  606. *
  607. * CV_BAD_DKY: The dky argument was NULL.
  608. *
  609. * CV_MEM_NULL: The cvode_mem argument was NULL.
  610. * -----------------------------------------------------------------
  611. */
  612. SUNDIALS_EXPORT int CVodeGetDky(void *cvode_mem, realtype t, int k, N_Vector dky);
  613. /*
  614. * -----------------------------------------------------------------
  615. * Integrator optional output extraction functions
  616. * -----------------------------------------------------------------
  617. * The following functions can be called to get optional outputs
  618. * and statistics related to the main integrator.
  619. * -----------------------------------------------------------------
  620. * CVodeGetWorkSpace returns the CVODE real and integer workspaces
  621. * CVodeGetNumSteps returns the cumulative number of internal
  622. * steps taken by the solver
  623. * CVodeGetNumRhsEvals returns the number of calls to the user's
  624. * f function
  625. * CVodeGetNumLinSolvSetups returns the number of calls made to
  626. * the linear solver's setup routine
  627. * CVodeGetNumErrTestFails returns the number of local error test
  628. * failures that have occured
  629. * CVodeGetLastOrder returns the order used during the last
  630. * internal step
  631. * CVodeGetCurrentOrder returns the order to be used on the next
  632. * internal step
  633. * CVodeGetNumStabLimOrderReds returns the number of order
  634. * reductions due to stability limit
  635. * detection
  636. * CVodeGetActualInitStep returns the actual initial step size
  637. * used by CVODE
  638. * CVodeGetLastStep returns the step size for the last internal
  639. * step
  640. * CVodeGetCurrentStep returns the step size to be attempted on
  641. * the next internal step
  642. * CVodeGetCurrentTime returns the current internal time reached
  643. * by the solver
  644. * CVodeGetTolScaleFactor returns a suggested factor by which the
  645. * user's tolerances should be scaled when
  646. * too much accuracy has been requested for
  647. * some internal step
  648. * CVodeGetErrWeights returns the current error weight vector.
  649. * The user must allocate space for eweight.
  650. * CVodeGetEstLocalErrors returns the vector of estimated local
  651. * errors. The user must allocate space
  652. * for ele.
  653. * CVodeGetNumGEvals returns the number of calls to the user's
  654. * g function (for rootfinding)
  655. * CVodeGetRootInfo returns the indices for which g_i was found to
  656. * have a root. The user must allocate space for
  657. * rootsfound. For i = 0 ... nrtfn-1,
  658. * rootsfound[i] = 1 if g_i has a root, and = 0 if not.
  659. *
  660. * CVodeGet* return values:
  661. * CV_SUCCESS if succesful
  662. * CV_MEM_NULL if the cvode memory was NULL
  663. * CV_NO_SLDET if stability limit was not turned on
  664. * -----------------------------------------------------------------
  665. */
  666. SUNDIALS_EXPORT int CVodeGetWorkSpace(void *cvode_mem, long int *lenrw, long int *leniw);
  667. SUNDIALS_EXPORT int CVodeGetNumSteps(void *cvode_mem, long int *nsteps);
  668. SUNDIALS_EXPORT int CVodeGetNumRhsEvals(void *cvode_mem, long int *nfevals);
  669. SUNDIALS_EXPORT int CVodeGetNumLinSolvSetups(void *cvode_mem, long int *nlinsetups);
  670. SUNDIALS_EXPORT int CVodeGetNumErrTestFails(void *cvode_mem, long int *netfails);
  671. SUNDIALS_EXPORT int CVodeGetLastOrder(void *cvode_mem, int *qlast);
  672. SUNDIALS_EXPORT int CVodeGetCurrentOrder(void *cvode_mem, int *qcur);
  673. SUNDIALS_EXPORT int CVodeGetNumStabLimOrderReds(void *cvode_mem, long int *nslred);
  674. SUNDIALS_EXPORT int CVodeGetActualInitStep(void *cvode_mem, realtype *hinused);
  675. SUNDIALS_EXPORT int CVodeGetLastStep(void *cvode_mem, realtype *hlast);
  676. SUNDIALS_EXPORT int CVodeGetCurrentStep(void *cvode_mem, realtype *hcur);
  677. SUNDIALS_EXPORT int CVodeGetCurrentTime(void *cvode_mem, realtype *tcur);
  678. SUNDIALS_EXPORT int CVodeGetTolScaleFactor(void *cvode_mem, realtype *tolsfac);
  679. SUNDIALS_EXPORT int CVodeGetErrWeights(void *cvode_mem, N_Vector eweight);
  680. SUNDIALS_EXPORT int CVodeGetEstLocalErrors(void *cvode_mem, N_Vector ele);
  681. SUNDIALS_EXPORT int CVodeGetNumGEvals(void *cvode_mem, long int *ngevals);
  682. SUNDIALS_EXPORT int CVodeGetRootInfo(void *cvode_mem, int *rootsfound);
  683. /*
  684. * -----------------------------------------------------------------
  685. * As a convenience, the following functions provides the
  686. * optional outputs in one group.
  687. * -----------------------------------------------------------------
  688. */
  689. SUNDIALS_EXPORT int CVodeGetIntegratorStats(void *cvode_mem, long int *nsteps,
  690. long int *nfevals, long int *nlinsetups,
  691. long int *netfails, int *qlast,
  692. int *qcur, realtype *hinused, realtype *hlast,
  693. realtype *hcur, realtype *tcur);
  694. /*
  695. * -----------------------------------------------------------------
  696. * Nonlinear solver optional output extraction functions
  697. * -----------------------------------------------------------------
  698. * The following functions can be called to get optional outputs
  699. * and statistics related to the nonlinear solver.
  700. * -----------------------------------------------------------------
  701. * CVodeGetNumNonlinSolvIters returns the number of nonlinear
  702. * solver iterations performed.
  703. * CVodeGetNumNonlinSolvConvFails returns the number of nonlinear
  704. * convergence failures.
  705. * -----------------------------------------------------------------
  706. */
  707. SUNDIALS_EXPORT int CVodeGetNumNonlinSolvIters(void *cvode_mem, long int *nniters);
  708. SUNDIALS_EXPORT int CVodeGetNumNonlinSolvConvFails(void *cvode_mem, long int *nncfails);
  709. /*
  710. * -----------------------------------------------------------------
  711. * As a convenience, the following function provides the
  712. * nonlinear solver optional outputs in a group.
  713. * -----------------------------------------------------------------
  714. */
  715. SUNDIALS_EXPORT int CVodeGetNonlinSolvStats(void *cvode_mem, long int *nniters,
  716. long int *nncfails);
  717. /*
  718. * -----------------------------------------------------------------
  719. * The following function returns the name of the constant
  720. * associated with a CVODE return flag
  721. * -----------------------------------------------------------------
  722. */
  723. SUNDIALS_EXPORT char *CVodeGetReturnFlagName(long int flag);
  724. /*
  725. * -----------------------------------------------------------------
  726. * Function : CVodeFree
  727. * -----------------------------------------------------------------
  728. * CVodeFree frees the problem memory cvode_mem allocated by
  729. * CVodeCreate and CVodeInit. Its only argument is the pointer
  730. * cvode_mem returned by CVodeCreate.
  731. * -----------------------------------------------------------------
  732. */
  733. SUNDIALS_EXPORT void CVodeFree(void **cvode_mem);
  734. #ifdef __cplusplus
  735. }
  736. #endif
  737. #endif