Cantera  2.0
Public Member Functions | Static Public Attributes | Protected Member Functions | Private Member Functions | Private Attributes | List of all members
NonlinearSolver Class Reference

Class that calculates the solution to a nonlinear system. More...

#include <NonlinearSolver.h>

Collaboration diagram for NonlinearSolver:
[legend]

Public Member Functions

 NonlinearSolver (ResidJacEval *func)
 Default constructor.
 
 NonlinearSolver (const NonlinearSolver &right)
 Copy Constructor for the ThermoPhase object.
 
 ~NonlinearSolver ()
 Destructor.
 
NonlinearSolveroperator= (const NonlinearSolver &right)
 Assignment operator.
 
void createSolnWeights (const doublereal *const y)
 Create solution weights for convergence criteria.
 
doublereal solnErrorNorm (const doublereal *const delta_y, const char *title=0, int printLargest=0, const doublereal dampFactor=1.0) const
 L2 norm of the delta of the solution vector.
 
doublereal residErrorNorm (const doublereal *const resid, const char *title=0, const int printLargest=0, const doublereal *const y=0) const
 L2 norm of the residual of the equation system.
 
int doResidualCalc (const doublereal time_curr, const int typeCalc, const doublereal *const y_curr, const doublereal *const ydot_curr, const ResidEval_Type_Enum evalType=Base_ResidEval) const
 Compute the current residual.
 
int doNewtonSolve (const doublereal time_curr, const doublereal *const y_curr, const doublereal *const ydot_curr, doublereal *const delta_y, GeneralMatrix &jac)
 Compute the undamped Newton step.
 
int doAffineNewtonSolve (const doublereal *const y_curr, const doublereal *const ydot_curr, doublereal *const delta_y, GeneralMatrix &jac)
 Compute the newton step, either by direct newton's or by solving a close problem that is represented by a Hessian (.
 
doublereal trustRegionLength () const
 Calculate the length of the current trust region in terms of the solution error norm.
 
void setDefaultDeltaBoundsMagnitudes ()
 Set default deulta bounds amounts.
 
void adjustUpStepMinimums ()
 Adjust the step minimums.
 
void setDeltaBoundsMagnitudes (const doublereal *const deltaBoundsMagnitudes)
 Set the delta Bounds magnitudes by hand.
 
doublereal boundStep (const doublereal *const y, const doublereal *const step0)
 Bound the step.
 
void setBoundsConstraints (const doublereal *const y_low_bounds, const doublereal *const y_high_bounds)
 Set bounds constraints for all variables in the problem.
 
std::vector< doublereal > & lowBoundsConstraintVector ()
 Return an editable vector of the low bounds constraints.
 
std::vector< doublereal > & highBoundsConstraintVector ()
 Return an editable vector of the high bounds constraints.
 
void calc_ydot (const int order, const doublereal *const y_curr, doublereal *const ydot_curr) const
 Internal function to calculate the time derivative of the solution at the new step.
 
int beuler_jac (GeneralMatrix &J, doublereal *const f, doublereal time_curr, doublereal CJ, doublereal *const y, doublereal *const ydot, int num_newt_its)
 Function called to evaluate the jacobian matrix and the current residual vector at the current time step.
 
doublereal filterNewStep (const doublereal timeCurrent, const doublereal *const ybase, doublereal *const step0)
 Apply a filtering process to the step.
 
doublereal filterNewSolution (const doublereal timeCurrent, doublereal *const y_current, doublereal *const ydot_current)
 Apply a filter to the solution.
 
doublereal deltaBoundStep (const doublereal *const y, const doublereal *const step0)
 Return the factor by which the undamped Newton step 'step0' must be multiplied in order to keep the update within the bounds of an accurate jacobian.
 
int dampStep (const doublereal time_curr, const doublereal *const y_n_curr, const doublereal *const ydot_n_curr, doublereal *const step_1, doublereal *const y_n_1, doublereal *const ydot_n_1, doublereal *step_2, doublereal &stepNorm_2, GeneralMatrix &jac, bool writetitle, int &num_backtracks)
 Find a damping coefficient through a look-ahead mechanism.
 
int solve_nonlinear_problem (int SolnType, doublereal *const y_comm, doublereal *const ydot_comm, doublereal CJ, doublereal time_curr, GeneralMatrix &jac, int &num_newt_its, int &num_linear_solves, int &num_backtracks, int loglevelInput)
 Find the solution to F(X) = 0 by damped Newton iteration.
 
void setColumnScaling (bool useColScaling, const double *const scaleFactors=0)
 Set the column scaling that are used for the inversion of the matrix.
 
void setRowScaling (bool useRowScaling)
 Set the rowscaling that are used for the inversion of the matrix.
 
void scaleMatrix (GeneralMatrix &jac, doublereal *const y_comm, doublereal *const ydot_comm, doublereal time_curr, int num_newt_its)
 Scale the matrix.
 
void print_solnDelta_norm_contrib (const doublereal *const step_1, const char *const stepNorm_1, const doublereal *const step_2, const char *const stepNorm_2, const char *const title, const doublereal *const y_n_curr, const doublereal *const y_n_1, doublereal damp, size_t num_entries)
 Print solution norm contribution.
 
void computeResidWts ()
 Compute the Residual Weights.
 
void getResidWts (doublereal *const residWts) const
 Return the residual weights.
 
int convergenceCheck (int dampCode, doublereal s1)
 Check to see if the nonlinear problem has converged.
 
void setAtol (const doublereal *const atol)
 Set the absolute tolerances for the solution variables.
 
void setRtol (const doublereal rtol)
 Set the relative tolerances for the solution variables.
 
void setResidualTols (double residRtol, double *residATol, int residNormHandling=2)
 Set the relative and absolute tolerances for the Residual norm comparisons, if used.
 
void setMaxNewtIts (const int maxNewtIts)
 Set the value of the maximum # of newton iterations.
 
void calcSolnToResNormVector ()
 Calculate the scaling factor for translating residual norms into solution norms.
 
doublereal doCauchyPointSolve (GeneralMatrix &jac)
 Calculate the steepest descent direction and the Cauchy Point where the quadratic formulation of the nonlinear problem expects a minimum along the descent direction.
 
void descentComparison (doublereal time_curr, doublereal *ydot0, doublereal *ydot1, int &numTrials)
 This is a utility routine that can be used to print out the rates of the initial residual decline.
 
void setupDoubleDogleg ()
 Setup the parameters for the double dog leg.
 
int lambdaToLeg (const doublereal lambda, doublereal &alpha) const
 Change the global lambda coordinate into the (leg,alpha) coordinate for the double dogleg.
 
int calcTrustIntersection (doublereal trustVal, doublereal &lambda, doublereal &alpha) const
 Given a trust distance, this routine calculates the intersection of the this distance with the double dogleg curve.
 
void initializeTrustRegion ()
 Initialize the size of the trust vector.
 
void setTrustRegionInitializationMethod (int method, doublereal factor)
 Set Trust region initialization strategy.
 
int dampDogLeg (const doublereal time_curr, const doublereal *y_n_curr, const doublereal *ydot_n_curr, std::vector< doublereal > &step_1, doublereal *const y_n_1, doublereal *const ydot_n_1, doublereal &stepNorm_1, doublereal &stepNorm_2, GeneralMatrix &jac, int &num_backtracks)
 Damp using the dog leg approach.
 
int decideStep (const doublereal time_curr, int leg, doublereal alpha, const doublereal *const y_n_curr, const doublereal *const ydot_n_curr, const std::vector< doublereal > &step_1, const doublereal *const y_n_1, const doublereal *const ydot_n_1, doublereal trustDeltaOld)
 Decide whether the current step is acceptable and adjust the trust region size.
 
doublereal expectedResidLeg (int leg, doublereal alpha) const
 Calculated the expected residual along the double dogleg curve.
 
void residualComparisonLeg (const doublereal time_curr, const doublereal *const ydot0, int &legBest, doublereal &alphaBest) const
 Here we print out the residual at various points along the double dogleg, comparing against the quadratic model in a table format.
 
void setPrintLvl (int printLvl)
 Set the print level from the nonlinear solver.
 
void setSolverScheme (int doDogLeg, int doAffineSolve)
 Parameter to turn on solution solver schemes.
 

Static Public Attributes

static bool s_TurnOffTiming
 Turn off printing of time.
 
static bool s_print_NumJac
 Turn on or off printing of the Jacobian.
 
static bool s_print_DogLeg
 Turn on extra printing of dogleg information.
 
static bool s_doBothSolvesAndCompare
 Turn on solving both the Newton and Hessian systems and comparing the results.
 
static bool s_alwaysAssumeNewtonGood
 This toggle turns off the use of the Hessian when it is warranted by the condition number.
 

Protected Member Functions

void readjustTrustVector ()
 Readjust the trust region vectors.
 
void fillDogLegStep (int leg, doublereal alpha, std::vector< doublereal > &deltaX) const
 Fill a dogleg solution step vector.
 
doublereal calcTrustDistance (std::vector< doublereal > const &deltaX) const
 Calculate the trust distance of a step in the solution variables.
 

Private Member Functions

void calcColumnScales ()
 Set the column scales.
 

Private Attributes

ResidJacEvalm_func
 Pointer to the residual and jacobian evaluator for the function.
 
int solnType_
 Solution type.
 
size_t neq_
 Local copy of the number of equations.
 
std::vector< doublereal > m_ewt
 Soln error weights.
 
int m_manualDeltaStepSet
 Boolean indicating whether a manual delta bounds has been input.
 
std::vector< doublereal > m_deltaStepMinimum
 Soln Delta bounds magnitudes.
 
std::vector< doublereal > m_deltaStepMaximum
 Value of the delta step magnitudes.
 
std::vector< doublereal > m_y_n_curr
 Vector containing the current solution vector within the nonlinear solver.
 
std::vector< doublereal > m_ydot_n_curr
 Vector containing the time derivative of the current solution vector within the nonlinear solver (where applicable)
 
std::vector< doublereal > m_y_nm1
 Vector containing the solution at the previous time step.
 
std::vector< doublereal > m_y_n_1
 Vector containing the solution at the previous time step.
 
std::vector< doublereal > m_ydot_n_1
 Value of the solution time derivative at the new point that is to be considered.
 
std::vector< doublereal > m_step_1
 Value of the step to be taken in the solution.
 
std::vector< doublereal > m_colScales
 Vector of column scaling factors.
 
std::vector< doublereal > m_rowScales
 Weights for normalizing the values of the residuals.
 
std::vector< doublereal > m_rowWtScales
 Weights for normalizing the values of the residuals.
 
std::vector< doublereal > m_resid
 Value of the residual for the nonlinear problem.
 
std::vector< doublereal > m_wksp
 Workspace of length neq_.
 
std::vector< doublereal > m_wksp_2
 Workspace of length neq_.
 
std::vector< doublereal > m_residWts
 Vector of residual weights.
 
doublereal m_normResid_0
 Norm of the residual at the start of each nonlinear iteration.
 
doublereal m_normResid_Bound
 Norm of the residual after it has been bounded.
 
doublereal m_normResid_1
 Norm of the residual at the end of the first leg of the current iteration.
 
doublereal m_normResid_full
 Norm of the residual at the end of the first leg of the current iteration.
 
doublereal m_normDeltaSoln_Newton
 Norm of the solution update created by the iteration in its raw, undamped form, using the solution norm.
 
doublereal m_normDeltaSoln_CP
 Norm of the distance to the cauchy point using the solution norm.
 
doublereal m_normResidTrial
 Norm of the residual for a trial calculation which may or may not be used.
 
doublereal m_normResidPoints [15]
 Vector of the norm.
 
bool m_resid_scaled
 Boolean indicating whether we should scale the residual.
 
std::vector< doublereal > m_y_high_bounds
 Bounds vector for each species.
 
std::vector< doublereal > m_y_low_bounds
 Lower bounds vector for each species.
 
doublereal m_dampBound
 Damping factor imposed by hard bounds and by delta bounds.
 
doublereal m_dampRes
 Additional damping factor due to bounds on the residual and solution norms.
 
doublereal delta_t_n
 Delta t for the current step.
 
int m_nfe
 Counter for the total number of function evaluations.
 
int m_colScaling
 The type of column scaling used in the matrix inversion of the problem.
 
int m_rowScaling
 int indicating whether row scaling is turned on (1) or not (0)
 
