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

📄 cktop.c

📁 ngspice又一个电子CAD仿真软件代码.功能更全
💻 C
📖 第 1 页 / 共 2 页
字号:
      fprintf (stderr, "Trying gmin = %12.4E ", ckt->CKTdiagGmin);      ckt->CKTnoncon = 1;      converged = NIiter (ckt, ckt->CKTdcTrcvMaxIter);      if (converged != 0){		  ckt->CKTdiagGmin = ckt->CKTgshunt;		  (*(SPfrontEnd->IFerror)) (ERR_WARNING,				    "Gmin step failed", (IFuid *) NULL);		  break;		}      ckt->CKTdiagGmin /= ckt->CKTgminFactor;      ckt->CKTmode = continuemode;      (*(SPfrontEnd->IFerror)) (ERR_INFO,				"One successful Gmin step", (IFuid *) NULL);    }  ckt->CKTdiagGmin = ckt->CKTgshunt;#ifdef XSPICE/* gtri - begin - wbk - add convergence problem reporting flags */  if (ckt->CKTnumSrcSteps <= 0)    ckt->enh->conv_debug.last_NIiter_call = MIF_TRUE;  else    ckt->enh->conv_debug.last_NIiter_call = MIF_FALSE;/* gtri - end - wbk - add convergence problem reporting flags */#endif  converged = NIiter (ckt, iterlim);  if (converged == 0){      (*(SPfrontEnd->IFerror)) (ERR_INFO,		"Gmin stepping completed", (IFuid *) NULL);#ifdef XSPICE/* gtri - begin - wbk - add convergence problem reporting flags */      ckt->enh->conv_debug.last_NIiter_call = MIF_FALSE;/* gtri - end - wbk - add convergence problem reporting flags */#endif    } else {      (*(SPfrontEnd->IFerror)) (ERR_WARNING,				"Gmin stepping failed", (IFuid *) NULL);    }  return (converged);}/* Gillespie's Source stepping * Modified 2005 - Paolo Nenzi (extracted from CKTop.c code) *  * return value: * 0 -> method converged * 1 -> method failed * * Note that no path out of this code allows ckt->CKTsrcFact to be  * anything but 1.00000. */static intgillespie_src (CKTcircuit * ckt, long int firstmode,	       long int continuemode, int iterlim){  int converged, NumNodes, i, iters;  double raise, ConvFact;  double *OldRhsOld, *OldCKTstate0;  CKTnode *n;  ckt->CKTmode = firstmode;  (*(SPfrontEnd->IFerror)) (ERR_INFO,			    "starting source stepping", (IFuid *) NULL);  ckt->CKTsrcFact = 0;  raise = 0.001;  ConvFact = 0;  NumNodes = 0;  for (n = ckt->CKTnodes; n; n = n->next){      NumNodes++;	}  OldRhsOld = (double *) MALLOC ((NumNodes + 1) * sizeof (double));  OldCKTstate0 =    (double *) MALLOC ((ckt->CKTnumStates + 1) * sizeof (double));  for (n = ckt->CKTnodes; n; n = n->next)      *(ckt->CKTrhsOld + n->number) = 0;  for (i = 0; i < ckt->CKTnumStates; i++)      *(ckt->CKTstate0 + i) = 0;/*  First, try a straight solution with all sources at zero */  fprintf (stderr, "\rSupplies reduced to %8.4f%% ", ckt->CKTsrcFact * 100);  converged = NIiter (ckt, ckt->CKTdcTrcvMaxIter);/*  If this doesn't work, try gmin stepping as well for the first solution */  if (converged != 0){      fprintf (stderr, "\n");      if (ckt->CKTgshunt <= 0){		  ckt->CKTdiagGmin = ckt->CKTgmin;		} else {		  ckt->CKTdiagGmin = ckt->CKTgshunt;		}	      for (i = 0; i < 10; i++)		  ckt->CKTdiagGmin *= 10;      for (i = 0; i <= 10; i++){		  fprintf (stderr, "Trying gmin = %12.4E ", ckt->CKTdiagGmin);		  ckt->CKTnoncon = 1;#ifdef XSPICE/* gtri - begin - wbk - add convergence problem reporting flags */      ckt->enh->conv_debug.last_NIiter_call = MIF_TRUE;/* gtri - end - wbk - add convergence problem reporting flags */#endif	  		  converged = NIiter (ckt, ckt->CKTdcTrcvMaxIter);	  if (converged != 0){	      ckt->CKTdiagGmin = ckt->CKTgshunt;	      (*(SPfrontEnd->IFerror)) (ERR_WARNING,					"Gmin step failed", (IFuid *) NULL);		#ifdef XSPICE/* gtri - begin - wbk - add convergence problem reporting flags */      ckt->enh->conv_debug.last_NIiter_call = MIF_FALSE;/* gtri - end - wbk - add convergence problem reporting flags */#endif	      break;	    }	  ckt->CKTdiagGmin /= 10;	  ckt->CKTmode = continuemode;	  (*(SPfrontEnd->IFerror)) (ERR_INFO,				    "One successful Gmin step",				    (IFuid *) NULL);	}      ckt->CKTdiagGmin = ckt->CKTgshunt;  }/*  If we've got convergence, then try stepping up the sources  */  if (converged == 0){	i = 0;	for (n = ckt->CKTnodes; n; n = n->next){	  OldRhsOld[i] = *(ckt->CKTrhsOld + n->number);	  i++;	}      for (i = 0; i < ckt->CKTnumStates; i++)		*(OldCKTstate0 + i) = *(ckt->CKTstate0 + i);	      (*(SPfrontEnd->IFerror)) (ERR_INFO,				"One successful source step", (IFuid *) NULL);      ckt->CKTsrcFact = ConvFact + raise;		}  if (converged == 0)    do {	fprintf (stderr,		 "\rSupplies reduced to %8.4f%% ", ckt->CKTsrcFact * 100);	iters = ckt->CKTstat->STATnumIter;#ifdef XSPICE/* gtri - begin - wbk - add convergence problem reporting flags */      ckt->enh->conv_debug.last_NIiter_call = MIF_TRUE;/* gtri - end - wbk - add convergence problem reporting flags */#endif	  	converged = NIiter (ckt, ckt->CKTdcTrcvMaxIter);	  	iters = (ckt->CKTstat->STATnumIter) - iters;	ckt->CKTmode = continuemode;	if (converged == 0){	    ConvFact = ckt->CKTsrcFact;	    i = 0;	    for (n = ckt->CKTnodes; n; n = n->next){			OldRhsOld[i] = *(ckt->CKTrhsOld + n->number);			i++;		}	    for (i = 0; i < ckt->CKTnumStates; i++)			*(OldCKTstate0 + i) = *(ckt->CKTstate0 + i);	    (*(SPfrontEnd->IFerror)) (ERR_INFO,				      "One successful source step",				      (IFuid *) NULL);	    ckt->CKTsrcFact = ConvFact + raise;	    if (iters <= (ckt->CKTdcTrcvMaxIter / 4)){			raise = raise * 1.5;		}	    if (iters > (3 * ckt->CKTdcTrcvMaxIter / 4)){			raise = raise * 0.5;		}/*                    if (raise>0.01) raise=0.01; */	} else {	    if ((ckt->CKTsrcFact - ConvFact) < 1e-8)	      break;	    raise = raise / 10;	    if (raise > 0.01)	      raise = 0.01;	    ckt->CKTsrcFact = ConvFact;	    i = 0;	    for (n = ckt->CKTnodes; n; n = n->next){			*(ckt->CKTrhsOld + n->number) = OldRhsOld[i];			i++;		}	    for (i = 0; i < ckt->CKTnumStates; i++)			*(ckt->CKTstate0 + i) = *(OldCKTstate0 + i);	      	  }	if ((ckt->CKTsrcFact) > 1)	  ckt->CKTsrcFact = 1;      }	while ((raise >= 1e-7) && (ConvFact < 1));  FREE (OldRhsOld);  FREE (OldCKTstate0);  ckt->CKTsrcFact = 1;  if (ConvFact != 1)    {      ckt->CKTsrcFact = 1;      ckt->CKTcurrentAnalysis = DOING_TRAN;      (*(SPfrontEnd->IFerror)) (ERR_WARNING,				"source stepping failed", (IFuid *) NULL);      return (E_ITERLIM);    }  else    {      (*(SPfrontEnd->IFerror)) (ERR_INFO,				"Source stepping completed", (IFuid *) NULL);      return (0);    }}/* Spice3 Source stepping * Modified 2005 - Paolo Nenzi (extracted from CKTop.c code) *  * return value: * 0 -> method converged * 1 -> method failed * * Note that no path out of this code allows ckt->CKTsrcFact to be  * anything but 1.00000. */static intspice3_src (CKTcircuit * ckt, long int firstmode,	    long int continuemode, int iterlim){  int converged, i;  ckt->CKTmode = firstmode;  (*(SPfrontEnd->IFerror)) (ERR_INFO,			    "starting source stepping", (IFuid *) NULL);  for (i = 0; i <= ckt->CKTnumSrcSteps; i++)    {      ckt->CKTsrcFact = ((double) i) / ((double) ckt->CKTnumSrcSteps);#ifdef XSPICE/* gtri - begin - wbk - add convergence problem reporting flags */      ckt->enh->conv_debug.last_NIiter_call = MIF_TRUE;/* gtri - end - wbk - add convergence problem reporting flags */#endif      converged = NIiter (ckt, ckt->CKTdcTrcvMaxIter);      ckt->CKTmode = continuemode;      if (converged != 0)	{	  ckt->CKTsrcFact = 1;	  ckt->CKTcurrentAnalysis = DOING_TRAN;	  (*(SPfrontEnd->IFerror)) (ERR_WARNING,				    "source stepping failed", (IFuid *) NULL);#ifdef XSPICE/* gtri - begin - wbk - add convergence problem reporting flags */	  ckt->enh->conv_debug.last_NIiter_call = MIF_FALSE;/* gtri - end - wbk - add convergence problem reporting flags */#endif	  return (converged);	}      (*(SPfrontEnd->IFerror)) (ERR_INFO,				"One successful source step", (IFuid *) NULL);    }  (*(SPfrontEnd->IFerror)) (ERR_INFO,			    "Source stepping completed", (IFuid *) NULL);  ckt->CKTsrcFact = 1;#ifdef XSPICE/* gtri - begin - wbk - add convergence problem reporting flags */  ckt->enh->conv_debug.last_NIiter_call = MIF_FALSE;/* gtri - end - wbk - add convergence problem reporting flags */#endif  return (0);}

⌨️ 快捷键说明

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