16 #include "component.h"
41 #define NP(node) real (getV (node))
42 #define BP(pnode,nnode) (NP(pnode) - NP(nnode))
43 #define _load_static_residual2(pnode,nnode,current)\
44 _rhs[pnode] -= current;\
45 _rhs[nnode] += current;
46 #define _load_static_augmented_residual2(pnode,nnode,current)\
47 _rhs[pnode] -= current;\
48 _rhs[nnode] += current;
49 #define _load_static_residual1(node,current)\
50 _rhs[node] -= current;
51 #define _load_static_augmented_residual1(node,current)\
52 _rhs[node] -= current;
53 #define _load_static_jacobian4(pnode,nnode,vpnode,vnnode,conductance)\
54 _jstat[pnode][vpnode] += conductance;\
55 _jstat[nnode][vnnode] += conductance;\
56 _jstat[pnode][vnnode] -= conductance;\
57 _jstat[nnode][vpnode] -= conductance;\
59 _ghs[pnode] += conductance * BP(vpnode,vnnode);\
60 _ghs[nnode] -= conductance * BP(vpnode,vnnode);\
62 _rhs[pnode] += conductance * BP(vpnode,vnnode);\
63 _rhs[nnode] -= conductance * BP(vpnode,vnnode);\
65 #define _load_static_jacobian2p(node,vpnode,vnnode,conductance)\
66 _jstat[node][vpnode] += conductance;\
67 _jstat[node][vnnode] -= conductance;\
69 _ghs[node] += conductance * BP(vpnode,vnnode);\
71 _rhs[node] += conductance * BP(vpnode,vnnode);\
73 #define _load_static_jacobian2s(pnode,nnode,node,conductance)\
74 _jstat[pnode][node] += conductance;\
75 _jstat[nnode][node] -= conductance;\
77 _ghs[pnode] += conductance * NP(node);\
78 _ghs[nnode] -= conductance * NP(node);\
80 _rhs[pnode] += conductance * NP(node);\
81 _rhs[nnode] -= conductance * NP(node);\
83 #define _load_static_jacobian1(node,vnode,conductance)\
84 _jstat[node][vnode] += conductance;\
86 _ghs[node] += conductance * NP(vnode);\
88 _rhs[node] += conductance * NP(vnode);\
90 #define _load_dynamic_residual2(pnode,nnode,charge)\
91 if (doTR) _charges[pnode][nnode] += charge;\
93 _qhs[pnode] -= charge;\
94 _qhs[nnode] += charge;\
96 #define _load_dynamic_residual1(node,charge)\
97 if (doTR) _charges[node][node] += charge;\
99 _qhs[node] -= charge;\
101 #define _load_dynamic_jacobian4(pnode,nnode,vpnode,vnnode,capacitance)\
103 _jdyna[pnode][vpnode] += capacitance;\
104 _jdyna[nnode][vnnode] += capacitance;\
105 _jdyna[pnode][vnnode] -= capacitance;\
106 _jdyna[nnode][vpnode] -= capacitance;\
109 _caps[pnode][nnode][vpnode][vnnode] += capacitance;\
112 _chs[pnode] += capacitance * BP(vpnode,vnnode);\
113 _chs[nnode] -= capacitance * BP(vpnode,vnnode);\
115 #define _load_dynamic_jacobian2s(pnode,nnode,vnode,capacitance)\
117 _jdyna[pnode][vnode] += capacitance;\
118 _jdyna[nnode][vnode] -= capacitance;\
121 _caps[pnode][nnode][vnode][vnode] += capacitance;\
124 _chs[pnode] += capacitance * NP(vnode);\
125 _chs[nnode] -= capacitance * NP(vnode);\
127 #define _load_dynamic_jacobian2p(node,vpnode,vnnode,capacitance)\
129 _jdyna[node][vpnode] += capacitance;\
130 _jdyna[node][vnnode] -= capacitance;\
133 _caps[node][node][vpnode][vnnode] += capacitance;\
136 _chs[node] += capacitance * BP(vpnode,vnnode);\
138 #define _load_dynamic_jacobian1(node,vnode,capacitance)\
140 _jdyna[node][vnode] += capacitance;\
143 _caps[node][node][vnode][vnode] += capacitance;\
146 _chs[node] += capacitance * NP(vnode);\
149 #define _save_whitenoise1(n1,pwr,type)\
150 _white_pwr[n1][n1] += pwr;
151 #define _save_whitenoise2(n1,n2,pwr,type)\
152 _white_pwr[n1][n2] += pwr;
153 #define _save_flickernoise1(n1,pwr,exp,type)\
154 _flicker_pwr[n1][n1] += pwr;\
155 _flicker_exp[n1][n1] += exp;
156 #define _save_flickernoise2(n1,n2,pwr,exp,type)\
157 _flicker_pwr[n1][n2] += pwr;\
158 _flicker_exp[n1][n2] += exp;
159 #define _load_whitenoise2(n1,n2,pwr)\
160 cy (n1,n2) -= pwr/kB/T0; cy (n2,n1) -= pwr/kB/T0;\
161 cy (n1,n1) += pwr/kB/T0; cy (n2,n2) += pwr/kB/T0;
162 #define _load_whitenoise1(n1,pwr)\
163 cy (n1,n1) += pwr/kB/T0;
164 #define _load_flickernoise2(n1,n2,pwr,exp)\
165 cy (n1,n2) -= pwr*pow(_freq,-exp)/kB/T0;\
166 cy (n2,n1) -= pwr*pow(_freq,-exp)/kB/T0;\
167 cy (n1,n1) += pwr*pow(_freq,-exp)/kB/T0;\
168 cy (n2,n2) += pwr*pow(_freq,-exp)/kB/T0;
169 #define _load_flickernoise1(n1,pwr,exp)\
170 cy (n1,n1) += pwr*pow(_freq,-exp)/kB/T0;
173 #define m00_hypot(v00,x,y) v00 = xhypot(x,y);
174 #define m10_hypot(v10,v00,x,y) v10 = (x)/(v00);
175 #define m11_hypot(v11,v00,x,y) v11 = (y)/(v00);
176 #define m00_max(v00,x,y) v00 = ((x)>(y))?(x):(y);
177 #define m10_max(v10,v00,x,y) v10 = ((x)>(y))?1.0:0.0;
178 #define m11_max(v11,v00,x,y) v11 = ((x)>(y))?0.0:1.0;
179 #define m00_min(v00,x,y) v00 = ((x)<(y))?(x):(y);
180 #define m10_min(v10,v00,x,y) v10 = ((x)<(y))?1.0:0.0;
181 #define m11_min(v11,v00,x,y) v11 = ((x)<(y))?0.0:1.0;
182 #define m00_pow(v00,x,y) v00 = pow(x,y);
183 #define m10_pow(v10,v00,x,y) v10 = (x==0.0)?0.0:(v00)*(y)/(x);
184 #define m11_pow(v11,v00,x,y) v11 = (x==0.0)?0.0:(log(x)*(v00));
186 #define m00_div(v00,v10,x,y) double v10=1/(y); double v00=(x)*v10;
187 #define m10_div(v10,v00,vv,x,y)
188 #define m11_div(v11,v00,vv,x,y) double v11 = -v00*vv;
190 #define m00_mult(v00,v10,v11,x,y) double v10=(x); double v11=(y); double v00=v10*v11;
191 #define m00_add(v00,x,y) double v00=(x)+(y);
193 #define m00_cos(v00,x) v00 = cos(x);
194 #define m10_cos(v10,v00,x) v10 = (-sin(x));
195 #define m00_sin(v00,x) v00 = sin(x);
196 #define m10_sin(v10,v00,x) v10 = (cos(x));
197 #define m00_tan(v00,x) v00 = tan(x);
198 #define m10_tan(v10,v00,x) v10 = (1.0/cos(x)/cos(x));
199 #define m00_cosh(v00,x) v00 = cosh(x);
200 #define m10_cosh(v10,v00,x) v10 = (sinh(x));
201 #define m00_sinh(v00,x) v00 = sinh(x);
202 #define m10_sinh(v10,v00,x) v10 = (cosh(x));
203 #define m00_tanh(v00,x) v00 = tanh(x);
204 #define m10_tanh(v10,v00,x) v10 = (1.0/cosh(x)/cosh(x));
205 #define m00_acos(v00,x) v00 = acos(x);
206 #define m10_acos(v10,v00,x) v10 = (-1.0/sqrt(1-x*x));
207 #define m00_asin(v00,x) v00 = asin(x);
208 #define m10_asin(v10,v00,x) v10 = (+1.0/sqrt(1-x*x));
209 #define m00_atan(v00,x) v00 = atan(x);
210 #define m10_atan(v10,v00,x) v10 = (+1.0/(1+x*x));
211 #define m00_atanh(v00,x) v00 = atanh(x);
212 #define m10_atanh(v10,v00,x) v10 = (+1.0/(1-x*x));
213 #define m00_logE(v00,x) v00 = log(x);
214 #define m10_logE(v10,v00,x) v10 = (1.0/x);
215 #define m00_log10(v00,x) v00 = log10(x);
216 #define m10_log10(v10,v00,x) v10 = (1.0/x/M_LN10);
217 #define m00_sqrt(v00,x) v00 = sqrt(x);
218 #define m10_sqrt(v10,v00,x) v10 = (0.5/v00);
219 #define m00_fabs(v00,x) v00 = fabs(x);
220 #define m10_fabs(v10,v00,x) v10 = (((x)>=0)?(+1.0):(-1.0));
222 #define m00_exp(v00,x) v00 = exp(x);
223 #define m10_exp(v10,v00,x) v10 = v00;
225 #define m00_abs(v00) ((v00)<(0)?(-(v00)):(v00))
226 #define m00_floor(v00,x) v00 = floor(x);
227 #define m00_limexp(v00,x) v00 = ((x)<80.0?exp(x):exp(80.0)*(x-79.0));
228 #define m10_limexp(v10,v00,x) v10 = ((x)<80.0?(v00):exp(80.0));
230 #define m20_logE(v00) (-1.0/v00/v00)
231 #define m20_exp(v00) exp(v00)
232 #define m20_limexp(v00) ((v00)<80.0?exp(v00):0.0)
233 #define m20_sqrt(v00) (-0.25/(v00)/sqrt(v00))
234 #define m20_fabs(v00) 0.0
235 #define m20_pow(x,y) ((y)*((y)-1.0)*pow(x,y)/(x)/(x))
236 #define m00_vt(x) (kBoverQ*(x))
237 #define m10_vt(x) (kBoverQ)
240 #define _modelname "dff_SR"
241 #define _instancename getName()
242 #define _circuit_temp (getPropertyDouble("Temp")+273.15)
243 #define _param_given(p) (isPropertyGiven(p)?1:0)
247 #define _vt_nom (kBoverQ*_circuit_temp)
249 using namespace device;
258 void dff_SR::initModel (
void)
276 initializeInstance ();
297 void dff_SR::initVerilog (
void)
304 for (i1 = 0; i1 < 13; i1++) {
305 for (i2 = 0; i2 < 13; i2++) {
306 _charges[i1][i2] = 0.0;
310 for (i1 = 0; i1 < 13; i1++) {
311 for (i2 = 0; i2 < 13; i2++) {
312 for (i3 = 0; i3 < 13; i3++) {
313 for (i4 = 0; i4 < 13; i4++) {
314 _caps[i1][i2][i3][i4] = 0.0;
318 for (i1 = 0; i1 < 13; i1++) {
323 for (i2 = 0; i2 < 13; i2++) {
324 _jstat[i1][i2] = 0.0;
325 _jdyna[i1][i2] = 0.0;
331 void dff_SR::loadVariables (
void)
344 #define _DERIVATEFORDDX
347 void dff_SR::initializeModel (
void)
349 #if defined(_DYNAMIC)
353 #if defined(_DYNAMIC)
354 Ccc=((Delay*1.43)/Rd);
360 void dff_SR::initializeInstance (
void)
365 void dff_SR::initialStep (
void)
370 void dff_SR::finalStep (
void)
375 void dff_SR::calcVerilog (
void)
381 #if defined(_DERIVATE)
385 #if defined(_DERIVATE)
392 #if defined(_DERIVATE)
397 #if defined(_DERIVATE)
401 #if defined(_DERIVATE)
408 #if defined(_DERIVATE)
413 #if defined(_DERIVATE)
417 #if defined(_DERIVATE)
424 #if defined(_DERIVATE)
429 #if defined(_DERIVATE)
433 #if defined(_DERIVATE)
440 #if defined(_DERIVATE)
445 #if defined(_DERIVATE)
449 #if defined(_DERIVATE)
456 #if defined(_DERIVATE)
461 #if defined(_DERIVATE)
465 #if defined(_DERIVATE)
472 #if defined(_DERIVATE)
476 #if defined(_DERIVATE)
479 #if defined(_DYNAMIC)
481 #if defined(_DERIVATE)
486 #if defined(_DERIVATE)
489 #if defined(_DYNAMIC)
491 #if defined(_DERIVATE)
496 #if defined(_DERIVATE)
499 #if defined(_DYNAMIC)
501 #if defined(_DERIVATE)
521 for (
int i1 = 0; i1 < 13; i1++) {
523 for (
int i2 = 0; i2 < 13; i2++) {
524 setY (i1, i2, _jstat[i1][i2]);
558 matrix dff_SR::calcMatrixY (nr_double_t frequency)
564 for (
int i1 = 0; i1 < 13; i1++) {
565 for (
int i2 = 0; i2 < 13; i2++) {
566 y (i1,i2) =
rect (_jstat[i1][i2], _jdyna[i1][i2] * 2 *
M_PI * _freq);
600 int i1, i2, i3, i4, state;
603 for (i1 = 0; i1 < 13; i1++) {
604 for (i2 = 0; i2 < 13; i2++) {
605 state = 2 * (i2 + 13 * i1);
607 if (_charges[i1][i2] != 0.0)
612 for (i1 = 0; i1 < 13; i1++) {
613 state = 2 * (i1 + 13 * i1);
614 if (_charges[i1][i1] != 0.0)
619 for (i1 = 0; i1 < 13; i1++) {
620 for (i2 = 0; i2 < 13; i2++) {
622 for (i3 = 0; i3 < 13; i3++) {
623 for (i4 = 0; i4 < 13; i4++) {
625 if (_caps[i1][i2][i3][i4] != 0.0)
630 for (i1 = 0; i1 < 13; i1++) {
631 for (i2 = 0; i2 < 13; i2++) {
633 for (i3 = 0; i3 < 13; i3++) {
634 if (_caps[i1][i2][i3][i3] != 0.0)
639 for (i1 = 0; i1 < 13; i1++) {
640 for (i3 = 0; i3 < 13; i3++) {
641 for (i4 = 0; i4 < 13; i4++) {
643 if (_caps[i1][i1][i3][i4] != 0.0)
648 for (i1 = 0; i1 < 13; i1++) {
649 for (i3 = 0; i3 < 13; i3++) {
650 if (_caps[i1][i1][i3][i3] != 0.0)
656 matrix dff_SR::calcMatrixCy (nr_double_t frequency)
696 for (
int i1 = 0; i1 < 13; i1++) {
698 setCV (i1, _chs[i1]);
699 setGV (i1, _ghs[i1]);
700 for (
int i2 = 0; i2 < 13; i2++) {
701 setQV (i1, i2, _jdyna[i1][i2]);