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

           Branch data     Line data    Source code
       1                 :            : /*
       2                 :            :  * mutualx.cpp - multiple mutual inductors class implementation
       3                 :            :  *
       4                 :            :  * Copyright (C) 2007, 2008 Stefan Jahn <stefan@lkcc.org>
       5                 :            :  *
       6                 :            :  * This is free software; you can redistribute it and/or modify
       7                 :            :  * it under the terms of the GNU General Public License as published by
       8                 :            :  * the Free Software Foundation; either version 2, or (at your option)
       9                 :            :  * any later version.
      10                 :            :  *
      11                 :            :  * This software is distributed in the hope that it will be useful,
      12                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      13                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      14                 :            :  * GNU General Public License for more details.
      15                 :            :  *
      16                 :            :  * You should have received a copy of the GNU General Public License
      17                 :            :  * along with this package; see the file COPYING.  If not, write to
      18                 :            :  * the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
      19                 :            :  * Boston, MA 02110-1301, USA.
      20                 :            :  *
      21                 :            :  * $Id$
      22                 :            :  *
      23                 :            :  */
      24                 :            : 
      25                 :            : #if HAVE_CONFIG_H
      26                 :            : # include <config.h>
      27                 :            : #endif
      28                 :            : 
      29                 :            : #include "component.h"
      30                 :            : #include "mutualx.h"
      31                 :            : 
      32                 :            : using namespace qucs;
      33                 :            : 
      34                 :          0 : mutualx::mutualx () : circuit () {
      35                 :          0 :   type = CIR_MUTUALX;
      36                 :          0 :   setVariableSized (true);
      37                 :          0 : }
      38                 :            : 
      39                 :          0 : void mutualx::calcSP (nr_double_t frequency) {
      40 [ #  # ][ #  # ]:          0 :   setMatrixS (ytos (calcMatrixY (frequency)));
         [ #  # ][ #  # ]
                 [ #  # ]
      41                 :          0 : }
      42                 :            : 
      43                 :          0 : matrix mutualx::calcMatrixY (nr_double_t frequency) {
      44                 :            : #if 1
      45 [ #  # ][ #  # ]:          0 :   matrix ts = ztos (calcMatrixZ (frequency));
                 [ #  # ]
      46 [ #  # ][ #  # ]:          0 :   matrix ty = stoy (ts);
                 [ #  # ]
      47                 :            : #else
      48                 :            :   matrix ty = ztoy (calcMatrixZ (frequency));
      49                 :            : #endif
      50                 :            :   int r, c;
      51                 :          0 :   int inductors = getSize () / 2;
      52         [ #  # ]:          0 :   matrix y = matrix (inductors * 2);
      53                 :            : 
      54         [ #  # ]:          0 :   for (r = 0; r < inductors; r++) {
      55         [ #  # ]:          0 :     for (c = 0; c < inductors; c++) {
      56         [ #  # ]:          0 :       y.set (2 * r + 0, 2 * c + 0, +ty (r, c));
      57         [ #  # ]:          0 :       y.set (2 * r + 1, 2 * c + 1, +ty (r, c));
      58         [ #  # ]:          0 :       y.set (2 * r + 0, 2 * c + 1, -ty (r, c));
      59         [ #  # ]:          0 :       y.set (2 * r + 1, 2 * c + 0, -ty (r, c));
      60                 :            :     }
      61                 :            :   }
      62 [ #  # ][ #  # ]:          0 :   return y;
      63                 :            : }
      64                 :            : 
      65                 :          0 : matrix mutualx::calcMatrixZ (nr_double_t frequency) {
      66                 :          0 :   int inductors = getSize () / 2;
      67                 :            :   int r, c, state;
      68                 :          0 :   qucs::vector * L = getPropertyVector ("L");
      69                 :          0 :   qucs::vector * C = getPropertyVector ("k");
      70                 :          0 :   nr_double_t o = 2 * M_PI * frequency;
      71                 :          0 :   matrix z = matrix (inductors);
      72                 :            : 
      73                 :            :   // fill Z-Matrix entries
      74         [ #  # ]:          0 :   for (state = 0, r = 0; r < inductors; r++) {
      75         [ #  # ]:          0 :     for (c = 0; c < inductors; c++, state++) {
      76         [ #  # ]:          0 :       nr_double_t l1 = real (L->get (r));
      77         [ #  # ]:          0 :       nr_double_t l2 = real (L->get (c));
      78         [ #  # ]:          0 :       nr_double_t k = real (C->get (state)) * std::sqrt (l1 * l2);
      79         [ #  # ]:          0 :       z.set (r, c, nr_complex_t (0.0, k * o));
      80                 :            :     }
      81                 :            :   }
      82                 :          0 :   return z;
      83                 :            : }
      84                 :            : 
      85                 :          0 : void mutualx::initAC (void) {
      86                 :          0 :   initDC ();
      87                 :          0 : }
      88                 :            : 
      89                 :          0 : void mutualx::calcAC (nr_double_t frequency) {
      90                 :          0 :   int inductors = getSize () / 2;
      91                 :            :   int r, c, state;
      92                 :          0 :   qucs::vector * L = getPropertyVector ("L");
      93                 :          0 :   qucs::vector * C = getPropertyVector ("k");
      94                 :          0 :   nr_double_t o = 2 * M_PI * frequency;
      95                 :            : 
      96                 :            :   // fill D-Matrix
      97         [ #  # ]:          0 :   for (state = 0, r = 0; r < inductors; r++) {
      98         [ #  # ]:          0 :     for (c = 0; c < inductors; c++, state++) {
      99                 :          0 :       nr_double_t l1 = real (L->get (r));
     100                 :          0 :       nr_double_t l2 = real (L->get (c));
     101                 :          0 :       nr_double_t k = real (C->get (state)) * std::sqrt (l1 * l2);
     102         [ #  # ]:          0 :       setD (VSRC_1 + r, VSRC_1 + c, nr_complex_t (0.0, k * o));
     103                 :            :     }
     104                 :            :   }
     105                 :          0 : }
     106                 :            : 
     107                 :          0 : void mutualx::initDC (void) {
     108                 :          0 :   int inductors = getSize () / 2;
     109                 :          0 :   setVoltageSources (inductors);
     110                 :          0 :   allocMatrixMNA ();
     111                 :            :   // fill C and B-Matrix entries
     112         [ #  # ]:          0 :   for (int i = 0; i < inductors; i++)
     113                 :          0 :     voltageSource (VSRC_1 + i, NODE_1 + i * 2, NODE_2 + i * 2);
     114                 :          0 : }
     115                 :            : 
     116                 :          0 : void mutualx::initTR (void) {
     117                 :          0 :   int inductors = getSize () / 2;
     118                 :          0 :   initDC ();
     119                 :          0 :   setStates (inductors * inductors * 2);
     120                 :          0 : }
     121                 :            : 
     122                 :          0 : void mutualx::calcTR (nr_double_t) {
     123                 :          0 :   int inductors = getSize () / 2;
     124                 :            :   int r, c, state;
     125                 :          0 :   qucs::vector * L = getPropertyVector ("L");
     126                 :          0 :   qucs::vector * C = getPropertyVector ("k");
     127                 :            : 
     128                 :          0 :   nr_double_t * veq = new nr_double_t[inductors * inductors];
     129                 :          0 :   nr_double_t * req = new nr_double_t[inductors * inductors];
     130                 :            : 
     131                 :            :   // integration for self and mutual inductances
     132         [ #  # ]:          0 :   for (state = 0, r = 0; r < inductors; r++) {
     133         [ #  # ]:          0 :     for (c = 0; c < inductors; c++, state++) {
     134                 :          0 :       nr_double_t l1 = real (L->get (r));
     135                 :          0 :       nr_double_t l2 = real (L->get (c));
     136                 :          0 :       nr_double_t i = real (getJ (VSRC_1 + c));
     137                 :          0 :       nr_double_t k = real (C->get (state)) * std::sqrt (l1 * l2);
     138                 :          0 :       setState  (2 * state, i * k);
     139                 :          0 :       integrate (2 * state, k, req[state], veq[state]);
     140                 :            :     }
     141                 :            :   }
     142                 :            : 
     143                 :            :   // fill D-Matrix entries and extended RHS
     144         [ #  # ]:          0 :   for (state = 0, r = 0; r < inductors; r++) {
     145                 :          0 :     nr_double_t v = 0;
     146         [ #  # ]:          0 :     for (c = 0; c < inductors; c++, state++) {
     147         [ #  # ]:          0 :       setD (VSRC_1 + r, VSRC_1 + c, -req[state]);
     148                 :          0 :       v += veq[state];
     149                 :            :     }
     150         [ #  # ]:          0 :     setE (VSRC_1 + r, v);
     151                 :            :   }
     152                 :            : 
     153         [ #  # ]:          0 :   delete[] veq;
     154         [ #  # ]:          0 :   delete[] req;
     155                 :          0 : }
     156                 :            : 
     157                 :            : // properties
     158                 :            : PROP_REQ [] = {
     159                 :            :   { "L", PROP_LIST, { 1e-9, PROP_NO_STR }, PROP_POS_RANGE },
     160                 :            :   { "k", PROP_LIST, { 0.9, PROP_NO_STR }, PROP_RNGII (-1, +1) },
     161                 :            :   PROP_NO_PROP };
     162                 :            : PROP_OPT [] = {
     163                 :            :   PROP_NO_PROP };
     164                 :            : struct define_t mutualx::cirdef =
     165                 :            :   { "MUTX",
     166                 :            :     PROP_NODES, PROP_COMPONENT, PROP_NO_SUBSTRATE, PROP_LINEAR, PROP_DEF };

Generated by: LCOV version 1.11