int m_numTotalLinearSolves
 Total number of linear solves taken by the solver object.
 
int m_numLocalLinearSolves
 Number of local linear solves done during the current iteration.
 
int m_numTotalNewtIts
 Total number of newton iterations.
 
int m_min_newt_its
 Minimum number of newton iterations to use.
 
int maxNewtIts_
 Maximum number of newton iterations.
 
int m_jacFormMethod
 Jacobian formation method.
 
int m_nJacEval
 Number of Jacobian evaluations.
 
doublereal time_n
 Current system time.
 
int m_matrixConditioning
 Boolean indicating matrix conditioning.
 
int m_order
 Order of the time step method = 1.
 
doublereal rtol_
 value of the relative tolerance to use in solving the equation set
 
doublereal atolBase_
 Base value of the absolute tolerance.
 
doublereal * m_ydot_nm1
 Pointer containing the solution derivative at the previous time step.
 
std::vector< doublereal > atolk_
 absolute tolerance in the solution unknown
 
std::vector< doublereal > userResidAtol_
 absolute tolerance in the unscaled solution unknowns
 
doublereal userResidRtol_
 absolute tolerance in the unscaled solution unknowns
 
int checkUserResidualTols_
 Check the residual tolerances explictly against user input.
 
int m_print_flag
 Determines the level of printing for each time step.
 
doublereal m_ScaleSolnNormToResNorm
 Scale factor for turning residual norms into solution norms.
 
Cantera::GeneralMatrixjacCopyPtr_
 Copy of the jacobian that doesn't get overwritten when the inverse is determined.
 
Cantera::GeneralMatrixHessianPtr_
 Hessian.
 
std::vector< doublereal > deltaX_CP_
 Steepest descent direction. This is also the distance to the Cauchy Point.
 
std::vector< doublereal > deltaX_Newton_
 Newton Step - This is the newton step determined from the straight Jacobian.
 
doublereal residNorm2Cauchy_
 Expected value of the residual norm at the Cauchy point if the quadratic model were valid.
 
int dogLegID_
 Current leg.
 
doublereal dogLegAlpha_
 Current Alpha param along the leg.
 
doublereal RJd_norm_
 Residual dot Jd norm.
 
doublereal lambdaStar_
 Value of lambdaStar_ which is used to calculate the Cauchy point.
 
std::vector< doublereal > Jd_
 Jacobian times the steepest descent direction in the normalized coordinates.
 
std::vector< doublereal > deltaX_trust_
 Vector of trust region values.
 
doublereal norm_deltaX_trust_
 Current norm of the vector deltaX_trust_ in terms of the solution norm.
 
doublereal trustDelta_
 Current value of trust radius.
 
int trustRegionInitializationMethod_
 Method for handling the trust region initialization.
 
doublereal trustRegionInitializationFactor_
 Factor used to set the initial trust region.
 
doublereal Nuu_
 Relative distance down the Newton step that the second dogleg starts.
 
doublereal dist_R0_
 Distance of the zeroeth leg of the dogleg in terms of the solution norm.
 
doublereal dist_R1_
 Distance of the first leg of the dogleg in terms of the solution norm.
 
doublereal dist_R2_
 Distance of the second leg of the dogleg in terms of the solution norm.
 
doublereal dist_Total_
 Distance of the sum of all legs of the doglegs in terms of the solution norm.
 
doublereal JdJd_norm_
 Dot product of the Jd_ variable defined above with itself.
 
doublereal normTrust_Newton_
 Norm of the Newton Step wrt trust region.
 
doublereal normTrust_CP_
 Norm of the Cauchy Step direction wrt trust region.
 
int doDogLeg_
 General toggle for turning on dog leg damping.
 
int doAffineSolve_
 General toggle for turning on Affine solve with Hessian.
 
doublereal m_conditionNumber
 Condition number of the matrix.
 
doublereal CurrentTrustFactor_
 Factor indicating how much trust region has been changed this iteration - output variable.
 
doublereal NextTrustFactor_
 Factor indicating how much trust region has been changed next iteration - output variable.
 
bool ResidWtsReevaluated_
 Boolean indicating that the residual weights have been reevaluated this iteration - output variable.
 
doublereal ResidDecreaseSDExp_
 Expected DResid_dS for the steepest descent path - output variable.
 
doublereal ResidDecreaseSD_
 Actual DResid_dS for the steepest descent path - output variable.
 
doublereal ResidDecreaseNewtExp_
 Expected DResid_dS for the Newton path - output variable.
 
doublereal ResidDecreaseNewt_
 Actual DResid_dS for the newton path - output variable.
 

Detailed Description

Class that calculates the solution to a nonlinear system.

This is a small nonlinear solver that can solve highly nonlinear problems that must use a dense matrix to relax the system.

Newton's method is used.

Damping is used extensively when relaxing the system.

The basic idea is that we predict a direction that is parameterized by an overall coordinate value, beta, from zero to one, This may or may not be the same as the value, damp, depending upon whether the direction is straight.

TIME STEP TYPE

The code solves a nonlinear problem. Frequently the nonlinear problem is created from time-dependent residual. Whenever you change the solution vector, you are also changing the derivative of the solution vector. Therefore, the code has the option of altering ydot, a vector of time derivatives of the solution in tandem with the solution vector and then feeding a residual and Jacobian routine with the time derivatives as well as the solution. The code has support for a backwards euler method and a second order Adams-Bashforth or Trapezoidal Rule.

In order to use these methods, the solver must be initialized with delta_t and m_y_nm1[i] to specify the conditions at the previous time step. For second order methods, the time derivative at t_nm1 must also be supplied, m_ydot_nm1[i]. Then the solution type NSOLN_TYPE_TIME_DEPENDENT may be used to solve the problem.

For steady state problem whose residual doesn't have a solution time derivative in it, you should use the NSOLN_TYPE_STEADY_STATE problem type.

We have a NSOLN_TYPE_PSEUDO_TIME_DEPENDENT defined. However, this is not implemented yet. This would be a pseudo time dependent calculation, where an optional time derivative could be added in order to help equilibrate a nonlinear steady state system. The time transient is not important in and of itself. Many physical systems have a time dependence to them that provides a natural way to relax the nonlinear system.

MATRIX SCALING

int solnType = NSOLN_TYPE_STEADY_STATE ;
nls->setDeltaBoundsMagnitudes(deltaBounds);
nls->solve_nonlinear_problem(solnType, y_comm, ydot_comm, CJ, time_curr, jac,
num_newt_its, num_linear_solves, numBacktracks,
loglevelInput);

Definition at line 133 of file NonlinearSolver.h.

Constructor & Destructor Documentation

NonlinearSolver ( const NonlinearSolver right)

Copy Constructor for the ThermoPhase object.

Parameters
rightItem to be copied

Definition at line 215 of file NonlinearSolver.cpp.

References NonlinearSolver::operator=().

Destructor.

Definition at line 305 of file NonlinearSolver.cpp.

References NonlinearSolver::HessianPtr_, and NonlinearSolver::jacCopyPtr_.

Member Function Documentation

NonlinearSolver & operator= ( const NonlinearSolver right)

Assignment operator.

This is NOT a virtual function.

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

Definition at line 315 of file NonlinearSolver.cpp.

References NonlinearSolver::atolBase_, NonlinearSolver::atolk_, NonlinearSolver::checkUserResidualTols_, NonlinearSolver::CurrentTrustFactor_, NonlinearSolver::delta_t_n, NonlinearSolver::deltaX_CP_, NonlinearSolver::deltaX_Newton_, NonlinearSolver::deltaX_trust_, NonlinearSolver::dist_R0_, NonlinearSolver::dist_R1_, NonlinearSolver::dist_R2_, NonlinearSolver::dist_Total_, NonlinearSolver::doAffineSolve_, NonlinearSolver::doDogLeg_, NonlinearSolver::dogLegAlpha_, NonlinearSolver::dogLegID_, ResidJacEval::duplMyselfAsResidJacEval(), NonlinearSolver::HessianPtr_, NonlinearSolver::jacCopyPtr_, NonlinearSolver::Jd_, NonlinearSolver::JdJd_norm_, NonlinearSolver::lambdaStar_, NonlinearSolver::m_colScales, NonlinearSolver::m_colScaling, NonlinearSolver::m_dampBound, NonlinearSolver::m_dampRes, NonlinearSolver::m_deltaStepMinimum, NonlinearSolver::m_ewt, NonlinearSolver::m_func, NonlinearSolver::m_jacFormMethod, NonlinearSolver::m_manualDeltaStepSet, NonlinearSolver::m_matrixConditioning, NonlinearSolver::m_min_newt_its, NonlinearSolver::m_nfe, NonlinearSolver::m_nJacEval, NonlinearSolver::m_normDeltaSoln_CP, NonlinearSolver::m_normDeltaSoln_Newton, NonlinearSolver::m_normResid_0, NonlinearSolver::m_normResid_1, NonlinearSolver::m_normResid_Bound, NonlinearSolver::m_normResidTrial, NonlinearSolver::m_numTotalLinearSolves, NonlinearSolver::m_numTotalNewtIts, NonlinearSolver::m_order, NonlinearSolver::m_print_flag, NonlinearSolver::m_resid, NonlinearSolver::m_resid_scaled, NonlinearSolver::m_residWts, NonlinearSolver::m_rowScales, NonlinearSolver::m_rowScaling, NonlinearSolver::m_rowWtScales, NonlinearSolver::m_ScaleSolnNormToResNorm, NonlinearSolver::m_step_1, NonlinearSolver::m_wksp, NonlinearSolver::m_wksp_2, NonlinearSolver::m_y_high_bounds, NonlinearSolver::m_y_low_bounds, NonlinearSolver::m_y_n_1, NonlinearSolver::m_y_n_curr, NonlinearSolver::m_y_nm1, NonlinearSolver::m_ydot_n_1, NonlinearSolver::m_ydot_n_curr, NonlinearSolver::maxNewtIts_, NonlinearSolver::neq_, NonlinearSolver::NextTrustFactor_, NonlinearSolver::norm_deltaX_trust_, NonlinearSolver::normTrust_CP_, NonlinearSolver::normTrust_Newton_, NonlinearSolver::Nuu_, NonlinearSolver::ResidDecreaseNewt_, NonlinearSolver::ResidDecreaseNewtExp_, NonlinearSolver::ResidDecreaseSD_, NonlinearSolver::ResidDecreaseSDExp_, NonlinearSolver::residNorm2Cauchy_, NonlinearSolver::ResidWtsReevaluated_, NonlinearSolver::RJd_norm_, NonlinearSolver::rtol_, NonlinearSolver::solnType_, NonlinearSolver::time_n, NonlinearSolver::trustDelta_, NonlinearSolver::trustRegionInitializationFactor_, NonlinearSolver::trustRegionInitializationMethod_, NonlinearSolver::userResidAtol_, and NonlinearSolver::userResidRtol_.

Referenced by NonlinearSolver::NonlinearSolver().

void createSolnWeights ( const doublereal *const  y)

Create solution weights for convergence criteria.

We create soln weights from the following formula

wt[i] = rtol * abs(y[i]) + atol[i]

The program always assumes that atol is specific to the solution component

Parameters
yvector of the current solution values

Definition at line 430 of file NonlinearSolver.cpp.

References NonlinearSolver::atolk_, NonlinearSolver::m_ewt, NonlinearSolver::neq_, and NonlinearSolver::rtol_.

Referenced by NonlinearSolver::solve_nonlinear_problem().

doublereal solnErrorNorm ( const doublereal *const  delta_y,
const char *  title = 0,
int  printLargest = 0,
const doublereal  dampFactor = 1.0 
) const

L2 norm of the delta of the solution vector.

calculate the norm of the solution vector. This will involve the column scaling of the matrix

The third argument has a default of false. However, if true, then a table of the largest values is printed out to standard output.

Parameters
delta_yVector to take the norm of
titleOptional title to be printed out
printLargestint indicating how many specific lines should be printed out
dampFactorCurrent value of the damping factor. Defaults to 1. only used for printout out a table.
Returns
Returns the L2 norm of the delta

Definition at line 483 of file NonlinearSolver.cpp.

References Cantera::error(), Cantera::int2str(), NonlinearSolver::m_ewt, NonlinearSolver::m_print_flag, NonlinearSolver::m_y_n_curr, NonlinearSolver::neq_, Cantera::npos, and Cantera::print_line().

