16 #include "component.h"
21 #define CIR_jkff_SR -1
43 #define NP(node) real (getV (node))
44 #define BP(pnode,nnode) (NP(pnode) - NP(nnode))
45 #define _load_static_residual2(pnode,nnode,current)\
46 _rhs[pnode] -= current;\
47 _rhs[nnode] += current;
48 #define _load_static_augmented_residual2(pnode,nnode,current)\
49 _rhs[pnode] -= current;\
50 _rhs[nnode] += current;
51 #define _load_static_residual1(node,current)\
52 _rhs[node] -= current;
53 #define _load_static_augmented_residual1(node,current)\
54 _rhs[node] -= current;
55 #define _load_static_jacobian4(pnode,nnode,vpnode,vnnode,conductance)\
56 _jstat[pnode][vpnode] += conductance;\
57 _jstat[nnode][vnnode] += conductance;\
58 _jstat[pnode][vnnode] -= conductance;\
59 _jstat[nnode][vpnode] -= conductance;\
61 _ghs[pnode] += conductance * BP(vpnode,vnnode);\
62 _ghs[nnode] -= conductance * BP(vpnode,vnnode);\
64 _rhs[pnode] += conductance * BP(vpnode,vnnode);\
65 _rhs[nnode] -= conductance * BP(vpnode,vnnode);\
67 #define _load_static_jacobian2p(node,vpnode,vnnode,conductance)\
68 _jstat[node][vpnode] += conductance;\
69 _jstat[node][vnnode] -= conductance;\
71 _ghs[node] += conductance * BP(vpnode,vnnode);\
73 _rhs[node] += conductance * BP(vpnode,vnnode);\
75 #define _load_static_jacobian2s(pnode,nnode,node,conductance)\
76 _jstat[pnode][node] += conductance;\
77 _jstat[nnode][node] -= conductance;\
79 _ghs[pnode] += conductance * NP(node);\
80 _ghs[nnode] -= conductance * NP(node);\
82 _rhs[pnode] += conductance * NP(node);\
83 _rhs[nnode] -= conductance * NP(node);\
85 #define _load_static_jacobian1(node,vnode,conductance)\
86 _jstat[node][vnode] += conductance;\
88 _ghs[node] += conductance * NP(vnode);\
90 _rhs[node] += conductance * NP(vnode);\
92 #define _load_dynamic_residual2(pnode,nnode,charge)\
93 if (doTR) _charges[pnode][nnode] += charge;\
95 _qhs[pnode] -= charge;\
96 _qhs[nnode] += charge;\
98 #define _load_dynamic_residual1(node,charge)\
99 if (doTR) _charges[node][node] += charge;\
101 _qhs[node] -= charge;\
103 #define _load_dynamic_jacobian4(pnode,nnode,vpnode,vnnode,capacitance)\
105 _jdyna[pnode][vpnode] += capacitance;\
106 _jdyna[nnode][vnnode] += capacitance;\
107 _jdyna[pnode][vnnode] -= capacitance;\
108 _jdyna[nnode][vpnode] -= capacitance;\
111 _caps[pnode][nnode][vpnode][vnnode] += capacitance;\
114 _chs[pnode] += capacitance * BP(vpnode,vnnode);\
115 _chs[nnode] -= capacitance * BP(vpnode,vnnode);\
117 #define _load_dynamic_jacobian2s(pnode,nnode,vnode,capacitance)\
119 _jdyna[pnode][vnode] += capacitance;\
120 _jdyna[nnode][vnode] -= capacitance;\
123 _caps[pnode][nnode][vnode][vnode] += capacitance;\
126 _chs[pnode] += capacitance * NP(vnode);\
127 _chs[nnode] -= capacitance * NP(vnode);\
129 #define _load_dynamic_jacobian2p(node,vpnode,vnnode,capacitance)\
131 _jdyna[node][vpnode] += capacitance;\
132 _jdyna[node][vnnode] -= capacitance;\
135 _caps[node][node][vpnode][vnnode] += capacitance;\
138 _chs[node] += capacitance * BP(vpnode,vnnode);\
140 #define _load_dynamic_jacobian1(node,vnode,capacitance)\
142 _jdyna[node][vnode] += capacitance;\
145 _caps[node][node][vnode][vnode] += capacitance;\
148 _chs[node] += capacitance * NP(vnode);\
151 #define _save_whitenoise1(n1,pwr,type)\
152 _white_pwr[n1][n1] += pwr;
153 #define _save_whitenoise2(n1,n2,pwr,type)\
154 _white_pwr[n1][n2] += pwr;
155 #define _save_flickernoise1(n1,pwr,exp,type)\
156 _flicker_pwr[n1][n1] += pwr;\
157 _flicker_exp[n1][n1] += exp;
158 #define _save_flickernoise2(n1,n2,pwr,exp,type)\
159 _flicker_pwr[n1][n2] += pwr;\
160 _flicker_exp[n1][n2] += exp;
161 #define _load_whitenoise2(n1,n2,pwr)\
162 cy (n1,n2) -= pwr/kB/T0; cy (n2,n1) -= pwr/kB/T0;\
163 cy (n1,n1) += pwr/kB/T0; cy (n2,n2) += pwr/kB/T0;
164 #define _load_whitenoise1(n1,pwr)\
165 cy (n1,n1) += pwr/kB/T0;
166 #define _load_flickernoise2(n1,n2,pwr,exp)\
167 cy (n1,n2) -= pwr*pow(_freq,-exp)/kB/T0;\
168 cy (n2,n1) -= pwr*pow(_freq,-exp)/kB/T0;\
169 cy (n1,n1) += pwr*pow(_freq,-exp)/kB/T0;\
170 cy (n2,n2) += pwr*pow(_freq,-exp)/kB/T0;
171 #define _load_flickernoise1(n1,pwr,exp)\
172 cy (n1,n1) += pwr*pow(_freq,-exp)/kB/T0;
175 #define m00_hypot(v00,x,y) v00 = xhypot(x,y);
176 #define m10_hypot(v10,v00,x,y) v10 = (x)/(v00);
177 #define m11_hypot(v11,v00,x,y) v11 = (y)/(v00);
178 #define m00_max(v00,x,y) v00 = ((x)>(y))?(x):(y);
179 #define m10_max(v10,v00,x,y) v10 = ((x)>(y))?1.0:0.0;
180 #define m11_max(v11,v00,x,y) v11 = ((x)>(y))?0.0:1.0;
181 #define m00_min(v00,x,y) v00 = ((x)<(y))?(x):(y);
182 #define m10_min(v10,v00,x,y) v10 = ((x)<(y))?1.0:0.0;
183 #define m11_min(v11,v00,x,y) v11 = ((x)<(y))?0.0:1.0;
184 #define m00_pow(v00,x,y) v00 = pow(x,y);
185 #define m10_pow(v10,v00,x,y) v10 = (x==0.0)?0.0:(v00)*(y)/(x);
186 #define m11_pow(v11,v00,x,y) v11 = (x==0.0)?0.0:(log(x)*(v00));
188 #define m00_div(v00,v10,x,y) double v10=1/(y); double v00=(x)*v10;
189 #define m10_div(v10,v00,vv,x,y)
190 #define m11_div(v11,v00,vv,x,y) double v11 = -v00*vv;
192 #define m00_mult(v00,v10,v11,x,y) double v10=(x); double v11=(y); double v00=v10*v11;
193 #define m00_add(v00,x,y) double v00=(x)+(y);
195 #define m00_cos(v00,x) v00 = cos(x);
196 #define m10_cos(v10,v00,x) v10 = (-sin(x));
197 #define m00_sin(v00,x) v00 = sin(x);
198 #define m10_sin(v10,v00,x) v10 = (cos(x));
199 #define m00_tan(v00,x) v00 = tan(x);
200 #define m10_tan(v10,v00,x) v10 = (1.0/cos(x)/cos(x));
201 #define m00_cosh(v00,x) v00 = cosh(x);
202 #define m10_cosh(v10,v00,x) v10 = (sinh(x));
203 #define m00_sinh(v00,x) v00 = sinh(x);
204 #define m10_sinh(v10,v00,x) v10 = (cosh(x));
205 #define m00_tanh(v00,x) v00 = tanh(x);
206 #define m10_tanh(v10,v00,x) v10 = (1.0/cosh(x)/cosh(x));
207 #define m00_acos(v00,x) v00 = acos(x);
208 #define m10_acos(v10,v00,x) v10 = (-1.0/sqrt(1-x*x));
209 #define m00_asin(v00,x) v00 = asin(x);
210 #define m10_asin(v10,v00,x) v10 = (+1.0/sqrt(1-x*x));
211 #define m00_atan(v00,x) v00 = atan(x);
212 #define m10_atan(v10,v00,x) v10 = (+1.0/(1+x*x));
213 #define m00_atanh(v00,x) v00 = atanh(x);
214 #define m10_atanh(v10,v00,x) v10 = (+1.0/(1-x*x));
215 #define m00_logE(v00,x) v00 = log(x);
216 #define m10_logE(v10,v00,x) v10 = (1.0/x);
217 #define m00_log10(v00,x) v00 = log10(x);
218 #define m10_log10(v10,v00,x) v10 = (1.0/x/M_LN10);
219 #define m00_sqrt(v00,x) v00 = sqrt(x);
220 #define m10_sqrt(v10,v00,x) v10 = (0.5/v00);
221 #define m00_fabs(v00,x) v00 = fabs(x);
222 #define m10_fabs(v10,v00,x) v10 = (((x)>=0)?(+1.0):(-1.0));
224 #define m00_exp(v00,x) v00 = exp(x);
225 #define m10_exp(v10,v00,x) v10 = v00;
227 #define m00_abs(v00) ((v00)<(0)?(-(v00)):(v00))
228 #define m00_floor(v00,x) v00 = floor(x);
229 #define m00_limexp(v00,x) v00 = ((x)<80.0?exp(x):exp(80.0)*(x-79.0));
230 #define m10_limexp(v10,v00,x) v10 = ((x)<80.0?(v00):exp(80.0));
232 #define m20_logE(v00) (-1.0/v00/v00)
233 #define m20_exp(v00) exp(v00)
234 #define m20_limexp(v00) ((v00)<80.0?exp(v00):0.0)
235 #define m20_sqrt(v00) (-0.25/(v00)/sqrt(v00))
236 #define m20_fabs(v00) 0.0
237 #define m20_pow(x,y) ((y)*((y)-1.0)*pow(x,y)/(x)/(x))
238 #define m00_vt(x) (kBoverQ*(x))
239 #define m10_vt(x) (kBoverQ)
242 #define _modelname "jkff_SR"
243 #define _instancename getName()
244 #define _circuit_temp (getPropertyDouble("Temp")+273.15)
245 #define _param_given(p) (isPropertyGiven(p)?1:0)
249 #define _vt_nom (kBoverQ*_circuit_temp)
251 using namespace device;
260 void jkff_SR::initModel (
void)
279 initializeInstance ();
300 void jkff_SR::initVerilog (
void)
307 for (i1 = 0; i1 < 15; i1++) {
308 for (i2 = 0; i2 < 15; i2++) {
309 _charges[i1][i2] = 0.0;
313 for (i1 = 0; i1 < 15; i1++) {
314 for (i2 = 0; i2 < 15; i2++) {
315 for (i3 = 0; i3 < 15; i3++) {
316 for (i4 = 0; i4 < 15; i4++) {
317 _caps[i1][i2][i3][i4] = 0.0;
321 for (i1 = 0; i1 < 15; i1++) {
326 for (i2 = 0; i2 < 15; i2++) {
327 _jstat[i1][i2] = 0.0;
328 _jdyna[i1][i2] = 0.0;
334 void jkff_SR::loadVariables (
void)
347 #define _DERIVATEFORDDX
350 void jkff_SR::initializeModel (
void)
352 #if defined(_DYNAMIC)
356 #if defined(_DYNAMIC)
357 Ccc=((Delay*1.43)/Rd);
363 void jkff_SR::initializeInstance (
void)
368 void jkff_SR::initialStep (
void)
373 void jkff_SR::finalStep (
void)
378 void jkff_SR::calcVerilog (
void)
384 #if defined(_DERIVATE)
388 #if defined(_DERIVATE)
396 #if defined(_DERIVATE)
401 #if defined(_DERIVATE)
405 #if defined(_DERIVATE)
412 #if defined(_DERIVATE)
417 #if defined(_DERIVATE)
421 #if defined(_DERIVATE)
428 #if defined(_DERIVATE)
433 #if defined(_DERIVATE)
437 #if defined(_DERIVATE)
444 #if defined(_DERIVATE)
449 #if defined(_DERIVATE)
453 #if defined(_DERIVATE)
460 #if defined(_DERIVATE)
465 #if defined(_DERIVATE)
469 #if defined(_DERIVATE)
476 #if defined(_DERIVATE)
481 #if defined(_DERIVATE)
485 #if defined(_DERIVATE)
492 #if defined(_DERIVATE)
496 #if defined(_DERIVATE)
499 #if defined(_DYNAMIC)
501 #if defined(_DERIVATE)
506 #if defined(_DERIVATE)
509 #if defined(_DYNAMIC)
511 #if defined(_DERIVATE)
516 #if defined(_DERIVATE)
519 #if defined(_DYNAMIC)
521 #if defined(_DERIVATE)
541 for (
int i1 = 0; i1 < 15; i1++) {
543 for (
int i2 = 0; i2 < 15; i2++) {
544 setY (i1, i2, _jstat[i1][i2]);
578 matrix jkff_SR::calcMatrixY (nr_double_t frequency)
584 for (
int i1 = 0; i1 < 15; i1++) {
585 for (
int i2 = 0; i2 < 15; i2++) {
586 y (i1,i2) =
rect (_jstat[i1][i2], _jdyna[i1][i2] * 2 *
M_PI * _freq);
620 int i1, i2, i3, i4, state;
623 for (i1 = 0; i1 < 15; i1++) {
624 for (i2 = 0; i2 < 15; i2++) {
625 state = 2 * (i2 + 15 * i1);
627 if (_charges[i1][i2] != 0.0)
632 for (i1 = 0; i1 < 15; i1++) {
633 state = 2 * (i1 + 15 * i1);
634 if (_charges[i1][i1] != 0.0)
639 for (i1 = 0; i1 < 15; i1++) {
640 for (i2 = 0; i2 < 15; i2++) {
642 for (i3 = 0; i3 < 15; i3++) {
643 for (i4 = 0; i4 < 15; i4++) {
645 if (_caps[i1][i2][i3][i4] != 0.0)
650 for (i1 = 0; i1 < 15; i1++) {
651 for (i2 = 0; i2 < 15; i2++) {
653 for (i3 = 0; i3 < 15; i3++) {
654 if (_caps[i1][i2][i3][i3] != 0.0)
659 for (i1 = 0; i1 < 15; i1++) {
660 for (i3 = 0; i3 < 15; i3++) {
661 for (i4 = 0; i4 < 15; i4++) {
663 if (_caps[i1][i1][i3][i4] != 0.0)
668 for (i1 = 0; i1 < 15; i1++) {
669 for (i3 = 0; i3 < 15; i3++) {
670 if (_caps[i1][i1][i3][i3] != 0.0)
676 matrix jkff_SR::calcMatrixCy (nr_double_t frequency)
716 for (
int i1 = 0; i1 < 15; i1++) {
718 setCV (i1, _chs[i1]);
719 setGV (i1, _ghs[i1]);
720 for (
int i2 = 0; i2 < 15; i2++) {
721 setQV (i1, i2, _jdyna[i1][i2]);