cvode_io.c 23 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139
  1. /*
  2. * -----------------------------------------------------------------
  3. * $Revision: 4210 $
  4. * $Date: 2014-08-27 15:40:02 -0700 (Wed, 27 Aug 2014) $
  5. * -----------------------------------------------------------------
  6. * Programmer(s): Alan C. Hindmarsh and Radu Serban @ LLNL
  7. * -----------------------------------------------------------------
  8. * LLNS Copyright Start
  9. * Copyright (c) 2014, Lawrence Livermore National Security
  10. * This work was performed under the auspices of the U.S. Department
  11. * of Energy by Lawrence Livermore National Laboratory in part under
  12. * Contract W-7405-Eng-48 and in part under Contract DE-AC52-07NA27344.
  13. * Produced at the Lawrence Livermore National Laboratory.
  14. * All rights reserved.
  15. * For details, see the LICENSE file.
  16. * LLNS Copyright End
  17. * -----------------------------------------------------------------
  18. * This is the implementation file for the optional input and output
  19. * functions for the CVODE solver.
  20. * -----------------------------------------------------------------
  21. */
  22. #include <stdio.h>
  23. #include <stdlib.h>
  24. #include "cvode_impl.h"
  25. #include <sundials/sundials_types.h>
  26. #define ZERO RCONST(0.0)
  27. #define ONE RCONST(1.0)
  28. #define lrw (cv_mem->cv_lrw)
  29. #define liw (cv_mem->cv_liw)
  30. #define lrw1 (cv_mem->cv_lrw1)
  31. #define liw1 (cv_mem->cv_liw1)
  32. /*
  33. * =================================================================
  34. * CVODE optional input functions
  35. * =================================================================
  36. */
  37. /*
  38. * CVodeSetErrHandlerFn
  39. *
  40. * Specifies the error handler function
  41. */
  42. SUNDIALS_EXPORT int CVodeSetErrHandlerFn(void *cvode_mem, CVErrHandlerFn ehfun, void *eh_data)
  43. {
  44. CVodeMem cv_mem;
  45. if (cvode_mem==NULL) {
  46. cvProcessError(NULL, CV_MEM_NULL, "CVODE", "CVodeSetErrHandlerFn", MSGCV_NO_MEM);
  47. return(CV_MEM_NULL);
  48. }
  49. cv_mem = (CVodeMem) cvode_mem;
  50. cv_mem->cv_ehfun = ehfun;
  51. cv_mem->cv_eh_data = eh_data;
  52. return(CV_SUCCESS);
  53. }
  54. /*
  55. * CVodeSetErrFile
  56. *
  57. * Specifies the FILE pointer for output (NULL means no messages)
  58. */
  59. SUNDIALS_EXPORT int CVodeSetErrFile(void *cvode_mem, FILE *errfp)
  60. {
  61. CVodeMem cv_mem;
  62. if (cvode_mem==NULL) {
  63. cvProcessError(NULL, CV_MEM_NULL, "CVODE", "CVodeSetErrFile", MSGCV_NO_MEM);
  64. return(CV_MEM_NULL);
  65. }
  66. cv_mem = (CVodeMem) cvode_mem;
  67. cv_mem->cv_errfp = errfp;
  68. return(CV_SUCCESS);
  69. }
  70. /*
  71. * CVodeSetIterType
  72. *
  73. * Specifies the iteration type (CV_FUNCTIONAL or CV_NEWTON)
  74. */
  75. SUNDIALS_EXPORT int CVodeSetIterType(void *cvode_mem, int iter)
  76. {
  77. CVodeMem cv_mem;
  78. if (cvode_mem==NULL) {
  79. cvProcessError(NULL, CV_MEM_NULL, "CVODE", "CVodeSetIterType", MSGCV_NO_MEM);
  80. return(CV_MEM_NULL);
  81. }
  82. cv_mem = (CVodeMem) cvode_mem;
  83. if ((iter != CV_FUNCTIONAL) && (iter != CV_NEWTON)) {
  84. cvProcessError(cv_mem, CV_ILL_INPUT, "CVODE", "CVodeSetIterType", MSGCV_BAD_ITER);
  85. return (CV_ILL_INPUT);
  86. }
  87. cv_mem->cv_iter = iter;
  88. return(CV_SUCCESS);
  89. }
  90. /*
  91. * CVodeSetUserData
  92. *
  93. * Specifies the user data pointer for f
  94. */
  95. SUNDIALS_EXPORT int CVodeSetUserData(void *cvode_mem, void *user_data)
  96. {
  97. CVodeMem cv_mem;
  98. if (cvode_mem==NULL) {
  99. cvProcessError(NULL, CV_MEM_NULL, "CVODE", "CVodeSetUserData", MSGCV_NO_MEM);
  100. return(CV_MEM_NULL);
  101. }
  102. cv_mem = (CVodeMem) cvode_mem;
  103. cv_mem->cv_user_data = user_data;
  104. return(CV_SUCCESS);
  105. }
  106. /*
  107. * CVodeSetMaxOrd
  108. *
  109. * Specifies the maximum method order
  110. */
  111. SUNDIALS_EXPORT int CVodeSetMaxOrd(void *cvode_mem, int maxord)
  112. {
  113. CVodeMem cv_mem;
  114. int qmax_alloc;
  115. if (cvode_mem==NULL) {
  116. cvProcessError(NULL, CV_MEM_NULL, "CVODE", "CVodeSetMaxOrd", MSGCV_NO_MEM);
  117. return(CV_MEM_NULL);
  118. }
  119. cv_mem = (CVodeMem) cvode_mem;
  120. if (maxord <= 0) {
  121. cvProcessError(cv_mem, CV_ILL_INPUT, "CVODE", "CVodeSetMaxOrd", MSGCV_NEG_MAXORD);
  122. return(CV_ILL_INPUT);
  123. }
  124. /* Cannot increase maximum order beyond the value that
  125. was used when allocating memory */
  126. qmax_alloc = cv_mem->cv_qmax_alloc;
  127. if (maxord > qmax_alloc) {
  128. cvProcessError(cv_mem, CV_ILL_INPUT, "CVODE", "CVodeSetMaxOrd", MSGCV_BAD_MAXORD);
  129. return(CV_ILL_INPUT);
  130. }
  131. cv_mem->cv_qmax = maxord;
  132. return(CV_SUCCESS);
  133. }
  134. /*
  135. * CVodeSetMaxNumSteps
  136. *
  137. * Specifies the maximum number of integration steps
  138. */
  139. SUNDIALS_EXPORT int CVodeSetMaxNumSteps(void *cvode_mem, long int mxsteps)
  140. {
  141. CVodeMem cv_mem;
  142. if (cvode_mem==NULL) {
  143. cvProcessError(NULL, CV_MEM_NULL, "CVODE", "CVodeSetMaxNumSteps", MSGCV_NO_MEM);
  144. return(CV_MEM_NULL);
  145. }
  146. cv_mem = (CVodeMem) cvode_mem;
  147. /* Passing mxsteps=0 sets the default. Passing mxsteps<0 disables the test. */
  148. if (mxsteps == 0)
  149. cv_mem->cv_mxstep = MXSTEP_DEFAULT;
  150. else
  151. cv_mem->cv_mxstep = mxsteps;
  152. return(CV_SUCCESS);
  153. }
  154. /*
  155. * CVodeSetMaxHnilWarns
  156. *
  157. * Specifies the maximum number of warnings for small h
  158. */
  159. SUNDIALS_EXPORT int CVodeSetMaxHnilWarns(void *cvode_mem, int mxhnil)
  160. {
  161. CVodeMem cv_mem;
  162. if (cvode_mem==NULL) {
  163. cvProcessError(NULL, CV_MEM_NULL, "CVODE", "CVodeSetMaxHnilWarns", MSGCV_NO_MEM);
  164. return(CV_MEM_NULL);
  165. }
  166. cv_mem = (CVodeMem) cvode_mem;
  167. cv_mem->cv_mxhnil = mxhnil;
  168. return(CV_SUCCESS);
  169. }
  170. /*
  171. *CVodeSetStabLimDet
  172. *
  173. * Turns on/off the stability limit detection algorithm
  174. */
  175. SUNDIALS_EXPORT int CVodeSetStabLimDet(void *cvode_mem, booleantype sldet)
  176. {
  177. CVodeMem cv_mem;
  178. if (cvode_mem==NULL) {
  179. cvProcessError(NULL, CV_MEM_NULL, "CVODE", "CVodeSetStabLimDet", MSGCV_NO_MEM);
  180. return(CV_MEM_NULL);
  181. }
  182. cv_mem = (CVodeMem) cvode_mem;
  183. if( sldet && (cv_mem->cv_lmm != CV_BDF) ) {
  184. cvProcessError(cv_mem, CV_ILL_INPUT, "CVODE", "CVodeSetStabLimDet", MSGCV_SET_SLDET);
  185. return(CV_ILL_INPUT);
  186. }
  187. cv_mem->cv_sldeton = sldet;
  188. return(CV_SUCCESS);
  189. }
  190. /*
  191. * CVodeSetInitStep
  192. *
  193. * Specifies the initial step size
  194. */
  195. SUNDIALS_EXPORT int CVodeSetInitStep(void *cvode_mem, realtype hin)
  196. {
  197. CVodeMem cv_mem;
  198. if (cvode_mem==NULL) {
  199. cvProcessError(NULL, CV_MEM_NULL, "CVODE", "CVodeSetInitStep", MSGCV_NO_MEM);
  200. return(CV_MEM_NULL);
  201. }
  202. cv_mem = (CVodeMem) cvode_mem;
  203. cv_mem->cv_hin = hin;
  204. return(CV_SUCCESS);
  205. }
  206. /*
  207. * CVodeSetMinStep
  208. *
  209. * Specifies the minimum step size
  210. */
  211. SUNDIALS_EXPORT int CVodeSetMinStep(void *cvode_mem, realtype hmin)
  212. {
  213. CVodeMem cv_mem;
  214. if (cvode_mem==NULL) {
  215. cvProcessError(NULL, CV_MEM_NULL, "CVODE", "CVodeSetMinStep", MSGCV_NO_MEM);
  216. return(CV_MEM_NULL);
  217. }
  218. cv_mem = (CVodeMem) cvode_mem;
  219. if (hmin<0) {
  220. cvProcessError(cv_mem, CV_ILL_INPUT, "CVODE", "CVodeSetMinStep", MSGCV_NEG_HMIN);
  221. return(CV_ILL_INPUT);
  222. }
  223. /* Passing 0 sets hmin = zero */
  224. if (hmin == ZERO) {
  225. cv_mem->cv_hmin = HMIN_DEFAULT;
  226. return(CV_SUCCESS);
  227. }
  228. if (hmin * cv_mem->cv_hmax_inv > ONE) {
  229. cvProcessError(cv_mem, CV_ILL_INPUT, "CVODE", "CVodeSetMinStep", MSGCV_BAD_HMIN_HMAX);
  230. return(CV_ILL_INPUT);
  231. }
  232. cv_mem->cv_hmin = hmin;
  233. return(CV_SUCCESS);
  234. }
  235. /*
  236. * CVodeSetMaxStep
  237. *
  238. * Specifies the maximum step size
  239. */
  240. SUNDIALS_EXPORT int CVodeSetMaxStep(void *cvode_mem, realtype hmax)
  241. {
  242. realtype hmax_inv;
  243. CVodeMem cv_mem;
  244. if (cvode_mem==NULL) {
  245. cvProcessError(NULL, CV_MEM_NULL, "CVODE", "CVodeSetMaxStep", MSGCV_NO_MEM);
  246. return (CV_MEM_NULL);
  247. }
  248. cv_mem = (CVodeMem) cvode_mem;
  249. if (hmax < 0) {
  250. cvProcessError(cv_mem, CV_ILL_INPUT, "CVODE", "CVodeSetMaxStep", MSGCV_NEG_HMAX);
  251. return(CV_ILL_INPUT);
  252. }
  253. /* Passing 0 sets hmax = infinity */
  254. if (hmax == ZERO) {
  255. cv_mem->cv_hmax_inv = HMAX_INV_DEFAULT;
  256. return(CV_SUCCESS);
  257. }
  258. hmax_inv = ONE/hmax;
  259. if (hmax_inv * cv_mem->cv_hmin > ONE) {
  260. cvProcessError(cv_mem, CV_ILL_INPUT, "CVODE", "CVodeSetMaxStep", MSGCV_BAD_HMIN_HMAX);
  261. return(CV_ILL_INPUT);
  262. }
  263. cv_mem->cv_hmax_inv = hmax_inv;
  264. return(CV_SUCCESS);
  265. }
  266. /*
  267. * CVodeSetStopTime
  268. *
  269. * Specifies the time beyond which the integration is not to proceed.
  270. */
  271. SUNDIALS_EXPORT int CVodeSetStopTime(void *cvode_mem, realtype tstop)
  272. {
  273. CVodeMem cv_mem;
  274. if (cvode_mem==NULL) {
  275. cvProcessError(NULL, CV_MEM_NULL, "CVODE", "CVodeSetStopTime", MSGCV_NO_MEM);
  276. return (CV_MEM_NULL);
  277. }
  278. cv_mem = (CVodeMem) cvode_mem;
  279. /* If CVode was called at least once, test if tstop is legal
  280. * (i.e. if it was not already passed).
  281. * If CVodeSetStopTime is called before the first call to CVode,
  282. * tstop will be checked in CVode. */
  283. if (cv_mem->cv_nst > 0) {
  284. if ( (tstop - cv_mem->cv_tn) * cv_mem->cv_h < ZERO ) {
  285. cvProcessError(cv_mem, CV_ILL_INPUT, "CVODE", "CVodeSetStopTime", MSGCV_BAD_TSTOP, tstop, cv_mem->cv_tn);
  286. return(CV_ILL_INPUT);
  287. }
  288. }
  289. cv_mem->cv_tstop = tstop;
  290. cv_mem->cv_tstopset = TRUE;
  291. return(CV_SUCCESS);
  292. }
  293. /*
  294. * CVodeSetMaxErrTestFails
  295. *
  296. * Specifies the maximum number of error test failures during one
  297. * step try.
  298. */
  299. SUNDIALS_EXPORT int CVodeSetMaxErrTestFails(void *cvode_mem, int maxnef)
  300. {
  301. CVodeMem cv_mem;
  302. if (cvode_mem==NULL) {
  303. cvProcessError(NULL, CV_MEM_NULL, "CVODE", "CVodeSetMaxErrTestFails", MSGCV_NO_MEM);
  304. return (CV_MEM_NULL);
  305. }
  306. cv_mem = (CVodeMem) cvode_mem;
  307. cv_mem->cv_maxnef = maxnef;
  308. return(CV_SUCCESS);
  309. }
  310. /*
  311. * CVodeSetMaxConvFails
  312. *
  313. * Specifies the maximum number of nonlinear convergence failures
  314. * during one step try.
  315. */
  316. SUNDIALS_EXPORT int CVodeSetMaxConvFails(void *cvode_mem, int maxncf)
  317. {
  318. CVodeMem cv_mem;
  319. if (cvode_mem==NULL) {
  320. cvProcessError(NULL, CV_MEM_NULL, "CVODE", "CVodeSetMaxConvFails", MSGCV_NO_MEM);
  321. return (CV_MEM_NULL);
  322. }
  323. cv_mem = (CVodeMem) cvode_mem;
  324. cv_mem->cv_maxncf = maxncf;
  325. return(CV_SUCCESS);
  326. }
  327. /*
  328. * CVodeSetMaxNonlinIters
  329. *
  330. * Specifies the maximum number of nonlinear iterations during
  331. * one solve.
  332. */
  333. SUNDIALS_EXPORT int CVodeSetMaxNonlinIters(void *cvode_mem, int maxcor)
  334. {
  335. CVodeMem cv_mem;
  336. if (cvode_mem==NULL) {
  337. cvProcessError(NULL, CV_MEM_NULL, "CVODE", "CVodeSetMaxNonlinIters", MSGCV_NO_MEM);
  338. return (CV_MEM_NULL);
  339. }
  340. cv_mem = (CVodeMem) cvode_mem;
  341. cv_mem->cv_maxcor = maxcor;
  342. return(CV_SUCCESS);
  343. }
  344. /*
  345. * CVodeSetNonlinConvCoef
  346. *
  347. * Specifies the coeficient in the nonlinear solver convergence
  348. * test
  349. */
  350. SUNDIALS_EXPORT int CVodeSetNonlinConvCoef(void *cvode_mem, realtype nlscoef)
  351. {
  352. CVodeMem cv_mem;
  353. if (cvode_mem==NULL) {
  354. cvProcessError(NULL, CV_MEM_NULL, "CVODE", "CVodeSetNonlinConvCoef", MSGCV_NO_MEM);
  355. return(CV_MEM_NULL);
  356. }
  357. cv_mem = (CVodeMem) cvode_mem;
  358. cv_mem->cv_nlscoef = nlscoef;
  359. return(CV_SUCCESS);
  360. }
  361. /*
  362. * CVodeSetRootDirection
  363. *
  364. * Specifies the direction of zero-crossings to be monitored.
  365. * The default is to monitor both crossings.
  366. */
  367. SUNDIALS_EXPORT int CVodeSetRootDirection(void *cvode_mem, int *rootdir)
  368. {
  369. CVodeMem cv_mem;
  370. int i, nrt;
  371. if (cvode_mem==NULL) {
  372. cvProcessError(NULL, CV_MEM_NULL, "CVODE", "CVodeSetRootDirection", MSGCV_NO_MEM);
  373. return(CV_MEM_NULL);
  374. }
  375. cv_mem = (CVodeMem) cvode_mem;
  376. nrt = cv_mem->cv_nrtfn;
  377. if (nrt==0) {
  378. cvProcessError(NULL, CV_ILL_INPUT, "CVODE", "CVodeSetRootDirection", MSGCV_NO_ROOT);
  379. return(CV_ILL_INPUT);
  380. }
  381. for(i=0; i<nrt; i++) cv_mem->cv_rootdir[i] = rootdir[i];
  382. return(CV_SUCCESS);
  383. }
  384. /*
  385. * CVodeSetNoInactiveRootWarn
  386. *
  387. * Disables issuing a warning if some root function appears
  388. * to be identically zero at the beginning of the integration
  389. */
  390. SUNDIALS_EXPORT int CVodeSetNoInactiveRootWarn(void *cvode_mem)
  391. {
  392. CVodeMem cv_mem;
  393. if (cvode_mem==NULL) {
  394. cvProcessError(NULL, CV_MEM_NULL, "CVODE", "CVodeSetNoInactiveRootWarn", MSGCV_NO_MEM);
  395. return(CV_MEM_NULL);
  396. }
  397. cv_mem = (CVodeMem) cvode_mem;
  398. cv_mem->cv_mxgnull = 0;
  399. return(CV_SUCCESS);
  400. }
  401. /*
  402. * =================================================================
  403. * CVODE optional output functions
  404. * =================================================================
  405. */
  406. /*
  407. * Readability constants
  408. */
  409. #define nst (cv_mem->cv_nst)
  410. #define nfe (cv_mem->cv_nfe)
  411. #define ncfn (cv_mem->cv_ncfn)
  412. #define netf (cv_mem->cv_netf)
  413. #define nni (cv_mem->cv_nni)
  414. #define nsetups (cv_mem->cv_nsetups)
  415. #define qu (cv_mem->cv_qu)
  416. #define next_q (cv_mem->cv_next_q)
  417. #define ewt (cv_mem->cv_ewt)
  418. #define hu (cv_mem->cv_hu)
  419. #define next_h (cv_mem->cv_next_h)
  420. #define h0u (cv_mem->cv_h0u)
  421. #define tolsf (cv_mem->cv_tolsf)
  422. #define acor (cv_mem->cv_acor)
  423. #define lrw (cv_mem->cv_lrw)
  424. #define liw (cv_mem->cv_liw)
  425. #define nge (cv_mem->cv_nge)
  426. #define iroots (cv_mem->cv_iroots)
  427. #define nor (cv_mem->cv_nor)
  428. #define sldeton (cv_mem->cv_sldeton)
  429. #define tn (cv_mem->cv_tn)
  430. #define efun (cv_mem->cv_efun)
  431. /*
  432. * CVodeGetNumSteps
  433. *
  434. * Returns the current number of integration steps
  435. */
  436. SUNDIALS_EXPORT int CVodeGetNumSteps(void *cvode_mem, long int *nsteps)
  437. {
  438. CVodeMem cv_mem;
  439. if (cvode_mem==NULL) {
  440. cvProcessError(NULL, CV_MEM_NULL, "CVODE", "CVodeGetNumSteps", MSGCV_NO_MEM);
  441. return(CV_MEM_NULL);
  442. }
  443. cv_mem = (CVodeMem) cvode_mem;
  444. *nsteps = nst;
  445. return(CV_SUCCESS);
  446. }
  447. /*
  448. * CVodeGetNumRhsEvals
  449. *
  450. * Returns the current number of calls to f
  451. */
  452. SUNDIALS_EXPORT int CVodeGetNumRhsEvals(void *cvode_mem, long int *nfevals)
  453. {
  454. CVodeMem cv_mem;
  455. if (cvode_mem==NULL) {
  456. cvProcessError(NULL, CV_MEM_NULL, "CVODE", "CVodeGetNumRhsEvals", MSGCV_NO_MEM);
  457. return(CV_MEM_NULL);
  458. }
  459. cv_mem = (CVodeMem) cvode_mem;
  460. *nfevals = nfe;
  461. return(CV_SUCCESS);
  462. }
  463. /*
  464. * CVodeGetNumLinSolvSetups
  465. *
  466. * Returns the current number of calls to the linear solver setup routine
  467. */
  468. SUNDIALS_EXPORT int CVodeGetNumLinSolvSetups(void *cvode_mem, long int *nlinsetups)
  469. {
  470. CVodeMem cv_mem;
  471. if (cvode_mem==NULL) {
  472. cvProcessError(NULL, CV_MEM_NULL, "CVODE", "CVodeGetNumLinSolvSetups", MSGCV_NO_MEM);
  473. return(CV_MEM_NULL);
  474. }
  475. cv_mem = (CVodeMem) cvode_mem;
  476. *nlinsetups = nsetups;
  477. return(CV_SUCCESS);
  478. }
  479. /*
  480. * CVodeGetNumErrTestFails
  481. *
  482. * Returns the current number of error test failures
  483. */
  484. SUNDIALS_EXPORT int CVodeGetNumErrTestFails(void *cvode_mem, long int *netfails)
  485. {
  486. CVodeMem cv_mem;
  487. if (cvode_mem==NULL) {
  488. cvProcessError(NULL, CV_MEM_NULL, "CVODE", "CVodeGetNumErrTestFails", MSGCV_NO_MEM);
  489. return(CV_MEM_NULL);
  490. }
  491. cv_mem = (CVodeMem) cvode_mem;
  492. *netfails = netf;
  493. return(CV_SUCCESS);
  494. }
  495. /*
  496. * CVodeGetLastOrder
  497. *
  498. * Returns the order on the last succesful step
  499. */
  500. SUNDIALS_EXPORT int CVodeGetLastOrder(void *cvode_mem, int *qlast)
  501. {
  502. CVodeMem cv_mem;
  503. if (cvode_mem==NULL) {
  504. cvProcessError(NULL, CV_MEM_NULL, "CVODE", "CVodeGetLastOrder", MSGCV_NO_MEM);
  505. return(CV_MEM_NULL);
  506. }
  507. cv_mem = (CVodeMem) cvode_mem;
  508. *qlast = qu;
  509. return(CV_SUCCESS);
  510. }
  511. /*
  512. * CVodeGetCurrentOrder
  513. *
  514. * Returns the order to be attempted on the next step
  515. */
  516. SUNDIALS_EXPORT int CVodeGetCurrentOrder(void *cvode_mem, int *qcur)
  517. {
  518. CVodeMem cv_mem;
  519. if (cvode_mem==NULL) {
  520. cvProcessError(NULL, CV_MEM_NULL, "CVODE", "CVodeGetCurrentOrder", MSGCV_NO_MEM);
  521. return(CV_MEM_NULL);
  522. }
  523. cv_mem = (CVodeMem) cvode_mem;
  524. *qcur = next_q;
  525. return(CV_SUCCESS);
  526. }
  527. /*
  528. * CVodeGetNumStabLimOrderReds
  529. *
  530. * Returns the number of order reductions triggered by the stability
  531. * limit detection algorithm
  532. */
  533. SUNDIALS_EXPORT int CVodeGetNumStabLimOrderReds(void *cvode_mem, long int *nslred)
  534. {
  535. CVodeMem cv_mem;
  536. if (cvode_mem==NULL) {
  537. cvProcessError(NULL, CV_MEM_NULL, "CVODE", "CVodeGetNumStabLimOrderReds", MSGCV_NO_MEM);
  538. return(CV_MEM_NULL);
  539. }
  540. cv_mem = (CVodeMem) cvode_mem;
  541. if (sldeton==FALSE)
  542. *nslred = 0;
  543. else
  544. *nslred = nor;
  545. return(CV_SUCCESS);
  546. }
  547. /*
  548. * CVodeGetActualInitStep
  549. *
  550. * Returns the step size used on the first step
  551. */
  552. SUNDIALS_EXPORT int CVodeGetActualInitStep(void *cvode_mem, realtype *hinused)
  553. {
  554. CVodeMem cv_mem;
  555. if (cvode_mem==NULL) {
  556. cvProcessError(NULL, CV_MEM_NULL, "CVODE", "CVodeGetActualInitStep", MSGCV_NO_MEM);
  557. return(CV_MEM_NULL);
  558. }
  559. cv_mem = (CVodeMem) cvode_mem;
  560. *hinused = h0u;
  561. return(CV_SUCCESS);
  562. }
  563. /*
  564. * CVodeGetLastStep
  565. *
  566. * Returns the step size used on the last successful step
  567. */
  568. SUNDIALS_EXPORT int CVodeGetLastStep(void *cvode_mem, realtype *hlast)
  569. {
  570. CVodeMem cv_mem;
  571. if (cvode_mem==NULL) {
  572. cvProcessError(NULL, CV_MEM_NULL, "CVODE", "CVodeGetLastStep", MSGCV_NO_MEM);
  573. return(CV_MEM_NULL);
  574. }
  575. cv_mem = (CVodeMem) cvode_mem;
  576. *hlast = hu;
  577. return(CV_SUCCESS);
  578. }
  579. /*
  580. * CVodeGetCurrentStep
  581. *
  582. * Returns the step size to be attempted on the next step
  583. */
  584. SUNDIALS_EXPORT int CVodeGetCurrentStep(void *cvode_mem, realtype *hcur)
  585. {
  586. CVodeMem cv_mem;
  587. if (cvode_mem==NULL) {
  588. cvProcessError(NULL, CV_MEM_NULL, "CVODE", "CVodeGetCurrentStep", MSGCV_NO_MEM);
  589. return(CV_MEM_NULL);
  590. }
  591. cv_mem = (CVodeMem) cvode_mem;
  592. *hcur = next_h;
  593. return(CV_SUCCESS);
  594. }
  595. /*
  596. * CVodeGetCurrentTime
  597. *
  598. * Returns the current value of the independent variable
  599. */
  600. SUNDIALS_EXPORT int CVodeGetCurrentTime(void *cvode_mem, realtype *tcur)
  601. {
  602. CVodeMem cv_mem;
  603. if (cvode_mem==NULL) {
  604. cvProcessError(NULL, CV_MEM_NULL, "CVODE", "CVodeGetCurrentTime", MSGCV_NO_MEM);
  605. return(CV_MEM_NULL);
  606. }
  607. cv_mem = (CVodeMem) cvode_mem;
  608. *tcur = tn;
  609. return(CV_SUCCESS);
  610. }
  611. /*
  612. * CVodeGetTolScaleFactor
  613. *
  614. * Returns a suggested factor for scaling tolerances
  615. */
  616. SUNDIALS_EXPORT int CVodeGetTolScaleFactor(void *cvode_mem, realtype *tolsfact)
  617. {
  618. CVodeMem cv_mem;
  619. if (cvode_mem==NULL) {
  620. cvProcessError(NULL, CV_MEM_NULL, "CVODE", "CVodeGetTolScaleFactor", MSGCV_NO_MEM);
  621. return(CV_MEM_NULL);
  622. }
  623. cv_mem = (CVodeMem) cvode_mem;
  624. *tolsfact = tolsf;
  625. return(CV_SUCCESS);
  626. }
  627. /*
  628. * CVodeGetErrWeights
  629. *
  630. * This routine returns the current weight vector.
  631. */
  632. SUNDIALS_EXPORT int CVodeGetErrWeights(void *cvode_mem, N_Vector eweight)
  633. {
  634. CVodeMem cv_mem;
  635. if (cvode_mem==NULL) {
  636. cvProcessError(NULL, CV_MEM_NULL, "CVODE", "CVodeGetErrWeights", MSGCV_NO_MEM);
  637. return(CV_MEM_NULL);
  638. }
  639. cv_mem = (CVodeMem) cvode_mem;
  640. N_VScale(ONE, ewt, eweight);
  641. return(CV_SUCCESS);
  642. }
  643. /*
  644. * CVodeGetEstLocalErrors
  645. *
  646. * Returns an estimate of the local error
  647. */
  648. SUNDIALS_EXPORT int CVodeGetEstLocalErrors(void *cvode_mem, N_Vector ele)
  649. {
  650. CVodeMem cv_mem;
  651. if (cvode_mem==NULL) {
  652. cvProcessError(NULL, CV_MEM_NULL, "CVODE", "CVodeGetEstLocalErrors", MSGCV_NO_MEM);
  653. return(CV_MEM_NULL);
  654. }
  655. cv_mem = (CVodeMem) cvode_mem;
  656. N_VScale(ONE, acor, ele);
  657. return(CV_SUCCESS);
  658. }
  659. /*
  660. * CVodeGetWorkSpace
  661. *
  662. * Returns integrator work space requirements
  663. */
  664. SUNDIALS_EXPORT int CVodeGetWorkSpace(void *cvode_mem, long int *lenrw, long int *leniw)
  665. {
  666. CVodeMem cv_mem;
  667. if (cvode_mem==NULL) {
  668. cvProcessError(NULL, CV_MEM_NULL, "CVODE", "CVodeGetWorkSpace", MSGCV_NO_MEM);
  669. return(CV_MEM_NULL);
  670. }
  671. cv_mem = (CVodeMem) cvode_mem;
  672. *leniw = liw;
  673. *lenrw = lrw;
  674. return(CV_SUCCESS);
  675. }
  676. /*
  677. * CVodeGetIntegratorStats
  678. *
  679. * Returns integrator statistics
  680. */
  681. SUNDIALS_EXPORT int CVodeGetIntegratorStats(void *cvode_mem, long int *nsteps, long int *nfevals,
  682. long int *nlinsetups, long int *netfails, int *qlast,
  683. int *qcur, realtype *hinused, realtype *hlast,
  684. realtype *hcur, realtype *tcur)
  685. {
  686. CVodeMem cv_mem;
  687. if (cvode_mem==NULL) {
  688. cvProcessError(NULL, CV_MEM_NULL, "CVODE", "CVodeGetIntegratorStats", MSGCV_NO_MEM);
  689. return(CV_MEM_NULL);
  690. }
  691. cv_mem = (CVodeMem) cvode_mem;
  692. *nsteps = nst;
  693. *nfevals = nfe;
  694. *nlinsetups = nsetups;
  695. *netfails = netf;
  696. *qlast = qu;
  697. *qcur = next_q;
  698. *hinused = h0u;
  699. *hlast = hu;
  700. *hcur = next_h;
  701. *tcur = tn;
  702. return(CV_SUCCESS);
  703. }
  704. /*
  705. * CVodeGetNumGEvals
  706. *
  707. * Returns the current number of calls to g (for rootfinding)
  708. */
  709. SUNDIALS_EXPORT int CVodeGetNumGEvals(void *cvode_mem, long int *ngevals)
  710. {
  711. CVodeMem cv_mem;
  712. if (cvode_mem==NULL) {
  713. cvProcessError(NULL, CV_MEM_NULL, "CVODE", "CVodeGetNumGEvals", MSGCV_NO_MEM);
  714. return(CV_MEM_NULL);
  715. }
  716. cv_mem = (CVodeMem) cvode_mem;
  717. *ngevals = nge;
  718. return(CV_SUCCESS);
  719. }
  720. /*
  721. * CVodeGetRootInfo
  722. *
  723. * Returns pointer to array rootsfound showing roots found
  724. */
  725. SUNDIALS_EXPORT int CVodeGetRootInfo(void *cvode_mem, int *rootsfound)
  726. {
  727. CVodeMem cv_mem;
  728. int i, nrt;
  729. if (cvode_mem==NULL) {
  730. cvProcessError(NULL, CV_MEM_NULL, "CVODE", "CVodeGetRootInfo", MSGCV_NO_MEM);
  731. return(CV_MEM_NULL);
  732. }
  733. cv_mem = (CVodeMem) cvode_mem;
  734. nrt = cv_mem->cv_nrtfn;
  735. for (i=0; i<nrt; i++) rootsfound[i] = iroots[i];
  736. return(CV_SUCCESS);
  737. }
  738. /*
  739. * CVodeGetNumNonlinSolvIters
  740. *
  741. * Returns the current number of iterations in the nonlinear solver
  742. */
  743. SUNDIALS_EXPORT int CVodeGetNumNonlinSolvIters(void *cvode_mem, long int *nniters)
  744. {
  745. CVodeMem cv_mem;
  746. if (cvode_mem==NULL) {
  747. cvProcessError(NULL, CV_MEM_NULL, "CVODE", "CVodeGetNumNonlinSolvIters", MSGCV_NO_MEM);
  748. return(CV_MEM_NULL);
  749. }
  750. cv_mem = (CVodeMem) cvode_mem;
  751. *nniters = nni;
  752. return(CV_SUCCESS);
  753. }
  754. /*
  755. * CVodeGetNumNonlinSolvConvFails
  756. *
  757. * Returns the current number of convergence failures in the
  758. * nonlinear solver
  759. */
  760. SUNDIALS_EXPORT int CVodeGetNumNonlinSolvConvFails(void *cvode_mem, long int *nncfails)
  761. {
  762. CVodeMem cv_mem;
  763. if (cvode_mem==NULL) {
  764. cvProcessError(NULL, CV_MEM_NULL, "CVODE", "CVodeGetNumNonlinSolvConvFails", MSGCV_NO_MEM);
  765. return(CV_MEM_NULL);
  766. }
  767. cv_mem = (CVodeMem) cvode_mem;
  768. *nncfails = ncfn;
  769. return(CV_SUCCESS);
  770. }
  771. /*
  772. * CVodeGetNonlinSolvStats
  773. *
  774. * Returns nonlinear solver statistics
  775. */
  776. SUNDIALS_EXPORT int CVodeGetNonlinSolvStats(void *cvode_mem, long int *nniters,
  777. long int *nncfails)
  778. {
  779. CVodeMem cv_mem;
  780. if (cvode_mem==NULL) {
  781. cvProcessError(NULL, CV_MEM_NULL, "CVODE", "CVodeGetNonlinSolvStats", MSGCV_NO_MEM);
  782. return(CV_MEM_NULL);
  783. }
  784. cv_mem = (CVodeMem) cvode_mem;
  785. *nniters = nni;
  786. *nncfails = ncfn;
  787. return(CV_SUCCESS);
  788. }
  789. /*-----------------------------------------------------------------*/
  790. SUNDIALS_EXPORT char *CVodeGetReturnFlagName(long int flag)
  791. {
  792. char *name;
  793. name = (char *)malloc(24*sizeof(char));
  794. switch(flag) {
  795. case CV_SUCCESS:
  796. sprintf(name,"CV_SUCCESS");
  797. break;
  798. case CV_TSTOP_RETURN:
  799. sprintf(name,"CV_TSTOP_RETURN");
  800. break;
  801. case CV_ROOT_RETURN:
  802. sprintf(name,"CV_ROOT_RETURN");
  803. break;
  804. case CV_TOO_MUCH_WORK:
  805. sprintf(name,"CV_TOO_MUCH_WORK");
  806. break;
  807. case CV_TOO_MUCH_ACC:
  808. sprintf(name,"CV_TOO_MUCH_ACC");
  809. break;
  810. case CV_ERR_FAILURE:
  811. sprintf(name,"CV_ERR_FAILURE");
  812. break;
  813. case CV_CONV_FAILURE:
  814. sprintf(name,"CV_CONV_FAILURE");
  815. break;
  816. case CV_LINIT_FAIL:
  817. sprintf(name,"CV_LINIT_FAIL");
  818. break;
  819. case CV_LSETUP_FAIL:
  820. sprintf(name,"CV_LSETUP_FAIL");
  821. break;
  822. case CV_LSOLVE_FAIL:
  823. sprintf(name,"CV_LSOLVE_FAIL");
  824. break;
  825. case CV_RHSFUNC_FAIL:
  826. sprintf(name,"CV_RHSFUNC_FAIL");
  827. break;
  828. case CV_FIRST_RHSFUNC_ERR:
  829. sprintf(name,"CV_FIRST_RHSFUNC_ERR");
  830. break;
  831. case CV_REPTD_RHSFUNC_ERR:
  832. sprintf(name,"CV_REPTD_RHSFUNC_ERR");
  833. break;
  834. case CV_UNREC_RHSFUNC_ERR:
  835. sprintf(name,"CV_UNREC_RHSFUNC_ERR");
  836. break;
  837. case CV_RTFUNC_FAIL:
  838. sprintf(name,"CV_RTFUNC_FAIL");
  839. break;
  840. case CV_MEM_FAIL:
  841. sprintf(name,"CV_MEM_FAIL");
  842. break;
  843. case CV_MEM_NULL:
  844. sprintf(name,"CV_MEM_NULL");
  845. break;
  846. case CV_ILL_INPUT:
  847. sprintf(name,"CV_ILL_INPUT");
  848. break;
  849. case CV_NO_MALLOC:
  850. sprintf(name,"CV_NO_MALLOC");
  851. break;
  852. case CV_BAD_K:
  853. sprintf(name,"CV_BAD_K");
  854. break;
  855. case CV_BAD_T:
  856. sprintf(name,"CV_BAD_T");
  857. break;
  858. case CV_BAD_DKY:
  859. sprintf(name,"CV_BAD_DKY");
  860. break;
  861. case CV_TOO_CLOSE:
  862. sprintf(name,"CV_TOO_CLOSE");
  863. break;
  864. default:
  865. sprintf(name,"NONE");
  866. }
  867. return(name);
  868. }
  869. /* undefine to be able to compile all source code files in a single compilation unit, added by 3ds.com */
  870. #undef lrw
  871. #undef liw
  872. #undef lrw1
  873. #undef liw1