16 #include "component.h"
20 #ifndef CIR_binarytogrey4bit
21 #define CIR_binarytogrey4bit -1
44 #define NP(node) real (getV (node))
45 #define BP(pnode,nnode) (NP(pnode) - NP(nnode))
46 #define _load_static_residual2(pnode,nnode,current)\
47 _rhs[pnode] -= current;\
48 _rhs[nnode] += current;
49 #define _load_static_augmented_residual2(pnode,nnode,current)\
50 _rhs[pnode] -= current;\
51 _rhs[nnode] += current;
52 #define _load_static_residual1(node,current)\
53 _rhs[node] -= current;
54 #define _load_static_augmented_residual1(node,current)\
55 _rhs[node] -= current;
56 #define _load_static_jacobian4(pnode,nnode,vpnode,vnnode,conductance)\
57 _jstat[pnode][vpnode] += conductance;\
58 _jstat[nnode][vnnode] += conductance;\
59 _jstat[pnode][vnnode] -= conductance;\
60 _jstat[nnode][vpnode] -= conductance;\
62 _ghs[pnode] += conductance * BP(vpnode,vnnode);\
63 _ghs[nnode] -= conductance * BP(vpnode,vnnode);\
65 _rhs[pnode] += conductance * BP(vpnode,vnnode);\
66 _rhs[nnode] -= conductance * BP(vpnode,vnnode);\
68 #define _load_static_jacobian2p(node,vpnode,vnnode,conductance)\
69 _jstat[node][vpnode] += conductance;\
70 _jstat[node][vnnode] -= conductance;\
72 _ghs[node] += conductance * BP(vpnode,vnnode);\
74 _rhs[node] += conductance * BP(vpnode,vnnode);\
76 #define _load_static_jacobian2s(pnode,nnode,node,conductance)\
77 _jstat[pnode][node] += conductance;\
78 _jstat[nnode][node] -= conductance;\
80 _ghs[pnode] += conductance * NP(node);\
81 _ghs[nnode] -= conductance * NP(node);\
83 _rhs[pnode] += conductance * NP(node);\
84 _rhs[nnode] -= conductance * NP(node);\
86 #define _load_static_jacobian1(node,vnode,conductance)\
87 _jstat[node][vnode] += conductance;\
89 _ghs[node] += conductance * NP(vnode);\
91 _rhs[node] += conductance * NP(vnode);\
93 #define _load_dynamic_residual2(pnode,nnode,charge)\
94 if (doTR) _charges[pnode][nnode] += charge;\
96 _qhs[pnode] -= charge;\
97 _qhs[nnode] += charge;\
99 #define _load_dynamic_residual1(node,charge)\
100 if (doTR) _charges[node][node] += charge;\
102 _qhs[node] -= charge;\
104 #define _load_dynamic_jacobian4(pnode,nnode,vpnode,vnnode,capacitance)\
106 _jdyna[pnode][vpnode] += capacitance;\
107 _jdyna[nnode][vnnode] += capacitance;\
108 _jdyna[pnode][vnnode] -= capacitance;\
109 _jdyna[nnode][vpnode] -= capacitance;\
112 _caps[pnode][nnode][vpnode][vnnode] += capacitance;\
115 _chs[pnode] += capacitance * BP(vpnode,vnnode);\
116 _chs[nnode] -= capacitance * BP(vpnode,vnnode);\
118 #define _load_dynamic_jacobian2s(pnode,nnode,vnode,capacitance)\
120 _jdyna[pnode][vnode] += capacitance;\
121 _jdyna[nnode][vnode] -= capacitance;\
124 _caps[pnode][nnode][vnode][vnode] += capacitance;\
127 _chs[pnode] += capacitance * NP(vnode);\
128 _chs[nnode] -= capacitance * NP(vnode);\
130 #define _load_dynamic_jacobian2p(node,vpnode,vnnode,capacitance)\
132 _jdyna[node][vpnode] += capacitance;\
133 _jdyna[node][vnnode] -= capacitance;\
136 _caps[node][node][vpnode][vnnode] += capacitance;\
139 _chs[node] += capacitance * BP(vpnode,vnnode);\
141 #define _load_dynamic_jacobian1(node,vnode,capacitance)\
143 _jdyna[node][vnode] += capacitance;\
146 _caps[node][node][vnode][vnode] += capacitance;\
149 _chs[node] += capacitance * NP(vnode);\
152 #define _save_whitenoise1(n1,pwr,type)\
153 _white_pwr[n1][n1] += pwr;
154 #define _save_whitenoise2(n1,n2,pwr,type)\
155 _white_pwr[n1][n2] += pwr;
156 #define _save_flickernoise1(n1,pwr,exp,type)\
157 _flicker_pwr[n1][n1] += pwr;\
158 _flicker_exp[n1][n1] += exp;
159 #define _save_flickernoise2(n1,n2,pwr,exp,type)\
160 _flicker_pwr[n1][n2] += pwr;\
161 _flicker_exp[n1][n2] += exp;
162 #define _load_whitenoise2(n1,n2,pwr)\
163 cy (n1,n2) -= pwr/kB/T0; cy (n2,n1) -= pwr/kB/T0;\
164 cy (n1,n1) += pwr/kB/T0; cy (n2,n2) += pwr/kB/T0;
165 #define _load_whitenoise1(n1,pwr)\
166 cy (n1,n1) += pwr/kB/T0;
167 #define _load_flickernoise2(n1,n2,pwr,exp)\
168 cy (n1,n2) -= pwr*pow(_freq,-exp)/kB/T0;\
169 cy (n2,n1) -= pwr*pow(_freq,-exp)/kB/T0;\
170 cy (n1,n1) += pwr*pow(_freq,-exp)/kB/T0;\
171 cy (n2,n2) += pwr*pow(_freq,-exp)/kB/T0;
172 #define _load_flickernoise1(n1,pwr,exp)\
173 cy (n1,n1) += pwr*pow(_freq,-exp)/kB/T0;
176 #define m00_hypot(v00,x,y) v00 = xhypot(x,y);
177 #define m10_hypot(v10,v00,x,y) v10 = (x)/(v00);
178 #define m11_hypot(v11,v00,x,y) v11 = (y)/(v00);
179 #define m00_max(v00,x,y) v00 = ((x)>(y))?(x):(y);
180 #define m10_max(v10,v00,x,y) v10 = ((x)>(y))?1.0:0.0;
181 #define m11_max(v11,v00,x,y) v11 = ((x)>(y))?0.0:1.0;
182 #define m00_min(v00,x,y) v00 = ((x)<(y))?(x):(y);
183 #define m10_min(v10,v00,x,y) v10 = ((x)<(y))?1.0:0.0;
184 #define m11_min(v11,v00,x,y) v11 = ((x)<(y))?0.0:1.0;
185 #define m00_pow(v00,x,y) v00 = pow(x,y);
186 #define m10_pow(v10,v00,x,y) v10 = (x==0.0)?0.0:(v00)*(y)/(x);
187 #define m11_pow(v11,v00,x,y) v11 = (x==0.0)?0.0:(log(x)*(v00));
189 #define m00_div(v00,v10,x,y) double v10=1/(y); double v00=(x)*v10;
190 #define m10_div(v10,v00,vv,x,y)
191 #define m11_div(v11,v00,vv,x,y) double v11 = -v00*vv;
193 #define m00_mult(v00,v10,v11,x,y) double v10=(x); double v11=(y); double v00=v10*v11;
194 #define m00_add(v00,x,y) double v00=(x)+(y);
196 #define m00_cos(v00,x) v00 = cos(x);
197 #define m10_cos(v10,v00,x) v10 = (-sin(x));
198 #define m00_sin(v00,x) v00 = sin(x);
199 #define m10_sin(v10,v00,x) v10 = (cos(x));
200 #define m00_tan(v00,x) v00 = tan(x);
201 #define m10_tan(v10,v00,x) v10 = (1.0/cos(x)/cos(x));
202 #define m00_cosh(v00,x) v00 = cosh(x);
203 #define m10_cosh(v10,v00,x) v10 = (sinh(x));
204 #define m00_sinh(v00,x) v00 = sinh(x);
205 #define m10_sinh(v10,v00,x) v10 = (cosh(x));
206 #define m00_tanh(v00,x) v00 = tanh(x);
207 #define m10_tanh(v10,v00,x) v10 = (1.0/cosh(x)/cosh(x));
208 #define m00_acos(v00,x) v00 = acos(x);
209 #define m10_acos(v10,v00,x) v10 = (-1.0/sqrt(1-x*x));
210 #define m00_asin(v00,x) v00 = asin(x);
211 #define m10_asin(v10,v00,x) v10 = (+1.0/sqrt(1-x*x));
212 #define m00_atan(v00,x) v00 = atan(x);
213 #define m10_atan(v10,v00,x) v10 = (+1.0/(1+x*x));
214 #define m00_atanh(v00,x) v00 = atanh(x);
215 #define m10_atanh(v10,v00,x) v10 = (+1.0/(1-x*x));
216 #define m00_logE(v00,x) v00 = log(x);
217 #define m10_logE(v10,v00,x) v10 = (1.0/x);
218 #define m00_log10(v00,x) v00 = log10(x);
219 #define m10_log10(v10,v00,x) v10 = (1.0/x/M_LN10);
220 #define m00_sqrt(v00,x) v00 = sqrt(x);
221 #define m10_sqrt(v10,v00,x) v10 = (0.5/v00);
222 #define m00_fabs(v00,x) v00 = fabs(x);
223 #define m10_fabs(v10,v00,x) v10 = (((x)>=0)?(+1.0):(-1.0));
225 #define m00_exp(v00,x) v00 = exp(x);
226 #define m10_exp(v10,v00,x) v10 = v00;
228 #define m00_abs(v00) ((v00)<(0)?(-(v00)):(v00))
229 #define m00_floor(v00,x) v00 = floor(x);
230 #define m00_limexp(v00,x) v00 = ((x)<80.0?exp(x):exp(80.0)*(x-79.0));
231 #define m10_limexp(v10,v00,x) v10 = ((x)<80.0?(v00):exp(80.0));
233 #define m20_logE(v00) (-1.0/v00/v00)
234 #define m20_exp(v00) exp(v00)
235 #define m20_limexp(v00) ((v00)<80.0?exp(v00):0.0)
236 #define m20_sqrt(v00) (-0.25/(v00)/sqrt(v00))
237 #define m20_fabs(v00) 0.0
238 #define m20_pow(x,y) ((y)*((y)-1.0)*pow(x,y)/(x)/(x))
239 #define m00_vt(x) (kBoverQ*(x))
240 #define m10_vt(x) (kBoverQ)
243 #define _modelname "binarytogrey4bit"
244 #define _instancename getName()
245 #define _circuit_temp (getPropertyDouble("Temp")+273.15)
246 #define _param_given(p) (isPropertyGiven(p)?1:0)
250 #define _vt_nom (kBoverQ*_circuit_temp)
252 using namespace device;
261 void binarytogrey4bit::initModel (
void)
280 initializeInstance ();
301 void binarytogrey4bit::initVerilog (
void)
308 for (i1 = 0; i1 < 16; i1++) {
309 for (i2 = 0; i2 < 16; i2++) {
310 _charges[i1][i2] = 0.0;
314 for (i1 = 0; i1 < 16; i1++) {
315 for (i2 = 0; i2 < 16; i2++) {
316 for (i3 = 0; i3 < 16; i3++) {
317 for (i4 = 0; i4 < 16; i4++) {
318 _caps[i1][i2][i3][i4] = 0.0;
322 for (i1 = 0; i1 < 16; i1++) {
327 for (i2 = 0; i2 < 16; i2++) {
328 _jstat[i1][i2] = 0.0;
329 _jdyna[i1][i2] = 0.0;
335 void binarytogrey4bit::loadVariables (
void)
347 #define _DERIVATEFORDDX
350 void binarytogrey4bit::initializeModel (
void)
352 #if defined(_DYNAMIC)
356 #if defined(_DYNAMIC)
357 Cd=((Delay*1.43)/Rd);
363 void binarytogrey4bit::initializeInstance (
void)
368 void binarytogrey4bit::initialStep (
void)
373 void binarytogrey4bit::finalStep (
void)
378 void binarytogrey4bit::calcVerilog (
void)
383 #if defined(_DERIVATE)
387 #if defined(_DERIVATE)
392 #if defined(_DERIVATE)
397 #if defined(_DERIVATE)
401 #if defined(_DERIVATE)
402 m0_VB0_GND=(((1-
NP(
B1)))+(-1.0)*
NP(
B1));
403 m0_VB1_GND=((
NP(
B0)*(-1.0))+((1-
NP(
B0))));
406 #if defined(_DERIVATE)
407 m1_VB1_GND=(((1-
NP(
B2)))+(-1.0)*
NP(
B2));
408 m1_VB2_GND=((
NP(
B1)*(-1.0))+((1-
NP(
B1))));
411 #if defined(_DERIVATE)
412 m2_VB2_GND=(((1-
NP(
B3)))+(-1.0)*
NP(
B3));
413 m2_VB3_GND=((
NP(
B2)*(-1.0))+((1-
NP(
B2))));
416 #if defined(_DERIVATE)
421 double m00_tanh(d00_tanh0,(TR*(m0-0.5)))
422 #if defined(_DERIVATE)
423 double m10_tanh(d10_tanh0,d00_tanh0,(TR*(m0-0.5)))
426 #if defined(_DERIVATE)
432 #if defined(_DERIVATE)
436 #if defined(_DERIVATE)
439 #if defined(_DYNAMIC)
441 #if defined(_DERIVATE)
446 #if defined(_DERIVATE)
450 #if defined(_DERIVATE)
454 double m00_tanh(d00_tanh0,(TR*(m1-0.5)))
455 #if defined(_DERIVATE)
456 double m10_tanh(d10_tanh0,d00_tanh0,(TR*(m1-0.5)))
459 #if defined(_DERIVATE)
465 #if defined(_DERIVATE)
469 #if defined(_DERIVATE)
472 #if defined(_DYNAMIC)
474 #if defined(_DERIVATE)
479 #if defined(_DERIVATE)
483 #if defined(_DERIVATE)
487 double m00_tanh(d00_tanh0,(TR*(m2-0.5)))
488 #if defined(_DERIVATE)
489 double m10_tanh(d10_tanh0,d00_tanh0,(TR*(m2-0.5)))
492 #if defined(_DERIVATE)
498 #if defined(_DERIVATE)
502 #if defined(_DERIVATE)
505 #if defined(_DYNAMIC)
507 #if defined(_DERIVATE)
512 #if defined(_DERIVATE)
516 #if defined(_DERIVATE)
520 double m00_tanh(d00_tanh0,(TR*(m3-0.5)))
521 #if defined(_DERIVATE)
522 double m10_tanh(d10_tanh0,d00_tanh0,(TR*(m3-0.5)))
525 #if defined(_DERIVATE)
530 #if defined(_DERIVATE)
534 #if defined(_DERIVATE)
537 #if defined(_DYNAMIC)
539 #if defined(_DERIVATE)
544 #if defined(_DERIVATE)
548 #if defined(_DERIVATE)
567 for (
int i1 = 0; i1 < 16; i1++) {
569 for (
int i2 = 0; i2 < 16; i2++) {
570 setY (i1, i2, _jstat[i1][i2]);
604 matrix binarytogrey4bit::calcMatrixY (nr_double_t frequency)
610 for (
int i1 = 0; i1 < 16; i1++) {
611 for (
int i2 = 0; i2 < 16; i2++) {
612 y (i1,i2) =
rect (_jstat[i1][i2], _jdyna[i1][i2] * 2 *
M_PI * _freq);
646 int i1, i2, i3, i4, state;
649 for (i1 = 0; i1 < 16; i1++) {
650 for (i2 = 0; i2 < 16; i2++) {
651 state = 2 * (i2 + 16 * i1);
653 if (_charges[i1][i2] != 0.0)
658 for (i1 = 0; i1 < 16; i1++) {
659 state = 2 * (i1 + 16 * i1);
660 if (_charges[i1][i1] != 0.0)
665 for (i1 = 0; i1 < 16; i1++) {
666 for (i2 = 0; i2 < 16; i2++) {
668 for (i3 = 0; i3 < 16; i3++) {
669 for (i4 = 0; i4 < 16; i4++) {
671 if (_caps[i1][i2][i3][i4] != 0.0)
676 for (i1 = 0; i1 < 16; i1++) {
677 for (i2 = 0; i2 < 16; i2++) {
679 for (i3 = 0; i3 < 16; i3++) {
680 if (_caps[i1][i2][i3][i3] != 0.0)
685 for (i1 = 0; i1 < 16; i1++) {
686 for (i3 = 0; i3 < 16; i3++) {
687 for (i4 = 0; i4 < 16; i4++) {
689 if (_caps[i1][i1][i3][i4] != 0.0)
694 for (i1 = 0; i1 < 16; i1++) {
695 for (i3 = 0; i3 < 16; i3++) {
696 if (_caps[i1][i1][i3][i3] != 0.0)
702 matrix binarytogrey4bit::calcMatrixCy (nr_double_t frequency)
742 for (
int i1 = 0; i1 < 16; i1++) {
744 setCV (i1, _chs[i1]);
745 setGV (i1, _ghs[i1]);
746 for (
int i2 = 0; i2 < 16; i2++) {
747 setQV (i1, i2, _jdyna[i1][i2]);