00001 /* 00002 * ----------------------------------------------------------------- 00003 * $Revision: 1.5 $ 00004 * $Date: 2006/11/29 00:05:06 $ 00005 * ----------------------------------------------------------------- 00006 * Programmer(s): Radu Serban @ LLNL 00007 * ----------------------------------------------------------------- 00008 * Copyright (c) 2005, The Regents of the University of California. 00009 * Produced at the Lawrence Livermore National Laboratory. 00010 * All rights reserved. 00011 * For details, see the LICENSE file. 00012 * ----------------------------------------------------------------- 00013 * This is the interface file for the main CVODES integrator. 00014 * ----------------------------------------------------------------- 00015 * 00016 * CVODES is used to solve numerically the ordinary initial value 00017 * problem: 00018 * 00019 * y' = f(t,y), 00020 * y(t0) = y0, 00021 * 00022 * where t0, y0 in R^N, and f: R x R^N -> R^N are given. 00023 * 00024 * Optionally, CVODES can perform forward or adjoint sensitivity 00025 * analysis to find sensitivities of the solution y with respect 00026 * to parameters in the right hand side f and/or in the initial 00027 * conditions y0. 00028 * 00029 * ----------------------------------------------------------------- 00030 */ 00031 00032 #ifndef _CVODES_H 00033 #define _CVODES_H 00034 00035 #ifdef __cplusplus /* wrapper to enable C++ usage */ 00036 extern "C" { 00037 #endif 00038 00039 #include <stdio.h> 00040 00041 #include <sundials/sundials_nvector.h> 00042 00043 /* 00044 * ================================================================= 00045 * C V O D E S C O N S T A N T S 00046 * ================================================================= 00047 */ 00048 00049 /* 00050 * ----------------------------------------------------------------- 00051 * Enumerations for inputs to CVodeCreate, CVodeMalloc, 00052 * CVodeReInit, CVodeSensMalloc, CVodeSensReInit, CVodeQuadMalloc, 00053 * CVodeQuadReInit, CVodeSet*, CVode, and CVadjMalloc. 00054 * ----------------------------------------------------------------- 00055 * Symbolic constants for the lmm, iter, and itol input parameters 00056 * to CVodeMalloc and CVodeReInit, the input parameter itask to CVode, 00057 * and the input parameter interp to CVadjMalloc, are given below. 00058 * 00059 * lmm: The user of the CVODES package specifies whether to use 00060 * the CV_ADAMS or CV_BDF (backward differentiation formula) 00061 * linear multistep method. The BDF method is recommended 00062 * for stiff problems, and the CV_ADAMS method is recommended 00063 * for nonstiff problems. 00064 * 00065 * iter: At each internal time step, a nonlinear equation must 00066 * be solved. The user can specify either CV_FUNCTIONAL 00067 * iteration, which does not require linear algebra, or a 00068 * CV_NEWTON iteration, which requires the solution of linear 00069 * systems. In the CV_NEWTON case, the user also specifies a 00070 * CVODE linear solver. CV_NEWTON is recommended in case of 00071 * stiff problems. 00072 * 00073 * itol: This parameter specifies the relative and absolute 00074 * tolerance types to be used. The CV_SS tolerance type means 00075 * a scalar relative and absolute tolerance. The CV_SV 00076 * tolerance type means a scalar relative tolerance and a 00077 * vector absolute tolerance (a potentially different 00078 * absolute tolerance for each vector component). The CV_WF 00079 * tolerance type means that the user provides a function 00080 * (of type CVEwtFn) to set the error weight vector. 00081 * 00082 * ism: This parameter specifies the sensitivity corrector type 00083 * to be used. In the CV_SIMULTANEOUS case, the nonlinear 00084 * systems for states and all sensitivities are solved 00085 * simultaneously. In the CV_STAGGERED case, the nonlinear 00086 * system for states is solved first and then, the 00087 * nonlinear systems for all sensitivities are solved 00088 * at the same time. Finally, in the CV_STAGGERED1 approach 00089 * all nonlinear systems are solved in a sequence. 00090 * 00091 * itask: The itask input parameter to CVode indicates the job 00092 * of the solver for the next user step. The CV_NORMAL 00093 * itask is to have the solver take internal steps until 00094 * it has reached or just passed the user specified tout 00095 * parameter. The solver then interpolates in order to 00096 * return an approximate value of y(tout). The CV_ONE_STEP 00097 * option tells the solver to just take one internal step 00098 * and return the solution at the point reached by that 00099 * step. The CV_NORMAL_TSTOP and CV_ONE_STEP_TSTOP modes are 00100 * similar to CV_NORMAL and CV_ONE_STEP, respectively, except 00101 * that the integration never proceeds past the value 00102 * tstop (specified through the routine CVodeSetStopTime). 00103 * 00104 * interp: Specifies the interpolation type used to evaluate the 00105 * forward solution during the backward integration phase. 00106 * CV_HERMITE specifies cubic Hermite interpolation. 00107 * CV_POYNOMIAL specifies the polynomial interpolation 00108 * ----------------------------------------------------------------- 00109 */ 00110 00111 /* lmm */ 00112 #define CV_ADAMS 1 00113 #define CV_BDF 2 00114 00115 /* iter */ 00116 #define CV_FUNCTIONAL 1 00117 #define CV_NEWTON 2 00118 00119 /* itol */ 00120 #define CV_SS 1 00121 #define CV_SV 2 00122 #define CV_WF 3 00123 #define CV_EE 4 00124 00125 /* itask */ 00126 #define CV_NORMAL 1 00127 #define CV_ONE_STEP 2 00128 #define CV_NORMAL_TSTOP 3 00129 #define CV_ONE_STEP_TSTOP 4 00130 00131 /* ism */ 00132 #define CV_SIMULTANEOUS 1 00133 #define CV_STAGGERED 2 00134 #define CV_STAGGERED1 3 00135 00136 /* DQtype */ 00137 #define CV_CENTERED 1 00138 #define CV_FORWARD 2 00139 00140 /* interp */ 00141 #define CV_HERMITE 1 00142 #define CV_POLYNOMIAL 2 00143 00144 /* 00145 * ---------------------------------------- 00146 * CVODES return flags 00147 * ---------------------------------------- 00148 */ 00149 00150 #define CV_SUCCESS 0 00151 #define CV_TSTOP_RETURN 1 00152 #define CV_ROOT_RETURN 2 00153 00154 #define CV_WARNING 99 00155 00156 #define CV_TOO_MUCH_WORK -1 00157 #define CV_TOO_MUCH_ACC -2 00158 #define CV_ERR_FAILURE -3 00159 #define CV_CONV_FAILURE -4 00160 00161 #define CV_LINIT_FAIL -5 00162 #define CV_LSETUP_FAIL -6 00163 #define CV_LSOLVE_FAIL -7 00164 #define CV_RHSFUNC_FAIL -8 00165 #define CV_FIRST_RHSFUNC_ERR -9 00166 #define CV_REPTD_RHSFUNC_ERR -10 00167 #define CV_UNREC_RHSFUNC_ERR -11 00168 #define CV_RTFUNC_FAIL -12 00169 00170 #define CV_MEM_FAIL -20 00171 #define CV_MEM_NULL -21 00172 #define CV_ILL_INPUT -22 00173 #define CV_NO_MALLOC -23 00174 #define CV_BAD_K -24 00175 #define CV_BAD_T -25 00176 #define CV_BAD_DKY -26 00177 #define CV_TOO_CLOSE -27 00178 00179 #define CV_NO_QUAD -30 00180 #define CV_QRHSFUNC_FAIL -31 00181 #define CV_FIRST_QRHSFUNC_ERR -32 00182 #define CV_REPTD_QRHSFUNC_ERR -33 00183 #define CV_UNREC_QRHSFUNC_ERR -34 00184 00185 #define CV_BAD_IS -40 00186 #define CV_NO_SENS -41 00187 #define CV_SRHSFUNC_FAIL -42 00188 #define CV_FIRST_SRHSFUNC_ERR -43 00189 #define CV_REPTD_SRHSFUNC_ERR -44 00190 #define CV_UNREC_SRHSFUNC_ERR -45 00191 00192 /* 00193 * ---------------------------------------- 00194 * CVODEA return flags 00195 * ---------------------------------------- 00196 */ 00197 00198 #define CV_ADJMEM_NULL -101 00199 #define CV_BAD_TB0 -103 00200 #define CV_BCKMEM_NULL -104 00201 #define CV_REIFWD_FAIL -105 00202 #define CV_FWD_FAIL -106 00203 #define CV_BAD_ITASK -107 00204 #define CV_BAD_TBOUT -108 00205 #define CV_GETY_BADT -109 00206 00207 /* 00208 * ================================================================= 00209 * F U N C T I O N T Y P E S 00210 * ================================================================= 00211 */ 00212 00213 /* 00214 * ----------------------------------------------------------------- 00215 * Type : CVRhsFn 00216 * ----------------------------------------------------------------- 00217 * The f function which defines the right hand side of the ODE 00218 * system y' = f(t,y) must have type CVRhsFn. 00219 * f takes as input the independent variable value t, and the 00220 * dependent variable vector y. It stores the result of f(t,y) 00221 * in the vector ydot. The y and ydot arguments are of type 00222 * N_Vector. 00223 * (Allocation of memory for ydot is handled within CVODES) 00224 * The f_data parameter is the same as the f_data 00225 * parameter set by the user through the CVodeSetFdata routine. 00226 * This user-supplied pointer is passed to the user's f function 00227 * every time it is called. 00228 * 00229 * A CVRhsFn should return 0 if successful, a negative value if 00230 * an unrecoverable error occured, and a positive value if a 00231 * recoverable error (e.g. invalid y values) occured. 00232 * If an unrecoverable occured, the integration is halted. 00233 * If a recoverable error occured, then (in most cases) CVODES 00234 * will try to correct and retry. 00235 * ----------------------------------------------------------------- 00236 */ 00237 00238 typedef int (*CVRhsFn)(realtype t, N_Vector y, 00239 N_Vector ydot, void *f_data); 00240 00241 /* 00242 * ----------------------------------------------------------------- 00243 * Type : CVRootFn 00244 * ----------------------------------------------------------------- 00245 * A function g, which defines a set of functions g_i(t,y) whose 00246 * roots are sought during the integration, must have type CVRootFn. 00247 * The function g takes as input the independent variable value 00248 * t, and the dependent variable vector y. It stores the nrtfn 00249 * values g_i(t,y) in the realtype array gout. 00250 * (Allocation of memory for gout is handled within CVODE.) 00251 * The g_data parameter is the same as that passed by the user 00252 * to the CVodeRootInit routine. This user-supplied pointer is 00253 * passed to the user's g function every time it is called. 00254 * 00255 * A CVRootFn should return 0 if successful or a non-zero value 00256 * if an error occured (in which case the integration will be halted). 00257 * ----------------------------------------------------------------- 00258 */ 00259 00260 typedef int (*CVRootFn)(realtype t, N_Vector y, realtype *gout, 00261 void *g_data); 00262 00263 /* 00264 * ----------------------------------------------------------------- 00265 * Type : CVEwtFn 00266 * ----------------------------------------------------------------- 00267 * A function e, which sets the error weight vector ewt, must have 00268 * type CVEwtFn. 00269 * The function e takes as input the current dependent variable y. 00270 * It must set the vector of error weights used in the WRMS norm: 00271 * 00272 * ||y||_WRMS = sqrt [ 1/N * sum ( ewt_i * y_i)^2 ] 00273 * 00274 * Typically, the vector ewt has components: 00275 * 00276 * ewt_i = 1 / (reltol * |y_i| + abstol_i) 00277 * 00278 * The e_data parameter is the same as that passed by the user 00279 * to the CVodeSetEdata routine. This user-supplied pointer is 00280 * passed to the user's e function every time it is called. 00281 * A CVEwtFn e must return 0 if the error weight vector has been 00282 * successfuly set and a non-zero value otherwise. 00283 * ----------------------------------------------------------------- 00284 */ 00285 00286 typedef int (*CVEwtFn)(N_Vector y, N_Vector ewt, void *e_data); 00287 00288 00289 /* 00290 * ----------------------------------------------------------------- 00291 * Type : CVErrHandlerFn 00292 * ----------------------------------------------------------------- 00293 * A function eh, which handles error messages, must have type 00294 * CVErrHandlerFn. 00295 * The function eh takes as input the error code, the name of the 00296 * module reporting the error, the error message, and a pointer to 00297 * user data, the same as that passed to CVodeSetErrHandlerFn. 00298 * 00299 * All error codes are negative, except CV_WARNING which indicates 00300 * a warning (the solver continues). 00301 * 00302 * A CVErrHandlerFn has no return value. 00303 * ----------------------------------------------------------------- 00304 */ 00305 00306 typedef void (*CVErrHandlerFn)(int error_code, 00307 const char *module, const char *function, 00308 char *msg, void *eh_data); 00309 00310 /* 00311 * ----------------------------------------------------------------- 00312 * Type : CVQuadRhsFn 00313 * ----------------------------------------------------------------- 00314 * The fQ function which defines the right hand side of the 00315 * quadrature equations yQ' = fQ(t,y) must have type CVQuadRhsFn. 00316 * fQ takes as input the value of the independent variable t, 00317 * the vector of states y and must store the result of fQ in 00318 * yQdot. (Allocation of memory for yQdot is handled by CVODES). 00319 * The fQ_data parameter is the same as the fQ_data parameter 00320 * set by the user through the CVodeSetQuadFdata routine and is 00321 * passed to the fQ function every time it is called. 00322 * 00323 * A CVQuadRhsFn should return 0 if successful, a negative value if 00324 * an unrecoverable error occured, and a positive value if a 00325 * recoverable error (e.g. invalid y values) occured. 00326 * If an unrecoverable occured, the integration is halted. 00327 * If a recoverable error occured, then (in most cases) CVODES 00328 * will try to correct and retry. 00329 * ----------------------------------------------------------------- 00330 */ 00331 00332 typedef int (*CVQuadRhsFn)(realtype t, N_Vector y, N_Vector yQdot, 00333 void *fQ_data); 00334 00335 /* 00336 * ----------------------------------------------------------------- 00337 * Type : CVSensRhsFn 00338 * ----------------------------------------------------------------- 00339 * The fS function which defines the right hand side of the 00340 * sensitivity ODE systems s' = f_y * s + f_p must have type 00341 * CVSensRhsFn. 00342 * fS takes as input the number of sensitivities Ns, the 00343 * independent variable value t, the states y and the 00344 * corresponding value of f(t,y) in ydot, and the dependent 00345 * sensitivity vectors yS. It stores the result of fS in ySdot. 00346 * (Allocation of memory for ySdot is handled within CVODES) 00347 * The fS_data parameter is the same as the fS_data parameter 00348 * set by the user through the CVodeSetSensFdata routine and is 00349 * passed to the fS function every time it is called. 00350 * 00351 * A CVSensRhsFn should return 0 if successful, a negative value if 00352 * an unrecoverable error occured, and a positive value if a 00353 * recoverable error (e.g. invalid y or yS values) occured. 00354 * If an unrecoverable occured, the integration is halted. 00355 * If a recoverable error occured, then (in most cases) CVODES 00356 * will try to correct and retry. 00357 * ----------------------------------------------------------------- 00358 */ 00359 00360 typedef int (*CVSensRhsFn)(int Ns, realtype t, 00361 N_Vector y, N_Vector ydot, 00362 N_Vector *yS, N_Vector *ySdot, 00363 void *fS_data, 00364 N_Vector tmp1, N_Vector tmp2); 00365 00366 /* 00367 * ----------------------------------------------------------------- 00368 * Type : CVSensRhs1Fn 00369 * ----------------------------------------------------------------- 00370 * The fS1 function which defines the right hand side of the i-th 00371 * sensitivity ODE system s_i' = f_y * s_i + f_p must have type 00372 * CVSensRhs1Fn. 00373 * fS1 takes as input the number of sensitivities Ns, the current 00374 * sensitivity iS, the independent variable value t, the states y 00375 * and the corresponding value of f(t,y) in ydot, and the 00376 * dependent sensitivity vector yS. It stores the result of fS in 00377 * ySdot. 00378 * (Allocation of memory for ySdot is handled within CVODES) 00379 * The fS_data parameter is the same as the fS_data parameter 00380 * set by the user through the CVodeSetSensFdata routine and is 00381 * passed to the fS1 function every time it is called. 00382 * 00383 * A CVSensRhs1Fn should return 0 if successful, a negative value if 00384 * an unrecoverable error occured, and a positive value if a 00385 * recoverable error (e.g. invalid y or yS values) occured. 00386 * If an unrecoverable occured, the integration is halted. 00387 * If a recoverable error occured, then (in most cases) CVODES 00388 * will try to correct and retry. 00389 * ----------------------------------------------------------------- 00390 */ 00391 00392 typedef int (*CVSensRhs1Fn)(int Ns, realtype t, 00393 N_Vector y, N_Vector ydot, 00394 int iS, N_Vector yS, N_Vector ySdot, 00395 void *fS_data, 00396 N_Vector tmp1, N_Vector tmp2); 00397 00398 /* 00399 * ----------------------------------------------------------------- 00400 * CVRhsFnB 00401 * The fB function which defines the right hand side of the 00402 * ODE systems to be integrated backwards must have type CVRhsFnB. 00403 * ----------------------------------------------------------------- 00404 * CVQuadRhsFnB 00405 * The fQB function which defines the quadratures to be integrated 00406 * backwards must have type CVQuadRhsFnB. 00407 * ----------------------------------------------------------------- 00408 */ 00409 00410 typedef int (*CVRhsFnB)(realtype t, N_Vector y, 00411 N_Vector yB, N_Vector yBdot, 00412 void *f_dataB); 00413 00414 typedef int (*CVQuadRhsFnB)(realtype t, N_Vector y, 00415 N_Vector yB, N_Vector qBdot, 00416 void *fQ_dataB); 00417 00418 /* 00419 * ================================================================= 00420 * U S E R - C A L L A B L E R O U T I N E S 00421 * ================================================================= 00422 */ 00423 00424 /* 00425 * ----------------------------------------------------------------- 00426 * Function : CVodeCreate 00427 * ----------------------------------------------------------------- 00428 * CVodeCreate creates an internal memory block for a problem to 00429 * be solved by CVODES. 00430 * 00431 * lmm is the type of linear multistep method to be used. 00432 * The legal values are CV_ADAMS and CV_BDF (see previous 00433 * description). 00434 * 00435 * iter is the type of iteration used to solve the nonlinear 00436 * system that arises during each internal time step. 00437 * The legal values are CV_FUNCTIONAL and CV_NEWTON. 00438 * 00439 * If successful, CVodeCreate returns a pointer to initialized 00440 * problem memory. This pointer should be passed to CVodeMalloc. 00441 * If an initialization error occurs, CVodeCreate prints an error 00442 * message to standard err and returns NULL. 00443 * ----------------------------------------------------------------- 00444 */ 00445 00446 SUNDIALS_EXPORT void *CVodeCreate(int lmm, int iter); 00447 00448 /* 00449 * ----------------------------------------------------------------- 00450 * Integrator optional input specification functions 00451 * ----------------------------------------------------------------- 00452 * The following functions can be called to set optional inputs 00453 * to values other than the defaults given below: 00454 * 00455 * Function | Optional input / [ default value ] 00456 * ----------------------------------------------------------------- 00457 * | 00458 * CVodeSetErrHandlerFn | user-provided ErrHandler function. 00459 * | [internal] 00460 * | 00461 * CVodeSetErrFile | the file pointer for an error file 00462 * | where all CVODE warning and error 00463 * | messages will be written if the default 00464 * | internal error handling function is used. 00465 * | This parameter can be stdout (standard 00466 * | output), stderr (standard error), or a 00467 * | file pointer (corresponding to a user 00468 * | error file opened for writing) returned 00469 * | by fopen. 00470 * | If not called, then all messages will 00471 * | be written to the standard error stream. 00472 * | [stderr] 00473 * | 00474 * CVodeSetFdata | a pointer to user data that will be 00475 * | passed to the user's f function every 00476 * | time f is called. 00477 * | [NULL] 00478 * | 00479 * CVodeSetEwtFn | user-provide EwtSet function e and 00480 * | a pointer to user data that will be 00481 * | passed to the user's e function every 00482 * | time e is called. 00483 * | [NULL] 00484 * | [NULL] 00485 * | 00486 * CVodeSetMaxOrd | maximum lmm order to be used by the 00487 * | solver. 00488 * | [12 for Adams , 5 for BDF] 00489 * | 00490 * CVodeSetMaxNumSteps | maximum number of internal steps to be 00491 * | taken by the solver in its attempt to 00492 * | reach tout. 00493 * | [500] 00494 * | 00495 * CVodeSetMaxHnilWarns | maximum number of warning messages 00496 * | issued by the solver that t+h==t on the 00497 * | next internal step. A value of -1 means 00498 * | no such messages are issued. 00499 * | [10] 00500 * | 00501 * CVodeSetStabLimDet | flag to turn on/off stability limit 00502 * | detection (TRUE = on, FALSE = off). 00503 * | When BDF is used and order is 3 or 00504 * | greater, CVsldet is called to detect 00505 * | stability limit. If limit is detected, 00506 * | the order is reduced. 00507 * | [FALSE] 00508 * | 00509 * CVodeSetInitStep | initial step size. 00510 * | [estimated by CVODES] 00511 * | 00512 * CVodeSetMinStep | minimum absolute value of step size 00513 * | allowed. 00514 * | [0.0] 00515 * | 00516 * CVodeSetMaxStep | maximum absolute value of step size 00517 * | allowed. 00518 * | [infinity] 00519 * | 00520 * CVodeSetStopTime | the independent variable value past 00521 * | which the solution is not to proceed. 00522 * | [infinity] 00523 * | 00524 * CVodeSetMaxErrTestFails | Maximum number of error test failures 00525 * | in attempting one step. 00526 * | [7] 00527 * | 00528 * CVodeSetMaxNonlinIters | Maximum number of nonlinear solver 00529 * | iterations at one solution. 00530 * | [3] 00531 * | 00532 * CVodeSetMaxConvFails | Maximum number of allowable conv. 00533 * | failures in attempting one step. 00534 * | [10] 00535 * | 00536 * CVodeSetNonlinConvCoef | Coeficient in the nonlinear conv. 00537 * | test. 00538 * | [0.1] 00539 * | 00540 * ----------------------------------------------------------------- 00541 * | 00542 * CVodeSetIterType | Changes the current nonlinear iteration 00543 * | type. 00544 * | [set by CVodecreate] 00545 * | 00546 * CVodeSetTolerances | Changes the integration tolerances 00547 * | between calls to CVode(). 00548 * | [set by CVodeMalloc/CVodeReInit] 00549 * | 00550 * ----------------------------------------------------------------- 00551 * Return flag: 00552 * CV_SUCCESS if successful 00553 * CV_MEM_NULL if the cvode memory is NULL 00554 * CV_ILL_INPUT if an argument has an illegal value 00555 * ----------------------------------------------------------------- 00556 */ 00557 00558 SUNDIALS_EXPORT int CVodeSetErrHandlerFn(void *cvode_mem, CVErrHandlerFn ehfun, void *eh_data); 00559 SUNDIALS_EXPORT int CVodeSetErrFile(void *cvode_mem, FILE *errfp); 00560 SUNDIALS_EXPORT int CVodeSetFdata(void *cvode_mem, void *f_data); 00561 SUNDIALS_EXPORT int CVodeSetEwtFn(void *cvode_mem, CVEwtFn efun, void *e_data); 00562 SUNDIALS_EXPORT int CVodeSetMaxOrd(void *cvode_mem, int maxord); 00563 SUNDIALS_EXPORT int CVodeSetMaxNumSteps(void *cvode_mem, long int mxsteps); 00564 SUNDIALS_EXPORT int CVodeSetMaxHnilWarns(void *cvode_mem, int mxhnil); 00565 SUNDIALS_EXPORT int CVodeSetStabLimDet(void *cvode_mem, booleantype stldet); 00566 SUNDIALS_EXPORT int CVodeSetInitStep(void *cvode_mem, realtype hin); 00567 SUNDIALS_EXPORT int CVodeSetMinStep(void *cvode_mem, realtype hmin); 00568 SUNDIALS_EXPORT int CVodeSetMaxStep(void *cvode_mem, realtype hmax); 00569 SUNDIALS_EXPORT int CVodeSetStopTime(void *cvode_mem, realtype tstop); 00570 SUNDIALS_EXPORT int CVodeSetMaxErrTestFails(void *cvode_mem, int maxnef); 00571 SUNDIALS_EXPORT int CVodeSetMaxNonlinIters(void *cvode_mem, int maxcor); 00572 SUNDIALS_EXPORT int CVodeSetMaxConvFails(void *cvode_mem, int maxncf); 00573 SUNDIALS_EXPORT int CVodeSetNonlinConvCoef(void *cvode_mem, realtype nlscoef); 00574 00575 SUNDIALS_EXPORT int CVodeSetIterType(void *cvode_mem, int iter); 00576 SUNDIALS_EXPORT int CVodeSetTolerances(void *cvode_mem, 00577 int itol, realtype reltol, void *abstol); 00578 00579 /* 00580 * ----------------------------------------------------------------- 00581 * Function : CVodeMalloc 00582 * ----------------------------------------------------------------- 00583 * CVodeMalloc allocates and initializes memory for a problem to 00584 * to be solved by CVODES. 00585 * 00586 * cvode_mem is pointer to CVODES memory returned by CVodeCreate. 00587 * 00588 * f is the right hand side function in y' = f(t,y). 00589 * 00590 * t0 is the initial value of t. 00591 * 00592 * y0 is the initial condition vector y(t0). 00593 * 00594 * itol is the type of tolerances to be used. 00595 * The legal values are: 00596 * CV_SS (scalar relative and absolute tolerances), 00597 * CV_SV (scalar relative tolerance and vector 00598 * absolute tolerance). 00599 * CV_WF (indicates that the user will provide a 00600 * function to evaluate the error weights. 00601 * In this case, reltol and abstol are ignored.) 00602 * 00603 * reltol is the relative tolerance scalar. 00604 * 00605 * abstol is a pointer to the absolute tolerance scalar or 00606 * an N_Vector of absolute tolerances. 00607 * 00608 * The parameters itol, reltol, and abstol define a vector of 00609 * error weights, ewt, with components 00610 * ewt[i] = 1/(reltol*abs(y[i]) + abstol) (if itol = CV_SS), or 00611 * ewt[i] = 1/(reltol*abs(y[i]) + abstol[i]) (if itol = CV_SV). 00612 * This vector is used in all error and convergence tests, which 00613 * use a weighted RMS norm on all error-like vectors v: 00614 * WRMSnorm(v) = sqrt( (1/N) sum(i=1..N) (v[i]*ewt[i])^2 ), 00615 * where N is the problem dimension. 00616 * 00617 * If successful, CVodeMalloc returns SUCCESS. If an argument has 00618 * an illegal value, CVodeMalloc prints an error message to the 00619 * file specified by errfp and returns one of the error flags 00620 * defined below. 00621 * ----------------------------------------------------------------- 00622 */ 00623 00624 SUNDIALS_EXPORT int CVodeMalloc(void *cvode_mem, CVRhsFn f, 00625 realtype t0, N_Vector y0, 00626 int itol, realtype reltol, void *abstol); 00627 00628 /* 00629 * ----------------------------------------------------------------- 00630 * Function : CVodeReInit 00631 * ----------------------------------------------------------------- 00632 * CVodeReInit re-initializes CVode for the solution of a problem, 00633 * where a prior call to CVodeMalloc has been made with the same 00634 * problem size N. CVodeReInit performs the same input checking 00635 * and initializations that CVodeMalloc does. 00636 * But it does no memory allocation, assuming that the existing 00637 * internal memory is sufficient for the new problem. 00638 * 00639 * The use of CVodeReInit requires that the maximum method order, 00640 * maxord, is no larger for the new problem than for the problem 00641 * specified in the last call to CVodeMalloc. This condition is 00642 * automatically fulfilled if the multistep method parameter lmm 00643 * is unchanged (or changed from CV_ADAMS to CV_BDF) and the default 00644 * value for maxord is specified. 00645 * 00646 * The first argument to CVodeReInit is: 00647 * 00648 * cvode_mem = pointer to CVODES memory returned by CVodeCreate. 00649 * 00650 * All the remaining arguments to CVodeReInit have names and 00651 * meanings identical to those of CVodeMalloc. 00652 * 00653 * The return value of CVodeReInit is equal to CV_SUCCESS = 0 if 00654 * there were no errors; otherwise it is a negative int equal to: 00655 * CV_MEM_NULL indicating cvode_mem was NULL (i.e., 00656 * CVodeCreate has not been called). 00657 * CV_NO_MALLOC indicating that cvode_mem has not been 00658 * allocated (i.e., CVodeMalloc has not been 00659 * called). 00660 * CV_ILL_INPUT indicating an input argument was illegal 00661 * (including an attempt to increase maxord). 00662 * In case of an error return, an error message is also printed. 00663 * ----------------------------------------------------------------- 00664 */ 00665 00666 SUNDIALS_EXPORT int CVodeReInit(void *cvode_mem, CVRhsFn f, 00667 realtype t0, N_Vector y0, 00668 int itol, realtype reltol, void *abstol); 00669 00670 /* 00671 * ----------------------------------------------------------------- 00672 * Function : CVodeRootInit 00673 * ----------------------------------------------------------------- 00674 * CVodeRootInit initializes a rootfinding problem to be solved 00675 * during the integration of the ODE system. It must be called 00676 * after CVodeCreate, and before CVode. The arguments are: 00677 * 00678 * cvode_mem = pointer to CVODE memory returned by CVodeCreate. 00679 * 00680 * nrtfn = number of functions g_i, an int >= 0. 00681 * 00682 * g = name of user-supplied function, of type CVRootFn, 00683 * defining the functions g_i whose roots are sought. 00684 * 00685 * g_data = a pointer to user data that will be passed to the 00686 * user's g function every time g is called. 00687 * 00688 * If a new problem is to be solved with a call to CVodeReInit, 00689 * where the new problem has no root functions but the prior one 00690 * did, then call CVodeRootInit with nrtfn = 0. 00691 * 00692 * The return value of CVodeRootInit is CV_SUCCESS = 0 if there were 00693 * no errors; otherwise it is a negative int equal to: 00694 * CV_MEM_NULL indicating cvode_mem was NULL, or 00695 * CV_MEM_FAIL indicating a memory allocation failed. 00696 * (including an attempt to increase maxord). 00697 * CV_ILL_INPUT indicating nrtfn > 0 but g = NULL. 00698 * In case of an error return, an error message is also printed. 00699 * ----------------------------------------------------------------- 00700 */ 00701 00702 SUNDIALS_EXPORT int CVodeRootInit(void *cvode_mem, int nrtfn, CVRootFn g, void *g_data); 00703 00704 /* 00705 * ----------------------------------------------------------------- 00706 * Quadrature optional input specification functions 00707 * ----------------------------------------------------------------- 00708 * The following functions can be called to set optional inputs 00709 * to values other than the defaults given below: 00710 * 00711 * Function | Optional input / [ default value ] 00712 * -------------------------------------------------------------- 00713 * | 00714 * CVodeSetQuadFdata | a pointer to user data that will be 00715 * | passed to the user's fQ function every 00716 * | time fQ is called. 00717 * | [NULL] 00718 * | 00719 * CVodeSetQuadErrCon | are quadrature variables considered in 00720 * | the error control? 00721 * | If yes, set tolerances for quadrature 00722 * | integration. 00723 * | [errconQ = FALSE] 00724 * | [ not tolerances] 00725 * | 00726 * ----------------------------------------------------------------- 00727 * If successful, these functions return CV_SUCCESS. If an argument 00728 * has an illegal value, they return one of the error flags 00729 * defined for the CVodeSet* routines. 00730 * ----------------------------------------------------------------- 00731 */ 00732 00733 SUNDIALS_EXPORT int CVodeSetQuadFdata(void *cvode_mem, void *fQ_data); 00734 SUNDIALS_EXPORT int CVodeSetQuadErrCon(void *cvode_mem, booleantype errconQ, 00735 int itolQ, realtype reltolQ, void *abstolQ); 00736 00737 /* 00738 * ----------------------------------------------------------------- 00739 * Function : CVodeQuadMalloc 00740 * ----------------------------------------------------------------- 00741 * CVodeQuadMalloc allocates and initializes memory related to 00742 * quadrature integration. 00743 * 00744 * cvode_mem is a pointer to CVODES memory returned by CVodeCreate 00745 * 00746 * fQ is the user-provided integrand routine. 00747 * 00748 * yQ0 is an N_Vector with initial values for quadratures 00749 * (typically yQ0 has all zero components). 00750 * 00751 * Return values: 00752 * CV_SUCCESS if successful 00753 * CV_MEM_NULL if the cvode memory was NULL 00754 * CV_MEM_FAIL if a memory allocation failed 00755 * ----------------------------------------------------------------- 00756 */ 00757 00758 SUNDIALS_EXPORT int CVodeQuadMalloc(void *cvode_mem, CVQuadRhsFn fQ, N_Vector yQ0); 00759 00760 /* 00761 * ----------------------------------------------------------------- 00762 * Function : CVodeQuadReInit 00763 * ----------------------------------------------------------------- 00764 * CVodeQuadReInit re-initializes CVODES's quadrature related 00765 * memory for a problem, assuming it has already been allocated 00766 * in prior calls to CVodeMalloc and CVodeQuadMalloc. 00767 * 00768 * All problem specification inputs are checked for errors. 00769 * The number of quadratures Nq is assumed to be unchanged 00770 * since the previous call to CVodeQuadMalloc. 00771 * 00772 * Return values: 00773 * CV_SUCCESS if successful 00774 * CV_MEM_NULL if the cvode memory was NULL 00775 * CV_NO_QUAD if quadratures were not initialized 00776 * ----------------------------------------------------------------- 00777 */ 00778 00779 SUNDIALS_EXPORT int CVodeQuadReInit(void *cvode_mem, CVQuadRhsFn fQ, N_Vector yQ0); 00780 00781 /* 00782 * ----------------------------------------------------------------- 00783 * Forward sensitivity optional input specification functions 00784 * ----------------------------------------------------------------- 00785 * The following functions can be called to set optional inputs 00786 * to other values than the defaults given below: 00787 * 00788 * Function | Optional input / [ default value ] 00789 * ----------------------------------------------------------------- 00790 * | 00791 * CVodeSetSensRhsFn | sensitivity right hand side function 00792 * | and user data pointer. 00793 * | This function must compute right hand 00794 * | sides for all sensitivity equations. 00795 * | [CVODES difference quotient approx.] 00796 * | [internal] 00797 * | 00798 * CVodeSetSensRhs1Fn | the sensitivity right hand side 00799 * | and user data pointer. 00800 * | This function must compute right hand 00801 * | sides for one sensitivity equation at a 00802 * | time. 00803 * | [CVODES difference quotient approx.] 00804 * | [internal] 00805 * | 00806 * CVodeSetSensDQMethod | controls the selection of finite 00807 * | difference schemes used in evaluating 00808 * | the sensitivity right hand sides: 00809 * | (centered vs. forward and 00810 * | simultaneous vs. separate) 00811 * | [DQtype=CV_CENTERED] 00812 * | [DQrhomax=0.0] 00813 * | 00814 * CVodeSetSensParams | parameter information: 00815 * | p: pointer to problem parameters 00816 * | plist: list of parameters with respect 00817 * | to which sensitivities are to be 00818 * | computed. 00819 * | pbar: order of magnitude info. 00820 * | Typically, if p[plist[i]] is nonzero, 00821 * | pbar[i]=p[plist[i]]. 00822 * | [p=NULL] 00823 * | [plist=NULL] 00824 * | [pbar=NULL] 00825 * | 00826 * CVodeSetSensErrCon | are sensitivity variables considered in 00827 * | the error control? 00828 * | [FALSE] 00829 * | 00830 * CVodeSetSensTolerances | type of sensi absolute tolerances. 00831 * | 00832 * | sensitivity relative tolerance scalar. 00833 * | 00834 * | pointer to the array of sensi 00835 * | abs tol scalars or a pointer 00836 * | to the array of N_Vector sensi 00837 * | absolute tolerances. 00838 * | [itolS = itol] 00839 * | [reltolS = reltol] 00840 * | [abstolS estimated by CVODES] 00841 * | 00842 * CVodeSetSensMaxNonlinIters | Maximum number of nonlinear solver 00843 * | iterations at one solution. 00844 * | [3] 00845 * | 00846 * ----------------------------------------------------------------- 00847 * The return values are the same as for CVodeSet* 00848 * ----------------------------------------------------------------- 00849 */ 00850 00851 SUNDIALS_EXPORT int CVodeSetSensRhsFn(void *cvode_mem, CVSensRhsFn f, void *fS_dataS); 00852 SUNDIALS_EXPORT int CVodeSetSensRhs1Fn(void *cvode_mem, CVSensRhs1Fn fS, void *fS_data); 00853 SUNDIALS_EXPORT int CVodeSetSensDQMethod(void *cvode_mem, int DQtype, realtype DQrhomax); 00854 SUNDIALS_EXPORT int CVodeSetSensErrCon(void *cvode_mem, booleantype errconS); 00855 SUNDIALS_EXPORT int CVodeSetSensMaxNonlinIters(void *cvode_mem, int maxcorS); 00856 SUNDIALS_EXPORT int CVodeSetSensParams(void *cvode_mem, realtype *p, realtype *pbar, int *plist); 00857 SUNDIALS_EXPORT int CVodeSetSensTolerances(void *cvode_mem, int itolS, 00858 realtype reltolS, void *abstolS); 00859 00860 /* 00861 * ----------------------------------------------------------------- 00862 * Function : CVodeSensMalloc 00863 * ----------------------------------------------------------------- 00864 * CVodeSensMalloc allocates and initializes memory related to 00865 * sensitivity computations. 00866 * 00867 * cvode_mem is pointer to CVODES memory returned by CVodeCreate 00868 * 00869 * Ns is the number of sensitivities to be computed. 00870 * 00871 * ism is the type of corrector used in sensitivity 00872 * analysis. The legal values are: CV_SIMULTANEOUS, 00873 * CV_STAGGERED, and CV_STAGGERED1 (see previous description) 00874 * 00875 * yS0 is the array of initial condition vectors for 00876 * sensitivity variables. 00877 * 00878 * Return values: 00879 * CV_SUCCESS 00880 * CV_MEM_NULL 00881 * CV_ILL_INPUT 00882 * CV_MEM_FAIL 00883 * ----------------------------------------------------------------- 00884 */ 00885 00886 SUNDIALS_EXPORT int CVodeSensMalloc(void *cvode_mem, int Ns, int ism, N_Vector *yS0); 00887 00888 /* 00889 * ----------------------------------------------------------------- 00890 * Function : CVodeSensReInit 00891 * ----------------------------------------------------------------- 00892 * CVodeSensReInit re-initializes CVODES's sensitivity related 00893 * memory for a problem, assuming it has already been allocated 00894 * in prior calls to CVodeMalloc and CvodeSensMalloc. 00895 * 00896 * All problem specification inputs are checked for errors. 00897 * The number of sensitivities Ns is assumed to be unchanged 00898 * since the previous call to CVodeSensMalloc. 00899 * If any error occurs during initialization, it is reported to 00900 * the file whose file pointer is errfp. 00901 * 00902 * CVodeSensReInit potentially does some minimal memory allocation 00903 * (for the sensitivity absolute tolerance and for arrays of 00904 * counters used by the CV_STAGGERED1 method). 00905 * 00906 * The return value is equal to CV_SUCCESS = 0 if there were no 00907 * errors; otherwise it is a negative int equal to: 00908 * CV_MEM_NULL indicating cvode_mem was NULL, or 00909 * CV_NO_SENS indicating there was not a prior call to 00910 * CVodeSensMalloc. 00911 * CV_ILL_INPUT indicating an input argument was illegal 00912 * (including an attempt to increase maxord). 00913 * CV_MEM_FAIL indicating a memory request failed. 00914 * In case of an error return, an error message is also printed. 00915 * ----------------------------------------------------------------- 00916 */ 00917 00918 SUNDIALS_EXPORT int CVodeSensReInit(void *cvode_mem, int ism, N_Vector *yS0); 00919 00920 /* 00921 * ----------------------------------------------------------------- 00922 * Function : CVodeSensToggleOff 00923 * ----------------------------------------------------------------- 00924 * CVodeSensToggleOff deactivates sensitivity calculations. 00925 * It does NOT deallocate sensitivity-related memory so that 00926 * sensitivity computations can be later toggled ON (through 00927 * CVodeSensReInit). 00928 * 00929 * The return value is equal to CV_SUCCESS = 0 if there were no 00930 * errors or CV_MEM_NULL if cvode_mem was NULL 00931 * ----------------------------------------------------------------- 00932 */ 00933 00934 SUNDIALS_EXPORT int CVodeSensToggleOff(void *cvode_mem); 00935 00936 /* 00937 * ----------------------------------------------------------------- 00938 * Function : CVode 00939 * ----------------------------------------------------------------- 00940 * CVode integrates the ODE over an interval in t. 00941 * If itask is CV_NORMAL, then the solver integrates from its 00942 * current internal t value to a point at or beyond tout, then 00943 * interpolates to t = tout and returns y(tout) in the user- 00944 * allocated vector yout. If itask is CV_ONE_STEP, then the solver 00945 * takes one internal time step and returns in yout the value of 00946 * y at the new internal time. In this case, tout is used only 00947 * during the first call to CVode to determine the direction of 00948 * integration and the rough scale of the problem. If itask is 00949 * CV_NORMAL_TSTOP or CV_ONE_STEP_TSTOP, then CVode returns the 00950 * solution at tstop if that comes sooner than tout or the end of 00951 * the next internal step, respectively. In any case, 00952 * the time reached by the solver is placed in (*tret). The 00953 * user is responsible for allocating the memory for this value. 00954 * 00955 * cvode_mem is the pointer to CVODES memory returned by 00956 * CVodeCreate. 00957 * 00958 * tout is the next time at which a computed solution is desired. 00959 * 00960 * yout is the computed solution vector. In CV_NORMAL mode with no 00961 * errors and no roots found, yout=y(tout). 00962 * 00963 * tret is a pointer to a real location. CVode sets (*tret) to 00964 * the time reached by the solver and returns yout=y(*tret). 00965 * 00966 * itask is CV_NORMAL, CV_ONE_STEP, CV_NORMAL_TSTOP, or CV_ONE_STEP_TSTOP. 00967 * These four modes are described above. 00968 * 00969 * Here is a brief description of each return value: 00970 * 00971 * CV_SUCCESS: CVode succeeded and no roots were found. 00972 * 00973 * CV_ROOT_RETURN: CVode succeeded, and found one or more roots. 00974 * If nrtfn > 1, call CVodeGetRootInfo to see 00975 * which g_i were found to have a root at (*tret). 00976 * 00977 * CV_TSTOP_RETURN: CVode succeded and returned at tstop. 00978 * 00979 * CV_MEM_NULL: The cvode_mem argument was NULL. 00980 * 00981 * CV_NO_MALLOC: cvode_mem was not allocated. 00982 * 00983 * CV_ILL_INPUT: One of the inputs to CVode is illegal. This 00984 * includes the situation when a component of the 00985 * error weight vectors becomes < 0 during 00986 * internal time-stepping. The ILL_INPUT flag 00987 * will also be returned if the linear solver 00988 * routine CV--- (called by the user after 00989 * calling CVodeCreate) failed to set one of the 00990 * linear solver-related fields in cvode_mem or 00991 * if the linear solver's init routine failed. In 00992 * any case, the user should see the printed 00993 * error message for more details. 00994 * 00995 * CV_TOO_MUCH_WORK: The solver took mxstep internal steps but 00996 * could not reach tout. The default value for 00997 * mxstep is MXSTEP_DEFAULT = 500. 00998 * 00999 * CV_TOO_MUCH_ACC: The solver could not satisfy the accuracy 01000 * demanded by the user for some internal step. 01001 * 01002 * CV_ERR_FAILURE: Error test failures occurred too many times 01003 * (= MXNEF = 7) during one internal time step or 01004 * occurred with |h| = hmin. 01005 * 01006 * CV_CONV_FAILURE: Convergence test failures occurred too many 01007 * times (= MXNCF = 10) during one internal time 01008 * step or occurred with |h| = hmin. 01009 * 01010 * CV_LINIT_FAIL: The linear solver's initialization function 01011 * failed. 01012 * 01013 * CV_LSETUP_FAIL: The linear solver's setup routine failed in an 01014 * unrecoverable manner. 01015 * 01016 * CV_LSOLVE_FAIL: The linear solver's solve routine failed in an 01017 * unrecoverable manner. 01018 * ----------------------------------------------------------------- 01019 */ 01020 01021 SUNDIALS_EXPORT int CVode(void *cvode_mem, realtype tout, N_Vector yout, 01022 realtype *tret, int itask); 01023 01024 /* 01025 * ----------------------------------------------------------------- 01026 * Function : CVodeGetDky 01027 * ----------------------------------------------------------------- 01028 * CVodeGetDky computes the kth derivative of the y function at 01029 * time t, where tn-hu <= t <= tn, tn denotes the current 01030 * internal time reached, and hu is the last internal step size 01031 * successfully used by the solver. The user may request 01032 * k=0, 1, ..., qu, where qu is the current order. The 01033 * derivative vector is returned in dky. This vector must be 01034 * allocated by the caller. It is only legal to call this 01035 * function after a successful return from CVode. 01036 * 01037 * cvode_mem is the pointer to CVODES memory returned by 01038 * CVodeCreate. 01039 * 01040 * t is the time at which the kth derivative of y is evaluated. 01041 * The legal range for t is [tn-hu,tn] as described above. 01042 * 01043 * k is the order of the derivative of y to be computed. The 01044 * legal range for k is [0,qu] as described above. 01045 * 01046 * dky is the output derivative vector [(D_k)y](t). 01047 * 01048 * The return values for CVodeGetDky are defined below. 01049 * Here is a brief description of each return value: 01050 * 01051 * CV_SUCCESS: CVodeGetDky succeeded. 01052 * 01053 * CV_BAD_K : k is not in the range 0, 1, ..., qu. 01054 * 01055 * CV_BAD_T : t is not in the interval [tn-hu,tn]. 01056 * 01057 * CV_BAD_DKY : The dky argument was NULL. 01058 * 01059 * CV_MEM_NULL : The cvode_mem argument was NULL. 01060 * ----------------------------------------------------------------- 01061 */ 01062 01063 SUNDIALS_EXPORT int CVodeGetDky(void *cvode_mem, realtype t, int k, N_Vector dky); 01064 01065 /* 01066 * ----------------------------------------------------------------- 01067 * Integrator optional output extraction functions 01068 * ----------------------------------------------------------------- 01069 * The following functions can be called to get optional outputs 01070 * and statistics related to the main integrator. 01071 * ----------------------------------------------------------------- 01072 * CVodeGetWorkSpace returns the CVODES real and integer workspaces 01073 * CVodeGetNumSteps returns the cumulative number of internal 01074 * steps taken by the solver 01075 * CVodeGetNumRhsEvals returns the number of calls to the user's 01076 * f function 01077 * CVodeGetNumLinSolvSetups returns the number of calls made to 01078 * the linear solver's setup routine 01079 * CVodeGetNumErrTestFails returns the number of local error test 01080 * failures that have occured 01081 * CVodeGetLastOrder returns the order used during the last 01082 * internal step 01083 * CVodeGetCurrentOrder returns the order to be used on the next 01084 * internal step 01085 * CVodeGetNumStabLimOrderReds returns the number of order 01086 * reductions due to stability limit detection 01087 * CVodeGetActualInitStep returns the actual initial step size 01088 * used by CVODES 01089 * CVodeGetLastStep returns the step size for the last internal 01090 * step 01091 * CVodeGetCurrentStep returns the step size to be attempted on 01092 * the next internal step 01093 * CVodeGetCurrentTime returns the current internal time reached 01094 * by the solver 01095 * CVodeGetTolScaleFactor returns a suggested factor by which the 01096 * user's tolerances should be scaled when too 01097 * much accuracy has been requested for some 01098 * internal step 01099 * CVodeGetErrWeights returns the current error weight vector. 01100 * The user must allocate space for eweight. 01101 * CVodeGetEstLocalErrors returns the vector of estimated local 01102 * errors. The user must allocate space for ele. 01103 * CVodeGetNumGEvals returns the number of calls to the user's 01104 * g function (for rootfinding) 01105 * CVodeGetRootInfo returns the indices for which g_i was found to 01106 * have a root. The user must allocate space for 01107 * rootsfound. For i = 0 ... nrtfn-1, 01108 * rootsfound[i] = 1 if g_i has a root, and = 0 if not. 01109 * 01110 * CVodeGet* return values: 01111 * CV_SUCCESS if succesful 01112 * CV_MEM_NULL if the cvode memory was NULL 01113 * CV_NO_SLDET if stability limit was not turned on 01114 * ----------------------------------------------------------------- 01115 */ 01116 01117 SUNDIALS_EXPORT int CVodeGetWorkSpace(void *cvode_mem, long int *lenrw, long int *leniw); 01118 SUNDIALS_EXPORT int CVodeGetNumSteps(void *cvode_mem, long int *nsteps); 01119 SUNDIALS_EXPORT int CVodeGetNumRhsEvals(void *cvode_mem, long int *nfevals); 01120 SUNDIALS_EXPORT int CVodeGetNumLinSolvSetups(void *cvode_mem, long int *nlinsetups); 01121 SUNDIALS_EXPORT int CVodeGetNumErrTestFails(void *cvode_mem, long int *netfails); 01122 SUNDIALS_EXPORT int CVodeGetLastOrder(void *cvode_mem, int *qlast); 01123 SUNDIALS_EXPORT int CVodeGetCurrentOrder(void *cvode_mem, int *qcur); 01124 SUNDIALS_EXPORT int CVodeGetNumStabLimOrderReds(void *cvode_mem, long int *nslred); 01125 SUNDIALS_EXPORT int CVodeGetActualInitStep(void *cvode_mem, realtype *hinused); 01126 SUNDIALS_EXPORT int CVodeGetLastStep(void *cvode_mem, realtype *hlast); 01127 SUNDIALS_EXPORT int CVodeGetCurrentStep(void *cvode_mem, realtype *hcur); 01128 SUNDIALS_EXPORT int CVodeGetCurrentTime(void *cvode_mem, realtype *tcur); 01129 SUNDIALS_EXPORT int CVodeGetTolScaleFactor(void *cvode_mem, realtype *tolsfac); 01130 SUNDIALS_EXPORT int CVodeGetErrWeights(void *cvode_mem, N_Vector eweight); 01131 SUNDIALS_EXPORT int CVodeGetEstLocalErrors(void *cvode_mem, N_Vector ele); 01132 SUNDIALS_EXPORT int CVodeGetNumGEvals(void *cvode_mem, long int *ngevals); 01133 SUNDIALS_EXPORT int CVodeGetRootInfo(void *cvode_mem, int *rootsfound); 01134 01135 /* 01136 * ----------------------------------------------------------------- 01137 * As a convenience, the following functions provides the 01138 * optional outputs in one group. 01139 * ----------------------------------------------------------------- 01140 */ 01141 01142 SUNDIALS_EXPORT int CVodeGetIntegratorStats(void *cvode_mem, long int *nsteps, 01143 long int *nfevals, long int *nlinsetups, 01144 long int *netfails, int *qlast, 01145 int *qcur, realtype *hinused, realtype *hlast, 01146 realtype *hcur, realtype *tcur); 01147 01148 /* 01149 * ----------------------------------------------------------------- 01150 * Nonlinear solver optional output extraction functions 01151 * ----------------------------------------------------------------- 01152 * The following functions can be called to get optional outputs 01153 * and statistics related to the nonlinear solver. 01154 * ----------------------------------------------------------------- 01155 * CVodeGetNumNonlinSolvIters returns the number of nonlinear 01156 * solver iterations performed. 01157 * CVodeGetNumNonlinSolvConvFails returns the number of nonlinear 01158 * convergence failures. 01159 * ----------------------------------------------------------------- 01160 */ 01161 01162 SUNDIALS_EXPORT int CVodeGetNumNonlinSolvIters(void *cvode_mem, long int *nniters); 01163 SUNDIALS_EXPORT int CVodeGetNumNonlinSolvConvFails(void *cvode_mem, long int *nncfails); 01164 01165 /* 01166 * ----------------------------------------------------------------- 01167 * As a convenience, the following function provides the 01168 * nonlinear solver optional outputs in a group. 01169 * ----------------------------------------------------------------- 01170 */ 01171 01172 SUNDIALS_EXPORT int CVodeGetNonlinSolvStats(void *cvode_mem, long int *nniters, 01173 long int *nncfails); 01174 01175 01176 /* 01177 * ----------------------------------------------------------------- 01178 * The following function returns the name of the constant 01179 * associated with a CVODES return flag 01180 * ----------------------------------------------------------------- 01181 */ 01182 01183 SUNDIALS_EXPORT char *CVodeGetReturnFlagName(int flag); 01184 01185 /* 01186 * ----------------------------------------------------------------- 01187 * Quadrature integration solution extraction routines 01188 * ----------------------------------------------------------------- 01189 * The following functions can be called to obtain the quadrature 01190 * variables after a successful integration step. 01191 * If quadratures were not computed, they return CV_NO_QUAD. 01192 * ----------------------------------------------------------------- 01193 */ 01194 01195 SUNDIALS_EXPORT int CVodeGetQuad(void *cvode_mem, realtype t, N_Vector yQout); 01196 SUNDIALS_EXPORT int CVodeGetQuadDky(void *cvode_mem, realtype t, int k, N_Vector dky); 01197 01198 /* 01199 * ----------------------------------------------------------------- 01200 * Quadrature integration optional output extraction routines 01201 * ----------------------------------------------------------------- 01202 * The following functions can be called to get optional outputs 01203 * and statistics related to the integration of quadratures. 01204 * ----------------------------------------------------------------- 01205 * CVodeGetQuadNumRhsEvals returns the number of calls to the 01206 * user function fQ defining the right hand 01207 * side of the quadrature variables. 01208 * CVodeGetQuadNumErrTestFails returns the number of local error 01209 * test failures for quadrature variables. 01210 * CVodeGetQuadErrWeights returns the vector of error weights for 01211 * the quadrature variables. The user must 01212 * allocate space for ewtQ. 01213 * ----------------------------------------------------------------- 01214 */ 01215 01216 SUNDIALS_EXPORT int CVodeGetQuadNumRhsEvals(void *cvode_mem, long int *nfQevals); 01217 SUNDIALS_EXPORT int CVodeGetQuadNumErrTestFails(void *cvode_mem, long int *nQetfails); 01218 SUNDIALS_EXPORT int CVodeGetQuadErrWeights(void *cvode_mem, N_Vector eQweight); 01219 01220 /* 01221 * ----------------------------------------------------------------- 01222 * As a convenience, the following function provides the 01223 * optional outputs in a group. 01224 * ----------------------------------------------------------------- 01225 */ 01226 01227 SUNDIALS_EXPORT int CVodeGetQuadStats(void *cvode_mem, long int *nfQevals, 01228 long int *nQetfails); 01229 01230 /* 01231 * ----------------------------------------------------------------- 01232 * Forward sensitivity solution extraction routines 01233 * ----------------------------------------------------------------- 01234 * CVodeGetSensDky1 computes the kth derivative of the is-th 01235 * sensitivity (is=1, 2, ..., Ns) of the y function at time t, 01236 * where tn-hu <= t <= tn, tn denotes the current internal time 01237 * reached, and hu is the last internal step size successfully 01238 * used by the solver. The user may request k=0, 1, ..., qu, 01239 * where qu is the current order. 01240 * The is-th sensitivity derivative vector is returned in dky. 01241 * This vector must be allocated by the caller. It is only legal 01242 * to call this function after a successful return from CVode 01243 * with sensitivty computations enabled. 01244 * Arguments have the same meaning as in CVodeDky. 01245 * 01246 * CVodeGetSensDky computes the k-th derivative of all 01247 * sensitivities of the y function at time t. It repeatedly calls 01248 * CVodeGetSensDky. The argument dkyA must be a pointer to 01249 * N_Vector and must be allocated by the user to hold at least Ns 01250 * vectors. 01251 * 01252 * CVodeGetSens1 returns the is-th sensitivity of the y function 01253 * at the time t. The argument ySout must be an N_Vector and must 01254 * be allocated by the user. 01255 * 01256 * CVodeGetSens returns sensitivities of the y function at 01257 * the time t. The argument ySout must be a pointer to N_Vector 01258 * and must be allocated by the user to hold at least Ns vectors. 01259 * 01260 * Return values are similar to those of CVodeDky. Additionally, 01261 * CVodeSensDky can return CV_NO_SENS if sensitivities were 01262 * not computed and CV_BAD_IS if is < 0 or is >= Ns. 01263 * ----------------------------------------------------------------- 01264 */ 01265 01266 SUNDIALS_EXPORT int CVodeGetSens(void *cvode_mem, realtype t, N_Vector *ySout); 01267 SUNDIALS_EXPORT int CVodeGetSens1(void *cvode_mem, realtype t, int is, N_Vector ySout); 01268 SUNDIALS_EXPORT int CVodeGetSensDky(void *cvode_mem, realtype t, int k, 01269 N_Vector *dkyA); 01270 SUNDIALS_EXPORT int CVodeGetSensDky1(void *cvode_mem, realtype t, int k, 01271 int is, N_Vector dky); 01272 01273 /* 01274 * ----------------------------------------------------------------- 01275 * Forward sensitivity optional output extraction routines 01276 * ----------------------------------------------------------------- 01277 * The following functions can be called to get optional outputs 01278 * and statistics related to the integration of sensitivities. 01279 * ----------------------------------------------------------------- 01280 * CVodeGetNumSensRhsEvals returns the number of calls to the 01281 * sensitivity right hand side routine. 01282 * CVodeGetNumRhsEvalsSens returns the number of calls to the 01283 * user f routine due to finite difference 01284 * evaluations of the sensitivity equations. 01285 * CVodeGetNumSensErrTestFails returns the number of local error 01286 * test failures for sensitivity variables. 01287 * CVodeGetNumSensLinSolvSetups returns the number of calls made 01288 * to the linear solver's setup routine 01289 * due to sensitivity computations. 01290 * CVodeGetSensErrWeights returns the sensitivity error weight 01291 * vectors. The user need not allocate space 01292 * for ewtS. 01293 * ----------------------------------------------------------------- 01294 */ 01295 01296 SUNDIALS_EXPORT int CVodeGetNumSensRhsEvals(void *cvode_mem, long int *nfSevals); 01297 SUNDIALS_EXPORT int CVodeGetNumRhsEvalsSens(void *cvode_mem, long int *nfevalsS); 01298 SUNDIALS_EXPORT int CVodeGetNumSensErrTestFails(void *cvode_mem, long int *nSetfails); 01299 SUNDIALS_EXPORT int CVodeGetNumSensLinSolvSetups(void *cvode_mem, long int *nlinsetupsS); 01300 SUNDIALS_EXPORT int CVodeGetSensErrWeights(void *cvode_mem, N_Vector_S eSweight); 01301 01302 /* 01303 * ----------------------------------------------------------------- 01304 * As a convenience, the following function provides the 01305 * optional outputs in a group. 01306 * ----------------------------------------------------------------- 01307 */ 01308 01309 SUNDIALS_EXPORT int CVodeGetSensStats(void *cvode_mem, long int *nfSevals, long int *nfevalsS, 01310 long int *nSetfails, long int *nlinsetupsS); 01311 01312 /* 01313 * ----------------------------------------------------------------- 01314 * Sensitivity nonlinear solver optional output extraction 01315 * ----------------------------------------------------------------- 01316 * The following functions can be called to get optional outputs 01317 * and statistics related to the sensitivity nonlinear solver. 01318 * ----------------------------------------------------------------- 01319 * CVodeGetNumSensNonlinSolvIters returns the total number of 01320 * nonlinear iterations for sensitivity 01321 * variables. 01322 * CVodeGetNumSensNonlinSolvConvFails returns the total number of 01323 * nonlinear convergence failures 01324 * for sensitivity variables 01325 * CVodeGetNumStgrSensNonlinSolvIters returns a vector of Ns 01326 * nonlinear iteration counters 01327 * for sensitivity variables 01328 * in the CV_STAGGERED1 method. 01329 * CVodeGetNumStgrSensNonlinSolvConvFails returns a vector of Ns 01330 * nonlinear solver convergence 01331 * failure counters for 01332 * sensitivity variables in 01333 * the CV_STAGGERED1 method. 01334 * ----------------------------------------------------------------- 01335 */ 01336 01337 SUNDIALS_EXPORT int CVodeGetNumSensNonlinSolvIters(void *cvode_mem, long int *nSniters); 01338 SUNDIALS_EXPORT int CVodeGetNumSensNonlinSolvConvFails(void *cvode_mem, long int *nSncfails); 01339 SUNDIALS_EXPORT int CVodeGetNumStgrSensNonlinSolvIters(void *cvode_mem, long int *nSTGR1niters); 01340 SUNDIALS_EXPORT int CVodeGetNumStgrSensNonlinSolvConvFails(void *cvode_mem, 01341 long int *nSTGR1ncfails); 01342 01343 /* 01344 * ----------------------------------------------------------------- 01345 * As a convenience, the following function provides the 01346 * optional outputs in groups. 01347 * ----------------------------------------------------------------- 01348 */ 01349 01350 SUNDIALS_EXPORT int CVodeGetSensNonlinSolvStats(void *cvode_mem, long int *nSniters, 01351 long int *nSncfails); 01352 01353 /* 01354 * ----------------------------------------------------------------- 01355 * Function : CVodeFree 01356 * ----------------------------------------------------------------- 01357 * CVodeFree frees the problem memory cvode_mem allocated by 01358 * CVodeMalloc. Its only argument is the pointer cvode_mem 01359 * returned by CVodeCreate. 01360 * ----------------------------------------------------------------- 01361 */ 01362 01363 SUNDIALS_EXPORT void CVodeFree(void **cvode_mem); 01364 01365 /* 01366 * ----------------------------------------------------------------- 01367 * Function : CVodeQuadFree 01368 * ----------------------------------------------------------------- 01369 * CVodeQuadFree frees the problem memory in cvode_mem allocated 01370 * for quadrature integration. Its only argument is the pointer 01371 * cvode_mem returned by CVodeCreate. 01372 * ----------------------------------------------------------------- 01373 */ 01374 01375 SUNDIALS_EXPORT void CVodeQuadFree(void *cvode_mem); 01376 01377 /* 01378 * ----------------------------------------------------------------- 01379 * Function : CVodeSensFree 01380 * ----------------------------------------------------------------- 01381 * CVodeSensFree frees the problem memory in cvode_mem allocated 01382 * for sensitivity analysis. Its only argument is the pointer 01383 * cvode_mem returned by CVodeCreate. 01384 * ----------------------------------------------------------------- 01385 */ 01386 01387 SUNDIALS_EXPORT void CVodeSensFree(void *cvode_mem); 01388 01389 /* 01390 * ----------------------------------------------------------------- 01391 * CVadjMalloc 01392 * ----------------------------------------------------------------- 01393 * CVadjMalloc specifies some parameters for the adjoint problem and 01394 * allocates space for the global CVODEA memory structure. 01395 * ----------------------------------------------------------------- 01396 */ 01397 01398 SUNDIALS_EXPORT void *CVadjMalloc(void *cvode_mem, long int steps, int interp); 01399 01400 /* 01401 * ----------------------------------------------------------------- 01402 * CVadjSetInterpType 01403 * ----------------------------------------------------------------- 01404 * Changes the interpolation type. 01405 * Must be called only after CVadjMalloc 01406 * ----------------------------------------------------------------- 01407 */ 01408 01409 SUNDIALS_EXPORT int CVadjSetInterpType(void *cvadj_mem, int interp); 01410 01411 /* 01412 * ----------------------------------------------------------------- 01413 * CVodeF 01414 * ----------------------------------------------------------------- 01415 * CVodeF integrates towards tout and returns solution into yout. 01416 * In the same time, it stores check point data every 'steps'. 01417 * 01418 * CVodeF can be called repeatedly by the user. 01419 * 01420 * ncheckPtr points to the number of check points stored so far. 01421 * 01422 * Return values: 01423 * CV_SUCCESS 01424 * CVADJ_MEM_FAIL 01425 * any CVode return value 01426 * ----------------------------------------------------------------- 01427 */ 01428 01429 SUNDIALS_EXPORT int CVodeF(void *cvadj_mem, realtype tout, N_Vector yout, 01430 realtype *tret, int itask, int *ncheckPtr); 01431 01432 /* 01433 * ----------------------------------------------------------------- 01434 * Interfaces to CVODES functions for setting-up the 01435 * backward integration 01436 * ----------------------------------------------------------------- 01437 * CVodeCreateB, CVodeMallocB, CVodeSet*B 01438 * These functions are just wrappers around the corresponding 01439 * functions in cvodes.h, with some particularizations for the 01440 * backward integration. 01441 * ----------------------------------------------------------------- 01442 * CVodeSetQuad*B, CVodeQuadMallocB, CVodeQuadReInitB 01443 * ----------------------------------------------------------------- 01444 */ 01445 01446 SUNDIALS_EXPORT int CVodeCreateB(void *cvadj_mem, int lmmB, int iterB); 01447 01448 SUNDIALS_EXPORT int CVodeMallocB(void *cvadj_mem, CVRhsFnB fB, 01449 realtype tB0, N_Vector yB0, 01450 int itolB, realtype reltolB, void *abstolB); 01451 01452 SUNDIALS_EXPORT int CVodeSetErrHandlerFnB(void *cvadj_mem, CVErrHandlerFn ehfunB, void *eh_dataB); 01453 SUNDIALS_EXPORT int CVodeSetErrFileB(void *cvadj_mem, FILE *errfpB); 01454 SUNDIALS_EXPORT int CVodeSetIterTypeB(void *cvadj_mem, int iterB); 01455 SUNDIALS_EXPORT int CVodeSetFdataB(void *cvadj_mem, void *f_dataB); 01456 SUNDIALS_EXPORT int CVodeSetMaxOrdB(void *cvadj_mem, int maxordB); 01457 SUNDIALS_EXPORT int CVodeSetMaxNumStepsB(void *cvadj_mem, long int mxstepsB); 01458 SUNDIALS_EXPORT int CVodeSetStabLimDetB(void *cvadj_mem, booleantype stldetB); 01459 SUNDIALS_EXPORT int CVodeSetInitStepB(void *cvadj_mem, realtype hinB); 01460 SUNDIALS_EXPORT int CVodeSetMinStepB(void *cvadj_mem, realtype hminB); 01461 SUNDIALS_EXPORT int CVodeSetMaxStepB(void *cvadj_mem, realtype hmaxB); 01462 01463 SUNDIALS_EXPORT int CVodeReInitB(void *cvadj_mem, CVRhsFnB fB, 01464 realtype tB0, N_Vector yB0, 01465 int itolB, realtype reltolB, void *abstolB); 01466 01467 SUNDIALS_EXPORT int CVodeSetQuadFdataB(void *cvadj_mem, void *fQ_dataB); 01468 SUNDIALS_EXPORT int CVodeSetQuadErrConB(void *cvadj_mem, booleantype errconQB, 01469 int itolQB, realtype reltolQB, void *abstolQB); 01470 SUNDIALS_EXPORT int CVodeQuadMallocB(void *cvadj_mem, CVQuadRhsFnB fQB, N_Vector yQB0); 01471 SUNDIALS_EXPORT int CVodeQuadReInitB(void *cvadj_mem, CVQuadRhsFnB fQB, N_Vector yQB0); 01472 01473 /* 01474 * ----------------------------------------------------------------- 01475 * CVodeB 01476 * ----------------------------------------------------------------- 01477 * CVodeB performs the backward integration from tfinal to 01478 * tinitial through a sequence of forward-backward runs in 01479 * between consecutive check points. It returns the values of 01480 * the adjoint variables and any existing quadrature variables 01481 * at tinitial. 01482 * ----------------------------------------------------------------- 01483 */ 01484 01485 SUNDIALS_EXPORT int CVodeB(void *cvadj_mem, realtype tBout, N_Vector yBout, 01486 realtype *tBret, int itaskB); 01487 01488 /* 01489 * ----------------------------------------------------------------- 01490 * CVodeGetQuadB 01491 * ----------------------------------------------------------------- 01492 * CVodeGetQuadB extracts values for quadrature variables in 01493 * the N_Vector qB. 01494 * ----------------------------------------------------------------- 01495 */ 01496 01497 SUNDIALS_EXPORT int CVodeGetQuadB(void *cvadj_mem, N_Vector qB); 01498 01499 /* 01500 * ----------------------------------------------------------------- 01501 * CVadjFree 01502 * ----------------------------------------------------------------- 01503 * CVadjFree frees the memory allocated by CVadjMalloc. 01504 * ----------------------------------------------------------------- 01505 */ 01506 01507 SUNDIALS_EXPORT void CVadjFree(void **cvadj_mem); 01508 01509 /* 01510 * ----------------------------------------------------------------- 01511 * CVadjGetCVodeBmem 01512 * ----------------------------------------------------------------- 01513 * CVadjGetCVodeBmem returns a (void *) pointer to the CVODES 01514 * memory allocated for the backward problem. This pointer can 01515 * then be used to call any of the CVodeGet* CVODES routines to 01516 * extract optional output for the backward integration phase. 01517 * ----------------------------------------------------------------- 01518 */ 01519 01520 SUNDIALS_EXPORT void *CVadjGetCVodeBmem(void *cvadj_mem); 01521 01522 /* 01523 * ----------------------------------------------------------------- 01524 * The following function returns the name of the constant 01525 * associated with a CVODEA-specific return flag 01526 * ----------------------------------------------------------------- 01527 */ 01528 01529 SUNDIALS_EXPORT char *CVadjGetReturnFlagName(int flag); 01530 01531 01532 /* 01533 * ----------------------------------------------------------------- 01534 * CVadjGetY 01535 * Returns the interpolated forward solution at time t. This 01536 * function is a wrapper around the interpType-dependent internal 01537 * function. 01538 * The calling function must allocate space for y. 01539 * ----------------------------------------------------------------- 01540 */ 01541 01542 SUNDIALS_EXPORT int CVadjGetY(void *cvadj_mem, realtype t, N_Vector y); 01543 01544 /* 01545 * ----------------------------------------------------------------- 01546 * CVadjGetCheckPointsInfo 01547 * Loads an array of nckpnts structures of type CVadjCheckPointRec. 01548 * The user must allocate space for ckpnt (ncheck+1). 01549 * ----------------------------------------------------------------- 01550 */ 01551 01552 typedef struct { 01553 void *my_addr; 01554 void *next_addr; 01555 realtype t0; 01556 realtype t1; 01557 long int nstep; 01558 int order; 01559 realtype step; 01560 } CVadjCheckPointRec; 01561 01562 SUNDIALS_EXPORT int CVadjGetCheckPointsInfo(void *cvadj_mem, CVadjCheckPointRec *ckpnt); 01563 01564 /* 01565 * ----------------------------------------------------------------- 01566 * CVadjGetDataPointHermite 01567 * Returns the 2 vectors stored for cubic Hermite interpolation 01568 * at the data point 'which'. The user must allocate space for 01569 * y and yd. Returns CVADJ_MEM_NULL if cvadj_mem is NULL. 01570 * Returns CV_ILL_INPUT if interpType != CV_HERMITE. 01571 * CVadjGetDataPointPolynomial 01572 * Returns the vector stored for polynomial interpolation 01573 * at the data point 'which'. The user must allocate space for 01574 * y. Returns CVADJ_MEM_NULL if cvadj_mem is NULL. 01575 * Returns CV_ILL_INPUT if interpType != CV_POLYNOMIAL. 01576 * ----------------------------------------------------------------- 01577 */ 01578 01579 SUNDIALS_EXPORT int CVadjGetDataPointHermite(void *cvadj_mem, long int which, 01580 realtype *t, N_Vector y, N_Vector yd); 01581 01582 SUNDIALS_EXPORT int CVadjGetDataPointPolynomial(void *cvadj_mem, long int which, 01583 realtype *t, int *order, N_Vector y); 01584 01585 /* 01586 * =============================================================== 01587 * DEVELOPMENT USER-CALLABLE FUNCTIONS 01588 * =============================================================== 01589 */ 01590 01591 /* 01592 * ----------------------------------------------------------------- 01593 * CVadjGetCurrentCheckPoint 01594 * Returns the address of the 'active' check point. 01595 * ----------------------------------------------------------------- 01596 */ 01597 01598 SUNDIALS_EXPORT int CVadjGetCurrentCheckPoint(void *cvadj_mem, void **addr); 01599 01600 #ifdef __cplusplus 01601 } 01602 #endif 01603 01604 #endif