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