50 #define STEPDEBUG 0 // set to zero for release
51 #define BREAKPOINTS 0 // exact breakpoint calculation
53 #define dState 0 // delta T state
54 #define sState 1 // solution state
56 using namespace transient;
63 setDescription (
"transient");
64 for (
int i = 0;
i < 8;
i++) solution[
i] = NULL;
76 for (
int i = 0;
i < 8;
i++) solution[
i] = NULL;
85 for (
int i = 0;
i < 8;
i++)
if (solution[
i] != NULL)
delete solution[
i];
86 if (tHistory)
delete tHistory;
93 swp = o.swp ?
new sweep (*o.swp) : NULL;
94 for (
int i = 0;
i < 8;
i++) solution[
i] = NULL;
95 tHistory = o.tHistory ?
new history (*o.tHistory) : NULL;
96 relaxTSR = o.relaxTSR;
97 initialDC = o.initialDC;
102 if (swp != NULL)
delete swp;
107 #define SOL(state) (solution[(int) getState (sState, (state))])
160 nr_double_t time, saveCurrent;
161 int error = 0, convError = 0;
167 saveCurrent = current = 0;
171 statRejected = statSteps = statIterations = statConvergence = 0;
174 if (!strcmp (solver,
"CroutLU"))
176 else if (!strcmp (solver,
"DoolittleLU"))
178 else if (!strcmp (solver,
"HouseholderQR"))
180 else if (!strcmp (solver,
"HouseholderLQ"))
182 else if (!strcmp (solver,
"GolubSVD"))
230 if (delta == deltaMin) {
232 "WARNING: %s: minimum delta h = %.3e at t = %.3e\n",
233 getName (), (
double) delta, (
double) current);
257 if (current > 0) current -= delta;
259 if (delta <= deltaMin) {
263 if (current > 0) current += delta;
278 "(no convergence)\n", (
double) saveCurrent, (
double) delta);
287 if (error)
return -1;
288 if (rejected)
continue;
293 "aborting %s analysis\n",
getName (), (
double) current,
313 saveCurrent = current;
329 while (saveCurrent < time);
334 (
double) saveCurrent, (
double) delta);
346 getName (), (
double) (saveCurrent / statSteps), statRejected);
348 "%d non-convergences\n",
getName (),
349 (
double) statIterations / statSteps, statConvergence);
363 nr_double_t age = 0.0;
366 if (
c->hasHistory ()) {
367 c->applyHistory (tHistory);
369 if (
c->getHistoryAge () > age) age =
c->getHistoryAge ();
379 if (t > tHistory->
last ()) {
395 for (i = 0; i <
s; i++) {
435 for (
int i = 0;
i < 8;
i++) *
SOL (
i) = *
s;
443 nr_double_t xn, dd, hn;
446 for (
int r = 0; r < N +
M; r++) {
447 xn = predCoeff[0] *
SOL(1)->get (r);
448 for (
int o = 1; o <= predOrder; o++) {
451 dd = (
SOL(o)->get (r) -
SOL(o + 1)->get (r)) / hn;
452 xn += predCoeff[o] * dd;
464 nr_double_t xn, dd, hn;
466 for (
int r = 0; r < N +
M; r++) {
467 xn = predCoeff[0] *
SOL(1)->get (r);
469 dd = (
SOL(1)->get (r) -
SOL(2)->get (r)) / hn;
470 xn += predCoeff[1] * dd;
483 for (
int r = 0; r < N +
M; r++) {
485 for (
int o = 0; o <= predOrder; o++) {
487 xn += predCoeff[o] *
SOL(o + 1)->get (r);
518 for (
int s = 0;
s <
c->getStates ();
s++)
519 c->fillState (
s,
c->getState (
s));
534 c->setDelta (deltas);
542 if (delta > deltaMax) delta = deltaMax;
543 if (delta < deltaMin) delta = deltaMin;
548 if (!statConvergence || converged > 64) {
550 if (stepDelta > 0.0) {
556 if (delta > (t - current) && t > current) {
558 stepDelta = deltaOld;
566 if (delta > deltaMax) delta = deltaMax;
567 if (delta < deltaMin) delta = deltaMin;
572 if (delta > 0.9 * deltaOld || good) {
577 "DEBUG: delta accepted at t = %.3e, h = %.3e\n",
578 (
double) current, (
double) delta);
581 else if (deltaOld > delta) {
586 "DEBUG: delta rejected at t = %.3e, h = %.3e\n",
587 (
double) current, (
double) delta);
589 if (current > 0) current -= deltaOld;
600 if ((corrOrder < corrMaxOrder && !rejected) || reduce) {
603 }
else if (!rejected) {
614 c->setOrder (corrOrder);
634 c->calcTR (self->current);
643 if (
c->isNonLinear ())
c->restartDC ();
667 predType = PMethod =
predictorType (CMethod, corrMaxOrder, predMaxOrder);
668 corrOrder = corrMaxOrder;
669 predOrder = predMaxOrder;
676 deltaMax =
MIN ((stop - start) / (points - 1), stop / 200);
678 deltaMin = NR_TINY * 10 * deltaMax;
680 delta =
MIN (stop / 200, deltaMax) / 10;
681 if (delta < deltaMin) delta = deltaMin;
682 if (delta > deltaMax) delta = deltaMax;
695 for (
int i = 0;
i < 8;
i++) {
712 for (
int i = 0;
i < 8;
i++) {
752 nr_double_t dif, rel, tol, lte, q,
n = NR_MAX;
762 for (
int r = 0; r < N +
M; r++) {
770 dif =
x->
get (r) -
SOL(0)->get (r);
771 if (finite (dif) && dif != 0) {
773 rel =
MAX (fabs (
x->
get (r)), fabs (
SOL(0)->get (r)));
774 tol = LTEreltol * rel + LTEabstol;
775 lte = LTEfactor * (cec / (pec - cec)) * dif;
776 q = delta *
exp (
log (fabs (tol / lte)) / (corrOrder + 1));
782 "error h = %.3e\n", (
double) n);
784 delta =
MIN ((n > 1.9 * delta) ? 2 * delta : delta, n);
806 PROP_RNG_STR4 (
"Euler",
"Trapezoidal",
"Gear",
"AdamsMoulton") },