Cantera  2.0
Public Member Functions | Protected Attributes | List of all members
ResidJacEval Class Reference

Wrappers for the function evaluators for Nonlinear solvers and Time steppers. More...

#include <ResidJacEval.h>

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

Public Member Functions

 ResidJacEval (doublereal atol=1.0e-13)
 Default constructor.
 
 ResidJacEval (const ResidJacEval &right)
 Copy Constructor for the ResidJacEval object.
 
virtual ~ResidJacEval ()
 Destructor. Does nothing.
 
ResidJacEvaloperator= (const ResidJacEval &right)
 Assignment operator.
 
virtual ResidJacEvalduplMyselfAsResidJacEval () const
 Duplication routine for objects which inherit from residJacEval.
 
virtual int nEquations () const
 Return the number of equations in the equation system.
 
virtual int evalResidNJ (const doublereal t, const doublereal delta_t, const doublereal *const y, const doublereal *const ydot, doublereal *const resid, const ResidEval_Type_Enum evalType=Base_ResidEval, const int id_x=-1, const doublereal delta_x=0.0)
 Evaluate the residual function.
 
virtual int eval (const doublereal t, const doublereal *const y, const doublereal *const ydot, doublereal *const r)
 Evaluate the residual function.
 
virtual int getInitialConditions (const doublereal t0, doublereal *const y, doublereal *const ydot)
 Fill in the initial conditions.
 
virtual doublereal filterNewStep (const doublereal t, const doublereal *const ybase, doublereal *const step)
 Filter the solution predictions.
 
virtual doublereal filterSolnPrediction (const doublereal t, doublereal *const y)
 Filter the solution predictions.
 
void setAtol (doublereal atol)
 Set a global value of the absolute tolerance.
 
virtual int evalTimeTrackingEqns (const doublereal t, const doublereal delta_t, const doublereal *const y, const doublereal *const ydot)
 Evaluate the time tracking equations, if any.
 
virtual bool evalStoppingCritera (const doublereal t, const doublereal delta_t, const doublereal *const y, const doublereal *const ydot)
 Evaluate any stopping criteria other than a final time limit.
 
virtual int calcDeltaSolnVariables (const doublereal t, const doublereal *const y, const doublereal *const ydot, doublereal *const delta_y, const doublereal *const solnWeights=0)
 Return a vector of delta y's for calculation of the numerical Jacobian.
 
virtual void calcSolnScales (const doublereal t, const doublereal *const y, const doublereal *const y_old, doublereal *const yScales)
 Returns a vector of column scale factors that can be used to column scale Jacobians.
 
virtual void user_out2 (const int ifunc, const doublereal t, const doublereal delta_t, const doublereal *const y, const doublereal *const ydot)
 This function may be used to create output at various points in the execution of an application.
 
virtual void user_out (const int ifunc, const doublereal t, const doublereal *y, const doublereal *ydot)
 This function may be used to create output at various points in the execution of an application.
 
virtual int matrixConditioning (doublereal *const matrix, const int nrows, doublereal *const rhs)
 Multiply the matrix by another matrix that leads to better conditioning.
 
virtual int evalJacobian (const doublereal t, const doublereal delta_t, doublereal cj, const doublereal *const y, const doublereal *const ydot, GeneralMatrix &J, doublereal *const resid)
 Calculate an analytical jacobian and the residual at the current time and values.
 
virtual int evalJacobianDP (const doublereal t, const doublereal delta_t, doublereal cj, const doublereal *const y, const doublereal *const ydot, doublereal *const *jacobianColPts, doublereal *const resid)
 Calculate an analytical jacobian and the residual at the current time and values.
 
virtual void constrain (const int k, const int flag)
 Constrain solution component k.
 
int constraint (const int k) const
 
virtual void initSizes ()
 Initialization function.
 
virtual void setAlgebraic (const int k)
 Specify that solution component k is purely algebraic - that is, the derivative of this component does not appear in the residual function.
 
virtual bool isAlgebraic (const int k)
 
