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

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

Generated by: LCOV version 1.11