GNU Octave  6.2.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 
22 
23 #define MAX_TOKENS 3
24 
26 {
27  const char *keyword;
28  const char *kw_tok[MAX_TOKENS + 1];
29  int min_len[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 
70 static void
71 print_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 
189 static void
190 set_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 
256 static octave_value_list
257 show_LSODE_options (const std::string& keyword)
258 {
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 
332 DEFUN (lsode_options, args, ,
333  doc: /* -*- texinfo -*-
334 @deftypefn {} {} lsode_options ()
335 @deftypefnx {} {val =} lsode_options (@var{opt})
336 @deftypefnx {} {} lsode_options (@var{opt}, @var{val})
337 Query or set options for the function @code{lsode}.
338 
339 When called with no arguments, the names of all available options and
340 their current values are displayed.
341 
342 Given one argument, return the value of the option @var{opt}.
343 
344 When called with two arguments, @code{lsode_options} sets the option
345 @var{opt} to value @var{val}.
346 
347 Options include
348 
349 @table @asis
350 @item @qcode{"absolute tolerance"}
351 Absolute tolerance. May be either vector or scalar. If a vector, it
352 must match the dimension of the state vector.
353 
354 @item @qcode{"relative tolerance"}
355 Relative tolerance parameter. Unlike the absolute tolerance, this
356 parameter may only be a scalar.
357 
358 The local error test applied at each integration step is
359 
360 @example
361 @group
362  abs (local error in x(i)) <= ...
363  rtol * abs (y(i)) + atol(i)
364 @end group
365 @end example
366 
367 @item @qcode{"integration method"}
368 A string specifying the method of integration to use to solve the ODE
369 system. Valid values are
370 
371 @table @asis
372 @item @qcode{"adams"}
373 @itemx @qcode{"non-stiff"}
374 No Jacobian used (even if it is available).
375 
376 @item @qcode{"bdf"}
377 @itemx @qcode{"stiff"}
378 Use stiff backward differentiation formula (BDF) method. If a
379 function to compute the Jacobian is not supplied, @code{lsode} will
380 compute a finite difference approximation of the Jacobian matrix.
381 @end table
382 
383 @item @qcode{"initial step size"}
384 The step size to be attempted on the first step (default is determined
385 automatically).
386 
387 @item @qcode{"maximum order"}
388 Restrict the maximum order of the solution method. If using the Adams
389 method, this option must be between 1 and 12. Otherwise, it must be
390 between 1 and 5, inclusive.
391 
392 @item @qcode{"maximum step size"}
393 Setting the maximum stepsize will avoid passing over very large
394 regions (default is not specified).
395 
396 @item @qcode{"minimum step size"}
397 The minimum absolute step size allowed (default is 0).
398 
399 @item @qcode{"step limit"}
400 Maximum number of steps allowed (default is 100000).
401 @end table
402 @end deftypefn */)
403 {
405 
406  int nargin = args.length ();
407 
408  if (nargin > 2)
409  print_usage ();
410 
411  if (nargin == 0)
412  {
414  }
415  else
416  {
417  std::string keyword = args(0).xstring_value ("lsode_options: expecting keyword as first argument");
418 
419  if (nargin == 1)
420  retval = show_LSODE_options (keyword);
421  else
422  set_LSODE_options (keyword, args(1));
423  }
424 
425  return retval;
426 }
#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:377
Definition: dMatrix.h:42
int int_value(bool req_int=false, bool frc_str_conv=false) const
Definition: ov.h:765
std::string string_value(bool force=false) const
Definition: ov.h:927
Array< double > vector_value(bool frc_str_conv=false, bool frc_vec_conv=false) const
double double_value(bool frc_str_conv=false) const
Definition: ov.h:794
OCTINTERP_API void print_usage(void)
Definition: defun.cc:53
#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:1050
static int left
Definition: randmtzig.cc:191
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:272
octave_value::octave_value(const Array< char > &chm, char type) return retval
Definition: ov.cc:811
#define octave_stdout
Definition: pager.h:313
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