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
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 // 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 "DASSL-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 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.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  Array<double> val = dassl_opts.relative_tolerance ();
111 
112  if (val.numel () == 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
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  dassl_opts.set_absolute_tolerance (tmp);
211  }
212  else if (keyword_almost_match (list[1].kw_tok, list[1].min_len,
213  keyword, list[1].min_toks_to_match, MAX_TOKENS))
214  {
215  Array<double> tmp = val.vector_value ();
216 
217  dassl_opts.set_relative_tolerance (tmp);
218  }
219  else if (keyword_almost_match (list[2].kw_tok, list[2].min_len,
220  keyword, list[2].min_toks_to_match, MAX_TOKENS))
221  {
222  int tmp = val.int_value ();
223 
225  }
226  else if (keyword_almost_match (list[3].kw_tok, list[3].min_len,
227  keyword, list[3].min_toks_to_match, MAX_TOKENS))
228  {
229  int tmp = val.int_value ();
230 
231  dassl_opts.set_enforce_nonnegativity_constraints (tmp);
232  }
233  else if (keyword_almost_match (list[4].kw_tok, list[4].min_len,
234  keyword, list[4].min_toks_to_match, MAX_TOKENS))
235  {
236  double tmp = val.double_value ();
237 
238  dassl_opts.set_initial_step_size (tmp);
239  }
240  else if (keyword_almost_match (list[5].kw_tok, list[5].min_len,
241  keyword, list[5].min_toks_to_match, MAX_TOKENS))
242  {
243  int tmp = val.int_value ();
244 
245  dassl_opts.set_maximum_order (tmp);
246  }
247  else if (keyword_almost_match (list[6].kw_tok, list[6].min_len,
248  keyword, list[6].min_toks_to_match, MAX_TOKENS))
249  {
250  double tmp = val.double_value ();
251 
252  dassl_opts.set_maximum_step_size (tmp);
253  }
254  else if (keyword_almost_match (list[7].kw_tok, list[7].min_len,
255  keyword, list[7].min_toks_to_match, MAX_TOKENS))
256  {
257  int tmp = val.int_value ();
258 
259  dassl_opts.set_step_limit (tmp);
260  }
261  else
262  {
263  warning ("dassl_options: no match for `%s'", keyword.c_str ());
264  }
265 }
266 
267 static octave_value_list
269 {
271 
273 
274  if (keyword_almost_match (list[0].kw_tok, list[0].min_len,
275  keyword, list[0].min_toks_to_match, MAX_TOKENS))
276  {
277  Array<double> val = dassl_opts.absolute_tolerance ();
278 
279  if (val.numel () == 1)
280  {
281  retval = val(0);
282  }
283  else
284  {
285  retval = ColumnVector (val);
286  }
287  }
288  else if (keyword_almost_match (list[1].kw_tok, list[1].min_len,
289  keyword, list[1].min_toks_to_match, MAX_TOKENS))
290  {
291  Array<double> val = dassl_opts.relative_tolerance ();
292 
293  if (val.numel () == 1)
294  {
295  retval = val(0);
296  }
297  else
298  {
299  retval = ColumnVector (val);
300  }
301  }
302  else if (keyword_almost_match (list[2].kw_tok, list[2].min_len,
303  keyword, list[2].min_toks_to_match, MAX_TOKENS))
304  {
305  int val = dassl_opts.compute_consistent_initial_condition ();
306 
307  retval = static_cast<double> (val);
308  }
309  else if (keyword_almost_match (list[3].kw_tok, list[3].min_len,
310  keyword, list[3].min_toks_to_match, MAX_TOKENS))
311  {
312  int val = dassl_opts.enforce_nonnegativity_constraints ();
313 
314  retval = static_cast<double> (val);
315  }
316  else if (keyword_almost_match (list[4].kw_tok, list[4].min_len,
317  keyword, list[4].min_toks_to_match, MAX_TOKENS))
318  {
319  double val = dassl_opts.initial_step_size ();
320 
321  retval = val;
322  }
323  else if (keyword_almost_match (list[5].kw_tok, list[5].min_len,
324  keyword, list[5].min_toks_to_match, MAX_TOKENS))
325  {
326  int val = dassl_opts.maximum_order ();
327 
328  retval = static_cast<double> (val);
329  }
330  else if (keyword_almost_match (list[6].kw_tok, list[6].min_len,
331  keyword, list[6].min_toks_to_match, MAX_TOKENS))
332  {
333  double val = dassl_opts.maximum_step_size ();
334 
335  retval = val;
336  }
337  else if (keyword_almost_match (list[7].kw_tok, list[7].min_len,
338  keyword, list[7].min_toks_to_match, MAX_TOKENS))
339  {
340  int val = dassl_opts.step_limit ();
341 
342  retval = static_cast<double> (val);
343  }
344  else
345  {
346  warning ("dassl_options: no match for `%s'", keyword.c_str ());
347  }
348 
349  return retval;
350 }
351 
352 DEFUN (dassl_options, args, ,
353  doc: /* -*- texinfo -*-
354 @deftypefn {} {} dassl_options ()
355 @deftypefnx {} {val =} dassl_options (@var{opt})
356 @deftypefnx {} {} dassl_options (@var{opt}, @var{val})
357 Query or set options for the function @code{dassl}.
358 
359 When called with no arguments, the names of all available options and
360 their current values are displayed.
361 
362 Given one argument, return the value of the option @var{opt}.
363 
364 When called with two arguments, @code{dassl_options} sets the option
365 @var{opt} to value @var{val}.
366 
367 Options include
368 
369 @table @asis
370 @item @qcode{"absolute tolerance"}
371 Absolute tolerance. May be either vector or scalar. If a vector, it
372 must match the dimension of the state vector, and the relative
373 tolerance must also be a vector of the same length.
374 
375 @item @qcode{"relative tolerance"}
376 Relative tolerance. May be either vector or scalar. If a vector, it
377 must match the dimension of the state vector, and the absolute
378 tolerance must also be a vector of the same length.
379 
380 The local error test applied at each integration step is
381 
382 @example
383 @group
384  abs (local error in x(i))
385  <= rtol(i) * abs (Y(i)) + atol(i)
386 @end group
387 @end example
388 
389 @item @qcode{"compute consistent initial condition"}
390 If nonzero, @code{dassl} will attempt to compute a consistent set of initial
391 conditions. This is generally not reliable, so it is best to provide
392 a consistent set and leave this option set to zero.
393 
394 @item @qcode{"enforce nonnegativity constraints"}
395 If you know that the solutions to your equations will always be
396 non-negative, it may help to set this parameter to a nonzero
397 value. However, it is probably best to try leaving this option set to
398 zero first, and only setting it to a nonzero value if that doesn't
399 work very well.
400 
401 @item @qcode{"initial step size"}
402 Differential-algebraic problems may occasionally suffer from severe
403 scaling difficulties on the first step. If you know a great deal
404 about the scaling of your problem, you can help to alleviate this
405 problem by specifying an initial stepsize.
406 
407 @item @qcode{"maximum order"}
408 Restrict the maximum order of the solution method. This option must
409 be between 1 and 5, inclusive.
410 
411 @item @qcode{"maximum step size"}
412 Setting the maximum stepsize will avoid passing over very large
413 regions (default is not specified).
414 
415 @item @qcode{"step limit"}
416 Maximum number of integration steps to attempt on a single call to the
417 underlying Fortran code.
418 @end table
419 @end deftypefn */)
420 {
422 
423  int nargin = args.length ();
424 
425  if (nargin > 2)
426  print_usage ();
427 
428  if (nargin == 0)
429  {
431  }
432  else
433  {
434  std::string keyword = args(0).xstring_value ("dassl_options: expecting keyword as first argument");
435 
436  if (nargin == 1)
437  retval = show_DASSL_options (keyword);
438  else
439  set_DASSL_options (keyword, args(1));
440  }
441 
442  return retval;
443 }
static int left
Definition: randmtzig.cc:185
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:268
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: 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: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_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:746
Array< double > relative_tolerance(void) const
Definition: DASSL-opts.h:132
#define DEFUN(name, args_name, nargout_name, doc)
Definition: defun.h:46
void set_enforce_nonnegativity_constraints(octave_idx_type val)
Definition: DASSL-opts.h:115
static DASSL_options dassl_opts
Definition: DASSL-opts.cc:20
JNIEnv void * args
Definition: ov-java.cc:67
octave_idx_type compute_consistent_initial_condition(void) const
Definition: DASSL-opts.h:135
int nargin
Definition: graphics.cc:10115
const char * keyword
Definition: DASSL-opts.cc:26
const char * kw_tok[4+1]
Definition: DASSL-opts.cc:27
double tmp
Definition: data.cc:6300
octave_value retval
Definition: data.cc:6294
octave_idx_type enforce_nonnegativity_constraints(void) const
Definition: DASSL-opts.h:138
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
void warning(const char *fmt,...)
Definition: error.cc:788
#define octave_stdout
Definition: pager.h:146
void set_absolute_tolerance(double val)
Definition: DASSL-opts.h:92
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
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:775
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
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
static void set_DASSL_options(const std::string &keyword, const octave_value &val)
Definition: DASSL-opts.cc:201