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
DASSL-opts.cc
Go to the documentation of this file.
1 // DO NOT EDIT!
2 // Generated automatically from ../liboctave/numeric/DASSL-opts.in.
3 
4 #ifdef HAVE_CONFIG_H
5 #include <config.h>
6 #endif
7 
8 #include <iomanip>
9 #include <iostream>
10 
11 #include "DASSL-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 4
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, 0, },
38  { 1, 0, 0, 0, 0, }, 1, },
39 
40  { "relative tolerance",
41  { "relative", "tolerance", 0, 0, 0, },
42  { 1, 0, 0, 0, 0, }, 1, },
43 
44  { "compute consistent initial condition",
45  { "compute", "consistent", "initial", "condition", 0, },
46  { 1, 0, 0, 0, 0, }, 1, },
47 
48  { "enforce nonnegativity constraints",
49  { "enforce", "nonnegativity", "constraints", 0, 0, },
50  { 1, 0, 0, 0, 0, }, 1, },
51 
52  { "initial step size",
53  { "initial", "step", "size", 0, 0, },
54  { 1, 0, 0, 0, 0, }, 1, },
55 
56  { "maximum order",
57  { "maximum", "order", 0, 0, 0, },
58  { 1, 1, 0, 0, 0, }, 2, },
59 
60  { "maximum step size",
61  { "maximum", "step", "size", 0, 0, },
62  { 1, 1, 0, 0, 0, }, 2, },
63 
64  { "step limit",
65  { "step", "limit", 0, 0, 0, },
66  { 1, 0, 0, 0, 0, }, 1, },
67 };
68 
69 static void
70 print_DASSL_options (std::ostream& os)
71 {
72  std::ostringstream buf;
73 
74  os << "\n"
75  << "Options for DASSL 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 = dassl_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  Array<double> val = dassl_opts.relative_tolerance ();
111 
112  if (val.length () == 1)
113  {
114  os << val(0) << "\n";
115  }
116  else
117  {
118  os << "\n\n";
119  Matrix tmp = Matrix (ColumnVector (val));
120  octave_print_internal (os, tmp, false, 2);
121  os << "\n\n";
122  }
123  }
124 
125  {
126  os << " "
127  << std::setiosflags (std::ios::left) << std::setw (50)
128  << list[2].keyword
129  << std::resetiosflags (std::ios::left)
130  << " ";
131 
132  int val = dassl_opts.compute_consistent_initial_condition ();
133 
134  os << val << "\n";
135  }
136 
137  {
138  os << " "
139  << std::setiosflags (std::ios::left) << std::setw (50)
140  << list[3].keyword
141  << std::resetiosflags (std::ios::left)
142  << " ";
143 
144  int val = dassl_opts.enforce_nonnegativity_constraints ();
145 
146  os << val << "\n";
147  }
148 
149  {
150  os << " "
151  << std::setiosflags (std::ios::left) << std::setw (50)
152  << list[4].keyword
153  << std::resetiosflags (std::ios::left)
154  << " ";
155 
156  double val = dassl_opts.initial_step_size ();
157 
158  os << val << "\n";
159  }
160 
161  {
162  os << " "
163  << std::setiosflags (std::ios::left) << std::setw (50)
164  << list[5].keyword
165  << std::resetiosflags (std::ios::left)
166  << " ";
167 
168  int val = dassl_opts.maximum_order ();
169 
170  os << val << "\n";
171  }
172 
173  {
174  os << " "
175  << std::setiosflags (std::ios::left) << std::setw (50)
176  << list[6].keyword
177  << std::resetiosflags (std::ios::left)
178  << " ";
179 
180  double val = dassl_opts.maximum_step_size ();
181 
182  os << val << "\n";
183  }
184 
185  {
186  os << " "
187  << std::setiosflags (std::ios::left) << std::setw (50)
188  << list[7].keyword
189  << std::resetiosflags (std::ios::left)
190  << " ";
191 
192  int val = dassl_opts.step_limit ();
193 
194  os << val << "\n";
195  }
196 
197  os << "\n";
198 }
199 
200 static void
201 set_DASSL_options (const std::string& keyword, const octave_value& val)
202 {
204 
205  if (keyword_almost_match (list[0].kw_tok, list[0].min_len,
206  keyword, list[0].min_toks_to_match, MAX_TOKENS))
207  {
208  Array<double> tmp = val.vector_value ();
209 
210  if (! error_state)
211  dassl_opts.set_absolute_tolerance (tmp);
212  }
213  else if (keyword_almost_match (list[1].kw_tok, list[1].min_len,
214  keyword, list[1].min_toks_to_match, MAX_TOKENS))
215  {
216  Array<double> tmp = val.vector_value ();
217 
218  if (! error_state)
219  dassl_opts.set_relative_tolerance (tmp);
220  }
221  else if (keyword_almost_match (list[2].kw_tok, list[2].min_len,
222  keyword, list[2].min_toks_to_match, MAX_TOKENS))
223  {
224  int tmp = val.int_value ();
225 
226  if (! error_state)
228  }
229  else if (keyword_almost_match (list[3].kw_tok, list[3].min_len,
230  keyword, list[3].min_toks_to_match, MAX_TOKENS))
231  {
232  int tmp = val.int_value ();
233 
234  if (! error_state)
235  dassl_opts.set_enforce_nonnegativity_constraints (tmp);
236  }
237  else if (keyword_almost_match (list[4].kw_tok, list[4].min_len,
238  keyword, list[4].min_toks_to_match, MAX_TOKENS))
239  {
240  double tmp = val.double_value ();
241 
242  if (! error_state)
243  dassl_opts.set_initial_step_size (tmp);
244  }
245  else if (keyword_almost_match (list[5].kw_tok, list[5].min_len,
246  keyword, list[5].min_toks_to_match, MAX_TOKENS))
247  {
248  int tmp = val.int_value ();
249 
250  if (! error_state)
251  dassl_opts.set_maximum_order (tmp);
252  }
253  else if (keyword_almost_match (list[6].kw_tok, list[6].min_len,
254  keyword, list[6].min_toks_to_match, MAX_TOKENS))
255  {
256  double tmp = val.double_value ();
257 
258  if (! error_state)
259  dassl_opts.set_maximum_step_size (tmp);
260  }
261  else if (keyword_almost_match (list[7].kw_tok, list[7].min_len,
262  keyword, list[7].min_toks_to_match, MAX_TOKENS))
263  {
264  int tmp = val.int_value ();
265 
266  if (! error_state)
267  dassl_opts.set_step_limit (tmp);
268  }
269  else
270  {
271  warning ("dassl_options: no match for `%s'", keyword.c_str ());
272  }
273 }
274 
275 static octave_value_list
276 show_DASSL_options (const std::string& keyword)
277 {
278  octave_value retval;
279 
281 
282  if (keyword_almost_match (list[0].kw_tok, list[0].min_len,
283  keyword, list[0].min_toks_to_match, MAX_TOKENS))
284  {
285  Array<double> val = dassl_opts.absolute_tolerance ();
286 
287  if (val.length () == 1)
288  {
289  retval = val(0);
290  }
291  else
292  {
293  retval = ColumnVector (val);
294  }
295  }
296  else if (keyword_almost_match (list[1].kw_tok, list[1].min_len,
297  keyword, list[1].min_toks_to_match, MAX_TOKENS))
298  {
299  Array<double> val = dassl_opts.relative_tolerance ();
300 
301  if (val.length () == 1)
302  {
303  retval = val(0);
304  }
305  else
306  {
307  retval = ColumnVector (val);
308  }
309  }
310  else if (keyword_almost_match (list[2].kw_tok, list[2].min_len,
311  keyword, list[2].min_toks_to_match, MAX_TOKENS))
312  {
313  int val = dassl_opts.compute_consistent_initial_condition ();
314 
315  retval = static_cast<double> (val);
316  }
317  else if (keyword_almost_match (list[3].kw_tok, list[3].min_len,
318  keyword, list[3].min_toks_to_match, MAX_TOKENS))
319  {
320  int val = dassl_opts.enforce_nonnegativity_constraints ();
321 
322  retval = static_cast<double> (val);
323  }
324  else if (keyword_almost_match (list[4].kw_tok, list[4].min_len,
325  keyword, list[4].min_toks_to_match, MAX_TOKENS))
326  {
327  double val = dassl_opts.initial_step_size ();
328 
329  retval = val;
330  }
331  else if (keyword_almost_match (list[5].kw_tok, list[5].min_len,
332  keyword, list[5].min_toks_to_match, MAX_TOKENS))
333  {
334  int val = dassl_opts.maximum_order ();
335 
336  retval = static_cast<double> (val);
337  }
338  else if (keyword_almost_match (list[6].kw_tok, list[6].min_len,
339  keyword, list[6].min_toks_to_match, MAX_TOKENS))
340  {
341  double val = dassl_opts.maximum_step_size ();
342 
343  retval = val;
344  }
345  else if (keyword_almost_match (list[7].kw_tok, list[7].min_len,
346  keyword, list[7].min_toks_to_match, MAX_TOKENS))
347  {
348  int val = dassl_opts.step_limit ();
349 
350  retval = static_cast<double> (val);
351  }
352  else
353  {
354  warning ("dassl_options: no match for `%s'", keyword.c_str ());
355  }
356 
357  return retval;
358 }
359 
360 DEFUN (dassl_options, args, ,
361  "-*- texinfo -*-\n\
362 @deftypefn {Built-in Function} {} dassl_options ()\n\
363 @deftypefnx {Built-in Function} {val =} dassl_options (@var{opt})\n\
364 @deftypefnx {Built-in Function} {} dassl_options (@var{opt}, @var{val})\n\
365 Query or set options for the function @code{dassl}.\n\
366 When called with no arguments, the names of all available options and\n\
367 their current values are displayed.\n\
368 Given one argument, return the value of the corresponding option.\n\
369 When called with two arguments, @code{dassl_options} set the option\n\
370 @var{opt} to value @var{val}.\n\
371 \n\
372 Options include\n\
373 \n\
374 @table @code\n\
375 @item @qcode{\"absolute tolerance\"}\n\
376 Absolute tolerance. May be either vector or scalar. If a vector, it\n\
377 must match the dimension of the state vector, and the relative\n\
378 tolerance must also be a vector of the same length.\n\
379 \n\
380 @item @qcode{\"relative tolerance\"}\n\
381 Relative tolerance. May be either vector or scalar. If a vector, it\n\
382 must match the dimension of the state vector, and the absolute\n\
383 tolerance must also be a vector of the same length.\n\
384 \n\
385 The local error test applied at each integration step is\n\
386 \n\
387 @example\n\
388 @group\n\
389  abs (local error in x(i))\n\
390  <= rtol(i) * abs (Y(i)) + atol(i)\n\
391 @end group\n\
392 @end example\n\
393 \n\
394 @item @qcode{\"compute consistent initial condition\"}\n\
395 If nonzero, @code{dassl} will attempt to compute a consistent set of initial\n\
396 conditions. This is generally not reliable, so it is best to provide\n\
397 a consistent set and leave this option set to zero.\n\
398 \n\
399 @item @qcode{\"enforce nonnegativity constraints\"}\n\
400 If you know that the solutions to your equations will always be\n\
401 non-negative, it may help to set this parameter to a nonzero\n\
402 value. However, it is probably best to try leaving this option set to\n\
403 zero first, and only setting it to a nonzero value if that doesn't\n\
404 work very well.\n\
405 \n\
406 @item @qcode{\"initial step size\"}\n\
407 Differential-algebraic problems may occasionally suffer from severe\n\
408 scaling difficulties on the first step. If you know a great deal\n\
409 about the scaling of your problem, you can help to alleviate this\n\
410 problem by specifying an initial stepsize.\n\
411 \n\
412 @item @qcode{\"maximum order\"}\n\
413 Restrict the maximum order of the solution method. This option must\n\
414 be between 1 and 5, inclusive.\n\
415 \n\
416 @item @qcode{\"maximum step size\"}\n\
417 Setting the maximum stepsize will avoid passing over very large\n\
418 regions (default is not specified).\n\
419 \n\
420 @item @qcode{\"step limit\"}\n\
421 Maximum number of integration steps to attempt on a single call to the\n\
422 underlying Fortran code.\n\
423 @end table\n\
424 @end deftypefn")
425 {
426  octave_value_list retval;
427 
428  int nargin = args.length ();
429 
430  if (nargin == 0)
431  {
433  }
434  else if (nargin == 1 || nargin == 2)
435  {
436  std::string keyword = args(0).string_value ();
437 
438  if (! error_state)
439  {
440  if (nargin == 1)
441  retval = show_DASSL_options (keyword);
442  else
443  set_DASSL_options (keyword, args(1));
444  }
445  else
446  error ("dassl_options: expecting keyword as first argument");
447  }
448  else
449  print_usage ();
450 
451  return retval;
452 }