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
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 When called with no arguments, the names of all available options and\n\
305 their current values are displayed.\n\
306 Given one argument, return the value of the corresponding option.\n\
307 When called with two arguments, @code{dasrt_options} set the option\n\
308 @var{opt} to value @var{val}.\n\
309 \n\
310 Options include\n\
311 \n\
312 @table @code\n\
313 @item @qcode{\"absolute tolerance\"}\n\
314 Absolute tolerance. May be either vector or scalar. If a vector, it\n\
315 must match the dimension of the state vector, and the relative\n\
316 tolerance must also be a vector of the same length.\n\
317 \n\
318 @item @qcode{\"relative tolerance\"}\n\
319 Relative tolerance. May be either vector or scalar. If a vector, it\n\
320 must match the dimension of the state vector, and the absolute\n\
321 tolerance must also be a vector of the same length.\n\
322 \n\
323 The local error test applied at each integration step is\n\
324 \n\
325 @example\n\
326 @group\n\
327  abs (local error in x(i)) <= ...\n\
328  rtol(i) * abs (Y(i)) + atol(i)\n\
329 @end group\n\
330 @end example\n\
331 \n\
332 @item @qcode{\"initial step size\"}\n\
333 Differential-algebraic problems may occasionally suffer from severe\n\
334 scaling difficulties on the first step. If you know a great deal\n\
335 about the scaling of your problem, you can help to alleviate this\n\
336 problem by specifying an initial stepsize.\n\
337 \n\
338 @item @qcode{\"maximum order\"}\n\
339 Restrict the maximum order of the solution method. This option must\n\
340 be between 1 and 5, inclusive.\n\
341 \n\
342 @item @qcode{\"maximum step size\"}\n\
343 Setting the maximum stepsize will avoid passing over very large\n\
344 regions.\n\
345 \n\
346 @item @qcode{\"step limit\"}\n\
347 Maximum number of integration steps to attempt on a single call to the\n\
348 underlying Fortran code.\n\
349 @end table\n\
350 @end deftypefn")
351 {
352  octave_value_list retval;
353 
354  int nargin = args.length ();
355 
356  if (nargin == 0)
357  {
359  }
360  else if (nargin == 1 || nargin == 2)
361  {
362  std::string keyword = args(0).string_value ();
363 
364  if (! error_state)
365  {
366  if (nargin == 1)
367  retval = show_DASRT_options (keyword);
368  else
369  set_DASRT_options (keyword, args(1));
370  }
371  else
372  error ("dasrt_options: expecting keyword as first argument");
373  }
374  else
375  print_usage ();
376 
377  return retval;
378 }