12#include "LSODE-opts.h"
25struct LSODE_options_struct
30 int min_toks_to_match;
35static LSODE_options_struct LSODE_options_table [] =
37 {
"absolute tolerance",
38 {
"absolute",
"tolerance",
nullptr,
nullptr, },
39 { 1, 0, 0, 0, }, 1, },
41 {
"relative tolerance",
42 {
"relative",
"tolerance",
nullptr,
nullptr, },
43 { 1, 0, 0, 0, }, 1, },
45 {
"integration method",
46 {
"integration",
"method",
nullptr,
nullptr, },
47 { 3, 0, 0, 0, }, 1, },
49 {
"initial step size",
50 {
"initial",
"step",
"size",
nullptr, },
51 { 3, 0, 0, 0, }, 1, },
54 {
"maximum",
"order",
nullptr,
nullptr, },
55 { 2, 1, 0, 0, }, 2, },
57 {
"maximum step size",
58 {
"maximum",
"step",
"size",
nullptr, },
59 { 2, 1, 0, 0, }, 2, },
61 {
"minimum step size",
62 {
"minimum",
"step",
"size",
nullptr, },
63 { 2, 0, 0, 0, }, 1, },
66 {
"step",
"limit",
nullptr,
nullptr, },
67 { 1, 0, 0, 0, }, 1, },
70 {
"jacobian",
"type",
nullptr,
nullptr, },
71 { 1, 0, 0, 0, }, 1, },
73 {
"lower jacobian subdiagonals",
74 {
"lower",
"jacobian",
"subdiagonals",
nullptr, },
75 { 1, 0, 0, 0, }, 1, },
77 {
"upper jacobian subdiagonals",
78 {
"upper",
"jacobian",
"subdiagonals",
nullptr, },
79 { 1, 0, 0, 0, }, 1, },
83print_LSODE_options (std::ostream& os)
85 std::ostringstream buf;
88 <<
"Options for LSODE include:\n\n"
90 <<
" ------- -----\n";
92 LSODE_options_struct *list = LSODE_options_table;
96 << std::setiosflags (std::ios::left) << std::setw (50)
98 << std::resetiosflags (std::ios::left)
103 if (val.
numel () == 1)
105 os << val(0) <<
"\n";
118 << std::setiosflags (std::ios::left) << std::setw (50)
120 << std::resetiosflags (std::ios::left)
123 double val = lsode_opts.relative_tolerance ();
130 << std::setiosflags (std::ios::left) << std::setw (50)
132 << std::resetiosflags (std::ios::left)
135 os << lsode_opts.integration_method () <<
"\n";
140 << std::setiosflags (std::ios::left) << std::setw (50)
142 << std::resetiosflags (std::ios::left)
145 double val = lsode_opts.initial_step_size ();
152 << std::setiosflags (std::ios::left) << std::setw (50)
154 << std::resetiosflags (std::ios::left)
157 int val = lsode_opts.maximum_order ();
164 << std::setiosflags (std::ios::left) << std::setw (50)
166 << std::resetiosflags (std::ios::left)
169 double val = lsode_opts.maximum_step_size ();
176 << std::setiosflags (std::ios::left) << std::setw (50)
178 << std::resetiosflags (std::ios::left)
181 double val = lsode_opts.minimum_step_size ();
188 << std::setiosflags (std::ios::left) << std::setw (50)
190 << std::resetiosflags (std::ios::left)
193 int val = lsode_opts.step_limit ();
200 << std::setiosflags (std::ios::left) << std::setw (50)
202 << std::resetiosflags (std::ios::left)
205 os << lsode_opts.jacobian_type () <<
"\n";
210 << std::setiosflags (std::ios::left) << std::setw (50)
212 << std::resetiosflags (std::ios::left)
215 int val = lsode_opts.lower_jacobian_subdiagonals ();
222 << std::setiosflags (std::ios::left) << std::setw (50)
224 << std::resetiosflags (std::ios::left)
227 int val = lsode_opts.upper_jacobian_subdiagonals ();
236set_LSODE_options (
const std::string& keyword,
const octave_value& val)
238 LSODE_options_struct *list = LSODE_options_table;
240 if (octave::keyword_almost_match (list[0].kw_tok, list[0].min_len,
241 keyword, list[0].min_toks_to_match,
MAX_TOKENS))
245 lsode_opts.set_absolute_tolerance (tmp);
247 else if (octave::keyword_almost_match (list[1].kw_tok, list[1].min_len,
248 keyword, list[1].min_toks_to_match,
MAX_TOKENS))
252 lsode_opts.set_relative_tolerance (tmp);
254 else if (octave::keyword_almost_match (list[2].kw_tok, list[2].min_len,
255 keyword, list[2].min_toks_to_match,
MAX_TOKENS))
259 lsode_opts.set_integration_method (tmp);
261 else if (octave::keyword_almost_match (list[3].kw_tok, list[3].min_len,
262 keyword, list[3].min_toks_to_match,
MAX_TOKENS))
266 lsode_opts.set_initial_step_size (tmp);
268 else if (octave::keyword_almost_match (list[4].kw_tok, list[4].min_len,
269 keyword, list[4].min_toks_to_match,
MAX_TOKENS))
273 lsode_opts.set_maximum_order (tmp);
275 else if (octave::keyword_almost_match (list[5].kw_tok, list[5].min_len,
276 keyword, list[5].min_toks_to_match,
MAX_TOKENS))
280 lsode_opts.set_maximum_step_size (tmp);
282 else if (octave::keyword_almost_match (list[6].kw_tok, list[6].min_len,
283 keyword, list[6].min_toks_to_match,
MAX_TOKENS))
287 lsode_opts.set_minimum_step_size (tmp);
289 else if (octave::keyword_almost_match (list[7].kw_tok, list[7].min_len,
290 keyword, list[7].min_toks_to_match,
MAX_TOKENS))
294 lsode_opts.set_step_limit (tmp);
296 else if (octave::keyword_almost_match (list[8].kw_tok, list[8].min_len,
297 keyword, list[8].min_toks_to_match,
MAX_TOKENS))
301 lsode_opts.set_jacobian_type (tmp);
303 else if (octave::keyword_almost_match (list[9].kw_tok, list[9].min_len,
304 keyword, list[9].min_toks_to_match,
MAX_TOKENS))
308 lsode_opts.set_lower_jacobian_subdiagonals (tmp);
310 else if (octave::keyword_almost_match (list[10].kw_tok, list[10].min_len,
311 keyword, list[10].min_toks_to_match,
MAX_TOKENS))
315 lsode_opts.set_upper_jacobian_subdiagonals (tmp);
319 warning (
"lsode_options: no match for `%s'", keyword.c_str ());
324show_LSODE_options (
const std::string& keyword)
328 LSODE_options_struct *list = LSODE_options_table;
330 if (octave::keyword_almost_match (list[0].kw_tok, list[0].min_len,
331 keyword, list[0].min_toks_to_match,
MAX_TOKENS))
335 if (val.
numel () == 1)
344 else if (octave::keyword_almost_match (list[1].kw_tok, list[1].min_len,
345 keyword, list[1].min_toks_to_match,
MAX_TOKENS))
347 double val = lsode_opts.relative_tolerance ();
351 else if (octave::keyword_almost_match (list[2].kw_tok, list[2].min_len,
352 keyword, list[2].min_toks_to_match,
MAX_TOKENS))
354 retval = lsode_opts.integration_method ();
356 else if (octave::keyword_almost_match (list[3].kw_tok, list[3].min_len,
357 keyword, list[3].min_toks_to_match,
MAX_TOKENS))
359 double val = lsode_opts.initial_step_size ();
363 else if (octave::keyword_almost_match (list[4].kw_tok, list[4].min_len,
364 keyword, list[4].min_toks_to_match,
MAX_TOKENS))
366 int val = lsode_opts.maximum_order ();
368 retval =
static_cast<double> (val);
370 else if (octave::keyword_almost_match (list[5].kw_tok, list[5].min_len,
371 keyword, list[5].min_toks_to_match,
MAX_TOKENS))
373 double val = lsode_opts.maximum_step_size ();
377 else if (octave::keyword_almost_match (list[6].kw_tok, list[6].min_len,
378 keyword, list[6].min_toks_to_match,
MAX_TOKENS))
380 double val = lsode_opts.minimum_step_size ();
384 else if (octave::keyword_almost_match (list[7].kw_tok, list[7].min_len,
385 keyword, list[7].min_toks_to_match,
MAX_TOKENS))
387 int val = lsode_opts.step_limit ();
389 retval =
static_cast<double> (val);
391 else if (octave::keyword_almost_match (list[8].kw_tok, list[8].min_len,
392 keyword, list[8].min_toks_to_match,
MAX_TOKENS))
394 retval = lsode_opts.jacobian_type ();
396 else if (octave::keyword_almost_match (list[9].kw_tok, list[9].min_len,
397 keyword, list[9].min_toks_to_match,
MAX_TOKENS))
399 int val = lsode_opts.lower_jacobian_subdiagonals ();
401 retval =
static_cast<double> (val);
403 else if (octave::keyword_almost_match (list[10].kw_tok, list[10].min_len,
404 keyword, list[10].min_toks_to_match,
MAX_TOKENS))
406 int val = lsode_opts.upper_jacobian_subdiagonals ();
408 retval =
static_cast<double> (val);
412 warning (
"lsode_options: no match for `%s'", keyword.c_str ());
420DEFUN (lsode_options, args, ,
528 int nargin = args.
length ();
539 std::string keyword = args(0).xstring_value (
"lsode_options: expecting keyword as first argument");
542 retval = show_LSODE_options (keyword);
544 set_LSODE_options (keyword, args(1));
550OCTAVE_END_NAMESPACE(octave)
N Dimensional Array with copy-on-write semantics.
octave_idx_type numel() const
Number of elements in the array.
int int_value(bool req_int=false, bool frc_str_conv=false) const
std::string string_value(bool force=false) const
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
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
#define DEFUN(name, args_name, nargout_name, doc)
Macro to define a builtin function.
void warning(const char *fmt,...)
void octave_print_internal(std::ostream &os, const float_display_format &fmt, bool d, bool pr_as_read_syntax)