GNU Octave 10.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 
Loading...
Searching...
No Matches
LSODE-opts.cc
Go to the documentation of this file.
1// DO NOT EDIT!
2// Generated automatically from ../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
21static LSODE_options lsode_opts;
22
23#define MAX_TOKENS 3
24
25struct LSODE_options_struct
26{
27 const char *keyword;
28 const char *kw_tok[MAX_TOKENS + 1];
29 int min_len[MAX_TOKENS + 1];
30 int min_toks_to_match;
31};
32
33#define NUM_OPTIONS 11
34
35static LSODE_options_struct LSODE_options_table [] =
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 { "jacobian type",
70 { "jacobian", "type", nullptr, nullptr, },
71 { 1, 0, 0, 0, }, 1, },
72
73 { "lower jacobian subdiagonals",
74 { "lower", "jacobian", "subdiagonals", nullptr, },
75 { 1, 0, 0, 0, }, 1, },
76
77 { "upper jacobian subdiagonals",
78 { "upper", "jacobian", "subdiagonals", nullptr, },
79 { 1, 0, 0, 0, }, 1, },
80};
81
82static void
83print_LSODE_options (std::ostream& os)
84{
85 std::ostringstream buf;
86
87 os << "\n"
88 << "Options for LSODE include:\n\n"
89 << " keyword value\n"
90 << " ------- -----\n";
91
92 LSODE_options_struct *list = LSODE_options_table;
93
94 {
95 os << " "
96 << std::setiosflags (std::ios::left) << std::setw (50)
97 << list[0].keyword
98 << std::resetiosflags (std::ios::left)
99 << " ";
100
101 Array<double> val = lsode_opts.absolute_tolerance ();
102
103 if (val.numel () == 1)
104 {
105 os << val(0) << "\n";
106 }
107 else
108 {
109 os << "\n\n";
110 Matrix tmp = Matrix (ColumnVector (val));
111 octave_print_internal (os, tmp, false, 2);
112 os << "\n\n";
113 }
114 }
115
116 {
117 os << " "
118 << std::setiosflags (std::ios::left) << std::setw (50)
119 << list[1].keyword
120 << std::resetiosflags (std::ios::left)
121 << " ";
122
123 double val = lsode_opts.relative_tolerance ();
124
125 os << val << "\n";
126 }
127
128 {
129 os << " "
130 << std::setiosflags (std::ios::left) << std::setw (50)
131 << list[2].keyword
132 << std::resetiosflags (std::ios::left)
133 << " ";
134
135 os << lsode_opts.integration_method () << "\n";
136 }
137
138 {
139 os << " "
140 << std::setiosflags (std::ios::left) << std::setw (50)
141 << list[3].keyword
142 << std::resetiosflags (std::ios::left)
143 << " ";
144
145 double val = lsode_opts.initial_step_size ();
146
147 os << val << "\n";
148 }
149
150 {
151 os << " "
152 << std::setiosflags (std::ios::left) << std::setw (50)
153 << list[4].keyword
154 << std::resetiosflags (std::ios::left)
155 << " ";
156
157 int val = lsode_opts.maximum_order ();
158
159 os << val << "\n";
160 }
161
162 {
163 os << " "
164 << std::setiosflags (std::ios::left) << std::setw (50)
165 << list[5].keyword
166 << std::resetiosflags (std::ios::left)
167 << " ";
168
169 double val = lsode_opts.maximum_step_size ();
170
171 os << val << "\n";
172 }
173
174 {
175 os << " "
176 << std::setiosflags (std::ios::left) << std::setw (50)
177 << list[6].keyword
178 << std::resetiosflags (std::ios::left)
179 << " ";
180
181 double val = lsode_opts.minimum_step_size ();
182
183 os << val << "\n";
184 }
185
186 {
187 os << " "
188 << std::setiosflags (std::ios::left) << std::setw (50)
189 << list[7].keyword
190 << std::resetiosflags (std::ios::left)
191 << " ";
192
193 int val = lsode_opts.step_limit ();
194
195 os << val << "\n";
196 }
197
198 {
199 os << " "
200 << std::setiosflags (std::ios::left) << std::setw (50)
201 << list[8].keyword
202 << std::resetiosflags (std::ios::left)
203 << " ";
204
205 os << lsode_opts.jacobian_type () << "\n";
206 }
207
208 {
209 os << " "
210 << std::setiosflags (std::ios::left) << std::setw (50)
211 << list[9].keyword
212 << std::resetiosflags (std::ios::left)
213 << " ";
214
215 int val = lsode_opts.lower_jacobian_subdiagonals ();
216
217 os << val << "\n";
218 }
219
220 {
221 os << " "
222 << std::setiosflags (std::ios::left) << std::setw (50)
223 << list[10].keyword
224 << std::resetiosflags (std::ios::left)
225 << " ";
226
227 int val = lsode_opts.upper_jacobian_subdiagonals ();
228
229 os << val << "\n";
230 }
231
232 os << "\n";
233}
234
235static void
236set_LSODE_options (const std::string& keyword, const octave_value& val)
237{
238 LSODE_options_struct *list = LSODE_options_table;
239
240 if (octave::keyword_almost_match (list[0].kw_tok, list[0].min_len,
241 keyword, list[0].min_toks_to_match, MAX_TOKENS))
242 {
243 Array<double> tmp = val.vector_value ();
244
245 lsode_opts.set_absolute_tolerance (tmp);
246 }
247 else if (octave::keyword_almost_match (list[1].kw_tok, list[1].min_len,
248 keyword, list[1].min_toks_to_match, MAX_TOKENS))
249 {
250 double tmp = val.double_value ();
251
252 lsode_opts.set_relative_tolerance (tmp);
253 }
254 else if (octave::keyword_almost_match (list[2].kw_tok, list[2].min_len,
255 keyword, list[2].min_toks_to_match, MAX_TOKENS))
256 {
257 std::string tmp = val.string_value ();
258
259 lsode_opts.set_integration_method (tmp);
260 }
261 else if (octave::keyword_almost_match (list[3].kw_tok, list[3].min_len,
262 keyword, list[3].min_toks_to_match, MAX_TOKENS))
263 {
264 double tmp = val.double_value ();
265
266 lsode_opts.set_initial_step_size (tmp);
267 }
268 else if (octave::keyword_almost_match (list[4].kw_tok, list[4].min_len,
269 keyword, list[4].min_toks_to_match, MAX_TOKENS))
270 {
271 int tmp = val.int_value ();
272
273 lsode_opts.set_maximum_order (tmp);
274 }
275 else if (octave::keyword_almost_match (list[5].kw_tok, list[5].min_len,
276 keyword, list[5].min_toks_to_match, MAX_TOKENS))
277 {
278 double tmp = val.double_value ();
279
280 lsode_opts.set_maximum_step_size (tmp);
281 }
282 else if (octave::keyword_almost_match (list[6].kw_tok, list[6].min_len,
283 keyword, list[6].min_toks_to_match, MAX_TOKENS))
284 {
285 double tmp = val.double_value ();
286
287 lsode_opts.set_minimum_step_size (tmp);
288 }
289 else if (octave::keyword_almost_match (list[7].kw_tok, list[7].min_len,
290 keyword, list[7].min_toks_to_match, MAX_TOKENS))
291 {
292 int tmp = val.int_value ();
293
294 lsode_opts.set_step_limit (tmp);
295 }
296 else if (octave::keyword_almost_match (list[8].kw_tok, list[8].min_len,
297 keyword, list[8].min_toks_to_match, MAX_TOKENS))
298 {
299 std::string tmp = val.string_value ();
300
301 lsode_opts.set_jacobian_type (tmp);
302 }
303 else if (octave::keyword_almost_match (list[9].kw_tok, list[9].min_len,
304 keyword, list[9].min_toks_to_match, MAX_TOKENS))
305 {
306 int tmp = val.int_value ();
307
308 lsode_opts.set_lower_jacobian_subdiagonals (tmp);
309 }
310 else if (octave::keyword_almost_match (list[10].kw_tok, list[10].min_len,
311 keyword, list[10].min_toks_to_match, MAX_TOKENS))
312 {
313 int tmp = val.int_value ();
314
315 lsode_opts.set_upper_jacobian_subdiagonals (tmp);
316 }
317 else
318 {
319 warning ("lsode_options: no match for `%s'", keyword.c_str ());
320 }
321}
322
324show_LSODE_options (const std::string& keyword)
325{
326 octave_value retval;
327
328 LSODE_options_struct *list = LSODE_options_table;
329
330 if (octave::keyword_almost_match (list[0].kw_tok, list[0].min_len,
331 keyword, list[0].min_toks_to_match, MAX_TOKENS))
332 {
333 Array<double> val = lsode_opts.absolute_tolerance ();
334
335 if (val.numel () == 1)
336 {
337 retval = val(0);
338 }
339 else
340 {
341 retval = ColumnVector (val);
342 }
343 }
344 else if (octave::keyword_almost_match (list[1].kw_tok, list[1].min_len,
345 keyword, list[1].min_toks_to_match, MAX_TOKENS))
346 {
347 double val = lsode_opts.relative_tolerance ();
348
349 retval = val;
350 }
351 else if (octave::keyword_almost_match (list[2].kw_tok, list[2].min_len,
352 keyword, list[2].min_toks_to_match, MAX_TOKENS))
353 {
354 retval = lsode_opts.integration_method ();
355 }
356 else if (octave::keyword_almost_match (list[3].kw_tok, list[3].min_len,
357 keyword, list[3].min_toks_to_match, MAX_TOKENS))
358 {
359 double val = lsode_opts.initial_step_size ();
360
361 retval = val;
362 }
363 else if (octave::keyword_almost_match (list[4].kw_tok, list[4].min_len,
364 keyword, list[4].min_toks_to_match, MAX_TOKENS))
365 {
366 int val = lsode_opts.maximum_order ();
367
368 retval = static_cast<double> (val);
369 }
370 else if (octave::keyword_almost_match (list[5].kw_tok, list[5].min_len,
371 keyword, list[5].min_toks_to_match, MAX_TOKENS))
372 {
373 double val = lsode_opts.maximum_step_size ();
374
375 retval = val;
376 }
377 else if (octave::keyword_almost_match (list[6].kw_tok, list[6].min_len,
378 keyword, list[6].min_toks_to_match, MAX_TOKENS))
379 {
380 double val = lsode_opts.minimum_step_size ();
381
382 retval = val;
383 }
384 else if (octave::keyword_almost_match (list[7].kw_tok, list[7].min_len,
385 keyword, list[7].min_toks_to_match, MAX_TOKENS))
386 {
387 int val = lsode_opts.step_limit ();
388
389 retval = static_cast<double> (val);
390 }
391 else if (octave::keyword_almost_match (list[8].kw_tok, list[8].min_len,
392 keyword, list[8].min_toks_to_match, MAX_TOKENS))
393 {
394 retval = lsode_opts.jacobian_type ();
395 }
396 else if (octave::keyword_almost_match (list[9].kw_tok, list[9].min_len,
397 keyword, list[9].min_toks_to_match, MAX_TOKENS))
398 {
399 int val = lsode_opts.lower_jacobian_subdiagonals ();
400
401 retval = static_cast<double> (val);
402 }
403 else if (octave::keyword_almost_match (list[10].kw_tok, list[10].min_len,
404 keyword, list[10].min_toks_to_match, MAX_TOKENS))
405 {
406 int val = lsode_opts.upper_jacobian_subdiagonals ();
407
408 retval = static_cast<double> (val);
409 }
410 else
411 {
412 warning ("lsode_options: no match for `%s'", keyword.c_str ());
413 }
414
415 return retval;
416}
417
419
420DEFUN (lsode_options, args, ,
421 doc: /* -*- texinfo -*-
422@deftypefn {} {} lsode_options ()
423@deftypefnx {} {val =} lsode_options (@var{opt})
424@deftypefnx {} {} lsode_options (@var{opt}, @var{val})
425Query or set options for the function @code{lsode}.
426
427When called with no arguments, the names of all available options and
428their current values are displayed.
429
430Given one argument, return the value of the option @var{opt}.
431
432When called with two arguments, @code{lsode_options} sets the option
433@var{opt} to value @var{val}.
434
435Options include
436
437@table @asis
438@item @qcode{"absolute tolerance"}
439Absolute tolerance. May be either vector or scalar. If a vector, it
440must match the dimension of the state vector.
441
442@item @qcode{"relative tolerance"}
443Relative tolerance parameter. Unlike the absolute tolerance, this
444parameter may only be a scalar.
445
446The local error test applied at each integration step is
447
448@example
449@group
450 abs (local error in x(i)) <= ...
451 rtol * abs (y(i)) + atol(i)
452@end group
453@end example
454
455@item @qcode{"integration method"}
456A string specifying the method of integration to use to solve the ODE
457system. Valid values are
458
459@table @asis
460@item @qcode{"adams"}
461@itemx @qcode{"non-stiff"}
462No Jacobian used (even if it is available).
463
464@item @qcode{"bdf"}
465@itemx @qcode{"stiff"}
466Use stiff backward differentiation formula (BDF) method. If a
467function to compute the Jacobian is not supplied, @code{lsode} will
468compute a finite difference approximation of the Jacobian matrix.
469@end table
470
471@item @qcode{"initial step size"}
472The step size to be attempted on the first step (default is determined
473automatically).
474
475@item @qcode{"maximum order"}
476Restrict the maximum order of the solution method. If using the Adams
477method, this option must be between 1 and 12. Otherwise, it must be
478between 1 and 5, inclusive.
479
480@item @qcode{"maximum step size"}
481Setting the maximum stepsize will avoid passing over very large
482regions (default is not specified).
483
484@item @qcode{"minimum step size"}
485The minimum absolute step size allowed (default is 0).
486
487@item @qcode{"step limit"}
488Maximum number of steps allowed (default is 100000).
489
490@item @qcode{"jacobian type"}
491A string specifying the type of Jacobian used with the stiff backward
492differentiation formula (BDF) integration method. Valid values are
493
494@table @asis
495@item @qcode{"full"}
496The default. All partial derivatives are approximated or used from the
497user-supplied Jacobian function.
498
499@item @qcode{"banded"}
500Only the diagonal and the number of lower and upper subdiagonals specified by
501the options @qcode{"lower jacobian subdiagonals"} and @qcode{"upper jacobian
502subdiagonals"}, respectively, are approximated or used from the user-supplied
503Jacobian function. A user-supplied Jacobian function may set all other
504partial derivatives to arbitrary values.
505
506@item @qcode{"diagonal"}
507If a Jacobian function is supplied by the user, this setting has no effect.
508A Jacobian approximated by @code{lsode} is restricted to the diagonal, where
509each partial derivative is computed by applying a finite change to all
510elements of the state together; if the real Jacobian is indeed always diagonal,
511this has the same effect as applying the finite change only to the respective
512element of the state, but is more efficient.
513@end table
514
515@item @qcode{"lower jacobian subdiagonals"}
516Number of lower subdiagonals used if option @qcode{"jacobian type"} is set to
517@qcode{"banded"}. The default is zero.
518
519@item @qcode{"upper jacobian subdiagonals"}
520Number of upper subdiagonals used if option @qcode{"jacobian type"} is set to
521@qcode{"banded"}. The default is zero.
522
523@end table
524@end deftypefn */)
525{
526 octave_value_list retval;
527
528 int nargin = args.length ();
529
530 if (nargin > 2)
531 print_usage ();
532
533 if (nargin == 0)
534 {
535 print_LSODE_options (octave_stdout);
536 }
537 else
538 {
539 std::string keyword = args(0).xstring_value ("lsode_options: expecting keyword as first argument");
540
541 if (nargin == 1)
542 retval = show_LSODE_options (keyword);
543 else
544 set_LSODE_options (keyword, args(1));
545 }
546
547 return retval;
548}
549
550OCTAVE_END_NAMESPACE(octave)
551
#define MAX_TOKENS
Definition LSODE-opts.cc:23
N Dimensional Array with copy-on-write semantics.
Definition Array.h:130
octave_idx_type numel() const
Number of elements in the array.
Definition Array.h:418
int int_value(bool req_int=false, bool frc_str_conv=false) const
Definition ov.h:812
std::string string_value(bool force=false) const
Definition ov.h:983
Array< double > vector_value(bool frc_str_conv=false, bool frc_vec_conv=false) const
octave_idx_type length() const
double double_value(bool frc_str_conv=false) const
Definition ov.h:847
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
void print_usage()
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:1078
#define octave_stdout
Definition pager.h:301
void octave_print_internal(std::ostream &os, const float_display_format &fmt, bool d, bool pr_as_read_syntax)