virtual int evalSS (const doublereal t, const doublereal *const y, doublereal *const r)
 
virtual int evalSimpleTD (const doublereal t, const doublereal *const y, const doublereal *const yold, doublereal deltaT, doublereal *const r)
 
virtual void writeSolution (int ievent, const double time, const double deltaT, const int time_step_num, const double *y, const double *ydot)
 Write out to a file or to standard output the current solution.
 
int nparams () const
 Return the number of parameters in the calculation.
 

Protected Attributes

doublereal m_atol
 constant value of atol
 
int neq_
 Number of equations.
 
std::vector< int > m_alg
 Mapping vector that stores whether a degree of freedom is a DAE or not.
 
std::map< int, int > m_constrain
 

Detailed Description

Wrappers for the function evaluators for Nonlinear solvers and Time steppers.

A class for full (non-sparse dense matrices with Fortran-compatible data storage. The class adds support for identifying what types of calls are made to the residual evaluator by adding the ResidEval_Type_Enum class.

Definition at line 53 of file ResidJacEval.h.

Constructor & Destructor Documentation

ResidJacEval ( doublereal  atol = 1.0e-13)

Default constructor.

Parameters
atolInitial value of the global tolerance (defaults to 1.0E-13)

Definition at line 25 of file ResidJacEval.cpp.

Referenced by ResidJacEval::duplMyselfAsResidJacEval().

ResidJacEval ( const ResidJacEval right)

Copy Constructor for the ResidJacEval object.

Parameters
rightItem to be copied

Definition at line 34 of file ResidJacEval.cpp.

References ResidJacEval::operator=().

~ResidJacEval ( )
virtual

Destructor. Does nothing.

Definition at line 40 of file ResidJacEval.cpp.

Member Function Documentation

ResidJacEval & operator= ( const ResidJacEval right)

Assignment operator.

This is NOT a virtual function.

Parameters
rightReference to ResidJacEval object to be copied into the current one.

Definition at line 44 of file ResidJacEval.cpp.

References ResidJacEval::m_atol, and ResidJacEval::neq_.

Referenced by ResidJacEval::ResidJacEval().

ResidJacEval * duplMyselfAsResidJacEval ( ) const
virtual

Duplication routine for objects which inherit from residJacEval.

This virtual routine can be used to duplicate ResidJacEval objects inherited from ResidJacEval even if the application only has a pointer to ResidJacEval to work with.

These routines are basically wrappers around the derived copy constructor.

Definition at line 67 of file ResidJacEval.cpp.

References ResidJacEval::ResidJacEval().

Referenced by NonlinearSolver::operator=().

int nEquations ( ) const
virtual

Return the number of equations in the equation system.

Implements ResidEval.

Definition at line 73 of file ResidJacEval.cpp.

References ResidJacEval::neq_.

Referenced by BEulerInt::doNewtonSolve(), DAE_Solver::nEquations(), and NonlinearSolver::NonlinearSolver().

int evalResidNJ ( const doublereal  t,
const doublereal  delta_t,
const doublereal *const  y,
const doublereal *const  ydot,
doublereal *const  resid,
const ResidEval_Type_Enum  evalType = Base_ResidEval,
const int  id_x = -1,
const doublereal  delta_x = 0.0 
)
virtual

Evaluate the residual function.

Parameters
tTime (input)
delta_tThe current value of the time step (input)
ySolution vector (input, do not modify)
ydotRate of change of solution vector. (input, do not modify)
residValue of the residual that is computed (output)
evalTypeType of the residual being computed (defaults to Base_ResidEval)
id_xIndex of the variable that is being numerically differenced to find the jacobian (defaults to -1, which indicates that no variable is being differenced or that the residual doesn't take this issue into account)
delta_xValue of the delta used in the numerical differencing
Returns
Returns a flag to indicate that operation is successful. 1 Means a successful operation -0 or neg value Means an unsuccessful operation

Definition at line 309 of file ResidJacEval.cpp.

Referenced by NonlinearSolver::beuler_jac(), BEulerInt::doNewtonSolve(), NonlinearSolver::doResidualCalc(), and ResidJacEval::eval().

int eval ( const doublereal  t,
const doublereal *const  y,
const doublereal *const  ydot,
doublereal *const  r 
)
virtual

Evaluate the residual function.

Called by the integrator.

Parameters
ttime. (input)
ysolution vector. (input)
ydotrate of change of solution vector. (input)
rresidual vector (output)

Reimplemented from ResidEval.

Definition at line 317 of file ResidJacEval.cpp.

References ResidJacEval::evalResidNJ().

int getInitialConditions ( const doublereal  t0,
doublereal *const  y,
doublereal *const  ydot 
)
virtual

Fill in the initial conditions.

Values for both the solution and the value of ydot may be provided.

Parameters
t0Time (input)
ySolution vector (output)
ydotRate of change of solution vector. (output)
Returns
Returns a flag to indicate that operation is successful. 1 Means a successful operation -0 or neg value Means an unsuccessful operation

Values for both the solution and the value of ydot may be provided.

Parameters
t0Time (input)
ySolution vector (output)
ydotRate of change of solution vector. (output)

Reimplemented from ResidEval.

Definition at line 100 of file ResidJacEval.cpp.

References ResidJacEval::neq_.

doublereal filterNewStep ( const doublereal  t,
const doublereal *const  ybase,
doublereal *const  step 
)
virtual

Filter the solution predictions.

Codes might provide a predicted step change. This routine filters the predicted solution vector eliminating illegal directions.

Parameters
tTime (input)
ybaseSolution vector (input, output)
stepProposed step in the solution that will be cropped
Returns
Return the norm of the amount of filtering

Definition at line 233 of file ResidJacEval.cpp.

Referenced by NonlinearSolver::filterNewStep().

doublereal filterSolnPrediction ( const doublereal  t,
doublereal *const  y 
)
virtual

Filter the solution predictions.

Codes might provide a predicted solution vector. This routine filters the predicted solution vector.

Parameters
tTime (input)
ySolution vector (input, output)
Returns
Return the norm of the amount of filtering

Definition at line 246 of file ResidJacEval.cpp.

Referenced by BEulerInt::calc_y_pred(), and NonlinearSolver::filterNewSolution().

void setAtol ( doublereal  atol)

Set a global value of the absolute tolerance.

Parameters
atolValue of atol

Definition at line 82 of file ResidJacEval.cpp.

References ResidJacEval::m_atol.

int evalTimeTrackingEqns ( const doublereal  t,
const doublereal  delta_t,
const doublereal *const  y,
const doublereal *const  ydot 
)
virtual

Evaluate the time tracking equations, if any.

Evaluate time integrated quantities that are calculated at the end of every successful time step. This call is made once at the end of every successful time step that advances the time. It's also made once at the start of the time stepping.

Parameters
tTime (input)
delta_tThe current value of the time step (input)
ySolution vector (input, do not modify)
ydotRate of change of solution vector. (input, do not modify)
Returns
Returns a flag to indicate that operation is successful. 1 Means a successful operation -0 or neg value Means an unsuccessful operation

Evaluate time integrated quantities that are calculated at the end of every successful time step. This call is made once at the end of every successful time step that advances the time. It's also made once at the start of the time stepping.

Parameters
tTime (input)
delta_tThe current value of the time step (input)
ySolution vector (input, do not modify)
ydotRate of change of solution vector. (input, do not modify)

Definition at line 162 of file ResidJacEval.cpp.

bool evalStoppingCritera ( const doublereal  t,
const doublereal  delta_t,
const doublereal *const  y,
const doublereal *const  ydot 
)
virtual

Evaluate any stopping criteria other than a final time limit.

If we are to stop the time integration for any reason other than reaching a final time limit, tout, provide a test here. This call is made at the end of every successful time step iteration

Returns
If true, the the time stepping is stopped. If false, then time stepping is stopped if t >= tout Defaults to false.
Parameters
tTime (input)
delta_tThe current value of the time step (input)
ySolution vector (input, do not modify)
ydotRate of change of solution vector. (input, do not modify)

Definition at line 265 of file ResidJacEval.cpp.

int calcDeltaSolnVariables ( const doublereal  t,
const doublereal *const  y,
const doublereal *const  ydot,
doublereal *const  delta_y,
const doublereal *const  solnWeights = 0 
)
virtual

Return a vector of delta y's for calculation of the numerical Jacobian.

There is a default algorithm provided.

 delta_y[i] = atol[i] + 1.0E-6 ysoln[i]
 delta_y[i] = atol[i] + MAX(1.0E-6 ysoln[i] * 0.01 * solnWeights[i])
Parameters
tTime (input)
ySolution vector (input, do not modify)
ydotRate of change of solution vector. (input, do not modify)
delta_yValue of the delta to be used in calculating the numerical jacobian
solnWeightsValue of the solution weights that are used in determining convergence (default = 0)
Returns
Returns a flag to indicate that operation is successful. 1 Means a successful operation -0 or neg value Means an unsuccessful operation

Definition at line 186 of file ResidJacEval.cpp.

References ResidJacEval::m_atol, ckr::max(), and ResidJacEval::neq_.

Referenced by NonlinearSolver::beuler_jac().

void calcSolnScales ( const doublereal  t,
const doublereal *const  y,
const doublereal *const  y_old,
doublereal *const  yScales 
)
virtual

Returns a vector of column scale factors that can be used to column scale Jacobians.

Default to yScales[] = 1.0

Parameters
tTime (input)
ySolution vector (input, do not modify)
y_oldOld Solution vector (input, do not modify)
yScalesValue of the column scales

Definition at line 212 of file ResidJacEval.cpp.

References ResidJacEval::neq_.

Referenced by NonlinearSolver::calcColumnScales().

void user_out2 ( const int  ifunc,
const doublereal  t,
const doublereal  delta_t,
const doublereal *const  y,
const doublereal *const  ydot 
)
virtual

This function may be used to create output at various points in the execution of an application.

Parameters
ifuncidentity of the call 0 Initial call 1 Called at the end of every successful time step -1 Called at the end of every unsuccessful time step 2 Called at the end of every call to integrateRJE()
tTime (input)
delta_tThe current value of the time step (input)
ySolution vector (input, do not modify)
ydotRate of change of solution vector. (input)

Definition at line 128 of file ResidJacEval.cpp.

Referenced by ResidJacEval::user_out().

void user_out ( const int  ifunc,
const doublereal  t,
const doublereal *  y,
const doublereal *  ydot 
)
virtual

This function may be used to create output at various points in the execution of an application.

This routine calls user_out2().

Parameters
ifuncidentity of the call
tTime (input)
ySolution vector (input, do not modify)
ydotRate of change of solution vector. (input)

Definition at line 144 of file ResidJacEval.cpp.

References ResidJacEval::user_out2().

int matrixConditioning ( doublereal *const  matrix,
const int  nrows,
doublereal *const  rhs 
)
virtual

Multiply the matrix by another matrix that leads to better conditioning.

Provide a left sided matrix that will multiply the current jacobian, after scaling and lead to a better conditioned system. This routine is called just before the matrix is factored.

Original Problem: J delta_x = - Resid

New problem: M (J delta_x) = - M Resid

Parameters
matrixPointer to the current jacobian (if zero, it's already been factored)
nrowsoffsets for the matrix
rhsresidual vector. This also needs to be lhs multiplied by M
Returns
Returns a flag to indicate that operation is successful. 1 Means a successful operation -0 or neg value Means an unsuccessful operation

Definition at line 290 of file ResidJacEval.cpp.

Referenced by BEulerInt::doNewtonSolve().

int evalJacobian ( const doublereal  t,
const doublereal  delta_t,
doublereal  cj,
const doublereal *const  y,
const doublereal *const  ydot,
GeneralMatrix J,
doublereal *const  resid 
)
virtual

Calculate an analytical jacobian and the residual at the current time and values.

Only called if the jacFormation method is set to analytical

Parameters
tTime (input)
delta_tThe current value of the time step (input)
cjCoefficient of yprime used in the evaluation of the jacobian
ySolution vector (input, do not modify)
ydotRate of change of solution vector. (input, do not modify)
JReference to the SquareMatrix object to be calculated (output)
residValue of the residual that is computed (output)
Returns
Returns a flag to indicate that operation is successful. 1 Means a successful operation -0 or neg value Means an unsuccessful operation

Definition at line 337 of file ResidJacEval.cpp.

References GeneralMatrix::colPts(), and ResidJacEval::evalJacobianDP().

Referenced by NonlinearSolver::beuler_jac().

int evalJacobianDP ( const doublereal  t,
const doublereal  delta_t,
doublereal  cj,
const doublereal *const  y,
const doublereal *const  ydot,
doublereal *const *  jacobianColPts,
doublereal *const  resid 
)
virtual

Calculate an analytical jacobian and the residual at the current time and values.

Only called if the jacFormation method is set to analytical

Parameters
tTime (input)
delta_tThe current value of the time step (input)
cjCoefficient of yprime used in the evaluation of the jacobian
ySolution vector (input, do not modify)
ydotRate of change of solution vector. (input, do not modify)
jacobianColPtsPointer to the vector of pts to columns of the SquareMatrix object to be calculated (output)
residValue of the residual that is computed (output)
Returns
Returns a flag to indicate that operation is successful. 1 Means a successful operation -0 or neg value Means an unsuccessful operation

Definition at line 360 of file ResidJacEval.cpp.

Referenced by ResidJacEval::evalJacobian().

virtual void constrain ( const int  k,
const int  flag 
)
inlinevirtualinherited

Constrain solution component k.

Possible values for 'flag' are:

  • c_NONE no constraint
  • c_GE_ZERO >= 0
  • c_GT_ZERO > 0
  • c_LE_ZERO <= 0
  • c_LT_ZERO < 0

Definition at line 48 of file ResidEval.h.

virtual void initSizes ( )
inlinevirtualinherited

Initialization function.

Definition at line 60 of file ResidEval.h.

References ResidEval::m_alg, and ResidEval::nEquations().

Referenced by ResidEval::getInitialConditions(), and ResidEval::setAlgebraic().

virtual void setAlgebraic ( const int  k)
inlinevirtualinherited

Specify that solution component k is purely algebraic - that is, the derivative of this component does not appear in the residual function.

Definition at line 70 of file ResidEval.h.

References ResidEval::initSizes(), and ResidEval::m_alg.

virtual void writeSolution ( int  ievent,
const double  time,
const double  deltaT,
const int  time_step_num,
const double *  y,
const double *  ydot 
)
inlinevirtualinherited

Write out to a file or to standard output the current solution.

ievent is a description of the event that caused this function to be called.

Definition at line 134 of file ResidEval.h.

References ResidEval::nEquations().

int nparams ( ) const
inlineinherited

Return the number of parameters in the calculation.

This is the number of parameters in the sensitivity calculation. We have set this to zero and have included it for later expansion

Definition at line 159 of file ResidEval.h.

Member Data Documentation

doublereal m_atol
protected

constant value of atol

Definition at line 357 of file ResidJacEval.h.

Referenced by ResidJacEval::calcDeltaSolnVariables(), ResidJacEval::operator=(), and ResidJacEval::setAtol().

int neq_
protected
std::vector<int> m_alg
protectedinherited

Mapping vector that stores whether a degree of freedom is a DAE or not.

The first index is the equation number. The second index is 1 if it is a DAE, and zero if it is not.

Definition at line 170 of file ResidEval.h.

Referenced by ResidEval::initSizes(), and ResidEval::setAlgebraic().


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