16 #include "component.h"
21 #define CIR_mux8to1 -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 "mux8to1"
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 mux8to1::initModel (
void)
273 initializeInstance ();
294 void mux8to1::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 mux8to1::loadVariables (
void)
340 #define _DERIVATEFORDDX
343 void mux8to1::initializeModel (
void)
345 #if defined(_DYNAMIC)
349 #if defined(_DYNAMIC)
350 Cd=((Delay*1.43)/Rd);
356 void mux8to1::initializeInstance (
void)
361 void mux8to1::initialStep (
void)
366 void mux8to1::finalStep (
void)
371 void mux8to1::calcVerilog (
void)
376 #if defined(_DERIVATE)
391 #if defined(_DERIVATE)
398 #if defined(_DERIVATE)
405 #if defined(_DERIVATE)
412 #if defined(_DERIVATE)
419 #if defined(_DERIVATE)
426 #if defined(_DERIVATE)
433 #if defined(_DERIVATE)
440 #if defined(_DERIVATE)
447 #if defined(_DERIVATE)
451 #if defined(_DERIVATE)
455 #if defined(_DERIVATE)
458 #if defined(_DERIVATE)
462 #if defined(_DERIVATE)
466 #if defined(_DERIVATE)
470 #if defined(_DERIVATE)
471 m0_VD0_GND=(VCI)*VBI*VAI;
472 m0_VC_GND=(
NP(
D0)*VCI_VC_GND)*VBI*VAI;
473 m0_VB_GND=((
NP(
D0)*VCI)*VBI_VB_GND)*VAI;
474 m0_VA_GND=(((
NP(
D0)*VCI)*VBI)*VAI_VA_GND);
476 m0=(((
NP(
D0)*VCI)*VBI)*VAI);
477 #if defined(_DERIVATE)
478 m1_VD1_GND=(VCI)*VBI*
NP(
A);
479 m1_VC_GND=(
NP(
D1)*VCI_VC_GND)*VBI*
NP(
A);
480 m1_VB_GND=((
NP(
D1)*VCI)*VBI_VB_GND)*
NP(
A);
481 m1_VA_GND=(((
NP(
D1)*VCI)*VBI));
484 #if defined(_DERIVATE)
485 m2_VD2_GND=(VCI)*
NP(
B)*VAI;
486 m2_VC_GND=(
NP(
D2)*VCI_VC_GND)*
NP(
B)*VAI;
487 m2_VB_GND=((
NP(
D2)*VCI))*VAI;
488 m2_VA_GND=(((
NP(
D2)*VCI)*
NP(
B))*VAI_VA_GND);
491 #if defined(_DERIVATE)
492 m3_VD3_GND=(VCI)*
NP(
B)*
NP(
A);
494 m3_VB_GND=((
NP(
D3)*VCI))*
NP(
A);
495 m3_VA_GND=(((
NP(
D3)*VCI)*
NP(
B)));
498 #if defined(_DERIVATE)
499 m4_VD4_GND=(
NP(
C))*VBI*VAI;
500 m4_VC_GND=(
NP(
D4))*VBI*VAI;
501 m4_VB_GND=((
NP(
D4)*
NP(
C))*VBI_VB_GND)*VAI;
502 m4_VA_GND=(((
NP(
D4)*
NP(
C))*VBI)*VAI_VA_GND);
505 #if defined(_DERIVATE)
506 m5_VD5_GND=(
NP(
C))*VBI*
NP(
A);
509 m5_VA_GND=(((
NP(
D5)*
NP(
C))*VBI));
512 #if defined(_DERIVATE)
513 m6_VD6_GND=(
NP(
C))*
NP(
B)*VAI;
515 m6_VB_GND=((
NP(
D6)*
NP(
C)))*VAI;
516 m6_VA_GND=(((
NP(
D6)*
NP(
C))*
NP(
B))*VAI_VA_GND);
519 #if defined(_DERIVATE)
526 #if defined(_DERIVATE)
527 In1_VEN_GND=(-1.0)*(((((((m0+m1)+m2)+m3)+m4)+m5)+m6)+m7);
528 In1_VD0_GND=((1-
NP(
EN))*m0_VD0_GND);
529 In1_VC_GND=((1-
NP(
EN))*(((((((m0_VC_GND+m1_VC_GND)+m2_VC_GND)+m3_VC_GND)+m4_VC_GND)+m5_VC_GND)+m6_VC_GND)+m7_VC_GND));
530 In1_VB_GND=((1-
NP(
EN))*(((((((m0_VB_GND+m1_VB_GND)+m2_VB_GND)+m3_VB_GND)+m4_VB_GND)+m5_VB_GND)+m6_VB_GND)+m7_VB_GND));
531 In1_VA_GND=((1-
NP(
EN))*(((((((m0_VA_GND+m1_VA_GND)+m2_VA_GND)+m3_VA_GND)+m4_VA_GND)+m5_VA_GND)+m6_VA_GND)+m7_VA_GND));
532 In1_VD1_GND=((1-
NP(
EN))*m1_VD1_GND);
533 In1_VD2_GND=((1-
NP(
EN))*m2_VD2_GND);
534 In1_VD3_GND=((1-
NP(
EN))*m3_VD3_GND);
535 In1_VD4_GND=((1-
NP(
EN))*m4_VD4_GND);
536 In1_VD5_GND=((1-
NP(
EN))*m5_VD5_GND);
537 In1_VD6_GND=((1-
NP(
EN))*m6_VD6_GND);
538 In1_VD7_GND=((1-
NP(
EN))*m7_VD7_GND);
540 In1=((1-
NP(
EN))*(((((((m0+m1)+m2)+m3)+m4)+m5)+m6)+m7));
542 double m00_tanh(d00_tanh0,(TR*(In1-0.5)))
543 #if defined(_DERIVATE)
544 double m10_tanh(d10_tanh0,d00_tanh0,(TR*(In1-0.5)))
547 #if defined(_DERIVATE)
563 #if defined(_DERIVATE)
567 #if defined(_DERIVATE)
570 #if defined(_DYNAMIC)
572 #if defined(_DERIVATE)
577 #if defined(_DERIVATE)
581 #if defined(_DERIVATE)
600 for (
int i1 = 0; i1 < 15; i1++) {
602 for (
int i2 = 0; i2 < 15; i2++) {
603 setY (i1, i2, _jstat[i1][i2]);
637 matrix mux8to1::calcMatrixY (nr_double_t frequency)
643 for (
int i1 = 0; i1 < 15; i1++) {
644 for (
int i2 = 0; i2 < 15; i2++) {
645 y (i1,i2) =
rect (_jstat[i1][i2], _jdyna[i1][i2] * 2 *
M_PI * _freq);
679 int i1, i2, i3, i4, state;
682 for (i1 = 0; i1 < 15; i1++) {
683 for (i2 = 0; i2 < 15; i2++) {
684 state = 2 * (i2 + 15 * i1);
686 if (_charges[i1][i2] != 0.0)
691 for (i1 = 0; i1 < 15; i1++) {
692 state = 2 * (i1 + 15 * i1);
693 if (_charges[i1][i1] != 0.0)
698 for (i1 = 0; i1 < 15; i1++) {
699 for (i2 = 0; i2 < 15; i2++) {
701 for (i3 = 0; i3 < 15; i3++) {
702 for (i4 = 0; i4 < 15; i4++) {
704 if (_caps[i1][i2][i3][i4] != 0.0)
709 for (i1 = 0; i1 < 15; i1++) {
710 for (i2 = 0; i2 < 15; i2++) {
712 for (i3 = 0; i3 < 15; i3++) {
713 if (_caps[i1][i2][i3][i3] != 0.0)
718 for (i1 = 0; i1 < 15; i1++) {
719 for (i3 = 0; i3 < 15; i3++) {
720 for (i4 = 0; i4 < 15; i4++) {
722 if (_caps[i1][i1][i3][i4] != 0.0)
727 for (i1 = 0; i1 < 15; i1++) {
728 for (i3 = 0; i3 < 15; i3++) {
729 if (_caps[i1][i1][i3][i3] != 0.0)
735 matrix mux8to1::calcMatrixCy (nr_double_t frequency)
775 for (
int i1 = 0; i1 < 15; i1++) {
777 setCV (i1, _chs[i1]);
778 setGV (i1, _ghs[i1]);
779 for (
int i2 = 0; i2 < 15; i2++) {
780 setQV (i1, i2, _jdyna[i1][i2]);