GNU Octave  6.2.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
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 
22 
23 #define MAX_TOKENS 3
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 6
34 
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 
62 static void
63 print_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 
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 
169 static void
170 set_DASRT_options (const std::string& keyword, const octave_value& val)
171 {
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 
222 static octave_value_list
223 show_DASRT_options (const std::string& keyword)
224 {
226 
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 
293 DEFUN (dasrt_options, args, ,
294  doc: /* -*- texinfo -*-
295 @deftypefn {} {} dasrt_options ()
296 @deftypefnx {} {val =} dasrt_options (@var{opt})
297 @deftypefnx {} {} dasrt_options (@var{opt}, @var{val})
298 Query or set options for the function @code{dasrt}.
299 
300 When called with no arguments, the names of all available options and
301 their current values are displayed.
302 
303 Given one argument, return the value of the option @var{opt}.
304 
305 When called with two arguments, @code{dasrt_options} sets the option
306 @var{opt} to value @var{val}.
307 
308 Options include
309 
310 @table @asis
311 @item @qcode{"absolute tolerance"}
312 Absolute tolerance. May be either vector or scalar. If a vector, it
313 must match the dimension of the state vector, and the relative
314 tolerance must also be a vector of the same length.
315 
316 @item @qcode{"relative tolerance"}
317 Relative tolerance. May be either vector or scalar. If a vector, it
318 must match the dimension of the state vector, and the absolute
319 tolerance must also be a vector of the same length.
320 
321 The local error test applied at each integration step is
322 
323 @example
324 @group
325  abs (local error in x(i)) <= ...
326  rtol(i) * abs (Y(i)) + atol(i)
327 @end group
328 @end example
329 
330 @item @qcode{"initial step size"}
331 Differential-algebraic problems may occasionally suffer from severe
332 scaling difficulties on the first step. If you know a great deal
333 about the scaling of your problem, you can help to alleviate this
334 problem by specifying an initial stepsize.
335 
336 @item @qcode{"maximum order"}
337 Restrict the maximum order of the solution method. This option must
338 be between 1 and 5, inclusive.
339 
340 @item @qcode{"maximum step size"}
341 Setting the maximum stepsize will avoid passing over very large
342 regions.
343 
344 @item @qcode{"step limit"}
345 Maximum number of integration steps to attempt on a single call to the
346 underlying Fortran code.
347 @end table
348 @end deftypefn */)
349 {
351 
352  int nargin = args.length ();
353 
354  if (nargin > 2)
355  print_usage ();
356 
357  if (nargin == 0)
358  {
360  }
361  else
362  {
363  std::string keyword = args(0).xstring_value ("dasrt_options: expecting keyword as first argument");
364 
365  if (nargin == 1)
366  retval = show_DASRT_options (keyword);
367  else
368  set_DASRT_options (keyword, args(1));
369  }
370 
371  return retval;
372 }
#define MAX_TOKENS
Definition: DASRT-opts.cc:23
static void print_DASRT_options(std::ostream &os)
Definition: DASRT-opts.cc:63
static octave_value_list show_DASRT_options(const std::string &keyword)
Definition: DASRT-opts.cc:223
static DASRT_options dasrt_opts
Definition: DASRT-opts.cc:21
static DASRT_options_struct DASRT_options_table[]
Definition: DASRT-opts.cc:35
static void set_DASRT_options(const std::string &keyword, const octave_value &val)
Definition: DASRT-opts.cc:170
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: DASRT-opts.cc:27
const char * kw_tok[3+1]
Definition: DASRT-opts.cc:28