My Project  0.0.16
QUCS Mapping
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
inductor.cpp
Go to the documentation of this file.
1 /*
2  * inductor.cpp - inductor class implementation
3  *
4  * Copyright (C) 2003, 2004, 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: inductor.cpp 1825 2011-03-11 20:42:14Z ela $
22  *
23  */
24 
25 #if HAVE_CONFIG_H
26 # include <config.h>
27 #endif
28 
29 #include "component.h"
30 #include "inductor.h"
31 
32 inductor::inductor () : circuit (2) {
33  type = CIR_INDUCTOR;
34  setISource (true);
35 }
36 
37 void inductor::calcSP (nr_double_t frequency) {
38  nr_double_t l = getPropertyDouble ("L") / z0;
39  nr_complex_t z = rect (0, 2.0 * M_PI * frequency * l);
40  setS (NODE_1, NODE_1, z / (z + 2.0));
41  setS (NODE_2, NODE_2, z / (z + 2.0));
42  setS (NODE_1, NODE_2, 2.0 / (z + 2.0));
43  setS (NODE_2, NODE_1, 2.0 / (z + 2.0));
44 }
45 
46 void inductor::initDC (void) {
47  setVoltageSources (1);
48  allocMatrixMNA ();
50 }
51 
52 void inductor::calcDC (void) {
53  clearY ();
54 }
55 
56 void inductor::initAC (void) {
57  nr_double_t l = getPropertyDouble ("L");
58 
59  // for non-zero inductance usual MNA entries
60  if (l != 0.0) {
62  allocMatrixMNA ();
63  }
64  // for zero inductance create a zero voltage source
65  else {
66  initDC ();
67  calcDC ();
68  }
69 }
70 
71 void inductor::calcAC (nr_double_t frequency) {
72  nr_double_t l = getPropertyDouble ("L");
73 
74  // for non-zero inductance usual MNA entries
75  if (l != 0.0) {
76  nr_complex_t y = rect (0, -1 / (2.0 * M_PI * frequency * l));
77  setY (NODE_1, NODE_1, +y); setY (NODE_2, NODE_2, +y);
78  setY (NODE_1, NODE_2, -y); setY (NODE_2, NODE_1, -y);
79  }
80 }
81 
82 void inductor::initTR (void) {
83  initDC ();
84  clearY ();
85  setStates (2);
86 }
87 
88 #define fState 0 // flux state
89 #define vState 1 // voltage state
90 
91 void inductor::calcTR (nr_double_t) {
92  nr_double_t l = getPropertyDouble ("L");
93  nr_double_t r, v;
94  nr_double_t i = real (getJ (VSRC_1));
95 
96  /* apply initial condition if requested */
97  if (getMode () == MODE_INIT && isPropertyGiven ("I")) {
98  i = getPropertyDouble ("I");
99  }
100 
101  setState (fState, i * l);
102  integrate (fState, l, r, v);
103  setD (VSRC_1, VSRC_1, -r);
104  setE (VSRC_1, v);
105 }
106 
107 void inductor::initHB (void) {
108  setVoltageSources (1);
110  allocMatrixMNA ();
112 }
113 
114 void inductor::calcHB (nr_double_t frequency) {
115  nr_double_t l = getPropertyDouble ("L");
116  setD (VSRC_1, VSRC_1, -l * 2 * M_PI * frequency);
117 }
118 
119 // properties
120 PROP_REQ [] = {
121  { "L", PROP_REAL, { 1e-9, PROP_NO_STR }, PROP_NO_RANGE }, PROP_NO_PROP };
122 PROP_OPT [] = {
123  { "I", PROP_REAL, { 0, PROP_NO_STR }, PROP_NO_RANGE }, PROP_NO_PROP };
124 struct define_t inductor::cirdef =