Cantera  2.3.0
Public Member Functions | Protected Attributes | List of all members
IDA_Solver Class Reference

Wrapper for Sundials IDA solver. More...

#include <IDA_Solver.h>

Inheritance diagram for IDA_Solver:
[legend]
Collaboration diagram for IDA_Solver:
[legend]

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...
 
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< ResidDatam_fdata
 
int m_mupper
 
int m_mlower
 
- Protected Attributes inherited from DAE_Solver
doublereal m_dummy
 
ResidJacEvalm_resid
 
integer m_neq
 Number of total equations in the system. More...
 
doublereal m_time
 

Detailed Description

Wrapper for Sundials IDA solver.

Attention
This class currently does not have any test cases or examples. Its implementation may be incomplete, and future changes to Cantera may unexpectedly cause this class to stop working. If you use this class, please consider contributing examples or test cases. In the absence of new tests or examples, this class may be deprecated and removed in a future version of Cantera. See https://github.com/Cantera/cantera/issues/267 for additional information.

Definition at line 53 of file IDA_Solver.h.

Constructor & Destructor Documentation

◆ IDA_Solver()

Constructor.

Default settings: dense Jacobian, no user-supplied Jacobian function, Newton iteration.

Parameters
fFunction that will supply the time dependent residual to be solved

Definition at line 113 of file IDA_Solver.cpp.

Member Function Documentation

◆ setTolerances() [1/2]

void setTolerances ( doublereal  reltol,
doublereal *  abstol 
)
virtual

Set error tolerances.

This version specifies a scalar relative tolerance, and a vector absolute tolerance.

Reimplemented from DAE_Solver.

Definition at line 187 of file IDA_Solver.cpp.

◆ setTolerances() [2/2]

void setTolerances ( doublereal  reltol,
doublereal  abstol 
)
virtual

Set error tolerances.

This version specifies a scalar relative tolerance, and a scalar absolute tolerance.

Reimplemented from DAE_Solver.

Definition at line 206 of file IDA_Solver.cpp.

◆ setDenseLinearSolver()

void setDenseLinearSolver ( )
virtual

Set up the problem to use a dense linear direct solver.

Reimplemented from DAE_Solver.

Definition at line 225 of file IDA_Solver.cpp.

◆ setBandedLinearSolver()

void setBandedLinearSolver ( int  m_upper,
int  m_lower 
)
virtual

Set up the problem to use a band solver.

Parameters
m_upperupper band width of the matrix
m_lowerlower band width of the matrix

Reimplemented from DAE_Solver.

Definition at line 230 of file IDA_Solver.cpp.

◆ setMaxNumSteps()

void setMaxNumSteps ( int  n)
virtual

Set the maximum number of time steps.

Parameters
ninput of maximum number of time steps

Reimplemented from DAE_Solver.

Definition at line 242 of file IDA_Solver.cpp.

References IDA_Solver::m_maxsteps.

◆ setInitialStepSize()

void setInitialStepSize ( doublereal  h0)
virtual

Set the initial step size.

Parameters
h0initial step size value

Reimplemented from DAE_Solver.

Definition at line 247 of file IDA_Solver.cpp.

References IDA_Solver::m_h0.

◆ setStopTime()

void setStopTime ( doublereal  tstop)
virtual

Set the stop time.

Parameters
tstopthe independent variable value past which the solution is not to proceed.

Reimplemented from DAE_Solver.

Definition at line 252 of file IDA_Solver.cpp.

References IDA_Solver::m_tstop.

◆ getCurrentStepFromIDA()

doublereal getCurrentStepFromIDA ( )
virtual

Get the current step size from IDA via a call.

Returns
the current step size.

Definition at line 257 of file IDA_Solver.cpp.

References IDA_Solver::m_ida_mem.

◆ setJacobianType()

void setJacobianType ( int  formJac)
virtual

Set the form of the Jacobian.

Parameters
formJacForm of the Jacobian 0 numerical Jacobian 1 analytical Jacobian given by the evalJacobianDP() function

Definition at line 264 of file IDA_Solver.cpp.

References ida_jacobian(), IDA_Solver::m_formJac, and IDA_Solver::m_ida_mem.

◆ setMaxNonlinIterations()

void setMaxNonlinIterations ( int  n)
virtual

Set the maximum number of nonlinear iterations on a timestep.

Parameters
nSet the max iterations. The default is 4, which seems awfully low to me.

Reimplemented from DAE_Solver.

Definition at line 281 of file IDA_Solver.cpp.

References IDA_Solver::m_maxNonlinIters.

◆ setMaxNonlinConvFailures()

void setMaxNonlinConvFailures ( int  n)
virtual

Set the maximum number of nonlinear solver convergence failures.

Parameters
nValue of nonlin failures. If value is exceeded, the calculation terminates.

Reimplemented from DAE_Solver.

Definition at line 286 of file IDA_Solver.cpp.

References IDA_Solver::m_maxNonlinConvFails.

◆ getOutputParameter()

doublereal getOutputParameter ( int  flag) const
virtual

