-
Notifications
You must be signed in to change notification settings - Fork 0
/
res.patch.old
318 lines (300 loc) · 13 KB
/
res.patch.old
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
diff -aur ngspice-26.origin/src/spicelib/devices/res/resask.c ngspice-26.new/src/spicelib/devices/res/resask.c
--- ngspice-26.origin/src/spicelib/devices/res/resask.c 2014-01-11 16:28:59.000000000 +0100
+++ ngspice-26.new/src/spicelib/devices/res/resask.c 2014-09-03 11:08:20.489567000 +0200
@@ -27,6 +27,10 @@
double sr;
double si;
double vm;
+ char *activityString;
+ double activity;
+ char *workingZoneString;
+ double workingZone;
static char *msg = "Current and power not available for ac analysis";
switch(which) {
@@ -176,9 +180,75 @@
errMsg = TMALLOC(char, strlen(msgloc) + 1);
errRtn = "RESask";
strcpy(errMsg, msgloc);
- return(E_ASKCURRENT);
- }
+ return(E_ASKPOWER);
+ }
+ case RES_MAX_POWER:
+ value->rValue = fast->RESmaxPower;
+ //value->rValue /= fast->RESm;
+ return(OK);
+ case RES_WORKING_ZONE:
+ if (ckt->CKTrhsOld) {
+
+ workingZone=fast->RESpower/fast->RESmaxPower;
+
+ if(workingZone<0.5){
+ workingZoneString = TMALLOC(char, strlen("Sub-optimal") + 10);
+ sprintf(workingZoneString, "suboptimal:%f",workingZone);
+ value->sValue=workingZoneString;
+ }else if(workingZone<=1){
+ workingZoneString = TMALLOC(char, strlen("Optimal") + 10);
+ sprintf(workingZoneString, "optimal:%f",workingZone);
+ value->sValue=workingZoneString;
+ }else if(workingZone<1.1){
+ workingZoneString = TMALLOC(char, strlen("Out of Range") + 10);
+ sprintf(workingZoneString, "outofrange:%f",workingZone);
+ value->sValue=workingZoneString;
+ }else{
+ workingZoneString = TMALLOC(char, strlen("Destructive") + 10);
+ sprintf(workingZoneString, "destructive:%f",workingZone);
+ value->sValue=workingZoneString;
+ }
+ }else{
+ workingZoneString = TMALLOC(char, strlen("Unknown"));
+ sprintf(workingZoneString, "Unknown");
+ value->sValue=workingZoneString;
+ }
+
+ //value->rValue /= fast->RESm;
+ return(OK);
+ case RES_ACTIVITY:
+ if(ckt->CKTrhsOld){
+ if(ckt->CKTcurrentAnalysis & (DOING_AC | DOING_TRAN)){
+ activity=fast->RESenergySum/ckt->CKTtimePoints[ckt->CKTtimeIndex]; // mean dissipated power
+ activity+=(fast->RESpower/*-fast->RESoldPower*/)/ckt->CKTdeltaList[ckt->CKTtimeIndex]; //divide by time lapse
+ activity/=(fast->RESmaxPower); // normalize
+ }else{ //dc or op
+ activity=fast->RESpower/(fast->RESmaxPower);
+ }
+ if(activity<0.1){
+ activityString = TMALLOC(char, strlen("Inactive") + 10);
+ sprintf(activityString, "inactive:%f",activity);
+ value->sValue=activityString;
+ }else if(activity<0.3){
+ activityString = TMALLOC(char, strlen("Sub-active") + 10);
+ sprintf(activityString, "subactive:%f",activity);
+ value->sValue=activityString;
+ }else if(activity<=1.0){
+ activityString = TMALLOC(char, strlen("Normal-active") + 10);
+ sprintf(activityString, "normalactive:%f",activity);
+ value->sValue=activityString;
+ }else{
+ activityString = TMALLOC(char, strlen("Over-active") + 10);
+ sprintf(activityString, "overactive:%f",activity);
+ value->sValue=activityString;
+ }
+ }else{
+ activityString = TMALLOC(char, strlen("Unknown"));
+ sprintf(activityString, "Unknown");
+ value->sValue=activityString;
+ }
+ return(OK);
default:
return(E_BADPARM);
}
diff -aur ngspice-26.origin/src/spicelib/devices/res/res.c ngspice-26.new/src/spicelib/devices/res/res.c
--- ngspice-26.origin/src/spicelib/devices/res/res.c 2014-01-11 16:28:59.000000000 +0100
+++ ngspice-26.new/src/spicelib/devices/res/res.c 2014-09-03 10:09:18.369423000 +0200
@@ -14,8 +14,7 @@
IOPP( "resistance", RES_RESIST, IF_REAL, "Resistance"),
IOPAA( "ac", RES_ACRESIST, IF_REAL, "AC resistance value"),
IOPZU( "temp", RES_TEMP, IF_REAL, "Instance operating temperature"),
- IOPZ( "dtemp", RES_DTEMP, IF_REAL,
- "Instance temperature difference with the rest of the circuit"),
+ IOPZ( "dtemp", RES_DTEMP, IF_REAL, "Instance temperature difference with the rest of the circuit"),
IOPQU( "l", RES_LENGTH, IF_REAL, "Length"),
IOPZU( "w", RES_WIDTH, IF_REAL, "Width"),
IOPU( "m", RES_M, IF_REAL, "Multiplication factor"),
@@ -36,7 +35,11 @@
"dc sensitivity and imag part of ac sensitivity"),
OPU( "sens_mag", RES_QUEST_SENS_MAG, IF_REAL, "ac sensitivity of magnitude"),
OPU( "sens_ph", RES_QUEST_SENS_PH, IF_REAL, "ac sensitivity of phase"),
- OPU( "sens_cplx", RES_QUEST_SENS_CPLX, IF_COMPLEX, "ac sensitivity")
+ OPU( "sens_cplx", RES_QUEST_SENS_CPLX, IF_COMPLEX, "ac sensitivity"),
+ IOPP( "max_power", RES_MAX_POWER, IF_REAL, "max power value"),
+ IOP( "activity", RES_ACTIVITY, IF_STRING, "activity emotion"),
+ IOP( "work_zone", RES_WORKING_ZONE, IF_STRING, "working zone emotion"),
+ IOPU( "energy_sum", RES_ENERGY_SUM, IF_REAL, "activity power sum")
};
IFparm RESmPTable[] = { /* model parameters */
diff -aur ngspice-26.origin/src/spicelib/devices/res/resdefs.h ngspice-26.new/src/spicelib/devices/res/resdefs.h
--- ngspice-26.origin/src/spicelib/devices/res/resdefs.h 2014-01-11 16:28:59.000000000 +0100
+++ ngspice-26.new/src/spicelib/devices/res/resdefs.h 2014-09-03 10:40:34.336166000 +0200
@@ -67,6 +67,16 @@
unsigned RESbv_maxGiven : 1; /* flags indicates maximum voltage is given */
int RESsenParmNo; /* parameter # for sensitivity use;
* set equal to 0 if not a design parameter*/
+ unsigned RESmaxPowerGiven :1;
+ unsigned RESactivityGiven :1;
+ unsigned RESworkingZoneGiven :1;
+
+ double RESenergySum;
+ double RESoldPower;
+ double RESpower;
+ double RESmaxPower;
+ char *RESactivity;
+ char *RESworkingZone;
/* indices to array of RES noise sources */
@@ -96,6 +106,8 @@
* model */
IFuid RESmodName; /* pointer to character string naming this model */
+ /* --- end of generic struct GENmodel --- */
+
double REStnom; /* temperature at which resistance measured */
double REStempCoeff1; /* first temperature coefficient of resistors */
double REStempCoeff2; /* second temperature coefficient of resistors */
@@ -120,6 +132,7 @@
unsigned RESfNexpGiven :1; /* flag to indicate af given */
unsigned RESresGiven :1; /* flag to indicate model resistance given */
unsigned RESbv_maxGiven :1; /* flags indicates maximum voltage is given */
+
} RESmodel;
/* device parameters */
@@ -142,6 +155,12 @@
#define RES_TC1 16
#define RES_TC2 17
#define RES_BV_MAX 18
+/*emotions*/
+#define RES_MAX_POWER 19
+#define RES_ACTIVITY 20
+#define RES_WORKING_ZONE 21
+#define RES_ENERGY_SUM 22
+#define RES_OLD_POWER 23
/* model parameters */
#define RES_MOD_TC1 101
@@ -157,6 +176,7 @@
#define RES_MOD_AF 111
#define RES_MOD_BV_MAX 112
+
/* device questions */
#define RES_QUEST_SENS_REAL 201
#define RES_QUEST_SENS_IMAG 202
diff -aur ngspice-26.origin/src/spicelib/devices/res/resinit.c ngspice-26.new/src/spicelib/devices/res/resinit.c
--- ngspice-26.origin/src/spicelib/devices/res/resinit.c 2014-01-11 16:28:59.000000000 +0100
+++ ngspice-26.new/src/spicelib/devices/res/resinit.c 2014-08-04 14:30:53.914850000 +0200
@@ -10,7 +10,7 @@
SPICEdev RESinfo = {
{
"Resistor",
- "Simple linear resistor",
+ "emotional linear resistor",
&RESnSize,
&RESnSize,
diff -aur ngspice-26.origin/src/spicelib/devices/res/resload.c ngspice-26.new/src/spicelib/devices/res/resload.c
--- ngspice-26.origin/src/spicelib/devices/res/resload.c 2014-01-11 16:28:59.000000000 +0100
+++ ngspice-26.new/src/spicelib/devices/res/resload.c 2014-09-03 11:17:50.972924000 +0200
@@ -17,7 +17,6 @@
{
RESmodel *model = (RESmodel *)inModel;
double m;
-
/* loop through all the resistor models */
for( ; model != NULL; model = model->RESnextModel ) {
RESinstance *here;
@@ -25,16 +24,27 @@
/* loop through all the instances of the model */
for (here = model->RESinstances; here != NULL ;
here = here->RESnextInstance) {
+
+
+ here->RESoldPower=here->REScurrent*here->REScurrent/here->RESconduct;
+
+
here->REScurrent = (*(ckt->CKTrhsOld+here->RESposNode) -
*(ckt->CKTrhsOld+here->RESnegNode)) * here->RESconduct;
+ here->RESpower=here->REScurrent*here->REScurrent/here->RESconduct;
+
m = (here->RESm);
*(here->RESposPosptr) += m * here->RESconduct;
*(here->RESnegNegptr) += m * here->RESconduct;
*(here->RESposNegptr) -= m * here->RESconduct;
*(here->RESnegPosptr) -= m * here->RESconduct;
+
+ //add power dissipation
+ here->RESenergySum+=here->RESpower*ckt->CKTdelta;
+
}
}
return(OK);
diff -aur ngspice-26.origin/src/spicelib/devices/res/resmask.c ngspice-26.new/src/spicelib/devices/res/resmask.c
--- ngspice-26.origin/src/spicelib/devices/res/resmask.c 2014-01-11 16:28:59.000000000 +0100
+++ ngspice-26.new/src/spicelib/devices/res/resmask.c 2014-08-04 14:30:53.914850000 +0200
@@ -66,6 +66,8 @@
case RES_MOD_R:
value->rValue = model->RESres;
return(OK);
+
+
default:
return(E_BADPARM);
}
diff -aur ngspice-26.origin/src/spicelib/devices/res/resmpar.c ngspice-26.new/src/spicelib/devices/res/resmpar.c
--- ngspice-26.origin/src/spicelib/devices/res/resmpar.c 2014-01-11 16:28:59.000000000 +0100
+++ ngspice-26.new/src/spicelib/devices/res/resmpar.c 2014-08-04 14:30:53.914850000 +0200
@@ -15,6 +15,8 @@
int
RESmParam(int param, IFvalue *value, GENmodel *inModel)
{
+
+
RESmodel *model = (RESmodel *)inModel;
switch(param) {
@@ -34,6 +36,8 @@
model->RESsheetRes = value->rValue;
model->RESsheetResGiven = TRUE;
break;
+
+
case RES_MOD_DEFWIDTH:
model->RESdefWidth = value->rValue;
model->RESdefWidthGiven = TRUE;
diff -aur ngspice-26.origin/src/spicelib/devices/res/resparam.c ngspice-26.new/src/spicelib/devices/res/resparam.c
--- ngspice-26.origin/src/spicelib/devices/res/resparam.c 2014-01-11 16:28:59.000000000 +0100
+++ ngspice-26.new/src/spicelib/devices/res/resparam.c 2014-08-04 14:30:53.914850000 +0200
@@ -78,6 +78,11 @@
here->RESbv_max = value->rValue;
here->RESbv_maxGiven = TRUE;
break;
+ case RES_MAX_POWER:
+ here->RESmaxPower = value->rValue;
+ here->RESmaxPowerGiven=TRUE;
+ break;
+
default:
return(E_BADPARM);
}
diff -aur ngspice-26.origin/src/spicelib/devices/res/ressetup.c ngspice-26.new/src/spicelib/devices/res/ressetup.c
--- ngspice-26.origin/src/spicelib/devices/res/ressetup.c 2014-01-11 16:28:59.000000000 +0100
+++ ngspice-26.new/src/spicelib/devices/res/ressetup.c 2014-09-03 10:29:48.802806000 +0200
@@ -10,8 +10,7 @@
#include "ngspice/sperror.h"
-int
-RESsetup(SMPmatrix *matrix, GENmodel *inModel, CKTcircuit*ckt, int *state)
+int RESsetup(SMPmatrix *matrix, GENmodel *inModel, CKTcircuit*ckt, int *state)
/* load the resistor structure with those pointers needed later
* for fast matrix loading
*/
@@ -36,13 +35,15 @@
here->RESm = 1.0;
if(!here->RESbv_maxGiven)
here->RESbv_max = model->RESbv_max;
+
+ //
+ here->RESenergySum=0;
/* macro to make elements with built in test for out of memory */
#define TSTALLOC(ptr,first,second) \
do { if((here->ptr = SMPmakeElt(matrix, here->first, here->second)) == NULL){\
return(E_NOMEM);\
} } while(0)
-
TSTALLOC(RESposPosptr, RESposNode, RESposNode);
TSTALLOC(RESnegNegptr, RESnegNode, RESnegNode);
TSTALLOC(RESposNegptr, RESposNode, RESnegNode);
diff -aur ngspice-26.origin/src/spicelib/devices/res/restemp.c ngspice-26.new/src/spicelib/devices/res/restemp.c
--- ngspice-26.origin/src/spicelib/devices/res/restemp.c 2014-01-11 16:28:59.000000000 +0100
+++ ngspice-26.new/src/spicelib/devices/res/restemp.c 2014-08-04 14:30:53.914850000 +0200
@@ -10,8 +10,7 @@
#include "resdefs.h"
#include "ngspice/sperror.h"
-int
-REStemp(GENmodel *inModel, CKTcircuit *ckt)
+int REStemp(GENmodel *inModel, CKTcircuit *ckt)
/* perform the temperature update to the resistors
* calculate the conductance as a function of the
* given nominal and current temperatures - the