Qucs-core  0.0.18
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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$
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 using namespace qucs;
33 
34 inductor::inductor () : circuit (2) {
35  type = CIR_INDUCTOR;
36  setISource (true);
37 }
38 
39 void inductor::calcSP (nr_double_t frequency) {
40  nr_double_t l = getPropertyDouble ("L") / z0;
41  nr_complex_t z = nr_complex_t (0, 2.0 * M_PI * frequency * l);
42  setS (NODE_1, NODE_1, z / (z + 2.0));
43  setS (NODE_2, NODE_2, z / (z + 2.0));
44  setS (NODE_1, NODE_2, 2.0 / (z + 2.0));
45  setS (NODE_2, NODE_1, 2.0 / (z + 2.0));
46 }
47 
48 void inductor::initDC (void) {
50  allocMatrixMNA ();
52 }
53 
54 void inductor::calcDC (void) {
55  clearY ();
56 }
57 
58 void inductor::initAC (void) {
59  nr_double_t l = getPropertyDouble ("L");
60 
61  // for non-zero inductance usual MNA entries
62  if (l != 0.0) {
64  allocMatrixMNA ();
65  }
66  // for zero inductance create a zero voltage source
67  else {
68  initDC ();
69  calcDC ();
70  }
71 }
72 
73 void inductor::calcAC (nr_double_t frequency) {
74  nr_double_t l = getPropertyDouble ("L");
75 
76  // for non-zero inductance usual MNA entries
77  if (l != 0.0) {
78  nr_complex_t y = nr_complex_t (0, -1 / (2.0 * M_PI * frequency * l));
79  setY (NODE_1, NODE_1, +y); setY (NODE_2, NODE_2, +y);
80  setY (NODE_1, NODE_2, -y); setY (NODE_2, NODE_1, -y);
81  }
82 }
83 
84 void inductor::initTR (void) {
85  initDC ();
86  clearY ();
87  setStates (2);
88 }
89 
90 #define fState 0 // flux state
91 #define vState 1 // voltage state
92 
93 void inductor::calcTR (nr_double_t) {
94  nr_double_t l = getPropertyDouble ("L");
95  nr_double_t r, v;
96  nr_double_t i = real (getJ (VSRC_1));
97 
98  /* apply initial condition if requested */
99  if (getMode () == MODE_INIT && isPropertyGiven ("I")) {
100  i = getPropertyDouble ("I");
101  }
102 
103  setState (fState, i * l);
104  integrate (fState, l, r, v);
105  setD (VSRC_1, VSRC_1, -r);
106  setE (VSRC_1, v);
107 }
108 
109 void inductor::initHB (void) {
110  setVoltageSources (1);
112  allocMatrixMNA ();
114 }
115 
116 void inductor::calcHB (nr_double_t frequency) {
117  nr_double_t l = getPropertyDouble ("L");
118  setD (VSRC_1, VSRC_1, -l * 2 * M_PI * frequency);
119 }
120 
121 // properties
122 PROP_REQ [] = {
123  { "L", PROP_REAL, { 1e-9, PROP_NO_STR }, PROP_NO_RANGE }, PROP_NO_PROP };
124 PROP_OPT [] = {
125  { "I", PROP_REAL, { 0, PROP_NO_STR }, PROP_NO_RANGE }, PROP_NO_PROP };
126 struct define_t inductor::cirdef =
std::complex< nr_double_t > nr_complex_t
Definition: complex.h:31
l
Definition: parse_vcd.y:213
void clearY(void)
Definition: circuit.cpp:740
#define NODE_2
Definition: circuit.h:35
matrix real(matrix a)
Real part matrix.
Definition: matrix.cpp:568
PROP_OPT[]
Definition: inductor.cpp:124
void setISource(bool i)
Definition: circuit.h:194
#define PROP_DEF
Definition: netdefs.h:189
void integrate(int, nr_double_t, nr_double_t &, nr_double_t &)
Definition: integrator.cpp:67
nr_double_t getPropertyDouble(const char *)
Definition: object.cpp:176
void setD(int, int, nr_complex_t)
Definition: circuit.cpp:373
void calcTR(nr_double_t)
Definition: inductor.cpp:93
#define PROP_REAL
Definition: netdefs.h:174
void setStates(int n)
Definition: states.h:52
#define fState
Definition: inductor.cpp:90
void setInternalVoltageSource(bool i)
Definition: circuit.h:184
int getMode(void)
Definition: integrator.h:55
#define PROP_NO_PROP
Definition: netdefs.h:122
void setVoltageSources(int)
Definition: circuit.cpp:607
#define PROP_NO_RANGE
Definition: netdefs.h:126
void calcHB(nr_double_t)
Definition: inductor.cpp:116
#define PROP_NO_STR
Definition: netdefs.h:125
#define PROP_LINEAR
Definition: netdefs.h:120
static const nr_double_t z0
Definition: circuit.h:320
r
Definition: parse_mdl.y:515
bool isPropertyGiven(const char *)
Definition: object.cpp:213
PROP_REQ[]
Definition: inductor.cpp:122
#define VSRC_1
Definition: circuit.h:40
i
Definition: parse_mdl.y:516
nr_double_t getJ(int, nr_double_t)
Definition: circuit.cpp:951
#define PROP_COMPONENT
Definition: netdefs.h:116
void setE(int, nr_complex_t)
Definition: circuit.cpp:385
#define M_PI
Archimedes' constant ( )
Definition: consts.h:47
void setY(int, int, nr_complex_t)
Definition: circuit.cpp:452
v
Definition: parse_zvr.y:141
void allocMatrixMNA(void)
Definition: circuit.cpp:267
void initDC(void)
Definition: inductor.cpp:48
void calcSP(nr_double_t)
Definition: inductor.cpp:39
y
Definition: parse_mdl.y:499
#define NODE_1
Definition: circuit.h:34
void voltageSource(int, int, int, nr_double_t value=0.0)
Definition: circuit.cpp:748
void calcAC(nr_double_t)
Definition: inductor.cpp:73
void setS(int, int, nr_complex_t)
Definition: circuit.cpp:587
void initAC(void)
Definition: inductor.cpp:58
void setState(int, state_type_t, int n=0)
Definition: states.cpp:109
PROP_NO_SUBSTRATE
Definition: inductor.cpp:127
void initHB(void)
Definition: inductor.cpp:109
#define MODE_INIT
Definition: integrator.h:31
void initTR(void)
Definition: inductor.cpp:84
void calcDC(void)
Definition: inductor.cpp:54