16 #include "component.h"
21 #define CIR_andor4x3 -1
43 #define NP(node) real (getV (node))
44 #define BP(pnode,nnode) (NP(pnode) - NP(nnode))
45 #define _load_static_residual2(pnode,nnode,current)\
46 _rhs[pnode] -= current;\
47 _rhs[nnode] += current;
48 #define _load_static_augmented_residual2(pnode,nnode,current)\
49 _rhs[pnode] -= current;\
50 _rhs[nnode] += current;
51 #define _load_static_residual1(node,current)\
52 _rhs[node] -= current;
53 #define _load_static_augmented_residual1(node,current)\
54 _rhs[node] -= current;
55 #define _load_static_jacobian4(pnode,nnode,vpnode,vnnode,conductance)\
56 _jstat[pnode][vpnode] += conductance;\
57 _jstat[nnode][vnnode] += conductance;\
58 _jstat[pnode][vnnode] -= conductance;\
59 _jstat[nnode][vpnode] -= conductance;\
61 _ghs[pnode] += conductance * BP(vpnode,vnnode);\
62 _ghs[nnode] -= conductance * BP(vpnode,vnnode);\
64 _rhs[pnode] += conductance * BP(vpnode,vnnode);\
65 _rhs[nnode] -= conductance * BP(vpnode,vnnode);\
67 #define _load_static_jacobian2p(node,vpnode,vnnode,conductance)\
68 _jstat[node][vpnode] += conductance;\
69 _jstat[node][vnnode] -= conductance;\
71 _ghs[node] += conductance * BP(vpnode,vnnode);\
73 _rhs[node] += conductance * BP(vpnode,vnnode);\
75 #define _load_static_jacobian2s(pnode,nnode,node,conductance)\
76 _jstat[pnode][node] += conductance;\
77 _jstat[nnode][node] -= conductance;\
79 _ghs[pnode] += conductance * NP(node);\
80 _ghs[nnode] -= conductance * NP(node);\
82 _rhs[pnode] += conductance * NP(node);\
83 _rhs[nnode] -= conductance * NP(node);\
85 #define _load_static_jacobian1(node,vnode,conductance)\
86 _jstat[node][vnode] += conductance;\
88 _ghs[node] += conductance * NP(vnode);\
90 _rhs[node] += conductance * NP(vnode);\
92 #define _load_dynamic_residual2(pnode,nnode,charge)\
93 if (doTR) _charges[pnode][nnode] += charge;\
95 _qhs[pnode] -= charge;\
96 _qhs[nnode] += charge;\
98 #define _load_dynamic_residual1(node,charge)\
99 if (doTR) _charges[node][node] += charge;\
101 _qhs[node] -= charge;\
103 #define _load_dynamic_jacobian4(pnode,nnode,vpnode,vnnode,capacitance)\
105 _jdyna[pnode][vpnode] += capacitance;\
106 _jdyna[nnode][vnnode] += capacitance;\
107 _jdyna[pnode][vnnode] -= capacitance;\
108 _jdyna[nnode][vpnode] -= capacitance;\
111 _caps[pnode][nnode][vpnode][vnnode] += capacitance;\
114 _chs[pnode] += capacitance * BP(vpnode,vnnode);\
115 _chs[nnode] -= capacitance * BP(vpnode,vnnode);\
117 #define _load_dynamic_jacobian2s(pnode,nnode,vnode,capacitance)\
119 _jdyna[pnode][vnode] += capacitance;\
120 _jdyna[nnode][vnode] -= capacitance;\
123 _caps[pnode][nnode][vnode][vnode] += capacitance;\
126 _chs[pnode] += capacitance * NP(vnode);\
127 _chs[nnode] -= capacitance * NP(vnode);\
129 #define _load_dynamic_jacobian2p(node,vpnode,vnnode,capacitance)\
131 _jdyna[node][vpnode] += capacitance;\
132 _jdyna[node][vnnode] -= capacitance;\
135 _caps[node][node][vpnode][vnnode] += capacitance;\
138 _chs[node] += capacitance * BP(vpnode,vnnode);\
140 #define _load_dynamic_jacobian1(node,vnode,capacitance)\
142 _jdyna[node][vnode] += capacitance;\
145 _caps[node][node][vnode][vnode] += capacitance;\
148 _chs[node] += capacitance * NP(vnode);\
151 #define _save_whitenoise1(n1,pwr,type)\
152 _white_pwr[n1][n1] += pwr;
153 #define _save_whitenoise2(n1,n2,pwr,type)\
154 _white_pwr[n1][n2] += pwr;
155 #define _save_flickernoise1(n1,pwr,exp,type)\
156 _flicker_pwr[n1][n1] += pwr;\
157 _flicker_exp[n1][n1] += exp;
158 #define _save_flickernoise2(n1,n2,pwr,exp,type)\
159 _flicker_pwr[n1][n2] += pwr;\
160 _flicker_exp[n1][n2] += exp;
161 #define _load_whitenoise2(n1,n2,pwr)\
162 cy (n1,n2) -= pwr/kB/T0; cy (n2,n1) -= pwr/kB/T0;\
163 cy (n1,n1) += pwr/kB/T0; cy (n2,n2) += pwr/kB/T0;
164 #define _load_whitenoise1(n1,pwr)\
165 cy (n1,n1) += pwr/kB/T0;
166 #define _load_flickernoise2(n1,n2,pwr,exp)\
167 cy (n1,n2) -= pwr*pow(_freq,-exp)/kB/T0;\
168 cy (n2,n1) -= pwr*pow(_freq,-exp)/kB/T0;\
169 cy (n1,n1) += pwr*pow(_freq,-exp)/kB/T0;\
170 cy (n2,n2) += pwr*pow(_freq,-exp)/kB/T0;
171 #define _load_flickernoise1(n1,pwr,exp)\
172 cy (n1,n1) += pwr*pow(_freq,-exp)/kB/T0;
175 #define m00_hypot(v00,x,y) v00 = xhypot(x,y);
176 #define m10_hypot(v10,v00,x,y) v10 = (x)/(v00);
177 #define m11_hypot(v11,v00,x,y) v11 = (y)/(v00);
178 #define m00_max(v00,x,y) v00 = ((x)>(y))?(x):(y);
179 #define m10_max(v10,v00,x,y) v10 = ((x)>(y))?1.0:0.0;
180 #define m11_max(v11,v00,x,y) v11 = ((x)>(y))?0.0:1.0;
181 #define m00_min(v00,x,y) v00 = ((x)<(y))?(x):(y);
182 #define m10_min(v10,v00,x,y) v10 = ((x)<(y))?1.0:0.0;
183 #define m11_min(v11,v00,x,y) v11 = ((x)<(y))?0.0:1.0;
184 #define m00_pow(v00,x,y) v00 = pow(x,y);
185 #define m10_pow(v10,v00,x,y) v10 = (x==0.0)?0.0:(v00)*(y)/(x);
186 #define m11_pow(v11,v00,x,y) v11 = (x==0.0)?0.0:(log(x)*(v00));
188 #define m00_div(v00,v10,x,y) double v10=1/(y); double v00=(x)*v10;
189 #define m10_div(v10,v00,vv,x,y)
190 #define m11_div(v11,v00,vv,x,y) double v11 = -v00*vv;
192 #define m00_mult(v00,v10,v11,x,y) double v10=(x); double v11=(y); double v00=v10*v11;
193 #define m00_add(v00,x,y) double v00=(x)+(y);
195 #define m00_cos(v00,x) v00 = cos(x);
196 #define m10_cos(v10,v00,x) v10 = (-sin(x));
197 #define m00_sin(v00,x) v00 = sin(x);
198 #define m10_sin(v10,v00,x) v10 = (cos(x));
199 #define m00_tan(v00,x) v00 = tan(x);
200 #define m10_tan(v10,v00,x) v10 = (1.0/cos(x)/cos(x));
201 #define m00_cosh(v00,x) v00 = cosh(x);
202 #define m10_cosh(v10,v00,x) v10 = (sinh(x));
203 #define m00_sinh(v00,x) v00 = sinh(x);
204 #define m10_sinh(v10,v00,x) v10 = (cosh(x));
205 #define m00_tanh(v00,x) v00 = tanh(x);
206 #define m10_tanh(v10,v00,x) v10 = (1.0/cosh(x)/cosh(x));
207 #define m00_acos(v00,x) v00 = acos(x);
208 #define m10_acos(v10,v00,x) v10 = (-1.0/sqrt(1-x*x));
209 #define m00_asin(v00,x) v00 = asin(x);
210 #define m10_asin(v10,v00,x) v10 = (+1.0/sqrt(1-x*x));
211 #define m00_atan(v00,x) v00 = atan(x);
212 #define m10_atan(v10,v00,x) v10 = (+1.0/(1+x*x));
213 #define m00_atanh(v00,x) v00 = atanh(x);
214 #define m10_atanh(v10,v00,x) v10 = (+1.0/(1-x*x));
215 #define m00_logE(v00,x) v00 = log(x);
216 #define m10_logE(v10,v00,x) v10 = (1.0/x);
217 #define m00_log10(v00,x) v00 = log10(x);
218 #define m10_log10(v10,v00,x) v10 = (1.0/x/M_LN10);
219 #define m00_sqrt(v00,x) v00 = sqrt(x);
220 #define m10_sqrt(v10,v00,x) v10 = (0.5/v00);
221 #define m00_fabs(v00,x) v00 = fabs(x);
222 #define m10_fabs(v10,v00,x) v10 = (((x)>=0)?(+1.0):(-1.0));
224 #define m00_exp(v00,x) v00 = exp(x);
225 #define m10_exp(v10,v00,x) v10 = v00;
227 #define m00_abs(v00) ((v00)<(0)?(-(v00)):(v00))
228 #define m00_floor(v00,x) v00 = floor(x);
229 #define m00_limexp(v00,x) v00 = ((x)<80.0?exp(x):exp(80.0)*(x-79.0));
230 #define m10_limexp(v10,v00,x) v10 = ((x)<80.0?(v00):exp(80.0));
232 #define m20_logE(v00) (-1.0/v00/v00)
233 #define m20_exp(v00) exp(v00)
234 #define m20_limexp(v00) ((v00)<80.0?exp(v00):0.0)
235 #define m20_sqrt(v00) (-0.25/(v00)/sqrt(v00))
236 #define m20_fabs(v00) 0.0
237 #define m20_pow(x,y) ((y)*((y)-1.0)*pow(x,y)/(x)/(x))
238 #define m00_vt(x) (kBoverQ*(x))
239 #define m10_vt(x) (kBoverQ)
242 #define _modelname "andor4x3"
243 #define _instancename getName()
244 #define _circuit_temp (getPropertyDouble("Temp")+273.15)
245 #define _param_given(p) (isPropertyGiven(p)?1:0)
249 #define _vt_nom (kBoverQ*_circuit_temp)
251 using namespace device;
260 void andor4x3::initModel (
void)
273 initializeInstance ();
294 void andor4x3::initVerilog (
void)
301 for (i1 = 0; i1 < 15; i1++) {
302 for (i2 = 0; i2 < 15; i2++) {
303 _charges[i1][i2] = 0.0;
307 for (i1 = 0; i1 < 15; i1++) {
308 for (i2 = 0; i2 < 15; i2++) {
309 for (i3 = 0; i3 < 15; i3++) {
310 for (i4 = 0; i4 < 15; i4++) {
311 _caps[i1][i2][i3][i4] = 0.0;
315 for (i1 = 0; i1 < 15; i1++) {
320 for (i2 = 0; i2 < 15; i2++) {
321 _jstat[i1][i2] = 0.0;
322 _jdyna[i1][i2] = 0.0;
328 void andor4x3::loadVariables (
void)
340 #define _DERIVATEFORDDX
343 void andor4x3::initializeModel (
void)
345 #if defined(_DYNAMIC)
349 #if defined(_DYNAMIC)
350 Cd=((Delay*1.43)/Rd);
356 void andor4x3::initializeInstance (
void)
361 void andor4x3::initialStep (
void)
366 void andor4x3::finalStep (
void)
371 void andor4x3::calcVerilog (
void)
376 #if defined(_DERIVATE)
377 double Iand_VA11_GND;
378 double Iand_VA12_GND;
379 double Iand_VA13_GND;
380 double Iand_VA21_GND;
381 double Iand_VA22_GND;
382 double Iand_VA23_GND;
383 double Iand_VA31_GND;
384 double Iand_VA32_GND;
385 double Iand_VA33_GND;
386 double Iand_VA41_GND;
387 double Iand_VA42_GND;
388 double Iand_VA43_GND;
391 #if defined(_DERIVATE)
397 #if defined(_DERIVATE)
403 #if defined(_DERIVATE)
409 #if defined(_DERIVATE)
414 #if defined(_DERIVATE)
420 #if defined(_DERIVATE)
426 #if defined(_DERIVATE)
432 #if defined(_DERIVATE)
438 #if defined(_DERIVATE)
439 Iand_VA11_GND=m1_VA11_GND;
440 Iand_VA12_GND=m1_VA12_GND;
441 Iand_VA13_GND=m1_VA13_GND;
442 Iand_VA21_GND=m2_VA21_GND;
443 Iand_VA22_GND=m2_VA22_GND;
444 Iand_VA23_GND=m2_VA23_GND;
445 Iand_VA31_GND=m3_VA31_GND;
446 Iand_VA32_GND=m3_VA32_GND;
447 Iand_VA33_GND=m3_VA33_GND;
448 Iand_VA41_GND=m4_VA41_GND;
449 Iand_VA42_GND=m4_VA42_GND;
450 Iand_VA43_GND=m4_VA43_GND;
452 Iand=(((m1+m2)+m3)+m4);
456 #if defined(_DERIVATE)
474 #if defined(_DERIVATE)
491 double m00_tanh(d00_tanh0,(TR*(Iand-0.5)))
492 #if defined(_DERIVATE)
493 double m10_tanh(d10_tanh0,d00_tanh0,(TR*(Iand-0.5)))
496 #if defined(_DERIVATE)
512 #if defined(_DERIVATE)
516 #if defined(_DERIVATE)
519 #if defined(_DYNAMIC)
521 #if defined(_DERIVATE)
526 #if defined(_DERIVATE)
530 #if defined(_DERIVATE)
549 for (
int i1 = 0; i1 < 15; i1++) {
551 for (
int i2 = 0; i2 < 15; i2++) {
552 setY (i1, i2, _jstat[i1][i2]);
586 matrix andor4x3::calcMatrixY (nr_double_t frequency)
592 for (
int i1 = 0; i1 < 15; i1++) {
593 for (
int i2 = 0; i2 < 15; i2++) {
594 y (i1,i2) =
rect (_jstat[i1][i2], _jdyna[i1][i2] * 2 *
M_PI * _freq);
628 int i1, i2, i3, i4, state;
631 for (i1 = 0; i1 < 15; i1++) {
632 for (i2 = 0; i2 < 15; i2++) {
633 state = 2 * (i2 + 15 * i1);
635 if (_charges[i1][i2] != 0.0)
640 for (i1 = 0; i1 < 15; i1++) {
641 state = 2 * (i1 + 15 * i1);
642 if (_charges[i1][i1] != 0.0)
647 for (i1 = 0; i1 < 15; i1++) {
648 for (i2 = 0; i2 < 15; i2++) {
650 for (i3 = 0; i3 < 15; i3++) {
651 for (i4 = 0; i4 < 15; i4++) {
653 if (_caps[i1][i2][i3][i4] != 0.0)
658 for (i1 = 0; i1 < 15; i1++) {
659 for (i2 = 0; i2 < 15; i2++) {
661 for (i3 = 0; i3 < 15; i3++) {
662 if (_caps[i1][i2][i3][i3] != 0.0)
667 for (i1 = 0; i1 < 15; i1++) {
668 for (i3 = 0; i3 < 15; i3++) {
669 for (i4 = 0; i4 < 15; i4++) {
671 if (_caps[i1][i1][i3][i4] != 0.0)
676 for (i1 = 0; i1 < 15; i1++) {
677 for (i3 = 0; i3 < 15; i3++) {
678 if (_caps[i1][i1][i3][i3] != 0.0)
684 matrix andor4x3::calcMatrixCy (nr_double_t frequency)
724 for (
int i1 = 0; i1 < 15; i1++) {
726 setCV (i1, _chs[i1]);
727 setGV (i1, _ghs[i1]);
728 for (
int i2 = 0; i2 < 15; i2++) {
729 setQV (i1, i2, _jdyna[i1][i2]);