spicelib/devices/{sw,csw}, #13/, improve SW/CSWtrunc()

shrink the timesteps down to CKTdelmin when aproaching a switchpoint,
but not any further.

fixme, thats not entirely save, consider lastChange==0 too !

Thanks to Alan Gillespie for pointing to this place.
This commit is contained in:
rlar 2018-03-28 17:26:39 +02:00
parent 624c523ad3
commit 21c4003dda
2 changed files with 12 additions and 8 deletions

View File

@ -27,9 +27,10 @@ CSWtrunc(GENmodel *inModel, CKTcircuit *ckt, double *timeStep)
ref = model->CSWiThreshold + fabs(model->CSWiHysteresis);
if (ckt->CKTstate0[here->CSWctrlvalue] < ref && lastChange > 0) {
maxChange =
(ref - ckt->CKTstate0[here->CSWctrlvalue]) * 0.75
+ 0.00005;
(ref - ckt->CKTstate0[here->CSWctrlvalue]) * 0.75;
maxStep = maxChange / lastChange * ckt->CKTdeltaOld[0];
if (maxStep < ckt->CKTdelmin)
maxStep = ckt->CKTdelmin;
if (*timeStep > maxStep)
*timeStep = maxStep;
}
@ -37,9 +38,10 @@ CSWtrunc(GENmodel *inModel, CKTcircuit *ckt, double *timeStep)
ref = model->CSWiThreshold - fabs(model->CSWiHysteresis);
if (ckt->CKTstate0[here->CSWctrlvalue] > ref && lastChange < 0) {
maxChange =
(ref - ckt->CKTstate0[here->CSWctrlvalue]) * 0.75
- 0.00005;
(ref - ckt->CKTstate0[here->CSWctrlvalue]) * 0.75;
maxStep = maxChange / lastChange * ckt->CKTdeltaOld[0];
if (maxStep < ckt->CKTdelmin)
maxStep = ckt->CKTdelmin;
if (*timeStep > maxStep)
*timeStep = maxStep;
}

View File

@ -27,9 +27,10 @@ SWtrunc(GENmodel *inModel, CKTcircuit *ckt, double *timeStep)
ref = model->SWvThreshold + fabs(model->SWvHysteresis);
if (ckt->CKTstate0[here->SWctrlvalue] < ref && lastChange > 0) {
maxChange =
(ref - ckt->CKTstate0[here->SWctrlvalue]) * 0.75
+ 0.05;
(ref - ckt->CKTstate0[here->SWctrlvalue]) * 0.75;
maxStep = maxChange / lastChange * ckt->CKTdeltaOld[0];
if (maxStep < ckt->CKTdelmin)
maxStep = ckt->CKTdelmin;
if (*timeStep > maxStep)
*timeStep = maxStep;
}
@ -37,9 +38,10 @@ SWtrunc(GENmodel *inModel, CKTcircuit *ckt, double *timeStep)
ref = model->SWvThreshold - fabs(model->SWvHysteresis);
if (ckt->CKTstate0[here->SWctrlvalue] > ref && lastChange < 0) {
maxChange =
(ref - ckt->CKTstate0[here->SWctrlvalue]) * 0.75
- 0.05;
(ref - ckt->CKTstate0[here->SWctrlvalue]) * 0.75;
maxStep = maxChange / lastChange * ckt->CKTdeltaOld[0];
if (maxStep < ckt->CKTdelmin)
maxStep = ckt->CKTdelmin;
if (*timeStep > maxStep)
*timeStep = maxStep;
}