ida.h 49 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943
  1. /*
  2. * -----------------------------------------------------------------
  3. * $Revision: 4378 $
  4. * $Date: 2015-02-19 10:55:14 -0800 (Thu, 19 Feb 2015) $
  5. * -----------------------------------------------------------------
  6. * Programmer(s): Allan G. Taylor, Alan C. Hindmarsh, Radu Serban,
  7. * and Aaron Collier @ 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 header (include) file for the main IDA solver.
  20. * -----------------------------------------------------------------
  21. *
  22. * IDA is used to solve numerically the initial value problem
  23. * for the differential algebraic equation (DAE) system
  24. * F(t,y,y') = 0,
  25. * given initial conditions
  26. * y(t0) = y0, y'(t0) = yp0.
  27. * Here y and F are vectors of length N.
  28. *
  29. * -----------------------------------------------------------------
  30. */
  31. #ifndef _IDA_H
  32. #define _IDA_H
  33. #include <stdio.h>
  34. #include <sundials/sundials_nvector.h>
  35. #ifdef __cplusplus /* wrapper to enable C++ usage */
  36. extern "C" {
  37. #endif
  38. /*
  39. * =================================================================
  40. * I D A C O N S T A N T S
  41. * =================================================================
  42. */
  43. /*
  44. * ----------------------------------------------------------------
  45. * Inputs to IDAInit, IDAReInit, IDACalcIC, and IDASolve.
  46. * ----------------------------------------------------------------
  47. */
  48. /* itask */
  49. #define IDA_NORMAL 1
  50. #define IDA_ONE_STEP 2
  51. /* icopt */
  52. #define IDA_YA_YDP_INIT 1
  53. #define IDA_Y_INIT 2
  54. /*
  55. * ----------------------------------------
  56. * IDA return flags
  57. * ----------------------------------------
  58. */
  59. #define IDA_SUCCESS 0
  60. #define IDA_TSTOP_RETURN 1
  61. #define IDA_ROOT_RETURN 2
  62. #define IDA_WARNING 99
  63. #define IDA_TOO_MUCH_WORK -1
  64. #define IDA_TOO_MUCH_ACC -2
  65. #define IDA_ERR_FAIL -3
  66. #define IDA_CONV_FAIL -4
  67. #define IDA_LINIT_FAIL -5
  68. #define IDA_LSETUP_FAIL -6
  69. #define IDA_LSOLVE_FAIL -7
  70. #define IDA_RES_FAIL -8
  71. #define IDA_REP_RES_ERR -9
  72. #define IDA_RTFUNC_FAIL -10
  73. #define IDA_CONSTR_FAIL -11
  74. #define IDA_FIRST_RES_FAIL -12
  75. #define IDA_LINESEARCH_FAIL -13
  76. #define IDA_NO_RECOVERY -14
  77. #define IDA_MEM_NULL -20
  78. #define IDA_MEM_FAIL -21
  79. #define IDA_ILL_INPUT -22
  80. #define IDA_NO_MALLOC -23
  81. #define IDA_BAD_EWT -24
  82. #define IDA_BAD_K -25
  83. #define IDA_BAD_T -26
  84. #define IDA_BAD_DKY -27
  85. /*
  86. * ----------------------------------------------------------------
  87. * Type : IDAResFn
  88. * ----------------------------------------------------------------
  89. * The F function which defines the DAE system F(t,y,y')=0
  90. * must have type IDAResFn.
  91. * Symbols are as follows:
  92. * t <-> t y <-> yy
  93. * y' <-> yp F <-> rr
  94. * A IDAResFn takes as input the independent variable value t,
  95. * the dependent variable vector yy, and the derivative (with
  96. * respect to t) of the yy vector, yp. It stores the result of
  97. * F(t,y,y') in the vector rr. The yy, yp, and rr arguments are of
  98. * type N_Vector. The user_data parameter is the pointer user_data
  99. * passed by the user to the IDASetUserData routine. This user-supplied
  100. * pointer is passed to the user's res function every time it is called,
  101. * to provide access in res to user data.
  102. *
  103. * A IDAResFn res should return a value of 0 if successful, a positive
  104. * value if a recoverable error occured (e.g. yy has an illegal value),
  105. * or a negative value if a nonrecoverable error occured. In the latter
  106. * case, the program halts. If a recoverable error occured, the integrator
  107. * will attempt to correct and retry.
  108. * ----------------------------------------------------------------
  109. */
  110. typedef int (*IDAResFn)(realtype tt, N_Vector yy, N_Vector yp,
  111. N_Vector rr, void *user_data);
  112. /*
  113. * -----------------------------------------------------------------
  114. * Type : IDARootFn
  115. * -----------------------------------------------------------------
  116. * A function g, which defines a set of functions g_i(t,y,y') whose
  117. * roots are sought during the integration, must have type IDARootFn.
  118. * The function g takes as input the independent variable value t,
  119. * the dependent variable vector y, and its t-derivative yp (= y').
  120. * It stores the nrtfn values g_i(t,y,y') in the realtype array gout.
  121. * (Allocation of memory for gout is handled within IDA.)
  122. * The user_data parameter is the same as that passed by the user
  123. * to the IDASetUserData routine. This user-supplied pointer is
  124. * passed to the user's g function every time it is called.
  125. *
  126. * An IDARootFn should return 0 if successful or a non-zero value
  127. * if an error occured (in which case the integration will be halted).
  128. * -----------------------------------------------------------------
  129. */
  130. typedef int (*IDARootFn)(realtype t, N_Vector y, N_Vector yp,
  131. realtype *gout, void *user_data);
  132. /*
  133. * -----------------------------------------------------------------
  134. * Type : IDAEwtFn
  135. * -----------------------------------------------------------------
  136. * A function e, which sets the error weight vector ewt, must have
  137. * type IDAEwtFn.
  138. * The function e takes as input the current dependent variable y.
  139. * It must set the vector of error weights used in the WRMS norm:
  140. *
  141. * ||y||_WRMS = sqrt [ 1/N * sum ( ewt_i * y_i)^2 ]
  142. *
  143. * Typically, the vector ewt has components:
  144. *
  145. * ewt_i = 1 / (reltol * |y_i| + abstol_i)
  146. *
  147. * The user_data parameter is the same as that passed by the user
  148. * to the IDASetUserData routine. This user-supplied pointer is
  149. * passed to the user's e function every time it is called.
  150. * An IDAEwtFn e must return 0 if the error weight vector has been
  151. * successfuly set and a non-zero value otherwise.
  152. * -----------------------------------------------------------------
  153. */
  154. typedef int (*IDAEwtFn)(N_Vector y, N_Vector ewt, void *user_data);
  155. /*
  156. * -----------------------------------------------------------------
  157. * Type : IDAErrHandlerFn
  158. * -----------------------------------------------------------------
  159. * A function eh, which handles error messages, must have type
  160. * IDAErrHandlerFn.
  161. * The function eh takes as input the error code, the name of the
  162. * module reporting the error, the error message, and a pointer to
  163. * user data, the same as that passed to IDASetUserData.
  164. *
  165. * All error codes are negative, except IDA_WARNING which indicates
  166. * a warning (the solver continues).
  167. *
  168. * An IDAErrHandlerFn has no return value.
  169. * -----------------------------------------------------------------
  170. */
  171. typedef void (*IDAErrHandlerFn)(int error_code,
  172. const char *module, const char *function,
  173. char *msg, void *user_data);
  174. /*
  175. * ================================================================
  176. * U S E R - C A L L A B L E R O U T I N E S
  177. * ================================================================
  178. */
  179. /*
  180. * ----------------------------------------------------------------
  181. * Function : IDACreate
  182. * ----------------------------------------------------------------
  183. * IDACreate creates an internal memory block for a problem to
  184. * be solved by IDA.
  185. *
  186. * If successful, IDACreate returns a pointer to initialized
  187. * problem memory. This pointer should be passed to IDAInit.
  188. * If an initialization error occurs, IDACreate prints an error
  189. * message to standard err and returns NULL.
  190. *
  191. * ----------------------------------------------------------------
  192. */
  193. SUNDIALS_EXPORT void *IDACreate(void);
  194. /*
  195. * ----------------------------------------------------------------
  196. * Integrator optional input specification functions
  197. * ----------------------------------------------------------------
  198. * The following functions can be called to set optional inputs
  199. * to values other than the defaults given below:
  200. *
  201. * |
  202. * Function | Optional input / [ default value ]
  203. * |
  204. * ----------------------------------------------------------------
  205. * |
  206. * IDASetErrHandlerFn | user-provided ErrHandler function.
  207. * | [internal]
  208. * |
  209. * IDASetErrFile | the file pointer for an error file
  210. * | where all IDA warning and error
  211. * | messages will be written if the default
  212. * | internal error handling function is used.
  213. * | This parameter can be stdout (standard
  214. * | output), stderr (standard error), or a
  215. * | file pointer (corresponding to a user
  216. * | error file opened for writing) returned
  217. * | by fopen.
  218. * | If not called, then all messages will
  219. * | be written to the standard error stream.
  220. * | [stderr]
  221. * |
  222. * IDASetUserData | a pointer to user data that will be
  223. * | passed to the user's res function every
  224. * | time a user-supplied function is called.
  225. * | [NULL]
  226. * |
  227. * IDASetMaxOrd | maximum lmm order to be used by the
  228. * | solver.
  229. * | [5]
  230. * |
  231. * IDASetMaxNumSteps | maximum number of internal steps to be
  232. * | taken by the solver in its attempt to
  233. * | reach tout.
  234. * | [500]
  235. * |
  236. * IDASetInitStep | initial step size.
  237. * | [estimated by IDA]
  238. * |
  239. * IDASetMaxStep | maximum absolute value of step size
  240. * | allowed.
  241. * | [infinity]
  242. * |
  243. * IDASetStopTime | the independent variable value past
  244. * | which the solution is not to proceed.
  245. * | [infinity]
  246. * |
  247. * IDASetNonlinConvCoef | Newton convergence test constant
  248. * | for use during integration.
  249. * | [0.33]
  250. * |
  251. * IDASetMaxErrTestFails| Maximum number of error test failures
  252. * | in attempting one step.
  253. * | [10]
  254. * |
  255. * IDASetMaxNonlinIters | Maximum number of nonlinear solver
  256. * | iterations at one solution.
  257. * | [4]
  258. * |
  259. * IDASetMaxConvFails | Maximum number of allowable conv.
  260. * | failures in attempting one step.
  261. * | [10]
  262. * |
  263. * IDASetSuppressAlg | flag to indicate whether or not to
  264. * | suppress algebraic variables in the
  265. * | local error tests:
  266. * | FALSE = do not suppress;
  267. * | TRUE = do suppress;
  268. * | [FALSE]
  269. * | NOTE: if suppressed algebraic variables
  270. * | is selected, the nvector 'id' must be
  271. * | supplied for identification of those
  272. * | algebraic components (see IDASetId).
  273. * |
  274. * IDASetId | an N_Vector, which states a given
  275. * | element to be either algebraic or
  276. * | differential.
  277. * | A value of 1.0 indicates a differential
  278. * | variable while a 0.0 indicates an
  279. * | algebraic variable. 'id' is required
  280. * | if optional input SUPPRESSALG is set,
  281. * | or if IDACalcIC is to be called with
  282. * | icopt = IDA_YA_YDP_INIT.
  283. * |
  284. * IDASetConstraints | an N_Vector defining inequality
  285. * | constraints for each component of the
  286. * | solution vector y. If a given element
  287. * | of this vector has values +2 or -2,
  288. * | then the corresponding component of y
  289. * | will be constrained to be > 0.0 or
  290. * | <0.0, respectively, while if it is +1
  291. * | or -1, the y component is constrained
  292. * | to be >= 0.0 or <= 0.0, respectively.
  293. * | If a component of constraints is 0.0,
  294. * | then no constraint is imposed on the
  295. * | corresponding component of y.
  296. * | The presence of a non-NULL constraints
  297. * | vector that is not 0.0 (ZERO) in all
  298. * | components will cause constraint
  299. * | checking to be performed.
  300. * |
  301. * -----------------------------------------------------------------
  302. * |
  303. * IDASetRootDirection | Specifies the direction of zero
  304. * | crossings to be monitored
  305. * | [both directions]
  306. * |
  307. * IDASetNoInactiveRootWarn | disable warning about possible
  308. * | g==0 at beginning of integration
  309. * |
  310. * -----------------------------------------------------------------
  311. * Return flag:
  312. * IDA_SUCCESS if successful
  313. * IDA_MEM_NULL if the ida memory is NULL
  314. * IDA_ILL_INPUT if an argument has an illegal value
  315. *
  316. * ----------------------------------------------------------------
  317. */
  318. SUNDIALS_EXPORT int IDASetErrHandlerFn(void *ida_mem, IDAErrHandlerFn ehfun, void *eh_data);
  319. SUNDIALS_EXPORT int IDASetErrFile(void *ida_mem, FILE *errfp);
  320. SUNDIALS_EXPORT int IDASetUserData(void *ida_mem, void *user_data);
  321. SUNDIALS_EXPORT int IDASetMaxOrd(void *ida_mem, int maxord);
  322. SUNDIALS_EXPORT int IDASetMaxNumSteps(void *ida_mem, long int mxsteps);
  323. SUNDIALS_EXPORT int IDASetInitStep(void *ida_mem, realtype hin);
  324. SUNDIALS_EXPORT int IDASetMaxStep(void *ida_mem, realtype hmax);
  325. SUNDIALS_EXPORT int IDASetStopTime(void *ida_mem, realtype tstop);
  326. SUNDIALS_EXPORT int IDASetNonlinConvCoef(void *ida_mem, realtype epcon);
  327. SUNDIALS_EXPORT int IDASetMaxErrTestFails(void *ida_mem, int maxnef);
  328. SUNDIALS_EXPORT int IDASetMaxNonlinIters(void *ida_mem, int maxcor);
  329. SUNDIALS_EXPORT int IDASetMaxConvFails(void *ida_mem, int maxncf);
  330. SUNDIALS_EXPORT int IDASetSuppressAlg(void *ida_mem, booleantype suppressalg);
  331. SUNDIALS_EXPORT int IDASetId(void *ida_mem, N_Vector id);
  332. SUNDIALS_EXPORT int IDASetConstraints(void *ida_mem, N_Vector constraints);
  333. SUNDIALS_EXPORT int IDASetRootDirection(void *ida_mem, int *rootdir);
  334. SUNDIALS_EXPORT int IDASetNoInactiveRootWarn(void *ida_mem);
  335. /*
  336. * ----------------------------------------------------------------
  337. * Function : IDAInit
  338. * ----------------------------------------------------------------
  339. * IDAInit allocates and initializes memory for a problem to
  340. * to be solved by IDA.
  341. *
  342. * res is the residual function F in F(t,y,y') = 0.
  343. *
  344. * t0 is the initial value of t, the independent variable.
  345. *
  346. * yy0 is the initial condition vector y(t0).
  347. *
  348. * yp0 is the initial condition vector y'(t0)
  349. *
  350. * IDA_SUCCESS if successful
  351. * IDA_MEM_NULL if the ida memory was NULL
  352. * IDA_MEM_FAIL if a memory allocation failed
  353. * IDA_ILL_INPUT f an argument has an illegal value.
  354. *
  355. * ----------------------------------------------------------------
  356. */
  357. SUNDIALS_EXPORT int IDAInit(void *ida_mem, IDAResFn res,
  358. realtype t0, N_Vector yy0, N_Vector yp0);
  359. /*
  360. * ----------------------------------------------------------------
  361. * Function : IDAReInit
  362. * ----------------------------------------------------------------
  363. * IDAReInit re-initializes IDA for the solution of a problem,
  364. * where a prior call to IDAInit has been made.
  365. * IDAReInit performs the same input checking and initializations
  366. * that IDAInit does.
  367. * But it does no memory allocation, assuming that the existing
  368. * internal memory is sufficient for the new problem.
  369. *
  370. * The use of IDAReInit requires that the maximum method order,
  371. * maxord, is no larger for the new problem than for the problem
  372. * specified in the last call to IDAInit. This condition is
  373. * automatically fulfilled if the default value for maxord is
  374. * specified.
  375. *
  376. * Following the call to IDAReInit, a call to the linear solver
  377. * specification routine is necessary if a different linear solver
  378. * is chosen, but may not be otherwise. If the same linear solver
  379. * is chosen, and there are no changes in its input parameters,
  380. * then no call to that routine is needed.
  381. *
  382. * The first argument to IDAReInit is:
  383. *
  384. * ida_mem = pointer to IDA memory returned by IDACreate.
  385. *
  386. * All the remaining arguments to IDAReInit have names and
  387. * meanings identical to those of IDAInit.
  388. *
  389. * The return value of IDAReInit is equal to SUCCESS = 0 if there
  390. * were no errors; otherwise it is a negative int equal to:
  391. * IDA_MEM_NULL indicating ida_mem was NULL, or
  392. * IDA_NO_MALLOC indicating that ida_mem was not allocated.
  393. * IDA_ILL_INPUT indicating an input argument was illegal
  394. * (including an attempt to increase maxord).
  395. * In case of an error return, an error message is also printed.
  396. * ----------------------------------------------------------------
  397. */
  398. SUNDIALS_EXPORT int IDAReInit(void *ida_mem,
  399. realtype t0, N_Vector yy0, N_Vector yp0);
  400. /*
  401. * -----------------------------------------------------------------
  402. * Functions : IDASStolerances
  403. * IDASVtolerances
  404. * IDAWFtolerances
  405. * -----------------------------------------------------------------
  406. *
  407. * These functions specify the integration tolerances. One of them
  408. * MUST be called before the first call to IDA.
  409. *
  410. * IDASStolerances specifies scalar relative and absolute tolerances.
  411. * IDASVtolerances specifies scalar relative tolerance and a vector
  412. * absolute tolerance (a potentially different absolute tolerance
  413. * for each vector component).
  414. * IDAWFtolerances specifies a user-provides function (of type IDAEwtFn)
  415. * which will be called to set the error weight vector.
  416. *
  417. * The tolerances reltol and abstol define a vector of error weights,
  418. * ewt, with components
  419. * ewt[i] = 1/(reltol*abs(y[i]) + abstol) (in the SS case), or
  420. * ewt[i] = 1/(reltol*abs(y[i]) + abstol[i]) (in the SV case).
  421. * This vector is used in all error and convergence tests, which
  422. * use a weighted RMS norm on all error-like vectors v:
  423. * WRMSnorm(v) = sqrt( (1/N) sum(i=1..N) (v[i]*ewt[i])^2 ),
  424. * where N is the problem dimension.
  425. *
  426. * The return value of these functions is equal to IDA_SUCCESS = 0 if
  427. * there were no errors; otherwise it is a negative int equal to:
  428. * IDa_MEM_NULL indicating ida_mem was NULL (i.e.,
  429. * IDACreate has not been called).
  430. * IDA_NO_MALLOC indicating that ida_mem has not been
  431. * allocated (i.e., IDAInit has not been
  432. * called).
  433. * IDA_ILL_INPUT indicating an input argument was illegal
  434. * (e.g. a negative tolerance)
  435. * In case of an error return, an error message is also printed.
  436. * -----------------------------------------------------------------
  437. */
  438. SUNDIALS_EXPORT int IDASStolerances(void *ida_mem, realtype reltol, realtype abstol);
  439. SUNDIALS_EXPORT int IDASVtolerances(void *ida_mem, realtype reltol, N_Vector abstol);
  440. SUNDIALS_EXPORT int IDAWFtolerances(void *ida_mem, IDAEwtFn efun);
  441. /* ----------------------------------------------------------------
  442. * Initial Conditions optional input specification functions
  443. * ----------------------------------------------------------------
  444. * The following functions can be called to set optional inputs
  445. * to control the initial conditions calculations.
  446. *
  447. * |
  448. * Function | Optional input / [ default value ]
  449. * |
  450. * --------------------------------------------------------------
  451. * |
  452. * IDASetNonlinConvCoefIC | positive coeficient in the Newton
  453. * | convergence test. This test uses a
  454. * | weighted RMS norm (with weights
  455. * | defined by the tolerances, as in
  456. * | IDASolve). For new initial value
  457. * | vectors y and y' to be accepted, the
  458. * | norm of J-inverse F(t0,y,y') is
  459. * | required to be less than epiccon,
  460. * | where J is the system Jacobian.
  461. * | [0.01 * 0.33]
  462. * |
  463. * IDASetMaxNumStepsIC | maximum number of values of h allowed
  464. * | when icopt = IDA_YA_YDP_INIT, where
  465. * | h appears in the system Jacobian,
  466. * | J = dF/dy + (1/h)dF/dy'.
  467. * | [5]
  468. * |
  469. * IDASetMaxNumJacsIC | maximum number of values of the
  470. * | approximate Jacobian or preconditioner
  471. * | allowed, when the Newton iterations
  472. * | appear to be slowly converging.
  473. * | [4]
  474. * |
  475. * IDASetMaxNumItersIC | maximum number of Newton iterations
  476. * | allowed in any one attempt to solve
  477. * | the IC problem.
  478. * | [10]
  479. * |
  480. * IDASetLineSearchOffIC | a boolean flag to turn off the
  481. * | linesearch algorithm.
  482. * | [FALSE]
  483. * |
  484. * IDASetStepToleranceIC | positive lower bound on the norm of
  485. * | a Newton step.
  486. * | [(unit roundoff)^(2/3)
  487. *
  488. * ----------------------------------------------------------------
  489. * Return flag:
  490. * IDA_SUCCESS if successful
  491. * IDA_MEM_NULL if the ida memory is NULL
  492. * IDA_ILL_INPUT if an argument has an illegal value
  493. *
  494. * ----------------------------------------------------------------
  495. */
  496. SUNDIALS_EXPORT int IDASetNonlinConvCoefIC(void *ida_mem, realtype epiccon);
  497. SUNDIALS_EXPORT int IDASetMaxNumStepsIC(void *ida_mem, int maxnh);
  498. SUNDIALS_EXPORT int IDASetMaxNumJacsIC(void *ida_mem, int maxnj);
  499. SUNDIALS_EXPORT int IDASetMaxNumItersIC(void *ida_mem, int maxnit);
  500. SUNDIALS_EXPORT int IDASetLineSearchOffIC(void *ida_mem, booleantype lsoff);
  501. SUNDIALS_EXPORT int IDASetStepToleranceIC(void *ida_mem, realtype steptol);
  502. /*
  503. * -----------------------------------------------------------------
  504. * Function : IDARootInit
  505. * -----------------------------------------------------------------
  506. * IDARootInit initializes a rootfinding problem to be solved
  507. * during the integration of the DAE system. It must be called
  508. * after IDACreate, and before IDASolve. The arguments are:
  509. *
  510. * ida_mem = pointer to IDA memory returned by IDACreate.
  511. *
  512. * nrtfn = number of functions g_i, an int >= 0.
  513. *
  514. * g = name of user-supplied function, of type IDARootFn,
  515. * defining the functions g_i whose roots are sought.
  516. *
  517. * If a new problem is to be solved with a call to IDAReInit,
  518. * where the new problem has no root functions but the prior one
  519. * did, then call IDARootInit with nrtfn = 0.
  520. *
  521. * The return value of IDARootInit is IDA_SUCCESS = 0 if there were
  522. * no errors; otherwise it is a negative int equal to:
  523. * IDA_MEM_NULL indicating ida_mem was NULL, or
  524. * IDA_MEM_FAIL indicating a memory allocation failed.
  525. * (including an attempt to increase maxord).
  526. * IDA_ILL_INPUT indicating nrtfn > 0 but g = NULL.
  527. * In case of an error return, an error message is also printed.
  528. * -----------------------------------------------------------------
  529. */
  530. SUNDIALS_EXPORT int IDARootInit(void *ida_mem, int nrtfn, IDARootFn g);
  531. /*
  532. * ----------------------------------------------------------------
  533. * Function : IDACalcIC
  534. * ----------------------------------------------------------------
  535. * IDACalcIC calculates corrected initial conditions for the DAE
  536. * system for a class of index-one problems of semi-implicit form.
  537. * It uses Newton iteration combined with a Linesearch algorithm.
  538. * Calling IDACalcIC is optional. It is only necessary when the
  539. * initial conditions do not solve the given system. I.e., if
  540. * y0 and yp0 are known to satisfy F(t0, y0, yp0) = 0, then
  541. * a call to IDACalcIC is NOT necessary (for index-one problems).
  542. *
  543. * A call to IDACalcIC must be preceded by a successful call to
  544. * IDAInit or IDAReInit for the given DAE problem, and by a
  545. * successful call to the linear system solver specification
  546. * routine.
  547. *
  548. * The call to IDACalcIC should precede the call(s) to IDASolve
  549. * for the given problem.
  550. *
  551. * The arguments to IDACalcIC are as follows:
  552. *
  553. * ida_mem is the pointer to IDA memory returned by IDACreate.
  554. *
  555. * icopt is the option of IDACalcIC to be used.
  556. * icopt = IDA_YA_YDP_INIT directs IDACalcIC to compute
  557. * the algebraic components of y and differential
  558. * components of y', given the differential
  559. * components of y. This option requires that the
  560. * N_Vector id was set through a call to IDASetId
  561. * specifying the differential and algebraic
  562. * components.
  563. * icopt = IDA_Y_INIT directs IDACalcIC to compute all
  564. * components of y, given y'. id is not required.
  565. *
  566. * tout1 is the first value of t at which a soluton will be
  567. * requested (from IDASolve). (This is needed here to
  568. * determine the direction of integration and rough scale
  569. * in the independent variable t.)
  570. *
  571. *
  572. * IDACalcIC returns an int flag. Its symbolic values and their
  573. * meanings are as follows. (The numerical return values are set
  574. * above in this file.) All unsuccessful returns give a negative
  575. * return value. If IFACalcIC failed, y0 and yp0 contain
  576. * (possibly) altered values, computed during the attempt.
  577. *
  578. * IDA_SUCCESS IDACalcIC was successful. The corrected
  579. * initial value vectors were stored internally.
  580. *
  581. * IDA_MEM_NULL The argument ida_mem was NULL.
  582. *
  583. * IDA_ILL_INPUT One of the input arguments was illegal.
  584. * See printed message.
  585. *
  586. * IDA_LINIT_FAIL The linear solver's init routine failed.
  587. *
  588. * IDA_BAD_EWT Some component of the error weight vector
  589. * is zero (illegal), either for the input
  590. * value of y0 or a corrected value.
  591. *
  592. * IDA_RES_FAIL The user's residual routine returned
  593. * a non-recoverable error flag.
  594. *
  595. * IDA_FIRST_RES_FAIL The user's residual routine returned
  596. * a recoverable error flag on the first call,
  597. * but IDACalcIC was unable to recover.
  598. *
  599. * IDA_LSETUP_FAIL The linear solver's setup routine had a
  600. * non-recoverable error.
  601. *
  602. * IDA_LSOLVE_FAIL The linear solver's solve routine had a
  603. * non-recoverable error.
  604. *
  605. * IDA_NO_RECOVERY The user's residual routine, or the linear
  606. * solver's setup or solve routine had a
  607. * recoverable error, but IDACalcIC was
  608. * unable to recover.
  609. *
  610. * IDA_CONSTR_FAIL IDACalcIC was unable to find a solution
  611. * satisfying the inequality constraints.
  612. *
  613. * IDA_LINESEARCH_FAIL The Linesearch algorithm failed to find a
  614. * solution with a step larger than steptol
  615. * in weighted RMS norm.
  616. *
  617. * IDA_CONV_FAIL IDACalcIC failed to get convergence of the
  618. * Newton iterations.
  619. *
  620. * ----------------------------------------------------------------
  621. */
  622. SUNDIALS_EXPORT int IDACalcIC(void *ida_mem, int icopt, realtype tout1);
  623. /*
  624. * ----------------------------------------------------------------
  625. * Function : IDASolve
  626. * ----------------------------------------------------------------
  627. * IDASolve integrates the DAE over an interval in t, the
  628. * independent variable. If itask is IDA_NORMAL, then the solver
  629. * integrates from its current internal t value to a point at or
  630. * beyond tout, then interpolates to t = tout and returns y(tret)
  631. * in the user-allocated vector yret. In general, tret = tout.
  632. * If itask is IDA_ONE_STEP, then the solver takes one internal
  633. * step of the independent variable and returns in yret the value
  634. * of y at the new internal independent variable value. In this
  635. * case, tout is used only during the first call to IDASolve to
  636. * determine the direction of integration and the rough scale of
  637. * the problem. If tstop is enabled (through a call to IDASetStopTime),
  638. * then IDASolve returns the solution at tstop. Once the integrator
  639. * returns at a tstop time, any future testing for tstop is disabled
  640. * (and can be reenabled only though a new call to IDASetStopTime).
  641. * The time reached by the solver is placed in (*tret). The
  642. * user is responsible for allocating the memory for this value.
  643. *
  644. * ida_mem is the pointer (void) to IDA memory returned by
  645. * IDACreate.
  646. *
  647. * tout is the next independent variable value at which a
  648. * computed solution is desired.
  649. *
  650. * tret is a pointer to a real location. IDASolve sets (*tret)
  651. * to the actual t value reached, corresponding to the
  652. * solution vector yret. In IDA_NORMAL mode, with no
  653. * errors and no roots found, (*tret) = tout.
  654. *
  655. * yret is the computed solution vector. With no errors,
  656. * yret = y(tret).
  657. *
  658. * ypret is the derivative of the computed solution at t = tret.
  659. *
  660. * Note: yret and ypret may be the same N_Vectors as y0 and yp0
  661. * in the call to IDAInit or IDAReInit.
  662. *
  663. * itask is IDA_NORMAL or IDA_ONE_STEP. These two modes are described above.
  664. *
  665. *
  666. * The return values for IDASolve are described below.
  667. * (The numerical return values are defined above in this file.)
  668. * All unsuccessful returns give a negative return value.
  669. *
  670. * IDA_SUCCESS
  671. * IDASolve succeeded and no roots were found.
  672. *
  673. * IDA_ROOT_RETURN: IDASolve succeeded, and found one or more roots.
  674. * If nrtfn > 1, call IDAGetRootInfo to see which g_i were found
  675. * to have a root at (*tret).
  676. *
  677. * IDA_TSTOP_RETURN:
  678. * IDASolve returns computed results for the independent variable
  679. * value tstop. That is, tstop was reached.
  680. *
  681. * IDA_MEM_NULL:
  682. * The IDA_mem argument was NULL.
  683. *
  684. * IDA_ILL_INPUT:
  685. * One of the inputs to IDASolve is illegal. This includes the
  686. * situation when a component of the error weight vectors
  687. * becomes < 0 during internal stepping. It also includes the
  688. * situation where a root of one of the root functions was found
  689. * both at t0 and very near t0. The ILL_INPUT flag
  690. * will also be returned if the linear solver function IDA---
  691. * (called by the user after calling IDACreate) failed to set one
  692. * of the linear solver-related fields in ida_mem or if the linear
  693. * solver's init routine failed. In any case, the user should see
  694. * the printed error message for more details.
  695. *
  696. * IDA_TOO_MUCH_WORK:
  697. * The solver took mxstep internal steps but could not reach tout.
  698. * The default value for mxstep is MXSTEP_DEFAULT = 500.
  699. *
  700. * IDA_TOO_MUCH_ACC:
  701. * The solver could not satisfy the accuracy demanded by the user
  702. * for some internal step.
  703. *
  704. * IDA_ERR_FAIL:
  705. * Error test failures occurred too many times (=MXETF = 10) during
  706. * one internal step.
  707. *
  708. * IDA_CONV_FAIL:
  709. * Convergence test failures occurred too many times (= MXNCF = 10)
  710. * during one internal step.
  711. *
  712. * IDA_LSETUP_FAIL:
  713. * The linear solver's setup routine failed
  714. * in an unrecoverable manner.
  715. *
  716. * IDA_LSOLVE_FAIL:
  717. * The linear solver's solve routine failed
  718. * in an unrecoverable manner.
  719. *
  720. * IDA_CONSTR_FAIL:
  721. * The inequality constraints were violated,
  722. * and the solver was unable to recover.
  723. *
  724. * IDA_REP_RES_ERR:
  725. * The user's residual function repeatedly returned a recoverable
  726. * error flag, but the solver was unable to recover.
  727. *
  728. * IDA_RES_FAIL:
  729. * The user's residual function returned a nonrecoverable error
  730. * flag.
  731. *
  732. * ----------------------------------------------------------------
  733. */
  734. SUNDIALS_EXPORT int IDASolve(void *ida_mem, realtype tout, realtype *tret,
  735. N_Vector yret, N_Vector ypret, int itask);
  736. /*
  737. * ----------------------------------------------------------------
  738. * Function: IDAGetDky
  739. * ----------------------------------------------------------------
  740. *
  741. * This routine computes the k-th derivative of the interpolating
  742. * polynomial at the time t and stores the result in the vector dky.
  743. *
  744. * The return values are:
  745. * IDA_SUCCESS: succeess.
  746. * IDA_BAD_T: t is not in the interval [tn-hu,tn].
  747. * IDA_MEM_NULL: The ida_mem argument was NULL.
  748. * IDA_BAD_DKY if the dky vector is NULL.
  749. * IDA_BAD_K if the requested k is not in the range 0,1,...,order used
  750. *
  751. * ----------------------------------------------------------------
  752. */
  753. SUNDIALS_EXPORT int IDAGetDky(void *ida_mem, realtype t, int k, N_Vector dky);
  754. /* ----------------------------------------------------------------
  755. * Integrator optional output extraction functions
  756. * ----------------------------------------------------------------
  757. *
  758. * The following functions can be called to get optional outputs
  759. * and statistics related to the main integrator.
  760. * ----------------------------------------------------------------
  761. *
  762. * IDAGetWorkSpace returns the IDA real and integer workspace sizes
  763. * IDAGetNumSteps returns the cumulative number of internal
  764. * steps taken by the solver
  765. * IDAGetNumRhsEvals returns the number of calls to the user's
  766. * res function
  767. * IDAGetNumLinSolvSetups returns the number of calls made to
  768. * the linear solver's setup routine
  769. * IDAGetNumErrTestFails returns the number of local error test
  770. * failures that have occured
  771. * IDAGetNumBacktrackOps returns the number of backtrack
  772. * operations done in the linesearch algorithm in IDACalcIC
  773. * IDAGetConsistentIC returns the consistent initial conditions
  774. * computed by IDACalcIC
  775. * IDAGetLastOrder returns the order used during the last
  776. * internal step
  777. * IDAGetCurentOrder returns the order to be used on the next
  778. * internal step
  779. * IDAGetActualInitStep returns the actual initial step size
  780. * used by IDA
  781. * IDAGetLAstStep returns the step size for the last internal
  782. * step (if from IDASolve), or the last value of the
  783. * artificial step size h (if from IDACalcIC)
  784. * IDAGetCurrentStep returns the step size to be attempted on the
  785. * next internal step
  786. * IDAGetCurrentTime returns the current internal time reached
  787. * by the solver
  788. * IDAGetTolScaleFactor returns a suggested factor by which the
  789. * user's tolerances should be scaled when too much
  790. * accuracy has been requested for some internal step
  791. * IDAGetErrWeights returns the current state error weight vector.
  792. * The user must allocate space for eweight.
  793. * IDAGetEstLocalErrors returns the estimated local errors. The user
  794. * must allocate space for the vector ele.
  795. * IDAGetNumGEvals returns the number of calls to the user's
  796. * g function (for rootfinding)
  797. * IDAGetRootInfo returns the indices for which g_i was found to
  798. * have a root. The user must allocate space for rootsfound.
  799. * For i = 0 ... nrtfn-1, rootsfound[i] = 1 if g_i has a root,
  800. * and rootsfound[i]= 0 if not.
  801. *
  802. * IDAGet* return values:
  803. * IDA_SUCCESS if succesful
  804. * IDA_MEM_NULL if the ida memory was NULL
  805. * IDA_ILL_INPUT if some input is illegal
  806. *
  807. * ----------------------------------------------------------------
  808. */
  809. SUNDIALS_EXPORT int IDAGetWorkSpace(void *ida_mem, long int *lenrw, long int *leniw);
  810. SUNDIALS_EXPORT int IDAGetNumSteps(void *ida_mem, long int *nsteps);
  811. SUNDIALS_EXPORT int IDAGetNumResEvals(void *ida_mem, long int *nrevals);
  812. SUNDIALS_EXPORT int IDAGetNumLinSolvSetups(void *ida_mem, long int *nlinsetups);
  813. SUNDIALS_EXPORT int IDAGetNumErrTestFails(void *ida_mem, long int *netfails);
  814. SUNDIALS_EXPORT int IDAGetNumBacktrackOps(void *ida_mem, long int *nbacktr);
  815. SUNDIALS_EXPORT int IDAGetConsistentIC(void *ida_mem, N_Vector yy0_mod, N_Vector yp0_mod);
  816. SUNDIALS_EXPORT int IDAGetLastOrder(void *ida_mem, int *klast);
  817. SUNDIALS_EXPORT int IDAGetCurrentOrder(void *ida_mem, int *kcur);
  818. SUNDIALS_EXPORT int IDAGetActualInitStep(void *ida_mem, realtype *hinused);
  819. SUNDIALS_EXPORT int IDAGetLastStep(void *ida_mem, realtype *hlast);
  820. SUNDIALS_EXPORT int IDAGetCurrentStep(void *ida_mem, realtype *hcur);
  821. SUNDIALS_EXPORT int IDAGetCurrentTime(void *ida_mem, realtype *tcur);
  822. SUNDIALS_EXPORT int IDAGetTolScaleFactor(void *ida_mem, realtype *tolsfact);
  823. SUNDIALS_EXPORT int IDAGetErrWeights(void *ida_mem, N_Vector eweight);
  824. SUNDIALS_EXPORT int IDAGetEstLocalErrors(void *ida_mem, N_Vector ele);
  825. SUNDIALS_EXPORT int IDAGetNumGEvals(void *ida_mem, long int *ngevals);
  826. SUNDIALS_EXPORT int IDAGetRootInfo(void *ida_mem, int *rootsfound);
  827. /*
  828. * ----------------------------------------------------------------
  829. * As a convenience, the following function provides the
  830. * optional outputs in a group.
  831. * ----------------------------------------------------------------
  832. */
  833. SUNDIALS_EXPORT int IDAGetIntegratorStats(void *ida_mem, long int *nsteps,
  834. long int *nrevals, long int *nlinsetups,
  835. long int *netfails, int *qlast, int *qcur,
  836. realtype *hinused, realtype *hlast, realtype *hcur,
  837. realtype *tcur);
  838. /*
  839. * ----------------------------------------------------------------
  840. * Nonlinear solver optional output extraction functions
  841. * ----------------------------------------------------------------
  842. *
  843. * The following functions can be called to get optional outputs
  844. * and statistics related to the nonlinear solver.
  845. * --------------------------------------------------------------
  846. *
  847. * IDAGetNumNonlinSolvIters returns the number of nonlinear
  848. * solver iterations performed.
  849. * IDAGetNumNonlinSolvConvFails returns the number of nonlinear
  850. * convergence failures.
  851. *
  852. * ----------------------------------------------------------------
  853. */
  854. SUNDIALS_EXPORT int IDAGetNumNonlinSolvIters(void *ida_mem, long int *nniters);
  855. SUNDIALS_EXPORT int IDAGetNumNonlinSolvConvFails(void *ida_mem, long int *nncfails);
  856. /*
  857. * ----------------------------------------------------------------
  858. * As a convenience, the following function provides the
  859. * nonlinear solver optional outputs in a group.
  860. * ----------------------------------------------------------------
  861. */
  862. SUNDIALS_EXPORT int IDAGetNonlinSolvStats(void *ida_mem, long int *nniters,
  863. long int *nncfails);
  864. /*
  865. * -----------------------------------------------------------------
  866. * The following function returns the name of the constant
  867. * associated with an IDA return flag
  868. * -----------------------------------------------------------------
  869. */
  870. SUNDIALS_EXPORT char *IDAGetReturnFlagName(long int flag);
  871. /*
  872. * ----------------------------------------------------------------
  873. * Function : IDAFree
  874. * ----------------------------------------------------------------
  875. * IDAFree frees the problem memory IDA_mem allocated by
  876. * IDAInit. Its only argument is the pointer idamem
  877. * returned by IDAInit.
  878. * ----------------------------------------------------------------
  879. */
  880. SUNDIALS_EXPORT void IDAFree(void **ida_mem);
  881. #ifdef __cplusplus
  882. }
  883. #endif
  884. #endif