16 #include "component.h"
21 #define CIR_mux4to1 -1
38 #define NP(node) real (getV (node))
39 #define BP(pnode,nnode) (NP(pnode) - NP(nnode))
40 #define _load_static_residual2(pnode,nnode,current)\
41 _rhs[pnode] -= current;\
42 _rhs[nnode] += current;
43 #define _load_static_augmented_residual2(pnode,nnode,current)\
44 _rhs[pnode] -= current;\
45 _rhs[nnode] += current;
46 #define _load_static_residual1(node,current)\
47 _rhs[node] -= current;
48 #define _load_static_augmented_residual1(node,current)\
49 _rhs[node] -= current;
50 #define _load_static_jacobian4(pnode,nnode,vpnode,vnnode,conductance)\
51 _jstat[pnode][vpnode] += conductance;\
52 _jstat[nnode][vnnode] += conductance;\
53 _jstat[pnode][vnnode] -= conductance;\
54 _jstat[nnode][vpnode] -= conductance;\
56 _ghs[pnode] += conductance * BP(vpnode,vnnode);\
57 _ghs[nnode] -= conductance * BP(vpnode,vnnode);\
59 _rhs[pnode] += conductance * BP(vpnode,vnnode);\
60 _rhs[nnode] -= conductance * BP(vpnode,vnnode);\
62 #define _load_static_jacobian2p(node,vpnode,vnnode,conductance)\
63 _jstat[node][vpnode] += conductance;\
64 _jstat[node][vnnode] -= conductance;\
66 _ghs[node] += conductance * BP(vpnode,vnnode);\
68 _rhs[node] += conductance * BP(vpnode,vnnode);\
70 #define _load_static_jacobian2s(pnode,nnode,node,conductance)\
71 _jstat[pnode][node] += conductance;\
72 _jstat[nnode][node] -= conductance;\
74 _ghs[pnode] += conductance * NP(node);\
75 _ghs[nnode] -= conductance * NP(node);\
77 _rhs[pnode] += conductance * NP(node);\
78 _rhs[nnode] -= conductance * NP(node);\
80 #define _load_static_jacobian1(node,vnode,conductance)\
81 _jstat[node][vnode] += conductance;\
83 _ghs[node] += conductance * NP(vnode);\
85 _rhs[node] += conductance * NP(vnode);\
87 #define _load_dynamic_residual2(pnode,nnode,charge)\
88 if (doTR) _charges[pnode][nnode] += charge;\
90 _qhs[pnode] -= charge;\
91 _qhs[nnode] += charge;\
93 #define _load_dynamic_residual1(node,charge)\
94 if (doTR) _charges[node][node] += charge;\
96 _qhs[node] -= charge;\
98 #define _load_dynamic_jacobian4(pnode,nnode,vpnode,vnnode,capacitance)\
100 _jdyna[pnode][vpnode] += capacitance;\
101 _jdyna[nnode][vnnode] += capacitance;\
102 _jdyna[pnode][vnnode] -= capacitance;\
103 _jdyna[nnode][vpnode] -= capacitance;\
106 _caps[pnode][nnode][vpnode][vnnode] += capacitance;\
109 _chs[pnode] += capacitance * BP(vpnode,vnnode);\
110 _chs[nnode] -= capacitance * BP(vpnode,vnnode);\
112 #define _load_dynamic_jacobian2s(pnode,nnode,vnode,capacitance)\
114 _jdyna[pnode][vnode] += capacitance;\
115 _jdyna[nnode][vnode] -= capacitance;\
118 _caps[pnode][nnode][vnode][vnode] += capacitance;\
121 _chs[pnode] += capacitance * NP(vnode);\
122 _chs[nnode] -= capacitance * NP(vnode);\
124 #define _load_dynamic_jacobian2p(node,vpnode,vnnode,capacitance)\
126 _jdyna[node][vpnode] += capacitance;\
127 _jdyna[node][vnnode] -= capacitance;\
130 _caps[node][node][vpnode][vnnode] += capacitance;\
133 _chs[node] += capacitance * BP(vpnode,vnnode);\
135 #define _load_dynamic_jacobian1(node,vnode,capacitance)\
137 _jdyna[node][vnode] += capacitance;\
140 _caps[node][node][vnode][vnode] += capacitance;\
143 _chs[node] += capacitance * NP(vnode);\
146 #define _save_whitenoise1(n1,pwr,type)\
147 _white_pwr[n1][n1] += pwr;
148 #define _save_whitenoise2(n1,n2,pwr,type)\
149 _white_pwr[n1][n2] += pwr;
150 #define _save_flickernoise1(n1,pwr,exp,type)\
151 _flicker_pwr[n1][n1] += pwr;\
152 _flicker_exp[n1][n1] += exp;
153 #define _save_flickernoise2(n1,n2,pwr,exp,type)\
154 _flicker_pwr[n1][n2] += pwr;\
155 _flicker_exp[n1][n2] += exp;
156 #define _load_whitenoise2(n1,n2,pwr)\
157 cy (n1,n2) -= pwr/kB/T0; cy (n2,n1) -= pwr/kB/T0;\
158 cy (n1,n1) += pwr/kB/T0; cy (n2,n2) += pwr/kB/T0;
159 #define _load_whitenoise1(n1,pwr)\
160 cy (n1,n1) += pwr/kB/T0;
161 #define _load_flickernoise2(n1,n2,pwr,exp)\
162 cy (n1,n2) -= pwr*pow(_freq,-exp)/kB/T0;\
163 cy (n2,n1) -= pwr*pow(_freq,-exp)/kB/T0;\
164 cy (n1,n1) += pwr*pow(_freq,-exp)/kB/T0;\
165 cy (n2,n2) += pwr*pow(_freq,-exp)/kB/T0;
166 #define _load_flickernoise1(n1,pwr,exp)\
167 cy (n1,n1) += pwr*pow(_freq,-exp)/kB/T0;
170 #define m00_hypot(v00,x,y) v00 = xhypot(x,y);
171 #define m10_hypot(v10,v00,x,y) v10 = (x)/(v00);
172 #define m11_hypot(v11,v00,x,y) v11 = (y)/(v00);
173 #define m00_max(v00,x,y) v00 = ((x)>(y))?(x):(y);
174 #define m10_max(v10,v00,x,y) v10 = ((x)>(y))?1.0:0.0;
175 #define m11_max(v11,v00,x,y) v11 = ((x)>(y))?0.0:1.0;
176 #define m00_min(v00,x,y) v00 = ((x)<(y))?(x):(y);
177 #define m10_min(v10,v00,x,y) v10 = ((x)<(y))?1.0:0.0;
178 #define m11_min(v11,v00,x,y) v11 = ((x)<(y))?0.0:1.0;
179 #define m00_pow(v00,x,y) v00 = pow(x,y);
180 #define m10_pow(v10,v00,x,y) v10 = (x==0.0)?0.0:(v00)*(y)/(x);
181 #define m11_pow(v11,v00,x,y) v11 = (x==0.0)?0.0:(log(x)*(v00));
183 #define m00_div(v00,v10,x,y) double v10=1/(y); double v00=(x)*v10;
184 #define m10_div(v10,v00,vv,x,y)
185 #define m11_div(v11,v00,vv,x,y) double v11 = -v00*vv;
187 #define m00_mult(v00,v10,v11,x,y) double v10=(x); double v11=(y); double v00=v10*v11;
188 #define m00_add(v00,x,y) double v00=(x)+(y);
190 #define m00_cos(v00,x) v00 = cos(x);
191 #define m10_cos(v10,v00,x) v10 = (-sin(x));
192 #define m00_sin(v00,x) v00 = sin(x);
193 #define m10_sin(v10,v00,x) v10 = (cos(x));
194 #define m00_tan(v00,x) v00 = tan(x);
195 #define m10_tan(v10,v00,x) v10 = (1.0/cos(x)/cos(x));
196 #define m00_cosh(v00,x) v00 = cosh(x);
197 #define m10_cosh(v10,v00,x) v10 = (sinh(x));
198 #define m00_sinh(v00,x) v00 = sinh(x);
199 #define m10_sinh(v10,v00,x) v10 = (cosh(x));
200 #define m00_tanh(v00,x) v00 = tanh(x);
201 #define m10_tanh(v10,v00,x) v10 = (1.0/cosh(x)/cosh(x));
202 #define m00_acos(v00,x) v00 = acos(x);
203 #define m10_acos(v10,v00,x) v10 = (-1.0/sqrt(1-x*x));
204 #define m00_asin(v00,x) v00 = asin(x);
205 #define m10_asin(v10,v00,x) v10 = (+1.0/sqrt(1-x*x));
206 #define m00_atan(v00,x) v00 = atan(x);
207 #define m10_atan(v10,v00,x) v10 = (+1.0/(1+x*x));
208 #define m00_atanh(v00,x) v00 = atanh(x);
209 #define m10_atanh(v10,v00,x) v10 = (+1.0/(1-x*x));
210 #define m00_logE(v00,x) v00 = log(x);
211 #define m10_logE(v10,v00,x) v10 = (1.0/x);
212 #define m00_log10(v00,x) v00 = log10(x);
213 #define m10_log10(v10,v00,x) v10 = (1.0/x/M_LN10);
214 #define m00_sqrt(v00,x) v00 = sqrt(x);
215 #define m10_sqrt(v10,v00,x) v10 = (0.5/v00);
216 #define m00_fabs(v00,x) v00 = fabs(x);
217 #define m10_fabs(v10,v00,x) v10 = (((x)>=0)?(+1.0):(-1.0));
219 #define m00_exp(v00,x) v00 = exp(x);
220 #define m10_exp(v10,v00,x) v10 = v00;
222 #define m00_abs(v00) ((v00)<(0)?(-(v00)):(v00))
223 #define m00_floor(v00,x) v00 = floor(x);
224 #define m00_limexp(v00,x) v00 = ((x)<80.0?exp(x):exp(80.0)*(x-79.0));
225 #define m10_limexp(v10,v00,x) v10 = ((x)<80.0?(v00):exp(80.0));
227 #define m20_logE(v00) (-1.0/v00/v00)
228 #define m20_exp(v00) exp(v00)
229 #define m20_limexp(v00) ((v00)<80.0?exp(v00):0.0)
230 #define m20_sqrt(v00) (-0.25/(v00)/sqrt(v00))
231 #define m20_fabs(v00) 0.0
232 #define m20_pow(x,y) ((y)*((y)-1.0)*pow(x,y)/(x)/(x))
233 #define m00_vt(x) (kBoverQ*(x))
234 #define m10_vt(x) (kBoverQ)
237 #define _modelname "mux4to1"
238 #define _instancename getName()
239 #define _circuit_temp (getPropertyDouble("Temp")+273.15)
240 #define _param_given(p) (isPropertyGiven(p)?1:0)
244 #define _vt_nom (kBoverQ*_circuit_temp)
246 using namespace device;
255 void mux4to1::initModel (
void)
268 initializeInstance ();
289 void mux4to1::initVerilog (
void)
296 for (i1 = 0; i1 < 10; i1++) {
297 for (i2 = 0; i2 < 10; i2++) {
298 _charges[i1][i2] = 0.0;
302 for (i1 = 0; i1 < 10; i1++) {
303 for (i2 = 0; i2 < 10; i2++) {
304 for (i3 = 0; i3 < 10; i3++) {
305 for (i4 = 0; i4 < 10; i4++) {
306 _caps[i1][i2][i3][i4] = 0.0;
310 for (i1 = 0; i1 < 10; i1++) {
315 for (i2 = 0; i2 < 10; i2++) {
316 _jstat[i1][i2] = 0.0;
317 _jdyna[i1][i2] = 0.0;
323 void mux4to1::loadVariables (
void)
335 #define _DERIVATEFORDDX
338 void mux4to1::initializeModel (
void)
340 #if defined(_DYNAMIC)
344 #if defined(_DYNAMIC)
345 Ccc=((Delay*1.43)/Rd);
351 void mux4to1::initializeInstance (
void)
356 void mux4to1::initialStep (
void)
361 void mux4to1::finalStep (
void)
366 void mux4to1::calcVerilog (
void)
371 #if defined(_DERIVATE)
381 #if defined(_DERIVATE)
385 #if defined(_DERIVATE)
388 #if defined(_DERIVATE)
392 #if defined(_DERIVATE)
396 #if defined(_DERIVATE)
401 In1_VD2_GND=((1-
NP(
EN))*(
NP(
B))*VAI);
402 In1_VD1_GND=((1-
NP(
EN))*(VBI)*
NP(
A));
403 In1_VD0_GND=((1-
NP(
EN))*(VBI)*VAI);
407 double m00_tanh(d00_tanh0,(TR*(In1-0.5)))
408 #if defined(_DERIVATE)
409 double m10_tanh(d10_tanh0,d00_tanh0,(TR*(In1-0.5)))
412 #if defined(_DERIVATE)
423 #if defined(_DERIVATE)
427 #if defined(_DERIVATE)
430 #if defined(_DYNAMIC)
432 #if defined(_DERIVATE)
437 #if defined(_DERIVATE)
441 #if defined(_DERIVATE)
460 for (
int i1 = 0; i1 < 10; i1++) {
462 for (
int i2 = 0; i2 < 10; i2++) {
463 setY (i1, i2, _jstat[i1][i2]);
497 matrix mux4to1::calcMatrixY (nr_double_t frequency)
503 for (
int i1 = 0; i1 < 10; i1++) {
504 for (
int i2 = 0; i2 < 10; i2++) {
505 y (i1,i2) =
rect (_jstat[i1][i2], _jdyna[i1][i2] * 2 *
M_PI * _freq);
539 int i1, i2, i3, i4, state;
542 for (i1 = 0; i1 < 10; i1++) {
543 for (i2 = 0; i2 < 10; i2++) {
544 state = 2 * (i2 + 10 * i1);
546 if (_charges[i1][i2] != 0.0)
551 for (i1 = 0; i1 < 10; i1++) {
552 state = 2 * (i1 + 10 * i1);
553 if (_charges[i1][i1] != 0.0)
558 for (i1 = 0; i1 < 10; i1++) {
559 for (i2 = 0; i2 < 10; i2++) {
561 for (i3 = 0; i3 < 10; i3++) {
562 for (i4 = 0; i4 < 10; i4++) {
564 if (_caps[i1][i2][i3][i4] != 0.0)
569 for (i1 = 0; i1 < 10; i1++) {
570 for (i2 = 0; i2 < 10; i2++) {
572 for (i3 = 0; i3 < 10; i3++) {
573 if (_caps[i1][i2][i3][i3] != 0.0)
578 for (i1 = 0; i1 < 10; i1++) {
579 for (i3 = 0; i3 < 10; i3++) {
580 for (i4 = 0; i4 < 10; i4++) {
582 if (_caps[i1][i1][i3][i4] != 0.0)
587 for (i1 = 0; i1 < 10; i1++) {
588 for (i3 = 0; i3 < 10; i3++) {
589 if (_caps[i1][i1][i3][i3] != 0.0)
595 matrix mux4to1::calcMatrixCy (nr_double_t frequency)
635 for (
int i1 = 0; i1 < 10; i1++) {
637 setCV (i1, _chs[i1]);
638 setGV (i1, _ghs[i1]);
639 for (
int i2 = 0; i2 < 10; i2++) {
640 setQV (i1, i2, _jdyna[i1][i2]);