Referenced by NonlinearSolver::dampDogLeg(), NonlinearSolver::dampStep(), NonlinearSolver::decideStep(), NonlinearSolver::descentComparison(), NonlinearSolver::doAffineNewtonSolve(), NonlinearSolver::doCauchyPointSolve(), NonlinearSolver::readjustTrustVector(), NonlinearSolver::residualComparisonLeg(), NonlinearSolver::setupDoubleDogleg(), NonlinearSolver::solve_nonlinear_problem(), and NonlinearSolver::trustRegionLength().

doublereal residErrorNorm ( const doublereal *const  resid,
const char *  title = 0,
const int  printLargest = 0,
const doublereal *const  y = 0 
) const

L2 norm of the residual of the equation system.

Calculate the norm of the residual vector. This may involve using the row sum scaling from the matrix problem.

The second argument has a default of false. However, if true, then a table of the largest values is printed out to standard output.

Parameters
residVector of the residuals
titleOptional title to be printed out
printLargestNumber of specific entries to be printed
yCurrent value of y - only used for printouts
Returns
Returns the L2 norm of the delta

Definition at line 565 of file NonlinearSolver.cpp.

References mdp::checkFinite(), Cantera::error(), Cantera::int2str(), NonlinearSolver::m_print_flag, NonlinearSolver::m_residWts, NonlinearSolver::neq_, Cantera::npos, and Cantera::print_line().

Referenced by NonlinearSolver::dampStep(), NonlinearSolver::decideStep(), NonlinearSolver::descentComparison(), NonlinearSolver::residualComparisonLeg(), and NonlinearSolver::solve_nonlinear_problem().

int doResidualCalc ( const doublereal  time_curr,
const int  typeCalc,
const doublereal *const  y_curr,
const doublereal *const  ydot_curr,
const ResidEval_Type_Enum  evalType = Base_ResidEval 
) const

Compute the current residual.

The current value of the residual is stored in the internal work array m_resid, which is defined as mutable

Parameters
time_currValue of the time
typeCalcType of the calculation
y_currCurrent value of the solution vector
ydot_currCurrent value of the time derivative of the solution vector
evalTypeBase evaluation type Defaults to Base_ResidEval
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 729 of file NonlinearSolver.cpp.

References DATA_PTR, NonlinearSolver::delta_t_n, ResidJacEval::evalResidNJ(), NonlinearSolver::m_func, NonlinearSolver::m_nfe, NonlinearSolver::m_resid, and NonlinearSolver::m_resid_scaled.

Referenced by NonlinearSolver::dampStep(), NonlinearSolver::decideStep(), NonlinearSolver::descentComparison(), NonlinearSolver::residualComparisonLeg(), and NonlinearSolver::solve_nonlinear_problem().

int doNewtonSolve ( const doublereal  time_curr,
const doublereal *const  y_curr,
const doublereal *const  ydot_curr,
doublereal *const  delta_y,
GeneralMatrix jac 
)

Compute the undamped Newton step.

Compute the undamped Newton step. The residual function is evaluated at the current time, t_n, at the current values of the solution vector, m_y_n, and the solution time derivative, m_ydot_n. The Jacobian is not recomputed.

A factored jacobian is reused, if available. If a factored jacobian is not available, then the jacobian is factored. Before factoring, the jacobian is row and column-scaled. Column scaling is not recomputed. The row scales are recomputed here, after column scaling has been implemented.

Parameters
time_currCurrent value of the time
y_currCurrent value of the solution
ydot_currCurrent value of the solution derivative.
delta_yreturn value of the raw change in y
jacJacobian
Returns
Returns the result code from lapack. A zero means success. Anything else indicates a failure.

Definition at line 964 of file NonlinearSolver.cpp.

References DATA_PTR, NonlinearSolver::m_colScales, NonlinearSolver::m_colScaling, NonlinearSolver::m_numLocalLinearSolves, NonlinearSolver::m_numTotalLinearSolves, NonlinearSolver::m_resid, NonlinearSolver::m_resid_scaled, NonlinearSolver::m_rowScales, NonlinearSolver::m_rowScaling, NonlinearSolver::neq_, and GeneralMatrix::solve().

Referenced by NonlinearSolver::dampStep(), and NonlinearSolver::solve_nonlinear_problem().

int doAffineNewtonSolve ( const doublereal *const  y_curr,
const doublereal *const  ydot_curr,
doublereal *const  delta_y,
GeneralMatrix jac 
)

Compute the newton step, either by direct newton's or by solving a close problem that is represented by a Hessian (.

This is algorith A.6.5.1 in Dennis / Schnabel

Compute the QR decomposition

Compute the undamped Newton step. The residual function is evaluated at the current time, t_n, at the current values of the solution vector, m_y_n, and the solution time derivative, m_ydot_n. The Jacobian is not recomputed.

A factored jacobian is reused, if available. If a factored jacobian is not available, then the jacobian is factored. Before factoring, the jacobian is row and column-scaled. Column scaling is not recomputed. The row scales are recomputed here, after column scaling has been implemented.

Parameters
y_currCurrent value of the solution
ydot_currCurrent value of the solution derivative.
delta_yreturn value of the raw change in y
jacJacobian

Internal input

internal m_resid Stored residual is used as input

Returns
Returns the result code from lapack. A zero means success. Anything else indicates a failure.

Definition at line 1056 of file NonlinearSolver.cpp.

References GeneralMatrix::begin(), DATA_PTR, NonlinearSolver::doDogLeg_, GeneralMatrix::duplMyselfAsGeneralMatrix(), GeneralMatrix::factor(), GeneralMatrix::factorAlgorithm(), GeneralMatrix::factored(), GeneralMatrix::factorQR(), NonlinearSolver::HessianPtr_, Cantera::int2str(), NonlinearSolver::jacCopyPtr_, NonlinearSolver::m_colScales, NonlinearSolver::m_colScaling, NonlinearSolver::m_conditionNumber, NonlinearSolver::m_numLocalLinearSolves, NonlinearSolver::m_numTotalLinearSolves, NonlinearSolver::m_print_flag, NonlinearSolver::m_resid, NonlinearSolver::m_resid_scaled, NonlinearSolver::m_rowScales, NonlinearSolver::m_rowScaling, GeneralMatrix::matrixType_, mdp::mdp_alloc_dbl_1(), mdp::mdp_copy_dbl_1(), mdp::mdp_safe_free(), NonlinearSolver::neq_, GeneralMatrix::oneNorm(), GeneralMatrix::rcond(), GeneralMatrix::rcondQR(), NonlinearSolver::s_alwaysAssumeNewtonGood, NonlinearSolver::s_doBothSolvesAndCompare, NonlinearSolver::solnErrorNorm(), GeneralMatrix::solve(), GeneralMatrix::useFactorAlgorithm(), and GeneralMatrix::zero().

Referenced by NonlinearSolver::solve_nonlinear_problem().

doublereal trustRegionLength ( ) const

Calculate the length of the current trust region in terms of the solution error norm.

We carry out a norm of deltaX_trust_ first. Then, we multiply that value by trustDelta_

Definition at line 1979 of file NonlinearSolver.cpp.

References DATA_PTR, NonlinearSolver::deltaX_trust_, NonlinearSolver::norm_deltaX_trust_, NonlinearSolver::solnErrorNorm(), and NonlinearSolver::trustDelta_.

Referenced by NonlinearSolver::dampDogLeg(), and NonlinearSolver::decideStep().

void setDefaultDeltaBoundsMagnitudes ( )

Set default deulta bounds amounts.

Delta bounds are set to 0.01 for all unknowns arbitrarily and capriciously Then, for each call to the nonlinear solver Then, they are increased to 1000 x atol then, they are increased to 0.1 fab(y[i])

Definition at line 1985 of file NonlinearSolver.cpp.

References NonlinearSolver::atolk_, NonlinearSolver::m_deltaStepMinimum, NonlinearSolver::m_y_n_curr, ckr::max(), and NonlinearSolver::neq_.

Referenced by NonlinearSolver::solve_nonlinear_problem().

void adjustUpStepMinimums ( )
void setDeltaBoundsMagnitudes ( const doublereal *const  deltaBoundsMagnitudes)

Set the delta Bounds magnitudes by hand.

Parameters
deltaBoundsMagnitudesset the deltaBoundsMagnitude vector

Definition at line 2004 of file NonlinearSolver.cpp.

References NonlinearSolver::m_deltaStepMinimum, NonlinearSolver::m_manualDeltaStepSet, and NonlinearSolver::neq_.

void readjustTrustVector ( )
protected

Readjust the trust region vectors.

The trust region is made up of the trust region vector calculation and the trustDelta_ value We periodically recalculate the trustVector_ values so that they renormalize to the correct length. We change the trustDelta_ values regularly

The trust region calculate is based on

|| delta_x   dot  1/trustDeltaX_ ||   <= trustDelta_

Definition at line 2134 of file NonlinearSolver.cpp.

References DATA_PTR, NonlinearSolver::deltaX_trust_, NonlinearSolver::doDogLeg_, NonlinearSolver::m_deltaStepMaximum, NonlinearSolver::m_deltaStepMinimum, NonlinearSolver::m_ewt, NonlinearSolver::m_print_flag, NonlinearSolver::m_y_n_curr, NonlinearSolver::neq_, NonlinearSolver::norm_deltaX_trust_, NonlinearSolver::solnErrorNorm(), and NonlinearSolver::trustDelta_.

Referenced by NonlinearSolver::initializeTrustRegion(), and NonlinearSolver::solve_nonlinear_problem().

void fillDogLegStep ( int  leg,
doublereal  alpha,
std::vector< doublereal > &  deltaX 
) const
protected

Fill a dogleg solution step vector.

Previously, we have filled up deltaX_Newton_[], deltaX_CP_[], and Nuu_, so that this routine is straightforward.

Parameters
legLeg of the dog leg you are on (0, 1, or 2)
alphaRelative length along the dog length that you are on.
deltaXVector to be filled up

Definition at line 2254 of file NonlinearSolver.cpp.

References NonlinearSolver::deltaX_CP_, NonlinearSolver::deltaX_Newton_, NonlinearSolver::neq_, and NonlinearSolver::Nuu_.

Referenced by NonlinearSolver::dampDogLeg().

doublereal calcTrustDistance ( std::vector< doublereal > const &  deltaX) const
protected

Calculate the trust distance of a step in the solution variables.

The trust distance is defined as the length of the step according to the norm wrt to the trust region. We calculate the trust distance by the following method.

trustDist =  || delta_x   dot  1/trustDeltaX_ ||
Parameters
deltaXCurrent value of deltaX

Definition at line 2280 of file NonlinearSolver.cpp.

References NonlinearSolver::deltaX_trust_, NonlinearSolver::neq_, and NonlinearSolver::trustDelta_.

Referenced by NonlinearSolver::initializeTrustRegion(), NonlinearSolver::setupDoubleDogleg(), and NonlinearSolver::solve_nonlinear_problem().

doublereal boundStep ( const doublereal *const  y,
const doublereal *const  step0 
)

Bound the step.

Return the factor by which the undamped Newton step 'step0' must be multiplied in order to keep all solution components in all domains between their specified lower and upper bounds. Other bounds may be applied here as well.

Currently the bounds are hard coded into this routine:

Minimum value for all variables: - 0.01 * m_ewt[i] Maximum value = none.

Thus, this means that all solution components are expected to be numerical greater than zero in the limit of time step truncation errors going to zero.

Delta bounds: The idea behind these is that the Jacobian couldn't possibly be representative if the variable is changed by a lot. (true for nonlinear systems, false for linear systems) Maximum increase in variable in any one newton iteration: factor of 2 Maximum decrease in variable in any one newton iteration: factor of 5

Parameters
yCurrent solution value of the old step
step0Proposed step change in the solution
Returns
Returns the damping factor determined by the bounds calculation

Definition at line 2366 of file NonlinearSolver.cpp.

References NonlinearSolver::deltaBoundStep(), Cantera::int2str(), NonlinearSolver::m_print_flag, NonlinearSolver::m_y_high_bounds, NonlinearSolver::m_y_low_bounds, ckr::min(), NonlinearSolver::neq_, and Cantera::npos.

Referenced by NonlinearSolver::dampDogLeg(), and NonlinearSolver::dampStep().

void setBoundsConstraints ( const doublereal *const  y_low_bounds,
const doublereal *const  y_high_bounds 
)

