Mercurial > octave
annotate liboctave/numeric/LSODE.cc @ 22133:59cadee1c74b
new macros for F77 data types
* f77-fcn.h (F77_DBLE, F77_REAL, F77_DBLE_CMPLX, F77_CMPLX, F77_INT,
F77_INT4, F77_LOGICAL): New macros.
* fortrandemo.cc, __pchip_deriv__.cc, dot.cc, interpreter.cc,
ordschur.cc, qz.cc, CColVector.cc, CMatrix.cc, CNDArray.cc,
CRowVector.cc, CSparse.cc, dColVector.cc, dMatrix.cc, dNDArray.cc,
dRowVector.cc, dSparse.cc, fCColVector.cc, fCMatrix.cc,
fCNDArray.cc, fCRowVector.cc, fColVector.cc, fMatrix.cc,
fNDArray.cc, fRowVector.cc, DASPK.cc, DASRT.cc, DASSL.cc, EIG.cc,
LSODE.cc, Quad.cc, aepbalance.cc, chol.cc, eigs-base.cc, fEIG.cc,
gepbalance.cc, hess.cc, lo-specfun.cc, lu.cc, oct-convn.cc,
oct-rand.cc, qr.cc, qrp.cc, randpoisson.cc, schur.cc, svd.cc:
Use new macros in declarations of Fortran subroutines.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Sun, 17 Jul 2016 12:42:37 -0400 |
parents | aba2e6293dd8 |
children | bac0d6f07a3e |
rev | line source |
---|---|
3 | 1 /* |
2 | |
19697
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
17769
diff
changeset
|
3 Copyright (C) 1993-2015 John W. Eaton |
3 | 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 | |
7016 | 9 Free Software Foundation; either version 3 of the License, or (at your |
10 option) any later version. | |
3 | 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 | |
7016 | 18 along with Octave; see the file COPYING. If not, see |
19 <http://www.gnu.org/licenses/>. | |
3 | 20 |
21 */ | |
22 | |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
23 #if defined (HAVE_CONFIG_H) |
21301
40de9f8f23a6
Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents:
21202
diff
changeset
|
24 # include "config.h" |
3 | 25 #endif |
26 | |
1367 | 27 #include <cfloat> |
28 | |
5765 | 29 #include <sstream> |
30 | |
1842 | 31 #include "LSODE.h" |
1847 | 32 #include "f77-fcn.h" |
227 | 33 #include "lo-error.h" |
7231 | 34 #include "lo-math.h" |
4180 | 35 #include "quit.h" |
3 | 36 |
11495 | 37 typedef octave_idx_type (*lsode_fcn_ptr) (const octave_idx_type&, |
38 const double&, double*, | |
39 double*, octave_idx_type&); | |
3507 | 40 |
11495 | 41 typedef octave_idx_type (*lsode_jac_ptr) (const octave_idx_type&, |
42 const double&, double*, | |
43 const octave_idx_type&, | |
44 const octave_idx_type&, | |
45 double*, const octave_idx_type&); | |
3507 | 46 |
3 | 47 extern "C" |
4552 | 48 { |
49 F77_RET_T | |
22133
59cadee1c74b
new macros for F77 data types
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
50 F77_FUNC (dlsode, DLSODE) (lsode_fcn_ptr, F77_INT&, F77_DBLE*, |
59cadee1c74b
new macros for F77 data types
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
51 F77_DBLE&, F77_DBLE&, F77_INT&, F77_DBLE&, |
59cadee1c74b
new macros for F77 data types
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
52 const F77_DBLE*, F77_INT&, |
59cadee1c74b
new macros for F77 data types
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
53 F77_INT&, F77_INT&, |
59cadee1c74b
new macros for F77 data types
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
54 F77_DBLE*, F77_INT&, F77_INT*, |
59cadee1c74b
new macros for F77 data types
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
55 F77_INT&, lsode_jac_ptr, |
59cadee1c74b
new macros for F77 data types
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
56 F77_INT&); |
4552 | 57 } |
3 | 58 |
532 | 59 static ODEFunc::ODERHSFunc user_fun; |
60 static ODEFunc::ODEJacFunc user_jac; | |
3 | 61 static ColumnVector *tmp_x; |
62 | |
5275 | 63 static octave_idx_type |
64 lsode_f (const octave_idx_type& neq, const double& time, double *, | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
65 double *deriv, octave_idx_type& ierr) |
3 | 66 { |
4180 | 67 BEGIN_INTERRUPT_WITH_EXCEPTIONS; |
68 | |
2343 | 69 ColumnVector tmp_deriv; |
3 | 70 |
1360 | 71 // NOTE: this won't work if LSODE passes copies of the state vector. |
72 // In that case we have to create a temporary vector object | |
73 // and copy. | |
74 | |
1251 | 75 tmp_deriv = (*user_fun) (*tmp_x, time); |
3 | 76 |
20974
1edf15793cac
maint: Use is_empty rather than "numel () == 0" for clarity.
Rik <rik@octave.org>
parents:
20232
diff
changeset
|
77 if (tmp_deriv.is_empty ()) |
1251 | 78 ierr = -1; |
258 | 79 else |
80 { | |
5275 | 81 for (octave_idx_type i = 0; i < neq; i++) |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14138
diff
changeset
|
82 deriv[i] = tmp_deriv.elem (i); |
258 | 83 } |
3 | 84 |
4180 | 85 END_INTERRUPT_WITH_EXCEPTIONS; |
86 | |
3 | 87 return 0; |
88 } | |
89 | |
5275 | 90 static octave_idx_type |
91 lsode_j (const octave_idx_type& neq, const double& time, double *, | |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
92 const octave_idx_type&, const octave_idx_type&, double *pd, |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
93 const octave_idx_type& nrowpd) |
3 | 94 { |
4180 | 95 BEGIN_INTERRUPT_WITH_EXCEPTIONS; |
96 | |
1251 | 97 Matrix tmp_jac (neq, neq); |
3 | 98 |
1360 | 99 // NOTE: this won't work if LSODE passes copies of the state vector. |
100 // In that case we have to create a temporary vector object | |
101 // and copy. | |
102 | |
1251 | 103 tmp_jac = (*user_jac) (*tmp_x, time); |
3 | 104 |
5275 | 105 for (octave_idx_type j = 0; j < neq; j++) |
106 for (octave_idx_type i = 0; i < neq; i++) | |
15020
560317fd5977
maint: Cuddle open bracket used for indexing C++ arrays in source code.
Rik <rik@octave.org>
parents:
15018
diff
changeset
|
107 pd[nrowpd * j + i] = tmp_jac (i, j); |
3 | 108 |
4180 | 109 END_INTERRUPT_WITH_EXCEPTIONS; |
110 | |
3 | 111 return 0; |
112 } | |
113 | |
114 ColumnVector | |
1842 | 115 LSODE::do_integrate (double tout) |
3 | 116 { |
1945 | 117 ColumnVector retval; |
118 | |
5275 | 119 static octave_idx_type nn = 0; |
4049 | 120 |
121 if (! initialized || restart || ODEFunc::reset || LSODE_options::reset) | |
1945 | 122 { |
4049 | 123 integration_error = false; |
1945 | 124 |
4049 | 125 initialized = true; |
126 | |
127 istate = 1; | |
128 | |
5275 | 129 octave_idx_type n = size (); |
4049 | 130 |
131 nn = n; | |
3955 | 132 |
5275 | 133 octave_idx_type max_maxord = 0; |
4231 | 134 |
4049 | 135 if (integration_method () == "stiff") |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
136 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
137 max_maxord = 5; |
4231 | 138 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
139 if (jac) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
140 method_flag = 21; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
141 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
142 method_flag = 22; |
3955 | 143 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
144 liw = 20 + n; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
145 lrw = 22 + n * (9 + n); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
146 } |
4049 | 147 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
148 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
149 max_maxord = 12; |
4231 | 150 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
151 method_flag = 10; |
3955 | 152 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
153 liw = 20; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
154 lrw = 22 + 16 * n; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
155 } |
4049 | 156 |
4231 | 157 maxord = maximum_order (); |
158 | |
11574
a83bad07f7e3
attempt better backward compatibility for Array resize functions
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
159 iwork.resize (dim_vector (liw, 1)); |
5552 | 160 |
161 for (octave_idx_type i = 4; i < 9; i++) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
162 iwork(i) = 0; |
5552 | 163 |
11574
a83bad07f7e3
attempt better backward compatibility for Array resize functions
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
164 rwork.resize (dim_vector (lrw, 1)); |
5552 | 165 |
166 for (octave_idx_type i = 4; i < 9; i++) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
167 rwork(i) = 0; |
5552 | 168 |
4231 | 169 if (maxord >= 0) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
170 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
171 if (maxord > 0 && maxord <= max_maxord) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
172 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
173 iwork(4) = maxord; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
174 iopt = 1; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
175 } |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
176 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
177 { |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
20974
diff
changeset
|
178 // FIXME: Should this be a warning? |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
179 (*current_liboctave_error_handler) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
180 ("lsode: invalid value for maximum order"); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
181 integration_error = true; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
182 return retval; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
183 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
184 } |
4231 | 185 |
4049 | 186 if (stop_time_set) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
187 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
188 itask = 4; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
189 rwork(0) = stop_time; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
190 iopt = 1; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
191 } |
4049 | 192 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
193 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
194 itask = 1; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
195 } |
258 | 196 |
4049 | 197 restart = false; |
198 | |
199 // ODEFunc | |
3 | 200 |
4049 | 201 // NOTE: this won't work if LSODE passes copies of the state vector. |
202 // In that case we have to create a temporary vector object | |
203 // and copy. | |
3 | 204 |
4049 | 205 tmp_x = &x; |
206 | |
207 user_fun = function (); | |
208 user_jac = jacobian_function (); | |
209 | |
2343 | 210 ColumnVector xdot = (*user_fun) (x, t); |
211 | |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20229
diff
changeset
|
212 if (x.numel () != xdot.numel ()) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
213 { |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
20974
diff
changeset
|
214 // FIXME: Should this be a warning? |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
215 (*current_liboctave_error_handler) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
216 ("lsode: inconsistent sizes for state and derivative vectors"); |
2343 | 217 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
218 integration_error = true; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
219 return retval; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
220 } |
2343 | 221 |
4049 | 222 ODEFunc::reset = false; |
223 | |
224 // LSODE_options | |
225 | |
226 rel_tol = relative_tolerance (); | |
227 abs_tol = absolute_tolerance (); | |
228 | |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20229
diff
changeset
|
229 octave_idx_type abs_tol_len = abs_tol.numel (); |
4049 | 230 |
231 if (abs_tol_len == 1) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
232 itol = 1; |
4049 | 233 else if (abs_tol_len == n) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
234 itol = 2; |
4049 | 235 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
236 { |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
20974
diff
changeset
|
237 // FIXME: Should this be a warning? |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
238 (*current_liboctave_error_handler) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
239 ("lsode: inconsistent sizes for state and absolute tolerance vectors"); |
4049 | 240 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
241 integration_error = true; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
242 return retval; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
243 } |
2343 | 244 |
4049 | 245 double iss = initial_step_size (); |
246 if (iss >= 0.0) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
247 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
248 rwork(4) = iss; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
249 iopt = 1; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
250 } |
4049 | 251 |
252 double maxss = maximum_step_size (); | |
253 if (maxss >= 0.0) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
254 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
255 rwork(5) = maxss; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
256 iopt = 1; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
257 } |
4049 | 258 |
259 double minss = minimum_step_size (); | |
260 if (minss >= 0.0) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
261 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
262 rwork(6) = minss; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
263 iopt = 1; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
264 } |
4049 | 265 |
5275 | 266 octave_idx_type sl = step_limit (); |
4049 | 267 if (sl > 0) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
268 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
269 iwork(5) = sl; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
270 iopt = 1; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
271 } |
4049 | 272 |
273 LSODE_options::reset = false; | |
3 | 274 } |
275 | |
11502
4638800cd660
delete data pointer members from liboctave ODE/DAE classes; make destuctors virtual in ODE/DAE base classes
John W. Eaton <jwe@octave.org>
parents:
11495
diff
changeset
|
276 double *px = x.fortran_vec (); |
4638800cd660
delete data pointer members from liboctave ODE/DAE classes; make destuctors virtual in ODE/DAE base classes
John W. Eaton <jwe@octave.org>
parents:
11495
diff
changeset
|
277 |
4638800cd660
delete data pointer members from liboctave ODE/DAE classes; make destuctors virtual in ODE/DAE base classes
John W. Eaton <jwe@octave.org>
parents:
11495
diff
changeset
|
278 double *pabs_tol = abs_tol.fortran_vec (); |
4638800cd660
delete data pointer members from liboctave ODE/DAE classes; make destuctors virtual in ODE/DAE base classes
John W. Eaton <jwe@octave.org>
parents:
11495
diff
changeset
|
279 |
4638800cd660
delete data pointer members from liboctave ODE/DAE classes; make destuctors virtual in ODE/DAE base classes
John W. Eaton <jwe@octave.org>
parents:
11495
diff
changeset
|
280 octave_idx_type *piwork = iwork.fortran_vec (); |
4638800cd660
delete data pointer members from liboctave ODE/DAE classes; make destuctors virtual in ODE/DAE base classes
John W. Eaton <jwe@octave.org>
parents:
11495
diff
changeset
|
281 double *prwork = rwork.fortran_vec (); |
4638800cd660
delete data pointer members from liboctave ODE/DAE classes; make destuctors virtual in ODE/DAE base classes
John W. Eaton <jwe@octave.org>
parents:
11495
diff
changeset
|
282 |
4583 | 283 F77_XFCN (dlsode, DLSODE, (lsode_f, nn, px, t, tout, itol, rel_tol, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
284 pabs_tol, itask, istate, iopt, prwork, lrw, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
285 piwork, liw, lsode_j, method_flag)); |
3 | 286 |
7482
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7231
diff
changeset
|
287 switch (istate) |
3 | 288 { |
7482
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7231
diff
changeset
|
289 case 1: // prior to initial integration step. |
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7231
diff
changeset
|
290 case 2: // lsode was successful. |
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7231
diff
changeset
|
291 retval = x; |
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7231
diff
changeset
|
292 t = tout; |
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7231
diff
changeset
|
293 break; |
3996 | 294 |
7482
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7231
diff
changeset
|
295 case -1: // excess work done on this call (perhaps wrong mf). |
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7231
diff
changeset
|
296 case -2: // excess accuracy requested (tolerances too small). |
8807
401d54a83690
use 'invalid', not 'illegal'
John W. Eaton <jwe@octave.org>
parents:
7482
diff
changeset
|
297 case -3: // invalid input detected (see printed message). |
7482
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7231
diff
changeset
|
298 case -4: // repeated error test failures (check all inputs). |
12600
7c000c70f873
LSODE.cc: Add semicolon to error messages to prevent run-together text.
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
299 case -5: // repeated convergence failures (perhaps bad Jacobian |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
300 // supplied or wrong choice of mf or tolerances). |
7482
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7231
diff
changeset
|
301 case -6: // error weight became zero during problem. (solution |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
302 // component i vanished, and atol or atol(i) = 0.) |
7482
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7231
diff
changeset
|
303 case -13: // return requested in user-supplied function. |
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7231
diff
changeset
|
304 integration_error = true; |
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7231
diff
changeset
|
305 break; |
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7231
diff
changeset
|
306 |
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7231
diff
changeset
|
307 default: |
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7231
diff
changeset
|
308 integration_error = true; |
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7231
diff
changeset
|
309 (*current_liboctave_error_handler) |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
20974
diff
changeset
|
310 ("unrecognized value of istate (= %d) returned from lsode", istate); |
7482
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7231
diff
changeset
|
311 break; |
3 | 312 } |
313 | |
1945 | 314 return retval; |
3 | 315 } |
316 | |
3959 | 317 std::string |
318 LSODE::error_message (void) const | |
319 { | |
320 std::string retval; | |
321 | |
5765 | 322 std::ostringstream buf; |
323 buf << t; | |
324 std::string t_curr = buf.str (); | |
4042 | 325 |
3959 | 326 switch (istate) |
327 { | |
328 case 1: | |
3996 | 329 retval = "prior to initial integration step"; |
3959 | 330 break; |
331 | |
332 case 2: | |
333 retval = "successful exit"; | |
334 break; | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
335 |
3959 | 336 case 3: |
337 retval = "prior to continuation call with modified parameters"; | |
338 break; | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
339 |
3996 | 340 case -1: |
4042 | 341 retval = std::string ("excess work on this call (t = ") |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
342 + t_curr + "; perhaps wrong integration method)"; |
3996 | 343 break; |
344 | |
345 case -2: | |
346 retval = "excess accuracy requested (tolerances too small)"; | |
347 break; | |
348 | |
349 case -3: | |
350 retval = "invalid input detected (see printed message)"; | |
351 break; | |
352 | |
353 case -4: | |
4042 | 354 retval = std::string ("repeated error test failures (t = ") |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
355 + t_curr + "; check all inputs)"; |
3996 | 356 break; |
357 | |
358 case -5: | |
4042 | 359 retval = std::string ("repeated convergence failures (t = ") |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
360 + t_curr |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
361 + "; perhaps bad Jacobian supplied or wrong choice of integration method or tolerances)"; |
3996 | 362 break; |
363 | |
364 case -6: | |
4042 | 365 retval = std::string ("error weight became zero during problem. (t = ") |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
366 + t_curr |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
367 + "; solution component i vanished, and atol or atol(i) == 0)"; |
3996 | 368 break; |
369 | |
370 case -13: | |
4042 | 371 retval = "return requested in user-supplied function (t = " |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
372 + t_curr + ")"; |
3996 | 373 break; |
374 | |
3959 | 375 default: |
376 retval = "unknown error state"; | |
377 break; | |
378 } | |
379 | |
380 return retval; | |
381 } | |
382 | |
3 | 383 Matrix |
1842 | 384 LSODE::do_integrate (const ColumnVector& tout) |
3 | 385 { |
386 Matrix retval; | |
4049 | 387 |
20229
5dfaaaae784f
Deprecate Array::capacity() and Sparse::capacity() for numel() and nzmax().
Carnë Draug <carandraug@octave.org>
parents:
19697
diff
changeset
|
388 octave_idx_type n_out = tout.numel (); |
5275 | 389 octave_idx_type n = size (); |
3 | 390 |
391 if (n_out > 0 && n > 0) | |
392 { | |
393 retval.resize (n_out, n); | |
394 | |
5275 | 395 for (octave_idx_type i = 0; i < n; i++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
396 retval.elem (0, i) = x.elem (i); |
3 | 397 |
5275 | 398 for (octave_idx_type j = 1; j < n_out; j++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
399 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
400 ColumnVector x_next = do_integrate (tout.elem (j)); |
258 | 401 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
402 if (integration_error) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
403 return retval; |
258 | 404 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
405 for (octave_idx_type i = 0; i < n; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
406 retval.elem (j, i) = x_next.elem (i); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
407 } |
3 | 408 } |
409 | |
410 return retval; | |
411 } | |
412 | |
413 Matrix | |
3511 | 414 LSODE::do_integrate (const ColumnVector& tout, const ColumnVector& tcrit) |
3 | 415 { |
416 Matrix retval; | |
4049 | 417 |
20229
5dfaaaae784f
Deprecate Array::capacity() and Sparse::capacity() for numel() and nzmax().
Carnë Draug <carandraug@octave.org>
parents:
19697
diff
changeset
|
418 octave_idx_type n_out = tout.numel (); |
5275 | 419 octave_idx_type n = size (); |
3 | 420 |
421 if (n_out > 0 && n > 0) | |
422 { | |
423 retval.resize (n_out, n); | |
424 | |
5275 | 425 for (octave_idx_type i = 0; i < n; i++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
426 retval.elem (0, i) = x.elem (i); |
3 | 427 |
20229
5dfaaaae784f
Deprecate Array::capacity() and Sparse::capacity() for numel() and nzmax().
Carnë Draug <carandraug@octave.org>
parents:
19697
diff
changeset
|
428 octave_idx_type n_crit = tcrit.numel (); |
3 | 429 |
430 if (n_crit > 0) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
431 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
432 octave_idx_type i_crit = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
433 octave_idx_type i_out = 1; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
434 double next_crit = tcrit.elem (0); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
435 double next_out; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
436 while (i_out < n_out) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
437 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
438 bool do_restart = false; |
3 | 439 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
440 next_out = tout.elem (i_out); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
441 if (i_crit < n_crit) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
442 next_crit = tcrit.elem (i_crit); |
3 | 443 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
444 octave_idx_type save_output; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
445 double t_out; |
3 | 446 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
447 if (next_crit == next_out) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
448 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
449 set_stop_time (next_crit); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
450 t_out = next_out; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
451 save_output = 1; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
452 i_out++; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
453 i_crit++; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
454 do_restart = true; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
455 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
456 else if (next_crit < next_out) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
457 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
458 if (i_crit < n_crit) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
459 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
460 set_stop_time (next_crit); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
461 t_out = next_crit; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
462 save_output = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
463 i_crit++; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
464 do_restart = true; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
465 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
466 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
467 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
468 clear_stop_time (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
469 t_out = next_out; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
470 save_output = 1; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
471 i_out++; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
472 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
473 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
474 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
475 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
476 set_stop_time (next_crit); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
477 t_out = next_out; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
478 save_output = 1; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
479 i_out++; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
480 } |
3 | 481 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
482 ColumnVector x_next = do_integrate (t_out); |
3 | 483 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
484 if (integration_error) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
485 return retval; |
258 | 486 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
487 if (save_output) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
488 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
489 for (octave_idx_type i = 0; i < n; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
490 retval.elem (i_out-1, i) = x_next.elem (i); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
491 } |
3 | 492 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
493 if (do_restart) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
494 force_restart (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
495 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
496 } |
3 | 497 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
498 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
499 retval = do_integrate (tout); |
258 | 500 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
501 if (integration_error) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
502 return retval; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
503 } |
3 | 504 } |
505 | |
506 return retval; | |
507 } |