16 #include "component.h"
21 #define CIR_logic_0 -1
29 #define NP(node) real (getV (node))
30 #define BP(pnode,nnode) (NP(pnode) - NP(nnode))
31 #define _load_static_residual2(pnode,nnode,current)\
32 _rhs[pnode] -= current;\
33 _rhs[nnode] += current;
34 #define _load_static_augmented_residual2(pnode,nnode,current)\
35 _rhs[pnode] -= current;\
36 _rhs[nnode] += current;
37 #define _load_static_residual1(node,current)\
38 _rhs[node] -= current;
39 #define _load_static_augmented_residual1(node,current)\
40 _rhs[node] -= current;
41 #define _load_static_jacobian4(pnode,nnode,vpnode,vnnode,conductance)\
42 _jstat[pnode][vpnode] += conductance;\
43 _jstat[nnode][vnnode] += conductance;\
44 _jstat[pnode][vnnode] -= conductance;\
45 _jstat[nnode][vpnode] -= conductance;\
47 _ghs[pnode] += conductance * BP(vpnode,vnnode);\
48 _ghs[nnode] -= conductance * BP(vpnode,vnnode);\
50 _rhs[pnode] += conductance * BP(vpnode,vnnode);\
51 _rhs[nnode] -= conductance * BP(vpnode,vnnode);\
53 #define _load_static_jacobian2p(node,vpnode,vnnode,conductance)\
54 _jstat[node][vpnode] += conductance;\
55 _jstat[node][vnnode] -= conductance;\
57 _ghs[node] += conductance * BP(vpnode,vnnode);\
59 _rhs[node] += conductance * BP(vpnode,vnnode);\
61 #define _load_static_jacobian2s(pnode,nnode,node,conductance)\
62 _jstat[pnode][node] += conductance;\
63 _jstat[nnode][node] -= conductance;\
65 _ghs[pnode] += conductance * NP(node);\
66 _ghs[nnode] -= conductance * NP(node);\
68 _rhs[pnode] += conductance * NP(node);\
69 _rhs[nnode] -= conductance * NP(node);\
71 #define _load_static_jacobian1(node,vnode,conductance)\
72 _jstat[node][vnode] += conductance;\
74 _ghs[node] += conductance * NP(vnode);\
76 _rhs[node] += conductance * NP(vnode);\
78 #define _load_dynamic_residual2(pnode,nnode,charge)\
79 if (doTR) _charges[pnode][nnode] += charge;\
81 _qhs[pnode] -= charge;\
82 _qhs[nnode] += charge;\
84 #define _load_dynamic_residual1(node,charge)\
85 if (doTR) _charges[node][node] += charge;\
87 _qhs[node] -= charge;\
89 #define _load_dynamic_jacobian4(pnode,nnode,vpnode,vnnode,capacitance)\
91 _jdyna[pnode][vpnode] += capacitance;\
92 _jdyna[nnode][vnnode] += capacitance;\
93 _jdyna[pnode][vnnode] -= capacitance;\
94 _jdyna[nnode][vpnode] -= capacitance;\
97 _caps[pnode][nnode][vpnode][vnnode] += capacitance;\
100 _chs[pnode] += capacitance * BP(vpnode,vnnode);\
101 _chs[nnode] -= capacitance * BP(vpnode,vnnode);\
103 #define _load_dynamic_jacobian2s(pnode,nnode,vnode,capacitance)\
105 _jdyna[pnode][vnode] += capacitance;\
106 _jdyna[nnode][vnode] -= capacitance;\
109 _caps[pnode][nnode][vnode][vnode] += capacitance;\
112 _chs[pnode] += capacitance * NP(vnode);\
113 _chs[nnode] -= capacitance * NP(vnode);\
115 #define _load_dynamic_jacobian2p(node,vpnode,vnnode,capacitance)\
117 _jdyna[node][vpnode] += capacitance;\
118 _jdyna[node][vnnode] -= capacitance;\
121 _caps[node][node][vpnode][vnnode] += capacitance;\
124 _chs[node] += capacitance * BP(vpnode,vnnode);\
126 #define _load_dynamic_jacobian1(node,vnode,capacitance)\
128 _jdyna[node][vnode] += capacitance;\
131 _caps[node][node][vnode][vnode] += capacitance;\
134 _chs[node] += capacitance * NP(vnode);\
137 #define _save_whitenoise1(n1,pwr,type)\
138 _white_pwr[n1][n1] += pwr;
139 #define _save_whitenoise2(n1,n2,pwr,type)\
140 _white_pwr[n1][n2] += pwr;
141 #define _save_flickernoise1(n1,pwr,exp,type)\
142 _flicker_pwr[n1][n1] += pwr;\
143 _flicker_exp[n1][n1] += exp;
144 #define _save_flickernoise2(n1,n2,pwr,exp,type)\
145 _flicker_pwr[n1][n2] += pwr;\
146 _flicker_exp[n1][n2] += exp;
147 #define _load_whitenoise2(n1,n2,pwr)\
148 cy (n1,n2) -= pwr/kB/T0; cy (n2,n1) -= pwr/kB/T0;\
149 cy (n1,n1) += pwr/kB/T0; cy (n2,n2) += pwr/kB/T0;
150 #define _load_whitenoise1(n1,pwr)\
151 cy (n1,n1) += pwr/kB/T0;
152 #define _load_flickernoise2(n1,n2,pwr,exp)\
153 cy (n1,n2) -= pwr*pow(_freq,-exp)/kB/T0;\
154 cy (n2,n1) -= pwr*pow(_freq,-exp)/kB/T0;\
155 cy (n1,n1) += pwr*pow(_freq,-exp)/kB/T0;\
156 cy (n2,n2) += pwr*pow(_freq,-exp)/kB/T0;
157 #define _load_flickernoise1(n1,pwr,exp)\
158 cy (n1,n1) += pwr*pow(_freq,-exp)/kB/T0;
161 #define m00_hypot(v00,x,y) v00 = xhypot(x,y);
162 #define m10_hypot(v10,v00,x,y) v10 = (x)/(v00);
163 #define m11_hypot(v11,v00,x,y) v11 = (y)/(v00);
164 #define m00_max(v00,x,y) v00 = ((x)>(y))?(x):(y);
165 #define m10_max(v10,v00,x,y) v10 = ((x)>(y))?1.0:0.0;
166 #define m11_max(v11,v00,x,y) v11 = ((x)>(y))?0.0:1.0;
167 #define m00_min(v00,x,y) v00 = ((x)<(y))?(x):(y);
168 #define m10_min(v10,v00,x,y) v10 = ((x)<(y))?1.0:0.0;
169 #define m11_min(v11,v00,x,y) v11 = ((x)<(y))?0.0:1.0;
170 #define m00_pow(v00,x,y) v00 = pow(x,y);
171 #define m10_pow(v10,v00,x,y) v10 = (x==0.0)?0.0:(v00)*(y)/(x);
172 #define m11_pow(v11,v00,x,y) v11 = (x==0.0)?0.0:(log(x)*(v00));
174 #define m00_div(v00,v10,x,y) double v10=1/(y); double v00=(x)*v10;
175 #define m10_div(v10,v00,vv,x,y)
176 #define m11_div(v11,v00,vv,x,y) double v11 = -v00*vv;
178 #define m00_mult(v00,v10,v11,x,y) double v10=(x); double v11=(y); double v00=v10*v11;
179 #define m00_add(v00,x,y) double v00=(x)+(y);
181 #define m00_cos(v00,x) v00 = cos(x);
182 #define m10_cos(v10,v00,x) v10 = (-sin(x));
183 #define m00_sin(v00,x) v00 = sin(x);
184 #define m10_sin(v10,v00,x) v10 = (cos(x));
185 #define m00_tan(v00,x) v00 = tan(x);
186 #define m10_tan(v10,v00,x) v10 = (1.0/cos(x)/cos(x));
187 #define m00_cosh(v00,x) v00 = cosh(x);
188 #define m10_cosh(v10,v00,x) v10 = (sinh(x));
189 #define m00_sinh(v00,x) v00 = sinh(x);
190 #define m10_sinh(v10,v00,x) v10 = (cosh(x));
191 #define m00_tanh(v00,x) v00 = tanh(x);
192 #define m10_tanh(v10,v00,x) v10 = (1.0/cosh(x)/cosh(x));
193 #define m00_acos(v00,x) v00 = acos(x);
194 #define m10_acos(v10,v00,x) v10 = (-1.0/sqrt(1-x*x));
195 #define m00_asin(v00,x) v00 = asin(x);
196 #define m10_asin(v10,v00,x) v10 = (+1.0/sqrt(1-x*x));
197 #define m00_atan(v00,x) v00 = atan(x);
198 #define m10_atan(v10,v00,x) v10 = (+1.0/(1+x*x));
199 #define m00_atanh(v00,x) v00 = atanh(x);
200 #define m10_atanh(v10,v00,x) v10 = (+1.0/(1-x*x));
201 #define m00_logE(v00,x) v00 = log(x);
202 #define m10_logE(v10,v00,x) v10 = (1.0/x);
203 #define m00_log10(v00,x) v00 = log10(x);
204 #define m10_log10(v10,v00,x) v10 = (1.0/x/M_LN10);
205 #define m00_sqrt(v00,x) v00 = sqrt(x);
206 #define m10_sqrt(v10,v00,x) v10 = (0.5/v00);
207 #define m00_fabs(v00,x) v00 = fabs(x);
208 #define m10_fabs(v10,v00,x) v10 = (((x)>=0)?(+1.0):(-1.0));
210 #define m00_exp(v00,x) v00 = exp(x);
211 #define m10_exp(v10,v00,x) v10 = v00;
213 #define m00_abs(v00) ((v00)<(0)?(-(v00)):(v00))
214 #define m00_floor(v00,x) v00 = floor(x);
215 #define m00_limexp(v00,x) v00 = ((x)<80.0?exp(x):exp(80.0)*(x-79.0));
216 #define m10_limexp(v10,v00,x) v10 = ((x)<80.0?(v00):exp(80.0));
218 #define m20_logE(v00) (-1.0/v00/v00)
219 #define m20_exp(v00) exp(v00)
220 #define m20_limexp(v00) ((v00)<80.0?exp(v00):0.0)
221 #define m20_sqrt(v00) (-0.25/(v00)/sqrt(v00))
222 #define m20_fabs(v00) 0.0
223 #define m20_pow(x,y) ((y)*((y)-1.0)*pow(x,y)/(x)/(x))
224 #define m00_vt(x) (kBoverQ*(x))
225 #define m10_vt(x) (kBoverQ)
228 #define _modelname "logic_0"
229 #define _instancename getName()
230 #define _circuit_temp (getPropertyDouble("Temp")+273.15)
231 #define _param_given(p) (isPropertyGiven(p)?1:0)
235 #define _vt_nom (kBoverQ*_circuit_temp)
237 using namespace device;
246 void logic_0::initModel (
void)
257 initializeInstance ();
278 void logic_0::initVerilog (
void)
285 for (i1 = 0; i1 < 1; i1++) {
286 for (i2 = 0; i2 < 1; i2++) {
287 _charges[i1][i2] = 0.0;
291 for (i1 = 0; i1 < 1; i1++) {
292 for (i2 = 0; i2 < 1; i2++) {
293 for (i3 = 0; i3 < 1; i3++) {
294 for (i4 = 0; i4 < 1; i4++) {
295 _caps[i1][i2][i3][i4] = 0.0;
299 for (i1 = 0; i1 < 1; i1++) {
304 for (i2 = 0; i2 < 1; i2++) {
305 _jstat[i1][i2] = 0.0;
306 _jdyna[i1][i2] = 0.0;
312 void logic_0::loadVariables (
void)
323 #define _DERIVATEFORDDX
326 void logic_0::initializeModel (
void)
331 void logic_0::initializeInstance (
void)
336 void logic_0::initialStep (
void)
341 void logic_0::finalStep (
void)
346 void logic_0::calcVerilog (
void)
351 #if defined(_DERIVATE)
354 #if defined(_DERIVATE)
373 for (
int i1 = 0; i1 < 1; i1++) {
375 for (
int i2 = 0; i2 < 1; i2++) {
376 setY (i1, i2, _jstat[i1][i2]);
410 matrix logic_0::calcMatrixY (nr_double_t frequency)
416 for (
int i1 = 0; i1 < 1; i1++) {
417 for (
int i2 = 0; i2 < 1; i2++) {
418 y (i1,i2) =
rect (_jstat[i1][i2], _jdyna[i1][i2] * 2 *
M_PI * _freq);
452 int i1, i2, i3, i4, state;
455 for (i1 = 0; i1 < 1; i1++) {
456 for (i2 = 0; i2 < 1; i2++) {
457 state = 2 * (i2 + 1 * i1);
459 if (_charges[i1][i2] != 0.0)
464 for (i1 = 0; i1 < 1; i1++) {
465 state = 2 * (i1 + 1 * i1);
466 if (_charges[i1][i1] != 0.0)
471 for (i1 = 0; i1 < 1; i1++) {
472 for (i2 = 0; i2 < 1; i2++) {
474 for (i3 = 0; i3 < 1; i3++) {
475 for (i4 = 0; i4 < 1; i4++) {
477 if (_caps[i1][i2][i3][i4] != 0.0)
482 for (i1 = 0; i1 < 1; i1++) {
483 for (i2 = 0; i2 < 1; i2++) {
485 for (i3 = 0; i3 < 1; i3++) {
486 if (_caps[i1][i2][i3][i3] != 0.0)
491 for (i1 = 0; i1 < 1; i1++) {
492 for (i3 = 0; i3 < 1; i3++) {
493 for (i4 = 0; i4 < 1; i4++) {
495 if (_caps[i1][i1][i3][i4] != 0.0)
500 for (i1 = 0; i1 < 1; i1++) {
501 for (i3 = 0; i3 < 1; i3++) {
502 if (_caps[i1][i1][i3][i3] != 0.0)
508 matrix logic_0::calcMatrixCy (nr_double_t frequency)
548 for (
int i1 = 0; i1 < 1; i1++) {
550 setCV (i1, _chs[i1]);
551 setGV (i1, _ghs[i1]);
552 for (
int i2 = 0; i2 < 1; i2++) {
553 setQV (i1, i2, _jdyna[i1][i2]);