Set bounds constraints for all variables in the problem.

Parameters
y_low_boundsVector of lower bounds
y_high_boundsVector of high bounds

Definition at line 443 of file NonlinearSolver.cpp.

References NonlinearSolver::m_y_high_bounds, NonlinearSolver::m_y_low_bounds, and NonlinearSolver::neq_.

std::vector< doublereal > & lowBoundsConstraintVector ( )

Return an editable vector of the low bounds constraints.

Definition at line 458 of file NonlinearSolver.cpp.

References NonlinearSolver::m_y_low_bounds.

std::vector< doublereal > & highBoundsConstraintVector ( )

Return an editable vector of the high bounds constraints.

Definition at line 463 of file NonlinearSolver.cpp.

References NonlinearSolver::m_y_high_bounds.

void calc_ydot ( const int  order,
const doublereal *const  y_curr,
doublereal *const  ydot_curr 
) const

Internal function to calculate the time derivative of the solution at the new step.

Previously, the user must have supplied information about the previous time step for this routine to work as intended.

Parameters
orderof the BDF method
y_currcurrent value of the solution
ydot_currCalculated value of the solution derivative that is consistent with y_curr

Definition at line 3969 of file NonlinearSolver.cpp.

References NonlinearSolver::delta_t_n, NonlinearSolver::m_y_nm1, NonlinearSolver::m_ydot_nm1, and NonlinearSolver::neq_.

Referenced by NonlinearSolver::dampDogLeg(), NonlinearSolver::dampStep(), NonlinearSolver::residualComparisonLeg(), and NonlinearSolver::solve_nonlinear_problem().

int beuler_jac ( GeneralMatrix J,
doublereal *const  f,
doublereal  time_curr,
doublereal  CJ,
doublereal *const  y,
doublereal *const  ydot,
int  num_newt_its 
)

Function called to evaluate the jacobian matrix and the current residual vector at the current time step.

Parameters
JJacobian matrix to be filled in
fRight hand side. This routine returns the current value of the rhs (output), so that it does not have to be computed again.
time_currCurrent time
CJinverse of the value of deltaT
yvalue of the solution vector
ydotvalue of the time derivative of the solution vector
num_newt_itsNumber of newton iterations
Returns
Returns a flag to indicate that operation is successful. 1 Means a successful operation 0 Means an unsuccessful operation

Definition at line 3690 of file NonlinearSolver.cpp.

References ResidJacEval::calcDeltaSolnVariables(), GeneralMatrix::checkColumns(), GeneralMatrix::checkRows(), GeneralMatrix::clearFactorFlag(), GeneralMatrix::copyData(), DATA_PTR, NonlinearSolver::delta_t_n, ResidJacEval::evalJacobian(), ResidJacEval::evalResidNJ(), Cantera::int2str(), Cantera::JacBase_ResidEval, NonlinearSolver::jacCopyPtr_, Cantera::JacDelta_ResidEval, NonlinearSolver::m_ewt, NonlinearSolver::m_func, NonlinearSolver::m_jacFormMethod, NonlinearSolver::m_nfe, NonlinearSolver::m_nJacEval, NonlinearSolver::m_print_flag, NonlinearSolver::m_wksp, GeneralMatrix::matrixType_, mdp::mdp_alloc_dbl_1(), mdp::mdp_safe_free(), NonlinearSolver::neq_, GeneralMatrix::nRowsAndStruct(), NSOLN_JAC_ANAL, NSOLN_TYPE_STEADY_STATE, GeneralMatrix::ptrColumn(), NonlinearSolver::s_print_NumJac, NonlinearSolver::solnType_, and Cantera::subtractRD().

Referenced by NonlinearSolver::solve_nonlinear_problem().

doublereal filterNewStep ( const doublereal  timeCurrent,
const doublereal *const  ybase,
doublereal *const  step0 
)

Apply a filtering process to the step.

Parameters
timeCurrentCurrent value of the time
ybasecurrent value of the solution
step0Proposed step change in the solution
Returns
Returns the norm of the value of the amount filtered

Definition at line 4003 of file NonlinearSolver.cpp.

References ResidJacEval::filterNewStep(), and NonlinearSolver::m_func.

Referenced by NonlinearSolver::solve_nonlinear_problem().

doublereal filterNewSolution ( const doublereal  timeCurrent,
doublereal *const  y_current,
doublereal *const  ydot_current 
)

Apply a filter to the solution.

Parameters
timeCurrentCurrent value of the time
y_currentcurrent value of the solution
ydot_currentCurrent value of the solution derivative.
Returns
Returns the norm of the value of the amount filtered

Definition at line 4018 of file NonlinearSolver.cpp.

References ResidJacEval::filterSolnPrediction(), and NonlinearSolver::m_func.

Referenced by NonlinearSolver::solve_nonlinear_problem().

double deltaBoundStep ( const doublereal *const  y,
const doublereal *const  step0 
)

Return the factor by which the undamped Newton step 'step0' must be multiplied in order to keep the update within the bounds of an accurate jacobian.

The idea behind these is that the Jacobian couldn't possibly be representative, if the variable is changed by a lot. (true for nonlinear systems, false for linear systems) Maximum increase in variable in any one newton iteration: factor of 1.5 Maximum decrease in variable in any one newton iteration: factor of 2

Parameters
yInitial value of the solution vector
step0initial proposed step size
Returns
returns the damping factor

Definition at line 2030 of file NonlinearSolver.cpp.

References Cantera::int2str(), NonlinearSolver::m_deltaStepMinimum, NonlinearSolver::m_print_flag, ckr::max(), and NonlinearSolver::neq_.

Referenced by NonlinearSolver::boundStep().

int dampStep ( const doublereal  time_curr,
const doublereal *const  y_n_curr,
const doublereal *const  ydot_n_curr,
doublereal *const  step_1,
doublereal *const  y_n_1,
doublereal *const  ydot_n_1,
doublereal *  step_2,
doublereal &  stepNorm_2,
GeneralMatrix jac,
bool  writetitle,
int &  num_backtracks 
)

Find a damping coefficient through a look-ahead mechanism.

On entry, step_1 must contain an undamped Newton step for the solution y_n_curr. This method attempts to find a damping coefficient such that all components stay in bounds, and the next undamped step would have a norm smaller than that of step_1. If successful, the new solution after taking the damped step is returned in y_n_1, and the undamped step at y_n_1 is returned in step_2.

Parameters
time_currCurrent physical time
y_n_currBase value of the solution before any steps are taken
ydot_n_currBase value of the time derivative of the solution
step_1Initial step suggested.
y_n_1Value of y1, the suggested solution after damping
ydot_n_1Value of the time derivative of the solution at y_n_1
step_2Value of the step change from y_n_1 to y_n_2
stepNorm_2norm of the step change in going from y_n_1 to y_n_2
jacJacobian
writetitleWrite a title line
num_backtracksNumber of backtracks taken
Returns
returns an integer indicating what happened.

Definition at line 2442 of file NonlinearSolver.cpp.

References Cantera::Base_LaggedSolutionComponents, NonlinearSolver::boundStep(), NonlinearSolver::calc_ydot(), Cantera::DampFactor, DATA_PTR, NonlinearSolver::doNewtonSolve(), NonlinearSolver::doResidualCalc(), NonlinearSolver::m_dampBound, NonlinearSolver::m_dampRes, NonlinearSolver::m_normResid_0, NonlinearSolver::m_normResid_1, NonlinearSolver::m_normResid_Bound, NonlinearSolver::m_normResidTrial, NonlinearSolver::m_order, NonlinearSolver::m_print_flag, NonlinearSolver::m_resid, NonlinearSolver::m_wksp, Cantera::NDAMP, NonlinearSolver::neq_, NSOLN_RETN_FAIL_DAMPSTEP, NSOLN_TYPE_STEADY_STATE, NonlinearSolver::print_solnDelta_norm_contrib(), NonlinearSolver::residErrorNorm(), NonlinearSolver::solnErrorNorm(), and NonlinearSolver::solnType_.

Referenced by NonlinearSolver::solve_nonlinear_problem().

int solve_nonlinear_problem ( int  SolnType,
doublereal *const  y_comm,
doublereal *const  ydot_comm,
doublereal  CJ,
doublereal  time_curr,
GeneralMatrix jac,
int &  num_newt_its,
int &  num_linear_solves,
int &  num_backtracks,
int  loglevelInput 
)

Find the solution to F(X) = 0 by damped Newton iteration.

On entry, x0 contains an initial estimate of the solution. On successful return, x1 contains the converged solution.

SolnType = TRANSIENT -> we will assume we are relaxing a transient equation system for now. Will make it more general later, if an application comes up.

Parameters
SolnTypeSolution type
y_commInitial value of the solution. On return this is the converged value of the solution
ydot_commInitial value of the solution derivative. On return this is the converged value of the solution derivative.
CJInverse of the value of deltaT
time_currCurrent value of the time
jacMatrix that will be used to store the jacobian
num_newt_itsNumber of newton iterations taken
num_linear_solvesNumber of linear solves taken
num_backtracksNumber of backtracking steps taken
loglevelInputInput log level determines the amount of printing.
Returns
A positive value indicates a successful convergence -1 Failed convergence

Definition at line 3031 of file NonlinearSolver.cpp.

References NonlinearSolver::beuler_jac(), NonlinearSolver::calc_ydot(), NonlinearSolver::calcColumnScales(), NonlinearSolver::calcTrustDistance(), NonlinearSolver::convergenceCheck(), NonlinearSolver::createSolnWeights(), NonlinearSolver::CurrentTrustFactor_, NonlinearSolver::dampDogLeg(), NonlinearSolver::dampStep(), DATA_PTR, NonlinearSolver::deltaX_Newton_, NonlinearSolver::deltaX_trust_, NonlinearSolver::descentComparison(), NonlinearSolver::doAffineNewtonSolve(), NonlinearSolver::doAffineSolve_, NonlinearSolver::doCauchyPointSolve(), NonlinearSolver::doDogLeg_, NonlinearSolver::dogLegAlpha_, NonlinearSolver::dogLegID_, NonlinearSolver::doNewtonSolve(), NonlinearSolver::doResidualCalc(), GeneralMatrix::duplMyselfAsGeneralMatrix(), NonlinearSolver::filterNewSolution(), NonlinearSolver::filterNewStep(), NonlinearSolver::initializeTrustRegion(), NonlinearSolver::jacCopyPtr_, NonlinearSolver::m_conditionNumber, NonlinearSolver::m_dampBound, NonlinearSolver::m_dampRes, NonlinearSolver::m_manualDeltaStepSet, NonlinearSolver::m_min_newt_its, NonlinearSolver::m_normDeltaSoln_CP, NonlinearSolver::m_normDeltaSoln_Newton, NonlinearSolver::m_normResid_0, NonlinearSolver::m_normResid_1, NonlinearSolver::m_normResid_Bound, NonlinearSolver::m_normResid_full, NonlinearSolver::m_normResidTrial, NonlinearSolver::m_numLocalLinearSolves, NonlinearSolver::m_numTotalLinearSolves, NonlinearSolver::m_numTotalNewtIts, NonlinearSolver::m_order, NonlinearSolver::m_print_flag, NonlinearSolver::m_resid, NonlinearSolver::m_step_1, NonlinearSolver::m_wksp_2, NonlinearSolver::m_y_n_1, NonlinearSolver::m_y_n_curr, NonlinearSolver::m_ydot_n_1, NonlinearSolver::m_ydot_n_curr, NonlinearSolver::maxNewtIts_, mdp::mdp_copy_dbl_1(), mdp::mdp_init_dbl_1(), NonlinearSolver::neq_, NonlinearSolver::NextTrustFactor_, NonlinearSolver::norm_deltaX_trust_, NSOLN_RETN_CONTINUE, NSOLN_RETN_JACOBIANFORMATIONERROR, NSOLN_RETN_MATRIXINVERSIONERROR, NSOLN_RETN_MAXIMUMITERATIONSEXCEEDED, NSOLN_RETN_RESIDUALFORMATIONERROR, NSOLN_RETN_SUCCESS, NSOLN_TYPE_STEADY_STATE, Cantera::print_line(), NonlinearSolver::readjustTrustVector(), NonlinearSolver::ResidDecreaseNewt_, NonlinearSolver::ResidDecreaseNewtExp_, NonlinearSolver::ResidDecreaseSD_, NonlinearSolver::ResidDecreaseSDExp_, NonlinearSolver::residErrorNorm(), NonlinearSolver::residualComparisonLeg(), NonlinearSolver::ResidWtsReevaluated_, NonlinearSolver::s_print_DogLeg, NonlinearSolver::s_TurnOffTiming, NonlinearSolver::scaleMatrix(), clockWC::secondsWC(), NonlinearSolver::setDefaultDeltaBoundsMagnitudes(), NonlinearSolver::setupDoubleDogleg(), NonlinearSolver::solnErrorNorm(), NonlinearSolver::solnType_, NonlinearSolver::time_n, NonlinearSolver::trustDelta_, NonlinearSolver::trustRegionInitializationFactor_, and NonlinearSolver::trustRegionInitializationMethod_.

