1 /********** 2 Copyright 1990 Regents of the University of California. All rights reserved. 3 Author: 1985 Thomas L. Quarles 4 **********/ 5 6 /* actually load the current inductance value into the 7 * sparse matrix previously provided 8 */ 9 10 #include "ngspice/ngspice.h" 11 #include "ngspice/cktdefs.h" 12 #include "inddefs.h" 13 #include "ngspice/trandefs.h" 14 #include "ngspice/sperror.h" 15 #include "ngspice/suffix.h" 16 17 int INDload(GENmodel * inModel,CKTcircuit * ckt)18INDload(GENmodel *inModel, CKTcircuit *ckt) 19 { 20 INDmodel *model = (INDmodel*)inModel; 21 INDinstance *here; 22 double veq; 23 double req; 24 double m; 25 int error; 26 27 MUTinstance *muthere; 28 MUTmodel *mutmodel; 29 int ktype; 30 int itype; 31 32 /* loop through all the inductor models */ 33 for( ; model != NULL; model = INDnextModel(model)) { 34 35 /* loop through all the instances of the model */ 36 for (here = INDinstances(model); here != NULL ; 37 here=INDnextInstance(here)) { 38 39 m = (here->INDm); 40 41 if(!(ckt->CKTmode & (MODEDC|MODEINITPRED))) { 42 if(ckt->CKTmode & MODEUIC && ckt->CKTmode & MODEINITTRAN) { 43 *(ckt->CKTstate0 + here->INDflux) = here->INDinduct / m * 44 here->INDinitCond; 45 } else { 46 *(ckt->CKTstate0 + here->INDflux) = here->INDinduct / m * 47 *(ckt->CKTrhsOld + here->INDbrEq); 48 } 49 } 50 } 51 } 52 ktype = CKTtypelook("mutual"); 53 mutmodel = (MUTmodel *)(ckt->CKThead[ktype]); 54 /* loop through all the mutual inductor models */ 55 for( ; mutmodel != NULL; mutmodel = MUTnextModel(mutmodel)) { 56 57 /* loop through all the instances of the model */ 58 for (muthere = MUTinstances(mutmodel); muthere != NULL ; 59 muthere=MUTnextInstance(muthere)) { 60 61 if(!(ckt->CKTmode& (MODEDC|MODEINITPRED))) { 62 /* set initial conditions for mutual inductance here, if uic is set */ 63 if (ckt->CKTmode & MODEUIC && ckt->CKTmode & MODEINITTRAN) { 64 *(ckt->CKTstate0 + muthere->MUTind1->INDflux) += 65 muthere->MUTfactor * muthere->MUTind2->INDinitCond; 66 67 *(ckt->CKTstate0 + muthere->MUTind2->INDflux) += 68 muthere->MUTfactor * muthere->MUTind1->INDinitCond; 69 } 70 else { 71 *(ckt->CKTstate0 + muthere->MUTind1->INDflux) += 72 muthere->MUTfactor * *(ckt->CKTrhsOld + 73 muthere->MUTind2->INDbrEq); 74 75 *(ckt->CKTstate0 + muthere->MUTind2->INDflux) += 76 muthere->MUTfactor * *(ckt->CKTrhsOld + 77 muthere->MUTind1->INDbrEq); 78 } 79 } 80 *(muthere->MUTbr1br2Ptr) -= muthere->MUTfactor*ckt->CKTag[0]; 81 *(muthere->MUTbr2br1Ptr) -= muthere->MUTfactor*ckt->CKTag[0]; 82 } 83 } 84 itype = CKTtypelook("Inductor"); 85 model = (INDmodel *)(ckt->CKThead[itype]); 86 /* loop through all the inductor models */ 87 for( ; model != NULL; model = INDnextModel(model)) { 88 89 /* loop through all the instances of the model */ 90 for (here = INDinstances(model); here != NULL ; 91 here=INDnextInstance(here)) { 92 93 if(ckt->CKTmode & MODEDC) { 94 req = 0.0; 95 veq = 0.0; 96 } else { 97 double newmind; 98 #ifndef PREDICTOR 99 if(ckt->CKTmode & MODEINITPRED) { 100 *(ckt->CKTstate0 + here->INDflux) = 101 *(ckt->CKTstate1 + here->INDflux); 102 } else { 103 #endif /*PREDICTOR*/ 104 if (ckt->CKTmode & MODEINITTRAN) { 105 *(ckt->CKTstate1 + here->INDflux) = 106 *(ckt->CKTstate0 + here->INDflux); 107 } 108 #ifndef PREDICTOR 109 } 110 #endif /*PREDICTOR*/ 111 m = (here->INDm); 112 newmind = here->INDinduct/m; 113 error=NIintegrate(ckt,&req,&veq,newmind,here->INDflux); 114 if(error) return(error); 115 } 116 117 *(ckt->CKTrhs+here->INDbrEq) += veq; 118 119 if(ckt->CKTmode & MODEINITTRAN) { 120 *(ckt->CKTstate1+here->INDvolt) = 121 *(ckt->CKTstate0+here->INDvolt); 122 } 123 124 *(here->INDposIbrPtr) += 1; 125 *(here->INDnegIbrPtr) -= 1; 126 *(here->INDibrPosPtr) += 1; 127 *(here->INDibrNegPtr) -= 1; 128 *(here->INDibrIbrPtr) -= req; 129 } 130 } 131 return(OK); 132 } 133