Exemple #1
0
static void
switch_dlg_use_preset (Widget w, XtPointer client_data, XtPointer call_data)
{
  int i;
  uint32_t num;
  PgmState *pgm = client_data;
  if (XAW_LIST_NONE == pgm->preset_idx)
    return;
  if (NULL != pgm->sp)
    for (i = 0; i < pgm->num_pos; i++)
    {
      spClear (pgm->sp + i);
    }
  pgm->sp = spGetPreset (pgm->preset_idx, &num);
  pgm->num_pos = num;
  switch_dlg_purge_pos (pgm);
  switch_dlg_load_pos (pgm);
}
Exemple #2
0
int
srvSetSwitch (Connection * c)
{
  uint32_t num = 0;
  SwitchPos *sp = dvbGetSwitch (&c->p->dvb, &num);
  uint32_t num2 = 0;
  SwitchPos *sp2;
  uint32_t i;
  debugMsg ("set_switch\n");
  if (!(c->active && c->super))
  {
    ipcSndS (c->sockfd, SRV_ERR);
    return 0;
  }

  ipcSndS (c->sockfd, SRV_NOERR);

  ipcRcvS (c->sockfd, num2);
  if (!num2)
  {
    sp2 = NULL;
  }
  else
  {
    sp2 = utlCalloc (num2, sizeof (SwitchPos));
    for (i = 0; i < num2; i++)
    {
      spRcv (sp2 + i, c->sockfd);
    }
  }
  debugMsg ("setup_switch done: %p, %u\n", sp2, num2);
  dvbSetSwitch (&c->p->dvb, sp2, num2);
  //now deallocate the old one
  for (i = 0; i < num; i++)
  {
    spClear (sp + i);
  }
  utlFAN (sp);
  return 0;
}
Exemple #3
0
/*
 * SMPclear()
 */
