alans proposal #1 for swtrunc.c, trying to avoid timestep too small

This commit is contained in:
alan 2018-02-24 19:18:09 +01:00 committed by rlar
parent 4da7e9a88b
commit ea29125518
1 changed files with 6 additions and 2 deletions

View File

@ -25,23 +25,27 @@ SWtrunc(GENmodel *inModel, CKTcircuit *ckt, double *timeStep)
ckt->CKTstates[1][here->SWstate + 1]; ckt->CKTstates[1][here->SWstate + 1];
if (ckt->CKTstates[0][here->SWstate + 0] == 0) { if (ckt->CKTstates[0][here->SWstate + 0] == 0) {
ref = (model->SWvThreshold + model->SWvHysteresis); ref = (model->SWvThreshold + model->SWvHysteresis);
if (ckt->CKTstates[0][here->SWstate + 1] < ref && lastChange > 0) if (ckt->CKTstates[0][here->SWstate + 1] < ref && lastChange > 1e-3)
{ {
maxChange = maxChange =
(ref - ckt->CKTstates[0][here->SWstate + 1]) * 0.75 (ref - ckt->CKTstates[0][here->SWstate + 1]) * 0.75
+ 0.05; + 0.05;
maxStep = maxChange / lastChange * ckt->CKTdeltaOld[0]; maxStep = maxChange / lastChange * ckt->CKTdeltaOld[0];
if (maxStep < ckt->CKTdelmin)
maxStep = ckt->CKTdelmin;
if (*timeStep > maxStep) if (*timeStep > maxStep)
*timeStep = maxStep; *timeStep = maxStep;
} }
} else { } else {
ref = model->SWvThreshold - model->SWvHysteresis; ref = model->SWvThreshold - model->SWvHysteresis;
if (ckt->CKTstates[0][here->SWstate + 1] > ref && lastChange < 0) if (ckt->CKTstates[0][here->SWstate + 1] > ref && lastChange < -1e-3)
{ {
maxChange = maxChange =
(ref - ckt->CKTstates[0][here->SWstate + 1]) * 0.75 (ref - ckt->CKTstates[0][here->SWstate + 1]) * 0.75
- 0.05; - 0.05;
maxStep = maxChange / lastChange * ckt->CKTdeltaOld[0]; maxStep = maxChange / lastChange * ckt->CKTdeltaOld[0];
if (maxStep < ckt->CKTdelmin)
maxStep = ckt->CKTdelmin;
if (*timeStep > maxStep) if (*timeStep > maxStep)
*timeStep = maxStep; *timeStep = maxStep;
} }