CLASS = "DASPK"

INCLUDE = "DAE.h"

OPTION
  NAME = "absolute tolerance"
  DOC_ITEM
Absolute tolerance.  May be either vector or scalar.  If a vector, it
must match the dimension of the state vector, and the relative
tolerance must also be a vector of the same length.
  END_DOC_ITEM
  TYPE = "Array<double>"
  SET_ARG_TYPE = "const $TYPE&"
  INIT_BODY
    $OPTVAR.resize (1);
    $OPTVAR(0) = ::sqrt (DBL_EPSILON);
  END_INIT_BODY
  SET_CODE
    void set_$OPT (double val)
      {
        $OPTVAR.resize (1);
        $OPTVAR(0) = (val > 0.0) ? val : ::sqrt (DBL_EPSILON);
        reset = true;
      }

    void set_$OPT (const $TYPE& val)
      { $OPTVAR = val; reset = true; }
  END_SET_CODE
END_OPTION

OPTION
  NAME = "relative tolerance"
  DOC_ITEM
Relative tolerance.  May be either vector or scalar.  If a vector, it
must match the dimension of the state vector, and the absolute
tolerance must also be a vector of the same length.

The local error test applied at each integration step is

@example
  abs (local error in x(i))
       <= rtol(i) * abs (Y(i)) + atol(i)
@end example
  END_DOC_ITEM
  TYPE = "Array<double>"
  SET_ARG_TYPE = "const $TYPE&"
  INIT_BODY
    $OPTVAR.resize (1);
    $OPTVAR(0) = ::sqrt (DBL_EPSILON);
  END_INIT_BODY
  SET_CODE
    void set_$OPT (double val)
      {
        $OPTVAR.resize (1);
        $OPTVAR(0) = (val > 0.0) ? val : ::sqrt (DBL_EPSILON);
        reset = true;
      }

    void set_$OPT (const $TYPE& val)
      { $OPTVAR = val; reset = true; }
  END_SET_CODE
END_OPTION

OPTION
  NAME = "compute consistent initial condition"
  DOC_ITEM
Denoting the differential variables in the state vector by @samp{Y_d}
and the algebraic variables by @samp{Y_a}, @code{ddaspk} can solve
one of two initialization problems:

@enumerate
@item Given Y_d, calculate Y_a and Y'_d
@item Given Y', calculate Y.
@end enumerate

In either case, initial values for the given components are input, and
initial guesses for the unknown components must also be provided as
input.  Set this option to 1 to solve the first problem, or 2 to solve
the second (the default default is 0, so you must provide a set of
initial conditions that are consistent).

