16 #include "component.h"
37 #define NP(node) real (getV (node))
38 #define BP(pnode,nnode) (NP(pnode) - NP(nnode))
39 #define _load_static_residual2(pnode,nnode,current)\
40 _rhs[pnode] -= current;\
41 _rhs[nnode] += current;
42 #define _load_static_augmented_residual2(pnode,nnode,current)\
43 _rhs[pnode] -= current;\
44 _rhs[nnode] += current;
45 #define _load_static_residual1(node,current)\
46 _rhs[node] -= current;
47 #define _load_static_augmented_residual1(node,current)\
48 _rhs[node] -= current;
49 #define _load_static_jacobian4(pnode,nnode,vpnode,vnnode,conductance)\
50 _jstat[pnode][vpnode] += conductance;\
51 _jstat[nnode][vnnode] += conductance;\
52 _jstat[pnode][vnnode] -= conductance;\
53 _jstat[nnode][vpnode] -= conductance;\
55 _ghs[pnode] += conductance * BP(vpnode,vnnode);\
56 _ghs[nnode] -= conductance * BP(vpnode,vnnode);\
58 _rhs[pnode] += conductance * BP(vpnode,vnnode);\
59 _rhs[nnode] -= conductance * BP(vpnode,vnnode);\
61 #define _load_static_jacobian2p(node,vpnode,vnnode,conductance)\
62 _jstat[node][vpnode] += conductance;\
63 _jstat[node][vnnode] -= conductance;\
65 _ghs[node] += conductance * BP(vpnode,vnnode);\
67 _rhs[node] += conductance * BP(vpnode,vnnode);\
69 #define _load_static_jacobian2s(pnode,nnode,node,conductance)\
70 _jstat[pnode][node] += conductance;\
71 _jstat[nnode][node] -= conductance;\
73 _ghs[pnode] += conductance * NP(node);\
74 _ghs[nnode] -= conductance * NP(node);\
76 _rhs[pnode] += conductance * NP(node);\
77 _rhs[nnode] -= conductance * NP(node);\
79 #define _load_static_jacobian1(node,vnode,conductance)\
80 _jstat[node][vnode] += conductance;\
82 _ghs[node] += conductance * NP(vnode);\
84 _rhs[node] += conductance * NP(vnode);\
86 #define _load_dynamic_residual2(pnode,nnode,charge)\
87 if (doTR) _charges[pnode][nnode] += charge;\
89 _qhs[pnode] -= charge;\
90 _qhs[nnode] += charge;\
92 #define _load_dynamic_residual1(node,charge)\
93 if (doTR) _charges[node][node] += charge;\
95 _qhs[node] -= charge;\
97 #define _load_dynamic_jacobian4(pnode,nnode,vpnode,vnnode,capacitance)\
99 _jdyna[pnode][vpnode] += capacitance;\
100 _jdyna[nnode][vnnode] += capacitance;\
101 _jdyna[pnode][vnnode] -= capacitance;\
102 _jdyna[nnode][vpnode] -= capacitance;\
105 _caps[pnode][nnode][vpnode][vnnode] += capacitance;\
108 _chs[pnode] += capacitance * BP(vpnode,vnnode);\
109 _chs[nnode] -= capacitance * BP(vpnode,vnnode);\
111 #define _load_dynamic_jacobian2s(pnode,nnode,vnode,capacitance)\
113 _jdyna[pnode][vnode] += capacitance;\
114 _jdyna[nnode][vnode] -= capacitance;\
117 _caps[pnode][nnode][vnode][vnode] += capacitance;\
120 _chs[pnode] += capacitance * NP(vnode);\
121 _chs[nnode] -= capacitance * NP(vnode);\
123 #define _load_dynamic_jacobian2p(node,vpnode,vnnode,capacitance)\
125 _jdyna[node][vpnode] += capacitance;\
126 _jdyna[node][vnnode] -= capacitance;\
129 _caps[node][node][vpnode][vnnode] += capacitance;\
132 _chs[node] += capacitance * BP(vpnode,vnnode);\
134 #define _load_dynamic_jacobian1(node,vnode,capacitance)\
136 _jdyna[node][vnode] += capacitance;\
139 _caps[node][node][vnode][vnode] += capacitance;\
142 _chs[node] += capacitance * NP(vnode);\
145 #define _save_whitenoise1(n1,pwr,type)\
146 _white_pwr[n1][n1] += pwr;
147 #define _save_whitenoise2(n1,n2,pwr,type)\
148 _white_pwr[n1][n2] += pwr;
149 #define _save_flickernoise1(n1,pwr,exp,type)\
150 _flicker_pwr[n1][n1] += pwr;\
151 _flicker_exp[n1][n1] += exp;
152 #define _save_flickernoise2(n1,n2,pwr,exp,type)\
153 _flicker_pwr[n1][n2] += pwr;\
154 _flicker_exp[n1][n2] += exp;
155 #define _load_whitenoise2(n1,n2,pwr)\
156 cy (n1,n2) -= pwr/kB/T0; cy (n2,n1) -= pwr/kB/T0;\
157 cy (n1,n1) += pwr/kB/T0; cy (n2,n2) += pwr/kB/T0;
158 #define _load_whitenoise1(n1,pwr)\
159 cy (n1,n1) += pwr/kB/T0;
160 #define _load_flickernoise2(n1,n2,pwr,exp)\
161 cy (n1,n2) -= pwr*pow(_freq,-exp)/kB/T0;\
162 cy (n2,n1) -= pwr*pow(_freq,-exp)/kB/T0;\
163 cy (n1,n1) += pwr*pow(_freq,-exp)/kB/T0;\
164 cy (n2,n2) += pwr*pow(_freq,-exp)/kB/T0;
165 #define _load_flickernoise1(n1,pwr,exp)\
166 cy (n1,n1) += pwr*pow(_freq,-exp)/kB/T0;
169 #define m00_hypot(v00,x,y) v00 = xhypot(x,y);
170 #define m10_hypot(v10,v00,x,y) v10 = (x)/(v00);
171 #define m11_hypot(v11,v00,x,y) v11 = (y)/(v00);
172 #define m00_max(v00,x,y) v00 = ((x)>(y))?(x):(y);
173 #define m10_max(v10,v00,x,y) v10 = ((x)>(y))?1.0:0.0;
174 #define m11_max(v11,v00,x,y) v11 = ((x)>(y))?0.0:1.0;
175 #define m00_min(v00,x,y) v00 = ((x)<(y))?(x):(y);
176 #define m10_min(v10,v00,x,y) v10 = ((x)<(y))?1.0:0.0;
177 #define m11_min(v11,v00,x,y) v11 = ((x)<(y))?0.0:1.0;
178 #define m00_pow(v00,x,y) v00 = pow(x,y);
179 #define m10_pow(v10,v00,x,y) v10 = (x==0.0)?0.0:(v00)*(y)/(x);
180 #define m11_pow(v11,v00,x,y) v11 = (x==0.0)?0.0:(log(x)*(v00));
182 #define m00_div(v00,v10,x,y) double v10=1/(y); double v00=(x)*v10;
183 #define m10_div(v10,v00,vv,x,y)
184 #define m11_div(v11,v00,vv,x,y) double v11 = -v00*vv;
186 #define m00_mult(v00,v10,v11,x,y) double v10=(x); double v11=(y); double v00=v10*v11;
187 #define m00_add(v00,x,y) double v00=(x)+(y);
189 #define m00_cos(v00,x) v00 = cos(x);
190 #define m10_cos(v10,v00,x) v10 = (-sin(x));
191 #define m00_sin(v00,x) v00 = sin(x);
192 #define m10_sin(v10,v00,x) v10 = (cos(x));
193 #define m00_tan(v00,x) v00 = tan(x);
194 #define m10_tan(v10,v00,x) v10 = (1.0/cos(x)/cos(x));
195 #define m00_cosh(v00,x) v00 = cosh(x);
196 #define m10_cosh(v10,v00,x) v10 = (sinh(x));
197 #define m00_sinh(v00,x) v00 = sinh(x);
198 #define m10_sinh(v10,v00,x) v10 = (cosh(x));
199 #define m00_tanh(v00,x) v00 = tanh(x);
200 #define m10_tanh(v10,v00,x) v10 = (1.0/cosh(x)/cosh(x));
201 #define m00_acos(v00,x) v00 = acos(x);
202 #define m10_acos(v10,v00,x) v10 = (-1.0/sqrt(1-x*x));
203 #define m00_asin(v00,x) v00 = asin(x);
204 #define m10_asin(v10,v00,x) v10 = (+1.0/sqrt(1-x*x));
205 #define m00_atan(v00,x) v00 = atan(x);
206 #define m10_atan(v10,v00,x) v10 = (+1.0/(1+x*x));
207 #define m00_atanh(v00,x) v00 = atanh(x);
208 #define m10_atanh(v10,v00,x) v10 = (+1.0/(1-x*x));
209 #define m00_logE(v00,x) v00 = log(x);
210 #define m10_logE(v10,v00,x) v10 = (1.0/x);
211 #define m00_log10(v00,x) v00 = log10(x);
212 #define m10_log10(v10,v00,x) v10 = (1.0/x/M_LN10);
213 #define m00_sqrt(v00,x) v00 = sqrt(x);
214 #define m10_sqrt(v10,v00,x) v10 = (0.5/v00);
215 #define m00_fabs(v00,x) v00 = fabs(x);
216 #define m10_fabs(v10,v00,x) v10 = (((x)>=0)?(+1.0):(-1.0));
218 #define m00_exp(v00,x) v00 = exp(x);
219 #define m10_exp(v10,v00,x) v10 = v00;
221 #define m00_abs(v00) ((v00)<(0)?(-(v00)):(v00))
222 #define m00_floor(v00,x) v00 = floor(x);
223 #define m00_limexp(v00,x) v00 = ((x)<80.0?exp(x):exp(80.0)*(x-79.0));
224 #define m10_limexp(v10,v00,x) v10 = ((x)<80.0?(v00):exp(80.0));
226 #define m20_logE(v00) (-1.0/v00/v00)
227 #define m20_exp(v00) exp(v00)
228 #define m20_limexp(v00) ((v00)<80.0?exp(v00):0.0)
229 #define m20_sqrt(v00) (-0.25/(v00)/sqrt(v00))
230 #define m20_fabs(v00) 0.0
231 #define m20_pow(x,y) ((y)*((y)-1.0)*pow(x,y)/(x)/(x))
232 #define m00_vt(x) (kBoverQ*(x))
233 #define m10_vt(x) (kBoverQ)
236 #define _modelname "fa1b"
237 #define _instancename getName()
238 #define _circuit_temp (getPropertyDouble("Temp")+273.15)
239 #define _param_given(p) (isPropertyGiven(p)?1:0)
243 #define _vt_nom (kBoverQ*_circuit_temp)
245 using namespace device;
254 void fa1b::initModel (
void)
269 initializeInstance ();
290 void fa1b::initVerilog (
void)
297 for (i1 = 0; i1 < 9; i1++) {
298 for (i2 = 0; i2 < 9; i2++) {
299 _charges[i1][i2] = 0.0;
303 for (i1 = 0; i1 < 9; i1++) {
304 for (i2 = 0; i2 < 9; i2++) {
305 for (i3 = 0; i3 < 9; i3++) {
306 for (i4 = 0; i4 < 9; i4++) {
307 _caps[i1][i2][i3][i4] = 0.0;
311 for (i1 = 0; i1 < 9; i1++) {
316 for (i2 = 0; i2 < 9; i2++) {
317 _jstat[i1][i2] = 0.0;
318 _jdyna[i1][i2] = 0.0;
324 void fa1b::loadVariables (
void)
336 #define _DERIVATEFORDDX
339 void fa1b::initializeModel (
void)
341 #if defined(_DYNAMIC)
345 #if defined(_DYNAMIC)
346 Cd=((Delay*1.43)/Rd);
352 void fa1b::initializeInstance (
void)
357 void fa1b::initialStep (
void)
362 void fa1b::finalStep (
void)
367 void fa1b::calcVerilog (
void)
372 #if defined(_DERIVATE)
378 #if defined(_DERIVATE)
384 #if defined(_DERIVATE)
389 #if defined(_DERIVATE)
393 #if defined(_DERIVATE)
398 #if defined(_DERIVATE)
399 HCO_VA_GND=(((1-
NP(
B)))+(-1.0)*
NP(
B));
400 HCO_VB_GND=((
NP(
A)*(-1.0))+((1-
NP(
A))));
403 #if defined(_DERIVATE)
404 ICO_VA_GND=(KS_VA_GND+(
NP(
CI)*HCO_VA_GND));
405 ICO_VB_GND=(KS_VB_GND+(
NP(
CI)*HCO_VB_GND));
408 ICO=(KS+(
NP(
CI)*HCO));
409 #if defined(_DERIVATE)
410 IS_VCI_GND=(((1-HCO))+(-1.0)*HCO);
411 IS_VA_GND=((
NP(
CI)*(-HCO_VA_GND))+((1-
NP(
CI))*HCO_VA_GND));
412 IS_VB_GND=((
NP(
CI)*(-HCO_VB_GND))+((1-
NP(
CI))*HCO_VB_GND));
414 IS=((
NP(
CI)*(1-HCO))+((1-
NP(
CI))*HCO));
418 #if defined(_DERIVATE)
427 #if defined(_DERIVATE)
437 #if defined(_DERIVATE)
446 #if defined(_DERIVATE)
454 double m00_tanh(d00_tanh0,(TR*(IS-0.5)))
455 #if defined(_DERIVATE)
456 double m10_tanh(d10_tanh0,d00_tanh0,(TR*(IS-0.5)))
459 #if defined(_DERIVATE)
466 #if defined(_DERIVATE)
470 #if defined(_DERIVATE)
473 #if defined(_DYNAMIC)
475 #if defined(_DERIVATE)
480 #if defined(_DERIVATE)
484 #if defined(_DERIVATE)
488 double m00_tanh(d00_tanh0,(TR*(ICO-0.5)))
489 #if defined(_DERIVATE)
490 double m10_tanh(d10_tanh0,d00_tanh0,(TR*(ICO-0.5)))
493 #if defined(_DERIVATE)
500 #if defined(_DERIVATE)
504 #if defined(_DERIVATE)
507 #if defined(_DYNAMIC)
509 #if defined(_DERIVATE)
514 #if defined(_DERIVATE)
518 #if defined(_DERIVATE)
537 for (
int i1 = 0; i1 < 9; i1++) {
539 for (
int i2 = 0; i2 < 9; i2++) {
540 setY (i1, i2, _jstat[i1][i2]);
574 matrix fa1b::calcMatrixY (nr_double_t frequency)
580 for (
int i1 = 0; i1 < 9; i1++) {
581 for (
int i2 = 0; i2 < 9; i2++) {
582 y (i1,i2) =
rect (_jstat[i1][i2], _jdyna[i1][i2] * 2 *
M_PI * _freq);
616 int i1, i2, i3, i4, state;
619 for (i1 = 0; i1 < 9; i1++) {
620 for (i2 = 0; i2 < 9; i2++) {
621 state = 2 * (i2 + 9 * i1);
623 if (_charges[i1][i2] != 0.0)
628 for (i1 = 0; i1 < 9; i1++) {
629 state = 2 * (i1 + 9 * i1);
630 if (_charges[i1][i1] != 0.0)
635 for (i1 = 0; i1 < 9; i1++) {
636 for (i2 = 0; i2 < 9; i2++) {
638 for (i3 = 0; i3 < 9; i3++) {
639 for (i4 = 0; i4 < 9; i4++) {
641 if (_caps[i1][i2][i3][i4] != 0.0)
646 for (i1 = 0; i1 < 9; i1++) {
647 for (i2 = 0; i2 < 9; i2++) {
649 for (i3 = 0; i3 < 9; i3++) {
650 if (_caps[i1][i2][i3][i3] != 0.0)
655 for (i1 = 0; i1 < 9; i1++) {
656 for (i3 = 0; i3 < 9; i3++) {
657 for (i4 = 0; i4 < 9; i4++) {
659 if (_caps[i1][i1][i3][i4] != 0.0)
664 for (i1 = 0; i1 < 9; i1++) {
665 for (i3 = 0; i3 < 9; i3++) {
666 if (_caps[i1][i1][i3][i3] != 0.0)
672 matrix fa1b::calcMatrixCy (nr_double_t frequency)
712 for (
int i1 = 0; i1 < 9; i1++) {
714 setCV (i1, _chs[i1]);
715 setGV (i1, _ghs[i1]);
716 for (
int i2 = 0; i2 < 9; i2++) {
717 setQV (i1, i2, _jdyna[i1][i2]);