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); |
|
57 x_absolute_tolerance = sqrt_eps; |
1867
|
58 x_initial_step_size = -1.0; |
|
59 x_maximum_step_size = -1.0; |
|
60 x_minimum_step_size = 0.0; |
3945
|
61 x_relative_tolerance = sqrt_eps; |
3189
|
62 |
|
63 // This is consistent with earlier versions of Octave, and is |
|
64 // much larger than the default of 500 specified in the LSODE |
|
65 // sources. |
|
66 x_step_limit = 100000; |
1867
|
67 } |
1841
|
68 |
1867
|
69 void copy (const LSODE_options& opt) |
|
70 { |
|
71 x_absolute_tolerance = opt.x_absolute_tolerance; |
|
72 x_initial_step_size = opt.x_initial_step_size; |
|
73 x_maximum_step_size = opt.x_maximum_step_size; |
|
74 x_minimum_step_size = opt.x_minimum_step_size; |
|
75 x_relative_tolerance = opt.x_relative_tolerance; |
3243
|
76 |
2850
|
77 x_step_limit = opt.x_step_limit; |
1867
|
78 } |
1841
|
79 |
1867
|
80 void set_default_options (void) { init (); } |
|
81 |
|
82 void set_absolute_tolerance (double val) |
3945
|
83 { x_absolute_tolerance = (val > 0.0) ? val : ::sqrt (DBL_EPSILON); } |
1867
|
84 |
|
85 void set_initial_step_size (double val) |
|
86 { x_initial_step_size = (val >= 0.0) ? val : -1.0; } |
|
87 |
|
88 void set_maximum_step_size (double val) |
|
89 { x_maximum_step_size = (val >= 0.0) ? val : -1.0; } |
1841
|
90 |
1867
|
91 void set_minimum_step_size (double val) |
|
92 { x_minimum_step_size = (val >= 0.0) ? val : 0.0; } |
|
93 |
|
94 void set_relative_tolerance (double val) |
|
95 { x_relative_tolerance = (val > 0.0) ? val : ::sqrt (DBL_EPSILON); } |
|
96 |
2850
|
97 void set_step_limit (int val) |
|
98 { x_step_limit = val; } |
|
99 |
1867
|
100 double absolute_tolerance (void) |
|
101 { return x_absolute_tolerance; } |
1841
|
102 |
1867
|
103 double initial_step_size (void) |
|
104 { return x_initial_step_size; } |
|
105 |
|
106 double maximum_step_size (void) |
|
107 { return x_maximum_step_size; } |
|
108 |
|
109 double minimum_step_size (void) |
|
110 { return x_minimum_step_size; } |
|
111 |
|
112 double relative_tolerance (void) |
|
113 { return x_relative_tolerance; } |
|
114 |
2850
|
115 int step_limit (void) |
|
116 { return x_step_limit; } |
|
117 |
1867
|
118 private: |
1841
|
119 |
|
120 double x_absolute_tolerance; |
|
121 double x_initial_step_size; |
|
122 double x_maximum_step_size; |
|
123 double x_minimum_step_size; |
|
124 double x_relative_tolerance; |
2850
|
125 |
|
126 int x_step_limit; |
1841
|
127 }; |
|
128 |
1867
|
129 class |
|
130 LSODE : public ODE, public LSODE_options |
1841
|
131 { |
|
132 public: |
|
133 |
|
134 LSODE (void); |
|
135 |
|
136 LSODE (int n); |
|
137 |
|
138 LSODE (const ColumnVector& state, double time, const ODEFunc& f); |
|
139 |
1945
|
140 ~LSODE (void) { } |
1841
|
141 |
|
142 void force_restart (void); |
|
143 |
|
144 void set_stop_time (double t); |
|
145 void clear_stop_time (void); |
|
146 |
|
147 ColumnVector do_integrate (double t); |
|
148 |
|
149 Matrix do_integrate (const ColumnVector& tout); |
|
150 |
3511
|
151 Matrix do_integrate (const ColumnVector& tout, const ColumnVector& tcrit); |
1841
|
152 |
|
153 private: |
|
154 |
|
155 double stop_time; |
|
156 int stop_time_set; |
|
157 |
|
158 int n; |
|
159 int integration_error; |
|
160 int restart; |
|
161 int method_flag; |
1945
|
162 Array<int> iwork; |
|
163 Array<double> rwork; |
1841
|
164 int istate; |
|
165 int itol; |
|
166 int itask; |
|
167 int iopt; |
|
168 int liw; |
|
169 int lrw; |
2343
|
170 int sanity_checked; |
1841
|
171 |
|
172 friend int lsode_f (int *neq, double *t, double *y, double *ydot); |
|
173 |
|
174 friend int lsode_j (int *neq, double *t, double *y, int *ml, int *mu, |
|
175 double *pd, int *nrowpd); |
|
176 }; |
|
177 |
|
178 #endif |
|
179 |
|
180 /* |
|
181 ;;; Local Variables: *** |
|
182 ;;; mode: C++ *** |
|
183 ;;; End: *** |
|
184 */ |