24 #include "cantera/base/mdp_allo.h"
34 #ifndef CONSTD_DATA_PTR
35 #define CONSTD_DATA_PTR(x) (( const doublereal *) (&x[0]))
58 for (
int i = 0; i < n; i++) {
64 bool NonlinearSolver::s_TurnOffTiming(
false);
67 bool NonlinearSolver::s_print_NumJac(
true);
69 bool NonlinearSolver::s_print_NumJac(
false);
73 bool NonlinearSolver::s_print_DogLeg(
false);
79 bool NonlinearSolver::s_doBothSolvesAndCompare(
false);
85 bool NonlinearSolver::s_alwaysAssumeNewtonGood(
false);
97 m_manualDeltaStepSet(0),
98 m_deltaStepMinimum(0),
112 m_normResid_Bound(0.0),
114 m_normDeltaSoln_Newton(0.0),
115 m_normDeltaSoln_CP(0.0),
116 m_normResidTrial(0.0),
117 m_resid_scaled(false),
126 m_numTotalLinearSolves(0),
127 m_numTotalNewtIts(0),
130 m_jacFormMethod(NSOLN_JAC_NUM),
133 m_matrixConditioning(0),
140 userResidRtol_(1.0E-3),
141 checkUserResidualTols_(0),
143 m_ScaleSolnNormToResNorm(0.001),
148 residNorm2Cauchy_(0.0),
155 norm_deltaX_trust_(0.0),
157 trustRegionInitializationMethod_(2),
158 trustRegionInitializationFactor_(1.0),
165 normTrust_Newton_(0.0),
169 CurrentTrustFactor_(1.0),
170 NextTrustFactor_(1.0),
171 ResidWtsReevaluated_(false),
172 ResidDecreaseSDExp_(0.0),
173 ResidDecreaseSD_(0.0),
174 ResidDecreaseNewtExp_(0.0),
175 ResidDecreaseNewt_(0.0)
202 for (
size_t i = 0; i <
neq_; i++) {
210 Jd_.resize(neq_, 0.0);
216 m_func(right.m_func),
220 m_manualDeltaStepSet(0),
221 m_deltaStepMinimum(0),
236 m_normResid_Bound(0.0),
238 m_normDeltaSoln_Newton(0.0),
239 m_normDeltaSoln_CP(0.0),
240 m_normResidTrial(0.0),
241 m_resid_scaled(false),
250 m_numTotalLinearSolves(0),
251 m_numTotalNewtIts(0),
254 m_jacFormMethod(NSOLN_JAC_NUM),
257 m_matrixConditioning(0),
264 userResidRtol_(1.0E-3),
265 checkUserResidualTols_(0),
267 m_ScaleSolnNormToResNorm(0.001),
272 residNorm2Cauchy_(0.0),
279 norm_deltaX_trust_(0.0),
281 trustRegionInitializationMethod_(2),
282 trustRegionInitializationFactor_(1.0),
289 normTrust_Newton_(0.0),
293 CurrentTrustFactor_(1.0),
294 NextTrustFactor_(1.0),
295 ResidWtsReevaluated_(false),
296 ResidDecreaseSDExp_(0.0),
297 ResidDecreaseSD_(0.0),
298 ResidDecreaseNewtExp_(0.0),
299 ResidDecreaseNewt_(0.0)
317 if (
this == &right) {
432 for (
size_t i = 0; i <
neq_; i++) {
444 const doublereal*
const y_high_bounds)
446 for (
size_t i = 0; i <
neq_; i++) {
484 const doublereal dampFactor)
const
486 doublereal sum_norm = 0.0,
error;
487 for (
size_t i = 0; i <
neq_; i++) {
491 sum_norm = sqrt(sum_norm / neq_);
495 printf(
"\t\t solnErrorNorm(): ");
499 printf(
" Delta soln norm ");
501 printf(
" = %-11.4E\n", sum_norm);
503 const int num_entries = printLargest;
506 printf(
"\t\t solnErrorNorm(): ");
510 printf(
" Delta soln norm ");
512 printf(
" = %-11.4E\n", sum_norm);
514 doublereal dmax1, normContrib;
516 std::vector<size_t> imax(num_entries,
npos);
517 printf(
"\t\t Printout of Largest Contributors: (damp = %g)\n", dampFactor);
518 printf(
"\t\t I weightdeltaY/sqtN| deltaY "
519 "ysolnOld ysolnNew Soln_Weights\n");
523 for (
int jnum = 0; jnum < num_entries; jnum++) {
525 for (
size_t i = 0; i <
neq_; i++) {
527 for (j = 0; j < jnum; j++) {
535 if (normContrib > dmax1) {
541 size_t i = imax[jnum];
545 printf(
"\t\t %4s %12.4e | %12.4e %12.4e %12.4e %12.4e\n",
546 int2str(i).c_str(), normContrib/sqrt((
double)neq_), delta_y[i],
566 const doublereal*
const y)
const
568 doublereal sum_norm = 0.0,
error;
570 for (
size_t i = 0; i <
neq_; i++) {
580 sum_norm = sqrt(sum_norm / neq_);
585 const int num_entries = printLargest;
586 doublereal dmax1, normContrib;
588 std::vector<size_t> imax(num_entries,
npos);
591 printf(
"\t\t residErrorNorm():");
593 printf(
" %s ", title);
595 printf(
" residual L2 norm ");
597 printf(
"= %12.4E\n", sum_norm);
602 printf(
"\t\t residErrorNorm(): ");
604 printf(
" %s ", title);
606 printf(
" residual L2 norm ");
608 printf(
"= %12.4E\n", sum_norm);
609 printf(
"\t\t Printout of Largest Contributors to norm:\n");
610 printf(
"\t\t I |Resid/ResWt| UnsclRes ResWt | y_curr\n");
613 for (
int jnum = 0; jnum < num_entries; jnum++) {
615 for (
size_t i = 0; i <
neq_; i++) {
617 for (j = 0; j < jnum; j++) {
625 if (normContrib > dmax1) {
631 size_t i = imax[jnum];
635 printf(
"\t\t %4s %12.4e %12.4e %12.4e | %12.4e\n",
672 for (
size_t i = 0; i <
neq_; i++) {
675 throw CanteraError(
"NonlinearSolver::setColumnScaling() ERROR",
"Bad column scale factor");
705 for (
size_t i = 0; i <
neq_; i++) {
709 for (
size_t i = 0; i <
neq_; i++) {
746 doublereal time_curr,
int num_newt_its)
769 doublereal* jptr = &(*(jac.
begin()));
770 for (jcol = 0; jcol <
neq_; jcol++) {
771 for (irow = 0; irow <
neq_; irow++) {
777 int kl =
static_cast<int>(ivec[0]);
778 int ku =
static_cast<int>(ivec[1]);
779 for (
int jcol = 0; jcol < (int)
neq_; jcol++) {
780 colP_j = (doublereal*) jac.
ptrColumn(jcol);
781 for (
int irow = jcol - ku; irow <= jcol + kl; irow++) {
782 if (irow >= 0 && irow < (
int)
neq_) {
783 colP_j[kl + ku + irow - jcol] *=
m_colScales[jcol];
800 doublereal* jptr = &(*(jac.
begin()));
801 for (irow = 0; irow <
neq_; irow++) {
806 for (jcol = 0; jcol <
neq_; jcol++) {
807 for (irow = 0; irow <
neq_; irow++) {
822 int kl =
static_cast<int>(ivec[0]);
823 int ku =
static_cast<int>(ivec[1]);
824 for (
int jcol = 0; jcol < (int) neq_; jcol++) {
825 colP_j = (doublereal*) jac.
ptrColumn(jcol);
826 for (
int irow = jcol - ku; irow <= jcol + kl; irow++) {
827 if (irow >= 0 && irow < (
int) neq_) {
828 double vv = fabs(colP_j[kl + ku + irow - jcol]);
844 for (irow = 0; irow <
neq_; irow++) {
848 for (irow = 0; irow <
neq_; irow++) {
857 jptr = &(*(jac.
begin()));
858 for (jcol = 0; jcol <
neq_; jcol++) {
859 for (irow = 0; irow <
neq_; irow++) {
865 int kl =
static_cast<int>(ivec[0]);
866 int ku =
static_cast<int>(ivec[1]);
867 for (
int jcol = 0; jcol < (int) neq_; jcol++) {
868 colP_j = (doublereal*) jac.
ptrColumn(jcol);
869 for (
int irow = jcol - ku; irow <= jcol + kl; irow++) {
870 if (irow >= 0 && irow < (
int) neq_) {
871 colP_j[kl + ku + irow - jcol] *=
m_rowScales[irow];
878 if (num_newt_its % 5 == 1) {
897 doublereal sum = 0.0;
898 for (
size_t irow = 0; irow <
neq_; irow++) {
903 for (
size_t irow = 0; irow <
neq_; irow++) {
907 for (
size_t irow = 0; irow <
neq_; irow++) {
912 for (
size_t irow = 0; irow <
neq_; irow++) {
918 for (
size_t irow = 0; irow <
neq_; irow++) {
921 doublereal* jptr = &(
jacCopyPtr_->operator()(0,0));
922 for (
size_t jcol = 0; jcol <
neq_; jcol++) {
923 for (
size_t irow = 0; irow <
neq_; irow++) {
928 doublereal resNormOld = 0.0;
931 for (
size_t irow = 0; irow <
neq_; irow++) {
933 resNormOld += error *
error;
935 resNormOld = sqrt(resNormOld / neq_);
937 if (resNormOld > 0.0) {
947 throw CanteraError(
"NonlinearSolver::calcSolnToResNormVector()" ,
"Logic error");
965 const doublereal*
const ydot_curr, doublereal*
const delta_y,
970 for (
size_t n = 0; n <
neq_; n++) {
975 for (
size_t n = 0; n <
neq_; n++) {
990 for (
size_t irow = 0; irow <
neq_; irow++) {
996 if (printJacContributions) {
997 for (
size_t iNum = 0; iNum < numRows; iNum++) {
1001 doublereal dsum = 0.0;
1003 doublereal dRow = Jdata[
neq_ * focusRow + focusRow];
1004 printf(
"\n Details on delta_Y for row %d \n", focusRow);
1005 printf(
" Value before = %15.5e, delta = %15.5e,"
1006 "value after = %15.5e\n", y_curr[focusRow],
1007 delta_y[focusRow], y_curr[focusRow] + delta_y[focusRow]);
1009 printf(
" Old Jacobian\n");
1011 printf(
" col delta_y aij "
1013 printf(
"--------------------------------------------------"
1014 "---------------------------------------------\n");
1015 printf(
" Res(%d) %15.5e %15.5e %15.5e (Res = %g)\n",
1016 focusRow, delta_y[focusRow],
1017 dRow, RRow[iNum] / dRow, RRow[iNum]);
1018 dsum += RRow[iNum] / dRow;
1019 for (
size_t ii = 0; ii <
neq_; ii++) {
1020 if (ii != focusRow) {
1021 doublereal aij = Jdata[neq_ * ii + focusRow];
1022 doublereal contrib = aij * delta_y[ii] * (-1.0) / dRow;
1024 if (fabs(contrib) > Pcutoff) {
1025 printf(
"%6d %15.5e %15.5e %15.5e\n", ii,
1026 delta_y[ii] , aij, contrib);
1030 printf(
"--------------------------------------------------"
1031 "---------------------------------------------\n");
1032 printf(
" %15.5e %15.5e\n",
1033 delta_y[focusRow], dsum);
1059 bool newtonGood =
true;
1060 doublereal* delyNewton = 0;
1067 for (
size_t n = 0; n <
neq_; n++) {
1072 for (
size_t n = 0; n <
neq_; n++) {
1092 doublereal rcond = 0.0;
1096 doublereal a1norm = jac.
oneNorm();
1097 rcond = jac.
rcond(a1norm);
1106 printf(
"\t\t doAffineNewtonSolve: ");
1108 printf(
"factorQR()");
1112 printf(
" returned with info = %d, indicating a zero row or column\n", info);
1115 bool doHessian =
false;
1121 printf(
"\t\t doAffineNewtonSolve: Condition number = %g during regular solve\n",
m_conditionNumber);
1130 printf(
"\t\t doAffineNewtonSolve() ERROR: QRSolve returned INFO = %d. Switching to Hessian solve\n", info);
1139 for (
size_t irow = 0; irow <
neq_; irow++) {
1140 delta_y[irow] = delta_y[irow] *
m_colScales[irow];
1148 printf(
"\t\t doAffineNewtonSolve() WARNING: Condition number too large, %g, But Banded Hessian solve "
1155 printf(
"\t\t doAffineNewtonSolve() WARNING: Condition number too large, %g. Doing a Hessian solve \n",
m_conditionNumber);
1164 for (
size_t irow = 0; irow <
neq_; irow++) {
1165 delyNewton[irow] = delta_y[irow];
1180 for (
size_t i = 0; i <
neq_; i++) {
1181 for (
size_t j = i; j <
neq_; j++) {
1182 for (
size_t k = 0; k <
neq_; k++) {
1185 hessian(j,i) = hessian(i,j);
1189 for (
size_t i = 0; i <
neq_; i++) {
1190 for (
size_t j = i; j <
neq_; j++) {
1191 for (
size_t k = 0; k <
neq_; k++) {
1192 hessian(i,j) += jacCopy(k,i) * jacCopy(k,j);
1194 hessian(j,i) = hessian(i,j);
1202 doublereal hnorm = 0.0;
1203 doublereal hcol = 0.0;
1205 for (
size_t i = 0; i <
neq_; i++) {
1206 for (
size_t j = i; j <
neq_; j++) {
1209 for (
size_t j = i+1; j <
neq_; j++) {
1218 for (
size_t i = 0; i <
neq_; i++) {
1219 for (
size_t j = i; j <
neq_; j++) {
1220 hcol += fabs(hessian(j,i));
1222 for (
size_t j = i+1; j <
neq_; j++) {
1223 hcol += fabs(hessian(i,j));
1234 hcol = sqrt(1.0*neq_) * 1.0E-7 * hnorm;
1235 #ifdef DEBUG_HKM_NOT
1241 for (
size_t i = 0; i <
neq_; i++) {
1245 for (
size_t i = 0; i <
neq_; i++) {
1246 hessian(i,i) += hcol;
1257 printf(
"\t\t doAffineNewtonSolve() ERROR: Hessian isn't positive definate DPOTRF returned INFO = %d\n", info);
1266 for (
size_t n = 0; n <
neq_; n++) {
1270 for (
size_t n = 0; n <
neq_; n++) {
1276 for (
size_t j = 0; j <
neq_; j++) {
1278 for (
size_t i = 0; i <
neq_; i++) {
1279 delta_y[j] += delyH[i] * jacCopy(i,j) *
m_rowScales[i];
1283 for (
size_t j = 0; j <
neq_; j++) {
1285 for (
size_t i = 0; i <
neq_; i++) {
1286 delta_y[j] += delyH[i] * jacCopy(i,j);
1294 ct_dpotrs(ctlapack::UpperTriangular, neq_, 1,&(*(hessian.
begin())),
neq_, delta_y,
neq_, info);
1297 printf(
"\t\t NonlinearSolver::doAffineNewtonSolve() ERROR: DPOTRS returned INFO = %d\n", info);
1305 for (
size_t irow = 0; irow <
neq_; irow++) {
1306 delta_y[irow] = delta_y[irow] *
m_colScales[irow];
1312 double normNewt =
solnErrorNorm(CONSTD_DATA_PTR(delyNewton));
1314 printf(
"\t\t doAffineNewtonSolve(): Printout Comparison between Hessian deltaX and Newton deltaX\n");
1316 printf(
"\t\t I Hessian+Junk Newton");
1318 printf(
" (USING NEWTON DIRECTION)\n");
1320 printf(
" (USING HESSIAN DIRECTION)\n");
1322 printf(
"\t\t Norm: %12.4E %12.4E\n", normHess, normNewt);
1324 printf(
"\t\t --------------------------------------------------------\n");
1325 for (
size_t i =0; i <
neq_; i++) {
1326 printf(
"\t\t %3s %13.5E %13.5E\n",
1327 int2str(i).c_str(), delta_y[i], delyNewton[i]);
1329 printf(
"\t\t --------------------------------------------------------\n");
1331 double normNewt =
solnErrorNorm(CONSTD_DATA_PTR(delyNewton));
1333 printf(
"\t\t doAffineNewtonSolve(): Hessian update norm = %12.4E \n"
1334 "\t\t Newton update norm = %12.4E \n", normHess, normNewt);
1336 printf(
"\t\t (USING NEWTON DIRECTION)\n");
1338 printf(
"\t\t (USING HESSIAN DIRECTION)\n");
1353 if (printJacContributions) {
1354 for (
int iNum = 0; iNum < numRows; iNum++) {
1358 doublereal dsum = 0.0;
1360 doublereal dRow = Jdata[
neq_ * focusRow + focusRow];
1361 printf(
"\n Details on delta_Y for row %d \n", focusRow);
1362 printf(
" Value before = %15.5e, delta = %15.5e,"
1363 "value after = %15.5e\n", y_curr[focusRow],
1364 delta_y[focusRow], y_curr[focusRow] + delta_y[focusRow]);
1366 printf(
" Old Jacobian\n");
1368 printf(
" col delta_y aij "
1370 printf(
"-----------------------------------------------------------------------------------------------\n");
1371 printf(
" Res(%d) %15.5e %15.5e %15.5e (Res = %g)\n",
1372 focusRow, delta_y[focusRow],
1373 dRow, RRow[iNum] / dRow, RRow[iNum]);
1374 dsum += RRow[iNum] / dRow;
1375 for (
int ii = 0; ii <
neq_; ii++) {
1376 if (ii != focusRow) {
1377 doublereal aij = Jdata[neq_ * ii + focusRow];
1378 doublereal contrib = aij * delta_y[ii] * (-1.0) / dRow;
1380 if (fabs(contrib) > Pcutoff) {
1381 printf(
"%6d %15.5e %15.5e %15.5e\n", ii,
1382 delta_y[ii] , aij, contrib);
1386 printf(
"-----------------------------------------------------------------------------------------------\n");
1387 printf(
" %15.5e %15.5e\n",
1388 delta_y[focusRow], dsum);
1406 doublereal rowFac = 1.0;
1407 doublereal colFac = 1.0;
1408 doublereal normSoln;
1419 for (
size_t j = 0; j <
neq_; j++) {
1424 for (
size_t i = 0; i <
neq_; i++) {
1439 for (
size_t i = 0; i <
neq_; i++) {
1446 for (
size_t j = 0; j <
neq_; j++) {
1460 for (
size_t i = 0; i <
neq_; i++) {
1471 throw CanteraError(
"NonlinearSolver::doCauchyPointSolve()",
"Unexpected condition: norms are zero");
1482 for (
size_t i = 0; i <
neq_; i++) {
1502 doublereal residCauchy = 0.0;
1519 printf(
"\t\t doCauchyPointSolve: Steepest descent to Cauchy point: \n");
1521 printf(
"\t\t\t Rpred = %g\n", residCauchy);
1524 printf(
"\t\t\t deltaX = %g\n", normSoln);
1536 doublereal ff = 1.0E-5;
1537 doublereal ffNewt = 1.0E-5;
1540 if (cauchyDistanceNorm < 1.0E-2) {
1541 ff = 1.0E-9 / cauchyDistanceNorm;
1546 for (
size_t i = 0; i <
neq_; i++) {
1561 doublereal residSteep2 = residSteep * residSteep *
neq_;
1562 doublereal funcDecreaseSD = 0.5 * (residSteep2 - normResid02) / (ff * cauchyDistanceNorm);
1566 ffNewt = ffNewt / sNewt;
1568 for (
size_t i = 0; i <
neq_; i++) {
1584 doublereal residNewt2 = residNewt * residNewt *
neq_;
1586 doublereal funcDecreaseNewt2 = 0.5 * (residNewt2 - normResid02) / (ffNewt * sNewt);
1592 doublereal funcDecreaseNewtExp2 = - normResid02 / sNewt;
1618 printf(
"\t\t descentComparison: initial rate of decrease of func in cauchy dir (expected) = %g\n", funcDecreaseSDExp);
1619 printf(
"\t\t descentComparison: initial rate of decrease of func in cauchy dir = %g\n", funcDecreaseSD);
1620 printf(
"\t\t descentComparison: initial rate of decrease of func in newton dir (expected) = %g\n", funcDecreaseNewtExp2);
1621 printf(
"\t\t descentComparison: initial rate of decrease of func in newton dir = %g\n", funcDecreaseNewt2);
1624 printf(
"\t\t descentComparison: initial rate of decrease of Resid in cauchy dir (expected) = %g\n",
ResidDecreaseSDExp_);
1625 printf(
"\t\t descentComparison: initial rate of decrease of Resid in cauchy dir = %g\n",
ResidDecreaseSD_);
1626 printf(
"\t\t descentComparison: initial rate of decrease of Resid in newton dir (expected) = %g\n",
ResidDecreaseNewtExp_);
1627 printf(
"\t\t descentComparison: initial rate of decrease of Resid in newton dir = %g\n",
ResidDecreaseNewt_);
1631 if (funcDecreaseNewt2 >= 0.0) {
1632 printf(
"\t\t %13.5E %22.16E\n", funcDecreaseNewtExp2,
m_normResid_0);
1633 double ff = ffNewt * 1.0E-5;
1634 for (
int ii = 0; ii < 13; ii++) {
1639 for (
size_t i = 0; i <
neq_; i++) {
1649 residNewt2 = residNewt * residNewt *
neq_;
1650 funcDecreaseNewt2 = 0.5 * (residNewt2 - normResid02) / (ff * sNewt);
1651 printf(
"\t\t %10.3E %13.5E %22.16E\n", ff, funcDecreaseNewt2, residNewt);
1700 doublereal Nres2CP = residSteepLin * residSteepLin *
neq_;
1702 doublereal a = Nres2CP / Nres2_o;
1703 doublereal betaEqual = (2.0 - sqrt(4.0 - 4 * (1.0 - a))) / 2.0;
1704 doublereal beta = (1.0 + betaEqual) / 2.0;
1710 for (
size_t i = 0; i <
neq_; i++) {
1757 doublereal resD2, res2, resNorm;
1767 doublereal tmp = - 2.0 * alpha + alpha * alpha;
1771 }
else if (leg == 1) {
1777 doublereal RdotJS = - tmp2;
1778 doublereal JsJs = tmp2;
1783 res2 = res0_2 + (1.0 - alpha) * 2 * RdotJS - 2 * alpha *
Nuu_ * res0_2
1784 + (1.0 - alpha) * (1.0 - alpha) * JsJs
1785 + alpha * alpha *
Nuu_ *
Nuu_ * res0_2
1786 - 2 * alpha *
Nuu_ * (1.0 - alpha) * RdotJS;
1788 resNorm = sqrt(res2 / neq_);
1792 doublereal beta =
Nuu_ + alpha * (1.0 -
Nuu_);
1793 doublereal tmp2 = normResid02;
1794 doublereal tmp = 1.0 - 2.0 * beta + 1.0 * beta * beta - 1.0;
1802 resNorm = sqrt(res2 / neq_);
1819 doublereal& alphaBest)
const
1824 doublereal alpha = 0;
1826 doublereal residSteepBest = 1.0E300;
1827 doublereal residSteepLinBest = 0.0;
1829 printf(
"\t\t residualComparisonLeg() \n");
1830 printf(
"\t\t Point StepLen Residual_Actual Residual_Linear RelativeMatch\n");
1833 std::vector<doublereal> alphaT;
1834 alphaT.push_back(0.00);
1835 alphaT.push_back(0.01);
1836 alphaT.push_back(0.1);
1837 alphaT.push_back(0.25);
1838 alphaT.push_back(0.50);
1839 alphaT.push_back(0.75);
1840 alphaT.push_back(1.0);
1841 for (
size_t iteration = 0; iteration < alphaT.size(); iteration++) {
1842 alpha = alphaT[iteration];
1843 for (
size_t i = 0; i <
neq_; i++) {
1863 if (residSteep < residSteepBest) {
1866 residSteepBest = residSteep;
1867 residSteepLinBest = residSteepLin;
1870 doublereal relFit = (residSteep - residSteepLin) / (fabs(residSteepLin) + 1.0E-10);
1872 printf(
"\t\t (%2d - % 10.3g) % 15.8E % 15.8E % 15.8E % 15.8E\n", 0, alpha, sLen, residSteep, residSteepLin , relFit);
1876 for (
size_t iteration = 0; iteration < alphaT.size(); iteration++) {
1877 doublereal alpha = alphaT[iteration];
1878 for (
size_t i = 0; i <
neq_; i++) {
1895 for (
size_t i = 0; i <
neq_; i++) {
1902 if (residSteep < residSteepBest) {
1905 residSteepBest = residSteep;
1906 residSteepLinBest = residSteepLin;
1909 doublereal relFit = (residSteep - residSteepLin) / (fabs(residSteepLin) + 1.0E-10);
1911 printf(
"\t\t (%2d - % 10.3g) % 15.8E % 15.8E % 15.8E % 15.8E\n", 1, alpha, sLen, residSteep, residSteepLin , relFit);
1915 for (
size_t iteration = 0; iteration < alphaT.size(); iteration++) {
1916 doublereal alpha = alphaT[iteration];
1917 for (
size_t i = 0; i <
neq_; i++) {
1938 if (residSteep < residSteepBest) {
1941 residSteepBest = residSteep;
1942 residSteepLinBest = residSteepLin;
1944 doublereal relFit = (residSteep - residSteepLin) / (fabs(residSteepLin) + 1.0E-10);
1946 printf(
"\t\t (%2d - % 10.3g) % 15.8E % 15.8E % 15.8E % 15.8E\n", 2, alpha, sLen, residSteep, residSteepLin , relFit);
1950 printf(
"\t\t Best Result: \n");
1951 doublereal relFit = (residSteepBest - residSteepLinBest) / (fabs(residSteepLinBest) + 1.0E-10);
1953 printf(
"\t\t Leg %2d alpha %5g: NonlinResid = %g LinResid = %g, relfit = %g\n",
1954 legBest, alphaBest, residSteepBest, residSteepLinBest, relFit);
1958 }
else if (legBest == 1) {
1959 for (
size_t i = 0; i <
neq_; i++) {
1967 printf(
"\t\t (%2d - % 10.3g) % 15.8E % 15.8E % 15.8E % 15.8E\n", legBest, alphaBest, sLen,
1968 residSteepBest, residSteepLinBest , relFit);
1987 for (
size_t i = 0; i <
neq_; i++) {
1995 for (
size_t i = 0; i <
neq_; i++) {
2006 for (
size_t i = 0; i <
neq_; i++) {
2033 size_t i_fbounds = 0;
2036 doublereal UPFAC = 2.0;
2038 doublereal sameSign = 0.0;
2040 doublereal f_delta_bounds = 1.0;
2042 for (
size_t i = 0; i <
neq_; i++) {
2043 doublereal y_new = y_n_curr[i] + step_1[i];
2044 sameSign = y_new * y_n_curr[i];
2054 if (sameSign >= 0.0) {
2055 if ((fabs(y_new) > UPFAC * fabs(y_n_curr[i])) &&
2057 ff = (UPFAC - 1.0) * fabs(y_n_curr[i]/(y_new - y_n_curr[i]));
2062 if ((fabs(2.0 * y_new) < fabs(y_n_curr[i])) &&
2064 ff = y_n_curr[i]/(y_new - y_n_curr[i]) * (1.0 - 2.0)/2.0;
2075 ff = y_n_curr[i]/(y_new - y_n_curr[i]) * (1.0 - 2.0)/2.0;
2078 if (y_n_curr[i] >= 0.0) {
2087 else if (fabs(y_new) > 0.5 * fabs(y_n_curr[i])) {
2088 ff = y_n_curr[i]/(y_new - y_n_curr[i]) * (-1.5);
2095 if (ff < f_delta_bounds) {
2096 f_delta_bounds = ff;
2109 if (f_delta_bounds < 1.0) {
2111 printf(
"\t\tdeltaBoundStep: Increase of Variable %s causing "
2112 "delta damping of %g: origVal = %10.3g, undampedNew = %10.3g, dampedNew = %10.3g\n",
2113 int2str(i_fbounds).c_str(), f_delta_bounds, y_n_curr[i_fbounds], y_n_curr[i_fbounds] + step_1[i_fbounds],
2114 y_n_curr[i_fbounds] + f_delta_bounds * step_1[i_fbounds]);
2116 printf(
"\t\tdeltaBoundStep: Decrease of variable %s causing"
2117 "delta damping of %g: origVal = %10.3g, undampedNew = %10.3g, dampedNew = %10.3g\n",
2118 int2str(i_fbounds).c_str(), f_delta_bounds, y_n_curr[i_fbounds], y_n_curr[i_fbounds] + step_1[i_fbounds],
2119 y_n_curr[i_fbounds] + f_delta_bounds * step_1[i_fbounds]);
2125 return f_delta_bounds;
2137 doublereal wtSum = 0.0;
2138 for (
size_t i = 0; i <
neq_; i++) {
2143 doublereal deltaXSizeOld = trustNorm;
2144 doublereal trustNormGoal = trustNorm *
trustDelta_;
2151 for (
size_t i = 0; i <
neq_; i++) {
2157 doublereal newValue = trustNormGoal *
m_ewt[i];
2158 if (newValue > 0.5 * fabsy) {
2165 if (newValue > 4.0 * oldVal) {
2166 newValue = 4.0 * oldVal;
2167 }
else if (newValue < 0.25 * oldVal) {
2168 newValue = 0.25 * oldVal;
2183 doublereal sum = trustNormGoal / trustNorm;
2184 for (
size_t i = 0; i <
neq_; i++) {
2191 printf(
"\t\t reajustTrustVector(): Trust size = %11.3E: Old deltaX size = %11.3E trustDelta_ = %11.3E\n"
2192 "\t\t new deltaX size = %11.3E trustdelta_ = %11.3E\n",
2207 for (
size_t i = 0; i <
neq_; i++) {
2213 for (
size_t i = 0; i <
neq_; i++) {
2218 printf(
"\t\t initializeTrustRegion(): Relative Distance of Cauchy Vector wrt Trust Vector = %g\n", cpd);
2224 printf(
"\t\t initializeTrustRegion(): Relative Distance of Cauchy Vector wrt Trust Vector = %g\n", cpd);
2228 for (
size_t i = 0; i <
neq_; i++) {
2233 printf(
"\t\t initializeTrustRegion(): Relative Distance of Newton Vector wrt Trust Vector = %g\n", cpd);
2239 printf(
"\t\t initializeTrustRegion(): Relative Distance of Newton Vector wrt Trust Vector = %g\n", cpd);
2257 for (
size_t i = 0; i <
neq_; i++) {
2260 }
else if (leg == 2) {
2261 for (
size_t i = 0; i <
neq_; i++) {
2265 for (
size_t i = 0; i <
neq_; i++) {
2282 doublereal sum = 0.0;
2283 doublereal tmp = 0.0;
2284 for (
size_t i = 0; i <
neq_; i++) {
2322 doublereal sumv = 0.0;
2323 for (
size_t i = 0; i <
neq_; i++) {
2328 doublereal b = 2.0 * Nuu_ * sumv;
2331 alpha =(-b + sqrt(b * b - 4.0 * a * c)) / (2.0 * a);
2368 size_t i_lower =
npos;
2369 doublereal fbound = 1.0, f_bounds = 1.0;
2370 doublereal ff, y_new;
2372 for (
size_t i = 0; i <
neq_; i++) {
2373 y_new = y[i] + step0[i];
2377 if (step0[i] < 0.0) {
2380 ff = legalDelta / step0[i];
2381 if (ff < f_bounds) {
2390 if (step0[i] > 0.0) {
2393 ff = legalDelta / step0[i];
2394 if (ff < f_bounds) {
2407 if (f_bounds != 1.0) {
2408 printf(
"\t\tboundStep: Variable %s causing bounds damping of %g\n",
2409 int2str(i_lower).c_str(), f_bounds);
2414 fbound =
std::min(f_bounds, f_delta_bounds);
2443 const doublereal*
const ydot_n_curr, doublereal*
const step_1,
2444 doublereal*
const y_n_1, doublereal*
const ydot_n_1, doublereal*
const step_2,
2445 doublereal& stepNorm_2,
GeneralMatrix& jac,
bool writetitle,
int& num_backtracks)
2454 for (
size_t j = 0; j <
neq_; j++) {
2455 step_1_orig[j] = step_1[j];
2468 printf(
"\t\t\tdampStep(): At limits.\n");
2482 for (m = 0; m <
NDAMP; m++) {
2491 for (
size_t j = 0; j <
neq_; j++) {
2492 step_1[j] = ff * step_1_orig[j];
2493 y_n_1[j] = y_n_curr[j] + step_1[j];
2510 printf(
"\t\t\tdampStep(): current trial step and damping led to Residual Calc ERROR %d. Bailing\n", info);
2525 printf(
"\t dampStep(): Current trial step and damping"
2526 " coefficient accepted because residTrial test step < 1:\n");
2528 }
else if (steepEnough) {
2529 printf(
"\t dampStep(): Current trial step and damping"
2530 " coefficient accepted because resid0 > residTrial and steep enough:\n");
2533 printf(
"\t dampStep(): Current trial step and damping"
2534 " coefficient accepted because residual solution damping is turned off:\n");
2558 info =
doNewtonSolve(time_curr, y_n_1, ydot_n_1, step_2, jac);
2560 info =
doNewtonSolve(time_curr, y_n_1, ydot_n_curr, step_2, jac);
2564 printf(
"\t\t\tdampStep: current trial step and damping led to LAPACK ERROR %d. Bailing\n", info);
2575 (
const doublereal*) step_2,
"DeltaSolnTrial",
2576 "dampNewt: Important Entries for Weighted Soln Updates:",
2577 y_n_curr, y_n_1, ff, 5);
2580 printf(
"\t\t\tdampStep(): s1 = %g, s2 = %g, dampBound = %g,"
2581 "dampRes = %g\n", stepNorm_1, stepNorm_2,
m_dampBound, m_dampRes);
2590 if (stepNorm_2 < 0.8 || stepNorm_2 < stepNorm_1) {
2591 if (stepNorm_2 < 1.0) {
2593 if (stepNorm_2 < 1.0) {
2594 printf(
"\t\t\tdampStep: current trial step and damping coefficient accepted because test step < 1\n");
2595 printf(
"\t\t\t s2 = %g, s1 = %g\n", stepNorm_2, stepNorm_1);
2605 printf(
"\t\t\tdampStep: current step rejected: (s1 = %g > "
2606 "s0 = %g)", stepNorm_2, stepNorm_1);
2607 if (m < (NDAMP-1)) {
2608 printf(
" Decreasing damping factor and retrying");
2610 printf(
" Giving up!!!");
2625 printf(
"\t dampStep(): current trial step accepted retnTrial = %d, its = %d, damp = %g\n", retnTrial, m+1, ff);
2629 if (stepNorm_2 < 0.5 && (stepNorm_1 < 0.5)) {
2631 printf(
"\t dampStep(): current trial step accepted kindof retnTrial = %d, its = %d, damp = %g\n", 2, m+1, ff);
2635 if (stepNorm_2 < 1.0) {
2637 printf(
"\t dampStep(): current trial step accepted and soln converged retnTrial ="
2638 "%d, its = %d, damp = %g\n", 0, m+1, ff);
2644 printf(
"\t dampStep(): current direction is rejected! retnTrial = %d, its = %d, damp = %g\n",
2675 const doublereal* ydot_n_curr, std::vector<doublereal> & step_1,
2676 doublereal*
const y_n_1, doublereal*
const ydot_n_1,
2677 doublereal& stepNorm_1, doublereal& stepNorm_2,
GeneralMatrix& jac,
int& numTrials)
2682 bool success =
false;
2683 bool haveASuccess =
false;
2696 for (m = 0; m <
NDAMP; m++) {
2704 printf(
"\t\t dampDogLeg: trust region with length %13.5E has intersection at leg = %d, alpha = %g, lambda = %g\n",
2721 for (
size_t j = 0; j <
neq_; j++) {
2728 for (
size_t j = 0; j <
neq_; j++) {
2729 y_n_1[j] = y_n_curr[j] + step_1[j];
2742 y_n_1, ydot_n_1, trustDeltaOld);
2752 printf(
"\t\t dampDogLeg: Current direction rejected, update became too small %g\n", stepNorm);
2759 printf(
"\t\t dampDogLeg: current trial step and damping led to LAPACK ERROR %d. Bailing\n", info);
2770 haveASuccess =
true;
2784 for (
size_t j = 0; j <
neq_; j++) {
2785 y_n_1[j] = y_n_curr[j] + step_1[j];
2802 stepNorm_2 = stepNorm_1;
2806 stepNorm_2 /= lambda;
2851 const doublereal*
const y_n_curr,
2852 const doublereal*
const ydot_n_curr,
const std::vector<doublereal> & step_1,
2853 const doublereal*
const y_n_1,
const doublereal*
const ydot_n_1,
2854 doublereal trustDeltaOld)
2871 if (funcDecreaseSDExp > 0.0) {
2873 printf(
"\t\tdecideStep(): Unexpected condition -> cauchy slope is positive\n");
2892 printf(
"\t\tdecideStep: current trial step and damping led to Residual Calc ERROR %d. Bailing\n", info);
2907 doublereal funcDecrease = 0.5 * (normResidTrial_2 - normResid0_2);
2908 doublereal acceptableDelF = funcDecreaseSDExp * stepNorm * 1.0E-4;
2909 if (funcDecrease < acceptableDelF) {
2914 printf(
"\t\t decideStep: Norm Residual(leg=%1d, alpha=%10.2E) = %11.4E passes\n",
2919 printf(
"\t\t decideStep: Norm Residual(leg=%1d, alpha=%10.2E) = %11.4E failes\n",
2926 if (
rtol_ * stepNorm < 1.0E-6) {
2949 doublereal expectedFuncDecrease = 0.5 * (neq_ * expectedNormRes * expectedNormRes - normResid0_2);
2950 if (funcDecrease > 0.1 * expectedFuncDecrease) {
2951 if ((m_normResidTrial > 0.5 *
m_normResid_0) && (m_normResidTrial > 0.1)) {
2956 printf(
"\t\t decideStep: Trust region decreased from %g to %g due to bad quad approximation\n",
2964 if (funcDecrease < 0.8 * expectedFuncDecrease || (m_normResidTrial < 0.33 *
m_normResid_0)) {
2965 if (
trustDelta_ <= trustDeltaOld && (leg != 2 || alpha < 0.75)) {
2972 printf(
"\t\t decideStep: Redo line search with trust region increased from %g to %g due to good nonlinear behavior\n",
2975 printf(
"\t\t decideStep: Redi line search with trust region increased from %g to %g due to good linear model approximation\n",
2984 if (m_normResidTrial < 0.99 * expectedNormRes || (m_normResidTrial < 0.20 *
m_normResid_0) ||
2985 (funcDecrease < -1.0E-50 && (funcDecrease < 0.9 *expectedFuncDecrease))) {
2986 if (leg == 2 && alpha == 1.0) {
2994 printf(
"\t\t decideStep: Trust region further increased from %g to %g next step due to good linear model behavior\n",
3005 printf(
"\t\t decideStep: Trust region further increased from %g to %g next step due to good linear model behavior\n",
3033 int& num_newt_its,
int& num_linear_solves,
3034 int& num_backtracks,
int loglevelInput)
3044 bool forceNewJac =
false;
3051 doublereal stepNorm_1;
3052 doublereal stepNorm_2;
3055 doublereal alphaBest;
3057 bool trInit =
false;
3086 printf(
"\tsolve_nonlinear_problem():\n\n");
3088 printf(
"\tWt Iter Resid NewJac log(CN)| dRdS_CDexp dRdS_CD dRdS_Newtexp dRdS_Newt |"
3089 "DS_Cauchy DS_Newton DS_Trust | legID legAlpha Fbound | CTF NTF | nTr|"
3090 "DS_Final ResidLag ResidFull\n");
3091 printf(
"\t---------------------------------------------------------------------------------------------------"
3092 "--------------------------------------------------------------------------------\n");
3094 printf(
"\t Wt Iter Resid NewJac | Fbound ResidBound | DampIts Fdamp DS_Step1 DS_Step2"
3095 "ResidLag | DS_Damp DS_Newton ResidFull\n");
3096 printf(
"\t--------------------------------------------------------------------------------------------------"
3097 "----------------------------------\n");
3117 printf(
"\tsolve_nonlinear_problem(): iteration %d:\n",
3136 if ((num_newt_its % 5) == 1) {
3163 printf(
"\t solve_nonlinear_problem(): Getting a new Jacobian\n");
3169 printf(
"\t solve_nonlinear_problem(): Jacobian Formation Error: %d Bailing\n", info);
3176 printf(
"\t solve_nonlinear_problem(): Solving system with old jacobian\n");
3189 printf(
"\t solve_nonlinear_problem(): Calculate the base residual\n");
3194 printf(
"\t solve_nonlinear_problem(): Residual Calc ERROR %d. Bailing\n", info);
3215 printf(
"\t solve_nonlinear_problem(): Initial Residual Norm = %13.4E\n",
m_normResid_0);
3222 printf(
"\t solve_nonlinear_problem(): Calculate the steepest descent direction and Cauchy Point\n");
3229 printf(
"\t solve_nonlinear_problem(): Calculate the steepest descent direction and Cauchy Point\n");
3238 printf(
"\t solve_nonlinear_problem(): Calculate the Newton direction via an Affine solve\n");
3243 printf(
"\t solve_nonlinear_problem(): Calculate the Newton direction via a Newton solve\n");
3251 printf(
"\t solve_nonlinear_problem(): Matrix Inversion Error: %d Bailing\n", info);
3267 printf(
"\t solve_nonlinear_problem(): Initialize the trust region size as the length of the Cauchy Vector times %f\n",
3270 printf(
"\t solve_nonlinear_problem(): Initialize the trust region size as the length of the Newton Vector times %f\n",
3288 printf(
"\t\t Newton's method step size, %g trustVectorUnits, larger than trust region, %g trustVectorUnits\n",
3290 printf(
"\t\t Newton's method step size, %g trustVectorUnits, larger than trust region, %g trustVectorUnits\n",
3293 printf(
"\t\t Newton's method step size, %g trustVectorUnits, smaller than trust region, %g trustVectorUnits\n",
3308 printf(
"\t solve_nonlinear_problem(): Compare descent rates for Cauchy and Newton directions\n");
3322 printf(
"\t solve_nonlinear_problem(): Compare Linear and nonlinear residuals along double dog-leg path\n");
3327 printf(
"\t solve_nonlinear_problem(): Calculate damping along dog-leg path to ensure residual decrease\n");
3335 printf(
"\t solve_nonlinear_problem(): Compare Linear and nonlinear residuals along double dog-leg path\n");
3356 num_backtracks += i_numTrials;
3367 printf(
"\t solve_nonlinear_problem(): Damped Newton successful (m=%d) but minimum newton"
3368 "iterations not attained. Resolving ...\n", retnDamp);
3380 printf(
"\t solve_nonlinear_problem(): Damped newton unsuccessful (max newts exceeded) sfinal = %g\n",
3392 printf(
"\t solve_nonlinear_problem(): current trial step and damping led to Residual Calc "
3393 "ERROR %d. Bailing\n", info);
3402 printf(
"\t solve_nonlinear_problem(): Full residual norm changed from %g to %g due to "
3421 bool m_filterIntermediate =
false;
3422 if (m_filterIntermediate) {
3445 bool m_jacAge =
false;
3459 printf(
" %2d ", i_numTrials);
3464 printf(
"%2d %10.2E %10.3E %10.3E %10.3E", i_numTrials + 1,
m_dampRes,
3474 printf(
"\t solve_nonlinear_problem(): Problem Converged, stepNorm = %11.3E, reduction of res from %11.3E to %11.3E\n",
3479 printf(
"\t solve_nonlinear_problem(): Successfull step taken with stepNorm = %11.3E, reduction of res from %11.3E to %11.3E\n",
3484 printf(
"\t solve_nonlinear_problem(): Damped Newton iteration successful, nonlin "
3485 "converged, final estimate of the next solution update norm = %-12.4E\n", stepNorm_2);
3489 printf(
"\t solve_nonlinear_problem(): Damped Newton iteration successful, "
3490 "estimate of the next solution update norm = %-12.4E\n", stepNorm_2);
3492 printf(
"\t solve_nonlinear_problem(): Damped Newton unsuccessful, final estimate "
3493 "of the next solution update norm = %-12.4E\n", stepNorm_2);
3518 " | | converged = 3 |(%11.3E) \n", stepNorm_2);
3521 " | | converged = %1d | %10.3E %10.3E\n", convRes,
3524 printf(
"\t-----------------------------------------------------------------------------------------------------"
3525 "------------------------------------------------------------------------------\n");
3529 " | converged = 3 | (%11.3E) \n", stepNorm_2);
3532 " | converged = %1d | %10.3E %10.3E\n", convRes,
3535 printf(
"\t------------------------------------------------------------------------------------"
3536 "-----------------------------------------------\n");
3551 doublereal time_elapsed = wc.
secondsWC();
3555 printf(
"\tNonlinear problem solved successfully in %d its\n",
3558 printf(
"\tNonlinear problem solved successfully in %d its, time elapsed = %g sec\n",
3559 num_newt_its, time_elapsed);
3562 printf(
"\tNonlinear problem failed to solve after %d its\n", num_newt_its);
3565 retnCode = retnDamp;
3590 const char*
const stepNorm_1,
3591 const doublereal*
const step_2,
3592 const char*
const stepNorm_2,
3593 const char*
const title,
3594 const doublereal*
const y_n_curr,
3595 const doublereal*
const y_n_1,
3600 doublereal dmax0, dmax1,
error, rel_norm;
3601 printf(
"\t\t%s currentDamp = %g\n", title, damp);
3602 printf(
"\t\t I ysolnOld %13s ysolnNewRaw | ysolnNewTrial "
3603 "%10s ysolnNewTrialRaw | solnWeight wtDelSoln wtDelSolnTrial\n", stepNorm_1, stepNorm_2);
3604 std::vector<size_t> imax(num_entries,
npos);
3607 for (
size_t jnum = 0; jnum < num_entries; jnum++) {
3609 for (
size_t i = 0; i <
neq_; i++) {
3611 for (
size_t j = 0; j < jnum; j++) {
3617 error = step_1[i] /
m_ewt[i];
3618 rel_norm = sqrt(error * error);
3619 error = step_2[i] /
m_ewt[i];
3620 rel_norm += sqrt(error * error);
3621 if (rel_norm > dmax1) {
3627 if (imax[jnum] !=
npos) {
3628 size_t i = imax[jnum];
3629 error = step_1[i] /
m_ewt[i];
3630 dmax0 = sqrt(error * error);
3631 error = step_2[i] /
m_ewt[i];
3632 dmax1 = sqrt(error * error);
3633 printf(
"\t\t %4s %12.4e %12.4e %12.4e | %12.4e %12.4e %12.4e |%12.4e %12.4e %12.4e\n",
3634 int2str(i).c_str(), y_n_curr[i], step_1[i], y_n_curr[i] + step_1[i], y_n_1[i],
3635 step_2[i], y_n_1[i]+ step_2[i],
m_ewt[i], dmax0, dmax1);
3661 static inline doublereal
subtractRD(doublereal a, doublereal b)
3663 doublereal diff = a - b;
3664 doublereal d =
std::min(fabs(a), fabs(b));
3666 doublereal ad = fabs(diff);
3667 if (ad < 1.0E-300) {
3691 doublereal time_curr, doublereal CJ,
3692 doublereal*
const y, doublereal*
const ydot,
3697 doublereal ysave, ydotsave, dy;
3741 printf(
"\t\tbeuler_jac ERROR: calcDeltaSolnVariables() returned an error condition.\n");
3742 printf(
"\t\t We will bail after calculating the Jacobian\n");
3745 printf(
"\t\tUnk m_ewt y dyVector ResN\n");
3746 for (
size_t iii = 0; iii <
neq_; iii++) {
3747 printf(
"\t\t %4s %16.8e %16.8e %16.8e %16.8e \n",
3748 int2str(iii).c_str(),
m_ewt[iii], y[iii], dyVector[iii], f[iii]);
3765 for (
size_t j = 0; j <
neq_; j++) {
3791 static_cast<int>(j), dy);
3799 for (
size_t i = 0; i <
neq_; i++) {
3801 col_j[i] = diff / dy;
3820 printf(
"we have probs\n");
3838 printf(
"\t\tbeuler_jac ERROR: calcDeltaSolnVariables() returned an error condition.\n");
3839 printf(
"\t\t We will bail after calculating the Jacobian\n");
3842 printf(
"\t\tUnk m_ewt y dyVector ResN\n");
3843 for (
size_t iii = 0; iii <
neq_; iii++) {
3844 printf(
"\t\t %4s %16.8e %16.8e %16.8e %16.8e \n",
3845 int2str(iii).c_str(),
m_ewt[iii], y[iii], dyVector[iii], f[iii]);
3852 for (
size_t j = 0; j <
neq_; j++) {
3869 static_cast<int>(j), dy);
3878 int ileft = (int) j - (
int) ku;
3879 int iright =
static_cast<int>(j + kl);
3880 for (
int i = ileft; i <= iright; i++) {
3881 if (i >= 0 && i < (
int)
neq_) {
3883 size_t index = (int) kl + (
int) ku + i - (int) j;
3885 col_j[index] = diff / dy;
3906 if (vSmall < 1.0E-100) {
3907 printf(
"WE have a zero row, %s\n",
int2str(ismall).c_str());
3911 if (vSmall < 1.0E-100) {
3912 printf(
"WE have a zero column, %s\n",
int2str(ismall).c_str());
3922 printf(
"\t\tCurrent Matrix and Residual:\n");
3923 printf(
"\t\t I,J | ");
3924 for (
size_t j = 0; j <
neq_; j++) {
3925 printf(
" %5s ",
int2str(j).c_str());
3927 printf(
"| Residual \n");
3929 for (
size_t j = 0; j <
neq_; j++) {
3930 printf(
"------------");
3932 printf(
"| -----------\n");
3935 for (
size_t i = 0; i <
neq_; i++) {
3936 printf(
"\t\t %4s |",
int2str(i).c_str());
3937 for (
size_t j = 0; j <
neq_; j++) {
3938 printf(
" % 11.4E", J(i,j));
3940 printf(
" | % 11.4E\n", f[i]);
3944 for (
size_t j = 0; j <
neq_; j++) {
3945 printf(
"------------");
3947 printf(
"--------------\n");
3969 calc_ydot(
const int order,
const doublereal*
const y_curr, doublereal*
const ydot_curr)
const
3979 for (
size_t i = 0; i <
neq_; i++) {
3980 ydot_curr[i] = c1 * (y_curr[i] -
m_y_nm1[i]);
3985 for (
size_t i = 0; i <
neq_; i++) {
4004 const doublereal*
const ybase, doublereal*
const step0)
4019 doublereal*
const y_current, doublereal*
const ydot_current)
4042 for (
size_t i = 0; i <
neq_; i++) {
4046 doublereal sum = 0.0;
4047 for (
size_t i = 0; i <
neq_; i++) {
4052 for (
size_t i = 0; i <
neq_; i++) {
4056 for (
size_t i = 0; i <
neq_; i++) {
4071 for (
size_t i = 0; i <
neq_; i++) {
4099 if (dampCode <= 0) {
4102 if (dampCode == 3) {
4114 if (dampCode == 4) {
4127 if (dampCode == 1 || dampCode == 2) {
4145 for (
size_t i = 0; i <
neq_; i++) {
4176 if (residNormHandling < 0 || residNormHandling > 2) {
4177 throw CanteraError(
"NonlinearSolver::setResidualTols()",
4178 "Unknown int for residNormHandling");
4184 for (
size_t i = 0; i <
neq_; i++) {
4188 if (residNormHandling ==1 || residNormHandling == 2) {
4189 throw CanteraError(
"NonlinearSolver::setResidualTols()",
4190 "Must set residATol vector");