3912
|
1 /* |
|
2 |
|
3 Copyright (C) 1996, 1997, 2002 John W. Eaton |
|
4 |
|
5 This file is part of Octave. |
|
6 |
|
7 Octave is free software; you can redistribute it and/or modify it |
|
8 under the terms of the GNU General Public License as published by the |
|
9 Free Software Foundation; either version 2, or (at your option) any |
|
10 later version. |
|
11 |
|
12 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
15 for more details. |
|
16 |
|
17 You should have received a copy of the GNU General Public License |
|
18 along with Octave; see the file COPYING. If not, write to the Free |
|
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
20 |
|
21 */ |
|
22 |
4192
|
23 #if defined (__GNUG__) && defined (USE_PRAGMA_INTERFACE_IMPLEMENTATION) |
3912
|
24 #pragma implementation |
|
25 #endif |
|
26 |
|
27 #ifdef HAVE_CONFIG_H |
|
28 #include <config.h> |
|
29 #endif |
|
30 |
|
31 #include <cfloat> |
|
32 #include <cmath> |
|
33 |
|
34 #include "DASPK.h" |
|
35 #include "f77-fcn.h" |
|
36 #include "lo-error.h" |
4051
|
37 #include "lo-sstream.h" |
4155
|
38 #include "quit.h" |
3912
|
39 |
|
40 typedef int (*daspk_fcn_ptr) (const double&, const double*, |
|
41 const double*, const double&, |
|
42 double*, int&, double*, int*); |
|
43 |
|
44 typedef int (*daspk_jac_ptr) (const double&, const double*, |
|
45 const double*, double*, |
|
46 const double&, double*, int*); |
|
47 |
|
48 typedef int (*daspk_psol_ptr) (const int&, const double&, |
|
49 const double*, const double*, |
|
50 const double*, const double&, |
|
51 const double*, double*, int*, |
|
52 double*, const double&, int&, |
|
53 double*, int*); |
|
54 |
|
55 extern "C" |
4552
|
56 { |
|
57 F77_RET_T |
|
58 F77_FUNC (ddaspk, DDASPK) (daspk_fcn_ptr, const int&, double&, |
|
59 double*, double*, double&, const int*, |
|
60 const double*, const double*, int&, |
|
61 double*, const int&, int*, const int&, |
|
62 const double*, const int*, |
|
63 daspk_jac_ptr, daspk_psol_ptr); |
|
64 } |
3912
|
65 |
|
66 static DAEFunc::DAERHSFunc user_fun; |
|
67 static DAEFunc::DAEJacFunc user_jac; |
|
68 static int nn; |
|
69 |
4049
|
70 static int |
3912
|
71 ddaspk_f (const double& time, const double *state, const double *deriv, |
|
72 const double&, double *delta, int& ires, double *, int *) |
|
73 { |
4180
|
74 BEGIN_INTERRUPT_WITH_EXCEPTIONS; |
|
75 |
3912
|
76 ColumnVector tmp_deriv (nn); |
|
77 ColumnVector tmp_state (nn); |
|
78 ColumnVector tmp_delta (nn); |
|
79 |
|
80 for (int i = 0; i < nn; i++) |
|
81 { |
|
82 tmp_deriv.elem (i) = deriv [i]; |
|
83 tmp_state.elem (i) = state [i]; |
|
84 } |
|
85 |
|
86 tmp_delta = user_fun (tmp_state, tmp_deriv, time, ires); |
|
87 |
|
88 if (ires >= 0) |
|
89 { |
|
90 if (tmp_delta.length () == 0) |
|
91 ires = -2; |
|
92 else |
|
93 { |
|
94 for (int i = 0; i < nn; i++) |
|
95 delta [i] = tmp_delta.elem (i); |
|
96 } |
|
97 } |
|
98 |
4180
|
99 END_INTERRUPT_WITH_EXCEPTIONS; |
|
100 |
3912
|
101 return 0; |
|
102 } |
|
103 |
|
104 //NEQ, T, Y, YPRIME, SAVR, WK, CJ, WGHT, |
|
105 //C WP, IWP, B, EPLIN, IER, RPAR, IPAR) |
|
106 |
4049
|
107 static int |
3912
|
108 ddaspk_psol (const int& neq, const double& time, const double *state, |
|
109 const double *deriv, const double *savr, |
|
110 const double& cj, const double *wght, double *wp, |
|
111 int *iwp, double *b, const double& eplin, int& ier, |
|
112 double *, int*) |
|
113 { |
4180
|
114 BEGIN_INTERRUPT_WITH_EXCEPTIONS; |
|
115 |
3912
|
116 abort (); |
4180
|
117 |
|
118 END_INTERRUPT_WITH_EXCEPTIONS; |
|
119 |
3946
|
120 return 0; |
3912
|
121 } |
|
122 |
3991
|
123 |
4049
|
124 static int |
3991
|
125 ddaspk_j (const double& time, const double *state, const double *deriv, |
|
126 double *pd, const double& cj, double *, int *) |
3912
|
127 { |
4180
|
128 BEGIN_INTERRUPT_WITH_EXCEPTIONS; |
|
129 |
3991
|
130 // XXX FIXME XXX -- would be nice to avoid copying the data. |
|
131 |
3912
|
132 ColumnVector tmp_state (nn); |
|
133 ColumnVector tmp_deriv (nn); |
|
134 |
3991
|
135 for (int i = 0; i < nn; i++) |
|
136 { |
|
137 tmp_deriv.elem (i) = deriv [i]; |
|
138 tmp_state.elem (i) = state [i]; |
|
139 } |
3912
|
140 |
3991
|
141 Matrix tmp_pd = user_jac (tmp_state, tmp_deriv, time, cj); |
3912
|
142 |
|
143 for (int j = 0; j < nn; j++) |
|
144 for (int i = 0; i < nn; i++) |
3991
|
145 pd [nn * j + i] = tmp_pd.elem (i, j); |
3912
|
146 |
4180
|
147 END_INTERRUPT_WITH_EXCEPTIONS; |
|
148 |
3912
|
149 return 0; |
|
150 } |
|
151 |
|
152 ColumnVector |
|
153 DASPK::do_integrate (double tout) |
|
154 { |
4047
|
155 // XXX FIXME XXX -- should handle all this option stuff just once |
|
156 // for each new problem. |
|
157 |
3912
|
158 ColumnVector retval; |
|
159 |
4049
|
160 if (! initialized || restart || DAEFunc::reset|| DASPK_options::reset) |
3912
|
161 { |
4049
|
162 integration_error = false; |
|
163 |
|
164 initialized = true; |
|
165 |
|
166 info.resize (20); |
3912
|
167 |
4049
|
168 for (int i = 0; i < 20; i++) |
|
169 info(i) = 0; |
|
170 |
|
171 pinfo = info.fortran_vec (); |
3912
|
172 |
4049
|
173 int n = size (); |
3912
|
174 |
4049
|
175 nn = n; |
|
176 |
|
177 info(0) = 0; |
3912
|
178 |
4049
|
179 if (stop_time_set) |
|
180 { |
|
181 rwork(0) = stop_time; |
|
182 info(3) = 1; |
|
183 } |
|
184 else |
|
185 info(3) = 0; |
3912
|
186 |
4049
|
187 px = x.fortran_vec (); |
|
188 pxdot = xdot.fortran_vec (); |
|
189 |
|
190 // DAEFunc |
|
191 |
|
192 user_fun = DAEFunc::function (); |
|
193 user_jac = DAEFunc::jacobian_function (); |
3912
|
194 |
4049
|
195 if (user_fun) |
|
196 { |
|
197 int ires = 0; |
3912
|
198 |
4049
|
199 ColumnVector res = (*user_fun) (x, xdot, t, ires); |
3912
|
200 |
4049
|
201 if (res.length () != x.length ()) |
|
202 { |
|
203 (*current_liboctave_error_handler) |
|
204 ("daspk: inconsistent sizes for state and residual vectors"); |
3912
|
205 |
4049
|
206 integration_error = true; |
|
207 return retval; |
|
208 } |
|
209 } |
|
210 else |
3912
|
211 { |
|
212 (*current_liboctave_error_handler) |
4049
|
213 ("daspk: no user supplied RHS subroutine!"); |
|
214 |
|
215 integration_error = true; |
|
216 return retval; |
|
217 } |
|
218 |
|
219 info(4) = user_jac ? 1 : 0; |
|
220 |
|
221 DAEFunc::reset = false; |
|
222 |
4144
|
223 int eiq = enforce_inequality_constraints (); |
|
224 int ccic = compute_consistent_initial_condition (); |
|
225 int eavfet = exclude_algebraic_variables_from_error_test (); |
|
226 |
|
227 liw = 40 + n; |
|
228 if (eiq == 1 || eiq == 3) |
|
229 liw += n; |
|
230 if (ccic == 1 || eavfet == 1) |
|
231 liw += n; |
|
232 |
|
233 lrw = 50 + 9*n; |
|
234 if (! user_jac) |
|
235 lrw += n*n; |
|
236 if (eavfet == 1) |
|
237 lrw += n; |
|
238 |
|
239 iwork.resize (liw); |
|
240 rwork.resize (lrw); |
|
241 |
|
242 piwork = iwork.fortran_vec (); |
|
243 prwork = rwork.fortran_vec (); |
|
244 |
4049
|
245 // DASPK_options |
|
246 |
4144
|
247 abs_tol = absolute_tolerance (); |
|
248 rel_tol = relative_tolerance (); |
4049
|
249 |
|
250 int abs_tol_len = abs_tol.length (); |
|
251 int rel_tol_len = rel_tol.length (); |
|
252 |
|
253 if (abs_tol_len == 1 && rel_tol_len == 1) |
|
254 { |
|
255 info(1) = 0; |
|
256 } |
|
257 else if (abs_tol_len == n && rel_tol_len == n) |
|
258 { |
|
259 info(1) = 1; |
|
260 } |
|
261 else |
|
262 { |
|
263 (*current_liboctave_error_handler) |
|
264 ("daspk: inconsistent sizes for tolerance arrays"); |
3912
|
265 |
3995
|
266 integration_error = true; |
3912
|
267 return retval; |
|
268 } |
|
269 |
4144
|
270 pabs_tol = abs_tol.fortran_vec (); |
|
271 prel_tol = rel_tol.fortran_vec (); |
|
272 |
4049
|
273 double hmax = maximum_step_size (); |
|
274 if (hmax >= 0.0) |
|
275 { |
|
276 rwork(1) = hmax; |
|
277 info(6) = 1; |
|
278 } |
|
279 else |
|
280 info(6) = 0; |
3998
|
281 |
4049
|
282 double h0 = initial_step_size (); |
|
283 if (h0 >= 0.0) |
4047
|
284 { |
4049
|
285 rwork(2) = h0; |
|
286 info(7) = 1; |
4047
|
287 } |
|
288 else |
4049
|
289 info(7) = 0; |
|
290 |
|
291 int maxord = maximum_order (); |
|
292 if (maxord >= 0) |
4047
|
293 { |
4049
|
294 if (maxord > 0 && maxord < 6) |
|
295 { |
|
296 info(8) = 1; |
|
297 iwork(2) = maxord; |
|
298 } |
|
299 else |
|
300 { |
|
301 (*current_liboctave_error_handler) |
|
302 ("daspk: invalid value for maximum order"); |
|
303 integration_error = true; |
|
304 return retval; |
|
305 } |
|
306 } |
|
307 |
|
308 switch (eiq) |
|
309 { |
|
310 case 1: |
|
311 case 3: |
|
312 { |
|
313 Array<int> ict = inequality_constraint_types (); |
|
314 |
|
315 if (ict.length () == n) |
|
316 { |
|
317 for (int i = 0; i < n; i++) |
|
318 { |
|
319 int val = ict(i); |
|
320 if (val < -2 || val > 2) |
|
321 { |
|
322 (*current_liboctave_error_handler) |
|
323 ("daspk: invalid value for inequality constraint type"); |
|
324 integration_error = true; |
|
325 return retval; |
|
326 } |
|
327 iwork(40+i) = val; |
|
328 } |
|
329 } |
|
330 else |
|
331 { |
|
332 (*current_liboctave_error_handler) |
|
333 ("daspk: inequality constraint types size mismatch"); |
|
334 integration_error = true; |
|
335 return retval; |
|
336 } |
|
337 } |
|
338 // Fall through... |
|
339 |
4144
|
340 case 0: |
4049
|
341 case 2: |
|
342 info(9) = eiq; |
|
343 break; |
|
344 |
|
345 default: |
4047
|
346 (*current_liboctave_error_handler) |
4049
|
347 ("daspk: invalid value for enforce inequality constraints option"); |
4047
|
348 integration_error = true; |
|
349 return retval; |
|
350 } |
4049
|
351 |
|
352 if (ccic) |
|
353 { |
|
354 if (ccic == 1) |
|
355 { |
|
356 // XXX FIXME XXX -- this code is duplicated below. |
|
357 |
|
358 Array<int> av = algebraic_variables (); |
4047
|
359 |
4049
|
360 if (av.length () == n) |
|
361 { |
|
362 int lid; |
|
363 if (eiq == 0 || eiq == 2) |
|
364 lid = 40; |
|
365 else if (eiq == 1 || eiq == 3) |
|
366 lid = 40 + n; |
|
367 else |
|
368 abort (); |
4047
|
369 |
4049
|
370 for (int i = 0; i < n; i++) |
|
371 iwork(lid+i) = av(i) ? -1 : 1; |
|
372 } |
|
373 else |
|
374 { |
|
375 (*current_liboctave_error_handler) |
|
376 ("daspk: algebraic variables size mismatch"); |
|
377 integration_error = true; |
|
378 return retval; |
|
379 } |
|
380 } |
|
381 else if (ccic != 2) |
|
382 { |
|
383 (*current_liboctave_error_handler) |
|
384 ("daspk: invalid value for compute consistent initial condition option"); |
|
385 integration_error = true; |
|
386 return retval; |
|
387 } |
4047
|
388 |
4049
|
389 info(10) = ccic; |
|
390 } |
4047
|
391 |
4049
|
392 if (eavfet) |
|
393 { |
|
394 info(15) = 1; |
4047
|
395 |
4049
|
396 // XXX FIXME XXX -- this code is duplicated above. |
4047
|
397 |
|
398 Array<int> av = algebraic_variables (); |
|
399 |
|
400 if (av.length () == n) |
|
401 { |
|
402 int lid; |
|
403 if (eiq == 0 || eiq == 2) |
|
404 lid = 40; |
|
405 else if (eiq == 1 || eiq == 3) |
|
406 lid = 40 + n; |
|
407 else |
|
408 abort (); |
|
409 |
|
410 for (int i = 0; i < n; i++) |
|
411 iwork(lid+i) = av(i) ? -1 : 1; |
|
412 } |
4049
|
413 } |
|
414 |
|
415 if (use_initial_condition_heuristics ()) |
|
416 { |
|
417 Array<double> ich = initial_condition_heuristics (); |
|
418 |
|
419 if (ich.length () == 6) |
|
420 { |
|
421 iwork(31) = NINT (ich(0)); |
|
422 iwork(32) = NINT (ich(1)); |
|
423 iwork(33) = NINT (ich(2)); |
|
424 iwork(34) = NINT (ich(3)); |
|
425 |
|
426 rwork(13) = ich(4); |
|
427 rwork(14) = ich(5); |
|
428 } |
4047
|
429 else |
|
430 { |
|
431 (*current_liboctave_error_handler) |
4049
|
432 ("daspk: invalid initial condition heuristics option"); |
4047
|
433 integration_error = true; |
|
434 return retval; |
|
435 } |
4049
|
436 |
|
437 info(16) = 1; |
4047
|
438 } |
4049
|
439 |
|
440 int pici = print_initial_condition_info (); |
|
441 switch (pici) |
4047
|
442 { |
4049
|
443 case 0: |
|
444 case 1: |
|
445 case 2: |
|
446 info(17) = pici; |
|
447 break; |
|
448 |
|
449 default: |
4047
|
450 (*current_liboctave_error_handler) |
4049
|
451 ("daspk: invalid value for print initial condition info option"); |
4047
|
452 integration_error = true; |
|
453 return retval; |
4049
|
454 break; |
4047
|
455 } |
|
456 |
4049
|
457 DASPK_options::reset = false; |
4047
|
458 |
4049
|
459 restart = false; |
4047
|
460 } |
|
461 |
4049
|
462 static double *dummy = 0; |
|
463 static int *idummy = 0; |
4047
|
464 |
4049
|
465 F77_XFCN (ddaspk, DDASPK, (ddaspk_f, nn, t, px, pxdot, tout, pinfo, |
3998
|
466 prel_tol, pabs_tol, istate, prwork, lrw, |
3912
|
467 piwork, liw, dummy, idummy, ddaspk_j, |
|
468 ddaspk_psol)); |
|
469 |
|
470 if (f77_exception_encountered) |
|
471 { |
3995
|
472 integration_error = true; |
3912
|
473 (*current_liboctave_error_handler) ("unrecoverable error in daspk"); |
|
474 } |
|
475 else |
|
476 { |
3997
|
477 switch (istate) |
3912
|
478 { |
|
479 case 1: // A step was successfully taken in intermediate-output |
|
480 // mode. The code has not yet reached TOUT. |
|
481 case 2: // The integration to TSTOP was successfully completed |
|
482 // (T=TSTOP) by stepping exactly to TSTOP. |
|
483 case 3: // The integration to TOUT was successfully completed |
|
484 // (T=TOUT) by stepping past TOUT. Y(*) is obtained by |
|
485 // interpolation. YPRIME(*) is obtained by interpolation. |
3996
|
486 case 4: // The initial condition calculation, with |
|
487 // INFO(11) > 0, was successful, and INFO(14) = 1. |
|
488 // No integration steps were taken, and the solution |
|
489 // is not considered to have been started. |
3912
|
490 retval = x; |
|
491 t = tout; |
|
492 break; |
|
493 |
|
494 case -1: // A large amount of work has been expended. (~500 steps). |
|
495 case -2: // The error tolerances are too stringent. |
|
496 case -3: // The local error test cannot be satisfied because you |
|
497 // specified a zero component in ATOL and the |
|
498 // corresponding computed solution component is zero. |
|
499 // Thus, a pure relative error test is impossible for |
|
500 // this component. |
|
501 case -6: // DDASPK had repeated error test failures on the last |
|
502 // attempted step. |
|
503 case -7: // The corrector could not converge. |
|
504 case -8: // The matrix of partial derivatives is singular. |
|
505 case -9: // The corrector could not converge. There were repeated |
|
506 // error test failures in this step. |
|
507 case -10: // The corrector could not converge because IRES was |
|
508 // equal to minus one. |
|
509 case -11: // IRES equal to -2 was encountered and control is being |
|
510 // returned to the calling program. |
|
511 case -12: // DDASPK failed to compute the initial YPRIME. |
3996
|
512 case -13: // Unrecoverable error encountered inside user's |
|
513 // PSOL routine, and control is being returned to |
|
514 // the calling program. |
|
515 case -14: // The Krylov linear system solver could not |
|
516 // achieve convergence. |
3912
|
517 case -33: // The code has encountered trouble from which it cannot |
|
518 // recover. A message is printed explaining the trouble |
|
519 // and control is returned to the calling program. For |
|
520 // example, this occurs when invalid input is detected. |
3996
|
521 integration_error = true; |
|
522 break; |
|
523 |
3912
|
524 default: |
3995
|
525 integration_error = true; |
3996
|
526 (*current_liboctave_error_handler) |
3997
|
527 ("unrecognized value of istate (= %d) returned from ddaspk", |
|
528 istate); |
3912
|
529 break; |
|
530 } |
|
531 } |
|
532 |
|
533 return retval; |
|
534 } |
|
535 |
|
536 Matrix |
|
537 DASPK::do_integrate (const ColumnVector& tout) |
|
538 { |
|
539 Matrix dummy; |
|
540 return integrate (tout, dummy); |
|
541 } |
|
542 |
|
543 Matrix |
|
544 DASPK::integrate (const ColumnVector& tout, Matrix& xdot_out) |
|
545 { |
|
546 Matrix retval; |
4049
|
547 |
3912
|
548 int n_out = tout.capacity (); |
4049
|
549 int n = size (); |
3912
|
550 |
|
551 if (n_out > 0 && n > 0) |
|
552 { |
|
553 retval.resize (n_out, n); |
|
554 xdot_out.resize (n_out, n); |
|
555 |
|
556 for (int i = 0; i < n; i++) |
|
557 { |
|
558 retval.elem (0, i) = x.elem (i); |
|
559 xdot_out.elem (0, i) = xdot.elem (i); |
|
560 } |
|
561 |
|
562 for (int j = 1; j < n_out; j++) |
|
563 { |
|
564 ColumnVector x_next = do_integrate (tout.elem (j)); |
|
565 |
|
566 if (integration_error) |
|
567 return retval; |
|
568 |
|
569 for (int i = 0; i < n; i++) |
|
570 { |
|
571 retval.elem (j, i) = x_next.elem (i); |
|
572 xdot_out.elem (j, i) = xdot.elem (i); |
|
573 } |
|
574 } |
|
575 } |
|
576 |
|
577 return retval; |
|
578 } |
|
579 |
|
580 Matrix |
|
581 DASPK::do_integrate (const ColumnVector& tout, const ColumnVector& tcrit) |
|
582 { |
|
583 Matrix dummy; |
|
584 return integrate (tout, dummy, tcrit); |
|
585 } |
|
586 |
|
587 Matrix |
|
588 DASPK::integrate (const ColumnVector& tout, Matrix& xdot_out, |
|
589 const ColumnVector& tcrit) |
|
590 { |
|
591 Matrix retval; |
4049
|
592 |
3912
|
593 int n_out = tout.capacity (); |
4049
|
594 int n = size (); |
3912
|
595 |
|
596 if (n_out > 0 && n > 0) |
|
597 { |
|
598 retval.resize (n_out, n); |
|
599 xdot_out.resize (n_out, n); |
|
600 |
|
601 for (int i = 0; i < n; i++) |
|
602 { |
|
603 retval.elem (0, i) = x.elem (i); |
|
604 xdot_out.elem (0, i) = xdot.elem (i); |
|
605 } |
|
606 |
|
607 int n_crit = tcrit.capacity (); |
|
608 |
|
609 if (n_crit > 0) |
|
610 { |
|
611 int i_crit = 0; |
|
612 int i_out = 1; |
|
613 double next_crit = tcrit.elem (0); |
|
614 double next_out; |
|
615 while (i_out < n_out) |
|
616 { |
|
617 bool do_restart = false; |
|
618 |
|
619 next_out = tout.elem (i_out); |
|
620 if (i_crit < n_crit) |
|
621 next_crit = tcrit.elem (i_crit); |
|
622 |
|
623 bool save_output; |
|
624 double t_out; |
|
625 |
|
626 if (next_crit == next_out) |
|
627 { |
|
628 set_stop_time (next_crit); |
|
629 t_out = next_out; |
|
630 save_output = true; |
|
631 i_out++; |
|
632 i_crit++; |
|
633 do_restart = true; |
|
634 } |
|
635 else if (next_crit < next_out) |
|
636 { |
|
637 if (i_crit < n_crit) |
|
638 { |
|
639 set_stop_time (next_crit); |
|
640 t_out = next_crit; |
|
641 save_output = false; |
|
642 i_crit++; |
|
643 do_restart = true; |
|
644 } |
|
645 else |
|
646 { |
|
647 clear_stop_time (); |
|
648 t_out = next_out; |
|
649 save_output = true; |
|
650 i_out++; |
|
651 } |
|
652 } |
|
653 else |
|
654 { |
|
655 set_stop_time (next_crit); |
|
656 t_out = next_out; |
|
657 save_output = true; |
|
658 i_out++; |
|
659 } |
|
660 |
|
661 ColumnVector x_next = do_integrate (t_out); |
|
662 |
|
663 if (integration_error) |
|
664 return retval; |
|
665 |
|
666 if (save_output) |
|
667 { |
|
668 for (int i = 0; i < n; i++) |
|
669 { |
|
670 retval.elem (i_out-1, i) = x_next.elem (i); |
|
671 xdot_out.elem (i_out-1, i) = xdot.elem (i); |
|
672 } |
|
673 } |
|
674 |
|
675 if (do_restart) |
|
676 force_restart (); |
|
677 } |
|
678 } |
|
679 else |
|
680 { |
|
681 retval = integrate (tout, xdot_out); |
|
682 |
|
683 if (integration_error) |
|
684 return retval; |
|
685 } |
|
686 } |
|
687 |
|
688 return retval; |
|
689 } |
|
690 |
3995
|
691 std::string |
|
692 DASPK::error_message (void) const |
|
693 { |
|
694 std::string retval; |
|
695 |
4051
|
696 OSSTREAM buf; |
|
697 buf << t << OSSTREAM_ENDS; |
|
698 std::string t_curr = OSSTREAM_STR (buf); |
|
699 OSSTREAM_FREEZE (buf); |
4043
|
700 |
3997
|
701 switch (istate) |
3995
|
702 { |
3996
|
703 case 1: |
|
704 retval = "a step was successfully taken in intermediate-output mode."; |
|
705 break; |
|
706 |
|
707 case 2: |
|
708 retval = "integration completed by stepping exactly to TOUT"; |
|
709 break; |
|
710 |
|
711 case 3: |
|
712 retval = "integration to tout completed by stepping past TOUT"; |
|
713 break; |
|
714 |
|
715 case 4: |
|
716 retval = "initial condition calculation completed successfully"; |
|
717 break; |
|
718 |
|
719 case -1: |
4043
|
720 retval = std::string ("a large amount of work has been expended (t =") |
|
721 + t_curr + ")"; |
3996
|
722 break; |
|
723 |
|
724 case -2: |
|
725 retval = "the error tolerances are too stringent"; |
|
726 break; |
|
727 |
|
728 case -3: |
4043
|
729 retval = std::string ("error weight became zero during problem. (t = ") |
|
730 + t_curr |
|
731 + "; solution component i vanished, and atol or atol(i) == 0)"; |
3996
|
732 break; |
|
733 |
|
734 case -6: |
4043
|
735 retval = std::string ("repeated error test failures on the last attempted step (t = ") |
|
736 + t_curr + ")"; |
3996
|
737 break; |
|
738 |
|
739 case -7: |
4043
|
740 retval = std::string ("the corrector could not converge (t = ") |
|
741 + t_curr + ")"; |
3996
|
742 break; |
|
743 |
|
744 case -8: |
4043
|
745 retval = std::string ("the matrix of partial derivatives is singular (t = ") |
|
746 + t_curr + ")"; |
3996
|
747 break; |
|
748 |
|
749 case -9: |
4043
|
750 retval = std::string ("the corrector could not converge (t = ") |
|
751 + t_curr + "; repeated test failures)"; |
3996
|
752 break; |
|
753 |
|
754 case -10: |
4043
|
755 retval = std::string ("corrector could not converge because IRES was -1 (t = ") |
|
756 + t_curr + ")"; |
3996
|
757 break; |
|
758 |
|
759 case -11: |
4043
|
760 retval = std::string ("return requested in user-supplied function (t = ") |
|
761 + t_curr + ")"; |
3996
|
762 break; |
|
763 |
|
764 case -12: |
|
765 retval = "failed to compute consistent initial conditions"; |
|
766 break; |
|
767 |
|
768 case -13: |
4043
|
769 retval = std::string ("unrecoverable error encountered inside user's PSOL function (t = ") |
|
770 + t_curr + ")"; |
3996
|
771 break; |
|
772 |
|
773 case -14: |
4043
|
774 retval = std::string ("the Krylov linear system solver failed to converge (t = ") |
|
775 + t_curr + ")"; |
3996
|
776 break; |
|
777 |
|
778 case -33: |
|
779 retval = "unrecoverable error (see printed message)"; |
|
780 break; |
|
781 |
3995
|
782 default: |
|
783 retval = "unknown error state"; |
|
784 break; |
|
785 } |
|
786 |
|
787 return retval; |
|
788 } |
|
789 |
3912
|
790 /* |
|
791 ;;; Local Variables: *** |
|
792 ;;; mode: C++ *** |
|
793 ;;; End: *** |
|
794 */ |