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