My Project  0.0.16
QUCS Mapping
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
tff_SR.core.cpp
Go to the documentation of this file.
1 /*
2  * tff_SR.core.cpp - device implementations for tff_SR module
3  *
4  * This is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2, or (at your option)
7  * any later version.
8  *
9  */
10 
11 #if HAVE_CONFIG_H
12 #include <config.h>
13 #endif
14 
15 #include "tff_SR.analogfunction.h"
16 #include "component.h"
17 #include "device.h"
18 #include "tff_SR.core.h"
19 
20 #ifndef CIR_tff_SR
21 #define CIR_tff_SR -1
22 #endif
23 
24 // external nodes
25 #define S 0
26 #define T 1
27 #define CLK 2
28 #define R 3
29 #define QB 4
30 #define QO 5
31 // internal nodes
32 #define n1 6
33 #define n1A 7
34 #define n2 8
35 #define n3 9
36 #define n3A 10
37 #define n4 11
38 #define Dsig 12
39 #define QA 13
40 
41 // useful macro definitions
42 #define NP(node) real (getV (node))
43 #define BP(pnode,nnode) (NP(pnode) - NP(nnode))
44 #define _load_static_residual2(pnode,nnode,current)\
45  _rhs[pnode] -= current;\
46  _rhs[nnode] += current;
47 #define _load_static_augmented_residual2(pnode,nnode,current)\
48  _rhs[pnode] -= current;\
49  _rhs[nnode] += current;
50 #define _load_static_residual1(node,current)\
51  _rhs[node] -= current;
52 #define _load_static_augmented_residual1(node,current)\
53  _rhs[node] -= current;
54 #define _load_static_jacobian4(pnode,nnode,vpnode,vnnode,conductance)\
55  _jstat[pnode][vpnode] += conductance;\
56  _jstat[nnode][vnnode] += conductance;\
57  _jstat[pnode][vnnode] -= conductance;\
58  _jstat[nnode][vpnode] -= conductance;\
59  if (doHB) {\
60  _ghs[pnode] += conductance * BP(vpnode,vnnode);\
61  _ghs[nnode] -= conductance * BP(vpnode,vnnode);\
62  } else {\
63  _rhs[pnode] += conductance * BP(vpnode,vnnode);\
64  _rhs[nnode] -= conductance * BP(vpnode,vnnode);\
65  }
66 #define _load_static_jacobian2p(node,vpnode,vnnode,conductance)\
67  _jstat[node][vpnode] += conductance;\
68  _jstat[node][vnnode] -= conductance;\
69  if (doHB) {\
70  _ghs[node] += conductance * BP(vpnode,vnnode);\
71  } else {\
72  _rhs[node] += conductance * BP(vpnode,vnnode);\
73  }
74 #define _load_static_jacobian2s(pnode,nnode,node,conductance)\
75  _jstat[pnode][node] += conductance;\
76  _jstat[nnode][node] -= conductance;\
77  if (doHB) {\
78  _ghs[pnode] += conductance * NP(node);\
79  _ghs[nnode] -= conductance * NP(node);\
80  } else {\
81  _rhs[pnode] += conductance * NP(node);\
82  _rhs[nnode] -= conductance * NP(node);\
83  }
84 #define _load_static_jacobian1(node,vnode,conductance)\
85  _jstat[node][vnode] += conductance;\
86  if (doHB) {\
87  _ghs[node] += conductance * NP(vnode);\
88  } else {\
89  _rhs[node] += conductance * NP(vnode);\
90  }
91 #define _load_dynamic_residual2(pnode,nnode,charge)\
92  if (doTR) _charges[pnode][nnode] += charge;\
93  if (doHB) {\
94  _qhs[pnode] -= charge;\
95  _qhs[nnode] += charge;\
96  }
97 #define _load_dynamic_residual1(node,charge)\
98  if (doTR) _charges[node][node] += charge;\
99  if (doHB) {\
100  _qhs[node] -= charge;\
101  }
102 #define _load_dynamic_jacobian4(pnode,nnode,vpnode,vnnode,capacitance)\
103  if (doAC) {\
104  _jdyna[pnode][vpnode] += capacitance;\
105  _jdyna[nnode][vnnode] += capacitance;\
106  _jdyna[pnode][vnnode] -= capacitance;\
107  _jdyna[nnode][vpnode] -= capacitance;\
108  }\
109  if (doTR) {\
110  _caps[pnode][nnode][vpnode][vnnode] += capacitance;\
111  }\
112  if (doHB) {\
113  _chs[pnode] += capacitance * BP(vpnode,vnnode);\
114  _chs[nnode] -= capacitance * BP(vpnode,vnnode);\
115  }
116 #define _load_dynamic_jacobian2s(pnode,nnode,vnode,capacitance)\
117  if (doAC) {\
118  _jdyna[pnode][vnode] += capacitance;\
119  _jdyna[nnode][vnode] -= capacitance;\
120  }\
121  if (doTR) {\
122  _caps[pnode][nnode][vnode][vnode] += capacitance;\
123  }\
124  if (doHB) {\
125  _chs[pnode] += capacitance * NP(vnode);\
126  _chs[nnode] -= capacitance * NP(vnode);\
127  }
128 #define _load_dynamic_jacobian2p(node,vpnode,vnnode,capacitance)\
129  if (doAC) {\
130  _jdyna[node][vpnode] += capacitance;\
131  _jdyna[node][vnnode] -= capacitance;\
132  }\
133  if (doTR) {\
134  _caps[node][node][vpnode][vnnode] += capacitance;\
135  }\
136  if (doHB) {\
137  _chs[node] += capacitance * BP(vpnode,vnnode);\
138  }
139 #define _load_dynamic_jacobian1(node,vnode,capacitance)\
140  if (doAC) {\
141  _jdyna[node][vnode] += capacitance;\
142  }\
143  if (doTR) {\
144  _caps[node][node][vnode][vnode] += capacitance;\
145  }\
146  if (doHB) {\
147  _chs[node] += capacitance * NP(vnode);\
148  }
149 
150 #define _save_whitenoise1(n1,pwr,type)\
151  _white_pwr[n1][n1] += pwr;
152 #define _save_whitenoise2(n1,n2,pwr,type)\
153  _white_pwr[n1][n2] += pwr;
154 #define _save_flickernoise1(n1,pwr,exp,type)\
155  _flicker_pwr[n1][n1] += pwr;\
156  _flicker_exp[n1][n1] += exp;
157 #define _save_flickernoise2(n1,n2,pwr,exp,type)\
158  _flicker_pwr[n1][n2] += pwr;\
159  _flicker_exp[n1][n2] += exp;
160 #define _load_whitenoise2(n1,n2,pwr)\
161  cy (n1,n2) -= pwr/kB/T0; cy (n2,n1) -= pwr/kB/T0;\
162  cy (n1,n1) += pwr/kB/T0; cy (n2,n2) += pwr/kB/T0;
163 #define _load_whitenoise1(n1,pwr)\
164  cy (n1,n1) += pwr/kB/T0;
165 #define _load_flickernoise2(n1,n2,pwr,exp)\
166  cy (n1,n2) -= pwr*pow(_freq,-exp)/kB/T0;\
167  cy (n2,n1) -= pwr*pow(_freq,-exp)/kB/T0;\
168  cy (n1,n1) += pwr*pow(_freq,-exp)/kB/T0;\
169  cy (n2,n2) += pwr*pow(_freq,-exp)/kB/T0;
170 #define _load_flickernoise1(n1,pwr,exp)\
171  cy (n1,n1) += pwr*pow(_freq,-exp)/kB/T0;
172 
173 // derivative helper macros
174 #define m00_hypot(v00,x,y) v00 = xhypot(x,y);
175 #define m10_hypot(v10,v00,x,y) v10 = (x)/(v00);
176 #define m11_hypot(v11,v00,x,y) v11 = (y)/(v00);
177 #define m00_max(v00,x,y) v00 = ((x)>(y))?(x):(y);
178 #define m10_max(v10,v00,x,y) v10 = ((x)>(y))?1.0:0.0;
179 #define m11_max(v11,v00,x,y) v11 = ((x)>(y))?0.0:1.0;
180 #define m00_min(v00,x,y) v00 = ((x)<(y))?(x):(y);
181 #define m10_min(v10,v00,x,y) v10 = ((x)<(y))?1.0:0.0;
182 #define m11_min(v11,v00,x,y) v11 = ((x)<(y))?0.0:1.0;
183 #define m00_pow(v00,x,y) v00 = pow(x,y);
184 #define m10_pow(v10,v00,x,y) v10 = (x==0.0)?0.0:(v00)*(y)/(x);
185 #define m11_pow(v11,v00,x,y) v11 = (x==0.0)?0.0:(log(x)*(v00));
186 
187 #define m00_div(v00,v10,x,y) double v10=1/(y); double v00=(x)*v10;
188 #define m10_div(v10,v00,vv,x,y)
189 #define m11_div(v11,v00,vv,x,y) double v11 = -v00*vv;
190 
191 #define m00_mult(v00,v10,v11,x,y) double v10=(x); double v11=(y); double v00=v10*v11;
192 #define m00_add(v00,x,y) double v00=(x)+(y);
193 
194 #define m00_cos(v00,x) v00 = cos(x);
195 #define m10_cos(v10,v00,x) v10 = (-sin(x));
196 #define m00_sin(v00,x) v00 = sin(x);
197 #define m10_sin(v10,v00,x) v10 = (cos(x));
198 #define m00_tan(v00,x) v00 = tan(x);
199 #define m10_tan(v10,v00,x) v10 = (1.0/cos(x)/cos(x));
200 #define m00_cosh(v00,x) v00 = cosh(x);
201 #define m10_cosh(v10,v00,x) v10 = (sinh(x));
202 #define m00_sinh(v00,x) v00 = sinh(x);
203 #define m10_sinh(v10,v00,x) v10 = (cosh(x));
204 #define m00_tanh(v00,x) v00 = tanh(x);
205 #define m10_tanh(v10,v00,x) v10 = (1.0/cosh(x)/cosh(x));
206 #define m00_acos(v00,x) v00 = acos(x);
207 #define m10_acos(v10,v00,x) v10 = (-1.0/sqrt(1-x*x));
208 #define m00_asin(v00,x) v00 = asin(x);
209 #define m10_asin(v10,v00,x) v10 = (+1.0/sqrt(1-x*x));
210 #define m00_atan(v00,x) v00 = atan(x);
211 #define m10_atan(v10,v00,x) v10 = (+1.0/(1+x*x));
212 #define m00_atanh(v00,x) v00 = atanh(x);
213 #define m10_atanh(v10,v00,x) v10 = (+1.0/(1-x*x));
214 #define m00_logE(v00,x) v00 = log(x);
215 #define m10_logE(v10,v00,x) v10 = (1.0/x);
216 #define m00_log10(v00,x) v00 = log10(x);
217 #define m10_log10(v10,v00,x) v10 = (1.0/x/M_LN10);
218 #define m00_sqrt(v00,x) v00 = sqrt(x);
219 #define m10_sqrt(v10,v00,x) v10 = (0.5/v00);
220 #define m00_fabs(v00,x) v00 = fabs(x);
221 #define m10_fabs(v10,v00,x) v10 = (((x)>=0)?(+1.0):(-1.0));
222 
223 #define m00_exp(v00,x) v00 = exp(x);
224 #define m10_exp(v10,v00,x) v10 = v00;
225 
226 #define m00_abs(v00) ((v00)<(0)?(-(v00)):(v00))
227 #define m00_floor(v00,x) v00 = floor(x);
228 #define m00_limexp(v00,x) v00 = ((x)<80.0?exp(x):exp(80.0)*(x-79.0));
229 #define m10_limexp(v10,v00,x) v10 = ((x)<80.0?(v00):exp(80.0));
230 
231 #define m20_logE(v00) (-1.0/v00/v00)
232 #define m20_exp(v00) exp(v00)
233 #define m20_limexp(v00) ((v00)<80.0?exp(v00):0.0)
234 #define m20_sqrt(v00) (-0.25/(v00)/sqrt(v00))
235 #define m20_fabs(v00) 0.0
236 #define m20_pow(x,y) ((y)*((y)-1.0)*pow(x,y)/(x)/(x))
237 #define m00_vt(x) (kBoverQ*(x))
238 #define m10_vt(x) (kBoverQ)
239 
240 // simulator specific definitions
241 #define _modelname "tff_SR"
242 #define _instancename getName()
243 #define _circuit_temp (getPropertyDouble("Temp")+273.15)
244 #define _param_given(p) (isPropertyGiven(p)?1:0)
245 
246 
247 // $vt and $vt() functions
248 #define _vt_nom (kBoverQ*_circuit_temp)
249 
250 using namespace device;
251 
252 /* Device constructor. */
253 tff_SR::tff_SR() : circuit (14)
254 {
255  type = CIR_tff_SR;
256 }
257 
258 /* Initialization of model. */
259 void tff_SR::initModel (void)
260 {
261  // create internal nodes
262  setInternalNode (n1, "n1");
263  setInternalNode (n1A, "n1A");
264  setInternalNode (n2, "n2");
265  setInternalNode (n3, "n3");
266  setInternalNode (n3A, "n3A");
267  setInternalNode (n4, "n4");
268  setInternalNode (Dsig, "Dsig");
269  setInternalNode (QA, "QA");
270 
271  // get device model parameters
272  loadVariables ();
273  // evaluate global model equations
274  initializeModel ();
275  // evaluate initial step equations
276  initialStep ();
277  // evaluate global instance equations
278  initializeInstance ();
279 }
280 
281 /* Initialization of DC analysis. */
282 void tff_SR::initDC (void)
283 {
284  allocMatrixMNA ();
285  initModel ();
286  pol = 1;
287  restartDC ();
288  doAC = 1;
289  doTR = 0;
290  doHB = 0;
291 }
292 
293 /* Run when DC is restarted (fallback algorithms). */
294 void tff_SR::restartDC (void)
295 {
296 }
297 
298 /* Initialize Verilog-AMS code. */
299 void tff_SR::initVerilog (void)
300 {
301  // initialization of noise variables
302 
303  int i1, i2, i3, i4;
304 
305  // zero charges
306  for (i1 = 0; i1 < 14; i1++) {
307  for (i2 = 0; i2 < 14; i2++) {
308  _charges[i1][i2] = 0.0;
309  } }
310 
311  // zero capacitances
312  for (i1 = 0; i1 < 14; i1++) {
313  for (i2 = 0; i2 < 14; i2++) {
314  for (i3 = 0; i3 < 14; i3++) {
315  for (i4 = 0; i4 < 14; i4++) {
316  _caps[i1][i2][i3][i4] = 0.0;
317  } } } }
318 
319  // zero right hand side, static and dynamic jacobian
320  for (i1 = 0; i1 < 14; i1++) {
321  _rhs[i1] = 0.0;
322  _qhs[i1] = 0.0;
323  _chs[i1] = 0.0;
324  _ghs[i1] = 0.0;
325  for (i2 = 0; i2 < 14; i2++) {
326  _jstat[i1][i2] = 0.0;
327  _jdyna[i1][i2] = 0.0;
328  }
329  }
330 }
331 
332 /* Load device model input parameters. */
333 void tff_SR::loadVariables (void)
334 {
335  TR_H = getPropertyDouble ("TR_H");
336  TR_L = getPropertyDouble ("TR_L");
337  Delay = getPropertyDouble ("Delay");
338 }
339 
340 /* #define's for translated code */
341 #undef _DDT
342 #define _DDT(q) q
343 #define _DYNAMIC
344 #define _DERIVATE
345 #define _DDX
346 #define _DERIVATEFORDDX
347 
348 /* Evaluate Verilog-AMS equations in model initialization. */
349 void tff_SR::initializeModel (void)
350 {
351 #if defined(_DYNAMIC)
352 #endif
353 {
354 Rd=1e3;
355 #if defined(_DYNAMIC)
356 Ccc=((Delay*1.43)/Rd);
357 #endif
358 }
359 }
360 
361 /* Evaluate Verilog-AMS equations in instance initialization. */
362 void tff_SR::initializeInstance (void)
363 {
364 }
365 
366 /* Evaluate Verilog-AMS equations in initial step. */
367 void tff_SR::initialStep (void)
368 {
369 }
370 
371 /* Evaluate Verilog-AMS equations in final step. */
372 void tff_SR::finalStep (void)
373 {
374 }
375 
376 /* Evaluate Verilog-AMS equations in analog block. */
377 void tff_SR::calcVerilog (void)
378 {
379 
380 /* ----------------- evaluate verilog analog equations -------------------- */
381 {
382 double m00_tanh(d00_tanh0,(TR_H*(((NP(T)*NP(QB))+((1-NP(T))*NP(QO)))-0.5)))
383 #if defined(_DERIVATE)
384 double m10_tanh(d10_tanh0,d00_tanh0,(TR_H*(((NP(T)*NP(QB))+((1-NP(T))*NP(QO)))-0.5)))
385 #endif
386 _load_static_residual1(Dsig,((-0.5)*(1+d00_tanh0)));
387 #if defined(_DERIVATE)
388 _load_static_jacobian1(Dsig,QO,((-0.5)*(TR_H*((1-NP(T))))*d10_tanh0));
389 _load_static_jacobian1(Dsig,QB,((-0.5)*(TR_H*(NP(T)))*d10_tanh0));
390 _load_static_jacobian1(Dsig,T,((-0.5)*(TR_H*((NP(QB))+(-1.0)*NP(QO)))*d10_tanh0));
391 #endif
392 }
394 #if defined(_DERIVATE)
396 #endif
397 {
398 double m00_tanh(d00_tanh0,(TR_H*(((NP(n4)*NP(n2))*NP(S))-0.5)))
399 #if defined(_DERIVATE)
400 double m10_tanh(d10_tanh0,d00_tanh0,(TR_H*(((NP(n4)*NP(n2))*NP(S))-0.5)))
401 #endif
402 _load_static_residual1(n1,((-0.5)*(1-d00_tanh0)));
403 #if defined(_DERIVATE)
404 _load_static_jacobian1(n1,S,((-0.5)*(-(TR_H*((NP(n4)*NP(n2))))*d10_tanh0)));
405 _load_static_jacobian1(n1,n2,((-0.5)*(-(TR_H*(NP(n4))*NP(S))*d10_tanh0)));
406 _load_static_jacobian1(n1,n4,((-0.5)*(-(TR_H*(NP(n2))*NP(S))*d10_tanh0)));
407 #endif
408 }
410 #if defined(_DERIVATE)
412 #endif
413 {
414 double m00_tanh(d00_tanh0,(TR_L*(((NP(n1A)*NP(CLK))*NP(R))-0.5)))
415 #if defined(_DERIVATE)
416 double m10_tanh(d10_tanh0,d00_tanh0,(TR_L*(((NP(n1A)*NP(CLK))*NP(R))-0.5)))
417 #endif
418 _load_static_residual1(n2,((-0.5)*(1-d00_tanh0)));
419 #if defined(_DERIVATE)
420 _load_static_jacobian1(n2,R,((-0.5)*(-(TR_L*((NP(n1A)*NP(CLK))))*d10_tanh0)));
421 _load_static_jacobian1(n2,CLK,((-0.5)*(-(TR_L*(NP(n1A))*NP(R))*d10_tanh0)));
422 _load_static_jacobian1(n2,n1A,((-0.5)*(-(TR_L*(NP(CLK))*NP(R))*d10_tanh0)));
423 #endif
424 }
426 #if defined(_DERIVATE)
428 #endif
429 {
430 double m00_tanh(d00_tanh0,(TR_H*(((NP(n2)*NP(CLK))*NP(n4))-0.5)))
431 #if defined(_DERIVATE)
432 double m10_tanh(d10_tanh0,d00_tanh0,(TR_H*(((NP(n2)*NP(CLK))*NP(n4))-0.5)))
433 #endif
434 _load_static_residual1(n3,((-0.5)*(1-d00_tanh0)));
435 #if defined(_DERIVATE)
436 _load_static_jacobian1(n3,n4,((-0.5)*(-(TR_H*((NP(n2)*NP(CLK))))*d10_tanh0)));
437 _load_static_jacobian1(n3,CLK,((-0.5)*(-(TR_H*(NP(n2))*NP(n4))*d10_tanh0)));
438 _load_static_jacobian1(n3,n2,((-0.5)*(-(TR_H*(NP(CLK))*NP(n4))*d10_tanh0)));
439 #endif
440 }
442 #if defined(_DERIVATE)
444 #endif
445 {
446 double m00_tanh(d00_tanh0,(TR_L*(((NP(n3A)*NP(Dsig))*NP(R))-0.5)))
447 #if defined(_DERIVATE)
448 double m10_tanh(d10_tanh0,d00_tanh0,(TR_L*(((NP(n3A)*NP(Dsig))*NP(R))-0.5)))
449 #endif
450 _load_static_residual1(n4,((-0.5)*(1-d00_tanh0)));
451 #if defined(_DERIVATE)
452 _load_static_jacobian1(n4,R,((-0.5)*(-(TR_L*((NP(n3A)*NP(Dsig))))*d10_tanh0)));
453 _load_static_jacobian1(n4,Dsig,((-0.5)*(-(TR_L*(NP(n3A))*NP(R))*d10_tanh0)));
454 _load_static_jacobian1(n4,n3A,((-0.5)*(-(TR_L*(NP(Dsig))*NP(R))*d10_tanh0)));
455 #endif
456 }
458 #if defined(_DERIVATE)
460 #endif
461 {
462 double m00_tanh(d00_tanh0,(TR_H*(((NP(n2)*NP(QB))*NP(S))-0.5)))
463 #if defined(_DERIVATE)
464 double m10_tanh(d10_tanh0,d00_tanh0,(TR_H*(((NP(n2)*NP(QB))*NP(S))-0.5)))
465 #endif
466 _load_static_residual1(QO,((-0.5)*(1-d00_tanh0)));
467 #if defined(_DERIVATE)
468 _load_static_jacobian1(QO,S,((-0.5)*(-(TR_H*((NP(n2)*NP(QB))))*d10_tanh0)));
469 _load_static_jacobian1(QO,QB,((-0.5)*(-(TR_H*(NP(n2))*NP(S))*d10_tanh0)));
470 _load_static_jacobian1(QO,n2,((-0.5)*(-(TR_H*(NP(QB))*NP(S))*d10_tanh0)));
471 #endif
472 }
474 #if defined(_DERIVATE)
476 #endif
477 {
478 double m00_tanh(d00_tanh0,(TR_L*(((NP(QA)*NP(n3A))*NP(R))-0.5)))
479 #if defined(_DERIVATE)
480 double m10_tanh(d10_tanh0,d00_tanh0,(TR_L*(((NP(QA)*NP(n3A))*NP(R))-0.5)))
481 #endif
482 _load_static_residual1(QB,((-0.5)*(1-d00_tanh0)));
483 #if defined(_DERIVATE)
484 _load_static_jacobian1(QB,R,((-0.5)*(-(TR_L*((NP(QA)*NP(n3A))))*d10_tanh0)));
485 _load_static_jacobian1(QB,n3A,((-0.5)*(-(TR_L*(NP(QA))*NP(R))*d10_tanh0)));
486 _load_static_jacobian1(QB,QA,((-0.5)*(-(TR_L*(NP(n3A))*NP(R))*d10_tanh0)));
487 #endif
488 }
490 #if defined(_DERIVATE)
492 #endif
494 #if defined(_DERIVATE)
496 #endif
497 #if defined(_DYNAMIC)
499 #if defined(_DERIVATE)
501 #endif
502 #endif
504 #if defined(_DERIVATE)
506 #endif
507 #if defined(_DYNAMIC)
509 #if defined(_DERIVATE)
511 #endif
512 #endif
514 #if defined(_DERIVATE)
516 #endif
517 #if defined(_DYNAMIC)
519 #if defined(_DERIVATE)
521 #endif
522 #endif
523 
524 /* ------------------ end of verilog analog equations --------------------- */
525 
526 /* ------------------ evaluate verilog noise equations -------------------- */
527 
528 /* ------------------- end of verilog noise equations --------------------- */
529 }
530 
531 /* Perform DC iteration. */
532 void tff_SR::calcDC (void)
533 {
534  // evaluate Verilog code
535  initVerilog ();
536  calcVerilog ();
537 
538  // fill right hand side and static jacobian
539  for (int i1 = 0; i1 < 14; i1++) {
540  setI (i1, _rhs[i1]);
541  for (int i2 = 0; i2 < 14; i2++) {
542  setY (i1, i2, _jstat[i1][i2]);
543  }
544  }
545 }
546 
547 /* Save operating points. */
549 {
550  // save global instance operating points
551 }
552 
553 /* Load operating points. */
555 {
556 }
557 
558 /* Calculate operating points. */
560 {
561 }
562 
563 /* Initialization of AC analysis. */
564 void tff_SR::initAC (void)
565 {
566  allocMatrixMNA ();
567 }
568 
569 /* Perform AC calculations. */
570 void tff_SR::calcAC (nr_double_t frequency)
571 {
572  setMatrixY (calcMatrixY (frequency));
573 }
574 
575 /* Compute Y-matrix for AC analysis. */
576 matrix tff_SR::calcMatrixY (nr_double_t frequency)
577 {
578  _freq = frequency;
580  matrix y (14);
581 
582  for (int i1 = 0; i1 < 14; i1++) {
583  for (int i2 = 0; i2 < 14; i2++) {
584  y (i1,i2) = rect (_jstat[i1][i2], _jdyna[i1][i2] * 2 * M_PI * _freq);
585  }
586  }
587 
588  return y;
589 }
590 
591 /* Initialization of S-parameter analysis. */
592 void tff_SR::initSP (void)
593 {
594  allocMatrixS ();
595 }
596 
597 /* Perform S-parameter calculations. */
598 void tff_SR::calcSP (nr_double_t frequency)
599 {
600  setMatrixS (ytos (calcMatrixY (frequency)));
601 }
602 
603 /* Initialization of transient analysis. */
604 void tff_SR::initTR (void)
605 {
606  setStates (2 * 14 * 14);
607  initDC ();
608 }
609 
610 /* Perform transient analysis iteration step. */
611 void tff_SR::calcTR (nr_double_t)
612 {
613  doHB = 0;
614  doAC = 1;
615  doTR = 1;
616  calcDC ();
617 
618  int i1, i2, i3, i4, state;
619 
620  // 2-node charge integrations
621  for (i1 = 0; i1 < 14; i1++) {
622  for (i2 = 0; i2 < 14; i2++) {
623  state = 2 * (i2 + 14 * i1);
624  if (i1 != i2)
625  if (_charges[i1][i2] != 0.0)
626  transientCapacitanceQ (state, i1, i2, _charges[i1][i2]);
627  } }
628 
629  // 1-node charge integrations
630  for (i1 = 0; i1 < 14; i1++) {
631  state = 2 * (i1 + 14 * i1);
632  if (_charges[i1][i1] != 0.0)
633  transientCapacitanceQ (state, i1, _charges[i1][i1]);
634  }
635 
636  // charge: 2-node, voltage: 2-node
637  for (i1 = 0; i1 < 14; i1++) {
638  for (i2 = 0; i2 < 14; i2++) {
639  if (i1 != i2)
640  for (i3 = 0; i3 < 14; i3++) {
641  for (i4 = 0; i4 < 14; i4++) {
642  if (i3 != i4)
643  if (_caps[i1][i2][i3][i4] != 0.0)
644  transientCapacitanceC (i1, i2, i3, i4, _caps[i1][i2][i3][i4], BP(i3,i4));
645  } } } }
646 
647  // charge: 2-node, voltage: 1-node
648  for (i1 = 0; i1 < 14; i1++) {
649  for (i2 = 0; i2 < 14; i2++) {
650  if (i1 != i2)
651  for (i3 = 0; i3 < 14; i3++) {
652  if (_caps[i1][i2][i3][i3] != 0.0)
653  transientCapacitanceC2Q (i1, i2, i3, _caps[i1][i2][i3][i3], NP(i3));
654  } } }
655 
656  // charge: 1-node, voltage: 2-node
657  for (i1 = 0; i1 < 14; i1++) {
658  for (i3 = 0; i3 < 14; i3++) {
659  for (i4 = 0; i4 < 14; i4++) {
660  if (i3 != i4)
661  if (_caps[i1][i1][i3][i4] != 0.0)
662  transientCapacitanceC2V (i1, i3, i4, _caps[i1][i1][i3][i4], BP(i3,i4));
663  } } }
664 
665  // charge: 1-node, voltage: 1-node
666  for (i1 = 0; i1 < 14; i1++) {
667  for (i3 = 0; i3 < 14; i3++) {
668  if (_caps[i1][i1][i3][i3] != 0.0)
669  transientCapacitanceC (i1, i3, _caps[i1][i1][i3][i3], NP(i3));
670  } }
671 }
672 
673 /* Compute Cy-matrix for AC noise analysis. */
674 matrix tff_SR::calcMatrixCy (nr_double_t frequency)
675 {
676  _freq = frequency;
677  matrix cy (14);
678 
679 
680  return cy;
681 }
682 
683 /* Perform AC noise computations. */
684 void tff_SR::calcNoiseAC (nr_double_t frequency)
685 {
686  setMatrixN (calcMatrixCy (frequency));
687 }
688 
689 /* Perform S-parameter noise computations. */
690 void tff_SR::calcNoiseSP (nr_double_t frequency)
691 {
692  setMatrixN (cytocs (calcMatrixCy (frequency) * z0, getMatrixS ()));
693 }
694 
695 /* Initialization of HB analysis. */
696 void tff_SR::initHB (int)
697 {
698  initDC ();
699  allocMatrixHB ();
700 }
701 
702 /* Perform HB analysis. */
703 void tff_SR::calcHB (int)
704 {
705  doHB = 1;
706  doAC = 1;
707  doTR = 0;
708 
709  // jacobian dI/dV and currents get filled
710  calcDC ();
712 
713  // fill in HB matrices
714  for (int i1 = 0; i1 < 14; i1++) {
715  setQ (i1, _qhs[i1]); // charges
716  setCV (i1, _chs[i1]); // jacobian dQ/dV * V
717  setGV (i1, _ghs[i1]); // jacobian dI/dV * V
718  for (int i2 = 0; i2 < 14; i2++) {
719  setQV (i1, i2, _jdyna[i1][i2]); // jacobian dQ/dV
720  }
721  }
722 }
723 
724 #include "tff_SR.defs.h"