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