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