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

           Branch data     Line data    Source code
       1                 :            : /*
       2                 :            :  * circulator.cpp - circulator class implementation
       3                 :            :  *
       4                 :            :  * Copyright (C) 2003, 2004, 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 "circulator.h"
      31                 :            : 
      32                 :            : using namespace qucs;
      33                 :            : 
      34                 :          0 : circulator::circulator () : circuit (3) {
      35                 :          0 :   type = CIR_CIRCULATOR;
      36   [ #  #  #  # ]:          0 :   setVoltageSources (3);
      37                 :          0 : }
      38                 :            : 
      39                 :          0 : void circulator::calcSP (nr_double_t) {
      40                 :          0 :   nr_double_t z1 = getPropertyDouble ("Z1");
      41                 :          0 :   nr_double_t z2 = getPropertyDouble ("Z2");
      42                 :          0 :   nr_double_t z3 = getPropertyDouble ("Z3");
      43                 :          0 :   nr_double_t r1 = (z0 - z1) / (z0 + z1);
      44                 :          0 :   nr_double_t r2 = (z0 - z2) / (z0 + z2);
      45                 :          0 :   nr_double_t r3 = (z0 - z3) / (z0 + z3);
      46                 :          0 :   nr_double_t d  = 1 - r1 * r2 * r3;
      47         [ #  # ]:          0 :   setS (NODE_1, NODE_1, (r2 * r3 - r1) / d);
      48         [ #  # ]:          0 :   setS (NODE_2, NODE_2, (r1 * r3 - r2) / d);
      49         [ #  # ]:          0 :   setS (NODE_3, NODE_3, (r1 * r2 - r3) / d);
      50                 :          0 :   setS (NODE_1, NODE_2, std::sqrt (z2 / z1) * (z1 + z0) /
      51         [ #  # ]:          0 :         (z2 + z0) * r3 * (1 - r1 * r1) / d);
      52                 :          0 :   setS (NODE_2, NODE_3, std::sqrt (z3 / z2) * (z2 + z0) /
      53         [ #  # ]:          0 :         (z3 + z0) * r1 * (1 - r2 * r2) / d);
      54                 :          0 :   setS (NODE_3, NODE_1, std::sqrt (z1 / z3) * (z3 + z0) /
      55         [ #  # ]:          0 :         (z1 + z0) * r2 * (1 - r3 * r3) / d);
      56                 :          0 :   setS (NODE_2, NODE_1, std::sqrt (z1 / z2) * (z2 + z0) /
      57         [ #  # ]:          0 :         (z1 + z0) * (1 - r2 * r2) / d);
      58                 :          0 :   setS (NODE_1, NODE_3, std::sqrt (z3 / z1) * (z1 + z0) /
      59         [ #  # ]:          0 :         (z3 + z0) * (1 - r1 * r1) / d);
      60                 :          0 :   setS (NODE_3, NODE_2, std::sqrt (z2 / z3) * (z3 + z0) /
      61         [ #  # ]:          0 :         (z2 + z0) * (1 - r3 * r3) / d);
      62                 :          0 : }
      63                 :            : 
      64                 :          0 : void circulator::initDC (void) {
      65                 :          0 :   nr_double_t z1 = getPropertyDouble ("Z1");
      66                 :          0 :   nr_double_t z2 = getPropertyDouble ("Z2");
      67                 :          0 :   nr_double_t z3 = getPropertyDouble ("Z3");
      68                 :          0 :   nr_double_t r1 = (z0 - z1) / (z0 + z1);
      69                 :          0 :   nr_double_t r2 = (z0 - z2) / (z0 + z2);
      70                 :          0 :   nr_double_t r3 = (z0 - z3) / (z0 + z3);
      71                 :          0 :   nr_double_t d  = 1 - r1 * r2 * r3;
      72                 :            : 
      73                 :          0 :   nr_double_t s11 = (r2 * r3 - r1) / d;
      74                 :          0 :   nr_double_t s22 = (r1 * r3 - r2) / d;
      75                 :          0 :   nr_double_t s33 = (r1 * r2 - r3) / d;
      76                 :          0 :   nr_double_t s12 = std::sqrt (z2/z1) * (z1+z0) / (z2+z0) * r3 * (1-r1*r1) / d;
      77                 :          0 :   nr_double_t s23 = std::sqrt (z3/z2) * (z2+z0) / (z3+z0) * r1 * (1-r2*r2) / d;
      78                 :          0 :   nr_double_t s31 = std::sqrt (z1/z3) * (z3+z0) / (z1+z0) * r2 * (1-r3*r3) / d;
      79                 :          0 :   nr_double_t s21 = std::sqrt (z1/z2) * (z2+z0) / (z1+z0) * (1-r2*r2) / d;
      80                 :          0 :   nr_double_t s13 = std::sqrt (z3/z1) * (z1+z0) / (z3+z0) * (1-r1*r1) / d;
      81                 :          0 :   nr_double_t s32 = std::sqrt (z2/z3) * (z3+z0) / (z2+z0) * (1-r3*r3) / d;
      82                 :            : 
      83                 :          0 :   allocMatrixMNA ();
      84                 :            : 
      85 [ #  # ][ #  # ]:          0 :   setB (NODE_1, VSRC_1, +1.0); setB (NODE_1, VSRC_2, +0.0);
      86         [ #  # ]:          0 :   setB (NODE_1, VSRC_3, +0.0);
      87 [ #  # ][ #  # ]:          0 :   setB (NODE_2, VSRC_1, +0.0); setB (NODE_2, VSRC_2, +1.0);
      88         [ #  # ]:          0 :   setB (NODE_2, VSRC_3, +0.0);
      89 [ #  # ][ #  # ]:          0 :   setB (NODE_3, VSRC_1, +0.0); setB (NODE_3, VSRC_2, +0.0);
      90         [ #  # ]:          0 :   setB (NODE_3, VSRC_3, +1.0);
      91                 :            : 
      92 [ #  # ][ #  # ]:          0 :   setC (VSRC_1, NODE_1, s11 - 1.0); setC (VSRC_1, NODE_2, s12);
      93         [ #  # ]:          0 :   setC (VSRC_1, NODE_3, s13);
      94 [ #  # ][ #  # ]:          0 :   setC (VSRC_2, NODE_1, s21); setC (VSRC_2, NODE_2, s22 - 1.0);
      95         [ #  # ]:          0 :   setC (VSRC_2, NODE_3, s23);
      96 [ #  # ][ #  # ]:          0 :   setC (VSRC_3, NODE_1, s31); setC (VSRC_3, NODE_2, s32);
      97         [ #  # ]:          0 :   setC (VSRC_3, NODE_3, s33 - 1.0);
      98                 :            : 
      99 [ #  # ][ #  # ]:          0 :   setD (VSRC_1, VSRC_1, z0 * (s11 + 1.0)); setD (VSRC_1, VSRC_2, z0 * s12);
     100         [ #  # ]:          0 :   setD (VSRC_1, VSRC_3, z0 * s13);
     101 [ #  # ][ #  # ]:          0 :   setD (VSRC_2, VSRC_1, z0 * s21); setD (VSRC_2, VSRC_2, z0 * (s22 + 1.0));
     102         [ #  # ]:          0 :   setD (VSRC_2, VSRC_3, z0 * s23);
     103 [ #  # ][ #  # ]:          0 :   setD (VSRC_3, VSRC_1, z0 * s31); setD (VSRC_3, VSRC_2, z0 * s32);
     104         [ #  # ]:          0 :   setD (VSRC_3, VSRC_3, z0 * (s33 + 1.0));
     105                 :            : 
     106 [ #  # ][ #  # ]:          0 :   setE (VSRC_1, +0.0); setE (VSRC_2, +0.0); setE (VSRC_3, +0.0);
                 [ #  # ]
     107                 :          0 : }
     108                 :            : 
     109                 :          0 : void circulator::initAC (void) {
     110                 :          0 :   initDC ();
     111                 :          0 : }
     112                 :            : 
     113                 :          0 : void circulator::initTR (void) {
     114                 :          0 :   initDC ();
     115                 :          0 : }
     116                 :            : 
     117                 :            : // properties
     118                 :            : PROP_REQ [] = {
     119                 :            :   PROP_NO_PROP };
     120                 :            : PROP_OPT [] = {
     121                 :            :   { "Z1", PROP_REAL, { 50, PROP_NO_STR }, PROP_POS_RANGE },
     122                 :            :   { "Z2", PROP_REAL, { 50, PROP_NO_STR }, PROP_POS_RANGE },
     123                 :            :   { "Z3", PROP_REAL, { 50, PROP_NO_STR }, PROP_POS_RANGE },
     124                 :            :   PROP_NO_PROP };
     125                 :            : struct define_t circulator::cirdef =
     126                 :            :   { "Circulator",
     127                 :            :     3, PROP_COMPONENT, PROP_NO_SUBSTRATE, PROP_LINEAR, PROP_DEF };

Generated by: LCOV version 1.11