LCOV - code coverage report
Current view: top level - src/components/verilog - greytobinary4bit.core.cpp (source / functions) Hit Total Coverage
Test: qucs-core-0.0.19 Code Coverage Lines: 0 237 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 296 0.0 %

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

Generated by: LCOV version 1.11