16 #include "component.h"
42 #define NP(node) real (getV (node))
43 #define BP(pnode,nnode) (NP(pnode) - NP(nnode))
44 #define _load_static_residual2(pnode,nnode,current)\
45 _rhs[pnode] -= current;\
46 _rhs[nnode] += current;
47 #define _load_static_augmented_residual2(pnode,nnode,current)\
48 _rhs[pnode] -= current;\
49 _rhs[nnode] += current;
50 #define _load_static_residual1(node,current)\
51 _rhs[node] -= current;
52 #define _load_static_augmented_residual1(node,current)\
53 _rhs[node] -= current;
54 #define _load_static_jacobian4(pnode,nnode,vpnode,vnnode,conductance)\
55 _jstat[pnode][vpnode] += conductance;\
56 _jstat[nnode][vnnode] += conductance;\
57 _jstat[pnode][vnnode] -= conductance;\
58 _jstat[nnode][vpnode] -= conductance;\
60 _ghs[pnode] += conductance * BP(vpnode,vnnode);\
61 _ghs[nnode] -= conductance * BP(vpnode,vnnode);\
63 _rhs[pnode] += conductance * BP(vpnode,vnnode);\
64 _rhs[nnode] -= conductance * BP(vpnode,vnnode);\
66 #define _load_static_jacobian2p(node,vpnode,vnnode,conductance)\
67 _jstat[node][vpnode] += conductance;\
68 _jstat[node][vnnode] -= conductance;\
70 _ghs[node] += conductance * BP(vpnode,vnnode);\
72 _rhs[node] += conductance * BP(vpnode,vnnode);\
74 #define _load_static_jacobian2s(pnode,nnode,node,conductance)\
75 _jstat[pnode][node] += conductance;\
76 _jstat[nnode][node] -= conductance;\
78 _ghs[pnode] += conductance * NP(node);\
79 _ghs[nnode] -= conductance * NP(node);\
81 _rhs[pnode] += conductance * NP(node);\
82 _rhs[nnode] -= conductance * NP(node);\
84 #define _load_static_jacobian1(node,vnode,conductance)\
85 _jstat[node][vnode] += conductance;\
87 _ghs[node] += conductance * NP(vnode);\
89 _rhs[node] += conductance * NP(vnode);\
91 #define _load_dynamic_residual2(pnode,nnode,charge)\
92 if (doTR) _charges[pnode][nnode] += charge;\
94 _qhs[pnode] -= charge;\
95 _qhs[nnode] += charge;\
97 #define _load_dynamic_residual1(node,charge)\
98 if (doTR) _charges[node][node] += charge;\
100 _qhs[node] -= charge;\
102 #define _load_dynamic_jacobian4(pnode,nnode,vpnode,vnnode,capacitance)\
104 _jdyna[pnode][vpnode] += capacitance;\
105 _jdyna[nnode][vnnode] += capacitance;\
106 _jdyna[pnode][vnnode] -= capacitance;\
107 _jdyna[nnode][vpnode] -= capacitance;\
110 _caps[pnode][nnode][vpnode][vnnode] += capacitance;\
113 _chs[pnode] += capacitance * BP(vpnode,vnnode);\
114 _chs[nnode] -= capacitance * BP(vpnode,vnnode);\
116 #define _load_dynamic_jacobian2s(pnode,nnode,vnode,capacitance)\
118 _jdyna[pnode][vnode] += capacitance;\
119 _jdyna[nnode][vnode] -= capacitance;\
122 _caps[pnode][nnode][vnode][vnode] += capacitance;\
125 _chs[pnode] += capacitance * NP(vnode);\
126 _chs[nnode] -= capacitance * NP(vnode);\
128 #define _load_dynamic_jacobian2p(node,vpnode,vnnode,capacitance)\
130 _jdyna[node][vpnode] += capacitance;\
131 _jdyna[node][vnnode] -= capacitance;\
134 _caps[node][node][vpnode][vnnode] += capacitance;\
137 _chs[node] += capacitance * BP(vpnode,vnnode);\
139 #define _load_dynamic_jacobian1(node,vnode,capacitance)\
141 _jdyna[node][vnode] += capacitance;\
144 _caps[node][node][vnode][vnode] += capacitance;\
147 _chs[node] += capacitance * NP(vnode);\
150 #define _save_whitenoise1(n1,pwr,type)\
151 _white_pwr[n1][n1] += pwr;
152 #define _save_whitenoise2(n1,n2,pwr,type)\
153 _white_pwr[n1][n2] += pwr;
154 #define _save_flickernoise1(n1,pwr,exp,type)\
155 _flicker_pwr[n1][n1] += pwr;\
156 _flicker_exp[n1][n1] += exp;
157 #define _save_flickernoise2(n1,n2,pwr,exp,type)\
158 _flicker_pwr[n1][n2] += pwr;\
159 _flicker_exp[n1][n2] += exp;
160 #define _load_whitenoise2(n1,n2,pwr)\
161 cy (n1,n2) -= pwr/kB/T0; cy (n2,n1) -= pwr/kB/T0;\
162 cy (n1,n1) += pwr/kB/T0; cy (n2,n2) += pwr/kB/T0;
163 #define _load_whitenoise1(n1,pwr)\
164 cy (n1,n1) += pwr/kB/T0;
165 #define _load_flickernoise2(n1,n2,pwr,exp)\
166 cy (n1,n2) -= pwr*pow(_freq,-exp)/kB/T0;\
167 cy (n2,n1) -= pwr*pow(_freq,-exp)/kB/T0;\
168 cy (n1,n1) += pwr*pow(_freq,-exp)/kB/T0;\
169 cy (n2,n2) += pwr*pow(_freq,-exp)/kB/T0;
170 #define _load_flickernoise1(n1,pwr,exp)\
171 cy (n1,n1) += pwr*pow(_freq,-exp)/kB/T0;
174 #define m00_hypot(v00,x,y) v00 = xhypot(x,y);
175 #define m10_hypot(v10,v00,x,y) v10 = (x)/(v00);
176 #define m11_hypot(v11,v00,x,y) v11 = (y)/(v00);
177 #define m00_max(v00,x,y) v00 = ((x)>(y))?(x):(y);
178 #define m10_max(v10,v00,x,y) v10 = ((x)>(y))?1.0:0.0;
179 #define m11_max(v11,v00,x,y) v11 = ((x)>(y))?0.0:1.0;
180 #define m00_min(v00,x,y) v00 = ((x)<(y))?(x):(y);
181 #define m10_min(v10,v00,x,y) v10 = ((x)<(y))?1.0:0.0;
182 #define m11_min(v11,v00,x,y) v11 = ((x)<(y))?0.0:1.0;
183 #define m00_pow(v00,x,y) v00 = pow(x,y);
184 #define m10_pow(v10,v00,x,y) v10 = (x==0.0)?0.0:(v00)*(y)/(x);
185 #define m11_pow(v11,v00,x,y) v11 = (x==0.0)?0.0:(log(x)*(v00));
187 #define m00_div(v00,v10,x,y) double v10=1/(y); double v00=(x)*v10;
188 #define m10_div(v10,v00,vv,x,y)
189 #define m11_div(v11,v00,vv,x,y) double v11 = -v00*vv;
191 #define m00_mult(v00,v10,v11,x,y) double v10=(x); double v11=(y); double v00=v10*v11;
192 #define m00_add(v00,x,y) double v00=(x)+(y);
194 #define m00_cos(v00,x) v00 = cos(x);
195 #define m10_cos(v10,v00,x) v10 = (-sin(x));
196 #define m00_sin(v00,x) v00 = sin(x);
197 #define m10_sin(v10,v00,x) v10 = (cos(x));
198 #define m00_tan(v00,x) v00 = tan(x);
199 #define m10_tan(v10,v00,x) v10 = (1.0/cos(x)/cos(x));
200 #define m00_cosh(v00,x) v00 = cosh(x);
201 #define m10_cosh(v10,v00,x) v10 = (sinh(x));
202 #define m00_sinh(v00,x) v00 = sinh(x);
203 #define m10_sinh(v10,v00,x) v10 = (cosh(x));
204 #define m00_tanh(v00,x) v00 = tanh(x);
205 #define m10_tanh(v10,v00,x) v10 = (1.0/cosh(x)/cosh(x));
206 #define m00_acos(v00,x) v00 = acos(x);
207 #define m10_acos(v10,v00,x) v10 = (-1.0/sqrt(1-x*x));
208 #define m00_asin(v00,x) v00 = asin(x);
209 #define m10_asin(v10,v00,x) v10 = (+1.0/sqrt(1-x*x));
210 #define m00_atan(v00,x) v00 = atan(x);
211 #define m10_atan(v10,v00,x) v10 = (+1.0/(1+x*x));
212 #define m00_atanh(v00,x) v00 = atanh(x);
213 #define m10_atanh(v10,v00,x) v10 = (+1.0/(1-x*x));
214 #define m00_logE(v00,x) v00 = log(x);
215 #define m10_logE(v10,v00,x) v10 = (1.0/x);
216 #define m00_log10(v00,x) v00 = log10(x);
217 #define m10_log10(v10,v00,x) v10 = (1.0/x/M_LN10);
218 #define m00_sqrt(v00,x) v00 = sqrt(x);
219 #define m10_sqrt(v10,v00,x) v10 = (0.5/v00);
220 #define m00_fabs(v00,x) v00 = fabs(x);
221 #define m10_fabs(v10,v00,x) v10 = (((x)>=0)?(+1.0):(-1.0));
223 #define m00_exp(v00,x) v00 = exp(x);
224 #define m10_exp(v10,v00,x) v10 = v00;
226 #define m00_abs(v00) ((v00)<(0)?(-(v00)):(v00))
227 #define m00_floor(v00,x) v00 = floor(x);
228 #define m00_limexp(v00,x) v00 = ((x)<80.0?exp(x):exp(80.0)*(x-79.0));
229 #define m10_limexp(v10,v00,x) v10 = ((x)<80.0?(v00):exp(80.0));
231 #define m20_logE(v00) (-1.0/v00/v00)
232 #define m20_exp(v00) exp(v00)
233 #define m20_limexp(v00) ((v00)<80.0?exp(v00):0.0)
234 #define m20_sqrt(v00) (-0.25/(v00)/sqrt(v00))
235 #define m20_fabs(v00) 0.0
236 #define m20_pow(x,y) ((y)*((y)-1.0)*pow(x,y)/(x)/(x))
237 #define m00_vt(x) (kBoverQ*(x))
238 #define m10_vt(x) (kBoverQ)
241 #define _modelname "fa2b"
242 #define _instancename getName()
243 #define _circuit_temp (getPropertyDouble("Temp")+273.15)
244 #define _param_given(p) (isPropertyGiven(p)?1:0)
248 #define _vt_nom (kBoverQ*_circuit_temp)
250 using namespace device;
259 void fa2b::initModel (
void)
276 initializeInstance ();
297 void fa2b::initVerilog (
void)
304 for (i1 = 0; i1 < 14; i1++) {
305 for (i2 = 0; i2 < 14; i2++) {
306 _charges[i1][i2] = 0.0;
310 for (i1 = 0; i1 < 14; i1++) {
311 for (i2 = 0; i2 < 14; i2++) {
312 for (i3 = 0; i3 < 14; i3++) {
313 for (i4 = 0; i4 < 14; i4++) {
314 _caps[i1][i2][i3][i4] = 0.0;
318 for (i1 = 0; i1 < 14; i1++) {
323 for (i2 = 0; i2 < 14; i2++) {
324 _jstat[i1][i2] = 0.0;
325 _jdyna[i1][i2] = 0.0;
331 void fa2b::loadVariables (
void)
343 #define _DERIVATEFORDDX
346 void fa2b::initializeModel (
void)
348 #if defined(_DYNAMIC)
352 #if defined(_DYNAMIC)
353 Cd=((Delay*1.43)/Rd);
359 void fa2b::initializeInstance (
void)
364 void fa2b::initialStep (
void)
369 void fa2b::finalStep (
void)
374 void fa2b::calcVerilog (
void)
379 #if defined(_DERIVATE)
387 #if defined(_DERIVATE)
395 #if defined(_DERIVATE)
400 #if defined(_DERIVATE)
406 #if defined(_DERIVATE)
412 #if defined(_DERIVATE)
416 #if defined(_DERIVATE)
417 mS0a_VB_GND=(((1-
NP(
D)))+(-1.0)*
NP(
D));
418 mS0a_VD_GND=((
NP(
B)*(-1.0))+((1-
NP(
B))));
421 #if defined(_DERIVATE)
422 mS0_VCI_GND=(((1-mS0a))+(-1.0)*mS0a);
423 mS0_VB_GND=((
NP(
CI)*(-mS0a_VB_GND))+((1-
NP(
CI))*mS0a_VB_GND));
424 mS0_VD_GND=((
NP(
CI)*(-mS0a_VD_GND))+((1-
NP(
CI))*mS0a_VD_GND));
426 mS0=((
NP(
CI)*(1-mS0a))+((1-
NP(
CI))*mS0a));
427 #if defined(_DERIVATE)
428 mS1a_VB_GND=((
NP(
D))+(
NP(
CI)));
429 mS1a_VD_GND=((
NP(
B))+(
NP(
CI)));
430 mS1a_VCI_GND=((
NP(
B))+(
NP(
D)));
433 #if defined(_DERIVATE)
434 mS1b_VA_GND=(((1-
NP(
C)))+(-1.0)*
NP(
C));
435 mS1b_VC_GND=((
NP(
A)*(-1.0))+((1-
NP(
A))));
438 #if defined(_DERIVATE)
439 mS1_VB_GND=(mS1a_VB_GND*(1-mS1b)+(-mS1a_VB_GND)*mS1b);
440 mS1_VD_GND=(mS1a_VD_GND*(1-mS1b)+(-mS1a_VD_GND)*mS1b);
441 mS1_VCI_GND=(mS1a_VCI_GND*(1-mS1b)+(-mS1a_VCI_GND)*mS1b);
442 mS1_VA_GND=((mS1a*(-mS1b_VA_GND))+((1-mS1a)*mS1b_VA_GND));
443 mS1_VC_GND=((mS1a*(-mS1b_VC_GND))+((1-mS1a)*mS1b_VC_GND));
445 mS1=((mS1a*(1-mS1b))+((1-mS1a)*mS1b));
446 #if defined(_DERIVATE)
447 mCO_VA_GND=((
NP(
C))+(mS1a));
448 mCO_VC_GND=((
NP(
A))+(mS1a));
449 mCO_VB_GND=((
NP(
A)+
NP(
C))*mS1a_VB_GND);
450 mCO_VD_GND=((
NP(
A)+
NP(
C))*mS1a_VD_GND);
451 mCO_VCI_GND=((
NP(
A)+
NP(
C))*mS1a_VCI_GND);
457 #if defined(_DERIVATE)
466 #if defined(_DERIVATE)
476 #if defined(_DERIVATE)
487 #if defined(_DERIVATE)
499 #if defined(_DERIVATE)
510 #if defined(_DERIVATE)
520 double m00_tanh(d00_tanh0,(TR*(mS0-0.5)))
521 #if defined(_DERIVATE)
522 double m10_tanh(d10_tanh0,d00_tanh0,(TR*(mS0-0.5)))
525 #if defined(_DERIVATE)
532 #if defined(_DERIVATE)
536 #if defined(_DERIVATE)
539 #if defined(_DYNAMIC)
541 #if defined(_DERIVATE)
546 #if defined(_DERIVATE)
550 #if defined(_DERIVATE)
554 double m00_tanh(d00_tanh0,(TR*(mS1-0.5)))
555 #if defined(_DERIVATE)
556 double m10_tanh(d10_tanh0,d00_tanh0,(TR*(mS1-0.5)))
559 #if defined(_DERIVATE)
568 #if defined(_DERIVATE)
572 #if defined(_DERIVATE)
575 #if defined(_DYNAMIC)
577 #if defined(_DERIVATE)
582 #if defined(_DERIVATE)
586 #if defined(_DERIVATE)
590 double m00_tanh(d00_tanh0,(TR*(mCO-0.5)))
591 #if defined(_DERIVATE)
592 double m10_tanh(d10_tanh0,d00_tanh0,(TR*(mCO-0.5)))
595 #if defined(_DERIVATE)
604 #if defined(_DERIVATE)
608 #if defined(_DERIVATE)
611 #if defined(_DYNAMIC)
613 #if defined(_DERIVATE)
618 #if defined(_DERIVATE)
622 #if defined(_DERIVATE)
641 for (
int i1 = 0; i1 < 14; i1++) {
643 for (
int i2 = 0; i2 < 14; i2++) {
644 setY (i1, i2, _jstat[i1][i2]);
678 matrix fa2b::calcMatrixY (nr_double_t frequency)
684 for (
int i1 = 0; i1 < 14; i1++) {
685 for (
int i2 = 0; i2 < 14; i2++) {
686 y (i1,i2) =
rect (_jstat[i1][i2], _jdyna[i1][i2] * 2 *
M_PI * _freq);
720 int i1, i2, i3, i4, state;
723 for (i1 = 0; i1 < 14; i1++) {
724 for (i2 = 0; i2 < 14; i2++) {
725 state = 2 * (i2 + 14 * i1);
727 if (_charges[i1][i2] != 0.0)
732 for (i1 = 0; i1 < 14; i1++) {
733 state = 2 * (i1 + 14 * i1);
734 if (_charges[i1][i1] != 0.0)
739 for (i1 = 0; i1 < 14; i1++) {
740 for (i2 = 0; i2 < 14; i2++) {
742 for (i3 = 0; i3 < 14; i3++) {
743 for (i4 = 0; i4 < 14; i4++) {
745 if (_caps[i1][i2][i3][i4] != 0.0)
750 for (i1 = 0; i1 < 14; i1++) {
751 for (i2 = 0; i2 < 14; i2++) {
753 for (i3 = 0; i3 < 14; i3++) {
754 if (_caps[i1][i2][i3][i3] != 0.0)
759 for (i1 = 0; i1 < 14; i1++) {
760 for (i3 = 0; i3 < 14; i3++) {
761 for (i4 = 0; i4 < 14; i4++) {
763 if (_caps[i1][i1][i3][i4] != 0.0)
768 for (i1 = 0; i1 < 14; i1++) {
769 for (i3 = 0; i3 < 14; i3++) {
770 if (_caps[i1][i1][i3][i3] != 0.0)
776 matrix fa2b::calcMatrixCy (nr_double_t frequency)
816 for (
int i1 = 0; i1 < 14; i1++) {
818 setCV (i1, _chs[i1]);
819 setGV (i1, _ghs[i1]);
820 for (
int i2 = 0; i2 < 14; i2++) {
821 setQV (i1, i2, _jdyna[i1][i2]);