1 /**********
2 Copyright 1990 Regents of the University of California. All rights reserved.
3 **********/
4
5 /* CKTpzSetup(ckt)
6 * iterate through all the various
7 * pzSetup functions provided for the circuit elements in the
8 * given circuit, setup ...
9 */
10
11 #include "ngspice/ngspice.h"
12 #include "ngspice/smpdefs.h"
13 #include "ngspice/cktdefs.h"
14 #include "ngspice/devdefs.h"
15 #include "ngspice/sperror.h"
16
17
18 int
CKTpzSetup(CKTcircuit * ckt,int type)19 CKTpzSetup(CKTcircuit *ckt, int type)
20 {
21 PZAN *job = (PZAN *) ckt->CKTcurJob;
22
23 SMPmatrix *matrix;
24 int error;
25 int i, solution_col, balance_col;
26 int input_pos, input_neg, output_pos, output_neg;
27
28 NIdestroy(ckt);
29 error = NIinit(ckt);
30 if (error)
31 return(error);
32 matrix = ckt->CKTmatrix;
33
34 /* Really awful . . . */
35 ckt->CKTnumStates = 0;
36
37 for (i = 0; i < DEVmaxnum; i++) {
38 if (DEVices[i] && DEVices[i]->DEVpzSetup != NULL && ckt->CKThead[i] != NULL) {
39 error = DEVices[i]->DEVpzSetup (matrix, ckt->CKThead[i],
40 ckt, &ckt->CKTnumStates);
41 if (error != OK)
42 return(error);
43 }
44 }
45
46 solution_col = 0;
47 balance_col = 0;
48
49 input_pos = job->PZin_pos;
50 input_neg = job->PZin_neg;
51
52 if (type == PZ_DO_ZEROS) {
53 /* Vo/Ii in Y */
54 output_pos = job->PZout_pos;
55 output_neg = job->PZout_neg;
56 } else if (job->PZinput_type == PZ_IN_VOL) {
57 /* Vi/Ii in Y */
58 output_pos = job->PZin_pos;
59 output_neg = job->PZin_neg;
60 } else {
61 /* Denominator */
62 output_pos = 0;
63 output_neg = 0;
64 input_pos = 0;
65 input_neg = 0;
66 }
67
68 if (output_pos) {
69 solution_col = output_pos;
70 if (output_neg)
71 balance_col = output_neg;
72 } else {
73 solution_col = output_neg;
74 SWAP(int, input_pos, input_neg);
75 }
76
77 if (input_pos)
78 job->PZdrive_pptr = SMPmakeElt(matrix, input_pos, solution_col);
79 else
80 job->PZdrive_pptr = NULL;
81
82 if (input_neg)
83 job->PZdrive_nptr = SMPmakeElt(matrix, input_neg, solution_col);
84 else
85 job->PZdrive_nptr = NULL;
86
87 job->PZsolution_col = solution_col;
88 job->PZbalance_col = balance_col;
89
90 job->PZnumswaps = 1;
91
92 error = NIreinit(ckt);
93 if (error)
94 return(error);
95
96 return OK;
97 }
98