void calcColumnScales ( )
private
void setColumnScaling ( bool  useColScaling,
const double *const  scaleFactors = 0 
)

Set the column scaling that are used for the inversion of the matrix.

There are three ways to do this.

The first method is to set the bool useColScaling to true, leaving the scaling factors unset. Then, the column scales will be set to the solution error weighting factors. This has the effect of ensuring that all delta variables will have the same order of magnitude at convergence end.

The second way is the explicity set the column factors in the second argument of this function call.

The final way to input the scales is to override the ResidJacEval member function call,

calcSolnScales(double time_n, const double *m_y_n_curr, const double *m_y_nm1, double *m_colScales)

Overriding this function call will trump all other ways to specify the column scaling factors.

Parameters
useColScalingTurn this on if you want to use column scaling in the calculations
scaleFactorsA vector of doubles that specifies the column factors.

Definition at line 667 of file NonlinearSolver.cpp.

References NonlinearSolver::m_colScales, NonlinearSolver::m_colScaling, and NonlinearSolver::neq_.

void setRowScaling ( bool  useRowScaling)

Set the rowscaling that are used for the inversion of the matrix.

Row scaling is set here. Right now the row scaling is set internally in the code.

Parameters
useRowScalingTurn row scaling on or off.

Definition at line 692 of file NonlinearSolver.cpp.

References NonlinearSolver::m_rowScaling.

void scaleMatrix ( GeneralMatrix jac,
doublereal *const  y_comm,
doublereal *const  ydot_comm,
doublereal  time_curr,
int  num_newt_its 
)

Scale the matrix.

Parameters
jacJacobian
y_commCurrent value of the solution vector
ydot_commCurrent value of the time derivative of the solution vector
time_currcurrent value of the time
num_newt_itsCurrent value of the number of newt its

Definition at line 745 of file NonlinearSolver.cpp.

References GeneralMatrix::begin(), NonlinearSolver::computeResidWts(), GeneralMatrix::factored(), NonlinearSolver::m_colScales, NonlinearSolver::m_colScaling, NonlinearSolver::m_ewt, NonlinearSolver::m_rowScales, NonlinearSolver::m_rowScaling, NonlinearSolver::m_rowWtScales, GeneralMatrix::matrixType_, NonlinearSolver::neq_, GeneralMatrix::nRowsAndStruct(), and GeneralMatrix::ptrColumn().

Referenced by NonlinearSolver::solve_nonlinear_problem().

void print_solnDelta_norm_contrib ( const doublereal *const  step_1,
const char *const  stepNorm_1,
const doublereal *const  step_2,
const char *const  stepNorm_2,
const char *const  title,
const doublereal *const  y_n_curr,
const doublereal *const  y_n_1,
doublereal  damp,
size_t  num_entries 
)

Print solution norm contribution.

Prints out the most important entries to the update to the solution vector for the current step

Parameters
step_1Raw update vector for the current nonlinear step
stepNorm_1Norm of the vector step_1
step_2Raw update vector for the next solution value based on the old matrix
stepNorm_2Norm of the vector step_2
titletitle of the printout
y_n_currOld value of the solution
y_n_1New value of the solution after damping corrections
dampValue of the damping factor
num_entriesNumber of entries to print out

Definition at line 3589 of file NonlinearSolver.cpp.

References Cantera::error(), Cantera::int2str(), NonlinearSolver::m_ewt, NonlinearSolver::neq_, Cantera::npos, and Cantera::print_line().

Referenced by NonlinearSolver::dampStep().

void computeResidWts ( )

Compute the Residual Weights.

The residual weights are defined here to be equal to the inverse of the row scaling factors used to row scale the matrix, after column scaling is used. They are multiplied by 10-3 because the column weights are also multiplied by that same quantity.

The basic idea is that a change in the solution vector on the order of the convergence tolerance multiplied by [RJC] which is of order one after row scaling should give you the relative weight of the row. Values of the residual for that row can then be normalized by the value of this weight. When the tolerance in delta x is achieved, the tolerance in the residual is also achieved.

Definition at line 4038 of file NonlinearSolver.cpp.

References NonlinearSolver::atolBase_, NonlinearSolver::checkUserResidualTols_, NonlinearSolver::m_residWts, NonlinearSolver::m_rowWtScales, NonlinearSolver::m_ScaleSolnNormToResNorm, ckr::min(), NonlinearSolver::neq_, NonlinearSolver::ResidWtsReevaluated_, NonlinearSolver::userResidAtol_, and NonlinearSolver::userResidRtol_.

Referenced by NonlinearSolver::calcSolnToResNormVector(), and NonlinearSolver::scaleMatrix().

void getResidWts ( doublereal *const  residWts) const

Return the residual weights.

Parameters
residWtsVector of length neq_

Definition at line 4069 of file NonlinearSolver.cpp.

References NonlinearSolver::m_residWts, and NonlinearSolver::neq_.

int convergenceCheck ( int  dampCode,
doublereal  s1 
)

Check to see if the nonlinear problem has converged.

Parameters
dampCodeCode from the damping routine
s1Value of the norm of the step change
Returns
integer is returned. If positive, then the problem has converged 1 Successful step was taken: Next step's norm is less than 1.0. The final residual norm is less than 1.0. 2 Successful step: Next step's norm is less than 0.8. This step's norm is less than 1.0. The residual norm can be anything. 3 Success: The final residual is less than 1.0 The predicted deltaSoln is below 1.0. 0 Not converged yet

Definition at line 4090 of file NonlinearSolver.cpp.

References NonlinearSolver::m_dampBound, NonlinearSolver::m_dampRes, NonlinearSolver::m_normDeltaSoln_Newton, and NonlinearSolver::m_normResidTrial.

Referenced by NonlinearSolver::solve_nonlinear_problem().

void setAtol ( const doublereal *const  atol)

Set the absolute tolerances for the solution variables.

Set the absolute tolerances used in the calculation

Parameters
atolVector of length neq_ that contains the tolerances to be used for the solution variables

Definition at line 4143 of file NonlinearSolver.cpp.

References NonlinearSolver::atolk_, and NonlinearSolver::neq_.

void setRtol ( const doublereal  rtol)

Set the relative tolerances for the solution variables.

Set the relative tolerances used in the calculation

Parameters
rtolsingle double

Definition at line 4156 of file NonlinearSolver.cpp.

References NonlinearSolver::rtol_.

void setResidualTols ( double  residRtol,
double *  residATol,
int  residNormHandling = 2 
)

Set the relative and absolute tolerances for the Residual norm comparisons, if used.

Residual norms are used to calculate convergence within the nonlinear solver, since these are the norms that are associated with convergence proofs, especially for ill-conditioned systems. Usually the residual weights for each row are calculated by the program such that they correlate with the convergence requirements on the solution variables input by the user using the routines setAtol() and setRtol(). The residual weights are essentially calculated from the value

 residWeightNorm[i]  = m_ScaleSolnNormToResNorm  * sum_j ( fabs(A_i,j) ewt(j))

The factor, m_ScaleSolnNormToResNorm, is computed periodically to ensure that the solution norms and the residual norms are converging at the same time and thus accounts for some-illconditioning issues but not all.

The user specified tolerance for the residual is given by the following quantity

residWeightNorm[i] = residAtol[i] + residRtol * m_rowWtScales[i] / neq

Parameters
residNormHandlingParameter that sets the default handling of the residual norms 0 The residual weighting vector is calculated to make sure that the solution norms are roughly 1 when the residual norm is roughly 1. This is the default if this routine is not called. 1 Use the user residual norm specified by the parameters in this routine 2 Use the minimum value of the residual weights calculcated by method 1 and 2. This is the default if this routine is called and this parameter isn't specified.

Definition at line 4174 of file NonlinearSolver.cpp.

References NonlinearSolver::checkUserResidualTols_, NonlinearSolver::neq_, NonlinearSolver::userResidAtol_, and NonlinearSolver::userResidRtol_.

void setMaxNewtIts ( const int  maxNewtIts)

Set the value of the maximum # of newton iterations.

Parameters
maxNewtItsMaximum number of newton iterations
void calcSolnToResNormVector ( )

Calculate the scaling factor for translating residual norms into solution norms.

This routine calls computeResidWts() a couple of times in the calculation of m_ScaleSolnNormToResNorm. A more sophisticated routine may do more with signs to get a better value. Perhaps, a series of calculations with different signs attached may be in order. Then, m_ScaleSolnNormToResNorm would be calculated as the minimum of a series of calculations.

Definition at line 892 of file NonlinearSolver.cpp.

References NonlinearSolver::atolBase_, NonlinearSolver::checkUserResidualTols_, NonlinearSolver::computeResidWts(), Cantera::error(), GeneralMatrix::factored(), NonlinearSolver::jacCopyPtr_, NonlinearSolver::m_ewt, NonlinearSolver::m_residWts, NonlinearSolver::m_rowWtScales, NonlinearSolver::m_ScaleSolnNormToResNorm, NonlinearSolver::m_wksp, ckr::min(), NonlinearSolver::neq_, NonlinearSolver::userResidAtol_, and NonlinearSolver::userResidRtol_.

doublereal doCauchyPointSolve ( GeneralMatrix jac)
void descentComparison ( doublereal  time_curr,
doublereal *  ydot0,
doublereal *  ydot1,
int &  numTrials 
)

This is a utility routine that can be used to print out the rates of the initial residual decline.

The residual**2 decline for various directions is printed out. The rate of decline of the square of the residuals multiplied by the number of equations along each direction is printed out This quantity can be directly related to the theory, and may be calculated from derivatives at the original point.

( (r)**2 * neq - (r0)**2 * neq ) / distance

What's printed out:

The theoretical linearized residual decline The actual residual decline in the steepest descent direction determined by numerical differencing The actual residual decline in the newton direction determined by numerical differencing

This routine doesn't need to be called for the solution of the nonlinear problem.

Parameters
time_currCurrent time
ydot0INPUT Current value of the derivative of the solution vector
ydot1INPUT Time derivatives of solution at the conditions which are evaluated for success
numTrialsOUTPUT Counter for the number of residual evaluations

Definition at line 1534 of file NonlinearSolver.cpp.

References Cantera::Base_LaggedSolutionComponents, DATA_PTR, NonlinearSolver::deltaX_CP_, NonlinearSolver::deltaX_Newton_, NonlinearSolver::doDogLeg_, NonlinearSolver::doResidualCalc(), NonlinearSolver::lambdaStar_, NonlinearSolver::m_normResid_0, NonlinearSolver::m_print_flag, NonlinearSolver::m_resid, NonlinearSolver::m_wksp, NonlinearSolver::m_y_n_curr, NonlinearSolver::neq_, NSOLN_TYPE_STEADY_STATE, NonlinearSolver::ResidDecreaseNewt_, NonlinearSolver::ResidDecreaseNewtExp_, NonlinearSolver::ResidDecreaseSD_, NonlinearSolver::ResidDecreaseSDExp_, NonlinearSolver::residErrorNorm(), NonlinearSolver::RJd_norm_, NonlinearSolver::s_print_DogLeg, NonlinearSolver::solnErrorNorm(), and NonlinearSolver::solnType_.

Referenced by NonlinearSolver::solve_nonlinear_problem().

void setupDoubleDogleg ( )

Setup the parameters for the double dog leg.

The calls to the doCauchySolve() and doNewtonSolve() routines are done at the main level. This routine comes after those calls. We calculate the point Nuu_ here, the distances of the dog-legs, and the norms of the CP and Newton points in terms of the trust vectors.

Definition at line 1668 of file NonlinearSolver.cpp.

