My Project  0.0.16
QUCS Mapping
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
comp_2bit.core.cpp
Go to the documentation of this file.
1 /*
2  * comp_2bit.core.cpp - device implementations for comp_2bit 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 "comp_2bit.core.h"
19 
20 #ifndef CIR_comp_2bit
21 #define CIR_comp_2bit -1
22 #endif
23 
24 // external nodes
25 #define X0 0
26 #define X1 1
27 #define Y0 2
28 #define Y1 3
29 #define L 4
30 #define G 5
31 #define E 6
32 // internal nodes
33 #define Ln1 7
34 #define Ln2 8
35 #define Gn1 9
36 #define Gn2 10
37 #define En1 11
38 #define En2 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 "comp_2bit"
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. */
253 {
254  type = CIR_comp_2bit;
255 }
256 
257 /* Initialization of model. */
258 void comp_2bit::initModel (void)
259 {
260  // create internal nodes
261  setInternalNode (Ln1, "Ln1");
262  setInternalNode (Ln2, "Ln2");
263  setInternalNode (Gn1, "Gn1");
264  setInternalNode (Gn2, "Gn2");
265  setInternalNode (En1, "En1");
266  setInternalNode (En2, "En2");
267 
268  // get device model parameters
269  loadVariables ();
270  // evaluate global model equations
271  initializeModel ();
272  // evaluate initial step equations
273  initialStep ();
274  // evaluate global instance equations
275  initializeInstance ();
276 }
277 
278 /* Initialization of DC analysis. */
279 void comp_2bit::initDC (void)
280 {
281  allocMatrixMNA ();
282  initModel ();
283  pol = 1;
284  restartDC ();
285  doAC = 1;
286  doTR = 0;
287  doHB = 0;
288 }
289 
290 /* Run when DC is restarted (fallback algorithms). */
292 {
293 }
294 
295 /* Initialize Verilog-AMS code. */
296 void comp_2bit::initVerilog (void)
297 {
298  // initialization of noise variables
299 
300  int i1, i2, i3, i4;
301 
302  // zero charges
303  for (i1 = 0; i1 < 13; i1++) {
304  for (i2 = 0; i2 < 13; i2++) {
305  _charges[i1][i2] = 0.0;
306  } }
307 
308  // zero capacitances
309  for (i1 = 0; i1 < 13; i1++) {
310  for (i2 = 0; i2 < 13; i2++) {
311  for (i3 = 0; i3 < 13; i3++) {
312  for (i4 = 0; i4 < 13; i4++) {
313  _caps[i1][i2][i3][i4] = 0.0;
314  } } } }
315 
316  // zero right hand side, static and dynamic jacobian
317  for (i1 = 0; i1 < 13; i1++) {
318  _rhs[i1] = 0.0;
319  _qhs[i1] = 0.0;
320  _chs[i1] = 0.0;
321  _ghs[i1] = 0.0;
322  for (i2 = 0; i2 < 13; i2++) {
323  _jstat[i1][i2] = 0.0;
324  _jdyna[i1][i2] = 0.0;
325  }
326  }
327 }
328 
329 /* Load device model input parameters. */
330 void comp_2bit::loadVariables (void)
331 {
332  TR = getPropertyDouble ("TR");
333  Delay = getPropertyDouble ("Delay");
334 }
335 
336 /* #define's for translated code */
337 #undef _DDT
338 #define _DDT(q) q
339 #define _DYNAMIC
340 #define _DERIVATE
341 #define _DDX
342 #define _DERIVATEFORDDX
343 
344 /* Evaluate Verilog-AMS equations in model initialization. */
345 void comp_2bit::initializeModel (void)
346 {
347 #if defined(_DYNAMIC)
348 #endif
349 {
350 Rd=1e3;
351 #if defined(_DYNAMIC)
352 Cd=((Delay*1.43)/Rd);
353 #endif
354 }
355 }
356 
357 /* Evaluate Verilog-AMS equations in instance initialization. */
358 void comp_2bit::initializeInstance (void)
359 {
360 }
361 
362 /* Evaluate Verilog-AMS equations in initial step. */
363 void comp_2bit::initialStep (void)
364 {
365 }
366 
367 /* Evaluate Verilog-AMS equations in final step. */
368 void comp_2bit::finalStep (void)
369 {
370 }
371 
372 /* Evaluate Verilog-AMS equations in analog block. */
373 void comp_2bit::calcVerilog (void)
374 {
375 
376 /* ----------------- evaluate verilog analog equations -------------------- */
377 double mL;
378 #if defined(_DERIVATE)
379 double mL_VX1_GND;
380 double mL_VY1_GND;
381 double mL_VX0_GND;
382 double mL_VY0_GND;
383 #endif
384 double mG;
385 #if defined(_DERIVATE)
386 double mG_VX1_GND;
387 double mG_VY1_GND;
388 double mG_VX0_GND;
389 double mG_VY0_GND;
390 #endif
391 double mE;
392 #if defined(_DERIVATE)
393 double mE_VX0_GND;
394 double mE_VY0_GND;
395 double mE_VX1_GND;
396 double mE_VY1_GND;
397 #endif
398 double xor1b;
399 #if defined(_DERIVATE)
400 double xor1b_VX1_GND;
401 double xor1b_VY1_GND;
402 #endif
403 double xor0b;
404 #if defined(_DERIVATE)
405 double xor0b_VX0_GND;
406 double xor0b_VY0_GND;
407 #endif
408 #if defined(_DERIVATE)
409 xor0b_VX0_GND=(-(((1-NP(Y0)))+(-1.0)*NP(Y0)));
410 xor0b_VY0_GND=(-((NP(X0)*(-1.0))+((1-NP(X0)))));
411 #endif
412 xor0b=(1-((NP(X0)*(1-NP(Y0)))+((1-NP(X0))*NP(Y0))));
413 #if defined(_DERIVATE)
414 xor1b_VX1_GND=(-(((1-NP(Y1)))+(-1.0)*NP(Y1)));
415 xor1b_VY1_GND=(-((NP(X1)*(-1.0))+((1-NP(X1)))));
416 #endif
417 xor1b=(1-((NP(X1)*(1-NP(Y1)))+((1-NP(X1))*NP(Y1))));
418 #if defined(_DERIVATE)
419 mE_VX0_GND=xor0b_VX0_GND*xor1b;
420 mE_VY0_GND=xor0b_VY0_GND*xor1b;
421 mE_VX1_GND=(xor0b*xor1b_VX1_GND);
422 mE_VY1_GND=(xor0b*xor1b_VY1_GND);
423 #endif
424 mE=(xor0b*xor1b);
425 #if defined(_DERIVATE)
426 mG_VX1_GND=(((1-NP(Y1)))+xor1b_VX1_GND*NP(X0)*(1-NP(Y0)));
427 mG_VY1_GND=((NP(X1)*(-1.0))+xor1b_VY1_GND*NP(X0)*(1-NP(Y0)));
428 mG_VX0_GND=(xor1b)*(1-NP(Y0));
429 mG_VY0_GND=((xor1b*NP(X0))*(-1.0));
430 #endif
431 mG=((NP(X1)*(1-NP(Y1)))+((xor1b*NP(X0))*(1-NP(Y0))));
432 #if defined(_DERIVATE)
433 mL_VX1_GND=((-1.0)*NP(Y1)+xor1b_VX1_GND*(1-NP(X0))*NP(Y0));
434 mL_VY1_GND=(((1-NP(X1)))+xor1b_VY1_GND*(1-NP(X0))*NP(Y0));
435 mL_VX0_GND=(xor1b*(-1.0))*NP(Y0);
436 mL_VY0_GND=((xor1b*(1-NP(X0))));
437 #endif
438 mL=(((1-NP(X1))*NP(Y1))+((xor1b*(1-NP(X0)))*NP(Y0)));
439 {
440 double m00_tanh(d00_tanh0,(TR*(mE-0.5)))
441 #if defined(_DERIVATE)
442 double m10_tanh(d10_tanh0,d00_tanh0,(TR*(mE-0.5)))
443 #endif
444 _load_static_residual1(En1,((-0.5)*(1+d00_tanh0)));
445 #if defined(_DERIVATE)
446 _load_static_jacobian1(En1,Y1,((-0.5)*(TR*mE_VY1_GND)*d10_tanh0));
447 _load_static_jacobian1(En1,X1,((-0.5)*(TR*mE_VX1_GND)*d10_tanh0));
448 _load_static_jacobian1(En1,Y0,((-0.5)*(TR*mE_VY0_GND)*d10_tanh0));
449 _load_static_jacobian1(En1,X0,((-0.5)*(TR*mE_VX0_GND)*d10_tanh0));
450 #endif
451 }
453 #if defined(_DERIVATE)
455 #endif
457 #if defined(_DERIVATE)
459 #endif
460 #if defined(_DYNAMIC)
462 #if defined(_DERIVATE)
464 #endif
465 #endif
467 #if defined(_DERIVATE)
469 #endif
471 #if defined(_DERIVATE)
473 #endif
474 {
475 double m00_tanh(d00_tanh0,(TR*(mG-0.5)))
476 #if defined(_DERIVATE)
477 double m10_tanh(d10_tanh0,d00_tanh0,(TR*(mG-0.5)))
478 #endif
479 _load_static_residual1(Gn1,((-0.5)*(1+d00_tanh0)));
480 #if defined(_DERIVATE)
481 _load_static_jacobian1(Gn1,Y0,((-0.5)*(TR*mG_VY0_GND)*d10_tanh0));
482 _load_static_jacobian1(Gn1,X0,((-0.5)*(TR*mG_VX0_GND)*d10_tanh0));
483 _load_static_jacobian1(Gn1,Y1,((-0.5)*(TR*mG_VY1_GND)*d10_tanh0));
484 _load_static_jacobian1(Gn1,X1,((-0.5)*(TR*mG_VX1_GND)*d10_tanh0));
485 #endif
486 }
488 #if defined(_DERIVATE)
490 #endif
492 #if defined(_DERIVATE)
494 #endif
495 #if defined(_DYNAMIC)
497 #if defined(_DERIVATE)
499 #endif
500 #endif
502 #if defined(_DERIVATE)
504 #endif
506 #if defined(_DERIVATE)
508 #endif
509 {
510 double m00_tanh(d00_tanh0,(TR*(mL-0.5)))
511 #if defined(_DERIVATE)
512 double m10_tanh(d10_tanh0,d00_tanh0,(TR*(mL-0.5)))
513 #endif
514 _load_static_residual1(Ln1,((-0.5)*(1+d00_tanh0)));
515 #if defined(_DERIVATE)
516 _load_static_jacobian1(Ln1,Y0,((-0.5)*(TR*mL_VY0_GND)*d10_tanh0));
517 _load_static_jacobian1(Ln1,X0,((-0.5)*(TR*mL_VX0_GND)*d10_tanh0));
518 _load_static_jacobian1(Ln1,Y1,((-0.5)*(TR*mL_VY1_GND)*d10_tanh0));
519 _load_static_jacobian1(Ln1,X1,((-0.5)*(TR*mL_VX1_GND)*d10_tanh0));
520 #endif
521 }
523 #if defined(_DERIVATE)
525 #endif
527 #if defined(_DERIVATE)
529 #endif
530 #if defined(_DYNAMIC)
532 #if defined(_DERIVATE)
534 #endif
535 #endif
537 #if defined(_DERIVATE)
539 #endif
541 #if defined(_DERIVATE)
543 #endif
544 
545 /* ------------------ end of verilog analog equations --------------------- */
546 
547 /* ------------------ evaluate verilog noise equations -------------------- */
548 
549 /* ------------------- end of verilog noise equations --------------------- */
550 }
551 
552 /* Perform DC iteration. */
553 void comp_2bit::calcDC (void)
554 {
555  // evaluate Verilog code
556  initVerilog ();
557  calcVerilog ();
558 
559  // fill right hand side and static jacobian
560  for (int i1 = 0; i1 < 13; i1++) {
561  setI (i1, _rhs[i1]);
562  for (int i2 = 0; i2 < 13; i2++) {
563  setY (i1, i2, _jstat[i1][i2]);
564  }
565  }
566 }
567 
568 /* Save operating points. */
570 {
571  // save global instance operating points
572 }
573 
574 /* Load operating points. */
576 {
577 }
578 
579 /* Calculate operating points. */
581 {
582 }
583 
584 /* Initialization of AC analysis. */
585 void comp_2bit::initAC (void)
586 {
587  allocMatrixMNA ();
588 }
589 
590 /* Perform AC calculations. */
591 void comp_2bit::calcAC (nr_double_t frequency)
592 {
593  setMatrixY (calcMatrixY (frequency));
594 }
595 
596 /* Compute Y-matrix for AC analysis. */
597 matrix comp_2bit::calcMatrixY (nr_double_t frequency)
598 {
599  _freq = frequency;
601  matrix y (13);
602 
603  for (int i1 = 0; i1 < 13; i1++) {
604  for (int i2 = 0; i2 < 13; i2++) {
605  y (i1,i2) = rect (_jstat[i1][i2], _jdyna[i1][i2] * 2 * M_PI * _freq);
606  }
607  }
608 
609  return y;
610 }
611 
612 /* Initialization of S-parameter analysis. */
613 void comp_2bit::initSP (void)
614 {
615  allocMatrixS ();
616 }
617 
618 /* Perform S-parameter calculations. */
619 void comp_2bit::calcSP (nr_double_t frequency)
620 {
621  setMatrixS (ytos (calcMatrixY (frequency)));
622 }
623 
624 /* Initialization of transient analysis. */
625 void comp_2bit::initTR (void)
626 {
627  setStates (2 * 13 * 13);
628  initDC ();
629 }
630 
631 /* Perform transient analysis iteration step. */
632 void comp_2bit::calcTR (nr_double_t)
633 {
634  doHB = 0;
635  doAC = 1;
636  doTR = 1;
637  calcDC ();
638 
639  int i1, i2, i3, i4, state;
640 
641  // 2-node charge integrations
642  for (i1 = 0; i1 < 13; i1++) {
643  for (i2 = 0; i2 < 13; i2++) {
644  state = 2 * (i2 + 13 * i1);
645  if (i1 != i2)
646  if (_charges[i1][i2] != 0.0)
647  transientCapacitanceQ (state, i1, i2, _charges[i1][i2]);
648  } }
649 
650  // 1-node charge integrations
651  for (i1 = 0; i1 < 13; i1++) {
652  state = 2 * (i1 + 13 * i1);
653  if (_charges[i1][i1] != 0.0)
654  transientCapacitanceQ (state, i1, _charges[i1][i1]);
655  }
656 
657  // charge: 2-node, voltage: 2-node
658  for (i1 = 0; i1 < 13; i1++) {
659  for (i2 = 0; i2 < 13; i2++) {
660  if (i1 != i2)
661  for (i3 = 0; i3 < 13; i3++) {
662  for (i4 = 0; i4 < 13; i4++) {
663  if (i3 != i4)
664  if (_caps[i1][i2][i3][i4] != 0.0)
665  transientCapacitanceC (i1, i2, i3, i4, _caps[i1][i2][i3][i4], BP(i3,i4));
666  } } } }
667 
668  // charge: 2-node, voltage: 1-node
669  for (i1 = 0; i1 < 13; i1++) {
670  for (i2 = 0; i2 < 13; i2++) {
671  if (i1 != i2)
672  for (i3 = 0; i3 < 13; i3++) {
673  if (_caps[i1][i2][i3][i3] != 0.0)
674  transientCapacitanceC2Q (i1, i2, i3, _caps[i1][i2][i3][i3], NP(i3));
675  } } }
676 
677  // charge: 1-node, voltage: 2-node
678  for (i1 = 0; i1 < 13; i1++) {
679  for (i3 = 0; i3 < 13; i3++) {
680  for (i4 = 0; i4 < 13; i4++) {
681  if (i3 != i4)
682  if (_caps[i1][i1][i3][i4] != 0.0)
683  transientCapacitanceC2V (i1, i3, i4, _caps[i1][i1][i3][i4], BP(i3,i4));
684  } } }
685 
686  // charge: 1-node, voltage: 1-node
687  for (i1 = 0; i1 < 13; i1++) {
688  for (i3 = 0; i3 < 13; i3++) {
689  if (_caps[i1][i1][i3][i3] != 0.0)
690  transientCapacitanceC (i1, i3, _caps[i1][i1][i3][i3], NP(i3));
691  } }
692 }
693 
694 /* Compute Cy-matrix for AC noise analysis. */
695 matrix comp_2bit::calcMatrixCy (nr_double_t frequency)
696 {
697  _freq = frequency;
698  matrix cy (13);
699 
700 
701  return cy;
702 }
703 
704 /* Perform AC noise computations. */
705 void comp_2bit::calcNoiseAC (nr_double_t frequency)
706 {
707  setMatrixN (calcMatrixCy (frequency));
708 }
709 
710 /* Perform S-parameter noise computations. */
711 void comp_2bit::calcNoiseSP (nr_double_t frequency)
712 {
713  setMatrixN (cytocs (calcMatrixCy (frequency) * z0, getMatrixS ()));
714 }
715 
716 /* Initialization of HB analysis. */
718 {
719  initDC ();
720  allocMatrixHB ();
721 }
722 
723 /* Perform HB analysis. */
725 {
726  doHB = 1;
727  doAC = 1;
728  doTR = 0;
729 
730  // jacobian dI/dV and currents get filled
731  calcDC ();
733 
734  // fill in HB matrices
735  for (int i1 = 0; i1 < 13; i1++) {
736  setQ (i1, _qhs[i1]); // charges
737  setCV (i1, _chs[i1]); // jacobian dQ/dV * V
738  setGV (i1, _ghs[i1]); // jacobian dI/dV * V
739  for (int i2 = 0; i2 < 13; i2++) {
740  setQV (i1, i2, _jdyna[i1][i2]); // jacobian dQ/dV
741  }
742  }
743 }
744 
745 #include "comp_2bit.defs.h"