16 #include "component.h"
21 #define CIR_pad2bit -1
30 #define NP(node) real (getV (node))
31 #define BP(pnode,nnode) (NP(pnode) - NP(nnode))
32 #define _load_static_residual2(pnode,nnode,current)\
33 _rhs[pnode] -= current;\
34 _rhs[nnode] += current;
35 #define _load_static_augmented_residual2(pnode,nnode,current)\
36 _rhs[pnode] -= current;\
37 _rhs[nnode] += current;
38 #define _load_static_residual1(node,current)\
39 _rhs[node] -= current;
40 #define _load_static_augmented_residual1(node,current)\
41 _rhs[node] -= current;
42 #define _load_static_jacobian4(pnode,nnode,vpnode,vnnode,conductance)\
43 _jstat[pnode][vpnode] += conductance;\
44 _jstat[nnode][vnnode] += conductance;\
45 _jstat[pnode][vnnode] -= conductance;\
46 _jstat[nnode][vpnode] -= conductance;\
48 _ghs[pnode] += conductance * BP(vpnode,vnnode);\
49 _ghs[nnode] -= conductance * BP(vpnode,vnnode);\
51 _rhs[pnode] += conductance * BP(vpnode,vnnode);\
52 _rhs[nnode] -= conductance * BP(vpnode,vnnode);\
54 #define _load_static_jacobian2p(node,vpnode,vnnode,conductance)\
55 _jstat[node][vpnode] += conductance;\
56 _jstat[node][vnnode] -= conductance;\
58 _ghs[node] += conductance * BP(vpnode,vnnode);\
60 _rhs[node] += conductance * BP(vpnode,vnnode);\
62 #define _load_static_jacobian2s(pnode,nnode,node,conductance)\
63 _jstat[pnode][node] += conductance;\
64 _jstat[nnode][node] -= conductance;\
66 _ghs[pnode] += conductance * NP(node);\
67 _ghs[nnode] -= conductance * NP(node);\
69 _rhs[pnode] += conductance * NP(node);\
70 _rhs[nnode] -= conductance * NP(node);\
72 #define _load_static_jacobian1(node,vnode,conductance)\
73 _jstat[node][vnode] += conductance;\
75 _ghs[node] += conductance * NP(vnode);\
77 _rhs[node] += conductance * NP(vnode);\
79 #define _load_dynamic_residual2(pnode,nnode,charge)\
80 if (doTR) _charges[pnode][nnode] += charge;\
82 _qhs[pnode] -= charge;\
83 _qhs[nnode] += charge;\
85 #define _load_dynamic_residual1(node,charge)\
86 if (doTR) _charges[node][node] += charge;\
88 _qhs[node] -= charge;\
90 #define _load_dynamic_jacobian4(pnode,nnode,vpnode,vnnode,capacitance)\
92 _jdyna[pnode][vpnode] += capacitance;\
93 _jdyna[nnode][vnnode] += capacitance;\
94 _jdyna[pnode][vnnode] -= capacitance;\
95 _jdyna[nnode][vpnode] -= capacitance;\
98 _caps[pnode][nnode][vpnode][vnnode] += capacitance;\
101 _chs[pnode] += capacitance * BP(vpnode,vnnode);\
102 _chs[nnode] -= capacitance * BP(vpnode,vnnode);\
104 #define _load_dynamic_jacobian2s(pnode,nnode,vnode,capacitance)\
106 _jdyna[pnode][vnode] += capacitance;\
107 _jdyna[nnode][vnode] -= capacitance;\
110 _caps[pnode][nnode][vnode][vnode] += capacitance;\
113 _chs[pnode] += capacitance * NP(vnode);\
114 _chs[nnode] -= capacitance * NP(vnode);\
116 #define _load_dynamic_jacobian2p(node,vpnode,vnnode,capacitance)\
118 _jdyna[node][vpnode] += capacitance;\
119 _jdyna[node][vnnode] -= capacitance;\
122 _caps[node][node][vpnode][vnnode] += capacitance;\
125 _chs[node] += capacitance * BP(vpnode,vnnode);\
127 #define _load_dynamic_jacobian1(node,vnode,capacitance)\
129 _jdyna[node][vnode] += capacitance;\
132 _caps[node][node][vnode][vnode] += capacitance;\
135 _chs[node] += capacitance * NP(vnode);\
138 #define _save_whitenoise1(n1,pwr,type)\
139 _white_pwr[n1][n1] += pwr;
140 #define _save_whitenoise2(n1,n2,pwr,type)\
141 _white_pwr[n1][n2] += pwr;
142 #define _save_flickernoise1(n1,pwr,exp,type)\
143 _flicker_pwr[n1][n1] += pwr;\
144 _flicker_exp[n1][n1] += exp;
145 #define _save_flickernoise2(n1,n2,pwr,exp,type)\
146 _flicker_pwr[n1][n2] += pwr;\
147 _flicker_exp[n1][n2] += exp;
148 #define _load_whitenoise2(n1,n2,pwr)\
149 cy (n1,n2) -= pwr/kB/T0; cy (n2,n1) -= pwr/kB/T0;\
150 cy (n1,n1) += pwr/kB/T0; cy (n2,n2) += pwr/kB/T0;
151 #define _load_whitenoise1(n1,pwr)\
152 cy (n1,n1) += pwr/kB/T0;
153 #define _load_flickernoise2(n1,n2,pwr,exp)\
154 cy (n1,n2) -= pwr*pow(_freq,-exp)/kB/T0;\
155 cy (n2,n1) -= pwr*pow(_freq,-exp)/kB/T0;\
156 cy (n1,n1) += pwr*pow(_freq,-exp)/kB/T0;\
157 cy (n2,n2) += pwr*pow(_freq,-exp)/kB/T0;
158 #define _load_flickernoise1(n1,pwr,exp)\
159 cy (n1,n1) += pwr*pow(_freq,-exp)/kB/T0;
162 #define m00_hypot(v00,x,y) v00 = xhypot(x,y);
163 #define m10_hypot(v10,v00,x,y) v10 = (x)/(v00);
164 #define m11_hypot(v11,v00,x,y) v11 = (y)/(v00);
165 #define m00_max(v00,x,y) v00 = ((x)>(y))?(x):(y);
166 #define m10_max(v10,v00,x,y) v10 = ((x)>(y))?1.0:0.0;
167 #define m11_max(v11,v00,x,y) v11 = ((x)>(y))?0.0:1.0;
168 #define m00_min(v00,x,y) v00 = ((x)<(y))?(x):(y);
169 #define m10_min(v10,v00,x,y) v10 = ((x)<(y))?1.0:0.0;
170 #define m11_min(v11,v00,x,y) v11 = ((x)<(y))?0.0:1.0;
171 #define m00_pow(v00,x,y) v00 = pow(x,y);
172 #define m10_pow(v10,v00,x,y) v10 = (x==0.0)?0.0:(v00)*(y)/(x);
173 #define m11_pow(v11,v00,x,y) v11 = (x==0.0)?0.0:(log(x)*(v00));
175 #define m00_div(v00,v10,x,y) double v10=1/(y); double v00=(x)*v10;
176 #define m10_div(v10,v00,vv,x,y)
177 #define m11_div(v11,v00,vv,x,y) double v11 = -v00*vv;
179 #define m00_mult(v00,v10,v11,x,y) double v10=(x); double v11=(y); double v00=v10*v11;
180 #define m00_add(v00,x,y) double v00=(x)+(y);
182 #define m00_cos(v00,x) v00 = cos(x);
183 #define m10_cos(v10,v00,x) v10 = (-sin(x));
184 #define m00_sin(v00,x) v00 = sin(x);
185 #define m10_sin(v10,v00,x) v10 = (cos(x));
186 #define m00_tan(v00,x) v00 = tan(x);
187 #define m10_tan(v10,v00,x) v10 = (1.0/cos(x)/cos(x));
188 #define m00_cosh(v00,x) v00 = cosh(x);
189 #define m10_cosh(v10,v00,x) v10 = (sinh(x));
190 #define m00_sinh(v00,x) v00 = sinh(x);
191 #define m10_sinh(v10,v00,x) v10 = (cosh(x));
192 #define m00_tanh(v00,x) v00 = tanh(x);
193 #define m10_tanh(v10,v00,x) v10 = (1.0/cosh(x)/cosh(x));
194 #define m00_acos(v00,x) v00 = acos(x);
195 #define m10_acos(v10,v00,x) v10 = (-1.0/sqrt(1-x*x));
196 #define m00_asin(v00,x) v00 = asin(x);
197 #define m10_asin(v10,v00,x) v10 = (+1.0/sqrt(1-x*x));
198 #define m00_atan(v00,x) v00 = atan(x);
199 #define m10_atan(v10,v00,x) v10 = (+1.0/(1+x*x));
200 #define m00_atanh(v00,x) v00 = atanh(x);
201 #define m10_atanh(v10,v00,x) v10 = (+1.0/(1-x*x));
202 #define m00_logE(v00,x) v00 = log(x);
203 #define m10_logE(v10,v00,x) v10 = (1.0/x);
204 #define m00_log10(v00,x) v00 = log10(x);
205 #define m10_log10(v10,v00,x) v10 = (1.0/x/M_LN10);
206 #define m00_sqrt(v00,x) v00 = sqrt(x);
207 #define m10_sqrt(v10,v00,x) v10 = (0.5/v00);
208 #define m00_fabs(v00,x) v00 = fabs(x);
209 #define m10_fabs(v10,v00,x) v10 = (((x)>=0)?(+1.0):(-1.0));
211 #define m00_exp(v00,x) v00 = exp(x);
212 #define m10_exp(v10,v00,x) v10 = v00;
214 #define m00_abs(v00) ((v00)<(0)?(-(v00)):(v00))
215 #define m00_floor(v00,x) v00 = floor(x);
216 #define m00_limexp(v00,x) v00 = ((x)<80.0?exp(x):exp(80.0)*(x-79.0));
217 #define m10_limexp(v10,v00,x) v10 = ((x)<80.0?(v00):exp(80.0));
219 #define m20_logE(v00) (-1.0/v00/v00)
220 #define m20_exp(v00) exp(v00)
221 #define m20_limexp(v00) ((v00)<80.0?exp(v00):0.0)
222 #define m20_sqrt(v00) (-0.25/(v00)/sqrt(v00))
223 #define m20_fabs(v00) 0.0
224 #define m20_pow(x,y) ((y)*((y)-1.0)*pow(x,y)/(x)/(x))
225 #define m00_vt(x) (kBoverQ*(x))
226 #define m10_vt(x) (kBoverQ)
229 #define _modelname "pad2bit"
230 #define _instancename getName()
231 #define _circuit_temp (getPropertyDouble("Temp")+273.15)
232 #define _param_given(p) (isPropertyGiven(p)?1:0)
236 #define _vt_nom (kBoverQ*_circuit_temp)
238 using namespace device;
247 void pad2bit::initModel (
void)
258 initializeInstance ();
279 void pad2bit::initVerilog (
void)
286 for (i1 = 0; i1 < 2; i1++) {
287 for (i2 = 0; i2 < 2; i2++) {
288 _charges[i1][i2] = 0.0;
292 for (i1 = 0; i1 < 2; i1++) {
293 for (i2 = 0; i2 < 2; i2++) {
294 for (i3 = 0; i3 < 2; i3++) {
295 for (i4 = 0; i4 < 2; i4++) {
296 _caps[i1][i2][i3][i4] = 0.0;
300 for (i1 = 0; i1 < 2; i1++) {
305 for (i2 = 0; i2 < 2; i2++) {
306 _jstat[i1][i2] = 0.0;
307 _jdyna[i1][i2] = 0.0;
313 void pad2bit::loadVariables (
void)
324 #define _DERIVATEFORDDX
327 void pad2bit::initializeModel (
void)
332 void pad2bit::initializeInstance (
void)
337 void pad2bit::initialStep (
void)
342 void pad2bit::finalStep (
void)
347 void pad2bit::calcVerilog (
void)
383 #if defined(_DERIVATE)
386 #if defined(_DERIVATE)
390 #if defined(_DERIVATE)
393 #if defined(_DERIVATE)
412 for (
int i1 = 0; i1 < 2; i1++) {
414 for (
int i2 = 0; i2 < 2; i2++) {
415 setY (i1, i2, _jstat[i1][i2]);
449 matrix pad2bit::calcMatrixY (nr_double_t frequency)
455 for (
int i1 = 0; i1 < 2; i1++) {
456 for (
int i2 = 0; i2 < 2; i2++) {
457 y (i1,i2) =
rect (_jstat[i1][i2], _jdyna[i1][i2] * 2 *
M_PI * _freq);
491 int i1, i2, i3, i4, state;
494 for (i1 = 0; i1 < 2; i1++) {
495 for (i2 = 0; i2 < 2; i2++) {
496 state = 2 * (i2 + 2 * i1);
498 if (_charges[i1][i2] != 0.0)
503 for (i1 = 0; i1 < 2; i1++) {
504 state = 2 * (i1 + 2 * i1);
505 if (_charges[i1][i1] != 0.0)
510 for (i1 = 0; i1 < 2; i1++) {
511 for (i2 = 0; i2 < 2; i2++) {
513 for (i3 = 0; i3 < 2; i3++) {
514 for (i4 = 0; i4 < 2; i4++) {
516 if (_caps[i1][i2][i3][i4] != 0.0)
521 for (i1 = 0; i1 < 2; i1++) {
522 for (i2 = 0; i2 < 2; i2++) {
524 for (i3 = 0; i3 < 2; i3++) {
525 if (_caps[i1][i2][i3][i3] != 0.0)
530 for (i1 = 0; i1 < 2; i1++) {
531 for (i3 = 0; i3 < 2; i3++) {
532 for (i4 = 0; i4 < 2; i4++) {
534 if (_caps[i1][i1][i3][i4] != 0.0)
539 for (i1 = 0; i1 < 2; i1++) {
540 for (i3 = 0; i3 < 2; i3++) {
541 if (_caps[i1][i1][i3][i3] != 0.0)
547 matrix pad2bit::calcMatrixCy (nr_double_t frequency)
587 for (
int i1 = 0; i1 < 2; i1++) {
589 setCV (i1, _chs[i1]);
590 setGV (i1, _ghs[i1]);
591 for (
int i2 = 0; i2 < 2; i2++) {
592 setQV (i1, i2, _jdyna[i1][i2]);