void
SMPclear(SMPmatrix *Matrix)
{
    spClear( (void *)Matrix );
}
Exemple #4
0
void 
ONE_jacLoad(ONEdevice *pDevice)
{
  /* used only for ac analysis */
  ONEelem *pElem;
  ONEnode *pNode, *pNode1;
  ONEedge *pEdge;
  int index, eIndex;
  double dx, rDx, dPsi;
  double generation;
  double fNd, fNa, fdNd, fdNa;
  double dNd, dNa, psi, nConc, pConc;


  /* first compute the currents and their derivatives */
  ONE_commonTerms(pDevice, FALSE, FALSE, NIL(ONEtranInfo));

  /* zero the matrix */
  spClear(pDevice->matrix);

  for (eIndex = 1; eIndex < pDevice->numNodes; eIndex++) {
    pElem = pDevice->elemArray[eIndex];
    dx = 0.5 * pElem->dx;
    rDx = pElem->epsRel * pElem->rDx;
    /* load for all i */
    for (index = 0; index <= 1; index++) {
      pNode = pElem->pNodes[index];
      if (pNode->nodeType != CONTACT) {
	*(pNode->fPsiPsi) += rDx;
	if (pElem->elemType == SEMICON) {
	  pEdge = pElem->pEdge;
	  dNd = 0.0;
	  dNa = 0.0;
	  psi = *(pDevice->devState0 + pNode->nodePsi);
	  nConc = *(pDevice->devState0 + pNode->nodeN);
	  pConc = *(pDevice->devState0 + pNode->nodeP);
	  if (FreezeOut) {
	    ONE_freezeOut(pNode, nConc, pConc, &fNd, &fNa, &fdNd, &fdNa);
	    dNd = pNode->nd * fdNd;
	    dNa = pNode->na * fdNa;
	  }
	  *(pNode->fPsiN) += dx * (1.0 - dNd);
	  *(pNode->fPsiP) -= dx * (1.0 - dNa);
	  *(pNode->fNPsi) -= pEdge->dJnDpsiP1;
	  *(pNode->fPPsi) -= pEdge->dJpDpsiP1;

	  if (pNode->baseType == N_TYPE) {
	    *(pNode->fNPsi) += 0.5 * nConc * pNode->eg;
	    *(pNode->fNN) -= 0.5 * pNode->eg
		* (pNode->vbe - psi + log(nConc / pNode->nie) + 1.0);
	  }
	  if (pNode->baseType == P_TYPE) {
	    *(pNode->fPPsi) += 0.5 * pConc * pNode->eg;
	    *(pNode->fPP) -= 0.5 * pNode->eg
		* (pNode->vbe - psi - log(pConc / pNode->nie) - 1.0);
	  }
	}
      }
    }
    pNode = pElem->pLeftNode;
    if (pNode->nodeType != CONTACT) {
      pEdge = pElem->pEdge;
      dPsi = pEdge->dPsi;
      if (pElem->elemType == SEMICON) {
	*(pNode->fNN) += pEdge->dJnDn - dx * pNode->dUdN;
	*(pNode->fNP) -= dx * pNode->dUdP;
	*(pNode->fPP) += pEdge->dJpDp + dx * pNode->dUdP;
	*(pNode->fPN) += dx * pNode->dUdN;
      }
      pNode1 = pElem->pRightNode;
      if (pNode1->nodeType != CONTACT) {
	*(pNode->fPsiPsiiP1) -= rDx;
	if (pElem->elemType == SEMICON) {
	  *(pNode->fNPsiiP1) += pEdge->dJnDpsiP1;
	  *(pNode->fNNiP1) += pEdge->dJnDnP1;
	  *(pNode->fPPsiiP1) += pEdge->dJpDpsiP1;
	  *(pNode->fPPiP1) += pEdge->dJpDpP1;
	}
      }
    }
    pNode = pElem->pRightNode;
    if (pNode->nodeType != CONTACT) {
      pEdge = pElem->pEdge;
      dPsi = pEdge->dPsi;
      if (pElem->elemType == SEMICON) {
	*(pNode->fNN) += -pEdge->dJnDnP1 - dx * pNode->dUdN;
	*(pNode->fNP) -= dx * pNode->dUdP;
	*(pNode->fPP) += -pEdge->dJpDpP1 + dx * pNode->dUdP;
	*(pNode->fPN) += dx * pNode->dUdN;
      }
      pNode1 = pElem->pLeftNode;
      if (pNode1->nodeType != CONTACT) {
	*(pNode->fPsiPsiiM1) -= rDx;
	if (pElem->elemType == SEMICON) {
	  *(pNode->fNPsiiM1) += pEdge->dJnDpsiP1;
	  *(pNode->fNNiM1) -= pEdge->dJnDn;
	  *(pNode->fPPsiiM1) += pEdge->dJpDpsiP1;
	  *(pNode->fPPiM1) -= pEdge->dJpDp;
	}
      }
    }
  }
  if (AvalancheGen) {
    /* add the generation terms */
    for (eIndex = 1; eIndex < pDevice->numNodes; eIndex++) {
      pElem = pDevice->elemArray[eIndex];
      for (index = 0; index <= 1; index++) {
	if (pElem->evalNodes[index]) {
	  pNode = pElem->pNodes[index];
	  if ((pNode->nodeType != CONTACT) && (pElem->elemType == SEMICON)) {
	    generation = ONEavalanche(FALSE, pDevice, pNode);
	  }
	}
      }
    }
  }
}
Exemple #5
0
void 
ONE_sysLoad(ONEdevice *pDevice, BOOLEAN tranAnalysis, 
            ONEtranInfo *info)
{
  ONEelem *pElem;
  ONEnode *pNode;
  ONEedge *pEdge;
  int index, eIndex;
  double *pRhs = pDevice->rhs;
  double dx, rDx, dPsi;
  double generation;
  double perTime = 0.0;
  double fNd, fNa, fdNd, fdNa;
  double netConc, dNd, dNa, psi, nConc, pConc;


  /* first compute the currents and their derivatives */
  ONE_commonTerms(pDevice, FALSE, tranAnalysis, info);

  /* find reciprocal timestep */
  if (tranAnalysis) {
    perTime = info->intCoeff[0];
  }
  /* zero the rhs vector */
  for (index = 1; index <= pDevice->numEqns; index++) {
    pRhs[index] = 0.0;
  }

  /* zero the matrix */
  spClear(pDevice->matrix);

  for (eIndex = 1; eIndex < pDevice->numNodes; eIndex++) {
    pElem = pDevice->elemArray[eIndex];
    dx = 0.5 * pElem->dx;
    rDx = pElem->epsRel * pElem->rDx;

    /* load for all i */
    for (index = 0; index <= 1; index++) {
      pNode = pElem->pNodes[index];
      if (pNode->nodeType != CONTACT) {
	*(pNode->fPsiPsi) += rDx;
	pRhs[pNode->psiEqn] += pNode->qf;
	if (pElem->elemType == SEMICON) {
	  pEdge = pElem->pEdge;
	  netConc = pNode->netConc;
	  dNd = 0.0;
	  dNa = 0.0;
	  psi = *(pDevice->devState0 + pNode->nodePsi);
	  nConc = *(pDevice->devState0 + pNode->nodeN);
	  pConc = *(pDevice->devState0 + pNode->nodeP);
	  
	  
	  if (FreezeOut) {
	    ONE_freezeOut(pNode, nConc, pConc, &fNd, &fNa, &fdNd, &fdNa);
	    netConc = pNode->nd * fNd - pNode->na * fNa;
	    dNd = pNode->nd * fdNd;
	    dNa = pNode->na * fdNa;
	  }
	  *(pNode->fPsiN) += dx * (1.0 - dNd);
	  *(pNode->fPsiP) -= dx * (1.0 - dNa);
	  *(pNode->fNPsi) -= pEdge->dJnDpsiP1;
	  *(pNode->fPPsi) -= pEdge->dJpDpsiP1;

	  pRhs[pNode->psiEqn] += dx * (netConc + pConc - nConc);

	  /* Handle generation terms */
	  *(pNode->fNN) -= dx * pNode->dUdN;
	  *(pNode->fNP) -= dx * pNode->dUdP;
	  *(pNode->fPP) += dx * pNode->dUdP;
	  *(pNode->fPN) += dx * pNode->dUdN;
	  pRhs[pNode->nEqn] -= -dx * pNode->uNet;
	  pRhs[pNode->pEqn] -= dx * pNode->uNet;

	  /* Handle dXdT continuity terms */
	  if (tranAnalysis) {
	    *(pNode->fNN) -= dx * perTime;
	    *(pNode->fPP) += dx * perTime;
	    pRhs[pNode->nEqn] += dx * pNode->dNdT;
	    pRhs[pNode->pEqn] -= dx * pNode->dPdT;
	  }
	  /* Take care of base contact if necessary */
	  /* eg holds the base edge mu/dx */
	  if (pNode->baseType == N_TYPE) {
	    pRhs[pNode->nEqn] += 0.5 * pNode->eg * nConc *
		(pNode->vbe - psi + log(nConc / pNode->nie));
	    *(pNode->fNPsi) += 0.5 * pNode->eg * nConc;
	    *(pNode->fNN) -= 0.5 * pNode->eg *
		(pNode->vbe - psi + log(nConc / pNode->nie) + 1.0);
	  } else if (pNode->baseType == P_TYPE) {
	    pRhs[pNode->pEqn] += 0.5 * pNode->eg * pConc *
		(pNode->vbe - psi - log(pConc / pNode->nie));
	    *(pNode->fPPsi) += 0.5 * pNode->eg * pConc;
	    *(pNode->fPP) -= 0.5 * pNode->eg *
		(pNode->vbe - psi - log(pConc / pNode->nie) - 1.0);
	  }
	}
      }
    }

    pEdge = pElem->pEdge;
    dPsi = pEdge->dPsi;

    pNode = pElem->pLeftNode;
    if (pNode->nodeType != CONTACT) {
      pRhs[pNode->psiEqn] += rDx * dPsi;
      *(pNode->fPsiPsiiP1) -= rDx;
      if (pElem->elemType == SEMICON) {
	pRhs[pNode->nEqn] -= pEdge->jn;
	pRhs[pNode->pEqn] -= pEdge->jp;
	
	*(pNode->fNN) += pEdge->dJnDn;
	*(pNode->fPP) += pEdge->dJpDp;
	*(pNode->fNPsiiP1) += pEdge->dJnDpsiP1;
	*(pNode->fNNiP1) += pEdge->dJnDnP1;
	*(pNode->fPPsiiP1) += pEdge->dJpDpsiP1;
	*(pNode->fPPiP1) += pEdge->dJpDpP1;
      }
    }
    pNode = pElem->pRightNode;
    if (pNode->nodeType != CONTACT) {
      pRhs[pNode->psiEqn] -= rDx * dPsi;
      *(pNode->fPsiPsiiM1) -= rDx;
      if (pElem->elemType == SEMICON) {
	pRhs[pNode->nEqn] += pEdge->jn;
	pRhs[pNode->pEqn] += pEdge->jp;
	
	
	*(pNode->fNN) -= pEdge->dJnDnP1;
	*(pNode->fPP) -= pEdge->dJpDpP1;
	*(pNode->fNPsiiM1) += pEdge->dJnDpsiP1;
	*(pNode->fNNiM1) -= pEdge->dJnDn;
	*(pNode->fPPsiiM1) += pEdge->dJpDpsiP1;
	*(pNode->fPPiM1) -= pEdge->dJpDp;
      }
    }
  }
  if (AvalancheGen) {
    /* add the generation terms */
    for (eIndex = 1; eIndex < pDevice->numNodes; eIndex++) {
      pElem = pDevice->elemArray[eIndex];
      for (index = 0; index <= 1; index++) {
	if (pElem->evalNodes[index]) {
	  pNode = pElem->pNodes[index];
	  if ((pNode->nodeType != CONTACT) && (pElem->elemType == SEMICON)) {
	    generation = ONEavalanche(FALSE, pDevice, pNode);
	    pRhs[pNode->nEqn] -= generation;
	    pRhs[pNode->pEqn] += generation;
	  }
	}
      }
    }
  }
}
Exemple #6
0
void
M_MatrixSetZero_SP(void *pA)
{
	M_MatrixSP *A=pA;
	spClear(A->d);
}
int 
pgBuildMNAEquation(Circuit *ckt)
{
	char     *matrix;
	char     *pstr;
	FILE     *fp;
	char     line[1024];
	int	   error;
	char     cValue[128];
	double   dValue;
	int      n1, n2;
	struct     spTemplate sTemplate;
	Branches *daux;

	assert(ckt->theDeviceList);

	theMatrix = spCreate(1, 0, &error);
	spClear(theMatrix);

	theRhs = (double *)malloc((ckt->nMatrixSize + 1) * sizeof(double));
	theSol = (double *)malloc((ckt->nMatrixSize + 1) * sizeof(double));

	/* initialization */
	memset(theRhs, 0, (ckt->nMatrixSize + 1)*sizeof(double));
	memset(theSol, 0, (ckt->nMatrixSize + 1)*sizeof(double));

	for( daux= ckt->theDeviceList; daux; daux = daux->next )
    {
		if(daux->stat == sAbnormal)
			continue;

		switch(daux->type)
		{

		case dRES: /* resistor */
			error =
				spGetAdmittance(theMatrix, 
								daux->n1, daux->n2, &sTemplate);
			if(error != spOKAY)
				return -1;
			dValue = 1/daux->value;
			/*
			  printf("admittance: %lf.\n",dValue);
			*/
			spADD_REAL_QUAD(sTemplate, dValue);
			break;

		case dCUR: /* independent current source */
			/*
			  printf("current source: %g.\n",daux->value);
			*/
			/* the current direction is from 
			   n1 to n2 */
			if(daux->n1 != 0)
				theRhs[daux->n1] -= daux->value;
			if(daux->n2 !=0)
				theRhs[daux->n2] += daux->value;
			break;

		case dVOL: /* independent voltage source */
			/*
			  printf("voltage source: %g.\n",daux->value);
			*/
			/* n1: positive, n2: negative */
			if(daux->vn != 0)
				theRhs[daux->vn] = daux->value;
			error =
				spGetOnes(theMatrix, daux->n1, daux->n2, 
						  daux->vn, &sTemplate);
			if(error != spOKAY)
				return -1;

			/*
			  spADD_REAL_QUAD(sTemplate, 1);
			*/

			break;

		default: 
			sprintf(buf, "Unknow device type: %s.", pstr);
			error_mesg(INT_ERROR,buf);
			break; 
		}
    }
	return 0;
}
Exemple #8
0
int
edit_bands (SwitchPos * sp, AppData * a)
{
  MENU *my_menu;
  SwitchBand *sb;
  SwitchPos tmp;
  uint32_t i, maxx;
  int state = 0;
  ITEM **my_items;
  char **mnu_str;
//      WINDOW * menu_win,*menu_sub;
  uint32_t num_strings;
  int lbl_x, idx = 0;
  uint32_t num;
  spDeepCopy (&tmp, sp);
  num = tmp.num_bands;
  sb = tmp.bands;

  message (a,
           "Select and press enter to edit. Use d to delete a frequency band or a to add a new one. Use c to cancel and backspace to exit.\n");

  while (state >= 0)
  {
    num_strings = num;
    state = 0;
    maxx = getmaxx (stdscr);
    if (num)
    {

      debugMsg ("allocating items\n");
      my_items = (ITEM **) utlCalloc (num_strings + 1, sizeof (ITEM *));
      mnu_str = utlCalloc (num_strings, sizeof (char *));
      for (i = 0; i < num_strings; ++i)
      {
        mnu_str[i] = utlCalloc (20, sizeof (char));
        snprintf (mnu_str[i], 20, "%" PRIu32, i);
        my_items[i] = new_item (mnu_str[i], mnu_str[i]);
        if (NULL == my_items[i])
        {
          if (errno == E_BAD_ARGUMENT)
            errMsg ("badarg i=%" PRIu32 "\n", i);
          if (errno == E_SYSTEM_ERROR)
            errMsg ("new_item: syserr i=%" PRIu32 "\n", i);
        }
      }
      my_items[num_strings] = (ITEM *) NULL;
      my_menu = new_menu ((ITEM **) my_items);
      set_menu_opts (my_menu, O_ONEVALUE | O_NONCYCLIC | O_ROWMAJOR);
      appDataMakeMenuWnd (my_menu);
      lbl_x = 3 + (maxx - 6) / 2 - strlen ("Bands") / 2;
      mvwprintw (menu_win (my_menu), 1, lbl_x, "%s", "Bands");
      post_menu (my_menu);
      debugMsg ("starting menu loop\n");
      wrefresh (menu_win (my_menu));
      while (state == 0)
      {
        int c;
        ITEM *selection;
        c = getch ();
        switch (c)
        {
        case 263:              //ESC
        case K_BACK:           //Backspace
          state = -1;
          break;
        case KEY_DOWN:
          menu_driver (my_menu, REQ_DOWN_ITEM);
          break;
        case KEY_UP:
          menu_driver (my_menu, REQ_UP_ITEM);
          break;
        case KEY_RESIZE:
          //windows need to be resized.. ignore
          break;
        case 'd':
          selection = current_item (my_menu);
          idx = item_index (selection);
          state = 1;
          break;
        case 'a':
          state = 2;
          break;
        case 'c':
          state = 3;
          break;
        case 13:               //enter
          selection = current_item (my_menu);
          idx = item_index (selection);
          state = 5;
          break;
        default:
          break;
        }
        wrefresh (menu_win (my_menu));
      }
      unpost_menu (my_menu);
      appDataDestroyMenuWnd (my_menu);
      free_menu (my_menu);
      for (i = 0; i < num_strings; ++i)
      {
        free_item (my_items[i]);
        utlFAN (mnu_str[i]);
      }
      utlFAN (mnu_str);
      utlFAN (my_items);
    }
    else
    {
      WINDOW *wnd;
      wnd = appDataMakeEmptyWnd ();

      wrefresh (wnd);
      while (state == 0)
      {
        int c;
        c = getch ();
        switch (c)
        {
        case KEY_RESIZE:
          wnd = appDataResizeEmpty (wnd);
          break;
        case 263:              //ESC
        case K_BACK:           //Backspace
          state = -1;
          break;
        case 'a':
          state = 2;
          break;
        case 'c':
          state = 3;
          break;
        default:
          break;
        }
        wrefresh (wnd);
      }
      assert (ERR != delwin (wnd));
    }
    if (state > 0)
    {
      switch (state)
      {
      case 1:                  //del
        spBandDel (&sb, &num, idx);
        break;
      case 2:                  //add(at the end)
        spBandAdd (&sb, &num, num);
        break;
      case 3:                  //cancel
        spClear (&tmp);         //clear temporary
        return 1;
      case 5:                  //edit
        edit_band (sb + idx, a);
        break;
      default:
        break;
      }
    }
  }
  spClear (sp);                 //clear original
  *sp = tmp;                    //replace with temporary
  return 0;
}
Exemple #9
0
int
sel_preset (uint32_t * num_ret, SwitchPos ** sp_ret, AppData * a)
{
  SwitchPos *np;
  uint32_t nn;
  MENU *my_menu;
  SwitchPos *sp = *sp_ret;
  uint32_t i, maxx;
  int state = 0;
  ITEM **my_items;
//      WINDOW * menu_win,*menu_sub;
  uint32_t num_strings;
  int lbl_x, idx = 0;
  uint32_t num = *num_ret;

  message (a,
           "Select a preset using cursor keys and Enter, or cancel using Esc or Backspace.\n");

  while (state >= 0)
  {
    num_strings = SP_NUM_PRESETS;
    state = 0;
    debugMsg ("allocating items\n");
    my_items = (ITEM **) utlCalloc (num_strings + 1, sizeof (ITEM *));
    for (i = 0; i < num_strings; ++i)
    {
      my_items[i] = new_item (spGetPresetStrings (i), spGetPresetStrings (i));
      if (NULL == my_items[i])
      {
        if (errno == E_BAD_ARGUMENT)
          errMsg ("badarg i=%" PRIu32 " \n", i);
        if (errno == E_SYSTEM_ERROR)
          errMsg ("new_item: syserr i=%" PRIu32 "\n", i);
      }
    }
    my_items[num_strings] = (ITEM *) NULL;
    my_menu = new_menu ((ITEM **) my_items);
    set_menu_opts (my_menu, O_ONEVALUE | O_NONCYCLIC | O_ROWMAJOR);
    maxx = getmaxx (stdscr);
    appDataMakeMenuWnd (my_menu);
    post_menu (my_menu);
    lbl_x = 3 + (maxx - 6) / 2 - strlen ("Presets") / 2;
    mvwprintw (menu_win (my_menu), 1, lbl_x, "%s", "Presets");
    wrefresh (menu_win (my_menu));
    debugMsg ("starting menu loop\n");
    while (state == 0)
    {
      int c;
      ITEM *selection;
      c = getch ();
      switch (c)
      {
      case 263:                //ESC
      case K_BACK:             //Backspace
        state = -1;
        break;
      case KEY_DOWN:
        menu_driver (my_menu, REQ_DOWN_ITEM);
        break;
      case KEY_UP:
        menu_driver (my_menu, REQ_UP_ITEM);
        break;
      case KEY_RESIZE:
        //windows need to be resized.. ignore
        break;
      case 13:                 //enter
        selection = current_item (my_menu);
        idx = item_index (selection);
        state = 5;
        break;
      default:
        break;
      }
      wrefresh (menu_win (my_menu));
    }
    unpost_menu (my_menu);
    appDataDestroyMenuWnd (my_menu);
    free_menu (my_menu);
    for (i = 0; i < num_strings; ++i)
    {
      free_item (my_items[i]);
    }
    utlFAN (my_items);
    if (state > 0)
    {
      switch (state)
      {
      case 5:                  //selected
        np = spGetPreset (idx, &nn);
        if (NULL != np)
        {
          for (i = 0; i < num; i++)
          {
            spClear (sp + i);
          }
          *sp_ret = np;
          *num_ret = nn;
          return 0;
        }
        break;
      default:
        break;
      }
    }
  }
  //cancelled
  return 0;
}