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
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 \n\
367 When called with no arguments, the names of all available options and\n\
368 their current values are displayed.\n\
369 \n\
370 Given one argument, return the value of the option @var{opt}.\n\
371 \n\
372 When called with two arguments, @code{dassl_options} sets the option\n\
373 @var{opt} to value @var{val}.\n\
374 \n\
375 Options include\n\
376 \n\
377 @table @code\n\
378 @item @qcode{\"absolute tolerance\"}\n\
379 Absolute tolerance. May be either vector or scalar. If a vector, it\n\
380 must match the dimension of the state vector, and the relative\n\
381 tolerance must also be a vector of the same length.\n\
382 \n\
383 @item @qcode{\"relative tolerance\"}\n\
384 Relative tolerance. May be either vector or scalar. If a vector, it\n\
385 must match the dimension of the state vector, and the absolute\n\
386 tolerance must also be a vector of the same length.\n\
387 \n\
388 The local error test applied at each integration step is\n\
389 \n\
390 @example\n\
391 @group\n\
392  abs (local error in x(i))\n\
393  <= rtol(i) * abs (Y(i)) + atol(i)\n\
394 @end group\n\
395 @end example\n\
396 \n\
397 @item @qcode{\"compute consistent initial condition\"}\n\
398 If nonzero, @code{dassl} will attempt to compute a consistent set of initial\n\
399 conditions. This is generally not reliable, so it is best to provide\n\
400 a consistent set and leave this option set to zero.\n\
401 \n\
402 @item @qcode{\"enforce nonnegativity constraints\"}\n\
403 If you know that the solutions to your equations will always be\n\
404 non-negative, it may help to set this parameter to a nonzero\n\
405 value. However, it is probably best to try leaving this option set to\n\
406 zero first, and only setting it to a nonzero value if that doesn't\n\
407 work very well.\n\
408 \n\
409 @item @qcode{\"initial step size\"}\n\
410 Differential-algebraic problems may occasionally suffer from severe\n\
411 scaling difficulties on the first step. If you know a great deal\n\
412 about the scaling of your problem, you can help to alleviate this\n\
413 problem by specifying an initial stepsize.\n\
414 \n\
415 @item @qcode{\"maximum order\"}\n\
416 Restrict the maximum order of the solution method. This option must\n\
417 be between 1 and 5, inclusive.\n\
418 \n\
419 @item @qcode{\"maximum step size\"}\n\
420 Setting the maximum stepsize will avoid passing over very large\n\
421 regions (default is not specified).\n\
422 \n\
423 @item @qcode{\"step limit\"}\n\
424 Maximum number of integration steps to attempt on a single call to the\n\
425 underlying Fortran code.\n\
426 @end table\n\
427 @end deftypefn")
428 {
429  octave_value_list retval;
430 
431  int nargin = args.length ();
432 
433  if (nargin == 0)
434  {
436  }
437  else if (nargin == 1 || nargin == 2)
438  {
439  std::string keyword = args(0).string_value ();
440 
441  if (! error_state)
442  {
443  if (nargin == 1)
444  retval = show_DASSL_options (keyword);
445  else
446  set_DASSL_options (keyword, args(1));
447  }
448  else
449  error ("dassl_options: expecting keyword as first argument");
450  }
451  else
452  print_usage ();
453 
454  return retval;
455 }
octave_idx_type maximum_order(void) const
Definition: DASSL-opts.h:144
void set_maximum_order(octave_idx_type val)
Definition: DASSL-opts.h:121
static octave_value_list show_DASSL_options(const std::string &keyword)
Definition: DASSL-opts.cc:276
Array< double > absolute_tolerance(void) const
Definition: DASSL-opts.h:129
void set_step_limit(octave_idx_type val)
Definition: DASSL-opts.h:127
OCTINTERP_API void print_usage(void)
Definition: defun.cc:51
octave_idx_type length(void) const
Definition: oct-obj.h:89
void set_relative_tolerance(double val)
Definition: DASSL-opts.h:102
int int_value(bool req_int=false, bool frc_str_conv=false) const
Definition: ov.h:730
Array< double > relative_tolerance(void) const
Definition: DASSL-opts.h:132
#define DEFUN(name, args_name, nargout_name, doc)
Definition: defun.h:44
void error(const char *fmt,...)
Definition: error.cc:476
void set_enforce_nonnegativity_constraints(octave_idx_type val)
Definition: DASSL-opts.h:115
static int left
Definition: randmtzig.c:189
static DASSL_options dassl_opts
Definition: DASSL-opts.cc:20
octave_idx_type compute_consistent_initial_condition(void) const
Definition: DASSL-opts.h:135
int error_state
Definition: error.cc:101
const char * keyword
Definition: DASSL-opts.cc:26
const char * kw_tok[4+1]
Definition: DASSL-opts.cc:27
octave_idx_type enforce_nonnegativity_constraints(void) const
Definition: DASSL-opts.h:138
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
void warning(const char *fmt,...)
Definition: error.cc:681
Handles the reference counting for all the derived classes.
Definition: Array.h:45
octave_idx_type length(void) const
Number of elements in the array.
Definition: Array.h:267
#define octave_stdout
Definition: pager.h:144
void set_absolute_tolerance(double val)
Definition: DASSL-opts.h:92
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 step_limit(void) const
Definition: DASSL-opts.h:150
void set_maximum_step_size(double val)
Definition: DASSL-opts.h:124
double initial_step_size(void) const
Definition: DASSL-opts.h:141
#define MAX_TOKENS
Definition: DASSL-opts.cc:22
double maximum_step_size(void) const
Definition: DASSL-opts.h:147
void set_initial_step_size(double val)
Definition: DASSL-opts.h:118
static void print_DASSL_options(std::ostream &os)
Definition: DASSL-opts.cc:70
double double_value(bool frc_str_conv=false) const
Definition: ov.h:759
void set_compute_consistent_initial_condition(octave_idx_type val)
Definition: DASSL-opts.h:112
static DASSL_options_struct DASSL_options_table[]
Definition: DASSL-opts.cc:34
static void set_DASSL_options(const std::string &keyword, const octave_value &val)
Definition: DASSL-opts.cc:201