16 #include "component.h"
21 #define CIR_log_amp -1
33 #define NP(node) real (getV (node))
34 #define BP(pnode,nnode) (NP(pnode) - NP(nnode))
35 #define _load_static_residual2(pnode,nnode,current)\
36 _rhs[pnode] -= current;\
37 _rhs[nnode] += current;
38 #define _load_static_augmented_residual2(pnode,nnode,current)\
39 _rhs[pnode] -= current;\
40 _rhs[nnode] += current;
41 #define _load_static_residual1(node,current)\
42 _rhs[node] -= current;
43 #define _load_static_augmented_residual1(node,current)\
44 _rhs[node] -= current;
45 #define _load_static_jacobian4(pnode,nnode,vpnode,vnnode,conductance)\
46 _jstat[pnode][vpnode] += conductance;\
47 _jstat[nnode][vnnode] += conductance;\
48 _jstat[pnode][vnnode] -= conductance;\
49 _jstat[nnode][vpnode] -= conductance;\
51 _ghs[pnode] += conductance * BP(vpnode,vnnode);\
52 _ghs[nnode] -= conductance * BP(vpnode,vnnode);\
54 _rhs[pnode] += conductance * BP(vpnode,vnnode);\
55 _rhs[nnode] -= conductance * BP(vpnode,vnnode);\
57 #define _load_static_jacobian2p(node,vpnode,vnnode,conductance)\
58 _jstat[node][vpnode] += conductance;\
59 _jstat[node][vnnode] -= conductance;\
61 _ghs[node] += conductance * BP(vpnode,vnnode);\
63 _rhs[node] += conductance * BP(vpnode,vnnode);\
65 #define _load_static_jacobian2s(pnode,nnode,node,conductance)\
66 _jstat[pnode][node] += conductance;\
67 _jstat[nnode][node] -= conductance;\
69 _ghs[pnode] += conductance * NP(node);\
70 _ghs[nnode] -= conductance * NP(node);\
72 _rhs[pnode] += conductance * NP(node);\
73 _rhs[nnode] -= conductance * NP(node);\
75 #define _load_static_jacobian1(node,vnode,conductance)\
76 _jstat[node][vnode] += conductance;\
78 _ghs[node] += conductance * NP(vnode);\
80 _rhs[node] += conductance * NP(vnode);\
82 #define _load_dynamic_residual2(pnode,nnode,charge)\
83 if (doTR) _charges[pnode][nnode] += charge;\
85 _qhs[pnode] -= charge;\
86 _qhs[nnode] += charge;\
88 #define _load_dynamic_residual1(node,charge)\
89 if (doTR) _charges[node][node] += charge;\
91 _qhs[node] -= charge;\
93 #define _load_dynamic_jacobian4(pnode,nnode,vpnode,vnnode,capacitance)\
95 _jdyna[pnode][vpnode] += capacitance;\
96 _jdyna[nnode][vnnode] += capacitance;\
97 _jdyna[pnode][vnnode] -= capacitance;\
98 _jdyna[nnode][vpnode] -= capacitance;\
101 _caps[pnode][nnode][vpnode][vnnode] += capacitance;\
104 _chs[pnode] += capacitance * BP(vpnode,vnnode);\
105 _chs[nnode] -= capacitance * BP(vpnode,vnnode);\
107 #define _load_dynamic_jacobian2s(pnode,nnode,vnode,capacitance)\
109 _jdyna[pnode][vnode] += capacitance;\
110 _jdyna[nnode][vnode] -= capacitance;\
113 _caps[pnode][nnode][vnode][vnode] += capacitance;\
116 _chs[pnode] += capacitance * NP(vnode);\
117 _chs[nnode] -= capacitance * NP(vnode);\
119 #define _load_dynamic_jacobian2p(node,vpnode,vnnode,capacitance)\
121 _jdyna[node][vpnode] += capacitance;\
122 _jdyna[node][vnnode] -= capacitance;\
125 _caps[node][node][vpnode][vnnode] += capacitance;\
128 _chs[node] += capacitance * BP(vpnode,vnnode);\
130 #define _load_dynamic_jacobian1(node,vnode,capacitance)\
132 _jdyna[node][vnode] += capacitance;\
135 _caps[node][node][vnode][vnode] += capacitance;\
138 _chs[node] += capacitance * NP(vnode);\
141 #define _save_whitenoise1(n1,pwr,type)\
142 _white_pwr[n1][n1] += pwr;
143 #define _save_whitenoise2(n1,n2,pwr,type)\
144 _white_pwr[n1][n2] += pwr;
145 #define _save_flickernoise1(n1,pwr,exp,type)\
146 _flicker_pwr[n1][n1] += pwr;\
147 _flicker_exp[n1][n1] += exp;
148 #define _save_flickernoise2(n1,n2,pwr,exp,type)\
149 _flicker_pwr[n1][n2] += pwr;\
150 _flicker_exp[n1][n2] += exp;
151 #define _load_whitenoise2(n1,n2,pwr)\
152 cy (n1,n2) -= pwr/kB/T0; cy (n2,n1) -= pwr/kB/T0;\
153 cy (n1,n1) += pwr/kB/T0; cy (n2,n2) += pwr/kB/T0;
154 #define _load_whitenoise1(n1,pwr)\
155 cy (n1,n1) += pwr/kB/T0;
156 #define _load_flickernoise2(n1,n2,pwr,exp)\
157 cy (n1,n2) -= pwr*pow(_freq,-exp)/kB/T0;\
158 cy (n2,n1) -= pwr*pow(_freq,-exp)/kB/T0;\
159 cy (n1,n1) += pwr*pow(_freq,-exp)/kB/T0;\
160 cy (n2,n2) += pwr*pow(_freq,-exp)/kB/T0;
161 #define _load_flickernoise1(n1,pwr,exp)\
162 cy (n1,n1) += pwr*pow(_freq,-exp)/kB/T0;
165 #define m00_hypot(v00,x,y) v00 = xhypot(x,y);
166 #define m10_hypot(v10,v00,x,y) v10 = (x)/(v00);
167 #define m11_hypot(v11,v00,x,y) v11 = (y)/(v00);
168 #define m00_max(v00,x,y) v00 = ((x)>(y))?(x):(y);
169 #define m10_max(v10,v00,x,y) v10 = ((x)>(y))?1.0:0.0;
170 #define m11_max(v11,v00,x,y) v11 = ((x)>(y))?0.0:1.0;
171 #define m00_min(v00,x,y) v00 = ((x)<(y))?(x):(y);
172 #define m10_min(v10,v00,x,y) v10 = ((x)<(y))?1.0:0.0;
173 #define m11_min(v11,v00,x,y) v11 = ((x)<(y))?0.0:1.0;
174 #define m00_pow(v00,x,y) v00 = pow(x,y);
175 #define m10_pow(v10,v00,x,y) v10 = (x==0.0)?0.0:(v00)*(y)/(x);
176 #define m11_pow(v11,v00,x,y) v11 = (x==0.0)?0.0:(log(x)*(v00));
178 #define m00_div(v00,v10,x,y) double v10=1/(y); double v00=(x)*v10;
179 #define m10_div(v10,v00,vv,x,y)
180 #define m11_div(v11,v00,vv,x,y) double v11 = -v00*vv;
182 #define m00_mult(v00,v10,v11,x,y) double v10=(x); double v11=(y); double v00=v10*v11;
183 #define m00_add(v00,x,y) double v00=(x)+(y);
185 #define m00_cos(v00,x) v00 = cos(x);
186 #define m10_cos(v10,v00,x) v10 = (-sin(x));
187 #define m00_sin(v00,x) v00 = sin(x);
188 #define m10_sin(v10,v00,x) v10 = (cos(x));
189 #define m00_tan(v00,x) v00 = tan(x);
190 #define m10_tan(v10,v00,x) v10 = (1.0/cos(x)/cos(x));
191 #define m00_cosh(v00,x) v00 = cosh(x);
192 #define m10_cosh(v10,v00,x) v10 = (sinh(x));
193 #define m00_sinh(v00,x) v00 = sinh(x);
194 #define m10_sinh(v10,v00,x) v10 = (cosh(x));
195 #define m00_tanh(v00,x) v00 = tanh(x);
196 #define m10_tanh(v10,v00,x) v10 = (1.0/cosh(x)/cosh(x));
197 #define m00_acos(v00,x) v00 = acos(x);
198 #define m10_acos(v10,v00,x) v10 = (-1.0/sqrt(1-x*x));
199 #define m00_asin(v00,x) v00 = asin(x);
200 #define m10_asin(v10,v00,x) v10 = (+1.0/sqrt(1-x*x));
201 #define m00_atan(v00,x) v00 = atan(x);
202 #define m10_atan(v10,v00,x) v10 = (+1.0/(1+x*x));
203 #define m00_atanh(v00,x) v00 = atanh(x);
204 #define m10_atanh(v10,v00,x) v10 = (+1.0/(1-x*x));
205 #define m00_logE(v00,x) v00 = log(x);
206 #define m10_logE(v10,v00,x) v10 = (1.0/x);
207 #define m00_log10(v00,x) v00 = log10(x);
208 #define m10_log10(v10,v00,x) v10 = (1.0/x/M_LN10);
209 #define m00_sqrt(v00,x) v00 = sqrt(x);
210 #define m10_sqrt(v10,v00,x) v10 = (0.5/v00);
211 #define m00_fabs(v00,x) v00 = fabs(x);
212 #define m10_fabs(v10,v00,x) v10 = (((x)>=0)?(+1.0):(-1.0));
214 #define m00_exp(v00,x) v00 = exp(x);
215 #define m10_exp(v10,v00,x) v10 = v00;
217 #define m00_abs(v00) ((v00)<(0)?(-(v00)):(v00))
218 #define m00_floor(v00,x) v00 = floor(x);
219 #define m00_limexp(v00,x) v00 = ((x)<80.0?exp(x):exp(80.0)*(x-79.0));
220 #define m10_limexp(v10,v00,x) v10 = ((x)<80.0?(v00):exp(80.0));
222 #define m20_logE(v00) (-1.0/v00/v00)
223 #define m20_exp(v00) exp(v00)
224 #define m20_limexp(v00) ((v00)<80.0?exp(v00):0.0)
225 #define m20_sqrt(v00) (-0.25/(v00)/sqrt(v00))
226 #define m20_fabs(v00) 0.0
227 #define m20_pow(x,y) ((y)*((y)-1.0)*pow(x,y)/(x)/(x))
228 #define m00_vt(x) (kBoverQ*(x))
229 #define m10_vt(x) (kBoverQ)
232 #define _modelname "log_amp"
233 #define _instancename getName()
234 #define _circuit_temp (getPropertyDouble("Temp")+273.15)
235 #define _param_given(p) (isPropertyGiven(p)?1:0)
239 #define _vt_nom (kBoverQ*_circuit_temp)
241 using namespace device;
250 void log_amp::initModel (
void)
263 initializeInstance ();
284 void log_amp::initVerilog (
void)
291 for (i1 = 0; i1 < 5; i1++) {
292 for (i2 = 0; i2 < 5; i2++) {
293 _charges[i1][i2] = 0.0;
297 for (i1 = 0; i1 < 5; i1++) {
298 for (i2 = 0; i2 < 5; i2++) {
299 for (i3 = 0; i3 < 5; i3++) {
300 for (i4 = 0; i4 < 5; i4++) {
301 _caps[i1][i2][i3][i4] = 0.0;
305 for (i1 = 0; i1 < 5; i1++) {
310 for (i2 = 0; i2 < 5; i2++) {
311 _jstat[i1][i2] = 0.0;
312 _jdyna[i1][i2] = 0.0;
318 void log_amp::loadVariables (
void)
344 #define _DERIVATEFORDDX
347 void log_amp::initializeModel (
void)
352 void log_amp::initializeInstance (
void)
357 void log_amp::initialStep (
void)
362 void log_amp::finalStep (
void)
367 void log_amp::calcVerilog (
void)
372 #if defined(_DERIVATE)
384 #if defined(_DYNAMIC)
389 #if defined(_DERIVATE)
393 #if defined(_DERIVATE)
396 #if defined(_DYNAMIC)
399 #if defined(_DYNAMIC)
400 PI=3.14159265358979323846;
402 #if defined(_DERIVATE)
406 #if defined(_DERIVATE)
411 #if defined(_DYNAMIC)
417 NTemp=(N+(Ntc*Tdiff));
418 VosoutTemp=(Vosout+(Vosouttc*Tdiff));
419 DkTemp=(Dk+(Dktc*Tdiff));
420 Ib1Temp=(Ib1+(Ib1tc*Tdiff));
421 IbrTemp=(Ibr+(Ibrtc*Tdiff));
426 double m00_log10(d00_log100,(((V1/R)-Ib1Temp)/((V2/R)-IbrTemp)))
427 #if defined(_DERIVATE)
428 double m10_log10(d10_log100,d00_log100,(((V1/R)-Ib1Temp)/((V2/R)-IbrTemp)))
430 #if defined(_DERIVATE)
431 Ix_VP_I1_GND=((Kv*(1+(DkTemp/100)))*((V1_VP_I1_GND/R)/((V2/
R)-IbrTemp))*d10_log100);
432 Ix_VP_Ir_GND=((Kv*(1+(DkTemp/100)))*(-((V1/R)-Ib1Temp)*(V2_VP_Ir_GND/R)/((V2/
R)-IbrTemp)/((V2/
R)-IbrTemp))*d10_log100);
434 Ix=((((Kv*(1+(DkTemp/100)))*d00_log100)+(((Kv*2)*(NTemp/100))*M))+VosoutTemp);
439 #if defined(_DERIVATE)
446 #if defined(_DERIVATE)
450 #if defined(_DERIVATE)
454 #if defined(_DERIVATE)
459 #if defined(_DERIVATE)
463 #if defined(_DERIVATE)
467 #if defined(_DERIVATE)
470 #if defined(_DYNAMIC)
472 #if defined(_DERIVATE)
477 #if defined(_DERIVATE)
481 #if defined(_DERIVATE)
500 for (
int i1 = 0; i1 < 5; i1++) {
502 for (
int i2 = 0; i2 < 5; i2++) {
503 setY (i1, i2, _jstat[i1][i2]);
537 matrix log_amp::calcMatrixY (nr_double_t frequency)
543 for (
int i1 = 0; i1 < 5; i1++) {
544 for (
int i2 = 0; i2 < 5; i2++) {
545 y (i1,i2) =
rect (_jstat[i1][i2], _jdyna[i1][i2] * 2 *
M_PI * _freq);
579 int i1, i2, i3, i4, state;
582 for (i1 = 0; i1 < 5; i1++) {
583 for (i2 = 0; i2 < 5; i2++) {
584 state = 2 * (i2 + 5 * i1);
586 if (_charges[i1][i2] != 0.0)
591 for (i1 = 0; i1 < 5; i1++) {
592 state = 2 * (i1 + 5 * i1);
593 if (_charges[i1][i1] != 0.0)
598 for (i1 = 0; i1 < 5; i1++) {
599 for (i2 = 0; i2 < 5; i2++) {
601 for (i3 = 0; i3 < 5; i3++) {
602 for (i4 = 0; i4 < 5; i4++) {
604 if (_caps[i1][i2][i3][i4] != 0.0)
609 for (i1 = 0; i1 < 5; i1++) {
610 for (i2 = 0; i2 < 5; i2++) {
612 for (i3 = 0; i3 < 5; i3++) {
613 if (_caps[i1][i2][i3][i3] != 0.0)
618 for (i1 = 0; i1 < 5; i1++) {
619 for (i3 = 0; i3 < 5; i3++) {
620 for (i4 = 0; i4 < 5; i4++) {
622 if (_caps[i1][i1][i3][i4] != 0.0)
627 for (i1 = 0; i1 < 5; i1++) {
628 for (i3 = 0; i3 < 5; i3++) {
629 if (_caps[i1][i1][i3][i3] != 0.0)
635 matrix log_amp::calcMatrixCy (nr_double_t frequency)
675 for (
int i1 = 0; i1 < 5; i1++) {
677 setCV (i1, _chs[i1]);
678 setGV (i1, _ghs[i1]);
679 for (
int i2 = 0; i2 < 5; i2++) {
680 setQV (i1, i2, _jdyna[i1][i2]);