If this option is set to a nonzero value, you must also set the
@code{\"algebraic variables\"} option to declare which variables in the
problem are algebraic.
  END_DOC_ITEM
  TYPE = "octave_idx_type"
  INIT_VALUE = "0"
  SET_EXPR = "val"
END_OPTION

OPTION
  NAME = "use initial condition heuristics"
  DOC_ITEM
Set to a nonzero value to use the initial condition heuristics options
described below.
  END_DOC_ITEM
  TYPE = "octave_idx_type"
  INIT_VALUE = "0"
  SET_EXPR = "val"
END_OPTION

OPTION
  NAME = "initial condition heuristics"
  DOC_ITEM
A vector of the following parameters that can be used to control the
initial condition calculation.

@table @code
@item MXNIT
Maximum number of Newton iterations (default is 5).
@item MXNJ
Maximum number of Jacobian evaluations (default is 6).
@item MXNH
Maximum number of values of the artificial stepsize parameter to be
tried if the @code{\"compute consistent initial condition\"} option has
been set to 1 (default is 5).

Note that the maximum number of Newton iterations allowed in all is
@code{MXNIT*MXNJ*MXNH} if the @code{\"compute consistent initial
condition\"} option has been set to 1 and @code{MXNIT*MXNJ} if it is
set to 2.
@item LSOFF
Set to a nonzero value to disable the linesearch algorithm (default is
0).
@item STPTOL
Minimum scaled step in linesearch algorithm (default is eps^(2/3)).
@item EPINIT
Swing factor in the Newton iteration convergence test.  The test is
applied to the residual vector, premultiplied by the approximate
Jacobian.  For convergence, the weighted RMS norm of this vector
(scaled by the error weights) must be less than @code{EPINIT*EPCON},
where @code{EPCON} = 0.33 is the analogous test constant used in the
time steps. The default is @code{EPINIT} = 0.01.
@end table
  END_DOC_ITEM
  TYPE = "Array<double>"
  SET_ARG_TYPE = "const $TYPE&"
  INIT_BODY
    $OPTVAR.resize (6);
    $OPTVAR(0) = 5.0;
    $OPTVAR(1) = 6.0;
    $OPTVAR(2) = 5.0;
    $OPTVAR(3) = 0.0;
    $OPTVAR(4) = ::pow (DBL_EPSILON, 2.0/3.0);
    $OPTVAR(5) = 0.01;
  END_INIT_BODY
  SET_EXPR = "val"
END_OPTION

OPTION
  NAME = "print initial condition info"
  DOC_ITEM
Set this option to a nonzero value to display detailed information
about the initial condition calculation (default is 0).
  END_DOC_ITEM
  TYPE = "octave_idx_type"
  INIT_VALUE = "0"
  SET_EXPR = "val"
END_OPTION

OPTION
  NAME = "exclude algebraic variables from error test"
  DOC_ITEM
Set to a nonzero value to exclude algebraic variables from the error
test.  You must also set the @code{\"algebraic variables\"} option to
declare which variables in the problem are algebraic (default is 0).
  END_DOC_ITEM
  TYPE = "octave_idx_type"
  INIT_VALUE = "0"
  SET_EXPR = "val"
END_OPTION

OPTION
  NAME = "algebraic variables"
  DOC_ITEM
A vector of the same length as the state vector.  A nonzero element
indicates that the corresponding element of the state vector is an
algebraic variable (i.e., its derivative does not appear explicitly
in the equation set.

This option is required by the
@code{compute consistent initial condition\"} and
@code{\"exclude algebraic variables from error test\"} options.
  END_DOC_ITEM
  TYPE = "Array<octave_idx_type>"
  SET_ARG_TYPE = const $TYPE&
  INIT_BODY
    $OPTVAR.resize (1);
    $OPTVAR(0) = 0;
  END_INIT_BODY
  SET_CODE
    void set_$OPT (int val)
      {
        $OPTVAR.resize (1);
        $OPTVAR(0) = val;
        reset = true;
      }

    void set_$OPT (const $TYPE& val)
      { $OPTVAR = val; reset = true; }
  END_SET_CODE
END_OPTION

OPTION
  NAME = "enforce inequality constraints"
  DOC_ITEM
Set to one of the following values to enforce the inequality
constraints specified by the @code{\"inequality constraint types\"}
option (default is 0).

@enumerate
@item To have constraint checking only in the initial condition calculation.
@item To enforce constraint checking during the integration.
@item To enforce both options 1 and 2.
@end enumerate
  END_DOC_ITEM
  TYPE = "octave_idx_type"
  INIT_VALUE = "0"
  SET_EXPR = "val"
END_OPTION

OPTION
  NAME = "inequality constraint types"
  DOC_ITEM
A vector of the same length as the state specifying the type of
inequality constraint.  Each element of the vector corresponds to an
element of the state and should be assigned one of the following
codes 

@table @asis
@item -2
Less than zero.
@item -1
Less than or equal to zero.
@item 0
Not constrained.
@item 1
Greater than or equal to zero.
@item 2
Greater than zero.
@end table

This option only has an effect if the
@code{\"enforce inequality constraints\"} option is nonzero.
  END_DOC_ITEM
  TYPE = "Array<octave_idx_type>"
  SET_ARG_TYPE = const $TYPE&
  INIT_BODY
    $OPTVAR.resize (1);
    $OPTVAR(0) = 0;
  END_INIT_BODY
  SET_CODE
    void set_$OPT (octave_idx_type val)
      {
        $OPTVAR.resize (1);
        $OPTVAR(0) = val;
        reset = true;
      }

    void set_$OPT (const $TYPE& val)
      { $OPTVAR = val; reset = true; }
  END_SET_CODE
END_OPTION

OPTION
  NAME = "initial step size"
  DOC_ITEM
Differential-algebraic problems may occaisionally suffer from severe
scaling difficulties on the first step.  If you know a great deal
about the scaling of your problem, you can help to alleviate this
problem by specifying an initial stepsize (default is computed
automatically).
  END_DOC_ITEM
  TYPE = "double"
  INIT_VALUE = "-1.0"
  SET_EXPR = "(val >= 0.0) ? val : -1.0"
END_OPTION

OPTION
  NAME = "maximum order"
  DOC_ITEM
Restrict the maximum order of the solution method.  This option must
be between 1 and 5, inclusive (default is 5).
  END_DOC_ITEM
  TYPE = "octave_idx_type"
  INIT_VALUE = "5"
  SET_EXPR = "val"
END_OPTION

OPTION
  NAME = "maximum step size"
  DOC_ITEM
Setting the maximum stepsize will avoid passing over very large
regions (default is not specified).
  END_DOC_ITEM
  TYPE = "double"
  INIT_VALUE = "-1.0"
  SET_EXPR = "(val >= 0.0) ? val : -1.0"
END_OPTION
