⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ltramisc.c

📁 spice中支持多层次元件模型仿真的可单独运行的插件源码
💻 C
📖 第 1 页 / 共 4 页
字号:
 * twiceintlinfunc(lolimit1,hilimit1,lolimit1,lovalue1,hivalue1, * lolimit1,hilimit1) + firstint1*(hilimit1-lolimit1); g1i = * thriceintlinfunc(lolimit1,hilimit1,lolimit1,lolimit1, * lovalue1,hivalue1,lolimit1,hilimit1) + * (hilimit1-lolimit1)*(hilimit1-lolimit1)*0.5*firstint1 + * (hilimit1-lolimit1)*secondint1; *  * (coefflist + i) = g2i - g1i + 0.5*(f1i + f2i)*(*(timelist+i) - * (timelist+i-1)); } } auxindexptr = auxindex; return(returnval); } *//* * formulae taken from the Handbook of Mathematical Functions by Milton * Abramowitz and Irene A. Stegan, page 378, formulae 9.8.1 - 9.8.4 *//* * double bessi0(x) double x; { double t, tsq, oneovert, result, dummy; int i; * static double coeffs1[7], coeffs2[9]; *  * coeffs1[0] = 1.0; coeffs1[1] = 3.5156229; coeffs1[2] = 3.0899424; coeffs1[3] * = 1.2067492; coeffs1[4] = 0.2659732; coeffs1[5] = 0.0360768; coeffs1[6] = * 0.0045813; *  * coeffs2[0] = 0.39894228; coeffs2[1] = 0.01328592; coeffs2[2] = 0.00225319; * coeffs2[3] = -0.00157565; coeffs2[4] = 0.00916281; coeffs2[5] = * -0.02057706; coeffs2[6] = 0.02635537; coeffs2[7] = -0.01647633; coeffs2[8] * = 0.00392377; *  * t = x/3.75; dummy = 1.0; *  * if (fabs(t) <= 1) { tsq = t*t; *  * result = 1.0; for (i=1;i<=6;i++) { dummy *= tsq; ; result += dummy * * coeffs1[i]; } } else { oneovert = 1/fabs(t); *  * result = coeffs2[0]; for (i=1;i<=8;i++) { dummy *= oneovert; result += * coeffs2[2] * dummy; } result *= exp(x) * sqrt(1/fabs(x)); } * return(result); } *  * double bessi1(x) double x; { double t, tsq, oneovert, result, dummy; int i; * static double coeffs1[7], coeffs2[9]; *  * coeffs1[0] = 0.5; coeffs1[1] = 0.87890594; coeffs1[2] = 0.51498869; * coeffs1[3] = 0.15084934; coeffs1[4] = 0.02658733; coeffs1[5] = 0.00301532; * coeffs1[6] = 0.00032411; *  * coeffs2[0] = 0.39894228; coeffs2[1] = -0.03988024; coeffs2[2] = -0.00362018; * coeffs2[3] = 0.00163801; coeffs2[4] = -0.01031555; coeffs2[5] = * 0.02282967; coeffs2[6] = -0.02895312; coeffs2[7] = 0.01787654; coeffs2[8] * = -0.00420059; *  * t = x/3.75; dummy = 1.0; *  * if (fabs(t) <= 1) { tsq = t*t; *  * result = 0.5; for (i=1;i<=6;i++) { dummy *= tsq; ; result += dummy * * coeffs1[i]; } result *= x; } else { oneovert = 1/fabs(t); *  * result = coeffs2[0]; for (i=1;i<=8;i++) { dummy *= oneovert; result += * coeffs2[2] * dummy; } result *= exp(x) * sqrt(1/fabs(x)); if (x < 0) * result = -result; } return(result); } *//* * LTRAdivDiffs returns divided differences after 2 iterations, an * approximation to the second derivatives. The algorithm is picked up * directly from Tom Quarles' CKTterr.c; no attempt has been made to figure * out why it does what it does. *//* * double LTRAdivDiffs(difflist, valuelist, firstvalue, curtime, timelist, * timeindex) double *difflist, *valuelist, firstvalue,  *timelist, curtime; * int timeindex; *  * { double *dtime, *diffs, returnval; int i,j; *  * diffs = (double *) MALLOC(sizeof(double) * (timeindex+2)); dtime = (double *) * MALLOC(sizeof(double) * (timeindex+2)); *//* now divided differences *//* * for(i=timeindex+1;i>=0;i--) { (diffs+i) = (i == timeindex+1 ? firstvalue : * *(valuelist + i)); } for(i=timeindex+1 ; i > 0 ; i--) { (dtime+i) = (i == * timeindex+1? curtime: *(timelist + i)) - (timelist + i - 1); } j = 2; *//* for the second derivative *//* * while(1) { for(i=timeindex + 1;i > 0; i--) { (diffs+i) = (*(diffs+i) - * *(diffs+i-1))/ *(dtime+i); } j--; if (j <= 0) break; for(i=timeindex+1;i > * 0;i--) { (dtime+i) = *(dtime+i-1) + (i == timeindex+1? curtime: *(timelist * + i)) - *(timelist + i - 1); } } *  * for (i = timeindex; i>=0 ; i--) { (difflist+i) = *(diffs+i); } *  * returnval = *(diffs+timeindex+1); FREE(dtime); FREE(diffs); *//* difflist[0] is going to be bad *//* * return(returnval); } *//* * LTRAlteCalculate - returns sum of the absolute values of the total local * truncation error of the 2 equations for the LTRAline *//* * double LTRAlteCalculate(ckt,model,instance,curtime) register CKTcircuit *ckt; * register LTRAmodel *model; register LTRAinstance *instance; double * curtime; *  * { double *h1dashTcoeffs, h1dashTfirstCoeff; double *h2Tcoeffs, h2TfirstCoeff; * double *h3dashTcoeffs, h3dashTfirstCoeff; double *SecondDerivs, * FirstSecondDeriv; double t1, t2, t3, f1, f2, f3; double eq1LTE=0.0, * eq2LTE=0.0; int isaved, tdover, i; *  * if (curtime > model->LTRAtd) { tdover = 1; } else { tdover = 0; } *  * h1dashTcoeffs = (double *) MALLOC(sizeof(double) * model->LTRAmodelListSize); * h2Tcoeffs = (double *) MALLOC(sizeof(double) * model->LTRAmodelListSize); * h3dashTcoeffs = (double *) MALLOC(sizeof(double) * * model->LTRAmodelListSize); SecondDerivs = (double *) MALLOC(sizeof(double) * * model->LTRAmodelListSize); *  *//* * note that other OthVals have been set up in LTRAaccept, and Values in * LTRAload *//* * h1dashTfirstCoeff = LTRAtCoeffSetup(h1dashTcoeffs, * model->LTRAmodelListSize, 0.0, model->LTRAh1dashValues, * model->LTRAh1dashFirstVal, model->LTRAh1dashOthVals, curtime, * ckt->CKTtimePoints,ckt->CKTtimeIndex, &(model->LTRAh1dashIndex), * model->LTRAlteConType); *  * if (tdover) { *  * h2TfirstCoeff = LTRAtCoeffSetup(h2Tcoeffs, model->LTRAmodelListSize, * model->LTRAtd, model->LTRAh2Values, model->LTRAh2FirstOthVal, * model->LTRAh2OthVals, curtime, ckt->CKTtimePoints, ckt->CKTtimeIndex, * &(model->LTRAh2Index), model->LTRAlteConType); *  * h3dashTfirstCoeff = LTRAtCoeffSetup(h3dashTcoeffs, model->LTRAmodelListSize, * model->LTRAtd, model->LTRAh3dashValues, model->LTRAh3dashFirstOthVal, * model->LTRAh3dashOthVals, curtime, ckt->CKTtimePoints,ckt->CKTtimeIndex, * &(model->LTRAh3dashIndex), model->LTRAlteConType); *//* setting up the coefficients for interpolation *//* * for (i = ckt->CKTtimeIndex; i>= 0; i--) { if (*(ckt->CKTtimePoints + i) < * curtime - model->LTRAtd) { break; } } #ifdef LTRAdebug if (i == * ckt->CKTtimeIndex) || (i == -1) { printf("LTRAtrunc: mistake: cannot find * delayed timepoint\n"); } #endif t1 = *(ckt->CKTtimePoints + i - 1); t2 = * *(ckt->CKTtimePoints + i); t3 = *(ckt->CKTtimePoints + i + 1); *  * LTRAquadInterp(curtime - model->LTRAtd, t1,t2,t3,&f1,&f2,&f3); *  * isaved = i; } *//* interpolation coefficients set-up *//* LTEs for convolution with v1 *//* get divided differences for v1 (2nd derivative estimates) *//* * no need to subtract operating point values because taking differences * anyway *//* * FirstSecondDeriv = LTRAdivDiffs(SecondDerivs,instance->LTRAv1, * (ckt->CKTrhsOld + instance->LTRAposNode1) - *(ckt->CKTrhsOld + * instance->LTRAnegNode1),curtime, ckt->CKTtimePoints,ckt->CKTtimeIndex); *  * eq1LTE += model->LTRAadmit*FABS(FirstSecondDeriv * h1dashTfirstCoeff); *  * if (model->LTRAlteConType != LTRA_MOD_HALFCONTROL) { for (i = * model->LTRAh1dashIndex; i > 0; i--) { if ((*(SecondDerivs+i) != 0.0) && * (*(h1dashTcoeffs+i)!=0.0)) { eq1LTE += * model->LTRAadmit*FABS(*(SecondDerivs+i) * (h1dashTcoeffs+i)); } } } *  *//* interpolate *//* * if (tdover) { *  * FirstSecondDeriv = *(SecondDerivs + isaved - 1) * f1 + *(SecondDerivs + * isaved) * f2 + *(SecondDerivs + isaved + 1) * f3; *  * eq2LTE += model->LTRAadmit*FABS(FirstSecondDeriv * h3dashTfirstCoeff); *  * if (model->LTRAlteConType != LTRA_MOD_HALFCONTROL) { for (i = * model->LTRAh3dashIndex; i > 0; i--) { if ((*(SecondDerivs+i) != 0.0) && * (*(h3dashTcoeffs+i)!=0.0)) { eq2LTE += * model->LTRAadmit*FABS(*(SecondDerivs+i) * (h3dashTcoeffs+i)); } } } } *//* end LTEs for convolution with v1 *//* LTEs for convolution with v2 *//* get divided differences for v2 (2nd derivative estimates) *//* * FirstSecondDeriv = LTRAdivDiffs(SecondDerivs,instance->LTRAv2, * (ckt->CKTrhsOld + instance->LTRAposNode2) - *(ckt->CKTrhsOld + * instance->LTRAnegNode2),curtime, ckt->CKTtimePoints,ckt->CKTtimeIndex); *  * eq2LTE += model->LTRAadmit*FABS(FirstSecondDeriv * h1dashTfirstCoeff); *  * if (model->LTRAlteConType != LTRA_MOD_HALFCONTROL) { for (i = * model->LTRAh1dashIndex; i > 0; i--) { if ((*(SecondDerivs+i) != 0.0) && * (*(h1dashTcoeffs+i)!=0.0)) { eq2LTE += * model->LTRAadmit*FABS(*(SecondDerivs+i) * (h1dashTcoeffs+i)); } } } *  * if (tdover) { *//* interpolate *//* * FirstSecondDeriv = *(SecondDerivs + isaved - 1) * f1 + *(SecondDerivs + * isaved) * f2 + *(SecondDerivs + isaved + 1) * f3; *  * eq1LTE += model->LTRAadmit*FABS(FirstSecondDeriv * h3dashTfirstCoeff); *  * if (model->LTRAlteConType != LTRA_MOD_HALFCONTROL) { for (i = * model->LTRAh3dashIndex; i > 0; i--) { if ((*(SecondDerivs+i) != 0.0) && * (*(h3dashTcoeffs+i)!=0.0)) { eq1LTE += * model->LTRAadmit*FABS(*(SecondDerivs+i) * (h3dashTcoeffs+i)); } } } } *  *//* end LTEs for convolution with v2 *//* LTE for convolution with i1 *//* get divided differences for i1 (2nd derivative estimates) *//* * if (tdover) { FirstSecondDeriv = * LTRAdivDiffs(SecondDerivs,instance->LTRAi1, (ckt->CKTrhsOld + * instance->LTRAbrEq1),curtime, ckt->CKTtimePoints,ckt->CKTtimeIndex); *  *//* interpolate *//* * FirstSecondDeriv = *(SecondDerivs + isaved - 1) * f1 + *(SecondDerivs + * isaved) * f2 + *(SecondDerivs + isaved + 1) * f3; *  * eq2LTE += FABS(FirstSecondDeriv * h2TfirstCoeff); *  * if (model->LTRAlteConType != LTRA_MOD_HALFCONTROL) { for (i = * model->LTRAh2Index; i > 0; i--) { if ((*(SecondDerivs+i) != 0.0) && * (*(h2Tcoeffs+i)!=0.0)) { eq2LTE += model->LTRAadmit*FABS(*(SecondDerivs+i) * * (h2Tcoeffs+i)); } } } *  * } *//* end LTE for convolution with i1 *//* LTE for convolution with i2 *//* get divided differences for i2 (2nd derivative estimates) *//* * if (tdover) { FirstSecondDeriv = * LTRAdivDiffs(SecondDerivs,instance->LTRAi2, (ckt->CKTrhsOld + * instance->LTRAbrEq2),curtime, ckt->CKTtimePoints,ckt->CKTtimeIndex); *  *//* interpolate *//* * FirstSecondDeriv = *(SecondDerivs + isaved - 1) * f1 + *(SecondDerivs + * isaved) * f2 + *(SecondDerivs + isaved + 1) * f3; *  * eq1LTE += FABS(FirstSecondDeriv * h2TfirstCoeff); *  * if (model->LTRAlteConType != LTRA_MOD_HALFCONTROL) { for (i = * model->LTRAh2Index; i > 0; i--) { if ((*(SecondDerivs+i) != 0.0) && * (*(h2Tcoeffs+i)!=0.0)) { eq1LTE += model->LTRAadmit*FABS(*(SecondDerivs+i) * * (h2Tcoeffs+i)); } } } } *  *//* end LTE for convolution with i1 */#ifdef LTRADEBUG/* * fprintf(stdout,"%s: LTE/input for Eq1 at time %g is: %g\n", * instance->LTRAname, curtime, eq1LTE/instance->LTRAinput1); * fprintf(stdout,"%s: LTE/input for Eq2 at time %g is: %g\n", * instance->LTRAname, curtime, eq2LTE/instance->LTRAinput1); * fprintf(stdout,"\n"); */#endif/* * FREE(SecondDerivs); FREE(h1dashTcoeffs); FREE(h2Tcoeffs); * FREE(h3dashTcoeffs); *  * return(FABS(eq1LTE) + FABS(eq2LTE)); } *//* * LTRAh3dashCoeffSetup sets up the coefficient list for h3dash for the * special case where G=0, * returns the coefficient at (current_timepoint-T) *//* * double * LTRAh3dashCoeffSetup(coefflist,listsize,T,beta,curtime,timelist,timeindex,a * uxindexptr) double *coefflist, *timelist; int listsize, timeindex; double * T, curtime, beta; int *auxindexptr; *  * { unsigned exact; double returnval, delta1, delta2; double dummy1, dummy2; * double lolimit1,lolimit2,hilimit1,hilimit2; double * lovalue1,lovalue2,hivalue1,hivalue2; int i,auxindex; *  *//* coefflist should already have been allocated to the necessary size *//* * #ifdef LTRAdebug if (listsize <= timeindex) { printf("LTRAcoeffSetup: not * enough space in coefflist\n"); } #endif *  *  *//* * we assume a piecewise linear function, and we calculate the coefficients * using this assumption in the integration of the function *//* * if (T == 0.0) { auxindex = timeindex; } else { *  * if (curtime - T <= 0.0) { for (i =0; i<= timeindex; i++) { (coefflist + i) = * 0.0; } auxindexptr = 0; return(0.0); } else { exact = 0; for (i = * timeindex; i>= 0; i--) { if (curtime - *(timelist + i) ==  T) { exact =1; * break; } if (curtime - *(timelist + i) > T) break; } *  * #ifdef LTRADEBUG if ((i < 0) || ((i==0) && (exact==1))) * printf("LTRAcoeffSetup: i <= 0: some mistake!\n"); #endif *  * if (exact == 1) { auxindex = i-1; } else { auxindex = i; } } } *//* the first coefficient *//* * delta1 = curtime -T - *(timelist + auxindex); lolimit1 = T; hilimit1 = T + * delta1; lovalue1 = 0.0; *//* E3dash should be consistent with this *//* * hivalue1 = LTRArlcH3dashIntFunc(hilimit1,T,beta); dummy1 = * intlinfunc(lolimit1,hilimit1,lovalue1, hivalue1,lolimit1,hilimit1)/delta1; * returnval = dummy1; *  *  *//* the coefficients for the rest of the timepoints *//* * for (i=auxindex; i>0; i--) { *  * delta2 = delta1; *//* previous delta1 *//* lolimit2 = lolimit1; *//* previous lolimit1 *//* hilimit2 = hilimit1; *//* previous hilimit1 *//* lovalue2 = lovalue1; *//* previous lovalue1 *//* hivalue2 = hivalue1; *//* previous hivalue1 *//* dummy2 = dummy1; *//* previous dummy1 *//* * delta1 = *(timelist + i) - *(timelist + i - 1); lolimit1 = hilimit2; * hilimit1 = curtime - *(timelist + i - 1); lovalue1 = hivalue2; hivalue1 = * LTRArlcH3dashIntFunc(hilimit1,T,beta); dummy1 = * intlinfunc(lolimit1,hilimit1,lovalue1,hivalue1,lolimit1,hilimit1)/delta1; *  * (coefflist + i) = dummy1 - dummy2; } auxindexptr = auxindex; * return(returnval); } *//* * LTRAh1dashCoeffSetup sets up the coefficient list for h1dash in the * special case where G=0 returns the coefficient at current_timepoint *//* * double * LTRAh1dashCoeffSetup(coefflist,listsize,beta,curtime,timelist,timeindex,aux * indexptr) double *coefflist, *timelist; int listsize, timeindex; double * beta, curtime; int *auxindexptr; *  * { double returnval, delta1, delta2; double dummy1, dummy2; double * lolimit1,lolimit2,hilimit1,hilimit2; double * lovalue1,lovalue2,hivalue1,hivalue2; int i,auxindex; *  *//* coefflist should already have been allocated to the necessary size *//* * #ifdef LTRAdebug if (listsize <= timeindex) { * printf("LTRAh1dashCoeffSetup: not enough space in coefflist\n"); } #endif *  *  *  * auxindex = timeindex; *  *//* the first coefficient *//* * delta1 = curtime - *(timelist + auxindex); lolimit1 = 0.0; hilimit1 = * delta1; lovalue1 = 0.0; hivalue1 = * LTRArlcH1dashTwiceIntFunc(hilimit1,beta); dummy1 = hivalue1/delta1; * returnval = dummy1; *  *  *  *//* the coefficients for the rest of the timepoints *//* * for (i=auxindex; i>0; i--) { *  * delta2 = delta1; *//* previous delta1 *//* lolimit2 = lolimit1; *//* previous lolimit1 *//* hilimit2 = hilimit1; *//* previous hilimit1 *//* lovalue2 = lovalue1; *//* previous lovalue1 *//* hivalue2 = hivalue1; *//* previous hivalue1 *//* dummy2 = dummy1; *//* previous dummy1 *//* * delta1 = *(timelist + i) - *(timelist + i - 1); lolimit1 = hilimit2; * hilimit1 = curtime - *(timelist + i - 1); lovalue1 = hivalue2; hivalue1 = * LTRArlcH1dashTwiceIntFunc(hilimit1,beta); dummy1 = (hivalue1 - * lovalue1)/delta1; *  * (coefflist + i) = dummy1 - dummy2; } auxindexptr = auxindex; * return(returnval); } */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -