47 #include <Xyce_config.h>
51 #include <N_UTL_Misc.h>
65 #include <N_ERH_ErrorMgr.h>
67 #include <N_LAS_Vector.h>
68 #include <N_LAS_Matrix.h>
69 #include <N_LAS_BlockVector.h>
70 #include <N_LAS_System.h>
72 #include <N_PDS_Comm.h>
73 #include <N_PDS_Manager.h>
93 sec.maxOrder_=(Xycemin(2,tiaParams.maxOrder));
94 sec.minOrder_=(Xycemax(1,tiaParams.minOrder));
96 if (sec.minOrder_ > sec.maxOrder_)
98 sec.minOrder_ = sec.maxOrder_;
132 #ifdef Xyce_DEBUG_TIME
133 Xyce::dout().width(21); Xyce::dout().precision(13); Xyce::dout().setf(std::ios::scientific);
137 Xyce::dout() << std::endl
138 << Xyce::section_divider << std::endl
139 <<
" N_TIA_Gear12::obtainPredictor" << std::endl
141 <<
"\n sec.nscsco_: " <<
sec.
nscsco_ << std::endl;
143 Xyce::dout() <<
"\n sec.beta_[" << i <<
"] = " <<
sec.
beta_[i] <<
"\n" << std::endl;
146 Xyce::dout() <<
"\n xHistory["<< i <<
"]: \n" << std::endl;
147 (
ds.
xHistory[i])->printPetraObject(Xyce::dout());
148 Xyce::dout() << std::endl;
152 Xyce::dout() <<
"\n qHistory["<< i <<
"]: \n" << std::endl;
153 (
ds.
qHistory[i])->printPetraObject(Xyce::dout());
154 Xyce::dout() << std::endl;
158 Xyce::dout() <<
"\n sHistory["<< i <<
"]: \n" << std::endl;
159 (
ds.
sHistory[i])->printPetraObject(Xyce::dout());
160 Xyce::dout() << std::endl;
162 Xyce::dout() <<
"\n xn0: \n" << std::endl;
163 ds.
xn0Ptr->printPetraObject(Xyce::dout());
164 Xyce::dout() << std::endl;
165 Xyce::dout() <<
"\n qn0: \n" << std::endl;
166 ds.
qn0Ptr->printPetraObject(Xyce::dout());
167 Xyce::dout() << std::endl;
168 Xyce::dout() <<
"\n qpn0: \n" << std::endl;
169 ds.
qpn0Ptr->printPetraObject(Xyce::dout());
170 Xyce::dout() << std::endl;
171 Xyce::dout() <<
"\n sn0: \n" << std::endl;
172 ds.
sn0Ptr->printPetraObject(Xyce::dout());
173 Xyce::dout() << std::endl;
174 Xyce::dout() <<
"\n spn0: \n" << std::endl;
175 ds.
spn0Ptr->printPetraObject(Xyce::dout());
176 Xyce::dout() << std::endl;
177 Xyce::dout() << Xyce::section_divider << std::endl;
179 #endif // Xyce_DEBUG_TIME
201 #ifdef Xyce_DEBUG_TIME
204 Xyce::dout() << std::endl
205 << Xyce::section_divider << std::endl
206 <<
" N_TIA_Gear12::obtainResidual" << std::endl
208 <<
"\n solution: \n" << std::endl;
210 Xyce::dout() <<
"\n daeQVector: \n" << std::endl;
212 Xyce::dout() <<
"\n qn0: \n" << std::endl;
213 ds.
qn0Ptr->printPetraObject(Xyce::dout());
214 Xyce::dout() <<
"\n qpn0: \n" << std::endl;
215 ds.
qpn0Ptr->printPetraObject(Xyce::dout());
217 <<
"\n daeFVector: \n" << std::endl;
220 Xyce::dout() <<
"\n dQdt-vector: \n" << std::endl;
222 Xyce::dout() << std::endl;
249 #ifdef Xyce_DEBUG_TIME
252 Xyce::dout() <<
"\n Residual-vector: \n" << std::endl
253 <<
"-(qpn0-(sec.alpha_s/h)*(Q-qn0)+F-B) \n" << std::endl;
255 Xyce::dout() << Xyce::section_divider << std::endl
274 #ifdef Xyce_DEBUG_TIME
277 Xyce::dout() << std::endl
278 << Xyce::section_divider << std::endl
279 <<
" N_TIA_Gear12::obtainJacobian" << std::endl;
296 #ifdef Xyce_NO_MATRIX_LINEAR_COMBO
300 #ifndef Xyce_FAST_MATRIX_ADD
303 Jac.addLocal( dQdx );
306 #ifdef Xyce_DEBUG_TIME
309 Xyce::dout() <<
"\n dQdx: \n" <<std::endl;
310 dQdx.printPetraObject();
314 Jac.scale( qscalar );
316 #ifdef Xyce_DEBUG_TIME
319 Xyce::dout() <<
"\n scaled dQdx by " << qscalar <<
" :" <<std::endl;
320 Jac.printPetraObject();
324 #ifndef Xyce_FAST_MATRIX_ADD
327 Jac.addLocal( dFdx );
331 Jac.linearCombo( qscalar, dQdx, fscalar, dFdx );
335 #ifdef Xyce_DEBUG_TIME
338 Xyce::dout() <<
"\n dFdx:" <<std::endl;
339 dFdx.printPetraObject(Xyce::dout());
340 Xyce::dout() <<
"\n Total Jacobian:" <<std::endl;
341 Jac.printPetraObject(Xyce::dout());
347 Xyce::dout() << Xyce::section_divider << std::endl << std::endl;
362 N_LAS_Vector * tmpSolVectorPtr, std::vector<N_LAS_Vector*> & historyVec)
369 if( -dtr < 100 * N_UTL_MachineDependentParams::MachinePrecision() )
371 *tmpSolVectorPtr = *(historyVec[0]);
375 tmpSolVectorPtr->linearCombo(1.0, *(historyVec[0]), -1.0, *(historyVec[1]));
382 tmpSolVectorPtr->linearCombo(1.0, *(historyVec[0]), dtr, *tmpSolVectorPtr);
406 N_LAS_Vector * tmpSolVectorPtr)
417 N_LAS_BlockVector * blockTempSolVectorPtr =
418 dynamic_cast<N_LAS_BlockVector*
>(tmpSolVectorPtr);
419 if (blockTempSolVectorPtr == NULL)
421 std::string msg =
"N_TIA_Gear12::interpolateMPDESolution: ";
422 msg +=
"N_LAS_Vector tmpSolVectorPtr is not of type N_LAS_BlockVector";
423 N_ERH_ErrorMgr::report(N_ERH_ErrorMgr::DEV_FATAL_0, msg);
429 int numblocks = timepoint.size();
430 int blockCount = blockTempSolVectorPtr->blockCount();
431 if (numblocks > blockCount)
433 std::string msg =
"N_TIA_Gear12::interpolateMPDESolution: ";
434 msg +=
"Number of time points requested is greater than number of fast time points in MPDE block vector";
435 N_ERH_ErrorMgr::report(N_ERH_ErrorMgr::DEV_FATAL_0, msg);
448 tfuzz = 100 * uround * (tn + hh);
449 tp = tn - hused - tfuzz;
450 for (
int i=0; i<numblocks ; ++i)
452 if ( (timepoint[i] - tp)*hh < 0.0 )
458 N_LAS_Vector * solVectorPtr;
459 N_LAS_Vector * xHistoryVectorPtr;
461 for (
int i=0; i < numblocks ; ++i)
463 if ((kused == 0) || (timepoint[i] == tn)) { kord = 1; }
464 else { kord = kused; }
465 solVectorPtr = &(blockTempSolVectorPtr->block(i));
467 delt = timepoint[i] - tn;
469 for (
int j=1 ; j <= kord ; ++j)
473 N_LAS_BlockVector * blockXHistoryVectorPtr =
474 dynamic_cast<N_LAS_BlockVector*>(
ds.
xHistory[j]);
475 if (blockXHistoryVectorPtr == NULL)
477 Xyce::Report::DevelFatal0().in(
"N_TIA_Gear12::interpolateMPDESolution") <<
"N_LAS_Vector ds.xHistory[j] is not of type N_LAS_BlockVector\n j = " << j;
480 xHistoryVectorPtr = &(blockXHistoryVectorPtr->block(i));
481 solVectorPtr->linearCombo(1.0,*solVectorPtr,c,*xHistoryVectorPtr);
497 RefCountPtr< N_ANP_OutputMgrAdapter > outputMgrAdapterRCPtr,
499 N_LAS_Vector * solnVecPtr,
500 const std::vector<double> & fastTimes )
775 RefCountPtr< N_ANP_OutputMgrAdapter > outputMgrAdapterRCPtr,
777 N_LAS_Vector * solnVecPtr,
778 const std::vector<double> & fastTimes,
1086 RefCountPtr< N_ANP_OutputMgrAdapter > outputMgrAdapterRCPtr,
1088 N_LAS_Vector * solnVecPtr,
1089 const bool doNotInterpolate,
1090 const std::vector<double> &outputInterpolationTimes,
1091 bool skipPrintLineOutput)
1093 #ifdef Xyce_DEBUG_TIME
1096 Xyce::dout() << std::endl
1097 << Xyce::section_divider << std::endl
1098 <<
" N_TIA_Gear12::printOutputSolution" << std::endl
1101 #endif // Xyce_DEBUG_TIME
1104 bool dointerp =
true;
1117 if (doNotInterpolate)
1122 if (dointerp && !outputInterpolationTimes.empty())
1124 for (
unsigned int i=0;i<outputInterpolationTimes.size();++i)
1129 outputMgrAdapterRCPtr->tranOutput(outputInterpolationTimes[i], *
ds.
tmpSolVectorPtr,
1133 skipPrintLineOutput);
1140 if (outputInterpolationTimes.empty() || doNotInterpolate)
1146 skipPrintLineOutput);
1149 #ifdef Xyce_DEBUG_TIME
1150 Xyce::dout() << Xyce::section_divider << std::endl;
1151 #endif // Xyce_DEBUG_TIME
1165 RefCountPtr< N_ANP_OutputMgrAdapter > outputMgrAdapterRCPtr,
1166 N_LAS_Vector * solnVecPtr,
1167 const double saveTime,
1168 const bool doNotInterpolate)
1170 #ifdef Xyce_DEBUG_TIME
1173 Xyce::dout() << std::endl
1174 << Xyce::section_divider << std::endl
1175 <<
" N_TIA_BackwardDifferentiation15::saveOutputSolution" << std::endl;
1177 #endif // Xyce_DEBUG_TIME
1181 bool dointerp =
true;
1186 #ifdef Xyce_DEBUG_TIME
1187 Xyce::dout() << Xyce::section_divider << std::endl;
1188 #endif // Xyce_DEBUG_TIME
1203 #ifdef Xyce_DEBUG_TIME
1206 Xyce::dout() << std::endl
1207 << Xyce::section_divider << std::endl
1208 <<
" N_TIA_Gear12::updateHistory" << std::endl
1209 <<
"\n Before updates \n" << std::endl;
1212 Xyce::dout() <<
"\n xHistory["<< i <<
"]: \n" << std::endl;
1213 (
ds.
xHistory[i])->printPetraObject(Xyce::dout());
1214 Xyce::dout() << std::endl;
1218 Xyce::dout() <<
"\n qHistory["<< i <<
"]: \n" << std::endl;
1219 (
ds.
qHistory[i])->printPetraObject(Xyce::dout());
1220 Xyce::dout() << std::endl;
1224 Xyce::dout() <<
"\n sHistory["<< i <<
"]: \n" << std::endl;
1225 (
ds.
sHistory[i])->printPetraObject(Xyce::dout());
1226 Xyce::dout() << std::endl;
1228 Xyce::dout() << Xyce::section_divider << std::endl;
1230 #endif // Xyce_DEBUG_TIME
1249 #ifdef Xyce_DEBUG_TIME
1252 Xyce::dout() <<
"\n After updates \n" << std::endl;
1253 Xyce::dout() <<
"\n newtonCorrectionPtr: " << std::endl;
1255 Xyce::dout() <<
"\n qnewtonCorrectionPtr: " << std::endl;
1259 Xyce::dout() <<
"\n xHistory["<< i <<
"]: \n" << std::endl;
1260 (
ds.
xHistory[i])->printPetraObject(Xyce::dout());
1261 Xyce::dout() << std::endl;
1265 Xyce::dout() <<
"\n qHistory["<< i <<
"]: \n" << std::endl;
1266 (
ds.
qHistory[i])->printPetraObject(Xyce::dout());
1267 Xyce::dout() << std::endl;
1269 Xyce::dout() <<
"\n sNewtonCorrectionPtr: " << std::endl;
1271 Xyce::dout() << std::endl;
1272 Xyce::dout() <<
"\n nextStatePtr: " << std::endl;
1274 Xyce::dout() << std::endl;
1277 Xyce::dout() <<
"\n sHistory["<< i <<
"]: \n" << std::endl;
1278 (
ds.
sHistory[i])->printPetraObject(Xyce::dout());
1279 Xyce::dout() << std::endl;
1281 Xyce::dout() << Xyce::section_divider << std::endl;
1283 #endif // Xyce_DEBUG_TIME
1301 #ifdef Xyce_DEBUG_TIME
1304 Xyce::dout() << std::endl
1305 << Xyce::section_divider << std::endl
1306 <<
" N_TIA_Gear12::restoreHistory" << std::endl;
1308 Xyce::dout() <<
"\n sec.psi_[i] = " <<
sec.
psi_[i] << std::endl;
1311 Xyce::dout() <<
"\n xHistory["<< i <<
"]: \n" << std::endl;
1312 (
ds.
xHistory[i])->printPetraObject(Xyce::dout());
1313 Xyce::dout() << std::endl;
1317 Xyce::dout() <<
"\n qHistory["<< i <<
"]: \n" << std::endl;
1318 (
ds.
qHistory[i])->printPetraObject(Xyce::dout());
1319 Xyce::dout() << std::endl;
1323 Xyce::dout() <<
"\n sHistory["<< i <<
"]: \n" << std::endl;
1324 (
ds.
sHistory[i])->printPetraObject(Xyce::dout());
1325 Xyce::dout() << std::endl;
1327 Xyce::dout() << Xyce::section_divider << std::endl;
1329 #endif // Xyce_DEBUG_TIME
1344 #ifdef Xyce_DEBUG_TIME
1347 Xyce::dout() << std::endl
1348 << Xyce::section_divider << std::endl
1349 <<
" N_TIA_Gear12::updateCoeffs" << std::endl
1354 <<
" psi_[0] = " <<
sec.
psi_[0] << std::endl;
1401 #ifdef Xyce_DEBUG_TIME
1404 Xyce::dout() <<
" nscsco_ = " <<
sec.
nscsco_ << std::endl
1405 <<
" beta_[0] = " <<
sec.
beta_[0] << std::endl
1406 <<
" beta_[1] = " <<
sec.
beta_[1] << std::endl
1407 <<
" beta_[2] = " <<
sec.
beta_[2] << std::endl
1408 <<
" beta_[3] = " <<
sec.
beta_[3] << std::endl
1409 <<
" beta_[4] = " <<
sec.
beta_[4] << std::endl
1410 <<
" alpha_[0] = " <<
sec.
alpha_[0] << std::endl
1411 <<
" alpha_[1] = " <<
sec.
alpha_[1] << std::endl
1412 <<
" alpha_[2] = " <<
sec.
alpha_[2] << std::endl
1413 <<
" alpha_[3] = " <<
sec.
alpha_[3] << std::endl
1414 <<
" alpha_[4] = " <<
sec.
alpha_[4] << std::endl
1417 <<
" gamma_[0] = " <<
sec.
gamma_[0] << std::endl
1418 <<
" gamma_[1] = " <<
sec.
gamma_[1] << std::endl
1419 <<
" gamma_[2] = " <<
sec.
gamma_[2] << std::endl
1420 <<
" gamma_[3] = " <<
sec.
gamma_[3] << std::endl
1421 <<
" gamma_[4] = " <<
sec.
gamma_[4] << std::endl
1422 <<
" psi_[0] = " <<
sec.
psi_[0] << std::endl
1423 <<
" psi_[1] = " <<
sec.
psi_[1] << std::endl
1424 <<
" psi_[2] = " <<
sec.
psi_[2] << std::endl
1425 <<
" psi_[3] = " <<
sec.
psi_[3] << std::endl
1426 <<
" psi_[4] = " <<
sec.
psi_[4] << std::endl
1427 <<
" sigma_[0] = " <<
sec.
sigma_[0] << std::endl
1428 <<
" sigma_[1] = " <<
sec.
sigma_[1] << std::endl
1429 <<
" sigma_[2] = " <<
sec.
sigma_[2] << std::endl
1430 <<
" sigma_[3] = " <<
sec.
sigma_[3] << std::endl
1431 <<
" sigma_[4] = " <<
sec.
sigma_[4] << std::endl
1432 <<
" ck_ = " <<
sec.
ck_ << std::endl
1433 << Xyce::section_divider << std::endl;
1435 #endif // Xyce_DEBUG_TIME
1462 double currentTimeStep;
1468 currentTimeStep = 0.1 * time_to_stop;
1476 #ifdef Xyce_INCOMPLETE_2LEVEL_NORMS
1477 double dnorm_q = 0.0;
1501 if (rh>1.0) currentTimeStep = currentTimeStep/rh;
1526 #ifdef Xyce_VERBOSE_TIME
1529 Xyce::dout() <<
"ERROROPTION=1: DeltaT Grow = 2" <<
"\n" << std::endl
1530 <<
"ERROROPTION=1: DeltaT Cut = 0.125" <<
"\n" << std::endl
1531 <<
"ERROROPTION=1: NL MIN = " <<
tiaParams.
NLmin <<
"\n" << std::endl
1532 <<
"ERROROPTION=1: NL MAX = " <<
tiaParams.
NLmax <<
"\n" << std::endl
1533 <<
"ERROROPTION=1: DELMAX = " <<
sec.
maxTimeStep <<
"\n" << std::endl;
1535 #endif //Xyce_VERBOSE_TIME
1574 #ifdef Xyce_DEBUG_TIME
1577 Xyce::dout() << std::endl
1578 << Xyce::section_divider << std::endl
1579 <<
" N_TIA_Gear12::initialize" << std::endl
1580 <<
"\n xHistory: \n" << std::endl;
1581 (
ds.
xHistory[0])->printPetraObject(Xyce::dout());
1582 Xyce::dout() << std::endl;
1583 (
ds.
xHistory[1])->printPetraObject(Xyce::dout());
1584 Xyce::dout() << std::endl
1585 <<
"\n qHistory: \n" << std::endl;
1586 (
ds.
qHistory[0])->printPetraObject(Xyce::dout());
1587 Xyce::dout() << std::endl;
1588 (
ds.
qHistory[1])->printPetraObject(Xyce::dout());
1589 Xyce::dout() << std::endl
1590 <<
"\n sHistory: \n" << std::endl;
1591 (
ds.
sHistory[0])->printPetraObject(Xyce::dout());
1592 Xyce::dout() << std::endl;
1593 (
ds.
sHistory[1])->printPetraObject(Xyce::dout());
1594 Xyce::dout() << std::endl
1595 <<
"\n" <<
"currentTimeStep = " << currentTimeStep <<
"\n" << std::endl
1596 <<
"\n" <<
"time_to_stop = " << time_to_stop <<
"\n" << std::endl
1597 << Xyce::section_divider << std::endl;
1599 #endif // Xyce_DEBUG_TIME
1614 double time_to_stop = sec.stopTime - sec.currentTime;
1618 *(ds.xHistory[0]) = *(ds.currSolutionPtr);
1619 *(ds.xHistory[1]) = *(ds.currSolutionPtr);
1622 *(ds.qHistory[0]) = *(ds.daeQVectorPtr);
1623 *(ds.qHistory[1]) = *(ds.daeQVectorPtr);
1626 *(ds.sHistory[0]) = *(ds.currStatePtr);
1627 (ds.sHistory[1])->putScalar(0.0);
1630 sec.numberOfSteps_ = 0;
1632 sec.psi_[0] = sec.currentTimeStep;
1633 sec.cj_ = 1/sec.psi_[0];
1677 #ifdef Xyce_DEBUG_TIME
1680 Xyce::dout() << std::endl
1681 << Xyce::section_divider << std::endl
1682 <<
" N_TIA_Gear12::rejectStep" << std::endl;
1711 std::string msg =
"N_TIA_Gear12::rejectStep: ";
1712 msg +=
" Maximum number of local error test failures. ";
1713 N_ERH_ErrorMgr::report(N_ERH_ErrorMgr::DEV_FATAL_0, msg);
1760 #ifdef Xyce_DEBUG_TIME
1767 <<
" alpha_[0] = " <<
sec.
alpha_[0] << std::endl
1768 <<
" alpha_[1] = " <<
sec.
alpha_[1] << std::endl
1769 <<
" alpha_[2] = " <<
sec.
alpha_[2] << std::endl
1770 <<
" alpha_[3] = " <<
sec.
alpha_[3] << std::endl
1771 <<
" alpha_[4] = " <<
sec.
alpha_[4] << std::endl
1772 <<
" psi_[0] = " <<
sec.
psi_[0] << std::endl
1773 <<
" psi_[1] = " <<
sec.
psi_[1] << std::endl
1774 <<
" psi_[2] = " <<
sec.
psi_[2] << std::endl
1775 <<
" psi_[3] = " <<
sec.
psi_[3] << std::endl
1776 <<
" psi_[4] = " <<
sec.
psi_[4] << std::endl
1777 <<
" sigma_[0] = " <<
sec.
sigma_[0] << std::endl
1778 <<
" sigma_[1] = " <<
sec.
sigma_[1] << std::endl
1779 <<
" sigma_[2] = " <<
sec.
sigma_[2] << std::endl
1780 <<
" sigma_[3] = " <<
sec.
sigma_[3] << std::endl
1781 <<
" sigma_[4] = " <<
sec.
sigma_[4] << std::endl
1782 <<
" rr = " << rr << std::endl
1785 <<
" Est_ = " <<
sec.
Est_ << std::endl
1789 <<
" newTimeStep_ = " << newTimeStep_ << std::endl;
1791 #endif // Xyce_DEBUG_TIME
1796 std::string tmp =
" Gear12:rejectStep: Warning: Local error test failed with constant step-size.\n";
1797 Xyce::dout() << tmp << std::endl;
1820 #ifdef Xyce_DEBUG_TIME
1823 Xyce::dout() <<
" newTimeStep_ = " << newTimeStep_ << std::endl
1826 #endif // Xyce_DEBUG_TIME
1845 #ifdef Xyce_DEBUG_TIME
1848 Xyce::dout() << Xyce::section_divider << std::endl;
1850 #endif // Xyce_DEBUG_TIME
1885 #ifdef Xyce_DEBUG_TIME
1888 Xyce::dout() << std::endl
1889 << Xyce::section_divider << std::endl
1890 <<
" N_TIA_Gear12::completeStep" << std::endl;
1910 #ifdef Xyce_DEBUG_TIME
1914 <<
" rr = " << rr << std::endl
1918 <<
" newTimeStep_ = " << newTimeStep_ << std::endl
1978 #ifdef Xyce_DEBUG_TIME
1992 " Est = " <<
sec.
Est_ << std::endl;
1994 " raw rr = " << rr << std::endl;
2048 #ifdef Xyce_DEBUG_TIME
2054 " newTimeStep_ = " << newTimeStep_ << std::endl;
2079 #ifdef Xyce_DEBUG_TIME
2082 Xyce::dout() << Xyce::section_divider << std::endl;
2115 #ifdef Xyce_DEBUG_TIME
2118 Xyce::dout() <<
"\n next state Ptr: \n" << std::endl;
2120 Xyce::dout() << std::endl;
2122 Xyce::dout() <<
"\n sn0: \n" << std::endl;
2123 ds.
sn0Ptr->printPetraObject(Xyce::dout());
2124 Xyce::dout() << std::endl;
2126 Xyce::dout() <<
"\n next State Deriv: \n" << std::endl;
2128 Xyce::dout() << std::endl;
2155 #ifdef Xyce_DEBUG_TIME
2158 Xyce::dout() <<
"\n next store Ptr: \n" << std::endl;
2160 Xyce::dout() << std::endl;
2197 #ifdef Xyce_DEBUG_TIME
2198 Xyce::dout() << tle;