GNU Octave  6.2.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
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 <ostream>
10 #include <sstream>
11 
12 #include "DASSL-opts.h"
13 
14 #include "defun.h"
15 #include "pr-output.h"
16 
17 #include "ovl.h"
18 #include "utils.h"
19 #include "pager.h"
20 
22 
23 #define MAX_TOKENS 4
24 
26 {
27  const char *keyword;
28  const char *kw_tok[MAX_TOKENS + 1];
29  int min_len[MAX_TOKENS + 1];
31 };
32 
33 #define NUM_OPTIONS 8
34 
36 {
37  { "absolute tolerance",
38  { "absolute", "tolerance", nullptr, nullptr, nullptr, },
39  { 1, 0, 0, 0, 0, }, 1, },
40 
41  { "relative tolerance",
42  { "relative", "tolerance", nullptr, nullptr, nullptr, },
43  { 1, 0, 0, 0, 0, }, 1, },
44 
45  { "compute consistent initial condition",
46  { "compute", "consistent", "initial", "condition", nullptr, },
47  { 1, 0, 0, 0, 0, }, 1, },
48 
49  { "enforce nonnegativity constraints",
50  { "enforce", "nonnegativity", "constraints", nullptr, nullptr, },
51  { 1, 0, 0, 0, 0, }, 1, },
52 
53  { "initial step size",
54  { "initial", "step", "size", nullptr, nullptr, },
55  { 1, 0, 0, 0, 0, }, 1, },
56 
57  { "maximum order",
58  { "maximum", "order", nullptr, nullptr, nullptr, },
59  { 1, 1, 0, 0, 0, }, 2, },
60 
61  { "maximum step size",
62  { "maximum", "step", "size", nullptr, nullptr, },
63  { 1, 1, 0, 0, 0, }, 2, },
64 
65  { "step limit",
66  { "step", "limit", nullptr, nullptr, nullptr, },
67  { 1, 0, 0, 0, 0, }, 1, },
68 };
69 
70 static void
71 print_DASSL_options (std::ostream& os)
72 {
73  std::ostringstream buf;
74 
75  os << "\n"
76  << "Options for DASSL include:\n\n"
77  << " keyword value\n"
78  << " ------- -----\n";
79 
81 
82  {
83  os << " "
84  << std::setiosflags (std::ios::left) << std::setw (50)
85  << list[0].keyword
86  << std::resetiosflags (std::ios::left)
87  << " ";
88 
89  Array<double> val = dassl_opts.absolute_tolerance ();
90 
91  if (val.numel () == 1)
92  {
93  os << val(0) << "\n";
94  }
95  else
96  {
97  os << "\n\n";
98  Matrix tmp = Matrix (ColumnVector (val));
99  octave_print_internal (os, tmp, false, 2);
100  os << "\n\n";
101  }
102  }
103 
104  {
105  os << " "
106  << std::setiosflags (std::ios::left) << std::setw (50)
107  << list[1].keyword
108  << std::resetiosflags (std::ios::left)
109  << " ";
110 
111  Array<double> val = dassl_opts.relative_tolerance ();
112 
113  if (val.numel () == 1)
114  {
115  os << val(0) << "\n";
116  }
117  else
118  {
119  os << "\n\n";
120  Matrix tmp = Matrix (ColumnVector (val));
121  octave_print_internal (os, tmp, false, 2);
122  os << "\n\n";
123  }
124  }
125 
126  {
127  os << " "
128  << std::setiosflags (std::ios::left) << std::setw (50)
129  << list[2].keyword
130  << std::resetiosflags (std::ios::left)
131  << " ";
132 
133  int val = dassl_opts.compute_consistent_initial_condition ();
134 
135  os << val << "\n";
136  }
137 
138  {
139  os << " "
140  << std::setiosflags (std::ios::left) << std::setw (50)
141  << list[3].keyword
142  << std::resetiosflags (std::ios::left)
143  << " ";
144 
145  int val = dassl_opts.enforce_nonnegativity_constraints ();
146 
147  os << val << "\n";
148  }
149 
150  {
151  os << " "
152  << std::setiosflags (std::ios::left) << std::setw (50)
153  << list[4].keyword
154  << std::resetiosflags (std::ios::left)
155  << " ";
156 
157  double val = dassl_opts.initial_step_size ();
158 
159  os << val << "\n";
160  }
161 
162  {
163  os << " "
164  << std::setiosflags (std::ios::left) << std::setw (50)
165  << list[5].keyword
166  << std::resetiosflags (std::ios::left)
167  << " ";
168 
169  int val = dassl_opts.maximum_order ();
170 
171  os << val << "\n";
172  }
173 
174  {
175  os << " "
176  << std::setiosflags (std::ios::left) << std::setw (50)
177  << list[6].keyword
178  << std::resetiosflags (std::ios::left)
179  << " ";
180 
181  double val = dassl_opts.maximum_step_size ();
182 
183  os << val << "\n";
184  }
185 
186  {
187  os << " "
188  << std::setiosflags (std::ios::left) << std::setw (50)
189  << list[7].keyword
190  << std::resetiosflags (std::ios::left)
191  << " ";
192 
193  int val = dassl_opts.step_limit ();
194 
195  os << val << "\n";
196  }
197 
198  os << "\n";
199 }
200 
201 static void
202 set_DASSL_options (const std::string& keyword, const octave_value& val)
203 {
205 
206  if (octave::keyword_almost_match (list[0].kw_tok, list[0].min_len,
207  keyword, list[0].min_toks_to_match, MAX_TOKENS))
208  {
209  Array<double> tmp = val.vector_value ();
210 
211  dassl_opts.set_absolute_tolerance (tmp);
212  }
213  else if (octave::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  dassl_opts.set_relative_tolerance (tmp);
219  }
220  else if (octave::keyword_almost_match (list[2].kw_tok, list[2].min_len,
221  keyword, list[2].min_toks_to_match, MAX_TOKENS))
222  {
223  int tmp = val.int_value ();
224 
225  dassl_opts.set_compute_consistent_initial_condition (tmp);
226  }
227  else if (octave::keyword_almost_match (list[3].kw_tok, list[3].min_len,
228  keyword, list[3].min_toks_to_match, MAX_TOKENS))
229  {
230  int tmp = val.int_value ();
231 
232  dassl_opts.set_enforce_nonnegativity_constraints (tmp);
233  }
234  else if (octave::keyword_almost_match (list[4].kw_tok, list[4].min_len,
235  keyword, list[4].min_toks_to_match, MAX_TOKENS))
236  {
237  double tmp = val.double_value ();
238 
239  dassl_opts.set_initial_step_size (tmp);
240  }
241  else if (octave::keyword_almost_match (list[5].kw_tok, list[5].min_len,
242  keyword, list[5].min_toks_to_match, MAX_TOKENS))
243  {
244  int tmp = val.int_value ();
245 
246  dassl_opts.set_maximum_order (tmp);
247  }
248  else if (octave::keyword_almost_match (list[6].kw_tok, list[6].min_len,
249  keyword, list[6].min_toks_to_match, MAX_TOKENS))
250  {
251  double tmp = val.double_value ();
252 
253  dassl_opts.set_maximum_step_size (tmp);
254  }
255  else if (octave::keyword_almost_match (list[7].kw_tok, list[7].min_len,
256  keyword, list[7].min_toks_to_match, MAX_TOKENS))
257  {
258  int tmp = val.int_value ();
259 
260  dassl_opts.set_step_limit (tmp);
261  }
262  else
263  {
264  warning ("dassl_options: no match for `%s'", keyword.c_str ());
265  }
266 }
267 
268 static octave_value_list
269 show_DASSL_options (const std::string& keyword)
270 {
272 
274 
275  if (octave::keyword_almost_match (list[0].kw_tok, list[0].min_len,
276  keyword, list[0].min_toks_to_match, MAX_TOKENS))
277  {
278  Array<double> val = dassl_opts.absolute_tolerance ();
279 
280  if (val.numel () == 1)
281  {
282  retval = val(0);
283  }
284  else
285  {
286  retval = ColumnVector (val);
287  }
288  }
289  else if (octave::keyword_almost_match (list[1].kw_tok, list[1].min_len,
290  keyword, list[1].min_toks_to_match, MAX_TOKENS))
291  {
292  Array<double> val = dassl_opts.relative_tolerance ();
293 
294  if (val.numel () == 1)
295  {
296  retval = val(0);
297  }
298  else
299  {
300  retval = ColumnVector (val);
301  }
302  }
303  else if (octave::keyword_almost_match (list[2].kw_tok, list[2].min_len,
304  keyword, list[2].min_toks_to_match, MAX_TOKENS))
305  {
306  int val = dassl_opts.compute_consistent_initial_condition ();
307 
308  retval = static_cast<double> (val);
309  }
310  else if (octave::keyword_almost_match (list[3].kw_tok, list[3].min_len,
311  keyword, list[3].min_toks_to_match, MAX_TOKENS))
312  {
313  int val = dassl_opts.enforce_nonnegativity_constraints ();
314 
315  retval = static_cast<double> (val);
316  }
317  else if (octave::keyword_almost_match (list[4].kw_tok, list[4].min_len,
318  keyword, list[4].min_toks_to_match, MAX_TOKENS))
319  {
320  double val = dassl_opts.initial_step_size ();
321 
322  retval = val;
323  }
324  else if (octave::keyword_almost_match (list[5].kw_tok, list[5].min_len,
325  keyword, list[5].min_toks_to_match, MAX_TOKENS))
326  {
327  int val = dassl_opts.maximum_order ();
328 
329  retval = static_cast<double> (val);
330  }
331  else if (octave::keyword_almost_match (list[6].kw_tok, list[6].min_len,
332  keyword, list[6].min_toks_to_match, MAX_TOKENS))
333  {
334  double val = dassl_opts.maximum_step_size ();
335 
336  retval = val;
337  }
338  else if (octave::keyword_almost_match (list[7].kw_tok, list[7].min_len,
339  keyword, list[7].min_toks_to_match, MAX_TOKENS))
340  {
341  int val = dassl_opts.step_limit ();
342 
343  retval = static_cast<double> (val);
344  }
345  else
346  {
347  warning ("dassl_options: no match for `%s'", keyword.c_str ());
348  }
349 
350  return retval;
351 }
352 
353 DEFUN (dassl_options, args, ,
354  doc: /* -*- texinfo -*-
355 @deftypefn {} {} dassl_options ()
356 @deftypefnx {} {val =} dassl_options (@var{opt})
357 @deftypefnx {} {} dassl_options (@var{opt}, @var{val})
358 Query or set options for the function @code{dassl}.
359 
360 When called with no arguments, the names of all available options and
361 their current values are displayed.
362 
363 Given one argument, return the value of the option @var{opt}.
364 
365 When called with two arguments, @code{dassl_options} sets the option
366 @var{opt} to value @var{val}.
367 
368 Options include
369 
370 @table @asis
371 @item @qcode{"absolute tolerance"}
372 Absolute tolerance. May be either vector or scalar. If a vector, it
373 must match the dimension of the state vector, and the relative
374 tolerance must also be a vector of the same length.
375 
376 @item @qcode{"relative tolerance"}
377 Relative tolerance. May be either vector or scalar. If a vector, it
378 must match the dimension of the state vector, and the absolute
379 tolerance must also be a vector of the same length.
380 
381 The local error test applied at each integration step is
382 
383 @example
384 @group
385  abs (local error in x(i))
386  <= rtol(i) * abs (Y(i)) + atol(i)
387 @end group
388 @end example
389 
390 @item @qcode{"compute consistent initial condition"}
391 If nonzero, @code{dassl} will attempt to compute a consistent set of initial
392 conditions. This is generally not reliable, so it is best to provide
393 a consistent set and leave this option set to zero.
394 
395 @item @qcode{"enforce nonnegativity constraints"}
396 If you know that the solutions to your equations will always be
397 non-negative, it may help to set this parameter to a nonzero
398 value. However, it is probably best to try leaving this option set to
399 zero first, and only setting it to a nonzero value if that doesn't
400 work very well.
401 
402 @item @qcode{"initial step size"}
403 Differential-algebraic problems may occasionally suffer from severe
404 scaling difficulties on the first step. If you know a great deal
405 about the scaling of your problem, you can help to alleviate this
406 problem by specifying an initial stepsize.
407 
408 @item @qcode{"maximum order"}
409 Restrict the maximum order of the solution method. This option must
410 be between 1 and 5, inclusive.
411 
412 @item @qcode{"maximum step size"}
413 Setting the maximum stepsize will avoid passing over very large
414 regions (default is not specified).
415 
416 @item @qcode{"step limit"}
417 Maximum number of integration steps to attempt on a single call to the
418 underlying Fortran code.
419 @end table
420 @end deftypefn */)
421 {
423 
424  int nargin = args.length ();
425 
426  if (nargin > 2)
427  print_usage ();
428 
429  if (nargin == 0)
430  {
432  }
433  else
434  {
435  std::string keyword = args(0).xstring_value ("dassl_options: expecting keyword as first argument");
436 
437  if (nargin == 1)
438  retval = show_DASSL_options (keyword);
439  else
440  set_DASSL_options (keyword, args(1));
441  }
442 
443  return retval;
444 }
#define MAX_TOKENS
Definition: DASSL-opts.cc:23
static DASSL_options_struct DASSL_options_table[]
Definition: DASSL-opts.cc:35
static octave_value_list show_DASSL_options(const std::string &keyword)
Definition: DASSL-opts.cc:269
static void set_DASSL_options(const std::string &keyword, const octave_value &val)
Definition: DASSL-opts.cc:202
static DASSL_options dassl_opts
Definition: DASSL-opts.cc:21
static void print_DASSL_options(std::ostream &os)
Definition: DASSL-opts.cc:71
octave_idx_type numel(void) const
Number of elements in the array.
Definition: Array.h:377
Definition: dMatrix.h:42
int int_value(bool req_int=false, bool frc_str_conv=false) const
Definition: ov.h:765
Array< double > vector_value(bool frc_str_conv=false, bool frc_vec_conv=false) const
double double_value(bool frc_str_conv=false) const
Definition: ov.h:794
OCTINTERP_API void print_usage(void)
Definition: defun.cc:53
#define DEFUN(name, args_name, nargout_name, doc)
Macro to define a builtin function.
Definition: defun.h:56
void warning(const char *fmt,...)
Definition: error.cc:1050
static int left
Definition: randmtzig.cc:191
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:272
octave_value::octave_value(const Array< char > &chm, char type) return retval
Definition: ov.cc:811
#define octave_stdout
Definition: pager.h:313
void octave_print_internal(std::ostream &os, const float_display_format &fmt, bool d, bool pr_as_read_syntax)
Definition: pr-output.cc:1762
const char * keyword
Definition: DASSL-opts.cc:27
const char * kw_tok[4+1]
Definition: DASSL-opts.cc:28