16 #include "component.h"
21 #define CIR_pad3bit -1
31 #define NP(node) real (getV (node))
32 #define BP(pnode,nnode) (NP(pnode) - NP(nnode))
33 #define _load_static_residual2(pnode,nnode,current)\
34 _rhs[pnode] -= current;\
35 _rhs[nnode] += current;
36 #define _load_static_augmented_residual2(pnode,nnode,current)\
37 _rhs[pnode] -= current;\
38 _rhs[nnode] += current;
39 #define _load_static_residual1(node,current)\
40 _rhs[node] -= current;
41 #define _load_static_augmented_residual1(node,current)\
42 _rhs[node] -= current;
43 #define _load_static_jacobian4(pnode,nnode,vpnode,vnnode,conductance)\
44 _jstat[pnode][vpnode] += conductance;\
45 _jstat[nnode][vnnode] += conductance;\
46 _jstat[pnode][vnnode] -= conductance;\
47 _jstat[nnode][vpnode] -= conductance;\
49 _ghs[pnode] += conductance * BP(vpnode,vnnode);\
50 _ghs[nnode] -= conductance * BP(vpnode,vnnode);\
52 _rhs[pnode] += conductance * BP(vpnode,vnnode);\
53 _rhs[nnode] -= conductance * BP(vpnode,vnnode);\
55 #define _load_static_jacobian2p(node,vpnode,vnnode,conductance)\
56 _jstat[node][vpnode] += conductance;\
57 _jstat[node][vnnode] -= conductance;\
59 _ghs[node] += conductance * BP(vpnode,vnnode);\
61 _rhs[node] += conductance * BP(vpnode,vnnode);\
63 #define _load_static_jacobian2s(pnode,nnode,node,conductance)\
64 _jstat[pnode][node] += conductance;\
65 _jstat[nnode][node] -= conductance;\
67 _ghs[pnode] += conductance * NP(node);\
68 _ghs[nnode] -= conductance * NP(node);\
70 _rhs[pnode] += conductance * NP(node);\
71 _rhs[nnode] -= conductance * NP(node);\
73 #define _load_static_jacobian1(node,vnode,conductance)\
74 _jstat[node][vnode] += conductance;\
76 _ghs[node] += conductance * NP(vnode);\
78 _rhs[node] += conductance * NP(vnode);\
80 #define _load_dynamic_residual2(pnode,nnode,charge)\
81 if (doTR) _charges[pnode][nnode] += charge;\
83 _qhs[pnode] -= charge;\
84 _qhs[nnode] += charge;\
86 #define _load_dynamic_residual1(node,charge)\
87 if (doTR) _charges[node][node] += charge;\
89 _qhs[node] -= charge;\
91 #define _load_dynamic_jacobian4(pnode,nnode,vpnode,vnnode,capacitance)\
93 _jdyna[pnode][vpnode] += capacitance;\
94 _jdyna[nnode][vnnode] += capacitance;\
95 _jdyna[pnode][vnnode] -= capacitance;\
96 _jdyna[nnode][vpnode] -= capacitance;\
99 _caps[pnode][nnode][vpnode][vnnode] += capacitance;\
102 _chs[pnode] += capacitance * BP(vpnode,vnnode);\
103 _chs[nnode] -= capacitance * BP(vpnode,vnnode);\
105 #define _load_dynamic_jacobian2s(pnode,nnode,vnode,capacitance)\
107 _jdyna[pnode][vnode] += capacitance;\
108 _jdyna[nnode][vnode] -= capacitance;\
111 _caps[pnode][nnode][vnode][vnode] += capacitance;\
114 _chs[pnode] += capacitance * NP(vnode);\
115 _chs[nnode] -= capacitance * NP(vnode);\
117 #define _load_dynamic_jacobian2p(node,vpnode,vnnode,capacitance)\
119 _jdyna[node][vpnode] += capacitance;\
120 _jdyna[node][vnnode] -= capacitance;\
123 _caps[node][node][vpnode][vnnode] += capacitance;\
126 _chs[node] += capacitance * BP(vpnode,vnnode);\
128 #define _load_dynamic_jacobian1(node,vnode,capacitance)\
130 _jdyna[node][vnode] += capacitance;\
133 _caps[node][node][vnode][vnode] += capacitance;\
136 _chs[node] += capacitance * NP(vnode);\
139 #define _save_whitenoise1(n1,pwr,type)\
140 _white_pwr[n1][n1] += pwr;
141 #define _save_whitenoise2(n1,n2,pwr,type)\
142 _white_pwr[n1][n2] += pwr;
143 #define _save_flickernoise1(n1,pwr,exp,type)\
144 _flicker_pwr[n1][n1] += pwr;\
145 _flicker_exp[n1][n1] += exp;
146 #define _save_flickernoise2(n1,n2,pwr,exp,type)\
147 _flicker_pwr[n1][n2] += pwr;\
148 _flicker_exp[n1][n2] += exp;
149 #define _load_whitenoise2(n1,n2,pwr)\
150 cy (n1,n2) -= pwr/kB/T0; cy (n2,n1) -= pwr/kB/T0;\
151 cy (n1,n1) += pwr/kB/T0; cy (n2,n2) += pwr/kB/T0;
152 #define _load_whitenoise1(n1,pwr)\
153 cy (n1,n1) += pwr/kB/T0;
154 #define _load_flickernoise2(n1,n2,pwr,exp)\
155 cy (n1,n2) -= pwr*pow(_freq,-exp)/kB/T0;\
156 cy (n2,n1) -= pwr*pow(_freq,-exp)/kB/T0;\
157 cy (n1,n1) += pwr*pow(_freq,-exp)/kB/T0;\
158 cy (n2,n2) += pwr*pow(_freq,-exp)/kB/T0;
159 #define _load_flickernoise1(n1,pwr,exp)\
160 cy (n1,n1) += pwr*pow(_freq,-exp)/kB/T0;
163 #define m00_hypot(v00,x,y) v00 = xhypot(x,y);
164 #define m10_hypot(v10,v00,x,y) v10 = (x)/(v00);
165 #define m11_hypot(v11,v00,x,y) v11 = (y)/(v00);
166 #define m00_max(v00,x,y) v00 = ((x)>(y))?(x):(y);
167 #define m10_max(v10,v00,x,y) v10 = ((x)>(y))?1.0:0.0;
168 #define m11_max(v11,v00,x,y) v11 = ((x)>(y))?0.0:1.0;
169 #define m00_min(v00,x,y) v00 = ((x)<(y))?(x):(y);
170 #define m10_min(v10,v00,x,y) v10 = ((x)<(y))?1.0:0.0;
171 #define m11_min(v11,v00,x,y) v11 = ((x)<(y))?0.0:1.0;
172 #define m00_pow(v00,x,y) v00 = pow(x,y);
173 #define m10_pow(v10,v00,x,y) v10 = (x==0.0)?0.0:(v00)*(y)/(x);
174 #define m11_pow(v11,v00,x,y) v11 = (x==0.0)?0.0:(log(x)*(v00));
176 #define m00_div(v00,v10,x,y) double v10=1/(y); double v00=(x)*v10;
177 #define m10_div(v10,v00,vv,x,y)
178 #define m11_div(v11,v00,vv,x,y) double v11 = -v00*vv;
180 #define m00_mult(v00,v10,v11,x,y) double v10=(x); double v11=(y); double v00=v10*v11;
181 #define m00_add(v00,x,y) double v00=(x)+(y);
183 #define m00_cos(v00,x) v00 = cos(x);
184 #define m10_cos(v10,v00,x) v10 = (-sin(x));
185 #define m00_sin(v00,x) v00 = sin(x);
186 #define m10_sin(v10,v00,x) v10 = (cos(x));
187 #define m00_tan(v00,x) v00 = tan(x);
188 #define m10_tan(v10,v00,x) v10 = (1.0/cos(x)/cos(x));
189 #define m00_cosh(v00,x) v00 = cosh(x);
190 #define m10_cosh(v10,v00,x) v10 = (sinh(x));
191 #define m00_sinh(v00,x) v00 = sinh(x);
192 #define m10_sinh(v10,v00,x) v10 = (cosh(x));
193 #define m00_tanh(v00,x) v00 = tanh(x);
194 #define m10_tanh(v10,v00,x) v10 = (1.0/cosh(x)/cosh(x));
195 #define m00_acos(v00,x) v00 = acos(x);
196 #define m10_acos(v10,v00,x) v10 = (-1.0/sqrt(1-x*x));
197 #define m00_asin(v00,x) v00 = asin(x);
198 #define m10_asin(v10,v00,x) v10 = (+1.0/sqrt(1-x*x));
199 #define m00_atan(v00,x) v00 = atan(x);
200 #define m10_atan(v10,v00,x) v10 = (+1.0/(1+x*x));
201 #define m00_atanh(v00,x) v00 = atanh(x);
202 #define m10_atanh(v10,v00,x) v10 = (+1.0/(1-x*x));
203 #define m00_logE(v00,x) v00 = log(x);
204 #define m10_logE(v10,v00,x) v10 = (1.0/x);
205 #define m00_log10(v00,x) v00 = log10(x);
206 #define m10_log10(v10,v00,x) v10 = (1.0/x/M_LN10);
207 #define m00_sqrt(v00,x) v00 = sqrt(x);
208 #define m10_sqrt(v10,v00,x) v10 = (0.5/v00);
209 #define m00_fabs(v00,x) v00 = fabs(x);
210 #define m10_fabs(v10,v00,x) v10 = (((x)>=0)?(+1.0):(-1.0));
212 #define m00_exp(v00,x) v00 = exp(x);
213 #define m10_exp(v10,v00,x) v10 = v00;
215 #define m00_abs(v00) ((v00)<(0)?(-(v00)):(v00))
216 #define m00_floor(v00,x) v00 = floor(x);
217 #define m00_limexp(v00,x) v00 = ((x)<80.0?exp(x):exp(80.0)*(x-79.0));
218 #define m10_limexp(v10,v00,x) v10 = ((x)<80.0?(v00):exp(80.0));
220 #define m20_logE(v00) (-1.0/v00/v00)
221 #define m20_exp(v00) exp(v00)
222 #define m20_limexp(v00) ((v00)<80.0?exp(v00):0.0)
223 #define m20_sqrt(v00) (-0.25/(v00)/sqrt(v00))
224 #define m20_fabs(v00) 0.0
225 #define m20_pow(x,y) ((y)*((y)-1.0)*pow(x,y)/(x)/(x))
226 #define m00_vt(x) (kBoverQ*(x))
227 #define m10_vt(x) (kBoverQ)
230 #define _modelname "pad3bit"
231 #define _instancename getName()
232 #define _circuit_temp (getPropertyDouble("Temp")+273.15)
233 #define _param_given(p) (isPropertyGiven(p)?1:0)
237 #define _vt_nom (kBoverQ*_circuit_temp)
239 using namespace device;
248 void pad3bit::initModel (
void)
259 initializeInstance ();
280 void pad3bit::initVerilog (
void)
287 for (i1 = 0; i1 < 3; i1++) {
288 for (i2 = 0; i2 < 3; i2++) {
289 _charges[i1][i2] = 0.0;
293 for (i1 = 0; i1 < 3; i1++) {
294 for (i2 = 0; i2 < 3; i2++) {
295 for (i3 = 0; i3 < 3; i3++) {
296 for (i4 = 0; i4 < 3; i4++) {
297 _caps[i1][i2][i3][i4] = 0.0;
301 for (i1 = 0; i1 < 3; i1++) {
306 for (i2 = 0; i2 < 3; i2++) {
307 _jstat[i1][i2] = 0.0;
308 _jdyna[i1][i2] = 0.0;
314 void pad3bit::loadVariables (
void)
325 #define _DERIVATEFORDDX
328 void pad3bit::initializeModel (
void)
333 void pad3bit::initializeInstance (
void)
338 void pad3bit::initialStep (
void)
343 void pad3bit::finalStep (
void)
348 void pad3bit::calcVerilog (
void)
421 #if defined(_DERIVATE)
424 #if defined(_DERIVATE)
428 #if defined(_DERIVATE)
431 #if defined(_DERIVATE)
435 #if defined(_DERIVATE)
438 #if defined(_DERIVATE)
457 for (
int i1 = 0; i1 < 3; i1++) {
459 for (
int i2 = 0; i2 < 3; i2++) {
460 setY (i1, i2, _jstat[i1][i2]);
494 matrix pad3bit::calcMatrixY (nr_double_t frequency)
500 for (
int i1 = 0; i1 < 3; i1++) {
501 for (
int i2 = 0; i2 < 3; i2++) {
502 y (i1,i2) =
rect (_jstat[i1][i2], _jdyna[i1][i2] * 2 *
M_PI * _freq);
536 int i1, i2, i3, i4, state;
539 for (i1 = 0; i1 < 3; i1++) {
540 for (i2 = 0; i2 < 3; i2++) {
541 state = 2 * (i2 + 3 * i1);
543 if (_charges[i1][i2] != 0.0)
548 for (i1 = 0; i1 < 3; i1++) {
549 state = 2 * (i1 + 3 * i1);
550 if (_charges[i1][i1] != 0.0)
555 for (i1 = 0; i1 < 3; i1++) {
556 for (i2 = 0; i2 < 3; i2++) {
558 for (i3 = 0; i3 < 3; i3++) {
559 for (i4 = 0; i4 < 3; i4++) {
561 if (_caps[i1][i2][i3][i4] != 0.0)
566 for (i1 = 0; i1 < 3; i1++) {
567 for (i2 = 0; i2 < 3; i2++) {
569 for (i3 = 0; i3 < 3; i3++) {
570 if (_caps[i1][i2][i3][i3] != 0.0)
575 for (i1 = 0; i1 < 3; i1++) {
576 for (i3 = 0; i3 < 3; i3++) {
577 for (i4 = 0; i4 < 3; i4++) {
579 if (_caps[i1][i1][i3][i4] != 0.0)
584 for (i1 = 0; i1 < 3; i1++) {
585 for (i3 = 0; i3 < 3; i3++) {
586 if (_caps[i1][i1][i3][i3] != 0.0)
592 matrix pad3bit::calcMatrixCy (nr_double_t frequency)
632 for (
int i1 = 0; i1 < 3; i1++) {
634 setCV (i1, _chs[i1]);
635 setGV (i1, _ghs[i1]);
636 for (
int i2 = 0; i2 < 3; i2++) {
637 setQV (i1, i2, _jdyna[i1][i2]);