Mercurial > octave
annotate liboctave/numeric/DASSL.cc @ 29358:0a5b15007766 stable
update Octave Project Developers copyright for the new year
In files that have the "Octave Project Developers" copyright notice,
update for 2021.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 10 Feb 2021 09:52:15 -0500 |
parents | bd51beb6205e |
children | a6ab7069a87c |
rev | line source |
---|---|
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
1 //////////////////////////////////////////////////////////////////////// |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
2 // |
29358
0a5b15007766
update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
3 // Copyright (C) 1993-2021 The Octave Project Developers |
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
4 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
5 // See the file COPYRIGHT.md in the top-level directory of this |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
6 // distribution or <https://octave.org/copyright/>. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
7 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
8 // This file is part of Octave. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
9 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
10 // Octave is free software: you can redistribute it and/or modify it |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
11 // under the terms of the GNU General Public License as published by |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
12 // the Free Software Foundation, either version 3 of the License, or |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
13 // (at your option) any later version. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
14 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
15 // Octave is distributed in the hope that it will be useful, but |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
16 // WITHOUT ANY WARRANTY; without even the implied warranty of |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
18 // GNU General Public License for more details. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
19 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
20 // You should have received a copy of the GNU General Public License |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
21 // along with Octave; see the file COPYING. If not, see |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
22 // <https://www.gnu.org/licenses/>. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
23 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
24 //////////////////////////////////////////////////////////////////////// |
3 | 25 |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21662
diff
changeset
|
26 #if defined (HAVE_CONFIG_H) |
21301
40de9f8f23a6
Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents:
21202
diff
changeset
|
27 # include "config.h" |
3 | 28 #endif |
29 | |
26569
0e77df67b522
Add static compile-time checking of printf functions in liboctave.
Markus Mützel <markus.muetzel@gmx.de>
parents:
26376
diff
changeset
|
30 #include <cinttypes> |
5765 | 31 #include <sstream> |
32 | |
1842 | 33 #include "DASSL.h" |
23475
d691ed308237
maint: Clean up #includes in liboctave/numeric directory.
Rik <rik@octave.org>
parents:
23457
diff
changeset
|
34 #include "dMatrix.h" |
1847 | 35 #include "f77-fcn.h" |
227 | 36 #include "lo-error.h" |
4180 | 37 #include "quit.h" |
3 | 38 |
22960
0d1422cb7e93
use F77_INT instead of octave_idx_type for liboctave ODE and DAE classes
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
39 typedef F77_INT (*dassl_fcn_ptr) (const double&, const double*, |
0d1422cb7e93
use F77_INT instead of octave_idx_type for liboctave ODE and DAE classes
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
40 const double*, double*, F77_INT&, |
0d1422cb7e93
use F77_INT instead of octave_idx_type for liboctave ODE and DAE classes
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
41 double*, F77_INT*); |
3507 | 42 |
22960
0d1422cb7e93
use F77_INT instead of octave_idx_type for liboctave ODE and DAE classes
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
43 typedef F77_INT (*dassl_jac_ptr) (const double&, const double*, |
0d1422cb7e93
use F77_INT instead of octave_idx_type for liboctave ODE and DAE classes
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
44 const double*, double*, const double&, |
0d1422cb7e93
use F77_INT instead of octave_idx_type for liboctave ODE and DAE classes
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
45 double*, F77_INT*); |
3507 | 46 |
3 | 47 extern "C" |
4552 | 48 { |
49 F77_RET_T | |
22960
0d1422cb7e93
use F77_INT instead of octave_idx_type for liboctave ODE and DAE classes
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
50 F77_FUNC (ddassl, DDASSL) (dassl_fcn_ptr, const F77_INT&, F77_DBLE&, |
0d1422cb7e93
use F77_INT instead of octave_idx_type for liboctave ODE and DAE classes
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
51 F77_DBLE*, F77_DBLE*, F77_DBLE&, const F77_INT*, |
0d1422cb7e93
use F77_INT instead of octave_idx_type for liboctave ODE and DAE classes
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
52 const F77_DBLE*, const F77_DBLE*, F77_INT&, |
0d1422cb7e93
use F77_INT instead of octave_idx_type for liboctave ODE and DAE classes
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
53 F77_DBLE*, const F77_INT&, F77_INT*, |
0d1422cb7e93
use F77_INT instead of octave_idx_type for liboctave ODE and DAE classes
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
54 const F77_INT&, const F77_DBLE*, const F77_INT*, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
55 dassl_jac_ptr); |
4552 | 56 } |
3 | 57 |
532 | 58 static DAEFunc::DAERHSFunc user_fun; |
59 static DAEFunc::DAEJacFunc user_jac; | |
3993 | 60 |
22960
0d1422cb7e93
use F77_INT instead of octave_idx_type for liboctave ODE and DAE classes
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
61 static F77_INT nn; |
3 | 62 |
22960
0d1422cb7e93
use F77_INT instead of octave_idx_type for liboctave ODE and DAE classes
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
63 static F77_INT |
3991 | 64 ddassl_f (const double& time, const double *state, const double *deriv, |
22960
0d1422cb7e93
use F77_INT instead of octave_idx_type for liboctave ODE and DAE classes
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
65 double *delta, F77_INT& ires, double *, F77_INT *) |
3 | 66 { |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
67 // FIXME: would be nice to avoid copying the data. |
3991 | 68 |
1546 | 69 ColumnVector tmp_deriv (nn); |
70 ColumnVector tmp_state (nn); | |
71 ColumnVector tmp_delta (nn); | |
3 | 72 |
22960
0d1422cb7e93
use F77_INT instead of octave_idx_type for liboctave ODE and DAE classes
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
73 for (F77_INT i = 0; i < nn; i++) |
3 | 74 { |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14138
diff
changeset
|
75 tmp_deriv.elem (i) = deriv[i]; |
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14138
diff
changeset
|
76 tmp_state.elem (i) = state[i]; |
3 | 77 } |
78 | |
22960
0d1422cb7e93
use F77_INT instead of octave_idx_type for liboctave ODE and DAE classes
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
79 octave_idx_type tmp_ires = ires; |
0d1422cb7e93
use F77_INT instead of octave_idx_type for liboctave ODE and DAE classes
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
80 |
0d1422cb7e93
use F77_INT instead of octave_idx_type for liboctave ODE and DAE classes
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
81 tmp_delta = user_fun (tmp_state, tmp_deriv, time, tmp_ires); |
0d1422cb7e93
use F77_INT instead of octave_idx_type for liboctave ODE and DAE classes
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
82 |
22988
cd33c785e80e
put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22960
diff
changeset
|
83 ires = octave::to_f77_int (tmp_ires); |
3 | 84 |
3849 | 85 if (ires >= 0) |
256 | 86 { |
23577
80c42f4cca13
maint: Deprecate is_empty and replace with isempty.
Rik <rik@octave.org>
parents:
23475
diff
changeset
|
87 if (tmp_delta.isempty ()) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
88 ires = -2; |
3849 | 89 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
90 { |
22960
0d1422cb7e93
use F77_INT instead of octave_idx_type for liboctave ODE and DAE classes
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
91 for (F77_INT i = 0; i < nn; i++) |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14138
diff
changeset
|
92 delta[i] = tmp_delta.elem (i); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
93 } |
256 | 94 } |
3 | 95 |
96 return 0; | |
97 } | |
98 | |
22960
0d1422cb7e93
use F77_INT instead of octave_idx_type for liboctave ODE and DAE classes
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
99 static F77_INT |
3991 | 100 ddassl_j (const double& time, const double *state, const double *deriv, |
22960
0d1422cb7e93
use F77_INT instead of octave_idx_type for liboctave ODE and DAE classes
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
101 double *pd, const double& cj, double *, F77_INT *) |
3 | 102 { |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
103 // FIXME: would be nice to avoid copying the data. |
3991 | 104 |
1546 | 105 ColumnVector tmp_state (nn); |
106 ColumnVector tmp_deriv (nn); | |
3 | 107 |
22960
0d1422cb7e93
use F77_INT instead of octave_idx_type for liboctave ODE and DAE classes
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
108 for (F77_INT i = 0; i < nn; i++) |
3991 | 109 { |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14138
diff
changeset
|
110 tmp_deriv.elem (i) = deriv[i]; |
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14138
diff
changeset
|
111 tmp_state.elem (i) = state[i]; |
3991 | 112 } |
3 | 113 |
3991 | 114 Matrix tmp_pd = user_jac (tmp_state, tmp_deriv, time, cj); |
3 | 115 |
22960
0d1422cb7e93
use F77_INT instead of octave_idx_type for liboctave ODE and DAE classes
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
116 for (F77_INT j = 0; j < nn; j++) |
0d1422cb7e93
use F77_INT instead of octave_idx_type for liboctave ODE and DAE classes
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
117 for (F77_INT i = 0; i < nn; i++) |
15020
560317fd5977
maint: Cuddle open bracket used for indexing C++ arrays in source code.
Rik <rik@octave.org>
parents:
15018
diff
changeset
|
118 pd[nn * j + i] = tmp_pd.elem (i, j); |
3 | 119 |
120 return 0; | |
121 } | |
122 | |
1546 | 123 ColumnVector |
1842 | 124 DASSL::do_integrate (double tout) |
3 | 125 { |
1945 | 126 ColumnVector retval; |
127 | |
21662
5b9868c2e212
maint: Octave coding convention cleanups.
Rik <rik@octave.org>
parents:
21301
diff
changeset
|
128 if (! initialized || restart || DAEFunc::reset || DASSL_options::reset) |
1945 | 129 { |
4049 | 130 integration_error = false; |
131 | |
132 initialized = true; | |
133 | |
11574
a83bad07f7e3
attempt better backward compatibility for Array resize functions
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
134 info.resize (dim_vector (15, 1)); |
4049 | 135 |
22960
0d1422cb7e93
use F77_INT instead of octave_idx_type for liboctave ODE and DAE classes
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
136 for (F77_INT i = 0; i < 15; i++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
137 info(i) = 0; |
1945 | 138 |
22988
cd33c785e80e
put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22960
diff
changeset
|
139 F77_INT n = octave::to_f77_int (size ()); |
4049 | 140 |
4429 | 141 liw = 21 + n; |
4049 | 142 lrw = 40 + 9*n + n*n; |
1945 | 143 |
4049 | 144 nn = n; |
1945 | 145 |
11574
a83bad07f7e3
attempt better backward compatibility for Array resize functions
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
146 iwork.resize (dim_vector (liw, 1)); |
a83bad07f7e3
attempt better backward compatibility for Array resize functions
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
147 rwork.resize (dim_vector (lrw, 1)); |
256 | 148 |
4049 | 149 info(0) = 0; |
3994 | 150 |
4049 | 151 if (stop_time_set) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
152 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
153 rwork(0) = stop_time; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
154 info(3) = 1; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
155 } |
4049 | 156 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
157 info(3) = 0; |
3 | 158 |
4049 | 159 restart = false; |
160 | |
161 // DAEFunc | |
3 | 162 |
4049 | 163 user_fun = DAEFunc::function (); |
164 user_jac = DAEFunc::jacobian_function (); | |
165 | |
166 if (user_fun) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
167 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
168 octave_idx_type ires = 0; |
4049 | 169 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
170 ColumnVector res = (*user_fun) (x, xdot, t, ires); |
3993 | 171 |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20229
diff
changeset
|
172 if (res.numel () != x.numel ()) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
173 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
174 (*current_liboctave_error_handler) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
175 ("dassl: inconsistent sizes for state and residual vectors"); |
3849 | 176 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
177 integration_error = true; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
178 return retval; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
179 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
180 } |
4049 | 181 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
182 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
183 (*current_liboctave_error_handler) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
184 ("dassl: no user supplied RHS subroutine!"); |
2344 | 185 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
186 integration_error = true; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
187 return retval; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
188 } |
2344 | 189 |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23443
diff
changeset
|
190 info(4) = (user_jac ? 1 : 0); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
191 |
4049 | 192 DAEFunc::reset = false; |
3 | 193 |
4049 | 194 // DASSL_options |
3998 | 195 |
4049 | 196 double hmax = maximum_step_size (); |
197 if (hmax >= 0.0) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
198 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
199 rwork(1) = hmax; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
200 info(6) = 1; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
201 } |
4049 | 202 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
203 info(6) = 0; |
3998 | 204 |
4049 | 205 double h0 = initial_step_size (); |
206 if (h0 >= 0.0) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
207 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
208 rwork(2) = h0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
209 info(7) = 1; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
210 } |
4049 | 211 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
212 info(7) = 0; |
3998 | 213 |
22988
cd33c785e80e
put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22960
diff
changeset
|
214 F77_INT sl = octave::to_f77_int (step_limit ()); |
22960
0d1422cb7e93
use F77_INT instead of octave_idx_type for liboctave ODE and DAE classes
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
215 |
0d1422cb7e93
use F77_INT instead of octave_idx_type for liboctave ODE and DAE classes
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
216 if (sl >= 0) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
217 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
218 info(11) = 1; |
22960
0d1422cb7e93
use F77_INT instead of octave_idx_type for liboctave ODE and DAE classes
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
219 iwork(20) = sl; |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
220 } |
4429 | 221 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
222 info(11) = 0; |
4429 | 223 |
22988
cd33c785e80e
put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22960
diff
changeset
|
224 F77_INT maxord = octave::to_f77_int (maximum_order ()); |
4049 | 225 if (maxord >= 0) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
226 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
227 if (maxord > 0 && maxord < 6) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
228 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
229 info(8) = 1; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
230 iwork(2) = maxord; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
231 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
232 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
233 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
234 (*current_liboctave_error_handler) |
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
|
235 ("dassl: invalid value for maximum order: %d", maxord); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
236 integration_error = true; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
237 return retval; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
238 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
239 } |
4047 | 240 |
22988
cd33c785e80e
put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22960
diff
changeset
|
241 F77_INT enc = octave::to_f77_int (enforce_nonnegativity_constraints ()); |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23443
diff
changeset
|
242 info(9) = (enc ? 1 : 0); |
4049 | 243 |
22988
cd33c785e80e
put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22960
diff
changeset
|
244 F77_INT ccic = octave::to_f77_int (compute_consistent_initial_condition ()); |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23443
diff
changeset
|
245 info(10) = (ccic ? 1 : 0); |
4049 | 246 |
247 abs_tol = absolute_tolerance (); | |
248 rel_tol = relative_tolerance (); | |
289 | 249 |
22988
cd33c785e80e
put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22960
diff
changeset
|
250 F77_INT abs_tol_len = octave::to_f77_int (abs_tol.numel ()); |
cd33c785e80e
put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22960
diff
changeset
|
251 F77_INT rel_tol_len = octave::to_f77_int (rel_tol.numel ()); |
4049 | 252 |
253 if (abs_tol_len == 1 && rel_tol_len == 1) | |
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 info(1) = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
256 } |
4049 | 257 else if (abs_tol_len == n && rel_tol_len == n) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
258 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
259 info(1) = 1; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
260 } |
4047 | 261 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
262 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
263 (*current_liboctave_error_handler) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
264 ("dassl: inconsistent sizes for tolerance arrays"); |
4049 | 265 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
266 integration_error = true; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
267 return retval; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
268 } |
4049 | 269 |
270 DASSL_options::reset = false; | |
289 | 271 } |
4047 | 272 |
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
|
273 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
|
274 double *pxdot = xdot.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
|
275 |
22960
0d1422cb7e93
use F77_INT instead of octave_idx_type for liboctave ODE and DAE classes
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
276 F77_INT *pinfo = info.fortran_vec (); |
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
|
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 *prel_tol = rel_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 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
|
280 |
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 (); |
22960
0d1422cb7e93
use F77_INT instead of octave_idx_type for liboctave ODE and DAE classes
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
282 F77_INT *piwork = iwork.fortran_vec (); |
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
|
283 |
23457
21baad6b35c4
maint: Use C++11 nullptr rather than 0 or NULL when possible.
Rik <rik@octave.org>
parents:
23450
diff
changeset
|
284 double *dummy = nullptr; |
21baad6b35c4
maint: Use C++11 nullptr rather than 0 or NULL when possible.
Rik <rik@octave.org>
parents:
23450
diff
changeset
|
285 F77_INT *idummy = nullptr; |
22960
0d1422cb7e93
use F77_INT instead of octave_idx_type for liboctave ODE and DAE classes
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
286 |
22988
cd33c785e80e
put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22960
diff
changeset
|
287 F77_INT tmp_istate = octave::to_f77_int (istate); |
3 | 288 |
4049 | 289 F77_XFCN (ddassl, DDASSL, (ddassl_f, nn, t, px, pxdot, tout, pinfo, |
22960
0d1422cb7e93
use F77_INT instead of octave_idx_type for liboctave ODE and DAE classes
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
290 prel_tol, pabs_tol, tmp_istate, prwork, lrw, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
291 piwork, liw, dummy, idummy, ddassl_j)); |
3 | 292 |
22960
0d1422cb7e93
use F77_INT instead of octave_idx_type for liboctave ODE and DAE classes
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
293 istate = tmp_istate; |
0d1422cb7e93
use F77_INT instead of octave_idx_type for liboctave ODE and DAE classes
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
294 |
7482
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7231
diff
changeset
|
295 switch (istate) |
3 | 296 { |
7482
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7231
diff
changeset
|
297 case 1: // A step was successfully taken in intermediate-output |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21724
diff
changeset
|
298 // mode. The code has not yet reached TOUT. |
7482
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7231
diff
changeset
|
299 case 2: // The integration to TSTOP was successfully completed |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
300 // (T=TSTOP) by stepping exactly to TSTOP. |
7482
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7231
diff
changeset
|
301 case 3: // The integration to TOUT was successfully completed |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
302 // (T=TOUT) by stepping past TOUT. Y(*) is obtained by |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
303 // interpolation. YPRIME(*) is obtained by interpolation. |
7482
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7231
diff
changeset
|
304 retval = x; |
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7231
diff
changeset
|
305 t = tout; |
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7231
diff
changeset
|
306 break; |
1360 | 307 |
7482
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7231
diff
changeset
|
308 case -1: // A large amount of work has been expended. (~500 steps). |
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7231
diff
changeset
|
309 case -2: // The error tolerances are too stringent. |
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7231
diff
changeset
|
310 case -3: // The local error test cannot be satisfied because you |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
311 // specified a zero component in ATOL and the |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
312 // corresponding computed solution component is zero. |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
313 // Thus, a pure relative error test is impossible for |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
314 // this component. |
7482
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7231
diff
changeset
|
315 case -6: // DDASSL had repeated error test failures on the last |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
316 // attempted step. |
7482
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7231
diff
changeset
|
317 case -7: // The corrector could not converge. |
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7231
diff
changeset
|
318 case -8: // The matrix of partial derivatives is singular. |
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7231
diff
changeset
|
319 case -9: // The corrector could not converge. There were repeated |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
320 // error test failures in this step. |
7482
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7231
diff
changeset
|
321 case -10: // The corrector could not converge because IRES was |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
322 // equal to minus one. |
7482
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7231
diff
changeset
|
323 case -11: // IRES equal to -2 was encountered and control is being |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
324 // returned to the calling program. |
7482
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7231
diff
changeset
|
325 case -12: // DDASSL failed to compute the initial YPRIME. |
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7231
diff
changeset
|
326 case -33: // The code has encountered trouble from which it cannot |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21724
diff
changeset
|
327 // recover. A message is printed explaining the trouble |
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21724
diff
changeset
|
328 // and control is returned to the calling program. For |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
329 // example, this occurs when invalid input is detected. |
7482
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7231
diff
changeset
|
330 integration_error = true; |
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7231
diff
changeset
|
331 break; |
3996 | 332 |
7482
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7231
diff
changeset
|
333 default: |
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7231
diff
changeset
|
334 integration_error = true; |
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7231
diff
changeset
|
335 (*current_liboctave_error_handler) |
26569
0e77df67b522
Add static compile-time checking of printf functions in liboctave.
Markus Mützel <markus.muetzel@gmx.de>
parents:
26376
diff
changeset
|
336 ("unrecognized value of istate (= %" OCTAVE_IDX_TYPE_FORMAT ") " |
0e77df67b522
Add static compile-time checking of printf functions in liboctave.
Markus Mützel <markus.muetzel@gmx.de>
parents:
26376
diff
changeset
|
337 "returned from ddassl", istate); |
7482
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7231
diff
changeset
|
338 break; |
3 | 339 } |
340 | |
1945 | 341 return retval; |
3 | 342 } |
343 | |
344 Matrix | |
1842 | 345 DASSL::do_integrate (const ColumnVector& tout) |
346 { | |
347 Matrix dummy; | |
348 return integrate (tout, dummy); | |
349 } | |
350 | |
351 Matrix | |
352 DASSL::integrate (const ColumnVector& tout, Matrix& xdot_out) | |
3 | 353 { |
354 Matrix retval; | |
4049 | 355 |
20229
5dfaaaae784f
Deprecate Array::capacity() and Sparse::capacity() for numel() and nzmax().
Carnë Draug <carandraug@octave.org>
parents:
19697
diff
changeset
|
356 octave_idx_type n_out = tout.numel (); |
22988
cd33c785e80e
put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22960
diff
changeset
|
357 F77_INT n = octave::to_f77_int (size ()); |
3 | 358 |
359 if (n_out > 0 && n > 0) | |
360 { | |
361 retval.resize (n_out, n); | |
362 xdot_out.resize (n_out, n); | |
363 | |
22960
0d1422cb7e93
use F77_INT instead of octave_idx_type for liboctave ODE and DAE classes
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
364 for (F77_INT i = 0; i < n; i++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
365 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
366 retval.elem (0, i) = x.elem (i); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
367 xdot_out.elem (0, i) = xdot.elem (i); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
368 } |
3 | 369 |
5275 | 370 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
|
371 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
372 ColumnVector x_next = do_integrate (tout.elem (j)); |
256 | 373 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
374 if (integration_error) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
375 return retval; |
256 | 376 |
22960
0d1422cb7e93
use F77_INT instead of octave_idx_type for liboctave ODE and DAE classes
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
377 for (F77_INT i = 0; i < n; i++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
378 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
379 retval.elem (j, i) = x_next.elem (i); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
380 xdot_out.elem (j, i) = xdot.elem (i); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
381 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
382 } |
3 | 383 } |
384 | |
385 return retval; | |
386 } | |
387 | |
388 Matrix | |
3519 | 389 DASSL::do_integrate (const ColumnVector& tout, const ColumnVector& tcrit) |
390 { | |
391 Matrix dummy; | |
392 return integrate (tout, dummy, tcrit); | |
393 } | |
394 | |
395 Matrix | |
1842 | 396 DASSL::integrate (const ColumnVector& tout, Matrix& xdot_out, |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
397 const ColumnVector& tcrit) |
3 | 398 { |
399 Matrix retval; | |
4049 | 400 |
20229
5dfaaaae784f
Deprecate Array::capacity() and Sparse::capacity() for numel() and nzmax().
Carnë Draug <carandraug@octave.org>
parents:
19697
diff
changeset
|
401 octave_idx_type n_out = tout.numel (); |
22988
cd33c785e80e
put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22960
diff
changeset
|
402 F77_INT n = octave::to_f77_int (size ()); |
3 | 403 |
404 if (n_out > 0 && n > 0) | |
405 { | |
406 retval.resize (n_out, n); | |
407 xdot_out.resize (n_out, n); | |
408 | |
22960
0d1422cb7e93
use F77_INT instead of octave_idx_type for liboctave ODE and DAE classes
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
409 for (F77_INT i = 0; i < n; i++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
410 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
411 retval.elem (0, i) = x.elem (i); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
412 xdot_out.elem (0, i) = xdot.elem (i); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
413 } |
3 | 414 |
20229
5dfaaaae784f
Deprecate Array::capacity() and Sparse::capacity() for numel() and nzmax().
Carnë Draug <carandraug@octave.org>
parents:
19697
diff
changeset
|
415 octave_idx_type n_crit = tcrit.numel (); |
3 | 416 |
417 if (n_crit > 0) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
418 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
419 octave_idx_type i_crit = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
420 octave_idx_type i_out = 1; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
421 double next_crit = tcrit.elem (0); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
422 double next_out; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
423 while (i_out < n_out) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
424 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
425 bool do_restart = false; |
3 | 426 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
427 next_out = tout.elem (i_out); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
428 if (i_crit < n_crit) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
429 next_crit = tcrit.elem (i_crit); |
3 | 430 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
431 bool save_output; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
432 double t_out; |
3 | 433 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
434 if (next_crit == next_out) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
435 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
436 set_stop_time (next_crit); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
437 t_out = next_out; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
438 save_output = true; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
439 i_out++; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
440 i_crit++; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
441 do_restart = true; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
442 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
443 else if (next_crit < next_out) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
444 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
445 if (i_crit < n_crit) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
446 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
447 set_stop_time (next_crit); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
448 t_out = next_crit; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
449 save_output = false; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
450 i_crit++; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
451 do_restart = true; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
452 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
453 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
454 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
455 clear_stop_time (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
456 t_out = next_out; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
457 save_output = true; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
458 i_out++; |
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 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
461 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
462 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
463 set_stop_time (next_crit); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
464 t_out = next_out; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
465 save_output = true; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
466 i_out++; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
467 } |
3 | 468 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
469 ColumnVector x_next = do_integrate (t_out); |
3 | 470 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
471 if (integration_error) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
472 return retval; |
256 | 473 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
474 if (save_output) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
475 { |
22960
0d1422cb7e93
use F77_INT instead of octave_idx_type for liboctave ODE and DAE classes
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
476 for (F77_INT i = 0; i < n; i++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
477 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
478 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
|
479 xdot_out.elem (i_out-1, i) = xdot.elem (i); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
480 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
481 } |
3 | 482 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
483 if (do_restart) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
484 force_restart (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
485 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
486 } |
3 | 487 else |
10314
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 retval = integrate (tout, xdot_out); |
256 | 490 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
491 if (integration_error) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
492 return retval; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
493 } |
3 | 494 } |
495 | |
496 return retval; | |
497 } | |
289 | 498 |
3995 | 499 std::string |
500 DASSL::error_message (void) const | |
501 { | |
502 std::string retval; | |
503 | |
5765 | 504 std::ostringstream buf; |
505 buf << t; | |
506 std::string t_curr = buf.str (); | |
4043 | 507 |
3997 | 508 switch (istate) |
3995 | 509 { |
3996 | 510 case 1: |
511 retval = "a step was successfully taken in intermediate-output mode."; | |
512 break; | |
513 | |
514 case 2: | |
515 retval = "integration completed by stepping exactly to TOUT"; | |
516 break; | |
517 | |
518 case 3: | |
519 retval = "integration to tout completed by stepping past TOUT"; | |
520 break; | |
521 | |
522 case -1: | |
23829
01899bdd2a3a
Eliminate unnecessary std::string ("...") constructor calls when "..." suffices.
Rik <rik@octave.org>
parents:
23807
diff
changeset
|
523 retval = "a large amount of work has been expended (t =" + t_curr + ')'; |
3996 | 524 break; |
525 | |
526 case -2: | |
527 retval = "the error tolerances are too stringent"; | |
528 break; | |
529 | |
530 case -3: | |
23829
01899bdd2a3a
Eliminate unnecessary std::string ("...") constructor calls when "..." suffices.
Rik <rik@octave.org>
parents:
23807
diff
changeset
|
531 retval = "error weight became zero during problem. (t = " + t_curr + |
01899bdd2a3a
Eliminate unnecessary std::string ("...") constructor calls when "..." suffices.
Rik <rik@octave.org>
parents:
23807
diff
changeset
|
532 "; solution component i vanished, and atol or atol(i) == 0)"; |
3996 | 533 break; |
534 | |
535 case -6: | |
23829
01899bdd2a3a
Eliminate unnecessary std::string ("...") constructor calls when "..." suffices.
Rik <rik@octave.org>
parents:
23807
diff
changeset
|
536 retval = "repeated error test failures on the last attempted step (t = " |
23807
336f89b6208b
Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents:
23577
diff
changeset
|
537 + t_curr + ')'; |
3996 | 538 break; |
539 | |
540 case -7: | |
23829
01899bdd2a3a
Eliminate unnecessary std::string ("...") constructor calls when "..." suffices.
Rik <rik@octave.org>
parents:
23807
diff
changeset
|
541 retval = "the corrector could not converge (t = " + t_curr + ')'; |
3996 | 542 break; |
543 | |
544 case -8: | |
23829
01899bdd2a3a
Eliminate unnecessary std::string ("...") constructor calls when "..." suffices.
Rik <rik@octave.org>
parents:
23807
diff
changeset
|
545 retval = "the matrix of partial derivatives is singular (t = " + t_curr + |
01899bdd2a3a
Eliminate unnecessary std::string ("...") constructor calls when "..." suffices.
Rik <rik@octave.org>
parents:
23807
diff
changeset
|
546 ')'; |
3996 | 547 break; |
548 | |
549 case -9: | |
23829
01899bdd2a3a
Eliminate unnecessary std::string ("...") constructor calls when "..." suffices.
Rik <rik@octave.org>
parents:
23807
diff
changeset
|
550 retval = "the corrector could not converge (t = " + t_curr + |
01899bdd2a3a
Eliminate unnecessary std::string ("...") constructor calls when "..." suffices.
Rik <rik@octave.org>
parents:
23807
diff
changeset
|
551 "; repeated test failures)"; |
3996 | 552 break; |
553 | |
554 case -10: | |
23829
01899bdd2a3a
Eliminate unnecessary std::string ("...") constructor calls when "..." suffices.
Rik <rik@octave.org>
parents:
23807
diff
changeset
|
555 retval = "corrector could not converge because IRES was -1 (t = " |
23807
336f89b6208b
Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents:
23577
diff
changeset
|
556 + t_curr + ')'; |
3996 | 557 break; |
558 | |
559 case -11: | |
23829
01899bdd2a3a
Eliminate unnecessary std::string ("...") constructor calls when "..." suffices.
Rik <rik@octave.org>
parents:
23807
diff
changeset
|
560 retval = "return requested in user-supplied function (t = " + t_curr + |
01899bdd2a3a
Eliminate unnecessary std::string ("...") constructor calls when "..." suffices.
Rik <rik@octave.org>
parents:
23807
diff
changeset
|
561 ')'; |
3996 | 562 break; |
563 | |
564 case -12: | |
565 retval = "failed to compute consistent initial conditions"; | |
566 break; | |
567 | |
568 case -33: | |
569 retval = "unrecoverable error (see printed message)"; | |
570 break; | |
571 | |
3995 | 572 default: |
573 retval = "unknown error state"; | |
574 break; | |
575 } | |
576 | |
577 return retval; | |
578 } |