Jspice3
pzan.c File Reference
#include "spice.h"
#include <stdio.h>
#include <math.h>
#include "devdefs.h"
#include "pzdefs.h"
#include "sperror.h"
#include "util.h"
#include "outdata.h"
#include "cktext.h"
Include dependency graph for pzan.c:

Go to the source code of this file.

Macros

#define DEBUG   if (0)
 

Functions

static int PZinit ()
 
static int PZpost ()
 
int PZan (GENERIC *cktp, int reset)
 
static int PZinit (CKTcircuit *ckt)
 
static int PZpost (CKTcircuit *ckt)
 
int CKTpzSetup (CKTcircuit *ckt, int type)
 

Macro Definition Documentation

#define DEBUG   if (0)

Definition at line 26 of file pzan.c.

Function Documentation

int CKTpzSetup ( CKTcircuit ckt,
int  type 
)

Definition at line 225 of file pzan.c.

234 {
235  extern SPICEdev *DEVices[];
236  PZAN *pzan = (PZAN *) ckt->CKTcurJob;
237  SMPmatrix *matrix;
238  int error;
239  int /*i,*/ temp, solution_col, balance_col;
240  int input_pos, input_neg, output_pos, output_neg;
241  struct sCKTmodHead *mh;
242  int (*func)();
243 
244  NIdestroy(ckt);
245  error = NIinit(ckt);
246  if (error)
247  return(error);
248  matrix = ckt->CKTmatrix;
249 
250  /* Really awful . . . */
251  ckt->CKTnumStates = 0;
252 
253  for (mh = ckt->CKTheadList; mh != NULL; mh = mh->next) {
254  if ((func = DEVices[mh->type]->DEVpzSetup) != NULL) {
255  error = (*func)(matrix, mh->head,ckt,&ckt->CKTnumStates);
256  if (error)
257  return(error);
258  }
259  }
260 
261  solution_col = 0;
262  balance_col = 0;
263 
264  input_pos = pzan->PZin_pos;
265  input_neg = pzan->PZin_neg;
266 
267  if (type == PZ_DO_ZEROS) {
268  /* Vo/Ii in Y */
269  output_pos = pzan->PZout_pos;
270  output_neg = pzan->PZout_neg;
271  }
272  else if (pzan->PZinput_type == PZ_IN_VOL) {
273  /* Vi/Ii in Y */
274  output_pos = pzan->PZin_pos;
275  output_neg = pzan->PZin_neg;
276  }
277  else {
278  /* Denominator */
279  output_pos = 0;
280  output_neg = 0;
281  input_pos = 0;
282  input_neg = 0;
283  }
284 
285  if (output_pos) {
286  solution_col = output_pos;
287  if (output_neg)
288  balance_col = output_neg;
289  }
290  else {
291  solution_col = output_neg;
292  temp = input_pos;
293  input_pos = input_neg;
294  input_neg = temp;
295  }
296 
297  if (input_pos)
298  pzan->PZdrive_pptr = spGetElement(matrix, input_pos, solution_col);
299  else
300  pzan->PZdrive_pptr = NULL;
301 
302  if (input_neg)
303  pzan->PZdrive_nptr = spGetElement(matrix, input_neg, solution_col);
304  else
305  pzan->PZdrive_nptr = NULL;
306 
307  pzan->PZsolution_col = solution_col;
308  pzan->PZbalance_col = balance_col;
309 
310  pzan->PZnumswaps = 1;
311 
312  error = NIreinit(ckt);
313  if (error)
314  return (error);
315 
316  return (OK);
317 }
int PZbalance_col
Definition: pzdefs.h:34
SPICEdev * DEVices[]
Definition: sconfig.c:109
SMPmatrix * CKTmatrix
Definition: cktdefs.h:95
int PZin_neg
Definition: pzdefs.h:28
int PZin_pos
Definition: pzdefs.h:27
int NIinit()
int PZout_pos
Definition: pzdefs.h:29
int NIreinit()
int(* DEVpzSetup)()
Definition: devdefs.h:94
#define OK
Definition: iferrmsg.h:17
int PZsolution_col
Definition: pzdefs.h:35
struct sCKTmodHead * CKTheadList
Definition: cktdefs.h:63
#define NULL
Definition: spdefs.h:121
Definition: types.c:18
void NIdestroy()
int PZinput_type
Definition: pzdefs.h:31
int PZnumswaps
Definition: pzdefs.h:33
int CKTnumStates
Definition: cktdefs.h:138
Definition: fteparse.h:37
spREAL * spGetElement()
double * PZdrive_pptr
Definition: pzdefs.h:40
#define PZ_DO_ZEROS
Definition: pzdefs.h:45
double * PZdrive_nptr
Definition: pzdefs.h:41
int PZout_neg
Definition: pzdefs.h:30
#define PZ_IN_VOL
Definition: pzdefs.h:46
#define SMPmatrix
Definition: smpdefs.h:11
JOB * CKTcurJob
Definition: cktdefs.h:216
Definition: pzdefs.h:23
int PZan ( GENERIC cktp,
int  reset 
)

