My Project  0.0.16
QUCS Mapping
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
fa2b.core.cpp
Go to the documentation of this file.
1 /*
2  * fa2b.core.cpp - device implementations for fa2b 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 "fa2b.analogfunction.h"
16 #include "component.h"
17 #include "device.h"
18 #include "fa2b.core.h"
19 
20 #ifndef CIR_fa2b
21 #define CIR_fa2b -1
22 #endif
23 
24 // external nodes
25 #define D 0
26 #define C 1
27 #define B 2
28 #define A 3
29 #define CI 4
30 #define CO 5
31 #define S1 6
32 #define S0 7
33 // internal nodes
34 #define S0n1 8
35 #define S0n2 9
36 #define S1n1 10
37 #define S1n2 11
38 #define COn1 12
39 #define COn2 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 "fa2b"
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 fa2b::fa2b() : circuit (14)
254 {
255  type = CIR_fa2b;
256 }
257 
258 /* Initialization of model. */
259 void fa2b::initModel (void)
260 {
261  // create internal nodes
262  setInternalNode (S0n1, "S0n1");
263  setInternalNode (S0n2, "S0n2");
264  setInternalNode (S1n1, "S1n1");
265  setInternalNode (S1n2, "S1n2");
266  setInternalNode (COn1, "COn1");
267  setInternalNode (COn2, "COn2");
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 fa2b::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 fa2b::restartDC (void)
293 {
294 }
295 
296 /* Initialize Verilog-AMS code. */
297 void fa2b::initVerilog (void)
298 {
299  // initialization of noise variables
300 
301  int i1, i2, i3, i4;
302 
303  // zero charges
304  for (i1 = 0; i1 < 14; i1++) {
305  for (i2 = 0; i2 < 14; i2++) {
306  _charges[i1][i2] = 0.0;
307  } }
308 
309  // zero capacitances
310  for (i1 = 0; i1 < 14; i1++) {
311  for (i2 = 0; i2 < 14; i2++) {
312  for (i3 = 0; i3 < 14; i3++) {
313  for (i4 = 0; i4 < 14; 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 < 14; 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 < 14; 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 fa2b::loadVariables (void)
332 {
333  TR = getPropertyDouble ("TR");
334  Delay = getPropertyDouble ("Delay");
335 }
336 
337 /* #define's for translated code */
338 #undef _DDT
339 #define _DDT(q) q
340 #define _DYNAMIC
341 #define _DERIVATE
342 #define _DDX
343 #define _DERIVATEFORDDX
344 
345 /* Evaluate Verilog-AMS equations in model initialization. */
346 void fa2b::initializeModel (void)
347 {
348 #if defined(_DYNAMIC)
349 #endif
350 {
351 Rd=1e3;
352 #if defined(_DYNAMIC)
353 Cd=((Delay*1.43)/Rd);
354 #endif
355 }
356 }
357 
358 /* Evaluate Verilog-AMS equations in instance initialization. */
359 void fa2b::initializeInstance (void)
360 {
361 }
362 
363 /* Evaluate Verilog-AMS equations in initial step. */
364 void fa2b::initialStep (void)
365 {
366 }
367 
368 /* Evaluate Verilog-AMS equations in final step. */
369 void fa2b::finalStep (void)
370 {
371 }
372 
373 /* Evaluate Verilog-AMS equations in analog block. */
374 void fa2b::calcVerilog (void)
375 {
376 
377 /* ----------------- evaluate verilog analog equations -------------------- */
378 double mCO;
379 #if defined(_DERIVATE)
380 double mCO_VA_GND;
381 double mCO_VC_GND;
382 double mCO_VB_GND;
383 double mCO_VD_GND;
384 double mCO_VCI_GND;
385 #endif
386 double mS1;
387 #if defined(_DERIVATE)
388 double mS1_VB_GND;
389 double mS1_VD_GND;
390 double mS1_VCI_GND;
391 double mS1_VA_GND;
392 double mS1_VC_GND;
393 #endif
394 double mS1b;
395 #if defined(_DERIVATE)
396 double mS1b_VA_GND;
397 double mS1b_VC_GND;
398 #endif
399 double mS1a;
400 #if defined(_DERIVATE)
401 double mS1a_VB_GND;
402 double mS1a_VD_GND;
403 double mS1a_VCI_GND;
404 #endif
405 double mS0;
406 #if defined(_DERIVATE)
407 double mS0_VCI_GND;
408 double mS0_VB_GND;
409 double mS0_VD_GND;
410 #endif
411 double mS0a;
412 #if defined(_DERIVATE)
413 double mS0a_VB_GND;
414 double mS0a_VD_GND;
415 #endif
416 #if defined(_DERIVATE)
417 mS0a_VB_GND=(((1-NP(D)))+(-1.0)*NP(D));
418 mS0a_VD_GND=((NP(B)*(-1.0))+((1-NP(B))));
419 #endif
420 mS0a=((NP(B)*(1-NP(D)))+((1-NP(B))*NP(D)));
421 #if defined(_DERIVATE)
422 mS0_VCI_GND=(((1-mS0a))+(-1.0)*mS0a);
423 mS0_VB_GND=((NP(CI)*(-mS0a_VB_GND))+((1-NP(CI))*mS0a_VB_GND));
424 mS0_VD_GND=((NP(CI)*(-mS0a_VD_GND))+((1-NP(CI))*mS0a_VD_GND));
425 #endif
426 mS0=((NP(CI)*(1-mS0a))+((1-NP(CI))*mS0a));
427 #if defined(_DERIVATE)
428 mS1a_VB_GND=((NP(D))+(NP(CI)));
429 mS1a_VD_GND=((NP(B))+(NP(CI)));
430 mS1a_VCI_GND=((NP(B))+(NP(D)));
431 #endif
432 mS1a=(((NP(B)*NP(D))+(NP(CI)*NP(B)))+(NP(CI)*NP(D)));
433 #if defined(_DERIVATE)
434 mS1b_VA_GND=(((1-NP(C)))+(-1.0)*NP(C));
435 mS1b_VC_GND=((NP(A)*(-1.0))+((1-NP(A))));
436 #endif
437 mS1b=((NP(A)*(1-NP(C)))+((1-NP(A))*NP(C)));
438 #if defined(_DERIVATE)
439 mS1_VB_GND=(mS1a_VB_GND*(1-mS1b)+(-mS1a_VB_GND)*mS1b);
440 mS1_VD_GND=(mS1a_VD_GND*(1-mS1b)+(-mS1a_VD_GND)*mS1b);
441 mS1_VCI_GND=(mS1a_VCI_GND*(1-mS1b)+(-mS1a_VCI_GND)*mS1b);
442 mS1_VA_GND=((mS1a*(-mS1b_VA_GND))+((1-mS1a)*mS1b_VA_GND));
443 mS1_VC_GND=((mS1a*(-mS1b_VC_GND))+((1-mS1a)*mS1b_VC_GND));
444 #endif
445 mS1=((mS1a*(1-mS1b))+((1-mS1a)*mS1b));
446 #if defined(_DERIVATE)
447 mCO_VA_GND=((NP(C))+(mS1a));
448 mCO_VC_GND=((NP(A))+(mS1a));
449 mCO_VB_GND=((NP(A)+NP(C))*mS1a_VB_GND);
450 mCO_VD_GND=((NP(A)+NP(C))*mS1a_VD_GND);
451 mCO_VCI_GND=((NP(A)+NP(C))*mS1a_VCI_GND);
452 #endif
453 mCO=((NP(A)*NP(C))+((NP(A)+NP(C))*mS1a));
454 if
455 ((mS0>=0.5))
456 {
457 #if defined(_DERIVATE)
458 mS0_VCI_GND=0.0;
459 mS0_VB_GND=0.0;
460 mS0_VD_GND=0.0;
461 #endif
462 mS0=1;
463 }
464 else
465 {
466 #if defined(_DERIVATE)
467 mS0_VCI_GND=0.0;
468 mS0_VB_GND=0.0;
469 mS0_VD_GND=0.0;
470 #endif
471 mS0=0;
472 }
473 if
474 ((mS1>=0.5))
475 {
476 #if defined(_DERIVATE)
477 mS1_VB_GND=0.0;
478 mS1_VD_GND=0.0;
479 mS1_VCI_GND=0.0;
480 mS1_VA_GND=0.0;
481 mS1_VC_GND=0.0;
482 #endif
483 mS1=1;
484 }
485 else
486 {
487 #if defined(_DERIVATE)
488 mS1_VB_GND=0.0;
489 mS1_VD_GND=0.0;
490 mS1_VCI_GND=0.0;
491 mS1_VA_GND=0.0;
492 mS1_VC_GND=0.0;
493 #endif
494 mS1=0;
495 }
496 if
497 ((mCO>=0.5))
498 {
499 #if defined(_DERIVATE)
500 mCO_VA_GND=0.0;
501 mCO_VC_GND=0.0;
502 mCO_VB_GND=0.0;
503 mCO_VD_GND=0.0;
504 mCO_VCI_GND=0.0;
505 #endif
506 mCO=1;
507 }
508 else
509 {
510 #if defined(_DERIVATE)
511 mCO_VA_GND=0.0;
512 mCO_VC_GND=0.0;
513 mCO_VB_GND=0.0;
514 mCO_VD_GND=0.0;
515 mCO_VCI_GND=0.0;
516 #endif
517 mCO=0;
518 }
519 {
520 double m00_tanh(d00_tanh0,(TR*(mS0-0.5)))
521 #if defined(_DERIVATE)
522 double m10_tanh(d10_tanh0,d00_tanh0,(TR*(mS0-0.5)))
523 #endif
524 _load_static_residual1(S0n1,((-0.5)*(1+d00_tanh0)));
525 #if defined(_DERIVATE)
526 _load_static_jacobian1(S0n1,D,((-0.5)*(TR*mS0_VD_GND)*d10_tanh0));
527 _load_static_jacobian1(S0n1,B,((-0.5)*(TR*mS0_VB_GND)*d10_tanh0));
528 _load_static_jacobian1(S0n1,CI,((-0.5)*(TR*mS0_VCI_GND)*d10_tanh0));
529 #endif
530 }
532 #if defined(_DERIVATE)
534 #endif
536 #if defined(_DERIVATE)
538 #endif
539 #if defined(_DYNAMIC)
541 #if defined(_DERIVATE)
543 #endif
544 #endif
546 #if defined(_DERIVATE)
548 #endif
550 #if defined(_DERIVATE)
552 #endif
553 {
554 double m00_tanh(d00_tanh0,(TR*(mS1-0.5)))
555 #if defined(_DERIVATE)
556 double m10_tanh(d10_tanh0,d00_tanh0,(TR*(mS1-0.5)))
557 #endif
558 _load_static_residual1(S1n1,((-0.5)*(1+d00_tanh0)));
559 #if defined(_DERIVATE)
560 _load_static_jacobian1(S1n1,C,((-0.5)*(TR*mS1_VC_GND)*d10_tanh0));
561 _load_static_jacobian1(S1n1,A,((-0.5)*(TR*mS1_VA_GND)*d10_tanh0));
562 _load_static_jacobian1(S1n1,CI,((-0.5)*(TR*mS1_VCI_GND)*d10_tanh0));
563 _load_static_jacobian1(S1n1,D,((-0.5)*(TR*mS1_VD_GND)*d10_tanh0));
564 _load_static_jacobian1(S1n1,B,((-0.5)*(TR*mS1_VB_GND)*d10_tanh0));
565 #endif
566 }
568 #if defined(_DERIVATE)
570 #endif
572 #if defined(_DERIVATE)
574 #endif
575 #if defined(_DYNAMIC)
577 #if defined(_DERIVATE)
579 #endif
580 #endif
582 #if defined(_DERIVATE)
584 #endif
586 #if defined(_DERIVATE)
588 #endif
589 {
590 double m00_tanh(d00_tanh0,(TR*(mCO-0.5)))
591 #if defined(_DERIVATE)
592 double m10_tanh(d10_tanh0,d00_tanh0,(TR*(mCO-0.5)))
593 #endif
594 _load_static_residual1(COn1,((-0.5)*(1+d00_tanh0)));
595 #if defined(_DERIVATE)
596 _load_static_jacobian1(COn1,CI,((-0.5)*(TR*mCO_VCI_GND)*d10_tanh0));
597 _load_static_jacobian1(COn1,D,((-0.5)*(TR*mCO_VD_GND)*d10_tanh0));
598 _load_static_jacobian1(COn1,B,((-0.5)*(TR*mCO_VB_GND)*d10_tanh0));
599 _load_static_jacobian1(COn1,C,((-0.5)*(TR*mCO_VC_GND)*d10_tanh0));
600 _load_static_jacobian1(COn1,A,((-0.5)*(TR*mCO_VA_GND)*d10_tanh0));
601 #endif
602 }
604 #if defined(_DERIVATE)
606 #endif
608 #if defined(_DERIVATE)
610 #endif
611 #if defined(_DYNAMIC)
613 #if defined(_DERIVATE)
615 #endif
616 #endif
618 #if defined(_DERIVATE)
620 #endif
622 #if defined(_DERIVATE)
624 #endif
625 
626 /* ------------------ end of verilog analog equations --------------------- */
627 
628 /* ------------------ evaluate verilog noise equations -------------------- */
629 
630 /* ------------------- end of verilog noise equations --------------------- */
631 }
632 
633 /* Perform DC iteration. */
634 void fa2b::calcDC (void)
635 {
636  // evaluate Verilog code
637  initVerilog ();
638  calcVerilog ();
639 
640  // fill right hand side and static jacobian
641  for (int i1 = 0; i1 < 14; i1++) {
642  setI (i1, _rhs[i1]);
643  for (int i2 = 0; i2 < 14; i2++) {
644  setY (i1, i2, _jstat[i1][i2]);
645  }
646  }
647 }
648 
649 /* Save operating points. */
651 {
652  // save global instance operating points
653 }
654 
655 /* Load operating points. */
657 {
658 }
659 
660 /* Calculate operating points. */
662 {
663 }
664 
665 /* Initialization of AC analysis. */
666 void fa2b::initAC (void)
667 {
668  allocMatrixMNA ();
669 }
670 
671 /* Perform AC calculations. */
672 void fa2b::calcAC (nr_double_t frequency)
673 {
674  setMatrixY (calcMatrixY (frequency));
675 }
676 
677 /* Compute Y-matrix for AC analysis. */
678 matrix fa2b::calcMatrixY (nr_double_t frequency)
679 {
680  _freq = frequency;
682  matrix y (14);
683 
684  for (int i1 = 0; i1 < 14; i1++) {
685  for (int i2 = 0; i2 < 14; i2++) {
686  y (i1,i2) = rect (_jstat[i1][i2], _jdyna[i1][i2] * 2 * M_PI * _freq);
687  }
688  }
689 
690  return y;
691 }
692 
693 /* Initialization of S-parameter analysis. */
694 void fa2b::initSP (void)
695 {
696  allocMatrixS ();
697 }
698 
699 /* Perform S-parameter calculations. */
700 void fa2b::calcSP (nr_double_t frequency)
701 {
702  setMatrixS (ytos (calcMatrixY (frequency)));
703 }
704 
705 /* Initialization of transient analysis. */
706 void fa2b::initTR (void)
707 {
708  setStates (2 * 14 * 14);
709  initDC ();
710 }
711 
712 /* Perform transient analysis iteration step. */
713 void fa2b::calcTR (nr_double_t)
714 {
715  doHB = 0;
716  doAC = 1;
717  doTR = 1;
718  calcDC ();
719 
720  int i1, i2, i3, i4, state;
721 
722  // 2-node charge integrations
723  for (i1 = 0; i1 < 14; i1++) {
724  for (i2 = 0; i2 < 14; i2++) {
725  state = 2 * (i2 + 14 * i1);
726  if (i1 != i2)
727  if (_charges[i1][i2] != 0.0)
728  transientCapacitanceQ (state, i1, i2, _charges[i1][i2]);
729  } }
730 
731  // 1-node charge integrations
732  for (i1 = 0; i1 < 14; i1++) {
733  state = 2 * (i1 + 14 * i1);
734  if (_charges[i1][i1] != 0.0)
735  transientCapacitanceQ (state, i1, _charges[i1][i1]);
736  }
737 
738  // charge: 2-node, voltage: 2-node
739  for (i1 = 0; i1 < 14; i1++) {
740  for (i2 = 0; i2 < 14; i2++) {
741  if (i1 != i2)
742  for (i3 = 0; i3 < 14; i3++) {
743  for (i4 = 0; i4 < 14; i4++) {
744  if (i3 != i4)
745  if (_caps[i1][i2][i3][i4] != 0.0)
746  transientCapacitanceC (i1, i2, i3, i4, _caps[i1][i2][i3][i4], BP(i3,i4));
747  } } } }
748 
749  // charge: 2-node, voltage: 1-node
750  for (i1 = 0; i1 < 14; i1++) {
751  for (i2 = 0; i2 < 14; i2++) {
752  if (i1 != i2)
753  for (i3 = 0; i3 < 14; i3++) {
754  if (_caps[i1][i2][i3][i3] != 0.0)
755  transientCapacitanceC2Q (i1, i2, i3, _caps[i1][i2][i3][i3], NP(i3));
756  } } }
757 
758  // charge: 1-node, voltage: 2-node
759  for (i1 = 0; i1 < 14; i1++) {
760  for (i3 = 0; i3 < 14; i3++) {
761  for (i4 = 0; i4 < 14; i4++) {
762  if (i3 != i4)
763  if (_caps[i1][i1][i3][i4] != 0.0)
764  transientCapacitanceC2V (i1, i3, i4, _caps[i1][i1][i3][i4], BP(i3,i4));
765  } } }
766 
767  // charge: 1-node, voltage: 1-node
768  for (i1 = 0; i1 < 14; i1++) {
769  for (i3 = 0; i3 < 14; i3++) {
770  if (_caps[i1][i1][i3][i3] != 0.0)
771  transientCapacitanceC (i1, i3, _caps[i1][i1][i3][i3], NP(i3));
772  } }
773 }
774 
775 /* Compute Cy-matrix for AC noise analysis. */
776 matrix fa2b::calcMatrixCy (nr_double_t frequency)
777 {
778  _freq = frequency;
779  matrix cy (14);
780 
781 
782  return cy;
783 }
784 
785 /* Perform AC noise computations. */
786 void fa2b::calcNoiseAC (nr_double_t frequency)
787 {
788  setMatrixN (calcMatrixCy (frequency));
789 }
790 
791 /* Perform S-parameter noise computations. */
792 void fa2b::calcNoiseSP (nr_double_t frequency)
793 {
794  setMatrixN (cytocs (calcMatrixCy (frequency) * z0, getMatrixS ()));
795 }
796 
797 /* Initialization of HB analysis. */
798 void fa2b::initHB (int)
799 {
800  initDC ();
801  allocMatrixHB ();
802 }
803 
804 /* Perform HB analysis. */
805 void fa2b::calcHB (int)
806 {
807  doHB = 1;
808  doAC = 1;
809  doTR = 0;
810 
811  // jacobian dI/dV and currents get filled
812  calcDC ();
814 
815  // fill in HB matrices
816  for (int i1 = 0; i1 < 14; i1++) {
817  setQ (i1, _qhs[i1]); // charges
818  setCV (i1, _chs[i1]); // jacobian dQ/dV * V
819  setGV (i1, _ghs[i1]); // jacobian dI/dV * V
820  for (int i2 = 0; i2 < 14; i2++) {
821  setQV (i1, i2, _jdyna[i1][i2]); // jacobian dQ/dV
822  }
823  }
824 }
825 
826 #include "fa2b.defs.h"