Mercurial > octave
annotate liboctave/numeric/LSODE.cc @ 33586:3216c01fd6a7 stable tip
fix dragging editor from main window into floating state (bug #65725)
* file-editor.cc (toplevel_changes): added missing call to original
slot octave_doc_widget::toplevel_changed
author | Torsten Lilge <ttl-octave@mailbox.org> |
---|---|
date | Tue, 14 May 2024 22:03:47 +0200 |
parents | 2e484f9f1f18 |
children | f53ac65ffba6 |
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 // |
32632
2e484f9f1f18
maint: update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents:
31771
diff
changeset
|
3 // Copyright (C) 1993-2024 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:
21301
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 "LSODE.h" |
1847 | 34 #include "f77-fcn.h" |
227 | 35 #include "lo-error.h" |
4180 | 36 #include "quit.h" |
3 | 37 |
30394
f3f3e3793fb5
maint: style check C++ files in liboctave/ ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30067
diff
changeset
|
38 typedef F77_INT (*lsode_fcn_ptr) (const F77_INT&, const double&, double *, |
f3f3e3793fb5
maint: style check C++ files in liboctave/ ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30067
diff
changeset
|
39 double *, F77_INT&); |
3507 | 40 |
30394
f3f3e3793fb5
maint: style check C++ files in liboctave/ ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30067
diff
changeset
|
41 typedef F77_INT (*lsode_jac_ptr) (const F77_INT&, const double&, double *, |
f3f3e3793fb5
maint: style check C++ files in liboctave/ ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30067
diff
changeset
|
42 const F77_INT&, const F77_INT&, double *, |
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 const F77_INT&); |
3507 | 44 |
3 | 45 extern "C" |
4552 | 46 { |
47 F77_RET_T | |
30394
f3f3e3793fb5
maint: style check C++ files in liboctave/ ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30067
diff
changeset
|
48 F77_FUNC (dlsode, DLSODE) (lsode_fcn_ptr, F77_INT&, F77_DBLE *, F77_DBLE&, |
f3f3e3793fb5
maint: style check C++ files in liboctave/ ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30067
diff
changeset
|
49 F77_DBLE&, F77_INT&, F77_DBLE&, const F77_DBLE *, |
f3f3e3793fb5
maint: style check C++ files in liboctave/ ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30067
diff
changeset
|
50 F77_INT&, F77_INT&, F77_INT&, F77_DBLE *, |
f3f3e3793fb5
maint: style check C++ files in liboctave/ ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30067
diff
changeset
|
51 F77_INT&, F77_INT *, F77_INT&, lsode_jac_ptr, |
22133
59cadee1c74b
new macros for F77 data types
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
52 F77_INT&); |
4552 | 53 } |
3 | 54 |
30898
51a3d3a69193
maint: Use "fcn" as preferred abbreviation for "function" in liboctave/.
Rik <rik@octave.org>
parents:
30564
diff
changeset
|
55 static ODEFunc::ODERHSFunc user_fcn; |
532 | 56 static ODEFunc::ODEJacFunc user_jac; |
3 | 57 static ColumnVector *tmp_x; |
31249
de6fc38c78c6
Make Jacobian types offered by dlsode.f accessible by lsode (bug #31626).
Olaf Till <olaf.till@uni-jena.de>
parents:
30898
diff
changeset
|
58 static bool user_jac_ignore_ml_mu; |
3 | 59 |
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
|
60 static 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
|
61 lsode_f (const F77_INT& neq, const double& time, double *, double *deriv, |
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
|
62 F77_INT& ierr) |
3 | 63 { |
2343 | 64 ColumnVector tmp_deriv; |
3 | 65 |
1360 | 66 // NOTE: this won't work if LSODE passes copies of the state vector. |
67 // In that case we have to create a temporary vector object | |
68 // and copy. | |
69 | |
30898
51a3d3a69193
maint: Use "fcn" as preferred abbreviation for "function" in liboctave/.
Rik <rik@octave.org>
parents:
30564
diff
changeset
|
70 tmp_deriv = (*user_fcn) (*tmp_x, time); |
3 | 71 |
23577
80c42f4cca13
maint: Deprecate is_empty and replace with isempty.
Rik <rik@octave.org>
parents:
23475
diff
changeset
|
72 if (tmp_deriv.isempty ()) |
1251 | 73 ierr = -1; |
258 | 74 else |
75 { | |
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
|
76 for (F77_INT 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
|
77 deriv[i] = tmp_deriv.elem (i); |
258 | 78 } |
3 | 79 |
80 return 0; | |
81 } | |
82 | |
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
|
83 static F77_INT |
31549
ed7b17c7ddf3
maint: Strip trailing spaces and add missing EOL to all files.
Rik <rik@octave.org>
parents:
31388
diff
changeset
|
84 lsode_j (const F77_INT& neq, const double& time, double *, |
31249
de6fc38c78c6
Make Jacobian types offered by dlsode.f accessible by lsode (bug #31626).
Olaf Till <olaf.till@uni-jena.de>
parents:
30898
diff
changeset
|
85 const F77_INT& ml, const F77_INT& mu, |
de6fc38c78c6
Make Jacobian types offered by dlsode.f accessible by lsode (bug #31626).
Olaf Till <olaf.till@uni-jena.de>
parents:
30898
diff
changeset
|
86 double *pd, const F77_INT& nrowpd) |
3 | 87 { |
1251 | 88 Matrix tmp_jac (neq, neq); |
3 | 89 |
1360 | 90 // NOTE: this won't work if LSODE passes copies of the state vector. |
91 // In that case we have to create a temporary vector object | |
92 // and copy. | |
93 | |
1251 | 94 tmp_jac = (*user_jac) (*tmp_x, time); |
3 | 95 |
31249
de6fc38c78c6
Make Jacobian types offered by dlsode.f accessible by lsode (bug #31626).
Olaf Till <olaf.till@uni-jena.de>
parents:
30898
diff
changeset
|
96 if (user_jac_ignore_ml_mu) |
de6fc38c78c6
Make Jacobian types offered by dlsode.f accessible by lsode (bug #31626).
Olaf Till <olaf.till@uni-jena.de>
parents:
30898
diff
changeset
|
97 for (F77_INT j = 0; j < neq; j++) |
de6fc38c78c6
Make Jacobian types offered by dlsode.f accessible by lsode (bug #31626).
Olaf Till <olaf.till@uni-jena.de>
parents:
30898
diff
changeset
|
98 for (F77_INT i = 0; i < neq; i++) |
de6fc38c78c6
Make Jacobian types offered by dlsode.f accessible by lsode (bug #31626).
Olaf Till <olaf.till@uni-jena.de>
parents:
30898
diff
changeset
|
99 pd[nrowpd * j + i] = tmp_jac (i, j); |
de6fc38c78c6
Make Jacobian types offered by dlsode.f accessible by lsode (bug #31626).
Olaf Till <olaf.till@uni-jena.de>
parents:
30898
diff
changeset
|
100 else |
de6fc38c78c6
Make Jacobian types offered by dlsode.f accessible by lsode (bug #31626).
Olaf Till <olaf.till@uni-jena.de>
parents:
30898
diff
changeset
|
101 // upper left ends of subdiagonals in tmp_jac |
de6fc38c78c6
Make Jacobian types offered by dlsode.f accessible by lsode (bug #31626).
Olaf Till <olaf.till@uni-jena.de>
parents:
30898
diff
changeset
|
102 for (F77_INT i = 0, j = mu; i <= ml; j == 0 ? i++ : j--) |
de6fc38c78c6
Make Jacobian types offered by dlsode.f accessible by lsode (bug #31626).
Olaf Till <olaf.till@uni-jena.de>
parents:
30898
diff
changeset
|
103 // walk down the subdiagonal in tmp_jac |
de6fc38c78c6
Make Jacobian types offered by dlsode.f accessible by lsode (bug #31626).
Olaf Till <olaf.till@uni-jena.de>
parents:
30898
diff
changeset
|
104 for (F77_INT k = i, l = j; k < neq && l < neq; k++, l++) |
31549
ed7b17c7ddf3
maint: Strip trailing spaces and add missing EOL to all files.
Rik <rik@octave.org>
parents:
31388
diff
changeset
|
105 pd[nrowpd * l + k + mu - l] = tmp_jac (k, l); |
ed7b17c7ddf3
maint: Strip trailing spaces and add missing EOL to all files.
Rik <rik@octave.org>
parents:
31388
diff
changeset
|
106 |
3 | 107 return 0; |
108 } | |
109 | |
110 ColumnVector | |
1842 | 111 LSODE::do_integrate (double tout) |
3 | 112 { |
1945 | 113 ColumnVector retval; |
114 | |
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
|
115 static F77_INT nn = 0; |
4049 | 116 |
30067
fc509c3c445a
maint: use "m_" prefix for member variables in base-de.h and base-dae.h
Rik <rik@octave.org>
parents:
30047
diff
changeset
|
117 if (! m_initialized || m_restart || ODEFunc::m_reset |
fc509c3c445a
maint: use "m_" prefix for member variables in base-de.h and base-dae.h
Rik <rik@octave.org>
parents:
30047
diff
changeset
|
118 || LSODE_options::m_reset) |
1945 | 119 { |
30067
fc509c3c445a
maint: use "m_" prefix for member variables in base-de.h and base-dae.h
Rik <rik@octave.org>
parents:
30047
diff
changeset
|
120 m_integration_error = false; |
1945 | 121 |
30046
b3717fd85e49
maint: use "m_" prefix for member variables ODE/DAE classes in liboctave/numeric.
Rik <rik@octave.org>
parents:
29358
diff
changeset
|
122 m_initialized = true; |
4049 | 123 |
30067
fc509c3c445a
maint: use "m_" prefix for member variables in base-de.h and base-dae.h
Rik <rik@octave.org>
parents:
30047
diff
changeset
|
124 m_istate = 1; |
4049 | 125 |
22988
cd33c785e80e
put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22960
diff
changeset
|
126 F77_INT n = octave::to_f77_int (size ()); |
4049 | 127 |
128 nn = n; | |
3955 | 129 |
5275 | 130 octave_idx_type max_maxord = 0; |
4231 | 131 |
31249
de6fc38c78c6
Make Jacobian types offered by dlsode.f accessible by lsode (bug #31626).
Olaf Till <olaf.till@uni-jena.de>
parents:
30898
diff
changeset
|
132 user_jac_ignore_ml_mu = true; |
de6fc38c78c6
Make Jacobian types offered by dlsode.f accessible by lsode (bug #31626).
Olaf Till <olaf.till@uni-jena.de>
parents:
30898
diff
changeset
|
133 |
31388
18a6c1408626
LSODE: Make sure m_iwork is sufficiently large for following assignments (bug #63303).
Markus Mützel <markus.muetzel@gmx.de>
parents:
31253
diff
changeset
|
134 m_iwork = Array<octave_f77_int_type> (dim_vector (2, 1)); |
18a6c1408626
LSODE: Make sure m_iwork is sufficiently large for following assignments (bug #63303).
Markus Mützel <markus.muetzel@gmx.de>
parents:
31253
diff
changeset
|
135 |
31253
a40c0b7aa376
maint: changes to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
31249
diff
changeset
|
136 m_iwork(0) = lower_jacobian_subdiagonals (); // 'ML' in dlsode.f |
31249
de6fc38c78c6
Make Jacobian types offered by dlsode.f accessible by lsode (bug #31626).
Olaf Till <olaf.till@uni-jena.de>
parents:
30898
diff
changeset
|
137 |
31253
a40c0b7aa376
maint: changes to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
31249
diff
changeset
|
138 m_iwork(1) = upper_jacobian_subdiagonals (); // 'MU' in dlsode.f |
31249
de6fc38c78c6
Make Jacobian types offered by dlsode.f accessible by lsode (bug #31626).
Olaf Till <olaf.till@uni-jena.de>
parents:
30898
diff
changeset
|
139 |
4049 | 140 if (integration_method () == "stiff") |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
141 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
142 max_maxord = 5; |
4231 | 143 |
30047
02e28f7e4d04
maint: use "m_" prefix for member variables DAERTFunc/ODEFunc classes in liboctave/numeric.
Rik <rik@octave.org>
parents:
30046
diff
changeset
|
144 if (m_jac) |
31249
de6fc38c78c6
Make Jacobian types offered by dlsode.f accessible by lsode (bug #31626).
Olaf Till <olaf.till@uni-jena.de>
parents:
30898
diff
changeset
|
145 { |
de6fc38c78c6
Make Jacobian types offered by dlsode.f accessible by lsode (bug #31626).
Olaf Till <olaf.till@uni-jena.de>
parents:
30898
diff
changeset
|
146 if (jacobian_type () == "banded") |
de6fc38c78c6
Make Jacobian types offered by dlsode.f accessible by lsode (bug #31626).
Olaf Till <olaf.till@uni-jena.de>
parents:
30898
diff
changeset
|
147 { |
de6fc38c78c6
Make Jacobian types offered by dlsode.f accessible by lsode (bug #31626).
Olaf Till <olaf.till@uni-jena.de>
parents:
30898
diff
changeset
|
148 m_method_flag = 24; |
de6fc38c78c6
Make Jacobian types offered by dlsode.f accessible by lsode (bug #31626).
Olaf Till <olaf.till@uni-jena.de>
parents:
30898
diff
changeset
|
149 user_jac_ignore_ml_mu = false; |
de6fc38c78c6
Make Jacobian types offered by dlsode.f accessible by lsode (bug #31626).
Olaf Till <olaf.till@uni-jena.de>
parents:
30898
diff
changeset
|
150 } |
de6fc38c78c6
Make Jacobian types offered by dlsode.f accessible by lsode (bug #31626).
Olaf Till <olaf.till@uni-jena.de>
parents:
30898
diff
changeset
|
151 else |
de6fc38c78c6
Make Jacobian types offered by dlsode.f accessible by lsode (bug #31626).
Olaf Till <olaf.till@uni-jena.de>
parents:
30898
diff
changeset
|
152 m_method_flag = 21; |
de6fc38c78c6
Make Jacobian types offered by dlsode.f accessible by lsode (bug #31626).
Olaf Till <olaf.till@uni-jena.de>
parents:
30898
diff
changeset
|
153 } |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
154 else |
31249
de6fc38c78c6
Make Jacobian types offered by dlsode.f accessible by lsode (bug #31626).
Olaf Till <olaf.till@uni-jena.de>
parents:
30898
diff
changeset
|
155 { |
de6fc38c78c6
Make Jacobian types offered by dlsode.f accessible by lsode (bug #31626).
Olaf Till <olaf.till@uni-jena.de>
parents:
30898
diff
changeset
|
156 if (jacobian_type () == "full") |
de6fc38c78c6
Make Jacobian types offered by dlsode.f accessible by lsode (bug #31626).
Olaf Till <olaf.till@uni-jena.de>
parents:
30898
diff
changeset
|
157 m_method_flag = 22; |
de6fc38c78c6
Make Jacobian types offered by dlsode.f accessible by lsode (bug #31626).
Olaf Till <olaf.till@uni-jena.de>
parents:
30898
diff
changeset
|
158 else if (jacobian_type () == "banded") |
de6fc38c78c6
Make Jacobian types offered by dlsode.f accessible by lsode (bug #31626).
Olaf Till <olaf.till@uni-jena.de>
parents:
30898
diff
changeset
|
159 m_method_flag = 25; |
de6fc38c78c6
Make Jacobian types offered by dlsode.f accessible by lsode (bug #31626).
Olaf Till <olaf.till@uni-jena.de>
parents:
30898
diff
changeset
|
160 else if (jacobian_type () == "diagonal") |
de6fc38c78c6
Make Jacobian types offered by dlsode.f accessible by lsode (bug #31626).
Olaf Till <olaf.till@uni-jena.de>
parents:
30898
diff
changeset
|
161 m_method_flag = 23; |
de6fc38c78c6
Make Jacobian types offered by dlsode.f accessible by lsode (bug #31626).
Olaf Till <olaf.till@uni-jena.de>
parents:
30898
diff
changeset
|
162 else |
de6fc38c78c6
Make Jacobian types offered by dlsode.f accessible by lsode (bug #31626).
Olaf Till <olaf.till@uni-jena.de>
parents:
30898
diff
changeset
|
163 { |
de6fc38c78c6
Make Jacobian types offered by dlsode.f accessible by lsode (bug #31626).
Olaf Till <olaf.till@uni-jena.de>
parents:
30898
diff
changeset
|
164 // should be prevented by lsode_options |
de6fc38c78c6
Make Jacobian types offered by dlsode.f accessible by lsode (bug #31626).
Olaf Till <olaf.till@uni-jena.de>
parents:
30898
diff
changeset
|
165 (*current_liboctave_error_handler) |
de6fc38c78c6
Make Jacobian types offered by dlsode.f accessible by lsode (bug #31626).
Olaf Till <olaf.till@uni-jena.de>
parents:
30898
diff
changeset
|
166 ("lsode: internal error, wrong jacobian type"); |
de6fc38c78c6
Make Jacobian types offered by dlsode.f accessible by lsode (bug #31626).
Olaf Till <olaf.till@uni-jena.de>
parents:
30898
diff
changeset
|
167 m_integration_error = true; |
de6fc38c78c6
Make Jacobian types offered by dlsode.f accessible by lsode (bug #31626).
Olaf Till <olaf.till@uni-jena.de>
parents:
30898
diff
changeset
|
168 return retval; |
de6fc38c78c6
Make Jacobian types offered by dlsode.f accessible by lsode (bug #31626).
Olaf Till <olaf.till@uni-jena.de>
parents:
30898
diff
changeset
|
169 } |
de6fc38c78c6
Make Jacobian types offered by dlsode.f accessible by lsode (bug #31626).
Olaf Till <olaf.till@uni-jena.de>
parents:
30898
diff
changeset
|
170 } |
3955 | 171 |
30046
b3717fd85e49
maint: use "m_" prefix for member variables ODE/DAE classes in liboctave/numeric.
Rik <rik@octave.org>
parents:
29358
diff
changeset
|
172 m_liw = 20 + n; |
b3717fd85e49
maint: use "m_" prefix for member variables ODE/DAE classes in liboctave/numeric.
Rik <rik@octave.org>
parents:
29358
diff
changeset
|
173 m_lrw = 22 + n * (9 + n); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
174 } |
4049 | 175 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
176 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
177 max_maxord = 12; |
4231 | 178 |
30046
b3717fd85e49
maint: use "m_" prefix for member variables ODE/DAE classes in liboctave/numeric.
Rik <rik@octave.org>
parents:
29358
diff
changeset
|
179 m_method_flag = 10; |
3955 | 180 |
30046
b3717fd85e49
maint: use "m_" prefix for member variables ODE/DAE classes in liboctave/numeric.
Rik <rik@octave.org>
parents:
29358
diff
changeset
|
181 m_liw = 20; |
b3717fd85e49
maint: use "m_" prefix for member variables ODE/DAE classes in liboctave/numeric.
Rik <rik@octave.org>
parents:
29358
diff
changeset
|
182 m_lrw = 22 + 16 * n; |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
183 } |
4049 | 184 |
30046
b3717fd85e49
maint: use "m_" prefix for member variables ODE/DAE classes in liboctave/numeric.
Rik <rik@octave.org>
parents:
29358
diff
changeset
|
185 m_iwork.resize (dim_vector (m_liw, 1)); |
5552 | 186 |
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
|
187 for (F77_INT i = 4; i < 9; i++) |
30046
b3717fd85e49
maint: use "m_" prefix for member variables ODE/DAE classes in liboctave/numeric.
Rik <rik@octave.org>
parents:
29358
diff
changeset
|
188 m_iwork(i) = 0; |
5552 | 189 |
30046
b3717fd85e49
maint: use "m_" prefix for member variables ODE/DAE classes in liboctave/numeric.
Rik <rik@octave.org>
parents:
29358
diff
changeset
|
190 m_rwork.resize (dim_vector (m_lrw, 1)); |
5552 | 191 |
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
|
192 for (F77_INT i = 4; i < 9; i++) |
30046
b3717fd85e49
maint: use "m_" prefix for member variables ODE/DAE classes in liboctave/numeric.
Rik <rik@octave.org>
parents:
29358
diff
changeset
|
193 m_rwork(i) = 0; |
5552 | 194 |
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
|
195 octave_idx_type maxord = maximum_order (); |
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
|
196 |
4231 | 197 if (maxord >= 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 if (maxord > 0 && maxord <= max_maxord) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
200 { |
30046
b3717fd85e49
maint: use "m_" prefix for member variables ODE/DAE classes in liboctave/numeric.
Rik <rik@octave.org>
parents:
29358
diff
changeset
|
201 m_iwork(4) = octave::to_f77_int (maxord); |
b3717fd85e49
maint: use "m_" prefix for member variables ODE/DAE classes in liboctave/numeric.
Rik <rik@octave.org>
parents:
29358
diff
changeset
|
202 m_iopt = 1; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
203 } |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
204 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
205 { |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
20974
diff
changeset
|
206 // FIXME: Should this be a warning? |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
207 (*current_liboctave_error_handler) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
208 ("lsode: invalid value for maximum order"); |
30067
fc509c3c445a
maint: use "m_" prefix for member variables in base-de.h and base-dae.h
Rik <rik@octave.org>
parents:
30047
diff
changeset
|
209 m_integration_error = true; |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
210 return retval; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
211 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
212 } |
4231 | 213 |
30067
fc509c3c445a
maint: use "m_" prefix for member variables in base-de.h and base-dae.h
Rik <rik@octave.org>
parents:
30047
diff
changeset
|
214 if (m_stop_time_set) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
215 { |
30046
b3717fd85e49
maint: use "m_" prefix for member variables ODE/DAE classes in liboctave/numeric.
Rik <rik@octave.org>
parents:
29358
diff
changeset
|
216 m_itask = 4; |
30067
fc509c3c445a
maint: use "m_" prefix for member variables in base-de.h and base-dae.h
Rik <rik@octave.org>
parents:
30047
diff
changeset
|
217 m_rwork(0) = m_stop_time; |
30046
b3717fd85e49
maint: use "m_" prefix for member variables ODE/DAE classes in liboctave/numeric.
Rik <rik@octave.org>
parents:
29358
diff
changeset
|
218 m_iopt = 1; |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
219 } |
4049 | 220 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
221 { |
30046
b3717fd85e49
maint: use "m_" prefix for member variables ODE/DAE classes in liboctave/numeric.
Rik <rik@octave.org>
parents:
29358
diff
changeset
|
222 m_itask = 1; |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
223 } |
258 | 224 |
30067
fc509c3c445a
maint: use "m_" prefix for member variables in base-de.h and base-dae.h
Rik <rik@octave.org>
parents:
30047
diff
changeset
|
225 m_restart = false; |
4049 | 226 |
227 // ODEFunc | |
3 | 228 |
4049 | 229 // NOTE: this won't work if LSODE passes copies of the state vector. |
230 // In that case we have to create a temporary vector object | |
231 // and copy. | |
3 | 232 |
30067
fc509c3c445a
maint: use "m_" prefix for member variables in base-de.h and base-dae.h
Rik <rik@octave.org>
parents:
30047
diff
changeset
|
233 tmp_x = &m_x; |
4049 | 234 |
30898
51a3d3a69193
maint: Use "fcn" as preferred abbreviation for "function" in liboctave/.
Rik <rik@octave.org>
parents:
30564
diff
changeset
|
235 user_fcn = function (); |
4049 | 236 user_jac = jacobian_function (); |
237 | |
30898
51a3d3a69193
maint: Use "fcn" as preferred abbreviation for "function" in liboctave/.
Rik <rik@octave.org>
parents:
30564
diff
changeset
|
238 ColumnVector m_xdot = (*user_fcn) (m_x, m_t); |
2343 | 239 |
30067
fc509c3c445a
maint: use "m_" prefix for member variables in base-de.h and base-dae.h
Rik <rik@octave.org>
parents:
30047
diff
changeset
|
240 if (m_x.numel () != m_xdot.numel ()) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
241 { |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
20974
diff
changeset
|
242 // FIXME: Should this be a warning? |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
243 (*current_liboctave_error_handler) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
244 ("lsode: inconsistent sizes for state and derivative vectors"); |
2343 | 245 |
30067
fc509c3c445a
maint: use "m_" prefix for member variables in base-de.h and base-dae.h
Rik <rik@octave.org>
parents:
30047
diff
changeset
|
246 m_integration_error = true; |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
247 return retval; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
248 } |
2343 | 249 |
30047
02e28f7e4d04
maint: use "m_" prefix for member variables DAERTFunc/ODEFunc classes in liboctave/numeric.
Rik <rik@octave.org>
parents:
30046
diff
changeset
|
250 ODEFunc::m_reset = false; |
4049 | 251 |
252 // LSODE_options | |
253 | |
30046
b3717fd85e49
maint: use "m_" prefix for member variables ODE/DAE classes in liboctave/numeric.
Rik <rik@octave.org>
parents:
29358
diff
changeset
|
254 m_rel_tol = relative_tolerance (); |
b3717fd85e49
maint: use "m_" prefix for member variables ODE/DAE classes in liboctave/numeric.
Rik <rik@octave.org>
parents:
29358
diff
changeset
|
255 m_abs_tol = absolute_tolerance (); |
4049 | 256 |
30046
b3717fd85e49
maint: use "m_" prefix for member variables ODE/DAE classes in liboctave/numeric.
Rik <rik@octave.org>
parents:
29358
diff
changeset
|
257 F77_INT abs_tol_len = octave::to_f77_int (m_abs_tol.numel ()); |
4049 | 258 |
259 if (abs_tol_len == 1) | |
30046
b3717fd85e49
maint: use "m_" prefix for member variables ODE/DAE classes in liboctave/numeric.
Rik <rik@octave.org>
parents:
29358
diff
changeset
|
260 m_itol = 1; |
4049 | 261 else if (abs_tol_len == n) |
30046
b3717fd85e49
maint: use "m_" prefix for member variables ODE/DAE classes in liboctave/numeric.
Rik <rik@octave.org>
parents:
29358
diff
changeset
|
262 m_itol = 2; |
4049 | 263 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
264 { |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
20974
diff
changeset
|
265 // FIXME: Should this be a warning? |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
266 (*current_liboctave_error_handler) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
267 ("lsode: inconsistent sizes for state and absolute tolerance vectors"); |
4049 | 268 |
30067
fc509c3c445a
maint: use "m_" prefix for member variables in base-de.h and base-dae.h
Rik <rik@octave.org>
parents:
30047
diff
changeset
|
269 m_integration_error = true; |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
270 return retval; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
271 } |
2343 | 272 |
4049 | 273 double iss = initial_step_size (); |
274 if (iss >= 0.0) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
275 { |
30046
b3717fd85e49
maint: use "m_" prefix for member variables ODE/DAE classes in liboctave/numeric.
Rik <rik@octave.org>
parents:
29358
diff
changeset
|
276 m_rwork(4) = iss; |
b3717fd85e49
maint: use "m_" prefix for member variables ODE/DAE classes in liboctave/numeric.
Rik <rik@octave.org>
parents:
29358
diff
changeset
|
277 m_iopt = 1; |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
278 } |
4049 | 279 |
280 double maxss = maximum_step_size (); | |
281 if (maxss >= 0.0) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
282 { |
30046
b3717fd85e49
maint: use "m_" prefix for member variables ODE/DAE classes in liboctave/numeric.
Rik <rik@octave.org>
parents:
29358
diff
changeset
|
283 m_rwork(5) = maxss; |
b3717fd85e49
maint: use "m_" prefix for member variables ODE/DAE classes in liboctave/numeric.
Rik <rik@octave.org>
parents:
29358
diff
changeset
|
284 m_iopt = 1; |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
285 } |
4049 | 286 |
287 double minss = minimum_step_size (); | |
288 if (minss >= 0.0) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
289 { |
30046
b3717fd85e49
maint: use "m_" prefix for member variables ODE/DAE classes in liboctave/numeric.
Rik <rik@octave.org>
parents:
29358
diff
changeset
|
290 m_rwork(6) = minss; |
b3717fd85e49
maint: use "m_" prefix for member variables ODE/DAE classes in liboctave/numeric.
Rik <rik@octave.org>
parents:
29358
diff
changeset
|
291 m_iopt = 1; |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
292 } |
4049 | 293 |
22988
cd33c785e80e
put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22960
diff
changeset
|
294 F77_INT sl = octave::to_f77_int (step_limit ()); |
4049 | 295 if (sl > 0) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
296 { |
30046
b3717fd85e49
maint: use "m_" prefix for member variables ODE/DAE classes in liboctave/numeric.
Rik <rik@octave.org>
parents:
29358
diff
changeset
|
297 m_iwork(5) = sl; |
b3717fd85e49
maint: use "m_" prefix for member variables ODE/DAE classes in liboctave/numeric.
Rik <rik@octave.org>
parents:
29358
diff
changeset
|
298 m_iopt = 1; |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
299 } |
4049 | 300 |
30046
b3717fd85e49
maint: use "m_" prefix for member variables ODE/DAE classes in liboctave/numeric.
Rik <rik@octave.org>
parents:
29358
diff
changeset
|
301 LSODE_options::m_reset = false; |
3 | 302 } |
303 | |
30067
fc509c3c445a
maint: use "m_" prefix for member variables in base-de.h and base-dae.h
Rik <rik@octave.org>
parents:
30047
diff
changeset
|
304 double *px = m_x.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
|
305 |
30046
b3717fd85e49
maint: use "m_" prefix for member variables ODE/DAE classes in liboctave/numeric.
Rik <rik@octave.org>
parents:
29358
diff
changeset
|
306 double *pabs_tol = m_abs_tol.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
|
307 |
30046
b3717fd85e49
maint: use "m_" prefix for member variables ODE/DAE classes in liboctave/numeric.
Rik <rik@octave.org>
parents:
29358
diff
changeset
|
308 F77_INT *piwork = m_iwork.fortran_vec (); |
b3717fd85e49
maint: use "m_" prefix for member variables ODE/DAE classes in liboctave/numeric.
Rik <rik@octave.org>
parents:
29358
diff
changeset
|
309 double *prwork = m_rwork.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
|
310 |
30067
fc509c3c445a
maint: use "m_" prefix for member variables in base-de.h and base-dae.h
Rik <rik@octave.org>
parents:
30047
diff
changeset
|
311 F77_INT tmp_istate = octave::to_f77_int (m_istate); |
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
|
312 |
30067
fc509c3c445a
maint: use "m_" prefix for member variables in base-de.h and base-dae.h
Rik <rik@octave.org>
parents:
30047
diff
changeset
|
313 F77_XFCN (dlsode, DLSODE, (lsode_f, nn, px, m_t, tout, m_itol, m_rel_tol, |
30046
b3717fd85e49
maint: use "m_" prefix for member variables ODE/DAE classes in liboctave/numeric.
Rik <rik@octave.org>
parents:
29358
diff
changeset
|
314 pabs_tol, m_itask, tmp_istate, m_iopt, prwork, |
b3717fd85e49
maint: use "m_" prefix for member variables ODE/DAE classes in liboctave/numeric.
Rik <rik@octave.org>
parents:
29358
diff
changeset
|
315 m_lrw, piwork, m_liw, lsode_j, m_method_flag)); |
3 | 316 |
30067
fc509c3c445a
maint: use "m_" prefix for member variables in base-de.h and base-dae.h
Rik <rik@octave.org>
parents:
30047
diff
changeset
|
317 m_istate = tmp_istate; |
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
|
318 |
30067
fc509c3c445a
maint: use "m_" prefix for member variables in base-de.h and base-dae.h
Rik <rik@octave.org>
parents:
30047
diff
changeset
|
319 switch (m_istate) |
3 | 320 { |
7482
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7231
diff
changeset
|
321 case 1: // prior to initial integration step. |
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7231
diff
changeset
|
322 case 2: // lsode was successful. |
30067
fc509c3c445a
maint: use "m_" prefix for member variables in base-de.h and base-dae.h
Rik <rik@octave.org>
parents:
30047
diff
changeset
|
323 retval = m_x; |
fc509c3c445a
maint: use "m_" prefix for member variables in base-de.h and base-dae.h
Rik <rik@octave.org>
parents:
30047
diff
changeset
|
324 m_t = tout; |
7482
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7231
diff
changeset
|
325 break; |
3996 | 326 |
7482
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7231
diff
changeset
|
327 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
|
328 case -2: // excess accuracy requested (tolerances too small). |
8807
401d54a83690
use 'invalid', not 'illegal'
John W. Eaton <jwe@octave.org>
parents:
7482
diff
changeset
|
329 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
|
330 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
|
331 case -5: // repeated convergence failures (perhaps bad Jacobian |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
332 // 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
|
333 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
|
334 // 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
|
335 case -13: // return requested in user-supplied function. |
30067
fc509c3c445a
maint: use "m_" prefix for member variables in base-de.h and base-dae.h
Rik <rik@octave.org>
parents:
30047
diff
changeset
|
336 m_integration_error = true; |
7482
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7231
diff
changeset
|
337 break; |
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7231
diff
changeset
|
338 |
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7231
diff
changeset
|
339 default: |
30067
fc509c3c445a
maint: use "m_" prefix for member variables in base-de.h and base-dae.h
Rik <rik@octave.org>
parents:
30047
diff
changeset
|
340 m_integration_error = true; |
7482
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7231
diff
changeset
|
341 (*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
|
342 ("unrecognized value of istate (= %" OCTAVE_IDX_TYPE_FORMAT ") " |
30067
fc509c3c445a
maint: use "m_" prefix for member variables in base-de.h and base-dae.h
Rik <rik@octave.org>
parents:
30047
diff
changeset
|
343 "returned from lsode", m_istate); |
7482
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7231
diff
changeset
|
344 break; |
3 | 345 } |
346 | |
1945 | 347 return retval; |
3 | 348 } |
349 | |
3959 | 350 std::string |
31771
21f9b34eb893
maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents:
31706
diff
changeset
|
351 LSODE::error_message () const |
3959 | 352 { |
353 std::string retval; | |
354 | |
5765 | 355 std::ostringstream buf; |
30067
fc509c3c445a
maint: use "m_" prefix for member variables in base-de.h and base-dae.h
Rik <rik@octave.org>
parents:
30047
diff
changeset
|
356 buf << m_t; |
5765 | 357 std::string t_curr = buf.str (); |
4042 | 358 |
30067
fc509c3c445a
maint: use "m_" prefix for member variables in base-de.h and base-dae.h
Rik <rik@octave.org>
parents:
30047
diff
changeset
|
359 switch (m_istate) |
3959 | 360 { |
361 case 1: | |
3996 | 362 retval = "prior to initial integration step"; |
3959 | 363 break; |
364 | |
365 case 2: | |
366 retval = "successful exit"; | |
367 break; | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
368 |
3959 | 369 case 3: |
370 retval = "prior to continuation call with modified parameters"; | |
371 break; | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
372 |
3996 | 373 case -1: |
23829
01899bdd2a3a
Eliminate unnecessary std::string ("...") constructor calls when "..." suffices.
Rik <rik@octave.org>
parents:
23807
diff
changeset
|
374 retval = "excess work on this call (t = " + t_curr + |
01899bdd2a3a
Eliminate unnecessary std::string ("...") constructor calls when "..." suffices.
Rik <rik@octave.org>
parents:
23807
diff
changeset
|
375 "; perhaps wrong integration method)"; |
3996 | 376 break; |
377 | |
378 case -2: | |
379 retval = "excess accuracy requested (tolerances too small)"; | |
380 break; | |
381 | |
382 case -3: | |
383 retval = "invalid input detected (see printed message)"; | |
384 break; | |
385 | |
386 case -4: | |
23829
01899bdd2a3a
Eliminate unnecessary std::string ("...") constructor calls when "..." suffices.
Rik <rik@octave.org>
parents:
23807
diff
changeset
|
387 retval = "repeated error test failures (t = " + t_curr + |
01899bdd2a3a
Eliminate unnecessary std::string ("...") constructor calls when "..." suffices.
Rik <rik@octave.org>
parents:
23807
diff
changeset
|
388 "; check all inputs)"; |
3996 | 389 break; |
390 | |
391 case -5: | |
23829
01899bdd2a3a
Eliminate unnecessary std::string ("...") constructor calls when "..." suffices.
Rik <rik@octave.org>
parents:
23807
diff
changeset
|
392 retval = "repeated convergence failures (t = " + t_curr + |
01899bdd2a3a
Eliminate unnecessary std::string ("...") constructor calls when "..." suffices.
Rik <rik@octave.org>
parents:
23807
diff
changeset
|
393 "; perhaps bad Jacobian supplied or wrong choice of integration method or tolerances)"; |
3996 | 394 break; |
395 | |
396 case -6: | |
23829
01899bdd2a3a
Eliminate unnecessary std::string ("...") constructor calls when "..." suffices.
Rik <rik@octave.org>
parents:
23807
diff
changeset
|
397 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
|
398 "; solution component i vanished, and atol or atol(i) == 0)"; |
3996 | 399 break; |
400 | |
401 case -13: | |
4042 | 402 retval = "return requested in user-supplied function (t = " |
23807
336f89b6208b
Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents:
23577
diff
changeset
|
403 + t_curr + ')'; |
3996 | 404 break; |
405 | |
3959 | 406 default: |
407 retval = "unknown error state"; | |
408 break; | |
409 } | |
410 | |
411 return retval; | |
412 } | |
413 | |
3 | 414 Matrix |
1842 | 415 LSODE::do_integrate (const ColumnVector& tout) |
3 | 416 { |
417 Matrix retval; | |
4049 | 418 |
20229
5dfaaaae784f
Deprecate Array::capacity() and Sparse::capacity() for numel() and nzmax().
Carnë Draug <carandraug@octave.org>
parents:
19697
diff
changeset
|
419 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
|
420 F77_INT n = octave::to_f77_int (size ()); |
3 | 421 |
422 if (n_out > 0 && n > 0) | |
423 { | |
424 retval.resize (n_out, n); | |
425 | |
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
|
426 for (F77_INT i = 0; i < n; i++) |
30067
fc509c3c445a
maint: use "m_" prefix for member variables in base-de.h and base-dae.h
Rik <rik@octave.org>
parents:
30047
diff
changeset
|
427 retval.elem (0, i) = m_x.elem (i); |
3 | 428 |
5275 | 429 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
|
430 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
431 ColumnVector x_next = do_integrate (tout.elem (j)); |
258 | 432 |
30067
fc509c3c445a
maint: use "m_" prefix for member variables in base-de.h and base-dae.h
Rik <rik@octave.org>
parents:
30047
diff
changeset
|
433 if (m_integration_error) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
434 return retval; |
258 | 435 |
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
|
436 for (F77_INT i = 0; i < n; i++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
437 retval.elem (j, i) = x_next.elem (i); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
438 } |
3 | 439 } |
440 | |
441 return retval; | |
442 } | |
443 | |
444 Matrix | |
3511 | 445 LSODE::do_integrate (const ColumnVector& tout, const ColumnVector& tcrit) |
3 | 446 { |
447 Matrix retval; | |
4049 | 448 |
20229
5dfaaaae784f
Deprecate Array::capacity() and Sparse::capacity() for numel() and nzmax().
Carnë Draug <carandraug@octave.org>
parents:
19697
diff
changeset
|
449 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
|
450 F77_INT n = octave::to_f77_int (size ()); |
3 | 451 |
452 if (n_out > 0 && n > 0) | |
453 { | |
454 retval.resize (n_out, n); | |
455 | |
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
|
456 for (F77_INT i = 0; i < n; i++) |
30067
fc509c3c445a
maint: use "m_" prefix for member variables in base-de.h and base-dae.h
Rik <rik@octave.org>
parents:
30047
diff
changeset
|
457 retval.elem (0, i) = m_x.elem (i); |
3 | 458 |
20229
5dfaaaae784f
Deprecate Array::capacity() and Sparse::capacity() for numel() and nzmax().
Carnë Draug <carandraug@octave.org>
parents:
19697
diff
changeset
|
459 octave_idx_type n_crit = tcrit.numel (); |
3 | 460 |
461 if (n_crit > 0) | |
10314
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 octave_idx_type i_crit = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
464 octave_idx_type i_out = 1; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
465 double next_crit = tcrit.elem (0); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
466 double next_out; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
467 while (i_out < n_out) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
468 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
469 bool do_restart = false; |
3 | 470 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
471 next_out = tout.elem (i_out); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
472 if (i_crit < n_crit) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
473 next_crit = tcrit.elem (i_crit); |
3 | 474 |
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
|
475 bool save_output = false; |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
476 double t_out; |
3 | 477 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
478 if (next_crit == next_out) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
479 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
480 set_stop_time (next_crit); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
481 t_out = next_out; |
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
|
482 save_output = true; |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
483 i_out++; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
484 i_crit++; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
485 do_restart = true; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
486 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
487 else if (next_crit < next_out) |
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 if (i_crit < n_crit) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
490 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
491 set_stop_time (next_crit); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
492 t_out = next_crit; |
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
|
493 save_output = false; |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
494 i_crit++; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
495 do_restart = true; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
496 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
497 else |
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 clear_stop_time (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
500 t_out = next_out; |
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
|
501 save_output = true; |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
502 i_out++; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
503 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
504 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
505 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
506 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
507 set_stop_time (next_crit); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
508 t_out = next_out; |
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
|
509 save_output = true; |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
510 i_out++; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
511 } |
3 | 512 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
513 ColumnVector x_next = do_integrate (t_out); |
3 | 514 |
30067
fc509c3c445a
maint: use "m_" prefix for member variables in base-de.h and base-dae.h
Rik <rik@octave.org>
parents:
30047
diff
changeset
|
515 if (m_integration_error) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
516 return retval; |
258 | 517 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
518 if (save_output) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
519 { |
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
|
520 for (F77_INT i = 0; i < n; i++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
521 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
|
522 } |
3 | 523 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
524 if (do_restart) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
525 force_restart (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
526 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
527 } |
3 | 528 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
529 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
530 retval = do_integrate (tout); |
258 | 531 |
30067
fc509c3c445a
maint: use "m_" prefix for member variables in base-de.h and base-dae.h
Rik <rik@octave.org>
parents:
30047
diff
changeset
|
532 if (m_integration_error) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
533 return retval; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
534 } |
3 | 535 } |
536 | |
537 return retval; | |
538 } |