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
DASRT-opts.cc
Go to the documentation of this file.
1 // DO NOT EDIT!
2 // Generated automatically from ../liboctave/numeric/DASRT-opts.in.
3 
4 #ifdef HAVE_CONFIG_H
5 #include <config.h>
6 #endif
7 
8 #include <iomanip>
9 #include <iostream>
10 
11 #include "DASRT-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 6
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  { "initial step size",
45  { "initial", "step", "size", 0, },
46  { 1, 0, 0, 0, }, 1, },
47 
48  { "maximum order",
49  { "maximum", "order", 0, 0, },
50  { 1, 1, 0, 0, }, 2, },
51 
52  { "maximum step size",
53  { "maximum", "step", "size", 0, },
54  { 1, 1, 0, 0, }, 2, },
55 
56  { "step limit",
57  { "step", "limit", 0, 0, },
58  { 1, 0, 0, 0, }, 1, },
59 };
60 
61 static void
62 print_DASRT_options (std::ostream& os)
63 {
64  std::ostringstream buf;
65 
66  os << "\n"
67  << "Options for DASRT include:\n\n"
68  << " keyword value\n"
69  << " ------- -----\n";
70 
72 
73  {
74  os << " "
75  << std::setiosflags (std::ios::left) << std::setw (50)
76  << list[0].keyword
77  << std::resetiosflags (std::ios::left)
78  << " ";
79 
80  Array<double> val = dasrt_opts.absolute_tolerance ();
81 
82  if (val.length () == 1)
83  {
84  os << val(0) << "\n";
85  }
86  else
87  {
88  os << "\n\n";
89  Matrix tmp = Matrix (ColumnVector (val));
90  octave_print_internal (os, tmp, false, 2);
91  os << "\n\n";
92  }
93  }
94 
95  {
96  os << " "
97  << std::setiosflags (std::ios::left) << std::setw (50)
98  << list[1].keyword
99  << std::resetiosflags (std::ios::left)
100  << " ";
101 
102  Array<double> val = dasrt_opts.relative_tolerance ();
103 
104  if (val.length () == 1)
105  {
106  os << val(0) << "\n";
107  }
108  else
109  {
110  os << "\n\n";
111  Matrix tmp = Matrix (ColumnVector (val));
112  octave_print_internal (os, tmp, false, 2);
113  os << "\n\n";
114  }
115  }
116 
117  {
118  os << " "
119  << std::setiosflags (std::ios::left) << std::setw (50)
120  << list[2].keyword
121  << std::resetiosflags (std::ios::left)
122  << " ";
123 
124  double val = dasrt_opts.initial_step_size ();
125 
126  os << val << "\n";
127  }
128 
129  {
130  os << " "
131  << std::setiosflags (std::ios::left) << std::setw (50)
132  << list[3].keyword
133  << std::resetiosflags (std::ios::left)
134  << " ";
135 
136  int val = dasrt_opts.maximum_order ();
137 
138  os << val << "\n";
139  }
140 
141  {
142  os << " "
143  << std::setiosflags (std::ios::left) << std::setw (50)
144  << list[4].keyword
145  << std::resetiosflags (std::ios::left)
146  << " ";
147 
148  double val = dasrt_opts.maximum_step_size ();
149 
150  os << val << "\n";
151  }
152 
153  {
154  os << " "
155  << std::setiosflags (std::ios::left) << std::setw (50)
156  << list[5].keyword
157  << std::resetiosflags (std::ios::left)
158  << " ";
159 
160  int val = dasrt_opts.step_limit ();
161 
162  os << val << "\n";
163  }
164 
165  os << "\n";
166 }
167 
168 static void
169 set_DASRT_options (const std::string& keyword, const octave_value& val)
170 {
172 
173  if (keyword_almost_match (list[0].kw_tok, list[0].min_len,
174  keyword, list[0].min_toks_to_match, MAX_TOKENS))
175  {
176  Array<double> tmp = val.vector_value ();
177 
178  if (! error_state)
179  dasrt_opts.set_absolute_tolerance (tmp);
180  }
181  else if (keyword_almost_match (list[1].kw_tok, list[1].min_len,
182  keyword, list[1].min_toks_to_match, MAX_TOKENS))
183  {
184  Array<double> tmp = val.vector_value ();
185 
186  if (! error_state)
187  dasrt_opts.set_relative_tolerance (tmp);
188  }
189  else if (keyword_almost_match (list[2].kw_tok, list[2].min_len,
190  keyword, list[2].min_toks_to_match, MAX_TOKENS))
191  {
192  double tmp = val.double_value ();
193 
194  if (! error_state)
195  dasrt_opts.set_initial_step_size (tmp);
196  }
197  else if (keyword_almost_match (list[3].kw_tok, list[3].min_len,
198  keyword, list[3].min_toks_to_match, MAX_TOKENS))
199  {
200  int tmp = val.int_value ();
201 
202  if (! error_state)
203  dasrt_opts.set_maximum_order (tmp);
204  }
205  else if (keyword_almost_match (list[4].kw_tok, list[4].min_len,
206  keyword, list[4].min_toks_to_match, MAX_TOKENS))
207  {
208  double tmp = val.double_value ();
209 
210  if (! error_state)
211  dasrt_opts.set_maximum_step_size (tmp);
212  }
213  else if (keyword_almost_match (list[5].kw_tok, list[5].min_len,
214  keyword, list[5].min_toks_to_match, MAX_TOKENS))
215  {
216  int tmp = val.int_value ();
217 
218  if (! error_state)
219  dasrt_opts.set_step_limit (tmp);
220  }
221  else
222  {
223  warning ("dasrt_options: no match for `%s'", keyword.c_str ());
224  }
225 }
226 
227 static octave_value_list
228 show_DASRT_options (const std::string& keyword)
229 {
230  octave_value retval;
231 
233 
234  if (keyword_almost_match (list[0].kw_tok, list[0].min_len,
235  keyword, list[0].min_toks_to_match, MAX_TOKENS))
236  {
237  Array<double> val = dasrt_opts.absolute_tolerance ();
238 
239  if (val.length () == 1)
240  {
241  retval = val(0);
242  }
243  else
244  {
245  retval = ColumnVector (val);
246  }
247  }
248  else if (keyword_almost_match (list[1].kw_tok, list[1].min_len,
249  keyword, list[1].min_toks_to_match, MAX_TOKENS))
250  {
251  Array<double> val = dasrt_opts.relative_tolerance ();
252 
253  if (val.length () == 1)
254  {
255  retval = val(0);
256  }
257  else
258  {
259  retval = ColumnVector (val);
260  }
261  }
262  else if (keyword_almost_match (list[2].kw_tok, list[2].min_len,
263  keyword, list[2].min_toks_to_match, MAX_TOKENS))
264  {
265  double val = dasrt_opts.initial_step_size ();
266 
267  retval = val;
268  }
269  else if (keyword_almost_match (list[3].kw_tok, list[3].min_len,
270  keyword, list[3].min_toks_to_match, MAX_TOKENS))
271  {
272  int val = dasrt_opts.maximum_order ();
273 
274  retval = static_cast<double> (val);
275  }
276  else if (keyword_almost_match (list[4].kw_tok, list[4].min_len,
277  keyword, list[4].min_toks_to_match, MAX_TOKENS))
278  {
279  double val = dasrt_opts.maximum_step_size ();
280 
281  retval = val;
282  }
283  else if (keyword_almost_match (list[5].kw_tok, list[5].min_len,
284  keyword, list[5].min_toks_to_match, MAX_TOKENS))
285  {
286  int val = dasrt_opts.step_limit ();
287 
288  retval = static_cast<double> (val);
289  }
290  else
291  {
292  warning ("dasrt_options: no match for `%s'", keyword.c_str ());
293  }
294 
295  return retval;
296 }
297 
298 DEFUN (dasrt_options, args, ,
299  "-*- texinfo -*-\n\
300 @deftypefn {Built-in Function} {} dasrt_options ()\n\
301 @deftypefnx {Built-in Function} {val =} dasrt_options (@var{opt})\n\
302 @deftypefnx {Built-in Function} {} dasrt_options (@var{opt}, @var{val})\n\
303 Query or set options for the function @code{dasrt}.\n\
304 \n\
305 When called with no arguments, the names of all available options and\n\
306 their current values are displayed.\n\
307 \n\
308 Given one argument, return the value of the option @var{opt}.\n\
309 \n\
310 When called with two arguments, @code{dasrt_options} sets the option\n\
311 @var{opt} to value @var{val}.\n\
312 \n\
313 Options include\n\
314 \n\
315 @table @code\n\
316 @item @qcode{\"absolute tolerance\"}\n\
317 Absolute tolerance. May be either vector or scalar. If a vector, it\n\
318 must match the dimension of the state vector, and the relative\n\
319 tolerance must also be a vector of the same length.\n\
320 \n\
321 @item @qcode{\"relative tolerance\"}\n\
322 Relative tolerance. May be either vector or scalar. If a vector, it\n\
323 must match the dimension of the state vector, and the absolute\n\
324 tolerance must also be a vector of the same length.\n\
325 \n\
326 The local error test applied at each integration step is\n\
327 \n\
328 @example\n\
329 @group\n\
330  abs (local error in x(i)) <= ...\n\
331  rtol(i) * abs (Y(i)) + atol(i)\n\
332 @end group\n\
333 @end example\n\
334 \n\
335 @item @qcode{\"initial step size\"}\n\
336 Differential-algebraic problems may occasionally suffer from severe\n\
337 scaling difficulties on the first step. If you know a great deal\n\
338 about the scaling of your problem, you can help to alleviate this\n\
339 problem by specifying an initial stepsize.\n\
340 \n\
341 @item @qcode{\"maximum order\"}\n\
342 Restrict the maximum order of the solution method. This option must\n\
343 be between 1 and 5, inclusive.\n\
344 \n\
345 @item @qcode{\"maximum step size\"}\n\
346 Setting the maximum stepsize will avoid passing over very large\n\
347 regions.\n\
348 \n\
349 @item @qcode{\"step limit\"}\n\
350 Maximum number of integration steps to attempt on a single call to the\n\
351 underlying Fortran code.\n\
352 @end table\n\
353 @end deftypefn")
354 {
355  octave_value_list retval;
356 
357  int nargin = args.length ();
358 
359  if (nargin == 0)
360  {
362  }
363  else if (nargin == 1 || nargin == 2)
364  {
365  std::string keyword = args(0).string_value ();
366 
367  if (! error_state)
368  {
369  if (nargin == 1)
370  retval = show_DASRT_options (keyword);
371  else
372  set_DASRT_options (keyword, args(1));
373  }
374  else
375  error ("dasrt_options: expecting keyword as first argument");
376  }
377  else
378  print_usage ();
379 
380  return retval;
381 }
double maximum_step_size(void) const
Definition: DASRT-opts.h:127
void set_relative_tolerance(double val)
Definition: DASRT-opts.h:94
void set_step_limit(octave_idx_type val)
Definition: DASRT-opts.h:113
OCTINTERP_API void print_usage(void)
Definition: defun.cc:51
void set_absolute_tolerance(double val)
Definition: DASRT-opts.h:84
octave_idx_type length(void) const
Definition: oct-obj.h:89
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
#define MAX_TOKENS
Definition: DASRT-opts.cc:22
static DASRT_options dasrt_opts
Definition: DASRT-opts.cc:20
void set_maximum_order(octave_idx_type val)
Definition: DASRT-opts.h:107
static int left
Definition: randmtzig.c:189
void set_maximum_step_size(double val)
Definition: DASRT-opts.h:110
static octave_value_list show_DASRT_options(const std::string &keyword)
Definition: DASRT-opts.cc:228
static void print_DASRT_options(std::ostream &os)
Definition: DASRT-opts.cc:62
const char * keyword
Definition: DASRT-opts.cc:26
static void set_DASRT_options(const std::string &keyword, const octave_value &val)
Definition: DASRT-opts.cc:169
int error_state
Definition: error.cc:101
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
octave_idx_type step_limit(void) const
Definition: DASRT-opts.h:130
void warning(const char *fmt,...)
Definition: error.cc:681
Handles the reference counting for all the derived classes.
Definition: Array.h:45
Array< double > relative_tolerance(void) const
Definition: DASRT-opts.h:118
octave_idx_type length(void) const
Number of elements in the array.
Definition: Array.h:267
#define octave_stdout
Definition: pager.h:144
const char * kw_tok[3+1]
Definition: DASRT-opts.cc:27
Array< double > absolute_tolerance(void) const
Definition: DASRT-opts.h:115
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
octave_idx_type maximum_order(void) const
Definition: DASRT-opts.h:124
void set_initial_step_size(double val)
Definition: DASRT-opts.h:104
double initial_step_size(void) const
Definition: DASRT-opts.h:121
double double_value(bool frc_str_conv=false) const
Definition: ov.h:759
static DASRT_options_struct DASRT_options_table[]
Definition: DASRT-opts.cc:34