16 #include "component.h"
21 #define CIR_andor4x4 -1
47 #define NP(node) real (getV (node))
48 #define BP(pnode,nnode) (NP(pnode) - NP(nnode))
49 #define _load_static_residual2(pnode,nnode,current)\
50 _rhs[pnode] -= current;\
51 _rhs[nnode] += current;
52 #define _load_static_augmented_residual2(pnode,nnode,current)\
53 _rhs[pnode] -= current;\
54 _rhs[nnode] += current;
55 #define _load_static_residual1(node,current)\
56 _rhs[node] -= current;
57 #define _load_static_augmented_residual1(node,current)\
58 _rhs[node] -= current;
59 #define _load_static_jacobian4(pnode,nnode,vpnode,vnnode,conductance)\
60 _jstat[pnode][vpnode] += conductance;\
61 _jstat[nnode][vnnode] += conductance;\
62 _jstat[pnode][vnnode] -= conductance;\
63 _jstat[nnode][vpnode] -= conductance;\
65 _ghs[pnode] += conductance * BP(vpnode,vnnode);\
66 _ghs[nnode] -= conductance * BP(vpnode,vnnode);\
68 _rhs[pnode] += conductance * BP(vpnode,vnnode);\
69 _rhs[nnode] -= conductance * BP(vpnode,vnnode);\
71 #define _load_static_jacobian2p(node,vpnode,vnnode,conductance)\
72 _jstat[node][vpnode] += conductance;\
73 _jstat[node][vnnode] -= conductance;\
75 _ghs[node] += conductance * BP(vpnode,vnnode);\
77 _rhs[node] += conductance * BP(vpnode,vnnode);\
79 #define _load_static_jacobian2s(pnode,nnode,node,conductance)\
80 _jstat[pnode][node] += conductance;\
81 _jstat[nnode][node] -= conductance;\
83 _ghs[pnode] += conductance * NP(node);\
84 _ghs[nnode] -= conductance * NP(node);\
86 _rhs[pnode] += conductance * NP(node);\
87 _rhs[nnode] -= conductance * NP(node);\
89 #define _load_static_jacobian1(node,vnode,conductance)\
90 _jstat[node][vnode] += conductance;\
92 _ghs[node] += conductance * NP(vnode);\
94 _rhs[node] += conductance * NP(vnode);\
96 #define _load_dynamic_residual2(pnode,nnode,charge)\
97 if (doTR) _charges[pnode][nnode] += charge;\
99 _qhs[pnode] -= charge;\
100 _qhs[nnode] += charge;\
102 #define _load_dynamic_residual1(node,charge)\
103 if (doTR) _charges[node][node] += charge;\
105 _qhs[node] -= charge;\
107 #define _load_dynamic_jacobian4(pnode,nnode,vpnode,vnnode,capacitance)\
109 _jdyna[pnode][vpnode] += capacitance;\
110 _jdyna[nnode][vnnode] += capacitance;\
111 _jdyna[pnode][vnnode] -= capacitance;\
112 _jdyna[nnode][vpnode] -= capacitance;\
115 _caps[pnode][nnode][vpnode][vnnode] += capacitance;\
118 _chs[pnode] += capacitance * BP(vpnode,vnnode);\
119 _chs[nnode] -= capacitance * BP(vpnode,vnnode);\
121 #define _load_dynamic_jacobian2s(pnode,nnode,vnode,capacitance)\
123 _jdyna[pnode][vnode] += capacitance;\
124 _jdyna[nnode][vnode] -= capacitance;\
127 _caps[pnode][nnode][vnode][vnode] += capacitance;\
130 _chs[pnode] += capacitance * NP(vnode);\
131 _chs[nnode] -= capacitance * NP(vnode);\
133 #define _load_dynamic_jacobian2p(node,vpnode,vnnode,capacitance)\
135 _jdyna[node][vpnode] += capacitance;\
136 _jdyna[node][vnnode] -= capacitance;\
139 _caps[node][node][vpnode][vnnode] += capacitance;\
142 _chs[node] += capacitance * BP(vpnode,vnnode);\
144 #define _load_dynamic_jacobian1(node,vnode,capacitance)\
146 _jdyna[node][vnode] += capacitance;\
149 _caps[node][node][vnode][vnode] += capacitance;\
152 _chs[node] += capacitance * NP(vnode);\
155 #define _save_whitenoise1(n1,pwr,type)\
156 _white_pwr[n1][n1] += pwr;
157 #define _save_whitenoise2(n1,n2,pwr,type)\
158 _white_pwr[n1][n2] += pwr;
159 #define _save_flickernoise1(n1,pwr,exp,type)\
160 _flicker_pwr[n1][n1] += pwr;\
161 _flicker_exp[n1][n1] += exp;
162 #define _save_flickernoise2(n1,n2,pwr,exp,type)\
163 _flicker_pwr[n1][n2] += pwr;\
164 _flicker_exp[n1][n2] += exp;
165 #define _load_whitenoise2(n1,n2,pwr)\
166 cy (n1,n2) -= pwr/kB/T0; cy (n2,n1) -= pwr/kB/T0;\
167 cy (n1,n1) += pwr/kB/T0; cy (n2,n2) += pwr/kB/T0;
168 #define _load_whitenoise1(n1,pwr)\
169 cy (n1,n1) += pwr/kB/T0;
170 #define _load_flickernoise2(n1,n2,pwr,exp)\
171 cy (n1,n2) -= pwr*pow(_freq,-exp)/kB/T0;\
172 cy (n2,n1) -= pwr*pow(_freq,-exp)/kB/T0;\
173 cy (n1,n1) += pwr*pow(_freq,-exp)/kB/T0;\
174 cy (n2,n2) += pwr*pow(_freq,-exp)/kB/T0;
175 #define _load_flickernoise1(n1,pwr,exp)\
176 cy (n1,n1) += pwr*pow(_freq,-exp)/kB/T0;
179 #define m00_hypot(v00,x,y) v00 = xhypot(x,y);
180 #define m10_hypot(v10,v00,x,y) v10 = (x)/(v00);
181 #define m11_hypot(v11,v00,x,y) v11 = (y)/(v00);
182 #define m00_max(v00,x,y) v00 = ((x)>(y))?(x):(y);
183 #define m10_max(v10,v00,x,y) v10 = ((x)>(y))?1.0:0.0;
184 #define m11_max(v11,v00,x,y) v11 = ((x)>(y))?0.0:1.0;
185 #define m00_min(v00,x,y) v00 = ((x)<(y))?(x):(y);
186 #define m10_min(v10,v00,x,y) v10 = ((x)<(y))?1.0:0.0;
187 #define m11_min(v11,v00,x,y) v11 = ((x)<(y))?0.0:1.0;
188 #define m00_pow(v00,x,y) v00 = pow(x,y);
189 #define m10_pow(v10,v00,x,y) v10 = (x==0.0)?0.0:(v00)*(y)/(x);
190 #define m11_pow(v11,v00,x,y) v11 = (x==0.0)?0.0:(log(x)*(v00));
192 #define m00_div(v00,v10,x,y) double v10=1/(y); double v00=(x)*v10;
193 #define m10_div(v10,v00,vv,x,y)
194 #define m11_div(v11,v00,vv,x,y) double v11 = -v00*vv;
196 #define m00_mult(v00,v10,v11,x,y) double v10=(x); double v11=(y); double v00=v10*v11;
197 #define m00_add(v00,x,y) double v00=(x)+(y);
199 #define m00_cos(v00,x) v00 = cos(x);
200 #define m10_cos(v10,v00,x) v10 = (-sin(x));
201 #define m00_sin(v00,x) v00 = sin(x);
202 #define m10_sin(v10,v00,x) v10 = (cos(x));
203 #define m00_tan(v00,x) v00 = tan(x);
204 #define m10_tan(v10,v00,x) v10 = (1.0/cos(x)/cos(x));
205 #define m00_cosh(v00,x) v00 = cosh(x);
206 #define m10_cosh(v10,v00,x) v10 = (sinh(x));
207 #define m00_sinh(v00,x) v00 = sinh(x);
208 #define m10_sinh(v10,v00,x) v10 = (cosh(x));
209 #define m00_tanh(v00,x) v00 = tanh(x);
210 #define m10_tanh(v10,v00,x) v10 = (1.0/cosh(x)/cosh(x));
211 #define m00_acos(v00,x) v00 = acos(x);
212 #define m10_acos(v10,v00,x) v10 = (-1.0/sqrt(1-x*x));
213 #define m00_asin(v00,x) v00 = asin(x);
214 #define m10_asin(v10,v00,x) v10 = (+1.0/sqrt(1-x*x));
215 #define m00_atan(v00,x) v00 = atan(x);
216 #define m10_atan(v10,v00,x) v10 = (+1.0/(1+x*x));
217 #define m00_atanh(v00,x) v00 = atanh(x);
218 #define m10_atanh(v10,v00,x) v10 = (+1.0/(1-x*x));
219 #define m00_logE(v00,x) v00 = log(x);
220 #define m10_logE(v10,v00,x) v10 = (1.0/x);
221 #define m00_log10(v00,x) v00 = log10(x);
222 #define m10_log10(v10,v00,x) v10 = (1.0/x/M_LN10);
223 #define m00_sqrt(v00,x) v00 = sqrt(x);
224 #define m10_sqrt(v10,v00,x) v10 = (0.5/v00);
225 #define m00_fabs(v00,x) v00 = fabs(x);
226 #define m10_fabs(v10,v00,x) v10 = (((x)>=0)?(+1.0):(-1.0));
228 #define m00_exp(v00,x) v00 = exp(x);
229 #define m10_exp(v10,v00,x) v10 = v00;
231 #define m00_abs(v00) ((v00)<(0)?(-(v00)):(v00))
232 #define m00_floor(v00,x) v00 = floor(x);
233 #define m00_limexp(v00,x) v00 = ((x)<80.0?exp(x):exp(80.0)*(x-79.0));
234 #define m10_limexp(v10,v00,x) v10 = ((x)<80.0?(v00):exp(80.0));
236 #define m20_logE(v00) (-1.0/v00/v00)
237 #define m20_exp(v00) exp(v00)
238 #define m20_limexp(v00) ((v00)<80.0?exp(v00):0.0)
239 #define m20_sqrt(v00) (-0.25/(v00)/sqrt(v00))
240 #define m20_fabs(v00) 0.0
241 #define m20_pow(x,y) ((y)*((y)-1.0)*pow(x,y)/(x)/(x))
242 #define m00_vt(x) (kBoverQ*(x))
243 #define m10_vt(x) (kBoverQ)
246 #define _modelname "andor4x4"
247 #define _instancename getName()
248 #define _circuit_temp (getPropertyDouble("Temp")+273.15)
249 #define _param_given(p) (isPropertyGiven(p)?1:0)
253 #define _vt_nom (kBoverQ*_circuit_temp)
255 using namespace device;
264 void andor4x4::initModel (
void)
277 initializeInstance ();
298 void andor4x4::initVerilog (
void)
305 for (i1 = 0; i1 < 19; i1++) {
306 for (i2 = 0; i2 < 19; i2++) {
307 _charges[i1][i2] = 0.0;
311 for (i1 = 0; i1 < 19; i1++) {
312 for (i2 = 0; i2 < 19; i2++) {
313 for (i3 = 0; i3 < 19; i3++) {
314 for (i4 = 0; i4 < 19; i4++) {
315 _caps[i1][i2][i3][i4] = 0.0;
319 for (i1 = 0; i1 < 19; i1++) {
324 for (i2 = 0; i2 < 19; i2++) {
325 _jstat[i1][i2] = 0.0;
326 _jdyna[i1][i2] = 0.0;
332 void andor4x4::loadVariables (
void)
344 #define _DERIVATEFORDDX
347 void andor4x4::initializeModel (
void)
349 #if defined(_DYNAMIC)
353 #if defined(_DYNAMIC)
354 Cd=((Delay*1.43)/Rd);
360 void andor4x4::initializeInstance (
void)
365 void andor4x4::initialStep (
void)
370 void andor4x4::finalStep (
void)
375 void andor4x4::calcVerilog (
void)
380 #if defined(_DERIVATE)
381 double Iand_VA11_GND;
382 double Iand_VA12_GND;
383 double Iand_VA13_GND;
384 double Iand_VA14_GND;
385 double Iand_VA21_GND;
386 double Iand_VA22_GND;
387 double Iand_VA23_GND;
388 double Iand_VA24_GND;
389 double Iand_VA31_GND;
390 double Iand_VA32_GND;
391 double Iand_VA33_GND;
392 double Iand_VA34_GND;
393 double Iand_VA41_GND;
394 double Iand_VA42_GND;
395 double Iand_VA43_GND;
396 double Iand_VA44_GND;
399 #if defined(_DERIVATE)
406 #if defined(_DERIVATE)
413 #if defined(_DERIVATE)
420 #if defined(_DERIVATE)
426 #if defined(_DERIVATE)
433 #if defined(_DERIVATE)
440 #if defined(_DERIVATE)
447 #if defined(_DERIVATE)
454 #if defined(_DERIVATE)
455 Iand_VA11_GND=m1_VA11_GND;
456 Iand_VA12_GND=m1_VA12_GND;
457 Iand_VA13_GND=m1_VA13_GND;
458 Iand_VA14_GND=m1_VA14_GND;
459 Iand_VA21_GND=m2_VA21_GND;
460 Iand_VA22_GND=m2_VA22_GND;
461 Iand_VA23_GND=m2_VA23_GND;
462 Iand_VA24_GND=m2_VA24_GND;
463 Iand_VA31_GND=m3_VA31_GND;
464 Iand_VA32_GND=m3_VA32_GND;
465 Iand_VA33_GND=m3_VA33_GND;
466 Iand_VA34_GND=m3_VA34_GND;
467 Iand_VA41_GND=m4_VA41_GND;
468 Iand_VA42_GND=m4_VA42_GND;
469 Iand_VA43_GND=m4_VA43_GND;
470 Iand_VA44_GND=m4_VA44_GND;
472 Iand=(((m1+m2)+m3)+m4);
476 #if defined(_DERIVATE)
498 #if defined(_DERIVATE)
519 double m00_tanh(d00_tanh0,(TR*(Iand-0.5)))
520 #if defined(_DERIVATE)
521 double m10_tanh(d10_tanh0,d00_tanh0,(TR*(Iand-0.5)))
524 #if defined(_DERIVATE)
544 #if defined(_DERIVATE)
548 #if defined(_DERIVATE)
551 #if defined(_DYNAMIC)
553 #if defined(_DERIVATE)
558 #if defined(_DERIVATE)
562 #if defined(_DERIVATE)
581 for (
int i1 = 0; i1 < 19; i1++) {
583 for (
int i2 = 0; i2 < 19; i2++) {
584 setY (i1, i2, _jstat[i1][i2]);
618 matrix andor4x4::calcMatrixY (nr_double_t frequency)
624 for (
int i1 = 0; i1 < 19; i1++) {
625 for (
int i2 = 0; i2 < 19; i2++) {
626 y (i1,i2) =
rect (_jstat[i1][i2], _jdyna[i1][i2] * 2 *
M_PI * _freq);
660 int i1, i2, i3, i4, state;
663 for (i1 = 0; i1 < 19; i1++) {
664 for (i2 = 0; i2 < 19; i2++) {
665 state = 2 * (i2 + 19 * i1);
667 if (_charges[i1][i2] != 0.0)
672 for (i1 = 0; i1 < 19; i1++) {
673 state = 2 * (i1 + 19 * i1);
674 if (_charges[i1][i1] != 0.0)
679 for (i1 = 0; i1 < 19; i1++) {
680 for (i2 = 0; i2 < 19; i2++) {
682 for (i3 = 0; i3 < 19; i3++) {
683 for (i4 = 0; i4 < 19; i4++) {
685 if (_caps[i1][i2][i3][i4] != 0.0)
690 for (i1 = 0; i1 < 19; i1++) {
691 for (i2 = 0; i2 < 19; i2++) {
693 for (i3 = 0; i3 < 19; i3++) {
694 if (_caps[i1][i2][i3][i3] != 0.0)
699 for (i1 = 0; i1 < 19; i1++) {
700 for (i3 = 0; i3 < 19; i3++) {
701 for (i4 = 0; i4 < 19; i4++) {
703 if (_caps[i1][i1][i3][i4] != 0.0)
708 for (i1 = 0; i1 < 19; i1++) {
709 for (i3 = 0; i3 < 19; i3++) {
710 if (_caps[i1][i1][i3][i3] != 0.0)
716 matrix andor4x4::calcMatrixCy (nr_double_t frequency)
756 for (
int i1 = 0; i1 < 19; i1++) {
758 setCV (i1, _chs[i1]);
759 setGV (i1, _ghs[i1]);
760 for (
int i2 = 0; i2 < 19; i2++) {
761 setQV (i1, i2, _jdyna[i1][i2]);