References NonlinearSolver::calcTrustDistance(), DATA_PTR, NonlinearSolver::deltaX_CP_, NonlinearSolver::deltaX_Newton_, NonlinearSolver::dist_R0_, NonlinearSolver::dist_R1_, NonlinearSolver::dist_R2_, NonlinearSolver::dist_Total_, NonlinearSolver::expectedResidLeg(), NonlinearSolver::m_normDeltaSoln_CP, NonlinearSolver::m_normDeltaSoln_Newton, NonlinearSolver::m_normResid_0, NonlinearSolver::m_wksp, NonlinearSolver::neq_, NonlinearSolver::normTrust_CP_, NonlinearSolver::normTrust_Newton_, NonlinearSolver::Nuu_, and NonlinearSolver::solnErrorNorm().

Referenced by NonlinearSolver::solve_nonlinear_problem().

int lambdaToLeg ( const doublereal  lambda,
doublereal &  alpha 
) const

Change the global lambda coordinate into the (leg,alpha) coordinate for the double dogleg.

Parameters
lambdaGlobal value of the distance along the double dogleg
alpharelative value along the particular leg
Returns
Returns the leg number ( 0, 1, or 2).

Definition at line 1732 of file NonlinearSolver.cpp.

References NonlinearSolver::dist_R0_, NonlinearSolver::dist_R1_, NonlinearSolver::dist_R2_, and NonlinearSolver::dist_Total_.

int calcTrustIntersection ( doublereal  trustVal,
doublereal &  lambda,
doublereal &  alpha 
) const

Given a trust distance, this routine calculates the intersection of the this distance with the double dogleg curve.

Parameters
trustVal(INPUT) Value of the trust distance
lambda(OUTPUT) Returns the internal coordinate of the double dogleg
alpha(OUTPUT) Returns the relative distance along the appropriate leg
Returns
leg (OUTPUT) Returns the leg ID (0, 1, or 2)

Definition at line 2300 of file NonlinearSolver.cpp.

References NonlinearSolver::deltaX_CP_, NonlinearSolver::deltaX_Newton_, NonlinearSolver::deltaX_trust_, NonlinearSolver::dist_R0_, NonlinearSolver::dist_R1_, NonlinearSolver::dist_R2_, NonlinearSolver::dist_Total_, NonlinearSolver::neq_, NonlinearSolver::normTrust_CP_, NonlinearSolver::normTrust_Newton_, and NonlinearSolver::Nuu_.

Referenced by NonlinearSolver::dampDogLeg().

void initializeTrustRegion ( )
void setTrustRegionInitializationMethod ( int  method,
doublereal  factor 
)

Set Trust region initialization strategy.

The default is use method 2 with a factor of 1. Then, on subsequent invocations of solve_nonlinear_problem() the strategy flips to method 0.

Parameters
methodMethod to set the strategy 0 No strategy - Use the previous strategy 1 Factor of the solution error weights 2 Factor of the first Cauchy Point distance 3 Factor of the first Newton step distance
factorFactor to use in combination with the method
int dampDogLeg ( const doublereal  time_curr,
const doublereal *  y_n_curr,
const doublereal *  ydot_n_curr,
std::vector< doublereal > &  step_1,
doublereal *const  y_n_1,
doublereal *const  ydot_n_1,
doublereal &  stepNorm_1,
doublereal &  stepNorm_2,
GeneralMatrix jac,
int &  num_backtracks 
)

Damp using the dog leg approach.

Parameters
time_currINPUT Current value of the time
y_n_currINPUT Current value of the solution vector
ydot_n_currINPUT Current value of the derivative of the solution vector
step_1INPUT First trial step for the first iteration
y_n_1INPUT First trial value of the solution vector
ydot_n_1INPUT First trial value of the derivative of the solution vector
stepNorm_1OUTPUT Norm of the vector step_1
stepNorm_2OUTPUT Estimated norm of the vector step_2
jacINPUT jacobian
num_backtracksOUTPUT number of backtracks taken in the current damping step
Returns
1 Successful step was taken. The predicted residual norm is less than one 2 Successful step: Next step's norm is less than 0.8 3 Success: The final residual is less than 1.0 A predicted deltaSoln1 is not produced however. s1 is estimated. 4 Success: The final residual is less than the residual from the previous step. A predicted deltaSoln1 is not produced however. s1 is estimated. 0 Uncertain Success: s1 is about the same as s0 -2 Unsuccessful step.

Definition at line 2674 of file NonlinearSolver.cpp.

References NonlinearSolver::boundStep(), NonlinearSolver::calc_ydot(), NonlinearSolver::calcTrustIntersection(), DATA_PTR, NonlinearSolver::decideStep(), NonlinearSolver::dogLegAlpha_, NonlinearSolver::dogLegID_, NonlinearSolver::fillDogLegStep(), NonlinearSolver::m_dampBound, NonlinearSolver::m_dampRes, NonlinearSolver::m_normResid_0, NonlinearSolver::m_normResid_1, NonlinearSolver::m_normResid_Bound, NonlinearSolver::m_normResidTrial, NonlinearSolver::m_order, NonlinearSolver::m_print_flag, NonlinearSolver::m_wksp, mdp::mdp_copy_dbl_1(), Cantera::NDAMP, NonlinearSolver::neq_, NonlinearSolver::normTrust_Newton_, NSOLN_RETN_FAIL_DAMPSTEP, NSOLN_TYPE_STEADY_STATE, NonlinearSolver::solnErrorNorm(), NonlinearSolver::solnType_, NonlinearSolver::trustDelta_, and NonlinearSolver::trustRegionLength().

Referenced by NonlinearSolver::solve_nonlinear_problem().

int decideStep ( const doublereal  time_curr,
int  leg,
doublereal  alpha,
const doublereal *const  y_n_curr,
const doublereal *const  ydot_n_curr,
const std::vector< doublereal > &  step_1,
const doublereal *const  y_n_1,
const doublereal *const  ydot_n_1,
doublereal  trustDeltaOld 
)

Decide whether the current step is acceptable and adjust the trust region size.

This is an extension of algorithm 6.4.5 of Dennis and Schnabel.

Here we decide whether to accept the current step At the end of the calculation a new estimate of the trust region is calculated

Parameters
time_currINPUT Current value of the time
legINPUT Leg of the dogleg that we are on
alphaINPUT Distance down that leg that we are on
y_n_currINPUT Current value of the solution vector
ydot_n_currINPUT Current value of the derivative of the solution vector
step_1INPUT Trial step
y_n_1OUTPUT Solution values at the conditions which are evaluated for success
ydot_n_1OUTPUT Time derivatives of solution at the conditions which are evaluated for success
trustDeltaOldINPUT Value of the trust length at the old conditions
Returns
This function returns a code which indicates whether the step will be accepted or not. 3 Step passed with flying colors. Try redoing the calculation with a bigger trust region. 2 Step didn't pass deltaF requirement. Decrease the size of the next trust region for a retry and return 0 The step passed. -1 The step size is now too small (||d || < 0.1). A really small step isn't decreasing the function. This is an error condition. -2 Current value of the solution vector caused a residual error in its evaluation. Step is a failure, and the step size must be reduced in order to proceed further.

Definition at line 2850 of file NonlinearSolver.cpp.

References NonlinearSolver::adjustUpStepMinimums(), Cantera::Base_LaggedSolutionComponents, NonlinearSolver::CurrentTrustFactor_, DATA_PTR, NonlinearSolver::deltaX_CP_, NonlinearSolver::dogLegAlpha_, NonlinearSolver::dogLegID_, NonlinearSolver::doResidualCalc(), NonlinearSolver::expectedResidLeg(), NonlinearSolver::lambdaStar_, NonlinearSolver::m_dampBound, NonlinearSolver::m_normDeltaSoln_Newton, NonlinearSolver::m_normResid_0, NonlinearSolver::m_normResid_1, NonlinearSolver::m_normResidTrial, NonlinearSolver::m_print_flag, NonlinearSolver::m_resid, NonlinearSolver::neq_, NonlinearSolver::NextTrustFactor_, NSOLN_TYPE_STEADY_STATE, NonlinearSolver::residErrorNorm(), NonlinearSolver::RJd_norm_, NonlinearSolver::rtol_, NonlinearSolver::solnErrorNorm(), NonlinearSolver::solnType_, NonlinearSolver::trustDelta_, and NonlinearSolver::trustRegionLength().

Referenced by NonlinearSolver::dampDogLeg().

doublereal expectedResidLeg ( int  leg,
doublereal  alpha 
) const

Calculated the expected residual along the double dogleg curve.

Parameters
leg0, 1, or 2 representing the curves of the dogleg
alphaRelative distance along the particular curve.
Returns
Returns the expected value of the residual at that point according to the quadratic model. The residual at the newton point will always be zero.

Definition at line 1754 of file NonlinearSolver.cpp.

References NonlinearSolver::lambdaStar_, NonlinearSolver::m_normResid_0, NonlinearSolver::neq_, NonlinearSolver::Nuu_, and NonlinearSolver::RJd_norm_.

Referenced by NonlinearSolver::decideStep(), NonlinearSolver::residualComparisonLeg(), and NonlinearSolver::setupDoubleDogleg().

void residualComparisonLeg ( const doublereal  time_curr,
const doublereal *const  ydot0,
int &  legBest,
doublereal &  alphaBest 
) const

Here we print out the residual at various points along the double dogleg, comparing against the quadratic model in a table format.

Parameters
time_currINPUT current time
ydot0INPUT Current value of the derivative of the solution vector for non-time dependent determinations
legBestOUTPUT leg of the dogleg that gives the lowest residual
alphaBestOUTPUT distance along dogleg for best result.

Definition at line 1818 of file NonlinearSolver.cpp.

References Cantera::Base_LaggedSolutionComponents, NonlinearSolver::calc_ydot(), DATA_PTR, NonlinearSolver::deltaX_CP_, NonlinearSolver::deltaX_Newton_, NonlinearSolver::doDogLeg_, NonlinearSolver::doResidualCalc(), NonlinearSolver::expectedResidLeg(), NonlinearSolver::m_order, NonlinearSolver::m_print_flag, NonlinearSolver::m_resid, NonlinearSolver::m_wksp, NonlinearSolver::m_wksp_2, NonlinearSolver::m_y_n_curr, NonlinearSolver::neq_, NSOLN_TYPE_STEADY_STATE, NonlinearSolver::Nuu_, NonlinearSolver::residErrorNorm(), NonlinearSolver::s_print_DogLeg, NonlinearSolver::solnErrorNorm(), and NonlinearSolver::solnType_.

Referenced by NonlinearSolver::solve_nonlinear_problem().

void setPrintLvl ( int  printLvl)

Set the print level from the nonlinear solver.

0 -> absolutely nothing is printed for a single time step. 1 -> One line summary per solve_nonlinear call 2 -> short description, points of interest: Table of nonlinear solve - one line per iteration 3 -> Table is included -> More printing per nonlinear iteration (default) that occurs during the table 4 -> Summaries of the nonlinear solve iteration as they are occurring -> table no longer printed 5 -> Algorithm information on the nonlinear iterates are printed out 6 -> Additional info on the nonlinear iterates are printed out 7 -> Additional info on the linear solve is printed out. 8 -> Info on a per iterate of the linear solve is printed out.

Parameters
printLvlinteger value

Definition at line 4195 of file NonlinearSolver.cpp.

References NonlinearSolver::m_print_flag.

void setSolverScheme ( int  doDogLeg,
int  doAffineSolve 
)

Parameter to turn on solution solver schemes.

Parameters
doDogLegParameter to turn on the double dog leg scheme Default is to always use a damping scheme in the Newton Direction. When this is nonzero, a model trust region approach is used using a double dog leg with the steepest descent direction used for small step sizes.
doAffineSolveParameter to turn on or off the solution of the system using a Hessian if the matrix has a bad condition number.

Definition at line 452 of file NonlinearSolver.cpp.

References NonlinearSolver::doAffineSolve_, and NonlinearSolver::doDogLeg_.

Member Data Documentation

ResidJacEval* m_func
private
int solnType_
private
size_t neq_
private

Local copy of the number of equations.

Definition at line 928 of file NonlinearSolver.h.

