14 #define M_PI 3.14159265 19 static double intlinfunc(
double,
double,
double,
double,
double,
double);
20 static double twiceintlinfunc(
double,
double,
double,
double,
double,
double,
double);
21 static double thriceintlinfunc(
double,
double,
double,
double,
double,
double,
double,
double);
22 static double bessI0(
double);
23 static double bessI1(
double);
24 static double bessXX(
double);
26 static double bessYY(
double,
double);
27 static double bessZZ(
double,
double);
66 double delta1, delta2;
67 double h1dummy1, h1dummy2;
68 double h2dummy1, h2dummy2;
69 double h3dummy1, h3dummy2;
70 double lolimit1, lolimit2, hilimit1, hilimit2;
71 double h1lovalue1, h1lovalue2, h1hivalue1, h1hivalue2;
72 double h2lovalue1, h2lovalue2, h2hivalue1, h2hivalue2;
73 double h3lovalue1, h3lovalue2, h3hivalue1, h3hivalue2;
74 double temp, temp2, temp3, temp4, temp5;
75 double h1relval, h2relval, h3relval;
76 int doh1 = 1, doh2 = 1, doh3 = 1;
79 auxindex = ckt->CKTtimeIndex;
83 delta1 = ckt->CKTtime - *(ckt->CKTtimePoints + auxindex);
89 h1dummy1 = h1hivalue1/delta1;
94 temp2 = (temp >= 100.0 ? 0.0 :
erfc(sqrt(temp)));
101 h2hivalue1 = (hilimit1 + model->
LTRArclsqr*0.5)*temp2 -
106 h2dummy1 = h2hivalue1/delta1;
111 if (hilimit1 != 0.0) {
112 temp = 2*sqrt(hilimit1/
M_PI)*temp3 - temp4*temp2;
113 h3hivalue1 = temp5*temp;
118 h3dummy1 = h3hivalue1/delta1;
124 for (i = auxindex; i > 0; i--) {
130 delta1 = *(ckt->CKTtimePoints + i) - *(ckt->CKTtimePoints + i - 1);
132 hilimit1 = ckt->CKTtime - *(ckt->CKTtimePoints + i - 1);
135 h1lovalue2 = h1lovalue1;
136 h1hivalue2 = h1hivalue1;
139 h1lovalue1 = h1hivalue2;
141 h1dummy1 = (h1hivalue1 - h1lovalue1)/delta1;
150 temp2 = (temp >= 100.0 ? 0.0 :
erfc(sqrt(temp)));
155 h2lovalue2 = h2lovalue1;
156 h2hivalue2 = h2hivalue1;
159 h2lovalue1 = h2hivalue2;
161 h2hivalue1 = (hilimit1 + model->
LTRArclsqr*0.5)*temp2 -
165 h2dummy1 = (h2hivalue1 - h2lovalue1)/delta1;
173 h3lovalue2 = h3lovalue1;
174 h3hivalue2 = h3hivalue1;
177 h3lovalue1 = h3hivalue2;
178 if (hilimit1 != 0.0) {
179 temp = 2*sqrt(hilimit1/
M_PI)*temp3 - temp4*temp2;
180 h3hivalue1 = temp5*temp;
184 h3dummy1 = (h3hivalue1 - h3lovalue1)/delta1;
202 double lolimit1, lolimit2, hilimit1, hilimit2;
203 double delta1, delta2;
204 double h1dummy1, h1dummy2;
205 double h1lovalue1, h1lovalue2, h1hivalue1, h1hivalue2;
206 double h2dummy1, h2dummy2;
207 double h2lovalue1, h2lovalue2, h2hivalue1, h2hivalue2;
208 double h3dummy1, h3dummy2;
209 double h3lovalue1, h3lovalue2, h3hivalue1, h3hivalue2;
210 double exparg, besselarg, bessi1overxterm, bessi0term;
211 double expbetaTterm, alphasqTterm;
212 double h1relval, h2relval, h3relval;
213 int doh1 = 1, doh2 = 1, doh3 = 1;
222 if (model->
LTRAtd == 0.0) {
223 auxindex = ckt->CKTtimeIndex;
227 if (ckt->CKTtime - model->
LTRAtd <= 0.0) {
232 for (i = ckt->CKTtimeIndex; i >= 0; i--) {
233 if (ckt->CKTtime - *(ckt->CKTtimePoints + i) ==
238 if (ckt->CKTtime - *(ckt->CKTtimePoints + i) >
243 if ((i < 0) || ((i == 0) && (exact == 1)))
244 printf(
"LTRAcoeffSetup: i <= 0: some mistake!\n");
259 hilimit1 = ckt->CKTtime - *(ckt->CKTtimePoints + auxindex);
260 delta1 = hilimit1 - lolimit1;
263 besselarg = (hilimit1 > model->
LTRAtd) ?
264 model->
LTRAalpha*sqrt(hilimit1*hilimit1 -
267 bessi1overxterm =
bessYY(besselarg, exparg);
271 alphasqTterm*bessi1overxterm;
274 h2hivalue1,lolimit1,hilimit1)/delta1;
279 bessi0term =
bessZZ(besselarg, exparg);
283 bessi0term - expbetaTterm;
284 h3dummy1 =
intlinfunc(lolimit1,hilimit1,h3lovalue1,
285 h3hivalue1,lolimit1,hilimit1)/delta1;
294 hilimit1 = ckt->CKTtime - *(ckt->CKTtimePoints + ckt->CKTtimeIndex);
295 delta1 = hilimit1 - lolimit1;
299 h1hivalue1 = (model->
LTRAbeta == 0.0)? hilimit1:
300 ((hilimit1 == 0.0) ? 0.0 :
bessXX(-exparg)*hilimit1 - hilimit1);
301 h1dummy1 = h1hivalue1/delta1;
308 for (i = ckt->CKTtimeIndex; i > 0; i--) {
310 if (doh1 || doh2 || doh3) {
316 hilimit1 = ckt->CKTtime - *(ckt->CKTtimePoints + i - 1);
318 *(ckt->CKTtimePoints + i) - *(ckt->CKTtimePoints + i - 1);
324 h1lovalue2 = h1lovalue1;
325 h1hivalue2 = h1hivalue1;
328 h1lovalue1 = h1hivalue2;
329 h1hivalue1 = (model->
LTRAbeta == 0.0)? hilimit1:
330 ((hilimit1 == 0.0) ? 0.0:
331 bessXX(-exparg)*hilimit1 - hilimit1);
332 h1dummy1 = (h1hivalue1 - h1lovalue1)/delta1;
343 besselarg = (hilimit1 > model->
LTRAtd) ?
344 model->
LTRAalpha*sqrt(hilimit1*hilimit1 -
348 h2lovalue2 = h2lovalue1;
349 h2hivalue2 = h2hivalue1;
352 h2lovalue1 = h2hivalue2;
353 bessi1overxterm =
bessYY(besselarg, exparg);
356 (hilimit1 < model->
LTRAtd)) ? 0.0 :
357 alphasqTterm*bessi1overxterm;
359 h2lovalue1,h2hivalue1,lolimit1,hilimit1)/delta1;
363 h2lovalue2,h2hivalue2,lolimit2,hilimit2);
370 h3lovalue2 = h3lovalue1;
371 h3hivalue2 = h3hivalue1;
374 h3lovalue1 = h3hivalue2;
375 bessi0term =
bessZZ(besselarg, exparg);
377 ((hilimit1 <= model->
LTRAtd) ||
379 bessi0term - expbetaTterm;
380 h3dummy1 =
intlinfunc(lolimit1,hilimit1,h3lovalue1,
381 h3hivalue1,lolimit1,hilimit1)/delta1;
402 double besselarg, exparg, returnval;
410 if (model->
LTRAalpha == 0.0)
return(0.0);
411 if (time < model->LTRAtd)
return(0.0);
413 if (time != model->
LTRAtd) {
431 double time,T,alpha,beta;
433 double exparg, besselarg, returnval;
441 if (alpha == 0.0)
return(0.0);
442 if (time < T)
return(0.0);
444 exparg = - beta*time;
446 besselarg = alpha*sqrt(time*time - T*T);
453 returnval *= alpha*exp(exparg);
471 double x1,y1,x2,y2,x3,y3,reltol,abstol;
474 double TRarea, QUADarea1,QUADarea2,QUADarea3, area;
483 TRarea =
FABS(QUADarea3 - QUADarea1 - QUADarea2);
484 area = QUADarea1 + QUADarea2;
485 if (area*reltol + abstol > TRarea)
495 #define SECONDDERIV(i,a,b,c) (oof = (i==ckt->CKTtimeIndex+1?curtime:\ 496 *(ckt->CKTtimePoints+i)),\ 497 (( c - b )/(oof-*(ckt->CKTtimePoints+i-1)) -\ 498 ( b - a )/(*(ckt->CKTtimePoints+i-1)-\ 499 *(ckt->CKTtimePoints+i-2)))/(oof - \ 500 *(ckt->CKTtimePoints+i-2))) 518 double h1dashTfirstCoeff;
519 double h2TfirstCoeff;
520 double h3dashTfirstCoeff;
523 double hilimit1, lolimit1, hivalue1, lovalue1, f1i, g1i;
524 double eq1LTE = 0.0, eq2LTE = 0.0;
525 int auxindex, tdover, i, exact;
535 if (curtime > model->
LTRAtd) {
539 for (i = ckt->CKTtimeIndex ; i>= 0; i--) {
540 if (curtime - *(ckt->CKTtimePoints + i) ==
545 if (curtime - *(ckt->CKTtimePoints + i)
551 if ((i < 0) || ((i==0) && (exact==1)))
552 printf(
"LTRAlteCalculate: i <= 0: some mistake!\n");
567 hilimit1 = curtime - *(ckt->CKTtimePoints + ckt->CKTtimeIndex);
573 g1i =
intlinfunc(lolimit1,hilimit1,lovalue1,hivalue1,
575 h1dashTfirstCoeff = 0.5 * f1i *
576 (curtime - *(ckt->CKTtimePoints+ckt->CKTtimeIndex)) - g1i;
579 hilimit1 = curtime - *(ckt->CKTtimePoints + auxindex);
580 lolimit1 = *(ckt->CKTtimePoints + ckt->CKTtimeIndex) -
581 *(ckt->CKTtimePoints + auxindex);
589 hivalue1,lolimit1,hilimit1);
591 lovalue1,hivalue1,lolimit1,hilimit1);
592 h2TfirstCoeff = 0.5*f1i*(curtime-model->
LTRAtd -
593 *(ckt->CKTtimePoints+auxindex)) - g1i;
599 f1i =
intlinfunc(lolimit1,hilimit1,lovalue1,hivalue1,
602 hivalue1,lolimit1,hilimit1);
603 h3dashTfirstCoeff = 0.5*f1i*(curtime - model->
LTRAtd -
604 *(ckt->CKTtimePoints+auxindex)) - g1i;
617 *(instance->
LTRAv1+ckt->CKTtimeIndex-1),
618 *(instance->
LTRAv1+ckt->CKTtimeIndex),
630 *(instance->
LTRAv1 + auxindex - 1),
631 *(instance->
LTRAv1 + auxindex),
632 *(instance->
LTRAv1 + auxindex + 1)) ;
643 *(instance->
LTRAv2+ckt->CKTtimeIndex-1),
644 *(instance->
LTRAv2+ckt->CKTtimeIndex),
654 *(instance->
LTRAv2 + auxindex - 1),
655 *(instance->
LTRAv2 + auxindex),
656 *(instance->
LTRAv2 + auxindex + 1)) ;
669 *(instance->
LTRAi1 + auxindex - 1),
670 *(instance->
LTRAi1 + auxindex),
671 *(instance->
LTRAi1 + auxindex + 1)) ;
673 eq2LTE +=
FABS(dashdash * h2TfirstCoeff);
682 *(instance->
LTRAi2 + auxindex - 1),
683 *(instance->
LTRAi2 + auxindex),
684 *(instance->
LTRAi2 + auxindex + 1)) ;
686 eq1LTE +=
FABS(dashdash * h2TfirstCoeff);
694 hilimit1 = curtime - *(ckt->CKTtimePoints + ckt->CKTtimeIndex);
701 g1i =
intlinfunc(lolimit1,hilimit1,lovalue1,hivalue1,lolimit1,
707 h2TfirstCoeff = 0.5*f1i*(curtime -
708 *(ckt->CKTtimePoints+ckt->CKTtimeIndex)) - g1i;
714 g1i =
intlinfunc(lolimit1,hilimit1,lovalue1,hivalue1,lolimit1,
716 h1dashTfirstCoeff = 0.5*f1i*(curtime -
717 *(ckt->CKTtimePoints+ckt->CKTtimeIndex)) - g1i;
724 hivalue1,lolimit1,hilimit1);
729 h3dashTfirstCoeff = 0.5*f1i*(curtime -
730 *(ckt->CKTtimePoints+ckt->CKTtimeIndex)) - g1i;
742 *(instance->
LTRAv1+ckt->CKTtimeIndex-1),
743 *(instance->
LTRAv1+ckt->CKTtimeIndex),
746 eq1LTE +=
FABS(dashdash * h1dashTfirstCoeff);
747 eq2LTE +=
FABS(dashdash * h3dashTfirstCoeff);
755 *(instance->
LTRAv2+ckt->CKTtimeIndex-1),
756 *(instance->
LTRAv2+ckt->CKTtimeIndex),
760 eq2LTE +=
FABS(dashdash * h1dashTfirstCoeff);
761 eq1LTE +=
FABS(dashdash * h3dashTfirstCoeff);
769 *(instance->
LTRAi1 + ckt->CKTtimeIndex - 1),
770 *(instance->
LTRAi1 + ckt->CKTtimeIndex),
771 *(ckt->CKTrhsOld + instance->
LTRAbrEq1));
773 eq2LTE +=
FABS(dashdash * h2TfirstCoeff);
781 *(instance->
LTRAi2 + ckt->CKTtimeIndex - 1),
782 *(instance->
LTRAi2 + ckt->CKTtimeIndex),
783 *(ckt->CKTrhsOld + instance->
LTRAbrEq2));
785 eq1LTE +=
FABS(dashdash * h2TfirstCoeff);
796 fprintf(stdout,
"%s: LTE/input for Eq1 at time %g is: %g\n",
798 fprintf(stdout,
"%s: LTE/input for Eq2 at time %g is: %g\n",
800 fprintf(stdout,
"\n");
803 return (
FABS(eq1LTE) +
FABS(eq2LTE));
817 double lolimit, hilimit, lovalue, hivalue, t1,t2;
822 if (width == 0.0)
return(0.0);
823 m = (hivalue - lovalue)/width;
825 return ((hilimit-lolimit)*lovalue + 0.5*m*((hilimit-t1)*(hilimit-t1)
826 - (lolimit - t1)*(lolimit - t1)));
840 double lolimit, hilimit, lovalue, hivalue, t1,t2, otherlolimit;
843 double temp1, temp2, temp3;
846 if (width == 0.0)
return(0.0);
847 m = (hivalue - lovalue)/width;
849 temp1 = hilimit - t1;
850 temp2 = lolimit - t1;
851 temp3 = otherlolimit - t1;
852 dummy = lovalue*((hilimit - otherlolimit)*(hilimit - otherlolimit) -
853 (lolimit - otherlolimit)*(lolimit - otherlolimit));
854 dummy += m*((temp1*temp1*temp1 - temp2*temp2*temp2)/3.0 -
855 temp3*temp3*(hilimit - lolimit));
871 double lolimit, hilimit, lovalue, hivalue, t1,t2, secondlolimit,
875 double temp1, temp2, temp3, temp4;
876 double temp5, temp6, temp7, temp8, temp9, temp10;
879 if (width == 0.0)
return(0.0);
880 m = (hivalue - lovalue)/width;
882 temp1 = hilimit - t1;
883 temp2 = lolimit - t1;
884 temp3 = secondlolimit - t1;
885 temp4 = thirdlolimit - t1;
886 temp5 = hilimit - thirdlolimit;
887 temp6 = lolimit - thirdlolimit;
888 temp7 = secondlolimit - thirdlolimit;
889 temp8 = hilimit - lolimit;
890 temp9 = hilimit - secondlolimit;
891 temp10 = lolimit - secondlolimit;
892 dummy = lovalue*((temp5*temp5*temp5 - temp6*temp6*temp6)/3 -
894 dummy += m*(((temp1*temp1*temp1*temp1 - temp2*temp2*temp2*temp2)*0.25 -
895 temp3*temp3*temp3*temp8)/3 - temp4*temp4*0.5*(temp9*temp9 -
915 if ((ax = fabs(x)) < 3.75) {
918 ans = 1.0+y*(3.5156229+y*(3.0899424+y*(1.2067492
919 +y*(0.2659732+y*(0.360768e-1+y*0.45813e-2)))));
923 ans = (exp(ax)/sqrt(ax))*(0.39894228+y*(0.1328592
e-1
924 +y*(0.225319
e-2+y*(-0.157565
e-2+y*(0.916281
e-2
925 +y*(-0.2057706
e-1+y*(0.2635537
e-1+y*(-0.1647633
e-1
926 +y*0.392377
e-2))))))));
969 double ans1 = 1.0+y*(3.5156229+y*(3.0899424+y*(1.2067492
970 +y*(0.2659732+y*(0.360768e-1+y*0.45813e-2)))));
971 double ans2 = ax*(0.5+y*(0.87890594+y*(0.51498869+y*(0.15084934
972 +y*(0.2658733e-1+y*(0.301532e-2+y*0.32411e-3))))));
977 return (ans1 * exp(-x));
981 double ans1 = (0.39894228+y*(0.1328592e-1
982 +y*(0.225319e-2+y*(-0.157565e-2+y*(0.916281e-2
983 +y*(-0.2057706e-1+y*(0.2635537e-1+y*(-0.1647633e-1
984 +y*0.392377e-2))))))));
985 double ans2 = 0.2282967e-1+y*(-0.2895312e-1+y*(0.1787654e-1
987 ans2 = 0.39894228+y*(-0.3988024e-1+y*(-0.362018e-2
988 +y*(0.163801e-2+y*(-0.1031555e-1+y*ans2))));
1007 if ((ax = fabs(x)) < 3.75) {
1010 ans = 0.5+y*(0.87890594+y*(0.51498869+y*(0.15084934
1011 +y*(0.2658733e-1+y*(0.301532e-2+y*0.32411e-3)))));
1015 ans = 0.2282967e-1+y*(-0.2895312e-1+y*(0.1787654e-1
1017 ans = 0.39894228+y*(-0.3988024e-1+y*(-0.362018e-2
1018 +y*(0.163801e-2+y*(-0.1031555e-1+y*ans))));
1019 ans *= (exp(ax)/(ax*sqrt(ax)));
1028 double ans, ax = fabs(x);
1032 ans = 0.5+y*(0.87890594+y*(0.51498869+y*(0.15084934
1033 +y*(0.2658733e-1+y*(0.301532e-2+y*0.32411e-3)))));
1038 ans = 0.2282967e-1+y*(-0.2895312e-1+y*(0.1787654e-1
1040 ans = 0.39894228+y*(-0.3988024e-1+y*(-0.362018e-2
1041 +y*(0.163801e-2+y*(-0.1031555e-1+y*ans))));
1042 ans *= (exp(ax + z)/(ax*sqrt(ax)));
1051 double ans, ax = fabs(x);
1055 ans = 1.0+y*(3.5156229+y*(3.0899424+y*(1.2067492
1056 +y*(0.2659732+y*(0.360768e-1+y*0.45813e-2)))));
1061 ans = (exp(ax + z)/sqrt(ax))*(0.39894228+y*(0.1328592
e-1
1062 +y*(0.225319
e-2+y*(-0.157565
e-2+y*(0.916281
e-2
1063 +y*(-0.2057706
e-1+y*(0.2635537
e-1+y*(-0.1647633
e-1
1064 +y*0.392377
e-2))))))));
1079 double arg, returnval;
1085 if (beta == 0.0)
return (time);
1087 if (arg == 0.0)
return (0.0);
1089 returnval = (
bessXX(arg)*time - time);
1101 double time, T, beta;
1103 double exparg, besselarg;
1106 if (time <= T)
return(0.0);
1107 if (beta == 0.0)
return(0.0);
1108 exparg = -beta*time;
1109 besselarg = beta*sqrt(time*time - T*T);
1110 returnval = (
bessZZ(besselarg, exparg) - exp(-beta*T));
1120 return (sqrt(4*cbyr*time/
M_PI));
1127 double time, rclsqr;
1132 temp = rclsqr/(4*time);
1133 return ((time + rclsqr*0.5)*
erfc(sqrt(temp)) -
1134 sqrt(time*rclsqr/
M_PI)*exp(-temp));
void LTRArcCoeffsSetup(CKTcircuit *ckt, GENmodel *InModel)
static double intlinfunc()
static double bessI1xOverX()
static double ltra_rlcH1dashTwiceIntFunc()
double LTRAh3dashFirstCoeff
static double ltra_rcH1dashTwiceIntFunc()
static double thriceintlinfunc()
static double ltra_rcH2TwiceIntFunc()
void LTRArlcCoeffsSetup(CKTcircuit *ckt, GENmodel *InModel)
double LTRArlcH3dashFunc(double time, double T, double alpha, double beta)
double LTRArlcH2Func(double time, GENmodel *InModel)
int LTRAstraightLineCheck(double x1, double y1, double x2, double y2, double x3, double y3, double reltol, double abstol)
double LTRAlteCalculate(CKTcircuit *ckt, GENmodel *genmodel, GENinstance *geninstance, double curtime)
double * LTRAh3dashCoeffs
static double ltra_rlcH3dashIntFunc()
static double twiceintlinfunc()
double * LTRAh1dashCoeffs
double LTRAh1dashFirstCoeff
#define SECONDDERIV(i, a, b, c)