Definition at line 31 of file pzan.c.

35 {
36  CKTcircuit *ckt = (CKTcircuit *)cktp;
37  PZAN *pzan = (PZAN *) ckt->CKTcurJob;
38  int error;
39 
40  if (ckt->CKTjjPresent) {
41  (*(SPfrontEnd->IFerror))(ERR_FATAL,
42  "PZ analysis not possible with Josephson junctions", NULL);
43  return (OK);
44  }
45  error = PZinit(ckt);
46  if (error != OK)
47  return error;
48 
49  /* Calculate small signal parameters at the operating point */
50  error = CKTop(ckt,
53  ckt->CKTdcMaxIter);
54  if (error)
55  return (error);
56 
58  error = CKTload(ckt);
59  if (error)
60  return (error);
61 
62  if (pzan->PZwhich & PZ_DO_POLES) {
63  error = CKTpzSetup(ckt, PZ_DO_POLES);
64  if (error != OK)
65  return (error);
66  error = CKTpzFindZeros(ckt,
67  (GENERIC**)&pzan->PZpoleList, &pzan->PZnPoles);
68  if (error != OK)
69  return (error);
70  }
71 
72  if (pzan->PZwhich & PZ_DO_ZEROS) {
73  error = CKTpzSetup(ckt, PZ_DO_ZEROS);
74  if (error != OK)
75  return (error);
76  error = CKTpzFindZeros(ckt,
77  (GENERIC**)&pzan->PZzeroList, &pzan->PZnZeros);
78  if (error != OK)
79  return (error);
80  }
81 
82  return PZpost(ckt);
83 }
CKTpzFindZeros(CKTcircuit *ckt, GENERIC **rootinfoptr, int *rootcount)
Definition: pzstr.c:104
static int PZinit()
if(TDesc==NULL)
Definition: cd.c:1326
#define MODEINITFLOAT
Definition: cktdefs.h:156
#define ERR_FATAL
Definition: ifsim.h:518
int CKTpzSetup(CKTcircuit *ckt, int type)
Definition: pzan.c:225
IFfrontEnd * SPfrontEnd
Definition: main.c:917
#define OK
Definition: iferrmsg.h:17
int PZnZeros
Definition: pzdefs.h:39
#define NULL
Definition: spdefs.h:121
PZtrial * PZzeroList
Definition: pzdefs.h:37
#define MODEINITSMSIG
Definition: cktdefs.h:159
int CKTjjPresent
Definition: cktdefs.h:168
int PZnPoles
Definition: pzdefs.h:38
#define PZ_DO_POLES
Definition: pzdefs.h:44
int CKTload()
int CKTop()
#define PZ_DO_ZEROS
Definition: pzdefs.h:45
#define MODEDCOP
Definition: cktdefs.h:150
JOB * CKTcurJob
Definition: cktdefs.h:216
long CKTmode
Definition: cktdefs.h:139
PZtrial * PZpoleList
Definition: pzdefs.h:36
#define MODEINITJCT
Definition: cktdefs.h:157
static int PZpost()
int CKTdcMaxIter
Definition: cktdefs.h:171
int PZwhich
Definition: pzdefs.h:32
char GENERIC
Definition: ifsim.h:27
Definition: pzdefs.h:23
static int PZinit ( )
static
static int PZinit ( CKTcircuit ckt)
static