Referenced by NonlinearSolver::adjustUpStepMinimums(), NonlinearSolver::beuler_jac(), NonlinearSolver::boundStep(), NonlinearSolver::calc_ydot(), NonlinearSolver::calcColumnScales(), NonlinearSolver::calcSolnToResNormVector(), NonlinearSolver::calcTrustDistance(), NonlinearSolver::calcTrustIntersection(), NonlinearSolver::computeResidWts(), NonlinearSolver::createSolnWeights(), NonlinearSolver::dampDogLeg(), NonlinearSolver::dampStep(), NonlinearSolver::decideStep(), NonlinearSolver::deltaBoundStep(), NonlinearSolver::descentComparison(), NonlinearSolver::doAffineNewtonSolve(), NonlinearSolver::doCauchyPointSolve(), NonlinearSolver::doNewtonSolve(), NonlinearSolver::expectedResidLeg(), NonlinearSolver::fillDogLegStep(), NonlinearSolver::getResidWts(), NonlinearSolver::initializeTrustRegion(), NonlinearSolver::NonlinearSolver(), NonlinearSolver::operator=(), NonlinearSolver::print_solnDelta_norm_contrib(), NonlinearSolver::readjustTrustVector(), NonlinearSolver::residErrorNorm(), NonlinearSolver::residualComparisonLeg(), NonlinearSolver::scaleMatrix(), NonlinearSolver::setAtol(), NonlinearSolver::setBoundsConstraints(), NonlinearSolver::setColumnScaling(), NonlinearSolver::setDefaultDeltaBoundsMagnitudes(), NonlinearSolver::setDeltaBoundsMagnitudes(), NonlinearSolver::setResidualTols(), NonlinearSolver::setupDoubleDogleg(), NonlinearSolver::solnErrorNorm(), and NonlinearSolver::solve_nonlinear_problem().

std::vector<doublereal> m_ewt
private
int m_manualDeltaStepSet
private

Boolean indicating whether a manual delta bounds has been input.

Definition at line 934 of file NonlinearSolver.h.

Referenced by NonlinearSolver::operator=(), NonlinearSolver::setDeltaBoundsMagnitudes(), and NonlinearSolver::solve_nonlinear_problem().

std::vector<doublereal> m_deltaStepMinimum
private
std::vector<doublereal> m_deltaStepMaximum
private

Value of the delta step magnitudes.

Definition at line 940 of file NonlinearSolver.h.

Referenced by NonlinearSolver::NonlinearSolver(), and NonlinearSolver::readjustTrustVector().

std::vector<doublereal> m_y_n_curr
private
std::vector<doublereal> m_ydot_n_curr
private

Vector containing the time derivative of the current solution vector within the nonlinear solver (where applicable)

Definition at line 947 of file NonlinearSolver.h.

Referenced by NonlinearSolver::NonlinearSolver(), NonlinearSolver::operator=(), and NonlinearSolver::solve_nonlinear_problem().

std::vector<doublereal> m_y_nm1
private

Vector containing the solution at the previous time step.

Definition at line 950 of file NonlinearSolver.h.

Referenced by NonlinearSolver::calc_ydot(), NonlinearSolver::calcColumnScales(), NonlinearSolver::NonlinearSolver(), and NonlinearSolver::operator=().

std::vector<doublereal> m_y_n_1
private

Vector containing the solution at the previous time step.

Definition at line 953 of file NonlinearSolver.h.

Referenced by NonlinearSolver::NonlinearSolver(), NonlinearSolver::operator=(), and NonlinearSolver::solve_nonlinear_problem().

std::vector<doublereal> m_ydot_n_1
private

Value of the solution time derivative at the new point that is to be considered.

Definition at line 956 of file NonlinearSolver.h.

Referenced by NonlinearSolver::NonlinearSolver(), NonlinearSolver::operator=(), and NonlinearSolver::solve_nonlinear_problem().

std::vector<doublereal> m_step_1
private

Value of the step to be taken in the solution.

Definition at line 959 of file NonlinearSolver.h.

Referenced by NonlinearSolver::NonlinearSolver(), NonlinearSolver::operator=(), and NonlinearSolver::solve_nonlinear_problem().

std::vector<doublereal> m_colScales
private
std::vector<doublereal> m_rowScales
private

Weights for normalizing the values of the residuals.

These are computed if row scaling, m_rowScaling, is turned on. They are calculated currently as the sum of the absolute values of the rows of the jacobian.

Definition at line 969 of file NonlinearSolver.h.

Referenced by NonlinearSolver::doAffineNewtonSolve(), NonlinearSolver::doCauchyPointSolve(), NonlinearSolver::doNewtonSolve(), NonlinearSolver::NonlinearSolver(), NonlinearSolver::operator=(), and NonlinearSolver::scaleMatrix().

std::vector<doublereal> m_rowWtScales
private

Weights for normalizing the values of the residuals.

They are calculated as the sum of the absolute values of the jacobian multiplied by the solution weight function. This is carried out in scaleMatrix().

Definition at line 977 of file NonlinearSolver.h.

Referenced by NonlinearSolver::calcSolnToResNormVector(), NonlinearSolver::computeResidWts(), NonlinearSolver::NonlinearSolver(), NonlinearSolver::operator=(), and NonlinearSolver::scaleMatrix().

std::vector<doublereal> m_resid
mutableprivate
std::vector<doublereal> m_wksp
mutableprivate
std::vector<doublereal> m_wksp_2
mutableprivate
std::vector<doublereal> m_residWts
private

Vector of residual weights.

These are used to establish useful and informative weighted norms of the residual vector.

Definition at line 995 of file NonlinearSolver.h.

Referenced by NonlinearSolver::calcSolnToResNormVector(), NonlinearSolver::computeResidWts(), NonlinearSolver::doCauchyPointSolve(), NonlinearSolver::getResidWts(), NonlinearSolver::NonlinearSolver(), NonlinearSolver::operator=(), and NonlinearSolver::residErrorNorm().

doublereal m_normResid_0
private
doublereal m_normResid_Bound
private

Norm of the residual after it has been bounded.

Definition at line 1001 of file NonlinearSolver.h.

Referenced by NonlinearSolver::dampDogLeg(), NonlinearSolver::dampStep(), NonlinearSolver::operator=(), and NonlinearSolver::solve_nonlinear_problem().

doublereal m_normResid_1
private

Norm of the residual at the end of the first leg of the current iteration.

Definition at line 1004 of file NonlinearSolver.h.

Referenced by NonlinearSolver::dampDogLeg(), NonlinearSolver::dampStep(), NonlinearSolver::decideStep(), NonlinearSolver::operator=(), and NonlinearSolver::solve_nonlinear_problem().

doublereal m_normResid_full
private

Norm of the residual at the end of the first leg of the current iteration.

Definition at line 1007 of file NonlinearSolver.h.

Referenced by NonlinearSolver::solve_nonlinear_problem().

doublereal m_normDeltaSoln_Newton
private

Norm of the solution update created by the iteration in its raw, undamped form, using the solution norm.

Definition at line 1010 of file NonlinearSolver.h.

Referenced by NonlinearSolver::convergenceCheck(), NonlinearSolver::decideStep(), NonlinearSolver::initializeTrustRegion(), NonlinearSolver::operator=(), NonlinearSolver::setupDoubleDogleg(), and NonlinearSolver::solve_nonlinear_problem().

doublereal m_normDeltaSoln_CP
private

Norm of the distance to the cauchy point using the solution norm.

Definition at line 1013 of file NonlinearSolver.h.

Referenced by NonlinearSolver::initializeTrustRegion(), NonlinearSolver::operator=(), NonlinearSolver::setupDoubleDogleg(), and NonlinearSolver::solve_nonlinear_problem().

doublereal m_normResidTrial
private
doublereal m_normResidPoints[15]
private

Vector of the norm.

Definition at line 1019 of file NonlinearSolver.h.

bool m_resid_scaled
mutableprivate

Boolean indicating whether we should scale the residual.

Definition at line 1022 of file NonlinearSolver.h.

Referenced by NonlinearSolver::doAffineNewtonSolve(), NonlinearSolver::doNewtonSolve(), NonlinearSolver::doResidualCalc(), and NonlinearSolver::operator=().

std::vector<doublereal> m_y_high_bounds
private
std::vector<doublereal> m_y_low_bounds
private
doublereal m_dampBound
private
doublereal m_dampRes
private

Additional damping factor due to bounds on the residual and solution norms.

Definition at line 1038 of file NonlinearSolver.h.

Referenced by NonlinearSolver::convergenceCheck(), NonlinearSolver::dampDogLeg(), NonlinearSolver::dampStep(), NonlinearSolver::operator=(), and NonlinearSolver::solve_nonlinear_problem().

doublereal delta_t_n
private
int m_nfe
mutableprivate

Counter for the total number of function evaluations.

Definition at line 1044 of file NonlinearSolver.h.

Referenced by NonlinearSolver::beuler_jac(), NonlinearSolver::doResidualCalc(), and NonlinearSolver::operator=().

int m_colScaling
private

The type of column scaling used in the matrix inversion of the problem.

If 1 then colScaling = m_ewt[] If 2 then colScaling = user set if 0 then colScaling = 1.0

Definition at line 1056 of file NonlinearSolver.h.

Referenced by NonlinearSolver::calcColumnScales(), NonlinearSolver::doAffineNewtonSolve(), NonlinearSolver::doCauchyPointSolve(), NonlinearSolver::doNewtonSolve(), NonlinearSolver::operator=(), NonlinearSolver::scaleMatrix(), and NonlinearSolver::setColumnScaling().

int m_rowScaling
private
int m_numTotalLinearSolves
private

Total number of linear solves taken by the solver object.

Definition at line 1062 of file NonlinearSolver.h.

Referenced by NonlinearSolver::doAffineNewtonSolve(), NonlinearSolver::doNewtonSolve(), NonlinearSolver::operator=(), and NonlinearSolver::solve_nonlinear_problem().

int m_numLocalLinearSolves
private

Number of local linear solves done during the current iteration.

Definition at line 1065 of file NonlinearSolver.h.

Referenced by NonlinearSolver::doAffineNewtonSolve(), NonlinearSolver::doNewtonSolve(), and NonlinearSolver::solve_nonlinear_problem().

int m_numTotalNewtIts
private

Total number of newton iterations.

Definition at line 1068 of file NonlinearSolver.h.

Referenced by NonlinearSolver::operator=(), and NonlinearSolver::solve_nonlinear_problem().

int m_min_newt_its
private

Minimum number of newton iterations to use.

Definition at line 1071 of file NonlinearSolver.h.

Referenced by NonlinearSolver::operator=(), and NonlinearSolver::solve_nonlinear_problem().

int maxNewtIts_
private

Maximum number of newton iterations.

Definition at line 1074 of file NonlinearSolver.h.

Referenced by NonlinearSolver::operator=(), and NonlinearSolver::solve_nonlinear_problem().

int m_jacFormMethod
private

Jacobian formation method.

1 = numerical (default) 2 = analytical

Definition at line 1081 of file NonlinearSolver.h.

Referenced by NonlinearSolver::beuler_jac(), and NonlinearSolver::operator=().

int m_nJacEval
private

Number of Jacobian evaluations.

Definition at line 1084 of file NonlinearSolver.h.

Referenced by NonlinearSolver::beuler_jac(), and NonlinearSolver::operator=().

doublereal time_n
private

Current system time.

Note, we assume even for steady state problems that the residual is a function of a system time.

Definition at line 1091 of file NonlinearSolver.h.

Referenced by NonlinearSolver::calcColumnScales(), NonlinearSolver::operator=(), and NonlinearSolver::solve_nonlinear_problem().

int m_matrixConditioning
private

Boolean indicating matrix conditioning.

Definition at line 1094 of file NonlinearSolver.h.

Referenced by NonlinearSolver::operator=().

int m_order
private
doublereal rtol_
private

value of the relative tolerance to use in solving the equation set

Definition at line 1100 of file NonlinearSolver.h.

Referenced by NonlinearSolver::createSolnWeights(), NonlinearSolver::decideStep(), NonlinearSolver::NonlinearSolver(), NonlinearSolver::operator=(), and NonlinearSolver::setRtol().

doublereal atolBase_
private
doublereal* m_ydot_nm1
private

Pointer containing the solution derivative at the previous time step.

Definition at line 1106 of file NonlinearSolver.h.

Referenced by NonlinearSolver::calc_ydot().

std::vector<doublereal> atolk_
private

absolute tolerance in the solution unknown

This is used to evaluating the weighting factor

Definition at line 1112 of file NonlinearSolver.h.

