My Project  0.0.16
QUCS Mapping
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
mod_amp.core.cpp
Go to the documentation of this file.
1 /*
2  * mod_amp.core.cpp - device implementations for mod_amp 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 "mod_amp.analogfunction.h"
16 #include "component.h"
17 #include "device.h"
18 #include "mod_amp.core.h"
19 
20 #ifndef CIR_mod_amp
21 #define CIR_mod_amp -1
22 #endif
23 
24 // external nodes
25 #define in_p 0
26 #define in_n 1
27 #define out_p 2
28 // internal nodes
29 #define n2 3
30 #define n3 4
31 #define n4 5
32 #define n5 6
33 #define n6 7
34 #define n7 8
35 #define n8 9
36 #define n9 10
37 #define n10 11
38 #define n11 12
39 #define n12 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 "mod_amp"
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 mod_amp::mod_amp() : circuit (14)
254 {
255  type = CIR_mod_amp;
256 }
257 
258 /* Initialization of model. */
259 void mod_amp::initModel (void)
260 {
261  // create internal nodes
262  setInternalNode (n2, "n2");
263  setInternalNode (n3, "n3");
264  setInternalNode (n4, "n4");
265  setInternalNode (n5, "n5");
266  setInternalNode (n6, "n6");
267  setInternalNode (n7, "n7");
268  setInternalNode (n8, "n8");
269  setInternalNode (n9, "n9");
270  setInternalNode (n10, "n10");
271  setInternalNode (n11, "n11");
272  setInternalNode (n12, "n12");
273 
274  // get device model parameters
275  loadVariables ();
276  // evaluate global model equations
277  initializeModel ();
278  // evaluate initial step equations
279  initialStep ();
280  // evaluate global instance equations
281  initializeInstance ();
282 }
283 
284 /* Initialization of DC analysis. */
285 void mod_amp::initDC (void)
286 {
287  allocMatrixMNA ();
288  initModel ();
289  pol = 1;
290  restartDC ();
291  doAC = 1;
292  doTR = 0;
293  doHB = 0;
294 }
295 
296 /* Run when DC is restarted (fallback algorithms). */
298 {
299 }
300 
301 /* Initialize Verilog-AMS code. */
302 void mod_amp::initVerilog (void)
303 {
304  // initialization of noise variables
305 
306  int i1, i2, i3, i4;
307 
308  // zero charges
309  for (i1 = 0; i1 < 14; i1++) {
310  for (i2 = 0; i2 < 14; i2++) {
311  _charges[i1][i2] = 0.0;
312  } }
313 
314  // zero capacitances
315  for (i1 = 0; i1 < 14; i1++) {
316  for (i2 = 0; i2 < 14; i2++) {
317  for (i3 = 0; i3 < 14; i3++) {
318  for (i4 = 0; i4 < 14; i4++) {
319  _caps[i1][i2][i3][i4] = 0.0;
320  } } } }
321 
322  // zero right hand side, static and dynamic jacobian
323  for (i1 = 0; i1 < 14; i1++) {
324  _rhs[i1] = 0.0;
325  _qhs[i1] = 0.0;
326  _chs[i1] = 0.0;
327  _ghs[i1] = 0.0;
328  for (i2 = 0; i2 < 14; i2++) {
329  _jstat[i1][i2] = 0.0;
330  _jdyna[i1][i2] = 0.0;
331  }
332  }
333 }
334 
335 /* Load device model input parameters. */
336 void mod_amp::loadVariables (void)
337 {
338  GBP = getPropertyDouble ("GBP");
339  AOLDC = getPropertyDouble ("AOLDC");
340  FP2 = getPropertyDouble ("FP2");
341  RO = getPropertyDouble ("RO");
342  CD = getPropertyDouble ("CD");
343  RD = getPropertyDouble ("RD");
344  IOFF = getPropertyDouble ("IOFF");
345  IB = getPropertyDouble ("IB");
346  VOFF = getPropertyDouble ("VOFF");
347  CMRRDC = getPropertyDouble ("CMRRDC");
348  FCM = getPropertyDouble ("FCM");
349  PSRT = getPropertyDouble ("PSRT");
350  NSRT = getPropertyDouble ("NSRT");
351  VLIMP = getPropertyDouble ("VLIMP");
352  VLIMN = getPropertyDouble ("VLIMN");
353  ILMAX = getPropertyDouble ("ILMAX");
354  CSCALE = getPropertyDouble ("CSCALE");
355 }
356 
357 /* #define's for translated code */
358 #undef _DDT
359 #define _DDT(q) q
360 #define _DYNAMIC
361 #define _DERIVATE
362 #define _DDX
363 #define _DERIVATEFORDDX
364 
365 /* Evaluate Verilog-AMS equations in model initialization. */
366 void mod_amp::initializeModel (void)
367 {
368 }
369 
370 /* Evaluate Verilog-AMS equations in instance initialization. */
371 void mod_amp::initializeInstance (void)
372 {
373 }
374 
375 /* Evaluate Verilog-AMS equations in initial step. */
376 void mod_amp::initialStep (void)
377 {
378 }
379 
380 /* Evaluate Verilog-AMS equations in final step. */
381 void mod_amp::finalStep (void)
382 {
383 }
384 
385 /* Evaluate Verilog-AMS equations in analog block. */
386 void mod_amp::calcVerilog (void)
387 {
388 
389 /* ----------------- evaluate verilog analog equations -------------------- */
390 double Slewratenegative;
391 double Slewratepositive;
392 #if defined(_DYNAMIC)
393 double CP2;
394 #endif
395 double RP2;
396 #if defined(_DYNAMIC)
397 double CP1;
398 #endif
399 double RP1;
400 #if defined(_DYNAMIC)
401 double QCM;
402 #if defined(_DERIVATE)
403 double QCM_Vn6_n10;
404 #endif
405 #endif
406 double CMgain;
407 double CMRR0;
408 double Rdiff;
409 double Voffset;
410 double MTWOPI;
411 MTWOPI=6.28318530717958647693;
412 Voffset=(VOFF*0.5);
413 Rdiff=(RD/2);
414 {
415 double m00_pow(d00_pow0,10,(CMRRDC/20))
416 CMRR0=d00_pow0;
417 }
418 CMgain=(1e6/CMRR0);
419 #if defined(_DYNAMIC)
420 #if defined(_DERIVATE)
421 QCM_Vn6_n10=((1.0/((MTWOPI*1e6)*FCM)));
422 #endif
423 QCM=((1.0/((MTWOPI*1e6)*FCM))*BP(n6,n10));
424 #endif
425 {
426 double m00_pow(d00_pow0,10,(AOLDC/20))
427 RP1=d00_pow0;
428 }
429 #if defined(_DYNAMIC)
430 CP1=(1/(MTWOPI*GBP));
431 #endif
432 RP2=1;
433 #if defined(_DYNAMIC)
434 CP2=(1/(MTWOPI*FP2));
435 #endif
436 Slewratepositive=(PSRT/(MTWOPI*GBP));
437 Slewratenegative=(NSRT/(MTWOPI*GBP));
439 #if defined(_DERIVATE)
441 #endif
443 #if defined(_DERIVATE)
444 #endif
446 #if defined(_DERIVATE)
448 #endif
449 _load_static_residual2(in_n,n9,(-Voffset));
450 #if defined(_DERIVATE)
451 #endif
453 #if defined(_DERIVATE)
454 #endif
456 #if defined(_DERIVATE)
457 #endif
458 _load_static_residual2(n7,n9,(IOFF/2));
459 #if defined(_DERIVATE)
460 #endif
461 _load_static_residual2(n7,n8,(BP(n7,n8)/Rdiff));
462 #if defined(_DERIVATE)
463 _load_static_jacobian4(n7,n8,n7,n8,(1/Rdiff));
464 #endif
465 _load_static_residual2(n9,n8,(BP(n9,n8)/Rdiff));
466 #if defined(_DERIVATE)
467 _load_static_jacobian4(n9,n8,n9,n8,(1/Rdiff));
468 #endif
469 #if defined(_DYNAMIC)
471 #if defined(_DERIVATE)
473 #endif
474 #endif
475 _load_static_residual1(n6,((-CMgain)*NP(n8)));
476 #if defined(_DERIVATE)
477 _load_static_jacobian1(n6,n8,((-CMgain)));
478 #endif
480 #if defined(_DERIVATE)
482 #endif
484 #if defined(_DERIVATE)
486 #endif
487 #if defined(_DYNAMIC)
489 #if defined(_DERIVATE)
490 _load_dynamic_jacobian4(n6,n10,n6,n10,QCM_Vn6_n10);
491 #endif
492 #endif
494 #if defined(_DERIVATE)
496 #endif
498 #if defined(_DERIVATE)
500 #endif
502 #if defined(_DERIVATE)
504 #endif
506 #if defined(_DERIVATE)
508 #endif
509 if
510 ((NP(n11)>Slewratepositive))
511 {
512 _load_static_residual1(n12,(-Slewratepositive));
513 #if defined(_DERIVATE)
514 #endif
515 }
516 else
517 {
518 if
519 ((NP(n11)<(-Slewratenegative)))
520 {
521 _load_static_residual1(n12,Slewratenegative);
522 #if defined(_DERIVATE)
523 #endif
524 }
525 else
526 {
528 #if defined(_DERIVATE)
530 #endif
531 }
532 }
534 #if defined(_DERIVATE)
536 #endif
538 #if defined(_DERIVATE)
540 #endif
542 #if defined(_DERIVATE)
543 _load_static_jacobian1(n3,n3,(1/RP1));
544 #endif
545 #if defined(_DYNAMIC)
547 #if defined(_DERIVATE)
549 #endif
550 #endif
552 #if defined(_DERIVATE)
554 #endif
556 #if defined(_DERIVATE)
557 _load_static_jacobian1(n5,n5,(1/RP2));
558 #endif
559 #if defined(_DYNAMIC)
561 #if defined(_DERIVATE)
563 #endif
564 #endif
565 if
566 ((BP(n2,out_p)>=ILMAX))
567 {
569 #if defined(_DERIVATE)
571 #endif
572 _load_static_residual1(n4,((CSCALE*NP(n5))*(BP(n2,out_p)-ILMAX)));
573 #if defined(_DERIVATE)
574 _load_static_jacobian2p(n4,n2,out_p,((CSCALE*NP(n5))));
575 _load_static_jacobian1(n4,n5,(CSCALE)*(BP(n2,out_p)-ILMAX));
576 #endif
578 #if defined(_DERIVATE)
580 #endif
581 }
582 else
583 {
584 if
585 ((BP(n2,out_p)<=(-ILMAX)))
586 {
588 #if defined(_DERIVATE)
590 #endif
591 _load_static_residual1(n4,(((-CSCALE)*NP(n5))*(BP(n2,out_p)+ILMAX)));
592 #if defined(_DERIVATE)
593 _load_static_jacobian2p(n4,n2,out_p,(((-CSCALE)*NP(n5))));
594 _load_static_jacobian1(n4,n5,((-CSCALE))*(BP(n2,out_p)+ILMAX));
595 #endif
597 #if defined(_DERIVATE)
599 #endif
600 }
601 else
602 {
604 #if defined(_DERIVATE)
606 #endif
608 #if defined(_DERIVATE)
610 #endif
611 }
612 }
613 _load_static_residual2(n4,n2,(BP(n4,n2)/(RO-1)));
614 #if defined(_DERIVATE)
615 _load_static_jacobian4(n4,n2,n4,n2,(1/(RO-1)));
616 #endif
618 #if defined(_DERIVATE)
620 #endif
621 if
622 ((NP(out_p)>VLIMP))
623 {
624 _load_static_residual1(out_p,((-10.0)*VLIMP));
625 #if defined(_DERIVATE)
626 #endif
628 #if defined(_DERIVATE)
630 #endif
631 }
632 else
633 {
634 if
635 ((NP(out_p)<VLIMN))
636 {
637 _load_static_residual1(out_p,((-10.0)*VLIMN));
638 #if defined(_DERIVATE)
639 #endif
641 #if defined(_DERIVATE)
643 #endif
644 }
645 }
646 
647 /* ------------------ end of verilog analog equations --------------------- */
648 
649 /* ------------------ evaluate verilog noise equations -------------------- */
650 
651 /* ------------------- end of verilog noise equations --------------------- */
652 }
653 
654 /* Perform DC iteration. */
655 void mod_amp::calcDC (void)
656 {
657  // evaluate Verilog code
658  initVerilog ();
659  calcVerilog ();
660 
661  // fill right hand side and static jacobian
662  for (int i1 = 0; i1 < 14; i1++) {
663  setI (i1, _rhs[i1]);
664  for (int i2 = 0; i2 < 14; i2++) {
665  setY (i1, i2, _jstat[i1][i2]);
666  }
667  }
668 }
669 
670 /* Save operating points. */
672 {
673  // save global instance operating points
674 }
675 
676 /* Load operating points. */
678 {
679 }
680 
681 /* Calculate operating points. */
683 {
684 }
685 
686 /* Initialization of AC analysis. */
687 void mod_amp::initAC (void)
688 {
689  allocMatrixMNA ();
690 }
691 
692 /* Perform AC calculations. */
693 void mod_amp::calcAC (nr_double_t frequency)
694 {
695  setMatrixY (calcMatrixY (frequency));
696 }
697 
698 /* Compute Y-matrix for AC analysis. */
699 matrix mod_amp::calcMatrixY (nr_double_t frequency)
700 {
701  _freq = frequency;
703  matrix y (14);
704 
705  for (int i1 = 0; i1 < 14; i1++) {
706  for (int i2 = 0; i2 < 14; i2++) {
707  y (i1,i2) = rect (_jstat[i1][i2], _jdyna[i1][i2] * 2 * M_PI * _freq);
708  }
709  }
710 
711  return y;
712 }
713 
714 /* Initialization of S-parameter analysis. */
715 void mod_amp::initSP (void)
716 {
717  allocMatrixS ();
718 }
719 
720 /* Perform S-parameter calculations. */
721 void mod_amp::calcSP (nr_double_t frequency)
722 {
723  setMatrixS (ytos (calcMatrixY (frequency)));
724 }
725 
726 /* Initialization of transient analysis. */
727 void mod_amp::initTR (void)
728 {
729  setStates (2 * 14 * 14);
730  initDC ();
731 }
732 
733 /* Perform transient analysis iteration step. */
734 void mod_amp::calcTR (nr_double_t)
735 {
736  doHB = 0;
737  doAC = 1;
738  doTR = 1;
739  calcDC ();
740 
741  int i1, i2, i3, i4, state;
742 
743  // 2-node charge integrations
744  for (i1 = 0; i1 < 14; i1++) {
745  for (i2 = 0; i2 < 14; i2++) {
746  state = 2 * (i2 + 14 * i1);
747  if (i1 != i2)
748  if (_charges[i1][i2] != 0.0)
749  transientCapacitanceQ (state, i1, i2, _charges[i1][i2]);
750  } }
751 
752  // 1-node charge integrations
753  for (i1 = 0; i1 < 14; i1++) {
754  state = 2 * (i1 + 14 * i1);
755  if (_charges[i1][i1] != 0.0)
756  transientCapacitanceQ (state, i1, _charges[i1][i1]);
757  }
758 
759  // charge: 2-node, voltage: 2-node
760  for (i1 = 0; i1 < 14; i1++) {
761  for (i2 = 0; i2 < 14; i2++) {
762  if (i1 != i2)
763  for (i3 = 0; i3 < 14; i3++) {
764  for (i4 = 0; i4 < 14; i4++) {
765  if (i3 != i4)
766  if (_caps[i1][i2][i3][i4] != 0.0)
767  transientCapacitanceC (i1, i2, i3, i4, _caps[i1][i2][i3][i4], BP(i3,i4));
768  } } } }
769 
770  // charge: 2-node, voltage: 1-node
771  for (i1 = 0; i1 < 14; i1++) {
772  for (i2 = 0; i2 < 14; i2++) {
773  if (i1 != i2)
774  for (i3 = 0; i3 < 14; i3++) {
775  if (_caps[i1][i2][i3][i3] != 0.0)
776  transientCapacitanceC2Q (i1, i2, i3, _caps[i1][i2][i3][i3], NP(i3));
777  } } }
778 
779  // charge: 1-node, voltage: 2-node
780  for (i1 = 0; i1 < 14; i1++) {
781  for (i3 = 0; i3 < 14; i3++) {
782  for (i4 = 0; i4 < 14; i4++) {
783  if (i3 != i4)
784  if (_caps[i1][i1][i3][i4] != 0.0)
785  transientCapacitanceC2V (i1, i3, i4, _caps[i1][i1][i3][i4], BP(i3,i4));
786  } } }
787 
788  // charge: 1-node, voltage: 1-node
789  for (i1 = 0; i1 < 14; i1++) {
790  for (i3 = 0; i3 < 14; i3++) {
791  if (_caps[i1][i1][i3][i3] != 0.0)
792  transientCapacitanceC (i1, i3, _caps[i1][i1][i3][i3], NP(i3));
793  } }
794 }
795 
796 /* Compute Cy-matrix for AC noise analysis. */
797 matrix mod_amp::calcMatrixCy (nr_double_t frequency)
798 {
799  _freq = frequency;
800  matrix cy (14);
801 
802 
803  return cy;
804 }
805 
806 /* Perform AC noise computations. */
807 void mod_amp::calcNoiseAC (nr_double_t frequency)
808 {
809  setMatrixN (calcMatrixCy (frequency));
810 }
811 
812 /* Perform S-parameter noise computations. */
813 void mod_amp::calcNoiseSP (nr_double_t frequency)
814 {
815  setMatrixN (cytocs (calcMatrixCy (frequency) * z0, getMatrixS ()));
816 }
817 
818 /* Initialization of HB analysis. */
819 void mod_amp::initHB (int)
820 {
821  initDC ();
822  allocMatrixHB ();
823 }
824 
825 /* Perform HB analysis. */
826 void mod_amp::calcHB (int)
827 {
828  doHB = 1;
829  doAC = 1;
830  doTR = 0;
831 
832  // jacobian dI/dV and currents get filled
833  calcDC ();
835 
836  // fill in HB matrices
837  for (int i1 = 0; i1 < 14; i1++) {
838  setQ (i1, _qhs[i1]); // charges
839  setCV (i1, _chs[i1]); // jacobian dQ/dV * V
840  setGV (i1, _ghs[i1]); // jacobian dI/dV * V
841  for (int i2 = 0; i2 < 14; i2++) {
842  setQV (i1, i2, _jdyna[i1][i2]); // jacobian dQ/dV
843  }
844  }
845 }
846 
847 #include "mod_amp.defs.h"