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