Definition at line 87 of file pzan.c.

93 {
94  PZAN *pzan = (PZAN *) ckt->CKTcurJob;
95  int i;
96 
97  if ((i = CKTtypelook("transmission line")) != -1 &&
98  ckt->CKThead[i] != NULL)
99  ERROR(E_XMISSIONLINE, "Transmission lines not supported")
100 
101  pzan->PZpoleList = (PZtrial *) NULL;
102  pzan->PZzeroList = (PZtrial *) NULL;
103  pzan->PZnPoles = 0;
104  pzan->PZnZeros = 0;
105 
106  if (pzan->PZin_pos == pzan->PZin_neg)
107  ERROR(E_SHORT, "Input is shorted")
108 
109  if (pzan->PZout_pos == pzan->PZout_neg)
110  ERROR(E_SHORT, "Output is shorted")
111 
112  if (pzan->PZin_pos == pzan->PZout_pos
113  && pzan->PZin_neg == pzan->PZout_neg
114  && pzan->PZinput_type == PZ_IN_VOL)
115  ERROR(E_INISOUT, "Transfer function is unity")
116  else
117  if (pzan->PZin_pos == pzan->PZout_neg
118  && pzan->PZin_neg == pzan->PZout_pos
119  && pzan->PZinput_type == PZ_IN_VOL)
120  ERROR(E_INISOUT, "Transfer function is -1")
121 
122  return (OK);
123 }
if(TDesc==NULL)
Definition: cd.c:1326
#define ERROR(CODE, MESSAGE)
Definition: util.h:66
int PZin_neg
Definition: pzdefs.h:28
int PZin_pos
Definition: pzdefs.h:27
int CKTtypelook()
#define E_SHORT
Definition: sperror.h:24
#define OK
Definition: iferrmsg.h:17
int PZnZeros
Definition: pzdefs.h:39
#define E_INISOUT
Definition: sperror.h:25
#define NULL
Definition: spdefs.h:121
PZtrial * PZzeroList
Definition: pzdefs.h:37
#define E_XMISSIONLINE
Definition: sperror.h:22
int PZnPoles
Definition: pzdefs.h:38
return(True)
Definition: pzdefs.h:13
#define PZ_IN_VOL
Definition: pzdefs.h:46
GENmodel * CKThead[MAXNUMDEVS]
Definition: cktdefs.h:64
JOB * CKTcurJob
Definition: cktdefs.h:216
PZtrial * PZpoleList
Definition: pzdefs.h:36
Definition: pzdefs.h:23
static int PZpost ( )
static
static int PZpost ( CKTcircuit ckt)
static

Definition at line 127 of file pzan.c.

