1 /*
2  * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3  * Copyright (C) Scilab Enterprises - 2012 - Paul Bignier
4  *
5  * Copyright (C) 2012 - 2016 - Scilab Enterprises
6  *
7  * This file is hereby licensed under the terms of the GNU GPL v2.0,
8  * pursuant to article 5.3.4 of the CeCILL v.2.1.
9  * This file was originally licensed under the terms of the CeCILL v2.1,
10  * and continues to be available under such terms.
11  * For more information, see the COPYING file which you should have received
12  * along with this program.
13  *
14  */
15 
16 #ifndef _LSODAR_H
17 #define _LSODAR_H
18 
19 #include "sundials_extension.h"
20 #include "sundials/sundials_types.h" // Definition of types 'realtype' and 'booleantype'
21 #include "nvector/nvector_serial.h"  // Type 'N_Vector'
22 #include "../scicos_sundials/src/cvode/cvode_impl.h" // Error handling
23 
24 #ifndef max
25 #define max(A,B) ((A>B) ? A:B)  // 'max()' function
26 #endif
27 
28 // realtype workspace
29 struct rWork_t
30 {
31     realtype tcrit;
32     realtype rwork2;
33     realtype rwork3;
34     realtype rwork4;
35     realtype h0;
36     realtype hmax;
37     realtype hmin;
38     realtype rwork[1];
39 };
40 
41 // Derivative computation and Root functions
42 typedef void (*LSRhsFn) (int * neq, realtype * t, realtype * y, realtype * rwork);
43 typedef void (*LSRootFn) (int * neq, realtype * t, realtype * y, int * ng, realtype * rwork);
44 typedef void (*LSErrHandlerFn) (int error_code, const char *module, const char *function, char *msg, void *user_data);
45 
46 // LSodar problem memory structure
47 typedef struct LSodarMemRec
48 {
49     LSRhsFn func;
50     int * nEquations;
51     realtype * yVector;
52     realtype tStart;
53     realtype tEnd;
54     int iTol;
55     realtype relTol;
56     realtype absTol;
57     int iState;
58     int iOpt;
59     struct rWork_t * rwork;
60     int lrw;
61     int * iwork;
62     int liw;
63     int jacobian;
64     int jacType;
65     LSRootFn g_fun;
66     int ng_fun;
67     int * jroot;
68     LSErrHandlerFn ehfun;
69 } *LSodarMem;
70 
71 // Creating the problem
72 void * LSodarCreate (int * neq, int ng);
73 
74 // Allocating the problem
75 int LSodarInit (void * lsodar_mem, LSRhsFn f, realtype t0, N_Vector y);
76 
77 // Reinitializing the problem
78 int LSodarReInit (void * lsodar_mem, realtype tOld, N_Vector y);
79 
80 // Specifying the tolerances
81 int LSodarSStolerances (void * lsodar_mem, realtype reltol, realtype abstol);
82 
83 // Initializing the root-finding problem
84 int LSodarRootInit (void * lsodar_mem, int ng, LSRootFn g);
85 
86 // Specifying the maximum step size
87 int LSodarSetMaxStep (void * lsodar_mem, realtype hmax);
88 
89 // Specifying the time beyond which the integration is not to proceed
90 int LSodarSetStopTime (void * lsodar_mem, realtype tcrit);
91 
92 // Solving the problem
93 int LSodar (void * lsodar_mem, realtype tOut, N_Vector yVec, realtype * tOld, int itask);
94 
95 // Update rootsfound to the computed jroots
96 int LSodarGetRootInfo (void * lsodar_mem, int * rootsfound);
97 
98 // Freeing the problem memory allocated by lsodarMalloc
99 void LSodarFree (void ** lsodar_mem);
100 
101 // Freeing the lsodar vectors allocated in lsodarAllocVectors
102 void LSFreeVectors (LSodarMem lsodar_mem);
103 
104 // Specifies the error handler function
105 int LSodarSetErrHandlerFn (void * lsodar_mem, LSErrHandlerFn ehfun, void * eh_data);
106 
107 // Error handling function
108 void LSProcessError (LSodarMem ls_mem, int error_code, const char *module, const char *fname, const char *msgfmt, ...);
109 
110 #endif
111