Qucs-core  0.0.19
inductor.cpp
Go to the documentation of this file.
00001 /*
00002  * inductor.cpp - inductor class implementation
00003  *
00004  * Copyright (C) 2003, 2004, 2005, 2006, 2008 Stefan Jahn <stefan@lkcc.org>
00005  *
00006  * This is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2, or (at your option)
00009  * any later version.
00010  *
00011  * This software is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this package; see the file COPYING.  If not, write to
00018  * the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
00019  * Boston, MA 02110-1301, USA.
00020  *
00021  * $Id$
00022  *
00023  */
00024 
00025 #if HAVE_CONFIG_H
00026 # include <config.h>
00027 #endif
00028 
00029 #include "component.h"
00030 #include "inductor.h"
00031 
00032 using namespace qucs;
00033 
00034 inductor::inductor () : circuit (2) {
00035   type = CIR_INDUCTOR;
00036   setISource (true);
00037 }
00038 
00039 void inductor::calcSP (nr_double_t frequency) {
00040   nr_double_t l = getPropertyDouble ("L") / z0;
00041   nr_complex_t z = nr_complex_t (0, 2.0 * pi * frequency * l);
00042   setS (NODE_1, NODE_1, z / (z + 2.0));
00043   setS (NODE_2, NODE_2, z / (z + 2.0));
00044   setS (NODE_1, NODE_2, 2.0 / (z + 2.0));
00045   setS (NODE_2, NODE_1, 2.0 / (z + 2.0));
00046 }
00047 
00048 void inductor::initDC (void) {
00049   setVoltageSources (1);
00050   allocMatrixMNA ();
00051   voltageSource (VSRC_1, NODE_1, NODE_2);
00052 }
00053 
00054 void inductor::calcDC (void) {
00055   clearY ();
00056 }
00057 
00058 void inductor::initAC (void) {
00059   nr_double_t l = getPropertyDouble ("L");
00060 
00061   // for non-zero inductance usual MNA entries
00062   if (l != 0.0) {
00063     setVoltageSources (0);
00064     allocMatrixMNA ();
00065   }
00066   // for zero inductance create a zero voltage source
00067   else {
00068     initDC ();
00069     calcDC ();
00070   }
00071 }
00072 
00073 void inductor::calcAC (nr_double_t frequency) {
00074   nr_double_t l = getPropertyDouble ("L");
00075 
00076   // for non-zero inductance usual MNA entries
00077   if (l != 0.0) {
00078     nr_complex_t y = nr_complex_t (0, -1 / (2.0 * pi * frequency * l));
00079     setY (NODE_1, NODE_1, +y); setY (NODE_2, NODE_2, +y);
00080     setY (NODE_1, NODE_2, -y); setY (NODE_2, NODE_1, -y);
00081   }
00082 }
00083 
00084 void inductor::initTR (void) {
00085   initDC ();
00086   clearY ();
00087   setStates (2);
00088 }
00089 
00090 #define fState 0 // flux state
00091 #define vState 1 // voltage state
00092 
00093 void inductor::calcTR (nr_double_t) {
00094   nr_double_t l = getPropertyDouble ("L");
00095   nr_double_t r, v;
00096   nr_double_t i = real (getJ (VSRC_1));
00097 
00098   /* apply initial condition if requested */
00099   if (getMode () == MODE_INIT && isPropertyGiven ("I")) {
00100     i = getPropertyDouble ("I");
00101   }
00102 
00103   setState (fState, i * l);
00104   integrate (fState, l, r, v);
00105   setD (VSRC_1, VSRC_1, -r);
00106   setE (VSRC_1, v);
00107 }
00108 
00109 void inductor::initHB (void) {
00110   setVoltageSources (1);
00111   setInternalVoltageSource (1);
00112   allocMatrixMNA ();
00113   voltageSource (VSRC_1, NODE_1, NODE_2);
00114 }
00115 
00116 void inductor::calcHB (nr_double_t frequency) {
00117   nr_double_t l = getPropertyDouble ("L");
00118   setD (VSRC_1, VSRC_1, -l * 2 * pi * frequency);
00119 }
00120 
00121 // properties
00122 PROP_REQ [] = {
00123   { "L", PROP_REAL, { 1e-9, PROP_NO_STR }, PROP_NO_RANGE }, PROP_NO_PROP };
00124 PROP_OPT [] = {
00125   { "I", PROP_REAL, { 0, PROP_NO_STR }, PROP_NO_RANGE }, PROP_NO_PROP };
00126 struct define_t inductor::cirdef =
00127   { "L", 2, PROP_COMPONENT, PROP_NO_SUBSTRATE, PROP_LINEAR, PROP_DEF };