133 {
134  PZAN *pzan = (PZAN *) ckt->CKTcurJob;
135  GENERIC *pzPlotPtr = NULL; /* the plot pointer for front end */
136  IFcomplex *out_list;
137  IFvalue outData; /* output variable (points to out_list) */
138  IFuid *namelist;
139  PZtrial *root;
140  char name[50];
141  int i, j;
142  struct sOUTdata outd;
143 
144  namelist = (IFuid *) MALLOC((pzan->PZnPoles
145  + pzan->PZnZeros)*sizeof(IFuid));
146  out_list = (IFcomplex *)MALLOC((pzan->PZnPoles
147  + pzan->PZnZeros)*sizeof(IFcomplex));
148 
149  j = 0;
150  for (i = 0; i < pzan->PZnPoles; i++) {
151  sprintf(name, "pole(%-u)", i+1);
152  (*(SPfrontEnd->IFnewUid))(ckt,&(namelist[j++]),(IFuid)NULL,
153  name,UID_OTHER,(GENERIC **)NULL);
154  }
155  for (i = 0; i < pzan->PZnZeros; i++) {
156  sprintf(name, "zero(%-u)", i+1);
157  (*(SPfrontEnd->IFnewUid))(ckt,&(namelist[j++]),(IFuid)NULL,
158  name,UID_OTHER,(GENERIC **)NULL);
159  }
160 
161  outd.circuitPtr = (GENERIC *)ckt;
162  outd.analysisPtr = (GENERIC*)pzan;
163  outd.analName = pzan->JOBname;
164  outd.refName = (IFuid)NULL;
165  outd.refType = (int)0;
166  outd.numNames = pzan->PZnPoles + pzan->PZnZeros;
167  outd.dataNames = namelist;
168  outd.dataType = IF_COMPLEX;
169  outd.plotPtr = &pzPlotPtr;
170  outd.numPts = 1;
171  outd.initValue = 0;
172  outd.finalValue = 0;
173  outd.step = 0;
174  (*SPfrontEnd->OUTbeginPlot)((GENERIC*)&outd);
175 
176  j = 0;
177  if (pzan->PZnPoles > 0) {
178  for (root = pzan->PZpoleList; root != NULL; root = root->next) {
179  for (i = 0; i < root->multiplicity; i++) {
180  out_list[j].real = root->s.real;
181  out_list[j].imag = root->s.imag;
182  j += 1;
183  if (root->s.imag != 0.0) {
184  out_list[j].real = root->s.real;
185  out_list[j].imag = -root->s.imag;
186  j += 1;
187  }
188  }
189  DEBUG printf("LIST pole: (%g,%g) x %d\n",
190  root->s.real, root->s.imag, root->multiplicity);
191  }
192  }
193 
194  if (pzan->PZnZeros > 0) {
195  for (root = pzan->PZzeroList; root != NULL; root = root->next) {
196  for (i = 0; i < root->multiplicity; i++) {
197  out_list[j].real = root->s.real;
198  out_list[j].imag = root->s.imag;
199  j += 1;
200  if (root->s.imag != 0.0) {
201  out_list[j].real = root->s.real;
202  out_list[j].imag = -root->s.imag;
203  j += 1;
204  }
205  }
206  DEBUG printf("LIST zero: (%g,%g) x %d\n",
207  root->s.real, root->s.imag, root->multiplicity);
208  }
209  }
210 
211  outData.v.numValue = pzan->PZnPoles + pzan->PZnZeros;
212  outData.v.vec.cVec = out_list;
213 
214  (*SPfrontEnd->OUTdata)(pzPlotPtr, (IFvalue *) 0, &outData);
215  (*(SPfrontEnd->OUTendPlot))(pzPlotPtr);
216 
217  FREE(out_list);
218  FREE(namelist);
219 
220  return(OK);
221 }
int numPts
Definition: outdata.h:22
double initValue
Definition: outdata.h:24
#define IF_COMPLEX
Definition: ifsim.h:109
int refType
Definition: outdata.h:17
IFuid * dataNames
Definition: outdata.h:19
IFuid analName
Definition: outdata.h:15
if(TDesc==NULL)
Definition: cd.c:1326
int numNames
Definition: outdata.h:18
IFfrontEnd * SPfrontEnd
Definition: main.c:917
#define DEBUG
Definition: pzan.c:26
double step
Definition: outdata.h:26
#define FREE(ptr)
Definition: spdefs.h:436
int OUTbeginPlot()
#define OK
Definition: iferrmsg.h:17
GENERIC * IFuid
Definition: ifsim.h:72
int PZnZeros
Definition: pzdefs.h:39
#define MALLOC(x)
Definition: util.h:9
#define NULL
Definition: spdefs.h:121
GENERIC * circuitPtr
Definition: outdata.h:13
int PZnPoles
Definition: pzdefs.h:38
struct sIFcomplex IFcomplex
double finalValue
Definition: outdata.h:25
#define UID_OTHER
Definition: ifsim.h:85
GENERIC * analysisPtr
Definition: outdata.h:14
Definition: pzdefs.h:13
GENERIC ** plotPtr
Definition: outdata.h:21
JOB * CKTcurJob
Definition: cktdefs.h:216
IFuid refName
Definition: outdata.h:16
char GENERIC
Definition: ifsim.h:27
int dataType
Definition: outdata.h:20
Definition: pzdefs.h:23