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