1841
|
1 /* |
|
2 |
2847
|
3 Copyright (C) 1996, 1997 John W. Eaton |
1841
|
4 |
|
5 This file is part of Octave. |
|
6 |
|
7 Octave is free software; you can redistribute it and/or modify it |
|
8 under the terms of the GNU General Public License as published by the |
|
9 Free Software Foundation; either version 2, or (at your option) any |
|
10 later version. |
|
11 |
|
12 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
15 for more details. |
|
16 |
|
17 You should have received a copy of the GNU General Public License |
|
18 along with Octave; see the file COPYING. If not, write to the Free |
|
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
20 |
|
21 */ |
|
22 |
|
23 #if !defined (octave_LSODE_h) |
|
24 #define octave_LSODE_h 1 |
|
25 |
|
26 #if defined (__GNUG__) |
|
27 #pragma interface |
|
28 #endif |
|
29 |
1872
|
30 #include <cfloat> |
1867
|
31 #include <cmath> |
|
32 |
1841
|
33 #include "ODE.h" |
|
34 |
1867
|
35 class |
|
36 LSODE_options |
1841
|
37 { |
1867
|
38 public: |
|
39 |
|
40 LSODE_options (void) { init (); } |
1841
|
41 |
1867
|
42 LSODE_options (const LSODE_options& opt) { copy (opt); } |
|
43 |
|
44 LSODE_options& operator = (const LSODE_options& opt) |
|
45 { |
|
46 if (this != &opt) |
|
47 copy (opt); |
1841
|
48 |
1867
|
49 return *this; |
|
50 } |
|
51 |
|
52 ~LSODE_options (void) { } |
1841
|
53 |
1867
|
54 void init (void) |
|
55 { |
3945
|
56 double sqrt_eps = ::sqrt (DBL_EPSILON); |
3952
|
57 x_absolute_tolerance.resize (1); |
|
58 x_absolute_tolerance(0) = sqrt_eps; |
1867
|
59 x_initial_step_size = -1.0; |
3955
|
60 x_integration_method = "stiff"; |
1867
|
61 x_maximum_step_size = -1.0; |
|
62 x_minimum_step_size = 0.0; |
3945
|
63 x_relative_tolerance = sqrt_eps; |
3189
|
64 |
|
65 // This is consistent with earlier versions of Octave, and is |
|
66 // much larger than the default of 500 specified in the LSODE |
|
67 // sources. |
|
68 x_step_limit = 100000; |
1867
|
69 } |
1841
|
70 |
1867
|
71 void copy (const LSODE_options& opt) |
|
72 { |
|
73 x_absolute_tolerance = opt.x_absolute_tolerance; |
|
74 x_initial_step_size = opt.x_initial_step_size; |
3955
|
75 x_integration_method = opt.x_integration_method; |
1867
|
76 x_maximum_step_size = opt.x_maximum_step_size; |
|
77 x_minimum_step_size = opt.x_minimum_step_size; |
|
78 x_relative_tolerance = opt.x_relative_tolerance; |
2850
|
79 x_step_limit = opt.x_step_limit; |
1867
|
80 } |
1841
|
81 |
1867
|
82 void set_default_options (void) { init (); } |
|
83 |
|
84 void set_absolute_tolerance (double val) |
3952
|
85 { |
|
86 x_absolute_tolerance.resize (1); |
|
87 x_absolute_tolerance(0) = (val > 0.0) ? val : ::sqrt (DBL_EPSILON); |
|
88 } |
|
89 |
|
90 void set_absolute_tolerance (const Array<double>& val) |
|
91 { x_absolute_tolerance = val; } |
1867
|
92 |
|
93 void set_initial_step_size (double val) |
|
94 { x_initial_step_size = (val >= 0.0) ? val : -1.0; } |
|
95 |
3955
|
96 void set_integration_method (const std::string& val); |
|
97 |
1867
|
98 void set_maximum_step_size (double val) |
|
99 { x_maximum_step_size = (val >= 0.0) ? val : -1.0; } |
1841
|
100 |
1867
|
101 void set_minimum_step_size (double val) |
|
102 { x_minimum_step_size = (val >= 0.0) ? val : 0.0; } |
|
103 |
|
104 void set_relative_tolerance (double val) |
|
105 { x_relative_tolerance = (val > 0.0) ? val : ::sqrt (DBL_EPSILON); } |
|
106 |
2850
|
107 void set_step_limit (int val) |
|
108 { x_step_limit = val; } |
|
109 |
3952
|
110 Array<double> absolute_tolerance (void) const |
1867
|
111 { return x_absolute_tolerance; } |
1841
|
112 |
3952
|
113 double initial_step_size (void) const |
1867
|
114 { return x_initial_step_size; } |
|
115 |
3955
|
116 std::string integration_method (void) const |
|
117 { return x_integration_method; } |
|
118 |
3952
|
119 double maximum_step_size (void) const |
1867
|
120 { return x_maximum_step_size; } |
|
121 |
3952
|
122 double minimum_step_size (void) const |
1867
|
123 { return x_minimum_step_size; } |
|
124 |
3952
|
125 double relative_tolerance (void) const |
1867
|
126 { return x_relative_tolerance; } |
|
127 |
3952
|
128 int step_limit (void) const |
2850
|
129 { return x_step_limit; } |
|
130 |
1867
|
131 private: |
1841
|
132 |
3952
|
133 Array<double> x_absolute_tolerance; |
1841
|
134 double x_initial_step_size; |
3955
|
135 std::string x_integration_method; |
1841
|
136 double x_maximum_step_size; |
|
137 double x_minimum_step_size; |
|
138 double x_relative_tolerance; |
2850
|
139 |
|
140 int x_step_limit; |
1841
|
141 }; |
|
142 |
1867
|
143 class |
|
144 LSODE : public ODE, public LSODE_options |
1841
|
145 { |
|
146 public: |
|
147 |
|
148 LSODE (void); |
|
149 |
|
150 LSODE (int n); |
|
151 |
|
152 LSODE (const ColumnVector& state, double time, const ODEFunc& f); |
|
153 |
1945
|
154 ~LSODE (void) { } |
1841
|
155 |
|
156 void force_restart (void); |
|
157 |
|
158 void set_stop_time (double t); |
|
159 void clear_stop_time (void); |
|
160 |
|
161 ColumnVector do_integrate (double t); |
|
162 |
|
163 Matrix do_integrate (const ColumnVector& tout); |
|
164 |
3511
|
165 Matrix do_integrate (const ColumnVector& tout, const ColumnVector& tcrit); |
1841
|
166 |
|
167 private: |
|
168 |
|
169 double stop_time; |
|
170 int stop_time_set; |
|
171 |
|
172 int n; |
|
173 int integration_error; |
|
174 int restart; |
3955
|
175 int method_flag; |
1945
|
176 Array<int> iwork; |
|
177 Array<double> rwork; |
1841
|
178 int istate; |
|
179 int itask; |
3955
|
180 int iopt; |
1841
|
181 int liw; |
|
182 int lrw; |
2343
|
183 int sanity_checked; |
1841
|
184 |
|
185 friend int lsode_f (int *neq, double *t, double *y, double *ydot); |
|
186 |
|
187 friend int lsode_j (int *neq, double *t, double *y, int *ml, int *mu, |
|
188 double *pd, int *nrowpd); |
|
189 }; |
|
190 |
|
191 #endif |
|
192 |
|
193 /* |
|
194 ;;; Local Variables: *** |
|
195 ;;; mode: C++ *** |
|
196 ;;; End: *** |
|
197 */ |