Cantera
2.4.0
|
Wrapper for Sundials IDA solver. More...
#include <IDA_Solver.h>
Public Member Functions | |
IDA_Solver (ResidJacEval &f) | |
Constructor. More... | |
virtual void | setTolerances (doublereal reltol, doublereal *abstol) |
Set error tolerances. More... | |
virtual void | setTolerances (doublereal reltol, doublereal abstol) |
Set error tolerances. More... | |
virtual void | setLinearSolverType (int solverType) |
virtual void | setDenseLinearSolver () |
Set up the problem to use a dense linear direct solver. More... | |
virtual void | setBandedLinearSolver (int m_upper, int m_lower) |
Set up the problem to use a band solver. More... | |
virtual void | setMaxOrder (int n) |
virtual void | setMaxNumSteps (int n) |
Set the maximum number of time steps. More... | |
virtual void | setInitialStepSize (doublereal h0) |
Set the initial step size. More... | |
virtual void | setStopTime (doublereal tstop) |
Set the stop time. More... | |
virtual double | getCurrentStepFromIDA () |
Get the current step size from IDA via a call. More... | |
virtual void | setJacobianType (int formJac) |
Set the form of the Jacobian. More... | |
virtual void | setMaxErrTestFailures (int n) |
virtual void | setMaxNonlinIterations (int n) |
Set the maximum number of nonlinear iterations on a timestep. More... | |
virtual void | setMaxNonlinConvFailures (int n) |
Set the maximum number of nonlinear solver convergence failures. More... | |
virtual void | inclAlgebraicInErrorTest (bool yesno) |
virtual doublereal | getOutputParameter (int flag) const |
Get the value of a solver-specific output parameter. More... | |
virtual void | correctInitial_Y_given_Yp (doublereal *y, doublereal *yp, doublereal tout) |
Calculate consistent value of the starting solution given the starting solution derivatives. More... | |
virtual void | correctInitial_YaYp_given_Yd (doublereal *y, doublereal *yp, doublereal tout) |
Calculate consistent value of the algebraic constraints and derivatives at the start of the problem. More... | |
virtual int | solve (doublereal tout) |
Step the system to a final value of the time. More... | |
virtual doublereal | step (doublereal tout) |
Take one internal step. More... | |
virtual void | init (doublereal t0) |
initialize. More... | |
virtual doublereal | solution (int k) const |
the current value of solution component k. More... | |
virtual const doublereal * | solutionVector () const |
virtual doublereal | derivative (int k) const |
the current value of the derivative of solution component k. More... | |
virtual const doublereal * | derivativeVector () const |
void * | IDAMemory () |
Public Member Functions inherited from DAE_Solver | |
DAE_Solver (ResidJacEval &f) | |
void | setJacobian (Jacobian &jac) |
Specify a Jacobian evaluator. More... | |
virtual void | setMaxStepSize (doublereal dtmax) |
int | nEquations () const |
Number of equations. More... | |
virtual void | setInputParameter (int flag, doublereal value) |
Set a solver-specific input parameter. More... | |
Protected Attributes | |
void * | m_ida_mem |
Pointer to the IDA memory for the problem. More... | |
void * | m_linsol |
Sundials linear solver object. More... | |
void * | m_linsol_matrix |
matrix used by Sundials More... | |
doublereal | m_t0 |
Initial value of the time. More... | |
N_Vector | m_y |
Current value of the solution vector. More... | |
N_Vector | m_ydot |
Current value of the derivative of the solution vector. More... | |
N_Vector | m_id |
N_Vector | m_constraints |
N_Vector | m_abstol |
int | m_type |
int | m_itol |
int | m_iter |
doublereal | m_reltol |
doublereal | m_abstols |
int | m_nabs |
doublereal | m_hmax |
Maximum value of the timestep allowed. More... | |
doublereal | m_hmin |
Minimum value of the timestep allowed. More... | |
doublereal | m_h0 |
Value of the initial time step. More... | |
int | m_maxsteps |
Maximum number of time steps allowed. More... | |
int | m_maxord |
maximum time step order of the method More... | |
int | m_formJac |
Form of the Jacobian. More... | |
doublereal | m_tstop |
maximum time More... | |
doublereal | m_told_old |
Value of the previous, previous time. More... | |
doublereal | m_told |
Value of the previous time. More... | |
doublereal | m_tcurrent |
Value of the current time. More... | |
doublereal | m_deltat |
Value of deltaT for the current step. More... | |
int | m_maxErrTestFails |
maximum number of error test failures More... | |
int | m_maxNonlinIters |
Maximum number of nonlinear solver iterations at one solution. More... | |
int | m_maxNonlinConvFails |
Maximum number of nonlinear convergence failures. More... | |
int | m_setSuppressAlg |
If true, the algebraic variables don't contribute to error tolerances. More... | |
std::unique_ptr< ResidData > | m_fdata |
int | m_mupper |
int | m_mlower |
Protected Attributes inherited from DAE_Solver | |
doublereal | m_dummy |
ResidJacEval & | m_resid |
integer | m_neq |
Number of total equations in the system. More... | |
doublereal | m_time |
Wrapper for Sundials IDA solver.
Definition at line 40 of file IDA_Solver.h.
IDA_Solver | ( | ResidJacEval & | f | ) |
Constructor.
Default settings: dense Jacobian, no user-supplied Jacobian function, Newton iteration.
f | Function that will supply the time dependent residual to be solved |
Definition at line 150 of file IDA_Solver.cpp.
|
virtual |
Set error tolerances.
This version specifies a scalar relative tolerance, and a vector absolute tolerance.
Reimplemented from DAE_Solver.
Definition at line 224 of file IDA_Solver.cpp.
|
virtual |
Set error tolerances.
This version specifies a scalar relative tolerance, and a scalar absolute tolerance.
Reimplemented from DAE_Solver.
Definition at line 243 of file IDA_Solver.cpp.
|
virtual |
Set up the problem to use a dense linear direct solver.
Reimplemented from DAE_Solver.
Definition at line 262 of file IDA_Solver.cpp.
|
virtual |
Set up the problem to use a band solver.
m_upper | upper band width of the matrix |
m_lower | lower band width of the matrix |
Reimplemented from DAE_Solver.
Definition at line 267 of file IDA_Solver.cpp.
|
virtual |
Set the maximum number of time steps.
n | input of maximum number of time steps |
Reimplemented from DAE_Solver.
Definition at line 279 of file IDA_Solver.cpp.
References IDA_Solver::m_maxsteps.
|
virtual |
Set the initial step size.
h0 | initial step size value |
Reimplemented from DAE_Solver.
Definition at line 284 of file IDA_Solver.cpp.
References IDA_Solver::m_h0.
|
virtual |
Set the stop time.
tstop | the independent variable value past which the solution is not to proceed. |
Reimplemented from DAE_Solver.
Definition at line 289 of file IDA_Solver.cpp.
References IDA_Solver::m_tstop.
|
virtual |
Get the current step size from IDA via a call.
Definition at line 294 of file IDA_Solver.cpp.
References IDA_Solver::m_ida_mem.
Referenced by ida_jacobian(), and ida_resid().
|
virtual |
Set the form of the Jacobian.
formJac | Form of the Jacobian 0 numerical Jacobian 1 analytical Jacobian given by the evalJacobianDP() function |
Definition at line 301 of file IDA_Solver.cpp.
References ida_jacobian(), IDA_Solver::m_formJac, and IDA_Solver::m_ida_mem.
|
virtual |
Set the maximum number of nonlinear iterations on a timestep.
n | Set the max iterations. The default is 4, which seems awfully low to me. |
Reimplemented from DAE_Solver.
Definition at line 322 of file IDA_Solver.cpp.
References IDA_Solver::m_maxNonlinIters.
|
virtual |
Set the maximum number of nonlinear solver convergence failures.
n | Value of nonlin failures. If value is exceeded, the calculation terminates. |
Reimplemented from DAE_Solver.
Definition at line 327 of file IDA_Solver.cpp.
References IDA_Solver::m_maxNonlinConvFails.
|
virtual |
Get the value of a solver-specific output parameter.
Reimplemented from DAE_Solver.
Definition at line 649 of file IDA_Solver.cpp.
|
virtual |
Calculate consistent value of the starting solution given the starting solution derivatives.
This method may be called if the initial conditions do not satisfy the residual equation F = 0. Given the derivatives of all variables, this method computes the initial y values.
Reimplemented from DAE_Solver.
Definition at line 534 of file IDA_Solver.cpp.
References IDA_Solver::m_h0, IDA_Solver::m_ida_mem, DAE_Solver::m_neq, IDA_Solver::m_t0, IDA_Solver::m_y, and IDA_Solver::m_ydot.
|
virtual |
Calculate consistent value of the algebraic constraints and derivatives at the start of the problem.
This method may be called if the initial conditions do not satisfy the residual equation F = 0. Given the initial values of all differential variables, it computes the initial values of all algebraic variables and the initial derivatives of all differential variables.
y | Calculated value of the solution vector after the procedure ends |
yp | Calculated value of the solution derivative after the procedure |
tout | The first value of t at which a soluton will be requested (from IDASolve). (This is needed here to determine the direction of integration and rough scale in the independent variable t. |
Reimplemented from DAE_Solver.
Definition at line 562 of file IDA_Solver.cpp.
References IDA_Solver::m_h0, IDA_Solver::m_ida_mem, DAE_Solver::m_neq, IDA_Solver::m_t0, IDA_Solver::m_y, and IDA_Solver::m_ydot.
|
virtual |
Step the system to a final value of the time.
tout | Final value of the time |
The return values for IDASolve are described below. (The numerical return values are defined above in this file.) All unsuccessful returns give a negative return value.
IDA_SUCCESS IDASolve succeeded and no roots were found.
IDA_ROOT_RETURN: IDASolve succeeded, and found one or more roots. If nrtfn > 1, call IDAGetRootInfo to see which g_i were found to have a root at (*tret).
IDA_TSTOP_RETURN: IDASolve returns computed results for the independent variable value tstop. That is, tstop was reached.
IDA_MEM_NULL: The IDA_mem argument was NULL.
IDA_ILL_INPUT: One of the inputs to IDASolve is illegal. This includes the situation when a component of the error weight vectors becomes < 0 during internal stepping. It also includes the situation where a root of one of the root functions was found both at t0 and very near t0. The ILL_INPUT flag will also be returned if the linear solver function IDA— (called by the user after calling IDACreate) failed to set one of the linear solver-related fields in ida_mem or if the linear solver's init routine failed. In any case, the user should see the printed error message for more details.
IDA_TOO_MUCH_WORK: The solver took mxstep internal steps but could not reach tout. The default value for mxstep is MXSTEP_DEFAULT = 500.
IDA_TOO_MUCH_ACC: The solver could not satisfy the accuracy demanded by the user for some internal step.
IDA_ERR_FAIL: Error test failures occurred too many times (=MXETF = 10) during one internal step.
IDA_CONV_FAIL: Convergence test failures occurred too many times (= MXNCF = 10) during one internal step.
IDA_LSETUP_FAIL: The linear solver's setup routine failed in an unrecoverable manner.
IDA_LSOLVE_FAIL: The linear solver's solve routine failed in an unrecoverable manner.
IDA_CONSTR_FAIL: The inequality constraints were violated, and the solver was unable to recover.
IDA_REP_RES_ERR: The user's residual function repeatedly returned a recoverable error flag, but the solver was unable to recover.
IDA_RES_FAIL: The user's residual function returned a nonrecoverable error flag.
Reimplemented from DAE_Solver.
Definition at line 591 of file IDA_Solver.cpp.
References IDA_Solver::m_deltat, IDA_Solver::m_ida_mem, IDA_Solver::m_tcurrent, IDA_Solver::m_told, IDA_Solver::m_told_old, IDA_Solver::m_y, and IDA_Solver::m_ydot.
|
virtual |
Take one internal step.
Reimplemented from DAE_Solver.
Definition at line 625 of file IDA_Solver.cpp.
References IDA_Solver::m_deltat, IDA_Solver::m_ida_mem, IDA_Solver::m_tcurrent, IDA_Solver::m_told, IDA_Solver::m_told_old, IDA_Solver::m_y, and IDA_Solver::m_ydot.
|
virtual |
initialize.
Base class method does nothing.
Reimplemented from DAE_Solver.
Definition at line 341 of file IDA_Solver.cpp.
References ResidJacEval::getInitialConditions(), IDA_Solver::m_ida_mem, DAE_Solver::m_neq, IDA_Solver::m_t0, IDA_Solver::m_tcurrent, IDA_Solver::m_told, IDA_Solver::m_told_old, IDA_Solver::m_y, and IDA_Solver::m_ydot.
|
virtual |
the current value of solution component k.
Reimplemented from DAE_Solver.
Definition at line 204 of file IDA_Solver.cpp.
References IDA_Solver::m_y.
|
virtual |
the current value of the derivative of solution component k.
Reimplemented from DAE_Solver.
Definition at line 214 of file IDA_Solver.cpp.
References IDA_Solver::m_ydot.
|
protected |
Pointer to the IDA memory for the problem.
Definition at line 225 of file IDA_Solver.h.
Referenced by IDA_Solver::correctInitial_Y_given_Yp(), IDA_Solver::correctInitial_YaYp_given_Yd(), IDA_Solver::getCurrentStepFromIDA(), IDA_Solver::init(), IDA_Solver::setJacobianType(), IDA_Solver::solve(), and IDA_Solver::step().
|
protected |
Sundials linear solver object.
Definition at line 226 of file IDA_Solver.h.
|
protected |
matrix used by Sundials
Definition at line 227 of file IDA_Solver.h.
|
protected |
Initial value of the time.
Definition at line 230 of file IDA_Solver.h.
Referenced by IDA_Solver::correctInitial_Y_given_Yp(), IDA_Solver::correctInitial_YaYp_given_Yd(), and IDA_Solver::init().
|
protected |
Current value of the solution vector.
Definition at line 233 of file IDA_Solver.h.
Referenced by IDA_Solver::correctInitial_Y_given_Yp(), IDA_Solver::correctInitial_YaYp_given_Yd(), IDA_Solver::init(), IDA_Solver::solution(), IDA_Solver::solve(), and IDA_Solver::step().
|
protected |
Current value of the derivative of the solution vector.
Definition at line 236 of file IDA_Solver.h.
Referenced by IDA_Solver::correctInitial_Y_given_Yp(), IDA_Solver::correctInitial_YaYp_given_Yd(), IDA_Solver::derivative(), IDA_Solver::init(), IDA_Solver::solve(), and IDA_Solver::step().
|
protected |
Maximum value of the timestep allowed.
Definition at line 249 of file IDA_Solver.h.
|
protected |
Minimum value of the timestep allowed.
Definition at line 252 of file IDA_Solver.h.
|
protected |
Value of the initial time step.
Definition at line 255 of file IDA_Solver.h.
Referenced by IDA_Solver::correctInitial_Y_given_Yp(), IDA_Solver::correctInitial_YaYp_given_Yd(), and IDA_Solver::setInitialStepSize().
|
protected |
Maximum number of time steps allowed.
Definition at line 258 of file IDA_Solver.h.
Referenced by IDA_Solver::setMaxNumSteps().
|
protected |
maximum time step order of the method
Definition at line 261 of file IDA_Solver.h.
|
protected |
Form of the Jacobian.
0 numerical Jacobian created by IDA 1 analytical Jacobian. Must have populated the evalJacobianDP() function in the ResidJacEval class. 2 numerical Jacobian formed by the ResidJacEval class (unimplemented)
Definition at line 270 of file IDA_Solver.h.
Referenced by IDA_Solver::setJacobianType().
|
protected |
|
protected |
Value of the previous, previous time.
Definition at line 276 of file IDA_Solver.h.
Referenced by IDA_Solver::init(), IDA_Solver::solve(), and IDA_Solver::step().
|
protected |
Value of the previous time.
Definition at line 279 of file IDA_Solver.h.
Referenced by IDA_Solver::init(), IDA_Solver::solve(), and IDA_Solver::step().
|
protected |
Value of the current time.
Definition at line 282 of file IDA_Solver.h.
Referenced by IDA_Solver::init(), IDA_Solver::solve(), and IDA_Solver::step().
|
protected |
Value of deltaT for the current step.
Definition at line 285 of file IDA_Solver.h.
Referenced by IDA_Solver::solve(), and IDA_Solver::step().
|
protected |
maximum number of error test failures
Definition at line 288 of file IDA_Solver.h.
|
protected |
Maximum number of nonlinear solver iterations at one solution.
If zero, this is the default of 4.
Definition at line 294 of file IDA_Solver.h.
Referenced by IDA_Solver::setMaxNonlinIterations().
|
protected |
Maximum number of nonlinear convergence failures.
Definition at line 297 of file IDA_Solver.h.
Referenced by IDA_Solver::setMaxNonlinConvFailures().
|
protected |
If true, the algebraic variables don't contribute to error tolerances.
Definition at line 300 of file IDA_Solver.h.