Browse Source

cktop.c, #10/14, whitespace

pre-master-46
rlar 10 years ago
parent
commit
64fadb90cc
  1. 192
      src/spicelib/analysis/cktop.c

192
src/spicelib/analysis/cktop.c

@ -15,20 +15,22 @@ Modified: 2005 Paolo Nenzi - Restructured
#endif #endif
static int dynamic_gmin (CKTcircuit *, long int, long int, int);
static int spice3_gmin (CKTcircuit *, long int, long int, int);
static int gillespie_src (CKTcircuit *, long int, long int, int);
static int spice3_src (CKTcircuit *, long int, long int, int);
static int dynamic_gmin(CKTcircuit *, long int, long int, int);
static int spice3_gmin(CKTcircuit *, long int, long int, int);
static int gillespie_src(CKTcircuit *, long int, long int, int);
static int spice3_src(CKTcircuit *, long int, long int, int);
int int
CKTop (CKTcircuit * ckt, long int firstmode, long int continuemode,
CKTop (CKTcircuit *ckt, long int firstmode, long int continuemode,
int iterlim) int iterlim)
{ {
int converged; int converged;
#ifdef HAS_PROGREP #ifdef HAS_PROGREP
SetAnalyse("op", 0); SetAnalyse("op", 0);
#endif #endif
ckt->CKTmode = firstmode; ckt->CKTmode = firstmode;
if (!ckt->CKTnoOpIter) { if (!ckt->CKTnoOpIter) {
@ -48,42 +50,41 @@ CKTop (CKTcircuit * ckt, long int firstmode, long int continuemode,
} }
/* no convergence on the first try, so we do something else */
/* first, check if we should try gmin stepping */
/* no convergence on the first try, so we do something else */
/* first, check if we should try gmin stepping */
if (ckt->CKTnumGminSteps >= 1) {
if (ckt->CKTnumGminSteps == 1)
converged = dynamic_gmin(ckt, firstmode, continuemode, iterlim);
else
converged = spice3_gmin(ckt, firstmode, continuemode, iterlim);
if (converged == 0) /* If gmin-stepping worked... move out */
return (0);
}
if (ckt->CKTnumGminSteps >= 1) {
if (ckt->CKTnumGminSteps == 1)
converged = dynamic_gmin(ckt, firstmode, continuemode, iterlim);
else
converged = spice3_gmin(ckt, firstmode, continuemode, iterlim);
if (converged == 0) /* If gmin-stepping worked... move out */
return (0);
}
/* ... otherwise try stepping sources ...
* now, we'll try source stepping - we scale the sources
* to 0, converge, then start stepping them up until they
* are at their normal values
*/
if (ckt->CKTnumSrcSteps >= 1) {
if (ckt->CKTnumSrcSteps == 1)
converged = gillespie_src(ckt, firstmode, continuemode, iterlim);
else
converged = spice3_src(ckt, firstmode, continuemode, iterlim);
}
/* ... otherwise try stepping sources ...
* now, we'll try source stepping - we scale the sources
* to 0, converge, then start stepping them up until they
* are at their normal values
*/
if (ckt->CKTnumSrcSteps >= 1) {
if (ckt->CKTnumSrcSteps == 1)
converged = gillespie_src(ckt, firstmode, continuemode, iterlim);
else
converged = spice3_src(ckt, firstmode, continuemode, iterlim);
}
#ifdef XSPICE #ifdef XSPICE
/* gtri - begin - wbk - add convergence problem reporting flags */
ckt->enh->conv_debug.last_NIiter_call = MIF_FALSE;
/* gtri - end - wbk - add convergence problem reporting flags */
/* gtri - begin - wbk - add convergence problem reporting flags */
ckt->enh->conv_debug.last_NIiter_call = MIF_FALSE;
/* gtri - end - wbk - add convergence problem reporting flags */
#endif #endif
return (converged); return (converged);
} }
/* CKTconvTest(ckt) /* CKTconvTest(ckt)
* this is a driver program to iterate through all the various * this is a driver program to iterate through all the various
* convTest functions provided for the circuit elements in the * convTest functions provided for the circuit elements in the
@ -91,11 +92,12 @@ CKTop (CKTcircuit * ckt, long int firstmode, long int continuemode,
*/ */
int int
CKTconvTest (CKTcircuit * ckt)
CKTconvTest (CKTcircuit *ckt)
{ {
int i; int i;
for (i = 0; i < DEVmaxnum; i++) { for (i = 0; i < DEVmaxnum; i++) {
if (DEVices[i] && DEVices[i]->DEVconvTest && ckt->CKThead[i]) { if (DEVices[i] && DEVices[i]->DEVconvTest && ckt->CKThead[i]) {
int error = DEVices[i]->DEVconvTest (ckt->CKThead[i], ckt); int error = DEVices[i]->DEVconvTest (ckt->CKThead[i], ckt);
if (error) if (error)
@ -126,7 +128,7 @@ CKTconvTest (CKTcircuit * ckt)
*/ */
static int static int
dynamic_gmin (CKTcircuit * ckt, long int firstmode,
dynamic_gmin (CKTcircuit *ckt, long int firstmode,
long int continuemode, int iterlim) long int continuemode, int iterlim)
{ {
double OldGmin, gtarget, factor; double OldGmin, gtarget, factor;
@ -138,7 +140,7 @@ dynamic_gmin (CKTcircuit * ckt, long int firstmode,
ckt->CKTmode = firstmode; ckt->CKTmode = firstmode;
SPfrontEnd->IFerrorf (ERR_INFO, SPfrontEnd->IFerrorf (ERR_INFO,
"Starting dynamic gmin stepping");
"Starting dynamic gmin stepping");
NumNodes = 0; NumNodes = 0;
for (n = ckt->CKTnodes; n; n = n->next) for (n = ckt->CKTnodes; n; n = n->next)
@ -160,59 +162,60 @@ dynamic_gmin (CKTcircuit * ckt, long int firstmode,
for (;;) { for (;;) {
fprintf (stderr, "Trying gmin = %12.4E ", ckt->CKTdiagGmin); fprintf (stderr, "Trying gmin = %12.4E ", ckt->CKTdiagGmin);
ckt->CKTnoncon = 1; ckt->CKTnoncon = 1;
iters = ckt->CKTstat->STATnumIter; iters = ckt->CKTstat->STATnumIter;
converged = NIiter (ckt, ckt->CKTdcTrcvMaxIter); converged = NIiter (ckt, ckt->CKTdcTrcvMaxIter);
iters = ckt->CKTstat->STATnumIter - iters; iters = ckt->CKTstat->STATnumIter - iters;
if (converged == 0) { if (converged == 0) {
ckt->CKTmode = continuemode; ckt->CKTmode = continuemode;
SPfrontEnd->IFerrorf (ERR_INFO, SPfrontEnd->IFerrorf (ERR_INFO,
"One successful gmin step");
"One successful gmin step");
if (ckt->CKTdiagGmin <= gtarget) { if (ckt->CKTdiagGmin <= gtarget) {
break; /* successfull */ break; /* successfull */
} }
for (i = 0, n = ckt->CKTnodes; n; n = n->next)
OldRhsOld[i++] = ckt->CKTrhsOld[n->number];
memcpy(OldCKTstate0, ckt->CKTstate0,
for (i = 0, n = ckt->CKTnodes; n; n = n->next)
OldRhsOld[i++] = ckt->CKTrhsOld[n->number];
memcpy(OldCKTstate0, ckt->CKTstate0,
(size_t) ckt->CKTnumStates * sizeof(double)); (size_t) ckt->CKTnumStates * sizeof(double));
if (iters <= (ckt->CKTdcTrcvMaxIter / 4)) {
factor *= sqrt (factor);
if (factor > ckt->CKTgminFactor)
factor = ckt->CKTgminFactor;
}
if (iters <= (ckt->CKTdcTrcvMaxIter / 4)) {
factor *= sqrt (factor);
if (factor > ckt->CKTgminFactor)
factor = ckt->CKTgminFactor;
}
if (iters > (3 * ckt->CKTdcTrcvMaxIter / 4))
factor = sqrt (factor);
if (iters > (3 * ckt->CKTdcTrcvMaxIter / 4))
factor = sqrt (factor);
OldGmin = ckt->CKTdiagGmin;
OldGmin = ckt->CKTdiagGmin;
if (ckt->CKTdiagGmin < factor * gtarget) {
factor = ckt->CKTdiagGmin / gtarget;
ckt->CKTdiagGmin = gtarget;
} else {
ckt->CKTdiagGmin /= factor;
}
if (ckt->CKTdiagGmin < factor * gtarget) {
factor = ckt->CKTdiagGmin / gtarget;
ckt->CKTdiagGmin = gtarget;
} else {
ckt->CKTdiagGmin /= factor;
}
} else { } else {
if (factor < 1.00005) { if (factor < 1.00005) {
SPfrontEnd->IFerrorf (ERR_WARNING, SPfrontEnd->IFerrorf (ERR_WARNING,
"Last gmin step failed");
"Last gmin step failed");
break; /* failed */ break; /* failed */
} }
SPfrontEnd->IFerrorf (ERR_WARNING,
"Further gmin increment");
factor = sqrt (sqrt (factor));
ckt->CKTdiagGmin = OldGmin / factor;
SPfrontEnd->IFerrorf (ERR_WARNING,
"Further gmin increment");
factor = sqrt (sqrt (factor));
ckt->CKTdiagGmin = OldGmin / factor;
for (i = 0, n = ckt->CKTnodes; n; n = n->next)
ckt->CKTrhsOld[n->number] = OldRhsOld[i++];
for (i = 0, n = ckt->CKTnodes; n; n = n->next)
ckt->CKTrhsOld[n->number] = OldRhsOld[i++];
memcpy(ckt->CKTstate0, OldCKTstate0,
(size_t) ckt->CKTnumStates * sizeof(double));
memcpy(ckt->CKTstate0, OldCKTstate0,
(size_t) ckt->CKTnumStates * sizeof(double));
} }
} }
@ -233,10 +236,10 @@ dynamic_gmin (CKTcircuit * ckt, long int firstmode,
if (converged != 0) { if (converged != 0) {
SPfrontEnd->IFerrorf (ERR_WARNING, SPfrontEnd->IFerrorf (ERR_WARNING,
"Dynamic gmin stepping failed");
"Dynamic gmin stepping failed");
} else { } else {
SPfrontEnd->IFerrorf (ERR_INFO, SPfrontEnd->IFerrorf (ERR_INFO,
"Dynamic gmin stepping completed");
"Dynamic gmin stepping completed");
#ifdef XSPICE #ifdef XSPICE
/* gtri - begin - wbk - add convergence problem reporting flags */ /* gtri - begin - wbk - add convergence problem reporting flags */
ckt->enh->conv_debug.last_NIiter_call = MIF_FALSE; ckt->enh->conv_debug.last_NIiter_call = MIF_FALSE;
@ -261,15 +264,14 @@ dynamic_gmin (CKTcircuit * ckt, long int firstmode,
*/ */
static int static int
spice3_gmin (CKTcircuit * ckt, long int firstmode,
spice3_gmin (CKTcircuit *ckt, long int firstmode,
long int continuemode, int iterlim) long int continuemode, int iterlim)
{ {
int converged, i; int converged, i;
ckt->CKTmode = firstmode; ckt->CKTmode = firstmode;
SPfrontEnd->IFerrorf (ERR_INFO, SPfrontEnd->IFerrorf (ERR_INFO,
"Starting gmin stepping");
"Starting gmin stepping");
if (ckt->CKTgshunt == 0) if (ckt->CKTgshunt == 0)
ckt->CKTdiagGmin = ckt->CKTgmin; ckt->CKTdiagGmin = ckt->CKTgmin;
@ -279,16 +281,16 @@ spice3_gmin (CKTcircuit * ckt, long int firstmode,
for (i = 0; i < ckt->CKTnumGminSteps; i++) for (i = 0; i < ckt->CKTnumGminSteps; i++)
ckt->CKTdiagGmin *= ckt->CKTgminFactor; ckt->CKTdiagGmin *= ckt->CKTgminFactor;
for (i = 0; i <= ckt->CKTnumGminSteps; i++) { for (i = 0; i <= ckt->CKTnumGminSteps; i++) {
fprintf (stderr, "Trying gmin = %12.4E ", ckt->CKTdiagGmin); fprintf (stderr, "Trying gmin = %12.4E ", ckt->CKTdiagGmin);
ckt->CKTnoncon = 1; ckt->CKTnoncon = 1;
converged = NIiter (ckt, ckt->CKTdcTrcvMaxIter); converged = NIiter (ckt, ckt->CKTdcTrcvMaxIter);
if (converged != 0) { if (converged != 0) {
ckt->CKTdiagGmin = ckt->CKTgshunt; ckt->CKTdiagGmin = ckt->CKTgshunt;
SPfrontEnd->IFerrorf (ERR_WARNING, SPfrontEnd->IFerrorf (ERR_WARNING,
"gmin step failed");
"gmin step failed");
break; break;
} }
@ -296,7 +298,7 @@ spice3_gmin (CKTcircuit * ckt, long int firstmode,
ckt->CKTmode = continuemode; ckt->CKTmode = continuemode;
SPfrontEnd->IFerrorf (ERR_INFO, SPfrontEnd->IFerrorf (ERR_INFO,
"One successful gmin step");
"One successful gmin step");
} }
ckt->CKTdiagGmin = ckt->CKTgshunt; ckt->CKTdiagGmin = ckt->CKTgshunt;
@ -314,7 +316,7 @@ spice3_gmin (CKTcircuit * ckt, long int firstmode,
if (converged == 0) { if (converged == 0) {
SPfrontEnd->IFerrorf (ERR_INFO, SPfrontEnd->IFerrorf (ERR_INFO,
"gmin stepping completed");
"gmin stepping completed");
#ifdef XSPICE #ifdef XSPICE
/* gtri - begin - wbk - add convergence problem reporting flags */ /* gtri - begin - wbk - add convergence problem reporting flags */
@ -324,7 +326,7 @@ spice3_gmin (CKTcircuit * ckt, long int firstmode,
} else { } else {
SPfrontEnd->IFerrorf (ERR_WARNING, SPfrontEnd->IFerrorf (ERR_WARNING,
"gmin stepping failed");
"gmin stepping failed");
} }
return (converged); return (converged);
@ -341,11 +343,11 @@ spice3_gmin (CKTcircuit * ckt, long int firstmode,
* Note that no path out of this code allows ckt->CKTsrcFact to be * Note that no path out of this code allows ckt->CKTsrcFact to be
* anything but 1.00000. * anything but 1.00000.
*/ */
static int static int
gillespie_src (CKTcircuit * ckt, long int firstmode,
gillespie_src (CKTcircuit *ckt, long int firstmode,
long int continuemode, int iterlim) long int continuemode, int iterlim)
{ {
int converged, i, iters; int converged, i, iters;
double ConvFact; double ConvFact;
CKTnode *n; CKTnode *n;
@ -354,7 +356,7 @@ gillespie_src (CKTcircuit * ckt, long int firstmode,
ckt->CKTmode = firstmode; ckt->CKTmode = firstmode;
SPfrontEnd->IFerrorf (ERR_INFO, SPfrontEnd->IFerrorf (ERR_INFO,
"Starting source stepping");
"Starting source stepping");
ckt->CKTsrcFact = 0; ckt->CKTsrcFact = 0;
ConvFact = 0; ConvFact = 0;
@ -374,6 +376,7 @@ gillespie_src (CKTcircuit * ckt, long int firstmode,
if (converged != 0) { if (converged != 0) {
fprintf (stderr, "\n"); fprintf (stderr, "\n");
if (ckt->CKTgshunt <= 0) { if (ckt->CKTgshunt <= 0) {
ckt->CKTdiagGmin = ckt->CKTgmin; ckt->CKTdiagGmin = ckt->CKTgmin;
} else { } else {
@ -398,7 +401,7 @@ gillespie_src (CKTcircuit * ckt, long int firstmode,
if (converged != 0) { if (converged != 0) {
ckt->CKTdiagGmin = ckt->CKTgshunt; ckt->CKTdiagGmin = ckt->CKTgshunt;
SPfrontEnd->IFerrorf (ERR_WARNING, SPfrontEnd->IFerrorf (ERR_WARNING,
"gmin step failed");
"gmin step failed");
#ifdef XSPICE #ifdef XSPICE
/* gtri - begin - wbk - add convergence problem reporting flags */ /* gtri - begin - wbk - add convergence problem reporting flags */
ckt->enh->conv_debug.last_NIiter_call = MIF_FALSE; ckt->enh->conv_debug.last_NIiter_call = MIF_FALSE;
@ -410,7 +413,7 @@ gillespie_src (CKTcircuit * ckt, long int firstmode,
ckt->CKTdiagGmin /= 10; ckt->CKTdiagGmin /= 10;
ckt->CKTmode = continuemode; ckt->CKTmode = continuemode;
SPfrontEnd->IFerrorf (ERR_INFO, SPfrontEnd->IFerrorf (ERR_INFO,
"One successful gmin step");
"One successful gmin step");
} }
ckt->CKTdiagGmin = ckt->CKTgshunt; ckt->CKTdiagGmin = ckt->CKTgshunt;
} }
@ -435,29 +438,28 @@ gillespie_src (CKTcircuit * ckt, long int firstmode,
(size_t) ckt->CKTnumStates * sizeof(double)); (size_t) ckt->CKTnumStates * sizeof(double));
SPfrontEnd->IFerrorf (ERR_INFO, SPfrontEnd->IFerrorf (ERR_INFO,
"One successful source step");
"One successful source step");
ckt->CKTsrcFact = ConvFact + raise; ckt->CKTsrcFact = ConvFact + raise;
do { do {
fprintf (stderr, fprintf (stderr,
"Supplies reduced to %8.4f%% ", ckt->CKTsrcFact * 100); "Supplies reduced to %8.4f%% ", ckt->CKTsrcFact * 100);
#ifdef XSPICE #ifdef XSPICE
/* gtri - begin - wbk - add convergence problem reporting flags */ /* gtri - begin - wbk - add convergence problem reporting flags */
ckt->enh->conv_debug.last_NIiter_call = MIF_TRUE; ckt->enh->conv_debug.last_NIiter_call = MIF_TRUE;
/* gtri - end - wbk - add convergence problem reporting flags */ /* gtri - end - wbk - add convergence problem reporting flags */
#endif #endif
iters = ckt->CKTstat->STATnumIter; iters = ckt->CKTstat->STATnumIter;
converged = NIiter (ckt, ckt->CKTdcTrcvMaxIter); converged = NIiter (ckt, ckt->CKTdcTrcvMaxIter);
iters = ckt->CKTstat->STATnumIter - iters; iters = ckt->CKTstat->STATnumIter - iters;
ckt->CKTmode = continuemode; ckt->CKTmode = continuemode;
if (converged == 0) { if (converged == 0) {
ConvFact = ckt->CKTsrcFact; ConvFact = ckt->CKTsrcFact;
for (i = 0, n = ckt->CKTnodes; n; n = n->next) for (i = 0, n = ckt->CKTnodes; n; n = n->next)
OldRhsOld[i++] = ckt->CKTrhsOld[n->number]; OldRhsOld[i++] = ckt->CKTrhsOld[n->number];
@ -465,7 +467,7 @@ gillespie_src (CKTcircuit * ckt, long int firstmode,
(size_t) ckt->CKTnumStates * sizeof(double)); (size_t) ckt->CKTnumStates * sizeof(double));
SPfrontEnd->IFerrorf (ERR_INFO, SPfrontEnd->IFerrorf (ERR_INFO,
"One successful source step");
"One successful source step");
ckt->CKTsrcFact = ConvFact + raise; ckt->CKTsrcFact = ConvFact + raise;
@ -475,7 +477,9 @@ gillespie_src (CKTcircuit * ckt, long int firstmode,
if (iters > (3 * ckt->CKTdcTrcvMaxIter / 4)) if (iters > (3 * ckt->CKTdcTrcvMaxIter / 4))
raise *= 0.5; raise *= 0.5;
/* if (raise>0.01) raise=0.01; */
/* if (raise > 0.01)
* raise = 0.01;
*/
} else { } else {
@ -488,6 +492,7 @@ gillespie_src (CKTcircuit * ckt, long int firstmode,
raise = 0.01; raise = 0.01;
ckt->CKTsrcFact = ConvFact; ckt->CKTsrcFact = ConvFact;
for (i = 0, n = ckt->CKTnodes; n; n = n->next) for (i = 0, n = ckt->CKTnodes; n; n = n->next)
ckt->CKTrhsOld[n->number] = OldRhsOld[i++]; ckt->CKTrhsOld[n->number] = OldRhsOld[i++];
@ -510,11 +515,11 @@ gillespie_src (CKTcircuit * ckt, long int firstmode,
if (ConvFact != 1) { if (ConvFact != 1) {
ckt->CKTcurrentAnalysis = DOING_TRAN; ckt->CKTcurrentAnalysis = DOING_TRAN;
SPfrontEnd->IFerrorf (ERR_WARNING, SPfrontEnd->IFerrorf (ERR_WARNING,
"source stepping failed");
"source stepping failed");
return (E_ITERLIM); return (E_ITERLIM);
} else { } else {
SPfrontEnd->IFerrorf (ERR_INFO, SPfrontEnd->IFerrorf (ERR_INFO,
"Source stepping completed");
"Source stepping completed");
return (0); return (0);
} }
} }
@ -530,18 +535,18 @@ gillespie_src (CKTcircuit * ckt, long int firstmode,
* Note that no path out of this code allows ckt->CKTsrcFact to be * Note that no path out of this code allows ckt->CKTsrcFact to be
* anything but 1.00000. * anything but 1.00000.
*/ */
static int static int
spice3_src (CKTcircuit * ckt, long int firstmode,
spice3_src (CKTcircuit *ckt, long int firstmode,
long int continuemode, int iterlim) long int continuemode, int iterlim)
{ {
int converged, i; int converged, i;
NG_IGNORE(iterlim); NG_IGNORE(iterlim);
ckt->CKTmode = firstmode; ckt->CKTmode = firstmode;
SPfrontEnd->IFerrorf (ERR_INFO, SPfrontEnd->IFerrorf (ERR_INFO,
"Starting source stepping");
"Starting source stepping");
for (i = 0; i <= ckt->CKTnumSrcSteps; i++) { for (i = 0; i <= ckt->CKTnumSrcSteps; i++) {
ckt->CKTsrcFact = ((double) i) / ((double) ckt->CKTnumSrcSteps); ckt->CKTsrcFact = ((double) i) / ((double) ckt->CKTnumSrcSteps);
@ -556,7 +561,7 @@ spice3_src (CKTcircuit * ckt, long int firstmode,
ckt->CKTsrcFact = 1; ckt->CKTsrcFact = 1;
ckt->CKTcurrentAnalysis = DOING_TRAN; ckt->CKTcurrentAnalysis = DOING_TRAN;
SPfrontEnd->IFerrorf (ERR_WARNING, SPfrontEnd->IFerrorf (ERR_WARNING,
"source stepping failed");
"source stepping failed");
#ifdef XSPICE #ifdef XSPICE
/* gtri - begin - wbk - add convergence problem reporting flags */ /* gtri - begin - wbk - add convergence problem reporting flags */
ckt->enh->conv_debug.last_NIiter_call = MIF_FALSE; ckt->enh->conv_debug.last_NIiter_call = MIF_FALSE;
@ -565,15 +570,18 @@ spice3_src (CKTcircuit * ckt, long int firstmode,
return (converged); return (converged);
} }
SPfrontEnd->IFerrorf (ERR_INFO, SPfrontEnd->IFerrorf (ERR_INFO,
"One successful source step");
"One successful source step");
} }
SPfrontEnd->IFerrorf (ERR_INFO, SPfrontEnd->IFerrorf (ERR_INFO,
"Source stepping completed");
"Source stepping completed");
ckt->CKTsrcFact = 1; ckt->CKTsrcFact = 1;
#ifdef XSPICE #ifdef XSPICE
/* gtri - begin - wbk - add convergence problem reporting flags */ /* gtri - begin - wbk - add convergence problem reporting flags */
ckt->enh->conv_debug.last_NIiter_call = MIF_FALSE; ckt->enh->conv_debug.last_NIiter_call = MIF_FALSE;
/* gtri - end - wbk - add convergence problem reporting flags */ /* gtri - end - wbk - add convergence problem reporting flags */
#endif #endif
return (0); return (0);
} }
Loading…
Cancel
Save