16 #include "component.h"
21 #define CIR_andor4x2 -1
39 #define NP(node) real (getV (node))
40 #define BP(pnode,nnode) (NP(pnode) - NP(nnode))
41 #define _load_static_residual2(pnode,nnode,current)\
42 _rhs[pnode] -= current;\
43 _rhs[nnode] += current;
44 #define _load_static_augmented_residual2(pnode,nnode,current)\
45 _rhs[pnode] -= current;\
46 _rhs[nnode] += current;
47 #define _load_static_residual1(node,current)\
48 _rhs[node] -= current;
49 #define _load_static_augmented_residual1(node,current)\
50 _rhs[node] -= current;
51 #define _load_static_jacobian4(pnode,nnode,vpnode,vnnode,conductance)\
52 _jstat[pnode][vpnode] += conductance;\
53 _jstat[nnode][vnnode] += conductance;\
54 _jstat[pnode][vnnode] -= conductance;\
55 _jstat[nnode][vpnode] -= conductance;\
57 _ghs[pnode] += conductance * BP(vpnode,vnnode);\
58 _ghs[nnode] -= conductance * BP(vpnode,vnnode);\
60 _rhs[pnode] += conductance * BP(vpnode,vnnode);\
61 _rhs[nnode] -= conductance * BP(vpnode,vnnode);\
63 #define _load_static_jacobian2p(node,vpnode,vnnode,conductance)\
64 _jstat[node][vpnode] += conductance;\
65 _jstat[node][vnnode] -= conductance;\
67 _ghs[node] += conductance * BP(vpnode,vnnode);\
69 _rhs[node] += conductance * BP(vpnode,vnnode);\
71 #define _load_static_jacobian2s(pnode,nnode,node,conductance)\
72 _jstat[pnode][node] += conductance;\
73 _jstat[nnode][node] -= conductance;\
75 _ghs[pnode] += conductance * NP(node);\
76 _ghs[nnode] -= conductance * NP(node);\
78 _rhs[pnode] += conductance * NP(node);\
79 _rhs[nnode] -= conductance * NP(node);\
81 #define _load_static_jacobian1(node,vnode,conductance)\
82 _jstat[node][vnode] += conductance;\
84 _ghs[node] += conductance * NP(vnode);\
86 _rhs[node] += conductance * NP(vnode);\
88 #define _load_dynamic_residual2(pnode,nnode,charge)\
89 if (doTR) _charges[pnode][nnode] += charge;\
91 _qhs[pnode] -= charge;\
92 _qhs[nnode] += charge;\
94 #define _load_dynamic_residual1(node,charge)\
95 if (doTR) _charges[node][node] += charge;\
97 _qhs[node] -= charge;\
99 #define _load_dynamic_jacobian4(pnode,nnode,vpnode,vnnode,capacitance)\
101 _jdyna[pnode][vpnode] += capacitance;\
102 _jdyna[nnode][vnnode] += capacitance;\
103 _jdyna[pnode][vnnode] -= capacitance;\
104 _jdyna[nnode][vpnode] -= capacitance;\
107 _caps[pnode][nnode][vpnode][vnnode] += capacitance;\
110 _chs[pnode] += capacitance * BP(vpnode,vnnode);\
111 _chs[nnode] -= capacitance * BP(vpnode,vnnode);\
113 #define _load_dynamic_jacobian2s(pnode,nnode,vnode,capacitance)\
115 _jdyna[pnode][vnode] += capacitance;\
116 _jdyna[nnode][vnode] -= capacitance;\
119 _caps[pnode][nnode][vnode][vnode] += capacitance;\
122 _chs[pnode] += capacitance * NP(vnode);\
123 _chs[nnode] -= capacitance * NP(vnode);\
125 #define _load_dynamic_jacobian2p(node,vpnode,vnnode,capacitance)\
127 _jdyna[node][vpnode] += capacitance;\
128 _jdyna[node][vnnode] -= capacitance;\
131 _caps[node][node][vpnode][vnnode] += capacitance;\
134 _chs[node] += capacitance * BP(vpnode,vnnode);\
136 #define _load_dynamic_jacobian1(node,vnode,capacitance)\
138 _jdyna[node][vnode] += capacitance;\
141 _caps[node][node][vnode][vnode] += capacitance;\
144 _chs[node] += capacitance * NP(vnode);\
147 #define _save_whitenoise1(n1,pwr,type)\
148 _white_pwr[n1][n1] += pwr;
149 #define _save_whitenoise2(n1,n2,pwr,type)\
150 _white_pwr[n1][n2] += pwr;
151 #define _save_flickernoise1(n1,pwr,exp,type)\
152 _flicker_pwr[n1][n1] += pwr;\
153 _flicker_exp[n1][n1] += exp;
154 #define _save_flickernoise2(n1,n2,pwr,exp,type)\
155 _flicker_pwr[n1][n2] += pwr;\
156 _flicker_exp[n1][n2] += exp;
157 #define _load_whitenoise2(n1,n2,pwr)\
158 cy (n1,n2) -= pwr/kB/T0; cy (n2,n1) -= pwr/kB/T0;\
159 cy (n1,n1) += pwr/kB/T0; cy (n2,n2) += pwr/kB/T0;
160 #define _load_whitenoise1(n1,pwr)\
161 cy (n1,n1) += pwr/kB/T0;
162 #define _load_flickernoise2(n1,n2,pwr,exp)\
163 cy (n1,n2) -= pwr*pow(_freq,-exp)/kB/T0;\
164 cy (n2,n1) -= pwr*pow(_freq,-exp)/kB/T0;\
165 cy (n1,n1) += pwr*pow(_freq,-exp)/kB/T0;\
166 cy (n2,n2) += pwr*pow(_freq,-exp)/kB/T0;
167 #define _load_flickernoise1(n1,pwr,exp)\
168 cy (n1,n1) += pwr*pow(_freq,-exp)/kB/T0;
171 #define m00_hypot(v00,x,y) v00 = xhypot(x,y);
172 #define m10_hypot(v10,v00,x,y) v10 = (x)/(v00);
173 #define m11_hypot(v11,v00,x,y) v11 = (y)/(v00);
174 #define m00_max(v00,x,y) v00 = ((x)>(y))?(x):(y);
175 #define m10_max(v10,v00,x,y) v10 = ((x)>(y))?1.0:0.0;
176 #define m11_max(v11,v00,x,y) v11 = ((x)>(y))?0.0:1.0;
177 #define m00_min(v00,x,y) v00 = ((x)<(y))?(x):(y);
178 #define m10_min(v10,v00,x,y) v10 = ((x)<(y))?1.0:0.0;
179 #define m11_min(v11,v00,x,y) v11 = ((x)<(y))?0.0:1.0;
180 #define m00_pow(v00,x,y) v00 = pow(x,y);
181 #define m10_pow(v10,v00,x,y) v10 = (x==0.0)?0.0:(v00)*(y)/(x);
182 #define m11_pow(v11,v00,x,y) v11 = (x==0.0)?0.0:(log(x)*(v00));
184 #define m00_div(v00,v10,x,y) double v10=1/(y); double v00=(x)*v10;
185 #define m10_div(v10,v00,vv,x,y)
186 #define m11_div(v11,v00,vv,x,y) double v11 = -v00*vv;
188 #define m00_mult(v00,v10,v11,x,y) double v10=(x); double v11=(y); double v00=v10*v11;
189 #define m00_add(v00,x,y) double v00=(x)+(y);
191 #define m00_cos(v00,x) v00 = cos(x);
192 #define m10_cos(v10,v00,x) v10 = (-sin(x));
193 #define m00_sin(v00,x) v00 = sin(x);
194 #define m10_sin(v10,v00,x) v10 = (cos(x));
195 #define m00_tan(v00,x) v00 = tan(x);
196 #define m10_tan(v10,v00,x) v10 = (1.0/cos(x)/cos(x));
197 #define m00_cosh(v00,x) v00 = cosh(x);
198 #define m10_cosh(v10,v00,x) v10 = (sinh(x));
199 #define m00_sinh(v00,x) v00 = sinh(x);
200 #define m10_sinh(v10,v00,x) v10 = (cosh(x));
201 #define m00_tanh(v00,x) v00 = tanh(x);
202 #define m10_tanh(v10,v00,x) v10 = (1.0/cosh(x)/cosh(x));
203 #define m00_acos(v00,x) v00 = acos(x);
204 #define m10_acos(v10,v00,x) v10 = (-1.0/sqrt(1-x*x));
205 #define m00_asin(v00,x) v00 = asin(x);
206 #define m10_asin(v10,v00,x) v10 = (+1.0/sqrt(1-x*x));
207 #define m00_atan(v00,x) v00 = atan(x);
208 #define m10_atan(v10,v00,x) v10 = (+1.0/(1+x*x));
209 #define m00_atanh(v00,x) v00 = atanh(x);
210 #define m10_atanh(v10,v00,x) v10 = (+1.0/(1-x*x));
211 #define m00_logE(v00,x) v00 = log(x);
212 #define m10_logE(v10,v00,x) v10 = (1.0/x);
213 #define m00_log10(v00,x) v00 = log10(x);
214 #define m10_log10(v10,v00,x) v10 = (1.0/x/M_LN10);
215 #define m00_sqrt(v00,x) v00 = sqrt(x);
216 #define m10_sqrt(v10,v00,x) v10 = (0.5/v00);
217 #define m00_fabs(v00,x) v00 = fabs(x);
218 #define m10_fabs(v10,v00,x) v10 = (((x)>=0)?(+1.0):(-1.0));
220 #define m00_exp(v00,x) v00 = exp(x);
221 #define m10_exp(v10,v00,x) v10 = v00;
223 #define m00_abs(v00) ((v00)<(0)?(-(v00)):(v00))
224 #define m00_floor(v00,x) v00 = floor(x);
225 #define m00_limexp(v00,x) v00 = ((x)<80.0?exp(x):exp(80.0)*(x-79.0));
226 #define m10_limexp(v10,v00,x) v10 = ((x)<80.0?(v00):exp(80.0));
228 #define m20_logE(v00) (-1.0/v00/v00)
229 #define m20_exp(v00) exp(v00)
230 #define m20_limexp(v00) ((v00)<80.0?exp(v00):0.0)
231 #define m20_sqrt(v00) (-0.25/(v00)/sqrt(v00))
232 #define m20_fabs(v00) 0.0
233 #define m20_pow(x,y) ((y)*((y)-1.0)*pow(x,y)/(x)/(x))
234 #define m00_vt(x) (kBoverQ*(x))
235 #define m10_vt(x) (kBoverQ)
238 #define _modelname "andor4x2"
239 #define _instancename getName()
240 #define _circuit_temp (getPropertyDouble("Temp")+273.15)
241 #define _param_given(p) (isPropertyGiven(p)?1:0)
245 #define _vt_nom (kBoverQ*_circuit_temp)
247 using namespace device;
256 void andor4x2::initModel (
void)
269 initializeInstance ();
290 void andor4x2::initVerilog (
void)
297 for (i1 = 0; i1 < 11; i1++) {
298 for (i2 = 0; i2 < 11; i2++) {
299 _charges[i1][i2] = 0.0;
303 for (i1 = 0; i1 < 11; i1++) {
304 for (i2 = 0; i2 < 11; i2++) {
305 for (i3 = 0; i3 < 11; i3++) {
306 for (i4 = 0; i4 < 11; i4++) {
307 _caps[i1][i2][i3][i4] = 0.0;
311 for (i1 = 0; i1 < 11; i1++) {
316 for (i2 = 0; i2 < 11; i2++) {
317 _jstat[i1][i2] = 0.0;
318 _jdyna[i1][i2] = 0.0;
324 void andor4x2::loadVariables (
void)
336 #define _DERIVATEFORDDX
339 void andor4x2::initializeModel (
void)
341 #if defined(_DYNAMIC)
345 #if defined(_DYNAMIC)
346 Cd=((Delay*1.43)/Rd);
352 void andor4x2::initializeInstance (
void)
357 void andor4x2::initialStep (
void)
362 void andor4x2::finalStep (
void)
367 void andor4x2::calcVerilog (
void)
372 #if defined(_DERIVATE)
373 double Iand_VA11_GND;
374 double Iand_VA12_GND;
375 double Iand_VA21_GND;
376 double Iand_VA22_GND;
377 double Iand_VA31_GND;
378 double Iand_VA32_GND;
379 double Iand_VA41_GND;
380 double Iand_VA42_GND;
383 #if defined(_DERIVATE)
388 #if defined(_DERIVATE)
393 #if defined(_DERIVATE)
398 #if defined(_DERIVATE)
402 #if defined(_DERIVATE)
403 m1_VA11_GND=(
NP(
A12));
404 m1_VA12_GND=(
NP(
A11));
407 #if defined(_DERIVATE)
408 m2_VA21_GND=(
NP(
A22));
409 m2_VA22_GND=(
NP(
A21));
412 #if defined(_DERIVATE)
413 m3_VA31_GND=(
NP(
A32));
414 m3_VA32_GND=(
NP(
A31));
417 #if defined(_DERIVATE)
418 m4_VA41_GND=(
NP(
A42));
419 m4_VA42_GND=(
NP(
A41));
422 #if defined(_DERIVATE)
423 Iand_VA11_GND=m1_VA11_GND;
424 Iand_VA12_GND=m1_VA12_GND;
425 Iand_VA21_GND=m2_VA21_GND;
426 Iand_VA22_GND=m2_VA22_GND;
427 Iand_VA31_GND=m3_VA31_GND;
428 Iand_VA32_GND=m3_VA32_GND;
429 Iand_VA41_GND=m4_VA41_GND;
430 Iand_VA42_GND=m4_VA42_GND;
432 Iand=(((m1+m2)+m3)+m4);
436 #if defined(_DERIVATE)
450 #if defined(_DERIVATE)
463 double m00_tanh(d00_tanh0,(TR*(Iand-0.5)))
464 #if defined(_DERIVATE)
465 double m10_tanh(d10_tanh0,d00_tanh0,(TR*(Iand-0.5)))
468 #if defined(_DERIVATE)
480 #if defined(_DERIVATE)
484 #if defined(_DERIVATE)
487 #if defined(_DYNAMIC)
489 #if defined(_DERIVATE)
494 #if defined(_DERIVATE)
498 #if defined(_DERIVATE)
517 for (
int i1 = 0; i1 < 11; i1++) {
519 for (
int i2 = 0; i2 < 11; i2++) {
520 setY (i1, i2, _jstat[i1][i2]);
554 matrix andor4x2::calcMatrixY (nr_double_t frequency)
560 for (
int i1 = 0; i1 < 11; i1++) {
561 for (
int i2 = 0; i2 < 11; i2++) {
562 y (i1,i2) =
rect (_jstat[i1][i2], _jdyna[i1][i2] * 2 *
M_PI * _freq);
596 int i1, i2, i3, i4, state;
599 for (i1 = 0; i1 < 11; i1++) {
600 for (i2 = 0; i2 < 11; i2++) {
601 state = 2 * (i2 + 11 * i1);
603 if (_charges[i1][i2] != 0.0)
608 for (i1 = 0; i1 < 11; i1++) {
609 state = 2 * (i1 + 11 * i1);
610 if (_charges[i1][i1] != 0.0)
615 for (i1 = 0; i1 < 11; i1++) {
616 for (i2 = 0; i2 < 11; i2++) {
618 for (i3 = 0; i3 < 11; i3++) {
619 for (i4 = 0; i4 < 11; i4++) {
621 if (_caps[i1][i2][i3][i4] != 0.0)
626 for (i1 = 0; i1 < 11; i1++) {
627 for (i2 = 0; i2 < 11; i2++) {
629 for (i3 = 0; i3 < 11; i3++) {
630 if (_caps[i1][i2][i3][i3] != 0.0)
635 for (i1 = 0; i1 < 11; i1++) {
636 for (i3 = 0; i3 < 11; i3++) {
637 for (i4 = 0; i4 < 11; i4++) {
639 if (_caps[i1][i1][i3][i4] != 0.0)
644 for (i1 = 0; i1 < 11; i1++) {
645 for (i3 = 0; i3 < 11; i3++) {
646 if (_caps[i1][i1][i3][i3] != 0.0)
652 matrix andor4x2::calcMatrixCy (nr_double_t frequency)
692 for (
int i1 = 0; i1 < 11; i1++) {
694 setCV (i1, _chs[i1]);
695 setGV (i1, _ghs[i1]);
696 for (
int i2 = 0; i2 < 11; i2++) {
697 setQV (i1, i2, _jdyna[i1][i2]);