Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**********
- Copyright 1990 Regents of the University of California. All rights reserved.
- Author: 1985 Thomas L. Quarles
- Modified: Apr 2000 - Paolo Nenzi
- **********/
- #include "ngspice/ngspice.h"
- #include "ngspice/const.h"
- #include "memdefs.h"
- #include "ngspice/ifsim.h"
- #include "ngspice/cktdefs.h"
- #include "ngspice/sperror.h"
- /* TODO : there are "double" value compared with 0 (eg: vm == 0)
- * Need to substitute this check with a suitable eps.
- * PN 2003
- */
- int
- MEMask(CKTcircuit *ckt, GENinstance *inst, int which, IFvalue *value,
- IFvalue *select)
- {
- MEMinstance *fast = (MEMinstance *)inst;
- double vr;
- double vi;
- double sr;
- double si;
- double vm;
- static char *msg = "Current and power not available for ac analysis";
- switch(which) {
- case MEM_TEMP:
- value->rValue = fast->MEMtemp - CONSTCtoK;
- return(OK);
- case MEM_DTEMP:
- value->rValue = fast->MEMdtemp;
- return(OK);
- case MEM_CONDUCT:
- value->rValue = fast->MEMconduct;
- value->rValue *= fast->MEMm;
- return(OK);
- case MEM_RESIST:
- value->rValue = fast->MEMresist;
- value->rValue /= fast->MEMm;
- return(OK);
- //NEW CODE
- case MEM_LENTOT:
- value->rValue = fast->MEMlentot;
- return(OK);
- case MEM_WPARAM:
- value->rValue = fast->MEMwparam;
- return(OK);
- case MEM_RHO1:
- value->rValue = fast->MEMrho1;
- return(OK);
- case MEM_RHO2:
- value->rValue = fast->MEMrho2;
- return(OK);
- case MEM_DWDQ:
- value->rValue = fast->MEMdwdq;
- return(OK);
- case MEM_AREA:
- value->rValue = fast->MEMarea;
- return(OK);
- //END NEW CODE
- case MEM_ACCONDUCT:
- value->rValue = fast->MEMacConduct;
- value->rValue *= fast->MEMm;
- return (OK);
- case MEM_ACRESIST:
- value->rValue = fast->MEMacResist;
- value->rValue /= fast->MEMm;
- return(OK);
- case MEM_LENGTH:
- value->rValue = fast->MEMlength;
- return(OK);
- case MEM_WIDTH:
- value->rValue = fast->MEMwidth;
- return(OK);
- case MEM_SCALE:
- value->rValue = fast->MEMscale;
- return(OK);
- case MEM_M:
- value->rValue = fast->MEMm;
- return(OK);
- case MEM_TC1:
- value->rValue = fast->MEMtc1;
- return(OK);
- case MEM_TC2:
- value->rValue = fast->MEMtc2;
- return(OK);
- case MEM_NOISY:
- value->iValue = fast->MEMnoisy;
- return(OK);
- case MEM_QUEST_SENS_DC:
- if(ckt->CKTsenInfo){
- value->rValue = *(ckt->CKTsenInfo->SEN_Sap[select->iValue + 1]+
- fast->MEMsenParmNo);
- }
- return(OK);
- case MEM_QUEST_SENS_REAL:
- if(ckt->CKTsenInfo){
- value->rValue = *(ckt->CKTsenInfo->SEN_RHS[select->iValue + 1]+
- fast->MEMsenParmNo);
- }
- return(OK);
- case MEM_QUEST_SENS_IMAG:
- if(ckt->CKTsenInfo){
- value->rValue = *(ckt->CKTsenInfo->SEN_iRHS[select->iValue + 1]+
- fast->MEMsenParmNo);
- }
- return(OK);
- case MEM_QUEST_SENS_MAG:
- if(ckt->CKTsenInfo){
- vr = *(ckt->CKTrhsOld + select->iValue + 1);
- vi = *(ckt->CKTirhsOld + select->iValue + 1);
- vm = sqrt(vr*vr + vi*vi);
- if(vm == 0){
- value->rValue = 0;
- return(OK);
- }
- sr = *(ckt->CKTsenInfo->SEN_RHS[select->iValue + 1]+
- fast->MEMsenParmNo);
- si = *(ckt->CKTsenInfo->SEN_iRHS[select->iValue + 1]+
- fast->MEMsenParmNo);
- value->rValue = (vr * sr + vi * si)/vm;
- }
- return(OK);
- case MEM_QUEST_SENS_PH:
- if(ckt->CKTsenInfo){
- vr = *(ckt->CKTrhsOld + select->iValue + 1);
- vi = *(ckt->CKTirhsOld + select->iValue + 1);
- vm = vr*vr + vi*vi;
- if(vm == 0){
- value->rValue = 0;
- return(OK);
- }
- sr = *(ckt->CKTsenInfo->SEN_RHS[select->iValue + 1]+
- fast->MEMsenParmNo);
- si = *(ckt->CKTsenInfo->SEN_iRHS[select->iValue + 1]+
- fast->MEMsenParmNo);
- value->rValue = (vr * si - vi * sr)/vm;
- }
- return(OK);
- case MEM_QUEST_SENS_CPLX:
- if(ckt->CKTsenInfo){
- value->cValue.real=
- *(ckt->CKTsenInfo->SEN_RHS[select->iValue + 1]+
- fast->MEMsenParmNo);
- value->cValue.imag=
- *(ckt->CKTsenInfo->SEN_iRHS[select->iValue + 1]+
- fast->MEMsenParmNo);
- }
- return(OK);
- case MEM_CURRENT:
- if (ckt->CKTcurrentAnalysis & DOING_AC) {
- errMsg = TMALLOC(char, strlen(msg) + 1);
- errRtn = "MEMask";
- strcpy(errMsg,msg);
- return(E_ASKCURRENT);
- } else {
- value->rValue = (*(ckt->CKTrhsOld + fast->MEMposNode) -
- *(ckt->CKTrhsOld + fast->MEMnegNode))
- *fast->MEMconduct;
- value->rValue *= fast->MEMm;
- }
- return(OK);
- case MEM_POWER:
- if (ckt->CKTcurrentAnalysis & DOING_AC) {
- errMsg = TMALLOC(char, strlen(msg) + 1);
- errRtn = "MEMask";
- strcpy(errMsg,msg);
- return(E_ASKPOWER);
- } else {
- value->rValue = (*(ckt->CKTrhsOld + fast->MEMposNode) -
- *(ckt->CKTrhsOld + fast->MEMnegNode)) *
- fast->MEMconduct *
- (*(ckt->CKTrhsOld + fast->MEMposNode) -
- *(ckt->CKTrhsOld + fast->MEMnegNode));
- value->rValue *= fast->MEMm;
- }
- return(OK);
- default:
- return(E_BADPARM);
- }
- /* NOTREACHED */
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement