12#include "DASPK-opts.h"
25struct DASPK_options_struct
30 int min_toks_to_match;
35static DASPK_options_struct DASPK_options_table [] =
37 {
"absolute tolerance",
38 {
"absolute",
"tolerance",
nullptr,
nullptr,
nullptr,
nullptr,
nullptr, },
39 { 2, 0, 0, 0, 0, 0, 0, }, 1, },
41 {
"relative tolerance",
42 {
"relative",
"tolerance",
nullptr,
nullptr,
nullptr,
nullptr,
nullptr, },
43 { 1, 0, 0, 0, 0, 0, 0, }, 1, },
45 {
"compute consistent initial condition",
46 {
"compute",
"consistent",
"initial",
"condition",
nullptr,
nullptr,
nullptr, },
47 { 1, 0, 0, 0, 0, 0, 0, }, 1, },
49 {
"use initial condition heuristics",
50 {
"use",
"initial",
"condition",
"heuristics",
nullptr,
nullptr,
nullptr, },
51 { 1, 0, 0, 0, 0, 0, 0, }, 1, },
53 {
"initial condition heuristics",
54 {
"initial",
"condition",
"heuristics",
nullptr,
nullptr,
nullptr,
nullptr, },
55 { 3, 1, 0, 0, 0, 0, 0, }, 2, },
57 {
"print initial condition info",
58 {
"print",
"initial",
"condition",
"info",
nullptr,
nullptr,
nullptr, },
59 { 1, 0, 0, 0, 0, 0, 0, }, 1, },
61 {
"exclude algebraic variables from error test",
62 {
"exclude",
"algebraic",
"variables",
"from",
"error",
"test",
nullptr, },
63 { 2, 0, 0, 0, 0, 0, 0, }, 1, },
65 {
"algebraic variables",
66 {
"algebraic",
"variables",
nullptr,
nullptr,
nullptr,
nullptr,
nullptr, },
67 { 2, 0, 0, 0, 0, 0, 0, }, 1, },
69 {
"enforce inequality constraints",
70 {
"enforce",
"inequality",
"constraints",
nullptr,
nullptr,
nullptr,
nullptr, },
71 { 2, 0, 0, 0, 0, 0, 0, }, 1, },
73 {
"inequality constraint types",
74 {
"inequality",
"constraint",
"types",
nullptr,
nullptr,
nullptr,
nullptr, },
75 { 3, 0, 0, 0, 0, 0, 0, }, 1, },
77 {
"initial step size",
78 {
"initial",
"step",
"size",
nullptr,
nullptr,
nullptr,
nullptr, },
79 { 3, 1, 0, 0, 0, 0, 0, }, 2, },
82 {
"maximum",
"order",
nullptr,
nullptr,
nullptr,
nullptr,
nullptr, },
83 { 1, 1, 0, 0, 0, 0, 0, }, 2, },
85 {
"maximum step size",
86 {
"maximum",
"step",
"size",
nullptr,
nullptr,
nullptr,
nullptr, },
87 { 1, 1, 0, 0, 0, 0, 0, }, 2, },
91print_DASPK_options (std::ostream& os)
93 std::ostringstream buf;
96 <<
"Options for DASPK include:\n\n"
98 <<
" ------- -----\n";
100 DASPK_options_struct *list = DASPK_options_table;
104 << std::setiosflags (std::ios::left) << std::setw (50)
106 << std::resetiosflags (std::ios::left)
111 if (val.
numel () == 1)
113 os << val(0) <<
"\n";
126 << std::setiosflags (std::ios::left) << std::setw (50)
128 << std::resetiosflags (std::ios::left)
133 if (val.
numel () == 1)
135 os << val(0) <<
"\n";
148 << std::setiosflags (std::ios::left) << std::setw (50)
150 << std::resetiosflags (std::ios::left)
153 int val = daspk_opts.compute_consistent_initial_condition ();
160 << std::setiosflags (std::ios::left) << std::setw (50)
162 << std::resetiosflags (std::ios::left)
165 int val = daspk_opts.use_initial_condition_heuristics ();
172 << std::setiosflags (std::ios::left) << std::setw (50)
174 << std::resetiosflags (std::ios::left)
177 Array<double> val = daspk_opts.initial_condition_heuristics ();
179 if (val.
numel () == 1)
181 os << val(0) <<
"\n";
194 << std::setiosflags (std::ios::left) << std::setw (50)
196 << std::resetiosflags (std::ios::left)
199 int val = daspk_opts.print_initial_condition_info ();
206 << std::setiosflags (std::ios::left) << std::setw (50)
208 << std::resetiosflags (std::ios::left)
211 int val = daspk_opts.exclude_algebraic_variables_from_error_test ();
218 << std::setiosflags (std::ios::left) << std::setw (50)
220 << std::resetiosflags (std::ios::left)
225 if (val.
numel () == 1)
227 os << val(0) <<
"\n";
243 << std::setiosflags (std::ios::left) << std::setw (50)
245 << std::resetiosflags (std::ios::left)
248 int val = daspk_opts.enforce_inequality_constraints ();
255 << std::setiosflags (std::ios::left) << std::setw (50)
257 << std::resetiosflags (std::ios::left)
262 if (val.
numel () == 1)
264 os << val(0) <<
"\n";
280 << std::setiosflags (std::ios::left) << std::setw (50)
282 << std::resetiosflags (std::ios::left)
285 double val = daspk_opts.initial_step_size ();
292 << std::setiosflags (std::ios::left) << std::setw (50)
294 << std::resetiosflags (std::ios::left)
297 int val = daspk_opts.maximum_order ();
304 << std::setiosflags (std::ios::left) << std::setw (50)
306 << std::resetiosflags (std::ios::left)
309 double val = daspk_opts.maximum_step_size ();
318set_DASPK_options (
const std::string& keyword,
const octave_value& val)
320 DASPK_options_struct *list = DASPK_options_table;
322 if (octave::keyword_almost_match (list[0].kw_tok, list[0].min_len,
323 keyword, list[0].min_toks_to_match,
MAX_TOKENS))
327 daspk_opts.set_absolute_tolerance (tmp);
329 else if (octave::keyword_almost_match (list[1].kw_tok, list[1].min_len,
330 keyword, list[1].min_toks_to_match,
MAX_TOKENS))
334 daspk_opts.set_relative_tolerance (tmp);
336 else if (octave::keyword_almost_match (list[2].kw_tok, list[2].min_len,
337 keyword, list[2].min_toks_to_match,
MAX_TOKENS))
341 daspk_opts.set_compute_consistent_initial_condition (tmp);
343 else if (octave::keyword_almost_match (list[3].kw_tok, list[3].min_len,
344 keyword, list[3].min_toks_to_match,
MAX_TOKENS))
348 daspk_opts.set_use_initial_condition_heuristics (tmp);
350 else if (octave::keyword_almost_match (list[4].kw_tok, list[4].min_len,
351 keyword, list[4].min_toks_to_match,
MAX_TOKENS))
355 daspk_opts.set_initial_condition_heuristics (tmp);
357 else if (octave::keyword_almost_match (list[5].kw_tok, list[5].min_len,
358 keyword, list[5].min_toks_to_match,
MAX_TOKENS))
362 daspk_opts.set_print_initial_condition_info (tmp);
364 else if (octave::keyword_almost_match (list[6].kw_tok, list[6].min_len,
365 keyword, list[6].min_toks_to_match,
MAX_TOKENS))
369 daspk_opts.set_exclude_algebraic_variables_from_error_test (tmp);
371 else if (octave::keyword_almost_match (list[7].kw_tok, list[7].min_len,
372 keyword, list[7].min_toks_to_match,
MAX_TOKENS))
376 daspk_opts.set_algebraic_variables (tmp);
378 else if (octave::keyword_almost_match (list[8].kw_tok, list[8].min_len,
379 keyword, list[8].min_toks_to_match,
MAX_TOKENS))
383 daspk_opts.set_enforce_inequality_constraints (tmp);
385 else if (octave::keyword_almost_match (list[9].kw_tok, list[9].min_len,
386 keyword, list[9].min_toks_to_match,
MAX_TOKENS))
390 daspk_opts.set_inequality_constraint_types (tmp);
392 else if (octave::keyword_almost_match (list[10].kw_tok, list[10].min_len,
393 keyword, list[10].min_toks_to_match,
MAX_TOKENS))
397 daspk_opts.set_initial_step_size (tmp);
399 else if (octave::keyword_almost_match (list[11].kw_tok, list[11].min_len,
400 keyword, list[11].min_toks_to_match,
MAX_TOKENS))
404 daspk_opts.set_maximum_order (tmp);
406 else if (octave::keyword_almost_match (list[12].kw_tok, list[12].min_len,
407 keyword, list[12].min_toks_to_match,
MAX_TOKENS))
411 daspk_opts.set_maximum_step_size (tmp);
415 warning (
"daspk_options: no match for `%s'", keyword.c_str ());
420show_DASPK_options (
const std::string& keyword)
424 DASPK_options_struct *list = DASPK_options_table;
426 if (octave::keyword_almost_match (list[0].kw_tok, list[0].min_len,
427 keyword, list[0].min_toks_to_match,
MAX_TOKENS))
431 if (val.
numel () == 1)
440 else if (octave::keyword_almost_match (list[1].kw_tok, list[1].min_len,
441 keyword, list[1].min_toks_to_match,
MAX_TOKENS))
445 if (val.
numel () == 1)
454 else if (octave::keyword_almost_match (list[2].kw_tok, list[2].min_len,
455 keyword, list[2].min_toks_to_match,
MAX_TOKENS))
457 int val = daspk_opts.compute_consistent_initial_condition ();
459 retval =
static_cast<double> (val);
461 else if (octave::keyword_almost_match (list[3].kw_tok, list[3].min_len,
462 keyword, list[3].min_toks_to_match,
MAX_TOKENS))
464 int val = daspk_opts.use_initial_condition_heuristics ();
466 retval =
static_cast<double> (val);
468 else if (octave::keyword_almost_match (list[4].kw_tok, list[4].min_len,
469 keyword, list[4].min_toks_to_match,
MAX_TOKENS))
471 Array<double> val = daspk_opts.initial_condition_heuristics ();
473 if (val.
numel () == 1)
482 else if (octave::keyword_almost_match (list[5].kw_tok, list[5].min_len,
483 keyword, list[5].min_toks_to_match,
MAX_TOKENS))
485 int val = daspk_opts.print_initial_condition_info ();
487 retval =
static_cast<double> (val);
489 else if (octave::keyword_almost_match (list[6].kw_tok, list[6].min_len,
490 keyword, list[6].min_toks_to_match,
MAX_TOKENS))
492 int val = daspk_opts.exclude_algebraic_variables_from_error_test ();
494 retval =
static_cast<double> (val);
496 else if (octave::keyword_almost_match (list[7].kw_tok, list[7].min_len,
497 keyword, list[7].min_toks_to_match,
MAX_TOKENS))
501 if (val.
numel () == 1)
503 retval =
static_cast<double> (val(0));
514 else if (octave::keyword_almost_match (list[8].kw_tok, list[8].min_len,
515 keyword, list[8].min_toks_to_match,
MAX_TOKENS))
517 int val = daspk_opts.enforce_inequality_constraints ();
519 retval =
static_cast<double> (val);
521 else if (octave::keyword_almost_match (list[9].kw_tok, list[9].min_len,
522 keyword, list[9].min_toks_to_match,
MAX_TOKENS))
526 if (val.
numel () == 1)
528 retval =
static_cast<double> (val(0));
539 else if (octave::keyword_almost_match (list[10].kw_tok, list[10].min_len,
540 keyword, list[10].min_toks_to_match,
MAX_TOKENS))
542 double val = daspk_opts.initial_step_size ();
546 else if (octave::keyword_almost_match (list[11].kw_tok, list[11].min_len,
547 keyword, list[11].min_toks_to_match,
MAX_TOKENS))
549 int val = daspk_opts.maximum_order ();
551 retval =
static_cast<double> (val);
553 else if (octave::keyword_almost_match (list[12].kw_tok, list[12].min_len,
554 keyword, list[12].min_toks_to_match,
MAX_TOKENS))
556 double val = daspk_opts.maximum_step_size ();
562 warning (
"daspk_options: no match for `%s'", keyword.c_str ());
570DEFUN (daspk_options, args, ,
746 int nargin = args.
length ();
757 std::string keyword = args(0).xstring_value (
"daspk_options: expecting keyword as first argument");
760 retval = show_DASPK_options (keyword);
762 set_DASPK_options (keyword, args(1));
768OCTAVE_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
Array< int > int_vector_value(bool req_int=false, bool frc_str_conv=false, bool frc_vec_conv=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)