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