16 #include "component.h"
36 #define NP(node) real (getV (node))
37 #define BP(pnode,nnode) (NP(pnode) - NP(nnode))
38 #define _load_static_residual2(pnode,nnode,current)\
39 _rhs[pnode] -= current;\
40 _rhs[nnode] += current;
41 #define _load_static_augmented_residual2(pnode,nnode,current)\
42 _rhs[pnode] -= current;\
43 _rhs[nnode] += current;
44 #define _load_static_residual1(node,current)\
45 _rhs[node] -= current;
46 #define _load_static_augmented_residual1(node,current)\
47 _rhs[node] -= current;
48 #define _load_static_jacobian4(pnode,nnode,vpnode,vnnode,conductance)\
49 _jstat[pnode][vpnode] += conductance;\
50 _jstat[nnode][vnnode] += conductance;\
51 _jstat[pnode][vnnode] -= conductance;\
52 _jstat[nnode][vpnode] -= conductance;\
54 _ghs[pnode] += conductance * BP(vpnode,vnnode);\
55 _ghs[nnode] -= conductance * BP(vpnode,vnnode);\
57 _rhs[pnode] += conductance * BP(vpnode,vnnode);\
58 _rhs[nnode] -= conductance * BP(vpnode,vnnode);\
60 #define _load_static_jacobian2p(node,vpnode,vnnode,conductance)\
61 _jstat[node][vpnode] += conductance;\
62 _jstat[node][vnnode] -= conductance;\
64 _ghs[node] += conductance * BP(vpnode,vnnode);\
66 _rhs[node] += conductance * BP(vpnode,vnnode);\
68 #define _load_static_jacobian2s(pnode,nnode,node,conductance)\
69 _jstat[pnode][node] += conductance;\
70 _jstat[nnode][node] -= conductance;\
72 _ghs[pnode] += conductance * NP(node);\
73 _ghs[nnode] -= conductance * NP(node);\
75 _rhs[pnode] += conductance * NP(node);\
76 _rhs[nnode] -= conductance * NP(node);\
78 #define _load_static_jacobian1(node,vnode,conductance)\
79 _jstat[node][vnode] += conductance;\
81 _ghs[node] += conductance * NP(vnode);\
83 _rhs[node] += conductance * NP(vnode);\
85 #define _load_dynamic_residual2(pnode,nnode,charge)\
86 if (doTR) _charges[pnode][nnode] += charge;\
88 _qhs[pnode] -= charge;\
89 _qhs[nnode] += charge;\
91 #define _load_dynamic_residual1(node,charge)\
92 if (doTR) _charges[node][node] += charge;\
94 _qhs[node] -= charge;\
96 #define _load_dynamic_jacobian4(pnode,nnode,vpnode,vnnode,capacitance)\
98 _jdyna[pnode][vpnode] += capacitance;\
99 _jdyna[nnode][vnnode] += capacitance;\
100 _jdyna[pnode][vnnode] -= capacitance;\
101 _jdyna[nnode][vpnode] -= capacitance;\
104 _caps[pnode][nnode][vpnode][vnnode] += capacitance;\
107 _chs[pnode] += capacitance * BP(vpnode,vnnode);\
108 _chs[nnode] -= capacitance * BP(vpnode,vnnode);\
110 #define _load_dynamic_jacobian2s(pnode,nnode,vnode,capacitance)\
112 _jdyna[pnode][vnode] += capacitance;\
113 _jdyna[nnode][vnode] -= capacitance;\
116 _caps[pnode][nnode][vnode][vnode] += capacitance;\
119 _chs[pnode] += capacitance * NP(vnode);\
120 _chs[nnode] -= capacitance * NP(vnode);\
122 #define _load_dynamic_jacobian2p(node,vpnode,vnnode,capacitance)\
124 _jdyna[node][vpnode] += capacitance;\
125 _jdyna[node][vnnode] -= capacitance;\
128 _caps[node][node][vpnode][vnnode] += capacitance;\
131 _chs[node] += capacitance * BP(vpnode,vnnode);\
133 #define _load_dynamic_jacobian1(node,vnode,capacitance)\
135 _jdyna[node][vnode] += capacitance;\
138 _caps[node][node][vnode][vnode] += capacitance;\
141 _chs[node] += capacitance * NP(vnode);\
144 #define _save_whitenoise1(n1,pwr,type)\
145 _white_pwr[n1][n1] += pwr;
146 #define _save_whitenoise2(n1,n2,pwr,type)\
147 _white_pwr[n1][n2] += pwr;
148 #define _save_flickernoise1(n1,pwr,exp,type)\
149 _flicker_pwr[n1][n1] += pwr;\
150 _flicker_exp[n1][n1] += exp;
151 #define _save_flickernoise2(n1,n2,pwr,exp,type)\
152 _flicker_pwr[n1][n2] += pwr;\
153 _flicker_exp[n1][n2] += exp;
154 #define _load_whitenoise2(n1,n2,pwr)\
155 cy (n1,n2) -= pwr/kB/T0; cy (n2,n1) -= pwr/kB/T0;\
156 cy (n1,n1) += pwr/kB/T0; cy (n2,n2) += pwr/kB/T0;
157 #define _load_whitenoise1(n1,pwr)\
158 cy (n1,n1) += pwr/kB/T0;
159 #define _load_flickernoise2(n1,n2,pwr,exp)\
160 cy (n1,n2) -= pwr*pow(_freq,-exp)/kB/T0;\
161 cy (n2,n1) -= pwr*pow(_freq,-exp)/kB/T0;\
162 cy (n1,n1) += pwr*pow(_freq,-exp)/kB/T0;\
163 cy (n2,n2) += pwr*pow(_freq,-exp)/kB/T0;
164 #define _load_flickernoise1(n1,pwr,exp)\
165 cy (n1,n1) += pwr*pow(_freq,-exp)/kB/T0;
168 #define m00_hypot(v00,x,y) v00 = xhypot(x,y);
169 #define m10_hypot(v10,v00,x,y) v10 = (x)/(v00);
170 #define m11_hypot(v11,v00,x,y) v11 = (y)/(v00);
171 #define m00_max(v00,x,y) v00 = ((x)>(y))?(x):(y);
172 #define m10_max(v10,v00,x,y) v10 = ((x)>(y))?1.0:0.0;
173 #define m11_max(v11,v00,x,y) v11 = ((x)>(y))?0.0:1.0;
174 #define m00_min(v00,x,y) v00 = ((x)<(y))?(x):(y);
175 #define m10_min(v10,v00,x,y) v10 = ((x)<(y))?1.0:0.0;
176 #define m11_min(v11,v00,x,y) v11 = ((x)<(y))?0.0:1.0;
177 #define m00_pow(v00,x,y) v00 = pow(x,y);
178 #define m10_pow(v10,v00,x,y) v10 = (x==0.0)?0.0:(v00)*(y)/(x);
179 #define m11_pow(v11,v00,x,y) v11 = (x==0.0)?0.0:(log(x)*(v00));
181 #define m00_div(v00,v10,x,y) double v10=1/(y); double v00=(x)*v10;
182 #define m10_div(v10,v00,vv,x,y)
183 #define m11_div(v11,v00,vv,x,y) double v11 = -v00*vv;
185 #define m00_mult(v00,v10,v11,x,y) double v10=(x); double v11=(y); double v00=v10*v11;
186 #define m00_add(v00,x,y) double v00=(x)+(y);
188 #define m00_cos(v00,x) v00 = cos(x);
189 #define m10_cos(v10,v00,x) v10 = (-sin(x));
190 #define m00_sin(v00,x) v00 = sin(x);
191 #define m10_sin(v10,v00,x) v10 = (cos(x));
192 #define m00_tan(v00,x) v00 = tan(x);
193 #define m10_tan(v10,v00,x) v10 = (1.0/cos(x)/cos(x));
194 #define m00_cosh(v00,x) v00 = cosh(x);
195 #define m10_cosh(v10,v00,x) v10 = (sinh(x));
196 #define m00_sinh(v00,x) v00 = sinh(x);
197 #define m10_sinh(v10,v00,x) v10 = (cosh(x));
198 #define m00_tanh(v00,x) v00 = tanh(x);
199 #define m10_tanh(v10,v00,x) v10 = (1.0/cosh(x)/cosh(x));
200 #define m00_acos(v00,x) v00 = acos(x);
201 #define m10_acos(v10,v00,x) v10 = (-1.0/sqrt(1-x*x));
202 #define m00_asin(v00,x) v00 = asin(x);
203 #define m10_asin(v10,v00,x) v10 = (+1.0/sqrt(1-x*x));
204 #define m00_atan(v00,x) v00 = atan(x);
205 #define m10_atan(v10,v00,x) v10 = (+1.0/(1+x*x));
206 #define m00_atanh(v00,x) v00 = atanh(x);
207 #define m10_atanh(v10,v00,x) v10 = (+1.0/(1-x*x));
208 #define m00_logE(v00,x) v00 = log(x);
209 #define m10_logE(v10,v00,x) v10 = (1.0/x);
210 #define m00_log10(v00,x) v00 = log10(x);
211 #define m10_log10(v10,v00,x) v10 = (1.0/x/M_LN10);
212 #define m00_sqrt(v00,x) v00 = sqrt(x);
213 #define m10_sqrt(v10,v00,x) v10 = (0.5/v00);
214 #define m00_fabs(v00,x) v00 = fabs(x);
215 #define m10_fabs(v10,v00,x) v10 = (((x)>=0)?(+1.0):(-1.0));
217 #define m00_exp(v00,x) v00 = exp(x);
218 #define m10_exp(v10,v00,x) v10 = v00;
220 #define m00_abs(v00) ((v00)<(0)?(-(v00)):(v00))
221 #define m00_floor(v00,x) v00 = floor(x);
222 #define m00_limexp(v00,x) v00 = ((x)<80.0?exp(x):exp(80.0)*(x-79.0));
223 #define m10_limexp(v10,v00,x) v10 = ((x)<80.0?(v00):exp(80.0));
225 #define m20_logE(v00) (-1.0/v00/v00)
226 #define m20_exp(v00) exp(v00)
227 #define m20_limexp(v00) ((v00)<80.0?exp(v00):0.0)
228 #define m20_sqrt(v00) (-0.25/(v00)/sqrt(v00))
229 #define m20_fabs(v00) 0.0
230 #define m20_pow(x,y) ((y)*((y)-1.0)*pow(x,y)/(x)/(x))
231 #define m00_vt(x) (kBoverQ*(x))
232 #define m10_vt(x) (kBoverQ)
235 #define _modelname "ha1b"
236 #define _instancename getName()
237 #define _circuit_temp (getPropertyDouble("Temp")+273.15)
238 #define _param_given(p) (isPropertyGiven(p)?1:0)
242 #define _vt_nom (kBoverQ*_circuit_temp)
244 using namespace device;
253 void ha1b::initModel (
void)
268 initializeInstance ();
289 void ha1b::initVerilog (
void)
296 for (i1 = 0; i1 < 8; i1++) {
297 for (i2 = 0; i2 < 8; i2++) {
298 _charges[i1][i2] = 0.0;
302 for (i1 = 0; i1 < 8; i1++) {
303 for (i2 = 0; i2 < 8; i2++) {
304 for (i3 = 0; i3 < 8; i3++) {
305 for (i4 = 0; i4 < 8; i4++) {
306 _caps[i1][i2][i3][i4] = 0.0;
310 for (i1 = 0; i1 < 8; i1++) {
315 for (i2 = 0; i2 < 8; i2++) {
316 _jstat[i1][i2] = 0.0;
317 _jdyna[i1][i2] = 0.0;
323 void ha1b::loadVariables (
void)
335 #define _DERIVATEFORDDX
338 void ha1b::initializeModel (
void)
340 #if defined(_DYNAMIC)
344 #if defined(_DYNAMIC)
345 Cd=((Delay*1.43)/Rd);
351 void ha1b::initializeInstance (
void)
356 void ha1b::initialStep (
void)
361 void ha1b::finalStep (
void)
366 void ha1b::calcVerilog (
void)
371 #if defined(_DERIVATE)
376 #if defined(_DERIVATE)
380 #if defined(_DERIVATE)
385 #if defined(_DERIVATE)
386 IS_VA_GND=(((1-
NP(
B)))+(-1.0)*
NP(
B));
387 IS_VB_GND=((
NP(
A)*(-1.0))+((1-
NP(
A))));
393 #if defined(_DERIVATE)
401 #if defined(_DERIVATE)
410 #if defined(_DERIVATE)
418 #if defined(_DERIVATE)
425 double m00_tanh(d00_tanh0,(TR*(IS-0.5)))
426 #if defined(_DERIVATE)
427 double m10_tanh(d10_tanh0,d00_tanh0,(TR*(IS-0.5)))
430 #if defined(_DERIVATE)
436 #if defined(_DERIVATE)
440 #if defined(_DERIVATE)
443 #if defined(_DYNAMIC)
445 #if defined(_DERIVATE)
450 #if defined(_DERIVATE)
454 #if defined(_DERIVATE)
458 double m00_tanh(d00_tanh0,(TR*(ICO-0.5)))
459 #if defined(_DERIVATE)
460 double m10_tanh(d10_tanh0,d00_tanh0,(TR*(ICO-0.5)))
463 #if defined(_DERIVATE)
469 #if defined(_DERIVATE)
473 #if defined(_DERIVATE)
476 #if defined(_DYNAMIC)
478 #if defined(_DERIVATE)
483 #if defined(_DERIVATE)
487 #if defined(_DERIVATE)
506 for (
int i1 = 0; i1 < 8; i1++) {
508 for (
int i2 = 0; i2 < 8; i2++) {
509 setY (i1, i2, _jstat[i1][i2]);
543 matrix ha1b::calcMatrixY (nr_double_t frequency)
549 for (
int i1 = 0; i1 < 8; i1++) {
550 for (
int i2 = 0; i2 < 8; i2++) {
551 y (i1,i2) =
rect (_jstat[i1][i2], _jdyna[i1][i2] * 2 *
M_PI * _freq);
585 int i1, i2, i3, i4, state;
588 for (i1 = 0; i1 < 8; i1++) {
589 for (i2 = 0; i2 < 8; i2++) {
590 state = 2 * (i2 + 8 * i1);
592 if (_charges[i1][i2] != 0.0)
597 for (i1 = 0; i1 < 8; i1++) {
598 state = 2 * (i1 + 8 * i1);
599 if (_charges[i1][i1] != 0.0)
604 for (i1 = 0; i1 < 8; i1++) {
605 for (i2 = 0; i2 < 8; i2++) {
607 for (i3 = 0; i3 < 8; i3++) {
608 for (i4 = 0; i4 < 8; i4++) {
610 if (_caps[i1][i2][i3][i4] != 0.0)
615 for (i1 = 0; i1 < 8; i1++) {
616 for (i2 = 0; i2 < 8; i2++) {
618 for (i3 = 0; i3 < 8; i3++) {
619 if (_caps[i1][i2][i3][i3] != 0.0)
624 for (i1 = 0; i1 < 8; i1++) {
625 for (i3 = 0; i3 < 8; i3++) {
626 for (i4 = 0; i4 < 8; i4++) {
628 if (_caps[i1][i1][i3][i4] != 0.0)
633 for (i1 = 0; i1 < 8; i1++) {
634 for (i3 = 0; i3 < 8; i3++) {
635 if (_caps[i1][i1][i3][i3] != 0.0)
641 matrix ha1b::calcMatrixCy (nr_double_t frequency)
681 for (
int i1 = 0; i1 < 8; i1++) {
683 setCV (i1, _chs[i1]);
684 setGV (i1, _ghs[i1]);
685 for (
int i2 = 0; i2 < 8; i2++) {
686 setQV (i1, i2, _jdyna[i1][i2]);