My Project  0.0.16
QUCS Mapping
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
jkff_SR.core.cpp
Go to the documentation of this file.
1 /*
2  * jkff_SR.core.cpp - device implementations for jkff_SR 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 "jkff_SR.analogfunction.h"
16 #include "component.h"
17 #include "device.h"
18 #include "jkff_SR.core.h"
19 
20 #ifndef CIR_jkff_SR
21 #define CIR_jkff_SR -1
22 #endif
23 
24 // external nodes
25 #define S 0
26 #define J 1
27 #define CLK 2
28 #define KO 3
29 #define R 4
30 #define QB 5
31 #define QO 6
32 // internal nodes
33 #define n1 7
34 #define n1A 8
35 #define n2 9
36 #define n3 10
37 #define n3A 11
38 #define n4 12
39 #define Dsig 13
40 #define QA 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 "jkff_SR"
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 jkff_SR::jkff_SR() : circuit (15)
255 {
256  type = CIR_jkff_SR;
257 }
258 
259 /* Initialization of model. */
260 void jkff_SR::initModel (void)
261 {
262  // create internal nodes
263  setInternalNode (n1, "n1");
264  setInternalNode (n1A, "n1A");
265  setInternalNode (n2, "n2");
266  setInternalNode (n3, "n3");
267  setInternalNode (n3A, "n3A");
268  setInternalNode (n4, "n4");
269  setInternalNode (Dsig, "Dsig");
270  setInternalNode (QA, "QA");
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 jkff_SR::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 jkff_SR::initVerilog (void)
301 {
302  // initialization of noise variables
303 
304  int i1, i2, i3, i4;
305 
306  // zero charges
307  for (i1 = 0; i1 < 15; i1++) {
308  for (i2 = 0; i2 < 15; i2++) {
309  _charges[i1][i2] = 0.0;
310  } }
311 
312  // zero capacitances
313  for (i1 = 0; i1 < 15; i1++) {
314  for (i2 = 0; i2 < 15; i2++) {
315  for (i3 = 0; i3 < 15; i3++) {
316  for (i4 = 0; i4 < 15; 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 < 15; 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 < 15; 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 jkff_SR::loadVariables (void)
335 {
336  TR_H = getPropertyDouble ("TR_H");
337  TR_L = getPropertyDouble ("TR_L");
338  Delay = getPropertyDouble ("Delay");
339 }
340 
341 /* #define's for translated code */
342 #undef _DDT
343 #define _DDT(q) q
344 #define _DYNAMIC
345 #define _DERIVATE
346 #define _DDX
347 #define _DERIVATEFORDDX
348 
349 /* Evaluate Verilog-AMS equations in model initialization. */
350 void jkff_SR::initializeModel (void)
351 {
352 #if defined(_DYNAMIC)
353 #endif
354 {
355 Rd=1e3;
356 #if defined(_DYNAMIC)
357 Ccc=((Delay*1.43)/Rd);
358 #endif
359 }
360 }
361 
362 /* Evaluate Verilog-AMS equations in instance initialization. */
363 void jkff_SR::initializeInstance (void)
364 {
365 }
366 
367 /* Evaluate Verilog-AMS equations in initial step. */
368 void jkff_SR::initialStep (void)
369 {
370 }
371 
372 /* Evaluate Verilog-AMS equations in final step. */
373 void jkff_SR::finalStep (void)
374 {
375 }
376 
377 /* Evaluate Verilog-AMS equations in analog block. */
378 void jkff_SR::calcVerilog (void)
379 {
380 
381 /* ----------------- evaluate verilog analog equations -------------------- */
382 {
383 double m00_tanh(d00_tanh0,((TR_H*((NP(J)*NP(QB))+((1-NP(KO))*NP(QO))))-0.5))
384 #if defined(_DERIVATE)
385 double m10_tanh(d10_tanh0,d00_tanh0,((TR_H*((NP(J)*NP(QB))+((1-NP(KO))*NP(QO))))-0.5))
386 #endif
387 _load_static_residual1(Dsig,((-0.5)*d00_tanh0));
388 #if defined(_DERIVATE)
389 _load_static_jacobian1(Dsig,QO,((-0.5)*(TR_H*((1-NP(KO))))*d10_tanh0));
390 _load_static_jacobian1(Dsig,KO,((-0.5)*(TR_H*(-1.0)*NP(QO))*d10_tanh0));
391 _load_static_jacobian1(Dsig,QB,((-0.5)*(TR_H*(NP(J)))*d10_tanh0));
392 _load_static_jacobian1(Dsig,J,((-0.5)*(TR_H*(NP(QB)))*d10_tanh0));
393 #endif
394 }
396 #if defined(_DERIVATE)
398 #endif
399 {
400 double m00_tanh(d00_tanh0,(TR_H*(((NP(n4)*NP(n2))*NP(S))-0.5)))
401 #if defined(_DERIVATE)
402 double m10_tanh(d10_tanh0,d00_tanh0,(TR_H*(((NP(n4)*NP(n2))*NP(S))-0.5)))
403 #endif
404 _load_static_residual1(n1,((-0.5)*(1-d00_tanh0)));
405 #if defined(_DERIVATE)
406 _load_static_jacobian1(n1,S,((-0.5)*(-(TR_H*((NP(n4)*NP(n2))))*d10_tanh0)));
407 _load_static_jacobian1(n1,n2,((-0.5)*(-(TR_H*(NP(n4))*NP(S))*d10_tanh0)));
408 _load_static_jacobian1(n1,n4,((-0.5)*(-(TR_H*(NP(n2))*NP(S))*d10_tanh0)));
409 #endif
410 }
412 #if defined(_DERIVATE)
414 #endif
415 {
416 double m00_tanh(d00_tanh0,(TR_L*(((NP(n1A)*NP(CLK))*NP(R))-0.5)))
417 #if defined(_DERIVATE)
418 double m10_tanh(d10_tanh0,d00_tanh0,(TR_L*(((NP(n1A)*NP(CLK))*NP(R))-0.5)))
419 #endif
420 _load_static_residual1(n2,((-0.5)*(1-d00_tanh0)));
421 #if defined(_DERIVATE)
422 _load_static_jacobian1(n2,R,((-0.5)*(-(TR_L*((NP(n1A)*NP(CLK))))*d10_tanh0)));
423 _load_static_jacobian1(n2,CLK,((-0.5)*(-(TR_L*(NP(n1A))*NP(R))*d10_tanh0)));
424 _load_static_jacobian1(n2,n1A,((-0.5)*(-(TR_L*(NP(CLK))*NP(R))*d10_tanh0)));
425 #endif
426 }
428 #if defined(_DERIVATE)
430 #endif
431 {
432 double m00_tanh(d00_tanh0,(TR_H*(((NP(n2)*NP(CLK))*NP(n4))-0.5)))
433 #if defined(_DERIVATE)
434 double m10_tanh(d10_tanh0,d00_tanh0,(TR_H*(((NP(n2)*NP(CLK))*NP(n4))-0.5)))
435 #endif
436 _load_static_residual1(n3,((-0.5)*(1-d00_tanh0)));
437 #if defined(_DERIVATE)
438 _load_static_jacobian1(n3,n4,((-0.5)*(-(TR_H*((NP(n2)*NP(CLK))))*d10_tanh0)));
439 _load_static_jacobian1(n3,CLK,((-0.5)*(-(TR_H*(NP(n2))*NP(n4))*d10_tanh0)));
440 _load_static_jacobian1(n3,n2,((-0.5)*(-(TR_H*(NP(CLK))*NP(n4))*d10_tanh0)));
441 #endif
442 }
444 #if defined(_DERIVATE)
446 #endif
447 {
448 double m00_tanh(d00_tanh0,(TR_L*(((NP(n3A)*NP(Dsig))*NP(R))-0.5)))
449 #if defined(_DERIVATE)
450 double m10_tanh(d10_tanh0,d00_tanh0,(TR_L*(((NP(n3A)*NP(Dsig))*NP(R))-0.5)))
451 #endif
452 _load_static_residual1(n4,((-0.5)*(1-d00_tanh0)));
453 #if defined(_DERIVATE)
454 _load_static_jacobian1(n4,R,((-0.5)*(-(TR_L*((NP(n3A)*NP(Dsig))))*d10_tanh0)));
455 _load_static_jacobian1(n4,Dsig,((-0.5)*(-(TR_L*(NP(n3A))*NP(R))*d10_tanh0)));
456 _load_static_jacobian1(n4,n3A,((-0.5)*(-(TR_L*(NP(Dsig))*NP(R))*d10_tanh0)));
457 #endif
458 }
460 #if defined(_DERIVATE)
462 #endif
463 {
464 double m00_tanh(d00_tanh0,(TR_H*(((NP(n2)*NP(QB))*NP(S))-0.5)))
465 #if defined(_DERIVATE)
466 double m10_tanh(d10_tanh0,d00_tanh0,(TR_H*(((NP(n2)*NP(QB))*NP(S))-0.5)))
467 #endif
468 _load_static_residual1(QO,((-0.5)*(1-d00_tanh0)));
469 #if defined(_DERIVATE)
470 _load_static_jacobian1(QO,S,((-0.5)*(-(TR_H*((NP(n2)*NP(QB))))*d10_tanh0)));
471 _load_static_jacobian1(QO,QB,((-0.5)*(-(TR_H*(NP(n2))*NP(S))*d10_tanh0)));
472 _load_static_jacobian1(QO,n2,((-0.5)*(-(TR_H*(NP(QB))*NP(S))*d10_tanh0)));
473 #endif
474 }
476 #if defined(_DERIVATE)
478 #endif
479 {
480 double m00_tanh(d00_tanh0,(TR_L*(((NP(QA)*NP(n3A))*NP(R))-0.5)))
481 #if defined(_DERIVATE)
482 double m10_tanh(d10_tanh0,d00_tanh0,(TR_L*(((NP(QA)*NP(n3A))*NP(R))-0.5)))
483 #endif
484 _load_static_residual1(QB,((-0.5)*(1-d00_tanh0)));
485 #if defined(_DERIVATE)
486 _load_static_jacobian1(QB,R,((-0.5)*(-(TR_L*((NP(QA)*NP(n3A))))*d10_tanh0)));
487 _load_static_jacobian1(QB,n3A,((-0.5)*(-(TR_L*(NP(QA))*NP(R))*d10_tanh0)));
488 _load_static_jacobian1(QB,QA,((-0.5)*(-(TR_L*(NP(n3A))*NP(R))*d10_tanh0)));
489 #endif
490 }
492 #if defined(_DERIVATE)
494 #endif
496 #if defined(_DERIVATE)
498 #endif
499 #if defined(_DYNAMIC)
501 #if defined(_DERIVATE)
503 #endif
504 #endif
506 #if defined(_DERIVATE)
508 #endif
509 #if defined(_DYNAMIC)
511 #if defined(_DERIVATE)
513 #endif
514 #endif
516 #if defined(_DERIVATE)
518 #endif
519 #if defined(_DYNAMIC)
521 #if defined(_DERIVATE)
523 #endif
524 #endif
525 
526 /* ------------------ end of verilog analog equations --------------------- */
527 
528 /* ------------------ evaluate verilog noise equations -------------------- */
529 
530 /* ------------------- end of verilog noise equations --------------------- */
531 }
532 
533 /* Perform DC iteration. */
534 void jkff_SR::calcDC (void)
535 {
536  // evaluate Verilog code
537  initVerilog ();
538  calcVerilog ();
539 
540  // fill right hand side and static jacobian
541  for (int i1 = 0; i1 < 15; i1++) {
542  setI (i1, _rhs[i1]);
543  for (int i2 = 0; i2 < 15; i2++) {
544  setY (i1, i2, _jstat[i1][i2]);
545  }
546  }
547 }
548 
549 /* Save operating points. */
551 {
552  // save global instance operating points
553 }
554 
555 /* Load operating points. */
557 {
558 }
559 
560 /* Calculate operating points. */
562 {
563 }
564 
565 /* Initialization of AC analysis. */
566 void jkff_SR::initAC (void)
567 {
568  allocMatrixMNA ();
569 }
570 
571 /* Perform AC calculations. */
572 void jkff_SR::calcAC (nr_double_t frequency)
573 {
574  setMatrixY (calcMatrixY (frequency));
575 }
576 
577 /* Compute Y-matrix for AC analysis. */
578 matrix jkff_SR::calcMatrixY (nr_double_t frequency)
579 {
580  _freq = frequency;
582  matrix y (15);
583 
584  for (int i1 = 0; i1 < 15; i1++) {
585  for (int i2 = 0; i2 < 15; i2++) {
586  y (i1,i2) = rect (_jstat[i1][i2], _jdyna[i1][i2] * 2 * M_PI * _freq);
587  }
588  }
589 
590  return y;
591 }
592 
593 /* Initialization of S-parameter analysis. */
594 void jkff_SR::initSP (void)
595 {
596  allocMatrixS ();
597 }
598 
599 /* Perform S-parameter calculations. */
600 void jkff_SR::calcSP (nr_double_t frequency)
601 {
602  setMatrixS (ytos (calcMatrixY (frequency)));
603 }
604 
605 /* Initialization of transient analysis. */
606 void jkff_SR::initTR (void)
607 {
608  setStates (2 * 15 * 15);
609  initDC ();
610 }
611 
612 /* Perform transient analysis iteration step. */
613 void jkff_SR::calcTR (nr_double_t)
614 {
615  doHB = 0;
616  doAC = 1;
617  doTR = 1;
618  calcDC ();
619 
620  int i1, i2, i3, i4, state;
621 
622  // 2-node charge integrations
623  for (i1 = 0; i1 < 15; i1++) {
624  for (i2 = 0; i2 < 15; i2++) {
625  state = 2 * (i2 + 15 * i1);
626  if (i1 != i2)
627  if (_charges[i1][i2] != 0.0)
628  transientCapacitanceQ (state, i1, i2, _charges[i1][i2]);
629  } }
630 
631  // 1-node charge integrations
632  for (i1 = 0; i1 < 15; i1++) {
633  state = 2 * (i1 + 15 * i1);
634  if (_charges[i1][i1] != 0.0)
635  transientCapacitanceQ (state, i1, _charges[i1][i1]);
636  }
637 
638  // charge: 2-node, voltage: 2-node
639  for (i1 = 0; i1 < 15; i1++) {
640  for (i2 = 0; i2 < 15; i2++) {
641  if (i1 != i2)
642  for (i3 = 0; i3 < 15; i3++) {
643  for (i4 = 0; i4 < 15; i4++) {
644  if (i3 != i4)
645  if (_caps[i1][i2][i3][i4] != 0.0)
646  transientCapacitanceC (i1, i2, i3, i4, _caps[i1][i2][i3][i4], BP(i3,i4));
647  } } } }
648 
649  // charge: 2-node, voltage: 1-node
650  for (i1 = 0; i1 < 15; i1++) {
651  for (i2 = 0; i2 < 15; i2++) {
652  if (i1 != i2)
653  for (i3 = 0; i3 < 15; i3++) {
654  if (_caps[i1][i2][i3][i3] != 0.0)
655  transientCapacitanceC2Q (i1, i2, i3, _caps[i1][i2][i3][i3], NP(i3));
656  } } }
657 
658  // charge: 1-node, voltage: 2-node
659  for (i1 = 0; i1 < 15; i1++) {
660  for (i3 = 0; i3 < 15; i3++) {
661  for (i4 = 0; i4 < 15; i4++) {
662  if (i3 != i4)
663  if (_caps[i1][i1][i3][i4] != 0.0)
664  transientCapacitanceC2V (i1, i3, i4, _caps[i1][i1][i3][i4], BP(i3,i4));
665  } } }
666 
667  // charge: 1-node, voltage: 1-node
668  for (i1 = 0; i1 < 15; i1++) {
669  for (i3 = 0; i3 < 15; i3++) {
670  if (_caps[i1][i1][i3][i3] != 0.0)
671  transientCapacitanceC (i1, i3, _caps[i1][i1][i3][i3], NP(i3));
672  } }
673 }
674 
675 /* Compute Cy-matrix for AC noise analysis. */
676 matrix jkff_SR::calcMatrixCy (nr_double_t frequency)
677 {
678  _freq = frequency;
679  matrix cy (15);
680 
681 
682  return cy;
683 }
684 
685 /* Perform AC noise computations. */
686 void jkff_SR::calcNoiseAC (nr_double_t frequency)
687 {
688  setMatrixN (calcMatrixCy (frequency));
689 }
690 
691 /* Perform S-parameter noise computations. */
692 void jkff_SR::calcNoiseSP (nr_double_t frequency)
693 {
694  setMatrixN (cytocs (calcMatrixCy (frequency) * z0, getMatrixS ()));
695 }
696 
697 /* Initialization of HB analysis. */
698 void jkff_SR::initHB (int)
699 {
700  initDC ();
701  allocMatrixHB ();
702 }
703 
704 /* Perform HB analysis. */
705 void jkff_SR::calcHB (int)
706 {
707  doHB = 1;
708  doAC = 1;
709  doTR = 0;
710 
711  // jacobian dI/dV and currents get filled
712  calcDC ();
714 
715  // fill in HB matrices
716  for (int i1 = 0; i1 < 15; i1++) {
717  setQ (i1, _qhs[i1]); // charges
718  setCV (i1, _chs[i1]); // jacobian dQ/dV * V
719  setGV (i1, _ghs[i1]); // jacobian dI/dV * V
720  for (int i2 = 0; i2 < 15; i2++) {
721  setQV (i1, i2, _jdyna[i1][i2]); // jacobian dQ/dV
722  }
723  }
724 }
725 
726 #include "jkff_SR.defs.h"