Qucs-core  0.0.19
capacitor.cpp
Go to the documentation of this file.
00001 /*
00002  * capacitor.cpp - capacitor 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 
00032 #if HAVE_CONFIG_H
00033 # include <config.h>
00034 #endif
00035 
00036 #include "component.h"
00037 #include "capacitor.h"
00038 
00039 using namespace qucs;
00040 
00042 capacitor::capacitor () : circuit (2) {
00043   type = CIR_CAPACITOR;
00044   setISource (true);
00045 }
00046 
00060 void capacitor::calcSP (nr_double_t frequency) {
00061   nr_double_t c = getPropertyDouble ("C") * z0;
00062   nr_complex_t y = 2.0 * nr_complex_t (0, 2.0 * pi * frequency * c);
00063   setS (NODE_1, NODE_1, 1.0 / (1.0 + y));
00064   setS (NODE_2, NODE_2, 1.0 / (1.0 + y));
00065   setS (NODE_1, NODE_2, y / (1.0 + y));
00066   setS (NODE_2, NODE_1, y / (1.0 + y));
00067 }
00068 
00069 /*\brief Init DC simulation of capacitor */
00070 void capacitor::initDC (void) {
00071   allocMatrixMNA ();
00072 }
00073 
00087 void capacitor::calcAC (nr_double_t frequency) {
00088   nr_double_t c = getPropertyDouble ("C");
00089   nr_complex_t y = nr_complex_t (0, 2.0 * pi * frequency * c);
00090   setY (NODE_1, NODE_1, +y); setY (NODE_2, NODE_2, +y);
00091   setY (NODE_1, NODE_2, -y); setY (NODE_2, NODE_1, -y);
00092 }
00093 
00095 void capacitor::initAC (void) {
00096   allocMatrixMNA ();
00097 }
00098 
00099 #define qState 0 // charge state
00100 #define cState 1 // current state
00101 
00102 void capacitor::initTR (void) {
00103   setStates (2);
00104   initDC ();
00105 }
00106 
00107 void capacitor::calcTR (nr_double_t) {
00108 
00109   /* if this is a controlled capacitance then do nothing here */
00110   if (hasProperty ("Controlled")) return;
00111 
00112   nr_double_t c = getPropertyDouble ("C");
00113   nr_double_t g, i;
00114   nr_double_t v = real (getV (NODE_1) - getV (NODE_2));
00115 
00116   /* apply initial condition if requested */
00117   if (getMode () == MODE_INIT && isPropertyGiven ("V")) {
00118     v = getPropertyDouble ("V");
00119   }
00120 
00121   setState (qState, c * v);
00122   integrate (qState, c, g, i);
00123   setY (NODE_1, NODE_1, +g); setY (NODE_2, NODE_2, +g);
00124   setY (NODE_1, NODE_2, -g); setY (NODE_2, NODE_1, -g);
00125   setI (NODE_1 , -i);
00126   setI (NODE_2 , +i);
00127 }
00128 
00129 void capacitor::initHB (void) {
00130   initAC ();
00131 }
00132 
00133 void capacitor::calcHB (nr_double_t frequency) {
00134   calcAC (frequency);
00135 }
00136 
00137 // properties
00138 PROP_REQ [] = {
00139   { "C", PROP_REAL, { 1e-12, PROP_NO_STR }, PROP_NO_RANGE },
00140   PROP_NO_PROP };
00141 PROP_OPT [] = {
00142   { "V", PROP_REAL, { 0, PROP_NO_STR }, PROP_NO_RANGE },
00143   PROP_NO_PROP };
00144 struct define_t capacitor::cirdef =
00145   { "C", 2, PROP_COMPONENT, PROP_NO_SUBSTRATE, PROP_LINEAR, PROP_DEF };