2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 * Copyright (C) Scilab Enterprises - 2013 - Paul Bignier
5 * This file must be used under the terms of the CeCILL.
6 * This source file is licensed as described in the file COPYING, which
7 * you should have received as part of this distribution. The terms
8 * are also available at
9 * http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
16 #include "sundials_extension.h"
17 #include "sundials/sundials_types.h" // Definition of types 'realtype' and 'booleantype'
18 #include "nvector/nvector_serial.h" // Type 'N_Vector'
19 #include "../scicos_sundials/src/ida/ida_impl.h" // Error handling
22 #define max(A,B) ((A>B) ? A:B) // 'max()' function
25 /* By default, we set the maximum order to 5 */
26 #define MAXORD_DEFAULT 5
49 // Derivative computation, root functions, preconditioner calculation and application
50 typedef void (*DDASResFn) (realtype *tOld, realtype *y, realtype *yp, realtype *res, int *flag, realtype *dummy1, int *dummy2);
51 typedef void (*DDASRootFn) (int *neq, realtype *tOld, realtype *y, int *ng, realtype *groot, realtype *dummy1, int *dummy2);
52 typedef void (*DDASJacPsolFn) (realtype *res, int *ires, int *neq, realtype *tOld, realtype *actual, realtype *actualP,
53 realtype *rewt, realtype *savr, realtype *wk, realtype *h, realtype *cj, realtype *wp,
54 int *iwp, int *ier, realtype *dummy1, int *dummy2);
55 typedef void (*DDASPsolFn) (int *neq, realtype *tOld, realtype *actual, realtype *actualP,
56 realtype *savr, realtype *wk, realtype *cj, realtype *wght, realtype *wp,
57 int *iwp, realtype *b, realtype *eplin, int *ier, realtype *dummy1, int *dummy2);
58 typedef void (*DDASErrHandlerFn) (int error_code, const char *module, const char *function, char *msg, void *user_data);
60 // DDaskr problem memory structure
61 typedef struct DDaskrMemRec
70 realtype * yPrimeVector;
73 struct DDrWork_t * rwork;
78 DDASErrHandlerFn ehfun;
83 DDASJacPsolFn jacpsol;
89 // Creating the problem
90 void * DDaskrCreate (int * neq, int ng, int solverIndex);
92 // Allocating the problem
93 int DDaskrInit (void * ddaskr_mem, DDASResFn Res, realtype t0, N_Vector yy0, N_Vector yp0, DDASJacPsolFn jacpsol, DDASPsolFn psol);
95 // Reinitializing the problem
96 int DDaskrReInit (void * ddaskr_mem, realtype tOld, N_Vector yy0, N_Vector yp0);
98 // Specifying the tolerances
99 int DDaskrSStolerances (void * ddaskr_mem, realtype reltol, realtype abstol);
101 // Initializing the root-finding problem
102 int DDaskrRootInit (void * ddaskr_mem, int ng, DDASRootFn g);
104 // Setting a pointer to user_data that will be passed to the user's res function every time a user-supplied function is called
105 int DDaskrSetUserData (void * ddaskr_mem, void * User_data);
107 // Specifying the maximum step size
108 int DDaskrSetMaxStep (void * ddaskr_mem, realtype hmax);
110 // Specifying the time beyond which the integration is not to proceed
111 int DDaskrSetStopTime (void * ddaskr_mem, realtype tcrit);
113 // Sets the maximum number of steps in an integration interval
114 int DDaskrSetMaxNumSteps (void * ddaskr_mem, int maxnh);
116 // Sets the maximum number of Jacobian or preconditioner evaluations
117 int DDaskrSetMaxNumJacsIC (void * ddaskr_mem, int maxnj);
119 // Sets the maximum number of Newton iterations per Jacobian or preconditioner evaluation
120 int DDaskrSetMaxNumItersIC (void * ddaskr_mem, int maxnit);
122 // Sets the maximum number of values of the artificial stepsize parameter H to be tried
123 int DDaskrSetMaxNumStepsIC (void * ddaskr_mem, int MaxnhIC);
125 // Sets the flag to turn off the linesearch algorithm
126 int DDaskrSetLineSearchOffIC (void * ddaskr_mem, int lsoff);
128 // Specifying which components are differential and which ones are algrebraic, in order to get consistent initial values
129 int DDaskrSetId (void * ddaskr_mem, N_Vector xproperty);
131 // Solving the problem
132 int DDaskrSolve (void * ddaskr_mem, realtype tOut, realtype * tOld, N_Vector yOut, N_Vector ypOut, int itask);
134 // Computing consistent initial values for the problem
135 int DDaskrCalcIC (void * ddaskr_mem, int icopt, realtype tout1);
137 // Following on DDasCalcIC, copying yy0 and yp0 (computed consistent values) into the memory space
138 int DDaskrGetConsistentIC (void * ddaskr_mem, N_Vector yy0, N_Vector yp0);
140 // Update rootsfound to the computed jroots
141 int DDaskrGetRootInfo (void * ddaskr_mem, int * rootsfound);
143 // Freeing the problem memory allocated by ddaskrMalloc
144 void DDaskrFree (void ** ddaskr_mem);
146 // Freeing the ddaskr vectors allocated in ddaskrAllocVectors
147 void DDASFreeVectors (DDaskrMem ddaskr_mem);
149 // Specifies the error handler function
150 int DDaskrSetErrHandlerFn (void * ddaskr_mem, DDASErrHandlerFn ehfun, void * eh_data);
152 // Error handling function
153 void DDASProcessError (DDaskrMem ddas_mem, int error_code, const char *module, const char *fname, const char *msgfmt, ...);