GNU Octave  9.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 ../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 
21 static LSODE_options lsode_opts;
22 
23 #define MAX_TOKENS 3
24 
25 struct 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 
35 static 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 
82 static void
83 print_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 
235 static void
236 set_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 
323 static octave_value_list
324 show_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 
420 DEFUN (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})
425 Query or set options for the function @code{lsode}.
426 
427 When called with no arguments, the names of all available options and
428 their current values are displayed.
429 
430 Given one argument, return the value of the option @var{opt}.
431 
432 When called with two arguments, @code{lsode_options} sets the option
433 @var{opt} to value @var{val}.
434 
435 Options include
436 
437 @table @asis
438 @item @qcode{"absolute tolerance"}
439 Absolute tolerance. May be either vector or scalar. If a vector, it
440 must match the dimension of the state vector.
441 
442 @item @qcode{"relative tolerance"}
443 Relative tolerance parameter. Unlike the absolute tolerance, this
444 parameter may only be a scalar.
445 
446 The 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"}
456 A string specifying the method of integration to use to solve the ODE
457 system. Valid values are
458 
459 @table @asis
460 @item @qcode{"adams"}
461 @itemx @qcode{"non-stiff"}
462 No Jacobian used (even if it is available).
463 
464 @item @qcode{"bdf"}
465 @itemx @qcode{"stiff"}
466 Use stiff backward differentiation formula (BDF) method. If a
467 function to compute the Jacobian is not supplied, @code{lsode} will
468 compute a finite difference approximation of the Jacobian matrix.
469 @end table
470 
471 @item @qcode{"initial step size"}
472 The step size to be attempted on the first step (default is determined
473 automatically).
474 
475 @item @qcode{"maximum order"}
476 Restrict the maximum order of the solution method. If using the Adams
477 method, this option must be between 1 and 12. Otherwise, it must be
478 between 1 and 5, inclusive.
479 
480 @item @qcode{"maximum step size"}
481 Setting the maximum stepsize will avoid passing over very large
482 regions (default is not specified).
483 
484 @item @qcode{"minimum step size"}
485 The minimum absolute step size allowed (default is 0).
486 
487 @item @qcode{"step limit"}
488 Maximum number of steps allowed (default is 100000).
489 
490 @item @qcode{"jacobian type"}
491 A string specifying the type of Jacobian used with the stiff backward
492 differentiation formula (BDF) integration method. Valid values are
493 
494 @table @asis
495 @item @qcode{"full"}
496 The default. All partial derivatives are approximated or used from the
497 user-supplied Jacobian function.
498 
499 @item @qcode{"banded"}
500 Only the diagonal and the number of lower and upper subdiagonals specified by
501 the options @qcode{"lower jacobian subdiagonals"} and @qcode{"upper jacobian
502 subdiagonals"}, respectively, are approximated or used from the user-supplied
503 Jacobian function. A user-supplied Jacobian function may set all other
504 partial derivatives to arbitrary values.
505 
506 @item @qcode{"diagonal"}
507 If a Jacobian function is supplied by the user, this setting has no effect.
508 A Jacobian approximated by @code{lsode} is restricted to the diagonal, where
509 each partial derivative is computed by applying a finite change to all
510 elements of the state together; if the real Jacobian is indeed always diagonal,
511 this has the same effect as applying the finite change only to the respective
512 element of the state, but is more efficient.
513 @end table
514 
515 @item @qcode{"lower jacobian subdiagonals"}
516 Number 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"}
520 Number 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 
550 OCTAVE_END_NAMESPACE(octave)
551 
#define MAX_TOKENS
Definition: LSODE-opts.cc:23
octave_idx_type numel() const
Number of elements in the array.
Definition: Array.h:414
void set_absolute_tolerance(double val)
Definition: LSODE-opts.h:109
std::string jacobian_type() const
Definition: LSODE-opts.h:188
void set_integration_method(const std::string &val)
Definition: LSODE-opts.h:122
double minimum_step_size() const
Definition: LSODE-opts.h:182
octave_idx_type lower_jacobian_subdiagonals() const
Definition: LSODE-opts.h:191
void set_jacobian_type(const std::string &val)
Definition: LSODE-opts.h:149
void set_upper_jacobian_subdiagonals(octave_idx_type val)
Definition: LSODE-opts.h:162
void set_lower_jacobian_subdiagonals(octave_idx_type val)
Definition: LSODE-opts.h:159
void set_minimum_step_size(double val)
Definition: LSODE-opts.h:143
std::string integration_method() const
Definition: LSODE-opts.h:170
void set_initial_step_size(double val)
Definition: LSODE-opts.h:134
octave_idx_type step_limit() const
Definition: LSODE-opts.h:185
octave_idx_type maximum_order() const
Definition: LSODE-opts.h:176
octave_idx_type upper_jacobian_subdiagonals() const
Definition: LSODE-opts.h:194
double relative_tolerance() const
Definition: LSODE-opts.h:167
void set_step_limit(octave_idx_type val)
Definition: LSODE-opts.h:146
double maximum_step_size() const
Definition: LSODE-opts.h:179
double initial_step_size() const
Definition: LSODE-opts.h:173
void set_relative_tolerance(double val)
Definition: LSODE-opts.h:119
Array< double > absolute_tolerance() const
Definition: LSODE-opts.h:164
void set_maximum_order(octave_idx_type val)
Definition: LSODE-opts.h:137
void set_maximum_step_size(double val)
Definition: LSODE-opts.h:140
Definition: dMatrix.h:42
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:974
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:841
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
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:1063
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:428
#define octave_stdout
Definition: pager.h:309
void octave_print_internal(std::ostream &os, const float_display_format &fmt, bool d, bool pr_as_read_syntax)
Definition: pr-output.cc:1761