16 #include "component.h"
21 #define CIR_comp_1bit -1
39 #define NP(node) real (getV (node))
40 #define BP(pnode,nnode) (NP(pnode) - NP(nnode))
41 #define _load_static_residual2(pnode,nnode,current)\
42 _rhs[pnode] -= current;\
43 _rhs[nnode] += current;
44 #define _load_static_augmented_residual2(pnode,nnode,current)\
45 _rhs[pnode] -= current;\
46 _rhs[nnode] += current;
47 #define _load_static_residual1(node,current)\
48 _rhs[node] -= current;
49 #define _load_static_augmented_residual1(node,current)\
50 _rhs[node] -= current;
51 #define _load_static_jacobian4(pnode,nnode,vpnode,vnnode,conductance)\
52 _jstat[pnode][vpnode] += conductance;\
53 _jstat[nnode][vnnode] += conductance;\
54 _jstat[pnode][vnnode] -= conductance;\
55 _jstat[nnode][vpnode] -= conductance;\
57 _ghs[pnode] += conductance * BP(vpnode,vnnode);\
58 _ghs[nnode] -= conductance * BP(vpnode,vnnode);\
60 _rhs[pnode] += conductance * BP(vpnode,vnnode);\
61 _rhs[nnode] -= conductance * BP(vpnode,vnnode);\
63 #define _load_static_jacobian2p(node,vpnode,vnnode,conductance)\
64 _jstat[node][vpnode] += conductance;\
65 _jstat[node][vnnode] -= conductance;\
67 _ghs[node] += conductance * BP(vpnode,vnnode);\
69 _rhs[node] += conductance * BP(vpnode,vnnode);\
71 #define _load_static_jacobian2s(pnode,nnode,node,conductance)\
72 _jstat[pnode][node] += conductance;\
73 _jstat[nnode][node] -= conductance;\
75 _ghs[pnode] += conductance * NP(node);\
76 _ghs[nnode] -= conductance * NP(node);\
78 _rhs[pnode] += conductance * NP(node);\
79 _rhs[nnode] -= conductance * NP(node);\
81 #define _load_static_jacobian1(node,vnode,conductance)\
82 _jstat[node][vnode] += conductance;\
84 _ghs[node] += conductance * NP(vnode);\
86 _rhs[node] += conductance * NP(vnode);\
88 #define _load_dynamic_residual2(pnode,nnode,charge)\
89 if (doTR) _charges[pnode][nnode] += charge;\
91 _qhs[pnode] -= charge;\
92 _qhs[nnode] += charge;\
94 #define _load_dynamic_residual1(node,charge)\
95 if (doTR) _charges[node][node] += charge;\
97 _qhs[node] -= charge;\
99 #define _load_dynamic_jacobian4(pnode,nnode,vpnode,vnnode,capacitance)\
101 _jdyna[pnode][vpnode] += capacitance;\
102 _jdyna[nnode][vnnode] += capacitance;\
103 _jdyna[pnode][vnnode] -= capacitance;\
104 _jdyna[nnode][vpnode] -= capacitance;\
107 _caps[pnode][nnode][vpnode][vnnode] += capacitance;\
110 _chs[pnode] += capacitance * BP(vpnode,vnnode);\
111 _chs[nnode] -= capacitance * BP(vpnode,vnnode);\
113 #define _load_dynamic_jacobian2s(pnode,nnode,vnode,capacitance)\
115 _jdyna[pnode][vnode] += capacitance;\
116 _jdyna[nnode][vnode] -= capacitance;\
119 _caps[pnode][nnode][vnode][vnode] += capacitance;\
122 _chs[pnode] += capacitance * NP(vnode);\
123 _chs[nnode] -= capacitance * NP(vnode);\
125 #define _load_dynamic_jacobian2p(node,vpnode,vnnode,capacitance)\
127 _jdyna[node][vpnode] += capacitance;\
128 _jdyna[node][vnnode] -= capacitance;\
131 _caps[node][node][vpnode][vnnode] += capacitance;\
134 _chs[node] += capacitance * BP(vpnode,vnnode);\
136 #define _load_dynamic_jacobian1(node,vnode,capacitance)\
138 _jdyna[node][vnode] += capacitance;\
141 _caps[node][node][vnode][vnode] += capacitance;\
144 _chs[node] += capacitance * NP(vnode);\
147 #define _save_whitenoise1(n1,pwr,type)\
148 _white_pwr[n1][n1] += pwr;
149 #define _save_whitenoise2(n1,n2,pwr,type)\
150 _white_pwr[n1][n2] += pwr;
151 #define _save_flickernoise1(n1,pwr,exp,type)\
152 _flicker_pwr[n1][n1] += pwr;\
153 _flicker_exp[n1][n1] += exp;
154 #define _save_flickernoise2(n1,n2,pwr,exp,type)\
155 _flicker_pwr[n1][n2] += pwr;\
156 _flicker_exp[n1][n2] += exp;
157 #define _load_whitenoise2(n1,n2,pwr)\
158 cy (n1,n2) -= pwr/kB/T0; cy (n2,n1) -= pwr/kB/T0;\
159 cy (n1,n1) += pwr/kB/T0; cy (n2,n2) += pwr/kB/T0;
160 #define _load_whitenoise1(n1,pwr)\
161 cy (n1,n1) += pwr/kB/T0;
162 #define _load_flickernoise2(n1,n2,pwr,exp)\
163 cy (n1,n2) -= pwr*pow(_freq,-exp)/kB/T0;\
164 cy (n2,n1) -= pwr*pow(_freq,-exp)/kB/T0;\
165 cy (n1,n1) += pwr*pow(_freq,-exp)/kB/T0;\
166 cy (n2,n2) += pwr*pow(_freq,-exp)/kB/T0;
167 #define _load_flickernoise1(n1,pwr,exp)\
168 cy (n1,n1) += pwr*pow(_freq,-exp)/kB/T0;
171 #define m00_hypot(v00,x,y) v00 = xhypot(x,y);
172 #define m10_hypot(v10,v00,x,y) v10 = (x)/(v00);
173 #define m11_hypot(v11,v00,x,y) v11 = (y)/(v00);
174 #define m00_max(v00,x,y) v00 = ((x)>(y))?(x):(y);
175 #define m10_max(v10,v00,x,y) v10 = ((x)>(y))?1.0:0.0;
176 #define m11_max(v11,v00,x,y) v11 = ((x)>(y))?0.0:1.0;
177 #define m00_min(v00,x,y) v00 = ((x)<(y))?(x):(y);
178 #define m10_min(v10,v00,x,y) v10 = ((x)<(y))?1.0:0.0;
179 #define m11_min(v11,v00,x,y) v11 = ((x)<(y))?0.0:1.0;
180 #define m00_pow(v00,x,y) v00 = pow(x,y);
181 #define m10_pow(v10,v00,x,y) v10 = (x==0.0)?0.0:(v00)*(y)/(x);
182 #define m11_pow(v11,v00,x,y) v11 = (x==0.0)?0.0:(log(x)*(v00));
184 #define m00_div(v00,v10,x,y) double v10=1/(y); double v00=(x)*v10;
185 #define m10_div(v10,v00,vv,x,y)
186 #define m11_div(v11,v00,vv,x,y) double v11 = -v00*vv;
188 #define m00_mult(v00,v10,v11,x,y) double v10=(x); double v11=(y); double v00=v10*v11;
189 #define m00_add(v00,x,y) double v00=(x)+(y);
191 #define m00_cos(v00,x) v00 = cos(x);
192 #define m10_cos(v10,v00,x) v10 = (-sin(x));
193 #define m00_sin(v00,x) v00 = sin(x);
194 #define m10_sin(v10,v00,x) v10 = (cos(x));
195 #define m00_tan(v00,x) v00 = tan(x);
196 #define m10_tan(v10,v00,x) v10 = (1.0/cos(x)/cos(x));
197 #define m00_cosh(v00,x) v00 = cosh(x);
198 #define m10_cosh(v10,v00,x) v10 = (sinh(x));
199 #define m00_sinh(v00,x) v00 = sinh(x);
200 #define m10_sinh(v10,v00,x) v10 = (cosh(x));
201 #define m00_tanh(v00,x) v00 = tanh(x);
202 #define m10_tanh(v10,v00,x) v10 = (1.0/cosh(x)/cosh(x));
203 #define m00_acos(v00,x) v00 = acos(x);
204 #define m10_acos(v10,v00,x) v10 = (-1.0/sqrt(1-x*x));
205 #define m00_asin(v00,x) v00 = asin(x);
206 #define m10_asin(v10,v00,x) v10 = (+1.0/sqrt(1-x*x));
207 #define m00_atan(v00,x) v00 = atan(x);
208 #define m10_atan(v10,v00,x) v10 = (+1.0/(1+x*x));
209 #define m00_atanh(v00,x) v00 = atanh(x);
210 #define m10_atanh(v10,v00,x) v10 = (+1.0/(1-x*x));
211 #define m00_logE(v00,x) v00 = log(x);
212 #define m10_logE(v10,v00,x) v10 = (1.0/x);
213 #define m00_log10(v00,x) v00 = log10(x);
214 #define m10_log10(v10,v00,x) v10 = (1.0/x/M_LN10);
215 #define m00_sqrt(v00,x) v00 = sqrt(x);
216 #define m10_sqrt(v10,v00,x) v10 = (0.5/v00);
217 #define m00_fabs(v00,x) v00 = fabs(x);
218 #define m10_fabs(v10,v00,x) v10 = (((x)>=0)?(+1.0):(-1.0));
220 #define m00_exp(v00,x) v00 = exp(x);
221 #define m10_exp(v10,v00,x) v10 = v00;
223 #define m00_abs(v00) ((v00)<(0)?(-(v00)):(v00))
224 #define m00_floor(v00,x) v00 = floor(x);
225 #define m00_limexp(v00,x) v00 = ((x)<80.0?exp(x):exp(80.0)*(x-79.0));
226 #define m10_limexp(v10,v00,x) v10 = ((x)<80.0?(v00):exp(80.0));
228 #define m20_logE(v00) (-1.0/v00/v00)
229 #define m20_exp(v00) exp(v00)
230 #define m20_limexp(v00) ((v00)<80.0?exp(v00):0.0)
231 #define m20_sqrt(v00) (-0.25/(v00)/sqrt(v00))
232 #define m20_fabs(v00) 0.0
233 #define m20_pow(x,y) ((y)*((y)-1.0)*pow(x,y)/(x)/(x))
234 #define m00_vt(x) (kBoverQ*(x))
235 #define m10_vt(x) (kBoverQ)
238 #define _modelname "comp_1bit"
239 #define _instancename getName()
240 #define _circuit_temp (getPropertyDouble("Temp")+273.15)
241 #define _param_given(p) (isPropertyGiven(p)?1:0)
245 #define _vt_nom (kBoverQ*_circuit_temp)
247 using namespace device;
256 void comp_1bit::initModel (
void)
273 initializeInstance ();
294 void comp_1bit::initVerilog (
void)
301 for (i1 = 0; i1 < 11; i1++) {
302 for (i2 = 0; i2 < 11; i2++) {
303 _charges[i1][i2] = 0.0;
307 for (i1 = 0; i1 < 11; i1++) {
308 for (i2 = 0; i2 < 11; i2++) {
309 for (i3 = 0; i3 < 11; i3++) {
310 for (i4 = 0; i4 < 11; i4++) {
311 _caps[i1][i2][i3][i4] = 0.0;
315 for (i1 = 0; i1 < 11; i1++) {
320 for (i2 = 0; i2 < 11; i2++) {
321 _jstat[i1][i2] = 0.0;
322 _jdyna[i1][i2] = 0.0;
328 void comp_1bit::loadVariables (
void)
340 #define _DERIVATEFORDDX
343 void comp_1bit::initializeModel (
void)
345 #if defined(_DYNAMIC)
349 #if defined(_DYNAMIC)
350 Cd=((Delay*1.43)/Rd);
356 void comp_1bit::initializeInstance (
void)
361 void comp_1bit::initialStep (
void)
366 void comp_1bit::finalStep (
void)
371 void comp_1bit::calcVerilog (
void)
376 #if defined(_DERIVATE)
381 #if defined(_DERIVATE)
386 #if defined(_DERIVATE)
390 #if defined(_DERIVATE)
391 mE_VX_GND=(-(((1-
NP(
Y)))+(-1.0)*
NP(
Y)));
392 mE_VY_GND=(-((
NP(
X)*(-1.0))+((1-
NP(
X)))));
395 #if defined(_DERIVATE)
396 mG_VX_GND=((1-
NP(
Y)));
397 mG_VY_GND=(
NP(
X)*(-1.0));
400 #if defined(_DERIVATE)
401 mL_VX_GND=(-1.0)*
NP(
Y);
402 mL_VY_GND=((1-
NP(
X)));
406 double m00_tanh(d00_tanh0,(TR*(mE-0.5)))
407 #if defined(_DERIVATE)
408 double m10_tanh(d10_tanh0,d00_tanh0,(TR*(mE-0.5)))
411 #if defined(_DERIVATE)
417 #if defined(_DERIVATE)
421 #if defined(_DERIVATE)
424 #if defined(_DYNAMIC)
426 #if defined(_DERIVATE)
431 #if defined(_DERIVATE)
435 #if defined(_DERIVATE)
439 double m00_tanh(d00_tanh0,(TR*(mG-0.5)))
440 #if defined(_DERIVATE)
441 double m10_tanh(d10_tanh0,d00_tanh0,(TR*(mG-0.5)))
444 #if defined(_DERIVATE)
450 #if defined(_DERIVATE)
454 #if defined(_DERIVATE)
457 #if defined(_DYNAMIC)
459 #if defined(_DERIVATE)
464 #if defined(_DERIVATE)
468 #if defined(_DERIVATE)
472 double m00_tanh(d00_tanh0,(TR*(mL-0.5)))
473 #if defined(_DERIVATE)
474 double m10_tanh(d10_tanh0,d00_tanh0,(TR*(mL-0.5)))
477 #if defined(_DERIVATE)
483 #if defined(_DERIVATE)
487 #if defined(_DERIVATE)
490 #if defined(_DYNAMIC)
492 #if defined(_DERIVATE)
497 #if defined(_DERIVATE)
501 #if defined(_DERIVATE)
520 for (
int i1 = 0; i1 < 11; i1++) {
522 for (
int i2 = 0; i2 < 11; i2++) {
523 setY (i1, i2, _jstat[i1][i2]);
557 matrix comp_1bit::calcMatrixY (nr_double_t frequency)
563 for (
int i1 = 0; i1 < 11; i1++) {
564 for (
int i2 = 0; i2 < 11; i2++) {
565 y (i1,i2) =
rect (_jstat[i1][i2], _jdyna[i1][i2] * 2 *
M_PI * _freq);
599 int i1, i2, i3, i4, state;
602 for (i1 = 0; i1 < 11; i1++) {
603 for (i2 = 0; i2 < 11; i2++) {
604 state = 2 * (i2 + 11 * i1);
606 if (_charges[i1][i2] != 0.0)
611 for (i1 = 0; i1 < 11; i1++) {
612 state = 2 * (i1 + 11 * i1);
613 if (_charges[i1][i1] != 0.0)
618 for (i1 = 0; i1 < 11; i1++) {
619 for (i2 = 0; i2 < 11; i2++) {
621 for (i3 = 0; i3 < 11; i3++) {
622 for (i4 = 0; i4 < 11; i4++) {
624 if (_caps[i1][i2][i3][i4] != 0.0)
629 for (i1 = 0; i1 < 11; i1++) {
630 for (i2 = 0; i2 < 11; i2++) {
632 for (i3 = 0; i3 < 11; i3++) {
633 if (_caps[i1][i2][i3][i3] != 0.0)
638 for (i1 = 0; i1 < 11; i1++) {
639 for (i3 = 0; i3 < 11; i3++) {
640 for (i4 = 0; i4 < 11; i4++) {
642 if (_caps[i1][i1][i3][i4] != 0.0)
647 for (i1 = 0; i1 < 11; i1++) {
648 for (i3 = 0; i3 < 11; i3++) {
649 if (_caps[i1][i1][i3][i3] != 0.0)
655 matrix comp_1bit::calcMatrixCy (nr_double_t frequency)
695 for (
int i1 = 0; i1 < 11; i1++) {
697 setCV (i1, _chs[i1]);
698 setGV (i1, _ghs[i1]);
699 for (
int i2 = 0; i2 < 11; i2++) {
700 setQV (i1, i2, _jdyna[i1][i2]);