Get the value of a solver-specific output parameter.

Reimplemented from DAE_Solver.

Definition at line 577 of file IDA_Solver.cpp.

◆ correctInitial_Y_given_Yp()

void correctInitial_Y_given_Yp ( doublereal *  y,
doublereal *  yp,
doublereal  tout 
)
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 462 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.

◆ correctInitial_YaYp_given_Yd()

void correctInitial_YaYp_given_Yd ( doublereal *  y,
doublereal *  yp,
doublereal  tout 
)
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.

Parameters
yCalculated value of the solution vector after the procedure ends
ypCalculated value of the solution derivative after the procedure
toutThe 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 490 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.

◆ solve()

int solve ( doublereal  tout)
virtual

Step the system to a final value of the time.

Parameters
toutFinal value of the time
Returns
the IDASolve() return flag

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 519 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.

◆ step()

double step ( doublereal  tout)
virtual

◆ init()

void init ( doublereal  t0)
virtual

◆ solution()

doublereal solution ( int  k) const
virtual

the current value of solution component k.

Reimplemented from DAE_Solver.

Definition at line 167 of file IDA_Solver.cpp.

References IDA_Solver::m_y.

◆ derivative()

doublereal derivative ( int  k) const
virtual

the current value of the derivative of solution component k.

Reimplemented from DAE_Solver.

Definition at line 177 of file IDA_Solver.cpp.

References IDA_Solver::m_ydot.

Member Data Documentation

◆ m_ida_mem

void* m_ida_mem
protected

◆ m_t0

doublereal m_t0
protected

Initial value of the time.

Definition at line 241 of file IDA_Solver.h.

Referenced by IDA_Solver::correctInitial_Y_given_Yp(), IDA_Solver::correctInitial_YaYp_given_Yd(), and IDA_Solver::init().

◆ m_y

N_Vector m_y
protected

◆ m_ydot

N_Vector m_ydot
protected

Current value of the derivative of the solution vector.

Definition at line 247 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().

◆ m_hmax

doublereal m_hmax
protected

Maximum value of the timestep allowed.

Definition at line 260 of file IDA_Solver.h.

◆ m_hmin

doublereal m_hmin
protected

Minimum value of the timestep allowed.

Definition at line 263 of file IDA_Solver.h.

◆ m_h0

doublereal m_h0
protected

Value of the initial time step.

Definition at line 266 of file IDA_Solver.h.

Referenced by IDA_Solver::correctInitial_Y_given_Yp(), IDA_Solver::correctInitial_YaYp_given_Yd(), and IDA_Solver::setInitialStepSize().

◆ m_maxsteps

int m_maxsteps
protected

Maximum number of time steps allowed.

Definition at line 269 of file IDA_Solver.h.

Referenced by IDA_Solver::setMaxNumSteps().

◆ m_maxord

int m_maxord
protected

maximum time step order of the method

Definition at line 272 of file IDA_Solver.h.

◆ m_formJac

int m_formJac
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 281 of file IDA_Solver.h.

Referenced by IDA_Solver::setJacobianType().

◆ m_tstop

doublereal m_tstop
protected

maximum time

Definition at line 284 of file IDA_Solver.h.

Referenced by IDA_Solver::setStopTime().

◆ m_told_old

doublereal m_told_old
protected

Value of the previous, previous time.

Definition at line 287 of file IDA_Solver.h.

Referenced by IDA_Solver::init(), IDA_Solver::solve(), and IDA_Solver::step().

◆ m_told

doublereal m_told
protected

Value of the previous time.

Definition at line 290 of file IDA_Solver.h.

Referenced by IDA_Solver::init(), IDA_Solver::solve(), and IDA_Solver::step().

◆ m_tcurrent

doublereal m_tcurrent
protected

Value of the current time.

Definition at line 293 of file IDA_Solver.h.

Referenced by IDA_Solver::init(), IDA_Solver::solve(), and IDA_Solver::step().

◆ m_deltat

doublereal m_deltat
protected

Value of deltaT for the current step.

Definition at line 296 of file IDA_Solver.h.

Referenced by IDA_Solver::solve(), and IDA_Solver::step().

◆ m_maxErrTestFails

int m_maxErrTestFails
protected

maximum number of error test failures

Definition at line 299 of file IDA_Solver.h.

◆ m_maxNonlinIters

int m_maxNonlinIters
protected

Maximum number of nonlinear solver iterations at one solution.

If zero, this is the default of 4.

Definition at line 305 of file IDA_Solver.h.

Referenced by IDA_Solver::setMaxNonlinIterations().

◆ m_maxNonlinConvFails

int m_maxNonlinConvFails
protected

Maximum number of nonlinear convergence failures.

Definition at line 308 of file IDA_Solver.h.

Referenced by IDA_Solver::setMaxNonlinConvFailures().

◆ m_setSuppressAlg

int m_setSuppressAlg
protected

If true, the algebraic variables don't contribute to error tolerances.

Definition at line 311 of file IDA_Solver.h.


The documentation for this class was generated from the following files: