GNU Octave  3.8.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 When called with no arguments, the names of all available options and\n\
346 their current values are displayed.\n\
347 Given one argument, return the value of the corresponding option.\n\
348 When called with two arguments, @code{lsode_options} set the option\n\
349 @var{opt} to value @var{val}.\n\
350 \n\
351 Options include\n\
352 \n\
353 @table @code\n\
354 @item @qcode{\"absolute tolerance\"}\n\
355 Absolute tolerance. May be either vector or scalar. If a vector, it\n\
356 must match the dimension of the state vector.\n\
357 \n\
358 @item @qcode{\"relative tolerance\"}\n\
359 Relative tolerance parameter. Unlike the absolute tolerance, this\n\
360 parameter may only be a scalar.\n\
361 \n\
362 The local error test applied at each integration step is\n\
363 \n\
364 @example\n\
365 @group\n\
366  abs (local error in x(i)) <= ...\n\
367  rtol * abs (y(i)) + atol(i)\n\
368 @end group\n\
369 @end example\n\
370 \n\
371 @item @qcode{\"integration method\"}\n\
372 A string specifying the method of integration to use to solve the ODE\n\
373 system. Valid values are\n\
374 \n\
375 @table @asis\n\
376 @item @qcode{\"adams\"}\n\
377 @itemx @qcode{\"non-stiff\"}\n\
378 No Jacobian used (even if it is available).\n\
379 \n\
380 @item @qcode{\"bdf\"}\n\
381 @itemx @qcode{\"stiff\"}\n\
382 Use stiff backward differentiation formula (BDF) method. If a\n\
383 function to compute the Jacobian is not supplied, @code{lsode} will\n\
384 compute a finite difference approximation of the Jacobian matrix.\n\
385 @end table\n\
386 \n\
387 @item @qcode{\"initial step size\"}\n\
388 The step size to be attempted on the first step (default is determined\n\
389 automatically).\n\
390 \n\
391 @item @qcode{\"maximum order\"}\n\
392 Restrict the maximum order of the solution method. If using the Adams\n\
393 method, this option must be between 1 and 12. Otherwise, it must be\n\
394 between 1 and 5, inclusive.\n\
395 \n\
396 @item @qcode{\"maximum step size\"}\n\
397 Setting the maximum stepsize will avoid passing over very large\n\
398 regions (default is not specified).\n\
399 \n\
400 @item @qcode{\"minimum step size\"}\n\
401 The minimum absolute step size allowed (default is 0).\n\
402 \n\
403 @item @qcode{\"step limit\"}\n\
404 Maximum number of steps allowed (default is 100000).\n\
405 @end table\n\
406 @end deftypefn")
407 {
408  octave_value_list retval;
409 
410  int nargin = args.length ();
411 
412  if (nargin == 0)
413  {
415  }
416  else if (nargin == 1 || nargin == 2)
417  {
418  std::string keyword = args(0).string_value ();
419 
420  if (! error_state)
421  {
422  if (nargin == 1)
423  retval = show_LSODE_options (keyword);
424  else
425  set_LSODE_options (keyword, args(1));
426  }
427  else
428  error ("lsode_options: expecting keyword as first argument");
429  }
430  else
431  print_usage ();
432 
433  return retval;
434 }