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

📄 ltramisc.c

📁 spice中支持多层次元件模型仿真的可单独运行的插件源码
💻 C
📖 第 1 页 / 共 4 页
字号:
  case LTRA_MOD_RLC:    if (curtime > model->LTRAtd) {      tdover = 1;      exact = 0;      for (i = ckt->CKTtimeIndex; i >= 0; i--) {	if (curtime - *(ckt->CKTtimePoints + i)	    == model->LTRAtd) {	  exact = 1;	  break;	}	if (curtime - *(ckt->CKTtimePoints + i)	    > model->LTRAtd)	  break;      }#ifdef LTRADEBUG      if ((i < 0) || ((i == 0) && (exact == 1)))	printf("LTRAlteCalculate: i <= 0: some mistake!\n");#endif      if (exact == 1) {	auxindex = i - 1;      } else {	auxindex = i;      }    } else {      tdover = 0;    }    hilimit1 = curtime - *(ckt->CKTtimePoints + ckt->CKTtimeIndex);    lolimit1 = 0.0;    hivalue1 = LTRArlcH1dashTwiceIntFunc(hilimit1, model->LTRAbeta);    lovalue1 = 0.0;    f1i = hivalue1;    g1i = intlinfunc(lolimit1, hilimit1, lovalue1, hivalue1,	lolimit1, hilimit1);    h1dashTfirstCoeff = 0.5 * f1i *	(curtime - *(ckt->CKTtimePoints + ckt->CKTtimeIndex)) - g1i;    if (tdover) {      hilimit1 = curtime - *(ckt->CKTtimePoints + auxindex);      lolimit1 = *(ckt->CKTtimePoints + ckt->CKTtimeIndex) - *(ckt->CKTtimePoints + auxindex);      lolimit1 = MAX(model->LTRAtd, lolimit1);      /*       * are the following really doing the operations in the write-up?       */      hivalue1 = LTRArlcH2Func(hilimit1, model->LTRAtd, model->LTRAalpha, model->LTRAbeta);      lovalue1 = LTRArlcH2Func(lolimit1, model->LTRAtd, model->LTRAalpha, model->LTRAbeta);      f1i = twiceintlinfunc(lolimit1, hilimit1, lolimit1, lovalue1, hivalue1, lolimit1,	  hilimit1);      g1i = thriceintlinfunc(lolimit1, hilimit1, lolimit1, lolimit1, lovalue1,	  hivalue1, lolimit1, hilimit1);      h2TfirstCoeff = 0.5 * f1i * (curtime - model->LTRAtd - *(ckt->CKTtimePoints + auxindex)) - g1i;      hivalue1 = LTRArlcH3dashIntFunc(hilimit1, model->LTRAtd, model->LTRAbeta);      lovalue1 = LTRArlcH3dashIntFunc(lolimit1, model->LTRAtd, model->LTRAbeta);      f1i = intlinfunc(lolimit1, hilimit1, lovalue1, hivalue1, lolimit1,	  hilimit1);      g1i = twiceintlinfunc(lolimit1, hilimit1, lolimit1, lovalue1,	  hivalue1, lolimit1, hilimit1);      h3dashTfirstCoeff = 0.5 * f1i * (curtime - model->LTRAtd - *(ckt->CKTtimePoints + auxindex)) - g1i;    }    /* LTEs for convolution with v1 */    /* get divided differences for v1 (2nd derivative estimates) */    /*     * no need to subtract operating point values because taking differences     * anyway     */    dashdash = SECONDDERIV(ckt->CKTtimeIndex + 1,	*(instance->LTRAv1 + ckt->CKTtimeIndex - 1),	*(instance->LTRAv1 + ckt->CKTtimeIndex),	*(ckt->CKTrhsOld + instance->LTRAposNode1) -	*(ckt->CKTrhsOld + instance->LTRAnegNode1));    eq1LTE += model->LTRAadmit * FABS(dashdash *	h1dashTfirstCoeff);    /*     * not bothering to interpolate since everything is approximate anyway     */    if (tdover) {      dashdash = SECONDDERIV(auxindex + 1,	  *(instance->LTRAv1 + auxindex - 1),	  *(instance->LTRAv1 + auxindex),	  *(instance->LTRAv1 + auxindex + 1));      eq2LTE += model->LTRAadmit * FABS(dashdash *	  h3dashTfirstCoeff);    }    /* end LTEs for convolution with v1 */    /* LTEs for convolution with v2 */    /* get divided differences for v2 (2nd derivative estimates) */    dashdash = SECONDDERIV(ckt->CKTtimeIndex + 1,	*(instance->LTRAv2 + ckt->CKTtimeIndex - 1),	*(instance->LTRAv2 + ckt->CKTtimeIndex),	*(ckt->CKTrhsOld + instance->LTRAposNode2) -	*(ckt->CKTrhsOld + instance->LTRAnegNode2));    eq2LTE += model->LTRAadmit * FABS(dashdash *	h1dashTfirstCoeff);    if (tdover) {      dashdash = SECONDDERIV(auxindex + 1,	  *(instance->LTRAv2 + auxindex - 1),	  *(instance->LTRAv2 + auxindex),	  *(instance->LTRAv2 + auxindex + 1));      eq1LTE += model->LTRAadmit * FABS(dashdash *	  h3dashTfirstCoeff);    }    /* end LTEs for convolution with v2 */    /* LTE for convolution with i1 */    /* get divided differences for i1 (2nd derivative estimates) */    if (tdover) {      dashdash = SECONDDERIV(auxindex + 1,	  *(instance->LTRAi1 + auxindex - 1),	  *(instance->LTRAi1 + auxindex),	  *(instance->LTRAi1 + auxindex + 1));      eq2LTE += FABS(dashdash * h2TfirstCoeff);    }    /* end LTE for convolution with i1 */    /* LTE for convolution with i2 */    /* get divided differences for i2 (2nd derivative estimates) */    if (tdover) {      dashdash = SECONDDERIV(auxindex + 1,	  *(instance->LTRAi2 + auxindex - 1),	  *(instance->LTRAi2 + auxindex),	  *(instance->LTRAi2 + auxindex + 1));      eq1LTE += FABS(dashdash * h2TfirstCoeff);    }    /* end LTE for convolution with i1 */    break;  case LTRA_MOD_RC:    hilimit1 = curtime - *(ckt->CKTtimePoints + ckt->CKTtimeIndex);    lolimit1 = 0.0;    hivalue1 = LTRArcH1dashTwiceIntFunc(hilimit1, model->LTRAcByR);    lovalue1 = 0.0;    f1i = hivalue1;    g1i = intlinfunc(lolimit1, hilimit1, lovalue1, hivalue1, lolimit1, hilimit1);    h1dashTfirstCoeff = 0.5 * f1i * (curtime - *(ckt->CKTtimePoints + ckt->CKTtimeIndex)) - g1i;    hivalue1 = LTRArcH2TwiceIntFunc(hilimit1, model->LTRArclsqr);    lovalue1 = 0.0;    f1i = hivalue1;    g1i = intlinfunc(lolimit1, hilimit1, lovalue1, hivalue1, lolimit1, hilimit1);    h1dashTfirstCoeff = 0.5 * f1i * (curtime - *(ckt->CKTtimePoints + ckt->CKTtimeIndex)) - g1i;    hivalue1 = LTRArcH2TwiceIntFunc(hilimit1, model->LTRArclsqr);    lovalue1 = 0.0;    f1i = hivalue1;    g1i = intlinfunc(lolimit1, hilimit1, lovalue1,	hivalue1, lolimit1, hilimit1);    h1dashTfirstCoeff = 0.5 * f1i * (curtime -	*(ckt->CKTtimePoints + ckt->CKTtimeIndex)) - g1i;    /* LTEs for convolution with v1 */    /* get divided differences for v1 (2nd derivative estimates) */    /*     * no need to subtract operating point values because taking differences     * anyway     */    dashdash = SECONDDERIV(ckt->CKTtimeIndex + 1,	*(instance->LTRAv1 + ckt->CKTtimeIndex - 1),	*(instance->LTRAv1 + ckt->CKTtimeIndex),	*(ckt->CKTrhsOld + instance->LTRAposNode1) -	*(ckt->CKTrhsOld + instance->LTRAnegNode1));    eq1LTE += FABS(dashdash * h1dashTfirstCoeff);    eq2LTE += FABS(dashdash * h3dashTfirstCoeff);    /* end LTEs for convolution with v1 */    /* LTEs for convolution with v2 */    /* get divided differences for v2 (2nd derivative estimates) */    dashdash = SECONDDERIV(ckt->CKTtimeIndex + 1,	*(instance->LTRAv2 + ckt->CKTtimeIndex - 1),	*(instance->LTRAv2 + ckt->CKTtimeIndex),	*(ckt->CKTrhsOld + instance->LTRAposNode2) -	*(ckt->CKTrhsOld + instance->LTRAnegNode2));    eq2LTE += FABS(dashdash * h1dashTfirstCoeff);    eq1LTE += FABS(dashdash * h3dashTfirstCoeff);    /* end LTEs for convolution with v2 */    /* LTE for convolution with i1 */    /* get divided differences for i1 (2nd derivative estimates) */    dashdash = SECONDDERIV(ckt->CKTtimeIndex + 1,	*(instance->LTRAi1 + ckt->CKTtimeIndex - 1),	*(instance->LTRAi1 + ckt->CKTtimeIndex),	*(ckt->CKTrhsOld + instance->LTRAbrEq1));    eq2LTE += FABS(dashdash * h2TfirstCoeff);    /* end LTE for convolution with i1 */    /* LTE for convolution with i2 */    /* get divided differences for i2 (2nd derivative estimates) */    dashdash = SECONDDERIV(ckt->CKTtimeIndex + 1,	*(instance->LTRAi2 + ckt->CKTtimeIndex - 1),	*(instance->LTRAi2 + ckt->CKTtimeIndex),	*(ckt->CKTrhsOld + instance->LTRAbrEq2));    eq1LTE += FABS(dashdash * h2TfirstCoeff);    /* end LTE for convolution with i1 */    break;  default:    return (1 /* error */ );  }#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  return (FABS(eq1LTE) + FABS(eq2LTE));}/*********************************************************************//****************** old stuff, retained for historical interest ******//*********************************************************************//* * LTRAcoeffSetup sets up the coefficient list for the convolution, returns * the coefficient at (current_timepoint-T) *//* * double * LTRAcoeffSetup(coefflist,listsize,T,firstvalue,valuelist,curtime,timelist,t * imeindex,auxindexptr) double *coefflist, *timelist, *valuelist; int * listsize, timeindex; double T, firstvalue, curtime; 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 = firstvalue; hivalue1 = *(valuelist + auxindex); dummy1 * = twiceintlinfunc(lolimit1,hilimit1,lolimit1,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 = * *(valuelist + i - 1); dummy1 = twiceintlinfunc(lolimit1,hilimit1,lolimit1, * lovalue1,hivalue1,lolimit1,hilimit1)/delta1; *  * (coefflist + i) = dummy1 - dummy2 + intlinfunc(lolimit2,hilimit2, * lovalue2,hivalue2,lolimit2,hilimit2); } auxindexptr = auxindex; * return(returnval); } *//* * LTRAtCoeffSetup sets up the coefficient list for the LTE calculation, * returns the coefficient at (current_timepoint-T) *//* * double LTRAtCoeffSetup(coefflist,listsize,T,valuelist, * firstothervalue,othervaluelist,curtime,timelist,timeindex, auxindexptr, * ltecontype) double *coefflist, *timelist, *valuelist, *othervaluelist; int * listsize, timeindex; double T, firstothervalue, curtime; int *auxindexptr, * ltecontype; *  * { unsigned exact; double returnval, delta; double dummy; double f1i, f2i, * g1i, g2i; double lolimit1, hilimit1; double lovalue1, hivalue1; double * lolimit2, hilimit2; double lovalue2, hivalue2; double firstint1 = 0.0, * firstint2 = 0.0; double secondint1 = 0.0, secondint2 = 0.0; int * i,auxindex; *  *//* coefflist should already have been allocated to the necessary size *//* * #ifdef LTRAdebug if (listsize <= timeindex) { printf("LTRAtCoeffSetup: 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 *//* i = n in the write-up *//* * hilimit1 = curtime - *(timelist + auxindex); hivalue1 = *(valuelist + * auxindex); lolimit1 = *(timelist + timeindex) - *(timelist + auxindex); * lolimit1 = MAX(T,lolimit1); lovalue1 = firstothervalue; f1i = * twiceintlinfunc(lolimit1,hilimit1,lolimit1,lovalue1,hivalue1,lolimit1, * hilimit1); g1i = * thriceintlinfunc(lolimit1,hilimit1,lolimit1,lolimit1,lovalue1, * hivalue1,lolimit1,hilimit1); returnval = 0.5*f1i*(curtime-T- * *(timelist+auxindex)) - g1i; *  *//* the coefficients for the rest of the timepoints *//* * if (ltecontype != LTRA_MOD_HALFCONTROL) { for (i=auxindex; i>0; i--) { *  * lolimit2 = lolimit1; *//* previous lolimit1 *//* hilimit2 = hilimit1; *//* previous hilimit1 *//* lovalue2 = lovalue1; *//* previous lovalue1 *//* hivalue2 = hivalue1; *//* previous hivalue1 *//* f2i = f1i; *//* previous f1i *//* g2i = g1i; *//* previous g1i *//* firstint2 = firstint1; *//* previous firstint1 *//* secondint2 = secondint1; *//* previous secondint1 *//* * lolimit1 = *(timelist + timeindex) - *(timelist + i - 1); hilimit1 = * curtime - *(timelist + i - 1); lovalue1 = *(othervaluelist + i - 1); * hivalue1 = *(valuelist + i - 1); firstint1 += intlinfunc(lolimit2, * lolimit1, lovalue2, lovalue1, lolimit2, lolimit1); secondint1 += * (lolimit1-lolimit2)*firstint2 + twiceintlinfunc( * lolimit2,lolimit1,lolimit2,lovalue2,lovalue1,lolimit2,lolimit1); f1i =

⌨️ 快捷键说明

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