16 #include "component.h"
20 #ifndef CIR_potentiometer
21 #define CIR_potentiometer -1
32 #define NP(node) real (getV (node))
33 #define BP(pnode,nnode) (NP(pnode) - NP(nnode))
34 #define _load_static_residual2(pnode,nnode,current)\
35 _rhs[pnode] -= current;\
36 _rhs[nnode] += current;
37 #define _load_static_augmented_residual2(pnode,nnode,current)\
38 _rhs[pnode] -= current;\
39 _rhs[nnode] += current;
40 #define _load_static_residual1(node,current)\
41 _rhs[node] -= current;
42 #define _load_static_augmented_residual1(node,current)\
43 _rhs[node] -= current;
44 #define _load_static_jacobian4(pnode,nnode,vpnode,vnnode,conductance)\
45 _jstat[pnode][vpnode] += conductance;\
46 _jstat[nnode][vnnode] += conductance;\
47 _jstat[pnode][vnnode] -= conductance;\
48 _jstat[nnode][vpnode] -= conductance;\
50 _ghs[pnode] += conductance * BP(vpnode,vnnode);\
51 _ghs[nnode] -= conductance * BP(vpnode,vnnode);\
53 _rhs[pnode] += conductance * BP(vpnode,vnnode);\
54 _rhs[nnode] -= conductance * BP(vpnode,vnnode);\
56 #define _load_static_jacobian2p(node,vpnode,vnnode,conductance)\
57 _jstat[node][vpnode] += conductance;\
58 _jstat[node][vnnode] -= conductance;\
60 _ghs[node] += conductance * BP(vpnode,vnnode);\
62 _rhs[node] += conductance * BP(vpnode,vnnode);\
64 #define _load_static_jacobian2s(pnode,nnode,node,conductance)\
65 _jstat[pnode][node] += conductance;\
66 _jstat[nnode][node] -= conductance;\
68 _ghs[pnode] += conductance * NP(node);\
69 _ghs[nnode] -= conductance * NP(node);\
71 _rhs[pnode] += conductance * NP(node);\
72 _rhs[nnode] -= conductance * NP(node);\
74 #define _load_static_jacobian1(node,vnode,conductance)\
75 _jstat[node][vnode] += conductance;\
77 _ghs[node] += conductance * NP(vnode);\
79 _rhs[node] += conductance * NP(vnode);\
81 #define _load_dynamic_residual2(pnode,nnode,charge)\
82 if (doTR) _charges[pnode][nnode] += charge;\
84 _qhs[pnode] -= charge;\
85 _qhs[nnode] += charge;\
87 #define _load_dynamic_residual1(node,charge)\
88 if (doTR) _charges[node][node] += charge;\
90 _qhs[node] -= charge;\
92 #define _load_dynamic_jacobian4(pnode,nnode,vpnode,vnnode,capacitance)\
94 _jdyna[pnode][vpnode] += capacitance;\
95 _jdyna[nnode][vnnode] += capacitance;\
96 _jdyna[pnode][vnnode] -= capacitance;\
97 _jdyna[nnode][vpnode] -= capacitance;\
100 _caps[pnode][nnode][vpnode][vnnode] += capacitance;\
103 _chs[pnode] += capacitance * BP(vpnode,vnnode);\
104 _chs[nnode] -= capacitance * BP(vpnode,vnnode);\
106 #define _load_dynamic_jacobian2s(pnode,nnode,vnode,capacitance)\
108 _jdyna[pnode][vnode] += capacitance;\
109 _jdyna[nnode][vnode] -= capacitance;\
112 _caps[pnode][nnode][vnode][vnode] += capacitance;\
115 _chs[pnode] += capacitance * NP(vnode);\
116 _chs[nnode] -= capacitance * NP(vnode);\
118 #define _load_dynamic_jacobian2p(node,vpnode,vnnode,capacitance)\
120 _jdyna[node][vpnode] += capacitance;\
121 _jdyna[node][vnnode] -= capacitance;\
124 _caps[node][node][vpnode][vnnode] += capacitance;\
127 _chs[node] += capacitance * BP(vpnode,vnnode);\
129 #define _load_dynamic_jacobian1(node,vnode,capacitance)\
131 _jdyna[node][vnode] += capacitance;\
134 _caps[node][node][vnode][vnode] += capacitance;\
137 _chs[node] += capacitance * NP(vnode);\
140 #define _save_whitenoise1(n1,pwr,type)\
141 _white_pwr[n1][n1] += pwr;
142 #define _save_whitenoise2(n1,n2,pwr,type)\
143 _white_pwr[n1][n2] += pwr;
144 #define _save_flickernoise1(n1,pwr,exp,type)\
145 _flicker_pwr[n1][n1] += pwr;\
146 _flicker_exp[n1][n1] += exp;
147 #define _save_flickernoise2(n1,n2,pwr,exp,type)\
148 _flicker_pwr[n1][n2] += pwr;\
149 _flicker_exp[n1][n2] += exp;
150 #define _load_whitenoise2(n1,n2,pwr)\
151 cy (n1,n2) -= pwr/kB/T0; cy (n2,n1) -= pwr/kB/T0;\
152 cy (n1,n1) += pwr/kB/T0; cy (n2,n2) += pwr/kB/T0;
153 #define _load_whitenoise1(n1,pwr)\
154 cy (n1,n1) += pwr/kB/T0;
155 #define _load_flickernoise2(n1,n2,pwr,exp)\
156 cy (n1,n2) -= pwr*pow(_freq,-exp)/kB/T0;\
157 cy (n2,n1) -= pwr*pow(_freq,-exp)/kB/T0;\
158 cy (n1,n1) += pwr*pow(_freq,-exp)/kB/T0;\
159 cy (n2,n2) += pwr*pow(_freq,-exp)/kB/T0;
160 #define _load_flickernoise1(n1,pwr,exp)\
161 cy (n1,n1) += pwr*pow(_freq,-exp)/kB/T0;
164 #define m00_hypot(v00,x,y) v00 = xhypot(x,y);
165 #define m10_hypot(v10,v00,x,y) v10 = (x)/(v00);
166 #define m11_hypot(v11,v00,x,y) v11 = (y)/(v00);
167 #define m00_max(v00,x,y) v00 = ((x)>(y))?(x):(y);
168 #define m10_max(v10,v00,x,y) v10 = ((x)>(y))?1.0:0.0;
169 #define m11_max(v11,v00,x,y) v11 = ((x)>(y))?0.0:1.0;
170 #define m00_min(v00,x,y) v00 = ((x)<(y))?(x):(y);
171 #define m10_min(v10,v00,x,y) v10 = ((x)<(y))?1.0:0.0;
172 #define m11_min(v11,v00,x,y) v11 = ((x)<(y))?0.0:1.0;
173 #define m00_pow(v00,x,y) v00 = pow(x,y);
174 #define m10_pow(v10,v00,x,y) v10 = (x==0.0)?0.0:(v00)*(y)/(x);
175 #define m11_pow(v11,v00,x,y) v11 = (x==0.0)?0.0:(log(x)*(v00));
177 #define m00_div(v00,v10,x,y) double v10=1/(y); double v00=(x)*v10;
178 #define m10_div(v10,v00,vv,x,y)
179 #define m11_div(v11,v00,vv,x,y) double v11 = -v00*vv;
181 #define m00_mult(v00,v10,v11,x,y) double v10=(x); double v11=(y); double v00=v10*v11;
182 #define m00_add(v00,x,y) double v00=(x)+(y);
184 #define m00_cos(v00,x) v00 = cos(x);
185 #define m10_cos(v10,v00,x) v10 = (-sin(x));
186 #define m00_sin(v00,x) v00 = sin(x);
187 #define m10_sin(v10,v00,x) v10 = (cos(x));
188 #define m00_tan(v00,x) v00 = tan(x);
189 #define m10_tan(v10,v00,x) v10 = (1.0/cos(x)/cos(x));
190 #define m00_cosh(v00,x) v00 = cosh(x);
191 #define m10_cosh(v10,v00,x) v10 = (sinh(x));
192 #define m00_sinh(v00,x) v00 = sinh(x);
193 #define m10_sinh(v10,v00,x) v10 = (cosh(x));
194 #define m00_tanh(v00,x) v00 = tanh(x);
195 #define m10_tanh(v10,v00,x) v10 = (1.0/cosh(x)/cosh(x));
196 #define m00_acos(v00,x) v00 = acos(x);
197 #define m10_acos(v10,v00,x) v10 = (-1.0/sqrt(1-x*x));
198 #define m00_asin(v00,x) v00 = asin(x);
199 #define m10_asin(v10,v00,x) v10 = (+1.0/sqrt(1-x*x));
200 #define m00_atan(v00,x) v00 = atan(x);
201 #define m10_atan(v10,v00,x) v10 = (+1.0/(1+x*x));
202 #define m00_atanh(v00,x) v00 = atanh(x);
203 #define m10_atanh(v10,v00,x) v10 = (+1.0/(1-x*x));
204 #define m00_logE(v00,x) v00 = log(x);
205 #define m10_logE(v10,v00,x) v10 = (1.0/x);
206 #define m00_log10(v00,x) v00 = log10(x);
207 #define m10_log10(v10,v00,x) v10 = (1.0/x/M_LN10);
208 #define m00_sqrt(v00,x) v00 = sqrt(x);
209 #define m10_sqrt(v10,v00,x) v10 = (0.5/v00);
210 #define m00_fabs(v00,x) v00 = fabs(x);
211 #define m10_fabs(v10,v00,x) v10 = (((x)>=0)?(+1.0):(-1.0));
213 #define m00_exp(v00,x) v00 = exp(x);
214 #define m10_exp(v10,v00,x) v10 = v00;
216 #define m00_abs(v00) ((v00)<(0)?(-(v00)):(v00))
217 #define m00_floor(v00,x) v00 = floor(x);
218 #define m00_limexp(v00,x) v00 = ((x)<80.0?exp(x):exp(80.0)*(x-79.0));
219 #define m10_limexp(v10,v00,x) v10 = ((x)<80.0?(v00):exp(80.0));
221 #define m20_logE(v00) (-1.0/v00/v00)
222 #define m20_exp(v00) exp(v00)
223 #define m20_limexp(v00) ((v00)<80.0?exp(v00):0.0)
224 #define m20_sqrt(v00) (-0.25/(v00)/sqrt(v00))
225 #define m20_fabs(v00) 0.0
226 #define m20_pow(x,y) ((y)*((y)-1.0)*pow(x,y)/(x)/(x))
227 #define m00_vt(x) (kBoverQ*(x))
228 #define m10_vt(x) (kBoverQ)
231 #define _modelname "potentiometer"
232 #define _instancename getName()
233 #define _circuit_temp (getPropertyDouble("Temp")+273.15)
234 #define _param_given(p) (isPropertyGiven(p)?1:0)
238 #define _vt_nom (kBoverQ*_circuit_temp)
240 using namespace device;
249 void potentiometer::initModel (
void)
261 initializeInstance ();
282 void potentiometer::initVerilog (
void)
285 _white_pwr[
M][
n1] = 0.0;
286 _white_pwr[
B][
n1] = 0.0;
287 _white_pwr[
T][
n1] = 0.0;
292 for (i1 = 0; i1 < 4; i1++) {
293 for (i2 = 0; i2 < 4; i2++) {
294 _charges[i1][i2] = 0.0;
298 for (i1 = 0; i1 < 4; i1++) {
299 for (i2 = 0; i2 < 4; i2++) {
300 for (i3 = 0; i3 < 4; i3++) {
301 for (i4 = 0; i4 < 4; i4++) {
302 _caps[i1][i2][i3][i4] = 0.0;
306 for (i1 = 0; i1 < 4; i1++) {
311 for (i2 = 0; i2 < 4; i2++) {
312 _jstat[i1][i2] = 0.0;
313 _jdyna[i1][i2] = 0.0;
319 void potentiometer::loadVariables (
void)
339 #define _DERIVATEFORDDX
342 void potentiometer::initializeModel (
void)
347 void potentiometer::initializeInstance (
void)
352 void potentiometer::initialStep (
void)
357 void potentiometer::finalStep (
void)
362 void potentiometer::calcVerilog (
void)
376 Rcontact=(Contact_Res+1
e-6);
377 Rad_Angle=((Rotation*3.14159265358979323846)/180);
378 R_pot_Temp=((R_pot+1
e-6)*(1+((Temp_Coeff*(
_circuit_temp-Tnom))/1e6)));
380 double m00_sin(d00_sin0,Rad_Angle)
381 Tpcoeff=(Taper_Coeff+((Conformity+(Linearity*d00_sin0))/100));
384 double m00_sin(d00_sin0,Rad_Angle)
385 error_term=(1+((Conformity+(Linearity*d00_sin0))/100));
390 RTB=(R_pot_Temp*Tpcoeff);
392 Rtop=((1.000001-(Rotation/(Max_Rotation+1
e-20)))*R_pot_Temp);
393 Rbot=((0.000001+(Rotation/(Max_Rotation+1
e-20)))*R_pot_Temp);
400 RTT=(R_pot_Temp*Tpcoeff);
401 Rtop=((1.000001-(Rotation/(Max_Rotation+1
e-20)))*R_pot_Temp);
402 Rbot=((0.000001+(Rotation/(Max_Rotation+1
e-20)))*R_pot_Temp);
408 Rtop=(((1.000001-(Rotation/(Max_Rotation+1
e-20)))*R_pot_Temp)*error_term);
409 Rbot=(((0.000001+(Rotation/(Max_Rotation+1
e-20)))*R_pot_Temp)*error_term);
416 Rtop=(((1.000001-(Rotation/(Max_Rotation+1
e-20)))*R_pot_Temp)*error_term);
417 Rbot=(((0.000001+(Rotation/(Max_Rotation+1
e-20)))*R_pot_Temp)*error_term);
420 #if defined(_DERIVATE)
424 #if defined(_DERIVATE)
428 #if defined(_DERIVATE)
432 #if defined(_DERIVATE)
436 #if defined(_DERIVATE)
461 for (
int i1 = 0; i1 < 4; i1++) {
463 for (
int i2 = 0; i2 < 4; i2++) {
464 setY (i1, i2, _jstat[i1][i2]);
498 matrix potentiometer::calcMatrixY (nr_double_t frequency)
504 for (
int i1 = 0; i1 < 4; i1++) {
505 for (
int i2 = 0; i2 < 4; i2++) {
506 y (i1,i2) =
rect (_jstat[i1][i2], _jdyna[i1][i2] * 2 *
M_PI * _freq);
540 int i1, i2, i3, i4, state;
543 for (i1 = 0; i1 < 4; i1++) {
544 for (i2 = 0; i2 < 4; i2++) {
545 state = 2 * (i2 + 4 * i1);
547 if (_charges[i1][i2] != 0.0)
552 for (i1 = 0; i1 < 4; i1++) {
553 state = 2 * (i1 + 4 * i1);
554 if (_charges[i1][i1] != 0.0)
559 for (i1 = 0; i1 < 4; i1++) {
560 for (i2 = 0; i2 < 4; i2++) {
562 for (i3 = 0; i3 < 4; i3++) {
563 for (i4 = 0; i4 < 4; i4++) {
565 if (_caps[i1][i2][i3][i4] != 0.0)
570 for (i1 = 0; i1 < 4; i1++) {
571 for (i2 = 0; i2 < 4; i2++) {
573 for (i3 = 0; i3 < 4; i3++) {
574 if (_caps[i1][i2][i3][i3] != 0.0)
579 for (i1 = 0; i1 < 4; i1++) {
580 for (i3 = 0; i3 < 4; i3++) {
581 for (i4 = 0; i4 < 4; i4++) {
583 if (_caps[i1][i1][i3][i4] != 0.0)
588 for (i1 = 0; i1 < 4; i1++) {
589 for (i3 = 0; i3 < 4; i3++) {
590 if (_caps[i1][i1][i3][i3] != 0.0)
596 matrix potentiometer::calcMatrixCy (nr_double_t frequency)
639 for (
int i1 = 0; i1 < 4; i1++) {
641 setCV (i1, _chs[i1]);
642 setGV (i1, _ghs[i1]);
643 for (
int i2 = 0; i2 < 4; i2++) {
644 setQV (i1, i2, _jdyna[i1][i2]);