GNU Octave 7.1.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 /home/jwe/src/octave-stable/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];
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
70static void
71print_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
201static void
202set_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
269show_DASSL_options (const std::string& keyword)
270{
271 octave_value retval;
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
353OCTAVE_NAMESPACE_BEGIN
354
355DEFUN (dassl_options, args, ,
356 doc: /* -*- texinfo -*-
357@deftypefn {} {} dassl_options ()
358@deftypefnx {} {val =} dassl_options (@var{opt})
359@deftypefnx {} {} dassl_options (@var{opt}, @var{val})
360Query or set options for the function @code{dassl}.
361
362When called with no arguments, the names of all available options and
363their current values are displayed.
364
365Given one argument, return the value of the option @var{opt}.
366
367When called with two arguments, @code{dassl_options} sets the option
368@var{opt} to value @var{val}.
369
370Options include
371
372@table @asis
373@item @qcode{"absolute tolerance"}
374Absolute tolerance. May be either vector or scalar. If a vector, it
375must match the dimension of the state vector, and the relative
376tolerance must also be a vector of the same length.
377
378@item @qcode{"relative tolerance"}
379Relative tolerance. May be either vector or scalar. If a vector, it
380must match the dimension of the state vector, and the absolute
381tolerance must also be a vector of the same length.
382
383The local error test applied at each integration step is
384
385@example
386@group
387 abs (local error in x(i))
388 <= rtol(i) * abs (Y(i)) + atol(i)
389@end group
390@end example
391
392@item @qcode{"compute consistent initial condition"}
393If nonzero, @code{dassl} will attempt to compute a consistent set of initial
394conditions. This is generally not reliable, so it is best to provide
395a consistent set and leave this option set to zero.
396
397@item @qcode{"enforce nonnegativity constraints"}
398If you know that the solutions to your equations will always be
399non-negative, it may help to set this parameter to a nonzero
400value. However, it is probably best to try leaving this option set to
401zero first, and only setting it to a nonzero value if that doesn't
402work very well.
403
404@item @qcode{"initial step size"}
405Differential-algebraic problems may occasionally suffer from severe
406scaling difficulties on the first step. If you know a great deal
407about the scaling of your problem, you can help to alleviate this
408problem by specifying an initial stepsize.
409
410@item @qcode{"maximum order"}
411Restrict the maximum order of the solution method. This option must
412be between 1 and 5, inclusive.
413
414@item @qcode{"maximum step size"}
415Setting the maximum stepsize will avoid passing over very large
416regions (default is not specified).
417
418@item @qcode{"step limit"}
419Maximum number of integration steps to attempt on a single call to the
420underlying Fortran code.
421@end table
422@end deftypefn */)
423{
424 octave_value_list retval;
425
426 int nargin = args.length ();
427
428 if (nargin > 2)
429 print_usage ();
430
431 if (nargin == 0)
432 {
434 }
435 else
436 {
437 std::string keyword = args(0).xstring_value ("dassl_options: expecting keyword as first argument");
438
439 if (nargin == 1)
440 retval = show_DASSL_options (keyword);
441 else
442 set_DASSL_options (keyword, args(1));
443 }
444
445 return retval;
446}
447
448OCTAVE_NAMESPACE_END
449
#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:411
Definition: dMatrix.h:42
octave_idx_type length(void) const
Definition: ovl.h:113
OCTINTERP_API Array< double > vector_value(bool frc_str_conv=false, bool frc_vec_conv=false) const
int int_value(bool req_int=false, bool frc_str_conv=false) const
Definition: ov.h:857
double double_value(bool frc_str_conv=false) const
Definition: ov.h:886
OCTINTERP_API void print_usage(void)
Definition: defun-int.h:72
#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:1055
class OCTAVE_API Matrix
Definition: mx-fwd.h:31
class OCTAVE_API ColumnVector
Definition: mx-fwd.h:45
static int left
Definition: randmtzig.cc:193
#define octave_stdout
Definition: pager.h:314
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
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:422