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

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

Generated by: LCOV version 1.11