GNU Octave 10.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 
Loading...
Searching...
No Matches
DASRT-opts.cc
Go to the documentation of this file.
1// DO NOT EDIT!
2// Generated automatically from ../liboctave/numeric/DASRT-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 "DASRT-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
21static DASRT_options dasrt_opts;
22
23#define MAX_TOKENS 3
24
25struct DASRT_options_struct
26{
27 const char *keyword;
28 const char *kw_tok[MAX_TOKENS + 1];
29 int min_len[MAX_TOKENS + 1];
30 int min_toks_to_match;
31};
32
33#define NUM_OPTIONS 6
34
35static DASRT_options_struct DASRT_options_table [] =
36{
37 { "absolute tolerance",
38 { "absolute", "tolerance", nullptr, nullptr, },
39 { 1, 0, 0, 0, }, 1, },
40
41 { "relative tolerance",
42 { "relative", "tolerance", nullptr, nullptr, },
43 { 1, 0, 0, 0, }, 1, },
44
45 { "initial step size",
46 { "initial", "step", "size", nullptr, },
47 { 1, 0, 0, 0, }, 1, },
48
49 { "maximum order",
50 { "maximum", "order", nullptr, nullptr, },
51 { 1, 1, 0, 0, }, 2, },
52
53 { "maximum step size",
54 { "maximum", "step", "size", nullptr, },
55 { 1, 1, 0, 0, }, 2, },
56
57 { "step limit",
58 { "step", "limit", nullptr, nullptr, },
59 { 1, 0, 0, 0, }, 1, },
60};
61
62static void
63print_DASRT_options (std::ostream& os)
64{
65 std::ostringstream buf;
66
67 os << "\n"
68 << "Options for DASRT include:\n\n"
69 << " keyword value\n"
70 << " ------- -----\n";
71
72 DASRT_options_struct *list = DASRT_options_table;
73
74 {
75 os << " "
76 << std::setiosflags (std::ios::left) << std::setw (50)
77 << list[0].keyword
78 << std::resetiosflags (std::ios::left)
79 << " ";
80
81 Array<double> val = dasrt_opts.absolute_tolerance ();
82
83 if (val.numel () == 1)
84 {
85 os << val(0) << "\n";
86 }
87 else
88 {
89 os << "\n\n";
90 Matrix tmp = Matrix (ColumnVector (val));
91 octave_print_internal (os, tmp, false, 2);
92 os << "\n\n";
93 }
94 }
95
96 {
97 os << " "
98 << std::setiosflags (std::ios::left) << std::setw (50)
99 << list[1].keyword
100 << std::resetiosflags (std::ios::left)
101 << " ";
102
103 Array<double> val = dasrt_opts.relative_tolerance ();
104
105 if (val.numel () == 1)
106 {
107 os << val(0) << "\n";
108 }
109 else
110 {
111 os << "\n\n";
112 Matrix tmp = Matrix (ColumnVector (val));
113 octave_print_internal (os, tmp, false, 2);
114 os << "\n\n";
115 }
116 }
117
118 {
119 os << " "
120 << std::setiosflags (std::ios::left) << std::setw (50)
121 << list[2].keyword
122 << std::resetiosflags (std::ios::left)
123 << " ";
124
125 double val = dasrt_opts.initial_step_size ();
126
127 os << val << "\n";
128 }
129
130 {
131 os << " "
132 << std::setiosflags (std::ios::left) << std::setw (50)
133 << list[3].keyword
134 << std::resetiosflags (std::ios::left)
135 << " ";
136
137 int val = dasrt_opts.maximum_order ();
138
139 os << val << "\n";
140 }
141
142 {
143 os << " "
144 << std::setiosflags (std::ios::left) << std::setw (50)
145 << list[4].keyword
146 << std::resetiosflags (std::ios::left)
147 << " ";
148
149 double val = dasrt_opts.maximum_step_size ();
150
151 os << val << "\n";
152 }
153
154 {
155 os << " "
156 << std::setiosflags (std::ios::left) << std::setw (50)
157 << list[5].keyword
158 << std::resetiosflags (std::ios::left)
159 << " ";
160
161 int val = dasrt_opts.step_limit ();
162
163 os << val << "\n";
164 }
165
166 os << "\n";
167}
168
169static void
170set_DASRT_options (const std::string& keyword, const octave_value& val)
171{
172 DASRT_options_struct *list = DASRT_options_table;
173
174 if (octave::keyword_almost_match (list[0].kw_tok, list[0].min_len,
175 keyword, list[0].min_toks_to_match, MAX_TOKENS))
176 {
177 Array<double> tmp = val.vector_value ();
178
179 dasrt_opts.set_absolute_tolerance (tmp);
180 }
181 else if (octave::keyword_almost_match (list[1].kw_tok, list[1].min_len,
182 keyword, list[1].min_toks_to_match, MAX_TOKENS))
183 {
184 Array<double> tmp = val.vector_value ();
185
186 dasrt_opts.set_relative_tolerance (tmp);
187 }
188 else if (octave::keyword_almost_match (list[2].kw_tok, list[2].min_len,
189 keyword, list[2].min_toks_to_match, MAX_TOKENS))
190 {
191 double tmp = val.double_value ();
192
193 dasrt_opts.set_initial_step_size (tmp);
194 }
195 else if (octave::keyword_almost_match (list[3].kw_tok, list[3].min_len,
196 keyword, list[3].min_toks_to_match, MAX_TOKENS))
197 {
198 int tmp = val.int_value ();
199
200 dasrt_opts.set_maximum_order (tmp);
201 }
202 else if (octave::keyword_almost_match (list[4].kw_tok, list[4].min_len,
203 keyword, list[4].min_toks_to_match, MAX_TOKENS))
204 {
205 double tmp = val.double_value ();
206
207 dasrt_opts.set_maximum_step_size (tmp);
208 }
209 else if (octave::keyword_almost_match (list[5].kw_tok, list[5].min_len,
210 keyword, list[5].min_toks_to_match, MAX_TOKENS))
211 {
212 int tmp = val.int_value ();
213
214 dasrt_opts.set_step_limit (tmp);
215 }
216 else
217 {
218 warning ("dasrt_options: no match for `%s'", keyword.c_str ());
219 }
220}
221
223show_DASRT_options (const std::string& keyword)
224{
225 octave_value retval;
226
227 DASRT_options_struct *list = DASRT_options_table;
228
229 if (octave::keyword_almost_match (list[0].kw_tok, list[0].min_len,
230 keyword, list[0].min_toks_to_match, MAX_TOKENS))
231 {
232 Array<double> val = dasrt_opts.absolute_tolerance ();
233
234 if (val.numel () == 1)
235 {
236 retval = val(0);
237 }
238 else
239 {
240 retval = ColumnVector (val);
241 }
242 }
243 else if (octave::keyword_almost_match (list[1].kw_tok, list[1].min_len,
244 keyword, list[1].min_toks_to_match, MAX_TOKENS))
245 {
246 Array<double> val = dasrt_opts.relative_tolerance ();
247
248 if (val.numel () == 1)
249 {
250 retval = val(0);
251 }
252 else
253 {
254 retval = ColumnVector (val);
255 }
256 }
257 else if (octave::keyword_almost_match (list[2].kw_tok, list[2].min_len,
258 keyword, list[2].min_toks_to_match, MAX_TOKENS))
259 {
260 double val = dasrt_opts.initial_step_size ();
261
262 retval = val;
263 }
264 else if (octave::keyword_almost_match (list[3].kw_tok, list[3].min_len,
265 keyword, list[3].min_toks_to_match, MAX_TOKENS))
266 {
267 int val = dasrt_opts.maximum_order ();
268
269 retval = static_cast<double> (val);
270 }
271 else if (octave::keyword_almost_match (list[4].kw_tok, list[4].min_len,
272 keyword, list[4].min_toks_to_match, MAX_TOKENS))
273 {
274 double val = dasrt_opts.maximum_step_size ();
275
276 retval = val;
277 }
278 else if (octave::keyword_almost_match (list[5].kw_tok, list[5].min_len,
279 keyword, list[5].min_toks_to_match, MAX_TOKENS))
280 {
281 int val = dasrt_opts.step_limit ();
282
283 retval = static_cast<double> (val);
284 }
285 else
286 {
287 warning ("dasrt_options: no match for `%s'", keyword.c_str ());
288 }
289
290 return retval;
291}
292
294
295DEFUN (dasrt_options, args, ,
296 doc: /* -*- texinfo -*-
297@deftypefn {} {} dasrt_options ()
298@deftypefnx {} {val =} dasrt_options (@var{opt})
299@deftypefnx {} {} dasrt_options (@var{opt}, @var{val})
300Query or set options for the function @code{dasrt}.
301
302When called with no arguments, the names of all available options and
303their current values are displayed.
304
305Given one argument, return the value of the option @var{opt}.
306
307When called with two arguments, @code{dasrt_options} sets the option
308@var{opt} to value @var{val}.
309
310Options include
311
312@table @asis
313@item @qcode{"absolute tolerance"}
314Absolute tolerance. May be either vector or scalar. If a vector, it
315must match the dimension of the state vector, and the relative
316tolerance must also be a vector of the same length.
317
318@item @qcode{"relative tolerance"}
319Relative tolerance. May be either vector or scalar. If a vector, it
320must match the dimension of the state vector, and the absolute
321tolerance must also be a vector of the same length.
322
323The local error test applied at each integration step is
324
325@example
326@group
327 abs (local error in x(i)) <= ...
328 rtol(i) * abs (Y(i)) + atol(i)
329@end group
330@end example
331
332@item @qcode{"initial step size"}
333Differential-algebraic problems may occasionally suffer from severe
334scaling difficulties on the first step. If you know a great deal
335about the scaling of your problem, you can help to alleviate this
336problem by specifying an initial stepsize.
337
338@item @qcode{"maximum order"}
339Restrict the maximum order of the solution method. This option must
340be between 1 and 5, inclusive.
341
342@item @qcode{"maximum step size"}
343Setting the maximum stepsize will avoid passing over very large
344regions.
345
346@item @qcode{"step limit"}
347Maximum number of integration steps to attempt on a single call to the
348underlying Fortran code.
349@end table
350@end deftypefn */)
351{
352 octave_value_list retval;
353
354 int nargin = args.length ();
355
356 if (nargin > 2)
357 print_usage ();
358
359 if (nargin == 0)
360 {
361 print_DASRT_options (octave_stdout);
362 }
363 else
364 {
365 std::string keyword = args(0).xstring_value ("dasrt_options: expecting keyword as first argument");
366
367 if (nargin == 1)
368 retval = show_DASRT_options (keyword);
369 else
370 set_DASRT_options (keyword, args(1));
371 }
372
373 return retval;
374}
375
376OCTAVE_END_NAMESPACE(octave)
377
#define MAX_TOKENS
Definition DASRT-opts.cc:23
N Dimensional Array with copy-on-write semantics.
Definition Array.h:130
octave_idx_type numel() const
Number of elements in the array.
Definition Array.h:418
int int_value(bool req_int=false, bool frc_str_conv=false) const
Definition ov.h:812
Array< double > vector_value(bool frc_str_conv=false, bool frc_vec_conv=false) const
octave_idx_type length() const
double double_value(bool frc_str_conv=false) const
Definition ov.h:847
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
void print_usage()
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:1078
#define octave_stdout
Definition pager.h:301
void octave_print_internal(std::ostream &os, const float_display_format &fmt, bool d, bool pr_as_read_syntax)