Management of errors in differential equations functions.
[scilab.git] / scilab / modules / differential_equations / includes / differentialequationfunctions.hxx
1 /*
2  *  Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3  *  Copyright (C) 2011 - DIGITEO - Cedric DELAMARRE
4  *
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-en.txt
10  *
11  */
12
13 #ifndef __DIFFERENTIALEQUATIONS_HXX__
14 #define __DIFFERENTIALEQUATIONS_HXX__
15
16 #include <map>
17 #include "dynlib_differential_equations.h"
18 #include "string.hxx"
19 #include "callable.hxx"
20
21 extern "C"
22 {
23 #include "Thread_Wrapper.h"
24 }
25
26 extern "C"
27 {
28     // jacobian
29     void C2F(jex)   (int*, double*, double*, int*, int*, double*, int*);
30
31     // ode
32     void C2F(arnol) (int*, double*, double*, double*);
33     void C2F(fex)   (int*, double*, double*, double*);
34     void C2F(fex2)  (int*, double*, double*, double*);
35     void C2F(fex3)  (int*, double*, double*, double*);
36     void C2F(fexab) (int*, double*, double*, double*);
37     void C2F(loren) (int*, double*, double*, double*);
38     void C2F(bcomp) (int*, double*, double*, double*);
39     void C2F(lcomp) (int*, double*, double*, double*);
40
41     // odedc
42     typedef int(*odedc_f_t)(int*, int*, int*, double*, double*, double*);
43     void C2F(fcd)   (int*, int*, int*, double*, double*, double*);
44     void C2F(fcd1)  (int*, int*, int*, double*, double*, double*);
45     void C2F(fexcd) (int*, int*, int*, double*, double*, double*);
46     void C2F(phis)  (int*, int*, int*, double*, double*, double*);
47     void C2F(phit)  (int*, int*, int*, double*, double*, double*);
48
49     // intg
50     double C2F(intgex)(double*);
51
52     // int2d
53     double C2F(int2dex)(double*, double*);
54
55     // int3d
56     void C2F(int3dex)(double*, int*, double*);
57
58     // feval
59     int C2F(parab)  (int*, double*, double*, double*, int*);
60     int C2F(parabc) (int*, double*, double*, double*, int*);
61
62     // bvode
63     void C2F(cndg)  (int*, double*, double*);
64     void C2F(cng)   (int*, double*, double*);
65     void C2F(cnf)   (double*, double*, double*);
66     void C2F(cndf)  (double*, double*, double*);
67     void C2F(cngu)  (double*, double*, double*);
68
69     // impl
70     void C2F(resid) (int*, double*, double*, double*, double*, int*);
71     void C2F(aplusp)(int*, double*, double*, double*, double*, double*, int*);
72     void C2F(dgbydy)(int*, double*, double*, double*, double*, double*, double*, int*);
73
74     // dassl, dasrt, daskr
75     void C2F(res1)  (double*, double*, double*, double*, int*, double*, int*);
76     void C2F(res2)  (double*, double*, double*, double*, int*, double*, int*);
77     void C2F(dres1) (double*, double*, double*, double*, int*, double*, int*);
78     void C2F(dres2) (double*, double*, double*, double*, int*, double*, int*);
79     void C2F(jac2)  (double*, double*, double*, double*, double*, double*, int*);
80     void C2F(djac2) (double*, double*, double*, double*, double*, double*, int*);
81     void C2F(djac1) (double*, double*, double*, double*, double*, double*, int*);
82
83     // dasrt
84     void C2F(gr1)(int*, double*, double*, int*, double*, double*, int*);
85     void C2F(gr2)(int*, double*, double*, int*, double*, double*, int*);
86
87     // daskr
88     void C2F(bpjacd)(double*, int*, int*, double*, double*, double*, double*, double*,
89                      double*, double*, double*, double*, int*, int*, double*, int*);
90     void C2F(bpsold)(int*, double*, double*, double*, double*, double*, double*,
91                      double*, double*, int*, double*, double*, int*, double*, int*);
92 }
93
94 class DIFFERENTIAL_EQUATIONS_IMPEXP DifferentialEquationFunctions
95 {
96
97 public :
98
99     DifferentialEquationFunctions(std::wstring callerName);
100     ~DifferentialEquationFunctions();
101
102     void setOdeYRows(int);
103     void setOdeYCols(int);
104
105     void setOdedcYDSize(int);
106     void setOdedcFlag();
107     void resetOdedcFlag();
108
109     void setFFunction(types::Callable*);
110     void setJacFunction(types::Callable*);
111     void setGFunction(types::Callable*);
112     void setPsolFunction(types::Callable*);
113     void setPjacFunction(types::Callable*);
114
115     bool setFFunction(types::String*);
116     bool setJacFunction(types::String*);
117     bool setGFunction(types::String*);
118     bool setPsolFunction(types::String*);
119     bool setPjacFunction(types::String*);
120
121     void setFArgs(types::InternalType*);
122     void setJacArgs(types::InternalType*);
123     void setGArgs(types::InternalType*);
124     void setPsolArgs(types::InternalType*);
125     void setPjacArgs(types::InternalType*);
126
127     int getOdeYRows();
128     int getOdeYCols();
129
130     int getOdedcYDSize();
131     int getOdedcFlag();
132
133     void execOdeF(int* n, double* t, double* y, double* ydot);
134     void execFunctionJac(int* n, double* t, double* y, int* ml, int* mu, double* J, int* nrpd);
135     void execFunctionG(int* n, double* t, double* y, int* ng, double* gout);
136
137     double execIntgF(double* x);
138     double execInt2dF(double* x, double* y);
139     void execInt3dF(double* x, int* numfun, double* funvls);
140
141     void execFevalF(int* nn, double* x1, double* x2, double* xres, int* itype);
142
143     // bvode
144     void setFsubFunction(types::Callable*);
145     void setDfsubFunction(types::Callable*);
146     void setGsubFunction(types::Callable*);
147     void setDgsubFunction(types::Callable*);
148     void setGuessFunction(types::Callable*);
149
150     bool setFsubFunction(types::String*);
151     bool setDfsubFunction(types::String*);
152     bool setGsubFunction(types::String*);
153     bool setDgsubFunction(types::String*);
154     bool setGuessFunction(types::String*);
155
156     void setFsubArgs(types::InternalType*);
157     void setDfsubArgs(types::InternalType*);
158     void setGsubArgs(types::InternalType*);
159     void setDgsubArgs(types::InternalType*);
160     void setGuessArgs(types::InternalType*);
161
162     void setBvodeM(int);
163     void setBvodeN(int);
164
165     void execBvodeGsub(int*, double*, double*);
166     void execBvodeDgsub(int*, double*, double*);
167     void execBvodeFsub(double*, double*, double*);
168     void execBvodeDfsub(double*, double*, double*);
169     void execBvodeGuess(double*, double*, double*);
170
171     // impl
172     void execImplF(int*, double*, double*, double*, double*, int*);
173     void execImplG(int*, double*, double*, double*, double*, double*, int*);
174     void execImplJac(int*, double*, double*, double*, double*, double*, double*, int*);
175
176     //dassl dasrt
177     void execDasslF(double*, double*, double*, double*, int*, double*, int*);
178     void execDasslJac(double*, double*, double*, double*, double*, double*, int*);
179     void setMu(int);
180     void setMl(int);
181
182     // dasrt
183     void execDasrtG(int*, double*, double*, int*, double*, double*, int*);
184
185     // daskr
186     void execDaskrPsol(int* neq, double* t, double* y, double* ydot, double* savr, double* wk,
187                        double* cj, double* wght, double* wp, int* iwp, double* b, double* eplin,
188                        int* iter, double* rpar, int* ipar);
189     void execDaskrPjac(double* res, int* ires, int* neq, double* t, double* y, double* ydot,
190                        double* rewt, double* savr, double* wk, double* h, double* cj,
191                        double* wp, int* iwp, int* ier, double* rpar, int* ipar);
192
193
194 private :
195
196     std::map<std::wstring, void*> m_staticFunctionMap;
197     std::wstring m_wstrCaller;
198
199     int m_odeYRows;
200     int m_odeYCols;
201
202     // odedc
203     int m_odedcYDSize;
204     int m_odedcFlag;
205
206     // bvode
207     int m_bvodeM;
208     int m_bvodeN;
209
210     // dassl dasrt daskr
211     int m_mu;
212     int m_ml;
213     bool m_bandedJac;
214
215     types::Callable* m_pCallFFunction;
216     types::Callable* m_pCallJacFunction;
217     types::Callable* m_pCallGFunction;
218     types::Callable* m_pCallPsolFunction;
219     types::Callable* m_pCallPjacFunction;
220
221     types::String* m_pStringFFunctionDyn;
222     types::String* m_pStringJacFunctionDyn;
223     types::String* m_pStringGFunctionDyn;
224     types::String* m_pStringPsolFunctionDyn;
225     types::String* m_pStringPjacFunctionDyn;
226
227     types::String* m_pStringFFunctionStatic;
228     types::String* m_pStringJacFunctionStatic;
229     types::String* m_pStringGFunctionStatic;
230     types::String* m_pStringPsolFunctionStatic;
231     types::String* m_pStringPjacFunctionStatic;
232
233     std::vector<types::InternalType*> m_FArgs;
234     std::vector<types::InternalType*> m_JacArgs;
235     std::vector<types::InternalType*> m_odeGArgs;
236     std::vector<types::InternalType*> m_pSolArgs;
237     std::vector<types::InternalType*> m_pJacArgs;
238
239     // ode / odedc
240     void callOdeMacroF(int* n, double* t, double* y, double* ydot);
241     void callMacroJac(int *n, double *t, double *y, int *ml, int *mu, double *J, int *nrpd);
242     void callMacroG(int* n, double* t, double* y, int* ng, double* gout);
243
244     // intg
245     double callIntgMacroF(double* x);
246
247     // int2d
248     double callInt2dMacroF(double* x, double* y);
249
250     // int3d
251     void callInt3dMacroF(double* x, int* numfun, double* funvls);
252
253     // feval
254     void callFevalMacroF(int *nn, double *x1, double *x2, double *xres, int *itype);
255
256     // bvode
257     types::Callable* m_pCallFsubFunction;
258     types::Callable* m_pCallDfsubFunction;
259     types::Callable* m_pCallGsubFunction;
260     types::Callable* m_pCallDgsubFunction;
261     types::Callable* m_pCallGuessFunction;
262
263     types::String* m_pStringFsubFunctionDyn;
264     types::String* m_pStringDfsubFunctionDyn;
265     types::String* m_pStringGsubFunctionDyn;
266     types::String* m_pStringDgsubFunctionDyn;
267     types::String* m_pStringGuessFunctionDyn;
268
269     types::String* m_pStringFsubFunctionStatic;
270     types::String* m_pStringDfsubFunctionStatic;
271     types::String* m_pStringGsubFunctionStatic;
272     types::String* m_pStringDgsubFunctionStatic;
273     types::String* m_pStringGuessFunctionStatic;
274
275     std::vector<types::InternalType*> m_FsubArgs;
276     std::vector<types::InternalType*> m_DfsubArgs;
277     std::vector<types::InternalType*> m_GsubArgs;
278     std::vector<types::InternalType*> m_DgsubArgs;
279     std::vector<types::InternalType*> m_GuessArgs;
280
281     void callBvodeMacroGsub  (int* i, double* z, double* g);
282     void callBvodeMacroDgsub (int* i, double* z, double* g);
283     void callBvodeMacroFsub  (double* x, double* z, double* d);
284     void callBvodeMacroDfsub (double* x, double* z, double* d);
285     void callBvodeMacroGuess (double* x, double* z, double* d);
286
287     // impl
288     void callImplMacroF(int*, double*, double*, double*, double*, int*);
289     void callImplMacroG(int*, double*, double*, double*, double*, double*, int*);
290     void callImplMacroJac(int*, double*, double*, double*, double*, double*, double*, int*);
291
292     // dassl dasrt
293     void callDasslMacroF(double*, double*, double*, double*, int*, double*, int*);
294     void callDasslMacroJac(double*, double*, double*, double*, double*, double*, int*);
295
296     // dasrt
297     void callDasrtMacroG(int*, double*, double*, int*, double*, double*, int*);
298
299     // daskr
300     void callDaskrMacroPsol(int* neq, double* t, double* y, double* ydot, double* savr, double* wk,
301                             double* cj, double* wght, double* wp, int* iwp, double* b, double* eplin,
302                             int* iter, double* rpar, int* ipar);
303     void callDaskrMacroPjac(double* res, int* ires, int* neq, double* t, double* y, double* ydot,
304                             double* rewt, double* savr, double* wk, double* h, double* cj,
305                             double* wp, int* iwp, int* ier, double* rpar, int* ipar);
306 };
307
308 class DIFFERENTIAL_EQUATIONS_IMPEXP DifferentialEquation
309 {
310     // differential equation functions
311 private :
312     static std::map<__threadId, DifferentialEquationFunctions*> m_mapDifferentialEquationFunctions;
313
314 public :
315     static void addDifferentialEquationFunctions(DifferentialEquationFunctions* _deFunction);
316     static void removeDifferentialEquationFunctions();
317     static DifferentialEquationFunctions* getDifferentialEquationFunctions();
318 };
319 #endif /* !__DIFFERENTIALEQUATIONS_HXX__ */
320