Referenced by NonlinearSolver::createSolnWeights(), NonlinearSolver::NonlinearSolver(), NonlinearSolver::operator=(), NonlinearSolver::setAtol(), and NonlinearSolver::setDefaultDeltaBoundsMagnitudes().

std::vector<doublereal> userResidAtol_
private

absolute tolerance in the unscaled solution unknowns

Definition at line 1115 of file NonlinearSolver.h.

Referenced by NonlinearSolver::calcSolnToResNormVector(), NonlinearSolver::computeResidWts(), NonlinearSolver::operator=(), and NonlinearSolver::setResidualTols().

doublereal userResidRtol_
private

absolute tolerance in the unscaled solution unknowns

Definition at line 1118 of file NonlinearSolver.h.

Referenced by NonlinearSolver::calcSolnToResNormVector(), NonlinearSolver::computeResidWts(), NonlinearSolver::operator=(), and NonlinearSolver::setResidualTols().

int checkUserResidualTols_
private

Check the residual tolerances explictly against user input.

0 Don't calculate residual weights from residual tolerance inputs 1 Calculate residual weights from residual tolerance inputs only 2 Calculate residual weights from a minimum of the solution error weights process and the direct residual tolerance inputs

Definition at line 1126 of file NonlinearSolver.h.

Referenced by NonlinearSolver::calcSolnToResNormVector(), NonlinearSolver::computeResidWts(), NonlinearSolver::operator=(), and NonlinearSolver::setResidualTols().

int m_print_flag
private

Determines the level of printing for each time step.

0 -> absolutely nothing is printed for a single time step. 1 -> One line summary per solve_nonlinear call 2 -> short description, points of interest: Table of nonlinear solve - one line per iteration 3 -> Table is included -> More printing per nonlinear iteration (default) that occurs during the table 4 -> Summaries of the nonlinear solve iteration as they are occurring -> table no longer printed 5 -> Algorithm information on the nonlinear iterates are printed out 6 -> Additional info on the nonlinear iterates are printed out 7 -> Additional info on the linear solve is printed out. 8 -> Info on a per iterate of the linear solve is printed out.

Definition at line 1140 of file NonlinearSolver.h.

Referenced by NonlinearSolver::beuler_jac(), NonlinearSolver::boundStep(), NonlinearSolver::dampDogLeg(), NonlinearSolver::dampStep(), NonlinearSolver::decideStep(), NonlinearSolver::deltaBoundStep(), NonlinearSolver::descentComparison(), NonlinearSolver::doAffineNewtonSolve(), NonlinearSolver::doCauchyPointSolve(), NonlinearSolver::initializeTrustRegion(), NonlinearSolver::operator=(), NonlinearSolver::readjustTrustVector(), NonlinearSolver::residErrorNorm(), NonlinearSolver::residualComparisonLeg(), NonlinearSolver::setPrintLvl(), NonlinearSolver::solnErrorNorm(), and NonlinearSolver::solve_nonlinear_problem().

doublereal m_ScaleSolnNormToResNorm
private

Scale factor for turning residual norms into solution norms.

Definition at line 1143 of file NonlinearSolver.h.

Referenced by NonlinearSolver::calcSolnToResNormVector(), NonlinearSolver::computeResidWts(), and NonlinearSolver::operator=().

Cantera::GeneralMatrix* jacCopyPtr_
private

Copy of the jacobian that doesn't get overwritten when the inverse is determined.

The jacobian stored here is the raw matrix, before any row or column scaling is carried out

Definition at line 1149 of file NonlinearSolver.h.

Referenced by NonlinearSolver::beuler_jac(), NonlinearSolver::calcSolnToResNormVector(), NonlinearSolver::doAffineNewtonSolve(), NonlinearSolver::operator=(), NonlinearSolver::solve_nonlinear_problem(), and NonlinearSolver::~NonlinearSolver().

Cantera::GeneralMatrix* HessianPtr_
private
std::vector<doublereal> deltaX_CP_
private
std::vector<doublereal> deltaX_Newton_
private
doublereal residNorm2Cauchy_
private

Expected value of the residual norm at the Cauchy point if the quadratic model were valid.

Definition at line 1169 of file NonlinearSolver.h.

Referenced by NonlinearSolver::doCauchyPointSolve(), and NonlinearSolver::operator=().

int dogLegID_
private
doublereal dogLegAlpha_
private
doublereal RJd_norm_
private

Residual dot Jd norm.

This is equal to R_hat dot J_hat d_y_descent

Definition at line 1181 of file NonlinearSolver.h.

Referenced by NonlinearSolver::decideStep(), NonlinearSolver::descentComparison(), NonlinearSolver::doCauchyPointSolve(), NonlinearSolver::expectedResidLeg(), and NonlinearSolver::operator=().

doublereal lambdaStar_
private

Value of lambdaStar_ which is used to calculate the Cauchy point.

Definition at line 1184 of file NonlinearSolver.h.

Referenced by NonlinearSolver::decideStep(), NonlinearSolver::descentComparison(), NonlinearSolver::doCauchyPointSolve(), NonlinearSolver::expectedResidLeg(), and NonlinearSolver::operator=().

std::vector<doublereal> Jd_
private

Jacobian times the steepest descent direction in the normalized coordinates.

This is equal to [ Jhat d^y_{descent} ] in the notes, Eqn. 18.

Definition at line 1190 of file NonlinearSolver.h.

Referenced by NonlinearSolver::doCauchyPointSolve(), NonlinearSolver::NonlinearSolver(), and NonlinearSolver::operator=().

std::vector<doublereal> deltaX_trust_
private
doublereal norm_deltaX_trust_
mutableprivate

Current norm of the vector deltaX_trust_ in terms of the solution norm.

Definition at line 1196 of file NonlinearSolver.h.

Referenced by NonlinearSolver::operator=(), NonlinearSolver::readjustTrustVector(), NonlinearSolver::solve_nonlinear_problem(), and NonlinearSolver::trustRegionLength().

doublereal trustDelta_
private
int trustRegionInitializationMethod_
private

Method for handling the trust region initialization.

Then, on subsequent invocations of solve_nonlinear_problem() the strategy flips to method 0.

method Method to set the strategy 0 No strategy - Use the previous strategy 1 Factor of the solution error weights 2 Factor of the first Cauchy Point distance 3 Factor of the first Newton step distance

Definition at line 1212 of file NonlinearSolver.h.

Referenced by NonlinearSolver::initializeTrustRegion(), NonlinearSolver::operator=(), and NonlinearSolver::solve_nonlinear_problem().

doublereal trustRegionInitializationFactor_
private

Factor used to set the initial trust region.

Definition at line 1215 of file NonlinearSolver.h.

Referenced by NonlinearSolver::initializeTrustRegion(), NonlinearSolver::operator=(), and NonlinearSolver::solve_nonlinear_problem().

doublereal Nuu_
private
doublereal dist_R0_
private

Distance of the zeroeth leg of the dogleg in terms of the solution norm.

Definition at line 1221 of file NonlinearSolver.h.

Referenced by NonlinearSolver::calcTrustIntersection(), NonlinearSolver::lambdaToLeg(), NonlinearSolver::operator=(), and NonlinearSolver::setupDoubleDogleg().

doublereal dist_R1_
private

Distance of the first leg of the dogleg in terms of the solution norm.

Definition at line 1224 of file NonlinearSolver.h.

Referenced by NonlinearSolver::calcTrustIntersection(), NonlinearSolver::lambdaToLeg(), NonlinearSolver::operator=(), and NonlinearSolver::setupDoubleDogleg().

doublereal dist_R2_
private

Distance of the second leg of the dogleg in terms of the solution norm.

Definition at line 1227 of file NonlinearSolver.h.

Referenced by NonlinearSolver::calcTrustIntersection(), NonlinearSolver::lambdaToLeg(), NonlinearSolver::operator=(), and NonlinearSolver::setupDoubleDogleg().

doublereal dist_Total_
private

Distance of the sum of all legs of the doglegs in terms of the solution norm.

Definition at line 1230 of file NonlinearSolver.h.

Referenced by NonlinearSolver::calcTrustIntersection(), NonlinearSolver::lambdaToLeg(), NonlinearSolver::operator=(), and NonlinearSolver::setupDoubleDogleg().

doublereal JdJd_norm_
private

Dot product of the Jd_ variable defined above with itself.

Definition at line 1233 of file NonlinearSolver.h.

Referenced by NonlinearSolver::doCauchyPointSolve(), and NonlinearSolver::operator=().

doublereal normTrust_Newton_
private
doublereal normTrust_CP_
private

Norm of the Cauchy Step direction wrt trust region.

Definition at line 1239 of file NonlinearSolver.h.

Referenced by NonlinearSolver::calcTrustIntersection(), NonlinearSolver::operator=(), and NonlinearSolver::setupDoubleDogleg().

int doDogLeg_
private
int doAffineSolve_
private

General toggle for turning on Affine solve with Hessian.

Definition at line 1245 of file NonlinearSolver.h.

Referenced by NonlinearSolver::operator=(), NonlinearSolver::setSolverScheme(), and NonlinearSolver::solve_nonlinear_problem().

doublereal m_conditionNumber
private

Condition number of the matrix.

Definition at line 1248 of file NonlinearSolver.h.

Referenced by NonlinearSolver::doAffineNewtonSolve(), and NonlinearSolver::solve_nonlinear_problem().

doublereal CurrentTrustFactor_
private

Factor indicating how much trust region has been changed this iteration - output variable.

Definition at line 1251 of file NonlinearSolver.h.

Referenced by NonlinearSolver::decideStep(), NonlinearSolver::operator=(), and NonlinearSolver::solve_nonlinear_problem().

doublereal NextTrustFactor_
private

Factor indicating how much trust region has been changed next iteration - output variable.

Definition at line 1254 of file NonlinearSolver.h.

Referenced by NonlinearSolver::decideStep(), NonlinearSolver::operator=(), and NonlinearSolver::solve_nonlinear_problem().

bool ResidWtsReevaluated_
private

Boolean indicating that the residual weights have been reevaluated this iteration - output variable.

Definition at line 1257 of file NonlinearSolver.h.

Referenced by NonlinearSolver::computeResidWts(), NonlinearSolver::operator=(), and NonlinearSolver::solve_nonlinear_problem().

doublereal ResidDecreaseSDExp_
private

Expected DResid_dS for the steepest descent path - output variable.

Definition at line 1260 of file NonlinearSolver.h.

Referenced by NonlinearSolver::descentComparison(), NonlinearSolver::operator=(), and NonlinearSolver::solve_nonlinear_problem().

doublereal ResidDecreaseSD_
private

Actual DResid_dS for the steepest descent path - output variable.

Definition at line 1263 of file NonlinearSolver.h.

Referenced by NonlinearSolver::descentComparison(), NonlinearSolver::operator=(), and NonlinearSolver::solve_nonlinear_problem().

doublereal ResidDecreaseNewtExp_
private

Expected DResid_dS for the Newton path - output variable.

Definition at line 1266 of file NonlinearSolver.h.

Referenced by NonlinearSolver::descentComparison(), NonlinearSolver::operator=(), and NonlinearSolver::solve_nonlinear_problem().

doublereal ResidDecreaseNewt_
private

Actual DResid_dS for the newton path - output variable.

Definition at line 1269 of file NonlinearSolver.h.

Referenced by NonlinearSolver::descentComparison(), NonlinearSolver::operator=(), and NonlinearSolver::solve_nonlinear_problem().

bool s_TurnOffTiming
static

Turn off printing of time.

Necessary to do for test suites

Definition at line 1280 of file NonlinearSolver.h.

Referenced by NonlinearSolver::solve_nonlinear_problem().

bool s_print_NumJac
static

Turn on or off printing of the Jacobian.

Definition at line 1283 of file NonlinearSolver.h.

Referenced by NonlinearSolver::beuler_jac().

bool s_print_DogLeg
static
bool s_doBothSolvesAndCompare
static

Turn on solving both the Newton and Hessian systems and comparing the results.

This is off by default

Definition at line 1292 of file NonlinearSolver.h.

Referenced by NonlinearSolver::doAffineNewtonSolve().

bool s_alwaysAssumeNewtonGood
static

This toggle turns off the use of the Hessian when it is warranted by the condition number.

This is a debugging option.

Definition at line 1298 of file NonlinearSolver.h.

Referenced by NonlinearSolver::doAffineNewtonSolve().


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