| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139 |
- /*
- * -----------------------------------------------------------------
- * $Revision: 4210 $
- * $Date: 2014-08-27 15:40:02 -0700 (Wed, 27 Aug 2014) $
- * -----------------------------------------------------------------
- * Programmer(s): Alan C. Hindmarsh and Radu Serban @ LLNL
- * -----------------------------------------------------------------
- * LLNS Copyright Start
- * Copyright (c) 2014, Lawrence Livermore National Security
- * This work was performed under the auspices of the U.S. Department
- * of Energy by Lawrence Livermore National Laboratory in part under
- * Contract W-7405-Eng-48 and in part under Contract DE-AC52-07NA27344.
- * Produced at the Lawrence Livermore National Laboratory.
- * All rights reserved.
- * For details, see the LICENSE file.
- * LLNS Copyright End
- * -----------------------------------------------------------------
- * This is the implementation file for the optional input and output
- * functions for the CVODE solver.
- * -----------------------------------------------------------------
- */
- #include <stdio.h>
- #include <stdlib.h>
- #include "cvode_impl.h"
- #include <sundials/sundials_types.h>
- #define ZERO RCONST(0.0)
- #define ONE RCONST(1.0)
- #define lrw (cv_mem->cv_lrw)
- #define liw (cv_mem->cv_liw)
- #define lrw1 (cv_mem->cv_lrw1)
- #define liw1 (cv_mem->cv_liw1)
- /*
- * =================================================================
- * CVODE optional input functions
- * =================================================================
- */
- /*
- * CVodeSetErrHandlerFn
- *
- * Specifies the error handler function
- */
- SUNDIALS_EXPORT int CVodeSetErrHandlerFn(void *cvode_mem, CVErrHandlerFn ehfun, void *eh_data)
- {
- CVodeMem cv_mem;
- if (cvode_mem==NULL) {
- cvProcessError(NULL, CV_MEM_NULL, "CVODE", "CVodeSetErrHandlerFn", MSGCV_NO_MEM);
- return(CV_MEM_NULL);
- }
- cv_mem = (CVodeMem) cvode_mem;
- cv_mem->cv_ehfun = ehfun;
- cv_mem->cv_eh_data = eh_data;
- return(CV_SUCCESS);
- }
- /*
- * CVodeSetErrFile
- *
- * Specifies the FILE pointer for output (NULL means no messages)
- */
- SUNDIALS_EXPORT int CVodeSetErrFile(void *cvode_mem, FILE *errfp)
- {
- CVodeMem cv_mem;
- if (cvode_mem==NULL) {
- cvProcessError(NULL, CV_MEM_NULL, "CVODE", "CVodeSetErrFile", MSGCV_NO_MEM);
- return(CV_MEM_NULL);
- }
- cv_mem = (CVodeMem) cvode_mem;
- cv_mem->cv_errfp = errfp;
- return(CV_SUCCESS);
- }
- /*
- * CVodeSetIterType
- *
- * Specifies the iteration type (CV_FUNCTIONAL or CV_NEWTON)
- */
- SUNDIALS_EXPORT int CVodeSetIterType(void *cvode_mem, int iter)
- {
- CVodeMem cv_mem;
- if (cvode_mem==NULL) {
- cvProcessError(NULL, CV_MEM_NULL, "CVODE", "CVodeSetIterType", MSGCV_NO_MEM);
- return(CV_MEM_NULL);
- }
- cv_mem = (CVodeMem) cvode_mem;
- if ((iter != CV_FUNCTIONAL) && (iter != CV_NEWTON)) {
- cvProcessError(cv_mem, CV_ILL_INPUT, "CVODE", "CVodeSetIterType", MSGCV_BAD_ITER);
- return (CV_ILL_INPUT);
- }
- cv_mem->cv_iter = iter;
- return(CV_SUCCESS);
- }
- /*
- * CVodeSetUserData
- *
- * Specifies the user data pointer for f
- */
- SUNDIALS_EXPORT int CVodeSetUserData(void *cvode_mem, void *user_data)
- {
- CVodeMem cv_mem;
- if (cvode_mem==NULL) {
- cvProcessError(NULL, CV_MEM_NULL, "CVODE", "CVodeSetUserData", MSGCV_NO_MEM);
- return(CV_MEM_NULL);
- }
- cv_mem = (CVodeMem) cvode_mem;
- cv_mem->cv_user_data = user_data;
- return(CV_SUCCESS);
- }
- /*
- * CVodeSetMaxOrd
- *
- * Specifies the maximum method order
- */
- SUNDIALS_EXPORT int CVodeSetMaxOrd(void *cvode_mem, int maxord)
- {
- CVodeMem cv_mem;
- int qmax_alloc;
- if (cvode_mem==NULL) {
- cvProcessError(NULL, CV_MEM_NULL, "CVODE", "CVodeSetMaxOrd", MSGCV_NO_MEM);
- return(CV_MEM_NULL);
- }
- cv_mem = (CVodeMem) cvode_mem;
- if (maxord <= 0) {
- cvProcessError(cv_mem, CV_ILL_INPUT, "CVODE", "CVodeSetMaxOrd", MSGCV_NEG_MAXORD);
- return(CV_ILL_INPUT);
- }
-
- /* Cannot increase maximum order beyond the value that
- was used when allocating memory */
- qmax_alloc = cv_mem->cv_qmax_alloc;
- if (maxord > qmax_alloc) {
- cvProcessError(cv_mem, CV_ILL_INPUT, "CVODE", "CVodeSetMaxOrd", MSGCV_BAD_MAXORD);
- return(CV_ILL_INPUT);
- }
- cv_mem->cv_qmax = maxord;
- return(CV_SUCCESS);
- }
- /*
- * CVodeSetMaxNumSteps
- *
- * Specifies the maximum number of integration steps
- */
- SUNDIALS_EXPORT int CVodeSetMaxNumSteps(void *cvode_mem, long int mxsteps)
- {
- CVodeMem cv_mem;
- if (cvode_mem==NULL) {
- cvProcessError(NULL, CV_MEM_NULL, "CVODE", "CVodeSetMaxNumSteps", MSGCV_NO_MEM);
- return(CV_MEM_NULL);
- }
- cv_mem = (CVodeMem) cvode_mem;
- /* Passing mxsteps=0 sets the default. Passing mxsteps<0 disables the test. */
- if (mxsteps == 0)
- cv_mem->cv_mxstep = MXSTEP_DEFAULT;
- else
- cv_mem->cv_mxstep = mxsteps;
- return(CV_SUCCESS);
- }
- /*
- * CVodeSetMaxHnilWarns
- *
- * Specifies the maximum number of warnings for small h
- */
- SUNDIALS_EXPORT int CVodeSetMaxHnilWarns(void *cvode_mem, int mxhnil)
- {
- CVodeMem cv_mem;
- if (cvode_mem==NULL) {
- cvProcessError(NULL, CV_MEM_NULL, "CVODE", "CVodeSetMaxHnilWarns", MSGCV_NO_MEM);
- return(CV_MEM_NULL);
- }
- cv_mem = (CVodeMem) cvode_mem;
- cv_mem->cv_mxhnil = mxhnil;
- return(CV_SUCCESS);
- }
- /*
- *CVodeSetStabLimDet
- *
- * Turns on/off the stability limit detection algorithm
- */
- SUNDIALS_EXPORT int CVodeSetStabLimDet(void *cvode_mem, booleantype sldet)
- {
- CVodeMem cv_mem;
- if (cvode_mem==NULL) {
- cvProcessError(NULL, CV_MEM_NULL, "CVODE", "CVodeSetStabLimDet", MSGCV_NO_MEM);
- return(CV_MEM_NULL);
- }
- cv_mem = (CVodeMem) cvode_mem;
- if( sldet && (cv_mem->cv_lmm != CV_BDF) ) {
- cvProcessError(cv_mem, CV_ILL_INPUT, "CVODE", "CVodeSetStabLimDet", MSGCV_SET_SLDET);
- return(CV_ILL_INPUT);
- }
- cv_mem->cv_sldeton = sldet;
- return(CV_SUCCESS);
- }
- /*
- * CVodeSetInitStep
- *
- * Specifies the initial step size
- */
- SUNDIALS_EXPORT int CVodeSetInitStep(void *cvode_mem, realtype hin)
- {
- CVodeMem cv_mem;
- if (cvode_mem==NULL) {
- cvProcessError(NULL, CV_MEM_NULL, "CVODE", "CVodeSetInitStep", MSGCV_NO_MEM);
- return(CV_MEM_NULL);
- }
- cv_mem = (CVodeMem) cvode_mem;
- cv_mem->cv_hin = hin;
- return(CV_SUCCESS);
- }
- /*
- * CVodeSetMinStep
- *
- * Specifies the minimum step size
- */
- SUNDIALS_EXPORT int CVodeSetMinStep(void *cvode_mem, realtype hmin)
- {
- CVodeMem cv_mem;
- if (cvode_mem==NULL) {
- cvProcessError(NULL, CV_MEM_NULL, "CVODE", "CVodeSetMinStep", MSGCV_NO_MEM);
- return(CV_MEM_NULL);
- }
- cv_mem = (CVodeMem) cvode_mem;
- if (hmin<0) {
- cvProcessError(cv_mem, CV_ILL_INPUT, "CVODE", "CVodeSetMinStep", MSGCV_NEG_HMIN);
- return(CV_ILL_INPUT);
- }
- /* Passing 0 sets hmin = zero */
- if (hmin == ZERO) {
- cv_mem->cv_hmin = HMIN_DEFAULT;
- return(CV_SUCCESS);
- }
- if (hmin * cv_mem->cv_hmax_inv > ONE) {
- cvProcessError(cv_mem, CV_ILL_INPUT, "CVODE", "CVodeSetMinStep", MSGCV_BAD_HMIN_HMAX);
- return(CV_ILL_INPUT);
- }
- cv_mem->cv_hmin = hmin;
- return(CV_SUCCESS);
- }
- /*
- * CVodeSetMaxStep
- *
- * Specifies the maximum step size
- */
- SUNDIALS_EXPORT int CVodeSetMaxStep(void *cvode_mem, realtype hmax)
- {
- realtype hmax_inv;
- CVodeMem cv_mem;
- if (cvode_mem==NULL) {
- cvProcessError(NULL, CV_MEM_NULL, "CVODE", "CVodeSetMaxStep", MSGCV_NO_MEM);
- return (CV_MEM_NULL);
- }
- cv_mem = (CVodeMem) cvode_mem;
- if (hmax < 0) {
- cvProcessError(cv_mem, CV_ILL_INPUT, "CVODE", "CVodeSetMaxStep", MSGCV_NEG_HMAX);
- return(CV_ILL_INPUT);
- }
- /* Passing 0 sets hmax = infinity */
- if (hmax == ZERO) {
- cv_mem->cv_hmax_inv = HMAX_INV_DEFAULT;
- return(CV_SUCCESS);
- }
- hmax_inv = ONE/hmax;
- if (hmax_inv * cv_mem->cv_hmin > ONE) {
- cvProcessError(cv_mem, CV_ILL_INPUT, "CVODE", "CVodeSetMaxStep", MSGCV_BAD_HMIN_HMAX);
- return(CV_ILL_INPUT);
- }
- cv_mem->cv_hmax_inv = hmax_inv;
- return(CV_SUCCESS);
- }
- /*
- * CVodeSetStopTime
- *
- * Specifies the time beyond which the integration is not to proceed.
- */
- SUNDIALS_EXPORT int CVodeSetStopTime(void *cvode_mem, realtype tstop)
- {
- CVodeMem cv_mem;
- if (cvode_mem==NULL) {
- cvProcessError(NULL, CV_MEM_NULL, "CVODE", "CVodeSetStopTime", MSGCV_NO_MEM);
- return (CV_MEM_NULL);
- }
- cv_mem = (CVodeMem) cvode_mem;
- /* If CVode was called at least once, test if tstop is legal
- * (i.e. if it was not already passed).
- * If CVodeSetStopTime is called before the first call to CVode,
- * tstop will be checked in CVode. */
- if (cv_mem->cv_nst > 0) {
- if ( (tstop - cv_mem->cv_tn) * cv_mem->cv_h < ZERO ) {
- cvProcessError(cv_mem, CV_ILL_INPUT, "CVODE", "CVodeSetStopTime", MSGCV_BAD_TSTOP, tstop, cv_mem->cv_tn);
- return(CV_ILL_INPUT);
- }
- }
- cv_mem->cv_tstop = tstop;
- cv_mem->cv_tstopset = TRUE;
- return(CV_SUCCESS);
- }
- /*
- * CVodeSetMaxErrTestFails
- *
- * Specifies the maximum number of error test failures during one
- * step try.
- */
- SUNDIALS_EXPORT int CVodeSetMaxErrTestFails(void *cvode_mem, int maxnef)
- {
- CVodeMem cv_mem;
- if (cvode_mem==NULL) {
- cvProcessError(NULL, CV_MEM_NULL, "CVODE", "CVodeSetMaxErrTestFails", MSGCV_NO_MEM);
- return (CV_MEM_NULL);
- }
- cv_mem = (CVodeMem) cvode_mem;
- cv_mem->cv_maxnef = maxnef;
- return(CV_SUCCESS);
- }
- /*
- * CVodeSetMaxConvFails
- *
- * Specifies the maximum number of nonlinear convergence failures
- * during one step try.
- */
- SUNDIALS_EXPORT int CVodeSetMaxConvFails(void *cvode_mem, int maxncf)
- {
- CVodeMem cv_mem;
- if (cvode_mem==NULL) {
- cvProcessError(NULL, CV_MEM_NULL, "CVODE", "CVodeSetMaxConvFails", MSGCV_NO_MEM);
- return (CV_MEM_NULL);
- }
- cv_mem = (CVodeMem) cvode_mem;
- cv_mem->cv_maxncf = maxncf;
- return(CV_SUCCESS);
- }
- /*
- * CVodeSetMaxNonlinIters
- *
- * Specifies the maximum number of nonlinear iterations during
- * one solve.
- */
- SUNDIALS_EXPORT int CVodeSetMaxNonlinIters(void *cvode_mem, int maxcor)
- {
- CVodeMem cv_mem;
- if (cvode_mem==NULL) {
- cvProcessError(NULL, CV_MEM_NULL, "CVODE", "CVodeSetMaxNonlinIters", MSGCV_NO_MEM);
- return (CV_MEM_NULL);
- }
- cv_mem = (CVodeMem) cvode_mem;
- cv_mem->cv_maxcor = maxcor;
- return(CV_SUCCESS);
- }
- /*
- * CVodeSetNonlinConvCoef
- *
- * Specifies the coeficient in the nonlinear solver convergence
- * test
- */
- SUNDIALS_EXPORT int CVodeSetNonlinConvCoef(void *cvode_mem, realtype nlscoef)
- {
- CVodeMem cv_mem;
- if (cvode_mem==NULL) {
- cvProcessError(NULL, CV_MEM_NULL, "CVODE", "CVodeSetNonlinConvCoef", MSGCV_NO_MEM);
- return(CV_MEM_NULL);
- }
- cv_mem = (CVodeMem) cvode_mem;
- cv_mem->cv_nlscoef = nlscoef;
- return(CV_SUCCESS);
- }
- /*
- * CVodeSetRootDirection
- *
- * Specifies the direction of zero-crossings to be monitored.
- * The default is to monitor both crossings.
- */
- SUNDIALS_EXPORT int CVodeSetRootDirection(void *cvode_mem, int *rootdir)
- {
- CVodeMem cv_mem;
- int i, nrt;
- if (cvode_mem==NULL) {
- cvProcessError(NULL, CV_MEM_NULL, "CVODE", "CVodeSetRootDirection", MSGCV_NO_MEM);
- return(CV_MEM_NULL);
- }
- cv_mem = (CVodeMem) cvode_mem;
- nrt = cv_mem->cv_nrtfn;
- if (nrt==0) {
- cvProcessError(NULL, CV_ILL_INPUT, "CVODE", "CVodeSetRootDirection", MSGCV_NO_ROOT);
- return(CV_ILL_INPUT);
- }
- for(i=0; i<nrt; i++) cv_mem->cv_rootdir[i] = rootdir[i];
- return(CV_SUCCESS);
- }
- /*
- * CVodeSetNoInactiveRootWarn
- *
- * Disables issuing a warning if some root function appears
- * to be identically zero at the beginning of the integration
- */
- SUNDIALS_EXPORT int CVodeSetNoInactiveRootWarn(void *cvode_mem)
- {
- CVodeMem cv_mem;
- if (cvode_mem==NULL) {
- cvProcessError(NULL, CV_MEM_NULL, "CVODE", "CVodeSetNoInactiveRootWarn", MSGCV_NO_MEM);
- return(CV_MEM_NULL);
- }
- cv_mem = (CVodeMem) cvode_mem;
- cv_mem->cv_mxgnull = 0;
-
- return(CV_SUCCESS);
- }
- /*
- * =================================================================
- * CVODE optional output functions
- * =================================================================
- */
- /*
- * Readability constants
- */
- #define nst (cv_mem->cv_nst)
- #define nfe (cv_mem->cv_nfe)
- #define ncfn (cv_mem->cv_ncfn)
- #define netf (cv_mem->cv_netf)
- #define nni (cv_mem->cv_nni)
- #define nsetups (cv_mem->cv_nsetups)
- #define qu (cv_mem->cv_qu)
- #define next_q (cv_mem->cv_next_q)
- #define ewt (cv_mem->cv_ewt)
- #define hu (cv_mem->cv_hu)
- #define next_h (cv_mem->cv_next_h)
- #define h0u (cv_mem->cv_h0u)
- #define tolsf (cv_mem->cv_tolsf)
- #define acor (cv_mem->cv_acor)
- #define lrw (cv_mem->cv_lrw)
- #define liw (cv_mem->cv_liw)
- #define nge (cv_mem->cv_nge)
- #define iroots (cv_mem->cv_iroots)
- #define nor (cv_mem->cv_nor)
- #define sldeton (cv_mem->cv_sldeton)
- #define tn (cv_mem->cv_tn)
- #define efun (cv_mem->cv_efun)
- /*
- * CVodeGetNumSteps
- *
- * Returns the current number of integration steps
- */
- SUNDIALS_EXPORT int CVodeGetNumSteps(void *cvode_mem, long int *nsteps)
- {
- CVodeMem cv_mem;
- if (cvode_mem==NULL) {
- cvProcessError(NULL, CV_MEM_NULL, "CVODE", "CVodeGetNumSteps", MSGCV_NO_MEM);
- return(CV_MEM_NULL);
- }
- cv_mem = (CVodeMem) cvode_mem;
- *nsteps = nst;
- return(CV_SUCCESS);
- }
- /*
- * CVodeGetNumRhsEvals
- *
- * Returns the current number of calls to f
- */
- SUNDIALS_EXPORT int CVodeGetNumRhsEvals(void *cvode_mem, long int *nfevals)
- {
- CVodeMem cv_mem;
- if (cvode_mem==NULL) {
- cvProcessError(NULL, CV_MEM_NULL, "CVODE", "CVodeGetNumRhsEvals", MSGCV_NO_MEM);
- return(CV_MEM_NULL);
- }
- cv_mem = (CVodeMem) cvode_mem;
- *nfevals = nfe;
- return(CV_SUCCESS);
- }
- /*
- * CVodeGetNumLinSolvSetups
- *
- * Returns the current number of calls to the linear solver setup routine
- */
- SUNDIALS_EXPORT int CVodeGetNumLinSolvSetups(void *cvode_mem, long int *nlinsetups)
- {
- CVodeMem cv_mem;
- if (cvode_mem==NULL) {
- cvProcessError(NULL, CV_MEM_NULL, "CVODE", "CVodeGetNumLinSolvSetups", MSGCV_NO_MEM);
- return(CV_MEM_NULL);
- }
- cv_mem = (CVodeMem) cvode_mem;
- *nlinsetups = nsetups;
- return(CV_SUCCESS);
- }
- /*
- * CVodeGetNumErrTestFails
- *
- * Returns the current number of error test failures
- */
- SUNDIALS_EXPORT int CVodeGetNumErrTestFails(void *cvode_mem, long int *netfails)
- {
- CVodeMem cv_mem;
- if (cvode_mem==NULL) {
- cvProcessError(NULL, CV_MEM_NULL, "CVODE", "CVodeGetNumErrTestFails", MSGCV_NO_MEM);
- return(CV_MEM_NULL);
- }
- cv_mem = (CVodeMem) cvode_mem;
- *netfails = netf;
- return(CV_SUCCESS);
- }
- /*
- * CVodeGetLastOrder
- *
- * Returns the order on the last succesful step
- */
- SUNDIALS_EXPORT int CVodeGetLastOrder(void *cvode_mem, int *qlast)
- {
- CVodeMem cv_mem;
- if (cvode_mem==NULL) {
- cvProcessError(NULL, CV_MEM_NULL, "CVODE", "CVodeGetLastOrder", MSGCV_NO_MEM);
- return(CV_MEM_NULL);
- }
- cv_mem = (CVodeMem) cvode_mem;
- *qlast = qu;
- return(CV_SUCCESS);
- }
- /*
- * CVodeGetCurrentOrder
- *
- * Returns the order to be attempted on the next step
- */
- SUNDIALS_EXPORT int CVodeGetCurrentOrder(void *cvode_mem, int *qcur)
- {
- CVodeMem cv_mem;
- if (cvode_mem==NULL) {
- cvProcessError(NULL, CV_MEM_NULL, "CVODE", "CVodeGetCurrentOrder", MSGCV_NO_MEM);
- return(CV_MEM_NULL);
- }
- cv_mem = (CVodeMem) cvode_mem;
- *qcur = next_q;
- return(CV_SUCCESS);
- }
- /*
- * CVodeGetNumStabLimOrderReds
- *
- * Returns the number of order reductions triggered by the stability
- * limit detection algorithm
- */
- SUNDIALS_EXPORT int CVodeGetNumStabLimOrderReds(void *cvode_mem, long int *nslred)
- {
- CVodeMem cv_mem;
- if (cvode_mem==NULL) {
- cvProcessError(NULL, CV_MEM_NULL, "CVODE", "CVodeGetNumStabLimOrderReds", MSGCV_NO_MEM);
- return(CV_MEM_NULL);
- }
- cv_mem = (CVodeMem) cvode_mem;
- if (sldeton==FALSE)
- *nslred = 0;
- else
- *nslred = nor;
- return(CV_SUCCESS);
- }
- /*
- * CVodeGetActualInitStep
- *
- * Returns the step size used on the first step
- */
- SUNDIALS_EXPORT int CVodeGetActualInitStep(void *cvode_mem, realtype *hinused)
- {
- CVodeMem cv_mem;
- if (cvode_mem==NULL) {
- cvProcessError(NULL, CV_MEM_NULL, "CVODE", "CVodeGetActualInitStep", MSGCV_NO_MEM);
- return(CV_MEM_NULL);
- }
- cv_mem = (CVodeMem) cvode_mem;
- *hinused = h0u;
- return(CV_SUCCESS);
- }
- /*
- * CVodeGetLastStep
- *
- * Returns the step size used on the last successful step
- */
- SUNDIALS_EXPORT int CVodeGetLastStep(void *cvode_mem, realtype *hlast)
- {
- CVodeMem cv_mem;
- if (cvode_mem==NULL) {
- cvProcessError(NULL, CV_MEM_NULL, "CVODE", "CVodeGetLastStep", MSGCV_NO_MEM);
- return(CV_MEM_NULL);
- }
- cv_mem = (CVodeMem) cvode_mem;
- *hlast = hu;
- return(CV_SUCCESS);
- }
- /*
- * CVodeGetCurrentStep
- *
- * Returns the step size to be attempted on the next step
- */
- SUNDIALS_EXPORT int CVodeGetCurrentStep(void *cvode_mem, realtype *hcur)
- {
- CVodeMem cv_mem;
- if (cvode_mem==NULL) {
- cvProcessError(NULL, CV_MEM_NULL, "CVODE", "CVodeGetCurrentStep", MSGCV_NO_MEM);
- return(CV_MEM_NULL);
- }
- cv_mem = (CVodeMem) cvode_mem;
-
- *hcur = next_h;
- return(CV_SUCCESS);
- }
- /*
- * CVodeGetCurrentTime
- *
- * Returns the current value of the independent variable
- */
- SUNDIALS_EXPORT int CVodeGetCurrentTime(void *cvode_mem, realtype *tcur)
- {
- CVodeMem cv_mem;
- if (cvode_mem==NULL) {
- cvProcessError(NULL, CV_MEM_NULL, "CVODE", "CVodeGetCurrentTime", MSGCV_NO_MEM);
- return(CV_MEM_NULL);
- }
- cv_mem = (CVodeMem) cvode_mem;
- *tcur = tn;
- return(CV_SUCCESS);
- }
- /*
- * CVodeGetTolScaleFactor
- *
- * Returns a suggested factor for scaling tolerances
- */
- SUNDIALS_EXPORT int CVodeGetTolScaleFactor(void *cvode_mem, realtype *tolsfact)
- {
- CVodeMem cv_mem;
- if (cvode_mem==NULL) {
- cvProcessError(NULL, CV_MEM_NULL, "CVODE", "CVodeGetTolScaleFactor", MSGCV_NO_MEM);
- return(CV_MEM_NULL);
- }
- cv_mem = (CVodeMem) cvode_mem;
- *tolsfact = tolsf;
- return(CV_SUCCESS);
- }
- /*
- * CVodeGetErrWeights
- *
- * This routine returns the current weight vector.
- */
- SUNDIALS_EXPORT int CVodeGetErrWeights(void *cvode_mem, N_Vector eweight)
- {
- CVodeMem cv_mem;
- if (cvode_mem==NULL) {
- cvProcessError(NULL, CV_MEM_NULL, "CVODE", "CVodeGetErrWeights", MSGCV_NO_MEM);
- return(CV_MEM_NULL);
- }
- cv_mem = (CVodeMem) cvode_mem;
- N_VScale(ONE, ewt, eweight);
- return(CV_SUCCESS);
- }
- /*
- * CVodeGetEstLocalErrors
- *
- * Returns an estimate of the local error
- */
- SUNDIALS_EXPORT int CVodeGetEstLocalErrors(void *cvode_mem, N_Vector ele)
- {
- CVodeMem cv_mem;
- if (cvode_mem==NULL) {
- cvProcessError(NULL, CV_MEM_NULL, "CVODE", "CVodeGetEstLocalErrors", MSGCV_NO_MEM);
- return(CV_MEM_NULL);
- }
- cv_mem = (CVodeMem) cvode_mem;
- N_VScale(ONE, acor, ele);
- return(CV_SUCCESS);
- }
- /*
- * CVodeGetWorkSpace
- *
- * Returns integrator work space requirements
- */
- SUNDIALS_EXPORT int CVodeGetWorkSpace(void *cvode_mem, long int *lenrw, long int *leniw)
- {
- CVodeMem cv_mem;
- if (cvode_mem==NULL) {
- cvProcessError(NULL, CV_MEM_NULL, "CVODE", "CVodeGetWorkSpace", MSGCV_NO_MEM);
- return(CV_MEM_NULL);
- }
- cv_mem = (CVodeMem) cvode_mem;
- *leniw = liw;
- *lenrw = lrw;
- return(CV_SUCCESS);
- }
- /*
- * CVodeGetIntegratorStats
- *
- * Returns integrator statistics
- */
- SUNDIALS_EXPORT int CVodeGetIntegratorStats(void *cvode_mem, long int *nsteps, long int *nfevals,
- long int *nlinsetups, long int *netfails, int *qlast,
- int *qcur, realtype *hinused, realtype *hlast,
- realtype *hcur, realtype *tcur)
- {
- CVodeMem cv_mem;
- if (cvode_mem==NULL) {
- cvProcessError(NULL, CV_MEM_NULL, "CVODE", "CVodeGetIntegratorStats", MSGCV_NO_MEM);
- return(CV_MEM_NULL);
- }
- cv_mem = (CVodeMem) cvode_mem;
- *nsteps = nst;
- *nfevals = nfe;
- *nlinsetups = nsetups;
- *netfails = netf;
- *qlast = qu;
- *qcur = next_q;
- *hinused = h0u;
- *hlast = hu;
- *hcur = next_h;
- *tcur = tn;
- return(CV_SUCCESS);
- }
- /*
- * CVodeGetNumGEvals
- *
- * Returns the current number of calls to g (for rootfinding)
- */
- SUNDIALS_EXPORT int CVodeGetNumGEvals(void *cvode_mem, long int *ngevals)
- {
- CVodeMem cv_mem;
- if (cvode_mem==NULL) {
- cvProcessError(NULL, CV_MEM_NULL, "CVODE", "CVodeGetNumGEvals", MSGCV_NO_MEM);
- return(CV_MEM_NULL);
- }
- cv_mem = (CVodeMem) cvode_mem;
- *ngevals = nge;
- return(CV_SUCCESS);
- }
- /*
- * CVodeGetRootInfo
- *
- * Returns pointer to array rootsfound showing roots found
- */
- SUNDIALS_EXPORT int CVodeGetRootInfo(void *cvode_mem, int *rootsfound)
- {
- CVodeMem cv_mem;
- int i, nrt;
- if (cvode_mem==NULL) {
- cvProcessError(NULL, CV_MEM_NULL, "CVODE", "CVodeGetRootInfo", MSGCV_NO_MEM);
- return(CV_MEM_NULL);
- }
- cv_mem = (CVodeMem) cvode_mem;
- nrt = cv_mem->cv_nrtfn;
- for (i=0; i<nrt; i++) rootsfound[i] = iroots[i];
- return(CV_SUCCESS);
- }
- /*
- * CVodeGetNumNonlinSolvIters
- *
- * Returns the current number of iterations in the nonlinear solver
- */
- SUNDIALS_EXPORT int CVodeGetNumNonlinSolvIters(void *cvode_mem, long int *nniters)
- {
- CVodeMem cv_mem;
- if (cvode_mem==NULL) {
- cvProcessError(NULL, CV_MEM_NULL, "CVODE", "CVodeGetNumNonlinSolvIters", MSGCV_NO_MEM);
- return(CV_MEM_NULL);
- }
- cv_mem = (CVodeMem) cvode_mem;
- *nniters = nni;
- return(CV_SUCCESS);
- }
- /*
- * CVodeGetNumNonlinSolvConvFails
- *
- * Returns the current number of convergence failures in the
- * nonlinear solver
- */
- SUNDIALS_EXPORT int CVodeGetNumNonlinSolvConvFails(void *cvode_mem, long int *nncfails)
- {
- CVodeMem cv_mem;
- if (cvode_mem==NULL) {
- cvProcessError(NULL, CV_MEM_NULL, "CVODE", "CVodeGetNumNonlinSolvConvFails", MSGCV_NO_MEM);
- return(CV_MEM_NULL);
- }
- cv_mem = (CVodeMem) cvode_mem;
- *nncfails = ncfn;
- return(CV_SUCCESS);
- }
- /*
- * CVodeGetNonlinSolvStats
- *
- * Returns nonlinear solver statistics
- */
- SUNDIALS_EXPORT int CVodeGetNonlinSolvStats(void *cvode_mem, long int *nniters,
- long int *nncfails)
- {
- CVodeMem cv_mem;
- if (cvode_mem==NULL) {
- cvProcessError(NULL, CV_MEM_NULL, "CVODE", "CVodeGetNonlinSolvStats", MSGCV_NO_MEM);
- return(CV_MEM_NULL);
- }
- cv_mem = (CVodeMem) cvode_mem;
- *nniters = nni;
- *nncfails = ncfn;
- return(CV_SUCCESS);
- }
- /*-----------------------------------------------------------------*/
- SUNDIALS_EXPORT char *CVodeGetReturnFlagName(long int flag)
- {
- char *name;
- name = (char *)malloc(24*sizeof(char));
- switch(flag) {
- case CV_SUCCESS:
- sprintf(name,"CV_SUCCESS");
- break;
- case CV_TSTOP_RETURN:
- sprintf(name,"CV_TSTOP_RETURN");
- break;
- case CV_ROOT_RETURN:
- sprintf(name,"CV_ROOT_RETURN");
- break;
- case CV_TOO_MUCH_WORK:
- sprintf(name,"CV_TOO_MUCH_WORK");
- break;
- case CV_TOO_MUCH_ACC:
- sprintf(name,"CV_TOO_MUCH_ACC");
- break;
- case CV_ERR_FAILURE:
- sprintf(name,"CV_ERR_FAILURE");
- break;
- case CV_CONV_FAILURE:
- sprintf(name,"CV_CONV_FAILURE");
- break;
- case CV_LINIT_FAIL:
- sprintf(name,"CV_LINIT_FAIL");
- break;
- case CV_LSETUP_FAIL:
- sprintf(name,"CV_LSETUP_FAIL");
- break;
- case CV_LSOLVE_FAIL:
- sprintf(name,"CV_LSOLVE_FAIL");
- break;
- case CV_RHSFUNC_FAIL:
- sprintf(name,"CV_RHSFUNC_FAIL");
- break;
- case CV_FIRST_RHSFUNC_ERR:
- sprintf(name,"CV_FIRST_RHSFUNC_ERR");
- break;
- case CV_REPTD_RHSFUNC_ERR:
- sprintf(name,"CV_REPTD_RHSFUNC_ERR");
- break;
- case CV_UNREC_RHSFUNC_ERR:
- sprintf(name,"CV_UNREC_RHSFUNC_ERR");
- break;
- case CV_RTFUNC_FAIL:
- sprintf(name,"CV_RTFUNC_FAIL");
- break;
- case CV_MEM_FAIL:
- sprintf(name,"CV_MEM_FAIL");
- break;
- case CV_MEM_NULL:
- sprintf(name,"CV_MEM_NULL");
- break;
- case CV_ILL_INPUT:
- sprintf(name,"CV_ILL_INPUT");
- break;
- case CV_NO_MALLOC:
- sprintf(name,"CV_NO_MALLOC");
- break;
- case CV_BAD_K:
- sprintf(name,"CV_BAD_K");
- break;
- case CV_BAD_T:
- sprintf(name,"CV_BAD_T");
- break;
- case CV_BAD_DKY:
- sprintf(name,"CV_BAD_DKY");
- break;
- case CV_TOO_CLOSE:
- sprintf(name,"CV_TOO_CLOSE");
- break;
- default:
- sprintf(name,"NONE");
- }
- return(name);
- }
- /* undefine to be able to compile all source code files in a single compilation unit, added by 3ds.com */
- #undef lrw
- #undef liw
- #undef lrw1
- #undef liw1
|