Advertisement
Guest User

Untitled

a guest
Mar 27th, 2015
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 6.31 KB | None | 0 0
  1. /**********
  2. Copyright 1990 Regents of the University of California.  All rights reserved.
  3. Author: 1985 Thomas L. Quarles
  4. Modified: Apr 2000 - Paolo Nenzi
  5. **********/
  6.  
  7. #include "ngspice/ngspice.h"
  8. #include "ngspice/const.h"
  9. #include "memdefs.h"
  10. #include "ngspice/ifsim.h"
  11. #include "ngspice/cktdefs.h"
  12. #include "ngspice/sperror.h"
  13.  
  14.  
  15. /* TODO : there are "double" value compared with 0 (eg: vm == 0)
  16.  *        Need to substitute this check with a suitable eps.
  17.  *        PN 2003
  18.  */
  19.  
  20. int
  21. MEMask(CKTcircuit *ckt, GENinstance *inst, int which, IFvalue *value,
  22.        IFvalue *select)
  23. {
  24.     MEMinstance *fast = (MEMinstance *)inst;
  25.     double vr;
  26.     double vi;
  27.     double sr;
  28.     double si;
  29.     double vm;
  30.     static char *msg = "Current and power not available for ac analysis";
  31.    
  32.     switch(which) {
  33.         case MEM_TEMP:
  34.             value->rValue = fast->MEMtemp - CONSTCtoK;
  35.             return(OK);
  36.         case MEM_DTEMP:
  37.             value->rValue = fast->MEMdtemp;
  38.             return(OK);    
  39.         case MEM_CONDUCT:
  40.             value->rValue = fast->MEMconduct;
  41.         value->rValue *= fast->MEMm;
  42.             return(OK);
  43.         case MEM_RESIST:
  44.             value->rValue = fast->MEMresist;
  45.         value->rValue /= fast->MEMm;
  46.             return(OK);
  47. //NEW CODE
  48.         case MEM_LENTOT:
  49.             value->rValue = fast->MEMlentot;
  50.             return(OK);
  51.         case MEM_WPARAM:
  52.             value->rValue = fast->MEMwparam;
  53.             return(OK);
  54.         case MEM_RHO1:
  55.             value->rValue = fast->MEMrho1;
  56.             return(OK);
  57.         case MEM_RHO2:
  58.             value->rValue = fast->MEMrho2;
  59.             return(OK);
  60.         case MEM_DWDQ:
  61.             value->rValue = fast->MEMdwdq;
  62.             return(OK);
  63.         case MEM_AREA:
  64.             value->rValue = fast->MEMarea;
  65.             return(OK);
  66. //END NEW CODE
  67.     case MEM_ACCONDUCT:
  68.         value->rValue = fast->MEMacConduct;
  69.         value->rValue *= fast->MEMm;
  70.         return (OK);
  71.     case MEM_ACRESIST:
  72.         value->rValue = fast->MEMacResist;
  73.         value->rValue /= fast->MEMm;
  74.         return(OK);
  75.         case MEM_LENGTH:
  76.             value->rValue = fast->MEMlength;
  77.             return(OK);
  78.         case MEM_WIDTH:
  79.             value->rValue = fast->MEMwidth;
  80.         return(OK);
  81.     case MEM_SCALE:
  82.         value->rValue = fast->MEMscale;
  83.             return(OK);
  84.     case MEM_M:
  85.         value->rValue = fast->MEMm;
  86.         return(OK);
  87.     case MEM_TC1:
  88.         value->rValue = fast->MEMtc1;
  89.         return(OK);
  90.     case MEM_TC2:
  91.         value->rValue = fast->MEMtc2;
  92.         return(OK);
  93.     case MEM_NOISY:
  94.         value->iValue = fast->MEMnoisy;
  95.         return(OK);    
  96.         case MEM_QUEST_SENS_DC:
  97.             if(ckt->CKTsenInfo){
  98.                 value->rValue = *(ckt->CKTsenInfo->SEN_Sap[select->iValue + 1]+
  99.                         fast->MEMsenParmNo);
  100.             }
  101.             return(OK);
  102.         case MEM_QUEST_SENS_REAL:
  103.             if(ckt->CKTsenInfo){
  104.                 value->rValue = *(ckt->CKTsenInfo->SEN_RHS[select->iValue + 1]+
  105.                         fast->MEMsenParmNo);
  106.             }
  107.             return(OK);
  108.         case MEM_QUEST_SENS_IMAG:
  109.             if(ckt->CKTsenInfo){
  110.                 value->rValue = *(ckt->CKTsenInfo->SEN_iRHS[select->iValue + 1]+
  111.                         fast->MEMsenParmNo);
  112.             }
  113.             return(OK);
  114.         case MEM_QUEST_SENS_MAG:
  115.             if(ckt->CKTsenInfo){
  116.                 vr = *(ckt->CKTrhsOld + select->iValue + 1);
  117.                 vi = *(ckt->CKTirhsOld + select->iValue + 1);
  118.                 vm = sqrt(vr*vr + vi*vi);
  119.                 if(vm == 0){
  120.                     value->rValue = 0;
  121.                     return(OK);
  122.                 }
  123.                 sr = *(ckt->CKTsenInfo->SEN_RHS[select->iValue + 1]+
  124.                         fast->MEMsenParmNo);
  125.                 si = *(ckt->CKTsenInfo->SEN_iRHS[select->iValue + 1]+
  126.                         fast->MEMsenParmNo);
  127.                 value->rValue = (vr * sr + vi * si)/vm;
  128.             }
  129.             return(OK);
  130.         case MEM_QUEST_SENS_PH:
  131.             if(ckt->CKTsenInfo){
  132.                 vr = *(ckt->CKTrhsOld + select->iValue + 1);
  133.                 vi = *(ckt->CKTirhsOld + select->iValue + 1);
  134.                 vm = vr*vr + vi*vi;
  135.                 if(vm == 0){
  136.                     value->rValue = 0;
  137.                     return(OK);
  138.                 }
  139.                 sr = *(ckt->CKTsenInfo->SEN_RHS[select->iValue + 1]+
  140.                         fast->MEMsenParmNo);
  141.                 si = *(ckt->CKTsenInfo->SEN_iRHS[select->iValue + 1]+
  142.                         fast->MEMsenParmNo);
  143.                 value->rValue = (vr * si - vi * sr)/vm;
  144.             }
  145.             return(OK);
  146.         case MEM_QUEST_SENS_CPLX:
  147.             if(ckt->CKTsenInfo){
  148.                 value->cValue.real=
  149.                         *(ckt->CKTsenInfo->SEN_RHS[select->iValue + 1]+
  150.                         fast->MEMsenParmNo);
  151.                 value->cValue.imag=
  152.                         *(ckt->CKTsenInfo->SEN_iRHS[select->iValue + 1]+
  153.                         fast->MEMsenParmNo);
  154.             }
  155.             return(OK);
  156.         case MEM_CURRENT:
  157.             if (ckt->CKTcurrentAnalysis & DOING_AC) {
  158.                 errMsg = TMALLOC(char, strlen(msg) + 1);
  159.                 errRtn = "MEMask";
  160.                 strcpy(errMsg,msg);
  161.                 return(E_ASKCURRENT);
  162.             } else {
  163.                 value->rValue = (*(ckt->CKTrhsOld + fast->MEMposNode) -  
  164.                         *(ckt->CKTrhsOld + fast->MEMnegNode))
  165.                         *fast->MEMconduct;
  166.         value->rValue *= fast->MEMm;       
  167.             }
  168.             return(OK);
  169.         case MEM_POWER:
  170.             if (ckt->CKTcurrentAnalysis & DOING_AC) {
  171.                 errMsg = TMALLOC(char, strlen(msg) + 1);
  172.                 errRtn = "MEMask";
  173.                 strcpy(errMsg,msg);
  174.                 return(E_ASKPOWER);
  175.             } else {
  176.                 value->rValue = (*(ckt->CKTrhsOld + fast->MEMposNode) -  
  177.                         *(ckt->CKTrhsOld + fast->MEMnegNode)) *
  178.                         fast->MEMconduct *  
  179.                         (*(ckt->CKTrhsOld + fast->MEMposNode) -
  180.                         *(ckt->CKTrhsOld + fast->MEMnegNode));
  181.         value->rValue *= fast->MEMm;           
  182.             }
  183.             return(OK);
  184.         default:
  185.             return(E_BADPARM);
  186.     }
  187.     /* NOTREACHED */
  188. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement