3990
|
1 /* |
|
2 |
|
3 Copyright (C) 2002 John W. Eaton |
|
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_DASRT_h) |
|
24 #define octave_DASRT_h 1 |
|
25 |
|
26 #if defined (__GNUG__) |
|
27 #pragma interface |
|
28 #endif |
|
29 |
|
30 #include <cfloat> |
|
31 #include <cmath> |
|
32 |
|
33 #include "DAERT.h" |
|
34 |
|
35 class |
|
36 DASRT_options |
|
37 { |
|
38 public: |
|
39 |
|
40 DASRT_options (void) { init (); } |
|
41 |
|
42 DASRT_options (const DASRT_options& opt) { copy (opt); } |
|
43 |
|
44 DASRT_options& operator = (const DASRT_options& opt) |
|
45 { |
|
46 if (this != &opt) |
|
47 copy (opt); |
|
48 |
|
49 return *this; |
|
50 } |
|
51 |
|
52 ~DASRT_options (void) { } |
|
53 |
|
54 void init (void) |
|
55 { |
|
56 double sqrt_eps = ::sqrt (DBL_EPSILON); |
|
57 x_absolute_tolerance = sqrt_eps; |
|
58 x_initial_step_size = -1.0; |
|
59 x_maximum_step_size = -1.0; |
|
60 x_minimum_step_size = 0.0; |
|
61 x_relative_tolerance = sqrt_eps; |
|
62 x_step_limit = -1; |
|
63 } |
|
64 |
|
65 void copy (const DASRT_options& opt) |
|
66 { |
|
67 x_absolute_tolerance = opt.x_absolute_tolerance; |
|
68 x_initial_step_size = opt.x_initial_step_size; |
|
69 x_maximum_step_size = opt.x_maximum_step_size; |
|
70 x_minimum_step_size = opt.x_minimum_step_size; |
|
71 x_relative_tolerance = opt.x_relative_tolerance; |
|
72 x_step_limit = opt.x_step_limit; |
|
73 } |
|
74 |
|
75 void set_default_options (void) { init (); } |
|
76 |
|
77 void set_absolute_tolerance (double val) |
|
78 { x_absolute_tolerance = (val > 0.0) ? val : ::sqrt (DBL_EPSILON); } |
|
79 |
|
80 void set_initial_step_size (double val) |
|
81 { x_initial_step_size = (val >= 0.0) ? val : -1.0; } |
|
82 |
|
83 void set_maximum_step_size (double val) |
|
84 { x_maximum_step_size = (val >= 0.0) ? val : -1.0; } |
|
85 |
|
86 void set_minimum_step_size (double val) |
|
87 { x_minimum_step_size = (val >= 0.0) ? val : 0.0; } |
|
88 |
|
89 void set_relative_tolerance (double val) |
|
90 { x_relative_tolerance = (val > 0.0) ? val : ::sqrt (DBL_EPSILON); } |
|
91 |
|
92 void set_step_limit (int val) |
|
93 { x_step_limit = (val >= 0) ? val : -1; } |
|
94 |
|
95 double absolute_tolerance (void) { return x_absolute_tolerance; } |
|
96 |
|
97 double initial_step_size (void) { return x_initial_step_size; } |
|
98 |
|
99 double maximum_step_size (void) { return x_maximum_step_size; } |
|
100 |
|
101 double minimum_step_size (void) { return x_minimum_step_size; } |
|
102 |
|
103 double relative_tolerance (void) { return x_relative_tolerance; } |
|
104 |
|
105 int step_limit (void) { return x_step_limit; } |
|
106 |
|
107 private: |
|
108 |
|
109 double x_absolute_tolerance; |
|
110 double x_initial_step_size; |
|
111 double x_maximum_step_size; |
|
112 double x_minimum_step_size; |
|
113 double x_relative_tolerance; |
|
114 int x_step_limit; |
|
115 }; |
|
116 |
|
117 class |
|
118 DASRT_result |
|
119 { |
|
120 public: |
|
121 |
|
122 DASRT_result (void) { } |
|
123 |
|
124 DASRT_result (const Matrix& xx, const Matrix& xxdot, const ColumnVector& tt) |
|
125 : x (xx), xdot (xxdot), t (tt) { } |
|
126 |
|
127 DASRT_result (const DASRT_result& r) |
|
128 : x (r.x), xdot (r.xdot), t (r.t) { } |
|
129 |
|
130 DASRT_result& operator = (const DASRT_result& r) |
|
131 { |
|
132 if (this != &r) |
|
133 { |
|
134 x = r.x; |
|
135 xdot = r.xdot; |
|
136 t = r.t; |
|
137 } |
|
138 return *this; |
|
139 } |
|
140 |
|
141 ~DASRT_result (void) { } |
|
142 |
|
143 Matrix state (void) const { return x; } |
|
144 Matrix deriv (void) const { return xdot; } |
|
145 ColumnVector times (void) const { return t; } |
|
146 |
|
147 private: |
|
148 |
|
149 Matrix x; |
|
150 Matrix xdot; |
|
151 ColumnVector t; |
|
152 }; |
|
153 |
|
154 class |
|
155 DASRT : public DAERT, public DASRT_options |
|
156 { |
|
157 public: |
|
158 |
|
159 DASRT (void); |
|
160 |
|
161 DASRT (const int& ng, const ColumnVector& x, const ColumnVector& xdot, |
|
162 double time, DAERTFunc& f); |
|
163 |
|
164 ~DASRT (void) { } |
|
165 |
|
166 void force_restart (void); |
|
167 |
|
168 void set_stop_time (double t); |
|
169 void clear_stop_time (void); |
|
170 void set_ng (int the_ng); |
|
171 int get_ng (void); |
|
172 |
|
173 DASRT_result integrate (const ColumnVector& tout); |
|
174 |
|
175 DASRT_result integrate (const ColumnVector& tout, |
|
176 const ColumnVector& tcrit); |
|
177 |
|
178 private: |
|
179 |
|
180 bool initialized; |
|
181 |
|
182 bool sanity_checked; |
|
183 |
|
184 bool stop_time_set; |
|
185 double stop_time; |
|
186 |
|
187 bool restart; |
|
188 |
|
189 bool integration_error; |
|
190 |
|
191 int liw; |
|
192 int lrw; |
|
193 int idid; |
|
194 int ieform; |
|
195 int lun; |
|
196 |
|
197 int n; |
|
198 int npar; |
|
199 int ng; |
|
200 |
|
201 Array<int> info; |
|
202 Array<int> iwork; |
|
203 Array<int> ipar; |
|
204 Array<int> jroot; |
|
205 |
|
206 Array<double> rwork; |
|
207 Array<double> rpar; |
|
208 |
|
209 Matrix y; |
|
210 Matrix ydot; |
|
211 |
|
212 double abs_tol; |
|
213 double rel_tol; |
|
214 |
|
215 double *py; |
|
216 double *pydot; |
|
217 int *pinfo; |
|
218 int *piwork; |
|
219 double *prwork; |
|
220 double *prpar; |
|
221 int *pipar; |
|
222 int *pjroot; |
|
223 |
|
224 void init_work_size (int); |
|
225 |
|
226 void integrate (double t); |
|
227 }; |
|
228 |
|
229 #endif |
|
230 |
|
231 /* |
|
232 ;;; Local Variables: *** |
|
233 ;;; mode: C++ *** |
|
234 ;;; End: *** |
|
235 */ |