LCOV - code coverage report
Current view: top level - src/components - mutual.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 9 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 132 0.0 %

           Branch data     Line data    Source code
       1                 :            : /*
       2                 :            :  * mutual.cpp - two mutual inductors class implementation
       3                 :            :  *
       4                 :            :  * Copyright (C) 2005, 2006, 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 "mutual.h"
      31                 :            : 
      32                 :            : using namespace qucs;
      33                 :            : 
      34                 :          0 : mutual::mutual () : circuit (4) {
      35                 :          0 :   type = CIR_MUTUAL;
      36                 :          0 : }
      37                 :            : 
      38                 :          0 : void mutual::calcSP (nr_double_t frequency) {
      39                 :            : #if 0
      40                 :            :   setMatrixS (ytos (calcMatrixY (frequency)));
      41                 :            : #else
      42         [ #  # ]:          0 :   nr_double_t l1 = getPropertyDouble ("L1");
      43         [ #  # ]:          0 :   nr_double_t l2 = getPropertyDouble ("L2");
      44         [ #  # ]:          0 :   nr_double_t k = getPropertyDouble ("k");
      45                 :          0 :   nr_double_t o = 2 * M_PI * frequency;
      46                 :          0 :   nr_double_t a = k * k - 1;
      47                 :          0 :   nr_complex_t d = nr_complex_t (o * o * l1 * l2 * a / 2 / z0 + 2 * z0, o * (l1 + l2));
      48                 :          0 :   nr_complex_t r;
      49         [ #  # ]:          0 :   r = nr_complex_t (2 * z0, o * l2) / d;
      50 [ #  # ][ #  # ]:          0 :   setS (NODE_1, NODE_4, r); setS (NODE_4, NODE_1, r);
      51                 :          0 :   r = 1.0 - r;
      52 [ #  # ][ #  # ]:          0 :   setS (NODE_1, NODE_1, r); setS (NODE_4, NODE_4, r);
      53         [ #  # ]:          0 :   r = nr_complex_t (2 * z0, o * l1) / d;
      54 [ #  # ][ #  # ]:          0 :   setS (NODE_2, NODE_3, r); setS (NODE_3, NODE_2, r);
      55                 :          0 :   r = 1.0 - r;
      56 [ #  # ][ #  # ]:          0 :   setS (NODE_2, NODE_2, r); setS (NODE_3, NODE_3, r);
      57         [ #  # ]:          0 :   r = nr_complex_t (0, o * k * std::sqrt (l1 * l2)) / d;
      58 [ #  # ][ #  # ]:          0 :   setS (NODE_1, NODE_2, r); setS (NODE_2, NODE_1, r);
      59 [ #  # ][ #  # ]:          0 :   setS (NODE_3, NODE_4, r); setS (NODE_4, NODE_3, r);
      60                 :          0 :   r = -r;
      61 [ #  # ][ #  # ]:          0 :   setS (NODE_1, NODE_3, r); setS (NODE_3, NODE_1, r);
      62 [ #  # ][ #  # ]:          0 :   setS (NODE_2, NODE_4, r); setS (NODE_4, NODE_2, r);
      63                 :            : #endif
      64                 :          0 : }
      65                 :            : 
      66                 :          0 : matrix mutual::calcMatrixY (nr_double_t frequency) {
      67         [ #  # ]:          0 :   nr_double_t l1 = getPropertyDouble ("L1");
      68         [ #  # ]:          0 :   nr_double_t l2 = getPropertyDouble ("L2");
      69         [ #  # ]:          0 :   nr_double_t k = getPropertyDouble ("k");
      70                 :          0 :   nr_double_t o = 2 * M_PI * frequency;
      71                 :          0 :   nr_double_t a = 1 - k * k;
      72                 :          0 :   nr_complex_t z1 = nr_complex_t (0, o * l1 * a);
      73                 :          0 :   nr_complex_t z2 = nr_complex_t (0, o * l2 * a);
      74                 :          0 :   nr_complex_t y3 = nr_complex_t (0, k / (o * std::sqrt (l1 * l2) * a));
      75                 :            : 
      76         [ #  # ]:          0 :   matrix y = matrix (4);
      77 [ #  # ][ #  # ]:          0 :   y.set (NODE_1, NODE_1, +1.0 / z1); y.set (NODE_4, NODE_4, +1.0 / z1);
         [ #  # ][ #  # ]
      78 [ #  # ][ #  # ]:          0 :   y.set (NODE_1, NODE_4, -1.0 / z1); y.set (NODE_4, NODE_1, -1.0 / z1);
         [ #  # ][ #  # ]
      79 [ #  # ][ #  # ]:          0 :   y.set (NODE_2, NODE_2, +1.0 / z2); y.set (NODE_3, NODE_3, +1.0 / z2);
         [ #  # ][ #  # ]
      80 [ #  # ][ #  # ]:          0 :   y.set (NODE_2, NODE_3, -1.0 / z2); y.set (NODE_3, NODE_2, -1.0 / z2);
         [ #  # ][ #  # ]
      81 [ #  # ][ #  # ]:          0 :   y.set (NODE_1, NODE_3, -y3); y.set (NODE_3, NODE_1, -y3);
      82 [ #  # ][ #  # ]:          0 :   y.set (NODE_2, NODE_4, -y3); y.set (NODE_4, NODE_2, -y3);
      83 [ #  # ][ #  # ]:          0 :   y.set (NODE_1, NODE_2, +y3); y.set (NODE_2, NODE_1, +y3);
      84 [ #  # ][ #  # ]:          0 :   y.set (NODE_3, NODE_4, +y3); y.set (NODE_4, NODE_3, +y3);
      85                 :          0 :   return y;
      86                 :            : }
      87                 :            : 
      88                 :          0 : void mutual::initAC (void) {
      89                 :          0 :   setVoltageSources (0);
      90                 :          0 :   allocMatrixMNA ();
      91                 :          0 : }
      92                 :            : 
      93                 :          0 : void mutual::calcAC (nr_double_t frequency) {
      94         [ #  # ]:          0 :   setMatrixY (calcMatrixY (frequency));
      95                 :          0 : }
      96                 :            : 
      97                 :          0 : void mutual::initDC (void) {
      98                 :          0 :   setVoltageSources (2);
      99                 :          0 :   allocMatrixMNA ();
     100                 :          0 :   voltageSource (VSRC_1, NODE_1, NODE_4);
     101                 :          0 :   voltageSource (VSRC_2, NODE_2, NODE_3);
     102                 :          0 : }
     103                 :            : 
     104                 :          0 : void mutual::initTR (void) {
     105                 :          0 :   initDC ();
     106                 :          0 :   setStates (8);
     107                 :          0 : }
     108                 :            : 
     109                 :            : #define fState11 0 // flux state
     110                 :            : #define vState11 1 // voltage state
     111                 :            : #define fState22 2
     112                 :            : #define vState22 3
     113                 :            : #define fState12 4
     114                 :            : #define vState12 5
     115                 :            : #define fState21 6
     116                 :            : #define vState21 7
     117                 :            : 
     118                 :          0 : void mutual::calcTR (nr_double_t) {
     119         [ #  # ]:          0 :   nr_double_t k  = getPropertyDouble ("k");
     120         [ #  # ]:          0 :   nr_double_t l1 = getPropertyDouble ("L1");
     121         [ #  # ]:          0 :   nr_double_t l2 = getPropertyDouble ("L2");
     122         [ #  # ]:          0 :   nr_double_t i1 = real (getJ (VSRC_1));
     123         [ #  # ]:          0 :   nr_double_t i2 = real (getJ (VSRC_2));
     124                 :            :   nr_double_t r11, r12, r21, r22, v11, v22, v12, v21;
     125                 :          0 :   nr_double_t M12 = k * std::sqrt (l1 * l2);
     126                 :            : 
     127                 :            :   // self inductances
     128                 :          0 :   setState  (fState11, i1 * l1);
     129         [ #  # ]:          0 :   integrate (fState11, l1, r11, v11);
     130                 :          0 :   setState  (fState22, i2 * l2);
     131         [ #  # ]:          0 :   integrate (fState22, l2, r22, v22);
     132                 :            : 
     133                 :            :   // mutual inductances
     134                 :          0 :   setState  (fState12, i2 * M12);
     135         [ #  # ]:          0 :   integrate (fState12, M12, r12, v12);
     136                 :          0 :   setState  (fState21, i1 * M12);
     137         [ #  # ]:          0 :   integrate (fState21, M12, r21, v21);
     138                 :            : 
     139 [ #  # ][ #  # ]:          0 :   setD (VSRC_1, VSRC_1, -r11); setD (VSRC_1, VSRC_2, -r12);
     140 [ #  # ][ #  # ]:          0 :   setD (VSRC_2, VSRC_2, -r22); setD (VSRC_2, VSRC_1, -r21);
     141         [ #  # ]:          0 :   setE (VSRC_1, v11 + v12);
     142         [ #  # ]:          0 :   setE (VSRC_2, v22 + v21);
     143                 :          0 : }
     144                 :            : 
     145                 :            : // properties
     146                 :            : PROP_REQ [] = {
     147                 :            :   { "L1", PROP_REAL, { 1e-3, PROP_NO_STR }, PROP_POS_RANGEX },
     148                 :            :   { "L2", PROP_REAL, { 1e-3, PROP_NO_STR }, PROP_POS_RANGEX },
     149                 :            :   { "k", PROP_REAL, { 0.9, PROP_NO_STR }, PROP_RNGXX (-1, 1) },
     150                 :            :   PROP_NO_PROP };
     151                 :            : PROP_OPT [] = {
     152                 :            :   PROP_NO_PROP };
     153                 :            : struct define_t mutual::cirdef =
     154                 :            :   { "MUT", 4, PROP_COMPONENT, PROP_NO_SUBSTRATE, PROP_LINEAR, PROP_DEF };

Generated by: LCOV version 1.11