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