1 /**********
2 Copyright 1990 Regents of the University of California. All rights reserved.
3 Author: 1985 Thomas L. Quarles
4 **********/
5
6 #include "ngspice/ngspice.h"
7 #include "ngspice/smpdefs.h"
8 #include "ngspice/cktdefs.h"
9 #include "vsrcdefs.h"
10 #include "ngspice/sperror.h"
11 #include "ngspice/suffix.h"
12
13 /* ARGSUSED */
14 int
VSRCsetup(SMPmatrix * matrix,GENmodel * inModel,CKTcircuit * ckt,int * state)15 VSRCsetup(SMPmatrix *matrix, GENmodel *inModel, CKTcircuit *ckt, int *state)
16 /* load the voltage source structure with those pointers needed later
17 * for fast matrix loading
18 */
19 {
20 VSRCmodel *model = (VSRCmodel *)inModel;
21 VSRCinstance *here;
22 CKTnode *tmp;
23 int error;
24
25 NG_IGNORE(state);
26
27 /* loop through all the voltage source models */
28 for( ; model != NULL; model = VSRCnextModel(model)) {
29
30 /* loop through all the instances of the model */
31 for (here = VSRCinstances(model); here != NULL ;
32 here=VSRCnextInstance(here)) {
33
34 if(here->VSRCposNode == here->VSRCnegNode) {
35 SPfrontEnd->IFerrorf (ERR_FATAL,
36 "instance %s is a shorted VSRC", here->VSRCname);
37 return(E_UNSUPP);
38 }
39
40 if(here->VSRCbranch == 0) {
41 error = CKTmkCur(ckt,&tmp,here->VSRCname,"branch");
42 if(error) return(error);
43 here->VSRCbranch = tmp->number;
44 }
45
46 /* macro to make elements with built in test for out of memory */
47 #define TSTALLOC(ptr,first,second) \
48 do { if((here->ptr = SMPmakeElt(matrix, here->first, here->second)) == NULL){\
49 return(E_NOMEM);\
50 } } while(0)
51
52 TSTALLOC(VSRCposIbrPtr, VSRCposNode, VSRCbranch);
53 TSTALLOC(VSRCnegIbrPtr, VSRCnegNode, VSRCbranch);
54 TSTALLOC(VSRCibrNegPtr, VSRCbranch, VSRCnegNode);
55 TSTALLOC(VSRCibrPosPtr, VSRCbranch, VSRCposNode);
56 }
57 }
58 return(OK);
59 }
60
61 int
VSRCunsetup(GENmodel * inModel,CKTcircuit * ckt)62 VSRCunsetup(GENmodel *inModel, CKTcircuit *ckt)
63 {
64 VSRCmodel *model;
65 VSRCinstance *here;
66
67 for (model = (VSRCmodel *)inModel; model != NULL;
68 model = VSRCnextModel(model))
69 {
70 for (here = VSRCinstances(model); here != NULL;
71 here=VSRCnextInstance(here))
72 {
73 if (here->VSRCbranch > 0)
74 CKTdltNNum(ckt, here->VSRCbranch);
75 here->VSRCbranch = 0;
76 }
77 }
78 return OK;
79 }
80