GNU Octave  4.2.1
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 // 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 <iostream>
10 
11 #include "LSODE-opts.h"
12 
13 #include "defun.h"
14 #include "pr-output.h"
15 
16 #include "ovl.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.numel () == 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
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  lsode_opts.set_absolute_tolerance (tmp);
199  }
200  else if (keyword_almost_match (list[1].kw_tok, list[1].min_len,
201  keyword, list[1].min_toks_to_match, MAX_TOKENS))
202  {
203  double tmp = val.double_value ();
204 
205  lsode_opts.set_relative_tolerance (tmp);
206  }
207  else if (keyword_almost_match (list[2].kw_tok, list[2].min_len,
208  keyword, list[2].min_toks_to_match, MAX_TOKENS))
209  {
210  std::string tmp = val.string_value ();
211 
212  lsode_opts.set_integration_method (tmp);
213  }
214  else if (keyword_almost_match (list[3].kw_tok, list[3].min_len,
215  keyword, list[3].min_toks_to_match, MAX_TOKENS))
216  {
217  double tmp = val.double_value ();
218 
219  lsode_opts.set_initial_step_size (tmp);
220  }
221  else if (keyword_almost_match (list[4].kw_tok, list[4].min_len,
222  keyword, list[4].min_toks_to_match, MAX_TOKENS))
223  {
224  int tmp = val.int_value ();
225 
226  lsode_opts.set_maximum_order (tmp);
227  }
228  else if (keyword_almost_match (list[5].kw_tok, list[5].min_len,
229  keyword, list[5].min_toks_to_match, MAX_TOKENS))
230  {
231  double tmp = val.double_value ();
232 
233  lsode_opts.set_maximum_step_size (tmp);
234  }
235  else if (keyword_almost_match (list[6].kw_tok, list[6].min_len,
236  keyword, list[6].min_toks_to_match, MAX_TOKENS))
237  {
238  double tmp = val.double_value ();
239 
240  lsode_opts.set_minimum_step_size (tmp);
241  }
242  else if (keyword_almost_match (list[7].kw_tok, list[7].min_len,
243  keyword, list[7].min_toks_to_match, MAX_TOKENS))
244  {
245  int tmp = val.int_value ();
246 
247  lsode_opts.set_step_limit (tmp);
248  }
249  else
250  {
251  warning ("lsode_options: no match for `%s'", keyword.c_str ());
252  }
253 }
254 
255 static octave_value_list
257 {
259 
261 
262  if (keyword_almost_match (list[0].kw_tok, list[0].min_len,
263  keyword, list[0].min_toks_to_match, MAX_TOKENS))
264  {
265  Array<double> val = lsode_opts.absolute_tolerance ();
266 
267  if (val.numel () == 1)
268  {
269  retval = val(0);
270  }
271  else
272  {
273  retval = ColumnVector (val);
274  }
275  }
276  else if (keyword_almost_match (list[1].kw_tok, list[1].min_len,
277  keyword, list[1].min_toks_to_match, MAX_TOKENS))
278  {
279  double val = lsode_opts.relative_tolerance ();
280 
281  retval = val;
282  }
283  else if (keyword_almost_match (list[2].kw_tok, list[2].min_len,
284  keyword, list[2].min_toks_to_match, MAX_TOKENS))
285  {
286  retval = lsode_opts.integration_method ();
287  }
288  else if (keyword_almost_match (list[3].kw_tok, list[3].min_len,
289  keyword, list[3].min_toks_to_match, MAX_TOKENS))
290  {
291  double val = lsode_opts.initial_step_size ();
292 
293  retval = val;
294  }
295  else if (keyword_almost_match (list[4].kw_tok, list[4].min_len,
296  keyword, list[4].min_toks_to_match, MAX_TOKENS))
297  {
298  int val = lsode_opts.maximum_order ();
299 
300  retval = static_cast<double> (val);
301  }
302  else if (keyword_almost_match (list[5].kw_tok, list[5].min_len,
303  keyword, list[5].min_toks_to_match, MAX_TOKENS))
304  {
305  double val = lsode_opts.maximum_step_size ();
306 
307  retval = val;
308  }
309  else if (keyword_almost_match (list[6].kw_tok, list[6].min_len,
310  keyword, list[6].min_toks_to_match, MAX_TOKENS))
311  {
312  double val = lsode_opts.minimum_step_size ();
313 
314  retval = val;
315  }
316  else if (keyword_almost_match (list[7].kw_tok, list[7].min_len,
317  keyword, list[7].min_toks_to_match, MAX_TOKENS))
318  {
319  int val = lsode_opts.step_limit ();
320 
321  retval = static_cast<double> (val);
322  }
323  else
324  {
325  warning ("lsode_options: no match for `%s'", keyword.c_str ());
326  }
327 
328  return retval;
329 }
330 
331 DEFUN (lsode_options, args, ,
332  doc: /* -*- texinfo -*-
333 @deftypefn {} {} lsode_options ()
334 @deftypefnx {} {val =} lsode_options (@var{opt})
335 @deftypefnx {} {} lsode_options (@var{opt}, @var{val})
336 Query or set options for the function @code{lsode}.
337 
338 When called with no arguments, the names of all available options and
339 their current values are displayed.
340 
341 Given one argument, return the value of the option @var{opt}.
342 
343 When called with two arguments, @code{lsode_options} sets the option
344 @var{opt} to value @var{val}.
345 
346 Options include
347 
348 @table @asis
349 @item @qcode{"absolute tolerance"}
350 Absolute tolerance. May be either vector or scalar. If a vector, it
351 must match the dimension of the state vector.
352 
353 @item @qcode{"relative tolerance"}
354 Relative tolerance parameter. Unlike the absolute tolerance, this
355 parameter may only be a scalar.
356 
357 The local error test applied at each integration step is
358 
359 @example
360 @group
361  abs (local error in x(i)) <= ...
362  rtol * abs (y(i)) + atol(i)
363 @end group
364 @end example
365 
366 @item @qcode{"integration method"}
367 A string specifying the method of integration to use to solve the ODE
368 system. Valid values are
369 
370 @table @asis
371 @item @qcode{"adams"}
372 @itemx @qcode{"non-stiff"}
373 No Jacobian used (even if it is available).
374 
375 @item @qcode{"bdf"}
376 @itemx @qcode{"stiff"}
377 Use stiff backward differentiation formula (BDF) method. If a
378 function to compute the Jacobian is not supplied, @code{lsode} will
379 compute a finite difference approximation of the Jacobian matrix.
380 @end table
381 
382 @item @qcode{"initial step size"}
383 The step size to be attempted on the first step (default is determined
384 automatically).
385 
386 @item @qcode{"maximum order"}
387 Restrict the maximum order of the solution method. If using the Adams
388 method, this option must be between 1 and 12. Otherwise, it must be
389 between 1 and 5, inclusive.
390 
391 @item @qcode{"maximum step size"}
392 Setting the maximum stepsize will avoid passing over very large
393 regions (default is not specified).
394 
395 @item @qcode{"minimum step size"}
396 The minimum absolute step size allowed (default is 0).
397 
398 @item @qcode{"step limit"}
399 Maximum number of steps allowed (default is 100000).
400 @end table
401 @end deftypefn */)
402 {
404 
405  int nargin = args.length ();
406 
407  if (nargin > 2)
408  print_usage ();
409 
410  if (nargin == 0)
411  {
413  }
414  else
415  {
416  std::string keyword = args(0).xstring_value ("lsode_options: expecting keyword as first argument");
417 
418  if (nargin == 1)
419  retval = show_LSODE_options (keyword);
420  else
421  set_LSODE_options (keyword, args(1));
422  }
423 
424  return retval;
425 }
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:256
static int left
Definition: randmtzig.cc:185
void set_initial_step_size(double val)
Definition: LSODE-opts.h:118
double maximum_step_size(void) const
Definition: LSODE-opts.h:147
The value of lines which begin with a space character are not saved in the history list A value of all commands are saved on the history list
Definition: oct-hist.cc:728
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:52
octave_idx_type numel(void) const
Number of elements in the array.
Definition: Array.h:363
identity matrix If supplied two scalar respectively For allows like xample val
Definition: data.cc:5068
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:746
#define DEFUN(name, args_name, nargout_name, doc)
Definition: defun.h:46
std::string integration_method(void) const
Definition: LSODE-opts.h:138
static LSODE_options_struct LSODE_options_table[]
Definition: LSODE-opts.cc:34
void set_maximum_step_size(double val)
Definition: LSODE-opts.h:124
void set_relative_tolerance(double val)
Definition: LSODE-opts.h:103
JNIEnv void * args
Definition: ov-java.cc:67
std::string string_value(bool force=false) const
Definition: ov.h:908
void set_minimum_step_size(double val)
Definition: LSODE-opts.h:127
int nargin
Definition: graphics.cc:10115
octave_idx_type step_limit(void) const
Definition: LSODE-opts.h:153
const char * keyword
Definition: LSODE-opts.cc:26
const char * kw_tok[3+1]
Definition: LSODE-opts.cc:27
double tmp
Definition: data.cc:6300
octave_value retval
Definition: data.cc:6294
void set_step_limit(octave_idx_type val)
Definition: LSODE-opts.h:130
Definition: dMatrix.h:37
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:152
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:788
#define octave_stdout
Definition: pager.h:146
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:1722
Array< double > vector_value(bool frc_str_conv=false, bool frc_vec_conv=false) const
Definition: ov.cc:1798
#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:775
double minimum_step_size(void) const
Definition: LSODE-opts.h:150
If this string is the system will ring the terminal sometimes it is useful to be able to print the original representation of the string
Definition: utils.cc:854
void set_integration_method(const std::string &val)
Definition: LSODE-opts.h:106