LCOV - code coverage report
Current view: top level - src/components/verilog - DLS_nto1.core.cpp (source / functions) Hit Total Coverage
Test: qucs-core-0.0.19 Code Coverage Lines: 0 173 0.0 %
Date: 2015-01-05 16:01:02 Functions: 0 28 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 170 0.0 %

           Branch data     Line data    Source code
       1                 :            : /*
       2                 :            :  * DLS_nto1.core.cpp - device implementations for DLS_nto1 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 "DLS_nto1.analogfunction.h"
      16                 :            : #include "component.h"
      17                 :            : #include "device.h"
      18                 :            : #include "DLS_nto1.core.h"
      19                 :            : 
      20                 :            : #ifndef CIR_DLS_nto1
      21                 :            : #define CIR_DLS_nto1 -1
      22                 :            : #endif
      23                 :            : 
      24                 :            : // external nodes
      25                 :            : #define Lin 0
      26                 :            : #define Lout 1
      27                 :            : // internal nodes
      28                 :            : #define n1 2
      29                 :            : #define n2 3
      30                 :            : 
      31                 :            : // useful macro definitions
      32                 :            : #define NP(node) real (getV (node))
      33                 :            : #define BP(pnode,nnode) (NP(pnode) - NP(nnode))
      34                 :            : #define _load_static_residual2(pnode,nnode,current)\
      35                 :            :         _rhs[pnode] -= current;\
      36                 :            :         _rhs[nnode] += current;
      37                 :            : #define _load_static_augmented_residual2(pnode,nnode,current)\
      38                 :            :         _rhs[pnode] -= current;\
      39                 :            :         _rhs[nnode] += current;
      40                 :            : #define _load_static_residual1(node,current)\
      41                 :            :         _rhs[node] -= current;
      42                 :            : #define _load_static_augmented_residual1(node,current)\
      43                 :            :         _rhs[node] -= current;
      44                 :            : #define _load_static_jacobian4(pnode,nnode,vpnode,vnnode,conductance)\
      45                 :            :         _jstat[pnode][vpnode] += conductance;\
      46                 :            :         _jstat[nnode][vnnode] += conductance;\
      47                 :            :         _jstat[pnode][vnnode] -= conductance;\
      48                 :            :         _jstat[nnode][vpnode] -= conductance;\
      49                 :            :         if (doHB) {\
      50                 :            :         _ghs[pnode] += conductance * BP(vpnode,vnnode);\
      51                 :            :         _ghs[nnode] -= conductance * BP(vpnode,vnnode);\
      52                 :            :         } else {\
      53                 :            :         _rhs[pnode] += conductance * BP(vpnode,vnnode);\
      54                 :            :         _rhs[nnode] -= conductance * BP(vpnode,vnnode);\
      55                 :            :         }
      56                 :            : #define _load_static_jacobian2p(node,vpnode,vnnode,conductance)\
      57                 :            :         _jstat[node][vpnode] += conductance;\
      58                 :            :         _jstat[node][vnnode] -= conductance;\
      59                 :            :         if (doHB) {\
      60                 :            :         _ghs[node] += conductance * BP(vpnode,vnnode);\
      61                 :            :         } else {\
      62                 :            :         _rhs[node] += conductance * BP(vpnode,vnnode);\
      63                 :            :         }
      64                 :            : #define _load_static_jacobian2s(pnode,nnode,node,conductance)\
      65                 :            :         _jstat[pnode][node] += conductance;\
      66                 :            :         _jstat[nnode][node] -= conductance;\
      67                 :            :         if (doHB) {\
      68                 :            :         _ghs[pnode] += conductance * NP(node);\
      69                 :            :         _ghs[nnode] -= conductance * NP(node);\
      70                 :            :         } else {\
      71                 :            :         _rhs[pnode] += conductance * NP(node);\
      72                 :            :         _rhs[nnode] -= conductance * NP(node);\
      73                 :            :         }
      74                 :            : #define _load_static_jacobian1(node,vnode,conductance)\
      75                 :            :         _jstat[node][vnode] += conductance;\
      76                 :            :         if (doHB) {\
      77                 :            :         _ghs[node] += conductance * NP(vnode);\
      78                 :            :         } else {\
      79                 :            :         _rhs[node] += conductance * NP(vnode);\
      80                 :            :         }
      81                 :            : #define _load_dynamic_residual2(pnode,nnode,charge)\
      82                 :            :         if (doTR) _charges[pnode][nnode] += charge;\
      83                 :            :         if (doHB) {\
      84                 :            :         _qhs[pnode] -= charge;\
      85                 :            :         _qhs[nnode] += charge;\
      86                 :            :         }
      87                 :            : #define _load_dynamic_residual1(node,charge)\
      88                 :            :         if (doTR) _charges[node][node] += charge;\
      89                 :            :         if (doHB) {\
      90                 :            :         _qhs[node] -= charge;\
      91                 :            :         }
      92                 :            : #define _load_dynamic_jacobian4(pnode,nnode,vpnode,vnnode,capacitance)\
      93                 :            :         if (doAC) {\
      94                 :            :         _jdyna[pnode][vpnode] += capacitance;\
      95                 :            :         _jdyna[nnode][vnnode] += capacitance;\
      96                 :            :         _jdyna[pnode][vnnode] -= capacitance;\
      97                 :            :         _jdyna[nnode][vpnode] -= capacitance;\
      98                 :            :         }\
      99                 :            :         if (doTR) {\
     100                 :            :         _caps[pnode][nnode][vpnode][vnnode] += capacitance;\
     101                 :            :         }\
     102                 :            :         if (doHB) {\
     103                 :            :         _chs[pnode] += capacitance * BP(vpnode,vnnode);\
     104                 :            :         _chs[nnode] -= capacitance * BP(vpnode,vnnode);\
     105                 :            :         }
     106                 :            : #define _load_dynamic_jacobian2s(pnode,nnode,vnode,capacitance)\
     107                 :            :         if (doAC) {\
     108                 :            :         _jdyna[pnode][vnode] += capacitance;\
     109                 :            :         _jdyna[nnode][vnode] -= capacitance;\
     110                 :            :         }\
     111                 :            :         if (doTR) {\
     112                 :            :         _caps[pnode][nnode][vnode][vnode] += capacitance;\
     113                 :            :         }\
     114                 :            :         if (doHB) {\
     115                 :            :         _chs[pnode] += capacitance * NP(vnode);\
     116                 :            :         _chs[nnode] -= capacitance * NP(vnode);\
     117                 :            :         }
     118                 :            : #define _load_dynamic_jacobian2p(node,vpnode,vnnode,capacitance)\
     119                 :            :         if (doAC) {\
     120                 :            :         _jdyna[node][vpnode] += capacitance;\
     121                 :            :         _jdyna[node][vnnode] -= capacitance;\
     122                 :            :         }\
     123                 :            :         if (doTR) {\
     124                 :            :         _caps[node][node][vpnode][vnnode] += capacitance;\
     125                 :            :         }\
     126                 :            :         if (doHB) {\
     127                 :            :         _chs[node] += capacitance * BP(vpnode,vnnode);\
     128                 :            :         }
     129                 :            : #define _load_dynamic_jacobian1(node,vnode,capacitance)\
     130                 :            :         if (doAC) {\
     131                 :            :         _jdyna[node][vnode] += capacitance;\
     132                 :            :         }\
     133                 :            :         if (doTR) {\
     134                 :            :         _caps[node][node][vnode][vnode] += capacitance;\
     135                 :            :         }\
     136                 :            :         if (doHB) {\
     137                 :            :         _chs[node] += capacitance * NP(vnode);\
     138                 :            :         }
     139                 :            : 
     140                 :            : #define _save_whitenoise1(n1,pwr,type)\
     141                 :            :         _white_pwr[n1][n1] += pwr;
     142                 :            : #define _save_whitenoise2(n1,n2,pwr,type)\
     143                 :            :         _white_pwr[n1][n2] += pwr;
     144                 :            : #define _save_flickernoise1(n1,pwr,exp,type)\
     145                 :            :         _flicker_pwr[n1][n1] += pwr;\
     146                 :            :         _flicker_exp[n1][n1] += exp;
     147                 :            : #define _save_flickernoise2(n1,n2,pwr,exp,type)\
     148                 :            :         _flicker_pwr[n1][n2] += pwr;\
     149                 :            :         _flicker_exp[n1][n2] += exp;
     150                 :            : #define _load_whitenoise2(n1,n2,pwr)\
     151                 :            :         cy (n1,n2) -= pwr/kB/T0; cy (n2,n1) -= pwr/kB/T0;\
     152                 :            :         cy (n1,n1) += pwr/kB/T0; cy (n2,n2) += pwr/kB/T0;
     153                 :            : #define _load_whitenoise1(n1,pwr)\
     154                 :            :         cy (n1,n1) += pwr/kB/T0;
     155                 :            : #define _load_flickernoise2(n1,n2,pwr,exp)\
     156                 :            :         cy (n1,n2) -= pwr*pow(_freq,-exp)/kB/T0;\
     157                 :            :         cy (n2,n1) -= pwr*pow(_freq,-exp)/kB/T0;\
     158                 :            :         cy (n1,n1) += pwr*pow(_freq,-exp)/kB/T0;\
     159                 :            :         cy (n2,n2) += pwr*pow(_freq,-exp)/kB/T0;
     160                 :            : #define _load_flickernoise1(n1,pwr,exp)\
     161                 :            :         cy (n1,n1) += pwr*pow(_freq,-exp)/kB/T0;
     162                 :            : 
     163                 :            : // derivative helper macros
     164                 :            : // transcendental LRM p. 59
     165                 :            : #define m00_cos(v00,x)          v00 = cos(x);
     166                 :            : #define m10_cos(v10,v00,x)      v10 = (-sin(x));
     167                 :            : #define m00_sin(v00,x)          v00 = sin(x);
     168                 :            : #define m10_sin(v10,v00,x)      v10 = (cos(x));
     169                 :            : #define m00_tan(v00,x)          v00 = tan(x);
     170                 :            : #define m10_tan(v10,v00,x)      v10 = (1.0/cos(x)/cos(x));
     171                 :            : #define m00_cosh(v00,x)         v00 = cosh(x);
     172                 :            : #define m10_cosh(v10,v00,x)     v10 = (sinh(x));
     173                 :            : #define m00_sinh(v00,x)         v00 = sinh(x);
     174                 :            : #define m10_sinh(v10,v00,x)     v10 = (cosh(x));
     175                 :            : #define m00_tanh(v00,x)         v00 = tanh(x);
     176                 :            : #define m10_tanh(v10,v00,x)     v10 = (1.0/cosh(x)/cosh(x));
     177                 :            : #define m00_acos(v00,x)         v00 = acos(x);
     178                 :            : #define m10_acos(v10,v00,x)     v10 = (-1.0/sqrt(1-x*x));
     179                 :            : #define m00_asin(v00,x)         v00 = asin(x);
     180                 :            : #define m10_asin(v10,v00,x)     v10 = (+1.0/sqrt(1-x*x));
     181                 :            : #define m00_atan(v00,x)         v00 = atan(x);
     182                 :            : #define m10_atan(v10,v00,x)     v10 = (+1.0/(1+x*x));
     183                 :            : #define m00_hypot(v00,x,y)      v00 = sqrt((x)*(x)+(y)*(y));
     184                 :            : #define m10_hypot(v10,v00,x,y)  v10 = (x)/(v00);
     185                 :            : #define m11_hypot(v11,v00,x,y)  v11 = (y)/(v00);
     186                 :            : #define m00_atan2(v00,x,y)      v00 = atan2(x,y);
     187                 :            : // TODO atan2 derivatives ?
     188                 :            : #define m00_acosh(v00,x)        v00 = acosh(x);
     189                 :            : #define m10_acosh(v10,v00,x)    v10 = (1.0/(sqrt(x-1)*sqrt(x+1)));
     190                 :            : #define m00_asinh(v00,x)        v00 = asinh(x);
     191                 :            : #define m10_asinh(v10,v00,x)    v10 = (1.0/(sqrt(x*x+1)));
     192                 :            : #define m00_atanh(v00,x)        v00 = atanh(x);
     193                 :            : #define m10_atanh(v10,v00,x)    v10 = (1.0/(1-x*x));
     194                 :            : 
     195                 :            : 
     196                 :            : // standard functions LRM p.58
     197                 :            : #define m00_logE(v00,x)         v00 = log(x);
     198                 :            : #define m10_logE(v10,v00,x)     v10 = (1.0/x);
     199                 :            : #define m00_log10(v00,x)        v00 = log10(x);
     200                 :            : #define m10_log10(v10,v00,x)    v10 = (1.0/x/M_LN10);
     201                 :            : #define m00_exp(v00,x)          v00 = exp(x);
     202                 :            : #define m10_exp(v10,v00,x)      v10 = v00;
     203                 :            : #define m00_sqrt(v00,x)         v00 = sqrt(x);
     204                 :            : #define m10_sqrt(v10,v00,x)     v10 = (0.5/v00);
     205                 :            : #define m00_min(v00,x,y)        v00 = ((x)<(y))?(x):(y);
     206                 :            : #define m10_min(v10,v00,x,y)    v10 = ((x)<(y))?1.0:0.0;
     207                 :            : #define m11_min(v11,v00,x,y)    v11 = ((x)<(y))?0.0:1.0;
     208                 :            : #define m00_max(v00,x,y)        v00 = ((x)>(y))?(x):(y);
     209                 :            : #define m10_max(v10,v00,x,y)    v10 = ((x)>(y))?1.0:0.0;
     210                 :            : #define m11_max(v11,v00,x,y)    v11 = ((x)>(y))?0.0:1.0;
     211                 :            : #define m00_pow(v00,x,y)        v00 = pow(x,y);
     212                 :            : #define m10_pow(v10,v00,x,y)    v10 = (x==0.0)?0.0:(v00)*(y)/(x);
     213                 :            : #define m11_pow(v11,v00,x,y)    v11 = (x==0.0)?0.0:(log(x)*(v00));
     214                 :            : #define m00_abs(v00,x)          v00 = ((x)<(0)?(-(x)):(x));
     215                 :            : #define m10_abs(v10,v00,x)      v10 = (((x)>=0)?(+1.0):(-1.0));
     216                 :            : #define m00_floor(v00,x)        v00 = floor(x);
     217                 :            : #define m10_floor(v10,v00,x)    v10 = 1.0;
     218                 :            : 
     219                 :            : #define m00_ceil(v00,x)         v00 = ceil(x);
     220                 :            : // TODO ceil derivative, needed?
     221                 :            : 
     222                 :            : // analog operator, LRM p.61
     223                 :            : #define m00_limexp(v00,x)       v00 = ((x)<80.0?exp(x):exp(80.0)*(x-79.0));
     224                 :            : #define m10_limexp(v10,v00,x)   v10 = ((x)<80.0?(v00):exp(80.0));
     225                 :            : 
     226                 :            : // analog kernel parameter system functions, LRM p.215
     227                 :            : #define m00_vt(x)               (kBoverQ*(x))
     228                 :            : #define m10_vt(x)               (kBoverQ)
     229                 :            : 
     230                 :            : // extra functions (?)
     231                 :            : #define m00_div(v00,v10,x,y)    double v10=1/(y); double v00=(x)*v10;
     232                 :            : #define m10_div(v10,v00,vv,x,y)
     233                 :            : #define m11_div(v11,v00,vv,x,y) double v11 = -v00*vv;
     234                 :            : #define m00_mult(v00,v10,v11,x,y) double v10=(x); double v11=(y); double v00=v10*v11;
     235                 :            : #define m00_add(v00,x,y)        double v00=(x)+(y);
     236                 :            : 
     237                 :            : // second derivatives
     238                 :            : #define m20_logE(v00)           (-1.0/v00/v00)
     239                 :            : #define m20_exp(v00)            exp(v00)
     240                 :            : #define m20_limexp(v00)         ((v00)<80.0?exp(v00):0.0)
     241                 :            : #define m20_sqrt(v00)           (-0.25/(v00)/sqrt(v00))
     242                 :            : #define m20_abs(v00)           0.0
     243                 :            : #define m20_pow(x,y)            ((y)*((y)-1.0)*pow(x,y)/(x)/(x))
     244                 :            : 
     245                 :            : 
     246                 :            : // simulator specific definitions
     247                 :            : #define _modelname              "DLS_nto1"
     248                 :            : #define _instancename           getName()
     249                 :            : #define _circuit_temp           (getPropertyDouble("Temp")+273.15)
     250                 :            : #define _param_given(p)         (isPropertyGiven(p)?1:0)
     251                 :            : 
     252                 :            : 
     253                 :            : // $vt and $vt() functions
     254                 :            : #define _vt_nom                 (kBoverQ*_circuit_temp)
     255                 :            : 
     256                 :            : using namespace qucs::device;
     257                 :            : using qucs::matrix;
     258                 :            : 
     259                 :            : /* Device constructor. */
     260                 :          0 : DLS_nto1::DLS_nto1() : circuit (4)
     261                 :            : {
     262                 :          0 :   type = CIR_DLS_nto1;
     263                 :          0 : }
     264                 :            : 
     265                 :            : /* Initialization of model. */
     266                 :          0 : void DLS_nto1::initModel (void)
     267                 :            : {
     268                 :            :   // create internal nodes
     269                 :          0 :   setInternalNode (n1, "n1");
     270                 :          0 :   setInternalNode (n2, "n2");
     271                 :            : 
     272                 :            :   // get device model parameters
     273                 :          0 :   loadVariables ();
     274                 :            :   // evaluate global model equations
     275                 :          0 :   initializeModel ();
     276                 :            :   // evaluate initial step equations
     277                 :          0 :   initialStep ();
     278                 :            :   // evaluate global instance equations
     279                 :          0 :   initializeInstance ();
     280                 :          0 : }
     281                 :            : 
     282                 :            : /* Initialization of DC analysis. */
     283                 :          0 : void DLS_nto1::initDC (void)
     284                 :            : {
     285                 :          0 :   allocMatrixMNA ();
     286                 :          0 :   initModel ();
     287                 :          0 :   pol = 1;
     288                 :          0 :   restartDC ();
     289                 :          0 :   doAC = 1;
     290                 :          0 :   doTR = 0;
     291                 :          0 :   doHB = 0;
     292                 :          0 : }
     293                 :            : 
     294                 :            : /* Run when DC is restarted (fallback algorithms). */
     295                 :          0 : void DLS_nto1::restartDC (void)
     296                 :            : {
     297                 :          0 : }
     298                 :            : 
     299                 :            : /* Initialize Verilog-AMS code. */
     300                 :          0 : void DLS_nto1::initVerilog (void)
     301                 :            : {
     302                 :            :   // initialization of noise variables
     303                 :            : 
     304                 :            :   int i1, i2, i3, i4;
     305                 :            : 
     306                 :            :   // zero charges
     307         [ #  # ]:          0 :   for (i1 = 0; i1 < 4; i1++) {
     308         [ #  # ]:          0 :   for (i2 = 0; i2 < 4; i2++) {
     309                 :          0 :     _charges[i1][i2] = 0.0;
     310                 :            :   } }
     311                 :            : 
     312                 :            :   // zero capacitances
     313         [ #  # ]:          0 :   for (i1 = 0; i1 < 4; i1++) {
     314         [ #  # ]:          0 :   for (i2 = 0; i2 < 4; i2++) {
     315         [ #  # ]:          0 :   for (i3 = 0; i3 < 4; i3++) {
     316         [ #  # ]:          0 :   for (i4 = 0; i4 < 4; i4++) {
     317                 :          0 :     _caps[i1][i2][i3][i4] = 0.0;
     318                 :            :   } } } }
     319                 :            : 
     320                 :            :   // zero right hand side, static and dynamic jacobian
     321         [ #  # ]:          0 :   for (i1 = 0; i1 < 4; i1++) {
     322                 :          0 :     _rhs[i1] = 0.0;
     323                 :          0 :     _qhs[i1] = 0.0;
     324                 :          0 :     _chs[i1] = 0.0;
     325                 :          0 :     _ghs[i1] = 0.0;
     326         [ #  # ]:          0 :     for (i2 = 0; i2 < 4; i2++) {
     327                 :          0 :       _jstat[i1][i2] = 0.0;
     328                 :          0 :       _jdyna[i1][i2] = 0.0;
     329                 :            :     }
     330                 :            :   }
     331                 :          0 : }
     332                 :            : 
     333                 :            : /* Load device model input parameters. */
     334                 :          0 : void DLS_nto1::loadVariables (void)
     335                 :            : {
     336                 :          0 :   LEVEL = getPropertyDouble ("LEVEL");
     337                 :          0 :   Delay = getPropertyDouble ("Delay");
     338                 :          0 : }
     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                 :          0 : void DLS_nto1::initializeModel (void)
     350                 :            : {
     351                 :            : #if defined(_DYNAMIC)
     352                 :            : #endif
     353                 :            : {
     354                 :          0 : Rd=1e3;
     355                 :            : #if defined(_DYNAMIC)
     356                 :          0 : Cd=((Delay*1.43)/Rd);
     357                 :            : #endif
     358                 :            : }
     359                 :          0 : }
     360                 :            : 
     361                 :            : /* Evaluate Verilog-AMS equations in instance initialization. */
     362                 :          0 : void DLS_nto1::initializeInstance (void)
     363                 :            : {
     364                 :          0 : }
     365                 :            : 
     366                 :            : /* Evaluate Verilog-AMS equations in initial step. */
     367                 :          0 : void DLS_nto1::initialStep (void)
     368                 :            : {
     369                 :          0 : }
     370                 :            : 
     371                 :            : /* Evaluate Verilog-AMS equations in final step. */
     372                 :          0 : void DLS_nto1::finalStep (void)
     373                 :            : {
     374                 :          0 : }
     375                 :            : 
     376                 :            : /* Evaluate Verilog-AMS equations in analog block. */
     377                 :          0 : void DLS_nto1::calcVerilog (void)
     378                 :            : {
     379                 :            : 
     380                 :            : /* ----------------- evaluate verilog analog equations -------------------- */
     381         [ #  # ]:          0 : _load_static_residual1(n1,((NP(Lin)>=(LEVEL/2))?(-1):0));
     382                 :            : #if defined(_DERIVATE)
     383 [ #  # ][ #  # ]:          0 : _load_static_jacobian1(n1,Lin,((NP(Lin)>=(LEVEL/2))?0.0:0.0));
                 [ #  # ]
     384                 :            : #endif
     385                 :          0 : _load_static_residual1(n1,NP(n1));
     386                 :            : #if defined(_DERIVATE)
     387         [ #  # ]:          0 : _load_static_jacobian1(n1,n1,1.0);
     388                 :            : #endif
     389 [ #  # ][ #  # ]:          0 : _load_static_residual2(n1,n2,(BP(n1,n2)/Rd));
     390                 :            : #if defined(_DERIVATE)
     391 [ #  # ][ #  # ]:          0 : _load_static_jacobian4(n1,n2,n1,n2,(1/Rd));
         [ #  # ][ #  # ]
                 [ #  # ]
     392                 :            : #endif
     393                 :            : #if defined(_DYNAMIC)
     394 [ #  # ][ #  # ]:          0 : _load_dynamic_residual1(n2,_DDT((Cd*NP(n2))));
     395                 :            : #if defined(_DERIVATE)
     396 [ #  # ][ #  # ]:          0 : _load_dynamic_jacobian1(n2,n2,(Cd));
                 [ #  # ]
     397                 :            : #endif
     398                 :            : #endif
     399                 :          0 : _load_static_residual1(Lout,(-NP(n2)));
     400                 :            : #if defined(_DERIVATE)
     401         [ #  # ]:          0 : _load_static_jacobian1(Lout,n2,(-1.0));
     402                 :            : #endif
     403                 :          0 : _load_static_residual1(Lout,NP(Lout));
     404                 :            : #if defined(_DERIVATE)
     405         [ #  # ]:          0 : _load_static_jacobian1(Lout,Lout,1.0);
     406                 :            : #endif
     407                 :            : 
     408                 :            : /* ------------------ end of verilog analog equations --------------------- */
     409                 :            : 
     410                 :            : /* ------------------ evaluate verilog noise equations -------------------- */
     411                 :            : 
     412                 :            : /* ------------------- end of verilog noise equations --------------------- */
     413                 :          0 : }
     414                 :            : 
     415                 :            : /* Perform DC iteration. */
     416                 :          0 : void DLS_nto1::calcDC (void)
     417                 :            : {
     418                 :            :   // evaluate Verilog code
     419                 :          0 :   initVerilog ();
     420                 :          0 :   calcVerilog ();
     421                 :            : 
     422                 :            :   // fill right hand side and static jacobian
     423         [ #  # ]:          0 :   for (int i1 = 0; i1 < 4; i1++) {
     424         [ #  # ]:          0 :     setI (i1, _rhs[i1]);
     425         [ #  # ]:          0 :     for (int i2 = 0; i2 < 4; i2++) {
     426         [ #  # ]:          0 :       setY (i1, i2, _jstat[i1][i2]);
     427                 :            :     }
     428                 :            :   }
     429                 :          0 : }
     430                 :            : 
     431                 :            : /* Save operating points. */
     432                 :          0 : void DLS_nto1::saveOperatingPoints (void)
     433                 :            : {
     434                 :            :   // save global instance operating points
     435                 :          0 : }
     436                 :            : 
     437                 :            : /* Load operating points. */
     438                 :          0 : void DLS_nto1::loadOperatingPoints (void)
     439                 :            : {
     440                 :          0 : }
     441                 :            : 
     442                 :            : /* Calculate operating points. */
     443                 :          0 : void DLS_nto1::calcOperatingPoints (void)
     444                 :            : {
     445                 :          0 : }
     446                 :            : 
     447                 :            : /* Initialization of AC analysis. */
     448                 :          0 : void DLS_nto1::initAC (void)
     449                 :            : {
     450                 :          0 :   allocMatrixMNA ();
     451                 :          0 : }
     452                 :            : 
     453                 :            : /* Perform AC calculations. */
     454                 :          0 : void DLS_nto1::calcAC (nr_double_t frequency)
     455                 :            : {
     456         [ #  # ]:          0 :   setMatrixY (calcMatrixY (frequency));
     457                 :          0 : }
     458                 :            : 
     459                 :            : /* Compute Y-matrix for AC analysis. */
     460                 :          0 : matrix DLS_nto1::calcMatrixY (nr_double_t frequency)
     461                 :            : {
     462                 :          0 :   _freq = frequency;
     463                 :          0 :   saveOperatingPoints ();
     464                 :          0 :   matrix y (4);
     465                 :            : 
     466         [ #  # ]:          0 :   for (int i1 = 0; i1 < 4; i1++) {
     467         [ #  # ]:          0 :     for (int i2 = 0; i2 < 4; i2++) {
     468                 :          0 :       y (i1,i2) = nr_complex_t (_jstat[i1][i2], _jdyna[i1][i2] * 2 * M_PI * _freq);
     469                 :            :     }
     470                 :            :   }
     471                 :            : 
     472                 :          0 :   return y;
     473                 :            : }
     474                 :            : 
     475                 :            : /* Initialization of S-parameter analysis. */
     476                 :          0 : void DLS_nto1::initSP (void)
     477                 :            : {
     478                 :          0 :   allocMatrixS ();
     479                 :          0 : }
     480                 :            : 
     481                 :            : /* Perform S-parameter calculations. */
     482                 :          0 : void DLS_nto1::calcSP (nr_double_t frequency)
     483                 :            : {
     484 [ #  # ][ #  # ]:          0 :   setMatrixS (ytos (calcMatrixY (frequency)));
         [ #  # ][ #  # ]
                 [ #  # ]
     485                 :          0 : }
     486                 :            : 
     487                 :            : /* Initialization of transient analysis. */
     488                 :          0 : void DLS_nto1::initTR (void)
     489                 :            : {
     490                 :          0 :   setStates (2 * 4 * 4);
     491                 :          0 :   initDC ();
     492                 :          0 : }
     493                 :            : 
     494                 :            : /* Perform transient analysis iteration step. */
     495                 :          0 : void DLS_nto1::calcTR (nr_double_t)
     496                 :            : {
     497                 :          0 :   doHB = 0;
     498                 :          0 :   doAC = 1;
     499                 :          0 :   doTR = 1;
     500                 :          0 :   calcDC ();
     501                 :            : 
     502                 :            :   int i1, i2, i3, i4, state;
     503                 :            : 
     504                 :            :   // 2-node charge integrations
     505         [ #  # ]:          0 :   for (i1 = 0; i1 < 4; i1++) {
     506         [ #  # ]:          0 :   for (i2 = 0; i2 < 4; i2++) {
     507                 :          0 :     state = 2 * (i2 + 4 * i1);
     508         [ #  # ]:          0 :     if (i1 != i2)
     509         [ #  # ]:          0 :     if (_charges[i1][i2] != 0.0)
     510                 :          0 :       transientCapacitanceQ (state, i1, i2, _charges[i1][i2]);
     511                 :            :   } }
     512                 :            : 
     513                 :            :   // 1-node charge integrations
     514         [ #  # ]:          0 :   for (i1 = 0; i1 < 4; i1++) {
     515                 :          0 :     state = 2 * (i1 + 4 * i1);
     516         [ #  # ]:          0 :     if (_charges[i1][i1] != 0.0)
     517                 :          0 :       transientCapacitanceQ (state, i1, _charges[i1][i1]);
     518                 :            :   }
     519                 :            : 
     520                 :            :   // charge: 2-node, voltage: 2-node
     521         [ #  # ]:          0 :   for (i1 = 0; i1 < 4; i1++) {
     522         [ #  # ]:          0 :   for (i2 = 0; i2 < 4; i2++) {
     523         [ #  # ]:          0 :   if (i1 != i2)
     524         [ #  # ]:          0 :   for (i3 = 0; i3 < 4; i3++) {
     525         [ #  # ]:          0 :   for (i4 = 0; i4 < 4; i4++) {
     526         [ #  # ]:          0 :     if (i3 != i4)
     527         [ #  # ]:          0 :     if (_caps[i1][i2][i3][i4] != 0.0)
     528 [ #  # ][ #  # ]:          0 :       transientCapacitanceC (i1, i2, i3, i4, _caps[i1][i2][i3][i4], BP(i3,i4));
     529                 :            :   } } } }
     530                 :            : 
     531                 :            :   // charge: 2-node, voltage: 1-node
     532         [ #  # ]:          0 :   for (i1 = 0; i1 < 4; i1++) {
     533         [ #  # ]:          0 :   for (i2 = 0; i2 < 4; i2++) {
     534         [ #  # ]:          0 :   if (i1 != i2)
     535         [ #  # ]:          0 :   for (i3 = 0; i3 < 4; i3++) {
     536         [ #  # ]:          0 :     if (_caps[i1][i2][i3][i3] != 0.0)
     537         [ #  # ]:          0 :       transientCapacitanceC2Q (i1, i2, i3, _caps[i1][i2][i3][i3], NP(i3));
     538                 :            :   } } }
     539                 :            : 
     540                 :            :   // charge: 1-node, voltage: 2-node
     541         [ #  # ]:          0 :   for (i1 = 0; i1 < 4; i1++) {
     542         [ #  # ]:          0 :   for (i3 = 0; i3 < 4; i3++) {
     543         [ #  # ]:          0 :   for (i4 = 0; i4 < 4; i4++) {
     544         [ #  # ]:          0 :     if (i3 != i4)
     545         [ #  # ]:          0 :     if (_caps[i1][i1][i3][i4] != 0.0)
     546 [ #  # ][ #  # ]:          0 :       transientCapacitanceC2V (i1, i3, i4, _caps[i1][i1][i3][i4], BP(i3,i4));
     547                 :            :   } } }
     548                 :            : 
     549                 :            :   // charge: 1-node, voltage: 1-node
     550         [ #  # ]:          0 :   for (i1 = 0; i1 < 4; i1++) {
     551         [ #  # ]:          0 :   for (i3 = 0; i3 < 4; i3++) {
     552         [ #  # ]:          0 :     if (_caps[i1][i1][i3][i3] != 0.0)
     553         [ #  # ]:          0 :       transientCapacitanceC (i1, i3, _caps[i1][i1][i3][i3], NP(i3));
     554                 :            :   } }
     555                 :          0 : }
     556                 :            : 
     557                 :            : /* Compute Cy-matrix for AC noise analysis. */
     558                 :          0 : matrix DLS_nto1::calcMatrixCy (nr_double_t frequency) 
     559                 :            : {
     560                 :          0 :   _freq = frequency;
     561                 :          0 :   matrix cy (4);
     562                 :            : 
     563                 :            : 
     564                 :          0 :   return cy;
     565                 :            : }
     566                 :            : 
     567                 :            : /* Perform AC noise computations. */
     568                 :          0 : void DLS_nto1::calcNoiseAC (nr_double_t frequency) 
     569                 :            : {
     570         [ #  # ]:          0 :   setMatrixN (calcMatrixCy (frequency));
     571                 :          0 : }
     572                 :            : 
     573                 :            : /* Perform S-parameter noise computations. */
     574                 :          0 : void DLS_nto1::calcNoiseSP (nr_double_t frequency) 
     575                 :            : {
     576 [ #  # ][ #  # ]:          0 :   setMatrixN (cytocs (calcMatrixCy (frequency) * z0, getMatrixS ()));
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     577                 :          0 : }
     578                 :            : 
     579                 :            : /* Initialization of HB analysis. */
     580                 :          0 : void DLS_nto1::initHB (int)
     581                 :            : {
     582                 :          0 :   initDC ();
     583                 :          0 :   allocMatrixHB ();
     584                 :          0 : }
     585                 :            : 
     586                 :            : /* Perform HB analysis. */
     587                 :          0 : void DLS_nto1::calcHB (int)
     588                 :            : {
     589                 :          0 :   doHB = 1;
     590                 :          0 :   doAC = 1;
     591                 :          0 :   doTR = 0;
     592                 :            : 
     593                 :            :   // jacobian dI/dV and currents get filled
     594                 :          0 :   calcDC ();
     595                 :          0 :   saveOperatingPoints ();
     596                 :            : 
     597                 :            :   // fill in HB matrices
     598         [ #  # ]:          0 :   for (int i1 = 0; i1 < 4; i1++) {
     599         [ #  # ]:          0 :     setQ  (i1, _qhs[i1]); // charges
     600         [ #  # ]:          0 :     setCV (i1, _chs[i1]); // jacobian dQ/dV * V
     601         [ #  # ]:          0 :     setGV (i1, _ghs[i1]); // jacobian dI/dV * V
     602         [ #  # ]:          0 :     for (int i2 = 0; i2 < 4; i2++) {
     603         [ #  # ]:          0 :       setQV (i1, i2, _jdyna[i1][i2]); // jacobian dQ/dV
     604                 :            :     }
     605                 :            :   }
     606                 :          0 : }
     607                 :            : 
     608                 :            : #include "DLS_nto1.defs.h"
     609                 :            : 

Generated by: LCOV version 1.11