16 #include "component.h"
21 #define CIR_comp_4bit -1
45 #define NP(node) real (getV (node))
46 #define BP(pnode,nnode) (NP(pnode) - NP(nnode))
47 #define _load_static_residual2(pnode,nnode,current)\
48 _rhs[pnode] -= current;\
49 _rhs[nnode] += current;
50 #define _load_static_augmented_residual2(pnode,nnode,current)\
51 _rhs[pnode] -= current;\
52 _rhs[nnode] += current;
53 #define _load_static_residual1(node,current)\
54 _rhs[node] -= current;
55 #define _load_static_augmented_residual1(node,current)\
56 _rhs[node] -= current;
57 #define _load_static_jacobian4(pnode,nnode,vpnode,vnnode,conductance)\
58 _jstat[pnode][vpnode] += conductance;\
59 _jstat[nnode][vnnode] += conductance;\
60 _jstat[pnode][vnnode] -= conductance;\
61 _jstat[nnode][vpnode] -= conductance;\
63 _ghs[pnode] += conductance * BP(vpnode,vnnode);\
64 _ghs[nnode] -= conductance * BP(vpnode,vnnode);\
66 _rhs[pnode] += conductance * BP(vpnode,vnnode);\
67 _rhs[nnode] -= conductance * BP(vpnode,vnnode);\
69 #define _load_static_jacobian2p(node,vpnode,vnnode,conductance)\
70 _jstat[node][vpnode] += conductance;\
71 _jstat[node][vnnode] -= conductance;\
73 _ghs[node] += conductance * BP(vpnode,vnnode);\
75 _rhs[node] += conductance * BP(vpnode,vnnode);\
77 #define _load_static_jacobian2s(pnode,nnode,node,conductance)\
78 _jstat[pnode][node] += conductance;\
79 _jstat[nnode][node] -= conductance;\
81 _ghs[pnode] += conductance * NP(node);\
82 _ghs[nnode] -= conductance * NP(node);\
84 _rhs[pnode] += conductance * NP(node);\
85 _rhs[nnode] -= conductance * NP(node);\
87 #define _load_static_jacobian1(node,vnode,conductance)\
88 _jstat[node][vnode] += conductance;\
90 _ghs[node] += conductance * NP(vnode);\
92 _rhs[node] += conductance * NP(vnode);\
94 #define _load_dynamic_residual2(pnode,nnode,charge)\
95 if (doTR) _charges[pnode][nnode] += charge;\
97 _qhs[pnode] -= charge;\
98 _qhs[nnode] += charge;\
100 #define _load_dynamic_residual1(node,charge)\
101 if (doTR) _charges[node][node] += charge;\
103 _qhs[node] -= charge;\
105 #define _load_dynamic_jacobian4(pnode,nnode,vpnode,vnnode,capacitance)\
107 _jdyna[pnode][vpnode] += capacitance;\
108 _jdyna[nnode][vnnode] += capacitance;\
109 _jdyna[pnode][vnnode] -= capacitance;\
110 _jdyna[nnode][vpnode] -= capacitance;\
113 _caps[pnode][nnode][vpnode][vnnode] += capacitance;\
116 _chs[pnode] += capacitance * BP(vpnode,vnnode);\
117 _chs[nnode] -= capacitance * BP(vpnode,vnnode);\
119 #define _load_dynamic_jacobian2s(pnode,nnode,vnode,capacitance)\
121 _jdyna[pnode][vnode] += capacitance;\
122 _jdyna[nnode][vnode] -= capacitance;\
125 _caps[pnode][nnode][vnode][vnode] += capacitance;\
128 _chs[pnode] += capacitance * NP(vnode);\
129 _chs[nnode] -= capacitance * NP(vnode);\
131 #define _load_dynamic_jacobian2p(node,vpnode,vnnode,capacitance)\
133 _jdyna[node][vpnode] += capacitance;\
134 _jdyna[node][vnnode] -= capacitance;\
137 _caps[node][node][vpnode][vnnode] += capacitance;\
140 _chs[node] += capacitance * BP(vpnode,vnnode);\
142 #define _load_dynamic_jacobian1(node,vnode,capacitance)\
144 _jdyna[node][vnode] += capacitance;\
147 _caps[node][node][vnode][vnode] += capacitance;\
150 _chs[node] += capacitance * NP(vnode);\
153 #define _save_whitenoise1(n1,pwr,type)\
154 _white_pwr[n1][n1] += pwr;
155 #define _save_whitenoise2(n1,n2,pwr,type)\
156 _white_pwr[n1][n2] += pwr;
157 #define _save_flickernoise1(n1,pwr,exp,type)\
158 _flicker_pwr[n1][n1] += pwr;\
159 _flicker_exp[n1][n1] += exp;
160 #define _save_flickernoise2(n1,n2,pwr,exp,type)\
161 _flicker_pwr[n1][n2] += pwr;\
162 _flicker_exp[n1][n2] += exp;
163 #define _load_whitenoise2(n1,n2,pwr)\
164 cy (n1,n2) -= pwr/kB/T0; cy (n2,n1) -= pwr/kB/T0;\
165 cy (n1,n1) += pwr/kB/T0; cy (n2,n2) += pwr/kB/T0;
166 #define _load_whitenoise1(n1,pwr)\
167 cy (n1,n1) += pwr/kB/T0;
168 #define _load_flickernoise2(n1,n2,pwr,exp)\
169 cy (n1,n2) -= pwr*pow(_freq,-exp)/kB/T0;\
170 cy (n2,n1) -= pwr*pow(_freq,-exp)/kB/T0;\
171 cy (n1,n1) += pwr*pow(_freq,-exp)/kB/T0;\
172 cy (n2,n2) += pwr*pow(_freq,-exp)/kB/T0;
173 #define _load_flickernoise1(n1,pwr,exp)\
174 cy (n1,n1) += pwr*pow(_freq,-exp)/kB/T0;
177 #define m00_hypot(v00,x,y) v00 = xhypot(x,y);
178 #define m10_hypot(v10,v00,x,y) v10 = (x)/(v00);
179 #define m11_hypot(v11,v00,x,y) v11 = (y)/(v00);
180 #define m00_max(v00,x,y) v00 = ((x)>(y))?(x):(y);
181 #define m10_max(v10,v00,x,y) v10 = ((x)>(y))?1.0:0.0;
182 #define m11_max(v11,v00,x,y) v11 = ((x)>(y))?0.0:1.0;
183 #define m00_min(v00,x,y) v00 = ((x)<(y))?(x):(y);
184 #define m10_min(v10,v00,x,y) v10 = ((x)<(y))?1.0:0.0;
185 #define m11_min(v11,v00,x,y) v11 = ((x)<(y))?0.0:1.0;
186 #define m00_pow(v00,x,y) v00 = pow(x,y);
187 #define m10_pow(v10,v00,x,y) v10 = (x==0.0)?0.0:(v00)*(y)/(x);
188 #define m11_pow(v11,v00,x,y) v11 = (x==0.0)?0.0:(log(x)*(v00));
190 #define m00_div(v00,v10,x,y) double v10=1/(y); double v00=(x)*v10;
191 #define m10_div(v10,v00,vv,x,y)
192 #define m11_div(v11,v00,vv,x,y) double v11 = -v00*vv;
194 #define m00_mult(v00,v10,v11,x,y) double v10=(x); double v11=(y); double v00=v10*v11;
195 #define m00_add(v00,x,y) double v00=(x)+(y);
197 #define m00_cos(v00,x) v00 = cos(x);
198 #define m10_cos(v10,v00,x) v10 = (-sin(x));
199 #define m00_sin(v00,x) v00 = sin(x);
200 #define m10_sin(v10,v00,x) v10 = (cos(x));
201 #define m00_tan(v00,x) v00 = tan(x);
202 #define m10_tan(v10,v00,x) v10 = (1.0/cos(x)/cos(x));
203 #define m00_cosh(v00,x) v00 = cosh(x);
204 #define m10_cosh(v10,v00,x) v10 = (sinh(x));
205 #define m00_sinh(v00,x) v00 = sinh(x);
206 #define m10_sinh(v10,v00,x) v10 = (cosh(x));
207 #define m00_tanh(v00,x) v00 = tanh(x);
208 #define m10_tanh(v10,v00,x) v10 = (1.0/cosh(x)/cosh(x));
209 #define m00_acos(v00,x) v00 = acos(x);
210 #define m10_acos(v10,v00,x) v10 = (-1.0/sqrt(1-x*x));
211 #define m00_asin(v00,x) v00 = asin(x);
212 #define m10_asin(v10,v00,x) v10 = (+1.0/sqrt(1-x*x));
213 #define m00_atan(v00,x) v00 = atan(x);
214 #define m10_atan(v10,v00,x) v10 = (+1.0/(1+x*x));
215 #define m00_atanh(v00,x) v00 = atanh(x);
216 #define m10_atanh(v10,v00,x) v10 = (+1.0/(1-x*x));
217 #define m00_logE(v00,x) v00 = log(x);
218 #define m10_logE(v10,v00,x) v10 = (1.0/x);
219 #define m00_log10(v00,x) v00 = log10(x);
220 #define m10_log10(v10,v00,x) v10 = (1.0/x/M_LN10);
221 #define m00_sqrt(v00,x) v00 = sqrt(x);
222 #define m10_sqrt(v10,v00,x) v10 = (0.5/v00);
223 #define m00_fabs(v00,x) v00 = fabs(x);
224 #define m10_fabs(v10,v00,x) v10 = (((x)>=0)?(+1.0):(-1.0));
226 #define m00_exp(v00,x) v00 = exp(x);
227 #define m10_exp(v10,v00,x) v10 = v00;
229 #define m00_abs(v00) ((v00)<(0)?(-(v00)):(v00))
230 #define m00_floor(v00,x) v00 = floor(x);
231 #define m00_limexp(v00,x) v00 = ((x)<80.0?exp(x):exp(80.0)*(x-79.0));
232 #define m10_limexp(v10,v00,x) v10 = ((x)<80.0?(v00):exp(80.0));
234 #define m20_logE(v00) (-1.0/v00/v00)
235 #define m20_exp(v00) exp(v00)
236 #define m20_limexp(v00) ((v00)<80.0?exp(v00):0.0)
237 #define m20_sqrt(v00) (-0.25/(v00)/sqrt(v00))
238 #define m20_fabs(v00) 0.0
239 #define m20_pow(x,y) ((y)*((y)-1.0)*pow(x,y)/(x)/(x))
240 #define m00_vt(x) (kBoverQ*(x))
241 #define m10_vt(x) (kBoverQ)
244 #define _modelname "comp_4bit"
245 #define _instancename getName()
246 #define _circuit_temp (getPropertyDouble("Temp")+273.15)
247 #define _param_given(p) (isPropertyGiven(p)?1:0)
251 #define _vt_nom (kBoverQ*_circuit_temp)
253 using namespace device;
262 void comp_4bit::initModel (
void)
279 initializeInstance ();
300 void comp_4bit::initVerilog (
void)
307 for (i1 = 0; i1 < 17; i1++) {
308 for (i2 = 0; i2 < 17; i2++) {
309 _charges[i1][i2] = 0.0;
313 for (i1 = 0; i1 < 17; i1++) {
314 for (i2 = 0; i2 < 17; i2++) {
315 for (i3 = 0; i3 < 17; i3++) {
316 for (i4 = 0; i4 < 17; i4++) {
317 _caps[i1][i2][i3][i4] = 0.0;
321 for (i1 = 0; i1 < 17; i1++) {
326 for (i2 = 0; i2 < 17; i2++) {
327 _jstat[i1][i2] = 0.0;
328 _jdyna[i1][i2] = 0.0;
334 void comp_4bit::loadVariables (
void)
346 #define _DERIVATEFORDDX
349 void comp_4bit::initializeModel (
void)
351 #if defined(_DYNAMIC)
355 #if defined(_DYNAMIC)
356 Cd=((Delay*1.43)/Rd);
362 void comp_4bit::initializeInstance (
void)
367 void comp_4bit::initialStep (
void)
372 void comp_4bit::finalStep (
void)
377 void comp_4bit::calcVerilog (
void)
382 #if defined(_DERIVATE)
393 #if defined(_DERIVATE)
404 #if defined(_DERIVATE)
415 #if defined(_DERIVATE)
424 #if defined(_DERIVATE)
431 #if defined(_DERIVATE)
432 double xor3b_VX3_GND;
433 double xor3b_VY3_GND;
436 #if defined(_DERIVATE)
437 double xor2b_VX2_GND;
438 double xor2b_VY2_GND;
441 #if defined(_DERIVATE)
442 double xor1b_VX1_GND;
443 double xor1b_VY1_GND;
446 #if defined(_DERIVATE)
447 double xor0b_VX0_GND;
448 double xor0b_VY0_GND;
450 #if defined(_DERIVATE)
451 xor0b_VX0_GND=(-(((1-
NP(
Y0)))+(-1.0)*
NP(
Y0)));
452 xor0b_VY0_GND=(-((
NP(
X0)*(-1.0))+((1-
NP(
X0)))));
455 #if defined(_DERIVATE)
456 xor1b_VX1_GND=(-(((1-
NP(
Y1)))+(-1.0)*
NP(
Y1)));
457 xor1b_VY1_GND=(-((
NP(
X1)*(-1.0))+((1-
NP(
X1)))));
460 #if defined(_DERIVATE)
461 xor2b_VX2_GND=(-(((1-
NP(
Y2)))+(-1.0)*
NP(
Y2)));
462 xor2b_VY2_GND=(-((
NP(
X2)*(-1.0))+((1-
NP(
X2)))));
465 #if defined(_DERIVATE)
466 xor3b_VX3_GND=(-(((1-
NP(
Y3)))+(-1.0)*
NP(
Y3)));
467 xor3b_VY3_GND=(-((
NP(
X3)*(-1.0))+((1-
NP(
X3)))));
470 #if defined(_DERIVATE)
471 t1_VX3_GND=xor3b_VX3_GND*xor2b;
472 t1_VY3_GND=xor3b_VY3_GND*xor2b;
473 t1_VX2_GND=(xor3b*xor2b_VX2_GND);
474 t1_VY2_GND=(xor3b*xor2b_VY2_GND);
477 #if defined(_DERIVATE)
478 t2_VX3_GND=t1_VX3_GND*xor1b;
479 t2_VY3_GND=t1_VY3_GND*xor1b;
480 t2_VX2_GND=t1_VX2_GND*xor1b;
481 t2_VY2_GND=t1_VY2_GND*xor1b;
482 t2_VX1_GND=(t1*xor1b_VX1_GND);
483 t2_VY1_GND=(t1*xor1b_VY1_GND);
486 #if defined(_DERIVATE)
487 mE_VX0_GND=xor0b_VX0_GND*t2;
488 mE_VY0_GND=xor0b_VY0_GND*t2;
489 mE_VX3_GND=(xor0b*t2_VX3_GND);
490 mE_VY3_GND=(xor0b*t2_VY3_GND);
491 mE_VX2_GND=(xor0b*t2_VX2_GND);
492 mE_VY2_GND=(xor0b*t2_VY2_GND);
493 mE_VX1_GND=(xor0b*t2_VX1_GND);
494 mE_VY1_GND=(xor0b*t2_VY1_GND);
497 #if defined(_DERIVATE)
501 mG_VY2_GND=((((xor3b*
NP(
X2))*(-1.0))+t1_VY2_GND*
NP(
X1)*(1-
NP(
Y1)))+t2_VY2_GND*
NP(
X0)*(1-
NP(
Y0)));
502 mG_VX1_GND=((t1)*(1-
NP(
Y1))+t2_VX1_GND*
NP(
X0)*(1-
NP(
Y0)));
503 mG_VY1_GND=(((t1*
NP(
X1))*(-1.0))+t2_VY1_GND*
NP(
X0)*(1-
NP(
Y0)));
504 mG_VX0_GND=(t2)*(1-
NP(
Y0));
505 mG_VY0_GND=((t2*
NP(
X0))*(-1.0));
508 #if defined(_DERIVATE)
513 mL_VX1_GND=((t1*(-1.0))*
NP(
Y1)+t2_VX1_GND*(1-
NP(
X0))*
NP(
Y0));
514 mL_VY1_GND=(((t1*(1-
NP(
X1))))+t2_VY1_GND*(1-
NP(
X0))*
NP(
Y0));
515 mL_VX0_GND=(t2*(-1.0))*
NP(
Y0);
516 mL_VY0_GND=((t2*(1-
NP(
X0))));
520 double m00_tanh(d00_tanh0,(TR*(mE-0.5)))
521 #if defined(_DERIVATE)
522 double m10_tanh(d10_tanh0,d00_tanh0,(TR*(mE-0.5)))
525 #if defined(_DERIVATE)
537 #if defined(_DERIVATE)
541 #if defined(_DERIVATE)
544 #if defined(_DYNAMIC)
546 #if defined(_DERIVATE)
551 #if defined(_DERIVATE)
555 #if defined(_DERIVATE)
559 double m00_tanh(d00_tanh0,(TR*(mG-0.5)))
560 #if defined(_DERIVATE)
561 double m10_tanh(d10_tanh0,d00_tanh0,(TR*(mG-0.5)))
564 #if defined(_DERIVATE)
576 #if defined(_DERIVATE)
580 #if defined(_DERIVATE)
583 #if defined(_DYNAMIC)
585 #if defined(_DERIVATE)
590 #if defined(_DERIVATE)
594 #if defined(_DERIVATE)
598 double m00_tanh(d00_tanh0,(TR*(mL-0.5)))
599 #if defined(_DERIVATE)
600 double m10_tanh(d10_tanh0,d00_tanh0,(TR*(mL-0.5)))
603 #if defined(_DERIVATE)
615 #if defined(_DERIVATE)
619 #if defined(_DERIVATE)
622 #if defined(_DYNAMIC)
624 #if defined(_DERIVATE)
629 #if defined(_DERIVATE)
633 #if defined(_DERIVATE)
652 for (
int i1 = 0; i1 < 17; i1++) {
654 for (
int i2 = 0; i2 < 17; i2++) {
655 setY (i1, i2, _jstat[i1][i2]);
689 matrix comp_4bit::calcMatrixY (nr_double_t frequency)
695 for (
int i1 = 0; i1 < 17; i1++) {
696 for (
int i2 = 0; i2 < 17; i2++) {
697 y (i1,i2) =
rect (_jstat[i1][i2], _jdyna[i1][i2] * 2 *
M_PI * _freq);
731 int i1, i2, i3, i4, state;
734 for (i1 = 0; i1 < 17; i1++) {
735 for (i2 = 0; i2 < 17; i2++) {
736 state = 2 * (i2 + 17 * i1);
738 if (_charges[i1][i2] != 0.0)
743 for (i1 = 0; i1 < 17; i1++) {
744 state = 2 * (i1 + 17 * i1);
745 if (_charges[i1][i1] != 0.0)
750 for (i1 = 0; i1 < 17; i1++) {
751 for (i2 = 0; i2 < 17; i2++) {
753 for (i3 = 0; i3 < 17; i3++) {
754 for (i4 = 0; i4 < 17; i4++) {
756 if (_caps[i1][i2][i3][i4] != 0.0)
761 for (i1 = 0; i1 < 17; i1++) {
762 for (i2 = 0; i2 < 17; i2++) {
764 for (i3 = 0; i3 < 17; i3++) {
765 if (_caps[i1][i2][i3][i3] != 0.0)
770 for (i1 = 0; i1 < 17; i1++) {
771 for (i3 = 0; i3 < 17; i3++) {
772 for (i4 = 0; i4 < 17; i4++) {
774 if (_caps[i1][i1][i3][i4] != 0.0)
779 for (i1 = 0; i1 < 17; i1++) {
780 for (i3 = 0; i3 < 17; i3++) {
781 if (_caps[i1][i1][i3][i3] != 0.0)
787 matrix comp_4bit::calcMatrixCy (nr_double_t frequency)
827 for (
int i1 = 0; i1 < 17; i1++) {
829 setCV (i1, _chs[i1]);
830 setGV (i1, _ghs[i1]);
831 for (
int i2 = 0; i2 < 17; i2++) {
832 setQV (i1, i2, _jdyna[i1][i2]);