GNU Octave 7.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
LSODE-opts.cc
Go to the documentation of this file.
1// DO NOT EDIT!
2// Generated automatically from /home/jwe/src/octave-stable/liboctave/numeric/LSODE-opts.in.
3
4// This file should not include config.h. It is only included in other
5// C++ source files that should have included config.h before including
6// this file.
7
8#include <iomanip>
9#include <ostream>
10#include <sstream>
11
12#include "LSODE-opts.h"
13
14#include "defun.h"
15#include "pr-output.h"
16
17#include "ovl.h"
18#include "utils.h"
19#include "pager.h"
20
22
23#define MAX_TOKENS 3
24
26{
27 const char *keyword;
28 const char *kw_tok[MAX_TOKENS + 1];
31};
32
33#define NUM_OPTIONS 8
34
36{
37 { "absolute tolerance",
38 { "absolute", "tolerance", nullptr, nullptr, },
39 { 1, 0, 0, 0, }, 1, },
40
41 { "relative tolerance",
42 { "relative", "tolerance", nullptr, nullptr, },
43 { 1, 0, 0, 0, }, 1, },
44
45 { "integration method",
46 { "integration", "method", nullptr, nullptr, },
47 { 3, 0, 0, 0, }, 1, },
48
49 { "initial step size",
50 { "initial", "step", "size", nullptr, },
51 { 3, 0, 0, 0, }, 1, },
52
53 { "maximum order",
54 { "maximum", "order", nullptr, nullptr, },
55 { 2, 1, 0, 0, }, 2, },
56
57 { "maximum step size",
58 { "maximum", "step", "size", nullptr, },
59 { 2, 1, 0, 0, }, 2, },
60
61 { "minimum step size",
62 { "minimum", "step", "size", nullptr, },
63 { 2, 0, 0, 0, }, 1, },
64
65 { "step limit",
66 { "step", "limit", nullptr, nullptr, },
67 { 1, 0, 0, 0, }, 1, },
68};
69
70static void
71print_LSODE_options (std::ostream& os)
72{
73 std::ostringstream buf;
74
75 os << "\n"
76 << "Options for LSODE include:\n\n"
77 << " keyword value\n"
78 << " ------- -----\n";
79
81
82 {
83 os << " "
84 << std::setiosflags (std::ios::left) << std::setw (50)
85 << list[0].keyword
86 << std::resetiosflags (std::ios::left)
87 << " ";
88
89 Array<double> val = lsode_opts.absolute_tolerance ();
90
91 if (val.numel () == 1)
92 {
93 os << val(0) << "\n";
94 }
95 else
96 {
97 os << "\n\n";
98 Matrix tmp = Matrix (ColumnVector (val));
99 octave_print_internal (os, tmp, false, 2);
100 os << "\n\n";
101 }
102 }
103
104 {
105 os << " "
106 << std::setiosflags (std::ios::left) << std::setw (50)
107 << list[1].keyword
108 << std::resetiosflags (std::ios::left)
109 << " ";
110
111 double val = lsode_opts.relative_tolerance ();
112
113 os << val << "\n";
114 }
115
116 {
117 os << " "
118 << std::setiosflags (std::ios::left) << std::setw (50)
119 << list[2].keyword
120 << std::resetiosflags (std::ios::left)
121 << " ";
122
123 os << lsode_opts.integration_method () << "\n";
124 }
125
126 {
127 os << " "
128 << std::setiosflags (std::ios::left) << std::setw (50)
129 << list[3].keyword
130 << std::resetiosflags (std::ios::left)
131 << " ";
132
133 double val = lsode_opts.initial_step_size ();
134
135 os << val << "\n";
136 }
137
138 {
139 os << " "
140 << std::setiosflags (std::ios::left) << std::setw (50)
141 << list[4].keyword
142 << std::resetiosflags (std::ios::left)
143 << " ";
144
145 int val = lsode_opts.maximum_order ();
146
147 os << val << "\n";
148 }
149
150 {
151 os << " "
152 << std::setiosflags (std::ios::left) << std::setw (50)
153 << list[5].keyword
154 << std::resetiosflags (std::ios::left)
155 << " ";
156
157 double val = lsode_opts.maximum_step_size ();
158
159 os << val << "\n";
160 }
161
162 {
163 os << " "
164 << std::setiosflags (std::ios::left) << std::setw (50)
165 << list[6].keyword
166 << std::resetiosflags (std::ios::left)
167 << " ";
168
169 double val = lsode_opts.minimum_step_size ();
170
171 os << val << "\n";
172 }
173
174 {
175 os << " "
176 << std::setiosflags (std::ios::left) << std::setw (50)
177 << list[7].keyword
178 << std::resetiosflags (std::ios::left)
179 << " ";
180
181 int val = lsode_opts.step_limit ();
182
183 os << val << "\n";
184 }
185
186 os << "\n";
187}
188
189static void
190set_LSODE_options (const std::string& keyword, const octave_value& val)
191{
193
194 if (octave::keyword_almost_match (list[0].kw_tok, list[0].min_len,
195 keyword, list[0].min_toks_to_match, MAX_TOKENS))
196 {
197 Array<double> tmp = val.vector_value ();
198
199 lsode_opts.set_absolute_tolerance (tmp);
200 }
201 else if (octave::keyword_almost_match (list[1].kw_tok, list[1].min_len,
202 keyword, list[1].min_toks_to_match, MAX_TOKENS))
203 {
204 double tmp = val.double_value ();
205
206 lsode_opts.set_relative_tolerance (tmp);
207 }
208 else if (octave::keyword_almost_match (list[2].kw_tok, list[2].min_len,
209 keyword, list[2].min_toks_to_match, MAX_TOKENS))
210 {
211 std::string tmp = val.string_value ();
212
213 lsode_opts.set_integration_method (tmp);
214 }
215 else if (octave::keyword_almost_match (list[3].kw_tok, list[3].min_len,
216 keyword, list[3].min_toks_to_match, MAX_TOKENS))
217 {
218 double tmp = val.double_value ();
219
220 lsode_opts.set_initial_step_size (tmp);
221 }
222 else if (octave::keyword_almost_match (list[4].kw_tok, list[4].min_len,
223 keyword, list[4].min_toks_to_match, MAX_TOKENS))
224 {
225 int tmp = val.int_value ();
226
227 lsode_opts.set_maximum_order (tmp);
228 }
229 else if (octave::keyword_almost_match (list[5].kw_tok, list[5].min_len,
230 keyword, list[5].min_toks_to_match, MAX_TOKENS))
231 {
232 double tmp = val.double_value ();
233
234 lsode_opts.set_maximum_step_size (tmp);
235 }
236 else if (octave::keyword_almost_match (list[6].kw_tok, list[6].min_len,
237 keyword, list[6].min_toks_to_match, MAX_TOKENS))
238 {
239 double tmp = val.double_value ();
240
241 lsode_opts.set_minimum_step_size (tmp);
242 }
243 else if (octave::keyword_almost_match (list[7].kw_tok, list[7].min_len,
244 keyword, list[7].min_toks_to_match, MAX_TOKENS))
245 {
246 int tmp = val.int_value ();
247
248 lsode_opts.set_step_limit (tmp);
249 }
250 else
251 {
252 warning ("lsode_options: no match for `%s'", keyword.c_str ());
253 }
254}
255
257show_LSODE_options (const std::string& keyword)
258{
259 octave_value retval;
260
262
263 if (octave::keyword_almost_match (list[0].kw_tok, list[0].min_len,
264 keyword, list[0].min_toks_to_match, MAX_TOKENS))
265 {
266 Array<double> val = lsode_opts.absolute_tolerance ();
267
268 if (val.numel () == 1)
269 {
270 retval = val(0);
271 }
272 else
273 {
274 retval = ColumnVector (val);
275 }
276 }
277 else if (octave::keyword_almost_match (list[1].kw_tok, list[1].min_len,
278 keyword, list[1].min_toks_to_match, MAX_TOKENS))
279 {
280 double val = lsode_opts.relative_tolerance ();
281
282 retval = val;
283 }
284 else if (octave::keyword_almost_match (list[2].kw_tok, list[2].min_len,
285 keyword, list[2].min_toks_to_match, MAX_TOKENS))
286 {
287 retval = lsode_opts.integration_method ();
288 }
289 else if (octave::keyword_almost_match (list[3].kw_tok, list[3].min_len,
290 keyword, list[3].min_toks_to_match, MAX_TOKENS))
291 {
292 double val = lsode_opts.initial_step_size ();
293
294 retval = val;
295 }
296 else if (octave::keyword_almost_match (list[4].kw_tok, list[4].min_len,
297 keyword, list[4].min_toks_to_match, MAX_TOKENS))
298 {
299 int val = lsode_opts.maximum_order ();
300
301 retval = static_cast<double> (val);
302 }
303 else if (octave::keyword_almost_match (list[5].kw_tok, list[5].min_len,
304 keyword, list[5].min_toks_to_match, MAX_TOKENS))
305 {
306 double val = lsode_opts.maximum_step_size ();
307
308 retval = val;
309 }
310 else if (octave::keyword_almost_match (list[6].kw_tok, list[6].min_len,
311 keyword, list[6].min_toks_to_match, MAX_TOKENS))
312 {
313 double val = lsode_opts.minimum_step_size ();
314
315 retval = val;
316 }
317 else if (octave::keyword_almost_match (list[7].kw_tok, list[7].min_len,
318 keyword, list[7].min_toks_to_match, MAX_TOKENS))
319 {
320 int val = lsode_opts.step_limit ();
321
322 retval = static_cast<double> (val);
323 }
324 else
325 {
326 warning ("lsode_options: no match for `%s'", keyword.c_str ());
327 }
328
329 return retval;
330}
331
332OCTAVE_NAMESPACE_BEGIN
333
334DEFUN (lsode_options, args, ,
335 doc: /* -*- texinfo -*-
336@deftypefn {} {} lsode_options ()
337@deftypefnx {} {val =} lsode_options (@var{opt})
338@deftypefnx {} {} lsode_options (@var{opt}, @var{val})
339Query or set options for the function @code{lsode}.
340
341When called with no arguments, the names of all available options and
342their current values are displayed.
343
344Given one argument, return the value of the option @var{opt}.
345
346When called with two arguments, @code{lsode_options} sets the option
347@var{opt} to value @var{val}.
348
349Options include
350
351@table @asis
352@item @qcode{"absolute tolerance"}
353Absolute tolerance. May be either vector or scalar. If a vector, it
354must match the dimension of the state vector.
355
356@item @qcode{"relative tolerance"}
357Relative tolerance parameter. Unlike the absolute tolerance, this
358parameter may only be a scalar.
359
360The local error test applied at each integration step is
361
362@example
363@group
364 abs (local error in x(i)) <= ...
365 rtol * abs (y(i)) + atol(i)
366@end group
367@end example
368
369@item @qcode{"integration method"}
370A string specifying the method of integration to use to solve the ODE
371system. Valid values are
372
373@table @asis
374@item @qcode{"adams"}
375@itemx @qcode{"non-stiff"}
376No Jacobian used (even if it is available).
377
378@item @qcode{"bdf"}
379@itemx @qcode{"stiff"}
380Use stiff backward differentiation formula (BDF) method. If a
381function to compute the Jacobian is not supplied, @code{lsode} will
382compute a finite difference approximation of the Jacobian matrix.
383@end table
384
385@item @qcode{"initial step size"}
386The step size to be attempted on the first step (default is determined
387automatically).
388
389@item @qcode{"maximum order"}
390Restrict the maximum order of the solution method. If using the Adams
391method, this option must be between 1 and 12. Otherwise, it must be
392between 1 and 5, inclusive.
393
394@item @qcode{"maximum step size"}
395Setting the maximum stepsize will avoid passing over very large
396regions (default is not specified).
397
398@item @qcode{"minimum step size"}
399The minimum absolute step size allowed (default is 0).
400
401@item @qcode{"step limit"}
402Maximum number of steps allowed (default is 100000).
403@end table
404@end deftypefn */)
405{
406 octave_value_list retval;
407
408 int nargin = args.length ();
409
410 if (nargin > 2)
411 print_usage ();
412
413 if (nargin == 0)
414 {
416 }
417 else
418 {
419 std::string keyword = args(0).xstring_value ("lsode_options: expecting keyword as first argument");
420
421 if (nargin == 1)
422 retval = show_LSODE_options (keyword);
423 else
424 set_LSODE_options (keyword, args(1));
425 }
426
427 return retval;
428}
429
430OCTAVE_NAMESPACE_END
431
#define MAX_TOKENS
Definition: LSODE-opts.cc:23
static LSODE_options lsode_opts
Definition: LSODE-opts.cc:21
static LSODE_options_struct LSODE_options_table[]
Definition: LSODE-opts.cc:35
static octave_value_list show_LSODE_options(const std::string &keyword)
Definition: LSODE-opts.cc:257
static void print_LSODE_options(std::ostream &os)
Definition: LSODE-opts.cc:71
static void set_LSODE_options(const std::string &keyword, const octave_value &val)
Definition: LSODE-opts.cc:190
octave_idx_type numel(void) const
Number of elements in the array.
Definition: Array.h:411
Definition: dMatrix.h:42
octave_idx_type length(void) const
Definition: ovl.h:113
OCTINTERP_API Array< double > vector_value(bool frc_str_conv=false, bool frc_vec_conv=false) const
int int_value(bool req_int=false, bool frc_str_conv=false) const
Definition: ov.h:857
std::string string_value(bool force=false) const
Definition: ov.h:1019
double double_value(bool frc_str_conv=false) const
Definition: ov.h:886
OCTINTERP_API void print_usage(void)
Definition: defun-int.h:72
#define DEFUN(name, args_name, nargout_name, doc)
Macro to define a builtin function.
Definition: defun.h:56
void warning(const char *fmt,...)
Definition: error.cc:1055
class OCTAVE_API Matrix
Definition: mx-fwd.h:31
class OCTAVE_API ColumnVector
Definition: mx-fwd.h:45
static int left
Definition: randmtzig.cc:193
#define octave_stdout
Definition: pager.h:314
void octave_print_internal(std::ostream &os, const float_display_format &fmt, bool d, bool pr_as_read_syntax)
Definition: pr-output.cc:1762
const char * kw_tok[3+1]
Definition: LSODE-opts.cc:28
const char * keyword
Definition: LSODE-opts.cc:27
int keyword_almost_match(const char *const *std, int *min_len, const std::string &s, int min_toks_to_match, int max_toks)
Definition: utils.cc:422