16 #include "component.h"
21 #define CIR_comp_2bit -1
41 #define NP(node) real (getV (node))
42 #define BP(pnode,nnode) (NP(pnode) - NP(nnode))
43 #define _load_static_residual2(pnode,nnode,current)\
44 _rhs[pnode] -= current;\
45 _rhs[nnode] += current;
46 #define _load_static_augmented_residual2(pnode,nnode,current)\
47 _rhs[pnode] -= current;\
48 _rhs[nnode] += current;
49 #define _load_static_residual1(node,current)\
50 _rhs[node] -= current;
51 #define _load_static_augmented_residual1(node,current)\
52 _rhs[node] -= current;
53 #define _load_static_jacobian4(pnode,nnode,vpnode,vnnode,conductance)\
54 _jstat[pnode][vpnode] += conductance;\
55 _jstat[nnode][vnnode] += conductance;\
56 _jstat[pnode][vnnode] -= conductance;\
57 _jstat[nnode][vpnode] -= conductance;\
59 _ghs[pnode] += conductance * BP(vpnode,vnnode);\
60 _ghs[nnode] -= conductance * BP(vpnode,vnnode);\
62 _rhs[pnode] += conductance * BP(vpnode,vnnode);\
63 _rhs[nnode] -= conductance * BP(vpnode,vnnode);\
65 #define _load_static_jacobian2p(node,vpnode,vnnode,conductance)\
66 _jstat[node][vpnode] += conductance;\
67 _jstat[node][vnnode] -= conductance;\
69 _ghs[node] += conductance * BP(vpnode,vnnode);\
71 _rhs[node] += conductance * BP(vpnode,vnnode);\
73 #define _load_static_jacobian2s(pnode,nnode,node,conductance)\
74 _jstat[pnode][node] += conductance;\
75 _jstat[nnode][node] -= conductance;\
77 _ghs[pnode] += conductance * NP(node);\
78 _ghs[nnode] -= conductance * NP(node);\
80 _rhs[pnode] += conductance * NP(node);\
81 _rhs[nnode] -= conductance * NP(node);\
83 #define _load_static_jacobian1(node,vnode,conductance)\
84 _jstat[node][vnode] += conductance;\
86 _ghs[node] += conductance * NP(vnode);\
88 _rhs[node] += conductance * NP(vnode);\
90 #define _load_dynamic_residual2(pnode,nnode,charge)\
91 if (doTR) _charges[pnode][nnode] += charge;\
93 _qhs[pnode] -= charge;\
94 _qhs[nnode] += charge;\
96 #define _load_dynamic_residual1(node,charge)\
97 if (doTR) _charges[node][node] += charge;\
99 _qhs[node] -= charge;\
101 #define _load_dynamic_jacobian4(pnode,nnode,vpnode,vnnode,capacitance)\
103 _jdyna[pnode][vpnode] += capacitance;\
104 _jdyna[nnode][vnnode] += capacitance;\
105 _jdyna[pnode][vnnode] -= capacitance;\
106 _jdyna[nnode][vpnode] -= capacitance;\
109 _caps[pnode][nnode][vpnode][vnnode] += capacitance;\
112 _chs[pnode] += capacitance * BP(vpnode,vnnode);\
113 _chs[nnode] -= capacitance * BP(vpnode,vnnode);\
115 #define _load_dynamic_jacobian2s(pnode,nnode,vnode,capacitance)\
117 _jdyna[pnode][vnode] += capacitance;\
118 _jdyna[nnode][vnode] -= capacitance;\
121 _caps[pnode][nnode][vnode][vnode] += capacitance;\
124 _chs[pnode] += capacitance * NP(vnode);\
125 _chs[nnode] -= capacitance * NP(vnode);\
127 #define _load_dynamic_jacobian2p(node,vpnode,vnnode,capacitance)\
129 _jdyna[node][vpnode] += capacitance;\
130 _jdyna[node][vnnode] -= capacitance;\
133 _caps[node][node][vpnode][vnnode] += capacitance;\
136 _chs[node] += capacitance * BP(vpnode,vnnode);\
138 #define _load_dynamic_jacobian1(node,vnode,capacitance)\
140 _jdyna[node][vnode] += capacitance;\
143 _caps[node][node][vnode][vnode] += capacitance;\
146 _chs[node] += capacitance * NP(vnode);\
149 #define _save_whitenoise1(n1,pwr,type)\
150 _white_pwr[n1][n1] += pwr;
151 #define _save_whitenoise2(n1,n2,pwr,type)\
152 _white_pwr[n1][n2] += pwr;
153 #define _save_flickernoise1(n1,pwr,exp,type)\
154 _flicker_pwr[n1][n1] += pwr;\
155 _flicker_exp[n1][n1] += exp;
156 #define _save_flickernoise2(n1,n2,pwr,exp,type)\
157 _flicker_pwr[n1][n2] += pwr;\
158 _flicker_exp[n1][n2] += exp;
159 #define _load_whitenoise2(n1,n2,pwr)\
160 cy (n1,n2) -= pwr/kB/T0; cy (n2,n1) -= pwr/kB/T0;\
161 cy (n1,n1) += pwr/kB/T0; cy (n2,n2) += pwr/kB/T0;
162 #define _load_whitenoise1(n1,pwr)\
163 cy (n1,n1) += pwr/kB/T0;
164 #define _load_flickernoise2(n1,n2,pwr,exp)\
165 cy (n1,n2) -= pwr*pow(_freq,-exp)/kB/T0;\
166 cy (n2,n1) -= pwr*pow(_freq,-exp)/kB/T0;\
167 cy (n1,n1) += pwr*pow(_freq,-exp)/kB/T0;\
168 cy (n2,n2) += pwr*pow(_freq,-exp)/kB/T0;
169 #define _load_flickernoise1(n1,pwr,exp)\
170 cy (n1,n1) += pwr*pow(_freq,-exp)/kB/T0;
173 #define m00_hypot(v00,x,y) v00 = xhypot(x,y);
174 #define m10_hypot(v10,v00,x,y) v10 = (x)/(v00);
175 #define m11_hypot(v11,v00,x,y) v11 = (y)/(v00);
176 #define m00_max(v00,x,y) v00 = ((x)>(y))?(x):(y);
177 #define m10_max(v10,v00,x,y) v10 = ((x)>(y))?1.0:0.0;
178 #define m11_max(v11,v00,x,y) v11 = ((x)>(y))?0.0:1.0;
179 #define m00_min(v00,x,y) v00 = ((x)<(y))?(x):(y);
180 #define m10_min(v10,v00,x,y) v10 = ((x)<(y))?1.0:0.0;
181 #define m11_min(v11,v00,x,y) v11 = ((x)<(y))?0.0:1.0;
182 #define m00_pow(v00,x,y) v00 = pow(x,y);
183 #define m10_pow(v10,v00,x,y) v10 = (x==0.0)?0.0:(v00)*(y)/(x);
184 #define m11_pow(v11,v00,x,y) v11 = (x==0.0)?0.0:(log(x)*(v00));
186 #define m00_div(v00,v10,x,y) double v10=1/(y); double v00=(x)*v10;
187 #define m10_div(v10,v00,vv,x,y)
188 #define m11_div(v11,v00,vv,x,y) double v11 = -v00*vv;
190 #define m00_mult(v00,v10,v11,x,y) double v10=(x); double v11=(y); double v00=v10*v11;
191 #define m00_add(v00,x,y) double v00=(x)+(y);
193 #define m00_cos(v00,x) v00 = cos(x);
194 #define m10_cos(v10,v00,x) v10 = (-sin(x));
195 #define m00_sin(v00,x) v00 = sin(x);
196 #define m10_sin(v10,v00,x) v10 = (cos(x));
197 #define m00_tan(v00,x) v00 = tan(x);
198 #define m10_tan(v10,v00,x) v10 = (1.0/cos(x)/cos(x));
199 #define m00_cosh(v00,x) v00 = cosh(x);
200 #define m10_cosh(v10,v00,x) v10 = (sinh(x));
201 #define m00_sinh(v00,x) v00 = sinh(x);
202 #define m10_sinh(v10,v00,x) v10 = (cosh(x));
203 #define m00_tanh(v00,x) v00 = tanh(x);
204 #define m10_tanh(v10,v00,x) v10 = (1.0/cosh(x)/cosh(x));
205 #define m00_acos(v00,x) v00 = acos(x);
206 #define m10_acos(v10,v00,x) v10 = (-1.0/sqrt(1-x*x));
207 #define m00_asin(v00,x) v00 = asin(x);
208 #define m10_asin(v10,v00,x) v10 = (+1.0/sqrt(1-x*x));
209 #define m00_atan(v00,x) v00 = atan(x);
210 #define m10_atan(v10,v00,x) v10 = (+1.0/(1+x*x));
211 #define m00_atanh(v00,x) v00 = atanh(x);
212 #define m10_atanh(v10,v00,x) v10 = (+1.0/(1-x*x));
213 #define m00_logE(v00,x) v00 = log(x);
214 #define m10_logE(v10,v00,x) v10 = (1.0/x);
215 #define m00_log10(v00,x) v00 = log10(x);
216 #define m10_log10(v10,v00,x) v10 = (1.0/x/M_LN10);
217 #define m00_sqrt(v00,x) v00 = sqrt(x);
218 #define m10_sqrt(v10,v00,x) v10 = (0.5/v00);
219 #define m00_fabs(v00,x) v00 = fabs(x);
220 #define m10_fabs(v10,v00,x) v10 = (((x)>=0)?(+1.0):(-1.0));
222 #define m00_exp(v00,x) v00 = exp(x);
223 #define m10_exp(v10,v00,x) v10 = v00;
225 #define m00_abs(v00) ((v00)<(0)?(-(v00)):(v00))
226 #define m00_floor(v00,x) v00 = floor(x);
227 #define m00_limexp(v00,x) v00 = ((x)<80.0?exp(x):exp(80.0)*(x-79.0));
228 #define m10_limexp(v10,v00,x) v10 = ((x)<80.0?(v00):exp(80.0));
230 #define m20_logE(v00) (-1.0/v00/v00)
231 #define m20_exp(v00) exp(v00)
232 #define m20_limexp(v00) ((v00)<80.0?exp(v00):0.0)
233 #define m20_sqrt(v00) (-0.25/(v00)/sqrt(v00))
234 #define m20_fabs(v00) 0.0
235 #define m20_pow(x,y) ((y)*((y)-1.0)*pow(x,y)/(x)/(x))
236 #define m00_vt(x) (kBoverQ*(x))
237 #define m10_vt(x) (kBoverQ)
240 #define _modelname "comp_2bit"
241 #define _instancename getName()
242 #define _circuit_temp (getPropertyDouble("Temp")+273.15)
243 #define _param_given(p) (isPropertyGiven(p)?1:0)
247 #define _vt_nom (kBoverQ*_circuit_temp)
249 using namespace device;
258 void comp_2bit::initModel (
void)
275 initializeInstance ();
296 void comp_2bit::initVerilog (
void)
303 for (i1 = 0; i1 < 13; i1++) {
304 for (i2 = 0; i2 < 13; i2++) {
305 _charges[i1][i2] = 0.0;
309 for (i1 = 0; i1 < 13; i1++) {
310 for (i2 = 0; i2 < 13; i2++) {
311 for (i3 = 0; i3 < 13; i3++) {
312 for (i4 = 0; i4 < 13; i4++) {
313 _caps[i1][i2][i3][i4] = 0.0;
317 for (i1 = 0; i1 < 13; i1++) {
322 for (i2 = 0; i2 < 13; i2++) {
323 _jstat[i1][i2] = 0.0;
324 _jdyna[i1][i2] = 0.0;
330 void comp_2bit::loadVariables (
void)
342 #define _DERIVATEFORDDX
345 void comp_2bit::initializeModel (
void)
347 #if defined(_DYNAMIC)
351 #if defined(_DYNAMIC)
352 Cd=((Delay*1.43)/Rd);
358 void comp_2bit::initializeInstance (
void)
363 void comp_2bit::initialStep (
void)
368 void comp_2bit::finalStep (
void)
373 void comp_2bit::calcVerilog (
void)
378 #if defined(_DERIVATE)
385 #if defined(_DERIVATE)
392 #if defined(_DERIVATE)
399 #if defined(_DERIVATE)
400 double xor1b_VX1_GND;
401 double xor1b_VY1_GND;
404 #if defined(_DERIVATE)
405 double xor0b_VX0_GND;
406 double xor0b_VY0_GND;
408 #if defined(_DERIVATE)
409 xor0b_VX0_GND=(-(((1-
NP(
Y0)))+(-1.0)*
NP(
Y0)));
410 xor0b_VY0_GND=(-((
NP(
X0)*(-1.0))+((1-
NP(
X0)))));
413 #if defined(_DERIVATE)
414 xor1b_VX1_GND=(-(((1-
NP(
Y1)))+(-1.0)*
NP(
Y1)));
415 xor1b_VY1_GND=(-((
NP(
X1)*(-1.0))+((1-
NP(
X1)))));
418 #if defined(_DERIVATE)
419 mE_VX0_GND=xor0b_VX0_GND*xor1b;
420 mE_VY0_GND=xor0b_VY0_GND*xor1b;
421 mE_VX1_GND=(xor0b*xor1b_VX1_GND);
422 mE_VY1_GND=(xor0b*xor1b_VY1_GND);
425 #if defined(_DERIVATE)
426 mG_VX1_GND=(((1-
NP(
Y1)))+xor1b_VX1_GND*
NP(
X0)*(1-
NP(
Y0)));
427 mG_VY1_GND=((
NP(
X1)*(-1.0))+xor1b_VY1_GND*
NP(
X0)*(1-
NP(
Y0)));
428 mG_VX0_GND=(xor1b)*(1-
NP(
Y0));
429 mG_VY0_GND=((xor1b*
NP(
X0))*(-1.0));
432 #if defined(_DERIVATE)
433 mL_VX1_GND=((-1.0)*
NP(
Y1)+xor1b_VX1_GND*(1-
NP(
X0))*
NP(
Y0));
434 mL_VY1_GND=(((1-
NP(
X1)))+xor1b_VY1_GND*(1-
NP(
X0))*
NP(
Y0));
435 mL_VX0_GND=(xor1b*(-1.0))*
NP(
Y0);
436 mL_VY0_GND=((xor1b*(1-
NP(
X0))));
440 double m00_tanh(d00_tanh0,(TR*(mE-0.5)))
441 #if defined(_DERIVATE)
442 double m10_tanh(d10_tanh0,d00_tanh0,(TR*(mE-0.5)))
445 #if defined(_DERIVATE)
453 #if defined(_DERIVATE)
457 #if defined(_DERIVATE)
460 #if defined(_DYNAMIC)
462 #if defined(_DERIVATE)
467 #if defined(_DERIVATE)
471 #if defined(_DERIVATE)
475 double m00_tanh(d00_tanh0,(TR*(mG-0.5)))
476 #if defined(_DERIVATE)
477 double m10_tanh(d10_tanh0,d00_tanh0,(TR*(mG-0.5)))
480 #if defined(_DERIVATE)
488 #if defined(_DERIVATE)
492 #if defined(_DERIVATE)
495 #if defined(_DYNAMIC)
497 #if defined(_DERIVATE)
502 #if defined(_DERIVATE)
506 #if defined(_DERIVATE)
510 double m00_tanh(d00_tanh0,(TR*(mL-0.5)))
511 #if defined(_DERIVATE)
512 double m10_tanh(d10_tanh0,d00_tanh0,(TR*(mL-0.5)))
515 #if defined(_DERIVATE)
523 #if defined(_DERIVATE)
527 #if defined(_DERIVATE)
530 #if defined(_DYNAMIC)
532 #if defined(_DERIVATE)
537 #if defined(_DERIVATE)
541 #if defined(_DERIVATE)
560 for (
int i1 = 0; i1 < 13; i1++) {
562 for (
int i2 = 0; i2 < 13; i2++) {
563 setY (i1, i2, _jstat[i1][i2]);
597 matrix comp_2bit::calcMatrixY (nr_double_t frequency)
603 for (
int i1 = 0; i1 < 13; i1++) {
604 for (
int i2 = 0; i2 < 13; i2++) {
605 y (i1,i2) =
rect (_jstat[i1][i2], _jdyna[i1][i2] * 2 *
M_PI * _freq);
639 int i1, i2, i3, i4, state;
642 for (i1 = 0; i1 < 13; i1++) {
643 for (i2 = 0; i2 < 13; i2++) {
644 state = 2 * (i2 + 13 * i1);
646 if (_charges[i1][i2] != 0.0)
651 for (i1 = 0; i1 < 13; i1++) {
652 state = 2 * (i1 + 13 * i1);
653 if (_charges[i1][i1] != 0.0)
658 for (i1 = 0; i1 < 13; i1++) {
659 for (i2 = 0; i2 < 13; i2++) {
661 for (i3 = 0; i3 < 13; i3++) {
662 for (i4 = 0; i4 < 13; i4++) {
664 if (_caps[i1][i2][i3][i4] != 0.0)
669 for (i1 = 0; i1 < 13; i1++) {
670 for (i2 = 0; i2 < 13; i2++) {
672 for (i3 = 0; i3 < 13; i3++) {
673 if (_caps[i1][i2][i3][i3] != 0.0)
678 for (i1 = 0; i1 < 13; i1++) {
679 for (i3 = 0; i3 < 13; i3++) {
680 for (i4 = 0; i4 < 13; i4++) {
682 if (_caps[i1][i1][i3][i4] != 0.0)
687 for (i1 = 0; i1 < 13; i1++) {
688 for (i3 = 0; i3 < 13; i3++) {
689 if (_caps[i1][i1][i3][i3] != 0.0)
695 matrix comp_2bit::calcMatrixCy (nr_double_t frequency)
735 for (
int i1 = 0; i1 < 13; i1++) {
737 setCV (i1, _chs[i1]);
738 setGV (i1, _ghs[i1]);
739 for (
int i2 = 0; i2 < 13; i2++) {
740 setQV (i1, i2, _jdyna[i1][i2]);